Esempio n. 1
0
File: Cost.php Progetto: arbi/MyCode
 public function downloadCsvAction()
 {
     $apartmentGeneralService = $this->getServiceLocator()->get('service_apartment_general');
     $currency = $apartmentGeneralService->getCurrencySymbol($this->apartmentId);
     $expenseDao = new ExpenseCost($this->getServiceLocator(), '\\ArrayObject');
     $costs = $expenseDao->getApartmentCosts($this->apartmentId);
     $costArray = [];
     foreach ($costs as $cost) {
         $costArray[] = ["ID" => $cost['id'], "Category" => $cost['category'], "Date" => date(Constants::GLOBAL_DATE_FORMAT, strtotime($cost['date'])), "Amount ({$currency})" => $cost['amount'], "Purpose" => $cost['purpose']];
     }
     if (!empty($costArray)) {
         $response = $this->getResponse();
         $headers = $response->getHeaders();
         $utilityCsvGenerator = new CsvGenerator();
         $filename = 'costs_apartment_' . str_replace(' ', '_', date('Y-m-d')) . '.csv';
         $utilityCsvGenerator->setDownloadHeaders($headers, $filename);
         $csv = $utilityCsvGenerator->generateCsv($costArray);
         $response->setContent($csv);
         return $response;
     } else {
         $flash_session = Helper::getSessionContainer('use_zf2');
         $flash_session->flash = ['notice' => 'There are empty data, nothing to download.'];
         $url = $this->getRequest()->getHeader('Referer')->getUri();
         $this->redirect()->toUrl($url);
     }
 }
Esempio n. 2
0
 /**
  * @param int $ticketId
  * @return bool
  */
 public function deleteTicket($ticketId)
 {
     $expenseDao = new Expenses($this->getServiceLocator(), '\\ArrayObject');
     $expenseItemDao = new ExpenseItem($this->getServiceLocator(), '\\ArrayObject');
     $costCenterDao = new ExpenseCost($this->getServiceLocator(), '\\ArrayObject');
     $expenseAttachmentDao = new ExpenseAttachments($this->getServiceLocator(), '\\ArrayObject');
     $expenseItemAttachmentDao = $this->getServiceLocator()->get('dao_finance_expense_expense_item_attachments');
     try {
         $expenseDao->beginTransaction();
         $expense = $expenseDao->fetchOne(['id' => $ticketId]);
         if (!$expense) {
             throw new NotFoundException('Purchase order not found.');
         }
         $expenseItems = $expenseItemDao->fetchAll(['expense_id' => $ticketId], ['id']);
         $expenseAttachments = $expenseAttachmentDao->fetchAll(['expense_id' => $ticketId], ['id']);
         $expenseItemAttachments = $expenseItemAttachmentDao->fetchAll(['expense_id' => $ticketId], ['item_id']);
         // Delete items
         if ($expenseItems->count()) {
             $itemIdList = [];
             foreach ($expenseItems as $expenseItem) {
                 array_push($itemIdList, $expenseItem['id']);
             }
             $costCenterDao->deleteItemCosts($itemIdList);
         }
         $expenseItemDao->delete(['expense_id' => $ticketId]);
         $purchaseOrderTransactions = $this->getServiceLocator()->get('service_finance_transaction_po_transaction');
         $purchaseOrderTransactions->removePurchaseOrderAllTransactions($ticketId, false);
         // Delete Ticket attachments
         if ($expenseAttachments->count()) {
             $attachmentIdList = [];
             foreach ($expenseAttachments as $expenseAttachment) {
                 array_push($attachmentIdList, $expenseAttachment['id']);
             }
             $errorMessages = $this->removeFiles($attachmentIdList);
             if (count($errorMessages)) {
                 /**
                  * @todo: There are an error messages
                  */
             }
         }
         // Delete Item attachments
         if ($expenseItemAttachments->count()) {
             $attachmentItemIdList = [];
             foreach ($expenseItemAttachments as $expenseItemAttachment) {
                 array_push($attachmentItemIdList, ['item_id' => $expenseItemAttachment->getItemId(), 'expense_id' => $ticketId]);
             }
             $this->removeItemFiles($attachmentItemIdList);
         }
         // Delete ticket
         $expenseDao->delete(['id' => $ticketId]);
         $expenseDao->commitTransaction();
         return true;
     } catch (\Exception $ex) {
         $expenseDao->rollbackTransaction();
     }
     return false;
 }