prepare_list_excel.20240724.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. //-- , getRemainTimeByPhase(".LIMIT_TIME_TENDER.", ".LIMIT_TIME_SELL.", dt_approve_sale, now()) as time_limit_sell
  52. // , getRemainTimeByPhase(ds_auction_time, ds_auction_time, dt_approve_sale, now()) as time_limit_sell
  53. $sql = "SELECT *
  54. , getCode('car_master','ds_type',ds_type) as nm_type
  55. , getCode('car_master','ds_open',ds_open) as nm_open
  56. , getCode('car_master','ds_sales',ds_sales) as nm_sales
  57. , getCode('car_master','ds_transmission',ds_transmission) as nm_transmission
  58. , getCode('member_master','ds_area',ds_area_sale) as nm_area
  59. , getCode('sale_master','ds_status',ds_status_sale) as nm_status
  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_hp nm_hp_sale
  68. , s.nm_recommend nm_recommend_sale
  69. , s.cd_aap_dealer cd_aap_dealer_sale
  70. , s.ds_status ds_status_sale
  71. , s.ds_status_contract ds_status_contract_sale
  72. , s.ds_area ds_area_sale
  73. , s.dt_approve dt_approve_sale
  74. , s.dt_update dt_update_sale
  75. , s.dt_insert dt_insert_sale
  76. , s.cd_user as cd_user
  77. , aap.nm_name aap_nm_name
  78. FROM sale_master s
  79. inner join car_master a on (s.cd_car = a.cd_car)
  80. left outer join car_model b on (a.cd_model = b.cd_model)
  81. left outer join car_brand d on (a.cd_brand = d.cd_brand)
  82. left outer join aap_master aap on (aap.cd_dealer = s.cd_aap_dealer)
  83. $add_sql $orderby
  84. ) as car
  85. ";
  86. // echo $sql;
  87. // exit;
  88. $r = mysql_query($sql, $connect);
  89. $i=1;
  90. $EXCEL_DATA = array();
  91. while($col = mysql_fetch_assoc($r)) {
  92. #리스트
  93. $DATA = array();
  94. $DATA['no'] = (string)$i;
  95. $DATA['nm_name_sale'] = $col['nm_name_sale'];
  96. $DATA['sa_nm_name'] = $col['sa_nm_name'];
  97. $DATA['car_info'] = $col['nm_brand']." ".$col['nm_model'];
  98. $DATA['nm_number'] = $col['nm_number'];
  99. $DATA['nm_hp_sale'] = $col['nm_hp_sale'];
  100. $DATA['nm_mileage'] = $col['nm_mileage']."km";
  101. $DATA['nm_color'] = $col['nm_color'];
  102. $DATA['nm_area'] = $col['nm_area'];
  103. $DATA['cd_user'] = $col['cd_user'];
  104. $DATA['time_limit_sell'] = $col['time_limit_sell'];
  105. $DATA['dt_insert'] = $col['dt_insert_sale'];
  106. $DATA['aap_nm_name'] = $col['aap_nm_name'];
  107. $EXCEL_DATA[] = $DATA;
  108. unset($DATA);
  109. $i++;
  110. }
  111. mysql_close($connect);
  112. $cells = array(
  113. 'A' => array(15, 'no', '번호'),
  114. 'B' => array(20, 'nm_name_sale', '판매자'),
  115. 'C' => array(20, 'sa_nm_name', 'SA명'),
  116. 'D' => array(20, 'nm_hp_sale', 'SA연락처'),
  117. 'E' => array(20, 'aap_nm_name', '희망AAP'),
  118. 'F' => array(40, 'car_info', '차종'),
  119. 'G' => array(20, 'nm_number', '차량번호'),
  120. 'H' => array(20, 'nm_mileage', '주행거리'),
  121. 'I' => array(20, 'nm_color', '색상'),
  122. 'J' => array(20, 'nm_area', '판매지역'),
  123. 'K' => array(20, 'time_limit_sell', '판매시간'),
  124. 'L' => array(20, 'dt_insert', '등록일')
  125. );
  126. foreach ($cells as $key => $val) {
  127. $cellName = $key.'1';
  128. $sheet->getColumnDimension($key)->setWidth($val[0]);
  129. $sheet->getRowDimension('1')->setRowHeight(25);
  130. $sheet->setCellValue($cellName, $val[2]);
  131. $sheet->getStyle($cellName)->getFont()->setBold(true);
  132. $sheet->getStyle($cellName)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
  133. $sheet->getStyle($cellName)->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
  134. }
  135. for ($i = 2; $row = array_shift($EXCEL_DATA); $i++) {
  136. foreach ($cells as $key => $val) {
  137. $sheet->setCellValue($key.$i, $row[$val[1]]);
  138. }
  139. }
  140. $filename = '관리자_입찰중_엑셀_'.date('Y-m-d');
  141. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  142. header('Content-Disposition: attachment; filename="'.$filename.'.xlsx"');
  143. $writer = new PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
  144. $writer->save('php://output');
  145. exit;
  146. ?>