enhance invoice display

This commit is contained in:
ludo
2023-12-03 02:20:41 +01:00
parent ec509df665
commit b5da5fc881
12 changed files with 152 additions and 150 deletions

View File

@@ -9,7 +9,7 @@ use Yajra\DataTables\Html\Column;
class InvoicesDataTable extends DataTable class InvoicesDataTable extends DataTable
{ {
public $model_name = 'Invoices'; public $model_name = 'invoices';
public function query(Invoice $model) public function query(Invoice $model)
{ {
@@ -28,7 +28,7 @@ class InvoicesDataTable extends DataTable
return $invoice->created_at->toDateTimeString(); return $invoice->created_at->toDateTimeString();
}) })
->editColumn('customer.last_name', function (Invoice $invoice) { ->editColumn('customer.last_name', function (Invoice $invoice) {
return ($invoice->customer ?? false) ? $invoice->customer->last_name.' '.$invoice->customer->first_name : ''; return ($invoice->customer ?? false) ? $invoice->customer->name : '';
}) })
->rawColumns(['action']); ->rawColumns(['action']);

View File

@@ -12,7 +12,7 @@ class OrdersDataTable extends DataTable
{ {
public $model_name = 'orders'; public $model_name = 'orders';
public $sortedColumn = 1; public $sortedColumn = 0;
public $sortedOrder = 'desc'; public $sortedOrder = 'desc';

View File

@@ -45,7 +45,6 @@ class OrderController extends Controller
'customer' => $customer ? $customer->toArray() : false, 'customer' => $customer ? $customer->toArray() : false,
'basket' => Baskets::getBasketTotal(), 'basket' => Baskets::getBasketTotal(),
'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(), 'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(),
'sale_channel' => SaleChannels::getDefault()->toArray(),
'delivery_types' => DeliveryTypes::getWithPrice(Baskets::getWeight()), 'delivery_types' => DeliveryTypes::getWithPrice(Baskets::getWeight()),
]; ];

View File

@@ -25,7 +25,7 @@ class Order extends Model
public function delivery_address() public function delivery_address()
{ {
return $this->belongsTo(CustomerAddress::class, 'customer_delivery_id'); return $this->belongsTo(CustomerAddress::class, 'delivery_address_id');
} }
public function delivery() public function delivery()

View File

@@ -62,6 +62,7 @@ class Invoices
{ {
InvoiceStats::increase($data['total_taxed']); InvoiceStats::increase($data['total_taxed']);
$data['uuid'] = Str::uuid()->toString(); $data['uuid'] = Str::uuid()->toString();
$data['ref'] = self::getNewRef();
return Invoice::create($data); return Invoice::create($data);
} }
@@ -77,7 +78,7 @@ class Invoices
public static function getNewRef() public static function getNewRef()
{ {
$ref = date('ymd').'00000'; $ref = date('ymd').'00000';
$lastRef = Invoice::orderBy('id', 'desc')->first(); $lastRef = Invoice::where($ref, '>', $ref)->orderBy('id', 'desc')->first();
return $lastRef ? $lastRef->ref + 1 : $ref + 1; return $lastRef ? $lastRef->ref + 1 : $ref + 1;
} }

View File

