diff --git a/webht/third_party/trippestOrderSync/controllers/vendor_money.php b/webht/third_party/trippestOrderSync/controllers/vendor_money.php index 3cf37c3e..f665d70e 100644 --- a/webht/third_party/trippestOrderSync/controllers/vendor_money.php +++ b/webht/third_party/trippestOrderSync/controllers/vendor_money.php @@ -23,7 +23,7 @@ class Vendor_money extends CI_Controller { public function index($download_vendor=null) { - // $this->permission->is_admin(true); // test: + $this->permission->is_admin(true); $date_range = $this->input->post("date_range"); preg_match_all('/\d{4}\-\d{2}\-\d{2}/', $date_range, $date_range_arr); if (empty($date_range_arr[0])) { @@ -39,8 +39,10 @@ class Vendor_money extends CI_Controller { if ($download_vendor !== null) { $vendors = array($download_vendor); $sourcetype = $vendor_sourcetype[strval($download_vendor)]["sourcetype"]; + $vendor_name = $vendor_sourcetype[strval($download_vendor)]["vendor_name"]; $vendor_data = $this->money_model->group_detail_list($download_vendor, $sourcetype, $start_date, $end_date, implode(',', $vendors)); - return $this->output->set_content_type('application/json')->set_output(json_encode($vendor_data, JSON_UNESCAPED_UNICODE)); + $file_name = str_replace(" ", "_", $date_range) . "_" . $vendor_name; + return $this->download_output($vendor_data, $file_name); } $result = array( "default_date1" => $start_date @@ -219,6 +221,59 @@ class Vendor_money extends CI_Controller { } + public function download_output($export_list, $file_name) + { + if (empty($export_list)) { + return false; + } + $this->load->library('PHPExcel'); + $objPHPExcel = new PHPExcel(); + $objPHPExcel->setActiveSheetIndex(0); + //set width + $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5); + $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30); + $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15); + $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20); + $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20); + $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20); + $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20); + // 对齐 + $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); + $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); + $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); + // 表标题行 + $objPHPExcel->getActiveSheet() + ->SetCellValue('A1', '#') + ->SetCellValue('B1', '团号') + ->SetCellValue('C1', '①海纳代收') + ->SetCellValue('D1', '②地接代收') + ->SetCellValue('E1', '③海纳成本') + ->SetCellValue('F1', '④地接成本') + ->SetCellValue('G1', '⑤利润'); + bcscale(2); + $rowCount = 2; + foreach ($export_list as $key => $row) { + $objPHPExcel->getActiveSheet() + ->SetCellValue('A'.$rowCount, ($rowCount-1)) + // ->SetCellValue('A'.$rowCount, $row->pn_sn) + ->setCellValueExplicit('B'.$rowCount, $row['GRI_No'],PHPExcel_Cell_DataType::TYPE_STRING) + ->setCellValue('C'.$rowCount, number_format($row['haina_income'], 2, ".", "")) + ->setCellValue('D'.$rowCount, number_format($row['vendor_income'], 2, ".", "")) + ->SetCellValue('E'.$rowCount, 0) + ->SetCellValue('F'.$rowCount, $row['group_vendor_cost']) + ->setCellValue('G'.$rowCount, bcsub(bcadd($row['vendor_income'],$row['haina_income']),$row['group_vendor_cost'])) + ; + $rowCount++; + } + $rowCount++; // 隔一行 + $filename = $file_name . "_" . date('Y-m-d'); + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment;filename="' . $filename . '.xls"'); + header('Cache-Control: max-age=0'); + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); + $objWriter->save('php://output'); + } + } /* End of file vendor_money.php */ diff --git a/webht/third_party/trippestOrderSync/models/vendor_money_model.php b/webht/third_party/trippestOrderSync/models/vendor_money_model.php index 988f43d9..50d92248 100644 --- a/webht/third_party/trippestOrderSync/models/vendor_money_model.php +++ b/webht/third_party/trippestOrderSync/models/vendor_money_model.php @@ -264,7 +264,7 @@ class Vendor_money_model extends CI_Model { and GAI_Type in (" . PAY_OTHER . ") ) as vendor_income ,coli.COLI_OPI_ID - , gri.GRI_Name + , gri.GRI_No ,(select SUM(isnull(tourcost,0)) from report_tour where ordernumber=COLI_ID and exists ( select 1 from BIZ_ConfirmLineDetail where COLD_SN=RPT_COLD_SN and COLD_PlanVEI_SN=$vendor @@ -298,7 +298,7 @@ class Vendor_money_model extends CI_Model { -- and COLI_sourcetype=$sourcetype ) as cgi_group"; $query = $this->HT->query($sql); - return $query->result(); + return $query->result_array(); } diff --git a/webht/third_party/trippestOrderSync/views/vendor_money_sum.php b/webht/third_party/trippestOrderSync/views/vendor_money_sum.php index ef8a421e..368142d3 100644 --- a/webht/third_party/trippestOrderSync/views/vendor_money_sum.php +++ b/webht/third_party/trippestOrderSync/views/vendor_money_sum.php @@ -29,6 +29,7 @@ .text-right {text-align: right;} .text-bold {font-weight: bold;} .cell-right {float: right;} + td a {cursor: pointer;} @@ -50,7 +51,7 @@

-
+
@@ -96,7 +97,7 @@ ?> - 导出账单明细 ⇓ + 导出账单明细 ⇓ @@ -274,6 +275,12 @@ ,allowInput: true ,defaultDate:['', ''] }); + }) + function detail_download(vendor) { + document.request_form.action = "/webht.php/apps/trippestordersync/vendor_money/index" + "/" + vendor; + document.querySelector('#request_form').submit(); + document.request_form.action = "/webht.php/apps/trippestordersync/vendor_money/index"; + }