From 9f9b7173d74e6320a7e3cbfb8f274525ea39c38b Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Wed, 24 May 2023 23:30:29 +0200 Subject: [PATCH] fixes on mail templates, change order edit layout, add DeliveryTypes, DeliveryTypeCalculations & DeliveryPackages --- app/Mail/Acheminement.php | 3 + app/Mail/ConfirmationCommande.php | 41 ++++++++++-- app/Mail/Preparation.php | 1 - app/Models/Shop/DeliveryPackage.php | 16 +++++ app/Models/Shop/DeliveryType.php | 11 ++++ app/Models/Shop/DeliveryTypeCalculation.php | 26 ++++++++ app/Models/Shop/Order.php | 5 ++ app/Repositories/Core/PDF.php | 21 +++++++ .../Shop/DeliveryTypeCalculations.php | 18 ++++++ app/Repositories/Shop/DeliveryTypes.php | 13 ++++ app/Repositories/Shop/Orders.php | 33 +++++----- .../views/Admin/Shop/Orders/edit.blade.php | 62 ++++++++++++++----- .../views/Admin/Shop/Orders/form.blade.php | 13 +++- 13 files changed, 220 insertions(+), 43 deletions(-) create mode 100644 app/Models/Shop/DeliveryPackage.php create mode 100644 app/Models/Shop/DeliveryType.php create mode 100644 app/Models/Shop/DeliveryTypeCalculation.php create mode 100644 app/Repositories/Shop/DeliveryTypeCalculations.php create mode 100644 app/Repositories/Shop/DeliveryTypes.php diff --git a/app/Mail/Acheminement.php b/app/Mail/Acheminement.php index d8881a3b..17ee3437 100644 --- a/app/Mail/Acheminement.php +++ b/app/Mail/Acheminement.php @@ -27,6 +27,8 @@ class Acheminement extends TemplateMailable public $numero_suivi; + public $lien_suivi; + public $numero_commande; public $adresse; @@ -49,6 +51,7 @@ class Acheminement extends TemplateMailable $this->societe = $order->customer->company; $this->email = $order->customer->email; $this->numero_suivi = $order->delivery_ref; + $this->lien_suivi = $order->delivery_link; $this->numero_commande = $order->ref; $this->date_expedition = $order->updated_at; $this->facture = Invoices::getInvoiceHtml($order->invoice->id); diff --git a/app/Mail/ConfirmationCommande.php b/app/Mail/ConfirmationCommande.php index 9b74db5b..bfad8a51 100644 --- a/app/Mail/ConfirmationCommande.php +++ b/app/Mail/ConfirmationCommande.php @@ -14,16 +14,45 @@ class ConfirmationCommande extends TemplateMailable protected static $templateModelClass = MailTemplate::class; - public $user; + public $email; - public $male; + public $nom; + + public $prenom; + + public $societe; public $subject; - public function __construct($user, $subject = '') + public $numero_commande; + + public $date_commande; + + public $facturation_adresse; + + public $facturation_cp; + + public $facturation_ville; + + public $livraison_adresse; + + public $livraison_cp; + + public $livraison_ville; + + public function __construct($order) { - $this->user = $user; - $this->male = $user->gender == 1; - $this->subject = $subject; + $this->prenom = $order->customer->first_name; + $this->nom = $order->customer->last_name; + $this->facturation_adresse = $order->address->address; + $this->facturation_cp = $order->address->zipcode; + $this->facturation_ville = $order->address->city; + $this->livraison_adresse = $order->delivery_address->address; + $this->livraison_cp = $order->delivery_address->zipcode; + $this->livraison_ville = $order->delivery_address->city; + $this->societe = $order->customer->company; + $this->email = $order->customer->email; + $this->numero_commande = $order->ref; + $this->date_commande = $order->created_at; } } diff --git a/app/Mail/Preparation.php b/app/Mail/Preparation.php index 9eeb672e..2baf9e8b 100644 --- a/app/Mail/Preparation.php +++ b/app/Mail/Preparation.php @@ -30,6 +30,5 @@ class Preparation extends TemplateMailable $this->nom = $order->customer->last_name; $this->societe = $order->customer->company; $this->email = $order->customer->email; - $this->subject = $subject; } } diff --git a/app/Models/Shop/DeliveryPackage.php b/app/Models/Shop/DeliveryPackage.php new file mode 100644 index 00000000..7cfadb39 --- /dev/null +++ b/app/Models/Shop/DeliveryPackage.php @@ -0,0 +1,16 @@ +orderBy('weight')->where($this->table . '.weight', '>=', $weight); + } +} diff --git a/app/Models/Shop/DeliveryType.php b/app/Models/Shop/DeliveryType.php new file mode 100644 index 00000000..874d57a8 --- /dev/null +++ b/app/Models/Shop/DeliveryType.php @@ -0,0 +1,11 @@ +belongsTo(DeliveryType::class); + } + + public function scopeByDeliveryType($query, $id) + { + return $query->where($this->table . '.type_id', $id); + } + + public function scopeByWeight($query, $weight) + { + return $query->orderBy('weight')->where($this->table . '.weight', '>=', $weight); + } +} diff --git a/app/Models/Shop/Order.php b/app/Models/Shop/Order.php index 417cab73..50002554 100644 --- a/app/Models/Shop/Order.php +++ b/app/Models/Shop/Order.php @@ -26,6 +26,11 @@ class Order extends Model return $this->belongsTo(CustomerAddress::class, 'customer_address_id'); } + public function delivery_address() + { + return $this->belongsTo(CustomerAddress::class, 'customer_delivery_id'); + } + public function delivery() { return $this->belongsTo(Delivery::class); diff --git a/app/Repositories/Core/PDF.php b/app/Repositories/Core/PDF.php index 305ba64a..52df7bba 100644 --- a/app/Repositories/Core/PDF.php +++ b/app/Repositories/Core/PDF.php @@ -10,6 +10,27 @@ use Symfony\Component\Process\Process; class PDF { + public function convertView($view, $data, $filename) + { + try { + Browsershot::html(view($view, $data)->render()) + ->noSandbox() + ->waitUntilNetworkIdle() + ->format('A4') + ->showBackground() + ->savePdf("temp.pdf"); + + $postRoute = URL::signedRoute('orderinvoices.store', ['order' => $this->order]); + Http::attach('invoice', file_get_contents('temp.pdf'), $filename) + ->post($postRoute) + ->throw(); + } + catch (\Exception $exception ) + { + Log::error($exception); + } + } + public static function view($view, $data, $filename = 'file.pdf') { \Debugbar::disable(); diff --git a/app/Repositories/Shop/DeliveryTypeCalculations.php b/app/Repositories/Shop/DeliveryTypeCalculations.php new file mode 100644 index 00000000..60fb0b12 --- /dev/null +++ b/app/Repositories/Shop/DeliveryTypeCalculations.php @@ -0,0 +1,18 @@ +get(); + } + + public static function getPrice($type_id, $weight) + { + return DeliveryTypeCalculation::byDeliveryType($type_id)->byWeight($weight)->get(); + } +} diff --git a/app/Repositories/Shop/DeliveryTypes.php b/app/Repositories/Shop/DeliveryTypes.php new file mode 100644 index 00000000..7d500aef --- /dev/null +++ b/app/Repositories/Shop/DeliveryTypes.php @@ -0,0 +1,13 @@ +toArray()); - exit; - self::sendPreparation($order); + self::sendPreparation($id); } public static function sendOrderConfirmed($order_id) { - $order = self::get($order_id, ['customer']); - $mail = new Acheminement($order); - return Mail::to($order->email)->send($mail); - } - - public static function sendShipping($order_id) - { - $order = self::get($order_id, ['customer']); - $mail = new Acheminement($order); - return Mail::to($order->email)->send($mail); + $order = self::get($order_id, ['customer', 'address']); + $mail = new ConfirmationCommande($order); + return Mail::to($order->customer->email)->send($mail); } public static function sendPreparation($order_id) { - $order = self::get($order_id, ['customer']); + $order = self::get($order_id, ['customer', 'address']); $mail = new Preparation($order); - return Mail::to($order->email)->send($mail); + return Mail::to($order->customer->email)->send($mail); + } + + public static function sendShipping($order_id) + { + $order = self::get($order_id, ['customer', 'address']); + $mail = new Acheminement($order); + return Mail::to($order->customer->email)->send($mail); } public static function count() @@ -99,8 +97,9 @@ class Orders public static function edit($id) { return [ - 'order' => self::get($id, ['customer', 'address', 'detail']), + 'order' => self::get($id, ['customer', 'address', 'delivery_address', 'detail']), 'statuses' => self::statuses(), + 'delivery_types' => DeliveryTypes::getOptions(), 'payment_types' => self::paymentTypes(), 'sale_channels' => SaleChannels::getOptions(), ]; diff --git a/resources/views/Admin/Shop/Orders/edit.blade.php b/resources/views/Admin/Shop/Orders/edit.blade.php index 2862baf7..765b5ce9 100644 --- a/resources/views/Admin/Shop/Orders/edit.blade.php +++ b/resources/views/Admin/Shop/Orders/edit.blade.php @@ -21,14 +21,23 @@

{{ $order['customer']['last_name'] }} {{ $order['customer']['first_name'] }}

-
-
- @if ($order['address']) - {{ $order['address']['address'] }}
- @isset ($order['address']['address2']) {{ $order['address']['address2'] }}
@endisset - {{ $order['address']['zipcode'] }} {{ $order['address']['city'] }}
- @endif -
+
+ + @if ($order['address']) + {{ $order['address']['address'] }}
+ @isset ($order['address']['address2']) {{ $order['address']['address2'] }}
@endisset + {{ $order['address']['zipcode'] }} {{ $order['address']['city'] }}
+ @endif +
+
+
+ + @if ($order['delivery_address']) + {{ $order['delivery_address']['address'] }}
+ @isset ($order['delivery_address']['address2']) {{ $order['delivery_address']['address2'] }}
@endisset + {{ $order['delivery_address']['zipcode'] }} {{ $order['delivery_address']['city'] }}
+ @endif +
@@ -49,7 +58,7 @@
-
+
@include('components.form.select', [ 'label' => 'Canal de vente', 'name' => 'sale_channel_id', @@ -58,14 +67,7 @@ 'class' => 'select2', ])
-
- @include('components.form.input', [ - 'label' => 'Référence colis', - 'name' => 'delivery_ref', - 'value' => $order['deivery_ref'], - ]) -
-
+
@include('components.form.select', [ 'label' => 'Règlement', 'name' => 'payment_type', @@ -75,6 +77,32 @@ ])
+
+
+ @include('components.form.select', [ + 'label' => 'Type de livraison', + 'name' => 'delivery_type_id', + 'list' => $delivery_types ?? [], + 'value' => $order['delivery_type_id'], + 'with_empty' => '', + ]) +
+
+ @include('components.form.input', [ + 'label' => 'Référence colis', + 'name' => 'delivery_ref', + 'value' => $order['delivery_ref'] ?? null, + ]) +
+
+ @include('components.form.input', [ + 'label' => 'Lien suivi', + 'name' => 'delivery_link', + 'value' => $order['delivery_link'] ?? null, + ]) +
+ +
diff --git a/resources/views/Admin/Shop/Orders/form.blade.php b/resources/views/Admin/Shop/Orders/form.blade.php index 532cd00c..6accd7fb 100644 --- a/resources/views/Admin/Shop/Orders/form.blade.php +++ b/resources/views/Admin/Shop/Orders/form.blade.php @@ -4,10 +4,19 @@
{{ Form::label('name', 'Nom') }} - @include('components.form.input', ['name' => 'name', 'value' => (isset($family['name'])) ? $family['name'] : null, 'required' => true]) + @include('components.form.input', [ + 'name' => 'name', + 'value' => $family['name'] ?? null, + 'required' => true, + ]) {{ Form::label('description', 'Description') }} - @include('components.form.textarea', ['name' => 'description', 'value' => isset($description) ? $description : null, 'class' => 'editor', 'required' => false]) + @include('components.form.textarea', [ + 'name' => 'description', + 'value' => $description ?? null, + 'class' => 'editor', + 'required' => false, + ])