Beispiel #1
0
 /**
  * Busca os dados da consulta
  */
 protected function _make()
 {
     $rs = $this->_getRecordset();
     $this->_printParams();
     $this->_verifyLineJump($this->_columns);
     $this->_addRow($this->_columns, true);
     if ($this->_options['driver'] == 'PDF') {
         #$this->_report->drawLine();
     }
     $row = $rs->getRow();
     if ($this->_options['log']) {
         $this->_log->finishDb();
     }
     $numRows = 0;
     if ($row) {
         if (count($this->_columnsBreak) > 0) {
             $current = '';
             $orderBreak = array();
             foreach ($this->_columnsBreak as $columnName => &$columnBreak) {
                 $orderBreak[] = $columnName;
                 $current .= $row[$columnName]->get();
                 $columnBreak['prev'] = $current;
             }
             $orderBreakReverse = array_reverse($orderBreak);
         }
         do {
             $numRows++;
             if (count($this->_columnsBreak) > 0) {
                 $current = '';
                 foreach ($this->_columnsBreak as $columnName => &$columnBreak) {
                     $current .= $row[$columnName]->get();
                     $columnBreak['current'] = $current;
                 }
                 foreach ($orderBreakReverse as $columnName) {
                     if ($this->_columnsBreak[$columnName]['current'] != $this->_columnsBreak[$columnName]['prev']) {
                         if ($this->_options['advanced']['order_column'] == '' && $this->_columnsBreak[$columnName]['subtotal']) {
                             $rowBreak = array();
                             $this->_labelBreak = 'Subtotal';
                             $rowBreak[$columnName] = $this->_labelBreak;
                             foreach ($this->_columnsBreak[$columnName]['subtotal'] as $column => $total) {
                                 $rowBreak[$column] = $total->getTotal($this->_mapper->getModel()->getAdapter());
                                 $this->_columnsBreak[$columnName]['subtotal'] = null;
                             }
                             $this->_addRow($rowBreak, false, true, array(), false);
                             /**
                              * Pula uma linha
                              */
                             foreach ($rowBreak as &$value) {
                                 $value = '';
                             }
                             $this->_addRow($rowBreak, false, true, array(), true);
                             #$this->_report->drawLine();
                         }
                         $this->_columnsBreak[$columnName]['prev'] = $this->_columnsBreak[$columnName]['current'];
                     }
                 }
             }
             $this->_verifyLineJump($row);
             $this->_addRow($row, false);
         } while ($row = $rs->getRow());
     }
     if ($this->_options['log']) {
         $this->_log->finish($numRows);
     }
     if (count($this->_columnsBreak) > 0) {
         foreach ($orderBreakReverse as $columnName) {
             if ($this->_options['advanced']['order_column'] == '' && $this->_columnsBreak[$columnName]['subtotal']) {
                 $rowBreak = array();
                 $this->_labelBreak = 'Subtotal';
                 $rowBreak[$columnName] = $this->_labelBreak;
                 foreach ($this->_columnsBreak[$columnName]['subtotal'] as $column => $total) {
                     $rowBreak[$column] = $total->getTotal($this->_mapper->getModel()->getAdapter());
                     $this->_columnsBreak[$columnName]['subtotal'] = null;
                 }
                 $this->_addRow($rowBreak, false, true);
                 #$this->_report->drawLine();
             }
         }
     }
     if (count($this->_total) > 0) {
         #$this->_report->drawLine();
         $row = array();
         foreach ($this->_columns as $column => $atributes) {
             break;
         }
         $this->_labelBreak = 'Total';
         $row[$column] = $this->_labelBreak;
         foreach ($this->_total as $columnName => $total) {
             $row[$columnName] = $total->getTotal($this->_mapper->getModel()->getAdapter());
         }
         $this->_addRow($row, false, true);
     }
 }
