Skip to content

Commit

Permalink
Merge branch 'master' into social
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Nov 13, 2023
2 parents 7f57f9c + 33f25bf commit 1c861ed
Show file tree
Hide file tree
Showing 78 changed files with 1,033 additions and 561 deletions.
52 changes: 33 additions & 19 deletions code/app/BookedProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public function getSlugID()

private function fixQuantity($attribute, $rectify)
{
/*
Nota: qui si può evitare di ottimizzare controllando che la quantità
sia diversa da 0, in quanto si può assumere che i prodotti prenotati
non abbiano mai una quantità a 0
*/
if ($this->variants->isEmpty() == false) {
return $this->variants->reduce(function($carry, $item) use ($rectify, $attribute) {
return $carry + ($item->unitPrice($rectify) * $item->$attribute);
Expand All @@ -100,10 +105,18 @@ public function testConstraints($quantity, $variant = null, $only_mandatory = fa
}
}

if ($variant) {
$combo = $variant->variantsCombo();
if ($combo->active == false) {
throw new InvalidQuantityConstraint(_('Questa combinazione di varianti non è attualmente ordinabile'), 4);
/*
Può capitare che in una prenotazione ci siano delle varianti che
solo dopo la chiusura dell'ordine sono state rese non prenotabili.
In questo caso devo comunque poter consegnare quanto è stato
prenotato, dunque ignoro lo stato di ordinabilità
*/
if ($only_mandatory == false) {
if ($variant) {
$combo = $variant->variantsCombo();
if ($combo->active == false) {
throw new InvalidQuantityConstraint(_('Questa combinazione di varianti non è attualmente ordinabile'), 4);
}
}
}

Expand Down Expand Up @@ -185,18 +198,15 @@ public function getAsSummaryAttribute()
return $summary;
}

private function normalizeQuantity($attribute)
{
$product = $this->product;
if ($product->portion_quantity != 0)
return $this->$attribute * $product->portion_quantity;
else
return $this->$attribute;
}

public function getTrueQuantityAttribute()
{
return $this->normalizeQuantity('quantity');
$product = $this->product;
if ($product->portion_quantity != 0) {
return $this->quantity * $product->portion_quantity;
}
else {
return $this->quantity;
}
}

/*
Expand Down Expand Up @@ -293,26 +303,30 @@ private function getShippedValue($type)

public function getValue($type)
{
$ret = 0;

if (Str::startsWith($type, 'modifier:')) {
return $this->getModifierValue($type);
$ret = $this->getModifierValue($type);
}
else {
if ($type == 'booked') {
return $this->fixQuantity('quantity', true);
$ret = $this->fixQuantity('quantity', true);
}
else {
switch($this->booking->status) {
case 'pending':
return $this->getPendingValue($type);
$ret = $this->getPendingValue($type);
break;

case 'shipped':
case 'saved':
return $this->getShippedValue($type);
$ret = $this->getShippedValue($type);
break;
}
}
}

return 0;
return $ret;
}

/********************************************************** ModifiedTrait */
Expand Down
86 changes: 42 additions & 44 deletions code/app/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,50 @@ public function getValue($type, $with_friends, $force_recalculate = false)
}

if ($type == 'effective') {
$modifiers = $this->involvedModifiers();
$aggregate_data = $obj->minimumRedux($modifiers);
$value = 0;
$modified_values = null;

$type = $obj->status == 'pending' ? 'booked' : 'delivered';
$modified_values = $obj->applyModifiers($aggregate_data, false);
/*
Se la prenotazione è stata consegnata, devo andare a
recuperare i modificatori che sono stati effettivamente
salvati sul DB a prescindere da quali sono quelli
"teorici" che potrei trovare (quelli restituiti da
involvedModifiers()).
Questo per recuperare anche gli eventuali modificatori
speciali delle consegne manuali
*/

if ($with_friends) {
foreach($obj->friends_bookings as $friend_booking) {
$friend_modified_values = $friend_booking->applyModifiers($aggregate_data, false);
$modified_values = $modified_values->merge($friend_modified_values);
if ($obj->status != 'pending') {
$type = 'delivered';
$modified_values = $obj->allModifiedValues(null, true);

if ($with_friends) {
foreach($obj->friends_bookings as $friend_booking) {
$friend_modified_values = $friend_booking->allModifiedValues(null, true);
$modified_values = $modified_values->merge($friend_modified_values);
}
}
}
else {
$type = 'booked';
$modifiers = $obj->involvedModifiers();

if ($modifiers->isEmpty() == false) {
$aggregate_data = $obj->minimumRedux($modifiers);
$modified_values = $obj->calculateModifiers($aggregate_data, false);

if ($with_friends) {
foreach($obj->friends_bookings as $friend_booking) {
$friend_modified_values = $friend_booking->calculateModifiers($aggregate_data, false);
$modified_values = $modified_values->merge($friend_modified_values);
}
}
}
}

$value = ModifiedValue::sumAmounts($modified_values, $value);
if ($modified_values) {
$value = ModifiedValue::sumAmounts($modified_values, $value);
}
}

foreach ($products as $booked) {
Expand Down Expand Up @@ -437,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 Expand Up @@ -518,7 +514,9 @@ public function involvedModifiers()
$modifiers = $modifiers->merge($this->user->shippingplace->modifiers);
}

return $modifiers->sortBy('priority');
return $modifiers->filter(function($mod) {
return $mod->active;
})->sortBy('priority');
}

public function involvedModifiedValues()
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]);
}
}
27 changes: 26 additions & 1 deletion code/app/Console/Commands/FixDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use App\Config;
use App\User;
use App\Supplier;
use App\Gas;

