Beispiel #1
0
 /**
  * 
  */
 public function businessPlanAction()
 {
     $id = $this->_getParam('id');
     if (empty($id)) {
         $this->_helper->redirector->goToSimple('index', 'index', 'external');
     }
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->_helper->layout()->disableLayout();
     }
     $formBusinessPlan = new External_Form_BusinessPlan();
     $formBusinessPlan->setAction($this->_helper->url('save-business-plan'));
     $businessPlan = $this->_mapper->fetchBusinessPlan($id);
     // Prepare Subdistrict SELECT Option
     $mapperSubDistrict = new Register_Model_Mapper_AddSubDistrict();
     $rowsSubdistrict = $mapperSubDistrict->listAll($businessPlan->fk_id_adddistrict);
     $rows = array('' => '');
     foreach ($rowsSubdistrict as $subDistrict) {
         $rows[$subDistrict->id_addsubdistrict] = $subDistrict->sub_district;
     }
     $formBusinessPlan->getElement('fk_id_addsubdistrict')->addMultiOptions($rows);
     // Prepare Business Plan Owner Select
     $rowOwner = array($businessPlan->fk_id_perdata => Client_Model_Mapper_Client::buildNameById($businessPlan->fk_id_perdata));
     $clientsBusinessPlan = $this->_mapper->listClientBusinessPlan($id);
     foreach ($clientsBusinessPlan as $client) {
         $rowOwner[$client->id_perdata] = Client_Model_Mapper_Client::buildName($client);
     }
     $formBusinessPlan->getElement('bussines_plan_developer')->addMultiOptions($rowOwner);
     $data = $businessPlan->toArray();
     $formBusinessPlan->populate($data);
     $this->view->formBusiness = $formBusinessPlan;
     $this->view->businessPlan = $businessPlan;
     $mapperBudgetCategory = new Fefop_Model_Mapper_Expense();
     $expenses = $mapperBudgetCategory->expensesInModule($businessPlan->fk_id_fefop_modules);
     $initial_expense = $mapperBudgetCategory->expensesInItem(Fefop_Model_Mapper_Expense::CONFIG_PCE_INITIAL);
     $annual_expense = $mapperBudgetCategory->expensesInItem(Fefop_Model_Mapper_Expense::CONFIG_PCE_ANNUAL);
     $revenue_expense = $mapperBudgetCategory->expensesInItem(Fefop_Model_Mapper_Expense::CONFIG_PCE_REVENUE);
     $this->view->expenses = $this->_mapper->aggregateExpenses($expenses, $businessPlan, $mapperBudgetCategory->getModuleToItem($businessPlan->fk_id_fefop_modules));
     $this->view->initial_expense = $this->_mapper->aggregateExpenses($initial_expense, $businessPlan, Fefop_Model_Mapper_Expense::CONFIG_PCE_INITIAL);
     $this->view->annual_expense = $this->_mapper->aggregateExpenses($annual_expense, $businessPlan, Fefop_Model_Mapper_Expense::CONFIG_PCE_ANNUAL);
     $this->view->revenue_expense = $this->_mapper->aggregateExpenses($revenue_expense, $businessPlan, Fefop_Model_Mapper_Expense::CONFIG_PCE_REVENUE);
     // Populate form
     $this->_populateFormBusinessPlan($formBusinessPlan, $businessPlan);
     if (!empty($data['submitted']) || !empty($businessPlan->business_group)) {
         foreach ($formBusinessPlan->getElements() as $element) {
             $element->setAttrib('disabled', true);
         }
         $this->view->no_edit = true;
     }
     $can_create = $this->_mapper->canCreateBusinessPlan($data['fk_id_perdata'], $data['fk_id_fefop_modules']);
     if (!$can_create) {
         foreach ($formBusinessPlan->getElements() as $element) {
             $element->setAttrib('disabled', true);
         }
     }
     $this->view->can_create = $can_create;
 }
 /**
  * 
  */
 public function exportAction()
 {
     $id = $this->_getParam('id');
     $row = $this->_mapper->fetchBusinessPlan($id);
     $contractFiles = array('CEG' => 'Contrato_CEG_tet.xlsx', 'CEC' => 'Contrato_CEC_II_tet.xlsx', 'CED' => 'Contrato_CED_II_tet.xlsx');
     // Fetch Contract
     $mapperContract = new Fefop_Model_Mapper_Contract();
     $contract = $mapperContract->detail($row->fk_id_fefop_contract);
     $data = $row->toArray();
     $data += $contract->toArray();
     $reserve_fund = $this->_mapper->getTotal($id, 'reserve_fund');
     $reserve_fund = $reserve_fund < 1 ? 600 : $reserve_fund;
     $data['contract'] = Fefop_Model_Mapper_Contract::buildNumById($row->fk_id_fefop_contract);
     $data['business_plan'] = External_Model_Mapper_Pce::buildNumRow($row);
     $data['date_inserted'] = $this->view->date($data['date_inserted']);
     $dateInsert = new Zend_Date($data['date_inserted']);
     $data['date_finish'] = $dateInsert->addYear(2)->toString('dd/MM/yyyy');
     $mapperClient = new Client_Model_Mapper_Client();
     $client = $mapperClient->detailClient($row->fk_id_perdata);
     $data['evidence_card'] = Client_Model_Mapper_Client::buildNumRow($client);
     $data['client_name'] = Client_Model_Mapper_Client::buildName($client);
     $data['is_handicapped'] = Client_Model_Mapper_Client::isHandicapped($row->fk_id_perdata);
     $data['electoral'] = $client->electoral;
     $data['gender'] = $client->gender;
     $data['client_fone'] = $client->client_fone;
     $group = array();
     $rowsGroup = $this->_mapper->listClientBusinessPlan($id);
     foreach ($rowsGroup as $rowGroup) {
         $group[] = array('name' => Client_Model_Mapper_Client::buildName($rowGroup), 'evidence_card' => Client_Model_Mapper_Client::buildNumRow($rowGroup), 'electoral' => $client->electoral, 'gender' => $client->gender, 'is_handicapped' => Client_Model_Mapper_Client::isHandicapped($client->id_perdata));
     }
     $expensesRows = $mapperContract->listExpensesContract($row->fk_id_fefop_contract);
     $expenses = array();
     $total = 0;
     foreach ($expensesRows as $expense) {
         $expenses[] = array('name' => $expense->description, 'amount' => (double) $expense->amount);
         $total += (double) $expense->amount;
     }
     $excelPath = APPLICATION_PATH . '/../library/PHPExcel/';
     require_once $excelPath . 'PHPExcel/IOFactory.php';
     $objReader = PHPExcel_IOFactory::createReader('Excel2007');
     $objPHPExcel = $objReader->load(APPLICATION_PATH . '/../public/forms/FEFOP/' . $contractFiles[$data['num_module']]);
     $activeSheet = $objPHPExcel->getActiveSheet();
     $activeSheet->setCellValue('P12', $data['contract']);
     $activeSheet->setCellValue('Q40', $data['business_plan']);
     $activeSheet->setCellValue('T8', $data['date_inserted']);
     $activeSheet->setCellValue('F45', $data['date_inserted']);
     $activeSheet->setCellValue('F46', $data['date_finish']);
     $activeSheet->setCellValue('F16', $data['evidence_card']);
     $activeSheet->setCellValue('F17', $data['electoral']);
     $activeSheet->setCellValue('E19', $data['client_name']);
     $activeSheet->setCellValue('D117', $data['client_name']);
     $activeSheet->setCellValue('Q19', $data['client_fone']);
     $activeSheet->setCellValue('O20', $data['email']);
     $activeSheet->setCellValue('H25', $data['total_partisipants']);
     // Responsible
     $activeSheet->setCellValue('E28', $data['client_name']);
     $activeSheet->setCellValue('M28', $data['evidence_card']);
     $activeSheet->setCellValue('O28', $data['electoral']);
     $activeSheet->setCellValue('Q28', $data['gender']);
     $activeSheet->setCellValue('R28', $data['is_handicapped'] ? 'Sin' : 'Lae');
     $startPerson = 29;
     foreach ($group as $person) {
         $activeSheet->setCellValue('E' . $startPerson, $person['name']);
         $activeSheet->setCellValue('M' . $startPerson, $person['evidence_card']);
         $activeSheet->setCellValue('O' . $startPerson, $person['electoral']);
         $activeSheet->setCellValue('Q' . $startPerson, $person['gender']);
         $activeSheet->setCellValue('R' . $startPerson, $person['is_handicapped'] ? 'Sin' : 'Lae');
         $startPerson++;
     }
     $activeSheet->setCellValue('F38', $data['name_disivion']);
     $activeSheet->setCellValue('L38', $data['name_classtimor']);
     $activeSheet->setCellValue('F40', $data['project_name']);
     $activeSheet->setCellValue('P45', $data['district']);
     $activeSheet->setCellValue('P46', $data['sub_district']);
     $activeSheet->setCellValue('P47', $data['sucu']);
     $startExpense = 52;
     $count = 'A';
     foreach ($expenses as $expense) {
         $activeSheet->setCellValue('B' . $startExpense, $count++);
         $activeSheet->setCellValue('C' . $startExpense, $expense['name']);
         $activeSheet->setCellValue('S' . $startExpense, $expense['amount']);
         $startExpense++;
     }
     $activeSheet->setCellValue('B' . $startExpense, $count++);
     $activeSheet->setCellValue('C' . $startExpense, 'Fundu Maneiu (600 USD + 10% rubrika sira iha leten)');
     $activeSheet->setCellValue('S' . $startExpense, $reserve_fund);
     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     $file = sprintf('Contract_%s.xlsx', $data['contract']);
     header(sprintf('Content-Disposition: attachment;filename="%s"', $file));
     header('Cache-Control: max-age=0');
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save('php://output');
     exit;
 }