Trippest 账单结算,未完成

feature/trippest
lyt 7 years ago
parent d53d6fc45b
commit 08844a835b

@ -0,0 +1,92 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Vendor_money extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->library('trippest');
$this->load->helper('array');
$this->load->model('Vendor_money_model', 'money_model');
mb_regex_encoding("UTF-8");
bcscale(4);
}
public function index()
{
}
public function settlement()
{
// $start_date = $this->input->post("start_date");
// $end_date = $this->input->post("end_date");
// if ($end_date == null) {
// $end_date = date("Y-m-d H:i:s", strtotime("+1 month", strtotime($start_date))-1);
// }
// $vendors = $this->input->post("vendors");
// test
$start_date = "2018-10-01";
$end_date = "2018-10-31 23:59:59";
$vendors = "1343,29188";
// end test
$vendor_sourcetype = $this->trippest->vendor_sourcetype();
$result = array(
"trippest_order_vendor_money" => array()
,"transfer_sum" => 0
);
/** 团款 */
foreach (explode(",", $vendors) as $key => $vendor) {
$sourcetype = $vendor_sourcetype[strval($vendor)]["sourcetype"];
$opi_summoney = $this->money_model->checked_group_list($vendor, $sourcetype, $start_date, $end_date);
$ret = array(
"trippest" =>
array(
"trippest_sum" => 0,
"vendor_sum" => 0
),
"vendor" =>
array(
"trippest_sum" => 0,
"vendor_sum" => 0,
"transfer_sum" => 0,
"trippest_order_vendor_money" => null
)
);
// 按照海纳的算法
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'])) ;
}
}
// 按照图兰朵算法: 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"]["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"];
}
/** 成本 */
// return $this->output->set_content_type('application/json')->set_output(json_encode($result));
$this->load->view('vendor_money_sum', $result);
return ;
}
}
/* End of file vendor_money.php */
/* Location: ./third_party/trippestOrderSync/controllers/vendor_money.php */

@ -74,6 +74,32 @@ class Trippest
return array($pag_code);
}
public function vendor_sourcetype()
{
return array(
// 北京图兰朵
"1343" => array(
"sourcetype" => "32090"
,"vendor_name" => "北京图兰朵"
)
// 上海图兰朵
,"29188" => array(
"sourcetype" => "32112"
,"vendor_name" => "上海图兰朵"
)
// 西安图兰朵
,"30548" => array(
"sourcetype" => "32116"
,"vendor_name" => "西安图兰朵"
)
// 桂林地接
,"628" => array(
"sourcetype" => "32122"
,"vendor_name" => "桂林地接"
)
);
}
}

