Example #1
0
 public function editBudgetAllocation($id = 0, $prevSectorID)
 {
     if ($id > 0) {
         $budgetallocation_model = new budgetallocation_model();
         $sector_id = $budgetallocation_model->get_sector();
         $this->validateEditForm();
         if (!$this->form_validation->run()) {
             $form_message = '';
             $this->load->view('header');
             $this->load->view('nav');
             $this->load->view('sidebar');
             //  $this->init_rpmb_session();
             $rpmb['sector_id'] = $sector_id;
             $rpmb['form_message'] = $form_message;
             $rpmb['budgetallocation_details'] = $this->budgetallocation_model->getBudgetAllocationByID($id, $prevSectorID);
             $this->load->view('budgetallocation_edit', $rpmb);
             $this->load->view('sidepanel');
             $this->load->view('footer');
         } else {
             //                $id = $this->input->post('profile_id');
             $sectorID = $this->input->post('sector_id');
             $year_indicated = $this->input->post('year_indicated');
             $budget_previous_year = preg_replace('/[^0-9.]*/', '', $this->input->post('budget_previous_year'));
             $budget_present_year = preg_replace('/[^0-9.]*/', '', $this->input->post('budget_present_year'));
             $utilization = preg_replace('/[^0-9.]*/', '', $this->input->post('utilization'));
             $no_bene_served = $this->input->post('no_bene_served');
             $no_target_bene = $this->input->post('no_target_bene');
             $modified_by = $this->session->userdata('user_id');
             $date_modified = 'NOW()';
             $checkDupli = $budgetallocation_model->checkDuplicate($id, $sectorID);
             if ($sectorID == $prevSectorID) {
                 $updateResult = $budgetallocation_model->updateBudgetAllocation($id, $sectorID, $year_indicated, $budget_previous_year, $budget_present_year, $utilization, $no_bene_served, $no_target_bene, $prevSectorID, $modified_by, $date_modified);
                 if ($updateResult) {
                     //                        $this->init_rpmb_session();
                     $rpmb['sector_id'] = $this->budgetallocation_model->get_sector();
                     $form_message = 'Update Success';
                     $this->load->view('header');
                     $this->load->view('nav');
                     $this->load->view('sidebar');
                     $this->load->view('budgetallocation_list', array('budgetallocation_data' => $budgetallocation_model->getBudgetAllocationByID($id, $prevSectorID), 'form_message' => $form_message));
                     $this->load->view('footer');
                     $this->redirectIndex($id, 2);
                 }
             } else {
                 if ($checkDupli->countProf == 0) {
                     $updateResult = $budgetallocation_model->updateBudgetAllocation($id, $sectorID, $year_indicated, $budget_previous_year, $budget_present_year, $utilization, $no_bene_served, $no_target_bene, $prevSectorID);
                     if ($updateResult) {
                         //                          $this->init_rpmb_session();
                         $rpmb['sector_id'] = $this->budgetallocation_model->get_sector();
                         $form_message = 'Update Success';
                         $this->load->view('header');
                         $this->load->view('nav');
                         $this->load->view('sidebar');
                         $this->load->view('budgetallocation_list', array('budgetallocation_data' => $budgetallocation_model->getBudgetAllocationByID($id), 'form_message' => $form_message));
                         $this->load->view('footer');
                         $this->redirectIndex($id, 2);
                     }
                 } else {
                     $sectorName = $budgetallocation_model->sectorName($sectorID);
                     $form_message = '<div class="kode-alert kode-alert kode-alert-icon kode-alert-click alert6"><i class="fa fa-lock"></i>' . $sectorName->sector_name . ' already exist<a href="#" class="closed">&times;</a></div>';
                     $rpmb['sector_id'] = $sector_id;
                     $rpmb['form_message'] = $form_message;
                     $rpmb['budgetallocation_details'] = $this->budgetallocation_model->getBudgetAllocationByID($id, $prevSectorID);
                     $this->load->view('header');
                     $this->load->view('nav');
                     $this->load->view('sidebar');
                     $this->load->view('budgetallocation_edit', $rpmb);
                     $this->load->view('footer');
                 }
             }
         }
     } else {
         $this->load->view('no_id', array('redirectIndex' => $this->redirectIndex($id)));
     }
 }
