Skip to content

Commit

Permalink
Merge branch 'master' into invoice_permission
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Dec 13, 2023
2 parents 834af27 + f98146a commit c3cafb9
Show file tree
Hide file tree
Showing 18 changed files with 247 additions and 138 deletions.
55 changes: 8 additions & 47 deletions code/app/Console/Commands/FixDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,17 @@ public function handle()
Artisan::call('db:seed', ['--force' => true, '--class' => 'ModifierTypesSeeder']);

/*
Per fixare gli URL dei listini autogenerati ed erroneamente
sovrascritti
*/
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();
}
}

/*
Per non attivare il tour di onboarding per gli utenti esistenti
*/
User::query()->update(['tour' => true]);

/*
Per impostare un default sull'approvazione manuale delle
registrazioni pubbliche degli utenti
Per revisionare le configurazioni relative ai limiti di credito per
permettere le prenotazioni
*/
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);
}
}

/*
Per azzerare le vecchie configurazioni Satispay non compatibili con
la nuova implementazione
*/
foreach(Gas::all() as $gas) {
$satispay_info = $gas->satispay;
if (isset($satispay_info['public']) == false) {
$satispay_info = (object) [
'public' => '',
'secret' => '',
'key' => '',
$restriction_info = $gas->getConfig('restrict_booking_to_credit');
if (is_array($restriction_info) == false) {
$restriction_info = (object) [
'enabled' => $restriction_info,
'limit' => 0,
];

$gas->setConfig('satispay', $satispay_info);
$gas->setConfig('restrict_booking_to_credit', $restriction_info);
}
}

Expand Down
85 changes: 35 additions & 50 deletions code/app/Formatters/GenericProductFormat.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,44 @@
<?php

/*
Questo serve da collettore unico per gli attributi di formattazione dei
prodotti e delle varianti (le quali comunque prelevano i propri attributi
dal relativo prodotto)
*/

namespace App\Formatters;

trait GenericProductFormat
{
protected static function genericColumns()
{
return [
'name' => (object) [
'name' => _i('Nome'),
'checked' => true,
],
'supplier_code' => (object) [
'name' => _i('Codice Fornitore'),
],
'measure' => (object) [
'name' => _i('Unità di Misura'),
],
'category' => (object) [
'name' => _i('Categoria'),
],
'price' => (object) [
'name' => _i('Prezzo Unitario'),
'checked' => true,
],
'active' => (object) [
'name' => _i('Ordinabile'),
],
'vat_rate' => (object) [
'name' => _i('Aliquota IVA'),
],
'portion_quantity' => (object) [
'name' => _i('Pezzatura'),
],
'variable' => (object) [
'name' => _i('Variabile'),
],
'package_size' => (object) [
'name' => _i('Dimensione Confezione'),
],
'weight' => (object) [
'name' => _i('Peso'),
],
'multiple' => (object) [
'name' => _i('Multiplo'),
],
'min_quantity' => (object) [
'name' => _i('Minimo'),
],
'max_quantity' => (object) [
'name' => _i('Massimo Consigliato'),
],
'max_available' => (object) [
'name' => _i('Disponibile'),
],
protected static function genericColumns()
{
$attributes = [
'name' => _i('Nome'),
'supplier_code' => _i('Codice Fornitore'),
'measure' => _i('Unità di Misura'),
'category' => _i('Categoria'),
'price' => _i('Prezzo Unitario'),
'active' => _i('Ordinabile'),
'vat_rate' => _i('Aliquota IVA'),
'portion_quantity' => _i('Pezzatura'),
'variable' => _i('Variabile'),
'package_size' => _i('Dimensione Confezione'),
'weight' => _i('Peso'),
'multiple' => _i('Multiplo'),
'min_quantity' => _i('Minimo'),
'max_quantity' => _i('Massimo Consigliato'),
'max_available' => _i('Disponibile'),
];

$ret = [];
$checked_by_default = ['name', 'price'];
foreach($attributes as $attr => $label) {
$ret[$attr] = (object) [
'name' => $label,
'checked' => in_array($attr, $checked_by_default),
];
}

return $ret;
}
}
2 changes: 2 additions & 0 deletions code/app/Gas.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public function hasFeature($name)
return (!empty($obj->extra_invoicing['taxcode']) || !empty($obj->extra_invoicing['vat']));
case 'public_registrations':
return $obj->public_registrations['enabled'];
case 'restrict_booking_to_credit':
return $obj->restrict_booking_to_credit['enabled'];
case 'auto_aggregates':
return Aggregate::has('orders', '>=', aggregatesConvenienceLimit())->count() > 3;
case 'send_order_reminder':
Expand Down
2 changes: 0 additions & 2 deletions code/app/Helpers/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ function formatObjectsToComponent($component, $params)

function formatPriceToComponent($component, $params)
{
$value = printablePrice($params['value']);

if (isset($params['currency']) == false) {
$currency = defaultCurrency()->symbol;
}
Expand Down
7 changes: 3 additions & 4 deletions code/app/Http/Controllers/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

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

use Aws\Sns\Message;
use Aws\Sns\MessageValidator;
Expand All @@ -33,6 +31,7 @@ private function saveInstances($email, $message)
$db->delete("DELETE FROM contacts WHERE type = 'email' and value = '$email'");
$message = _i('Rimosso indirizzo email %s', [$email]);
$db->insert("INSERT INTO inner_logs (level, type, message, created_at, updated_at) VALUES ('error', 'mailsuppression', '$message', '$now', '$now')");
Log::info($message);
}
}
}
Expand Down
16 changes: 2 additions & 14 deletions code/app/Http/Controllers/VariantsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,7 @@ public function matrix(Request $request, $id)
private function transformFromSimplified($request, $product)
{
$original_combinations = $request->input('combination', []);

$ids = array_map(function($item) {
if (Str::startsWith($item, 'new_')) {
return '';
}
else {
return $item;
}
}, $original_combinations);
$ids = array_map(fn($item) => Str::startsWith($item, 'new_') ? '' : $item, $original_combinations);

$values = $request->input('value', []);

Expand All @@ -87,11 +79,7 @@ private function transformFromSimplified($request, $product)
'value' => $values,
]);

$combinations = [];

foreach($values as $value) {
$combinations[] = $variant->values()->where('value', $value)->first()->id;
}
$combinations = array_map(fn($v) => $variant->values()->where('value', $v)->first()->id, $values);

/*
Ai nuovi valori dinamicamente immessi nella tabella aggiungo un
Expand Down
4 changes: 2 additions & 2 deletions code/app/Models/Concerns/BookerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public function getLastBookingAttribute()

public function canBook()
{
if ($this->gas->restrict_booking_to_credit) {
if ($this->gas->hasFeature('restrict_booking_to_credit')) {
if ($this->isFriend()) {
return $this->parent->canBook();
}
else {
return $this->activeBalance() > 0;
return $this->activeBalance() > $this->gas->restrict_booking_to_credit['limit'];
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion code/app/Models/Concerns/ReducibleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function minimumRedux($modifiers)
}
}

if (($faster || $target_priority <= 1) && ($booking && $order)) {
if (($faster && $target_priority <= 1) && ($booking && $order)) {
$aggregate_data = $aggregate->reduxData([
'orders' => [$order],
'bookings' => [$booking]
Expand Down
5 changes: 4 additions & 1 deletion code/app/Observers/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class UserObserver
{
private function checkUsername($user)
{
$test = User::withTrashed()->where('id', '!=', $user->id)->where('username', $user->username)->first();
/*
Lo username deve essere univoco per tutti gli utenti di tutti i GAS
*/
$test = User::withTrashed()->withoutGlobalScopes()->where('id', '!=', $user->id)->where('username', $user->username)->first();
if ($test != null) {
throw new IllegalArgumentException(_i('Username già assegnato'), 'username');
}
Expand Down
25 changes: 23 additions & 2 deletions code/app/Parameters/Config/RestrictedBookingToCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,32 @@ public function identifier()

public function type()
{
return 'boolean';
return 'object';
}

public function default()
{
return 0;
return (object) [
'enabled' => false,
'limit' => 0,
];
}

public function handleSave($gas, $request)
{
if ($request->has('enable_restrict_booking_to_credit')) {
$restriction_info = (object) [
'enabled' => true,
'limit' => $request->input('restrict_booking_to_credit->limit', 0),
];
}
else {
$restriction_info = (object) [
'enabled' => false,
'limit' => 0,
];
}

$gas->setConfig('restrict_booking_to_credit', $restriction_info);
}
}
6 changes: 3 additions & 3 deletions code/app/Services/BookingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,16 @@ public function handleBookingUpdate($request, $user, $order, $target_user, $deli
*/
private function checkAvailableCredit($user)
{
if ($user->gas->restrict_booking_to_credit) {
if ($user->gas->hasFeature('restrict_booking_to_credit')) {
/*
Questa funzione viene invocata dopo aver salvato la
prenotazione, nel contesto di una transazione, dunque il
bilancio attivo dell'utente già prevede la prenotazione stessa e
pertanto, per essere valido, deve essere superiore a 0
pertanto, per essere valido, deve essere superiore al limite
*/
$current_active_balance = $user->activeBalance();

if ($current_active_balance < 0) {
if ($current_active_balance < $user->gas->restrict_booking_to_credit['limit']) {
DB::rollback();
throw new IllegalArgumentException(_i('Credito non sufficiente'), 1);
}
Expand Down
2 changes: 1 addition & 1 deletion code/app/Singletons/ModifierEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function handlingAttributes($booking, $modifier)
OrdersController::postFixModifiers(), previa conferma dell'utente,
quando l'ordine è davvero in stato "consegnato"
*/
if ($booking->status != 'pending') {
if (in_array($booking->status, ['saved', 'shipped'])) {
switch($modifier->applies_type) {
case 'none':
case 'quantity':
Expand Down
6 changes: 5 additions & 1 deletion code/config/larastrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@

'tabpane' => [
'reviewCallback' => 'formatTabLabel',
]
],

'collapse' => [
'classes' => ['mb-2'],
],
],

'customs' => [
Expand Down
6 changes: 3 additions & 3 deletions code/resources/views/booking/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<input type="hidden" name="close-modal" value="1" class="skip-on-submit">
<input type="hidden" name="action" value="booked">

@if($user->gas->restrict_booking_to_credit)
<input type="hidden" name="max-bookable" value="{{ $user->activeBalance() }}" class="skip-on-submit">
@if($user->gas->hasFeature('restrict_booking_to_credit'))
<input type="hidden" name="max-bookable" value="{{ $user->activeBalance() - $user->gas->restrict_booking_to_credit['limit'] }}" class="skip-on-submit">
@endif

<div class="d-flex flowbox mb-3">
Expand Down Expand Up @@ -214,7 +214,7 @@
'skip_cells' => 3
])

@if($user->gas->restrict_booking_to_credit)
@if($user->gas->hasFeature('restrict_booking_to_credit'))
<tr class="do-not-sort">
<td><label class="static-label">{{ _i('Credito Disponibile') }}</label></td>
<td>&nbsp;</td>
Expand Down
6 changes: 5 additions & 1 deletion code/resources/views/gas/orders.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<input type="hidden" name="group" value="orders">

<div class="col">
<x-larastrap::check name="restrict_booking_to_credit" :label="_i('Permetti solo prenotazioni entro il credito disponibile')" />
<x-larastrap::check name="enable_restrict_booking_to_credit" :label="_i('Permetti solo prenotazioni entro il credito disponibile')" triggers_collapse="enable_restrict_booking_to_credit" :value="$gas->hasFeature('restrict_booking_to_credit')" />
<x-larastrap::collapse id="enable_restrict_booking_to_credit">
<x-larastrap::number name="restrict_booking_to_credit->limit" :label="_i('Limite di Credito')" :value="$gas->restrict_booking_to_credit['limit']" :pophelp="_i('Gli utenti non possono prenotare nuovi prodotti se il loro credito diventa inferiore a questa soglia')" :textappend="defaultCurrency()->symbol" />
</x-larastrap::collapse>

<x-larastrap::check name="unmanaged_shipping" :label="_i('Permetti consegne manuali senza quantità')" :pophelp="_i('Abilitando questa opzione, sarà possibile attivare per ogni fornitore la possibilità di effettuare le consegne specificando direttamente il valore totale della consegna anziché le quantità di ogni prodotto consegnato. Attenzione: l\'uso di questa funzione non permetterà di ottenere delle statistiche precise sui prodotti consegnati, né una ripartizione equa dei modificatori basati sulle quantità e sui pesi dei prodotti consegnati.')" />

<?php
Expand Down
Loading

0 comments on commit c3cafb9

Please sign in to comment.