|
|
@@ -215,17 +215,26 @@ class ProcurementController extends Controller
|
|
|
{
|
|
|
$param=$request->all(['id','delivernum']);
|
|
|
$procurement_id=ProcurementDeliverie::query()->where('id',$param['id'])->first()['procurement_id'];
|
|
|
+ $deliverAmount=0;
|
|
|
+ $procurementDeliveries=ProcurementDeliverie::query()->where('procurement_id',$procurement_id)->get();
|
|
|
+ foreach ($procurementDeliveries as $delivery){
|
|
|
+ $deliverAmount+=(int)$delivery->amount;
|
|
|
+ }
|
|
|
+
|
|
|
$procurement=Procurement::query()->find($procurement_id);
|
|
|
$procurementDelivery=null;
|
|
|
if ($procurement){
|
|
|
if ($param['delivernum']>$procurement->quantity){
|
|
|
response()->json(['status'=>0,'message' => '送货数量大于采购数量','data'=>null], 401);
|
|
|
}
|
|
|
- if ($param['delivernum']<$procurement->quantity || $procurement->status==5){
|
|
|
+ if ($param['delivernum']==0){
|
|
|
+ response()->json(['status'=>0,'message' => '送货数量不能为零','data'=>null], 401);
|
|
|
+ }
|
|
|
+ if (($param['delivernum']+$deliverAmount) < $procurement->quantity && $procurement->status==5){
|
|
|
$procurementDelivery=ProcurementDeliverie::query()->where('id',$param['id'])->update(['amount'=>$param['delivernum']]);
|
|
|
if($procurementDelivery){
|
|
|
$procurementDeliver=new ProcurementDeliverie();
|
|
|
- $procurementDeliver['procurement_id']=$param['id'];
|
|
|
+ $procurementDeliver['procurement_id']=$procurement->id;
|
|
|
$procurementDeliver['amount']=((int)$procurement->quantity-(int)$param['delivernum']);
|
|
|
$procurementDeliver['initiator']=Auth::user()['id'];
|
|
|
$procurementDeliver['signer']=$procurement->initiator ?? 0;
|