finish implementing mails

This commit is contained in:
Ludovic CANDELLIER
2023-04-17 00:27:03 +02:00
parent 6649c32501
commit b283363543
8 changed files with 274 additions and 49 deletions

View File

@@ -26,11 +26,21 @@ class CategoryController extends Controller
dump($product_type); dump($product_type);
exit; exit;
} else { } else {
// $product_type = Articles::getProductTypeByCategory($category_id);
// dump($product_type);
$article_nature = $request->input('article_nature'); $article_nature = $request->input('article_nature');
// dump($article_nature); if (!$article_nature) {
// exit; $article_natures = Articles::getArticleNaturesWithOffers([
'category_id' => $category_id,
]);
if (count($article_natures) === 1) {
$article_nature = $article_natures[0];
}
$product_types = Articles::getProductTypesWithOffers([
'category_id' => $category_id,
]);
if (count($product_types) === 1) {
$product_type = $product_types[0];
}
}
switch ($article_nature) { switch ($article_nature) {
case 'semences': case 'semences':
@@ -46,14 +56,17 @@ class CategoryController extends Controller
$article_nature_id = 3; $article_nature_id = 3;
break; break;
default: default:
if (!($product_type ?? false)) {
$product_type = 'botanic'; $product_type = 'botanic';
$article_nature_id = 1; $article_nature_id = 1;
$article_nature = 'semences'; $article_nature = 'semences';
}
break; break;
} }
// $product_type = ArticleNatures::getProductType($article_nature_id); // $product_type = ArticleNatures::getProductType($article_nature_id);
// dump($product_type); // dump($product_type);
// dump($article_nature_id); // dump($article_nature_id);
// exit;
} }
// exit; // exit;
$data = [ $data = [
@@ -62,12 +75,8 @@ class CategoryController extends Controller
'display_by_rows' => $request->input('display_by_rows') ?? false, 'display_by_rows' => $request->input('display_by_rows') ?? false,
'product_type' => $product_type, 'product_type' => $product_type,
'article_nature' => $article_nature, 'article_nature' => $article_nature,
'article_natures' => Articles::getArticleNaturesWithOffers([ 'article_natures' => $article_natures,
'category_id' => $category_id, 'product_types' => $product_types,
]),
'product_types' => Articles::getProductTypesWithOffers([
'category_id' => $category_id,
]),
'tags_selected' => $request->input('tags') ?? [], 'tags_selected' => $request->input('tags') ?? [],
'articles' => Articles::getArticlesToSell([ 'articles' => Articles::getArticlesToSell([
'category_id' => $category_id, 'category_id' => $category_id,
@@ -77,6 +86,8 @@ class CategoryController extends Controller
]), ]),
'tags' => TagGroups::getWithTagsAndCountOffers($category_id), 'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
]; ];
// dump($data);
// exit;
return view('Shop.Shelves.shelve', $data); return view('Shop.Shelves.shelve', $data);
} }

View File

@@ -3,6 +3,7 @@
namespace App\Mail; namespace App\Mail;
use App\Models\Core\Mail\MailTemplate; use App\Models\Core\Mail\MailTemplate;
use App\Repositories\Shop\Invoices;
use App\Repositories\Shop\Traits\MailCustomers; use App\Repositories\Shop\Traits\MailCustomers;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
@@ -14,18 +15,42 @@ class Acheminement extends TemplateMailable
protected static $templateModelClass = MailTemplate::class; protected static $templateModelClass = MailTemplate::class;
public $user; public $email;
public $male; public $nom;
public $prenom;
public $societe;
public $subject; public $subject;
public $url; public $numero_suivi;
public function __construct($user, $subject = '') public $numero_commande;
public $adresse;
public $cp;
public $ville;
public $date_expedition;
public $facture;
public function __construct($order)
{ {
$this->user = $user; $this->prenom = $order->customer->first_name;
$this->male = $user->gender == 1; $this->nom = $order->customer->last_name;
$this->subject = $subject; $this->adresse = $order->address->address;
$this->cp = $order->address->zipcode;
$this->ville = $order->address->city;
$this->societe = $order->customer->company;
$this->email = $order->customer->email;
$this->numero_suivi = $order->delivery_ref;
$this->numero_commande = $order->ref;
$this->date_expedition = $order->updated_at;
$this->facture = Invoices::getInvoiceHtml($order->invoice->id);
} }
} }

