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
{
public $model_name = 'Invoices';
public $model_name = 'invoices';
public function query(Invoice $model)
{
@@ -28,7 +28,7 @@ class InvoicesDataTable extends DataTable
return $invoice->created_at->toDateTimeString();
})
->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']);

View File

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

View File

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

View File

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

View File

@@ -62,6 +62,7 @@ class Invoices
{
InvoiceStats::increase($data['total_taxed']);
$data['uuid'] = Str::uuid()->toString();
$data['ref'] = self::getNewRef();
return Invoice::create($data);
}
@@ -77,7 +78,7 @@ class Invoices
public static function getNewRef()
{
$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;
}

View File

@@ -34,7 +34,6 @@ class Orders
public static function saveOrder($data)
{
$data += $data['basket'];
$basket = $data['basket'];
unset($data['basket']);
$order = self::store($data);
@@ -42,10 +41,8 @@ class Orders
$data['ref'] = $order->ref;
unset($data['comment']);
unset($data['agree']);
unset($data['customer_id']);
unset($data['delivery_id']);
unset($data['delivery_address_id']);
unset($data['detail']);
unset($data['payment_type']);
unset($data['sale_channel_id']);
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
@@ -54,7 +51,14 @@ class Orders
public static function edit($id)
{
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(),
'delivery_types' => DeliveryTypes::getOptions(),
'payment_types' => self::paymentTypes(),
@@ -107,7 +111,7 @@ class Orders
public static function getNewRef()
{
$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;
}

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
@extends('layout.index', [
'title' => __('shop.orders.title'),
'subtitle' => __('shop.orders.edit'),
'breadcrumb' => ['Commandes']
'breadcrumb' => ['Commandes'],
])
@section('content')
@@ -9,52 +9,49 @@
<input type="hidden" name="id" value="{{ $order['id'] ?? null }}">
<x-card>
<div class="row">
<div class="col-6">
<h4>{{ $order['delivery']['name'] }} </h4>
<div class="col-9">
<h5>
<a href="{{ route('Admin.Shop.Invoices.edit', ['id' => $order['invoice']['id']]) }}"
class="btn btn-success">
<i class="fa fa-file-invoice"></i>
</a>
Commande : {{ $order['ref'] }}
<span class="small">
du {{ Carbon\Carbon::parse($order['created_at'])->isoFormat('LLLL') }}
</span>
</h5>
</div>
<div class="col-6 text-right">
<div class="col-3 text-right">
<x-save />
</div>
</div>
<div class="row mb-3">
<div class="col-6">
<h3>
{{ $order['customer']['last_name'] }} {{ $order['customer']['first_name'] }}
</h3>
<div class="row">
<div class="col-6">
<x-card title="Adresse de facturation" classBody="mt-3">
@if ($order['invoice']['address'])
{{ $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/>
<h5>
{{ $order['customer']['first_name'] }} {{ $order['customer']['last_name'] }}
@if ($order['customer']['company'])
<br>
{{ $order['customer']['company'] }}
@endif
</x-card>
</div>
<div class="col-6">
<x-card title="Adresse de livraison" classBody="mt-3">
</h5>
<h6>
{{ $order['delivery']['name'] }}<br>
Canal de vente : {{ $order['sale_channel']['name'] ?? '' }}
</h6>
@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 title="Adresse de livraison" classBody="mt-3">
@include('components.address-view', [
'address' => $order['delivery_address'],
])
</x-card>
</div>
</div>
@endif
</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',
@@ -64,17 +61,6 @@
'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',
@@ -85,8 +71,11 @@
])
</div>
</div>
@if ($order['delivery']['at_house'])
<x-card title="Livraison">
<div class="row mb-3">
<div class="col-4">
<div class="col-6">
@include('components.form.select', [
'label' => 'Type de livraison',
'name' => 'delivery_type_id',
@@ -95,22 +84,25 @@
'with_empty' => '',
])
</div>
<div class="col-4">
<div class="col-6">
@include('components.form.input', [
'label' => 'Référence colis',
'name' => 'delivery_ref',
'value' => $order['delivery_ref'] ?? null,
])
</div>
<div class="col-4">
</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">

View File

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

View File

@@ -33,9 +33,7 @@
function handleDeliveryTypes() {
$('input.delivery_type').change(function() {
var deliveryTypeId = $(this).val();
var deliveryId = $('input[name=delivery_id]').val()
console.log(deliveryId);
console.log(deliveryTypeId);
var deliveryId = $('input[name=delivery_id]:checked').val()
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 />