Skip to content

Commit

Permalink
piccoli aggiustamenti
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Nov 13, 2023
1 parent 790e9b7 commit f9eb90a
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 125 deletions.
34 changes: 0 additions & 34 deletions code/app/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,45 +467,11 @@ public function printableName()
return $this->order->printableName();
}

/*
TODO: questa funzione potrebbe essere da sopprimere. Da verificare
*/
public function printableHeader()
{
\Log::debug('printableHeader di Booking');

$ret = $this->printableName();

$user = Auth::user();

$tot = $this->getValue('effective', false);
$friends_tot = $this->total_friends_value;

if($tot == 0 && $friends_tot == 0) {
$message = _i("Non hai partecipato a quest'ordine");
}
else {
$message = _i('Hai ordinato %s', [printablePriceCurrency($tot)]);
if ($friends_tot != 0) {
// @phpstan-ignore-next-line
$message += sprintf(' + %s', printablePriceCurrency($friends_tot));
}
}

$ret .= '<span class="pull-right">' . $message . '</span>';
return $ret;
}

public function getShowURL()
{
return route('booking.user.show', ['booking' => $this->order->aggregate_id, 'user' => $this->user_id]);
}

public function getModalURL()
{
return route('booking.modal', ['aggregate_id' => $this->order->aggregate_id, 'user_id' => $this->user_id]);
}

public function wipeStatus()
{
if ($this->payment) {
Expand Down
10 changes: 1 addition & 9 deletions code/app/Console/Commands/ArchiveBalances.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@

use Illuminate\Console\Command;

use App\Services\MovementsService;

class ArchiveBalances extends Command
{
protected $signature = 'balances:archive {date}';
protected $description = 'Archivia i saldi ad una certa data';

public function __construct()
{
parent::__construct();
}

public function handle()
{
$date = $this->argument('date');
$service = new MovementsService();
$service->closeBalance(['date' => $date]);
app()->make('MovementsService')->closeBalance(['date' => $date]);
}
}
10 changes: 1 addition & 9 deletions code/app/Console/Commands/RecalculateBalances.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@

use Illuminate\Console\Command;

use App\Services\MovementsService;

class RecalculateBalances extends Command
{
protected $signature = 'balances:recalculate';
protected $description = 'Effettua un ricalcolo saldi';

public function __construct()
{
parent::__construct();
}

public function handle()
{
$service = new MovementsService();
$service->recalculate();
app()->make('MovementsService')->recalculate();
}
}
14 changes: 10 additions & 4 deletions code/app/Helpers/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,22 @@ function inlineId($obj)
return sprintf('%s---%s', $class, $obj->id);
}

function fromInlineId($id)
function fromInlineId($identifier)
{
$parts = explode('---', $id);
$parts = explode('---', $identifier);
if (count($parts) != 2) {
throw new \Exception("Identificativo non valido per recupero riferimento: " . $id, 1);
throw new \Exception("Identificativo non valido per recupero riferimento: " . $identifier, 1);
}

list($class, $id) = $parts;
$class = sprintf('App\\%s', $class);
return $class::find($id);

$ret = $class::find($id);
if (is_null($ret)) {
\Log::error("Identificativo non valido per recupero riferimento: " . $identifier);
}

return $ret;
}

function unrollSpecialSelectors($users)
Expand Down
4 changes: 1 addition & 3 deletions code/app/Http/Controllers/DeliveryUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use URL;

use App\Services\BookingsService;
use App\Services\FastBookingsService;

use App\User;
use App\Aggregate;
Expand Down Expand Up @@ -83,8 +82,7 @@ public function postFastShipping(Request $request, $aggregate_id)
];
}

$fastshipping = new FastBookingsService();
$fastshipping->fastShipping($deliverer, $aggregate, $users);
app()->make('FastBookingsService')->fastShipping($deliverer, $aggregate, $users);
return $this->successResponse();
}

Expand Down
15 changes: 6 additions & 9 deletions code/app/Importers/CSV/Deliveries.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use App;
use Auth;
use DB;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

