Exemple #1
0
 /**
  * 
  * @return int|bool
  */
 public function save()
 {
     $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
     $dbAdapter->beginTransaction();
     try {
         $dateStart = new Zend_Date($this->_data['date_start']);
         $dateFinish = new Zend_Date($this->_data['date_finish']);
         $mapperExpense = new Fefop_Model_Mapper_Expense();
         $item = $mapperExpense->getModuleToItem($this->_data['fk_id_fefop_modules']);
         $mapperRule = new Fefop_Model_Mapper_Rule();
         $mapperRule->validate($this->_message, $this->_data, $item);
         // Check if the initial date is later than finish date
         if ($dateStart->isLater($dateFinish)) {
             $this->_message->addMessage('Data loron keta liu data remata.');
             $this->addFieldError('date_start')->addFieldError('date_finish');
             return false;
         }
         // If there is no contract yet
         if (empty($this->_data['fk_id_fefop_contract'])) {
             $dataContract = array('module' => $this->_data['fk_id_fefop_modules'], 'district' => $this->_data['fk_id_adddistrict']);
             $mapperFefopContract = new Fefop_Model_Mapper_Contract();
             $this->_data['fk_id_fefop_contract'] = $mapperFefopContract->save($dataContract);
         }
         $this->_data['amount'] = App_General_String::toFloat($this->_data['amount']);
         $this->_data['date_start'] = $dateStart->toString('yyyy-MM-dd');
         $this->_data['date_finish'] = $dateFinish->toString('yyyy-MM-dd');
         $dataForm = $this->_data;
         // Save the contract
         $dataForm['id_per_contract'] = parent::_simpleSave();
         $dataForm['fk_id_per_contract'] = $dataForm['id_per_contract'];
         // Save budget category
         $this->_saveExpenses($dataForm);
         if (empty($this->_data['id_per_contract'])) {
             $history = 'REJISTU KONTRAKTU PER: %s';
         } else {
             $history = 'ATUALIZA KONTRAKTU PER: %s';
         }
         $history = sprintf($history, $dataForm['id_per_contract']);
         $this->_sysAudit($history);
         $dbAdapter->commit();
         return $dataForm['id_per_contract'];
     } catch (Exception $e) {
         $dbAdapter->rollBack();
         $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR);
         return false;
     }
 }
 /**
  * 
  */
 public function informationAction()
 {
     $id = $this->_getParam('id');
     $row = $this->_mapper->fetchBusinessPlan($id);
     $mapperClient = new Client_Model_Mapper_Client();
     $client = $mapperClient->detailClient($row->fk_id_perdata);
     $clientsBusinessPlan = $this->_mapper->listClientBusinessPlan($id);
     $this->view->clientsBusinessPlan = $clientsBusinessPlan;
     // Fetch description fields
     $fieldsBusinessPlan = $this->_mapper->groupFieldsBusinessPlan($id);
     // Fetch totals
     $totalsFields = $this->_mapper->groupTotals($id);
     $mapperBudgetCategory = new Fefop_Model_Mapper_Expense();
     $itemConfig = $mapperBudgetCategory->getModuleToItem($row->fk_id_fefop_modules);
     $this->view->expenses = $this->_mapper->listExpenses($id, $itemConfig);
     $this->view->initial_expense = $this->_mapper->listExpenses($id, Fefop_Model_Mapper_Expense::CONFIG_PCE_INITIAL);
     $this->view->annual_expense = $this->_mapper->listExpenses($id, Fefop_Model_Mapper_Expense::CONFIG_PCE_ANNUAL);
     $this->view->revenue_expense = $this->_mapper->listExpenses($id, Fefop_Model_Mapper_Expense::CONFIG_PCE_REVENUE);
     // List the items expense detailed
     $itensExpense = $this->_mapper->listItemExpenses($id);
     $dataItensExpense = array();
     foreach ($itensExpense as $item) {
         if (!array_key_exists($item->fk_id_budget_category, $dataItensExpense)) {
             $dataItensExpense[$item->fk_id_budget_category] = array();
         }
         $dataItensExpense[$item->fk_id_budget_category][] = $item;
     }
     $this->view->itemsExpense = $dataItensExpense;
     $this->view->id = $id;
     $this->view->contract = $row;
     $this->view->totals_fields = $totalsFields;
     $this->view->values_description_fields = $fieldsBusinessPlan;
     $this->view->description_fields = $this->_mapper->getDescriptionFields();
     $this->view->client = $client;
     $this->view->no_edit = true;
 }
