/** * Lists all preBills matching a criteria */ public function indexAction() { // Check if the user is allowed to perform this action $dumbPreBill = new Application\Model\PreBillModel(); $this->_helper->allowed('list', $dumbPreBill); $filterList = $this->_preBillSrv->buildFilterList($this->getRequest()->getParams()); $this->_helper->filterNotAllowedFilters('filter_by', $filterList); $params = array(); if ($data = $this->_getParam('page')) { $params['page'] = $data; } if ($data = $this->_getParam('count')) { $params['count'] = $data; } $preBillList = $this->_preBillSrv->listAll($filterList, $params); $this->_checkReadPermisions($preBillList); $this->view->data = $preBillList->getItems(); $this->view->count = $preBillList->getCount(); }
/** * Lists all prebills matching a criteria */ public function indexAction() { // Check if the user is allowed to perform this action $dumbPreBill = new Application\Model\PreBillModel(); $this->_helper->allowed('list', $dumbPreBill); $filters = $this->_getFilterParams(); if (isset($filters['customerID'])) { $filters['customerId'] = $filters['customerID']; unset($filters['customerID']); } if (isset($filters['billingAccountID'])) { $orgUserLogged = App::getOrgUserLogged(); if ($orgUserLogged instanceof \Application\Model\Organization\OrgCustomerModel) { $filters['customerId'] = $orgUserLogged->id; } else { if (!isset($filters['customerId'])) { throw new InvalidArgumentException('Needed parameter was not found: customerID'); } } $filters['billingAccountId'] = $filters['billingAccountID']; unset($filters['billingAccountID']); } if (isset($filters['startDate'])) { if (isset($filters['endDate']) && strtotime($filters['endDate']) < strtotime($filters['startDate'])) { throw new InvalidArgumentException("Invalid parameter value: The start date can't be after the end date"); } $filters['creationPeriod'] = date('Y-m-d', strtotime($filters['startDate'])) . '<>'; unset($filters['startDate']); } if (isset($filters['endDate'])) { if (!isset($filters['creationPeriod']) || !$filters['creationPeriod']) { $filters['creationPeriod'] = '<>'; } $filters['creationPeriod'] .= date('Y-m-d', strtotime($filters['endDate'])); unset($filters['endDate']); } $this->_checkFilterParams($filters, PreBillFilterFields::getWhiteList()); try { $filterList = $this->_prebillSrv->buildFilterList($filters, true); } catch (\Application\Exceptions\ValidateException $e) { // HACK to override creationPeriod filter errors! $dataMap = array('startDate' => 'creationPeriod.min', 'endDate' => 'creationPeriod.max', 'billingAccountID' => 'billingAccountId', 'customerID' => 'customerId'); $e = $this->_mapException($e, $dataMap, true); $messages = $e->getValidationErrors(); $messageKeys = array_keys($messages); throw new Application\Exceptions\ValidateException("Invalid parameter value: '" . array_shift($messageKeys) . "'. " . array_shift($messages), array('validationErrors' => $messages, 'code' => $e->getCode())); } $this->_helper->filterNotAllowedFilters('filter_by', $filterList); $params = $this->_getPaginatorParams(); $prebillList = $this->_prebillSrv->listAll($filterList, $params); $items = $prebillList->getItems(); $this->view->prebill = array(); $orgUserLogged = App::getOrgUserLogged(); if ($orgUserLogged instanceof \Application\Model\Organization\OrgCustomerModel) { $items = array_slice($items, ($params['page'] - 1) * $params['count'], $params['count']); } foreach ($items as $item) { try { set_time_limit(30); $prebill = $this->_prebillSrv->load($item->getId()); $this->_helper->allowed('read', $prebill); $this->view->prebill[] = $this->_mapToSdp($prebill->exportData()); } catch (Exception $e) { \App::log()->warn($e); } } // $this->view->prebill = $prebillList->getItems(); }
/** * Lists all prebills matching a criteria */ public function indexAction() { // Check if the user is allowed to perform this action $dumbPreBill = new Application\Model\PreBillModel(); $this->_helper->allowed('list', $dumbPreBill); $filters = $this->_getFilterParams(); if (isset($filters['customerID'])) { $filters['customerId'] = $filters['customerID']; unset($filters['customerID']); } else { if (isset($filters['billingAccountID'])) { //BUG: #73707 unset($filters['billingAccountID']); } } if (isset($filters['billingAccountID'])) { $filters['billingAccountId'] = $filters['billingAccountID']; unset($filters['billingAccountID']); } if (isset($filters['startDate'])) { $filters['creationPeriod'] = date('Y-m-d', strtotime($filters['startDate'])) . '<>'; unset($filters['startDate']); } if (isset($filters['endDate'])) { if (!isset($filters['creationPeriod']) || !$filters['creationPeriod']) { $filters['creationPeriod'] = '<>'; } $filters['creationPeriod'] .= date('Y-m-d', strtotime($filters['endDate'])); unset($filters['endDate']); } // GLOBALPORTAL-26755: // CLONE - MTWOMPLATFORM-1828 - API. Prebill. getPrebills. Si se env�a startDate // pero no endDate (o viceversa) el error devuelto no es correcto if (isset($filters['startDate']) && !isset($filters['endDate'])) { // Missing endDate throw new InvalidArgumentException('Needed parameter was not found: endDate'); } if (!isset($filters['startDate']) && isset($filters['endDate'])) { // Missing startDate throw new InvalidArgumentException('Needed parameter was not found: startDate'); } $this->_checkFilterParams($filters, PreBillFilterFields::getWhiteList()); try { $filterList = $this->_prebillSrv->buildFilterList($filters, true); } catch (\Application\Exceptions\ValidateException $e) { $messages = $e->getValidationErrors(); $messageKeys = array_keys($messages); $exceptionMessage = "Invalid parameter value '" . array_shift($messageKeys) . "': " . array_shift($messages); $newException = new Application\Exceptions\ValidateException($exceptionMessage, array('validationErrors' => $messages, 'code' => $e->getCode())); $dataMap = array('startDate' => 'creationPeriod.min', 'endDate' => 'creationPeriod.max', 'billingAccountID' => 'billingAccountId', 'customerID' => 'customerId'); throw $this->_mapException($newException, $dataMap, true); } $this->_helper->filterNotAllowedFilters('filter_by', $filterList); $params = $this->_getPaginatorParams(); $prebillList = $this->_prebillSrv->listAll($filterList, $params); $items = $prebillList->getItems(); $this->view->prebill = array(); foreach ($items as $item) { try { $prebill = $this->_prebillSrv->load($item->getId()); $this->_helper->allowed('read', $prebill); $this->view->prebill[] = $this->_mapToSdp($prebill->exportData()); } catch (Exception $e) { \App::log()->warn($e); } } // $this->view->prebill = $prebillList->getItems(); }