]> _ Git - bastide-resah.git/commitdiff
wip #6883 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 24 Apr 2024 17:00:27 +0000 (19:00 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 24 Apr 2024 17:00:27 +0000 (19:00 +0200)
.env.production
app/Http/Controllers/FluidbookController.php
app/Models/Client.php
app/Notifications/ResahNotification.php [new file with mode: 0644]
resources/views/vendor/mail/html/message.blade.php [new file with mode: 0644]

index 22e8d4f79abdf92b7acf5c967caf605ed5117189..f23217f0c9e84524e9c684ba3f66e0dcc665bb05 100644 (file)
@@ -1,4 +1,4 @@
-APP_NAME=bastide-resah
+APP_NAME=Bastide-resah.fr
 APP_ENV=production
 APP_KEY=base64:OpYzvRTnIiViilkl5ngdoPNJ6UQeQUB8WBKhR4XD/UY=
 APP_DEBUG=true
index 7fe07354766fbab6b967c654d630551071850bc1..f80ff64e2fd248a3519541a11d55bae9f258e223 100644 (file)
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
 
 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;
@@ -51,6 +53,8 @@ class FluidbookController extends Controller
             $client->enabled = false;
             $client->save();
 
+            User::withoutGlobalScopes()->find(3)->notify(new ResahNotification(ResahNotification::ACCOUNT_CREATED, $client));
+
             return response()->json(['success' => 'ok'])->setStatusCode(200);
 
         }
@@ -128,13 +132,18 @@ class FluidbookController extends Controller
             . '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 = ' €')
index 1950a98150516a86d494b70a6efd9ca5f18e9436..d92e80018bd5e297d09fe6daa36c7f9cddea4236 100644 (file)
@@ -4,12 +4,16 @@ namespace App\Models;
 
 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',
@@ -31,4 +35,12 @@ class Client extends CubistMagicAuthenticatable
         $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();
+    }
 }
diff --git a/app/Notifications/ResahNotification.php b/app/Notifications/ResahNotification.php
new file mode 100644 (file)
index 0000000..a116ce6
--- /dev/null
@@ -0,0 +1,92 @@
+<?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;
+
+    }
+}
diff --git a/resources/views/vendor/mail/html/message.blade.php b/resources/views/vendor/mail/html/message.blade.php
new file mode 100644 (file)
index 0000000..986fa24
--- /dev/null
@@ -0,0 +1,27 @@
+<x-mail::layout>
+    {{-- Header --}}
+    <x-slot:header>
+        <x-mail::header :url="config('app.url')">
+            <img src="{{url('/images/logo-bastide.svg')}}" width="100" alt="{{ config('app.name') }}">
+        </x-mail::header>
+    </x-slot:header>
+
+    {{-- Body --}}
+    {{ $slot }}
+
+    {{-- Subcopy --}}
+    @isset($subcopy)
+        <x-slot:subcopy>
+            <x-mail::subcopy>
+                {{ $subcopy }}
+            </x-mail::subcopy>
+        </x-slot:subcopy>
+    @endisset
+
+    {{-- Footer --}}
+    <x-slot:footer>
+        <x-mail::footer>
+            © {{ date('Y') }} {{ config('app.name') }}.
+        </x-mail::footer>
+    </x-slot:footer>
+</x-mail::layout>