|
@@ -3,10 +3,8 @@
|
|
|
namespace App\Service;
|
|
|
|
|
|
use App\Model\Dispatch;
|
|
|
+use App\Model\DispatchEmpSub;
|
|
|
use App\Model\DispatchSub;
|
|
|
-use App\Model\FinishedOrder;
|
|
|
-use App\Model\FinishedOrderScrapp;
|
|
|
-use App\Model\FinishedOrderSub;
|
|
|
use App\Model\Orders;
|
|
|
use App\Model\OrdersProduct;
|
|
|
use App\Model\OrdersProductBom;
|
|
@@ -165,10 +163,11 @@ class DeleteOrderService extends Service
|
|
|
|
|
|
//派工单删除
|
|
|
public function delDispatch($id){
|
|
|
- $bool = FinishedOrderSub::where('del_time',0)
|
|
|
- ->whereIn('dispatch_id',$id)
|
|
|
+ $bool = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('id',$id)
|
|
|
+ ->where('finished_num','>',0)
|
|
|
->exists();
|
|
|
- if($bool) return [false,'工序派工单已生成工序完工单,删除失败!'];
|
|
|
+ if($bool) return [false,'工序派工单已有完工操作,删除失败!'];
|
|
|
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
@@ -207,6 +206,7 @@ class DeleteOrderService extends Service
|
|
|
$message = DispatchSub::whereIn('id',$id)->select('out_order_no_time','sale_orders_product_id','dispatch_no','dispatch_quantity','order_product_id','process_id')->get()->toArray();
|
|
|
if(! empty($message)){
|
|
|
date_default_timezone_set("PRC");
|
|
|
+
|
|
|
foreach ($message as $value){
|
|
|
$tmp_time = date('Ymd',$value['out_order_no_time']);
|
|
|
$modelProcess = new OrdersProductProcess(['channel' => $tmp_time]);
|
|
@@ -218,6 +218,12 @@ class DeleteOrderService extends Service
|
|
|
'dispatch_no' => '',
|
|
|
'status' => 0
|
|
|
]);
|
|
|
+
|
|
|
+ DispatchEmpSub::where('order_product_id',$value['order_product_id'])
|
|
|
+ ->where('dispatch_no',$value['dispatch_no'])
|
|
|
+ ->update([
|
|
|
+ 'del_time' => time()
|
|
|
+ ]);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -235,65 +241,47 @@ class DeleteOrderService extends Service
|
|
|
|
|
|
//完工单删除
|
|
|
public function delFinished($id){
|
|
|
+ $result = DispatchSub::whereIn('id',$id)
|
|
|
+ ->select('id','finished_num','dispatch_quantity','out_order_no_time','process_id','dispatch_no','order_product_id','sale_orders_product_id','order_no','product_no','product_title')
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
- //工序完工单
|
|
|
- FinishedOrderSub::whereIn('id',$id)->update([
|
|
|
- 'del_time' => time()
|
|
|
- ]);
|
|
|
-
|
|
|
- //工序完工单主表
|
|
|
- $subquery = DB::table('finished_order_sub')
|
|
|
- ->select('finished_no')
|
|
|
- ->whereIn('id',$id);
|
|
|
- $order_no = DB::table('finished_order_sub')
|
|
|
- ->select('finished_no','del_time')
|
|
|
- ->joinSub($subquery, 'sub', function ($join) {
|
|
|
- $join->on('finished_order_sub.finished_no', '=', 'sub.finished_no');
|
|
|
- })->get()->toArray();
|
|
|
- $update_order = [];
|
|
|
- if(! empty($order_no)){
|
|
|
- $tmp = [];
|
|
|
- foreach ($order_no as $value){
|
|
|
- if($value['del_time'] == 0){
|
|
|
- $tmp[] = $value['finished_no'];
|
|
|
- }else{
|
|
|
- $update_order[] = $value['finished_no'];
|
|
|
- }
|
|
|
- }
|
|
|
- $tmp = array_unique($tmp);
|
|
|
- $update_order = array_unique($update_order);
|
|
|
- $update_order = array_diff($update_order, $tmp);
|
|
|
- }
|
|
|
- if(! empty($update_order)) {
|
|
|
- FinishedOrder::from('finished_order as a')
|
|
|
- ->leftJoin('finished_order_scrapp as b','b.finished_order_id','a.id')
|
|
|
- ->whereIn('a.finished_no',$update_order)
|
|
|
- ->update(['a.del_time' => time(),'b.del_time' => time()]);
|
|
|
+ date_default_timezone_set('PRC');
|
|
|
+
|
|
|
+ foreach ($result as $value){
|
|
|
+ SaleOrdersProduct::where('id',$value['sale_orders_product_id'])->decrement('finished_num', $value['finished_num']);
|
|
|
+
|
|
|
+ $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
+
|
|
|
+ $process_model->where('order_product_id',$value['order_product_id'])
|
|
|
+ ->where('process_id',$value['process_id'])
|
|
|
+ ->where('dispatch_no',$value['dispatch_no'])
|
|
|
+ ->take($value['finished_num'])
|
|
|
+ ->update([
|
|
|
+ 'finished_time' => 0,
|
|
|
+ 'status' => 1,
|
|
|
+ 'finished_id' => 0,
|
|
|
+ 'team_id' => 0,
|
|
|
+ 'equipment_id' => 0
|
|
|
+ ]);
|
|
|
+ $process_model->where('order_product_id',$value['order_product_id'])
|
|
|
+ ->where('process_id',$value['process_id'])
|
|
|
+ ->where('dispatch_no',$value['dispatch_no'])
|
|
|
+ ->where('status',4)
|
|
|
+ ->update([
|
|
|
+ 'del_time' => time()
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
- //工序表
|
|
|
- $message = FinishedOrderSub::whereIn('id',$id)->select('out_order_no_time','finished_no','finished_num','order_product_id','process_id','dispatch_no','sale_orders_product_id')->get()->toArray();
|
|
|
- if(! empty($message)){
|
|
|
- date_default_timezone_set("PRC");
|
|
|
- foreach ($message as $value){
|
|
|
- $tmp_time = date('Ymd',$value['out_order_no_time']);
|
|
|
- $modelProcess = new OrdersProductProcess(['channel' => $tmp_time]);
|
|
|
- $modelProcess->where('order_product_id',$value['order_product_id'])
|
|
|
- ->where('process_id',$value['process_id'])
|
|
|
- ->where('finished_no',$value['finished_no'])
|
|
|
- ->where('dispatch_no',$value['dispatch_no'])
|
|
|
- ->take($value['finished_num'])
|
|
|
- ->update([
|
|
|
- 'finished_no' => '',
|
|
|
- 'status' => 1
|
|
|
- ]);
|
|
|
- }
|
|
|
- }
|
|
|
+ DispatchSub::whereIn('id',$id)->update([
|
|
|
+ 'finished_num' => 0,
|
|
|
+ 'waste_num' => 0
|
|
|
+ ]);
|
|
|
|
|
|
- //已完工数量
|
|
|
- (new FinishedOrderService())->writeFinishedQuantity(array_column($message,'sale_orders_product_id'));
|
|
|
+ //出库单生成 TODO
|
|
|
|
|
|
DB::commit();
|
|
|
}catch (\Throwable $e){
|