Skip to content

Commit

Permalink
revisione di comandi e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Nov 27, 2023
1 parent be67730 commit 989715c
Show file tree
Hide file tree
Showing 30 changed files with 398 additions and 437 deletions.
6 changes: 0 additions & 6 deletions code/app/Console/Commands/CheckFees.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\DB;
use Illuminate\Support\Facades\Log;

Expand All @@ -16,11 +15,6 @@ class CheckFees extends Command
protected $signature = 'check:fees';
protected $description = "Controlla la scadenza delle quote di iscrizione alla chiusura dell'anno sociale";

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

private function iterateUsers($users, $gas, $amount)
{
$auto_fee = $gas->getConfig('auto_fee');
Expand Down
9 changes: 1 addition & 8 deletions code/app/Console/Commands/CheckRemoteProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
namespace App\Console\Commands;

use Illuminate\Console\Command;

use Illuminate\Support\Str;

use App;
use Illuminate\Support\Facades\App;

use App\Supplier;
use App\Role;
Expand All @@ -18,11 +16,6 @@ class CheckRemoteProducts extends Command
protected $signature = 'check:remote_products';
protected $description = 'Controlla il repository remoto dei listini per aggiornamenti.';

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

private function notify($supplier, $e)
{
$body = _i('Nuovo aggiornamento disponibile per il listino %s (%s). Consultalo dal pannello Fornitori -> Indice Remoto.', [$supplier->printableName(), printableDate($e->lastchange)]);
Expand Down
8 changes: 1 addition & 7 deletions code/app/Console/Commands/CloseOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace App\Console\Commands;

use Illuminate\Console\Command;

use Log;
use Illuminate\Support\Facades\Log;

use App\Jobs\NotifyClosedOrder;
use App\Order;
Expand All @@ -14,11 +13,6 @@ class CloseOrders extends Command
protected $signature = 'close:orders';
protected $description = 'Controlla lo stato degli ordini, ed eventualmente li chiude';

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

public function handle()
{
$orders = Order::where('status', 'open')->where('end', '<', date('Y-m-d'))->get();
Expand Down
5 changes: 0 additions & 5 deletions code/app/Console/Commands/EmptyMovements.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class EmptyMovements extends Command
protected $signature = 'empty:movements';
protected $description = 'Invalida tutti i movimenti contabili';

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

private function emptyMovements()
{
$movements = Movement::all();
Expand Down
5 changes: 0 additions & 5 deletions code/app/Console/Commands/ExportSupplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class ExportSupplier extends Command
protected $signature = 'gdxp:write:supplier {supplier_id} {format}';
protected $description = 'Genera il file GDXP per un dato fornitore';

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

public function handle()
{
$id = $this->argument('supplier_id');
Expand Down
5 changes: 0 additions & 5 deletions code/app/Console/Commands/FixDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ class FixDatabase extends Command
protected $signature = 'fix:database';
protected $description = 'Sistema le informazioni sul DB per completare il deploy';

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

public function handle()
{
/*
Expand Down
5 changes: 0 additions & 5 deletions code/app/Console/Commands/InvalidateDeliveries.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ class InvalidateDeliveries extends Command
protected $signature = 'reset:deliveries {order}';
protected $description = 'Annulla tutte le consegne per un ordine';

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

private function wipeProducts($booking)
{
foreach($booking->products as $product) {
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,10 +3,9 @@
namespace App\Console\Commands;

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

use Log;

use App\Date;
use App\Order;
use App\Aggregate;
Expand All @@ -16,11 +15,6 @@ class OpenOrders extends Command
protected $signature = 'open:orders';
protected $description = 'Controlla lo stato degli ordini da aprire automaticamente';

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

private function getDates()
{
$dates = Date::where('type', 'order')->get();
Expand Down
8 changes: 1 addition & 7 deletions code/app/Console/Commands/RemindOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace App\Console\Commands;

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

use Carbon\Carbon;

use Log;

use App\Jobs\NotifyRemindOrder;
use App\Gas;
use App\Order;
Expand All @@ -17,11 +16,6 @@ class RemindOrders extends Command
protected $signature = 'remind:orders';
protected $description = 'Invia le notifiche di promemoria per gli ordini';

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

public function handle()
{
$orders = Order::where('status', 'open')->where('end', '>', Carbon::today()->format('Y-m-d'))->get();
Expand Down
8 changes: 1 addition & 7 deletions code/app/Console/Commands/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace App\Console\Commands;

use Illuminate\Console\Command;

use Hash;
use Illuminate\Support\Facades\Hash;

use App\User;

Expand All @@ -13,11 +12,6 @@ class ResetPassword extends Command
protected $signature = 'reset:password {user} {new_password}';
protected $description = 'Resetta la password di un utente';

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

public function handle()
{
$username = $this->argument('user');
Expand Down
92 changes: 47 additions & 45 deletions code/resources/views/gdxp/json/supplier.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,69 @@
$bookings = false;
}
function serializeTransformations($target, $json_target)
{
$transformations = [];
$modifiers = $target->modifiers->filter(fn($m) => $m->active && in_array($m->modifierType->identifier, ['shipping', 'discount']));
foreach($modifiers as $mod) {
if (in_array($mod->arithmetic, ['sum', 'sub'])) {
$trans = (object) [
'type' => $mod->modifierType->identifier,
'operation' => $mod->arithmetic,
];
if (function_exists('serializeTransformations') == false) {
function serializeTransformations($target, $json_target)
{
$transformations = [];
$modifiers = $target->modifiers->filter(fn($m) => $m->active && in_array($m->modifierType->identifier, ['shipping', 'discount']));
foreach($modifiers as $mod) {
if (in_array($mod->arithmetic, ['sum', 'sub'])) {
$trans = (object) [
'type' => $mod->modifierType->identifier,
'operation' => $mod->arithmetic,
];
$definitions = $mod->definitions;
$definitions = $mod->definitions;
if ($mod->scale == 'minor') {
$shifted_definitions = [];
$prev_theshold = 0;
if ($mod->scale == 'minor') {
$shifted_definitions = [];
$prev_theshold = 0;
foreach($definitions as $def) {
$shifted_definitions[] = (object) [
'threshold' => $prev_theshold,
'amount' => $def->amount,
];
$prev_theshold = $def->threshold;
}
foreach($definitions as $def) {
$shifted_definitions[] = (object) [
'threshold' => $prev_theshold,
'amount' => $def->amount,
'amount' => 0,
];
$prev_theshold = $def->threshold;
$definitions = $shifted_definitions;
}
$shifted_definitions[] = (object) [
'threshold' => $prev_theshold,
'amount' => 0,
];
$definitions = $shifted_definitions;
}
if (count($definitions) == 1) {
$trans->fixed = formatPercentage($definitions[0]->amount, $mod->value == 'percentage');
}
else {
$trans->variable = (object) [
'theshold_type' => $mod->applies_type,
'thesholds' => [],
];
foreach($definitions as $definition) {
$trans->variable->thesholds[] = (object) [
'theshold' => $definition->threshold,
'amount' => formatPercentage($definition->amount, $mod->value == 'percentage'),
if (count($definitions) == 1) {
$trans->fixed = formatPercentage($definitions[0]->amount, $mod->value == 'percentage');
}
else {
$trans->variable = (object) [
'theshold_type' => $mod->applies_type,
'thesholds' => [],
];
foreach($definitions as $definition) {
$trans->variable->thesholds[] = (object) [
'theshold' => $definition->threshold,
'amount' => formatPercentage($definition->amount, $mod->value == 'percentage'),
];
}
}
$json_target->transformations[] = $trans;
}
}
$json_target->transformations[] = $trans;
if (empty($transformations) == false) {
$json_target->transformations = $transformations;
}
}
if (empty($transformations) == false) {
$json_target->transformations = $transformations;
return $json_target;
}
return $json_target;
}
$json_object = (object) [
Expand Down
14 changes: 7 additions & 7 deletions code/tests/Services/BookingsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testUnaggregatedFriend()

$this->nextRound();

$product = $this->services['products']->store(array(
$product = app()->make('ProductsService')->store(array(
'name' => 'Test Product',
'price' => rand(),
'supplier_id' => $this->sample_order->supplier->id,
Expand All @@ -120,7 +120,7 @@ public function testUnaggregatedFriend()
$product->id => 2,
'action' => 'booked',
];
$this->services['bookings']->bookingUpdate($data_friend, $this->sample_order->aggregate, $friend, false);
app()->make('BookingsService')->bookingUpdate($data_friend, $this->sample_order->aggregate, $friend, false);

$this->nextRound();

Expand All @@ -130,7 +130,7 @@ public function testUnaggregatedFriend()
$product->id => 1,
'action' => 'booked',
];
$this->services['bookings']->bookingUpdate($data_master, $this->sample_order->aggregate, $this->userWithBasePerms, false);
app()->make('BookingsService')->bookingUpdate($data_master, $this->sample_order->aggregate, $this->userWithBasePerms, false);

$this->nextRound();

Expand All @@ -153,7 +153,7 @@ public function testShippingWithFriend()
$this->actingAs($friend);
list($friend_data, $friend_booked_count, $friend_total) = $this->randomQuantities($this->sample_order->products);
$friend_data['action'] = 'booked';
$this->services['bookings']->bookingUpdate($friend_data, $this->sample_order->aggregate, $friend, false);
app()->make('BookingsService')->bookingUpdate($friend_data, $this->sample_order->aggregate, $friend, false);

$this->actingAs($this->userWithBasePerms);
list($data, $booked_count, $total) = $this->randomQuantities($this->sample_order->products);
Expand Down Expand Up @@ -199,7 +199,7 @@ public function testShippingWithOnlyFriend()
$this->actingAs($friend);
list($friend_data, $friend_booked_count, $friend_total) = $this->randomQuantities($this->sample_order->products);
$friend_data['action'] = 'booked';
$this->services['bookings']->bookingUpdate($friend_data, $this->sample_order->aggregate, $friend, false);
app()->make('BookingsService')->bookingUpdate($friend_data, $this->sample_order->aggregate, $friend, false);

$this->actingAs($this->userWithShippingPerms);
$friend_data['action'] = 'shipped';
Expand Down Expand Up @@ -252,7 +252,7 @@ public function testMultipleRead()
$complete_data = array_merge($data, $data2);

$complete_data['action'] = 'booked';
$this->services['bookings']->bookingUpdate($complete_data, $this->sample_order->aggregate, $this->userWithBasePerms, false);
app()->make('BookingsService')->bookingUpdate($complete_data, $this->sample_order->aggregate, $this->userWithBasePerms, false);

$this->nextRound();

Expand All @@ -262,7 +262,7 @@ public function testMultipleRead()

$this->actingAs($this->userWithShippingPerms);
$complete_data['action'] = 'shipped';
$this->services['bookings']->bookingUpdate($complete_data, $this->sample_order->aggregate, $this->userWithBasePerms, true);
app()->make('BookingsService')->bookingUpdate($complete_data, $this->sample_order->aggregate, $this->userWithBasePerms, true);

$this->nextRound();

Expand Down
Loading

0 comments on commit 989715c

Please sign in to comment.