|
|
@@ -1189,4 +1189,83 @@ where purch.islower=1');
|
|
|
}
|
|
|
ProcurementCheckSheet::query()->insert($insert);
|
|
|
}
|
|
|
+ public function addProcurementDeliverAndCheckMeet()
|
|
|
+ {
|
|
|
+ $id=ProcurementDeliverie::query()->orderByDesc('id')->value('id');
|
|
|
+ $sql=DB::raw('SELECT
|
|
|
+deliver.id id,request.id procurement_id,deliver.delivernum amount,deliver.status status,deliver.accepttime signed_at,
|
|
|
+deliver.createtime created_at,deliver.createtime updated_at,deliver.confirmnum receipt_amount
|
|
|
+from deliver
|
|
|
+LEFT JOIN purch on deliver.purchid=purch.id
|
|
|
+LEFT JOIN ask on purch.askid=ask.id
|
|
|
+LEFT JOIN request on ask.requestid=request.id
|
|
|
+where purch.islower=1 and deliver.id>'.$id);
|
|
|
+ $params = DB::connection('erp')->select($sql);
|
|
|
+ $insert=[];
|
|
|
+ foreach ($params as $param){
|
|
|
+ $insert[]=[
|
|
|
+ 'id'=>$param->id,
|
|
|
+ 'procurement_id'=>$param->procurement_id,
|
|
|
+ 'amount'=>$param->amount,
|
|
|
+ 'status'=>$param->status?$param->status-1:$param->status,
|
|
|
+ 'signed_at'=>Carbon::parse($param->signed_at)->toDateString(),
|
|
|
+ 'created_at'=>Carbon::parse($param->created_at)->toDateTimeString(),
|
|
|
+ 'updated_at'=>Carbon::parse($param->updated_at)->toDateTimeString(),
|
|
|
+ 'receipt_amount'=>$param->receipt_amount,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ ProcurementDeliverie::query()->insert($insert);
|
|
|
+
|
|
|
+ $procurement_delivers=ProcurementDeliverie::query()->where('id','>',$id)->get();
|
|
|
+ $dataHandlerService = app(DataHandlerService::class);
|
|
|
+ $procurement_delivers_map = $dataHandlerService->dataHeader(['procurement_id'], $procurement_delivers);
|
|
|
+ $sql=DB::raw('SELECT deliver.id id,request.id procurement_id,
|
|
|
+deliver.createtime created_at,deliver.createtime updated_at,purch.acceptnum amount,purch.acceptprice price
|
|
|
+from deliver
|
|
|
+LEFT JOIN purch on deliver.purchid=purch.id
|
|
|
+LEFT JOIN ask on purch.askid=ask.id
|
|
|
+LEFT JOIN request on ask.requestid=request.id
|
|
|
+where purch.islower=1 and deliver.id>'.$id);
|
|
|
+ $params=DB::connection('erp')->select($sql);
|
|
|
+ $insert_=[];
|
|
|
+ foreach ($params as $param){
|
|
|
+ $procurement_deliver = $dataHandlerService->getKeyValue(['procurement_id' => $param->procurement_id], $procurement_delivers_map);
|
|
|
+ if (!$procurement_deliver) continue;
|
|
|
+ $insert_[$param->procurement_id]=[
|
|
|
+ 'procurement_delivery_id'=>$procurement_deliver->id,
|
|
|
+ 'account_payable'=>$param->amount*$param->price,
|
|
|
+ 'status'=>0,
|
|
|
+ 'created_at'=>$param->created_at,
|
|
|
+ 'updated_at'=>$param->updated_at,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ ProcurementCheckSheet::query()->insert($insert_);
|
|
|
+ }
|
|
|
+ public function test111()
|
|
|
+ {
|
|
|
+ $status=0;
|
|
|
+ /*$procurements=Procurement::query()
|
|
|
+ ->withCount('procurementQuotations')
|
|
|
+ ->with('ownerMaterial.material')
|
|
|
+ ->where('status',$status)
|
|
|
+ ->get();*/
|
|
|
+// $a = DB::select(DB::raw(<<<sql
|
|
|
+//select `procurements`.*, (select count(*) from `procurement_quotations` where `procurements`.`id` = `procurement_quotations`.`procurement_id` and `supplier_id` in ('83')) as `procurement_quotations_count` from `procurements` where `status` = '0'
|
|
|
+//sql
|
|
|
+//));
|
|
|
+// dd($a);
|
|
|
+ dd($procurements=Procurement::query()
|
|
|
+ ->withCount('procurementQuotations')
|
|
|
+ ->with('ownerMaterial.material')
|
|
|
+ ->where('status',$status)->get());
|
|
|
+ $keys = [];
|
|
|
+ foreach ($procurements as $key=>$procurement){
|
|
|
+ if ($procurement->procurement_quotations_count>0 && $status==0 )$keys[]= $key;
|
|
|
+ if ($procurement->type==2 && $procurement->supplier_id )$keys[]= $key;
|
|
|
+ if (Carbon::parse($procurement->deadline)->gt(Carbon::now())) $procurement->deadline=Carbon::parse($procurement->deadline)->diffInMilliseconds();
|
|
|
+ else $procurement->deadline=0;
|
|
|
+ }
|
|
|
+ $procurements = $procurements->diffKeys($keys);
|
|
|
+ dd($procurements);
|
|
|
+ }
|
|
|
}
|