anne-hasan

Untitled

Mar 21st, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  4. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  5.  
  6. class Aggregated extends CI_Controller
  7. {
  8.  
  9. function __construct()
  10. {
  11. parent::__construct();
  12. $this->load->library('asec_giz_api_library');
  13. }
  14.  
  15. function index()
  16. {
  17. render('apps/aggregated/index', [], 'main-layout');
  18. }
  19.  
  20. function records($type = '')
  21. {
  22. $this->load->model('ProjectTr');
  23. $get = $_GET;
  24. if (isset($get['page'])) {
  25. $get['page'] = (!is_numeric($get['page'])) ? 0 : $get['page'];
  26. }
  27. // $get['alias']['search_type_of_pillars_code'] = 'a.type_of_pillars_code';
  28. if (isGroup("DO")) {
  29. $get['where'] = "struc_org_id_assign = " . id_user('id_struc_org');
  30. }
  31. // $get['debug_query'] = 1;
  32. // debug_api();
  33. $data_result = $this->ProjectTr->fetchAllReport(null, $get);
  34. $data['data'] = ($type == 'excel') ? $data_result : set_nomor_urut($data_result, isset($get['page']) ? $get['page'] : 0);
  35.  
  36. foreach ($data['data'] as $key => $value)
  37. {
  38. $data['data'][$key]['remarks'] = !empty($value['remarks']) ? $value['remarks'] : '-';
  39. $data['data'][$key]['main_pillar'] = !empty($value['main_pillar']) ? $value['main_pillar'] : 'Data empty';
  40. $data['data'][$key]['review_position'] = !empty($value['review_position']) ? $value['review_position'] : '-';
  41. $data['data'][$key]['id'] = isset($value['type_of_pillars_id']) ? $value['type_of_pillars_id'] : '';
  42. $data['data'][$key]['create_date'] = dateDbToUser($value['create_date']);
  43. $data['data'][$key]['modify_date'] = isset($value['modify_date']) ? dateDbToUser($value['modify_date']) : '';
  44. $data['data'][$key]['programme_txt'] = empty($value['is_programme']) ? 'No' : 'Yes';
  45. $data['data'][$key]['total_funding'] = number_format($value['propose_total_funding'],2,".",",");
  46. $data['data'][$key]['email'] = !empty($value['email']) ? $value['email'] : '-';
  47. $data['data'][$key]['proposal_submission_date'] = date('Y-m-d', strtotime($value['proposal_submission_date']));
  48. }
  49.  
  50. $get['is_num_rows'] = 1;
  51. $total_rows = (int)$this->ProjectTr->fetchAllReport(null, $get);
  52. $data['paging'] = ($type == 'excel') ? [] : paging_grid($total_rows, 3);
  53.  
  54. if ($type == 'excel') {
  55. $this->load->helper('excel');
  56. $this->excel = new Spreadsheet();
  57. $excel = $this->excel->setActiveSheetIndex(0);
  58. excelCellValue("A1", 'aggregated as of ' . date('d/m/Y') , array(
  59. 'fontSize' => 20,
  60. 'bold' => 1
  61. ));
  62. excelHeaderTable("A3:S3", 'CCCCCC');
  63. excelCellValue("A3", 'No');
  64. excelCellValue("B3", 'ID');
  65. excelCellValue("C3", 'Temp-Proposal-ID');
  66. excelCellValue("D3", 'Project Title');
  67. excelCellValue("E3", 'Date of Proposal Input');
  68. excelCellValue("F3", 'Funding Source');
  69. excelCellValue("G3", 'Category Funding Source');
  70. excelCellValue("H3", 'Total Funds (USD)');
  71. excelCellValue("I3", 'Proponent');
  72. excelCellValue("J3", 'Proponent Country');
  73. excelCellValue("K3", 'Assign DO Division');
  74. excelCellValue("L3", 'Main Pillar');
  75. excelCellValue("M3", 'Review Position');
  76. excelCellValue("N3", 'Status Action');
  77. excelCellValue("O3", 'Last Update');
  78. excelCellValue("P3", 'Remarks');
  79. excelCellValue("Q3", 'Is Programme');
  80. excelCellValue("R3", 'Created By');
  81. excelCellValue("S3", 'Submission Date');
  82.  
  83. $row = 4;
  84. $n = 0;
  85. foreach ($data['data'] as $key => $value) {
  86. excelCellValue("A$row", ++$n);
  87. excelCellValue("B$row", $value['proposal_id']);
  88. excelCellValue("C$row", $value['proposal_temp_id']);
  89. excelCellValue("D$row", $value['project_tr_title'], array(
  90. 'wrap' => 1
  91. ));
  92. excelCellValue("E$row", $value['create_date']);
  93. excelCellValue("F$row", $value['funding_source'], array(
  94. 'wrap' => 1
  95. ));
  96. excelCellValue("G$row", $value['funding_source_parent']);
  97. excelCellValue("H$row", $value['total_funding']);
  98. excelCellValue("I$row", $value['proponent'], array(
  99. 'wrap' => 1
  100. ));
  101. excelCellValue("J$row", $value['proponent_country'], array(
  102. 'wrap' => 1
  103. ));
  104. excelCellValue("K$row", str_replace('&amp;', '&', $value['do_division']) , array(
  105. 'wrap' => 1
  106. ));
  107. excelCellValue("L$row", $value['main_pillar'], array(
  108. 'wrap' => 1
  109. ));
  110. excelCellValue("M$row", $value['review_position']);
  111. excelCellValue("N$row", $value['review_status']);
  112. excelCellValue("O$row", $value['modify_date']);
  113. excelCellValue("P$row", $value['remarks']);
  114. excelCellValue("Q$row", $value['programme_txt']);
  115. excelCellValue("R$row", $value['email']);
  116. excelCellValue("S$row", $value['proposal_submission_date']);
  117. ++$row;
  118. }
  119. excelBorder("A3:Q$row");
  120. // excelAutoWidth();
  121. excelWidth('A', 10);
  122. excelWidth('B', 40);
  123. excelWidth('C', 15);
  124. excelWidth('D', 70);
  125. excelWidth('E', 17);
  126. excelWidth('F', 30);
  127. excelWidth('G', 30);
  128. excelWidth('H', 12);
  129. excelWidth('I', 60);
  130. excelWidth('J', 35);
  131. excelWidth('K', 35);
  132. excelWidth('L', 35);
  133. excelWidth('O', 17);
  134. excelWidth('Q', 13);
  135. excelExport('aggregated-' . date('Ymd'));
  136. } else {
  137. render('apps/aggregated/records', $data, 'blank');
  138. }
  139. }
  140. }
  141.  
  142. /* End of file Aggregated.php */
  143. /* Location: ./application/controllers/Aggregated.php */
  144.  
  145.  
Advertisement
Add Comment
Please, Sign In to add comment