-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStoreBatchCode.php
More file actions
72 lines (57 loc) · 2.34 KB
/
Copy pathStoreBatchCode.php
File metadata and controls
72 lines (57 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
* Author: stewicca <stewicalf@gmail.com>
* Created: Mon, 21 Apr 2026, Kuala Lumpur, Malaysia
* Copyright (c) 2026, Steven Wicca Alfredo
*/
namespace App\Actions\Dispatching\BatchCode;
use App\Actions\Inventory\OrgStock\Hydrators\OrgStockHydrateCurrentBatchCodes;
use App\Actions\OrgAction;
use App\Models\Dispatching\BatchCode;
use App\Models\Inventory\OrgStock;
use App\Models\Inventory\Warehouse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;
use Lorisleiva\Actions\ActionRequest;
class StoreBatchCode extends OrgAction
{
public function handle(Warehouse $warehouse, array $modelData): BatchCode
{
data_set($modelData, 'group_id', $warehouse->group_id);
data_set($modelData, 'organisation_id', $warehouse->organisation_id);
$batchCode = BatchCode::create($modelData);
OrgStockHydrateCurrentBatchCodes::run(OrgStock::find($batchCode->org_stock_id));
return $batchCode;
}
public function rules(): array
{
return [
'code' => ['required', 'string', 'max:255'],
'expiry_date' => ['nullable', 'date'],
'org_stock_id' => ['required', 'exists:org_stocks,id'],
];
}
public function asController(Warehouse $warehouse, ActionRequest $request): BatchCode
{
$this->initialisationFromWarehouse($warehouse, $request);
return $this->handle($warehouse, $this->validatedData);
}
public function action(Warehouse $warehouse, array $modelData): BatchCode
{
$this->asAction = true;
$this->initialisationFromWarehouse($warehouse, $modelData);
return $this->handle($warehouse, $this->validatedData);
}
public function htmlResponse(BatchCode $batchCode, ActionRequest $request): RedirectResponse
{
$redirectRouteName = $request->input('redirect_route_name');
$redirectRouteParameters = $request->input('redirect_route_parameters', []);
if (is_string($redirectRouteName) && is_array($redirectRouteParameters)) {
return Redirect::route($redirectRouteName, $redirectRouteParameters);
}
return Redirect::route('grp.org.warehouses.show.inventory.batch_codes.index', [
'organisation' => $this->warehouse->organisation->slug,
'warehouse' => $this->warehouse->slug,
]);
}
}