Trippest 账单结算汇总表格

feature/trippest
lyt 6 years ago
parent 08844a835b
commit e867d57e56

@ -9,33 +9,61 @@ class Vendor_money extends CI_Controller {
$this->load->helper('array');
$this->load->model('Vendor_money_model', 'money_model');
mb_regex_encoding("UTF-8");
bcscale(4);
bcscale(2);
}
public function index()
public function settlement()
{
$data['default_date1'] = date('Y-m-01', strtotime("last month"));
$data['default_date2'] = date('Y-m-d', mktime(0,0,0,date('m'),1,date('Y'))-1);
$this->load->view('vendor_money_sum', $data);
}
public function settlement()
public function index()
{
// $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
$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])) {
return $this->settlement();
}
$start_date = $date_range_arr[0][0];
$end_date =$date_range_arr[0][1];
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");
$vendor_sourcetype = $this->trippest->vendor_sourcetype();
$result = array(
"trippest_order_vendor_money" => array()
"default_date1" => $start_date
,"default_date2" => $end_date
,"trippest_order_vendor_money" => array()
,"transfer_sum" => 0
/** 列总计 */
,"col_sum" => array(
"trippest" => 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
),
"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
)
)
);
/** 团款 */
foreach (explode(",", $vendors) as $key => $vendor) {
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);
$ret = array(
@ -48,8 +76,7 @@ class Vendor_money extends CI_Controller {
array(
"trippest_sum" => 0,
"vendor_sum" => 0,
"transfer_sum" => 0,
"trippest_order_vendor_money" => null
"transfer_sum" => 0
)
);
// 按照海纳的算法
@ -79,8 +106,53 @@ class Vendor_money extends CI_Controller {
$result["money"][strval($vendor)] = $ret;
$result["money"][strval($vendor)]["vendor_code"] = $vendor;
$result["money"][strval($vendor)]["vendor_name"] = $vendor_sourcetype[strval($vendor)]["vendor_name"];
/** 团款合计 */
$result['col_sum']['trippest']['sum_trippest_sum'] = bcadd($result['col_sum']['trippest']['sum_trippest_sum'], $ret["trippest"]['trippest_sum']);
$result['col_sum']['trippest']['sum_vendor_sum'] = bcadd($result['col_sum']['trippest']['sum_vendor_sum'], $ret["trippest"]['vendor_sum']);
$result['col_sum']['vendor']['sum_trippest_sum'] = bcadd($result['col_sum']['vendor']['sum_trippest_sum'], $ret["vendor"]['trippest_sum']);
$result['col_sum']['vendor']['sum_vendor_sum'] = bcadd($result['col_sum']['vendor']['sum_vendor_sum'], $ret["vendor"]['vendor_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'];
}
}
// 成本总计
$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_vendor_cost'] = $result['col_sum']['vendor']['sum_vendor_cost'] = bcadd($result['col_sum']['trippest']['sum_vendor_cost'], $vm['vendor_cost']);
}
foreach ($result['money'] as $kmi => &$vmi) {
/** 利润 */
$vmi['trippest']['total_profit'] = bcsub(
bcadd($vmi['trippest']['trippest_sum'], $vmi['trippest']['vendor_sum']),
bcadd($vmi['trippest_cost'], $vmi['vendor_cost']));
$vmi['vendor']['total_profit'] = bcsub(
bcadd($vmi['vendor']['trippest_sum'], $vmi['vendor']['vendor_sum']),
bcadd($vmi['trippest_cost'], $vmi['vendor_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']);
}
// return $this->output->set_content_type('application/json')->set_output(json_encode($result));
$this->load->view('vendor_money_sum', $result);
return ;

@ -81,21 +81,25 @@ class Trippest
"1343" => array(
"sourcetype" => "32090"
,"vendor_name" => "北京图兰朵"
,"profit_rate" => 0.4
)
// 上海图兰朵
,"29188" => array(
"sourcetype" => "32112"
,"vendor_name" => "上海图兰朵"
,"profit_rate" => 0.4
)
// 西安图兰朵
,"30548" => array(
"sourcetype" => "32116"
,"vendor_name" => "西安图兰朵"
,"profit_rate" => 0.4
)
// 桂林地接
,"628" => array(
"sourcetype" => "32122"
,"vendor_name" => "桂林地接"
,"profit_rate" => 0.4
)
);
}

@ -113,11 +113,34 @@ class Vendor_money_model extends CI_Model {
)
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();
}
public function vendor_cost($vendor_str, $start_date, $end_date)
{
$sql = "SELECT group_cost.GCI_VEI_SN vendor_code,
SUM(group_cost.cost) vendor_cost
FROM
(SELECT DISTINCT gci.GCI_combineNo,
(SELECT SUM(CONVERT(float, gcod.GCOD_sumMoney))
FROM GroupCombineOperationDetail gcod
WHERE gcod.GCOD_GCI_combineNo=GCI_combineNo
AND gcod.GCOD_operationType <> 'otherReceives' ) AS cost ,
GCI_VEI_SN
FROM GroupCombineInfo gci
WHERE 1=1
AND GCI_VEI_SN IN ($vendor_str)
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')
) AS group_cost
GROUP BY group_cost.GCI_VEI_SN";
$query = $this->HT->query($sql);
return $query->result_array();
}
}

