File "SendOrderArtworkReminderCommand.php"

Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Console/Commands/SendOrderArtworkReminderCommand.php
File size: 2.44 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Console\Commands;

use App\Models\Order;
use App\Models\OrderArtworkReminder;
use App\Models\SiteSetting;
use App\Notifications\OrderArtworkReminderNotification;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class SendOrderArtworkReminderCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'email:send-order-artwork-reminder';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send email every 8 hours to users waiting on order.';

    public function handle(): void
    {
        if (!now()->isWeekend()) {
            $orders = OrderArtworkReminder::all();
            $company_phone_1 = SiteSetting::where('key', 'Site Phone')->first();
            $company_phone_2 = SiteSetting::where('key', 'Site Phone 2')->first();

            foreach ($orders as $key => $order) {
                $db_order = Order::find($order->order_id);

                $approve_url = config('app.react_app_artwork_approve_url');
                $templates = $attachments = [];
                foreach ($db_order->items as $item) {
                    if (!empty($item->template)) {
                        $templates[] = '<li style="text-align: center; list-style: none"><strong><a href="' . asset('storage/order/' . $item->template) . '" style="text-decoration: underline; font-size: 25px; color: blue"><u>CLICK HERE TO VIEW ARTWORK</u></a></strong></li>';
                        $attachments[] = $item->templateUrl;
                    }
                }

                $data = [
                    'order_number' => $order->order_number,
                    'user' => $order->user,
                    'notes' => $order->notes,
                    'approve_url' => $approve_url . $order->order_id,
                    'templates' => $templates,
                    'company_phone_1' => $company_phone_1->value ?? "N/A",
                    'company_phone_2' => $company_phone_2->value ?? "N/A",
                    'attachments' => $attachments,
                ];
                $order->user->notify((new OrderArtworkReminderNotification($data))->delay(now()->addSeconds($key)));
                Log::channel('cron_jobs')
                    ->info('Order artwork reminder mail sent successfully to order id : ' . $order->order_id . ' at ' . now()->format('m-d-Y h:i:s'));
            }
        }
    }
}