Пример #1
0
 public function listTotals()
 {
     $dbFundPlanning = App_Model_DbTable_Factory::get('FundPlanning');
     $dbFEFOPFund = App_Model_DbTable_Factory::get('FEFOPFund');
     $select = $dbFEFOPFund->select()->from(array('f' => $dbFEFOPFund))->setIntegrityCheck(false)->join(array('p' => $dbFundPlanning), 'p.fk_id_fefopfund = f.id_fefopfund', array('year_planning', 'amount', 'additional_cost'))->order(array('year_planning', 'name_fund'));
     $rows = $dbFEFOPFund->fetchAll($select);
     $mapperReport = new Report_Model_Mapper_Fefop();
     $currentBalanceReport = $mapperReport->donorContractCostReport();
     $currentBalance = array();
     foreach ($currentBalanceReport['item']['donor'] as $current) {
         foreach ($current as $fund => $values) {
             $currentBalance[$fund] = $values['balance'];
         }
     }
     $totals = array();
     $years = array();
     $balance = array();
     $additional = array();
     $totalBalance = 0;
     foreach ($rows as $row) {
         if (empty($years[$row['year_planning']])) {
             $years[$row['year_planning']] = 0;
         }
         if (empty($totals[$row['name_fund']])) {
             $totals[$row['name_fund']] = array();
         }
         $totals[$row['name_fund']][$row['year_planning']] = $row->amount;
         $additional[$row['name_fund']][$row['year_planning']] = $row->additional_cost;
         $balance[$row['name_fund']] = empty($currentBalance[$row['id_fefopfund']]) ? 0 : $currentBalance[$row['id_fefopfund']];
         $years[$row['year_planning']] += (double) $row->amount;
         $totalBalance += $balance[$row['name_fund']];
     }
     return array('years' => $years, 'totals' => $totals, 'balance' => $balance, 'total_balance' => $totalBalance);
 }
Пример #2
0
 /**
  * 
  */
 public function fundContractAction()
 {
     $this->_helper->layout()->disableLayout();
     $id = $this->_getParam('id');
     $formFundContract = new Fefop_Form_ContractFund();
     $formFundContract->setAction($this->_helper->url('save-fund-contract'));
     $formFundContract->getElement('fk_id_fefop_contract')->setValue($id);
     // List all Funds
     $mapperFunds = new Fefop_Model_Mapper_Fund();
     $funds = $mapperFunds->fetchAll(array(), array('type'));
     // Fetch the totals by fund
     $reportFefop = new Report_Model_Mapper_Fefop();
     $filterReport = array('year' => date('Y'));
     $fundsTotals = $reportFefop->donorContractCostReport();
     $donorsTotals = $fundsTotals['item']['donor'];
     $donorTotalsViews = array();
     foreach ($donorsTotals as $typeDonor) {
         foreach ($typeDonor as $idDonor => $donor) {
             $donorTotalsViews[$idDonor] = $donor['balance'];
         }
     }
     $this->view->donor_totals = $donorTotalsViews;
     // List the funds already registered to the contract
     $fundsContract = $this->_mapper->listFundsContract($id);
     // List all the components related to the contract
     $mapperContract = new Fefop_Model_Mapper_Contract();
     $components = $mapperContract->listComponentsContract($id);
     // Reimbursement by Component
     $reimbursement = $this->_mapper->listExpenseTypeTotalsByContract($id, Fefop_Model_Mapper_Financial::TYPE_REIMBURSEMENT);
     $dataReimbursement = array();
     foreach ($reimbursement as $row) {
         $dataReimbursement[$row->fk_id_budget_category_type] = $row->total;
     }
     $this->view->reimbursement = $dataReimbursement;
     $this->view->components = $components;
     $this->view->funds = $funds;
     $this->view->funds_contract = $fundsContract;
     $this->view->form = $formFundContract;
 }