|
@@ -407,6 +407,45 @@ class ReportFormsService extends Service
|
|
return [true,$list];
|
|
return [true,$list];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function badGoodsReason($data){
|
|
|
|
+ $reason = $data['reason'] ?? "";
|
|
|
|
+
|
|
|
|
+ $scrapp = Scrapp::where('del_time',0)
|
|
|
|
+ ->when(! empty($reason), function ($query) use ($reason){
|
|
|
|
+ return $query->where('title', $reason);
|
|
|
|
+ })
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+ if(empty($scrapp)) return [true ,''];
|
|
|
|
+
|
|
|
|
+ $scrapp_count = ScrappCount::where('del_time',0)
|
|
|
|
+ ->whereIn('scrapp_id',array_keys($scrapp))
|
|
|
|
+ ->where('crt_time','>=',strtotime(date("Y-01-01 00:00:00")))
|
|
|
|
+ ->where('scrapp_num',">=",0)
|
|
|
|
+ ->select('scrapp_id as id',DB::raw("sum(scrapp_num) as waste"))
|
|
|
|
+ ->groupBy('scrapp_id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $sum = ! empty($scrapp_count) ? array_sum(array_column($scrapp_count,'waste')) : 0;
|
|
|
|
+ $scrapp_count_map = array_column($scrapp_count,'waste','id');
|
|
|
|
+
|
|
|
|
+ $return = [];
|
|
|
|
+ foreach ($scrapp as $id => $title){
|
|
|
|
+ $num = $scrapp_count_map[$id] ?? 0;
|
|
|
|
+ $rate = floatval($sum) > 0.0 ? bcmul(bcdiv($num, $sum,4),100,2) : 0 ;
|
|
|
|
+ $return[] = [
|
|
|
|
+ 'title' => $title,
|
|
|
|
+ 'num' => $num,
|
|
|
|
+ 'rate' => $rate . "%"
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ usort($return, function($a, $b) {
|
|
|
|
+ return $b['num'] <=> $a['num'];
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return [true, $return];
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 不良品
|
|
* 不良品
|
|
* @param $data
|
|
* @param $data
|
|
@@ -416,7 +455,7 @@ class ReportFormsService extends Service
|
|
if(empty($data['production_time'][0]) || empty($data['production_time'][1])) return [false, '生产订单时间必须选择!'];
|
|
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','id');
|
|
|
|
|
|
+ $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','technology_name');
|
|
$model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
|
|
$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['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]]);
|
|
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]]);
|
|
@@ -468,20 +507,23 @@ class ReportFormsService extends Service
|
|
$scrapp = ScrappCount::where('del_time',0)
|
|
$scrapp = ScrappCount::where('del_time',0)
|
|
->whereIn('order_product_id',$production_id)
|
|
->whereIn('order_product_id',$production_id)
|
|
->where('scrapp_num','>',0)
|
|
->where('scrapp_num','>',0)
|
|
- ->select('order_product_id','scrapp_num as bad_goods_num')
|
|
|
|
|
|
+ ->select('order_product_id','scrapp_num as bad_goods_num','technology_name')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
foreach ($scrapp as $value){
|
|
foreach ($scrapp as $value){
|
|
- if(isset($detail[$value['order_product_id']])){
|
|
|
|
- $tmp = bcadd($detail[$value['order_product_id']],$value['bad_goods_num'],3);
|
|
|
|
- $detail[$value['order_product_id']] = $tmp;
|
|
|
|
|
|
+ $key = $value['order_product_id'] . $value['technology_name'];
|
|
|
|
+ if(isset($detail[$key])){
|
|
|
|
+ $tmp = bcadd($detail[$key],$value['bad_goods_num'],3);
|
|
|
|
+ $detail[$key] = $tmp;
|
|
}else{
|
|
}else{
|
|
- $detail[$value['order_product_id']] = $value['bad_goods_num'];
|
|
|
|
|
|
+ $detail[$key] = $value['bad_goods_num'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//返回统计数据
|
|
//返回统计数据
|
|
foreach ($list as $key => $value) {
|
|
foreach ($list as $key => $value) {
|
|
- $del_num = $detail[$value['id']] ?? 0;
|
|
|
|
|
|
+ $n_key = $value['id'] . $value['technology_name'];
|
|
|
|
+
|
|
|
|
+ $del_num = $detail[$n_key] ?? 0;
|
|
if(floatval($del_num) <= 0.0) {
|
|
if(floatval($del_num) <= 0.0) {
|
|
unset($list[$key]);
|
|
unset($list[$key]);
|
|
continue;
|
|
continue;
|
|
@@ -489,7 +531,7 @@ class ReportFormsService extends Service
|
|
$list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
$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]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
$list[$key]['bad_goods_num'] = $del_num;
|
|
$list[$key]['bad_goods_num'] = $del_num;
|
|
- $list[$key]['rate'] = $value['production_quantity'] > 0 ? bcdiv($del_num ,$value['production_quantity'], 2) : 0;
|
|
|
|
|
|
+ $list[$key]['rate'] = $value['production_quantity'] > 0 ? bcdiv($del_num ,$value['production_quantity'], 4) : 0;
|
|
}
|
|
}
|
|
|
|
|
|
return [true,array_values($list)];
|
|
return [true,array_values($list)];
|
|
@@ -502,8 +544,10 @@ class ReportFormsService extends Service
|
|
*/
|
|
*/
|
|
public function badGoodsReportDetail($data){
|
|
public function badGoodsReportDetail($data){
|
|
if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
|
|
if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
|
|
|
|
+ if(empty($data['technology_name'])) return [false,'产品颜色不能为空!'];
|
|
|
|
|
|
$list = OrdersProduct::where('production_no',$data['production_no'])
|
|
$list = OrdersProduct::where('production_no',$data['production_no'])
|
|
|
|
+ ->where('technology_name',$data['technology_name'])
|
|
->select('id','production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','production_quantity','order_quantity')
|
|
->select('id','production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','production_quantity','order_quantity')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
|
|
|
@@ -561,7 +605,7 @@ class ReportFormsService extends Service
|
|
$list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
$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]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
$list[$key]['bad_goods_num'] = $detail[$value['id']] ?? 0;
|
|
$list[$key]['bad_goods_num'] = $detail[$value['id']] ?? 0;
|
|
- $list[$key]['rate'] = number_format($list[$key]['bad_goods_num'] / $value['production_quantity'], 2);
|
|
|
|
|
|
+ $list[$key]['rate'] = bcdiv($list[$key]['bad_goods_num'] ,$value['production_quantity'], 4);
|
|
$scrapp = $detail_scrapp[$value['id']] ?? '';
|
|
$scrapp = $detail_scrapp[$value['id']] ?? '';
|
|
$tmp_str = '';
|
|
$tmp_str = '';
|
|
if(! empty($scrapp)){
|
|
if(! empty($scrapp)){
|
|
@@ -585,7 +629,7 @@ class ReportFormsService extends Service
|
|
if(empty($data['production_time'][0]) || empty($data['production_time'][1])) return [false, '生产订单时间必须选择!'];
|
|
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','id');
|
|
|
|
|
|
+ $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','technology_name');
|
|
$model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
|
|
$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['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]]);
|
|
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]]);
|
|
@@ -618,14 +662,21 @@ class ReportFormsService extends Service
|
|
$scrapp = ScrappCount::where('del_time',0)
|
|
$scrapp = ScrappCount::where('del_time',0)
|
|
->whereIn('order_product_id',$production_id)
|
|
->whereIn('order_product_id',$production_id)
|
|
->where('scrapp_num','>',0)
|
|
->where('scrapp_num','>',0)
|
|
- ->select('order_product_id','scrapp_num as bad_goods_num')
|
|
|
|
|
|
+ ->select('order_product_id','scrapp_num as bad_goods_num','technology_name')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
foreach ($scrapp as $value){
|
|
foreach ($scrapp as $value){
|
|
- if(isset($detail[$value['order_product_id']])){
|
|
|
|
- $tmp = bcadd($detail[$value['order_product_id']],$value['bad_goods_num'],3);
|
|
|
|
- $detail[$value['order_product_id']] = $tmp;
|
|
|
|
|
|
+// if(isset($detail[$value['order_product_id']])){
|
|
|
|
+// $tmp = bcadd($detail[$value['order_product_id']],$value['bad_goods_num'],3);
|
|
|
|
+// $detail[$value['order_product_id']] = $tmp;
|
|
|
|
+// }else{
|
|
|
|
+// $detail[$value['order_product_id']] = $value['bad_goods_num'];
|
|
|
|
+// }
|
|
|
|
+ $key = $value['order_product_id'] . $value['technology_name'];
|
|
|
|
+ if(isset($detail[$key])){
|
|
|
|
+ $tmp = bcadd($detail[$key],$value['bad_goods_num'],3);
|
|
|
|
+ $detail[$key] = $tmp;
|
|
}else{
|
|
}else{
|
|
- $detail[$value['order_product_id']] = $value['bad_goods_num'];
|
|
|
|
|
|
+ $detail[$key] = $value['bad_goods_num'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// foreach ($out_time as $value){
|
|
// foreach ($out_time as $value){
|
|
@@ -648,9 +699,10 @@ class ReportFormsService extends Service
|
|
// }
|
|
// }
|
|
|
|
|
|
//返回统计数据
|
|
//返回统计数据
|
|
-
|
|
|
|
foreach ($list as $key => $value) {
|
|
foreach ($list as $key => $value) {
|
|
- $del_num = $detail[$value['id']] ?? 0;
|
|
|
|
|
|
+ $n_key = $value['id'] . $value['technology_name'];
|
|
|
|
+
|
|
|
|
+ $del_num = $detail[$n_key] ?? 0;
|
|
if(floatval($del_num) <= 0.0) {
|
|
if(floatval($del_num) <= 0.0) {
|
|
unset($list[$key]);
|
|
unset($list[$key]);
|
|
continue;
|
|
continue;
|
|
@@ -658,7 +710,7 @@ class ReportFormsService extends Service
|
|
$list[$key]['bad_goods_num'] = $del_num;
|
|
$list[$key]['bad_goods_num'] = $del_num;
|
|
$list[$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
$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]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
- $list[$key]['rate'] = $value['production_quantity'] > 0 ? bcdiv($del_num ,$value['production_quantity'], 2) : 0;
|
|
|
|
|
|
+ $list[$key]['rate'] = $value['production_quantity'] > 0 ? bcdiv($del_num ,$value['production_quantity'], 4) : 0;
|
|
}
|
|
}
|
|
|
|
|
|
return [true,array_values($list)];
|
|
return [true,array_values($list)];
|
|
@@ -667,8 +719,10 @@ class ReportFormsService extends Service
|
|
//不良品原因 详情
|
|
//不良品原因 详情
|
|
public function badGoodsReasonReportDetail($data){
|
|
public function badGoodsReasonReportDetail($data){
|
|
if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
|
|
if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
|
|
|
|
+ if(empty($data['technology_name'])) return [false,'产品颜色不能为空!'];
|
|
|
|
|
|
$list = OrdersProduct::where('production_no',$data['production_no'])
|
|
$list = OrdersProduct::where('production_no',$data['production_no'])
|
|
|
|
+ ->where('technology_name',$data['technology_name'])
|
|
->select('id','production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','production_quantity')
|
|
->select('id','production_time','production_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','production_quantity')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
|
|
|
@@ -682,6 +736,7 @@ class ReportFormsService extends Service
|
|
|
|
|
|
$scrapp = ScrappCount::where('del_time',0)
|
|
$scrapp = ScrappCount::where('del_time',0)
|
|
->whereIn('order_product_id',$order_product_id)
|
|
->whereIn('order_product_id',$order_product_id)
|
|
|
|
+ ->where('technology_name',$data['technology_name'])
|
|
->select('order_product_id','scrapp_num as bad_goods_num','scrapp_id','team_id','finished_id')
|
|
->select('order_product_id','scrapp_num as bad_goods_num','scrapp_id','team_id','finished_id')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
foreach ($scrapp as $value){
|
|
foreach ($scrapp as $value){
|
|
@@ -746,9 +801,9 @@ class ReportFormsService extends Service
|
|
$sum = 0;
|
|
$sum = 0;
|
|
$d_t = $detail[$value['id']] ?? [];
|
|
$d_t = $detail[$value['id']] ?? [];
|
|
if(! empty($d_t)) $sum = array_sum(array_column($d_t,'bad_goods_num'));
|
|
if(! empty($d_t)) $sum = array_sum(array_column($d_t,'bad_goods_num'));
|
|
- $list[$key]['rate'] = $value['production_quantity'] > 0 ? bcdiv($sum ,$value['production_quantity'], 2) * 100 ."%" : 0 ."%";
|
|
|
|
|
|
+ $list[$key]['rate'] = $value['production_quantity'] > 0 ? bcdiv($sum ,$value['production_quantity'], 4) * 100 ."%" : 0 ."%";
|
|
foreach ($d_t as $dk => $dv){
|
|
foreach ($d_t as $dk => $dv){
|
|
- $d_t[$dk]['rate'] = $value['production_quantity'] > 0 ? bcdiv($dv['bad_goods_num'] ,$value['production_quantity'], 2) * 100 . "%" : 0 . "%";
|
|
|
|
|
|
+ $d_t[$dk]['rate'] = $value['production_quantity'] > 0 ? bcdiv($dv['bad_goods_num'] ,$value['production_quantity'], 4) * 100 . "%" : 0 . "%";
|
|
$d_t[$dk]['scrapp_name'] = $map[$dv['scrapp_id']] ?? '';
|
|
$d_t[$dk]['scrapp_name'] = $map[$dv['scrapp_id']] ?? '';
|
|
$d_t[$dk]['team_name'] = $map1[$dv['team_id']] ?? '';
|
|
$d_t[$dk]['team_name'] = $map1[$dv['team_id']] ?? '';
|
|
$d_t[$dk]['man_name'] = $map2[$dv['finished_id']] ?? '';
|
|
$d_t[$dk]['man_name'] = $map2[$dv['finished_id']] ?? '';
|