Example #1
0
 /**
  * @param $queryParams
  * @return array
  * @throws \Exception
  */
 public function getCsvArrayForDownload($queryParams)
 {
     $expenseItemDao = new ExpenseItem($this->getServiceLocator(), '\\ArrayObject');
     $costCenterDao = new ExpenseCost($this->getServiceLocator(), '\\ArrayObject');
     $where = $this->constructWhereForItemSearchForDatatable($queryParams);
     $itemIdList = [];
     $result = $expenseItemDao->getItemsCsvForDownload($where);
     $items = iterator_to_array($result);
     $finalArray = [['Created Date', 'Period', 'Supplier', 'Reference', 'Cost Centers', 'Category', 'Subcategory', 'Amount', 'Comment', 'Type']];
     $costCenters = $this->getCostCenters($costCenterDao, $items, $itemIdList);
     foreach ($items as &$item) {
         $costCenterArray = [];
         if (isset($costCenters[$item['id']])) {
             foreach ($costCenters[$item['id']] as $costCenter) {
                 array_push($costCenterArray, $costCenter['name'] . ' (' . $costCenter['label'] . ')  ');
             }
         }
         $supplier = $item['account_name'] . ' (' . TransactionBase::getAccountTypeById($item['account_type']) . ')';
         $supplierRefference = $item['account_reference'];
         $dateCreated = date(Constants::GLOBAL_DATE_FORMAT, strtotime($item['date_created']));
         $periodFrom = !is_null($item['period_from']) ? date(Constants::GLOBAL_DATE_FORMAT, strtotime($item['period_from'])) : '';
         $periodTo = !is_null($item['period_to']) ? date(Constants::GLOBAL_DATE_FORMAT, strtotime($item['period_to'])) : '';
         $period = $periodFrom . ' - ' . $periodTo;
         $comment = $item['comment'];
         $category = $item['category_name'];
         $subCategory = $item['sub_category_name'];
         $amount = $item['amount'] . $item['currency'];
         $type = $item['type'];
         array_push($finalArray, [$dateCreated, $period, $supplier, $supplierRefference, implode(',', $costCenterArray), $category, $subCategory, $amount, $comment, Helper::$types[$type]]);
     }
     return $finalArray;
 }