|
|
@@ -17,21 +17,21 @@ class ReceivingTaskController extends Controller
|
|
|
public $service;
|
|
|
public $ownerService;
|
|
|
|
|
|
- public function __construct(ReceivingTaskService $service,OwnerService $ownerService)
|
|
|
+ public function __construct(ReceivingTaskService $service, OwnerService $ownerService)
|
|
|
{
|
|
|
$this->service = $service;
|
|
|
$this->ownerService = $ownerService;
|
|
|
}
|
|
|
|
|
|
- public function index(Request $request,ReceivingTaskFilters $filter)
|
|
|
+ public function index(Request $request, ReceivingTaskFilters $filter)
|
|
|
{
|
|
|
if (Gate::denies('入库管理-开单入库-查询')) {
|
|
|
return redirect('/');
|
|
|
}
|
|
|
- $receivingTasks = ReceivingTask::query()->with(['items','owner','wareHouse','file','deliveryAppointmentCar'])->filter($filter)->orderByDesc('created_at')->paginate(50);
|
|
|
- $owners = $this->ownerService->getQuery()->select('id','name')->get();
|
|
|
- $warehouses = Warehouse::query()->get();
|
|
|
- return view("store.receivingTasks.index",compact('receivingTasks','owners','warehouses'));
|
|
|
+ $receivingTasks = ReceivingTask::query()->with(['items', 'owner', 'wareHouse', 'file', 'deliveryAppointmentCar'])->filter($filter)->orderByDesc('created_at')->paginate(50);
|
|
|
+ $owners = $this->ownerService->getQuery()->select('id', 'name')->get();
|
|
|
+ $warehouses = Warehouse::query()->get();
|
|
|
+ return view("store.receivingTasks.index", compact('receivingTasks', 'owners', 'warehouses'));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -41,37 +41,43 @@ class ReceivingTaskController extends Controller
|
|
|
return redirect('/');
|
|
|
}
|
|
|
$wareHouse = Warehouse::query()->get();
|
|
|
- $owners = $this->ownerService->getQuery()->select("id","code","name")->get();
|
|
|
- return view("store.receivingTasks.create",compact('wareHouse','owners'));
|
|
|
+ $owners = $this->ownerService->getQuery()->select("id", "code", "name")->get();
|
|
|
+ return view("store.receivingTasks.create", compact('wareHouse', 'owners'));
|
|
|
}
|
|
|
|
|
|
|
|
|
public function storeApi(ReceivingTaskRequest $request): array
|
|
|
{
|
|
|
- if(Gate::denies('入库管理-开单入库-创建')){
|
|
|
- return ['success' => false,'message' => '没有对应权限'];
|
|
|
+ if (Gate::denies('入库管理-开单入库-创建')) {
|
|
|
+ return ['success' => false, 'message' => '没有对应权限'];
|
|
|
}
|
|
|
- $appointment_number = $request->input('appointment_number',null);
|
|
|
+ $appointment_number = $request->input('appointment_number', null);
|
|
|
|
|
|
- $delivery_appointment_car = DeliveryAppointmentCar::query()->with('deliveryAppointment')->where('appointment_number',$appointment_number)->first();
|
|
|
+ $delivery_appointment_car = DeliveryAppointmentCar::query()->with('deliveryAppointment')->where('appointment_number', $appointment_number)->first();
|
|
|
|
|
|
- if (!$delivery_appointment_car){
|
|
|
- return ['success' => false,'errors' =>['appointment_number' => ['对应预约号未找到']]];
|
|
|
+ if (!$delivery_appointment_car || !$delivery_appointment_car->deliveryAppointment) {
|
|
|
+ return ['success' => false, 'errors' => ['appointment_number' => ['对应预约号未找到']]];
|
|
|
}
|
|
|
- if (!$delivery_appointment_car->deliveryAppointment){
|
|
|
- return ['success' => false,'errors' =>['appointment_number' => ['对应预约号未找到']]];
|
|
|
+
|
|
|
+ $ans_number_string = $delivery_appointment_car->deliveryAppointment->asn_number ?? '';
|
|
|
+ $ans_numbers = array_filter(preg_split('/[,, ]+/is', $ans_number_string));
|
|
|
+
|
|
|
+ if (count($ans_numbers) === 0 && count($request->input('asn_no')) == 0) {
|
|
|
+ return ['success' => false, 'errors' => ['appointment_number' => ['预约号没有对应的Asn号']]];
|
|
|
}
|
|
|
|
|
|
- if ($delivery_appointment_car->deliveryAppointment->owner_id != $request->input('owner_id')){
|
|
|
- return ['success' => false,'errors' =>['appointment_number' => ['预约号与货主未对应']]];
|
|
|
+ if ($delivery_appointment_car->deliveryAppointment->owner_id != $request->input('owner_id')) {
|
|
|
+ return ['success' => false, 'errors' => ['appointment_number' => ['预约号与货主未对应']]];
|
|
|
}
|
|
|
- if (ReceivingTask::query()->where('delivery_appointment_car_id',$delivery_appointment_car->id)->exists()){
|
|
|
- return ['success' => false, 'errors' =>['appointment_number' => ['预约号已有对应的任务']]];
|
|
|
+
|
|
|
+ if (ReceivingTask::query()->where('delivery_appointment_car_id', $delivery_appointment_car->id)->exists()) {
|
|
|
+ return ['success' => false, 'errors' => ['appointment_number' => ['预约号已有对应的任务']]];
|
|
|
}
|
|
|
+
|
|
|
try {
|
|
|
$receiving_task = $this->service->createReceivingTask($delivery_appointment_car, $request->all());
|
|
|
if (!$receiving_task->id) return ['success' => false, 'message' => '生成入库单任务失败,请重新尝试'];
|
|
|
- $receiving_task->loadMissing(['wareHouse','owner','deliveryAppointmentCar']);
|
|
|
+ $receiving_task->loadMissing(['wareHouse', 'owner', 'deliveryAppointmentCar']);
|
|
|
return ['success' => true, 'data' => $receiving_task];
|
|
|
} catch (\Exception $e) {
|
|
|
return ['success' => false, 'message' => '生成入库单任务失败,请重新尝试'];
|
|
|
@@ -86,15 +92,15 @@ class ReceivingTaskController extends Controller
|
|
|
public function getAsnByAppointmentNumberApi(Request $request): array
|
|
|
{
|
|
|
$appointment_number = $request->input('appointment_number');
|
|
|
- if (!$appointment_number){
|
|
|
+ if (!$appointment_number) {
|
|
|
return ['success' => false, 'errors' => ['appointment_number' => '预约号不能为空']];
|
|
|
}
|
|
|
- $delivery_appointment_car = DeliveryAppointmentCar::query()->with('deliveryAppointment')->where('appointment_number',$appointment_number)->first();
|
|
|
- if (ReceivingTask::query()->where('delivery_appointment_car_id',$delivery_appointment_car->id)->exists()){
|
|
|
- return ['success' => false, 'errors' =>['appointment_number' => ['预约号已有对应的任务']]];
|
|
|
+ $delivery_appointment_car = DeliveryAppointmentCar::query()->with('deliveryAppointment')->where('appointment_number', $appointment_number)->first();
|
|
|
+ if (ReceivingTask::query()->where('delivery_appointment_car_id', $delivery_appointment_car->id)->exists()) {
|
|
|
+ return ['success' => false, 'errors' => ['appointment_number' => ['预约号已有对应的任务']]];
|
|
|
}
|
|
|
$ans_number_string = $delivery_appointment_car->deliveryAppointment->asn_number ?? '';
|
|
|
$ans_numbers = array_filter(preg_split('/[,, ]+/is', $ans_number_string));
|
|
|
- return ['success' => true,'data' => $ans_numbers];
|
|
|
+ return ['success' => true, 'data' => $ans_numbers];
|
|
|
}
|
|
|
}
|