use App\Services\BookingsService;
use App\Services\FastBookingsService;
use App\User;
use App\Aggregate;
use App\Order;
Expand Down Expand Up @@ -59,7 +57,7 @@ public function guess($request)
public function select($request)
{
$user = Auth::user();
$service = new BookingsService();
$service = app()->make('BookingsService');
$errors = [];

list($reader, $columns) = $this->initRead($request);
Expand Down Expand Up @@ -201,7 +199,7 @@ public function formatSelect($parameters)
public function run($request)
{
$user = Auth::user();
$service = new BookingsService();
$service = app()->make('BookingsService');

$data = json_decode($request->input('data', '[]'), true);
$users = $request->input('user', []);
Expand Down Expand Up @@ -229,8 +227,7 @@ public function run($request)
DB::commit();

if ($action == 'close') {
$fast = new FastBookingsService();
$fast->fastShipping($user, $target_order->aggregate, null);
app()->make('FastBookingsService')->fastShipping($user, $target_order->aggregate, null);
}

return [
Expand Down
66 changes: 66 additions & 0 deletions code/app/Providers/ServicesProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Support\DeferrableProvider;

class ServicesProvider extends ServiceProvider implements DeferrableProvider
{
public function boot(): void
{
//
}

private function services(): array
{
/*
Questo si suppone essere l'elenco di tutte le classi in
app/Services: da tenere aggiornato!
*/
return [
\App\Services\BookingsService::class,
\App\Services\DatesService::class,
\App\Services\DynamicBookingsService::class,
\App\Services\FastBookingsService::class,
\App\Services\InvoicesService::class,
\App\Services\ModifiersService::class,
\App\Services\ModifierTypesService::class,
\App\Services\MovementsService::class,
\App\Services\MovementTypesService::class,
\App\Services\MultiGasService::class,
\App\Services\NotificationsService::class,
\App\Services\OrdersService::class,
\App\Services\ProductsService::class,
\App\Services\ReceiptsService::class,
\App\Services\RolesService::class,
\App\Services\SuppliersService::class,
\App\Services\UsersService::class,
\App\Services\VariantsService::class,
\App\Services\VatRatesService::class,
];
}

public function register(): void
{
$classes = $this->services();

foreach($classes as $class) {
$this->app->singleton(class_basename($class), function ($app) use ($class) {
return new $class();
});
}
}

public function provides(): array
{
$classes = $this->services();
$ret = [];

foreach($classes as $class) {
$ret[] = class_basename($class);
}

return $ret;
}
}
37 changes: 0 additions & 37 deletions code/app/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,43 +391,6 @@ public function mandatoryAction($action)
return false;
}

public function enableAction($action)
{
if ($this->enabledAction($action) == false) {
$this->actions .= ',' . $action;
$this->save();

/*
Se attivo un permesso che ha un solo target (di solito: il GAS),
attacco quest'ultimo direttamente a tutti gli utenti coinvolti
*/
$class = classByRule($action);
if ($class::count() == 1) {
$only_target = $class::first();

foreach($this->users as $user) {
$urole = $user->roles()->where('roles.id', $this->id)->first();
if ($urole)
$urole->attachApplication($only_target);
}
}
}
}

public function disableAction($action)
{
$new_actions = [];
$actions = explode(',', $this->actions);
foreach($actions as $a) {
if ($a == $action)
continue;
$new_actions[] = $a;
}

$this->actions = join(',', $new_actions);
$this->save();
}

public static function havingAction($action)
{
return Role::where('actions', 'LIKE', "%$action%")->get();
Expand Down
6 changes: 3 additions & 3 deletions code/app/Services/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Services;

use App\Exceptions\AuthException;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

use Auth;
use Log;
use App\Exceptions\AuthException;

class BaseService
{
Expand Down
2 changes: 1 addition & 1 deletion code/app/Services/FastBookingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function fastShipping($deliverer, $aggregate, $users = null)
{
DB::beginTransaction();

$service = new BookingsService();
$service = app()->make('BookingsService');

$default_payment_method = defaultPaymentByType('booking-payment');
$bookings = $aggregate->bookings;
Expand Down
9 changes: 4 additions & 5 deletions code/app/Services/MultiGasService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Services;

use Auth;
use Log;
use DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;

use App\Gas;
use App\User;
Expand Down Expand Up @@ -66,9 +66,8 @@ public function store(array $request)

DB::beginTransaction();

$user_service = new UsersService();
$user_params = array_intersect_key($request, array_flip(['username', 'firstname', 'lastname', 'password', 'enforce_password_change']));
$admin = $user_service->store($user_params);
$admin = app()->make('UsersService')->store($user_params);

$gas = new Gas();
$this->setIfSet($gas, $request, 'name');
Expand Down
29 changes: 23 additions & 6 deletions code/app/Services/RolesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,35 @@ public function attachAction($role_id, $action)
$this->ensureAuth(['gas.permissions' => 'gas']);

$r = Role::findOrFail($role_id);
if ($action) {
$r->enableAction($action);
if ($r->enabledAction($action)) {
return;
}

$r->actions .= ',' . $action;
$r->save();

/*
Se attivo un permesso che ha un solo target (di solito: il GAS),
attacco quest'ultimo direttamente a tutti gli utenti coinvolti
*/
$class = classByRule($action);
if ($class::count() == 1) {
$only_target = $class::first();

foreach($r->users as $user) {
$urole = $user->roles()->where('roles.id', $r->id)->first();
$urole->attachApplication($only_target);
}
}
}

public function detachAction($role_id, $action)
{
$this->ensureAuth(['gas.permissions' => 'gas']);

$r = Role::findOrFail($role_id);
if ($action) {
$r->disableAction($action);
}
$actions = explode(',', $r->actions);
$new_actions = array_filter($actions, fn($a) => $a != $action);
$r->actions = join(',', $new_actions);
$r->save();
}
}
Loading

0 comments on commit f9eb90a

Please sign in to comment.