public function paymentAction() { $id = $this->getRequest()->getQuery('id'); if (!$id) { return $this->getViewModel()->setVariable('errorMsg', ['Không tìm thấy phiếu thu chi']); } $transaction = new \Accounting\Model\Transaction(); $transaction->setId($id); $transactionMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\TransactionMapper'); if (!$transactionMapper->get($transaction)) { return $this->getViewModel()->setVariable('errorMsg', ['Không tìm thấy phiếu thu chi']); } if (!in_array($transaction->getStatus(), [\Accounting\Model\Transaction::STATUS_ACCOUNTING])) { return $this->getViewModel()->setVariable('errorMsg', ['Phiếu chưa được hạch toán, không thể kí chi thu']); } $form = new \Accounting\Form\Transaction\ApproveReq($this->getServiceLocator()); $form->setData($transaction->toFormValue()); $form->setCompanyId($transaction->getCompanyId()); $form->setId($transaction->getId()); $this->getViewModel()->setVariable('form', $form); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $formData = $form->getData(); $transaction->exchangeArray($formData); $transaction->setPaymentById($this->user()->getIdentity()); $transaction->setPaymentDateTime(DateBase::getCurrentDateTime()); $transaction->setStatus(\Accounting\Model\Transaction::STATUS_PAYMENT); $transactionMapper->save($transaction); if (isset($formData['itemData']) && count($formData['itemData'])) { $transactionItemMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\Transaction\\ItemMapper'); foreach ($formData['itemData'] as $itemData) { $transactionItem = new \Accounting\Model\Transaction\Item(); $transactionItem->exchangeArray($itemData); $transactionItem->setTransactionDate($transaction->getApplyDate()); $transactionItem->setTransactionId($transaction->getId()); $transactionItem->setStatus($transaction->getStatus()); $transactionItemMapper->save($transactionItem); } } return $this->redirect()->toUrl('/accounting/transaction/index?id=' . $transaction->getId()); } } $this->getViewModel()->setVariable('transaction', $transaction); $transactionItem = new \Accounting\Model\Transaction\Item(); $transactionItem->setTransactionId($transaction->getId()); $transactionItem->addOption('loadAccountId', true); $transactionItem->addOption('loadExpenseCategory', true); $transactionItemMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\Transaction\\ItemMapper'); $items = $transactionItemMapper->fetchAll($transactionItem); $this->getViewModel()->setVariable('items', $items); $company = new \Company\Model\Company(); $company->setId($transaction->getCompanyId()); $companyMapper = $this->getServiceLocator()->get('\\Company\\Model\\CompanyMapper'); if ($companyMapper->get($company)) { $this->getViewModel()->setVariable('company', $company); } $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper'); $this->getViewModel()->setVariable('createdBy', $userMapper->get($transaction->getCreatedById())); if ($transaction->getApprovedById()) { $this->getViewModel()->setVariable('approveBy', $userMapper->get($transaction->getApprovedById())); } if ($transaction->getAccountingById()) { $this->getViewModel()->setVariable('accountingBy', $userMapper->get($transaction->getAccountingById())); } $expenseCategory = new \Accounting\Model\ExpenseCategory(); $expenseCategory->setCompanyId($transaction->getCompanyId()); $expenseCategoryMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\ExpenseCategoryMapper'); $tree = new \Home\Model\Tree(); $this->getViewModel()->setVariable('categories', $tree->toArrayRecusived($expenseCategoryMapper->fetchAll($expenseCategory))); $account = new \Accounting\Model\Account(); $account->setCompanyId($transaction->getCompanyId()); $account->addOption('sort', ['sort' => 'c.id', 'dir' => 'ASC']); $accountMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\AccountMapper'); $this->getViewModel()->setVariable('accounts', $tree->toArrayRecusived($accountMapper->fetchAll($account))); return $this->getViewModel(); }
public function companyAction() { $form = new \System\Form\System\Company($this->getServiceLocator()); $form->setData($this->getRequest()->getQuery()); $this->getViewModel()->setVariable('form', $form); $companyId = $this->getRequest()->getQuery('companyId'); if (!$companyId) { $this->getViewModel()->setVariable('errorMsg', 'Bạn phải chọn doanh nghiệp'); return $this->getViewModel(); } if ($form->isValid()) { $formData = $form->getData(); $action = new Action(); $action->setDisplay(Action::DISPLAY_ACTIVE); $action->setStatus(Action::STATUS_ACTIVE); $action->addOption('controllerStatus', Action::STATUS_ACTIVE); $action->addOption('moduleStatus', Action::STATUS_ACTIVE); $actionMapper = $this->getServiceLocator()->get('\\System\\Model\\ActionMapper'); $mcaList = $actionMapper->fetchAdminGridView($action); $this->getViewModel()->setVariable('mcaList', $mcaList); $companyFeature = new \Company\Model\Feature(); $companyFeature->setCompanyId($formData['companyId']); $companyFeatureMapper = $this->getServiceLocator()->get('\\Company\\Model\\FeatureMapper'); $companyFeatures = $companyFeatureMapper->fetchCompanyFeature($companyFeature); $this->getViewModel()->setVariable('features', $companyFeatures); $this->getViewModel()->setVariable('companyId', $formData['companyId']); if ($formData['compareCompanyId']) { $compareFeature = new \Company\Model\Feature(); $compareFeature->setCompanyId($formData['compareCompanyId']); $compareFeatures = $companyFeatureMapper->fetchCompanyFeature($compareFeature); $this->getViewModel()->setVariable('compareFeatures', $compareFeatures); $company = new \Company\Model\Company(); $company->setId($formData['compareCompanyId']); $companyMapper = $this->getServiceLocator()->get('\\Company\\Model\\CompanyMapper'); $companyMapper->get($company); $this->getViewModel()->setVariable('compareTitle', $company->getName()); } } return $this->getViewModel(); }
/** * (non-PHPdoc) * @see \Zend\Form\Form::setData() */ public function setData($data) { if ($this->has('companyId') && isset($data['companyId']) && $data['companyId']) { $companyId = $this->get('companyId'); if ($companyId instanceof \Zend\Form\Element\Hidden && $this->has('companyIdSuggest')) { if (!isset($data['companyIdSuggest']) || !$data['companyIdSuggest']) { $company = new \Company\Model\Company(); $company->setId($data['companyId']); $companyMapper = $this->getServiceLocator()->get('\\Company\\Model\\CompanyMapper'); if ($companyMapper->get($company)) { $data['companyIdSuggest'] = $company->getName(); } } } } return parent::setData($data); }