feat: Implement order management with datatable display and updated forms

This commit is contained in:
pbao9
2026-02-14 18:00:15 +07:00
parent d683afc901
commit 5252f9142c
21 changed files with 490 additions and 541 deletions
@@ -1,181 +1,201 @@
@php use Carbon\Carbon; @endphp
@extends("administrator.layout.master")
@section("content")
@extends('administrator.layout.master')
@section('breadcrumb')
@php
$breadcrumbItems = [
['label' => 'Order'],
['label' => 'Order Management', 'url' => route('administrator.pages.order.index')],
['label' => 'View Order', 'active' => true],
];
@endphp
<x-admin-breadcrumb :items="$breadcrumbItems" />
@endsection
@section('content')
@if(auth()->guard('admins')->user()->can("edit order"))
<div class="card card-outline card-primary">
<div class="card-body">
<div class="row form-group">
<table class="form" width="100%" border="0" cellspacing="2" cellpadding="3">
<tbody>
<tr>
<td class="fieldlabel">Date</td>
<td class="fieldarea">{{ Carbon::parse($order->date)->format("d/m/Y H:i:s") }}</td>
<td width="15%" class="fieldlabel">Payment Method</td>
<td class="fieldarea">{{ $order->payment->name ?? 'VN Pay' }}</td>
</tr>
<tr>
<td width="15%" class="fieldlabel">Order #</td>
<td class="fieldarea">{{ $order->order_num }} (ID: {{$order->id}})</td>
<td class="fieldlabel">Amount</td>
<td class="fieldarea">@money($order->amount) đ</td>
</tr>
<tr>
<td class="fieldlabel">Client</td>
<td class="fieldarea">
<a href="{{ route('customer.info',['userid' => $order->customer->id]) }}">{{ $order->customer->firstname . ' ' . $order->customer->lastname }}</a>
<br>
{{ $order->customer->address }}
</td>
<td class="fieldlabel">Invoice #</td>
<td class="fieldarea">{{ $order->invoice_id !== 0 ? $order->invoice_id : "No Invoice" }}</td>
</tr>
<tr>
<td class="fieldlabel">Status</td>
<td class="fieldarea">{!! App\Http\Helpers\Helper::OrderStatus($order->status) !!}</td>
<td class="fieldlabel">IP Address</td>
<td class="fieldarea">
{{ $order->client_ip }}
</td>
</tr>
<tr>
<td class="fieldlabel">Order Placed By</td>
<td class="fieldarea">
@if($order->user)
{{ $order->user->username }} (#ID: {{ $order->user->id }})
<em>{{ $order->user->email }}</em>
@endif
</td>
<td class="fieldlabel">Promotion Code</td>
<td class="fieldarea">
@if($order->discount)
{{ $order->discount->code }}
@endif
</td>
</tr>
</tbody>
</table>
</div>
<div class="row form-group">
<div class="col-md-12">
<h3 class="mb-3">Order Item</h3>
<table class="table table-invoice table-bordered">
<thead>
<tr>
<th>Item</th>
<th>Description</th>
<th>Billing Cycle</th>
<th>Amount</th>
<th style="width: 40px">Status</th>
<th>Payment Status</th>
</tr>
</thead>
<tbody>
@if($order->orderItem->isNotEmpty())
@foreach($order->orderItem->all() as $item)
<form action="{{ route('administrator.pages.order.update', ['id' => $order->id]) }}" method="post">
@csrf
@method('PUT')
<input type="hidden" name="module" value="1">
<div class="row align-items-start">
<div class="col-md-8">
<div class="card card-outline card-primary">
<div class="card-header bg-white">
<h5 class="card-title m-0">Order Information</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-borderless">
<tbody>
<tr>
<td class="text-center">
@if($item->type && in_array($item->Type->id,[3,4]))
<a href="{{ route('customer.product',['userid' => $item->customer_id,'product' =>$item->relid,'type' => $item->type_id ]) }}">
{{ $item->type->name }}
</a>
@else
{{ $item->type->name }}
@endif
</td>
<td>
{{ $item->description }}
</td>
<td class="text-center">
{{ Helper::billing_cycle($item->billing) }}
</td>
<td class="text-center">
@money($item->amount) đ
</td>
<td class="text-center">
@if($item->status)
{!! $item->status->getStatus() !!}
@endif
</td>
<td class="text-center">
@if($order->invoice_id !== 0)
{!! $order->invoice->getStatus() !!}
@else
No Invoice Due
@endif
</td>
<td class="text-muted" style="width: 150px;">Date</td>
<td>{{ Carbon::parse($order->date)->format("d/m/Y H:i:s") }}</td>
<td class="text-muted" style="width: 150px;">Payment Method</td>
<td>{{ $order->payment->name ?? 'VN Pay' }}</td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
</div>
@if( $order->status !== 1)
<div class="row mt-2 form-group">
<div class="col-md-12">
<label class="box-input__checker">
<span>Auto Create Product (Hosting/VPS)</span>
<input type="checkbox" name="module_checker" checked="checked">
<span class="checkmark"></span>
</label>
<tr>
<td class="text-muted">Order #</td>
<td>{{ $order->order_num }} (ID: {{ $order->id }})</td>
<td class="text-muted">Amount</td>
<td>@money($order->amount) đ</td>
</tr>
<tr>
<td class="text-muted">Client</td>
<td>
<a href="{{ route('customer.info', ['userid' => $order->customer->id]) }}">
{{ $order->customer->firstname . ' ' . $order->customer->lastname }}
</a>
<br>
<small class="text-muted">{{ $order->customer->address }}</small>
</td>
<td class="text-muted">Invoice #</td>
<td>{{ $order->invoice_id !== 0 ? $order->invoice_id : "No Invoice" }}</td>
</tr>
<tr>
<td class="text-muted">Status</td>
<td>{!! App\Http\Helpers\Helper::OrderStatus($order->status) !!}</td>
<td class="text-muted">IP Address</td>
<td>{{ $order->client_ip }}</td>
</tr>
<tr>
<td class="text-muted">Order Placed By</td>
<td>
@if($order->user)
{{ $order->user->username }} (#ID: {{ $order->user->id }})
<br>
<small class="text-muted">{{ $order->user->email }}</small>
@endif
</td>
<td class="text-muted">Promotion Code</td>
<td>{{ $order->discount?->code }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
@endif
<div class="card card-outline card-primary">
<div class="card-header bg-white">
<h5 class="card-title m-0">Order Item</h5>
</div>
<div class="card-body p-0">
<table class="table table-invoice table-bordered mb-0">
<thead>
<tr>
<th>Item</th>
<th>Description</th>
<th>Billing Cycle</th>
<th>Amount</th>
<th style="width: 100px">Status</th>
<th style="width: 120px">Payment Status</th>
</tr>
</thead>
<tbody>
@if($order->orderItem->isNotEmpty())
@foreach($order->orderItem->all() as $item)
<tr>
<td class="text-center">
@if($item->type && in_array($item->Type->id, [3, 4]))
<a href="{{ route('customer.product', ['userid' => $item->customer_id, 'product' => $item->relid, 'type' => $item->type_id]) }}">
{{ $item->type->name }}
</a>
@else
{{ $item->type->name }}
@endif
</td>
<td>{{ $item->description }}</td>
<td class="text-center">{{ Helper::billing_cycle($item->billing) }}</td>
<td class="text-center">@money($item->amount) đ</td>
<td class="text-center">
@if($item->status)
{!! $item->status->getStatus() !!}
@endif
</td>
<td class="text-center">
@if($order->invoice_id !== 0)
{!! $order->invoice->getStatus() !!}
@else
No Invoice Due
@endif
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card card-outline card-primary">
<div class="card-header bg-white">
<h5 class="card-title m-0">Order Actions</h5>
</div>
<div class="card-body">
@if($order->status !== 1)
<div class="form-group mb-3">
<label class="box-input__checker">
<span>Auto Create Product (Hosting/VPS)</span>
<input type="checkbox" name="module_checker" checked>
<span class="checkmark"></span>
</label>
</div>
@endif
<div class="d-flex flex-column gap-2">
@if($order->status !== 1)
<x-button-crm type="submit" name="action" value="accept" variant="success" icon="check-circle">
Accept Order
</x-button-crm>
@endif
<x-button-crm type="submit" name="action" value="cancel" variant="secondary" icon="x-circle">
Cancel Order
</x-button-crm>
@if(auth()->guard('admins')->user()->can("delete order"))
<form method="POST" action="{{ route('administrator.pages.order.destroy') }}" class="d-inline">
@csrf
@method('DELETE')
<input type="hidden" name="order" value="{{ $order->id }}">
<x-button-crm type="submit" variant="danger" icon="trash-2">
Delete Order
</x-button-crm>
</form>
@endif
</div>
</div>
</div>
</div>
</div>
<div class="card-footer text-center">
<form
onclick=" {{ $order->status === 1 ? "return false;" : "" }}"
class="d-lg-inline"
action="{{ route('administrator.pages.order.update',['id' => $order->id,'action' => 'accept']) }}"
method="post">
@method('put')
@csrf
<input type="hidden" name="module" value="1">
<button type="submit"
class="btn {{ $order->status === 1 ? "disabled" : "" }} bg-gradient-success">
<i class="far fa-check-circle"></i>
Accept Order
</button>
</form>
<form class="d-lg-inline"
action="{{ route('administrator.pages.order.update',['id' => $order->id,'action' => 'cancel']) }}"
method="post">
@method('put')
@csrf
<button type="submit"
class="btn bg-gradient-secondary">Cancel Order
</button>
</form>
<form class="d-lg-inline" action="{{ route('administrator.pages.order.destroy',['id' => $order->id]) }}"
method="post">
@method('delete')
@csrf
<button type="submit"
class="btn bg-gradient-danger">Delete Order
</button>
</form>
<a href="{{ route('administrator.pages.order.index') }}" class="btn bg-gradient-secondary">
Back
</a>
</div>
</div>
<x-fixed-action-bar>
<x-button-crm type="button" variant="secondary" size="sm" icon="arrow-left"
route="administrator.pages.order.index">Back</x-button-crm>
</x-fixed-action-bar>
</form>
@else
<div class="alert alert-danger alert-dismissible">
<h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Order
management department</h5>
</div>
@endif
@endsection
@push("scripts")
<script type="text/javascript">
$('.box-input__checker span').click(function () {
let inputModule = $('input[name="module"][type="hidden"]');
$('input[name="module_checker"]').prop('checked') ?
inputModule.val(0) :
inputModule.val(1)
@push('custom-scripts')
<script>
document.addEventListener('DOMContentLoaded', function() {
const moduleChecker = document.querySelector('input[name="module_checker"]');
const moduleInput = document.querySelector('input[name="module"]');
if (moduleChecker && moduleInput) {
moduleChecker.addEventListener('change', function() {
moduleInput.value = this.checked ? '0' : '1';
});
}
});
</script>
@endpush