|
@@ -75,9 +75,11 @@ class ProductionOrderService extends Service
|
|
|
}
|
|
|
OrdersProduct::insert($result);
|
|
|
|
|
|
+ //获取上一次插入订单的所有id
|
|
|
$last_insert_id = OrdersProduct::where('production_no',$production_no)->select('id')->get()->toArray();
|
|
|
$last_insert_id = array_column($last_insert_id,'id');
|
|
|
|
|
|
+ //组织process bom的数据 写入与主表的关联id
|
|
|
foreach ($result as $key => $value){
|
|
|
$quantity_tmp = $data['quantity'][$key];
|
|
|
|
|
@@ -107,6 +109,9 @@ class ProductionOrderService extends Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //反写已经生产数量
|
|
|
+ $this->writeProductionQuantity($data['id']);
|
|
|
+
|
|
|
foreach ($boom as $key => $value){
|
|
|
$boom_model = new OrdersProductBom(['channel'=> $key]);
|
|
|
$boom_model->insert($value);
|
|
@@ -172,15 +177,11 @@ class ProductionOrderService extends Service
|
|
|
if(in_array(false, $data['quantity'], true) || in_array(0, $data['quantity'], true) || in_array('', $data['quantity'], true))return [false,'数量不能为空!'];
|
|
|
|
|
|
$result = SaleOrdersProduct::whereIn('id',$data['id'])
|
|
|
- ->select('id as sale_orders_product_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')->get()->toArray();
|
|
|
- $map = $this->getProductionOrderQuantity(array_column($result,'sale_orders_product_id'));
|
|
|
+ ->select('id as sale_orders_product_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')->get()->toArray();
|
|
|
|
|
|
foreach ($result as $key => $value){
|
|
|
- if(isset($map[$value['sale_orders_product_id']])){
|
|
|
- if($map[$value['sale_orders_product_id']] + $data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
|
|
|
- }else{
|
|
|
- if($data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
|
|
|
- }
|
|
|
+ if($value['production_quantity'] + $data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
|
|
|
+ unset($result[$key]['production_quantity']);//删除销售订单的已生产数量
|
|
|
}
|
|
|
|
|
|
return [true, $result];
|
|
@@ -203,6 +204,26 @@ class ProductionOrderService extends Service
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+ //反写已生产数量
|
|
|
+ public function writeProductionQuantity($sale_orders_product_id){
|
|
|
+ if(empty($sale_orders_product_id)) return;
|
|
|
+
|
|
|
+ $result = OrdersProduct::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id',$sale_orders_product_id)
|
|
|
+ ->select(DB::raw("sum(production_quantity) as production_quantity"),'sale_orders_product_id')
|
|
|
+ ->groupby('sale_orders_product_id')
|
|
|
+ ->pluck('production_quantity','sale_orders_product_id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ if(empty($result)) return;
|
|
|
+
|
|
|
+ foreach ($result as $key => $value){
|
|
|
+ SaleOrdersProduct::where('id',$key)->update([
|
|
|
+ 'production_quantity' => $value
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//返回已生产数量
|
|
|
public function getProductionOrderQuantity($data){
|
|
|
if(empty($data)) return [];
|