prepare_list_excel.php20240723 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
  3. include $_SERVER['DOCUMENT_ROOT'].ADMIN_PATH.'common/auth_chk.php';
  4. include $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
  5. $searchtype = $_REQUEST['searchtype'];
  6. $searchword = $_REQUEST['searchword'];
  7. $ds_usertype = $_REQUEST['ds_usertype'];
  8. $dt_start = $_REQUEST['dt_start'];
  9. $dt_end = $_REQUEST['dt_end'];
  10. $ds_status = $_REQUEST['ds_status'];
  11. $add_sql = "where s.ds_delind='N'";
  12. // $orderby = "order by s.dt_insert desc"; //2200513 등록일 날짜 기준으로 리스트 정렬하기
  13. //$orderby = "order by s.dt_update desc"; //20191207 디비에 업데이트 날짜 기준으로 리스트 정렬하기
  14. if(empty($PageSort)) {
  15. $orderby = "order by s.dt_update desc";
  16. }else {
  17. $sort = explode("|", $PageSort);
  18. $orderby = "order by $sort[0] $sort[1] ";
  19. }
  20. $ds_type = "A0"; //A0 : 매입
  21. $add_sql.= " and s.ds_type = '$ds_type' ";
  22. if($searchword != ""){
  23. if($searchtype=="" || $searchtype==null){
  24. $add_sql.= " and (s.nm_name like '$searchword%' or a.nm_number like '$searchword%') ";
  25. }else{
  26. $add_sql.= " and $searchtype like '$searchword%'";
  27. }
  28. }
  29. if($ds_usertype != ""){
  30. $add_sql.= " and s.ds_usertype = '$ds_usertype'";
  31. }
  32. if($dt_start != "" && $dt_end != ""){
  33. $add_sql.= " and s.dt_insert between '$dt_start' and '$dt_end' ";
  34. }
  35. $add_sql.= " and s.ds_status in ('E0','F0')";
  36. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. //관계사/지점 Setting
  38. $admin_ds_company_bp = $_SESSION['admin_ds_company_bp']; //관계사
  39. $admin_ds_branch = $_SESSION['admin_ds_branch']; //지점
  40. $admin_bp_ok = ($admin_ds_company_bp != "" || $admin_ds_branch != "") ? true : false; //admin_ds_company_bp 나 admin_ds_branch 값이 하나라도 있으면 관계사로 보고 권한 제한한다. $admin_bp_ok == true 이면 해당 관계사/지점 데이타만 확인 가능하다.
  41. //관계사 일 경우 해당 관계사/지점 데이타만 확인 가능하다.
  42. // if($admin_bp_ok){
  43. // if($admin_ds_company_bp != "" && $admin_ds_branch != ""){
  44. // $add_sql.= " and s.ds_company_bp = '$admin_ds_company_bp' and s.ds_branch = '$admin_ds_branch' ";
  45. // }else{ //admin_ds_company_bp 나 admin_ds_branch 값이 하나라도 없으면 데이타 확인 안되게 한다.
  46. // $add_sql.= " and 1 = 2 ";
  47. // }
  48. // }
  49. $spreadsheet = new PhpOffice\PhpSpreadsheet\Spreadsheet();
  50. $sheet = $spreadsheet->getActiveSheet();
  51. $sql = "SELECT *
  52. , getCode('car_master','ds_type',ds_type) as nm_type
  53. , getCode('car_master','ds_open',ds_open) as nm_open
  54. , getCode('car_master','ds_sales',ds_sales) as nm_sales
  55. , getCode('car_master','ds_transmission',ds_transmission) as nm_transmission
  56. , getCode('member_master','ds_area',ds_area_sale) as nm_area
  57. , getCode('sale_master','ds_status',ds_status_sale) as nm_status
  58. -- , getRemainTimeByPhase(".LIMIT_TIME_TENDER.", ".LIMIT_TIME_SELL.", dt_approve_sale, now()) as time_limit_sell
  59. , getRemainTimeByPhase(ds_auction_time, ".LIMIT_TIME_SELL.", dt_approve_sale, now()) as time_limit_sell
  60. FROM (
  61. SELECT
  62. a.*
  63. , b.nm_model
  64. , d.nm_brand
  65. , s.cd_sale
  66. , s.nm_name nm_name_sale
  67. , s.nm_recommend nm_recommend_sale
  68. , s.ds_status ds_status_sale
  69. , s.ds_status_contract ds_status_contract_sale
  70. , s.ds_area ds_area_sale
  71. , s.dt_approve dt_approve_sale
  72. , s.dt_update dt_update_sale
  73. , s.dt_insert dt_insert_sale
  74. FROM sale_master s
  75. inner join car_master a on (s.cd_car = a.cd_car)
  76. left outer join car_model b on (a.cd_model = b.cd_model)
  77. left outer join car_brand d on (a.cd_brand = d.cd_brand)
  78. $add_sql $orderby
  79. ) as car
  80. ";
  81. // echo $sql;
  82. // exit;
  83. $r = mysql_query($sql, $connect);
  84. $i=1;
  85. $EXCEL_DATA = array();
  86. while($col = mysql_fetch_assoc($r)) {
  87. #리스트
  88. $DATA = array();
  89. $DATA['no'] = (string)$i;
  90. $DATA['nm_name_sale'] = $col['nm_name_sale'];
  91. $DATA['car_info'] = $col['nm_brand']." ".$col['nm_model'];
  92. $DATA['nm_number'] = $col['nm_number'];
  93. $DATA['nm_mileage'] = $col['nm_mileage']."km";
  94. $DATA['nm_color'] = $col['nm_color'];
  95. $DATA['nm_area'] = $col['nm_area'];
  96. $DATA['time_limit_sell'] = $col['time_limit_sell'];
  97. $DATA['dt_insert'] = $col['dt_insert_sale'];
  98. $EXCEL_DATA[] = $DATA;
  99. unset($DATA);
  100. $i++;
  101. }
  102. mysql_close($connect);
  103. $cells = array(
  104. 'A' => array(15, 'no', '번호'),
  105. 'B' => array(20, 'nm_name_sale', '판매자'),
  106. 'C' => array(40, 'car_info', '차종'),
  107. 'D' => array(20, 'nm_number', '차량번호'),
  108. 'E' => array(20, 'nm_mileage', '주행거리'),
  109. 'F' => array(20, 'nm_color', '색상'),
  110. 'G' => array(20, 'nm_area', '판매지역'),
  111. 'H' => array(20, 'time_limit_sell', '판매시간'),
  112. 'I' => array(20, 'dt_insert', '등록일')
  113. );
  114. foreach ($cells as $key => $val) {
  115. $cellName = $key.'1';
  116. $sheet->getColumnDimension($key)->setWidth($val[0]);
  117. $sheet->getRowDimension('1')->setRowHeight(25);
  118. $sheet->setCellValue($cellName, $val[2]);
  119. $sheet->getStyle($cellName)->getFont()->setBold(true);
  120. $sheet->getStyle($cellName)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
  121. $sheet->getStyle($cellName)->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
  122. }
  123. for ($i = 2; $row = array_shift($EXCEL_DATA); $i++) {
  124. foreach ($cells as $key => $val) {
  125. $sheet->setCellValue($key.$i, $row[$val[1]]);
  126. }
  127. }
  128. $filename = '관리자_입찰중_엑셀_'.date('Y-m-d');
  129. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  130. header('Content-Disposition: attachment; filename="'.$filename.'.xlsx"');
  131. $writer = new PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
  132. $writer->save('php://output');
  133. exit;
  134. ?>