fixes on mail templates, change order edit layout, add DeliveryTypes, DeliveryTypeCalculations & DeliveryPackages

This commit is contained in:
Ludovic CANDELLIER
2023-05-24 23:30:29 +02:00
parent c677dbd5fa
commit 9f9b7173d7
13 changed files with 220 additions and 43 deletions

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class DeliveryPackage extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_delivery_packages';
public function scopeByWeight($query, $weight)
{
return $query->orderBy('weight')->where($this->table . '.weight', '>=', $weight);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class DeliveryType extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_delivery_types';
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class DeliveryTypeCalculation extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_delivery_type_calculations';
public function DeliveryType()
{
return $this->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);
}
}

View File

@@ -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);

View File

@@ -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();

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\DeliveryTypeCalculation;
class DeliveryTypeCalculations
{
public static function getByDeliveryType($type_id)
{
return DeliveryTypeCalculation::byDeliveryTpe($type_id)->get();
}
public static function getPrice($type_id, $weight)
{
return DeliveryTypeCalculation::byDeliveryType($type_id)->byWeight($weight)->get();
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\DeliveryType;
class DeliveryTypes
{
public static function getOptions()
{
return DeliveryType::pluck('name', 'id');
}
}

View File

@@ -4,6 +4,7 @@ namespace App\Repositories\Shop;
use Carbon\Carbon;
use App\Mail\Acheminement;
use App\Mail\ConfirmationCommande;
use App\Mail\Preparation;
use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
@@ -39,31 +40,28 @@ class Orders
public static function testSend($id)
{
$order = self::get($id, ['customer', 'address']);
dump($order->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(),
];