public function getUsers(PaginationParameters $paginationParameters)
 {
     $queryBuilder = $this->createQueryBuilder('User');
     $paginationParameters->setFilters(array());
     //        return $queryBuilder->getQuery()->getResult();
     return $this->getPaginatedResult($queryBuilder, $paginationParameters);
 }
 public function getTransactions(PaginationParameters $paginationParameters)
 {
     $queryBuilder = $this->createQueryBuilder('BankTransaction');
     $queryBuilder->where('BankTransaction.user = :user')->setParameter('user', $paginationParameters->getFilter('user'));
     $queryBuilder->andWhere('BankTransaction.type = :type')->setParameter('type', $paginationParameters->getFilter('type'));
     $queryBuilder->addOrderBy('BankTransaction.paymentDate', 'DESC');
     $paginationParameters->setFilters(array());
     return $this->getPaginatedResult($queryBuilder, $paginationParameters);
 }
 public function getBankAutocompleteInvoices(PaginationParameters $paginationParameters)
 {
     $queryBuilder = $this->createQueryBuilder('Invoice');
     $queryBuilder->where('Invoice.status = :status')->setParameter('status', Document\Invoice::STATUS_CONFIRMED);
     $queryBuilder->andWhere('Invoice.paymentStatus = :paymentStatus')->setParameter('paymentStatus', Document\Invoice::PAYMENT_STATUS_UNPAID);
     if ($paginationParameters->getFilter('autocomplete') != null) {
         $queryBuilder->andWhere('Invoice.documentNumber LIKE :autocomplete OR Invoice.prefix LIKE :autocomplete OR Invoice.referenceNumber LIKE :autocomplete')->setParameter('autocomplete', '%' . $paginationParameters->getFilter('autocomplete') . '%');
     }
     $paginationParameters->setFilters(array());
     return $this->getPaginatedResult($queryBuilder, $paginationParameters);
 }
 public function getSubmittedPayments(\DateTime $fromDate, \DateTime $toDate, User $user)
 {
     $paginationParameters = new PaginationParameters();
     $paginationParameters->setFilters(array('fromDate' => $fromDate, 'toDate' => $toDate, 'confirmed' => true));
     $sum = 0;
     $invoices = $this->invoiceService->getPurchaseInvoices($user, $paginationParameters);
     foreach ($invoices as $invoice) {
         /* @var $invoice \Application\Entity\Document */
         $sum += $this->invoiceService->getPaidAmountByInvoice($invoice);
     }
     return $sum;
 }
 public function indexAction()
 {
     $paginationParameters = new PaginationParameters($this->params('page'), $this->params('sort', 'id'), $this->params('order', 'desc'));
     $auth = $this->getServiceLocator()->get('zfcuser_auth_service');
     $user = $auth->getIdentity();
     $view = new ViewModel();
     if ($this->request->isGet()) {
         $paginationParameters->setFilters(array('name' => $this->request->getQuery()->name, 'regNo' => $this->request->getQuery()->regNo, 'taxNo' => $this->request->getQuery()->taxNo));
     }
     $view->customers = $this->customerService->getCustomers($user, $paginationParameters);
     $view->paginationParameters = $paginationParameters;
     $view->messages = $this->flashMessenger()->getMessages();
     $view->page = $this->params('page');
     $view->subject = Company::SUBJECT_CUSTOMER;
     return $view;
 }
 public function getCompanies(PaginationParameters $paginationParameters)
 {
     $queryBuilder = $this->createQueryBuilder('Company');
     if ($paginationParameters->getFilter('name') != null) {
         $queryBuilder->where('Company.name LIKE :name')->setParameter('name', '%' . $paginationParameters->getFilter('name') . '%');
     }
     if ($paginationParameters->getFilter('regNo') != null) {
         $queryBuilder->where('Company.regNo LIKE :regNo')->setParameter('regNo', '%' . $paginationParameters->getFilter('regNo') . '%');
     }
     if ($paginationParameters->getFilter('taxNo') != null) {
         $queryBuilder->where('Company.kmkrNo LIKE :taxNo')->setParameter('taxNo', '%' . $paginationParameters->getFilter('taxNo') . '%');
     }
     $paginationParameters->setFilters(array());
     return $this->getPaginatedResult($queryBuilder, $paginationParameters);
 }
 public function indexAction()
 {
     $paginationParameters = new PaginationParameters($this->params('page'), $this->params('sort', 'id'), $this->params('order', 'desc'));
     $auth = $this->getServiceLocator()->get('zfcuser_auth_service');
     $user = $auth->getIdentity();
     $view = new ViewModel();
     $form = $this->getServiceLocator()->get('Application\\Form\\Article');
     $form->setUser($user);
     $form->init();
     if ($this->request->isGet()) {
         $paginationParameters->setFilters(array('name' => $this->request->getQuery()->name, 'code' => $this->request->getQuery()->code));
     }
     $view->articles = $this->articleService->getArticles($user, $paginationParameters);
     $view->paginationParameters = $paginationParameters;
     $view->messages = $this->flashMessenger()->getMessages();
     $view->form = $form;
     $view->page = $this->params('page');
     return $view;
 }
 public function getSuppliers(User $user, PaginationParameters $paginationParameters = null)
 {
     $queryBuilder = $this->createQueryBuilder('Supplier');
     $queryBuilder->where('Supplier.user = :user')->setParameter('user', $user);
     if (!$paginationParameters) {
         return $queryBuilder->getQuery()->getResult();
     }
     if ($paginationParameters->getFilter('name') != null) {
         $queryBuilder->andWhere('Supplier.name LIKE :name')->setParameter('name', '%' . $paginationParameters->getFilter('name') . '%');
     }
     if ($paginationParameters->getFilter('regNo') != null) {
         $queryBuilder->andWhere('Supplier.regNo LIKE :regNo')->setParameter('regNo', '%' . $paginationParameters->getFilter('regNo') . '%');
     }
     if ($paginationParameters->getFilter('taxNo') != null) {
         $queryBuilder->andWhere('Supplier.kmkrNo LIKE :taxNo')->setParameter('taxNo', '%' . $paginationParameters->getFilter('taxNo') . '%');
     }
     $paginationParameters->setFilters(array());
     return $this->getPaginatedResult($queryBuilder, $paginationParameters);
 }
 public function outgoingAction()
 {
     $view = new ViewModel();
     $form = $this->getServiceLocator()->get('Application\\Form\\Transaction')->init();
     $type = BankTransaction::TYPE_OUTGOING;
     $form->get('type')->setValue($type);
     $paginationParameters = new PaginationParameters($this->params('page'), $this->params('sort', 'id'), $this->params('order', 'desc'));
     $auth = $this->getServiceLocator()->get('zfcuser_auth_service');
     $user = $auth->getIdentity();
     if ($this->request->isGet()) {
         $paginationParameters->setFilters(array('type' => $type, 'user' => $user));
     }
     $view->outgoings = $this->bankService->getTransactions($paginationParameters);
     $view->messages = $this->flashMessenger()->getMessages();
     $view->errorMessages = $this->flashMessenger()->getErrorMessages();
     $view->type = $type;
     $view->form = $form;
     return $view;
 }
 public function getPurchaseInvoices(User $user, PaginationParameters $paginationParameters = null)
 {
     $queryBuilder = $this->createQueryBuilder('PurchaseInvoice');
     $queryBuilder->where('PurchaseInvoice.user = :user')->setParameter('user', $user);
     $queryBuilder->leftJoin('PurchaseInvoice.supplier', 'Supplier');
     if ($paginationParameters->getFilter('status') != null) {
         $queryBuilder->andWhere('PurchaseInvoice.status = :status')->setParameter('status', $paginationParameters->getFilter('status'));
     }
     if ($paginationParameters->getFilter('date') != null) {
         $queryBuilder->andWhere('PurchaseInvoice.documentDate = :date')->setParameter('date', $paginationParameters->getFilter('date'));
     }
     if ($paginationParameters->getFilter('fromDate') != null) {
         $queryBuilder->andWhere('PurchaseInvoice.documentDate >= :fromDate')->setParameter('fromDate', $paginationParameters->getFilter('fromDate'));
     }
     if ($paginationParameters->getFilter('toDate') != null) {
         $queryBuilder->andWhere('PurchaseInvoice.documentDate <= :toDate')->setParameter('toDate', $paginationParameters->getFilter('toDate'));
     }
     if ($paginationParameters->getFilter('confirmed') != null) {
         $queryBuilder->andWhere('PurchaseInvoice.confirmed = :confirmed')->setParameter('confirmed', $paginationParameters->getFilter('confirmed'));
     }
     if ($paginationParameters->getFilter('unpaid') != null && $paginationParameters->getFilter('unpaid') == true) {
         $queryBuilder->andWhere('PurchaseInvoice.paymentStatus != :statusPaid')->setParameter('statusPaid', Document::PAYMENT_STATUS_PAID);
     }
     if ($paginationParameters->getFilter('supplier') != null) {
         $queryBuilder->andWhere('Supplier.name LIKE :supplier')->setParameter('supplier', '%' . $paginationParameters->getFilter('supplier') . '%');
     }
     if ($paginationParameters->getFilter('purchaseInvoiceText') != null) {
         $queryBuilder->andWhere('PurchaseInvoice.supplierDocumentNumber LIKE :purchaseInvoiceText OR Supplier.name LIKE :purchaseInvoiceText')->setParameter('purchaseInvoiceText', '%' . $paginationParameters->getFilter('purchaseInvoiceText') . '%');
     }
     if ($paginationParameters->getFilter('amount') != null) {
         $queryBuilder->andWhere('PurchaseInvoice.amount = :amount')->setParameter('amount', $paginationParameters->getFilter('amount'));
     }
     if ($paginationParameters->getFilter('paymentStatus') != null) {
         $queryBuilder->andWhere('PurchaseInvoice.paymentStatus = :paymentStatus')->setParameter('paymentStatus', $paginationParameters->getFilter('paymentStatus'));
     }
     $paginationParameters->setFilters(array());
     return $this->getPaginatedResult($queryBuilder, $paginationParameters);
 }
 public function jsonGetUserPurchaseInvoicesAction()
 {
     if ($this->request->isGet() && $this->request->isXmlHttpRequest()) {
         $paginationParameters = new PaginationParameters($this->params('page'), $this->params('sort', 'id'), $this->params('order', 'desc'));
         $paginationParameters->setFilters(array('purcheInvoiceText' => $this->request->getQuery()->query, 'confirmed' => true, 'unpaid' => true));
         $auth = $this->getServiceLocator()->get('zfcuser_auth_service');
         $user = $auth->getIdentity();
         $invoiceArray = array();
         $invoices = $this->invoiceService->getPurchaseInvoices($user, $paginationParameters);
         foreach ($invoices as $invoice) {
             $supplierName = $invoice->getSupplier() ? '_' . str_replace(' ', '_', $invoice->getSupplier()->getName()) : '';
             $number = $invoice->getSupplierDocumentNumber();
             $value = $number . $supplierName;
             $invoiceArray[] = array('value' => htmlspecialchars($value), 'id' => $invoice->getId(), 'num' => $number);
         }
         $json = new JsonModel($invoiceArray);
         return $json;
     }
 }
 /**
  * An internal method for getting paginated results from querybuilder
  * @param QueryBuilder $queryBuilder
  * @param PaginationParameters $paginationParameters
  * @param $resultKey Deprecated, use HIDDEN keyword instead
  * @return \Zend\Paginator\Paginator
  */
 public function getPaginatedResult(QueryBuilder $queryBuilder, PaginationParameters $paginationParameters, $resultKey = null)
 {
     if ($paginationParameters->getOrder() != null && $paginationParameters->getSort() != null) {
         if (!is_array($paginationParameters->getSort()) && !is_array($paginationParameters->getOrder())) {
             $sort = array($paginationParameters->getSort());
             $order = array($paginationParameters->getOrder());
         } else {
             if (count($paginationParameters->getSort()) != count($paginationParameters->getOrder())) {
                 throw new \InvalidArgumentException('Sort and order arrays must be the same length');
             }
             $sort = $paginationParameters->getSort();
             $order = $paginationParameters->getOrder();
         }
         foreach ($sort as $key => $oneSortField) {
             if (!strstr($oneSortField, '.')) {
                 $alias = $queryBuilder->getRootAlias() . '.';
             } else {
                 $alias = '';
             }
             $queryBuilder->addOrderBy($alias . $oneSortField, $order[$key]);
         }
     }
     if ($paginationParameters->getFilters() != null) {
         foreach ($paginationParameters->getFilters() as $field => $value) {
             if ($value == '' || $queryBuilder->getParameter($field) != null) {
                 continue;
             }
             if (!strstr($field, '.')) {
                 $entityField = $queryBuilder->getRootAlias() . '.' . $field;
             } else {
                 $entityField = $field;
             }
             if (is_array($value)) {
                 $queryBuilder->andWhere($entityField . ' IN (\'' . implode("', '", $value) . '\')');
             } else {
                 $queryBuilder->andWhere($entityField . ' = :' . str_replace('.', '_', $field))->setParameter(str_replace('.', '_', $field), $value);
             }
         }
     }
     if ($this->usedPaginator == null) {
         $paginatorTool = new \Doctrine\ORM\Tools\Pagination\Paginator($queryBuilder);
     } else {
         $paginatorTool = $this->usedPaginator;
     }
     $paginator = new Paginator(new Adapter\DoctrinePaginator($paginatorTool));
     $paginator->setItemCountPerPage($paginationParameters->getItemCountPerPage());
     $paginator->setCurrentPageNumber($paginationParameters->getCurrentPageNumber());
     if ($paginationParameters->getCache() != null) {
         $paginator->setCache($paginationParameters->getCache());
     }
     if ($resultKey !== null) {
         foreach ($paginator as &$itemElement) {
             $itemElement = $itemElement[$resultKey];
         }
     }
     return $paginator;
 }