Beispiel #2
0
 public function configReportSample($type = 'pdf', $options = false)
 {
     set_time_limit(3200);
     $moduleName = $this->getRequest()->getModuleName();
     $controllerName = $this->getRequest()->getControllerName();
     /**
      * Configuração do estilos padrão
      */
     $dnsEmpresas = array();
     $dnsEmpresas['tanet.com.br'] = 'TA';
     $dnsEmpresas['talog.com.br'] = 'TAL';
     $dnsEmpresas['taexpress.com.br'] = 'TAE';
     $dnsEmpresas['windexpress.com.br'] = 'TAE';
     $dnsEmpresas['tawind.com.br'] = 'TAE';
     $domain = ZendT_Url::getDomain();
     $empresa = 'TA';
     if (isset($dnsEmpresas[$domain])) {
         $empresa = $dnsEmpresas[$domain];
     }
     $default = array('title' => array('fontSize' => 10, 'bold' => true, 'width' => 160, 'align' => 'center', 'value' => utf8_decode($this->_translate->_($moduleName . '.' . $controllerName . '.grid'))), 'default' => array('fontSize' => 8, 'bold' => false, 'fontName' => 'Arial'), 'cellsTitle' => array('fontSize' => 8, 'bold' => true, 'align' => 'center'), 'empresa' => $empresa, 'maxPerLine' => 4, 'orientation' => 'P');
     if (is_array($options)) {
         $options = ZendT_Functions::array_merge_recursive_distinct($default, $options);
     } else {
         $options = $default;
     }
     $title = $this->_translate->_($moduleName . '.' . $controllerName . '.grid');
     if (is_array($options['title'])) {
         $options['title'] = new ZendT_Report_Cell($options['title']);
         $options['title']->setStyleName('title');
     }
     if (is_array($options['footer'])) {
         $options['footer'] = new ZendT_Report_Cell($options['footer']);
         $options['footer']->setStyleName('footer');
     }
     /**
      * Tratamento para buscar os dados no banco de dados
      */
     $postData = $this->getRequest()->getParams();
     $postData['page'] = false;
     $postData['count'] = false;
     $whereGroup = $this->getWherePostData();
     $mapperView = get_class($this->_mapper);
     $logReport = new ZendT_Log_Report($mapperView, $title);
     if ($this->_mapper instanceof ZendT_Db_View) {
         $dataGrid = $this->getMapper()->getDataGrid($whereGroup, $postData);
     } else {
         $dataGrid = $this->getModel()->getDataGrid($whereGroup, $postData);
     }
     $logReport->finishDb();
     /**
      * Instancia do objeto de relat�rio
      */
     $report = ZendT_Report::factory($type, $options);
     $report->addPage();
     /**
      * Configuração da coluna de título
      */
     $celulas = array();
     foreach ($this->getColumns() as $column) {
         if (!$column->getHidden()) {
             $key = $column->getName();
             $celulas[$key] = new ZendT_Report_Cell($options['cellsTitle']);
             $celulas[$key]->setTextAlign($column->getAlign())->setWidth($column->getWidth())->setValue($column->getHeaderTitle());
             $celulas[$key]->setStyleName('cellsTitle-' . $key);
             $report->addCell($celulas[$key]);
         }
     }
     $report->printCells();
     /**
      * Impressão dos registros detalhe
      */
     $callStylesRow = method_exists($this->getMapper(), 'getStylesRow');
     $celulas = array();
     $numRows = 0;
     while ($row = $dataGrid->getRow()) {
         $stylesRow = array();
         if ($callStylesRow) {
             $stylesRow = $this->getMapper()->getStylesRow($row);
         }
         foreach ($this->getColumns() as $column) {
             if (!$column->getHidden()) {
                 $key = $column->getName();
                 $cellOptions = $column->getOptions();
                 if ($dataGrid->getType()) {
                     $value = $row[strtolower($key)];
                     $type = $value->getType();
                     if (isset($cellOptions['expandTree'])) {
                         $newValue = $value->get();
                         $newValue = str_repeat(' ', $row['tree_level']->toPhp() * 4) . $newValue;
                         $value->set($newValue);
                     }
                 } elseif ($dataGrid->isRowFormated()) {
                     $value = $row[strtolower($key)];
                     $type = $column->getSorttype();
                 } else {
                     $value = $column->format($row[strtolower($key)]);
                     $type = $column->getSorttype();
                 }
                 $celName = $key;
                 if (isset($stylesRow[$key])) {
                     if (!$stylesRow[$key]['suffix']) {
                         $stylesRow[$key]['suffix'] = 'plus';
                     }
                     $celName .= '-' . $stylesRow[$key]['suffix'];
                 }
                 if (!isset($celulas[$celName])) {
                     $celulas[$celName] = new ZendT_Report_Cell($options['default']);
                     $celulas[$celName]->setTextAlign($column->getAlign())->setWidth($column->getWidth())->setType($type);
                     $celulas[$celName]->setStyleName('default-' . $celName);
                     if (isset($stylesRow[$key])) {
                         $celulas[$celName]->setStyles($stylesRow[$key]);
                     }
                 }
                 $celulas[$celName]->setValue($value);
                 $report->addCell($celulas[$celName]);
             }
         }
         $report->printCells();
         $numRows++;
     }
     /**
      * Impressão/Saída do relatório
      */
     $result = array('name' => str_replace(' ', '-', $title), 'content' => $report->output(ZendT_Lib::getTableDesc(), 'S'));
     $logReport->finish($numRows);
     return $result;
 }