|
@@ -68,7 +68,7 @@ class OutBoundOrderService extends Service
|
|
|
->where('type', PurchaseOrderInfoForOutBound::type_one)
|
|
|
->update(['del_time' => $time]);
|
|
|
|
|
|
- //增加采购占用
|
|
|
+ //增加占用
|
|
|
$purchase_return = $msg[2] ?? [];
|
|
|
if(! empty($purchase_return)){
|
|
|
foreach ($purchase_return as $key => $value){
|
|
@@ -135,7 +135,7 @@ class OutBoundOrderService extends Service
|
|
|
ProductInventoryService::changeLockNumber($user,$msg[0],[]);
|
|
|
}
|
|
|
|
|
|
- //增加采购占用
|
|
|
+ //增加占用
|
|
|
$purchase_return = $msg[2] ?? [];
|
|
|
if(! empty($purchase_return)){
|
|
|
foreach ($purchase_return as $key => $value){
|
|
@@ -232,7 +232,7 @@ class OutBoundOrderService extends Service
|
|
|
]);
|
|
|
PurchaseOrderInfoForOutBound::where('del_time',0)
|
|
|
->where('data_id', $order['id'])
|
|
|
- ->where('type', 1)
|
|
|
+ ->where('type', PurchaseOrderInfoForOutBound::type_one)
|
|
|
->update(['del_time' => $time]);
|
|
|
// (new RangeService())->RangeDelete($order['id'],SeeRange::type_three);
|
|
|
|
|
@@ -354,7 +354,7 @@ class OutBoundOrderService extends Service
|
|
|
if($number > $s_number) return [false,'出库产品数量不能超过合同产品数量'];
|
|
|
}
|
|
|
|
|
|
- //校验采购单
|
|
|
+ //校验产品
|
|
|
list($status, $msg) = $this->checkPurchase($id,$data,$user);
|
|
|
if(! $status) return [false, $msg];
|
|
|
|
|
@@ -414,9 +414,12 @@ class OutBoundOrderService extends Service
|
|
|
->where('id', $data_id)
|
|
|
->first();
|
|
|
if(empty($sale)) return [false, '合同不存在或已被删除'];
|
|
|
- $sale = $sale->toArray();
|
|
|
- //仓库ID
|
|
|
- $storehouse = Storehouse::where('top_depart_id', $sale['top_depart_id'])->where('del_time',0)->value('id');
|
|
|
+
|
|
|
+ //当前所在门店
|
|
|
+ $top_depart_id = $user['depart_top'][0] ?? [];
|
|
|
+ $top_depart_id = $top_depart_id['depart_id'] ?? 0;
|
|
|
+ //门店所在仓库
|
|
|
+ $storehouse = Storehouse::where('top_depart_id', $top_depart_id)->where('del_time',0)->value('id');
|
|
|
|
|
|
$product = SalesOrderProductInfo::where('del_time',0)
|
|
|
->where('sales_order_id', $data_id)
|
|
@@ -429,6 +432,25 @@ class OutBoundOrderService extends Service
|
|
|
$service = new PurchaseOrderService();
|
|
|
$purchase = $service->getPurchaseProduct($product_id, $storehouse);
|
|
|
|
|
|
+ //盘点单产品
|
|
|
+ $service = new InventoryService();
|
|
|
+ $inventory = $service->getInventoryProduct($product_id, $storehouse);
|
|
|
+ $return_product = [];
|
|
|
+ foreach ($inventory as $key => $value){
|
|
|
+ if(! empty($value)){
|
|
|
+ foreach ($value as $val){
|
|
|
+ $return_product[$key][] = $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach ($purchase as $key => $value){
|
|
|
+ if(! empty($value)){
|
|
|
+ foreach ($value as $val){
|
|
|
+ $return_product[$key][] = $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//合同出库产品
|
|
|
$product_map = [];
|
|
|
$save = OutBoundOrderInfo::where('del_time',0)
|
|
@@ -491,6 +513,7 @@ class OutBoundOrderService extends Service
|
|
|
}
|
|
|
|
|
|
$tmp = $map[$value['product_id']] ?? [];
|
|
|
+
|
|
|
$return[] = [
|
|
|
'number' => $number, //可出数量
|
|
|
'out_number' => $p1, //已出库数量
|
|
@@ -504,7 +527,7 @@ class OutBoundOrderService extends Service
|
|
|
'code' => $tmp['code'] ?? "",
|
|
|
'size' => $tmp['size'] ?? "",
|
|
|
'unit' => $tmp['unit'] ?? "",
|
|
|
- 'purchase_product' => $purchase[$value['product_id']] ?? [],
|
|
|
+ 'purchase_product' => $return_product[$value['product_id']] ?? [],
|
|
|
];
|
|
|
}
|
|
|
|
|
@@ -519,14 +542,12 @@ class OutBoundOrderService extends Service
|
|
|
->where('id', $data_id)
|
|
|
->first();
|
|
|
if(empty($sale)) return [false, '合同不存在或已被删除'];
|
|
|
- $sale = $sale->toArray();
|
|
|
|
|
|
+ //当前所在门店
|
|
|
$top_depart_id = $user['depart_top'][0] ?? [];
|
|
|
$top_depart_id = $top_depart_id['depart_id'] ?? 0;
|
|
|
- list($status, $msg) = $this->returnOrderEditErrorCommon($top_depart_id,$sale['top_depart_id']);
|
|
|
- if(! $status) return [false, $msg];
|
|
|
-
|
|
|
- $storehouse = Storehouse::where('top_depart_id', $sale['top_depart_id'])->where('del_time',0)->value('id');
|
|
|
+ //门店所在仓库
|
|
|
+ $storehouse = Storehouse::where('top_depart_id', $top_depart_id)->where('del_time',0)->value('id');
|
|
|
if($storehouse_id && $storehouse_id != $storehouse) return [false, '出库仓库错误'];
|
|
|
|
|
|
$product = SalesOrderProductInfo::where('del_time',0)
|
|
@@ -630,25 +651,27 @@ class OutBoundOrderService extends Service
|
|
|
$purchase_product = [];
|
|
|
foreach ($data['product'] as $value){
|
|
|
$purchase = $value['purchase_product'] ?? [];
|
|
|
- if(empty($purchase)) return [false, '出库操作时,请选择出库的产品来源采购单'];
|
|
|
+ if(empty($purchase)) return [false, '出库操作时,请选择出库的产品来源单据'];
|
|
|
|
|
|
+ //产品明细校验
|
|
|
foreach ($purchase as $p_v){
|
|
|
//必须校验的内容
|
|
|
- if(empty($p_v['number'])) return [false, '采购单产品数量不能为空'];
|
|
|
+ if(empty($p_v['number'])) return [false, '订单产品数量不能为空'];
|
|
|
$res = $this->checkNumber($p_v['number']);
|
|
|
- if(! $res) return [false,'请输入正确的采购单产品数量'];
|
|
|
- if(empty($p_v['product_id'])) return [false, '采购单产品ID不能为空'];
|
|
|
+ if(! $res) return [false,'请输入正确的订单产品数量'];
|
|
|
+ if(empty($p_v['product_id'])) return [false, '订单产品ID不能为空'];
|
|
|
+ if(! isset($p_v['from_order_type']) || ! in_array($p_v['from_order_type'], PurchaseOrderInfoForOutBound::from_type)) return [false, '来源单据类型不存在或不正确'];
|
|
|
|
|
|
if($is_check_stock != ProductInventorySet::type_two){
|
|
|
//库存校验开启时 校验 需要采购单明细子表id
|
|
|
if(! isset($p_v['id'])) return [false, 'ID不能为空'];
|
|
|
if(! empty($p_v['id'])) {
|
|
|
- list($status, $msg) = $this->limitingSendRequestBackgExpire("purchaseOrderInfo" . $p_v['id']);
|
|
|
- if(! $status) return [false, '采购单产品处于出库操作中,请稍后'];
|
|
|
+ list($status, $msg) = $this->limitingSendRequestBackgExpire("ckOrderFromInfo" . $p_v['id'] . $p_v['from_order_type']);
|
|
|
+ if(! $status) return [false, '订单产品处于出库操作中,请稍后'];
|
|
|
}
|
|
|
if(! isset($p_v['purchase_order_id'])) return [false, 'purchaseOrderId不能为空'];
|
|
|
if(! isset($p_v['price'])) return [false, '采购单产品单价不能为空'];
|
|
|
- if(! isset($p_v['order_number'])) return [false, '采购单单号不能为空'];
|
|
|
+ if(! isset($p_v['order_number'])) return [false, '订单单号不能为空'];
|
|
|
}
|
|
|
|
|
|
$purchase_product[$value['product_id']] = [
|
|
@@ -660,8 +683,22 @@ class OutBoundOrderService extends Service
|
|
|
}
|
|
|
|
|
|
if($is_check_stock != ProductInventorySet::type_two){
|
|
|
- //库存校验开启时 校验 需要采购单产品数量
|
|
|
- list($status, $msg) = (new PurchaseOrderService())->checkPurchaseProductByPurchaseInfoID($id, $purchase_product);
|
|
|
+ list($status, $msg) = $this->checkOrderProductCommon($purchase_product);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+ //采购 盘点
|
|
|
+ list($purchase_id, $inventory_id) = $msg;
|
|
|
+
|
|
|
+ //库存校验开启时 校验 需要采购产品数量
|
|
|
+ list($status, $msg) = (new PurchaseOrderService())->checkPurchaseProductByPurchaseInfoID($id, $purchase_product,$purchase_id);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+ $purchase_count = $msg;
|
|
|
+
|
|
|
+ //库存校验开启时 校验 需要盘点盘盈产品数量
|
|
|
+ list($status, $msg) = (new InventoryService())->checkInventoryeProductByPurchaseInfoID($id, $purchase_product,$inventory_id);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+ $inventory_count = $msg;
|
|
|
+
|
|
|
+ list($status, $msg) = $this->checkOrderProductCommon2($purchase_count, $inventory_count, $purchase_product);
|
|
|
if(! $status) return [false, $msg];
|
|
|
}
|
|
|
|
|
@@ -671,6 +708,42 @@ class OutBoundOrderService extends Service
|
|
|
return [true, $return];
|
|
|
}
|
|
|
|
|
|
+ public function checkOrderProductCommon($product){
|
|
|
+ if(empty($product)) return [false, "出库产品来源单据不能为空"];
|
|
|
+
|
|
|
+ $purchase_id = $inventory_id = [];
|
|
|
+ foreach ($product as $value){
|
|
|
+ foreach ($value['from'] as $f_v){
|
|
|
+ if($f_v['from_order_type'] == PurchaseOrderInfoForOutBound::from_type_zero){
|
|
|
+ if(! in_array($f_v['purchase_order_id'], $purchase_id)) $purchase_id[] = $f_v['purchase_order_id'];
|
|
|
+ }elseif($f_v['from_order_type'] == PurchaseOrderInfoForOutBound::from_type_one){
|
|
|
+ if(! in_array($f_v['purchase_order_id'], $inventory_id)) $inventory_id[] = $f_v['purchase_order_id'];
|
|
|
+ }else{
|
|
|
+ return [false, '来源单据类型不正确'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(empty($purchase_id) && empty($inventory_id)) return [false, "出库产品来源单据数据不能为空"];
|
|
|
+
|
|
|
+ return [true, [$purchase_id, $inventory_id]];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function checkOrderProductCommon2($purchase_count, $inventory_count, $product){
|
|
|
+ if(empty($purchase_count) && empty($inventory_count)) return [false, '来源单据产品汇总数据为空'];
|
|
|
+
|
|
|
+ foreach ($product as $value){
|
|
|
+ $product_id = $value['product_id'];
|
|
|
+ $total = $value['total'];
|
|
|
+ $p_tmp = $purchase_count[$product_id] ?? 0;
|
|
|
+ $i_tmp = $inventory_count[$product_id] ?? 0;
|
|
|
+ $count_tmp = bcadd($p_tmp, $i_tmp, 2);
|
|
|
+
|
|
|
+ if(floatval($total) != floatval($count_tmp)) return [false, '出库数量需等于来源单据选择产品数量'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
public function returnProductData($product, $user, $storehouse_id){
|
|
|
$top_depart_id = $user['depart_top'][0] ?? [];
|
|
|
$my_top_depart_id = $top_depart_id['id'] ?? 0;
|
|
@@ -738,6 +811,7 @@ class OutBoundOrderService extends Service
|
|
|
'storehouse_id' => $storehouse_id,
|
|
|
'type' => PurchaseOrderInfoForOutBound::type_one,
|
|
|
'is_use' => PurchaseOrderInfoForOutBound::is_not_use,
|
|
|
+ 'from_order_type' => PurchaseOrderInfoForOutBound::from_type_zero
|
|
|
];
|
|
|
}else{
|
|
|
$return[] = [
|
|
@@ -750,6 +824,7 @@ class OutBoundOrderService extends Service
|
|
|
'storehouse_id' => $storehouse_id,
|
|
|
'type' => PurchaseOrderInfoForOutBound::type_one,
|
|
|
'is_use' => PurchaseOrderInfoForOutBound::is_not_use,
|
|
|
+ 'from_order_type' => $p_v['from_order_type']
|
|
|
];
|
|
|
}
|
|
|
}
|