Ottimizzazione file con php8.1

This commit is contained in:
Pek5892 2024-04-08 15:44:33 +02:00
parent 00baaa0788
commit 6369cb466e
106 changed files with 233 additions and 360 deletions

View File

@ -67,7 +67,8 @@
"willdurand/geocoder": "^4.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.10.0"
"friendsofphp/php-cs-fixer": "^3.10.0",
"rector/rector": "^1.0"
},
"autoload": {
"psr-4": {

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
$result['idarticolo'] = isset($result['idarticolo']) ? $result['idarticolo'] : null;
$result['idarticolo'] ??= null;
$qta_minima = 0;
$id_listino = $dbo->selectOne('an_anagrafiche', 'id_listino', ['idanagrafica' => $options['idanagrafica']])['id_listino'];

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
$result['id'] = isset($result['id']) ? $result['id'] : null;
$result['id'] ??= null;
// Form di inserimento riga documento
echo '

View File

@ -99,7 +99,7 @@ if (post('action') == 'init') {
'password' => Auth::hashPassword(post('admin_password')),
'email' => post('admin_email'),
'idgruppo' => $admin['id'],
'idanagrafica' => isset($id_record) ? $id_record : 0,
'idanagrafica' => $id_record ?? 0,
'enabled' => 1,
]);

View File

@ -84,7 +84,7 @@ foreach ($modules as $name => $values) {
$status = isset($available_modules) ? in_array($name, $available_modules) : $_SERVER[$values['server']] == 'On';
if ($name == 'mod_mime' && $php_interface != 'apache') {
$headers = get_headers((!empty($config['redirectHTTPS']) && !isHTTPS(true)) ? 'https://' : 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], 1);
$headers = get_headers((!empty($config['redirectHTTPS']) && !isHTTPS(true)) ? 'https://' : 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], true);
if (isset($headers['Content-Type'])) {
$status = 1;
} else {
@ -431,11 +431,11 @@ foreach ($config_to_check as $name => $values) {
if ($type == 'value') {
$description = tr('Valore consigliato: _SUGGESTED_ (Valore attuale: _ACTUAL_)', [
'_SUGGESTED_' => $values['suggested_value'],
'_ACTUAL_' => (!empty($values['section']) ? ${$values['section']}[$name] : $$name),
'_ACTUAL_' => (!empty($values['section']) ? ${$values['section']}[$name] : ${$name}),
]);
}
$status = ($values['operator'](!empty($values['section']) ? ${$values['section']}[$name] : $$name, $values['value_to_check']) ? 1 : 0);
$status = ($values['operator'](!empty($values['section']) ? ${$values['section']}[$name] : ${$name}, $values['value_to_check']) ? 1 : 0);
$config[] = [
'name' => $name,

View File

@ -99,7 +99,7 @@ if (!empty($type) && $type != 'menu' && $type != 'custom') {
$_SESSION['module_'.$id_module]['selected'] = [];
$selezione = array_keys($_SESSION['module_'.$id_module]['selected']);
$table_id = 'main_'.rand(0, 99);
$table_id = 'main_'.random_int(0, 99);
echo '
<table data-idmodule="'.$id_module.'" data-idplugin="'.$id_plugin.'" data-idparent="'.$id_record.'" data-selected="'.implode(';', $selezione).'" id="'.$table_id.'" width="100%" class="main-records'.(!empty($id_plugin) ? '-plugins' : '').' table table-condensed table-bordered">
<thead>

View File

@ -47,7 +47,7 @@ echo '<!DOCTYPE html>
if (file_exists(base_dir().'/manifest.json')) {
echo '
<link rel="manifest" href="'.base_path().'/manifest.json?r='.rand().'">';
<link rel="manifest" href="'.base_path().'/manifest.json?r='.random_int(0, mt_getrandmax()).'">';
}
// CSS

View File

@ -442,7 +442,7 @@ function session_get($name, $default = null)
$session = &$session[$piece];
}
return isset($session) ? $session : $default;
return $session ?? $default;
}
/**

View File

@ -38,9 +38,7 @@ if (!function_exists('array_column')) {
*/
function array_column($array, $key)
{
return array_map(function ($v) use ($key) {
return is_object($v) ? $v->$key : $v[$key];
}, $array);
return array_map(fn($v) => is_object($v) ? $v->$key : $v[$key], $array);
}
}
@ -55,9 +53,7 @@ if (!function_exists('array_clean')) {
function array_clean($array)
{
if (!empty($array)) {
return array_unique(array_values(array_filter($array, function ($value) {
return !empty($value);
})));
return array_unique(array_values(array_filter($array, fn($value) => !empty($value))));
}
}
}
@ -448,8 +444,8 @@ if (!function_exists('color_inverse')) {
$R2 = 255;
$G2 = 255;
$B2 = 255;
$L1 = 0.2126 * pow($R1 / 255, 2.2) + 0.7152 * pow($G1 / 255, 2.2) + 0.0722 * pow($B1 / 255, 2.2);
$L2 = 0.2126 * pow($R2 / 255, 2.2) + 0.7152 * pow($G2 / 255, 2.2) + 0.0722 * pow($B2 / 255, 2.2);
$L1 = 0.2126 * ($R1 / 255) ** 2.2 + 0.7152 * ($G1 / 255) ** 2.2 + 0.0722 * ($B1 / 255) ** 2.2;
$L2 = 0.2126 * ($R2 / 255) ** 2.2 + 0.7152 * ($G2 / 255) ** 2.2 + 0.0722 * ($B2 / 255) ** 2.2;
if ($L1 > $L2) {
$lum = ($L1 + 0.05) / ($L2 + 0.05);
} else {
@ -602,6 +598,6 @@ if (!function_exists('adjustBrightness')) {
$color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
}
return '#'.implode($hexCode);
return '#'.implode('', $hexCode);
}
}

View File

@ -260,7 +260,7 @@ if (!empty($results) || !empty($results_settings) || !empty($results_settings_ad
'.$key.'
</td>
<td>
'.($setting['current'] ? $setting['current'] : '⚠️ Impostazione mancante').'
'.($setting['current'] ?: '⚠️ Impostazione mancante').'
</td>
<td>
'.$setting['expected'].'

View File

@ -43,7 +43,7 @@ echo '
</div>
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Tipo di anagrafica').'", "name": "idtipoanagrafica[]", "id": "idtipoanagrafica_add", "multiple": "1", "required": 1, "values": "query=SELECT `an_tipianagrafiche`.`id`, `name` as descrizione FROM `an_tipianagrafiche` LEFT JOIN `an_tipianagrafiche_lang` ON (`an_tipianagrafiche`.`id` = `an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `an_tipianagrafiche`.`id` NOT IN (SELECT DISTINCT(`x`.`idtipoanagrafica`) FROM `an_tipianagrafiche_anagrafiche` x INNER JOIN `an_tipianagrafiche` t ON `x`.`idtipoanagrafica` = `t`.`id` LEFT JOIN `an_tipianagrafiche_lang` ON (`t`.`id` = `an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `x`.`idanagrafica` WHERE `an_tipianagrafiche`.`id` = '.prepare($id_tipo_azienda).' AND `deleted_at` IS NULL) ORDER BY `name`", "value": "'.(isset($idtipoanagrafica) ? $idtipoanagrafica : null).'", "readonly": '.(!empty(get('readonly_tipo')) ? 1 : 0).' ]}
{[ "type": "select", "label": "'.tr('Tipo di anagrafica').'", "name": "idtipoanagrafica[]", "id": "idtipoanagrafica_add", "multiple": "1", "required": 1, "values": "query=SELECT `an_tipianagrafiche`.`id`, `name` as descrizione FROM `an_tipianagrafiche` LEFT JOIN `an_tipianagrafiche_lang` ON (`an_tipianagrafiche`.`id` = `an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `an_tipianagrafiche`.`id` NOT IN (SELECT DISTINCT(`x`.`idtipoanagrafica`) FROM `an_tipianagrafiche_anagrafiche` x INNER JOIN `an_tipianagrafiche` t ON `x`.`idtipoanagrafica` = `t`.`id` LEFT JOIN `an_tipianagrafiche_lang` ON (`t`.`id` = `an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `x`.`idanagrafica` WHERE `an_tipianagrafiche`.`id` = '.prepare($id_tipo_azienda).' AND `deleted_at` IS NULL) ORDER BY `name`", "value": "'.($idtipoanagrafica ?? null).'", "readonly": '.(!empty(get('readonly_tipo')) ? 1 : 0).' ]}
</div>
</div>

View File

@ -360,9 +360,9 @@ switch ($resource) {
*
FROM
(SELECT '0' AS id, (SELECT `lat` FROM `an_anagrafiche` |where|) AS lat, (SELECT `lng` FROM `an_anagrafiche` |where|) AS lng, (SELECT `idzona` FROM `an_anagrafiche` |where|) AS idzona, CONCAT_WS(' - ', \"".tr('Sede legale')."\" , (SELECT CONCAT (`citta`, IF(`indirizzo`!='',CONCAT(' (', `indirizzo`, ')'), ''), ' (',`ragione_sociale`,')') FROM `an_anagrafiche` |where|)) AS descrizione
UNION
SELECT
`id`,
`lat`,

View File

@ -473,9 +473,7 @@ if ($is_cliente or $is_fornitore or $is_tecnico) {
</div>';
$banche = Banca::where('id_anagrafica', $anagrafica->id)->get();
$banca_predefinita = $banche->first(function ($item) {
return !empty($item['predefined']);
});
$banca_predefinita = $banche->first(fn($item) => !empty($item['predefined']));
$modulo_banche = (new Module())->getByField('name', 'Banche', Models\Locale::getPredefined()->id);
if (!$banche->isEmpty()) {
echo '

View File

@ -192,9 +192,7 @@ class Anagrafica extends Model
*/
public function isTipo($type)
{
return $this->tipi()->get()->search(function ($item, $key) use ($type) {
return TipoAnagrafica::find($item->id)->getTranslation('name', \Models\Locale::getPredefined()->id) == $type;
}) !== false;
return $this->tipi()->get()->search(fn($item, $key) => TipoAnagrafica::find($item->id)->getTranslation('name', \Models\Locale::getPredefined()->id) == $type) !== false;
}
public function delete()

View File

@ -32,19 +32,19 @@ if (!function_exists('aggiorna_sedi_movimenti')) {
$idsede = ($rs[0]['dir'] == 'uscita') ? $rs[0]['idsede_destinazione'] : $rs[0]['idsede_partenza'];
$dbo->query('UPDATE `mg_movimenti` SET `idsede`='.prepare($idsede).' WHERE `reference_type`='.prepare('Modules\DDT\DDT').' AND `reference_id`='.prepare($id));
$dbo->query('UPDATE `mg_movimenti` SET `idsede`='.prepare($idsede).' WHERE `reference_type`='.prepare(\Modules\DDT\DDT::class).' AND `reference_id`='.prepare($id));
} elseif ($module == 'documenti') {
$rs = $dbo->fetchArray('SELECT `idsede_partenza`, `idsede_destinazione`, `dir` FROM `co_documenti` INNER JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`id`='.prepare($id));
$idsede = ($rs[0]['dir'] == 'uscita') ? $rs[0]['idsede_destinazione'] : $rs[0]['idsede_partenza'];
$dbo->query('UPDATE mg_movimenti SET idsede='.prepare($idsede).' WHERE reference_type='.prepare('Modules\Fatture\Fattura').' AND reference_id='.prepare($id));
$dbo->query('UPDATE mg_movimenti SET idsede='.prepare($idsede).' WHERE reference_type='.prepare(\Modules\Fatture\Fattura::class).' AND reference_id='.prepare($id));
} elseif ($module == 'interventi') {
$rs = $dbo->fetchArray('SELECT idsede_partenza, idsede_destinazione FROM in_interventi WHERE in_interventi.id='.prepare($id));
$idsede = $rs[0]['idsede_partenza'];
$dbo->query('UPDATE mg_movimenti SET idsede='.prepare($idsede).' WHERE reference_type='.prepare('Modules\Interventi\Intervento').' AND reference_id='.prepare($id));
$dbo->query('UPDATE mg_movimenti SET idsede='.prepare($idsede).' WHERE reference_type='.prepare(\Modules\Interventi\Intervento::class).' AND reference_id='.prepare($id));
}
}
}

View File

@ -149,7 +149,7 @@ if (!empty($movimenti)) {
// Data
$utente = $dbo->table('zz_users')->where('id', $movimento->idutente)->first();
$data = ($movimento->data ? $movimento->data : $movimento->data_movimento);
$data = ($movimento->data ?: $movimento->data_movimento);
echo '
<td class="text-center">'.dateFormat($data).' <span class="tip" title="'.tr('Creazione movimento: _DATE_ <br>Creatore movimento: _USER_', [
'_DATE_' => timestampFormat($movimento->data_movimento),

View File

@ -82,7 +82,7 @@ class Articoli extends Resource implements RetrieveInterface, UpdateInterface, C
$data = $request['data'];
// Gestione categoria
list($categoria, $sottocategoria) = $this->gestioneCategorie($data['categoria'], $data['sottocategoria']);
[$categoria, $sottocategoria] = $this->gestioneCategorie($data['categoria'], $data['sottocategoria']);
$articolo = Articolo::build($data['codice'], $categoria, $sottocategoria);
$articolo->setPrezzoVendita($data['prezzo_vendita'], $articolo->idiva_vendita);
@ -99,7 +99,7 @@ class Articoli extends Resource implements RetrieveInterface, UpdateInterface, C
$data = $request['data'];
$articolo = Articolo::find($request['id']);
list($categoria, $sottocategoria) = $this->gestioneCategorie($data['categoria'], $data['sottocategoria']);
[$categoria, $sottocategoria] = $this->gestioneCategorie($data['categoria'], $data['sottocategoria']);
// Gestione categoria
if (!empty($categoria)) {

View File

@ -296,9 +296,7 @@ class Articolo extends Model
}
$movimenti = $movimenti->get()
->mapToGroups(function ($item, $key) {
return [$item->idsede => (float) $item->attributes['qta']];
})
->mapToGroups(fn($item, $key) => [$item->idsede => (float) $item->attributes['qta']])
->toArray();
return $movimenti;

View File

@ -85,11 +85,7 @@ class Movimento extends Model
public function getQtaAttribute()
{
if (isset($this->qta_documento)) {
return $this->qta_documento;
}
return $this->qta;
return $this->qta_documento ?? $this->qta;
}
public function articolo()

View File

@ -56,7 +56,7 @@ switch (post('op')) {
$data_fine = post('data_fine');
}
}
$data_fine = isset($data_fine) ? $data_fine : '0000-00-00';
$data_fine ??= '0000-00-00';
// Inserisco il tecnico
$dbo->insert('an_sedi_tecnici', [
@ -84,7 +84,7 @@ switch (post('op')) {
$data_fine = post('data_fine')[$idautomezzotecnico];
}
}
$data_fine = isset($data_fine) ? $data_fine : '0000-00-00';
$data_fine ??= '0000-00-00';
$dbo->update('an_sedi_tecnici', [
'idtecnico' => $idtecnico,

View File

@ -82,7 +82,7 @@ class Banca extends Model
protected function fixPredefined()
{
$predefined = isset($this->predefined) ? $this->predefined : false;
$predefined = $this->predefined ?? false;
// Selezione automatica per primo record
$count = self::where('id_anagrafica', $this->id_anagrafica)

View File

@ -73,9 +73,7 @@ class Combinazione extends Model
$result = parent::save($options);
// Sincronizzazione dei campi condivisi con la Combinazione
$sincro = collect($this->toArray())->filter(function ($value, $key) {
return in_array($key, self::$campi_combinazione);
});
$sincro = collect($this->toArray())->filter(fn($value, $key) => in_array($key, self::$campi_combinazione));
$this->sincronizzaCampi($sincro->toArray());
return $result;
@ -178,9 +176,7 @@ class Combinazione extends Model
return;
}
$sincro = collect($articolo->toArray())->filter(function ($value, $key) {
return in_array($key, self::$campi_varianti);
});
$sincro = collect($articolo->toArray())->filter(fn($value, $key) => in_array($key, self::$campi_varianti));
$combinazione->sincronizzaCampi($sincro->toArray());
}
@ -219,9 +215,7 @@ class Combinazione extends Model
->update($values);
// Filtro campi combinazioni
$combo = collect($values)->filter(function ($value, $key) {
return in_array($key, self::$campi_combinazione);
});
$combo = collect($values)->filter(fn($value, $key) => in_array($key, self::$campi_combinazione));
// Aggiornamento dati combinazioni
database()->table('mg_combinazioni')

View File

@ -34,7 +34,7 @@ use Plugins\PianificazioneInterventi\Promemoria;
$id_fatture = (new Module())->getByField('name', 'Fatture di vendita', Models\Locale::getPredefined()->id);
if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) {
$segments = Modules::getSegments($id_fatture);
$_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
$_SESSION['module_'.$id_fatture]['id_segment'] = $segments[0]['id'] ?? null;
}
$id_segment = $_SESSION['module_'.$id_fatture]['id_segment'];
$idconto = setting('Conto predefinito fatture di vendita');
@ -77,13 +77,9 @@ switch (post('op')) {
// Ricerca fattura per anagrafica tra le registrate
$id_sede = $raggruppamento == 'sede' ? $documento_import->idsede : 0;
if ($raggruppamento == 'sede') {
$fattura = $documenti->first(function ($item, $key) use ($id_anagrafica, $id_sede) {
return $item->anagrafica->id == $id_anagrafica && $item->idsede_destinazione == $id_sede;
});
$fattura = $documenti->first(fn($item, $key) => $item->anagrafica->id == $id_anagrafica && $item->idsede_destinazione == $id_sede);
} else {
$fattura = $documenti->first(function ($item, $key) use ($id_anagrafica) {
return $item->anagrafica->id == $id_anagrafica;
});
$fattura = $documenti->first(fn($item, $key) => $item->anagrafica->id == $id_anagrafica);
}
// Ricerca fattura per anagrafica se l'impostazione di accodamento è selezionata
@ -123,7 +119,7 @@ switch (post('op')) {
// Fix per idconto righe fattura
$articolo = ArticoloOriginale::find($copia->idarticolo);
$copia->id_conto = ($articolo->idconto_vendita ? $articolo->idconto_vendita : $idconto);
$copia->id_conto = ($articolo->idconto_vendita ?: $idconto);
// Aggiornamento seriali dalla riga dell'ordine
if ($copia->isArticolo()) {

View File

@ -586,7 +586,7 @@ switch (filter('op')) {
}
$id_iva = ($ddt->anagrafica->idiva_vendite && (!$originale->idiva_vendita || $aliquota_articolo != 0) ? $ddt->anagrafica->idiva_vendite : $originale->idiva_vendita) ?: setting('Iva predefinita');
} else {
$id_iva = ($ddt->anagrafica->idiva_acquisti ? $ddt->anagrafica->idiva_acquisti : ($originale->idiva_vendita ? $originale->idiva_vendita : setting('Iva predefinita')));
$id_iva = ($ddt->anagrafica->idiva_acquisti ?: ($originale->idiva_vendita ?: setting('Iva predefinita')));
}
$id_anagrafica = $ddt->idanagrafica;
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');

View File

@ -38,7 +38,7 @@ if ($module->getTranslation('name') == 'Ddt di vendita') {
$id_fatture = (new Module())->getByField('name', $module_fatture, Models\Locale::getPredefined()->id);
if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) {
$segments = Modules::getSegments($id_fatture);
$_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
$_SESSION['module_'.$id_fatture]['id_segment'] = $segments[0]['id'] ?? null;
}
$id_segment = $_SESSION['module_'.$id_fatture]['id_segment'];
$idconto = $module_fatture == 'Fatture di vendita' ? setting('Conto predefinito fatture di vendita') : setting('Conto predefinito fatture di acquisto');
@ -77,13 +77,9 @@ switch (post('op')) {
// Ricerca fattura per anagrafica tra le registrate
$id_sede = $raggruppamento == 'sede' ? $documento_import->idsede_destinazione : 0;
if ($raggruppamento == 'sede') {
$fattura = $documenti->first(function ($item, $key) use ($id_anagrafica, $id_sede) {
return $item->anagrafica->id == $id_anagrafica && $item->idsede_destinazione == $id_sede;
});
$fattura = $documenti->first(fn($item, $key) => $item->anagrafica->id == $id_anagrafica && $item->idsede_destinazione == $id_sede);
} else {
$fattura = $documenti->first(function ($item, $key) use ($id_anagrafica) {
return $item->anagrafica->id == $id_anagrafica;
});
$fattura = $documenti->first(fn($item, $key) => $item->anagrafica->id == $id_anagrafica);
}
// Ricerca fattura per anagrafica se l'impostazione di accodamento è selezionata
@ -123,7 +119,7 @@ switch (post('op')) {
// Fix per idconto righe fattura
$articolo = ArticoloOriginale::find($copia->idarticolo);
$copia->id_conto = ($articolo->idconto_vendita ? $articolo->idconto_vendita : $idconto);
$copia->id_conto = ($articolo->idconto_vendita ?: $idconto);
// Aggiornamento seriali dalla riga dell'ordine
if ($copia->isArticolo()) {

View File

@ -264,9 +264,7 @@ if (!function_exists('verifica_numero_ddt')) {
do {
$numero = Generator::generate($maschera, $ultimo, 1, Generator::dateToPattern($data));
$filtered = $documenti->reject(function ($item, $key) use ($numero) {
return $item->numero_esterno == $numero;
});
$filtered = $documenti->reject(fn($item, $key) => $item->numero_esterno == $numero);
if ($documenti->count() == $filtered->count()) {
return $numero;

View File

@ -153,9 +153,7 @@ class DDT extends Document
{
$righe = $this->getRighe();
$peso_lordo = $righe->sum(function ($item) {
return $item->isArticolo() ? $item->articolo->peso_lordo * $item->qta : 0;
});
$peso_lordo = $righe->sum(fn($item) => $item->isArticolo() ? $item->articolo->peso_lordo * $item->qta : 0);
return $peso_lordo;
}
@ -169,9 +167,7 @@ class DDT extends Document
{
$righe = $this->getRighe();
$volume = $righe->sum(function ($item) {
return $item->isArticolo() ? $item->articolo->volume * $item->qta : 0;
});
$volume = $righe->sum(fn($item) => $item->isArticolo() ? $item->articolo->volume * $item->qta : 0);
return $volume;
}

View File

@ -83,7 +83,7 @@ foreach ($results as $result) {
}
?>
</div>
<div class="pull-right">
<button type="button" class="btn btn-info" onclick="aggiungiData()">

View File

@ -302,7 +302,7 @@ switch ($op) {
}
$totale_documento = abs($totale_documento);
$totale_documento = $dati_generali['ImportoTotaleDocumento'] ? $dati_generali['ImportoTotaleDocumento'] : $totale_documento;
$totale_documento = $dati_generali['ImportoTotaleDocumento'] ?: $totale_documento;
} catch (Exception $e) {
}
@ -760,7 +760,7 @@ switch ($op) {
$fattura->idpagamento = setting('Tipo di pagamento predefinito');
}
$idsede = ($documento->idsede_destinazione ? $documento->idsede_destinazione : $documento->idsede);
$idsede = ($documento->idsede_destinazione ?: $documento->idsede);
$fattura->idsede_destinazione = $idsede;
$fattura->id_ritenuta_contributi = post('id_ritenuta_contributi') ?: null;
@ -1000,7 +1000,7 @@ switch ($op) {
}
$id_iva = ($fattura->anagrafica->idiva_vendite && (!$originale->idiva_vendita || $aliquota_articolo != 0) ? $fattura->anagrafica->idiva_vendite : $originale->idiva_vendita) ?: setting('Iva predefinita');
} else {
$id_iva = ($fattura->anagrafica->idiva_acquisti ? $fattura->anagrafica->idiva_acquisti : ($originale->idiva_vendita ? $originale->idiva_vendita : setting('Iva predefinita')));
$id_iva = ($fattura->anagrafica->idiva_acquisti ?: ($originale->idiva_vendita ?: setting('Iva predefinita')));
}
$id_anagrafica = $fattura->idanagrafica;
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');

View File

@ -125,7 +125,7 @@ switch (post('op')) {
$fattura_elettronica = new FatturaElettronica($id);
if (!empty($fattura_elettronica) && !$fattura_elettronica->isGenerated()) {
$file = $fattura_elettronica->save($upload_dir);
$file = $fattura_elettronica->save();
$added[] = $fattura->numero_esterno;
}
} catch (UnexpectedValueException $e) {
@ -311,7 +311,7 @@ switch (post('op')) {
foreach ($id_records as $id) {
$fattura = Fattura::find($id);
$id_segment = (post('id_segment') ? post('id_segment') : $fattura->id_segment);
$id_segment = (post('id_segment') ?: $fattura->id_segment);
$dir = $dbo->fetchOne('SELECT `dir` FROM `co_tipidocumento` WHERE `id`='.prepare($fattura->idtipodocumento))['dir'];
// + 1 giorno

View File

@ -81,9 +81,7 @@ if (isset($id_record)) {
$fattura_acquisto_originale = null;
if (!empty($fattura)) {
$reverse_charge = $fattura->getRighe()->first(function ($item, $key) {
return $item->aliquota != null && substr($item->aliquota->codice_natura_fe, 0, 2) == 'N6';
})->id;
$reverse_charge = $fattura->getRighe()->first(fn($item, $key) => $item->aliquota != null && substr($item->aliquota->codice_natura_fe, 0, 2) == 'N6')->id;
$autofattura_vendita = Fattura::find($fattura->id_autofattura);
$abilita_autofattura = (($fattura->anagrafica->nazione->iso2 != 'IT' && !empty($fattura->anagrafica->nazione->iso2)) || $reverse_charge) && $dir == 'uscita' && $fattura->id_autofattura == null;

View File

@ -449,9 +449,7 @@ if (!function_exists('verifica_numero_fattura')) {
do {
$numero = Generator::generate($maschera, $ultimo, 1, Generator::dateToPattern($data));
$filtered = $documenti->reject(function ($item, $key) use ($numero) {
return $item->numero_esterno == $numero;
});
$filtered = $documenti->reject(fn($item, $key) => $item->numero_esterno == $numero);
if ($documenti->count() == $filtered->count()) {
return $numero;
@ -471,9 +469,7 @@ if (!function_exists('verifica_numero_fattura')) {
$righe = [];
// Righe documento
$righe_documento = $documento->getRighe()->where('idintervento', '!=', null)->groupBy(function ($item, $key) {
return $item['prezzo_unitario'].'|'.$item['idiva'].'|'.$item['sconto_unitario'];
});
$righe_documento = $documento->getRighe()->where('idintervento', '!=', null)->groupBy(fn($item, $key) => $item['prezzo_unitario'].'|'.$item['idiva'].'|'.$item['sconto_unitario']);
if (setting('Raggruppa attività per tipologia in fattura') && !$righe_documento->isEmpty()) {
$articoli = [];

View File

@ -188,7 +188,7 @@ trait RelationTrait
*/
public function setQtaAttribute($value)
{
list($qta, $diff) = $this->parseQta($value);
[$qta, $diff] = $this->parseQta($value);
parent::setQtaAttribute($value);
// Individuazione fattura corrente (fix in caso di creazione diretta)

View File

@ -281,9 +281,7 @@ class Fattura extends Document
{
$righe = $this->getRighe();
$peso_lordo = $righe->sum(function ($item) {
return $item->isArticolo() ? $item->articolo->peso_lordo * $item->qta : 0;
});
$peso_lordo = $righe->sum(fn($item) => $item->isArticolo() ? $item->articolo->peso_lordo * $item->qta : 0);
return $peso_lordo;
}
@ -297,9 +295,7 @@ class Fattura extends Document
{
$righe = $this->getRighe();
$volume = $righe->sum(function ($item) {
return $item->isArticolo() ? $item->articolo->volume * $item->qta : 0;
});
$volume = $righe->sum(fn($item) => $item->isArticolo() ? $item->articolo->volume * $item->qta : 0);
return $volume;
}
@ -500,9 +496,7 @@ class Fattura extends Document
{
$nome = 'Ricevuta';
return $this->uploads()->filter(function ($item) use ($nome) {
return false !== strstr($item->getTranslation('name'), $nome);
})->sortBy('created_at');
return $this->uploads()->filter(fn($item) => false !== strstr($item->getTranslation('name'), $nome))->sortBy('created_at');
}
/**
@ -659,7 +653,7 @@ class Fattura extends Document
$checks = FatturaElettronica::controllaFattura($this);
$fattura_elettronica = new FatturaElettronica($this->id);
if ($abilita_genera && empty($checks)) {
$fattura_elettronica->save(base_dir().'/'.FatturaElettronica::getDirectory());
$fattura_elettronica->save();
if (!$fattura_elettronica->isValid()) {
$errors = $fattura_elettronica->getErrors();

View File

@ -47,9 +47,7 @@ class Bollo
return $this->fattura->bollo;
}
$righe_bollo = $this->fattura->getRighe()->filter(function ($item, $key) {
return $item->aliquota != null && in_array($item->aliquota->codice_natura_fe, ['N2.1', 'N2.2', 'N3.5', 'N3.6', 'N4']);
});
$righe_bollo = $this->fattura->getRighe()->filter(fn($item, $key) => $item->aliquota != null && in_array($item->aliquota->codice_natura_fe, ['N2.1', 'N2.2', 'N3.5', 'N3.6', 'N4']));
$importo_righe_bollo = $righe_bollo->sum('subtotale');
// Leggo la marca da bollo se c'è e se il netto a pagare supera la soglia
@ -72,9 +70,7 @@ class Bollo
public function manageRigaMarcaDaBollo()
{
$riga = $this->fattura->rigaBollo;
$righe_bollo = $this->fattura->getRighe()->filter(function ($item, $key) {
return $item->aliquota != null && in_array($item->aliquota->codice_natura_fe, ['N2.1', 'N2.2', 'N3.5', 'N3.6', 'N4']);
})->first();
$righe_bollo = $this->fattura->getRighe()->filter(fn($item, $key) => $item->aliquota != null && in_array($item->aliquota->codice_natura_fe, ['N2.1', 'N2.2', 'N3.5', 'N3.6', 'N4']))->first();
$addebita_bollo = $this->fattura->addebita_bollo;
$marca_da_bollo = $this->getBollo();

View File

@ -73,7 +73,7 @@ if (empty($id_record)) {
$nomi_disponibili = [];
foreach ($fields as $key => $value) {
$nomi_disponibili[$key] = [];
$names = isset($value['names']) ? $value['names'] : [$value['label']];
$names = $value['names'] ?? [$value['label']];
foreach ($names as $name) {
$nomi_disponibili[$key][] = trim(string_lowercase($name));
}

View File

@ -626,11 +626,11 @@ switch (post('op')) {
$intervento->idreferente = $documento->idreferente;
$intervento->idagente = $documento->idagente;
if ($class == 'Modules\Preventivi\Preventivo') {
if ($class == \Modules\Preventivi\Preventivo::class) {
$intervento->id_preventivo = $documento->id;
$intervento->richiesta = 'Attività creata da preventivo num. '.$documento->numero.'<br>'.$documento->nome;
}
if ($class == 'Modules\Ordini\Ordine') {
if ($class == \Modules\Ordini\Ordine::class) {
$intervento->id_ordine = $documento->id;
$intervento->richiesta = 'Attività creata da ordine num. '.$documento->numero_esterno;
}

View File

@ -210,7 +210,7 @@ if (!empty($sessioni)) {
$tipo_sconto = (setting('Tipo di sconto predefinito') == '%' ? 'PRC' : 'UNT');
echo '
<td style="border-right:1px solid #aaa;">
{[ "type": "number", "name": "sconto_unitario_'.$sessione['id'].'", "value": "'.Translator::numberToLocale($sessione['sconto_unitario']).'", "onchange": "aggiornaSessioneInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.($sessione['tipo_sconto'] ? $sessione['tipo_sconto'] : $tipo_sconto).'", "disabled": "'.$block_edit.'" ]}
{[ "type": "number", "name": "sconto_unitario_'.$sessione['id'].'", "value": "'.Translator::numberToLocale($sessione['sconto_unitario']).'", "onchange": "aggiornaSessioneInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.($sessione['tipo_sconto'] ?: $tipo_sconto).'", "disabled": "'.$block_edit.'" ]}
</td>';
}
@ -218,7 +218,7 @@ if (!empty($sessioni)) {
if ($show_costi) {
echo '
<td style="border-right:1px solid #aaa;">
{[ "type": "number", "name": "scontokm_unitario_'.$sessione['id'].'", "value": "'.Translator::numberToLocale($sessione['scontokm_unitario']).'", "onchange": "aggiornaSessioneInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.($sessione['tipo_sconto_km'] ? $sessione['tipo_sconto_km'] : $tipo_sconto).'", "disabled": "'.$block_edit.'" ]}
{[ "type": "number", "name": "scontokm_unitario_'.$sessione['id'].'", "value": "'.Translator::numberToLocale($sessione['scontokm_unitario']).'", "onchange": "aggiornaSessioneInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.($sessione['tipo_sconto_km'] ?: $tipo_sconto).'", "disabled": "'.$block_edit.'" ]}
</td>';
}

View File

@ -34,7 +34,7 @@ use Util\Zip;
$id_fatture = (new Module())->getByField('name', 'Fatture di vendita', Models\Locale::getPredefined()->id);
if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) {
$segments = Modules::getSegments($id_fatture);
$_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
$_SESSION['module_'.$id_fatture]['id_segment'] = $segments[0]['id'] ?? null;
}
$id_segment = $_SESSION['module_'.$id_fatture]['id_segment'];
$idtipodocumento = $dbo->selectOne('co_tipidocumento', ['id'], [

View File

@ -190,9 +190,7 @@ if (!function_exists('aggiungi_intervento_in_fattura')) {
} else {
$decimals = setting('Cifre decimali per quantità');
$ore_di_lavoro = $sessioni->groupBy(function ($item, $key) {
return $item['prezzo_orario'].'|'.$item['sconto_unitario'].'|'.$item['tipo_sconto'];
});
$ore_di_lavoro = $sessioni->groupBy(fn($item, $key) => $item['prezzo_orario'].'|'.$item['sconto_unitario'].'|'.$item['tipo_sconto']);
foreach ($ore_di_lavoro as $gruppo) {
$sessione = $gruppo->first();
$riga = Riga::build($fattura);
@ -234,9 +232,7 @@ if (!function_exists('aggiungi_intervento_in_fattura')) {
}
// Diritti di chiamata raggruppati per costo
$diritti_chiamata = $sessioni->where('prezzo_diritto_chiamata', '>', 0)->groupBy(function ($item, $key) {
return $item['prezzo_diritto_chiamata'];
});
$diritti_chiamata = $sessioni->where('prezzo_diritto_chiamata', '>', 0)->groupBy(fn($item, $key) => $item['prezzo_diritto_chiamata']);
foreach ($diritti_chiamata as $gruppo) {
$diritto_chiamata = $gruppo->first();
$riga = Riga::build($fattura);
@ -267,9 +263,7 @@ if (!function_exists('aggiungi_intervento_in_fattura')) {
}
// Viaggi raggruppati per costo
$viaggi = $sessioni->where('prezzo_km_unitario', '>', 0)->groupBy(function ($item, $key) {
return $item['prezzo_km_unitario'].'|'.$item['scontokm_unitario'].'|'.$item['tipo_scontokm'];
});
$viaggi = $sessioni->where('prezzo_km_unitario', '>', 0)->groupBy(fn($item, $key) => $item['prezzo_km_unitario'].'|'.$item['scontokm_unitario'].'|'.$item['tipo_scontokm']);
foreach ($viaggi as $gruppo) {
$qta_trasferta = $gruppo->sum('km');
if ($qta_trasferta == 0) {
@ -323,7 +317,7 @@ if (!function_exists('aggiungi_intervento_in_fattura')) {
if ($copia->isArticolo()) {
$copia->serials = $riga->serials;
$articolo = ArticoloOriginale::find($copia->idarticolo);
$copia->id_conto = ($articolo->idconto_vendita ? $articolo->idconto_vendita : $id_conto);
$copia->id_conto = ($articolo->idconto_vendita ?: $id_conto);
}
$copia->save();
@ -371,9 +365,7 @@ if (!function_exists('verifica_numero_intervento')) {
do {
$numero = Generator::generate($maschera, $ultimo, 1, Generator::dateToPattern($data), $data);
$filtered = $documenti->reject(function ($item, $key) use ($numero) {
return $item->codice == $numero;
});
$filtered = $documenti->reject(fn($item, $key) => $item->codice == $numero);
if ($documenti->count() == $filtered->count()) {
return $numero;

View File

@ -24,9 +24,7 @@ include_once __DIR__.'/../../../core.php';
// Interventi da pianificare NON completati
$interventi_da_pianificare = Intervento::doesntHave('sessioni')
->orderByRaw('IF(data_scadenza IS NULL, data_richiesta, data_scadenza)')
->whereHas('stato', function ($query) {
return $query->where('is_completato', '=', 0);
})
->whereHas('stato', fn($query) => $query->where('is_completato', '=', 0))
->get();
$raggruppamenti = $interventi_da_pianificare->groupBy(function ($item, $key) {
$data = $item->data_scadenza ?: $item->data_richiesta;

View File

@ -80,7 +80,7 @@ switch (filter('op')) {
// Selezione manuale
$id_receivers = post('receivers');
foreach ($id_receivers as $id_receiver) {
list($tipo, $id) = explode('_', $id_receiver);
[$tipo, $id] = explode('_', $id_receiver);
if ($tipo == 'anagrafica') {
$type = Anagrafica::class;
} elseif ($tipo == 'sede') {

View File

@ -168,7 +168,7 @@ switch (filter('op')) {
// Selezione manuale
$id_receivers = post('receivers');
foreach ($id_receivers as $id_receiver) {
list($tipo, $id) = explode('_', $id_receiver);
[$tipo, $id] = explode('_', $id_receiver);
if ($tipo == 'anagrafica') {
$type = Anagrafica::class;
} elseif ($tipo == 'sede') {

View File

@ -25,7 +25,7 @@ if (!empty($search)) {
include_once __DIR__.'/select.php';
$results = collect($results)->mapToGroups(function ($item, $key) {
list($tipo, $id) = explode('_', $item['id']);
[$tipo, $id] = explode('_', $item['id']);
return [$tipo => $id];
});
@ -82,7 +82,7 @@ foreach ($destinatari_filtrati as $destinatario) {
input([
'type' => 'text',
'name' => 'email',
'id' => 'email_'.rand(0, 99999),
'id' => 'email_'.random_int(0, 99999),
'readonly' => '1',
'class' => 'email-mask',
'value' => $origine->email,

View File

@ -635,7 +635,7 @@ switch (post('op')) {
}
$id_iva = ($ordine->anagrafica->idiva_vendite && (!$originale->idiva_vendita || $aliquota_articolo != 0) ? $ordine->anagrafica->idiva_vendite : $originale->idiva_vendita) ?: setting('Iva predefinita');
} else {
$id_iva = ($ordine->anagrafica->idiva_acquisti ? $ordine->anagrafica->idiva_acquisti : ($originale->idiva_vendita ? $originale->idiva_vendita : setting('Iva predefinita')));
$id_iva = ($ordine->anagrafica->idiva_acquisti ?: ($originale->idiva_vendita ?: setting('Iva predefinita')));
}
$id_anagrafica = $ordine->idanagrafica;
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');

View File

@ -32,7 +32,7 @@ use Modules\Ordini\Tipo;
$id_modulo_fatture = (new Module())->getByField('name', 'Fatture di vendita', Models\Locale::getPredefined()->id);
if (!isset($_SESSION['module_'.$id_modulo_fatture]['id_segment'])) {
$segments = Modules::getSegments($id_modulo_fatture);
$_SESSION['module_'.$id_modulo_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
$_SESSION['module_'.$id_modulo_fatture]['id_segment'] = $segments[0]['id'] ?? null;
}
$id_segment = $_SESSION['module_'.$id_modulo_fatture]['id_segment'];
$id_segment_ordini = $_SESSION['module_'.$id_module]['id_segment'];
@ -72,13 +72,9 @@ switch (post('op')) {
// Ricerca fattura per anagrafica tra le registrate
$id_sede = $raggruppamento == 'sede' ? $documento_import->idsede : 0;
if ($raggruppamento == 'sede') {
$fattura = $documenti->first(function ($item, $key) use ($id_anagrafica, $id_sede) {
return $item->anagrafica->id == $id_anagrafica && $item->idsede_destinazione == $id_sede;
});
$fattura = $documenti->first(fn($item, $key) => $item->anagrafica->id == $id_anagrafica && $item->idsede_destinazione == $id_sede);
} else {
$fattura = $documenti->first(function ($item, $key) use ($id_anagrafica) {
return $item->anagrafica->id == $id_anagrafica;
});
$fattura = $documenti->first(fn($item, $key) => $item->anagrafica->id == $id_anagrafica);
}
// Ricerca fattura per anagrafica se l'impostazione di accodamento è selezionata
@ -118,7 +114,7 @@ switch (post('op')) {
// Fix per idconto righe fattura
$articolo = ArticoloOriginale::find($copia->idarticolo);
$copia->id_conto = ($articolo->idconto_vendita ? $articolo->idconto_vendita : $idconto);
$copia->id_conto = ($articolo->idconto_vendita ?: $idconto);
// Aggiornamento seriali dalla riga dell'ordine
if ($copia->isArticolo()) {

View File

@ -380,8 +380,8 @@ foreach ($materiali_art as $key => $materiali_array1) {
foreach ($materiali_array1 as $materiali_array2) {
foreach ($materiali_array2 as $materiale) {
$margine = $materiale['ricavo'] - $materiale['costo'];
$margine_prc = (int) (1 - ($materiale['costo'] / ($materiale['ricavo'] ? $materiale['ricavo'] : 1))) * 100;
$ricarico_prc = ($materiale['ricavo'] && $materiale['costo']) ? (int) ((($materiale['ricavo'] / ($materiale['costo'] ? $materiale['costo'] : 1)) - 1) * 100) : 100;
$margine_prc = (int) (1 - ($materiale['costo'] / ($materiale['ricavo'] ?: 1))) * 100;
$ricarico_prc = ($materiale['ricavo'] && $materiale['costo']) ? (int) ((($materiale['ricavo'] / ($materiale['costo'] ?: 1)) - 1) * 100) : 100;
echo '
<tr>
<td>'.Modules::link('Articoli', $materiale['id'], $key).'</td>
@ -398,8 +398,8 @@ foreach ($materiali_art as $key => $materiali_array1) {
ksort($materiali_righe);
foreach ($materiali_righe as $key => $materiale) {
$margine = $materiale['ricavo'] - $materiale['costo'];
$margine_prc = (int) (1 - ($materiale['costo'] / ($materiale['ricavo'] ? $materiale['ricavo'] : 1))) * 100;
$ricarico_prc = ($materiale['ricavo'] && $materiale['costo']) ? (int) ((($materiale['ricavo'] / ($materiale['costo'] ? $materiale['costo'] : 1)) - 1) * 100) : 100;
$margine_prc = (int) (1 - ($materiale['costo'] / ($materiale['ricavo'] ?: 1))) * 100;
$ricarico_prc = ($materiale['ricavo'] && $materiale['costo']) ? (int) ((($materiale['ricavo'] / ($materiale['costo'] ?: 1)) - 1) * 100) : 100;
echo '
<tr>
<td>'.$key.'</td>

View File

@ -72,7 +72,7 @@ class Pagamento extends Model
if ($rata->num_giorni % 30 == 0) {
$date->addMonthsNoOverflow(round($rata->num_giorni / 30));
} else {
$date->addDay($rata->num_giorni);
$date->addDay();
}
}
@ -82,7 +82,7 @@ class Pagamento extends Model
if ($rata->num_giorni % 30 == 0) {
$date->addMonthsNoOverflow(round($rata->num_giorni / 30));
} else {
$date->addDay($rata->num_giorni);
$date->addDay();
}
$date->modify('last day of this month');
@ -102,7 +102,7 @@ class Pagamento extends Model
if ($rata->num_giorni % 30 == 0) {
$date->addMonthsNoOverflow(round($rata->num_giorni / 30));
} else {
$date->addDay($rata->num_giorni);
$date->addDay();
}
// Individuazione giorno effettivo (se il giorno indicato è eccessivamente grande, viene preso il massimo possibile)
@ -118,7 +118,7 @@ class Pagamento extends Model
$regola_pagamento = database()->selectOne('an_pagamenti_anagrafiche', '*', ['idanagrafica' => $id_anagrafica, 'mese' => $date->format('m')]);
if (!empty($regola_pagamento)) {
$date->modify('last day of this month');
$date->addDay($regola_pagamento->giorno_fisso);
$date->addDay();
}
// Conversione della data in stringa standard

View File

@ -31,7 +31,7 @@ use Modules\Preventivi\Stato as StatoPreventivo;
$id_fatture = (new Module())->getByField('name', 'Fatture di vendita', Models\Locale::getPredefined()->id);
if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) {
$segments = Modules::getSegments($id_fatture);
$_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
$_SESSION['module_'.$id_fatture]['id_segment'] = $segments[0]['id'] ?? null;
}
$id_segment = $_SESSION['module_'.$id_fatture]['id_segment'];
$idtipodocumento = $dbo->selectOne('co_tipidocumento', ['id'], [
@ -73,13 +73,9 @@ switch (post('op')) {
// Ricerca fattura per anagrafica tra le registrate
$id_sede = $raggruppamento == 'sede' ? $documento_import->idsede : 0;
if ($raggruppamento == 'sede') {
$fattura = $documenti->first(function ($item, $key) use ($id_anagrafica, $id_sede) {
return $item->anagrafica->id == $id_anagrafica && $item->idsede_destinazione == $id_sede;
});
$fattura = $documenti->first(fn($item, $key) => $item->anagrafica->id == $id_anagrafica && $item->idsede_destinazione == $id_sede);
} else {
$fattura = $documenti->first(function ($item, $key) use ($id_anagrafica) {
return $item->anagrafica->id == $id_anagrafica;
});
$fattura = $documenti->first(fn($item, $key) => $item->anagrafica->id == $id_anagrafica);
}
// Ricerca fattura per anagrafica se l'impostazione di accodamento è selezionata
@ -119,7 +115,7 @@ switch (post('op')) {
// Fix per idconto righe fattura
$articolo = ArticoloOriginale::find($copia->idarticolo);
$copia->idconto = ($articolo->idconto_vendita ? $articolo->idconto_vendita : $idconto);
$copia->idconto = ($articolo->idconto_vendita ?: $idconto);
// Aggiornamento seriali dalla riga dell'ordine
if ($copia->isArticolo()) {

View File

@ -46,8 +46,8 @@ function renderRiga($id, $riga, &$totale_dare, &$totale_avere)
</td>
</tr>';
$totale_dare += ($riga['dare'] ? $riga['dare'] : 0);
$totale_avere += ($riga['avere'] ? $riga['avere'] : 0);
$totale_dare += ($riga['dare'] ?: 0);
$totale_avere += ($riga['avere'] ?: 0);
}
function renderTabella($nome, $righe, &$totale_dare, &$totale_avere)
@ -78,7 +78,7 @@ function renderTabella($nome, $righe, &$totale_dare, &$totale_avere)
<tbody>';
foreach ($righe as $riga) {
renderRiga($counter++, $riga, $totale_dare, $totale_avere);
renderRiga($counter++, $riga);
}
// Totale per controllare sbilancio
@ -169,9 +169,7 @@ renderRiga('-id-',
[
'iddocumento' => '-id_documento-',
'id_scadenza' => '-id_scadenza-',
],
$totale_dare,
$totale_avere
]
);
echo '

View File

@ -393,7 +393,7 @@ foreach ($tipi as $tipo) {
$interventi = Stats::monthly($interventi, $start, $end);
// Random color
$background = '#'.dechex(rand(256, 16777215));
$background = '#'.dechex(random_int(256, 16777215));
$dataset .= '{
label: "'.$tipo['descrizione'].'",
@ -449,7 +449,7 @@ foreach ($tipi as $tipo) {
$interventi = Stats::monthly($interventi, $start, $end);
// Random color
$background = '#'.dechex(rand(256, 16777215));
$background = '#'.dechex(random_int(256, 16777215));
$dataset .= '{
label: "'.$tipo['descrizione'].'",
@ -523,7 +523,7 @@ foreach ($tecnici as $tecnico) {
$background = strtoupper($tecnico['colore']);
if (empty($background) || $background == '#FFFFFF') {
// Random color
$background = '#'.dechex(rand(256, 16777215));
$background = '#'.dechex(random_int(256, 16777215));
}
$dataset .= '{
@ -674,7 +674,7 @@ ORDER BY
YEAR(`an_anagrafiche`.`created_at`) ASC, MONTH(`an_anagrafiche`.`created_at`) ASC');
// Random color
$background = '#'.dechex(rand(256, 16777215));
$background = '#'.dechex(random_int(256, 16777215));
$dataset .= '{
label: "'.tr('Nuovi clienti').'",
@ -685,7 +685,7 @@ $dataset .= '{
},';
// Random color
$background = '#'.dechex(rand(256, 16777215));
$background = '#'.dechex(random_int(256, 16777215));
$dataset .= '{
label: "'.tr('Clienti acquisiti').'",
@ -696,7 +696,7 @@ $dataset .= '{
},';
// Random color
$background = '#'.dechex(rand(256, 16777215));
$background = '#'.dechex(random_int(256, 16777215));
$dataset .= '{
label: "'.tr('Nuovi fornitori').'",

View File

@ -151,7 +151,7 @@ if (Services::isEnabled()) {
echo '
<tr class="'.($scadenza->lessThan(Carbon::now()) ? 'danger' : ($scadenza->lessThan($limite_scadenze) ? 'warning' : '')).'">
<td>'.$servizio['name'].'</td>
<td>'.(($servizio['credits'] < 100 && $servizio['credits'] !== null) ? '<b><i class="fa fa-warning text-warning" ></i> ' : '').(($servizio['credits'] !== null) ? $servizio['credits'] : '-').(($servizio['credits'] < 100 && $servizio['credits'] !== null) ? '</b>' : '').'</td>
<td>'.(($servizio['credits'] < 100 && $servizio['credits'] !== null) ? '<b><i class="fa fa-warning text-warning" ></i> ' : '').($servizio['credits'] ?? '-').(($servizio['credits'] < 100 && $servizio['credits'] !== null) ? '</b>' : '').'</td>
<td>'.((Carbon::now()->diffInDays($scadenza, false) < $days && $scadenza) ? '<b><i class="fa fa-warning text-warning" ></i> ' : '').dateFormat($scadenza).' ('.$scadenza->diffForHumans().')'.((Carbon::now()->diffInDays($scadenza, false) < $days && $scadenza) ? '</b>' : '').'</td>
</tr>';
}

View File

@ -278,9 +278,7 @@ function renderElencoModuli($elenco, $depth = 0)
->where('zz_plugins_lang.id_lang', '=', Models\Locale::getDefault()->id);
})
->where('idmodule_to', '=', $record['id'])
->get()->map(function ($i) {
return (array) $i;
})->toArray();
->get()->map(fn($i) => (array) $i)->toArray();
$elenco_plugin = renderElencoModuli($plugins, $depth + 1);
}

View File

@ -19,4 +19,4 @@
include_once __DIR__.'/../../core.php';
echo '{( "name": "filelist_and_upload", "id":"'.rand(1, 999).'", "id_record": "'.get('id').'", "id_module": "'.$id_module.'", "id_plugin": "'.$id_plugin.'" )}';
echo '{( "name": "filelist_and_upload", "id":"'.random_int(1, 999).'", "id_record": "'.get('id').'", "id_module": "'.$id_module.'", "id_plugin": "'.$id_plugin.'" )}';

View File

@ -282,7 +282,7 @@ class FatturaElettronica
$json = json_decode($response->getBody(), true);
return isset($json['data'][0]['OU'][0]['cod_uni_ou']) ? $json['data'][0]['OU'][0]['cod_uni_ou'] : null;
return $json['data'][0]['OU'][0]['cod_uni_ou'] ?? null;
}
public static function getDirectory()
@ -1146,7 +1146,7 @@ class FatturaElettronica
*/
protected static function getDatiOrdineAcquisto($fattura, $lista = null)
{
$lista = isset($lista) ? $lista : $fattura->getOrdiniAcquisto();
$lista ??= $fattura->getOrdiniAcquisto();
$result = [];
foreach ($lista as $element) {
@ -1387,9 +1387,7 @@ class FatturaElettronica
$result = [];
// Righe del documento
$iva_descrizioni = $righe->first(function ($item, $key) {
return $item->aliquota != null;
})->aliquota;
$iva_descrizioni = $righe->first(fn($item, $key) => $item->aliquota != null)->aliquota;
$order = 1;
foreach ($righe as $idx => $riga) {
@ -1558,11 +1556,7 @@ class FatturaElettronica
}
// Riepiloghi per IVA per percentuale
$riepiloghi_percentuale = $righe->filter(function ($item, $key) {
return $item->aliquota != null && $item->aliquota->codice_natura_fe == null;
})->groupBy(function ($item, $key) {
return $item->aliquota->percentuale;
});
$riepiloghi_percentuale = $righe->filter(fn($item, $key) => $item->aliquota != null && $item->aliquota->codice_natura_fe == null)->groupBy(fn($item, $key) => $item->aliquota->percentuale);
foreach ($riepiloghi_percentuale as $riepilogo) {
$totale = round($riepilogo->sum('totale_imponibile') + $riepilogo->sum('rivalsa_inps'), 2);
$imposta = round($riepilogo->sum('iva') + $riepilogo->sum('iva_rivalsa_inps'), 2);
@ -1594,11 +1588,7 @@ class FatturaElettronica
}
// Riepiloghi per IVA per natura
$riepiloghi_natura = $righe->filter(function ($item, $key) {
return $item->aliquota != null && $item->aliquota->codice_natura_fe != null;
})->groupBy(function ($item, $key) {
return $item->aliquota->codice_natura_fe;
});
$riepiloghi_natura = $righe->filter(fn($item, $key) => $item->aliquota != null && $item->aliquota->codice_natura_fe != null)->groupBy(fn($item, $key) => $item->aliquota->codice_natura_fe);
foreach ($riepiloghi_natura as $riepilogo) {
$totale = round($riepilogo->sum('totale_imponibile') + $riepilogo->sum('rivalsa_inps'), 2);
$imposta = round($riepilogo->sum('iva') + $riepilogo->sum('iva_rivalsa_inps'), 2);

View File

@ -596,7 +596,7 @@ class Validator
}
} elseif (!is_null($input)) {
$info = static::$validators[$key];
$size = isset($info['size']) ? $info['size'] : null;
$size = $info['size'] ?? null;
$output = $input;

View File

@ -254,34 +254,20 @@ switch (filter('op')) {
}
// Ricerca del tipo di documento più utilizzato
$tipi = $fatture->groupBy(function ($item, $key) {
return $item->tipo->id;
})->transform(function ($item, $key) {
return $item->count();
});
$tipi = $fatture->groupBy(fn($item, $key) => $item->tipo->id)->transform(fn($item, $key) => $item->count());
$id_tipo = $tipi->sort()->keys()->last();
// Ricerca del conto più utilizzato
$conti = $righe->groupBy(function ($item, $key) {
return $item->idconto;
})->transform(function ($item, $key) {
return $item->count();
});
$conti = $righe->groupBy(fn($item, $key) => $item->idconto)->transform(fn($item, $key) => $item->count());
$id_conto = $conti->sort()->keys()->last();
$conto = $database->fetchOne('SELECT * FROM co_pianodeiconti3 WHERE id = '.prepare($id_conto));
// Ricerca dell'IVA più utilizzata secondo percentuali
$iva = [];
$percentuali_iva = $righe->groupBy(function ($item, $key) {
return $item->aliquota->percentuale;
});
$percentuali_iva = $righe->groupBy(fn($item, $key) => $item->aliquota->percentuale);
foreach ($percentuali_iva as $key => $values) {
$aliquote = $values->mapToGroups(function ($item, $key) {
return [$item->aliquota->id => $item->aliquota];
});
$id_aliquota = $aliquote->map(function ($item, $key) {
return $item->count();
})->sort()->keys()->last();
$aliquote = $values->mapToGroups(fn($item, $key) => [$item->aliquota->id => $item->aliquota]);
$id_aliquota = $aliquote->map(fn($item, $key) => $item->count())->sort()->keys()->last();
$aliquota = $aliquote[$id_aliquota]->first();
$iva[$key] = [

View File

@ -143,7 +143,7 @@ if (in_array($dati_generali['TipoDocumento'], ['TD16', 'TD17', 'TD18', 'TD19', '
}
// Individuazione metodo di pagamento di base
$metodi = isset($pagamenti[0]['DettaglioPagamento']) ? $pagamenti[0]['DettaglioPagamento'] : [];
$metodi = $pagamenti[0]['DettaglioPagamento'] ?? [];
$metodi = isset($metodi[0]) ? $metodi : [$metodi];
$codice_modalita_pagamento = $metodi[0]['ModalitaPagamento'];

View File

@ -87,9 +87,7 @@ class FatturaElettronica
$plugins = $module->plugins;
if (!empty($plugins)) {
$plugin = $plugins->first(function ($value, $key) {
return $value->getTranslation('name') == 'Fatturazione Elettronica';
});
$plugin = $plugins->first(fn($value, $key) => $value->getTranslation('name') == 'Fatturazione Elettronica');
self::$directory = base_dir().'/'.$plugin->upload_directory;
}

View File

@ -263,7 +263,7 @@ class FatturaOrdinaria extends FatturaElettronica
$has_serial_riferimento = false;
if (!empty($tipi_riferimenti[$key]) && is_subclass_of($tipi_riferimenti[$key], Component::class) && !empty($id_riferimenti[$key])) {
$riga_origine = ($tipi_riferimenti[$key])::find($id_riferimenti[$key]);
list($riferimento_precedente, $nuovo_riferimento) = $obj->impostaOrigine($riga_origine);
[$riferimento_precedente, $nuovo_riferimento] = $obj->impostaOrigine($riga_origine);
// Correzione della descrizione
$obj->descrizione = str_replace($riferimento_precedente, '', $obj->descrizione);

View File

@ -50,9 +50,7 @@ class InvoiceHook extends CachedManager
if (!empty($plugins)) {
$notify = !empty($count);
$plugin = $plugins->first(function ($value, $key) {
return $value->getTranslation('name') == 'Fatturazione Elettronica';
});
$plugin = $plugins->first(fn($value, $key) => $value->getTranslation('name') == 'Fatturazione Elettronica');
$link = base_path().'/controller.php?id_module='.$module->id.'#tab_'.$plugin->id;
}

View File

@ -50,9 +50,7 @@ echo '
<h4>'.tr('Elenco fornitori').'</h4>';
$dettagli_fornitori = DettaglioFornitore::where('id_articolo', $id_record)->get()
->mapToGroups(function ($item, $key) {
return [$item->id_fornitore => $item];
});
->mapToGroups(fn($item, $key) => [$item->id_fornitore => $item]);
$prezzi_fornitori = DettaglioPrezzo::where('id_articolo', $id_articolo)
->where('dir', 'uscita')
->get()

View File

@ -131,7 +131,7 @@ switch ($operazione) {
$riga->setPrezzoUnitario($prezzo_unitario, $r->idiva);
$riga->setSconto($r->tipo_sconto == 'PRC' ? $r->sconto_percentuale : $r->sconto_unitario, $r->tipo_sconto);
$riga->qta = $qta_riga;
$riga->setProvvigione($r->provvigione_percentuale ? $r->provvigione_percentuale : $r->provvigione_unitaria, $r->tipo_provvigione);
$riga->setProvvigione($r->provvigione_percentuale ?: $r->provvigione_unitaria, $r->tipo_provvigione);
$riga->idpianificazione = $pianificazioni[$rata];
$riga->save();

View File

@ -81,9 +81,7 @@ switch ($action) {
->whereYear('co_fatturazione_contratti.data_scadenza', $year)
->get();
$raggruppamenti = $pianificazioni->groupBy(function ($item) {
return ucfirst($item->data_scadenza->format('m'));
});
$raggruppamenti = $pianificazioni->groupBy(fn($item) => ucfirst($item->data_scadenza->format('m')));
$ret = [];
foreach ($raggruppamenti as $i => $item) {

View File

@ -86,9 +86,7 @@ class Pianificazione extends Document
$p = $this;
return $pianificazioni->search(function ($item) use ($p) {
return $item->id == $p->id;
}) + 1;
return $pianificazioni->search(fn($item) => $item->id == $p->id) + 1;
}
public function getRighe()
@ -98,15 +96,11 @@ class Pianificazione extends Document
$numero_righe = $righe->count() / $pianificazioni->count();
$p = $this;
$index = $pianificazioni->search(function ($item) use ($p) {
return $item->id == $p->id;
});
$index = $pianificazioni->search(fn($item) => $item->id == $p->id);
$skip = $pianificazioni->count();
return $righe->filter(function ($value, $key) use ($skip, $index) {
return $key % $skip == $index;
});
return $righe->filter(fn($value, $key) => $key % $skip == $index);
}
public function articoli()

View File

@ -102,9 +102,7 @@ switch ($operazione) {
$promemoria_contratto = $contratto->promemoria()
->where('idtipointervento', $promemoria_originale->tipo->id)
->get()
->groupBy(function ($item) {
return $item->data_richiesta->toDateString();
});
->groupBy(fn($item) => $item->data_richiesta->toDateString());
$date_preimpostate = $promemoria_contratto->keys()->toArray();

View File

@ -38,9 +38,7 @@ if ($elenco_promemoria->isEmpty()) {
return;
}
$raggruppamenti = $elenco_promemoria->groupBy(function ($item) {
return $item->data_richiesta->format('Y-m');
});
$raggruppamenti = $elenco_promemoria->groupBy(fn($item) => $item->data_richiesta->format('Y-m'));
$counter = 0;
foreach ($raggruppamenti as $mese => $raggruppamento) {

View File

@ -43,9 +43,7 @@ switch (filter('op')) {
$descrizione = 'Fattura num. '.$documento->numero_esterno ?: $documento->numero;
// Individuazione altre scadenze del documento
$scadenze_documento = $documento->scadenze->sortBy('scadenza');
$pos = $scadenze_documento->search(function ($item, $key) use ($scadenza) {
return $item->id == $scadenza->id;
});
$pos = $scadenze_documento->search(fn($item, $key) => $item->id == $scadenza->id);
// Generazione della descrizione del pagamento
$descrizione .= tr(' pag _NUM_/_TOT_', [

View File

@ -75,7 +75,7 @@ class CbiSepa
}
$credtm = date('Y-m-d\TH:i:s');
$msgid = dechex(rand(100, 999).date('siHdmY')).'-';
$msgid = dechex(random_int(100, 999).date('siHdmY')).'-';
$content = file_get_contents(base_dir().'/plugins/presentazioni_bancarie/template/template_CBIPaymentRequest.xml');

View File

@ -85,7 +85,7 @@ abstract class BaseRecord implements RecordInterface
public function get(string $name): ?string
{
return isset($this->dati[$name]) ? $this->dati[$name] : null;
return $this->dati[$name] ?? null;
}
public function set(string $name, ?string $value): void
@ -99,7 +99,7 @@ abstract class BaseRecord implements RecordInterface
// Pad automatico sulla base del tipo
if ($record['tipo'] == 'string') {
$value = $this->padString($value, $record['dimensione'], isset($record['forzaPadding']) ? $record['forzaPadding'] : STR_PAD_RIGHT);
$value = $this->padString($value, $record['dimensione'], $record['forzaPadding'] ?? STR_PAD_RIGHT);
} elseif ($record['tipo'] == 'numeric') {
$value = $this->padNumber($value, $record['dimensione']);
} elseif ($record['tipo'] == 'constant') {

View File

@ -93,18 +93,14 @@ $totale_ddt_uscita = $ddt_uscita->sum('totale_imponibile');
$segmenti = $dbo->select('zz_segments', 'id', [], ['autofatture' => 0]);
$fatture_vendita = Fattura::whereBetween('data', [$start, $end])
->where('idanagrafica', $id_record)
->whereHas('tipo', function ($query) {
return $query->where('co_tipidocumento.dir', '=', 'entrata')
->where('co_tipidocumento.reversed', '=', 0);
})
->whereHas('tipo', fn($query) => $query->where('co_tipidocumento.dir', '=', 'entrata')
->where('co_tipidocumento.reversed', '=', 0))
->whereIn('id_segment', array_column($segmenti, 'id'))
->get();
$note_credito = Fattura::whereBetween('data', [$start, $end])
->where('idanagrafica', $id_record)
->whereHas('tipo', function ($query) {
return $query->where('co_tipidocumento.dir', '=', 'entrata')
->where('co_tipidocumento.reversed', '=', 1);
})
->whereHas('tipo', fn($query) => $query->where('co_tipidocumento.dir', '=', 'entrata')
->where('co_tipidocumento.reversed', '=', 1))
->get();
$totale_fatture_vendita = $fatture_vendita->sum('totale_imponibile') - $note_credito->sum('totale_imponibile');

28
rector.php Normal file
View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/api',
__DIR__ . '/config',
__DIR__ . '/include',
__DIR__ . '/lib',
__DIR__ . '/modules',
__DIR__ . '/plugins',
__DIR__ . '/src',
__DIR__ . '/update',
]);
// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81
]);
};

View File

@ -70,7 +70,7 @@ class AJAX
}
}
$results = isset($results) ? $results : [];
$results ??= [];
$total = array_key_exists('recordsFiltered', $results) ? $results['recordsFiltered'] : count($results);
$list = array_key_exists('results', $results) ? $results['results'] : $results;
@ -262,7 +262,7 @@ class AJAX
$results = self::selectResults($query, $where, $filter, $search_fields, $limit, $custom);
}
return isset($results) ? $results : null;
return $results ?? null;
}
/**

View File

@ -188,9 +188,7 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
protected function mapModifiedRecords($records)
{
if ($records instanceof Collection) {
return $records->mapToGroups(function ($item, $key) {
return [$item['id'] => $item];
})->toArray();
return $records->mapToGroups(fn($item, $key) => [$item['id'] => $item])->toArray();
}
return array_reduce($records, function ($accumulator, $item) {

View File

@ -85,9 +85,7 @@ class Services
{
return self::getServiziAttivi()
->flatten(1)
->filter(function ($item) use ($limite_scadenze) {
return isset($item['data_conclusione']) && Carbon::parse($item['expiration_at'])->greaterThan(Carbon::now()) && Carbon::parse($item['data_conclusione'])->lessThan($limite_scadenze);
});
->filter(fn($item) => isset($item['data_conclusione']) && Carbon::parse($item['expiration_at'])->greaterThan(Carbon::now()) && Carbon::parse($item['data_conclusione'])->lessThan($limite_scadenze));
}
/**
@ -99,9 +97,7 @@ class Services
{
return self::getServiziAttivi()
->flatten(1)
->filter(function ($item) {
return isset($item['data_conclusione']) && Carbon::parse($item['data_conclusione'])->lessThan(Carbon::now());
});
->filter(fn($item) => isset($item['data_conclusione']) && Carbon::parse($item['data_conclusione'])->lessThan(Carbon::now()));
}
/**
@ -121,9 +117,7 @@ class Services
*/
public static function verificaRisorsaAttiva($servizio)
{
return self::isEnabled() && self::getRisorseAttive()->search(function ($item) use ($servizio) {
return $item['name'] == $servizio;
}) !== false;
return self::isEnabled() && self::getRisorseAttive()->search(fn($item) => $item['name'] == $servizio) !== false;
}
/**
@ -136,10 +130,8 @@ class Services
public static function getRisorseInScadenza($limite_scadenze)
{
return self::getRisorseAttive()
->filter(function ($item) use ($limite_scadenze) {
return (isset($item['expiration_at']) && Carbon::parse($item['expiration_at'])->greaterThan(Carbon::now()) && Carbon::parse($item['expiration_at'])->lessThan($limite_scadenze))
|| (isset($item['credits']) && $item['credits'] < 100);
});
->filter(fn($item) => (isset($item['expiration_at']) && Carbon::parse($item['expiration_at'])->greaterThan(Carbon::now()) && Carbon::parse($item['expiration_at'])->lessThan($limite_scadenze))
|| (isset($item['credits']) && $item['credits'] < 100));
}
/**
@ -150,10 +142,8 @@ class Services
public static function getRisorseScadute()
{
return self::getRisorseAttive()
->filter(function ($item) {
return (isset($item['expiration_at']) && Carbon::parse($item['expiration_at'])->lessThan(Carbon::now()))
|| (isset($item['credits']) && $item['credits'] < 0);
});
->filter(fn($item) => (isset($item['expiration_at']) && Carbon::parse($item['expiration_at'])->lessThan(Carbon::now()))
|| (isset($item['credits']) && $item['credits'] < 0));
}
/**

View File

@ -89,7 +89,7 @@ class App
$result = array_merge($defaultConfig, $config);
// Operazioni di normalizzazione sulla configurazione
$result['debug'] = isset(self::$config['debug']) ? self::$config['debug'] : !empty($result['debug']);
$result['debug'] = self::$config['debug'] ?? !empty($result['debug']);
$result['lang'] = $result['lang'] == 'it' ? 'it_IT' : $result['lang'];
self::$config = $result;

View File

@ -116,7 +116,7 @@ abstract class Component extends Model
*/
public function setQtaAttribute($value)
{
list($qta, $diff) = $this->parseQta($value);
[$qta, $diff] = $this->parseQta($value);
$this->attributes['qta'] = $qta;
// Aggiornamento della quantità evasa di origine
@ -227,7 +227,7 @@ abstract class Component extends Model
$model->original_type = $this->original_type;
// Aggiornamento dei riferimenti
list($riferimento_precedente, $nuovo_riferimento) = $model->impostaOrigine($this);
[$riferimento_precedente, $nuovo_riferimento] = $model->impostaOrigine($this);
// Correzione della descrizione
$attributes['descrizione'] = str_replace($riferimento_precedente, '', $attributes['descrizione']);

View File

@ -67,13 +67,7 @@ abstract class Document extends Model implements ReferenceInterface, DocumentInt
->get(),
])->flatten();
return $riferimenti->reject(function ($item) {
return empty($item->original_document_type);
})->unique(function ($item) {
return $item->original_document_type.'|'.$item->original_document_id;
})->mapToGroups(function ($item) {
return [$item->original_document_type => ($item->original_document_type)::find($item->original_document_id)];
});
return $riferimenti->reject(fn($item) => empty($item->original_document_type))->unique(fn($item) => $item->original_document_type.'|'.$item->original_document_id)->mapToGroups(fn($item) => [$item->original_document_type => ($item->original_document_type)::find($item->original_document_id)]);
}
/**
@ -85,9 +79,7 @@ abstract class Document extends Model implements ReferenceInterface, DocumentInt
{
$results = $this->mergeCollections($this->descrizioni, $this->righe, $this->articoli, $this->sconti);
return $results->sortBy(function ($item) {
return [$item->order, $item->id];
});
return $results->sortBy(fn($item) => [$item->order, $item->id]);
}
/**
@ -97,9 +89,7 @@ abstract class Document extends Model implements ReferenceInterface, DocumentInt
{
$righe = $this->getRighe();
return $righe->first(function ($item) use ($type, $id) {
return $item instanceof $type && $item->id == $id;
});
return $righe->first(fn($item) => $item instanceof $type && $item->id == $id);
}
/**

View File

@ -122,7 +122,7 @@ class Database extends Util\Singleton
*/
public static function getConnection($new = false, $data = [])
{
$class = get_called_class();
$class = static::class;
if (empty(parent::$instance[$class]) || !parent::$instance[$class]->isConnected() || $new) {
$config = App::getConfig();
@ -345,11 +345,7 @@ class Database extends Util\Singleton
$result = $this->fetchArray($query, $parameters);
if (isset($result[0])) {
return $result[0];
}
return $result;
return $result[0] ?? $result;
}
/**

View File

@ -55,9 +55,7 @@ abstract class CSVExporter implements ExporterInterface
public function setHeader()
{
$fields = $this->getAvailableFields();
$header = array_map(function ($item) {
return $item['label'];
}, $fields);
$header = array_map(fn($item) => $item['label'], $fields);
return $this->csv->insertOne($header);
}

View File

@ -45,7 +45,7 @@ class Filter
$value = null;
if (empty($method)) {
$value = (self::post($property, $raw) !== null) ? self::post($property, $raw) : self::get($property, $raw);
$value = self::post($property, $raw) ?? self::get($property, $raw);
} elseif (strtolower($method) == 'post') {
$value = self::post($property, $raw);
} elseif (strtolower($method) == 'get') {

View File

@ -401,7 +401,7 @@ class HTMLBuilder
// Sostituzione delle variabili $nome$ col relativo valore da database
elseif (is_string($json[$key]) && preg_match_all('/\$([a-z0-9\_]+)\$/i', $json[$key], $m)) {
for ($i = 0; $i < count($m[0]); ++$i) {
$record = isset(self::$record[$m[1][$i]]) ? self::$record[$m[1][$i]] : '';
$record = self::$record[$m[1][$i]] ?? '';
$json[$key] = str_replace($m[0][$i], prepareToField($record), $json[$key]);
}
}
@ -434,7 +434,7 @@ class HTMLBuilder
$values['name'] = str_replace(' ', '_', $values['name']);
$values['id'] = empty($values['id']) ? $values['name'] : $values['id'];
$values['id'] = str_replace(['[', ']', ' '], ['', '', '_'], $values['id']);
$values['value'] = isset($values['value']) ? $values['value'] : '';
$values['value'] ??= '';
// Gestione delle classi CSS
$values['class'] = [];

View File

@ -66,7 +66,7 @@ class ChoicesHandler implements HandlerInterface
}
// Gestione dei placeholder
$values['placeholder'] = isset($values['placeholder']) ? $values['placeholder'] : $values['label'];
$values['placeholder'] ??= $values['label'];
// Gestione valori custom
if (!empty($values['values'])) {

View File

@ -289,7 +289,7 @@ class DefaultHandler implements HandlerInterface
$values['decimals'] = $decimals;
// Se non è previsto un valore minimo, lo imposta a 1
$values['min-value'] = isset($values['min-value']) ? $values['min-value'] : '0.'.str_repeat('0', $decimals - 1).'1';
$values['min-value'] ??= '0.'.str_repeat('0', $decimals - 1).'1';
}
}

View File

@ -32,9 +32,9 @@ class SelectHandler implements HandlerInterface
{
$values['class'][] = 'openstamanager-input';
$values['class'][] = 'select-input';
$values['data-select2-id'][] = $values['id'].'_'.rand(0, 999);
$values['data-select2-id'][] = $values['id'].'_'.random_int(0, 999);
$source = isset($values['ajax-source']) ? $values['ajax-source'] : (isset($values['select-source']) ? $values['select-source'] : null);
$source = $values['ajax-source'] ?? $values['select-source'] ?? null;
// Individuazione della classe per la corretta gestione JavaScript
$values['class'][] = !empty($source) ? 'superselectajax' : 'superselect';
@ -71,7 +71,7 @@ class SelectHandler implements HandlerInterface
unset($values['select-source']);
// Informazioni aggiuntive per il select
$infos = isset($values['select-options']) ? $values['select-options'] : [];
$infos = $values['select-options'] ?? [];
$values['data-select-options'] = json_encode($infos);
unset($values['select-options']);
@ -106,9 +106,9 @@ class SelectHandler implements HandlerInterface
// Impostazione del placeholder
$values['placeholder'] = !empty($values['placeholder']) ? $values['placeholder'] : tr("Seleziona un'opzione");
$values['data-placeholder'] = isset($values['placeholder']) ? $values['placeholder'] : null;
$values['data-placeholder'] = $values['placeholder'] ?? null;
$values['data-maximum-selection-length'] = isset($values['maximum-selection-length']) ? $values['maximum-selection-length'] : null;
$values['data-maximum-selection-length'] = $values['maximum-selection-length'] ?? null;
unset($values['values']);

View File

@ -30,7 +30,7 @@ class ButtonManager implements ManagerInterface
{
public function manage($options)
{
$options['parameters'] = isset($options['parameters']) ? $options['parameters'] : null;
$options['parameters'] ??= null;
// Impostazione id HTML automatico
if (empty($options['html_id'])) {
@ -89,10 +89,10 @@ class ButtonManager implements ManagerInterface
{
$info = $this->getInfo($options);
$class = isset($options['class']) ? $options['class'] : 'btn-info';
$class = $options['class'] ?? 'btn-info';
$class = !empty($class) ? ' class="btn '.$class.'" ' : '';
$title = isset($options['label']) ? $options['label'] : $info['title'];
$title = $options['label'] ?? $info['title'];
$icon = !empty($options['icon']) ? $options['icon'] : $info['icon'];
$icon = str_replace('|default|', $info['icon'], $icon);
@ -140,7 +140,7 @@ class ButtonManager implements ManagerInterface
$list = $this->getList($options);
$count = count($list);
$options['class'] = isset($options['class']) ? $options['class'] : 'btn-info';
$options['class'] ??= 'btn-info';
if ($count > 1) {
$result = '

View File

@ -80,7 +80,7 @@ class FieldManager implements ManagerInterface
<div class="row">';
}
$field['value'] = isset($field['value']) ? $field['value'] : '';
$field['value'] ??= '';
// Gestione valori multipli
$values = json_decode((string) $field['value'], true);

View File

@ -40,7 +40,7 @@ class FileManager implements ManagerInterface
public function manage($options)
{
$options['readonly'] = !empty($options['readonly']) ? true : false;
$options['showpanel'] = isset($options['showpanel']) ? $options['showpanel'] : true;
$options['showpanel'] ??= true;
$options['id_plugin'] = !empty($options['id_plugin']) ? $options['id_plugin'] : null;

View File

@ -106,7 +106,7 @@ class WidgetManager implements ManagerInterface
$value = null;
if (!empty($query)) {
$value = $database->fetchArray($query)[0]['dato'];
if (!preg_match('/\\d/', $value)) {
if (!preg_match('/\d/', $value) === false) {
$value = '-';
}
}

View File

@ -63,7 +63,7 @@ class HTMLWrapper implements WrapperInterface
public function after(&$values, &$extras)
{
$rand = rand(0, 99);
$rand = random_int(0, 99);
$pseudo_id = $values['id'].$rand;
$result = '';
@ -113,8 +113,8 @@ class HTMLWrapper implements WrapperInterface
$value = explode('|', $values['validation']);
$name = $value[0];
$id_module = isset($value[1]) ? $value[1] : '$id_module$';
$id_record = isset($value[2]) ? $value[2] : '$id_record$';
$id_module = $value[1] ?? '$id_module$';
$id_record = $value[2] ?? '$id_record$';
$result .= '
<script>
@ -293,7 +293,7 @@ class HTMLWrapper implements WrapperInterface
$value = (empty($pieces[2]) || !in_array($pieces[2], array_column($choices, 'id'))) ? $choices[0]['id'] : $pieces[2];
$result = '{[ "type": "select", "name": "tipo_'.prepareToField($values['name']).'", "id": "tipo_'.prepareToField($values['name']).'_'.rand(0, 99).'", "value": "'.prepareToField($value).'", "values": '.json_encode($choices).', "class": "no-search tipo_icon_after", "extra": "'.$extra.'", "disabled": "'.$disabled.'" ]}';
$result = '{[ "type": "select", "name": "tipo_'.prepareToField($values['name']).'", "id": "tipo_'.prepareToField($values['name']).'_'.random_int(0, 99).'", "value": "'.prepareToField($value).'", "values": '.json_encode($choices).', "class": "no-search tipo_icon_after", "extra": "'.$extra.'", "disabled": "'.$disabled.'" ]}';
$result = \HTMLBuilder\HTMLBuilder::replace($result);

View File

@ -143,7 +143,7 @@ abstract class CSVImporter implements ImporterInterface
// Interpretazione della riga come record
$record = [];
foreach ($row as $key => $value) {
$field = isset($associations[$key]) ? $associations[$key] : null;
$field = $associations[$key] ?? null;
if (!empty($field)) {
$record[$field] = $value;
}

View File

@ -45,9 +45,7 @@ class FileLoader extends \Symfony\Component\Translation\Loader\FileLoader
if (!empty($this->include_filename)) {
$result = array_combine(
array_map(function ($k) use ($resource, $extension) {
return basename($resource, '.'.$extension).'.'.$k;
}, array_keys($result)),
array_map(fn($k) => basename($resource, '.'.$extension).'.'.$k, array_keys($result)),
$result
);
}

View File

@ -287,7 +287,7 @@ class Formatter
return false;
}
$integer = $pieces[0];
$decimal = (isset($pieces[1])) ? $pieces[1] : null;
$decimal = $pieces[1] ?? null;
if (!empty($current['thousands'])) {
$error = true;
@ -300,7 +300,7 @@ class Formatter
}
}
$integer = strrev(implode($values));
$integer = strrev(implode('', $values));
$error = substr_count($integer, $current['thousands']);
}

View File

@ -107,9 +107,7 @@ class Module extends Model
$group = \Auth::user()->group->id;
$pivot = $this->pivot ?: $this->groups->first(function ($item) use ($group) {
return $item->id == $group;
})->pivot;
$pivot = $this->pivot ?: $this->groups->first(fn($item) => $item->id == $group)->pivot;
return $pivot->permessi ?: '-';
}

View File

@ -74,9 +74,9 @@ class Upload extends Model
$model = new static();
// Informazioni di base
$original_name = isset($source['name']) ? $source['name'] : basename($source);
$name = isset($data['name']) ? $data['name'] : $name;
$category = isset($data['category']) ? $data['category'] : $category;
$original_name = $source['name'] ?? basename($source);
$name = $data['name'] ?? $name;
$category = $data['category'] ?? $category;
// Nome e categoria dell'allegato
$model->name = !empty($name) ? $name : $original_name;

View File

@ -302,7 +302,7 @@ class EmailNotification extends PHPMailer implements NotificationInterface
protected function getTempDirectory()
{
if (!isset($this->directory)) {
$this->directory = base_dir().'/files/notifications/'.rand(0, 999);
$this->directory = base_dir().'/files/notifications/'.random_int(0, 999);
directory($this->directory);
}

View File

@ -262,7 +262,7 @@ class Prints
{
$info = self::render($print, $id_record, $directory);
return self::getPDFLink($info['path'].'?'.rand());
return self::getPDFLink($info['path'].'?'.random_int(0, mt_getrandmax()));
}
/**
@ -274,7 +274,7 @@ class Prints
*/
public static function getPDFLink($path)
{
return base_path().'/assets/dist/pdfjs/web/viewer.html?file='.base_url().'/'.ltrim(str_replace(base_dir(), '', $path.'?'.rand()), '/');
return base_path().'/assets/dist/pdfjs/web/viewer.html?file='.base_url().'/'.ltrim(str_replace(base_dir(), '', $path.'?'.random_int(0, mt_getrandmax())), '/');
}
/**

View File

@ -67,9 +67,7 @@ trait LocalPoolTrait
}
// Ricerca
$result = self::$collection->first(function ($item) use ($identifier) {
return $item->{self::$name} == $identifier || $item->{self::$id} == $identifier;
});
$result = self::$collection->first(fn($item) => $item->{self::$name} == $identifier || $item->{self::$id} == $identifier);
if (!empty($result)) {
return $result;

View File

@ -210,7 +210,7 @@ class Update
// Normalizzazione di charset e collation
self::normalizeDatabase($database->getDatabaseName());
if (class_exists('\Models\Cache')) {
if (class_exists(\Models\Cache::class)) {
Cache::find((new Cache())->getByField('name', 'Ultima versione di OpenSTAManager disponibile', Models\Locale::getPredefined()->id))->set(null);
}

View File

@ -46,8 +46,8 @@ class Autofill
{
$this->max_rows = $rows;
$this->max_additional = isset($additional) ? $additional : floor($this->max_rows - $this->max_rows / 4);
$this->max_rows_first_page = isset($first_page) ? $first_page : $rows;
$this->max_additional = $additional ?? floor($this->max_rows - $this->max_rows / 4);
$this->max_rows_first_page = $first_page ?? $rows;
}
public function count($text, $small = false)

Some files were not shown because too many files have changed in this diff Show More