Ejemplo n.º 1
0
 /**
  * 
  */
 public function informationAction()
 {
     // Form Information
     $formInformation = $this->_getForm($this->_helper->url('save'));
     $id = $this->_getParam('id');
     if (!empty($id)) {
         $row = $this->_mapper->detail($id);
         $data = $row->toArray();
         $data['date_start'] = $this->view->date($data['date_start']);
         $data['date_finish'] = $this->view->date($data['date_finish']);
         $mapperIsicTimor = new Register_Model_Mapper_IsicTimor();
         $classTimor = $mapperIsicTimor->listClassByDisivion($data['fk_id_isicdivision']);
         $classes = array();
         if (!empty($classTimor[$data['fk_id_isicdivision']]['classes'])) {
             $classes = $classTimor[$data['fk_id_isicdivision']]['classes'];
         }
         $opt = array('' => '');
         foreach ($classes as $class) {
             $opt[$class->id_isicclasstimor] = $class->name_classtimor;
         }
         $formInformation->getElement('fk_id_isicclasstimor')->addMultiOptions($opt);
         $formInformation->populate($data);
         $formInformation->getElement('fk_id_adddistrict')->setAttrib('readonly', true);
         $formInformation->getElement('fk_id_fefop_modules')->setAttrib('readonly', true);
         // List the expenses related to the contract
         $this->view->expenses = $this->_mapper->listExpenses($id);
         // 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;
         if (!$this->view->fefopContract($data['id_fefop_contract'])->isEditable()) {
             $formInformation->removeDisplayGroup('toolbar');
         }
     } else {
         $module = $this->_getParam('module');
         if (!empty($module)) {
             $formInformation->getElement('fk_id_fefop_modules')->setValue($module);
             $constant = Fefop_Model_Mapper_Expense::CONFIG_PCE_CEC_FASE_I;
             if (Fefop_Model_Mapper_Module::CED == $module) {
                 $constant = Fefop_Model_Mapper_Expense::CONFIG_PCE_CED_FASE_I;
             }
             // Fetch the Expenses related to the module
             $mapperBudgetCategory = new Fefop_Model_Mapper_Expense();
             $this->view->expenses = $mapperBudgetCategory->expensesInItem($constant);
         } else {
             foreach ($formInformation->getElements() as $element) {
                 $element->setAttrib('disabled', true);
             }
             $formInformation->getElement('fk_id_fefop_modules')->setAttrib('disabled', null);
         }
     }
     $this->view->form = $formInformation;
 }
Ejemplo n.º 2
0
 /**
  * 
  * @param array $expenses
  * @param int $id
  * @param int|bool $type
  * @return array
  */
 public function aggregateExpenses(&$expenses, $businessPlan, $type)
 {
     $expensesAmounts = array();
     $clients = $this->listClientBusinessPlan($businessPlan->fk_id_fefop_modules);
     if ($clients->count() > 0) {
         foreach ($clients as $client) {
             if (empty($client->business_plan)) {
                 continue;
             }
             $expensesSubBusinessPlan = $this->listExpenses($client->business_plan, $type);
             foreach ($expensesSubBusinessPlan as $expense) {
                 if (empty($expensesAmounts[$expense['id_budget_category']])) {
                     $expensesAmounts[$expense['id_budget_category']] = 0;
                 }
                 $expensesAmounts[$expense['id_budget_category']] += $expense['amount'];
             }
         }
     }
     if (!empty($businessPlan->fk_id_pce_contract)) {
         $mapperPceContract = new Fefop_Model_Mapper_PCEContract();
         $itemPceContract = $mapperPceContract->listExpenses($businessPlan->fk_id_pce_contract);
         foreach ($itemPceContract as $item) {
             if (empty($expensesAmounts[$item['id_budget_category']])) {
                 $expensesAmounts[$item['id_budget_category']] = 0;
             }
             $expensesAmounts[$item['id_budget_category']] += $item['amount'];
         }
     }
     foreach ($expenses as $expenseBusinessPlan) {
         if (!empty($expensesAmounts[$expenseBusinessPlan['id_budget_category']])) {
             $expenseBusinessPlan['amount'] += $expensesAmounts[$expenseBusinessPlan['id_budget_category']];
         }
     }
     return $expenses;
 }