|
@@ -9,6 +9,8 @@ use App\Model\ConstructionProductInfo;
|
|
|
use App\Model\Customer;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\SalesOrder;
|
|
|
+use App\Model\SalesOrderInfo;
|
|
|
+use App\Model\SalesOrderProductInfo;
|
|
|
use App\Model\Storehouse;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
@@ -427,6 +429,20 @@ class ConstructionService extends Service
|
|
|
$product_id[] = $value['product_id'];
|
|
|
}
|
|
|
|
|
|
+ //剩余能施工
|
|
|
+ $id = $data['id'] ?? 0;
|
|
|
+ $s_product = $this->getSaveReturnCompareMessage($id, $data['sales_order_id']);
|
|
|
+
|
|
|
+ //比较
|
|
|
+ foreach ($product_submit as $pro => $number){
|
|
|
+ $tmp = explode(',',$pro);
|
|
|
+ $p = $tmp[0];
|
|
|
+ if(! isset($s_product[$p])) return [false,'施工产品错误,合同中不存在该产品'];
|
|
|
+ $s_number = $s_product[$p];
|
|
|
+
|
|
|
+ if($number > $s_number) return [false,'施工产品数量不能超过合同产品数据'];
|
|
|
+ }
|
|
|
+
|
|
|
$id = $data['id'] ?? 0;
|
|
|
$product_save = $this->getSaveDetail($id);
|
|
|
list($status,$msg) = (new ProductInventoryService())->compareStock($product_id, $product_submit, $product_save);
|
|
@@ -525,4 +541,35 @@ class ConstructionService extends Service
|
|
|
|
|
|
return $product_save;
|
|
|
}
|
|
|
+
|
|
|
+ public function getSaveReturnCompareMessage($id = 0, $sales_order_id = 0){
|
|
|
+ $product_save = [];
|
|
|
+ $sub = ConstructionProductInfo::where('del_time',0)
|
|
|
+ ->when(! empty($id), function ($query) use ($id) {
|
|
|
+ return $query->where('construction_id', '<>',$id);
|
|
|
+ })
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($sub as $value){
|
|
|
+ if(isset($product_save[$value['product_id']])){
|
|
|
+ $product_save[$value['product_id']] += $value['number'];
|
|
|
+ }else{
|
|
|
+ $product_save[$value['product_id']] = $value['number'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $sales_order_product = [];
|
|
|
+ $sales_product = SalesOrderProductInfo::where('del_time',0)
|
|
|
+ ->where('sales_order_id',$sales_order_id)
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($sales_product as $value){
|
|
|
+ $product_save_tmp = $product_save[$value['product_id']] ?? 0;
|
|
|
+ if(isset($sales_order_product[$value['product_id']])){
|
|
|
+ $sales_order_product[$value['product_id']] += $value['number'];
|
|
|
+ }else{
|
|
|
+ $sales_order_product[$value['product_id']] = $value['number'] - $product_save_tmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $sales_order_product;
|
|
|
+ }
|
|
|
}
|