cqpCow 2 年 前
コミット
5b5d1f4fa6

+ 47 - 59
app/Service/DeleteOrderService.php

@@ -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){

+ 1 - 1
app/Service/DispatchService.php

@@ -272,7 +272,7 @@ class DispatchService extends Service
         if($this->isEmpty($data,'process_id')) return [false,'工序不能为空!'];
 
         $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')
+            ->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')
             ->orderBy('id','desc')
             ->get()->toArray();
 

+ 20 - 18
app/Service/FinishedOrderService.php

@@ -137,14 +137,10 @@ class FinishedOrderService extends Service
             //反写数量
             $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
 
-            if(! empty($insert_sql_server)){
-                //生成产成品入库
-                $sqlServerModel = new FyySqlServerService();
-                list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($insert_sql_server);
-                if(! $status) {
-                    DB::rollBack();
-                    return [false,$msg];
-                }
+            list($status,$msg) = $this->insertSqlServer($insert_sql_server);
+            if(! $status) {
+                DB::rollBack();
+                return [false,$msg];
             }
 
             DB::commit();
@@ -211,7 +207,7 @@ class FinishedOrderService extends Service
         if($this->isEmpty($data,'finish_id') && $this->isEmpty($data,'team_id')) return [false,'人员和班组不能都为空!'];
 
         $result = DispatchSub::whereIn('id',$data['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')
+            ->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','price')
             ->orderBy('id','desc')
             ->get()->toArray();
 
@@ -410,14 +406,10 @@ class FinishedOrderService extends Service
             //反写数量
             $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
 
-            if(! empty($insert_sql_server)){
-                //生成产成品入库
-                $sqlServerModel = new FyySqlServerService();
-                list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($insert_sql_server);
-                if(! $status) {
-                    DB::rollBack();
-                    return [false,$msg];
-                }
+            list($status,$msg) = $this->insertSqlServer($insert_sql_server);
+            if(! $status) {
+                DB::rollBack();
+                return [false,$msg];
             }
 
             DB::commit();
@@ -444,7 +436,7 @@ class FinishedOrderService extends Service
         }
 
         $result = DispatchSub::whereIn('id',array_unique(array_column($data,'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')
+            ->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','price')
             ->orderBy('id','desc')
             ->get()->toArray();
 
@@ -454,4 +446,14 @@ class FinishedOrderService extends Service
 
         return [true, $result,$post];
     }
+
+    //产成品入库
+    public function insertSqlServer($array){return [true, ''];
+        if(empty($array)) return [true,''];
+
+        $sqlServerModel = new FyySqlServerService();
+        list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($array);
+
+        return [$status,$msg];
+    }
 }

+ 4 - 4
app/Service/FyySqlServerService.php

@@ -163,7 +163,7 @@ class FyySqlServerService extends Service
             ->leftJoin('SO_SODetails as b','b.cSOCode','a.cSOCode')
             ->whereBetween('a.dDate',[$start, $end])
             ->whereNotNull('a.cVerifier')
-            ->select('a.cSOCode as out_order_no','a.dDate as out_order_no_time','a.cCusCode as customer_no','a.cCusName as customer_name','a.cMemo as table_header_mark','a.cMaker as out_crt_man','a.cVerifier as out_checker_man','a.dverifydate as out_checker_time','b.cInvCode as product_no','b.iQuantity as order_quantity','b.cDefine28 as technology_material','b.cFree1 as technology_name','b.cFree2 as wood_name','b.cDefine30 as process_mark','b.cMemo as table_body_mark');
+            ->select('a.cSOCode as out_order_no','a.dDate as out_order_no_time','a.cCusCode as customer_no','a.cCusName as customer_name','a.cMemo as table_header_mark','a.cMaker as out_crt_man','a.cVerifier as out_checker_man','a.dverifydate as out_checker_time','b.cInvCode as product_no','b.iQuantity as order_quantity','b.cDefine28 as technology_material','b.cFree1 as technology_name','b.cFree2 as wood_name','b.cDefine30 as process_mark','b.cMemo as table_body_mark','b.iTaxUnitPrice as price');
 
         if(! empty($data['out_order_no'])) $model->where('a.cSOCode', 'LIKE', '%'.$data['out_order_no'].'%');
         if(! empty($data['customer_no'])) $model->where('a.cCusCode', 'LIKE', '%'.$data['customer_no'].'%');
@@ -299,8 +299,8 @@ class FyySqlServerService extends Service
                 "cbatch" => "",
                 "iquantity" => $value["quantity"],
                 "inum" => $value["quantity"],
-                "iunitcost" => "0",
-                "iprice" => "0",
+                "iunitcost" => $value["price"] * 0.95,
+                "iprice" => $value["price"] * 0.95 * $value['quantity'],
                 "iinvexchrate" => "1.00",
                 "impoids" => "",
                 "cmocode" => "",
@@ -331,7 +331,7 @@ class FyySqlServerService extends Service
                 "cwhcode"=>"02",
                 "cdepcode"=>"",
                 "crdcode"=>"",
-                "cmemo"=>"",
+                "cmemo"=>"来源:福羊羊完工操作",
                 "bodys"=>$bodys
             ]
         ];

+ 1 - 1
app/Service/ProductionOrderService.php

@@ -184,7 +184,7 @@ 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','production_quantity')
+            ->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','price')
             ->orderBy('id','desc')
             ->get()->toArray();