|
@@ -51,13 +51,14 @@ class DispatchService extends Service
|
|
try{
|
|
try{
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
+ $time = time();
|
|
if($data['is_split']){
|
|
if($data['is_split']){
|
|
foreach ($msg as $value){
|
|
foreach ($msg as $value){
|
|
- list($s,$m) = $this->insertDispatch([$value],$data,$user);
|
|
|
|
|
|
+ list($s,$m) = $this->insertDispatch([$value],$data,$user,$time);
|
|
if(! $s) return [false,$m];
|
|
if(! $s) return [false,$m];
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
- list($s,$m) = $this->insertDispatch($msg,$data,$user);
|
|
|
|
|
|
+ list($s,$m) = $this->insertDispatch($msg,$data,$user,$time);
|
|
if(! $s) return [false, $m];
|
|
if(! $s) return [false, $m];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -67,7 +68,7 @@ class DispatchService extends Service
|
|
DB::commit();
|
|
DB::commit();
|
|
}catch (\Exception $e){
|
|
}catch (\Exception $e){
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
- return [false,$e->getLine().':'.$e->getMessage()];
|
|
|
|
|
|
+ return [false,$e->getFile() . ':' .$e->getLine().':'.$e->getMessage()];
|
|
}
|
|
}
|
|
|
|
|
|
return [true,''];
|
|
return [true,''];
|
|
@@ -147,10 +148,9 @@ class DispatchService extends Service
|
|
return $arr;
|
|
return $arr;
|
|
}
|
|
}
|
|
|
|
|
|
- public function insertDispatch($msg, $data, $user){
|
|
|
|
|
|
+ public function insertDispatch($msg, $data, $user, $time){
|
|
//生产数据的源数据
|
|
//生产数据的源数据
|
|
$result = $msg;
|
|
$result = $msg;
|
|
- $time = time();
|
|
|
|
|
|
|
|
$dispatch_no = $this->setOrderNO();
|
|
$dispatch_no = $this->setOrderNO();
|
|
if(! $dispatch_no) return [false,'单号生成失败!'];
|
|
if(! $dispatch_no) return [false,'单号生成失败!'];
|
|
@@ -161,39 +161,23 @@ class DispatchService extends Service
|
|
$time_tmp = date("Ymd", $data['out_order_no_time'][0]);
|
|
$time_tmp = date("Ymd", $data['out_order_no_time'][0]);
|
|
$process_model = new OrdersProductProcess(['channel' => $time_tmp]);
|
|
$process_model = new OrdersProductProcess(['channel' => $time_tmp]);
|
|
|
|
|
|
- $equipment_id = is_array($data['equipment_id']) ? $data['equipment_id'] : [$data['equipment_id']];
|
|
|
|
- $equipment_id = array_filter($equipment_id);
|
|
|
|
- $team_id = is_array($data['team_id']) ? $data['team_id'] : [$data['team_id']];
|
|
|
|
- $team_id = array_filter($team_id);
|
|
|
|
-
|
|
|
|
- $insert_emp_sub = [];
|
|
|
|
foreach ($result as $key => $value){
|
|
foreach ($result as $key => $value){
|
|
$result[$key]['dispatch_no'] = $dispatch_no;
|
|
$result[$key]['dispatch_no'] = $dispatch_no;
|
|
- $result[$key]['process_id'] = $data['process_id'];
|
|
|
|
- $result[$key]['dispatch_time_start'] = $data['dispatch_time'][0];
|
|
|
|
- $result[$key]['dispatch_time_end'] = $data['dispatch_time'][1];
|
|
|
|
- $result[$key]['dispatch_quantity'] = $value['quantity'];
|
|
|
|
$result[$key]['crt_time'] = $time;
|
|
$result[$key]['crt_time'] = $time;
|
|
$result[$key]['crt_id'] = $user['id'];
|
|
$result[$key]['crt_id'] = $user['id'];
|
|
|
|
|
|
- $tmp = $this->makeData($equipment_id,$team_id,$data['employee_id'],$result[$key]);
|
|
|
|
- $insert_emp_sub = array_merge_recursive($insert_emp_sub,$tmp);
|
|
|
|
-
|
|
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
- ->where('process_id',$data['process_id'])
|
|
|
|
|
|
+ ->where('process_id',$value['process_id'])
|
|
->where('dispatch_no','')
|
|
->where('dispatch_no','')
|
|
- ->take($value['quantity'])
|
|
|
|
|
|
+ ->take($value['dispatch_quantity'])
|
|
->update([
|
|
->update([
|
|
'dispatch_no' => $dispatch_no,
|
|
'dispatch_no' => $dispatch_no,
|
|
'status' => 1
|
|
'status' => 1
|
|
]);
|
|
]);
|
|
- unset($result[$key]['quantity']);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
DispatchSub::insert($result);
|
|
DispatchSub::insert($result);
|
|
|
|
|
|
- if(! empty($insert_emp_sub)) DispatchEmpSub::insert($insert_emp_sub);
|
|
|
|
-
|
|
|
|
return [true,''];
|
|
return [true,''];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -227,7 +211,7 @@ class DispatchService extends Service
|
|
if(! $status) return [false, $msg];
|
|
if(! $status) return [false, $msg];
|
|
|
|
|
|
$model = OrdersProduct::where('del_time',0)
|
|
$model = OrdersProduct::where('del_time',0)
|
|
- ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity','production_time','production_no','status','crt_id','dispatch_complete_quantity','pre_shipment_time')
|
|
|
|
|
|
+ ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity','production_time','production_no','status','crt_id','dispatch_complete_quantity','pre_shipment_time','process_id')
|
|
->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]])
|
|
->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]])
|
|
->whereIn('id',$msg)
|
|
->whereIn('id',$msg)
|
|
->orderBy('id','desc');
|
|
->orderBy('id','desc');
|
|
@@ -285,43 +269,75 @@ class DispatchService extends Service
|
|
}
|
|
}
|
|
|
|
|
|
public function orderRule($data){
|
|
public function orderRule($data){
|
|
- if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
|
- if($this->isEmpty($data,'quantity')) return [false,'请填写数量!'];
|
|
|
|
- if(in_array(false, $data['quantity'], true) || in_array(0, $data['quantity'], true) || in_array('', $data['quantity'], true))return [false,'数量不能为空!'];
|
|
|
|
- if(empty($data['dispatch_time'][0]) || empty($data['dispatch_time'][1])) return [false,'计划生产时间不能为空!'];
|
|
|
|
if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单时间不能为空!'];
|
|
if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单时间不能为空!'];
|
|
-// if($this->isEmpty($data,'process_id')) return [false,'工序不能为空!'];
|
|
|
|
if(! isset($data['is_split'])) return [false,'是否拆分标识不能为空!'];
|
|
if(! isset($data['is_split'])) return [false,'是否拆分标识不能为空!'];
|
|
|
|
+ if(empty($data['detail'])) return [false, '派工明细数据不能为空!'];
|
|
|
|
+ $id = [];
|
|
|
|
+ $detail_map = $detail_2 = [];
|
|
|
|
+ foreach ($data['detail'] as $value){
|
|
|
|
+ if(empty($value['id'])) return [false,'请选择派工数据!'];
|
|
|
|
+ if(empty($value['process_id'])) return [false,'工序不能为空!'];
|
|
|
|
+ if(! is_numeric($value['quantity']) || $value['quantity'] < 0) return [false,'数量不能小于0!'];
|
|
|
|
+ if(empty($value['dispatch_time'][0]) || empty($value['dispatch_time'][1])) return [false,'计划生产时间不能为空!'];
|
|
|
|
+ if(! in_array($value['id'], $id)) $id[] = $value['id'];
|
|
|
|
+ $key = $value['id'] . $value['process_id'];
|
|
|
|
+ if(isset($detail_map[$key])){
|
|
|
|
+ $detail_map[$key] += $value['quantity'];
|
|
|
|
+ }else{
|
|
|
|
+ $detail_map[$key] = $value['quantity'];
|
|
|
|
+ }
|
|
|
|
+ if(isset($detail_2[$value['id']][$value['process_id']])){
|
|
|
|
+ $detail_2[$value['id']][$value['process_id']] += $value['quantity'];
|
|
|
|
+ }else{
|
|
|
|
+ $detail_2[$value['id']][$value['process_id']] = $value['quantity'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- $result = OrdersProduct::whereIn('id',$data['id'])
|
|
|
|
- ->select('id as order_product_id','sale_orders_product_id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','production_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','sale_orders_product_id','out_order_no_time','price','customer_name','out_order_no','customer_no','pre_shipment_time')
|
|
|
|
|
|
+ $result = OrdersProduct::whereIn('id',$id)
|
|
|
|
+ ->select('id as order_product_id','sale_orders_product_id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','production_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','sale_orders_product_id','out_order_no_time','price','customer_name','out_order_no','customer_no','pre_shipment_time','process_id','production_no')
|
|
->orderBy('id','desc')
|
|
->orderBy('id','desc')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
$result_map = array_column($result,null,'order_product_id');
|
|
$result_map = array_column($result,null,'order_product_id');
|
|
|
|
|
|
|
|
+ //每个生产订单所有的工序
|
|
|
|
+ $process_map = $this->getProcess($result);
|
|
//已派工数据
|
|
//已派工数据
|
|
- $map = $this->getDispatchQuantity($data['id']);
|
|
|
|
-
|
|
|
|
- $total_map = $return = [];
|
|
|
|
- foreach ($data['id'] as $key => $value){
|
|
|
|
- if(isset($total_map[$value])){
|
|
|
|
- $total_map[$value] += $data['quantity'][$key];
|
|
|
|
- }else{
|
|
|
|
- $total_map[$value] = $data['quantity'][$key];
|
|
|
|
|
|
+ $map = $this->getDispatchQuantity($id);
|
|
|
|
+ //校验
|
|
|
|
+ foreach ($result as $value){
|
|
|
|
+ //总数量校验
|
|
|
|
+ $detail2 = $detail_2[$value['order_product_id']] ?? [];
|
|
|
|
+ $uniqueValuesCount = count(array_unique($detail2));
|
|
|
|
+ if($uniqueValuesCount != 1) return [false , "生产订单号:" . $value['production_no'] . "所有工序派工数量必须相等"];
|
|
|
|
+
|
|
|
|
+ //本次提交的工序
|
|
|
|
+// $submit_process = array_keys($detail2);
|
|
|
|
+
|
|
|
|
+ //工序
|
|
|
|
+ $tmp = $process_map[$value['order_product_id']] ?? [];
|
|
|
|
+ foreach ($tmp as $v) {
|
|
|
|
+// if(! in_array($v['process_id'], $submit_process)) continue;
|
|
|
|
+ //键值 生成订单id + 工序id
|
|
|
|
+ $key = $value['order_product_id'] . $v['process_id'];
|
|
|
|
+ //本次提交数量
|
|
|
|
+ $quantity_tmp = $detail_map[$key] ?? 0;
|
|
|
|
+ //工序已派工
|
|
|
|
+ $q = $map[$key] ?? 0;
|
|
|
|
+ if($q + $quantity_tmp > $value['production_quantity']) return [false, "生产订单号:" . $value['production_no'] . "的工序:" . $v['process_title'] . "的派单数量不能超过生产订单数量"];
|
|
}
|
|
}
|
|
- $tmp = $result_map[$value];
|
|
|
|
- $tmp['quantity'] = $data['quantity'][$key];
|
|
|
|
- $return[] = $tmp;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- foreach ($result as $key => $value){
|
|
|
|
- //数据校验
|
|
|
|
- $quantity_tmp = $total_map[$value['order_product_id']];
|
|
|
|
- if(isset($map[$value['order_product_id']])){
|
|
|
|
- if($map[$value['order_product_id']] + $quantity_tmp > $value['production_quantity']) return [false,'派单数量不能大于生产订单数量'];
|
|
|
|
- }else{
|
|
|
|
- if($quantity_tmp > $value['production_quantity']) return [false,'派单数量不能大于生产订单数量'];
|
|
|
|
- }
|
|
|
|
|
|
+ $return = [];
|
|
|
|
+ foreach ($data['detail'] as $value){
|
|
|
|
+ $tmp = $result_map[$value['id']] ?? [];
|
|
|
|
+ unset($tmp['process_id']);unset($tmp['production_no']);
|
|
|
|
+ $tmp['process_id'] = $value['process_id'];
|
|
|
|
+ $tmp['team_id'] = $value['team_id'];
|
|
|
|
+ $tmp['device_id'] = $value['device_id'];
|
|
|
|
+ $tmp['dispatch_time_start'] = $value['dispatch_time'][0];
|
|
|
|
+ $tmp['dispatch_time_end'] = $value['dispatch_time'][1];
|
|
|
|
+ $tmp['dispatch_quantity'] = $value['quantity'];
|
|
|
|
+ $return[] = $tmp;
|
|
}
|
|
}
|
|
|
|
|
|
return [true, $return];
|
|
return [true, $return];
|
|
@@ -335,13 +351,24 @@ class DispatchService extends Service
|
|
->pluck('emp_name','id')
|
|
->pluck('emp_name','id')
|
|
->toArray();
|
|
->toArray();
|
|
|
|
|
|
|
|
+ $process_map = $this->getProcess($data['data']);
|
|
|
|
+
|
|
foreach ($data['data'] as $key => $value){
|
|
foreach ($data['data'] as $key => $value){
|
|
|
|
+ $tmp = $process_map[$value['id']] ?? [];
|
|
|
|
+ foreach ($tmp as $t => $v) {
|
|
|
|
+ $q = $map[$value['id'] . $v['process_id']] ?? 0;
|
|
|
|
+ $tmp[$t]['dispatch_quantity'] = $q;
|
|
|
|
+ $tmp[$t]['not_dispatch_quantity'] = $value['production_quantity'] - $q;
|
|
|
|
+ }
|
|
|
|
+ $data['data'][$key]['process'] = $tmp;
|
|
|
|
+ $last_process = end($tmp);
|
|
|
|
+ $dispatch_quantity = $last_process['dispatch_quantity'] ?? 0;
|
|
|
|
+ $data['data'][$key]['dispatch_quantity'] = $dispatch_quantity;
|
|
|
|
+ $data['data'][$key]['not_dispatch_quantity'] = $value['production_quantity'] - $dispatch_quantity;
|
|
$data['data'][$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
$data['data'][$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
|
|
$data['data'][$key]['out_checker_time'] = $value['out_checker_time'] ? date('Y-m-d',$value['out_checker_time']) : '';
|
|
$data['data'][$key]['out_checker_time'] = $value['out_checker_time'] ? date('Y-m-d',$value['out_checker_time']) : '';
|
|
$data['data'][$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
$data['data'][$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
$data['data'][$key]['pre_shipment_time'] = $value['pre_shipment_time'] ? date('Y-m-d',$value['pre_shipment_time']) : '';
|
|
$data['data'][$key]['pre_shipment_time'] = $value['pre_shipment_time'] ? date('Y-m-d',$value['pre_shipment_time']) : '';
|
|
- $data['data'][$key]['dispatch_quantity'] = $map[$value['id']] ?? 0;
|
|
|
|
- $data['data'][$key]['not_dispatch_quantity'] = $value['production_quantity'] - ($map[$value['id']] ?? 0);
|
|
|
|
$data['data'][$key]['order_product_man'] = $emp_map[$value['crt_id']] ?? '';
|
|
$data['data'][$key]['order_product_man'] = $emp_map[$value['crt_id']] ?? '';
|
|
if($value['dispatch_complete_quantity'] >= $value['production_quantity']){
|
|
if($value['dispatch_complete_quantity'] >= $value['production_quantity']){
|
|
$data['data'][$key]['is_create'] = 1;
|
|
$data['data'][$key]['is_create'] = 1;
|
|
@@ -362,21 +389,69 @@ class DispatchService extends Service
|
|
|
|
|
|
$result = DispatchSub::where('del_time',0)
|
|
$result = DispatchSub::where('del_time',0)
|
|
->whereIn("order_product_id",$order_product_id)
|
|
->whereIn("order_product_id",$order_product_id)
|
|
- ->select(DB::raw("sum(dispatch_quantity) as dispatch_quantity"),'order_product_id')
|
|
|
|
- ->groupby('order_product_id')
|
|
|
|
- ->pluck('dispatch_quantity','order_product_id')
|
|
|
|
|
|
+ ->select('dispatch_quantity','order_product_id','process_id')
|
|
|
|
+ ->get()
|
|
->toArray();
|
|
->toArray();
|
|
|
|
|
|
- return $result;
|
|
|
|
|
|
+ $return = [];
|
|
|
|
+ foreach ($result as $value){
|
|
|
|
+ $key = $value['order_product_id'] . $value['process_id'];
|
|
|
|
+ if(isset($return[$key])){
|
|
|
|
+ $return[$key] += $value['dispatch_quantity'];
|
|
|
|
+ }else{
|
|
|
|
+ $return[$key] = $value['dispatch_quantity'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function getProcess($data){
|
|
|
|
+ if(empty($data)) return [];
|
|
|
|
+
|
|
|
|
+ $process_id_array = [];
|
|
|
|
+ $process_id = array_column($data,'process_id');
|
|
|
|
+ foreach ($process_id as $value){
|
|
|
|
+ $tmp = explode(',',$value);
|
|
|
|
+ foreach ($tmp as $v){
|
|
|
|
+ if(! in_array($v,$process_id_array)) $process_id_array[] = $v;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $process_array = Process::whereIn('id', $process_id_array)->get()->toArray();
|
|
|
|
+ $process_map = array_column($process_array,null,'id');
|
|
|
|
+
|
|
|
|
+ $return = [];
|
|
|
|
+ foreach ($data as $value){
|
|
|
|
+ $tmp = explode(',',$value['process_id']);
|
|
|
|
+ foreach ($tmp as $v){
|
|
|
|
+ $process_tmp = $process_map[$v] ?? [];
|
|
|
|
+ if(isset($value['id'])){
|
|
|
|
+ $return[$value['id']][] = [
|
|
|
|
+ 'process_id' => $v,
|
|
|
|
+ 'process_title' => $process_tmp['title'] ?? "",
|
|
|
|
+ 'team_id' => $process_tmp['team_id'] ?? 0,
|
|
|
|
+ 'device_id' => $process_tmp['device_id'] ?? 0,
|
|
|
|
+ ];
|
|
|
|
+ }else{
|
|
|
|
+ $return[$value['order_product_id']][] = [
|
|
|
|
+ 'process_id' => $v,
|
|
|
|
+ 'process_title' => $process_tmp['title'] ?? "",
|
|
|
|
+ 'team_id' => $process_tmp['team_id'] ?? 0,
|
|
|
|
+ 'device_id' => $process_tmp['device_id'] ?? 0,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $return;
|
|
}
|
|
}
|
|
|
|
|
|
public function dispatchOrderList($data){
|
|
public function dispatchOrderList($data){
|
|
$model = DispatchSub::where('del_time',0)
|
|
$model = DispatchSub::where('del_time',0)
|
|
- ->select('id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','production_quantity','dispatch_no','status','crt_id','process_id','dispatch_time_start','dispatch_time_end','crt_time','finished_num','waste_num','customer_name','order_product_id','out_order_no')
|
|
|
|
|
|
+ ->select('id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','production_quantity','dispatch_no','status','crt_id','process_id','dispatch_time_start','dispatch_time_end','crt_time','finished_num','waste_num','customer_name','order_product_id','out_order_no','team_id','device_id')
|
|
->orderBy('id','desc');
|
|
->orderBy('id','desc');
|
|
|
|
|
|
if(isset($data['finished_num'])) $model->where('finished_num', '>',0);
|
|
if(isset($data['finished_num'])) $model->where('finished_num', '>',0);
|
|
-
|
|
|
|
if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
|
|
if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
|
|
if(! empty($data['dispatch_no'])) $model->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%');
|
|
if(! empty($data['dispatch_no'])) $model->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%');
|
|
if(! empty($data['process_id'])) $model->where('process_id',$data['process_id']);
|
|
if(! empty($data['process_id'])) $model->where('process_id',$data['process_id']);
|
|
@@ -386,29 +461,14 @@ class DispatchService extends Service
|
|
$model->where('dispatch_time_start','<=',$data['dispatch_time'][0]);
|
|
$model->where('dispatch_time_start','<=',$data['dispatch_time'][0]);
|
|
$model->where('dispatch_time_end','>=',$data['dispatch_time'][1]);
|
|
$model->where('dispatch_time_end','>=',$data['dispatch_time'][1]);
|
|
}
|
|
}
|
|
- if(! empty($data['team_id'])) {
|
|
|
|
- $res = DispatchEmpSub::where('del_time',0)
|
|
|
|
- ->where('team_id',$data['team_id'])
|
|
|
|
- ->distinct()
|
|
|
|
- ->select('dispatch_no')
|
|
|
|
- ->get()->toArray();
|
|
|
|
- $model->whereIn('dispatch_no',array_column($res,'dispatch_no'));
|
|
|
|
- }
|
|
|
|
- if(! empty($data['equipment_id'])) {
|
|
|
|
- $res = DispatchEmpSub::where('del_time',0)
|
|
|
|
- ->where('equipment_id',$data['equipment_id'])
|
|
|
|
- ->distinct()
|
|
|
|
- ->select('dispatch_no')
|
|
|
|
- ->get()->toArray();
|
|
|
|
- $model->whereIn('dispatch_no',array_column($res,'dispatch_no'));
|
|
|
|
- }
|
|
|
|
- if(! empty($data['employee_id'])) {
|
|
|
|
- $res = DispatchEmpSub::where('del_time',0)
|
|
|
|
- ->where('employee_id',$data['employee_id'])
|
|
|
|
- ->distinct()
|
|
|
|
- ->select('dispatch_no')
|
|
|
|
- ->get()->toArray();
|
|
|
|
- $model->whereIn('dispatch_no',array_column($res,'dispatch_no'));
|
|
|
|
|
|
+ if(! empty($data['team_id'])) $model->where('team_id',$data['team_id']);
|
|
|
|
+ if(! empty($data['device_id'])) $model->whereIn('device_id',$data['device_id']);
|
|
|
|
+ if(isset($data['is_finished'])) {
|
|
|
|
+ if($data['is_finished']){
|
|
|
|
+ $model->wherecolumn('dispatch_quantity','=','finished_num');
|
|
|
|
+ }else{
|
|
|
|
+ $model->wherecolumn('dispatch_quantity','>','finished_num');
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
$list = $this->limit($model,'',$data);
|
|
$list = $this->limit($model,'',$data);
|
|
@@ -420,36 +480,12 @@ class DispatchService extends Service
|
|
public function fillDispatchOrderListData($data){
|
|
public function fillDispatchOrderListData($data){
|
|
if(empty($data['data'])) return $data;
|
|
if(empty($data['data'])) return $data;
|
|
|
|
|
|
- $emp_sub = DispatchEmpSub::where('del_time',0)
|
|
|
|
- ->whereIn('dispatch_no',array_column($data['data'],'dispatch_no'))
|
|
|
|
- ->select('dispatch_no','equipment_id','team_id','employee_id')
|
|
|
|
- ->get()->toArray();
|
|
|
|
- if(! empty($emp_sub)){
|
|
|
|
- $team_map = Team::whereIn('id',array_unique(array_column($emp_sub,'team_id')))
|
|
|
|
- ->pluck('title','id')
|
|
|
|
- ->toArray();
|
|
|
|
- $equipment_map = Equipment::whereIn('id',array_unique(array_column($emp_sub,'equipment_id')))
|
|
|
|
- ->pluck('title','id')
|
|
|
|
- ->toArray();
|
|
|
|
- $emp_map = Employee::whereIn('id',array_unique(array_column($emp_sub,'employee_id')))
|
|
|
|
- ->pluck('emp_name','id')
|
|
|
|
- ->toArray();
|
|
|
|
-
|
|
|
|
- $equipment_map1 = $team_map1 = $employee_map1 = $employee_map2 = $equipment_map2 = $team_map2 = [];
|
|
|
|
- foreach ($emp_sub as $value){
|
|
|
|
- $equipment_name = $equipment_map[$value['equipment_id']] ?? '';
|
|
|
|
- $team_name = $team_map[$value['team_id']] ?? '';
|
|
|
|
- $employee_name = $emp_map[$value['employee_id']] ?? '';
|
|
|
|
-
|
|
|
|
- $equipment_map1[$value['dispatch_no']][] = $equipment_name;
|
|
|
|
- $equipment_map2[$value['dispatch_no']][] = $value['equipment_id'];
|
|
|
|
- $team_map1[$value['dispatch_no']][] = $team_name;
|
|
|
|
- $team_map2[$value['dispatch_no']][] = $value['team_id'];
|
|
|
|
- $employee_map1[$value['dispatch_no']][] = $employee_name;
|
|
|
|
- $employee_map2[$value['dispatch_no']][] = $value['employee_id'];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ $team_map = Team::whereIn('id',array_unique(array_column($data['data'],'team_id')))
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+ $equipment_map = Equipment::whereIn('id',array_unique(array_column($data['data'],'device_id')))
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
$process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
|
|
$process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
|
|
->pluck('title','id')
|
|
->pluck('title','id')
|
|
->toArray();
|
|
->toArray();
|
|
@@ -461,19 +497,10 @@ class DispatchService extends Service
|
|
$time2 = $value['dispatch_time_end'] ? date('Y-m-d',$value['dispatch_time_end']) : '';
|
|
$time2 = $value['dispatch_time_end'] ? date('Y-m-d',$value['dispatch_time_end']) : '';
|
|
$data['data'][$key]['dispatch_time'] = $time1 . ' ' . $time2;
|
|
$data['data'][$key]['dispatch_time'] = $time1 . ' ' . $time2;
|
|
$data['data'][$key]['process_name'] = $process_map[$value['process_id']] ?? '';
|
|
$data['data'][$key]['process_name'] = $process_map[$value['process_id']] ?? '';
|
|
- $tmp = $employee_map1[$value['dispatch_no']] ?? [];
|
|
|
|
- $data['data'][$key]['team_man'] = implode(',',array_unique($tmp));
|
|
|
|
- $tmp = $employee_map2[$value['dispatch_no']] ?? [];
|
|
|
|
- $data['data'][$key]['team_man_id'] = array_unique($tmp);
|
|
|
|
- $tmp = $team_map1[$value['dispatch_no']] ?? [];
|
|
|
|
- $data['data'][$key]['team_name'] = implode(',',array_unique($tmp));
|
|
|
|
- $tmp = $team_map2[$value['dispatch_no']] ?? [];
|
|
|
|
- $data['data'][$key]['team_id'] = implode(',',array_unique($tmp));
|
|
|
|
- $tmp = $equipment_map1[$value['dispatch_no']] ?? [];
|
|
|
|
- $data['data'][$key]['equipment_name'] = implode(',',array_unique($tmp));
|
|
|
|
- $tmp = $equipment_map2[$value['dispatch_no']] ?? [];
|
|
|
|
- $data['data'][$key]['equipment_id'] = implode(',',array_unique($tmp));
|
|
|
|
- $data['data'][$key]['un_finished_quantity'] = $value['dispatch_quantity'] - $value['finished_num'] - $value['waste_num'];
|
|
|
|
|
|
+ $data['data'][$key]['team_name'] = $team_map[$value['team_id']] ?? "";
|
|
|
|
+ $data['data'][$key]['equipment_name'] = $equipment_map[$value['device_id']] ?? "";
|
|
|
|
+ $data['data'][$key]['equipment_id'] = $value['device_id'];
|
|
|
|
+ $data['data'][$key]['un_finished_quantity'] = $value['dispatch_quantity'] - $value['finished_num'];
|
|
}
|
|
}
|
|
$data['dispatch_quantity'] = array_sum(array_column($data['data'], 'dispatch_quantity'));
|
|
$data['dispatch_quantity'] = array_sum(array_column($data['data'], 'dispatch_quantity'));
|
|
|
|
|
|
@@ -484,18 +511,38 @@ class DispatchService extends Service
|
|
public function writeDispatchQuantity($order_product_id){
|
|
public function writeDispatchQuantity($order_product_id){
|
|
if(empty($order_product_id)) return;
|
|
if(empty($order_product_id)) return;
|
|
|
|
|
|
|
|
+ //最后一道工序
|
|
|
|
+ $last_process = [];
|
|
|
|
+ $process_id = OrdersProduct::whereIn('id',$order_product_id)
|
|
|
|
+ ->select('id','process_id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ foreach ($process_id as $value){
|
|
|
|
+ $tmp_process = explode(',', $value['process_id']);
|
|
|
|
+ $last_process[$value['id']] = end($tmp_process);
|
|
|
|
+ }
|
|
$result = DispatchSub::where('del_time',0)
|
|
$result = DispatchSub::where('del_time',0)
|
|
->whereIn('order_product_id',$order_product_id)
|
|
->whereIn('order_product_id',$order_product_id)
|
|
- ->select(DB::raw("sum(dispatch_quantity) as dispatch_quantity"),'order_product_id')
|
|
|
|
- ->groupby('order_product_id')
|
|
|
|
- ->pluck('dispatch_quantity','order_product_id')
|
|
|
|
|
|
+ ->select('dispatch_quantity','order_product_id','process_id')
|
|
|
|
+ ->get()
|
|
->toArray();
|
|
->toArray();
|
|
|
|
|
|
if(empty($result)) return;
|
|
if(empty($result)) return;
|
|
|
|
+ $new_result = [];
|
|
|
|
+ foreach ($result as $value){
|
|
|
|
+ //统计最后一道工序的派工数量
|
|
|
|
+ $tmp_last_process = $last_process[$value['order_product_id']];
|
|
|
|
+ if($tmp_last_process == $value['process_id']){
|
|
|
|
+ if(isset($new_result[$value['order_product_id']])){
|
|
|
|
+ $new_result[$value['order_product_id']] += $value['dispatch_quantity'];
|
|
|
|
+ }else{
|
|
|
|
+ $new_result[$value['order_product_id']] = $value['dispatch_quantity'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- foreach ($result as $key => $value){
|
|
|
|
- OrdersProduct::where('id',$key)->update([
|
|
|
|
- 'dispatch_complete_quantity' => $value
|
|
|
|
|
|
+ foreach ($new_result as $order_product_id => $num){
|
|
|
|
+ OrdersProduct::where('id',$order_product_id)->update([
|
|
|
|
+ 'dispatch_complete_quantity' => $num
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -504,15 +551,36 @@ class DispatchService extends Service
|
|
public function writeDispatchQuantityDEL($order_product_id){
|
|
public function writeDispatchQuantityDEL($order_product_id){
|
|
if(empty($order_product_id)) return;
|
|
if(empty($order_product_id)) return;
|
|
|
|
|
|
|
|
+ //最后一道工序
|
|
|
|
+ $last_process = [];
|
|
|
|
+ $process_id = OrdersProduct::whereIn('id',$order_product_id)
|
|
|
|
+ ->select('id','process_id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ foreach ($process_id as $value){
|
|
|
|
+ $tmp_process = explode(',', $value['process_id']);
|
|
|
|
+ $last_process[$value['id']] = end($tmp_process);
|
|
|
|
+ }
|
|
$result = DispatchSub::where('del_time',0)
|
|
$result = DispatchSub::where('del_time',0)
|
|
->whereIn('order_product_id',$order_product_id)
|
|
->whereIn('order_product_id',$order_product_id)
|
|
- ->select(DB::raw("sum(dispatch_quantity) as dispatch_quantity"),'order_product_id')
|
|
|
|
- ->groupby('order_product_id')
|
|
|
|
- ->pluck('dispatch_quantity','order_product_id')
|
|
|
|
|
|
+ ->select('dispatch_quantity','order_product_id','process_id')
|
|
|
|
+ ->get()
|
|
->toArray();
|
|
->toArray();
|
|
|
|
|
|
|
|
+ $new_result = [];
|
|
|
|
+ foreach ($result as $value){
|
|
|
|
+ //统计最后一道工序的派工数量
|
|
|
|
+ $tmp_last_process = $last_process[$value['order_product_id']];
|
|
|
|
+ if($tmp_last_process == $value['process_id']){
|
|
|
|
+ if(isset($new_result[$value['order_product_id']])){
|
|
|
|
+ $new_result[$value['order_product_id']] += $value['dispatch_quantity'];
|
|
|
|
+ }else{
|
|
|
|
+ $new_result[$value['order_product_id']] = $value['dispatch_quantity'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
foreach ($order_product_id as $value){
|
|
foreach ($order_product_id as $value){
|
|
- $quantity = $result[$value] ?? 0;
|
|
|
|
|
|
+ $quantity = $new_result[$value] ?? 0;
|
|
OrdersProduct::where('id',$value)->update([
|
|
OrdersProduct::where('id',$value)->update([
|
|
'dispatch_complete_quantity' => $quantity
|
|
'dispatch_complete_quantity' => $quantity
|
|
]);
|
|
]);
|