class FixDatabase extends Command
Expand All @@ -36,14 +37,38 @@ public function handle()
Artisan::call('db:seed', ['--force' => true, '--class' => 'MovementTypesSeeder']);
Artisan::call('db:seed', ['--force' => true, '--class' => 'ModifierTypesSeeder']);

User::query()->update(['tour' => false]);
foreach(Supplier::all() as $supplier) {
$attachments = $supplier->attachments;

$pdf = $attachments->firstWhere('name', 'Listino PDF (autogenerato)');
if ($pdf) {
$pdf->url = route('suppliers.catalogue', ['id' => $supplier->id, 'format' => 'pdf']);
$pdf->save();
}

$csv = $attachments->firstWhere('name', 'Listino CSV (autogenerato)');
if ($csv) {
$csv->url = route('suppliers.catalogue', ['id' => $supplier->id, 'format' => 'csv']);
$csv->save();
}
}

User::query()->update(['tour' => true]);

foreach(Gas::all() as $gas) {
$registrations_info = $gas->public_registrations;
if (isset($registrations_info['manual']) == false) {
$registrations_info['manual'] = false;
$gas->setConfig('public_registrations', $registrations_info);
}

$satispay_info = (object) [
'public' => '',
'secret' => '',
'key' => '',
];

$gas->setConfig('satispay', $satispay_info);
}
}
}
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();
}
}
25 changes: 13 additions & 12 deletions code/app/Helpers/Accounting.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,27 @@ function paymentMethodByType($type)

function paymentsByType($type)
{
$function = null;
$ret = [];

if ($type != null) {
$metadata = movementTypes($type);

if ($metadata) {
$function = json_decode($metadata->function);
}
}

$movement_methods = paymentTypes();
$ret = [];
if ($function) {
$movement_methods = paymentTypes();

foreach ($movement_methods as $method_id => $info) {
if ($function) {
foreach($function as $f) {
if ($f->method == $method_id) {
$ret[$method_id] = $info->name;
break;
foreach ($movement_methods as $method_id => $info) {
foreach($function as $f) {
if ($f->method == $method_id) {
$ret[$method_id] = $info->name;
break;
}
}
}
}

}
}

Expand Down Expand Up @@ -215,7 +216,7 @@ function duplicateAllCurrentBalances($latest_date)
$class = get_class($obj);

foreach ($currencies as $curr) {
if (!isset($current_status[$curr->id][$class][$obj->id])) {
if (isset($current_status[$curr->id][$class][$obj->id]) == false) {
$latest = $obj->currentBalance($curr);
$new = $latest->replicate();

Expand Down
2 changes: 1 addition & 1 deletion code/app/Helpers/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function allPermissions()
'measures.admin' => _i('Amministrare le unità di misura'),
'gas.statistics' => _i('Visualizzare le statistiche'),
'notifications.admin' => _i('Amministrare le notifiche'),
'gas.multi' => _i('Amministrare i GAS su questa istanza'),
'gas.multi' => _i('Amministrare la modalità Multi-GAS su questa istanza'),
],
'App\Supplier' => [
'supplier.modify' => _i('Modificare i fornitori assegnati'),
Expand Down
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
Loading

0 comments on commit 1c861ed

Please sign in to comment.