Skip to content

Commit 487e628

Browse files
feat: update order flow and inventory control
1 parent cdb503e commit 487e628

17 files changed

Lines changed: 672 additions & 227 deletions

File tree

app/Http/Controllers/Orders/OrderItemController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
public function store(StoreOrderItemRequest $request, Order $order): RedirectResponse
2323
{
2424
abort_if(
25-
in_array($order->status, ['completed', 'cancelled']),
25+
! in_array($order->status, OrderService::ACTIVE_STATUSES),
2626
422,
2727
'Cannot add items to a completed or cancelled order.'
2828
);
@@ -63,7 +63,7 @@ public function updateStatus(Request $request, Order $order, OrderItem $orderIte
6363
abort_if($orderItem->status === 'cancelled', 422, 'Cannot update a cancelled item.');
6464

6565
$validated = $request->validate([
66-
'status' => ['required', 'string', 'in:pending,confirmed,preparing,ready,served'],
66+
'status' => ['required', 'string', 'in:sent_to_kitchen,preparing,ready,served'],
6767
]);
6868

6969
$this->orderService->changeItemStatus($orderItem, $validated['status']);

app/Http/Controllers/PosController.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ public function getOrders(Request $request): JsonResponse
5353
'outlet:id,name',
5454
])
5555
->withCount('items')
56-
->latest('ordered_at');
56+
->latest('created_at');
5757

5858
match ($view) {
59-
'ongoing' => $query->whereIn('status', ['confirmed', 'preparing', 'ready']),
60-
'today' => $query->whereDate('ordered_at', today()),
59+
'ongoing' => $query->whereIn('status', ['accepted', 'preparing', 'partially_ready', 'ready', 'partially_served', 'served']),
60+
'today' => $query->whereDate('created_at', today()),
6161
'qr' => $query->where('order_source', 'qr'),
62-
default => $query->whereDate('ordered_at', today()),
62+
default => $query->whereDate('created_at', today()),
6363
};
6464

6565
$orders = $query->limit(100)->get([
6666
'id', 'order_number', 'order_type', 'status', 'source',
67-
'ordered_at', 'outlet_id',
67+
'created_at', 'outlet_id',
6868
]);
6969

7070
return response()->json($orders);
@@ -156,6 +156,17 @@ public function getMergeableOrders(Order $order): JsonResponse
156156
return response()->json($orders);
157157
}
158158

159+
public function sendToKitchen(Order $order): JsonResponse
160+
{
161+
if (in_array($order->status, ['completed', 'cancelled'])) {
162+
return response()->json(['message' => 'Cannot update a completed or cancelled order.'], 422);
163+
}
164+
165+
$this->orderService->sendItemsToKitchen($order);
166+
167+
return response()->json(['success' => true, 'message' => 'Items sent to kitchen.']);
168+
}
169+
159170
public function storeCustomer(Request $request): JsonResponse
160171
{
161172
$validated = $request->validate([

app/Http/Requests/Orders/UpdateOrderStatusRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function authorize(): bool
1515
public function rules(): array
1616
{
1717
return [
18-
'status' => ['required', Rule::in(['confirmed', 'preparing', 'ready', 'served', 'completed', 'cancelled'])],
18+
'status' => ['required', Rule::in(['completed', 'cancelled'])],
1919
'note' => ['nullable', 'string', 'max:500'],
2020
];
2121
}

app/Models/Order.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ class Order extends Model
2222
'order_source',
2323
'approval_status',
2424
'status',
25-
'ordered_at',
26-
'confirmed_at',
27-
'preparing_at',
28-
'ready_at',
29-
'served_at',
3025
'completed_at',
3126
'cancelled_at',
3227
'note',
@@ -36,11 +31,6 @@ class Order extends Model
3631
protected function casts(): array
3732
{
3833
return [
39-
'ordered_at' => 'datetime',
40-
'confirmed_at' => 'datetime',
41-
'preparing_at' => 'datetime',
42-
'ready_at' => 'datetime',
43-
'served_at' => 'datetime',
4434
'completed_at' => 'datetime',
4535
'cancelled_at' => 'datetime',
4636
];

app/Models/OrderItem.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class OrderItem extends Model
1212
'order_id',
1313
'food_id',
1414
'food_variant_id',
15+
'preparation_department_id',
1516
'quantity',
1617
'unit_price',
1718
'discount_amount',
@@ -25,11 +26,11 @@ class OrderItem extends Model
2526
protected function casts(): array
2627
{
2728
return [
28-
'quantity' => 'decimal:2',
29-
'unit_price' => 'decimal:2',
29+
'quantity' => 'decimal:2',
30+
'unit_price' => 'decimal:2',
3031
'discount_amount' => 'decimal:2',
31-
'tax_amount' => 'decimal:2',
32-
'total_amount' => 'decimal:2',
32+
'tax_amount' => 'decimal:2',
33+
'total_amount' => 'decimal:2',
3334
];
3435
}
3536

@@ -48,6 +49,11 @@ public function foodVariant(): BelongsTo
4849
return $this->belongsTo(FoodVariant::class);
4950
}
5051

52+
public function preparationDepartment(): BelongsTo
53+
{
54+
return $this->belongsTo(OutletDepartment::class, 'preparation_department_id');
55+
}
56+
5157
public function addons(): HasMany
5258
{
5359
return $this->hasMany(OrderItemAddon::class);

0 commit comments

Comments
 (0)