diff --git a/app/Livewire/Datatable/Studio/Manage/OrdersTable.php b/app/Livewire/Datatable/Studio/Manage/OrdersTable.php
index 45ae93e..9c1cb49 100644
--- a/app/Livewire/Datatable/Studio/Manage/OrdersTable.php
+++ b/app/Livewire/Datatable/Studio/Manage/OrdersTable.php
@@ -114,6 +114,12 @@ public function columns(): array
->label(function ($row) {
$actions = '';
+ if (auth()->user()->can('create order') && auth()->user()->can('show order')) {
+ $actions .= view('components.datatables.print', [
+ 'id' => $row->hash,
+ ])->render();
+ }
+
if (auth()->user()->can('show order')) {
$actions .= view('components.datatables.show', [
'id' => $row->hash,
diff --git a/app/Livewire/Studio/Manage/Order/Create.php b/app/Livewire/Studio/Manage/Order/Create.php
index 7a252cd..f213fc8 100644
--- a/app/Livewire/Studio/Manage/Order/Create.php
+++ b/app/Livewire/Studio/Manage/Order/Create.php
@@ -105,7 +105,9 @@ public function save()
$this->toast('Order berhasil ditambahkan.');
- $this->redirectRoute('studio.manage.order.index');
+ $this->redirectRoute('studio.manage.order.index', [
+ 'order' => $result['data']->id,
+ ]);
}
public function updatedFormOutletId($value)
diff --git a/app/Livewire/Studio/Manage/Order/Index.php b/app/Livewire/Studio/Manage/Order/Index.php
index 4cb225c..77f5136 100644
--- a/app/Livewire/Studio/Manage/Order/Index.php
+++ b/app/Livewire/Studio/Manage/Order/Index.php
@@ -9,6 +9,7 @@
use App\Traits\WithConfirmation;
use App\Traits\WithToast;
use Flux\Flux;
+use Livewire\Attributes\On;
use Livewire\Attributes\Title;
use Livewire\Component;
@@ -17,6 +18,25 @@ class Index extends Component
{
use WithCloseModal, WithConfirmation, WithSubscribeNotification, WithToast, WithUpdateStock;
+ public function mount()
+ {
+ if (request()->has('order')) {
+ $order = Order::find(request('order'));
+
+ if (! $order) {
+ return;
+ }
+
+ $this->dispatch('fn:print', order: $order->hash);
+
+ $this->js("
+ const url = new URL(window.location);
+ url.search = '';
+ window.history.replaceState({}, '', url);
+ ");
+ }
+ }
+
public function delete(Order $order)
{
foreach ($order->items as $item) {
@@ -32,6 +52,27 @@ public function delete(Order $order)
Flux::modals()->close();
}
+ #[On('fn:print')]
+ public function print(Order $order)
+ {
+ $order->load(['items', 'user', 'user.employee']);
+
+ $this->dispatch(
+ 'printReceipt',
+ cashier: $order->user?->employee?->full_name ?? '',
+ customer: $order->customer?->name ?? '',
+ subtotal: $order->subtotal,
+ discount: $order->discount,
+ total: $order->total,
+ items: $order->items->map(function ($item) {
+ $item->name = $item->orderable?->name;
+ $item->total = $item->unit_price * $item->quantity;
+
+ return $item;
+ })->toArray()
+ );
+ }
+
public function render()
{
return view('livewire.studio.manage.order.index', [
diff --git a/resources/views/components/datatables/print.blade.php b/resources/views/components/datatables/print.blade.php
new file mode 100644
index 0000000..9332a67
--- /dev/null
+++ b/resources/views/components/datatables/print.blade.php
@@ -0,0 +1,5 @@
+