From ffc227c0edd5ed652cd11b6bcaaa2859f9a576e4 Mon Sep 17 00:00:00 2001 From: Daniel Tamajon Date: Wed, 22 Mar 2017 17:25:37 +0100 Subject: [PATCH 1/7] Update Grid.php --- .../Adminhtml/Customreport/View/Grid.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php b/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php index 2752d34..6b68f45 100755 --- a/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php +++ b/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php @@ -90,10 +90,18 @@ protected function _prepareColumns() $filterable = $config->getFilterable(); $clickable = $config->getClickable(); $hidden = $config->getHidden(); + $type = $config->getType(); + $alignment = $config->getAlignment(); $items = $collection->getItems(); + + $store = Mage::app()->getStore(); + $currency_code = $store->getBaseCurrency()->getCode(); if (count($items)) { $item = reset($items); foreach ($item->getData() as $key => $val) { + $column_css_class = array(); + $header_css_class = array(); + $isFilterable = false; if (isset($filterable[$key])) { $isFilterable = $filterable[$key]; @@ -111,7 +119,19 @@ protected function _prepareColumns() $isHidden = false; if (isset($hidden[$key])) { $isHidden = true; + $column_css_class[] = 'no-display'; + $header_css_class[] = 'no-display'; } + + if(isset($alignment[$key])) { + if($alignment[$key] == 'right') { + $column_css_class[] = 'a-right'; + } + elseif($alignment[$key] == 'center') { + $column_css_class[] = 'a-center'; + } + } + $this->addColumn( Mage::getModel('catalog/product')->formatUrlKey($key), array( @@ -119,9 +139,11 @@ protected function _prepareColumns() 'index' => $key, 'filter' => $isFilterable, 'sortable' => true, + 'type' => (isset($type[$key]) ? $type[$key] : 'text'), 'renderer' => $isClickable, - 'column_css_class' => ($isHidden ? 'no-display' : ''), - 'header_css_class' => ($isHidden ? 'no-display' : ''), + 'column_css_class' => implode(' ', $column_css_class), + 'header_css_class' => implode(' ', $header_css_class), + 'currency_code' => $currency_code, ) ); } From ebc91df24486746b315328ba92c1abca03cd2bc5 Mon Sep 17 00:00:00 2001 From: Daniel Tamajon Date: Wed, 22 Mar 2017 17:26:17 +0100 Subject: [PATCH 2/7] Update GridConfig.php --- .../SqlReports/Model/Report/GridConfig.php | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php b/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php index 27d11c1..600acc3 100644 --- a/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php +++ b/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php @@ -40,4 +40,30 @@ public function getClickable() return array(); } -} \ No newline at end of file + /** + * get list of columns types + * @return array + */ + public function getType() + { + $type = $this->getData('type'); + if (is_array($type)) { + return $type; + } + return array(); + } + + /** + * get list of columns alignment options + * @return array + */ + public function getAlignment() + { + $alignment = $this->getData('alignment'); + if (is_array($alignment)) { + return $alignment; + } + return array(); + } + +} From 1484f57c3ce6089d96414ff17be11950838ee313 Mon Sep 17 00:00:00 2001 From: Daniel Tamajon Date: Wed, 22 Mar 2017 20:27:51 +0100 Subject: [PATCH 3/7] Support to export to Excel --- .../default/default/layout/clean_sqlreports/cleansql.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/design/adminhtml/default/default/layout/clean_sqlreports/cleansql.xml b/app/design/adminhtml/default/default/layout/clean_sqlreports/cleansql.xml index 7d56787..e501576 100644 --- a/app/design/adminhtml/default/default/layout/clean_sqlreports/cleansql.xml +++ b/app/design/adminhtml/default/default/layout/clean_sqlreports/cleansql.xml @@ -59,5 +59,9 @@ + + + + From 16385261289f8cfefa639741578f3b2a9e261dcd Mon Sep 17 00:00:00 2001 From: Daniel Tamajon Date: Wed, 22 Mar 2017 20:29:41 +0100 Subject: [PATCH 4/7] Support to export to Excel --- .../Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php b/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php index 6b68f45..0654c41 100755 --- a/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php +++ b/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php @@ -12,6 +12,7 @@ public function __construct() $this->setDefaultDir('ASC'); $this->setSaveParametersInSession(true); $this->addExportType('*/*/exportCsv', $this->__('CSV')); + $this->addExportType('*/*/exportExcel', $this->__('Excel')); } protected function _prepareLayout() From 70f03ed04987cfe0e139a56025d20f1ea3a84148 Mon Sep 17 00:00:00 2001 From: Daniel Tamajon Date: Wed, 22 Mar 2017 20:30:49 +0100 Subject: [PATCH 5/7] Support to export to Excel --- .../Adminhtml/CustomreportController.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/code/community/Clean/SqlReports/controllers/Adminhtml/CustomreportController.php b/app/code/community/Clean/SqlReports/controllers/Adminhtml/CustomreportController.php index 7b40c39..afc4a71 100755 --- a/app/code/community/Clean/SqlReports/controllers/Adminhtml/CustomreportController.php +++ b/app/code/community/Clean/SqlReports/controllers/Adminhtml/CustomreportController.php @@ -114,6 +114,31 @@ public function exportCsvAction() ); } + /** + * Export grid to Excel format + */ + public function exportExcelAction() + { + Mage::register('current_report', $this->_getReport()); + $this->loadLayout(); + + /** @var $grid Mage_Adminhtml_Block_Widget_Grid */ + $grid = $this->getLayout()->getBlock('report.view.grid'); + + if(!$grid instanceof Mage_Adminhtml_Block_Widget_Grid) { + $this->_forward('noroute'); + return; + } + + $fileName = strtolower(str_replace(' ', '_', $this->_getReport()->getTitle())) . '_' . time() . '.xls'; + $content = $grid->getExcel($fileName); + + $this->_prepareDownloadResponse( + $fileName, + $content + ); + } + /** * Get JSON action * @@ -156,7 +181,7 @@ protected function _getReport() protected function _isAllowed() { - $isView = in_array($this->getRequest()->getActionName(), array('index', 'view', 'viewtable', 'viewchart', 'getJson', 'exportCsv')); + $isView = in_array($this->getRequest()->getActionName(), array('index', 'view', 'viewtable', 'viewchart', 'getJson', 'exportCsv', 'exportExcel')); /** @var $helper Clean_SqlReport_Helper_Data */ $helper = Mage::helper('cleansql'); From eceaf8ef72e5729576d7ec1a0f58852fb94bb34b Mon Sep 17 00:00:00 2001 From: Daniel Tamajon Date: Wed, 22 Mar 2017 20:41:47 +0100 Subject: [PATCH 6/7] Update GridConfig.php --- .../SqlReports/Model/Report/GridConfig.php | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php b/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php index 600acc3..a7f8111 100644 --- a/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php +++ b/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php @@ -40,30 +40,4 @@ public function getClickable() return array(); } - /** - * get list of columns types - * @return array - */ - public function getType() - { - $type = $this->getData('type'); - if (is_array($type)) { - return $type; - } - return array(); - } - - /** - * get list of columns alignment options - * @return array - */ - public function getAlignment() - { - $alignment = $this->getData('alignment'); - if (is_array($alignment)) { - return $alignment; - } - return array(); - } - } From f51c6a59ce47a2cb705ab84e664cf485322115be Mon Sep 17 00:00:00 2001 From: Daniel Tamajon Date: Wed, 22 Mar 2017 20:42:54 +0100 Subject: [PATCH 7/7] Update Grid.php --- .../Adminhtml/Customreport/View/Grid.php | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php b/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php index 0654c41..7a621a4 100755 --- a/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php +++ b/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php @@ -91,18 +91,10 @@ protected function _prepareColumns() $filterable = $config->getFilterable(); $clickable = $config->getClickable(); $hidden = $config->getHidden(); - $type = $config->getType(); - $alignment = $config->getAlignment(); $items = $collection->getItems(); - - $store = Mage::app()->getStore(); - $currency_code = $store->getBaseCurrency()->getCode(); if (count($items)) { $item = reset($items); foreach ($item->getData() as $key => $val) { - $column_css_class = array(); - $header_css_class = array(); - $isFilterable = false; if (isset($filterable[$key])) { $isFilterable = $filterable[$key]; @@ -120,19 +112,7 @@ protected function _prepareColumns() $isHidden = false; if (isset($hidden[$key])) { $isHidden = true; - $column_css_class[] = 'no-display'; - $header_css_class[] = 'no-display'; } - - if(isset($alignment[$key])) { - if($alignment[$key] == 'right') { - $column_css_class[] = 'a-right'; - } - elseif($alignment[$key] == 'center') { - $column_css_class[] = 'a-center'; - } - } - $this->addColumn( Mage::getModel('catalog/product')->formatUrlKey($key), array( @@ -140,11 +120,9 @@ protected function _prepareColumns() 'index' => $key, 'filter' => $isFilterable, 'sortable' => true, - 'type' => (isset($type[$key]) ? $type[$key] : 'text'), 'renderer' => $isClickable, - 'column_css_class' => implode(' ', $column_css_class), - 'header_css_class' => implode(' ', $header_css_class), - 'currency_code' => $currency_code, + 'column_css_class' => ($isHidden ? 'no-display' : ''), + 'header_css_class' => ($isHidden ? 'no-display' : ''), ) ); }