use App\Models\Client;
use App\Models\Order;
+use App\Models\User;
+use App\Notifications\ResahNotification;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
$client->enabled = false;
$client->save();
+ User::withoutGlobalScopes()->find(3)->notify(new ResahNotification(ResahNotification::ACCOUNT_CREATED, $client));
+
return response()->json(['success' => 'ok'])->setStatusCode(200);
}
. 'ECOTAXE : ' . self::formatNumber($cumul_ecotaxe) . "\n"
. 'TOTAL TTC : ' . self::formatNumber($total + $cumul_ecotaxe + $cumul_tva);
+ /** @var Client $user */
+ $user = auth()->guard('client')->user();
$order = new Order();
- $order->client = auth()->guard('client')->user()->id;
+ $order->client = $user->id;
$order->details = implode("\n\n----\n\n", $details);
$order->quantity = $quantity;
$order->total_ht = $total;
-
$order->save();
+
+ $user->notify(new ResahNotification(ResahNotification::QUOTE_REQUEST_SENT, $order));
+ User::withoutGlobalScopes()->find(3)->notify(new ResahNotification(ResahNotification::QUOTE_REQUEST, $order));
+
}
protected static function formatNumber($n, $suffix = ' €')
use App\Http\Controllers\Operations\Client\Fluidbook;
use App\Http\Controllers\Operations\Client\Landing;
+use App\Notifications\ResahNotification;
use Cubist\Backpack\Magic\Fields\Text;
use Cubist\Backpack\Magic\Models\CubistMagicAuthenticatable;
+use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Password;
class Client extends CubistMagicAuthenticatable
{
+ use Notifiable;
+
protected $table = 'client';
protected $_options = ['name' => 'client',
'singular' => 'client',
$this->addField('function', Text::class, 'Fonction', ['tab' => 'Login']);
$this->addField('phone', Text::class, 'Numéro de téléphone', ['tab' => 'Login']);
}
+
+ public function onSaving(): bool
+ {
+ if ($this->isDirty('enabled') && $this->enabled) {
+ $this->notify(new ResahNotification(ResahNotification::ACCOUNT_VALIDATED, null));
+ }
+ return parent::onSaving();
+ }
}
--- /dev/null
+<?php
+
+namespace App\Notifications;
+
+use App\Models\User;
+use Illuminate\Bus\Queueable;
+use Illuminate\Notifications\Messages\MailMessage;
+use Illuminate\Notifications\Notification;
+use Illuminate\Support\HtmlString;
+use NotificationChannels\WebPush\WebPushChannel;
+
+class ResahNotification extends Notification
+{
+ use Queueable;
+
+ const ACCOUNT_CREATED = 0;
+ const ACCOUNT_VALIDATED = 1;
+ const QUOTE_REQUEST = 2;
+ const QUOTE_REQUEST_SENT = 3;
+ const FORGOT_PASSWORD = 4;
+
+ /**
+ * @var int
+ */
+ protected $type = -1;
+ protected $data;
+
+ public function __construct($type, $data)
+ {
+ $this->type = $type;
+ $this->data = $data;
+ }
+
+ public function via($notifiable)
+ {
+ return ['mail'];
+ }
+
+ /**
+ * Get the mail representation of the notification.
+ *
+ * @param mixed $notifiable
+ * @return \Illuminate\Notifications\Messages\MailMessage
+ */
+ public function toMail($notifiable)
+ {
+ $greetings = 'Bonjour,';
+ $salutation = 'Cordialement,<br><br>L\'équipe Bastide-resah.fr';
+ $subjectPrefix = '';
+ if ($notifiable instanceof User) {
+ $greetings = '';
+ $salutation = 'Message envoyé automatiquement depuis le site Bastide-resah.fr';
+ $subjectPrefix = '[Bastide-resah.fr] ';
+ }
+
+ if ($this->type === self::ACCOUNT_CREATED) {
+ $url = backpack_url('/client/' . $this->data->id . '/edit');
+ $subject = 'Nouveau compte en attente de validation';
+ $html = 'Un nouveau compte client a été créé.<br>Pour le valider, rendez-vous sur <a href="' . $url . '">' . $url . '</a>';
+ } else if ($this->type === self::ACCOUNT_VALIDATED) {
+ $subject = 'Votre compte Bastide-resah.fr a été validé';
+ $url = url('/');
+ $html = 'Votre compte client Bastide-resah.fr a été validé.<br><br>Pous pouvez dès à présent vous connecter sur <a href="' . $url . '">' . $url . '</a> pour consulter le catalogue interactif complet avec les tarifs. Vous pourrez y sélectionner vos produits, déterminer votre budget en instantané, et recevoir un devis par le Resah dans les 72h.';
+ } else if ($this->type === self::QUOTE_REQUEST) {
+ $subject = 'Demande de devis';
+ $url = backpack_url('/order/' . $this->data->id . '/edit');
+ $html = 'Une nouvelle demande de devis a été envoyée.<br>Pour la visualiser, rendez-vous sur <a href="' . $url . '">' . $url . '</a>';
+ //$file = storage_path('orders/' . $this->data->id . '.pdf');
+ } else if ($this->type === self::QUOTE_REQUEST_SENT) {
+ $subject = 'Votre demande de devis sur Bastide-resah.fr';
+ $html = 'Votre demande de devis est en cours de traitement (récapitulatif en pièce jointe).<br>Nous vous recontacterons dans les meilleurs délais.';
+ //$file = storage_path('orders/' . $this->data->id . '.pdf');
+ }
+
+
+ $m = (new MailMessage);
+ $m->subject($subjectPrefix . $subject);
+ $m->greeting($greetings);
+ if ($html) {
+ $m->line(new HtmlString($html));
+ }
+ if ($salutation) {
+ $m->salutation(new HtmlString($salutation));
+ }
+ if (isset($file) && file_exists($file)) {
+ $m->attach($file);
+ }
+
+ return $m;
+
+ }
+}