public function convertSingleToArray($user) { $paymentCategory = Utility::getPaymentCateInfo($user->getCategoryId()); $date = $user->getTime(); $date == '' ? $time = time() : ($time = $date); $array = array(); $array['id'] = $user->getId(); $array['title'] = $user->getTitle(); $array['value'] = number_format($user->getValue()); $array['reason'] = $user->getReason(); $array['time'] = date('d-m-Y', $time); $array['categoryId'] = $user->getCategoryId(); return $array; }
public function ajaxListAction() { $fields = array('id', 'title', 'value', 'reason', 'time', 'categoryId'); $offset = $this->getDataTableQueryOffset(); $limit = $this->getDataTableQueryLimit(); $sortCol = $this->getDataTableQuerySortingColumn(4); $sortDirection = $this->getDataTableQuerySortingDirection(); $search = $this->getDataTableQuerySearch(); $customWhere = ''; // WHERE conditions $customQuery = $this->customWhereSql($customWhere); $dqlWhere = $this->getDataTableWhereDql('c', $fields, $search, $customWhere); if (!empty($dqlWhere)) { $customQuery = ''; } // ORDERING $dqlOrder = $this->getDataTableOrderDql('c', $fields, $sortCol, $sortDirection); // DQL $dql = "SELECT c FROM Admin\\Entity\\Payment c"; // RESULTS $query = $this->getEntityManager()->createQuery($dql . $customQuery . $dqlWhere . $dqlOrder); if (!empty($dqlWhere)) { $query->setParameter(':search', '%' . $search . '%'); } $results = $query->setMaxResults($limit)->setFirstResult($offset)->getResult(); // TOTAL RESULTS COUNT $countDql = "SELECT COUNT(c.id) FROM Admin\\Entity\\Payment c"; $count = $this->getEntityManager()->createQuery($countDql)->getSingleScalarResult(); // map data $ret = array_map(function ($item) { $paymentCate = Utility::getPaymentCateInfo($item->getCategoryId()); // create link $linkEdit = '/admin/payment/add/' . $item->getId(); $linkDelete = '/admin/payment/delete/' . $item->getId(); $linkDetail = '/admin/payment/detail/' . $item->getId(); $item->getTime() != '' ? $time = date('d-m-Y', $item->getTime()) : ($time = time()); return array('id' => $item->getId(), 'title' => $item->getTitle(), 'value' => number_format($item->getValue()), 'reason' => $item->getReason(), 'time' => $time, 'categoryId' => $paymentCate->getName(), 'action' => ' <a href="' . $linkDetail . '" class="btn btn-info"><i class="icon-edit-sign"></i></a> <a class="btn btn-primary" href="' . $linkEdit . '"><i class="icon-edit-sign"></i></a> <a href="' . $linkDelete . '" class="btn btn-danger"><i class="icon-trash"></i></a>'); }, $results); return $this->getDataTableJsonResponse($ret, $count, $dqlWhere); }
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)); }