/** * */ public function detailCoursesAction() { $this->_helper->layout()->disableLayout(); $id = $this->_getParam('id'); $this->view->row = $this->_mapper->detailEducationInstitution($id); $this->view->courses = $this->_mapper->listCourses($id); $this->view->contact = $this->_mapper->listContacts($id); }
/** * */ public function exportAction() { $id = $this->_getParam('id'); $contract = $this->_mapper->detail($id); $data = $contract->toArray(); $data['contract'] = Fefop_Model_Mapper_Contract::buildNumById($contract->fk_id_fefop_contract); $data['date_start'] = $this->view->date($data['date_start'], 'MM/dd/yyyy'); $data['date_finish'] = $this->view->date($data['date_finish'], 'MM/dd/yyyy'); $data['date_inserted'] = $this->view->date($data['date_inserted']); $mapperInstitute = new Register_Model_Mapper_EducationInstitute(); $contacts = $mapperInstitute->listContacts($data['fk_id_fefpeduinstitution'])->toArray(); $expenses = $this->_mapper->listExpenses($id)->toArray(); $itensExpense = $this->_mapper->listItemExpenses($id)->toArray(); $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; } $excelPath = APPLICATION_PATH . '/../library/PHPExcel/'; require_once $excelPath . 'PHPExcel/IOFactory.php'; $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load(APPLICATION_PATH . '/../public/forms/FEFOP/Contrato_RI_tet.xlsx'); $activeSheet = $objPHPExcel->getActiveSheet(); $activeSheet->setCellValue('S10', $data['contract']); $activeSheet->setCellValue('W8', $data['date_inserted']); $activeSheet->setCellValue('F12', $data['institute']); $activeSheet->setCellValue('F14', $data['district']); $activeSheet->setCellValue('F15', $data['sub_district']); if (!empty($contacts)) { $activeSheet->setCellValue('G18', $contacts[0]['contact_name']); $activeSheet->setCellValue('S18', $contacts[0]['cell_fone']); $activeSheet->setCellValue('S19', $contacts[0]['email']); } $startRow = 24; $startSubRow = 35; $count = 'A'; $styleCell = new PHPExcel_Style(); $borders = array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('argb' => '0000000'))); $styleCell->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('argb' => 'FFFFFFFF')), 'borders' => $borders)); $ranges = array(); foreach ($expenses as $expense) { $marker = $count++ . '.'; $expenseName = ucwords(strtolower($expense['description'])); $activeSheet->setCellValue('C' . $startRow, $marker); $activeSheet->setCellValue('D' . $startRow, $expenseName); $activeSheet->setCellValueExplicit('U' . $startRow, $expense['amount'], PHPExcel_Cell_DataType::TYPE_NUMERIC); $activeSheet->mergeCells('U' . $startRow . ':V' . $startRow); $activeSheet->setCellValue('C' . $startSubRow, $marker); $activeSheet->setCellValue('D' . $startSubRow, $expenseName); $subExpenseRow = $startSubRow + 1; $subRowCount = 0; if (!empty($dataItensExpense[$expense['id_budget_category']])) { foreach ($dataItensExpense[$expense['id_budget_category']] as $subExpense) { $activeSheet->setCellValue('D' . $subExpenseRow, $subExpense['description']); $activeSheet->setCellValue('O' . $subExpenseRow, $subExpense['quantity']); $activeSheet->setCellValue('P' . $subExpenseRow, number_format((double) $subExpense['amount_unit'], 2, '.', ',')); $activeSheet->setCellValue('Q' . $subExpenseRow, number_format((double) $subExpense['amount_total'], 2, '.', ',')); $activeSheet->setCellValue('S' . $subExpenseRow, $subExpense['comments']); $activeSheet->mergeCells('Q' . $subExpenseRow . ':R' . $subExpenseRow); $activeSheet->mergeCells('S' . $subExpenseRow . ':V' . $subExpenseRow); $subRowCount++; $subExpenseRow++; $activeSheet->insertNewRowBefore($subExpenseRow + 1, 1); } $ranges[] = 'O' . ($startSubRow + 2) . ':V' . $subExpenseRow; } $activeSheet->insertNewRowBefore($subExpenseRow, 3); $startSubRow = $subExpenseRow + 2; $startRow++; if ($startRow > 28) { $activeSheet->insertNewRowBefore($startRow + 1, 1); } } $activeSheet->removeRow($startSubRow, 4); foreach ($ranges as $range) { $activeSheet->setSharedStyle($styleCell, $range); } $dateStartCell = 'G' . ($startSubRow + 2); $dateFinishCell = 'G' . ($startSubRow + 3); $formulaDate = $activeSheet->getCell('L' . ($startSubRow + 2))->getValue(); $formulaDate = str_replace('98', $dateStartCell, $formulaDate); $formulaDate = str_replace('99', $dateFinishCell, $formulaDate); $activeSheet->setCellValueExplicit('L' . ($startSubRow + 2), $formulaDate, PHPExcel_Cell_DataType::TYPE_FORMULA); $activeSheet->setCellValue($dateStartCell, $data['date_start']); $activeSheet->setCellValue($dateFinishCell, $data['date_finish']); 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; }
/** * */ public function exportAction() { $id = $this->_getParam('id'); $contract = $this->_mapper->detail($id); $data = $contract->toArray(); $data['contract'] = Fefop_Model_Mapper_Contract::buildNumById($contract->fk_id_fefop_contract); $data['date_start'] = $this->view->date($data['date_start']); $data['date_finish'] = $this->view->date($data['date_finish']); $data['date_inserted'] = $this->view->date($data['date_inserted']); $mapperInstitute = new Register_Model_Mapper_EducationInstitute(); $contacts = $mapperInstitute->listContacts($contract->fk_id_fefpeduinstitution)->toArray(); $beneficiaries = $this->_mapper->listBeneficiaries($id)->toArray(); foreach ($beneficiaries as $key => $beneficiary) { $beneficiaries[$key]['complete_nane'] = Client_Model_Mapper_Client::buildName($beneficiary); $beneficiaries[$key]['evidence'] = Client_Model_Mapper_Client::buildNumRow($beneficiary); } $excelPath = APPLICATION_PATH . '/../library/PHPExcel/'; require_once $excelPath . 'PHPExcel/IOFactory.php'; $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load(APPLICATION_PATH . '/../public/forms/FEFOP/Contrato_FP_tet.xlsx'); $activeSheet = $objPHPExcel->getActiveSheet(); $activeSheet->setCellValue('S14', $data['contract']); $activeSheet->setCellValue('W12', $data['date_inserted']); $activeSheet->setCellValue('E17', $data['scholarity']); $activeSheet->setCellValue('O17', $data['level_scholarity']); $activeSheet->setCellValue('S17', $data['class_name']); $activeSheet->setCellValue('E20', $data['district']); $activeSheet->setCellValue('Q20', $data['date_start']); $activeSheet->setCellValue('Q21', $data['date_finish']); #$activeSheet->setCellValue( 'F10', $data['institute'] ); if (!empty($contacts)) { $activeSheet->setCellValue('G24', $contacts[0]['contact_name']); $activeSheet->setCellValue('S24', $contacts[0]['cell_fone']); $activeSheet->setCellValue('S25', $contacts[0]['email']); } $activeSheet->setCellValue('R31', $data['unit_cost']); $activeSheet->setCellValue('J29', count($beneficiaries)); $activeSheet->setCellValue('R29', $data['amount']); $startRow = 34; foreach ($beneficiaries as $beneficiary) { $activeSheet->setCellValue('F' . $startRow, $beneficiary['complete_nane']); $activeSheet->setCellValue('L' . $startRow, $beneficiary['evidence']); $activeSheet->setCellValue('N' . $startRow, $beneficiary['electoral']); $activeSheet->setCellValue('P' . $startRow, $beneficiary['gender']); $activeSheet->setCellValue('Q' . $startRow, empty($beneficiary['id_handicapped']) ? 'Lae' : 'Sin'); $activeSheet->setCellValue('R' . $startRow, $beneficiary['amount']); $startRow++; } 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; }