@ -6,7 +6,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Trippest账单结算</title>
<title>Trippest &amp; 地接账单结算</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">
@ -15,13 +15,17 @@
<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'; ?>
<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;}
thead th {text-align: center;}
tbody td {text-align: right;}
.text-left {text-align: left;}
.text-bold {font-weight: bold;}
</style>
</head>
<body>
@ -30,31 +34,31 @@
<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>
<h1>Trippest &amp; 地接账单结算</h1>
</div>
</div>
<div class="container-fluid">
<p></p>
<form action="" method="POST" role="form">
<form action="/webht.php/apps/trippestordersync/vendor_money/index" 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>
<label class="form-check-label"><input type="checkbox" class="" name="vendors[]" id="" value="1343" checked>北京图兰朵</label>
<label class="form-check-label"><input type="checkbox" class="" name="vendors[]" id="" value="29188" checked>上海图兰朵</label>
<label class="form-check-label"><input type="checkbox" class="" name="vendors[]" id="" value="30548" checked>西安图兰朵</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 class="col-md-6">
<input type="text" class="form-control" name="date_range" id="date_range" placeholder="选择日期范围" required>
</div>
<div class="col-md-3">
<input type="text" class="form-control" id="" placeholder="结束日期">
</div>
<!-- <input type="text" class="form-control" id="end_date" placeholder="结束日期"> -->
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
<p></p>
<table class="table table-bordered table-hover">
@ -63,16 +67,16 @@
<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>
<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>
<th >海纳代收</th>
<th >地接代收</th>
<th rowspan="2">海纳成本</th>
<th rowspan="2">地接成本</th>
</tr>
</thead>
<tbody>
@ -80,36 +84,51 @@
foreach ($money as $kt => $trippest) {
?>
<tr>
<td><?php echo $trippest['vendor_name'] ?></td>
<td class="text-left"><?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>
<td><?php echo $trippest['trippest_cost'] ?></td>
<td><?php echo $trippest['vendor_cost'] ?></td>
<td><?php echo $trippest['trippest']['total_profit'] ?></td>
<td><?php echo $trippest['trippest']['trippest_profit'] ?></td>
<td><?php echo $trippest['trippest']['vendor_profit'] ?></td>
<td><?php echo $trippest['trippest']['payout'] ?></td>
</tr>
<?php }
} ?>
<?php if ( ! empty($col_sum)) {
?>
<tr class="text-bold">
<td class="text-left">合计</td>
<td><?php echo $col_sum['trippest']['sum_trippest_sum'] ?></td>
<td><?php echo $col_sum['trippest']['sum_vendor_sum'] ?></td>
<td><?php echo $col_sum['trippest']['sum_trippest_cost'] ?></td>
<td><?php echo $col_sum['trippest']['sum_vendor_cost'] ?></td>
<td><?php echo $col_sum['trippest']['sum_profit'] ?></td>
<td><?php echo $col_sum['trippest']['sum_trippest_profit'] ?></td>
<td><?php echo $col_sum['trippest']['sum_vendor_profit'] ?></td>
<td><?php echo $col_sum['trippest']['sum_payout'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<p>旧的算法, 需扣除Trippest自营订单的地接代收款项:</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>
<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>
<th >海纳代收</th>
<th >地接代收</th>
<th rowspan="2">海纳成本</th>
<th rowspan="2">地接成本</th>
</tr>
</thead>
<tbody>
@ -117,38 +136,60 @@
foreach ($money as $kv => $vendor) {
?>
<tr>
<td><?php echo $vendor['vendor_name'] ?></td>
<td class="text-left"><?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>
<td><?php echo $vendor['trippest_cost'] ?></td>
<td><?php echo $vendor['vendor_cost'] ?></td>
<td><?php echo $vendor['vendor']['total_profit'] ?></td>
<td><?php echo $vendor['vendor']['trippest_profit'] ?></td>
<td><?php echo $vendor['vendor']['vendor_profit'] ?></td>
<td><?php echo $vendor['vendor']['payout'] ?></td>
</tr>
<?php }
} ?>
<?php if ( ! empty($col_sum)) {
?>
<tr class="text-bold">
<td class="text-left">合计</td>
<td><?php echo $col_sum['vendor']['sum_trippest_sum'] ?></td>
<td><?php echo $col_sum['vendor']['sum_vendor_sum'] ?></td>
<td><?php echo $col_sum['vendor']['sum_trippest_cost'] ?></td>
<td><?php echo $col_sum['vendor']['sum_vendor_cost'] ?></td>
<td><?php echo $col_sum['vendor']['sum_profit'] ?></td>
<td><?php echo $col_sum['vendor']['sum_trippest_profit'] ?></td>
<td><?php echo $col_sum['vendor']['sum_vendor_profit'] ?></td>
<td><?php echo $col_sum['vendor']['sum_payout'] ?></td>
</tr>
<?php } ?>
<?php if ( ! empty($trippest_order_vendor_money)) {
?>
<tr>
<tr class="text-bold">
<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>
<td colspan="2" class="text-left"><?php echo $order['COLI_GroupCode'] ?></td>
<td colspan="7" class="text-left"><?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/jquery.min.js" 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>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#date_range").flatpickr({
dateFormat: 'Y-m-d'
,mode: 'range'
,allowInput: true
,defaultDate:['<?php echo $default_date1 ?>', '<?php echo $default_date2 ?>']
});
})
</script>
</html>

Loading…
Cancel
Save