View File

@@ -24,12 +24,12 @@ class Preparation extends TemplateMailable
public $subject; public $subject;
public function __construct($user, $subject = '') public function __construct($order)
{ {
$this->prenom = $user->first_name; $this->prenom = $order->customer->first_name;
$this->nom = $user->last_name; $this->nom = $order->customer->last_name;
$this->societe = $user->society; $this->societe = $order->customer->company;
$this->email = $user->email; $this->email = $order->customer->email;
$this->subject = $subject; $this->subject = $subject;
} }
} }

View File

@@ -26,7 +26,7 @@ class Customers
public static function editProfile($id = false) public static function editProfile($id = false)
{ {
$id = $id ? $id : self::getId(); $id = $id ? $id : self::getId();
$orders_datatable = new CustomerOrdersDataTable; $orders_datatable = new CustomerOrdersDataTable();
$data = [ $data = [
'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(), 'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(),
'deliveries' => Deliveries::getAll('sale_channel')->toArray(), 'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
@@ -144,7 +144,7 @@ class Customers
return false; return false;
} }
$deliveries = collect($deliveries)->transform( $deliveries = collect($deliveries)->transform(
function ($item, $key) { function ($item) {
return (int) $item; return (int) $item;
} }
)->toArray(); )->toArray();

View File

@@ -8,6 +8,20 @@ use App\Models\Shop\Invoice;
class Invoices class Invoices
{ {
public static function getInvoiceHtml($id)
{
$invoice = self::get($id, ['order.customer', 'order.address', 'order.detail']);
$order = $invoice->order;
$customer = $order->customer;
unset($invoice->order, $order->customer);
$data = [
'invoice' => $invoice->toArray(),
'order' => $order->toArray(),
'customer' => $customer->toArray(),
];
return view('Shop.Invoices.mail', $data)->render();
}
public static function getByUUID($uuid) public static function getByUUID($uuid)
{ {
return Invoice::byUUID($uuid)->first(); return Invoice::byUUID($uuid)->first();

View File

@@ -3,10 +3,13 @@
namespace App\Repositories\Shop; namespace App\Repositories\Shop;
use Carbon\Carbon; use Carbon\Carbon;
use App\Mail\Acheminement;
use App\Mail\Preparation;
use App\Models\Shop\Order; use App\Models\Shop\Order;
use App\Repositories\Core\DateStats; use App\Repositories\Core\DateStats;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Support\Facades\Mail;
class Orders class Orders
{ {
@@ -34,6 +37,35 @@ class Orders
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false; return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
} }
public static function testSend($id)
{
$order = self::get($id, ['customer', 'address']);
dump($order->toArray());
exit;
self::sendPreparation($order);
}
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);
}
public static function sendPreparation($order_id)
{
$order = self::get($order_id, ['customer']);
$mail = new Preparation($order);
return Mail::to($order->email)->send($mail);
}
public static function count() public static function count()
{ {
return Order::count(); return Order::count();

View File

@@ -9,28 +9,6 @@ use Illuminate\Mail\Mailables\Envelope;
trait MailCustomers trait MailCustomers
{ {
public static function getContext()
{
return Customers::getOptions();
}
public static function getData($id)
{
$user = self::getUser($id);
return $user ? [
'prenom' => $user->first_name,
'nom' => $user->last_name,
'societe' => $user->society,
'email' => $user->email,
] : false;
}
public static function getUser($id)
{
return Customers::get($id);
}
public function envelope() public function envelope()
{ {
return new Envelope( return new Envelope(

View File

@@ -0,0 +1,165 @@
<table style="background-color: #fff; font-weight: 400; font-family: Arial,'HelveticaNeue',Helvetica,sans-serif;" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
<tr>
<td style="text-align: left; border: 0;" width="50%">
<img src="http://opensem.test/693d11c7-2be8-4c7e-aafb-e5baa4b097fd" style="display: block; border: 0px none; max-width: 100%;" alt="jardin'envie" width="150" height="69" align="top" />
</td>
<td align="center" width="50%">
<div style="font-weight: 400; font-family: Arial,'HelveticaNeue',Helvetica,sans-serif; color: #010000; line-height: 1.5;">
<p style="margin: 0; font-size: 26px; line-height: 1.5; word-break: break-word; letter-spacing: 5px;">
<strong>FACTURE</strong>
</p>
</div>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
<tr>
<td style="text-align: left;" width="33.3%">
<div style="font-size: 14px; color: #555; line-height: 1.2;">
<p style="margin: 0; text-align: left; color: #010000;">
<strong>Livr&eacute; &agrave;:</strong>
</p>
<span style="text-transform: capitalize; letter-spacing: 0px; color: #666666;">
{{ $order['address']['name'] }}<br />
{{ $order['address']['address'] }}<br />
{{ $order['address']['zipcode'] }} {{ $order['address']['city'] }}<br />
FR
</span>
</div>
</td>
<td style="text-align: left;" width="33.3%">
<div style="font-size: 14px; color: #555; line-height: 1.2;">
<p><strong>Factur&eacute; &agrave;:</strong></p>
<p>
{{ $customer['first_name'] }} {{ $customer['last_name'] }}<br />
{{ $customer['address'] }}<br />
{{ $customer['zipcode'] }} {{ $customer['city'] }}<br />
FR
</p>
</div>
</td>
<td style="text-align: left;" width="33.3%">
<div style="font-size: 14px; color: #555; line-height: 1.2;">
<p>Jardin'enVie Artisan Semencier SCIC SA</p>
<p>429 route des chaux</p>
<p>26500 Bourge les Valence</p>
</div>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
<tr>
<td width="33.3%">
<div style="font-size: 14px; color: #555; line-height: 1.2;">
<strong style="color: #000000;">N&deg; Facture</strong><br />
{{ $invoice['ref'] }}
</div>
</td>
<td width="33.3%">
<div style="font-size: 14px; color: #555; line-height: 1.2;">
<strong style="color: #000000;">Date D'&eacute;mission</strong><br />
{{ $invoice['created_at'] }}
</div>
</td>
<td width="33.3%">
<div style="font-size: 14px; color: #555; line-height: 1.2;">
<strong style="color: #000000;">TVA N&deg;</strong><br />
FR21 818 557 589
</div>
</td>
</tr>
<tr>
<td>
<div style="font-size: 14px; color: #000; line-height: 1.2;">
<strong>Num&eacute;ro de commande</strong><br />
{{ $order['ref'] }}
</div>
</td>
<td>
<div style="font-size: 14px; color: #000; line-height: 1.2;">
<strong>N&deg; Client </strong><br />
{{ $customer['id'] }}
</div>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
<tr>
<td>
<strong>D&eacute;signation</strong>
</td>
<td>
<strong>Quantit&eacute;</strong>
</td>
<td>
<strong>TOTAL HT</strong>
</td>
<td>
<strong>Total TVA</strong>
</td>
<td>
<strong>Total</strong>
</td>
<td>
<strong>TAUX</strong>
</td>
</tr>
<tr>
<td>
<strong>Livraison</strong>
</td>
<td colspan="3"></td>
<td align="right">{{ $invoice['shipping'] }}</td>
<td></td>
</tr>
<tr>
<td colspan="6"></td>
</tr>
@foreach ($order['detail'] as $detail)
<tr>
<td>{{ $detail['name'] }}</td>
<td>{{ $detail['quantity'] }}</td>
<td>{{ $detail['total'] }}</td>
<td>{{ $detail['total_tax'] }}</td>
<td>{{ $detail['total_taxed'] }}</td>
<td></td>
</tr>
@endforeach
<tr>
<td></td>
<td></td>
<td>TOTAL HT</td>
<td>TOTAL TVA</td>
<td>TOTAL</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td align="right">{{ $invoice['total'] }}</td>
<td align="right">{{ $invoice['taxes'] }}</td>
<td align="right">{{ $invoice['total_taxed'] }}</td>
<td>EUR</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>