Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.05 KB | None | 0 0
  1. <?php
  2. session_start();
  3. error_reporting(E_ALL);
  4. include("excel/PHPExcel.php");
  5. include("config.php");
  6.  
  7. //if ($_SESSION['username'] && $_SESSION['status'] && $_SESSION['ip'] && $_SESSION['agent'] && $_SESSION['idx'] && $_SESSION['pyrCode']) {
  8.  
  9. //include("session_regenerate.php");
  10.  
  11. $username = mysql_escape_string($_SESSION['username']);
  12. $status = mysql_escape_string($_SESSION['status']);
  13. //$approve = mysql_escape_string($_GET['approve']);
  14. //$reject = mysql_escape_string($_GET['reject']);
  15. $ip = mysql_escape_string($_SESSION['ip']);
  16. $idx = mysql_escape_string($_SESSION['idx']);
  17. $agent = mysql_escape_string($_SESSION['agent']);
  18. //$pyrCode = mysql_escape_string($_SESSION[pyrCode]);
  19. //$data_idx = mysql_escape_string($_GET['data_idx']);
  20. $data_idx = mysql_escape_string($_POST['data_idx']);
  21. $effective_date = mysql_escape_string($_POST['effective_date']);
  22. //$con_date1 = mysql_escape_string($_GET['con_date1']);
  23.  
  24.  
  25. $objPHPExcel = new PHPExcel();
  26. /******************************************************* Start Header ***********************************************************************/
  27. $DebitedAccountNo = preg_replace('/(?<=^|;)"(.+)"(?=;)/','$1',"Debited Account No");
  28. $objPHPExcel->setActiveSheetIndex(0)
  29. ->setCellValue('A1', $DebitedAccountNo)
  30. ->setCellValue('A2', 'Total Detail Records')
  31. ->setCellValue('A3', 'Total Amount')
  32. ->setCellValue('A4', 'File Creation Time')
  33. ->setCellValue('A5', 'Transaction Instruction Date');
  34.  
  35. $sqlRekDebt = "
  36. SELECT
  37. (
  38. SELECT
  39. value_param
  40. FROM
  41. tm_parameter_csv_mega
  42. WHERE
  43. id_param = '1'
  44. AND istatus = '1'
  45. )AS DAN,
  46. (
  47. SELECT
  48. value_param
  49. FROM
  50. tm_parameter_csv_mega
  51. WHERE
  52. id_param = '2'
  53. AND istatus = '1'
  54. )AS BN,
  55. (
  56. SELECT
  57. value_param
  58. FROM
  59. tm_parameter_csv_mega
  60. WHERE
  61. id_param = '3'
  62. AND istatus = '1'
  63. )AS CB,
  64. (
  65. SELECT
  66. value_param
  67. FROM
  68. tm_parameter_csv_mega
  69. WHERE
  70. id_param = '4'
  71. AND istatus = '1'
  72. )AS SC,
  73. (
  74. SELECT
  75. value_param
  76. FROM
  77. tm_parameter_csv_mega
  78. WHERE
  79. id_param = '5'
  80. AND istatus = '1'
  81. )AS NE,
  82. (
  83. SELECT
  84. value_param
  85. FROM
  86. tm_parameter_csv_mega
  87. WHERE
  88. id_param = '6'
  89. AND istatus = '1'
  90. )AS EA,
  91. (
  92. SELECT
  93. value_param
  94. FROM
  95. tm_parameter_csv_mega
  96. WHERE
  97. id_param = '7'
  98. AND istatus = '1'
  99. )AS BCS,
  100. (
  101. SELECT
  102. value_param
  103. FROM
  104. tm_parameter_csv_mega
  105. WHERE
  106. id_param = '8'
  107. AND istatus = '1'
  108. )AS BCCC,
  109. (
  110. SELECT
  111. value_param
  112. FROM
  113. tm_parameter_csv_mega
  114. WHERE
  115. id_param = '9'
  116. AND istatus = '1'
  117. )AS BT
  118. FROM
  119. tm_parameter_csv_mega
  120. LIMIT 1;
  121. ";
  122. $executeSqlRekDebt = mysql_query($sqlRekDebt) or die (mysql_error());
  123. while($list = mysql_fetch_array($executeSqlRekDebt)) {
  124. $DAN=$list[0];
  125. $BN=$list[1];
  126. $CB=$list[2];
  127. $SC=$list[3];
  128. $NE=$list[4];
  129. $EA=$list[5];
  130. $BCS=$list[6];
  131. $BCCC=$list[7];
  132. $BT=$list[8];
  133. }
  134.  
  135. $sqlHeader = "SELECT count(*) as jumlah, SUM(_amount) as total FROM tmp_file WHERE idx='$data_idx' and _code ='426' ORDER BY id ASC";
  136. $executeSqlHeader = mysql_query($sqlHeader) or die (mysql_error());
  137.  
  138. while($row = mysql_fetch_array($executeSqlHeader)) {
  139.  
  140. //$jumlah = $row[0];
  141. $jumlah = '1';
  142. //$total = $row[1];
  143. $total = '1000';
  144. }
  145. //$debittedAccount ="010740011003920";
  146. $timeCreatedOn = date('d/m/Y');
  147. $stringType = PHPExcel_Cell_DataType::TYPE_STRING;
  148. $objPHPExcel->setActiveSheetIndex(0)
  149. //->setCellValueExplicit('B1', $DAN,PHPExcel_Cell_DataType::TYPE_STRING)// 010740011003920, titov@bsmi.co.id
  150. ->setCellValueExplicit('B1', $DAN,PHPExcel_Cell_DataType::TYPE_STRING)// 010740011003920, titov@bsmi.co.id
  151. ->setCellValue("B2", $jumlah)
  152. ->setCellValue("B3", $total)
  153. ->setCellValue("B4", $timeCreatedOn)
  154. ->setCellValue("B5", $effective_date);
  155. /******************************************************* End Header ***********************************************************************/
  156.  
  157. /******************************************************* Start Body ***********************************************************************/
  158. $objPHPExcel->setActiveSheetIndex(0)
  159. ->setCellValue('A7', 'Nama')
  160. ->setCellValue('B7', 'No Rekening')
  161. ->setCellValue('C7', 'Nominal')
  162. ->setCellValue('D7', 'Nama Bank Tujuan')
  163. ->setCellValue('E7', 'Kode Bank')
  164. ->setCellValue('F7', 'Service Code')
  165. ->setCellValue('G7', 'Remarks')
  166. ->setCellValue('H7', 'Notification Email')
  167. ->setCellValue('I7', 'Email Address')
  168. ->setCellValue('J7', 'Beneficiary Citizenship Status')
  169. ->setCellValue('K7', 'Beneficiary Citizenship Country Code')
  170. ->setCellValue('L7', 'Beneficiary Type');
  171. /************************************* Start Query *******************************************************/
  172. $sql = "SELECT * FROM tmp_file WHERE idx='$data_idx' and _code ='426' ORDER BY id ASC limit 1";
  173. //$sql = "SELECT * FROM tmp_file WHERE idx='$data_idx' and _code not in ('506','426') ORDER BY id ASC";
  174. //$qr_file = mysql_query("SELECT * FROM tmp_file WHERE idx='$data_idx' and _code='426' ORDER BY id ASC");
  175. $qr_file = mysql_query($sql) or die (mysql_error());
  176. //$qr_file = mysql_query("SELECT * FROM tmp_file WHERE idx='$data_idx' and _code='426' and _amount < 100000000 ORDER BY id ASC");
  177. //$qr_file = mysql_query("SELECT * FROM tmp_file WHERE idx='125' and _code='426' and _amount < 100000000 ORDER BY id ASC");
  178.  
  179. $baris = 8;
  180. $no_urut = 1;
  181. while($temp = mysql_fetch_array($qr_file)) {
  182. $no = $temp[2];
  183. $nama = $temp[3];
  184. $bank = $temp[4];
  185. $code = $temp[5];
  186. $branch = $temp[6];
  187. //$account = $temp[7];
  188. $account = preg_replace('/[^0-9]/','',$temp[7]);
  189. //$amount = $temp[8];
  190. $amount = '1000';
  191. //$bankTujuan = "Mega";
  192. $kodeBank ="4260448";
  193. $serviceCode = "PYR";
  194. $remark = $temp[9];
  195. //$notificationEmail = "N";
  196. $emailAddress ="cops@bsmi.co.id";
  197. $beneficiaryCitizenshipStatus = '1';
  198. $beneficiaryCitizenshipCountryCode = "IND";
  199. $beneficiaryType = '1';
  200. //print_r($code);die;
  201. $type = PHPExcel_Cell_DataType::TYPE_STRING;
  202. $objPHPExcel->setActiveSheetIndex(0)
  203. ->setCellValue("A$baris", $nama)
  204. ->setCellValueExplicit("B$baris", $account,PHPExcel_Cell_DataType::TYPE_STRING)
  205. ->setCellValue("C$baris", $amount);
  206. // Set Account as String, jadi jika ada nomor rekening dengan awal 0 maka akan bisa dibaca oleh Excel
  207. // Contohnya No rekening 052201005665504 akan tetap dibaca oleh Excel 052201005665504 bukan dibaca 52201005665504
  208. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("D$baris", $BN);
  209. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("E$baris", $CB);
  210. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("F$baris", $SC);
  211. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("G$baris", $remark);
  212. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("H$baris", $NE);
  213. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("I$baris", $EA);
  214. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("J$baris", $BCS);
  215. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("K$baris", $BCCC);
  216. $objPHPExcel->setActiveSheetIndex(0)->setCellValue("L$baris", $BT);
  217. $baris = $baris + 1;
  218. }
  219. /******************************************************* End Body ***********************************************************************/
  220. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  221. //$objPHPExcel->setActiveSheetIndex(0);
  222. $tgl = date('Ymd');
  223. $waktu = substr(gmdate("his",time()+60*60*7),0,5);
  224. $fileName ="payrollupload_".$tgl.$waktu;
  225. // Redirect output to a client’s web browser (Excel5)
  226. // Jika CSV
  227.  
  228. header('Content-Type: application/csv');
  229. header('Content-Disposition: attachment;filename="'.$fileName.'".csv"');
  230. header('Pragma: no-cache');
  231.  
  232. /*
  233. // Jika xls
  234. // We'll be outputting an excel file
  235. header('Content-type: application/vnd.ms-excel');
  236. header('Content-Disposition: attachment;filename="'.$fileName.'".xls"');
  237. header("Cache-Control: max-age=0");
  238. */
  239. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
  240. //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  241. $objWriter->save('php://output');
  242. exit;
  243. //}
  244. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement