修复销售单品客户表错误
This commit is contained in:
parent
dcddd8e35a
commit
dc44127259
|
@ -28,9 +28,6 @@ return [
|
|||
],
|
||||
"delete" => [
|
||||
"name" => "删除"
|
||||
],
|
||||
"help" => [
|
||||
"name" => "帮助"
|
||||
]
|
||||
]
|
||||
],
|
||||
|
|
|
@ -1190,8 +1190,8 @@ class ReportController extends DefaultController
|
|||
'))
|
||||
->selectRaw('
|
||||
m.customer_id,
|
||||
product_category.code as category_code,
|
||||
product.code as product_code,
|
||||
product_category.code category_code,
|
||||
product.code product_code,
|
||||
customer.name customer_name,
|
||||
product.name product_name,
|
||||
product.spec product_spec,
|
||||
|
@ -1224,8 +1224,8 @@ class ReportController extends DefaultController
|
|||
'))
|
||||
->selectRaw('
|
||||
m.customer_id,
|
||||
product_category.code as category_code,
|
||||
product.code as product_code,
|
||||
product_category.code category_code,
|
||||
product.code product_code,
|
||||
customer.name customer_name,
|
||||
product.name product_name,
|
||||
product.spec product_spec,
|
||||
|
@ -1237,7 +1237,7 @@ class ReportController extends DefaultController
|
|||
'.sql_month('m.invoice_dt').' [month]
|
||||
');
|
||||
// 直营
|
||||
$cancel = DB::table('stock_direct_data as d')
|
||||
$direct = DB::table('stock_direct_data as d')
|
||||
->leftJoin('stock_direct as m', 'm.id', '=', 'd.direct_id')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('product_category', 'product_category.id', '=', 'product.category_id')
|
||||
|
@ -1259,8 +1259,8 @@ class ReportController extends DefaultController
|
|||
->selectRaw('
|
||||
m.customer_id,
|
||||
customer.name customer_name,
|
||||
product_category.code as category_code,
|
||||
product.code as product_code,
|
||||
product_category.code category_code,
|
||||
product.code product_code,
|
||||
product.name product_name,
|
||||
product.spec product_spec,
|
||||
d.product_id,
|
||||
|
@ -1273,31 +1273,32 @@ class ReportController extends DefaultController
|
|||
// 客户圈权限
|
||||
if ($selects['authorise']) {
|
||||
foreach ($selects['whereIn'] as $k => $v) {
|
||||
$direct->whereIn($k, $v);
|
||||
$cancel->whereIn($k, $v);
|
||||
$delivery->whereIn($k, $v);
|
||||
}
|
||||
}
|
||||
if ($category_id) {
|
||||
$direct->whereIn('product.category_id', $category);
|
||||
$delivery->whereIn('product.category_id', $category);
|
||||
$cancel->whereIn('product.category_id', $category);
|
||||
}
|
||||
$rows = $cancel->unionAll($delivery)
|
||||
$rows = $cancel->unionAll($delivery)->unionAll($direct)
|
||||
->orderBy('category_code', 'ASC')
|
||||
->get();
|
||||
|
||||
if ($rows->count()) {
|
||||
$single = [];
|
||||
foreach ($rows as $v) {
|
||||
if ($v['product_id'] > 0) {
|
||||
$month = $v['month'];
|
||||
$product_id = $v['product_id'];
|
||||
$single = [];
|
||||
foreach ($rows as $v) {
|
||||
if ($v['product_id'] > 0) {
|
||||
$month = $v['month'];
|
||||
$product_id = $v['product_id'];
|
||||
|
||||
$single['product'][$product_id] = $v;
|
||||
$single['category'][$product_id] = $v['category_id'];
|
||||
$single['customer'][$v['customer_id']] = $v['customer_id'];
|
||||
$single['all'][$product_id][$v['customer_id']] = $v['customer_id'];
|
||||
$single['sum'][$product_id][$month][$v['customer_id']] = $v['customer_id'];
|
||||
}
|
||||
$single['product'][$product_id] = $v;
|
||||
$single['category'][$product_id] = $v['category_id'];
|
||||
$single['customer'][$v['customer_id']] = $v['customer_id'];
|
||||
$single['all'][$product_id][$v['customer_id']] = $v['customer_id'];
|
||||
$single['sum'][$product_id][$month][$v['customer_id']] = $v['customer_id'];
|
||||
$single['sum_money'][$product_id][$month] += $v['money'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1324,80 +1325,173 @@ class ReportController extends DefaultController
|
|||
{
|
||||
$year = Request::get('year');
|
||||
$product_id = Request::get('product_id');
|
||||
$query = select::head1();
|
||||
|
||||
// 筛选专用函数
|
||||
$selects = regionCustomer('customer');
|
||||
|
||||
$n = date("n", time());
|
||||
|
||||
if ($product_id > 0) {
|
||||
$rows = DB::table('order_data as i')
|
||||
->leftJoin('order_type as t', 't.id', '=', 'i.type')
|
||||
->leftJoin('order as o', 'o.id', '=', 'i.order_id')
|
||||
->leftJoin('user as c', 'c.id', '=', 'o.client_id')
|
||||
->leftJoin('client', 'client.user_id', '=', 'c.id')
|
||||
->leftJoin('region as r', 'r.id', '=', 'c.city_id')
|
||||
->leftJoin('product as p', 'p.id', '=', 'i.product_id')
|
||||
->leftJoin('product_category as pc', 'pc.id', '=', 'p.category_id')
|
||||
->where('i.deleted', 0)
|
||||
->where('o.add_time', '>', 0)
|
||||
->where('p.id', $product_id)
|
||||
->whereRaw('FROM_UNIXTIME(o.add_time,"%Y")=?', [$year])
|
||||
//->whereRaw($sql, $params)
|
||||
->where('t.type', 1)
|
||||
//->groupBy('month')
|
||||
->groupBy('o.client_id')
|
||||
->orderBy('pc.lft', 'ASC')
|
||||
->orderBy('p.sort', 'ASC')
|
||||
->selectRaw('r.name city_name,client.circle_id,o.client_id,c.nickname company_name,p.name product_name,p.spec product_spec,i.product_id,p.category_id,SUM(i.amount * i.price) money,SUM(i.amount) amount,FROM_UNIXTIME(o.add_time,"%Y") year,FROM_UNIXTIME(o.add_time,"%c") month, pc.name category_name');
|
||||
|
||||
if ($query['whereIn']) {
|
||||
foreach ($query['whereIn'] as $key => $whereIn) {
|
||||
if ($whereIn) {
|
||||
$rows->whereIn($key, $whereIn);
|
||||
}
|
||||
// 发货
|
||||
$delivery = DB::table('stock_delivery_data as d')
|
||||
->leftJoin('stock_delivery as m', 'm.id', '=', 'd.delivery_id')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('product_category', 'product_category.id', '=', 'product.category_id')
|
||||
->leftJoin('customer', 'customer.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw('year(m.invoice_dt)=?', [$year])
|
||||
->groupBy(DB::raw('
|
||||
customer.name,
|
||||
product.name,
|
||||
product.spec,
|
||||
product.category_id,
|
||||
year(m.invoice_dt),
|
||||
month(m.invoice_dt),
|
||||
m.customer_id,
|
||||
d.product_id,
|
||||
product_category.code,
|
||||
product.code,
|
||||
customer.region_id
|
||||
'))
|
||||
->selectRaw('
|
||||
product_category.code category_code,
|
||||
product.code,
|
||||
m.customer_id,
|
||||
customer.name customer_name,
|
||||
product.name product_name,
|
||||
product.spec product_spec,
|
||||
d.product_id,
|
||||
product.category_id,
|
||||
sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money,
|
||||
SUM(d.quantity) quantity,
|
||||
year(m.invoice_dt) [year],
|
||||
month(m.invoice_dt) [month],
|
||||
customer.region_id
|
||||
');
|
||||
// 退货
|
||||
$cancel = DB::table('stock_cancel_data as d')
|
||||
->leftJoin('stock_cancel as m', 'm.id', '=', 'd.cancel_id')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('product_category', 'product_category.id', '=', 'product.category_id')
|
||||
->leftJoin('customer', 'customer.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw('year(m.invoice_dt)=?', [$year])
|
||||
->groupBy(DB::raw('
|
||||
customer.name,
|
||||
product.name,
|
||||
product.spec,
|
||||
product.category_id,
|
||||
year(m.invoice_dt),
|
||||
month(m.invoice_dt),
|
||||
m.customer_id,
|
||||
d.product_id,
|
||||
product_category.code,
|
||||
product.code,
|
||||
customer.region_id
|
||||
'))
|
||||
->selectRaw('
|
||||
product_category.code category_code,
|
||||
product.code,
|
||||
m.customer_id,
|
||||
customer.name customer_name,
|
||||
product.name product_name,
|
||||
product.spec product_spec,
|
||||
d.product_id,
|
||||
product.category_id,
|
||||
sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money,
|
||||
SUM(d.quantity) quantity,
|
||||
year(m.invoice_dt) [year],
|
||||
month(m.invoice_dt) [month],
|
||||
customer.region_id
|
||||
');
|
||||
// 直营
|
||||
$direct = DB::table('stock_direct_data as d')
|
||||
->leftJoin('stock_direct as m', 'm.id', '=', 'd.direct_id')
|
||||
->leftJoin('product', 'product.id', '=', 'd.product_id')
|
||||
->leftJoin('product_category', 'product_category.id', '=', 'product.category_id')
|
||||
->leftJoin('customer', 'customer.id', '=', 'm.customer_id')
|
||||
->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1')
|
||||
->whereRaw('year(m.invoice_dt)=?', [$year])
|
||||
->groupBy(DB::raw('
|
||||
customer.name,
|
||||
product.name,
|
||||
product.spec,
|
||||
product.category_id,
|
||||
year(m.invoice_dt),
|
||||
month(m.invoice_dt),
|
||||
m.customer_id,
|
||||
d.product_id,
|
||||
product_category.code,
|
||||
product.code,
|
||||
customer.region_id
|
||||
'))
|
||||
->selectRaw('
|
||||
product_category.code category_code,
|
||||
product.code,
|
||||
m.customer_id,
|
||||
customer.name customer_name,
|
||||
product.name product_name,
|
||||
product.spec product_spec,
|
||||
d.product_id,
|
||||
product.category_id,
|
||||
sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money,
|
||||
SUM(d.quantity) quantity,
|
||||
year(m.invoice_dt) [year],
|
||||
month(m.invoice_dt) [month],
|
||||
customer.region_id
|
||||
');
|
||||
// 客户圈权限
|
||||
if ($selects['authorise']) {
|
||||
foreach ($selects['whereIn'] as $k => $v) {
|
||||
$delivery->whereIn($k, $v);
|
||||
$direct->whereIn($k, $v);
|
||||
$cancel->whereIn($k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
$rows = $rows->get();
|
||||
$delivery->where('product.id', $product_id);
|
||||
$cancel->where('product.id', $product_id);
|
||||
$direct->where('product.id', $product_id);
|
||||
|
||||
$rows = $cancel->unionAll($delivery)->unionAll($direct)
|
||||
->orderBy('category_code', 'ASC')
|
||||
->get();
|
||||
|
||||
$circles = DB::table('customer_circle')->get()->pluck('name', 'id');
|
||||
$regions = DB::table('customer_region')->get()->pluck('name', 'id');
|
||||
$customers = [];
|
||||
|
||||
$single = array();
|
||||
foreach ($rows as $key => $value) {
|
||||
$single = [];
|
||||
foreach ($rows as $row) {
|
||||
//如何当前月存在数据
|
||||
$client_id = $value['client_id'];
|
||||
$customer_id = $row['customer_id'];
|
||||
//客户编号公司名称
|
||||
$clients[$client_id] = array(
|
||||
'client_id' => $value['company_name'],
|
||||
'area' => $value['city_name'],
|
||||
'circle_name' => $circles[$value['circle_id']],
|
||||
);
|
||||
$customers[$customer_id] = [
|
||||
'customer_id' => $row['customer_name'],
|
||||
'region_name' => $regions[$row['region_id']],
|
||||
];
|
||||
|
||||
if ($value['money'] > 0) {
|
||||
$single['all'][$client_id] += $value['money'];
|
||||
$single['cat'] = $value['category_name'];
|
||||
$single['name'] = $value['product_name'];
|
||||
$single['spec'] = $value['product_spec'];
|
||||
if ($row['money'] > 0) {
|
||||
$single['all'][$customer_id] += $row['money'];
|
||||
$single['product_code'] = $row['product_code'];
|
||||
$single['product_name'] = $row['product_name'];
|
||||
$single['product_spec'] = $row['product_spec'];
|
||||
}
|
||||
if ($value['month'] == $n) {
|
||||
if ($row['month'] == $n) {
|
||||
//筛选本月没有数量的客户
|
||||
$notpurchase[$client_id] = $value;
|
||||
$notpurchase[$customer_id] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arsort($single['all']);
|
||||
|
||||
return $this->display(array(
|
||||
return $this->display([
|
||||
'single' => $single,
|
||||
'years' => $years,
|
||||
'year' => $year,
|
||||
'year_id' => $year_id,
|
||||
'code_id' => $code_id,
|
||||
'month' => $n,
|
||||
'clients' => $clients,
|
||||
'customers' => $customers,
|
||||
'notpurchase'=> $notpurchase,
|
||||
'assess' => $assess,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="panel">
|
||||
|
||||
<div class="wrapper-sm b-b b-light">
|
||||
<div class="text-md">{{$year_id}}年度发生交易客户数[{{count((array)$single['customer'])}}]</div>
|
||||
<div class="text-md">{{$year}}年单品客户数({{count((array)$single['customer'])}})</div>
|
||||
</div>
|
||||
|
||||
<div class="wrapper-sm b-b b-light">
|
||||
|
@ -9,22 +9,26 @@
|
|||
<form class="form-inline" id="myquery" name="myquery" action="{{url()}}" method="get">
|
||||
|
||||
<div class="pull-right">
|
||||
<a class="btn btn-default btn-sm" onclick="LocalTableExport('report_export', '客户单品交易');"><i class="fa fa-mail-forward"></i> 导出</a>
|
||||
<a class="btn btn-default btn-sm" onclick="LocalTableExport('report_export', '销售单品客户表');"><i class="fa fa-mail-forward"></i> 导出</a>
|
||||
</div>
|
||||
|
||||
@if(Auth::user()->role->code != 'c001')
|
||||
@include('report/select')
|
||||
|
||||
@endif
|
||||
@include('report/select')
|
||||
|
||||
|
||||
<select class="form-control input-sm" id='year' name='year' data-toggle="redirect" data-url="{{$query}}">
|
||||
@if($years)
|
||||
@foreach($years as $v)
|
||||
<option value="{{$v}}" @if($select['query']['year']==$v) selected @endif>{{$v}}年</option>
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
|
||||
<select class="form-control input-sm" id='category_id' name='category_id' data-toggle="redirect" data-url="{{$query}}">
|
||||
<option value="0">全部品类</option>
|
||||
@foreach($categorys as $k => $v)
|
||||
<option value="{{$v['id']}}" @if($select['query']['category_id'] == $v['id']) selected @endif>{{$v['layer_space']}}{{$v['name']}}</option>
|
||||
@if($v['layer_level'] == 2)
|
||||
<option value="{{$v['id']}}" @if($select['query']['category_id'] == $v['id']) selected @endif>{{$v['name']}}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
|
@ -34,27 +38,51 @@
|
|||
|
||||
<table class="table table-bordered" id="report_export">
|
||||
<tr>
|
||||
<th>品类</th>
|
||||
<th>单品</th>
|
||||
<th>产品编码</th>
|
||||
<th>产品名称</th>
|
||||
|
||||
<th>总销售家数</th>
|
||||
<th></th>
|
||||
|
||||
<th>合计</th>
|
||||
|
||||
@if($months)
|
||||
@foreach($months as $k => $v)
|
||||
<th>{{$v}}月</th>
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
@if($single['sum'])
|
||||
@foreach($single['sum'] as $k => $v)
|
||||
<tr>
|
||||
<td align="center">{{$single['category'][$k]}}</td>
|
||||
<td align="left"><a href="{{url('clientdata')}}?aspect_id={{$select['select']['aspect_id']}}®ion_id={{$select['select']['region_id']}}&circle_id={{$select['select']['circle_id']}}&client_id={{$select['select']['client_id']}}&product_id={{$k}}&year={{$year}}">[查]</a> {{$single['product'][$k]['product_name']}} - {{$single['product'][$k]['product_spec']}}</td>
|
||||
<td align="right">{{sizeof($single['all'][$k])}}</td>
|
||||
<td align="center" rowspan="2">{{$single['product'][$k]['product_code']}}</td>
|
||||
<td align="left" rowspan="2"><a href="{{url('clientdata')}}?aspect_id={{$select['select']['aspect_id']}}®ion_id={{$select['select']['region_id']}}&circle_id={{$select['select']['circle_id']}}&client_id={{$select['select']['client_id']}}&product_id={{$k}}&year={{$year}}">[查]</a> {{$single['product'][$k]['product_name']}} - {{$single['product'][$k]['product_spec']}}</td>
|
||||
|
||||
<td align="right" style="vertical-align:middle;color:#999;">销售客户数</td>
|
||||
|
||||
<td align="right">{{count((array)$single['all'][$k])}}</td>
|
||||
@if($months)
|
||||
@foreach($months as $v2)
|
||||
<td align="right">
|
||||
{{:$sum = count((array)$v[$v2])}}
|
||||
@if($sum > 0) {{$sum}} @else <span style="color:#ccc;">0</span> @endif
|
||||
@if($sum>0) {{$sum}} @else @endif
|
||||
</td>
|
||||
@endforeach
|
||||
@endif
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="right" style="vertical-align:middle;color:#999;">销售金额</td>
|
||||
<td align="right" colspan="1">@number(array_sum((array)$single['sum_money'][$k]), 2)</td>
|
||||
@if($months)
|
||||
@foreach($months as $v2)
|
||||
<td align="right">
|
||||
@if($single['sum_money'][$k][$v2] > 0) @number($single['sum_money'][$k][$v2], 2) @else @endif
|
||||
</td>
|
||||
@endforeach
|
||||
@endif
|
||||
</tr>
|
||||
|
||||
@endforeach
|
||||
@endif
|
||||
</table>
|
||||
</div>
|
|
@ -1,27 +1,25 @@
|
|||
<div class="panel">
|
||||
|
||||
<div class="wrapper b-b b-light">
|
||||
<div class='h5'>{{$single['cat']}} * ({{$single['name']}} - {{$single['spec']}}) - {{$year}}年度({{$month}}月)未进货经销商列表</div>
|
||||
<div class="wrapper-xs b-b b-light">
|
||||
<div class='h5'>{{$single['product_name']}} - {{$single['product_spec']}} - {{$year}}年{{$month}}月无数据的客户列表</div>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th width="40">序号</th>
|
||||
<th width="100">区域</th>
|
||||
<th width="100">客户圈</th>
|
||||
<th width="60">序号</th>
|
||||
<th width="160">销售组</th>
|
||||
<th width="280">客户名称</th>
|
||||
<th align="left">单品</th>
|
||||
<th width="100"></th>
|
||||
</tr>
|
||||
@if(count($clients))
|
||||
@if($customers)
|
||||
<?php $i = 0; ?>
|
||||
@foreach($clients as $key => $value)
|
||||
@foreach($customers as $key => $value)
|
||||
@if(empty($notpurchase[$key]))
|
||||
<tr>
|
||||
<td align="center">{{$i + 1}}</td>
|
||||
<td align="center">{{$value['area']}}</td>
|
||||
<td align="center">{{$value['circle_name']}}</td>
|
||||
<td align="left">{{$value['client_id']}}</td>
|
||||
<td align="left">{{$single['name']}} - {{$single['spec']}}</td>
|
||||
<td align="center">{{$value['region_name']}}</td>
|
||||
<td align="left">{{$value['customer_id']}}</td>
|
||||
<td align="left"></td>
|
||||
</tr>
|
||||
@endif
|
||||
<?php $i++; ?>
|
||||
|
@ -33,28 +31,24 @@
|
|||
|
||||
<div class="panel">
|
||||
|
||||
<div class="wrapper b-b b-light">
|
||||
<div class='h5'>{{$single['cat']}} * ({{$single['name']}} - {{$single['spec']}}) - {{$year}}度年经销商销售分析</div>
|
||||
<div class="wrapper-xs b-b b-light">
|
||||
<div class='h5'>{{$single['product_name']}} - {{$single['product_spec']}} - {{$year}}年客户销售统计</div>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th width="40">序号</th>
|
||||
<th width="100">区域</th>
|
||||
<th width="100">客户圈</th>
|
||||
<th width="60">序号</th>
|
||||
<th width="160">销售组</th>
|
||||
<th width="280">客户名称</th>
|
||||
<th align="left">单品</th>
|
||||
<th width="100">金额</th>
|
||||
</tr>
|
||||
<?php $i = 0; ?>
|
||||
@if(count($single['all']))
|
||||
@if($single['all'])
|
||||
@foreach($single['all'] as $key => $value)
|
||||
<tr>
|
||||
<td align="center">{{$i + 1}}</td>
|
||||
<td align="center">{{$clients[$key]['area']}}</td>
|
||||
<td align="center">{{$clients[$key]['circle_name']}}</td>
|
||||
<td align="left">{{$clients[$key]['client_id']}}</td>
|
||||
<td align="left">{{$single['name']}} - {{$single['spec']}}</td>
|
||||
<td align="center">{{$customers[$key]['region_name']}}</td>
|
||||
<td align="left">{{$customers[$key]['customer_id']}}</td>
|
||||
<td align="right">{{$value}}</td>
|
||||
</tr>
|
||||
<?php $i++; ?>
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
<td align="right">项目权限</td>
|
||||
<td align="left">
|
||||
<select class="form-control input-sm" name="permission">
|
||||
<option value="0">公开</option>
|
||||
<option value="1">私有</option>
|
||||
<option value="0">公开</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
<td align="right">项目权限 <a href="javascript:;" class="fa fa-question-circle hinted" title="公开:所有人可以访问,成员编辑。私有:成员访问和编辑。"></a></td>
|
||||
<td align="left">
|
||||
<select class="form-control input-sm" name="permission">
|
||||
<option value="0" @if($project['permission'] == '0') selected="selected" @endif>公开</option>
|
||||
<option value="1" @if($project['permission'] == '1') selected="selected" @endif>私有</option>
|
||||
<option value="0" @if($project['permission'] == '0') selected="selected" @endif>公开</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue