Skip to content

Commit

Permalink
Merge branch 'master' into aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed May 4, 2024
2 parents 831b06e + ed847d3 commit 001dc02
Show file tree
Hide file tree
Showing 37 changed files with 310 additions and 169 deletions.
1 change: 1 addition & 0 deletions code/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

QUEUE_DRIVER=loopback
QUEUE_LOOPBACK_KEY=InsertHereARandomString

MAIL_MAILER=smtp
Expand Down
8 changes: 1 addition & 7 deletions code/app/Console/Commands/OpenOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;

Expand All @@ -19,16 +20,13 @@ private function getDates()
{
$dates = Date::where('type', 'order')->get();
$today = date('Y-m-d');
\Log::debug('Oggi ' . $today . ' ci sono ' . $dates->count() . ' date per apertura ordini');
$aggregable = [];

foreach($dates as $date) {
try {
$all_previous = true;

foreach($date->order_dates as $d) {
\Log::debug($date->id . ' / ' . $d->start . ' / ' . $d->end . ' / ' . $d->shipping);

if ($d->start < $today) {
// @phpstan-ignore-next-line
$all_previous = $all_previous && true;
Expand All @@ -37,7 +35,6 @@ private function getDates()
$all_previous = false;
}
else if ($d->start == $today) {
\Log::debug('Data apertura ordine!');
$all_previous = false;

/*
Expand All @@ -47,7 +44,6 @@ private function getDates()
scaduto o meno, e nel caso va eliminato
*/
if ($date->suspend) {
\Log::debug('Data sospesa');
continue;
}

Expand All @@ -58,7 +54,6 @@ private function getDates()
*/
$supplier = $d->target;
if (is_null($supplier) || $supplier->orders()->withoutGlobalScopes()->where('start', $today)->count() != 0) {
\Log::debug('Fornitore non trovato, o ordine già aperto');
continue;
}

Expand All @@ -72,7 +67,6 @@ private function getDates()
}

if ($all_previous) {
Log::debug('Rimosso ordine ricorrente non più operativo: ' . $date->id);
$date->delete();
}
}
Expand Down
22 changes: 14 additions & 8 deletions code/app/Jobs/AggregateSummaries.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

namespace App\Jobs;

use Log;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use App\Notifications\BookingNotification;

use App\Aggregate;

class AggregateSummaries extends Job
class AggregateSummaries implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public $aggregate_id;
public $message;

public function __construct($aggregate_id, $message = '')
{
parent::__construct();
$this->aggregate_id = $aggregate_id;
$this->message = $message;
}
Expand All @@ -33,15 +37,17 @@ private function handleBookings($aggregate, $status)
$booking->user->notify(new BookingNotification($this->aggregate_id, $redux, $booking->user->id, $this->message));
}
catch(\Exception $e) {
Log::error('Impossibile inviare notifica mail prenotazione di ' . $booking->user->id);
\Log::error('Impossibile inviare notifica mail prenotazione di ' . $booking->user->id . ': ' . $e->getMessage());
}
}
}

protected function realHandle()
public function handle()
{
$hub = app()->make('GlobalScopeHub');

$aggregate = Aggregate::findOrFail($this->aggregate_id);
$this->hub->enable(false);
$hub->enable(false);

$date = date('Y-m-d');
foreach($aggregate->orders as $order) {
Expand All @@ -57,6 +63,6 @@ protected function realHandle()
}

$this->handleBookings($aggregate, $status);
$this->hub->enable(true);
$hub->enable(true);
}
}
13 changes: 10 additions & 3 deletions code/app/Jobs/DeleteFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

namespace App\Jobs;

class DeleteFiles extends Job
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class DeleteFiles implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public $files;

public function __construct($files)
{
parent::__construct();
$this->files = $files;
}