Exemple #3
0
 /**
  * 
  * @param int $module
  * @return float
  */
 public function getTotalModule($module)
 {
     $mapperBudgetCategory = new Fefop_Model_Mapper_Expense();
     $identifier = $mapperBudgetCategory->getModuleToItem($module);
     $mapperRule = new Fefop_Model_Mapper_Rule();
     $ruleAmount = $mapperRule->getRuleIdentifier($identifier, Fefop_Model_Mapper_Rule::AMOUNT_MAX);
     if (empty($ruleAmount)) {
         return (double) $this->_limitAmounts[$module];
     } else {
         return (double) $ruleAmount->value;
     }
 }
Exemple #4
0
 /**
  * 
  * @param Zend_Form $form
  * @param Zend_Db_Table_Row $businessPlan
  */
 protected function _populateFormBusinessPlan($form, $businessPlan)
 {
     $dataForm = array();
     // Fetch description fields
     $fieldsBusinessPlan = $this->_mapper->groupFieldsBusinessPlan($businessPlan->id_businessplan);
     // Fetch totals
     $totalsFields = $this->_mapper->groupTotals($businessPlan->id_businessplan);
     if (!empty($businessPlan->fk_id_addsucu)) {
         $mapperSuku = new Register_Model_Mapper_AddSuku();
         $suku = $mapperSuku->fetchRow($businessPlan->fk_id_addsucu);
         $dataForm['fk_id_addsubdistrict'] = $suku->fk_id_addsubdistrict;
         $sukuRows = $mapperSuku->listAll($suku->fk_id_addsubdistrict);
         $rows = array('' => '');
         foreach ($sukuRows as $suku) {
             $rows[$suku->id_addsucu] = $suku->sucu;
         }
         $form->getElement('fk_id_addsucu')->addMultiOptions($rows);
     }
     // List the items expense detailed
     $itensExpense = $this->_mapper->listItemExpenses($businessPlan->id_businessplan);
     $dataItensExpense = array();
     foreach ($itensExpense as $item) {
         if (!array_key_exists($item->fk_id_budget_category, $dataItensExpense)) {
             $dataItensExpense[$item->fk_id_budget_category] = array();
         }
         $dataItensExpense[$item->fk_id_budget_category][] = $item;
     }
     // Check if the business plan has Budget Category defined
     if ($this->_mapper->hasBudgetCategory($businessPlan->id_businessplan)) {
         $idBusinessPlan = $businessPlan->id_businessplan;
         $mapperBudgetCategory = new Fefop_Model_Mapper_Expense();
         $itemConfig = $mapperBudgetCategory->getModuleToItem($businessPlan->fk_id_fefop_modules);
         $this->view->expenses = $this->_mapper->listExpenses($idBusinessPlan, $itemConfig);
         $this->view->initial_expense = $this->_mapper->listExpenses($idBusinessPlan, Fefop_Model_Mapper_Expense::CONFIG_PCE_INITIAL);
         $this->view->annual_expense = $this->_mapper->listExpenses($idBusinessPlan, Fefop_Model_Mapper_Expense::CONFIG_PCE_ANNUAL);
         $this->view->revenue_expense = $this->_mapper->listExpenses($idBusinessPlan, Fefop_Model_Mapper_Expense::CONFIG_PCE_REVENUE);
     } else {
         $dataItensExpense = $this->_mapper->aggregateItemsExpense($dataItensExpense, $businessPlan);
     }
     $this->view->itemsExpense = $dataItensExpense;
     $dataForm += $fieldsBusinessPlan;
     $dataForm += $totalsFields;
     $form->populate($dataForm);
 }