diff --git a/app/Datatables/Shop/CustomerOrdersDataTable.php b/app/Datatables/Shop/CustomerOrdersDataTable.php index ed2d6aec..68cacd7a 100644 --- a/app/Datatables/Shop/CustomerOrdersDataTable.php +++ b/app/Datatables/Shop/CustomerOrdersDataTable.php @@ -36,7 +36,11 @@ class CustomerOrdersDataTable extends DataTable public function getHtmlButtons() { - return self::getButtonShow('uuid', 'Voir la commande'); + $buttons = ''; + + $buttons .= self::getButtonShow('uuid', 'Voir la facture'); + + return $buttons; } public function modifier($datatables) diff --git a/app/Repositories/Shop/CustomerAddresses.php b/app/Repositories/Shop/CustomerAddresses.php index 93a9142a..05e82a98 100644 --- a/app/Repositories/Shop/CustomerAddresses.php +++ b/app/Repositories/Shop/CustomerAddresses.php @@ -24,6 +24,26 @@ class CustomerAddresses ]); } + public static function getInvoiceAddress($customerId) + { + $addresses = CustomerAddress::byCustomer($customerId)->byInvoicing()->get(); + if (count($addresses)) { + $address = $addresses->first(); + } + + return $address; + } + + public static function getDeliveryAddress($customerId) + { + $addresses = CustomerAddress::byCustomer($customerId)->byDelivery()->get(); + if (count($addresses)) { + $address = $addresses->first(); + } + + return $address; + } + public static function storeByCustomer($customer, $data) { $deliveries = $data['deliveries'] ?? false; diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php index 0a255544..b57e2bc4 100644 --- a/app/Repositories/Shop/Customers.php +++ b/app/Repositories/Shop/Customers.php @@ -55,15 +55,12 @@ class Customers public static function editProfile($id = false) { - $datatableOrders = new CustomerOrdersDataTable(); - $datatableInvoices = new CustomerInvoicesDataTable(); - - return [ + return $id ? [ 'customer' => self::get($id, ['addresses', 'deliveries'])->toArray(), 'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(), - 'orders' => $datatableOrders->html(), - 'invoices' => $datatableInvoices->html(), - ]; + 'orders' => (new CustomerOrdersDataTable())->html(), + 'invoices' => (new CustomerInvoicesDataTable())->html(), + ] : abort('403'); } public static function getAvatar($id = false) @@ -151,6 +148,9 @@ class Customers public static function edit($id) { + if (!$id) { + abort('403'); + } $customer = self::get($id, ['delivery_addresses', 'invoice_addresses', 'sale_channels']); $data = $customer->toArray(); $data['sale_channels'] = $customer->sale_channels->pluck('id')->toArray(); diff --git a/resources/views/Shop/Customers/partials/deliveries.blade.php b/resources/views/Shop/Customers/partials/deliveries.blade.php index c34f8ade..d45862b7 100644 --- a/resources/views/Shop/Customers/partials/deliveries.blade.php +++ b/resources/views/Shop/Customers/partials/deliveries.blade.php @@ -6,11 +6,20 @@ 'id_name' => 'delivery_id_' . $delivery['id'], 'value' => $delivery['id'], 'checked' => $customer['sale_delivery_id'] ?? false, + 'class' => 'delivery', ])
- {{ $delivery['name'] }} - {{ $delivery['sale_channel']['name'] }}
+ {{ $delivery['name'] }} - {{ $delivery['sale_channel']['name'] }}

{{ $delivery['description'] }}

@endforeach + +@push('js') + +@endpush diff --git a/resources/views/load/form/toggle.blade.php b/resources/views/load/form/toggle.blade.php index 8d20a6fc..62aff714 100644 --- a/resources/views/load/form/toggle.blade.php +++ b/resources/views/load/form/toggle.blade.php @@ -1,34 +1,33 @@ -@if(!defined('LOAD_TOGGLE')) - @push('scripts') - +@if (!defined('LOAD_TOGGLE')) + @push('scripts') + - + + @endpush - @push('css') - - @endpush - @php(define('LOAD_TOGGLE', true)) -@endif \ No newline at end of file + @push('css') + + @endpush + @php(define('LOAD_TOGGLE', true)) +@endif