protected function realHandle()
public function handle()
{
foreach($this->files as $file) {
@unlink($file);
Expand Down
16 changes: 10 additions & 6 deletions code/app/Jobs/DeliverNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

namespace App\Jobs;

use Log;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use App\Notifications\GenericNotificationWrapper;

use App\Notification;

class DeliverNotification extends Job
class DeliverNotification implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public $notification_id;

public function __construct($notification_id)
{
parent::__construct();
$this->notification_id = $notification_id;
}

protected function realHandle()
public function handle()
{
$notification = Notification::findOrFail($this->notification_id);

Expand All @@ -27,7 +31,7 @@ protected function realHandle()
$user->notify(new GenericNotificationWrapper($notification));
}
catch(\Exception $e) {
Log::error('Impossibile inoltrare mail di notifica a utente ' . $user->id . ': ' . $e->getMessage());
\Log::error('Impossibile inoltrare mail di notifica a utente ' . $user->id . ': ' . $e->getMessage());
}
}
}
Expand Down
42 changes: 0 additions & 42 deletions code/app/Jobs/Job.php

This file was deleted.

30 changes: 24 additions & 6 deletions code/app/Jobs/NotifyClosedOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use App\Notifications\ClosedOrdersNotification;
use App\Notifications\SupplierOrderShipping;
use App\Printers\Order as OrderPrinter;
use App\User;
use App\Order;

class NotifyClosedOrder extends Job
class NotifyClosedOrder implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public $orders;

public function __construct($orders)
{
parent::__construct();
$this->orders = $orders;
}

Expand Down Expand Up @@ -45,9 +52,11 @@ private function dispatchToSupplier($order)
$supplier = $order->supplier;

if ($supplier->notify_on_close_enabled != 'none') {
$hub = app()->make('GlobalScopeHub');

foreach($order->aggregate->gas as $gas) {
try {
$this->hub->enable(false);
$hub->enable(false);
$files = $this->filesForSupplier($order);

/*
Expand All @@ -57,7 +66,7 @@ private function dispatchToSupplier($order)
*/
$supplier->notify(new SupplierOrderShipping($gas, $order, $files));

$this->hub->enable(true);
$hub->enable(true);
}
catch(\Exception $e) {
\Log::error('Errore in notifica chiusura ordine a fornitore: ' . $e->getMessage() . "\n" . $e->getTraceAsString());
Expand All @@ -83,20 +92,29 @@ private function dispatchToReferents($notifiable_users)
}
}

protected function realHandle()
public function handle()
{
$printer = new OrderPrinter();
$notifiable_users = [];
$all_files = [];
$aggregates = [];

$hub = app()->make('GlobalScopeHub');
$hub->enable(false);

foreach($this->orders as $order_id) {
$order = Order::find($order_id);
if (is_null($order)) {
\Log::error('Non trovato ordine in fase di notifica chiusura: ' . $order_id . ' / ' . env('DB_DATABASE'));
continue;
}

$aggregate = $order->aggregate;
$closed_aggregate = ($aggregate->last_notify == null && $aggregate->status == 'closed');

foreach($aggregate->gas as $gas) {
$this->hub->setGas($gas->id);
$hub->enable(true);
$hub->setGas($gas->id);

/*
Nota: il flag send_mail serve solo a farsi restituire il
Expand Down
18 changes: 12 additions & 6 deletions code/app/Jobs/NotifyNewOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@

namespace App\Jobs;

use Log;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use App\Notifications\NewOrderNotification;
use App\Order;

class NotifyNewOrder extends Job
class NotifyNewOrder implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public $order_id;

public function __construct($order_id)
{
parent::__construct();
$this->order_id = $order_id;
}

protected function realHandle()
public function handle()
{
$order = Order::find($this->order_id);

Expand All @@ -27,17 +32,18 @@ protected function realHandle()

$order->first_notify = date('Y-m-d');
$order->save();
$hub = app()->make('GlobalScopeHub');

foreach($order->aggregate->gas as $gas) {
$this->hub->setGas($gas->id);
$hub->setGas($gas->id);
$users = $order->notifiableUsers($gas);

foreach($users as $user) {
try {
$user->notify(new NewOrderNotification($order));
}
catch(\Exception $e) {
Log::error('Impossibile inoltrare mail di notifica apertura ordine: ' . $e->getMessage());
\Log::error('Impossibile inoltrare mail di notifica apertura ordine: ' . $e->getMessage());
}
}
}
Expand Down
Loading

0 comments on commit 001dc02

Please sign in to comment.