/** * Lập phiếu xin chi */ public function addreqpaymentAction() { $form = new \Accounting\Form\Transaction\ReqRecieve($this->getServiceLocator()); $this->getViewModel()->setVariable('form', $form); $companyId = $this->getRequest()->getPost('companyId'); if (!$this->user()->getUser()->isAdmin()) { $companyId = $this->user()->getCompanyId(); } $expenseCategory = new \Accounting\Model\ExpenseCategory(); $expenseCategory->setCompanyId($companyId); $expenseCategoryMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\ExpenseCategoryMapper'); $tree = new \Home\Model\Tree(); $categoryValueOptions = $tree->toSelectBoxArray($expenseCategoryMapper->fetchAll($expenseCategory)); $this->getViewModel()->setVariable('categoryValueOptions', $categoryValueOptions); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $formData = $form->getData(); $transaction = new \Accounting\Model\Transaction(); $transaction->exchangeArray($formData); $transaction->setType(\Accounting\Model\Transaction::TYPE_PAYMENT); $transaction->setCreatedDate(DateBase::getCurrentDate()); $transaction->setCreatedDateTime(DateBase::getCurrentDateTime()); $transaction->setCreatedById($this->user()->getIdentity()); $transaction->setStatus(\Accounting\Model\Transaction::STATUS_NEW); $transactionMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\TransactionMapper'); $transactionMapper->save($transaction); $itemMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\Transaction\\ItemMapper'); if (isset($formData['itemData']) && count($formData['itemData'])) { foreach ($formData['itemData'] as $itemData) { $item = new \Accounting\Model\Transaction\Item(); $item->exchangeArray($itemData); $item->setTransactionId($transaction->getId()); $item->setStatus($transaction->getStatus()); $item->setTransactionDate($transaction->getApplyDate()); $itemMapper->save($item); } } if ($form->get('afterSubmit')->getValue()) { return $this->redirect()->toUrl($form->get('afterSubmit')->getValue()); } return $this->redirect()->toUrl('/accounting/transaction/index'); } } return $this->getViewModel(); }