diff --git a/webht/third_party/trippestOrderSync/controllers/vendor_money.php b/webht/third_party/trippestOrderSync/controllers/vendor_money.php index 2650aab2..6cb3eda4 100644 --- a/webht/third_party/trippestOrderSync/controllers/vendor_money.php +++ b/webht/third_party/trippestOrderSync/controllers/vendor_money.php @@ -36,24 +36,15 @@ class Vendor_money extends CI_Controller { } $vendors = $this->input->post("vendors"); $vendor_sourcetype = $this->trippest->vendor_sourcetype(); - // 不同地接社但是拼团号相同 - $actual_vendor_duplicate_combineno = $this->money_model->get_duplicate_vei_combineno($start_date, $end_date, implode(",", $vendors)); - $duplicate_coli_sn = array_filter(array_column($actual_vendor_duplicate_combineno, 'COLI_SN')); + $final_table = $this->money_model->checked_group_list(0, 0, $start_date, $end_date, implode(',', $vendors)); 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), implode(',', $duplicate_coli_sn)); - foreach ($actual_vendor_duplicate_combineno as $kad => $vad) { - if ($vad['vendor1'] == $download_vendor) { - $tmp['haina_income'] = $vad['trippest_sum']; - $tmp['vendor_income'] = $vad['vendor_sum']; - $tmp['GRI_No'] = $vad['gri_no']; - $tmp['group_vendor_cost'] = $vad['report_cost']; - $vendor_data[] = $tmp; - $tmp = array(); - } - } + $vendor_data = array_filter($final_table, function ($row) use ($download_vendor) + { + return $row['vendor']==$download_vendor; + }); $file_name = str_replace(" ", "_", $date_range) . "_" . $vendor_name; return $this->download_output($vendor_data, $file_name); } @@ -78,17 +69,6 @@ class Vendor_money extends CI_Controller { ,"sum_payout" => 0 ,"sum_other" => 0 ), - // "vendor" => array( - // "sum_trippest_cost" => 0 - // ,"sum_vendor_cost" => 0 - // ,"sum_trippest_sum" => 0 - // ,"sum_vendor_sum" => 0 - // ,"sum_profit" => 0 - // ,"sum_trippest_profit" => 0 - // ,"sum_vendor_profit" => 0 - // ,"sum_payout" => 0 - // ,"sum_other" => 0 - // ), "sync" => array( "sum_trippest_cost" => 0 ,"sum_vendor_cost" => 0 @@ -112,28 +92,21 @@ class Vendor_money extends CI_Controller { $all_price_cost = $this->money_model->get_sync_price_cost($start_date, $end_date, implode(',', $vendors)); $unique_sync_groupno = array(); $dumplicate_groupno = array(); - /** 团款 */ + /** 汇总计算 */ foreach ($vendors as $key => $vendor) { - $sourcetype = $vendor_sourcetype[strval($vendor)]["sourcetype"]; - $opi_summoney = $this->money_model->checked_group_list($vendor, $sourcetype, $start_date, $end_date, implode(',', $vendors), implode(",", $duplicate_coli_sn)); $ret = array( + "trippest_cost" => 0, + "vendor_cost" => 0, "trippest" => array( "trippest_sum" => 0, "vendor_sum" => 0, "other_sum_cost" => 0, "other_sum" => 0, - "other_vendor_sum" => 0 + "other_vendor_sum" => 0, + "trippest_cost" => 0, + "vendor_cost" => 0 ), - // "vendor" => - // array( - // "trippest_sum" => 0, - // "vendor_sum" => 0, - // "transfer_sum" => 0, - // "other_sum_cost" => 0, - // "other_sum" => 0, - // "other_vendor_sum" => 0 - // ), "sync" => array( "price_sum" => 0, @@ -146,24 +119,19 @@ class Vendor_money extends CI_Controller { "other_vendor_sum" => 0 ) ); - foreach ($actual_vendor_duplicate_combineno as $kad => $vad) { - if ($vad['vendor1'] == $vendor) { - $opi_summoney[] = $vad; - } - } - // 按照海纳的算法 - foreach ($opi_summoney as $key => $opi_money) { - if (floatval($opi_money['vendor_sum']) > 0) { - $ret["trippest"]['vendor_sum'] = bcadd(floatval($ret["trippest"]['vendor_sum']), floatval($opi_money['vendor_sum'])) ; - } - if (floatval($opi_money['trippest_sum']) > 0) { - $ret["trippest"]['trippest_sum'] = bcadd(floatval($ret["trippest"]['trippest_sum']), floatval($opi_money['trippest_sum'])) ; + foreach ($final_table as $line => $row) { + if ($row['vendor'] == $vendor) { + $ret['trippest']['trippest_sum'] = bcadd($ret['trippest']['trippest_sum'], $row['haina_receipt']); + $ret['trippest']['vendor_sum'] = bcadd($ret['trippest']['vendor_sum'], $row['vendor_receipt']); + $ret['trippest']['vendor_cost'] = bcadd($ret['trippest']['vendor_cost'], $row['group_vendor_cost']); + $ret['trippest']['other_sum'] = bcadd($ret['trippest']['other_sum'], $row['other_price_RMB']); + $ret['trippest']['other_sum_cost'] = bcadd($ret['trippest']['other_sum_cost'], $row['other_cost_RMB']); + $ret['trippest']['other_vendor_sum'] = bcadd($ret['trippest']['other_vendor_sum'], $row['other_vendorprice_RMB']); + + $ret['vendor_cost'] = bcadd($ret['vendor_cost'], $row['group_vendor_cost']); } - $ret['trippest']['other_sum'] = bcadd($ret['trippest']['other_sum'], $opi_money['other_price_sum']); - $ret['trippest']['other_sum_cost'] = bcadd($ret['trippest']['other_sum_cost'], $opi_money['other_cost_sum']); - $ret["trippest"]['trippest_sum'] = bcsub($ret["trippest"]['trippest_sum'], $opi_money['other_price_sum']); - $ret['trippest']['other_vendor_sum'] = bcadd($ret['trippest']['other_vendor_sum'], $opi_money['other_vendorprice_RMB_sum']); } + /** 计算同步的数据 */ foreach ($all_price_cost as $ks => $sync) { if ($sync['vendor_code'] != $vendor ) { continue; @@ -175,28 +143,7 @@ class Vendor_money extends CI_Controller { $unique_sync_groupno[] = $sync['GCI_combineNo']; $ret['sync']['price_sum'] = bcadd($ret['sync']['price_sum'], $sync['receive_price']); $ret['sync']['cost_sum'] = bcadd($ret['sync']['cost_sum'], $sync['cost']); - // $ret['sync']['vendor_sum'] = bcadd(floatval($ret["sync"]['vendor_sum']), floatval($sync['agency_receive_price'])) ; - // $ret["sync"]['trippest_sum'] = bcadd(floatval($ret["sync"]['trippest_sum']), bcsub(floatval($sync['receive_price']),floatval($sync['agency_receive_price']))) ; } - // 按照图兰朵算法: Trippest自营订单的代收算在海纳收款 - // foreach ($opi_summoney as $kv => $opi_money_v) { - // if (strval($opi_money_v['COLI_OPI_ID']) === '435') { - // $ret["vendor"]['vendor_sum'] = bcadd(floatval($ret["vendor"]['vendor_sum']), floatval($opi_money_v['vendor_sum'])) ; - // } else { - // $ret["vendor"]['trippest_sum'] = bcadd(floatval($ret["vendor"]['trippest_sum']), floatval($opi_money_v['trippest_sum'])) ; - // $ret["vendor"]['trippest_sum'] = bcadd(floatval($ret["vendor"]['trippest_sum']), floatval($opi_money_v['vendor_sum'])) ; - // } - // $ret['vendor']['other_sum'] = bcadd($ret['vendor']['other_sum'], $opi_money_v['other_price_sum']); - // $ret['vendor']['other_sum_cost'] = bcadd($ret['vendor']['other_sum_cost'], $opi_money_v['other_cost_sum']); - // $ret["vendor"]['trippest_sum'] = bcsub($ret["vendor"]['trippest_sum'], $opi_money_v['other_price_sum']); - // $ret['vendor']['other_vendor_sum'] = bcadd($ret['vendor']['other_vendor_sum'], $opi_money['other_vendorprice_RMB_sum']); - // } - // $ret["vendor"]["transfer_sum"] = bcsub($ret["vendor"]['vendor_sum'], $ret["trippest"]['vendor_sum']); - // if ($ret["vendor"]["transfer_sum"] != 0) { - // $result['transfer_sum'] = bcadd($result['transfer_sum'], $ret["vendor"]["transfer_sum"]); - // $result['trippest_order_vendor_money'] = array_merge($result['trippest_order_vendor_money'], $this->money_model->trippest_order_with_vendormoney($vendor, $sourcetype, $start_date, $end_date)); - // } - $result["money"][strval($vendor)] = $ret; $result["money"][strval($vendor)]["vendor_code"] = $vendor; $result["money"][strval($vendor)]["vendor_name"] = $vendor_sourcetype[strval($vendor)]["vendor_name"]; @@ -209,69 +156,37 @@ class Vendor_money extends CI_Controller { $result['col_sum']['sync']['sum_price_sum'] = bcadd($result['col_sum']['sync']['sum_price_sum'], $ret["sync"]['price_sum']); $result['col_sum']['sync']['sum_cost_sum'] = bcadd($result['col_sum']['sync']['sum_cost_sum'], $ret["sync"]['cost_sum']); - // $result['col_sum']['sync']['sum_trippest_sum'] = bcadd($result['col_sum']['sync']['sum_trippest_sum'], $ret["sync"]['trippest_sum']); - // $result['col_sum']['sync']['sum_vendor_sum'] = bcadd($result['col_sum']['sync']['sum_vendor_sum'],$ret['sync']['vendor_sum']); - - // $result['col_sum']['vendor']['sum_trippest_sum'] = bcadd( - // bcadd($result['col_sum']['vendor']['sum_trippest_sum'], $ret["vendor"]['trippest_sum']) - // ,$ret['vendor']['other_sum']); - // $result['col_sum']['vendor']['sum_vendor_sum'] = bcadd($result['col_sum']['vendor']['sum_vendor_sum'], $ret["vendor"]['vendor_sum']); - // $result['col_sum']['vendor']['sum_other'] = bcadd($result['col_sum']['vendor']['sum_other'], $ret['vendor']['other_sum']); - } - /** 成本 */ - // 排除上述的重复拼团号, 后面再加到第一个地接的数据中 - $vendors_cost = $this->money_model->vendor_cost(implode(',', $vendors), $start_date, $end_date); - foreach ($result['money'] as $km => &$vm) { - $vm['vendor_cost'] = $vm['trippest_cost'] = 0; - foreach ($vendors_cost as $kvc => $vvc) { - if (strval($vm['vendor_code']) === strval($vvc['vendor_code'])) { - $vm['vendor_cost'] = $vvc['vendor_cost']; - } - } - foreach ($actual_vendor_duplicate_combineno as $kdc => $vdc) { - if (strval($vm['vendor_code']) === strval($vdc['vendor1'])) { - $vm['vendor_cost'] += $vdc['pure_cost']; - } - } // 成本总计 - $result['col_sum']['trippest']['sum_trippest_cost'] = $result['col_sum']['vendor']['sum_trippest_cost'] = bcadd($result['col_sum']['trippest']['sum_trippest_cost'], $vm['trippest_cost']); + $result['col_sum']['trippest']['sum_trippest_cost'] = $result['col_sum']['vendor']['sum_trippest_cost'] = bcadd($result['col_sum']['trippest']['sum_trippest_cost'], $ret['trippest_cost']); $result['col_sum']['trippest']['sum_vendor_cost'] = $result['col_sum']['vendor']['sum_vendor_cost'] = bcadd( - bcadd($result['col_sum']['trippest']['sum_vendor_cost'], $vm['vendor_cost']) - ,$vm['trippest']['other_sum_cost']); + bcadd($result['col_sum']['trippest']['sum_vendor_cost'], $ret['vendor_cost']) + ,$ret['trippest']['other_sum_cost']); } + foreach ($result['money'] as $kmi => &$vmi) { /** 利润 */ $vmi['trippest']['total_profit'] = bcsub( bcadd(bcadd($vmi['trippest']['trippest_sum'], $vmi['trippest']['vendor_sum']),$vmi['trippest']['other_sum']), bcadd(bcadd($vmi['trippest_cost'], $vmi['vendor_cost']),$vmi['trippest']['other_sum_cost'])); - // $vmi['vendor']['total_profit'] = bcsub( - // bcadd(bcadd($vmi['vendor']['trippest_sum'], $vmi['vendor']['vendor_sum']),$vmi['vendor']['other_sum']), - // bcadd(bcadd($vmi['trippest_cost'], $vmi['vendor_cost']),$vmi['vendor']['other_sum_cost'])); /** 利润分成 */ $vmi['trippest']['vendor_profit'] = bcmul($vmi['trippest']['total_profit'], $vendor_sourcetype[strval($vmi['vendor_code'])]["profit_rate"]); $vmi['trippest']['trippest_profit'] = bcmul($vmi['trippest']['total_profit'], bcsub(1, $vendor_sourcetype[strval($vmi['vendor_code'])]["profit_rate"]) ); - // $vmi['vendor']['vendor_profit'] = bcmul($vmi['vendor']['total_profit'], $vendor_sourcetype[strval($vmi['vendor_code'])]["profit_rate"]); - // $vmi['vendor']['trippest_profit'] = bcmul($vmi['vendor']['total_profit'], bcsub(1, $vendor_sourcetype[strval($vmi['vendor_code'])]["profit_rate"]) ); /** Trippest应付地接 */ $vmi['trippest']['payout'] = bcsub(bcadd($vmi['vendor_cost'], $vmi['trippest']['vendor_profit'] ), $vmi['trippest']['vendor_sum']); - // $vmi['vendor']['payout'] = bcsub(bcadd($vmi['vendor_cost'], $vmi['vendor']['vendor_profit'] ), $vmi['vendor']['vendor_sum']); /** 利润总计 */ $result['col_sum']['trippest']['sum_profit'] = bcadd($result['col_sum']['trippest']['sum_profit'], $vmi['trippest']['total_profit']); $result['col_sum']['trippest']['sum_trippest_profit'] = bcadd($result['col_sum']['trippest']['sum_trippest_profit'], $vmi['trippest']['trippest_profit']); $result['col_sum']['trippest']['sum_vendor_profit'] = bcadd($result['col_sum']['trippest']['sum_vendor_profit'], $vmi['trippest']['vendor_profit']); - // $result['col_sum']['vendor']['sum_profit'] = bcadd($result['col_sum']['vendor']['sum_profit'], $vmi['vendor']['total_profit']); - // $result['col_sum']['vendor']['sum_trippest_profit'] = bcadd($result['col_sum']['vendor']['sum_trippest_profit'], $vmi['vendor']['trippest_profit']); - // $result['col_sum']['vendor']['sum_vendor_profit'] = bcadd($result['col_sum']['vendor']['sum_vendor_profit'], $vmi['vendor']['vendor_profit']); /** 应付总计 */ $result['col_sum']['trippest']['sum_payout'] = bcadd($result['col_sum']['trippest']['sum_payout'], $vmi['trippest']['payout']); - // $result['col_sum']['vendor']['sum_payout'] = bcadd($result['col_sum']['vendor']['sum_payout'], $vmi['vendor']['payout']); } // 财务表成本和实际成本不相等 $result['diff_cost'] = $this->money_model->report_tour_diff($start_date, $end_date, implode(',', $vendors)); - $this->load->view('vendor_money_sum', $result); - return ; + return $this->load->view('vendor_money_sum', $result); + // return $this->output->set_content_type('application/json')->set_output(json_encode($result)); + ; } public function download_output($export_list, $file_name) @@ -310,11 +225,11 @@ class Vendor_money extends CI_Controller { ->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('C'.$rowCount, number_format($row['haina_receipt'], 2, ".", "")) + ->setCellValue('D'.$rowCount, number_format($row['vendor_receipt'], 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'])) + ->setCellValue('G'.$rowCount, bcsub(bcadd($row['vendor_receipt'],$row['haina_receipt']),$row['group_vendor_cost'])) ; $rowCount++; } diff --git a/webht/third_party/trippestOrderSync/models/vendor_money_model.php b/webht/third_party/trippestOrderSync/models/vendor_money_model.php index 83c73740..48992d58 100644 --- a/webht/third_party/trippestOrderSync/models/vendor_money_model.php +++ b/webht/third_party/trippestOrderSync/models/vendor_money_model.php @@ -12,21 +12,25 @@ class Vendor_money_model extends CI_Model { bcscale(4); } - public function checked_group_list($vendor, $sourcetype, $start_date, $end_date, $all_vendor, $duplicate_gri) + public function checked_group_list($vendor, $sourcetype, $start_date, $end_date, $all_vendor) { - $duplicate_gri = $duplicate_gri==='' ? 0 : $duplicate_gri; - $sql = "SELECT sum_opi.COLI_OPI_ID,sum(sum_opi.海纳收款) as trippest_sum,sum(sum_opi.地接社收款) as vendor_sum, + /* + SELECT sum_opi.COLI_OPI_ID,sum(sum_opi.海纳收款) as trippest_sum,sum(sum_opi.地接社收款) as vendor_sum, sum(sum_opi.other_price_RMB) as other_price_sum , sum(sum_opi.other_cost_RMB) as other_cost_sum ,sum(sum_opi.other_vendorprice_RMB) as other_vendorprice_RMB_sum from ( - SELECT + ) as sum_opi + group by sum_opi.COLI_OPI_ID + order by case sum_opi.COLI_OPI_ID when '435' then 0 else 1 end + */ + $sql = "SELECT (select isnull(SUM(COLD_TotalPrice),0) from BIZ_ConfirmLineDetail cold where cold.COLD_COLI_SN=cgi_group.COLI_SN and COLD_ServiceType <> 'D' and COLD_PlanVEI_SN IN ($all_vendor) and cold.DeleteFlag=0 - )*cgi_group.汇率 as other_price_RMB, + )*cgi_group.gai_rate as other_price_RMB, (select isnull(SUM(COLD_TotalCost),0) from BIZ_ConfirmLineDetail cold where cold.COLD_COLI_SN=cgi_group.COLI_SN and COLD_ServiceType <> 'D' @@ -35,13 +39,20 @@ class Vendor_money_model extends CI_Model { ) as other_cost_RMB, (dbo.ConvertToRMB('USD',other_vendor_price)) as other_vendorprice_RMB, case when other_vendor_price > 0 then - (总收款-dbo.ConvertToRMB('USD',other_vendor_price)) - else 海纳收款_origin end - as 海纳收款, + (order_total_receipt-dbo.ConvertToRMB('USD',other_vendor_price)) + else ht_origin end + as haina_receipt, * + ,(select ROUND(SUM(isnull(tourcost,0)),4) + 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 + ) + ) as group_vendor_cost from ( select - COLI_SN, + COLI_SN,COLI_ID,GRI_No, (select COUNT(0) from BIZ_ConfirmLineDetail where COLD_COLI_SN=COLI_SN and COLD_ServiceType='D' @@ -51,7 +62,7 @@ class Vendor_money_model extends CI_Model { where COLD_COLI_SN=COLI_SN --and COLD_ServiceType='D' and DeleteFlag=0 - and COLD_PlanVEI_SN<>$vendor + --and COLD_PlanVEI_SN<>$vendor and COLD_PlanVEI_SN not in ($all_vendor) ) as other_vendor_price, COLI.COLI_sourcetype, @@ -61,21 +72,24 @@ class Vendor_money_model extends CI_Model { convert(decimal(10,2),round((select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo where DeleteFlag=0 and GAI_COLI_SN=COLI_SN )/isnull(COLI.COLI_Price,1),2)) - else 0 end as 汇率, + else 0 end as gai_rate, (select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo where DeleteFlag=0 and GAI_COLI_SN=COLI_SN - ) as 总收款, + ) as order_total_receipt, (select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo where DeleteFlag=0 and GAI_COLI_SN=COLI_SN and GAI_Type not in (" . PAY_OTHER . ") - ) as 海纳收款_origin, + ) as ht_origin, (select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo where DeleteFlag=0 and GAI_COLI_SN=COLI_SN - and GAI_VEI_SN in ($vendor, 1343) + and GAI_VEI_SN in ($all_vendor) and GAI_Type in (" . PAY_OTHER . ") - ) as 地接社收款 + ) as vendor_receipt ,coli.COLI_OPI_ID - + ,( + select top 1 v.COLD_PlanVEI_SN from BIZ_ConfirmLineDetail v where COLD_COLI_SN=COLI_SN + and v.DeleteFlag=0 and COLD_PlanVEI_SN in ($all_vendor) + ) as vendor from CK_GroupInfo cgi inner join GRoupInfo gri on CGI_GRI_SN=GRI_SN inner join BIZ_ConfirmLineInfo coli on COLI_GRI_SN=GRI_SN @@ -86,17 +100,17 @@ class Vendor_money_model extends CI_Model { ) and CGI_Checked=1 and GRI_OrderType=227002 - and COLI_SN not in ($duplicate_gri) + and COLI_State<>50 + and exists ( select 1 from BIZ_ConfirmLineDetail where COLD_COLI_SN=coli.COLI_SN and DeleteFlag=0 - and COLD_PlanVEI_SN=$vendor + and COLD_PlanVEI_SN in ($all_vendor) ) - -- and COLI_sourcetype=$sourcetype - ) as cgi_group - ) as sum_opi - group by sum_opi.COLI_OPI_ID - order by case sum_opi.COLI_OPI_ID when '435' then 0 else 1 end "; + + ) as cgi_group"; + // -- and COLI_SN not in ($duplicate_gri) + // -- and COLI_sourcetype=$sourcetype $query = $this->HT->query($sql); $opi_sum_money = $query->result_array(); return $opi_sum_money; @@ -232,9 +246,8 @@ class Vendor_money_model extends CI_Model { return $query->result_array(); } - public function group_detail_list($vendor, $sourcetype, $start_date, $end_date, $all_vendor, $duplicate_gri) + public function group_detail_list($vendor, $sourcetype, $start_date, $end_date, $all_vendor) { - $duplicate_gri = $duplicate_gri==='' ? 0 : $duplicate_gri; $sql = "SELECT (dbo.ConvertToRMB('USD',other_vendor_price)) as other_vendorprice_RMB, case when other_vendor_price > 0 then @@ -299,14 +312,16 @@ class Vendor_money_model extends CI_Model { ) and CGI_Checked=1 and GRI_OrderType=227002 - and COLI_SN not in ($duplicate_gri) + and exists ( select 1 from BIZ_ConfirmLineDetail where COLD_COLI_SN=coli.COLI_SN and DeleteFlag=0 and COLD_PlanVEI_SN=$vendor ) - -- and COLI_sourcetype=$sourcetype + ) as cgi_group"; + // and COLI_SN not in ($duplicate_gri) + // -- and COLI_sourcetype=$sourcetype $query = $this->HT->query($sql); return $query->result_array(); } @@ -515,60 +530,70 @@ class Vendor_money_model extends CI_Model { public function get_duplicate_vei_combineno($start_date, $end_date, $all_vendor) { - $sql = "SELECT pure_group.* - ,(select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo - where DeleteFlag=0 and GAI_GRI_SN=COLI_SN - and GAI_VEI_SN in ($all_vendor) - and GAI_Type in (" . PAY_OTHER . ") - ) as vendor_sum - ,(select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo - where DeleteFlag=0 and GAI_COLI_SN=COLI_SN - ) as total_receipt - ,(select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo - where DeleteFlag=0 and GAI_COLI_SN=COLI_SN - and GAI_Type not in (" . PAY_OTHER . ") - ) as trippest_sum + $sql = "SELECT + duplicate_gri.* ,( - select SUM(tourcost) - from BIZ_ConfirmLineInfo - inner join GroupCombineInfo on COLI_GRI_SN=GCI_GRI_SN - inner join report_tour on ordernumber=COLI_ID - where 1=1 - and GCI_VEI_SN in ($all_vendor) - and GCI_combineNo=pure_group.GCI_combineNo - and exists ( - select 1 from VEndorInfo2 where VEI2_LGC=2 - and VEI2_VEI_SN=GCI_VEI_SN and VEI2_CompanyBN=tourProvide - ) - ) as report_cost - ,0 as other_price_sum,0 as other_cost_sum,0 as other_vendorprice_RMB_sum - from (SELECT GCI_combineNo - ,(select top 1 GCI_VEI_SN from groupcombineinfo g1 where g1.gci_combineno=vendor_group.GCI_combineNo) as vendor1 - ,(select top 1 c.COLI_SN from groupcombineinfo g1 - inner join BIZ_ConfirmLineInfo c on COLI_GRI_SN=GCI_GRI_SN - where g1.gci_combineno=vendor_group.GCI_combineNo - ) as COLI_SN - ,(select top 1 GRI_No from groupInfo inner join groupcombineinfo gc on gc.GCI_GRI_SN=GRI_SN where gc.gci_combineno=vendor_group.GCI_combineNo) as gri_no - ,(SELECT isnull(SUM(CONVERT(float, isnull(gcod.GCOD_sumMoney,0))),0) - FROM GroupCombineOperationDetail gcod - WHERE gcod.GCOD_GCI_combineNo=GCI_combineNo - AND gcod.GCOD_operationType<> 'otherReceives' - ) as pure_cost - from ( - select GCI_combineNo ,GCI_VEI_SN - from GroupCombineInfo where 1=1 - and GCI_VEI_SN in ($all_vendor) - AND EXISTS - ( SELECT 1 - FROM CK_GroupInfo - WHERE CGI_Checked=1 - AND CGI_GRI_SN=GCI_GRI_SN - AND CGI_ArriveDate BETWEEN '$start_date' AND '$end_date') - group by GCI_combineNo, GCI_VEI_SN - ) as vendor_group - group by vendor_group.GCI_combineNo - having COUNT(1)>1 - ) as pure_group"; + SELECT isnull(SUM(GAI_SSJE),0) + FROM BIZ_GroupAccountInfo + WHERE DeleteFlag=0 + AND GAI_GRI_SN=COLI_SN + AND GAI_VEI_SN IN ($all_vendor) + AND GAI_Type IN (" . PAY_OTHER . ") + ) AS vendor_sum + ,( + SELECT isnull(SUM(GAI_SSJE),0) + FROM BIZ_GroupAccountInfo + WHERE DeleteFlag=0 + AND GAI_COLI_SN=COLI_SN ) AS total_receipt + ,( + SELECT isnull(SUM(GAI_SSJE),0) + FROM BIZ_GroupAccountInfo + WHERE DeleteFlag=0 + AND GAI_COLI_SN=COLI_SN + AND GAI_Type not IN (" . PAY_OTHER . ") ) AS trippest_sum + ,0 AS other_price_sum + ,0 AS other_cost_sum + ,0 AS other_vendorprice_RMB_sum + from( + select tmp.GCI_combineNo, tmp.GCI_SN, tmp.GCI_VEI_SN vendor1,real_unique.* + ,(SELECT top 1 c.COLI_SN FROM BIZ_ConfirmLineInfo c WHERE c.coli_gri_sn=real_unique.gci_gri_sn) as COLI_SN + ,(SELECT top 1 GRI_No FROM groupInfo where gri_sn=real_unique.gci_gri_sn) as gri_no + ,( + SELECT SUM(tourcost) + FROM BIZ_ConfirmLineInfo + INNER JOIN GroupCombineInfo + ON COLI_GRI_SN=GCI_GRI_SN + INNER JOIN report_tour + ON ordernumber=COLI_ID + WHERE 1=1 + AND GCI_VEI_SN IN ($all_vendor) + and GCI_GRI_SN=tmp.GCI_GRI_SN + AND exists ( + SELECT 1 + FROM VEndorInfo2 + WHERE VEI2_LGC=2 + AND VEI2_VEI_SN=GCI_VEI_SN + AND VEI2_CompanyBN=tourProvide ) + ) AS report_cost + ,( + SELECT isnull(SUM(CONVERT(float,isnull(gcod.GCOD_sumMoney,0))),0) + FROM GroupCombineOperationDetail gcod + WHERE gcod.GCOD_GCI_combineNo=tmp.GCI_combineNo + AND gcod.GCOD_operationType<> 'otherReceives' ) AS pure_cost + from GroupCombineInfo tmp + inner join ( + select GCI_GRI_SN + from GroupCombineInfo unique_gci + where GCI_travelDate between '$start_date' AND '$end_date' + and isnull(GCI_combineNo,'') not in ('','cancel','forbidden') + and isnull(convert(decimal(10,2), GCI_priceCNY),0)>0 + group by GCI_GRI_SN + having count(GCI_GRI_SN)>1 + ) as real_unique on real_unique.GCI_GRI_SN=tmp.GCI_GRI_SN + where isnull(tmp.GCI_combineNo,'') not in ('','cancel','forbidden') + ) as duplicate_gri + order by duplicate_gri.COLI_SN + "; $query = $this->HT->query($sql); return $query->result_array(); }