@ -0,0 +1,126 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Vendor_money_model extends CI_Model {
function __construct() {
parent::__construct();
$this->load->helper('array');
$this->HT = $this->load->database('HT', TRUE);
bcscale(4);
}
public function checked_group_list($vendor, $sourcetype, $start_date, $end_date)
{
$sql = "SELECT sum_opi.COLI_OPI_ID,sum(sum_opi.海纳收款) as trippest_sum,sum(sum_opi.地接社收款) as vendor_sum
from (
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=$vendor
)*cgi_group.汇率 as cold_price_RMB,
*
from (
select
COLI_SN,
(select COUNT(0) from BIZ_ConfirmLineDetail
where COLD_COLI_SN=COLI_SN
and COLD_ServiceType='D'
) as service_cnt,
COLI.COLI_sourcetype,
COLI.COLI_Price,
coli.COLI_Currency,
case when coli.COLI_Price <> 0 then
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 汇率,
(select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo
where DeleteFlag=0 and GAI_COLI_SN=COLI_SN
) as 总收款,
(select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo
where DeleteFlag=0 and GAI_COLI_SN=COLI_SN
and GAI_Type not in (15017,15008,15006)
) as 海纳收款,
(select isnull(SUM(GAI_SSJE),0) from BIZ_GroupAccountInfo
where DeleteFlag=0 and GAI_COLI_SN=COLI_SN
and GAI_Type in (15017,15008,15006)
) as 地接社收款
,coli.COLI_OPI_ID
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
where 1=1
and CGI_ArriveDate between '$start_date' and '$end_date'
and exists (
select 1 from OperatorInfo where OPI_DEI_SN=30 and OPI_SN=CGI_OPI_SN
)
and CGI_Checked=1
and GRI_OrderType=227002
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 ";
$query = $this->HT->query($sql);
$opi_sum_money = $query->result_array();
return $opi_sum_money;
}
// Trippest自营订单,含地接代收的
public function trippest_order_with_vendormoney($vendor, $sourcetype, $start_date, $end_date)
{
$sql = "SELECT COLI_SN,coli_id,COLI_GroupCode,
convert(date,cgi.CGI_ArriveDate) CGI_ArriveDate,
COLI.COLI_sourcetype, COLI.COLI_Price, coli.COLI_Currency,
(SELECT isnull(SUM(GAI_SSJE),0)
FROM BIZ_GroupAccountInfo
WHERE DeleteFlag=0
AND GAI_COLI_SN=COLI_SN
AND GAI_Type IN (15017,
15008,
15006)) AS vendor_sum ,
coli.COLI_OPI_ID
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
WHERE 1=1
AND CGI_ArriveDate BETWEEN '$start_date' AND '$end_date'
AND EXISTS
(SELECT 1
FROM OperatorInfo
WHERE OPI_DEI_SN=30
AND OPI_SN=CGI_OPI_SN)
AND CGI_Checked=1
AND GRI_OrderType=227002
AND COLI_sourcetype=$sourcetype
AND COLI_OPI_ID <> 435
AND exists (
select 1 from BIZ_ConfirmLineDetail where COLD_COLI_SN=COLI_SN and COLD_PlanVEI_SN=$vendor
)
AND exists(
SELECT 1
FROM BIZ_GroupAccountInfo
WHERE DeleteFlag=0
AND GAI_COLI_SN=COLI_SN
AND GAI_SSJE>0
AND GAI_Type IN (15017,
15008,
15006)
)
ORDER BY cgi.CGI_ArriveDate ";
$query = $this->HT->query($sql);
// log_message('error',$sql);
// log_message('error',var_export($query->result_array(), 1));
return $query->result_array();
}
}
/* End of file vendor_money.php */
/* Location: ./third_party/trippestOrderSync/models/vendor_money.php */

File diff suppressed because one or more lines are too long

@ -0,0 +1,154 @@
<?php
/**
* 账单结算
*/
?>
<!DOCTYPE html>
<html>
<head>
<title>Trippest账单结算</title>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="referrer" content="always">
<link href="http://www.mycht.cn/css/webht/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="http://www.mycht.cn/css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" />
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css"> -->
<?php // include 'flatpickr.css.php'; ?>
<style type="text/css">
form{border-bottom: 1px solid #ccc;}
.navbar-header h1{display: inline-block;margin-left: 30px;margin-right: 30px;}
label {display: inline-block;max-width: none;margin-bottom: 5px;font-weight: bold; }
.form-check-label{font-weight: normal; margin-left: 5px;}
</style>
</head>
<body>
<div id="wrapper" class="chkVisible print-none">
<div class="navbar-header" style="float:none;border-bottom: 1px solid #ccc;">
<a class="navbar-brand text-muted" style="height: 52px;padding-top: 7px;padding-left: 30px;" href="http://www.mycht.cn/webht.php/index/index">
<img width="150" style="height:40px;" src="/css/nav/img/6000.png">
</a>
<h1>Trippest账单结算</h1>
</div>
</div>
<div class="container-fluid">
<p></p>
<form action="" method="POST" role="form">
<div class="form-group row">
<label for="" class="col-md-2">地接社</label>
<div class="">
<label class="form-check-label"><input type="checkbox" class="" name="vendors[]" id="" value="1343">北京图兰朵</label>
<label class="form-check-label"><input type="checkbox" class="" name="vendors[]" id="" value="29188">上海图兰朵</label>
<label class="form-check-label"><input type="checkbox" class="" name="vendors[]" id="" value="30548">西安图兰朵</label>
<label class="form-check-label"><input type="checkbox" class="" name="vendors[]" id="" value="628">桂林地接</label>
</div>
</div>
<div class="form-group row">
<label for="" class="col-md-2">发团日期</label>
<div class="col-md-3">
<input type="text" class="form-control" id="" placeholder="开始日期" required>
</div>
<div class="col-md-3">
<input type="text" class="form-control" id="" placeholder="结束日期">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
<p></p>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th rowspan="2">目的地</th>
<th colspan="2">总营收</th>
<th colspan="2">总成本</th>
<th rowspan="2">利润</th>
<th rowspan="2">海纳利润</th>
<th rowspan="2">地接利润</th>
<th rowspan="2">海纳应付地接</th>
</tr>
<tr>
<th >海纳代收</th>
<th >地接代收</th>
<th rowspan="2">海纳成本</th>
<th rowspan="2">地接成本</th>
</tr>
</thead>
<tbody>
<?php if ( ! empty($money)) {
foreach ($money as $kt => $trippest) {
?>
<tr>
<td><?php echo $trippest['vendor_name'] ?></td>
<td><?php echo $trippest['trippest']['trippest_sum'] ?></td>
<td><?php echo $trippest['trippest']['vendor_sum'] ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php }
} ?>
</tbody>
</table>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th rowspan="2">目的地</th>
<th colspan="2">总营收</th>
<th colspan="2">总成本</th>
<th rowspan="2">利润</th>
<th rowspan="2">海纳利润</th>
<th rowspan="2">地接利润</th>
<th rowspan="2">海纳应付地接</th>
</tr>
<tr>
<th >海纳代收</th>
<th >地接代收</th>
<th rowspan="2">海纳成本</th>
<th rowspan="2">地接成本</th>
</tr>
</thead>
<tbody>
<?php if ( ! empty($money)) {
foreach ($money as $kv => $vendor) {
?>
<tr>
<td><?php echo $vendor['vendor_name'] ?></td>
<td><?php echo $vendor['vendor']['trippest_sum'] ?></td>
<td><?php echo $vendor['vendor']['vendor_sum'] ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php }
} ?>
<?php if ( ! empty($trippest_order_vendor_money)) {
?>
<tr>
<th colspan="2">团号</th>
<th colspan="7">应扣除地接收款: 总计 <?php echo $transfer_sum ?></th>
</tr>
<?php foreach ($trippest_order_vendor_money as $ko => $order) {
?>
<tr>
<td colspan="2"><?php echo $order['COLI_GroupCode'] ?></td>
<td colspan="7"><?php echo $order["vendor_sum"] ?></td>
</tr>
<?php } } ?>
</tbody>
</table>
</div>
</body>
<script src="/js/jquery.min.js&v=20170811" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<script src="/js/jquery.form.min.js" type="text/javascript"></script>
</html>
Loading…
Cancel
Save