Ejemplo n.º 1
0
 public function reportExpenseAction()
 {
     $allCategory = Utility::getPaymentCate();
     $result = array();
     $link = false;
     $reportTitle = '';
     if ($this->getRequest()->isPost()) {
         $data = $this->params()->fromPost();
         $categoryId = $data['expense_category'];
         $strTime = ' ';
         $strCategory = '';
         if ($categoryId != 0) {
             $strCategory .= ' table.categoryId = ' . $categoryId;
         } else {
             $strCategory .= '  table.categoryId != -1 ';
         }
         if ($data['start'] != '' || $data['end'] != '') {
             $strTime .= ' AND table.time >= ' . strtotime($data['start']);
             $strTime .= ' AND table.time <= ' . strtotime($data['end']);
         }
         $result = $this->modelPayment->createQueryToArray($strCategory . $strTime);
         $category = Utility::getPaymentCateInfo($categoryId);
         $reportTitle = 'Report Expense in ' . $data['start'] . ' to ' . $data['end'] . ' by Category ' . $category->getName();
         if (isset($data['excel']) && $data['excel'] == true) {
             // $reportTitle = 'Report Expense in ' . $data['start'] . ' to ' . $data['end'] .' by Category '.$category->getName() ;
             // $dataExcel = $this->modelPayment->convertToArray($result);
             $column = array('id' => ' id', 'title' => 'Name', 'value' => 'Quantity', 'reason' => 'Reason', 'time' => 'Time', 'categoryId' => 'Category');
             $link = renderExcel::renderExcelBasic($result, $column, $reportTitle);
             return self::forceDownloadAction($link);
         }
     }
     return new ViewModel(array('title' => $reportTitle, 'result' => $result, 'categories' => $allCategory, 'linkDownload' => $link));
 }