Skip to content

Commit

Permalink
Merge branch 'master' into fix_friends_sum
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Mar 16, 2024
2 parents a0ab7ed + 4e3fb1d commit 84536a7
Show file tree
Hide file tree
Showing 45 changed files with 1,073 additions and 488 deletions.
12 changes: 11 additions & 1 deletion code/app/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public function users(): BelongsToMany
return $this->belongsToMany('App\User', 'attachments_access');
}

public function getTypeAttribute()
{
if (empty($this->url) == false) {
return 'url';
}
else {
return 'file';
}
}

public function hasAccess($user = null)
{
if ($this->users->isEmpty()) {
Expand Down Expand Up @@ -89,7 +99,7 @@ public function getSize()

public function getDownloadUrlAttribute()
{
if (!empty($this->url)) {
if (empty($this->url) == false) {
return $this->url;
} else {
return url('attachments/download/'.$this->id);
Expand Down
17 changes: 10 additions & 7 deletions code/app/Console/Commands/CheckRemoteProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ private function notify($supplier, $e)

public function handle()
{
$entries = App::make('RemoteRepository')->getList();

$suppliers = Supplier::whereNotNull('remote_lastimport')->get();
foreach($suppliers as $supplier) {
foreach($entries as $e) {
if ($e->vat == $supplier->vat && $e->lastchange > $supplier->remote_lastimport) {
$this->notify($supplier, $e);
break;

if ($suppliers->isEmpty() == false) {
$entries = App::make('RemoteRepository')->getList();

foreach($suppliers as $supplier) {
foreach($entries as $e) {
if ($e->vat == $supplier->vat && $e->lastchange > $supplier->remote_lastimport) {
$this->notify($supplier, $e);
break;
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions code/app/Console/Commands/CloseOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Console\Commands;

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

use App\Jobs\NotifyClosedOrder;
use App\Order;
Expand All @@ -25,7 +24,7 @@ public function handle()
$closed[] = $order->id;
}
catch(\Exception $e) {
Log::error('Errore in chiusura automatica ordine: ' . $e->getMessage());
\Log::error('Errore in chiusura automatica ordine: ' . $e->getMessage());
}
}

Expand Down
34 changes: 32 additions & 2 deletions code/app/Console/Commands/FixDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
use App\Supplier;
use App\ModifierType;
use App\Role;
use App\Date;

class FixDatabase extends Command
{
protected $signature = 'fix:database';
protected $description = 'Sistema le informazioni sul DB per completare il deploy';

public function handle()
private function doAlways()
{
/*
I seeder dei tipi di movimento contabile e dei tipi di modificatore
Expand All @@ -34,14 +35,20 @@ public function handle()
*/
Artisan::call('db:seed', ['--force' => true, '--class' => 'MovementTypesSeeder']);
Artisan::call('db:seed', ['--force' => true, '--class' => 'ModifierTypesSeeder']);
}

public function handle()
{
$this->doAlways();

/*
Per revisionare le configurazioni relative ai limiti di credito per
permettere le prenotazioni
*/
foreach(Gas::all() as $gas) {
$restriction_info = $gas->getConfig('restrict_booking_to_credit');
if (is_array($restriction_info) == false) {
$restriction_info = json_decode($restriction_info);
if (is_object($restriction_info) == false) {
$restriction_info = (object) [
'enabled' => $restriction_info,
'limit' => 0,
Expand Down Expand Up @@ -70,5 +77,28 @@ public function handle()
Schema::table('invoices', function (Blueprint $table) {
$table->integer('payment_id')->nullable()->change();
});

Schema::table('users', function (Blueprint $table) {
$table->integer('fee_id')->nullable()->default(null)->change();
$table->integer('deposit_id')->nullable()->default(null)->change();
});

/*
Per aggiornare il formato delle date per gli ordini automatici
*/

$dates = Date::where('type', 'order')->get();
foreach($dates as $d) {
$attributes = json_decode($d->description);
if (isset($attributes->action) == false) {
$attributes->action = 'open';
$attributes->offset1 = $attributes->end;
$attributes->offset2 = $attributes->shipping;
unset($attributes->end);
unset($attributes->shipping);
$d->description = json_encode($attributes);
$d->save();
}
}
}
}
31 changes: 16 additions & 15 deletions code/app/Console/Commands/OpenOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@ private function getDates()
try {
$all_previous = true;

foreach($date->all_dates as $d) {
if ($d < $today) {
foreach($date->order_dates as $d) {
if ($d->start < $today) {
// @phpstan-ignore-next-line
$all_previous = $all_previous && true;
}
else if ($d > $today) {
else if ($d->start > $today) {
$all_previous = false;
}
else if ($d == $today) {
else if ($d->start == $today) {
$all_previous = false;

/*
Non cedere alla tentazione di spostare questo
controllo in cima al ciclo: arrivare fino a qui
serve a verificare se il set di ordini automatici è
scaduto o meno, e nel caso va eliminato
*/
if ($date->suspend) {
continue;
}
Expand All @@ -45,17 +51,17 @@ private function getDates()
l'ordine automatico: se già esiste un ordine aperto
oggi per il fornitore desiderato, passo oltre
*/
$supplier = $date->target;
$supplier = $d->target;
if (is_null($supplier) || $supplier->orders()->where('start', $today)->count() != 0) {
continue;
}

$aggregable_key = sprintf('%s_%s', $date->end, $date->shipping);
$aggregable_key = sprintf('%s_%s', $d->end, $d->shipping);
if (!isset($aggregable[$aggregable_key])) {
$aggregable[$aggregable_key] = [];
}

$aggregable[$aggregable_key][] = $date;
$aggregable[$aggregable_key][] = $d;
}
}

Expand All @@ -74,8 +80,6 @@ private function getDates()

private function openByDates($aggregable)
{
$today = date('Y-m-d');

foreach($aggregable as $aggr) {
$aggregate = new Aggregate();
$aggregate->save();
Expand All @@ -89,12 +93,9 @@ private function openByDates($aggregable)
$order->comment = $date->comment;
$order->status = 'suspended';
$order->keep_open_packages = 'no';
$order->start = $today;
$order->end = date('Y-m-d', strtotime($today . ' +' . $date->end . ' days'));

if (!empty($date->shipping)) {
$order->shipping = date('Y-m-d', strtotime($today . ' +' . $date->shipping . ' days'));
}
$order->start = $date->start;
$order->end = $date->end;
$order->shipping = $date->shipping;

Log::debug('Apro ordine automatico per ' . $supplier->name);
$order->save();
Expand Down
98 changes: 85 additions & 13 deletions code/app/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Facades\Auth;

use Auth;
use Log;
use Carbon\Carbon;

use App\Models\Concerns\Datable;

Expand Down Expand Up @@ -67,7 +67,7 @@ public function getCalendarStringAttribute()
$name = $this->target->name;
}
else {
Log::error('Impossibile recuperare nome del fornitore assegnato alla data ' . $this->id);
\Log::error('Impossibile recuperare nome del fornitore assegnato alla data ' . $this->id);
$name = '???';
}

Expand All @@ -80,21 +80,88 @@ public function getCalendarStringAttribute()
}
}

/*
Per motivi ignoti (collisione con qualche altra definizione?), tavolta
l'attributo dates restituisce una variabile vuota. Meglio cambiare nome
in all_dates
*/
public function getAllDatesAttribute()
{
if (empty($this->recurring)) {
return [$this->date];
}
else {
return unrollPeriodic(json_decode($this->recurring));
$dates = unrollPeriodic(json_decode($this->recurring));

\Log::debug($this->type . ' - ' . $this->action);

if ($this->type == 'order' && $this->action != 'open') {
$offset = $this->first_offset;
$shifted = [];

foreach($dates as $date) {
\Log::debug($date . ' / ' . Carbon::parse($date)->subDays($offset)->format('Y-m-d'));
$shifted[] = Carbon::parse($date)->subDays($offset)->format('Y-m-d');
}

$dates = $shifted;
}

return $dates;
}
}

public function getOrderDatesAttribute()
{
$ret = [];

if ($this->type != 'order') {
return $ret;
}

$dates = unrollPeriodic(json_decode($this->recurring));
$action = $this->action;
$offset1 = $this->first_offset;
$offset2 = $this->second_offset;

foreach($dates as $date) {
$d = Carbon::parse($date);
$node = null;

switch($action) {
case 'open':
$node = (object) [
'start' => $d->format('Y-m-d'),
'end' => $d->copy()->addDays($offset1)->format('Y-m-d'),
'shipping' => $d->copy()->addDays($offset2)->format('Y-m-d'),
];

break;

case 'close':
$node = (object) [
'start' => $d->copy()->subDays($offset1)->format('Y-m-d'),
'end' => $d->format('Y-m-d'),
'shipping' => $d->copy()->addDays($offset2)->format('Y-m-d'),
];

break;

case 'ship':
$node = (object) [
'start' => $d->copy()->subDays($offset1)->format('Y-m-d'),
'end' => $d->copy()->subDays($offset2)->format('Y-m-d'),
'shipping' => $d->format('Y-m-d'),
];

break;
}

if ($node) {
$node->target = $this->target;
$node->comment = $this->comment;
$ret[] = $node;
}
}

return $ret;
}

public function printableName()
{
return $this->printableDate('date');
Expand All @@ -115,14 +182,19 @@ private function internalAttribute($name)
return $attributes->$name ?? '';
}

public function getEndAttribute()
public function getActionAttribute()
{
return $this->internalAttribute('action');
}

public function getFirstOffsetAttribute()
{
return $this->internalAttribute('end');
return $this->internalAttribute('offset1');
}

public function getShippingAttribute()
public function getSecondOffsetAttribute()
{
return $this->internalAttribute('shipping');
return $this->internalAttribute('offset2');
}

public function getCommentAttribute()
Expand Down
15 changes: 15 additions & 0 deletions code/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Throwable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Facades\Route;

class Handler extends ExceptionHandler
{
Expand All @@ -28,4 +29,18 @@ public function register()
//
});
}

protected function context(): array
{
$parent = parent::context();

$url = request()->getRequestUri();
if ($url) {
$parent = array_merge($parent, [
'url' => $url,
]);
}

return $parent;
}
}
3 changes: 2 additions & 1 deletion code/app/Helpers/Dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ function decodePeriodic($value)
return '';

$values = explode(' - ', $value);
if (count($values) < 4)
if (count($values) < 4) {
return '';
}

$ret = (object) [
'day' => '',
Expand Down
Loading

0 comments on commit 84536a7

Please sign in to comment.