Пример #1
0
 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();
 }
Пример #2
0
 /**
  * (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);
 }
 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();
 }
Пример #4
0
 private function travelCreateDepartment($items, $companyId, $parentId = null, $privateSource = \Home\Model\Consts::PRIVATE_SOURCE_OFFICEVG)
 {
     $result = array();
     if ($items && count($items)) {
         $companyMapper = $this->getServiceLocator()->get('\\Company\\Model\\CompanyMapper');
         $departmentMapper = $this->getServiceLocator()->get('\\Company\\Model\\DepartmentMapper');
         foreach ($items as $node) {
             $item = $node['obj'];
             if ($item['is_company'] == '1') {
                 //nếu dc đanh dấu là company, sẽ kiểm tra nếu company chưa tồn tại thì tạo mới company.
                 //Sau đó chạy đệ quy với companyId mới
                 $company = new \Company\Model\Company();
                 $company->setOneofficeId($item['ID']);
                 $company->setPrivateSource($privateSource);
                 if (!$companyMapper->isExistedOfficeId($company)) {
                     $company->setName($item['title']);
                     $company->setParentId($companyId);
                     if (!$companyMapper->isExisted($company)) {
                         $company->setCreatedById(1);
                         $company->setCreatedDateTime(DateBase::getCurrentDateTime());
                         $company->setHeadquartersCityId(2);
                         $company->setHeadquartersDistrictId(6);
                         $company->setHeadquartersAddress('51 Lê Đại Hành');
                     } else {
                         $company->setParentId($companyId);
                     }
                 } else {
                     $company->setParentId($companyId);
                 }
                 $companyMapper->save($company);
                 if (isset($node['childs']) && count($node['childs'])) {
                     $this->travelCreateDepartment($node['childs'], $company->getId(), null, $privateSource);
                 }
             } else {
                 $department = new \Company\Model\Department();
                 $department->setOneofficeId($item['ID']);
                 $department->setPrivateSource($privateSource);
                 if (!$departmentMapper->isExistedOfficeId($department)) {
                     $department->setName($item['title']);
                     $department->setParentId($parentId);
                     $department->setCompanyId($companyId);
                     if (!$departmentMapper->isExisted($department)) {
                         $department->setStatus(\Company\Model\Department::STATUS_ACTIVE);
                         $department->setCreatedById(1);
                         $department->setCreatedDateTime(DateBase::getCurrentDateTime());
                     }
                 } else {
                     $department->setParentId($parentId);
                     $department->setCompanyId($companyId);
                 }
                 $departmentMapper->save($department);
                 if (isset($node['childs']) && count($node['childs'])) {
                     $this->travelCreateDepartment($node['childs'], $companyId, $department->getId(), $privateSource);
                 }
             }
         }
     }
 }