|
@@ -29,23 +29,28 @@ class ProcurementController extends Controller
|
|
|
{
|
|
{
|
|
|
use AsyncResponse;
|
|
use AsyncResponse;
|
|
|
|
|
|
|
|
- private function newProcurement($param){
|
|
|
|
|
|
|
+ private function newProcurement($param,$userId,$type=0,$status=0){
|
|
|
$procurement=new Procurement([
|
|
$procurement=new Procurement([
|
|
|
'owner_material_id'=>$param['owner_material_id'],
|
|
'owner_material_id'=>$param['owner_material_id'],
|
|
|
'quantity'=>$param['quantity'],
|
|
'quantity'=>$param['quantity'],
|
|
|
'amount'=>$param['amount'],
|
|
'amount'=>$param['amount'],
|
|
|
'unit_price'=>$param['unit_price'],
|
|
'unit_price'=>$param['unit_price'],
|
|
|
- 'initiator'=>Auth::user()['id'],
|
|
|
|
|
- 'type'=>0,
|
|
|
|
|
|
|
+ 'initiator'=>$userId,
|
|
|
|
|
+ 'type'=>$type,
|
|
|
|
|
+ 'status'=>$status,
|
|
|
]);
|
|
]);
|
|
|
$procurement->save();
|
|
$procurement->save();
|
|
|
$number_id=$procurement['id'];
|
|
$number_id=$procurement['id'];
|
|
|
$procurement_code='BSHC';
|
|
$procurement_code='BSHC';
|
|
|
$procurement_code .= date ("ymd").str_pad($number_id>99999?$number_id%99999:$number_id,4,"0",STR_PAD_LEFT);
|
|
$procurement_code .= date ("ymd").str_pad($number_id>99999?$number_id%99999:$number_id,4,"0",STR_PAD_LEFT);
|
|
|
- $procurement->update(['code'=>$procurement_code]);
|
|
|
|
|
|
|
+ /** @var ProcurementService $procurementService*/
|
|
|
|
|
+ $procurementService=app(ProcurementService::class);
|
|
|
|
|
+ $deadline=$procurementService->computeDeadline($procurement->created_at);
|
|
|
|
|
+ $procurement->update(['code'=>$procurement_code,'deadline'=>$deadline]);
|
|
|
return $procurement;
|
|
return $procurement;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
public function index(Request $request,ProcurementFilters $filters)
|
|
public function index(Request $request,ProcurementFilters $filters)
|
|
|
{
|
|
{
|
|
|
if(!Gate::allows('采购管理-采购-查询')){ return ["success"=>false,"data"=>"您无此权限操作!"]; }
|
|
if(!Gate::allows('采购管理-采购-查询')){ return ["success"=>false,"data"=>"您无此权限操作!"]; }
|
|
@@ -80,7 +85,7 @@ class ProcurementController extends Controller
|
|
|
{
|
|
{
|
|
|
$this->gate('采购管理-采购-新建');
|
|
$this->gate('采购管理-采购-新建');
|
|
|
$param=$request->all(['owner_material_id','quantity','amount','unit_price']);
|
|
$param=$request->all(['owner_material_id','quantity','amount','unit_price']);
|
|
|
- $procurement=$this->newProcurement($param);
|
|
|
|
|
|
|
+ $procurement=$this->newProcurement($param,Auth::user()['id']);
|
|
|
return redirect('procurement/procurement/index')->with('successTip','新采购单“'.$procurement->code.'”添加成功');
|
|
return redirect('procurement/procurement/index')->with('successTip','新采购单“'.$procurement->code.'”添加成功');
|
|
|
}
|
|
}
|
|
|
public function createProcurement(ProcurementRequest $request)
|
|
public function createProcurement(ProcurementRequest $request)
|
|
@@ -89,7 +94,7 @@ class ProcurementController extends Controller
|
|
|
$request->validated();
|
|
$request->validated();
|
|
|
$param=$request->all(['owner_material_id','quantity','amount','unit_price']);
|
|
$param=$request->all(['owner_material_id','quantity','amount','unit_price']);
|
|
|
try {
|
|
try {
|
|
|
- $procurement=$this->newProcurement($param);
|
|
|
|
|
|
|
+ $procurement=$this->newProcurement($param,Auth::user()['id']);
|
|
|
$procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
$procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
|
if ($procurement) return ['success' => true,'data' => $procurement];
|
|
if ($procurement) return ['success' => true,'data' => $procurement];
|
|
|
else return ['success' => false, 'message' => '添加失败'];
|
|
else return ['success' => false, 'message' => '添加失败'];
|
|
@@ -111,14 +116,18 @@ class ProcurementController extends Controller
|
|
|
'unit_price'=>0,
|
|
'unit_price'=>0,
|
|
|
'initiator'=>Auth::user()['id'],
|
|
'initiator'=>Auth::user()['id'],
|
|
|
'type'=>1,
|
|
'type'=>1,
|
|
|
- 'status'=>9,
|
|
|
|
|
- //'is_enquiry'=>'是',
|
|
|
|
|
|
|
+ 'status'=>0,
|
|
|
|
|
+ 'is_enquiry'=>'是',
|
|
|
|
|
+ 'time'=>14400000,
|
|
|
]);
|
|
]);
|
|
|
$procurement->save();
|
|
$procurement->save();
|
|
|
$number_id=$procurement['id'];
|
|
$number_id=$procurement['id'];
|
|
|
$procurement_code='BSHC';
|
|
$procurement_code='BSHC';
|
|
|
$procurement_code .= date ("ymd").str_pad($number_id>99999?$number_id%99999:$number_id,4,"0",STR_PAD_LEFT);
|
|
$procurement_code .= date ("ymd").str_pad($number_id>99999?$number_id%99999:$number_id,4,"0",STR_PAD_LEFT);
|
|
|
- $procurement->update(['code'=>$procurement_code]);
|
|
|
|
|
|
|
+ /** @var ProcurementService $procurementService*/
|
|
|
|
|
+ $procurementService=app(ProcurementService::class);
|
|
|
|
|
+ $deadline=$procurementService->computeDeadline($procurement->created_at);
|
|
|
|
|
+ $procurement->update(['code'=>$procurement_code,'deadline'=>$deadline]);
|
|
|
$procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
$procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
|
if ($procurement) return ['success' => true,'data' => $procurement];
|
|
if ($procurement) return ['success' => true,'data' => $procurement];
|
|
|
else return ['success' => false, 'message' => '添加失败'];
|
|
else return ['success' => false, 'message' => '添加失败'];
|
|
@@ -140,12 +149,16 @@ class ProcurementController extends Controller
|
|
|
'unit_price'=>0,
|
|
'unit_price'=>0,
|
|
|
'initiator'=>Auth::user()['id'],
|
|
'initiator'=>Auth::user()['id'],
|
|
|
'type'=>2,
|
|
'type'=>2,
|
|
|
|
|
+ 'status'=>2,
|
|
|
]);
|
|
]);
|
|
|
$procurement->save();
|
|
$procurement->save();
|
|
|
$number_id=$procurement['id'];
|
|
$number_id=$procurement['id'];
|
|
|
$procurement_code='BSHC';
|
|
$procurement_code='BSHC';
|
|
|
$procurement_code .= date ("ymd").str_pad($number_id>99999?$number_id%99999:$number_id,4,"0",STR_PAD_LEFT);
|
|
$procurement_code .= date ("ymd").str_pad($number_id>99999?$number_id%99999:$number_id,4,"0",STR_PAD_LEFT);
|
|
|
- $procurement->update(['code'=>$procurement_code]);
|
|
|
|
|
|
|
+ /** @var ProcurementService $procurementService*/
|
|
|
|
|
+ $procurementService=app(ProcurementService::class);
|
|
|
|
|
+ $deadline=$procurementService->computeDeadline($procurement->created_at);
|
|
|
|
|
+ $procurement->update(['code'=>$procurement_code,'deadline'=>$deadline]);
|
|
|
$procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
$procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
|
if ($procurement) return ['success' => true,'data' => $procurement];
|
|
if ($procurement) return ['success' => true,'data' => $procurement];
|
|
|
else return ['success' => false, 'message' => '添加失败'];
|
|
else return ['success' => false, 'message' => '添加失败'];
|
|
@@ -153,11 +166,12 @@ class ProcurementController extends Controller
|
|
|
return ['success' => false,'message' => $e->getMessage()];
|
|
return ['success' => false,'message' => $e->getMessage()];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //取消采购单
|
|
|
public function cancel($id){
|
|
public function cancel($id){
|
|
|
$this->gate('采购管理-采购-编辑');
|
|
$this->gate('采购管理-采购-编辑');
|
|
|
try {
|
|
try {
|
|
|
$procurement=Procurement::query()->find($id);
|
|
$procurement=Procurement::query()->find($id);
|
|
|
- $procurement->update(['status'=>3]);
|
|
|
|
|
|
|
+ $procurement->update(['status'=>10]);
|
|
|
$procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
$procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
|
if ($procurement) return ['success' => true,'data' => $procurement];
|
|
if ($procurement) return ['success' => true,'data' => $procurement];
|
|
|
else return ['success' => false, 'message' => '取消失败'];
|
|
else return ['success' => false, 'message' => '取消失败'];
|
|
@@ -179,7 +193,7 @@ class ProcurementController extends Controller
|
|
|
}
|
|
}
|
|
|
$procurement->update([
|
|
$procurement->update([
|
|
|
'type'=>0,
|
|
'type'=>0,
|
|
|
- 'status'=>0,
|
|
|
|
|
|
|
+ 'status'=>2,
|
|
|
'quantity'=>$param['quantity'],
|
|
'quantity'=>$param['quantity'],
|
|
|
'amount'=>$param['amount'],
|
|
'amount'=>$param['amount'],
|
|
|
'unit_price'=>$unit_price,
|
|
'unit_price'=>$unit_price,
|
|
@@ -220,6 +234,25 @@ class ProcurementController extends Controller
|
|
|
return ['success' => false,'message' => $e->getMessage()];
|
|
return ['success' => false,'message' => $e->getMessage()];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ public function createAnew(Request $request)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->gate('采购管理-采购-新建');
|
|
|
|
|
+ $ids=$request->input('checkData');
|
|
|
|
|
+ if (empty($ids)) return ['success' => false, 'message' => '当前未勾选指定订单!'];
|
|
|
|
|
+ $collect=collect();
|
|
|
|
|
+ $procurements=Procurement::query()->whereIn('id',$ids)->get();
|
|
|
|
|
+ foreach ($procurements as $procurement){
|
|
|
|
|
+ if ($procurement->type==2){
|
|
|
|
|
+ $pro=$this->newProcurement($procurement,Auth::user()['id'],$procurement->type,2);
|
|
|
|
|
+ $pro->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $pro=$this->newProcurement($procurement,Auth::user()['id'],$procurement->type);
|
|
|
|
|
+ $pro->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
|
|
|
|
|
+ $collect->add($pro);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!empty($collect)) return ['success' => true,'data' => $collect];
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|