Example #2
0
 public function budgetAllocation($sectorID)
 {
     $reports_model = new reports_model();
     $budgetallocation_model = new budgetallocation_model();
     $sectorName = $budgetallocation_model->sectorName($sectorID);
     $sName = $sectorName->sector_name;
     // Create new PHPExcel object
     $objPHPExcel = new PHPExcel();
     $getBudgetAllocation = $reports_model->getBudgetAlloc($sectorID);
     $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Distribution of LSWDO with budget allocation (present year) in ' . $sName . ' sector, by region, Philippines');
     //autosize column
     $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
     $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
     $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
     $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
     $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
     $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
     $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
     $objPHPExcel->getActiveSheet()->getStyle('B1')->getFill()->getStartColor()->setRGB('FF0000');
     //        $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1);a
     $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);
     $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
     $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(20);
     $objPHPExcel->getActiveSheet()->mergeCells('B1:G2');
     //Center text merge columns
     $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     //    $col = 'A';
     //        $row = 5;
     $objPHPExcel->getActiveSheet()->setCellValue('A3', 'Region');
     $objPHPExcel->getActiveSheet()->getStyle('A3')->getFont()->setBold(true);
     $objPHPExcel->getActiveSheet()->setCellValue('B3', $sName . ' Sector');
     $objPHPExcel->getActiveSheet()->mergeCells('A3:A5');
     $objPHPExcel->getActiveSheet()->mergeCells('B3:G3');
     //Center text merge columns
     $objPHPExcel->getActiveSheet()->getStyle('B3')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $objPHPExcel->getActiveSheet()->getStyle('A3')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $objPHPExcel->getActiveSheet()->getStyle('A3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
     $objPHPExcel->getActiveSheet()->mergeCells('B6:e6');
     $objPHPExcel->getActiveSheet()->freezePane('B6');
     //Header
     $objPHPExcel->getActiveSheet()->setCellValue('B4', 'Average PSWDO Allocation');
     $objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $objPHPExcel->getActiveSheet()->setCellValue('C4', 'Average No. of Target Beneficiaries');
     $objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $objPHPExcel->getActiveSheet()->setCellValue('D4', 'Average CSWDO Allocation');
     $objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $objPHPExcel->getActiveSheet()->setCellValue('E4', 'Average No. of Target Beneficiaries');
     $objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $objPHPExcel->getActiveSheet()->setCellValue('F4', 'Average MSWDO Allocation');
     $objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     $objPHPExcel->getActiveSheet()->setCellValue('G4', 'Average No. of Target Beneficiaries');
     $objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
     //Start Editing
     //Part1
     $row2 = 7;
     $col2 = 'A';
     foreach ($getBudgetAllocation as $budgetUtil) {
         $objPHPExcel->getActiveSheet()->setCellValue($col2 . $row2, $budgetUtil->region_name);
         $col2++;
         $objPHPExcel->getActiveSheet()->setCellValue($col2 . $row2, $budgetUtil->BudgetPresentP);
         $col2++;
         $objPHPExcel->getActiveSheet()->setCellValue($col2 . $row2, $budgetUtil->BeneTargetP);
         $col2++;
         $objPHPExcel->getActiveSheet()->setCellValue($col2 . $row2, $budgetUtil->BudgetPresentC);
         $col2++;
         $objPHPExcel->getActiveSheet()->setCellValue($col2 . $row2, $budgetUtil->BeneTargetC);
         $col2++;
         $objPHPExcel->getActiveSheet()->setCellValue($col2 . $row2, $budgetUtil->BudgetPresentM);
         $col2++;
         $objPHPExcel->getActiveSheet()->setCellValue($col2 . $row2, $budgetUtil->BeneTargetM);
         if ($col2 == 'G') {
             $col2 = 'A';
         }
         $row2++;
     }
     $col3 = 'B';
     $row3 = $row2 - 1;
     $objPHPExcel->getActiveSheet()->setCellValue('A' . $row2, 'Total');
     for ($i = 0; $i < 6; $i++) {
         $objPHPExcel->getActiveSheet()->setCellValue($col3 . $row2, '=SUM(' . $col3 . '7:' . $col3 . $row3 . ')');
         $col3++;
     }
     //End Editing
     //    //border
     $objPHPExcel->getActiveSheet()->getStyle('A1:' . $objPHPExcel->getActiveSheet()->getHighestColumn() . $objPHPExcel->getActiveSheet()->getHighestRow())->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
     // Rename worksheet (worksheet, not filename)
     $objPHPExcel->setActiveSheetIndex(0)->setTitle('Budget Allocation)');
     // Add new sheet
     // Add some data
     // Set active sheet index to the first sheet, so Excel opens this as the first asheet
     $objPHPExcel->setActiveSheetIndex(0);
     // Redirect output to a client’s web browser (Excel2007)
     //clean the output buffer
     ob_end_clean();
     //this is the header given from PHPExcel examples. but the output seems somewhat corrupted in some cases.
     //header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     //so, we use this header instead.
     //    $regionName = $this->reports_model->getRegionName($region);
     $filename = 'Non-CompliantIndicator.xlsx';
     header('Content-type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename=' . $filename);
     header('Cache-Control: max-age=0');
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save('php://output');
 }