@@ -34,7 +34,6 @@ class Orders
public static function saveOrder($data) public static function saveOrder($data)
{ {
$data += $data['basket'];
$basket = $data['basket']; $basket = $data['basket'];
unset($data['basket']); unset($data['basket']);
$order = self::store($data); $order = self::store($data);
@@ -42,10 +41,8 @@ class Orders
$data['ref'] = $order->ref; $data['ref'] = $order->ref;
unset($data['comment']); unset($data['comment']);
unset($data['agree']); unset($data['agree']);
unset($data['customer_id']); unset($data['delivery_address_id']);
unset($data['delivery_id']);
unset($data['detail']); unset($data['detail']);
unset($data['payment_type']);
unset($data['sale_channel_id']); unset($data['sale_channel_id']);
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false; return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
@@ -54,7 +51,14 @@ class Orders
public static function edit($id) public static function edit($id)
{ {
return [ return [
'order' => self::get($id, ['customer', 'invoice.address', 'delivery', 'delivery_address', 'detail'])->toArray(), 'order' => self::get($id, [
'customer',
'invoice.address',
'delivery',
'delivery_address',
'detail',
'sale_channel',
])->toArray(),
'statuses' => self::statuses(), 'statuses' => self::statuses(),
'delivery_types' => DeliveryTypes::getOptions(), 'delivery_types' => DeliveryTypes::getOptions(),
'payment_types' => self::paymentTypes(), 'payment_types' => self::paymentTypes(),
@@ -107,7 +111,7 @@ class Orders
public static function getNewRef() public static function getNewRef()
{ {
$ref = date('ymd').'00000'; $ref = date('ymd').'00000';
$lastRef = Order::orderBy('id', 'desc')->first(); $lastRef = Order::where($ref, '>', $ref)->orderBy('id', 'desc')->first();
return $lastRef ? $lastRef->ref + 1 : $ref + 1; return $lastRef ? $lastRef->ref + 1 : $ref + 1;
} }

View File

@@ -1,37 +1,40 @@
{{ Form::open(['route' => 'Admin.Shop.Invoices.update', 'id' => 'invoice-form', 'autocomplete' => 'off']) }} {{ Form::open(['route' => 'Admin.Shop.Invoices.update', 'id' => 'invoice-form', 'autocomplete' => 'off']) }}
<input type="hidden" name="id" id="id" value="{{ $invoice['id'] ?? false }}"> <input type="hidden" name="id" id="id" value="{{ $invoice['id'] ?? false }}">
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-9">
<h5> <h5>
<a href="{{ route('Admin.Shop.Orders.edit', ['id' => $invoice['order_id']]) }}" class="btn btn-success">
<i class="fa fa-truck"></i>
</a>
Facture {{ $invoice['ref'] }} Facture {{ $invoice['ref'] }}
du {{ Carbon\Carbon::parse($invoice['created_at'])->isoFormat('LLLL') }} <span class="small">
du {{ Carbon\Carbon::parse($invoice['created_at'])->isoFormat('LLLL') }}
</span>
</h5> </h5>
</div> </div>
<div class="col-6 text-right"> <div class="col-3 text-right">
@include('components.form.buttons.button-save') <x-save />
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-6"> <div class="col-6">
<h3> <h5>
{{ $invoice['order']['customer']['last_name'] }}
{{ $invoice['order']['customer']['first_name'] }} {{ $invoice['order']['customer']['first_name'] }}
</h3> {{ $invoice['order']['customer']['last_name'] }}
<div class="row"> @if ($invoice['order']['customer']['company'])
<div class="col-12"> <br>
<h6> {{ $invoice['order']['customer']['company'] }}
@if ($invoice['order']['delivery_address']) @endif
{{ $invoice['order']['delivery_address']['address'] }}<br /> </h5>
@isset($invoice['order']['delivery_address']['address2'])
{{ $invoice['order']['delivery_address']['address2'] }}<br /> @if ($invoice['order']['delivery_address'])
@endisset <x-card title="Adresse de facturation" classBody="mt-3">
{{ $invoice['order']['delivery_address']['zipcode'] }} @include('components.address-view', [
{{ $invoice['order']['delivery_address']['city'] }}<br /> 'address' => $invoice['order']['delivery_address'],
@endif ])
</h6> </x-card>
</div> @endif
</div>
</div> </div>
<div class="col-6"> <div class="col-6">
<div class="row mb-3"> <div class="row mb-3">

View File

@@ -1,14 +1,14 @@
@extends('layout.index', [ @extends('layout.index', [
'title' => __('shop.invoice_payments.title'), 'title' => __('shop.invoices.title'),
'subtitle' => __('shop.invoice_payments.list'), 'subtitle' => __('shop.invoices.list'),
'breadcrumb' => [__('shop.invoice_payments.title')], 'breadcrumb' => [__('shop.invoices.title')],
]) ])
@section('content') @section('content')
<x-card> <x-card>
@include('components.datatable', [ @include('components.datatable', [
'route' => route('Admin.Shop.InvoicePayments.index'), 'route' => route('Admin.Shop.Invoices.index'),
'model' => 'invoice_payments', 'model' => 'invoices',
]) ])
</x-card> </x-card>
@endsection @endsection

View File

@@ -1,124 +1,116 @@
@extends('layout.index', [ @extends('layout.index', [
'title' => __('shop.orders.title'), 'title' => __('shop.orders.title'),
'subtitle' => __('shop.orders.edit'), 'subtitle' => __('shop.orders.edit'),
'breadcrumb' => ['Commandes'] 'breadcrumb' => ['Commandes'],
]) ])
@section('content') @section('content')
{{ Form::open(['route' => 'Admin.Shop.Orders.store', 'id' => 'order-form', 'autocomplete' => 'off']) }} {{ Form::open(['route' => 'Admin.Shop.Orders.store', 'id' => 'order-form', 'autocomplete' => 'off']) }}
<input type="hidden" name="id" value="{{ $order['id'] ?? null }}"> <input type="hidden" name="id" value="{{ $order['id'] ?? null }}">
<x-card> <x-card>
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-9">
<h4>{{ $order['delivery']['name'] }} </h4> <h5>
</div> <a href="{{ route('Admin.Shop.Invoices.edit', ['id' => $order['invoice']['id']]) }}"
<div class="col-6 text-right"> class="btn btn-success">
<x-save /> <i class="fa fa-file-invoice"></i>
</div> </a>
Commande : {{ $order['ref'] }}
<span class="small">
du {{ Carbon\Carbon::parse($order['created_at'])->isoFormat('LLLL') }}
</span>
</h5>
</div> </div>
<div class="col-3 text-right">
<x-save />
</div>
</div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-6"> <div class="col-6">
<h3> <h5>
{{ $order['customer']['last_name'] }} {{ $order['customer']['first_name'] }} {{ $order['customer']['first_name'] }} {{ $order['customer']['last_name'] }}
</h3> @if ($order['customer']['company'])
<div class="row"> <br>
<div class="col-6"> {{ $order['customer']['company'] }}
<x-card title="Adresse de facturation" classBody="mt-3"> @endif
@if ($order['invoice']['address']) </h5>
{{ $order['invoice']['address']['address'] }}<br/>
@isset ($order['invoice']['address']['address2'])
{{ $order['invoice']['address']['address2'] }}<br/>
@endisset
{{ $order['invoice']['address']['zipcode'] }}
{{ $order['invoice']['address']['city'] }}<br/>
@endif
</x-card>
</div>
<div class="col-6">
<x-card title="Adresse de livraison" classBody="mt-3">
@if ($order['delivery_address'])
{{ $order['delivery_address']['address'] }}<br/>
@isset ($order['delivery_address']['address2'])
{{ $order['delivery_address']['address2'] }}<br/>
@endisset
{{ $order['delivery_address']['zipcode'] }}
{{ $order['delivery_address']['city'] }}<br/>
@endif
</x-card>
</div>
</div>
</div>
<div class="col-6">
<div class="row mb-3">
<div class="col-6" style="font-size: 1.2em; font-weight: 500;">
Commande <br/>
du {{ Carbon\Carbon::parse($order['created_at'])->isoFormat('LLLL') }}
</div>
<div class="col-6">
@include('components.form.select', [
'label' => 'Statut',
'name' => 'status',
'list' => $statuses ?? [],
'value' => $order['status'],
'class' => 'select2',
])
</div>
</div>
<div class="row mb-3">
<div class="col-6">
@include('components.form.select', [
'label' => 'Canal de vente',
'name' => 'sale_channel_id',
'list' => $sale_channels ?? [],
'value' => $order['sale_channel_id'],
'class' => 'select2',
])
</div>
<div class="col-6">
@include('components.form.select', [
'label' => 'Règlement',
'name' => 'payment_type',
'list' => $payment_types ?? [],
'value' => $order['payment_type'],
'class' => 'select2',
])
</div>
</div>
<div class="row mb-3">
<div class="col-4">
@include('components.form.select', [
'label' => 'Type de livraison',
'name' => 'delivery_type_id',
'list' => $delivery_types ?? [],
'value' => $order['delivery_type_id'],
'with_empty' => '',
])
</div>
<div class="col-4">
@include('components.form.input', [
'label' => 'Référence colis',
'name' => 'delivery_ref',
'value' => $order['delivery_ref'] ?? null,
])
</div>
<div class="col-4">
@include('components.form.input', [
'label' => 'Lien suivi',
'name' => 'delivery_link',
'value' => $order['delivery_link'] ?? null,
])
</div>
<h6>
{{ $order['delivery']['name'] }}<br>
Canal de vente : {{ $order['sale_channel']['name'] ?? '' }}
</h6>
@if ($order['delivery_address'])
<x-card title="Adresse de livraison" classBody="mt-3">
@include('components.address-view', [
'address' => $order['delivery_address'],
])
</x-card>
@endif
</div>
<div class="col-6">
<div class="row mb-3">
<div class="col-6">
@include('components.form.select', [
'label' => 'Statut',
'name' => 'status',
'list' => $statuses ?? [],
'value' => $order['status'],
'class' => 'select2',
])
</div>
<div class="col-6">
@include('components.form.select', [
'label' => 'Règlement',
'name' => 'payment_type',
'list' => $payment_types ?? [],
'value' => $order['payment_type'],
'class' => 'select2',
])
</div> </div>
</div> </div>
@if ($order['delivery']['at_house'])
<x-card title="Livraison">
<div class="row mb-3">
<div class="col-6">
@include('components.form.select', [
'label' => 'Type de livraison',
'name' => 'delivery_type_id',
'list' => $delivery_types ?? [],
'value' => $order['delivery_type_id'],
'with_empty' => '',
])
</div>
<div class="col-6">
@include('components.form.input', [
'label' => 'Référence colis',
'name' => 'delivery_ref',
'value' => $order['delivery_ref'] ?? null,
])
</div>
</div>
<div class="row mb-3">
<div class="col-12">
@include('components.form.input', [
'label' => 'Lien suivi',
'name' => 'delivery_link',
'value' => $order['delivery_link'] ?? null,
])
</div>
</div>
</x-card>
@endif
</div> </div>
<div class="row mb-3"> </div>
<div class="col-12"> <div class="row mb-3">
@include('Admin.Shop.Orders.partials.detail', ['detail_type' => 'commande']) <div class="col-12">
</div> @include('Admin.Shop.Orders.partials.detail', ['detail_type' => 'commande'])
</div> </div>
</x-card> </div>
</x-card>
{{ Form::close() }} {{ Form::close() }}
@endsection @endsection

View File

@@ -33,8 +33,6 @@ ci-contre
$('#delivery_addresses').closest('.card').addClass('d-none'); $('#delivery_addresses').closest('.card').addClass('d-none');
} }
var deliveryId = $(this).val(); var deliveryId = $(this).val();
console.log(deliveryId);
console.log(deliveryTypeId);
refreshBasketTotal(deliveryId, deliveryTypeId); refreshBasketTotal(deliveryId, deliveryTypeId);
}); });
} }

View File

@@ -33,9 +33,7 @@
function handleDeliveryTypes() { function handleDeliveryTypes() {
$('input.delivery_type').change(function() { $('input.delivery_type').change(function() {
var deliveryTypeId = $(this).val(); var deliveryTypeId = $(this).val();
var deliveryId = $('input[name=delivery_id]').val() var deliveryId = $('input[name=delivery_id]:checked').val()
console.log(deliveryId);
console.log(deliveryTypeId);
refreshBasketTotal(deliveryId, deliveryTypeId); refreshBasketTotal(deliveryId, deliveryTypeId);
}); });
} }

View File

@@ -0,0 +1,7 @@
{{ $address['name'] }}<br />
{{ $address['address'] }}<br />
@isset($address['address2'])
{{ $address['address2'] }}<br />
@endisset
{{ $address['zipcode'] }}
{{ $address['city'] }}<br />