From e584ddad687cdb9eb9675c9791e8e30aadf05352 Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Mon, 27 Nov 2023 00:58:46 +0100 Subject: [PATCH] aggiustamenti minori --- code/app/AggregateBooking.php | 23 +-- code/app/Gas.php | 72 +------ .../Controllers/AttachmentsController.php | 4 +- .../Http/Controllers/DeliveriesController.php | 8 +- code/app/Http/Controllers/GasController.php | 183 ++++-------------- code/app/Models/Concerns/AttachableTrait.php | 16 +- code/app/Models/Concerns/Configurable.php | 89 +++++++++ code/app/Parameters/Config/Config.php | 37 ++++ code/app/Parameters/Config/ExtraInvoicing.php | 29 +++ code/app/Parameters/Config/IntegralCES.php | 20 ++ .../Parameters/Config/PublicRegistrations.php | 26 +++ code/app/Parameters/Config/Rid.php | 20 ++ code/app/Parameters/Config/Roles.php | 13 ++ code/app/Parameters/Config/Satispay.php | 33 ++++ .../Parameters/Config/SendOrderReminder.php | 5 + code/app/Parameters/Config/YearClosing.php | 5 + code/app/Printers/AggregateBooking.php | 2 +- code/app/Printers/Components/Table.php | 8 +- code/app/Scopes/RestrictedGAS.php | 21 +- .../Services/FastBookingsServiceTest.php | 37 +++- 20 files changed, 387 insertions(+), 264 deletions(-) create mode 100644 code/app/Models/Concerns/Configurable.php diff --git a/code/app/AggregateBooking.php b/code/app/AggregateBooking.php index 8e1c7eae3..d0b0cc6d8 100644 --- a/code/app/AggregateBooking.php +++ b/code/app/AggregateBooking.php @@ -3,6 +3,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; use App\Models\Concerns\TracksUpdater; use App\GASModel; @@ -22,18 +23,19 @@ class AggregateBooking extends Model public $id; public $user; public $aggregate; - public $bookings = []; + public $bookings; public function __construct($user_id, $aggregate) { $this->id = $user_id; $this->user = User::withTrashed()->find($user_id); $this->aggregate = $aggregate; + $this->bookings = new Collection(); } public function add($booking) { - $this->bookings[] = $booking; + $this->bookings->push($booking); } public function getCreatedAtAttribute() @@ -176,12 +178,7 @@ public function getConvenientStringsAttribute() public function generateReceipt() { if ($this->user->gas->hasFeature('extra_invoicing')) { - $ids = []; - foreach ($this->bookings as $booking) { - if ($booking->exists) { - $ids[] = $booking->id; - } - } + $ids = $this->bookings->filter(fn($b) => $b->exists)->pluck('id')->all(); if (empty($ids)) { \Log::error('Tentativo di creare fattura non assegnata a nessuna prenotazione'); @@ -215,12 +212,10 @@ public function getPrintableUpdaterAttribute() $last_update = null; $last_updater = null; - foreach($this->bookings as $booking) { - if ($booking->updater) { - if (is_null($last_update) || $booking->updated_at->greaterThan($last_update)) { - $last_update = $booking->updated_at; - $last_updater = $booking->updater; - } + foreach($this->bookings->filter(fn($b) => $b->updater) as $booking) { + if (is_null($last_update) || $booking->updated_at->greaterThan($last_update)) { + $last_update = $booking->updated_at; + $last_updater = $booking->updater; } } diff --git a/code/app/Gas.php b/code/app/Gas.php index 50c42900a..07d85032a 100644 --- a/code/app/Gas.php +++ b/code/app/Gas.php @@ -11,13 +11,14 @@ use Log; use App\Models\Concerns\AttachableTrait; +use App\Models\Concerns\Configurable; use App\Models\Concerns\PayableTrait; use App\Models\Concerns\CreditableTrait; use App\Events\SluggableCreating; class Gas extends Model { - use HasFactory, AttachableTrait, CreditableTrait, PayableTrait, GASModel, SluggableID, Cachable; + use HasFactory, Configurable, AttachableTrait, CreditableTrait, PayableTrait, GASModel, SluggableID, Cachable; public $incrementing = false; protected $keyType = 'string'; @@ -66,75 +67,6 @@ public function deliveries(): BelongsToMany return $this->belongsToMany('App\Delivery')->orderBy('name', 'asc'); } - public function configs(): HasMany - { - return $this->hasMany('App\Config'); - } - - private function availableConfigs() - { - return systemParameters('Config'); - } - - public function getConfig($name) - { - foreach ($this->configs as $conf) { - if ($conf->name == $name) { - return $conf->value; - } - } - - $defined = $this->availableConfigs(); - if (!isset($defined[$name])) { - Log::error(_i('Configurazione GAS non prevista')); - return ''; - } - else { - $this->setConfig($name, $defined[$name]->default()); - $this->load('configs'); - return $this->getConfig($name); - } - } - - public function setConfig($name, $value) - { - if (is_object($value) || is_array($value)) { - $value = json_encode($value); - } - - foreach ($this->configs as $conf) { - if ($conf->name == $name) { - $conf->value = $value; - $conf->save(); - return; - } - } - - $conf = new Config(); - $conf->name = $name; - $conf->value = $value; - $conf->gas_id = $this->id; - $conf->save(); - } - - /* - Questa funzione permette di accedere direttamente alle configurazioni - del GAS, usandone il nome (definito da ciascun parametro definito nelle - classi nel namespace App\Parameters\Config) - */ - public function getAttribute($key) - { - $configs = $this->availableConfigs(); - $c = $configs[$key] ?? null; - - if ($c) { - return $c->asAttribute($this); - } - else { - return parent::getAttribute($key); - } - } - public function nextInvoiceNumber() { $status = $this->extra_invoicing; diff --git a/code/app/Http/Controllers/AttachmentsController.php b/code/app/Http/Controllers/AttachmentsController.php index 3f241a08a..4f32cdd31 100644 --- a/code/app/Http/Controllers/AttachmentsController.php +++ b/code/app/Http/Controllers/AttachmentsController.php @@ -32,7 +32,7 @@ public function store(Request $request) return $this->errorResponse(_i('Non autorizzato')); } - $a = $target->attachByRequest($request); + $a = $target->attachByRequest($request->all()); if ($a === false) { return $this->errorResponse(_i('File non caricato correttamente')); } @@ -55,7 +55,7 @@ public function update(Request $request, $id) } if ($request->hasFile('file')) { - $a = $a->attached->attachByRequest($request, $a->id); + $a = $a->attached->attachByRequest($request->all(), $a->id); if ($a === false) { return $this->errorResponse(_i('File non caricato correttamente')); } diff --git a/code/app/Http/Controllers/DeliveriesController.php b/code/app/Http/Controllers/DeliveriesController.php index fd3bd3fbd..4e3bfe40e 100644 --- a/code/app/Http/Controllers/DeliveriesController.php +++ b/code/app/Http/Controllers/DeliveriesController.php @@ -95,13 +95,13 @@ public function destroy($id) if ($d->default) { $fallback = Delivery::where('id', '!=', $d->id)->orderBy(DB::raw('RAND()'))->first(); - if ($fallback != null) - $fallback_id = $fallback->id; } else { $fallback = Delivery::where('default', true)->first(); - if ($fallback != null) - $fallback_id = $fallback->id; + } + + if (is_null($fallback) == false) { + $fallback_id = $fallback->id; } foreach($d->users as $u) { diff --git a/code/app/Http/Controllers/GasController.php b/code/app/Http/Controllers/GasController.php index 48031a8ff..b9061d7c4 100644 --- a/code/app/Http/Controllers/GasController.php +++ b/code/app/Http/Controllers/GasController.php @@ -5,7 +5,6 @@ use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Str; -use Illuminate\Support\Arr; use Auth; use DB; @@ -63,159 +62,65 @@ private function configGeneral($gas, $request) $gas->name = $request->input('name'); $gas->email = $request->input('email'); $gas->message = $request->input('message'); - $gas->setConfig('restricted', $request->has('restricted') ? '1' : '0'); - $gas->setConfig('language', $request->input('language')); $currency = defaultCurrency(); $currency->symbol = $request->input('currency', '€'); $currency->save(); + + $gas->setManyConfigs($request, [ + 'restricted', + 'language' + ]); } private function configBanking($gas, $request) { - $gas->setConfig('year_closing', decodeDateMonth($request->input('year_closing'))); - $gas->setConfig('annual_fee_amount', $request->input('annual_fee_amount', 0)); - $gas->setConfig('deposit_amount', $request->input('deposit_amount', 0)); - $gas->setConfig('auto_fee', $request->has('auto_fee')); - - if ($request->has('enable_rid')) { - $rid_info = (object) [ - 'iban' => $request->input('rid->iban'), - 'id' => $request->input('rid->id'), - 'org' => $request->input('rid->org'), - ]; - } - else { - $rid_info = (object) [ - 'iban' => '', - 'id' => '', - 'org' => '', - ]; - } - - $gas->setConfig('rid', $rid_info); - - $satispay_info = null; - - if ($request->has('enable_satispay')) { - $auth_code = $request->input('satispay_auth_code'); - if ($auth_code) { - try { - $authentication = \SatispayGBusiness\Api::authenticateWithToken($auth_code); - $satispay_info = (object) [ - 'public' => $authentication->publicKey, - 'secret' => $authentication->privateKey, - 'key' => $authentication->keyId, - ]; - } - catch(\Exception $e) { - \Log::error('Impossibile completare procedura di verifica su Satispay: ' . $e->getMessage()); - } - } - } - else { - $satispay_info = (object) [ - 'public' => '', - 'secret' => '', - 'key' => '', - ]; - } - - if ($satispay_info) { - $gas->setConfig('satispay', $satispay_info); - } - - if ($request->has('enable_integralces')) { - $integralces_info = (object) [ - 'enabled' => true, - 'identifier' => $request->input('integralces->identifier'), - 'symbol' => $request->input('integralces->symbol'), - ]; - } - else { - $integralces_info = (object) [ - 'enabled' => false, - 'identifier' => '', - 'symbol' => '', - ]; - } - - $gas->setConfig('integralces', $integralces_info); - - if ($request->has('enable_extra_invoicing')) { - $invoicing_info = $gas->extra_invoicing; - $invoicing_info['business_name'] = $request->input('extra_invoicing->business_name'); - $invoicing_info['taxcode'] = $request->input('extra_invoicing->taxcode'); - $invoicing_info['vat'] = $request->input('extra_invoicing->vat'); - $invoicing_info['address'] = $request->input('extra_invoicing->address'); - $invoicing_info['invoices_counter_year'] = date('Y'); - - $reset_counter = $request->input('extra_invoicing->invoices_counter'); - if (!empty($reset_counter)) { - $invoicing_info['invoices_counter'] = $reset_counter; - } - } - else { - $invoicing_info = [ - 'business_name' => '', - 'taxcode' => '', - 'vat' => '', - 'address' => '', - 'invoices_counter' => 0, - 'invoices_counter_year' => '', - ]; - } - - $gas->setConfig('extra_invoicing', $invoicing_info); + $gas->setManyConfigs($request, [ + 'year_closing', + 'annual_fee_amount', + 'deposit_amount', + 'auto_fee', + 'rid', + 'satispay', + 'integralces', + 'extra_invoicing' + ]); } private function configUsers($gas, $request) { - if ($request->has('enable_public_registrations')) { - $registrations_info = (object) [ - 'enabled' => true, - 'privacy_link' => $request->input('public_registrations->privacy_link', ''), - 'terms_link' => $request->input('public_registrations->terms_link', ''), - 'mandatory_fields' => Arr::wrap($request->input('public_registrations->mandatory_fields', [])), - 'manual' => $request->has('public_registrations->manual'), - ]; - } - else { - $registrations_info = (object) [ - 'enabled' => false, - 'privacy_link' => '', - 'terms_link' => '', - 'mandatory_fields' => ['firstname', 'lastname', 'email', 'phone'], - 'manual' => false, - ]; - } - - $gas->setConfig('public_registrations', $registrations_info); + $gas->setManyConfigs($request, ['public_registrations']); } private function configProducts($gas, $request) { - $gas->setConfig('manual_products_sorting', $request->has('manual_products_sorting') ? '1' : '0'); - $gas->setConfig('products_grid_display_columns', $request->input('products_grid_display_columns', [])); + $gas->setManyConfigs($request, [ + 'manual_products_sorting', + 'products_grid_display_columns', + ]); } private function configOrders($gas, $request) { - $gas->setConfig('restrict_booking_to_credit', $request->has('restrict_booking_to_credit') ? '1' : '0'); - $gas->setConfig('unmanaged_shipping', $request->has('unmanaged_shipping') ? '1' : '0'); - $gas->setConfig('booking_contacts', $request->input('booking_contacts')); - $gas->setConfig('orders_display_columns', $request->input('orders_display_columns', [])); - $gas->setConfig('orders_shipping_user_columns', $request->input('orders_shipping_user_columns', [])); - $gas->setConfig('orders_shipping_product_columns', $request->input('orders_shipping_product_columns', [])); + $gas->setManyConfigs($request, [ + 'restrict_booking_to_credit', + 'unmanaged_shipping', + 'booking_contacts', + 'orders_display_columns', + 'orders_shipping_user_columns', + 'orders_shipping_product_columns', + ]); } private function configMails($gas, $request) { - $gas->setConfig('notify_all_new_orders', $request->has('notify_all_new_orders') ? '1' : '0'); - $gas->setConfig('send_order_reminder', $request->has('enable_send_order_reminder') ? $request->input('send_order_reminder') : '0'); - $gas->setConfig('auto_user_order_summary', $request->has('auto_user_order_summary') ? '1' : '0'); - $gas->setConfig('auto_referent_order_summary', $request->has('auto_referent_order_summary') ? '1' : '0'); - $gas->setConfig('auto_supplier_order_summary', $request->has('auto_supplier_order_summary') ? '1' : '0'); + $gas->setManyConfigs($request, [ + 'notify_all_new_orders', + 'send_order_reminder', + 'auto_user_order_summary', + 'auto_referent_order_summary', + 'auto_supplier_order_summary', + ]); foreach(systemParameters('MailTypes') as $identifier => $metadata) { if ($request->has("custom_mails_${identifier}_subject")) { @@ -229,21 +134,17 @@ private function configMails($gas, $request) private function configImport($gas, $request) { - $gas->setConfig('es_integration', $request->has('es_integration') ? '1' : '0'); - $gas->setConfig('csv_separator', $request->input('csv_separator')); + $gas->setManyConfigs($request, [ + 'es_integration', + 'csv_separator', + ]); } private function configRoles($gas, $request) { - $role_service = app()->make('RolesService'); - - foreach(['user', 'friend', 'multigas'] as $role_type) { - $input_key = sprintf('roles->%s', $role_type); - if ($request->has($input_key)) { - $role = $request->input($input_key); - $role_service->setMasterRole($gas, $role_type, $role); - } - } + $gas->setManyConfigs($request, [ + 'roles', + ]); } public function update(Request $request, $id) diff --git a/code/app/Models/Concerns/AttachableTrait.php b/code/app/Models/Concerns/AttachableTrait.php index 04bc50859..cf617ec8a 100644 --- a/code/app/Models/Concerns/AttachableTrait.php +++ b/code/app/Models/Concerns/AttachableTrait.php @@ -61,18 +61,10 @@ private function retrieveAttachment($id) public function attachByRequest($request, $id = null) { - if (is_array($request)) { - $file = $request['file'] ?? null; - $name = ''; - $users = $request['users'] ?? []; - $to_delete = $request['delete_attachment'] ?? []; - } - else { - $file = $request->file('file'); - $name = $request->input('name', ''); - $users = $request->input('users', []); - $to_delete = $request->input('to_delete', []); - } + $file = $request['file'] ?? null; + $name = $request['name'] ?? ''; + $users = $request['users'] ?? []; + $to_delete = $request['delete_attachment'] ?? []; foreach ($this->attachments()->whereIn('id', $to_delete)->get() as $att) { $att->delete(); diff --git a/code/app/Models/Concerns/Configurable.php b/code/app/Models/Concerns/Configurable.php new file mode 100644 index 000000000..b6b44242a --- /dev/null +++ b/code/app/Models/Concerns/Configurable.php @@ -0,0 +1,89 @@ +hasMany(Config::class); + } + + private function availableConfigs() + { + return systemParameters('Config'); + } + + public function getConfig($name) + { + foreach ($this->configs as $conf) { + if ($conf->name == $name) { + return $conf->value; + } + } + + $defined = $this->availableConfigs(); + if (!isset($defined[$name])) { + \Log::error(_i('Configurazione GAS non prevista')); + return ''; + } + else { + $this->setConfig($name, $defined[$name]->default()); + $this->load('configs'); + return $this->getConfig($name); + } + } + + public function setConfig($name, $value) + { + if (is_object($value) || is_array($value)) { + $value = json_encode($value); + } + + foreach ($this->configs as $conf) { + if ($conf->name == $name) { + $conf->value = $value; + $conf->save(); + return; + } + } + + $conf = new Config(); + $conf->name = $name; + $conf->value = $value; + $conf->gas_id = $this->id; + $conf->save(); + } + + public function setManyConfigs($request, $params) + { + $configs = $this->availableConfigs(); + + foreach($params as $param) { + $c = $configs[$param]; + $c->handleSave($this, $request); + } + } + + /* + Questa funzione permette di accedere direttamente alle configurazioni + del GAS, usandone il nome (definito da ciascun parametro definito nelle + classi nel namespace App\Parameters\Config) + */ + public function getAttribute($key) + { + $configs = $this->availableConfigs(); + $c = $configs[$key] ?? null; + + if ($c) { + return $c->asAttribute($this); + } + else { + return parent::getAttribute($key); + } + } +} diff --git a/code/app/Parameters/Config/Config.php b/code/app/Parameters/Config/Config.php index 999ddc406..2c49002df 100644 --- a/code/app/Parameters/Config/Config.php +++ b/code/app/Parameters/Config/Config.php @@ -23,6 +23,43 @@ public function asAttribute($gas) } } + /* + Questa funzione gestisce il salvataggio della configurazione, così come + rappresentata nei relativi pannelli. + Le configurazioni di tipo "object", che richiedono vari e variegati + sotto-attributi, dovrebbero sempre sovrascrivere questa funzione per + organizzarli nel modo opportuno + */ + public function handleSave($gas, $request) + { + $id = $this->identifier(); + + switch ($this->type()) { + case 'boolean': + $value = $request->has($id) ? '1' : '0'; + break; + + case 'float': + case 'number': + $value = $request->input($id, 0); + break; + + case 'array': + $value = $request->input($id, []); + break; + + case 'object': + throw new \Exception("Le configurazioni di tipo 'object' devono avere una propria funzione di salvataggio", 1); + + default: + $value = $request->input($id); + break; + } + + $gas->setConfig($id, $value); + } + + public abstract function identifier(); public abstract function type(); public abstract function default(); } diff --git a/code/app/Parameters/Config/ExtraInvoicing.php b/code/app/Parameters/Config/ExtraInvoicing.php index 208e34c43..eebbc6c0b 100644 --- a/code/app/Parameters/Config/ExtraInvoicing.php +++ b/code/app/Parameters/Config/ExtraInvoicing.php @@ -25,4 +25,33 @@ public function default() 'invoices_counter_year' => date('Y'), ]; } + + public function handleSave($gas, $request) + { + if ($request->has('enable_extra_invoicing')) { + $invoicing_info = $gas->extra_invoicing; + $invoicing_info['business_name'] = $request->input('extra_invoicing->business_name'); + $invoicing_info['taxcode'] = $request->input('extra_invoicing->taxcode'); + $invoicing_info['vat'] = $request->input('extra_invoicing->vat'); + $invoicing_info['address'] = $request->input('extra_invoicing->address'); + $invoicing_info['invoices_counter_year'] = date('Y'); + + $reset_counter = $request->input('extra_invoicing->invoices_counter'); + if (!empty($reset_counter)) { + $invoicing_info['invoices_counter'] = $reset_counter; + } + } + else { + $invoicing_info = [ + 'business_name' => '', + 'taxcode' => '', + 'vat' => '', + 'address' => '', + 'invoices_counter' => 0, + 'invoices_counter_year' => '', + ]; + } + + $gas->setConfig('extra_invoicing', $invoicing_info); + } } diff --git a/code/app/Parameters/Config/IntegralCES.php b/code/app/Parameters/Config/IntegralCES.php index fd212e279..12f94cb44 100644 --- a/code/app/Parameters/Config/IntegralCES.php +++ b/code/app/Parameters/Config/IntegralCES.php @@ -31,4 +31,24 @@ public function asAttribute($gas) $ret['symbol'] = Currency::where('context', 'integralces')->first()->symbol ?? ''; return $ret; } + + public function handleSave($gas, $request) + { + if ($request->has('enable_integralces')) { + $integralces_info = (object) [ + 'enabled' => true, + 'identifier' => $request->input('integralces->identifier'), + 'symbol' => $request->input('integralces->symbol'), + ]; + } + else { + $integralces_info = (object) [ + 'enabled' => false, + 'identifier' => '', + 'symbol' => '', + ]; + } + + $gas->setConfig('integralces', $integralces_info); + } } diff --git a/code/app/Parameters/Config/PublicRegistrations.php b/code/app/Parameters/Config/PublicRegistrations.php index e976985a5..b331daea4 100644 --- a/code/app/Parameters/Config/PublicRegistrations.php +++ b/code/app/Parameters/Config/PublicRegistrations.php @@ -2,6 +2,8 @@ namespace App\Parameters\Config; +use Illuminate\Support\Arr; + class PublicRegistrations extends Config { public function identifier() @@ -24,4 +26,28 @@ public function default() 'manual' => false, ]; } + + public function handleSave($gas, $request) + { + if ($request->has('enable_public_registrations')) { + $registrations_info = (object) [ + 'enabled' => true, + 'privacy_link' => $request->input('public_registrations->privacy_link', ''), + 'terms_link' => $request->input('public_registrations->terms_link', ''), + 'mandatory_fields' => Arr::wrap($request->input('public_registrations->mandatory_fields', [])), + 'manual' => $request->has('public_registrations->manual'), + ]; + } + else { + $registrations_info = (object) [ + 'enabled' => false, + 'privacy_link' => '', + 'terms_link' => '', + 'mandatory_fields' => ['firstname', 'lastname', 'email', 'phone'], + 'manual' => false, + ]; + } + + $gas->setConfig('public_registrations', $registrations_info); + } } diff --git a/code/app/Parameters/Config/Rid.php b/code/app/Parameters/Config/Rid.php index 9d557a6d2..ca6f163dc 100644 --- a/code/app/Parameters/Config/Rid.php +++ b/code/app/Parameters/Config/Rid.php @@ -22,4 +22,24 @@ public function default() 'org' => '' ]; } + + public function handleSave($gas, $request) + { + if ($request->has('enable_rid')) { + $rid_info = (object) [ + 'iban' => $request->input('rid->iban'), + 'id' => $request->input('rid->id'), + 'org' => $request->input('rid->org'), + ]; + } + else { + $rid_info = (object) [ + 'iban' => '', + 'id' => '', + 'org' => '', + ]; + } + + $gas->setConfig('rid', $rid_info); + } } diff --git a/code/app/Parameters/Config/Roles.php b/code/app/Parameters/Config/Roles.php index 7ccfbcac2..f8f65cadb 100644 --- a/code/app/Parameters/Config/Roles.php +++ b/code/app/Parameters/Config/Roles.php @@ -28,4 +28,17 @@ public function default() 'multigas' => $secondary_admin_role ? $secondary_admin_role->id : -1 ]; } + + public function handleSave($gas, $request) + { + $role_service = app()->make('RolesService'); + + foreach(['user', 'friend', 'multigas'] as $role_type) { + $input_key = sprintf('roles->%s', $role_type); + if ($request->has($input_key)) { + $role = $request->input($input_key); + $role_service->setMasterRole($gas, $role_type, $role); + } + } + } } diff --git a/code/app/Parameters/Config/Satispay.php b/code/app/Parameters/Config/Satispay.php index 7539cb624..477483d92 100644 --- a/code/app/Parameters/Config/Satispay.php +++ b/code/app/Parameters/Config/Satispay.php @@ -22,4 +22,37 @@ public function default() 'key' => '', ]; } + + public function handleSave($gas, $request) + { + $satispay_info = null; + + if ($request->has('enable_satispay')) { + $auth_code = $request->input('satispay_auth_code'); + if ($auth_code) { + try { + $authentication = \SatispayGBusiness\Api::authenticateWithToken($auth_code); + $satispay_info = (object) [ + 'public' => $authentication->publicKey, + 'secret' => $authentication->privateKey, + 'key' => $authentication->keyId, + ]; + } + catch(\Exception $e) { + \Log::error('Impossibile completare procedura di verifica su Satispay: ' . $e->getMessage()); + } + } + } + else { + $satispay_info = (object) [ + 'public' => '', + 'secret' => '', + 'key' => '', + ]; + } + + if ($satispay_info) { + $gas->setConfig('satispay', $satispay_info); + } + } } diff --git a/code/app/Parameters/Config/SendOrderReminder.php b/code/app/Parameters/Config/SendOrderReminder.php index bee32a173..89f1ec815 100644 --- a/code/app/Parameters/Config/SendOrderReminder.php +++ b/code/app/Parameters/Config/SendOrderReminder.php @@ -18,4 +18,9 @@ public function default() { return 0; } + + public function handleSave($gas, $request) + { + $gas->setConfig('send_order_reminder', $request->has('enable_send_order_reminder') ? $request->input('send_order_reminder') : '0'); + } } diff --git a/code/app/Parameters/Config/YearClosing.php b/code/app/Parameters/Config/YearClosing.php index 619673cf4..64cfe45cb 100644 --- a/code/app/Parameters/Config/YearClosing.php +++ b/code/app/Parameters/Config/YearClosing.php @@ -18,4 +18,9 @@ public function default() { return date('Y') . '-09-01'; } + + public function handleSave($gas, $request) + { + $gas->setConfig('year_closing', decodeDateMonth($request->input('year_closing'))); + } } diff --git a/code/app/Printers/AggregateBooking.php b/code/app/Printers/AggregateBooking.php index 638c4212a..6ba0348fc 100644 --- a/code/app/Printers/AggregateBooking.php +++ b/code/app/Printers/AggregateBooking.php @@ -12,7 +12,7 @@ public function document($obj, $type, $request) foreach($obj->user->friends as $friend) { $friend_booking = $obj->aggregate->bookingBy($friend->id); - if (!empty($friend_booking->bookings)) { + if ($friend_booking->bookings->isEmpty() == false) { $bookings[] = $friend_booking; } } diff --git a/code/app/Printers/Components/Table.php b/code/app/Printers/Components/Table.php index a63701411..fb1de2aef 100644 --- a/code/app/Printers/Components/Table.php +++ b/code/app/Printers/Components/Table.php @@ -19,12 +19,7 @@ public function renderHtml() if (empty($this->headers) == false) { $cellsize = round(100 / count($this->headers), 3); - } - else { - $cellsize = round(100 / count(($this->contents[0] ?? [])), 3); - } - if (empty($this->headers) == false) { $ret .= ''; foreach ($this->headers as $header) { @@ -33,6 +28,9 @@ public function renderHtml() $ret .= ''; } + else { + $cellsize = round(100 / count(($this->contents[0] ?? [])), 3); + } $ret .= ''; diff --git a/code/app/Scopes/RestrictedGAS.php b/code/app/Scopes/RestrictedGAS.php index ae6d4b05e..dcc42939f 100644 --- a/code/app/Scopes/RestrictedGAS.php +++ b/code/app/Scopes/RestrictedGAS.php @@ -53,19 +53,16 @@ public function apply(Builder $builder, Model $model) */ if ($hub->hubRequired() && $hub->enabled()) { $gas_id = $hub->getGas(); + $inner_query = $this->initInnerQuery($gas_id); + $models = explode('.', $this->key); - if ($gas_id) { - $inner_query = $this->initInnerQuery($gas_id); - $models = explode('.', $this->key); - - if (count($models) == 1) { - $builder->whereHas($models[0], $inner_query); - } - else { - $builder->whereHas($models[0], function($query) use ($models, $inner_query) { - $query->whereHas($models[1], $inner_query); - }); - } + if (count($models) == 1) { + $builder->whereHas($models[0], $inner_query); + } + else { + $builder->whereHas($models[0], function($query) use ($models, $inner_query) { + $query->whereHas($models[1], $inner_query); + }); } } } diff --git a/code/tests/Services/FastBookingsServiceTest.php b/code/tests/Services/FastBookingsServiceTest.php index 858e4e671..074e22e0f 100644 --- a/code/tests/Services/FastBookingsServiceTest.php +++ b/code/tests/Services/FastBookingsServiceTest.php @@ -19,7 +19,7 @@ public function setUp(): void } /* - Test consegne veloci + Consegne veloci */ public function testFastShipping() { @@ -44,7 +44,7 @@ public function testFastShipping() } /* - Test consegne veloci parziali + Consegne veloci parziali */ public function testFastShippingFiltered() { @@ -84,7 +84,7 @@ public function testFastShippingFiltered() } /* - Test consegne veloci su prenotazioni salvate + Consegne veloci su prenotazioni salvate */ public function testFastShippingPreSaved() { @@ -133,4 +133,35 @@ public function testFastShippingPreSaved() $this->assertEquals($booking->payment->amount, $booking->getValue('effective', true)); } } + + /* + Consegne veloci e generazione ricevute + */ + public function testFastShippingReceipts() + { + $this->gas->setConfig('extra_invoicing', [ + 'business_name' => 'Test', + 'taxcode' => '0123456789', + 'vat' => '0123456789', + 'address' => '', + 'invoices_counter' => 0, + 'invoices_counter_year' => '', + ]); + + $this->nextRound(); + + $this->populateOrder($this->sample_order); + + $this->actingAs($this->userWithShippingPerms); + $order = $this->services['orders']->show($this->sample_order->id); + $this->services['fast_bookings']->fastShipping($this->userWithShippingPerms, $order->aggregate, null); + + $this->nextRound(); + $receipts = \App\Receipt::all(); + $this->assertEquals($order->bookings->count(), $receipts->count()); + + foreach($receipts as $receipt) { + $this->assertEquals(1, $receipt->bookings->count()); + } + } }