|
@@ -382,7 +382,7 @@ class ReportFormsService extends Service
|
|
|
if(empty($data['production_time'][0]) || empty($data['production_time'][1])) return [false, '生产订单时间必须选择!'];
|
|
|
|
|
|
//检索条件 生产订单主表----------------
|
|
|
- $model = OrdersProduct::where('del_time',0)->select('production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','order_quantity','production_quantity','out_crt_man');
|
|
|
+ $model = OrdersProduct::where('del_time',0)->select('production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','order_quantity','production_quantity','out_crt_man','id');
|
|
|
$model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
|
|
|
if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
|
|
|
if(! empty($data['out_order_no_time'][0]) && ! empty($data['out_order_no_time'][1])) $model->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]]);
|
|
@@ -401,45 +401,44 @@ class ReportFormsService extends Service
|
|
|
//分组以后的订单列表
|
|
|
$list = [];
|
|
|
foreach ($orderList as $value){
|
|
|
- if(! isset($list[$value['production_no']])){
|
|
|
- $list[$value['production_no']] = $value;
|
|
|
+ if(! isset($list[$value['id']])){
|
|
|
+ $list[$value['id']] = $value;
|
|
|
}else{
|
|
|
- $list[$value['production_no']]['order_quantity'] += $value['order_quantity'];
|
|
|
- $list[$value['production_no']]['production_quantity'] += $value['production_quantity'];
|
|
|
+ $list[$value['id']]['order_quantity'] += $value['order_quantity'];
|
|
|
+ $list[$value['id']]['production_quantity'] += $value['production_quantity'];
|
|
|
}
|
|
|
}unset($orderList);
|
|
|
|
|
|
//查询分表数据
|
|
|
- $production_no = array_column($list,'production_no');
|
|
|
+ $production_id = array_keys($list);
|
|
|
$detail = [];
|
|
|
foreach ($out_time as $value){
|
|
|
//子表搜索
|
|
|
$models = new OrdersProductProcess(['channel' => $value]);
|
|
|
- $tmp = $models->whereIn('production_no',$production_no)
|
|
|
+ $tmp = $models->whereIn('order_product_id',$production_id)
|
|
|
->where('del_time',0)
|
|
|
->where('status',4)
|
|
|
- ->select('production_no',DB::raw('COUNT(id) as bad_goods_num'))
|
|
|
- ->groupBy('production_no')
|
|
|
+ ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'))
|
|
|
+ ->groupBy('order_product_id')
|
|
|
->get()->toArray();//不良品数据
|
|
|
|
|
|
foreach ($tmp as $t){
|
|
|
- if(isset($detail[$t['production_no']])){
|
|
|
- $detail[$t['production_no']]['bad_goods_num'] += $t['bad_goods_num'];
|
|
|
+ if(isset($detail[$t['order_product_id']])){
|
|
|
+ $detail[$t['order_product_id']]['bad_goods_num'] += $t['bad_goods_num'];
|
|
|
}else{
|
|
|
- $detail[$t['production_no']] = $t;
|
|
|
+ $detail[$t['order_product_id']] = $t['bad_goods_num'];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//返回统计数据
|
|
|
-
|
|
|
foreach ($list as $key => $value) {
|
|
|
$list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
|
$list[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
|
|
|
|
- $del_num = $detail[$value['production_no']] ?? 0;
|
|
|
+ $del_num = $detail[$value['id']] ?? 0;
|
|
|
$list[$key]['bad_goods_num'] = $del_num;
|
|
|
- $list[$key]['rate'] = number_format($del_num / $value['production_quantity'], 2);
|
|
|
+ $list[$key]['rate'] = bcdiv($del_num ,$value['production_quantity'], 2);
|
|
|
}
|
|
|
|
|
|
return [true,array_values($list)];
|
|
@@ -463,10 +462,11 @@ class ReportFormsService extends Service
|
|
|
$out_time = $this->checkSameQuarter($out_order_no_time);
|
|
|
|
|
|
$detail = $detail_scrapp = [];
|
|
|
+ $order_product_id = array_column($list,'id');
|
|
|
foreach ($out_time as $value){
|
|
|
//子表搜索
|
|
|
$models = new OrdersProductProcess(['channel' => $value]);
|
|
|
- $tmp = $models->where('production_no',$data['production_no'])
|
|
|
+ $tmp = $models->whereIn('order_product_id',$order_product_id)
|
|
|
->where('del_time',0)
|
|
|
->where('status',4)
|
|
|
->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'), DB::raw("GROUP_CONCAT(DISTINCT scrapp_id ORDER BY scrapp_id SEPARATOR ',') as scrapp_ids"))
|
|
@@ -488,8 +488,6 @@ class ReportFormsService extends Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
$scrapp_map = Scrapp::where('del_time',0)->pluck('title','id')->toArray();
|
|
|
foreach ($list as $key => $value) {
|
|
|
$list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
@@ -518,7 +516,7 @@ class ReportFormsService extends Service
|
|
|
if(empty($data['production_time'][0]) || empty($data['production_time'][1])) return [false, '生产订单时间必须选择!'];
|
|
|
|
|
|
//检索条件 生产订单主表----------------
|
|
|
- $model = OrdersProduct::where('del_time',0)->select('production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','order_quantity','production_quantity','out_crt_man');
|
|
|
+ $model = OrdersProduct::where('del_time',0)->select('production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','order_quantity','production_quantity','out_crt_man','id');
|
|
|
$model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
|
|
|
if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
|
|
|
if(! empty($data['out_order_no_time'][0]) && ! empty($data['out_order_no_time'][1])) $model->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]]);
|
|
@@ -537,32 +535,32 @@ class ReportFormsService extends Service
|
|
|
//分组以后的订单列表
|
|
|
$list = [];
|
|
|
foreach ($orderList as $value){
|
|
|
- if(! isset($list[$value['production_no']])){
|
|
|
- $list[$value['production_no']] = $value;
|
|
|
+ if(! isset($list[$value['id']])){
|
|
|
+ $list[$value['id']] = $value;
|
|
|
}else{
|
|
|
- $list[$value['production_no']]['order_quantity'] += $value['order_quantity'];
|
|
|
- $list[$value['production_no']]['production_quantity'] += $value['production_quantity'];
|
|
|
+ $list[$value['id']]['order_quantity'] += $value['order_quantity'];
|
|
|
+ $list[$value['id']]['production_quantity'] += $value['production_quantity'];
|
|
|
}
|
|
|
}unset($orderList);
|
|
|
|
|
|
//查询分表数据
|
|
|
- $production_no = array_column($list,'production_no');
|
|
|
+ $production_id = array_keys($list);
|
|
|
$detail = [];
|
|
|
foreach ($out_time as $value){
|
|
|
//子表搜索
|
|
|
$models = new OrdersProductProcess(['channel' => $value]);
|
|
|
- $tmp = $models->whereIn('production_no',$production_no)
|
|
|
+ $tmp = $models->whereIn('order_product_id',$production_id)
|
|
|
->where('del_time',0)
|
|
|
->where('status',4)
|
|
|
- ->select('production_no',DB::raw('COUNT(id) as bad_goods_num'))
|
|
|
- ->groupBy('production_no')
|
|
|
+ ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'))
|
|
|
+ ->groupBy('order_product_id')
|
|
|
->get()->toArray();//不良品数据
|
|
|
|
|
|
foreach ($tmp as $t){
|
|
|
- if(isset($detail[$t['production_no']])){
|
|
|
- $detail[$t['production_no']]['bad_goods_num'] += $t['bad_goods_num'];
|
|
|
+ if(isset($detail[$t['order_product_id']])){
|
|
|
+ $detail[$t['order_product_id']]['bad_goods_num'] += $t['bad_goods_num'];
|
|
|
}else{
|
|
|
- $detail[$t['production_no']] = $t;
|
|
|
+ $detail[$t['order_product_id']] = $t['bad_goods_num'];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -573,9 +571,9 @@ class ReportFormsService extends Service
|
|
|
$list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
|
$list[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
|
|
|
|
- $del_num = $detail[$value['production_no']] ?? 0;
|
|
|
+ $del_num = $detail[$value['id']] ?? 0;
|
|
|
$list[$key]['bad_goods_num'] = $del_num;
|
|
|
- $list[$key]['rate'] = number_format($del_num / $value['production_quantity'], 2);
|
|
|
+ $list[$key]['rate'] = bcdiv($del_num ,$value['production_quantity'], 2);
|
|
|
}
|
|
|
|
|
|
return [true,array_values($list)];
|
|
@@ -595,10 +593,11 @@ class ReportFormsService extends Service
|
|
|
$out_time = $this->checkSameQuarter($out_order_no_time);
|
|
|
|
|
|
$detail = $scrapp_id = $team = $man = [];
|
|
|
+ $order_product_id = array_column($list,'id');
|
|
|
foreach ($out_time as $value){
|
|
|
//子表搜索
|
|
|
$models = new OrdersProductProcess(['channel' => $value]);
|
|
|
- $tmp = $models->where('production_no',$data['production_no'])
|
|
|
+ $tmp = $models->where('order_product_id',$order_product_id)
|
|
|
->where('del_time',0)
|
|
|
->where('status',4)
|
|
|
->select('order_product_id','scrapp_id','team_id','finished_id',DB::raw('COUNT(id) as bad_goods_num'))
|
|
@@ -611,19 +610,18 @@ class ReportFormsService extends Service
|
|
|
if(! in_array($v['finished_id'], $man)) $man[] = $v['finished_id'];
|
|
|
if(isset($detail[$v['order_product_id']])){
|
|
|
foreach ($detail[$v['order_product_id']] as $k => $d){
|
|
|
- if($d['scrapp_id'] == $v['scrapp_id']){
|
|
|
+ if($k == $v['scrapp_id']){
|
|
|
$detail[$v['order_product_id']][$k]['bad_goods_num'] += $v['bad_goods_num'];
|
|
|
}else{
|
|
|
- $detail[$v['order_product_id']][] = $v;
|
|
|
+ $detail[$v['order_product_id']][$v['scrapp_id']] = $v;
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
- $detail[$v['order_product_id']][] = $v;
|
|
|
+ $detail[$v['order_product_id']][$v['scrapp_id']] = $v;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//次品原因 班组 人员
|
|
|
$map = Scrapp::whereIn('id',$scrapp_id)
|
|
|
->pluck('title','id')
|
|
@@ -637,15 +635,17 @@ class ReportFormsService extends Service
|
|
|
foreach ($list as $key => $value) {
|
|
|
$list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
|
$list[$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
|
- $list[$key]['rate'] = number_format(($detail[$value['id']] ?? 0) / $value['production_quantity'], 2);
|
|
|
- $del_tmp = $detail[$value['id']] ?? [];
|
|
|
- foreach ($del_tmp as $dk => $dv){
|
|
|
- $del_tmp[$dk]['rate'] = number_format($dv['bad_goods_num'] / $value['production_quantity'], 2);
|
|
|
- $del_tmp[$dk]['scrapp_name'] = $map[$dv['scrapp_id']] ?? '';
|
|
|
- $del_tmp[$dk]['team_name'] = $map1[$dv['team_id']] ?? '';
|
|
|
- $del_tmp[$dk]['man_name'] = $map2[$dv['finished_id']] ?? '';
|
|
|
+ $sum = 0;
|
|
|
+ $d_t = $detail[$value['id']] ?? [];
|
|
|
+ if(! empty($d_t)) $sum = array_sum(array_column($d_t,'bad_goods_num'));
|
|
|
+ $list[$key]['rate'] = bcdiv($sum ,$value['production_quantity'], 2) * 100 ."%";
|
|
|
+ foreach ($d_t as $dk => $dv){
|
|
|
+ $d_t[$dk]['rate'] = bcdiv($dv['bad_goods_num'] ,$value['production_quantity'], 2) * 100 . "%";
|
|
|
+ $d_t[$dk]['scrapp_name'] = $map[$dv['scrapp_id']] ?? '';
|
|
|
+ $d_t[$dk]['team_name'] = $map1[$dv['team_id']] ?? '';
|
|
|
+ $d_t[$dk]['man_name'] = $map2[$dv['finished_id']] ?? '';
|
|
|
}
|
|
|
- $list[$key]['bad_goods'] = $del_tmp;
|
|
|
+ $list[$key]['bad_goods'] = array_values($d_t);
|
|
|
}
|
|
|
return [true, $list];
|
|
|
}
|