Example #1
0
 /**
  *
  * Enter description here ...
  */
 public function exportToExcelAction()
 {
     $post['id_product_group'] = urldecode($this->getRequest()->getParam('id_product_group'));
     $post['id_family'] = urldecode($this->getRequest()->getParam('id_family'));
     $post['status'] = $this->getRequest()->getParam('status');
     $families = FamilyQuery::create()->filter($post)->find();
     if (!$families->isEmpty()) {
         $i = 1;
         while ($family = $families->read()) {
             if (ProductGroupQuery::create()->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $family->getIdProductGroup())->count()) {
                 $productGroup = ProductGroupQuery::create()->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $family->getIdProductGroup())->findOne();
             } else {
                 $productGroup = new ProductGroup();
             }
             $data[$i] = array($productGroup->getCode() . '-' . $productGroup->getName(), $family->getName(), $family->getCode(), $family->getStatusName());
             $i++;
         }
         $header = array($this->i18n->_('Product Group'), $this->i18n->_('Family'), $this->i18n->_('Code'), $this->i18n->_('Status'));
         $title = $this->i18n->_('Family Report');
         $fileName = $this->i18n->_('Family_report');
         $tableColumnsWidth = array('medium', 'medium', 'mini');
         $report = new SimpleListReport();
         $report->setTableTitle($title);
         $report->setTableHeaders($header);
         $report->setTableContent($data);
         $report->setFilename($fileName);
         $report->setTableColumnsWidth($tableColumnsWidth);
         $report->createSpreadsheet();
     } else {
         $filter = $this->createFilterForUrl($post);
         $this->setFlash("error", $this->i18n->_('No records'));
         $this->_redirect('family/list');
     }
 }