diff --git a/actions.php b/actions.php index 274543a25..7cc1746de 100755 --- a/actions.php +++ b/actions.php @@ -67,7 +67,7 @@ if (filter('op') == 'aggiungi-allegato' || filter('op') == 'rimuovi-allegato') { $upload = Uploads::upload($_FILES['upload'], [ 'name' => filter('nome_allegato'), 'category' => filter('categoria'), - 'id_module' => (new Module())->getByField('title', 'Gestione documentale', Models\Locale::getPredefined()->id), + 'id_module' => Module::where('name', 'Gestione documentale')->first()->id, 'id_record' => $id_record, ]); diff --git a/cron.php b/cron.php index cd21b4180..be5e36135 100644 --- a/cron.php +++ b/cron.php @@ -61,13 +61,13 @@ $handler->setFormatter($formatter); $logger->pushHandler($handler); // Lettura della cache -$ultima_esecuzione = Cache::find((new Cache())->getByField('title', 'Ultima esecuzione del cron', Models\Locale::getPredefined()->id)); +$ultima_esecuzione = Cache::where('name', 'Ultima esecuzione del cron')->first(); $data = $ultima_esecuzione->content; -$in_esecuzione = Cache::find((new Cache())->getByField('title', 'Cron in esecuzione', Models\Locale::getPredefined()->id)); -$cron_id = Cache::find((new Cache())->getByField('title', 'ID del cron', Models\Locale::getPredefined()->id)); +$in_esecuzione = Cache::where('name', 'Cron in esecuzione')->first(); +$cron_id = Cache::where('name', 'ID del cron')->first(); -$disattiva = Cache::find((new Cache())->getByField('title', 'Disabilita cron', Models\Locale::getPredefined()->id)); +$disattiva = Cache::where('name', 'Disabilita cron')->first(); if ($disattiva->content || (in_array($_SERVER['HTTP_HOST'], ['localhost', '127.0.0.1']) && !$forza_cron_localhost)) { return; } diff --git a/editor.php b/editor.php index 42f2a2981..d54d9759f 100755 --- a/editor.php +++ b/editor.php @@ -176,7 +176,7 @@ if (empty($record) || !$has_access) { {( "name": "button", "type": "email", "id_module": "'.$id_module.'", "id_plugin": "'.$id_plugin.'", "id_record": "'.$id_record.'" )}'; - if (Module::find((new Module())->getByField('title', 'Account SMS', Models\Locale::getPredefined()->id))) { + if (Module::where('name', 'Account SMS')->first()->id) { echo ' {( "name": "button", "type": "sms", "id_module": "'.$id_module.'", "id_plugin": "'.$id_plugin.'", "id_record": "'.$id_record.'" )}'; } diff --git a/include/common/importa.php b/include/common/importa.php index 252750a59..0529b61f7 100755 --- a/include/common/importa.php +++ b/include/common/importa.php @@ -34,10 +34,10 @@ if (empty($documento)) { // Informazioni utili $dir = $documento->direzione; -$original_module = Module::find((new Module())->getByField('title', $documento->module, Models\Locale::getPredefined()->id)); +$original_module = Module::where('name', $documento->module)->first(); $name = !empty($documento_finale) ? $documento_finale->module : $options['module']; -$final_module = Module::find((new Module())->getByField('title', $name, Models\Locale::getPredefined()->id)); +$final_module = Module::where('name', $name)->first(); $id_segment = $_SESSION['module_'.$final_module->id]['id_segment']; // IVA predefinita @@ -45,8 +45,8 @@ $id_iva = $id_iva ?: setting('Iva predefinita'); $righe_totali = $documento->getRighe(); -$id_module_interventi = (new Module())->getByField('title', 'Attività', Models\Locale::getPredefined()->id); -$id_module_ordini_f = (new Module())->getByField('title', 'Ordini fornitore', Models\Locale::getPredefined()->id); +$id_module_interventi = Module::where('name', 'Interventi')->first()->id; +$id_module_ordini_f = Module::where('name', 'Ordini fornitore')->first()->id; if ($final_module->id == $id_module_interventi) { $righe = $righe_totali->where('is_descrizione', '=', 0) ->where('qta_rimanente', '>', 0); @@ -96,14 +96,14 @@ if (!empty($options['create_document'])) { '; // Opzioni aggiuntive per le Fatture - $id_module_fatt_vendita = (new Module())->getByField('title', 'Fatture di vendita', Models\Locale::getPredefined()->id); - $id_module_fatt_acquisto = (new Module())->getByField('title', 'Fatture di acquisto', Models\Locale::getPredefined()->id); - $id_module_ddt_vendita = (new Module())->getByField('title', 'Ddt in uscita', Models\Locale::getPredefined()->id); - $id_module_ddt_acquisto = (new Module())->getByField('title', 'Ddt in entrata', Models\Locale::getPredefined()->id); + $id_module_fatt_vendita = Module::where('name', 'Fatture di vendita')->first()->id; + $id_module_fatt_acquisto = Module::where('name', 'Fatture di acquisto')->first()->id; + $id_module_ddt_vendita = Module::where('name', 'Ddt di vendita')->first()->id; + $id_module_ddt_acquisto = Module::where('name', 'Ddt di acquisto')->first()->id; if (in_array($final_module->id, [$id_module_fatt_vendita, $id_module_fatt_acquisto])) { - $stato_predefinito = (new StatoFattura())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id); - $fatt_differita_acquisto = (new Tipofattura())->getByField('title', 'Fattura differita di acquisto', Models\Locale::getPredefined()->id); - $fatt_differita_vendita = (new Tipofattura())->getByField('title', 'Fattura differita di vendita', Models\Locale::getPredefined()->id); + $stato_predefinito = StatoFattura::where('name', 'Bozza')->first()->id; + $fatt_differita_acquisto = Tipofattura::where('name', 'Fattura differita di acquisto')->first()->id; + $fatt_differita_vendita = Tipofattura::where('name', 'Fattura differita di vendita')->first()->id;; if (!empty($options['reversed'])) { $idtipodocumento = database()->fetchOne('SELECT `co_tipidocumento`.`id` FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento_lang`.`id_record` = `co_tipidocumento`.`id` AND `co_tipidocumento_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `title` = "Nota di credito" AND `dir` = \''.$dir.'\'')['id']; @@ -113,8 +113,8 @@ if (!empty($options['create_document'])) { $idtipodocumento = database()->fetchOne('SELECT `co_tipidocumento`.`id` FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento_lang`.`id_record` = `co_tipidocumento`.`id` AND `co_tipidocumento_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `dir` = \''.$dir.'\' AND `predefined` = 1')['id']; } - $id_bozza = (new StatoFattura())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id); - $id_emessa = (new StatoFattura())->getByField('title', 'Emessa', Models\Locale::getPredefined()->id); + $id_bozza = StatoFattura::where('name', 'Bozza')->first()->id; + $id_emessa = StatoFattura::where('name', 'Emessa')->first()->id; echo '
{[ "type": "select", "label": "'.tr('Stato').'", "name": "id_stato", "required": 1, "values": "query=SELECT `co_statidocumento`.`id` as id, `co_statidocumento_lang`.`title` as descrizione FROM `co_statidocumento` LEFT JOIN `co_statidocumento_lang` ON (`co_statidocumento`.`id` = `co_statidocumento_lang`.`id_record` AND `co_statidocumento_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `co_statidocumento`.`id` IN ('.$id_bozza.', '.$id_emessa.')", "value": "'.$stato_predefinito.'"]} @@ -143,7 +143,7 @@ if (!empty($options['create_document'])) { // Opzioni aggiuntive per i Contratti elseif ($final_module->getTranslation('title') == 'Contratti') { - $stato_predefinito = (new StatoContratto())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id); + $stato_predefinito = StatoContratto::where('name', 'Bozza')->first()->id; echo '
@@ -153,7 +153,7 @@ if (!empty($options['create_document'])) { // Opzioni aggiuntive per i DDT elseif (in_array($final_module->getTranslation('title'), ['Ddt in uscita', 'Ddt in entrata'])) { - $stato_predefinito = (new Stato())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id); + $stato_predefinito = Stato::where('name', 'Bozza')->first()->id; echo '
@@ -161,13 +161,13 @@ if (!empty($options['create_document'])) {
- {[ "type": "select", "label": "'.tr('Causale trasporto').'", "name": "id_causale_trasporto", "required": 1, "ajax-source": "causali", "icon-after": "add|'.(new Module())->getByField('title', 'Causali', Models\Locale::getPredefined()->id).'", "help": "'.tr('Definisce la causale del trasporto').'" ]} + {[ "type": "select", "label": "'.tr('Causale trasporto').'", "name": "id_causale_trasporto", "required": 1, "ajax-source": "causali", "icon-after": "add|'.Module::where('name', 'Causali')->first()->id.'", "help": "'.tr('Definisce la causale del trasporto').'" ]}
'; } // Opzioni aggiuntive per gli Ordini elseif (in_array($final_module->getTranslation('title'), ['Ordini cliente', 'Ordini fornitore'])) { - $stato_predefinito = (new StatoOrdine())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id); + $stato_predefinito = StatoOrdine::where('name', 'Bozza')->first()->id; echo '
@@ -182,7 +182,7 @@ if (!empty($options['create_document'])) { echo '
- {[ "type": "select", "label": "'.$tipo_anagrafica.'", "name": "idanagrafica", "required": 1, "ajax-source": "'.$ajax.'", "icon-after": "add|'.(new Module())->getByField('title', 'Anagrafiche', Models\Locale::getPredefined()->id).'|tipoanagrafica='.$tipo_anagrafica.'" ]} + {[ "type": "select", "label": "'.$tipo_anagrafica.'", "name": "idanagrafica", "required": 1, "ajax-source": "'.$ajax.'", "icon-after": "add|'.Module::where('name', 'Anagrafiche')->first()->id.'|tipoanagrafica='.$tipo_anagrafica.'" ]}
'; } diff --git a/include/common/riga.php b/include/common/riga.php index fbd585da6..bc1b86489 100755 --- a/include/common/riga.php +++ b/include/common/riga.php @@ -45,7 +45,7 @@ echo ' // Unità di misura echo '
- {[ "type": "select", "label": "'.tr('Unità di misura').'", "icon-after": "add|'.(new Module())->getByField('title', 'Unità di misura', Models\Locale::getPredefined()->id).'", "name": "um", "value": "'.$result['um'].'", "ajax-source": "misure" ]} + {[ "type": "select", "label": "'.tr('Unità di misura').'", "icon-after": "add|'.Module::where('name', 'Unità di misura')->first()->id.'", "name": "um", "value": "'.$result['um'].'", "ajax-source": "misure" ]}
'; // Unità di misura diff --git a/include/init/init.php b/include/init/init.php index 510e50de5..e09699b83 100755 --- a/include/init/init.php +++ b/include/init/init.php @@ -28,7 +28,7 @@ if (Update::isUpdateAvailable() || !$dbo->isInstalled()) { return; } -$id_tipo_azienda = Tipo::find((new Tipo())->getByField('title', 'Azienda', Models\Locale::getPredefined()->id))->id; +$id_tipo_azienda = Tipo::where('name', 'Azienda')->first()->id; $has_azienda = $dbo->fetchNum('SELECT `an_anagrafiche`.`idanagrafica` FROM `an_anagrafiche` LEFT JOIN `an_tipianagrafiche_anagrafiche` ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica` @@ -74,7 +74,7 @@ if (post('action') == 'init') { // Azienda predefinita if (!$has_azienda) { Filter::set('post', 'op', 'add'); - $id_module = (new Module())->getByField('title', 'Anagrafiche', Models\Locale::getPredefined()->id); + $id_module = Module::where('name', 'Anagrafiche')->first()->id; include base_dir().'/modules/anagrafiche/actions.php'; // Logo stampe @@ -178,7 +178,7 @@ if (!$has_azienda) {
'; - $idtipoanagrafica = (new Tipo())->getByField('title', 'Azienda', Models\Locale::getPredefined()->id); + $idtipoanagrafica = Tipo::where('name', 'Azienda')->first()->id; $readonly_tipo = true; ob_start(); diff --git a/include/riferimenti/riferimenti.php b/include/riferimenti/riferimenti.php index dc3659413..a9b4d2a53 100644 --- a/include/riferimenti/riferimenti.php +++ b/include/riferimenti/riferimenti.php @@ -54,7 +54,7 @@ $direzione_richiesta = $source->getDocument()->direzione == 'entrata' ? 'uscita' // Individuazione DDT disponibili $ddt = DDT::whereHas('stato', function ($query) { - $id_stato = (new StatoDDT())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id); + $id_stato = StatoDDT::where('name', 'Bozza')->first()->id; $query->where('id', '!=', $id_stato); })->whereHas('tipo', function ($query) use ($direzione_richiesta) { $query->where('dir', '=', $direzione_richiesta); @@ -70,7 +70,7 @@ foreach ($ddt as $elemento) { // Individuazione ordini disponibili $tipo_ordini = $direzione_richiesta == 'entrata' ? 'cliente' : 'fornitore'; $ordini = Ordine::whereHas('stato', function ($query) { - $id_stato = (new StatoOrdine())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id); + $id_stato = StatoOrdine::where('name', 'Bozza')->first()->id; $query->where('id', '!=', $id_stato); })->whereHas('tipo', function ($query) use ($direzione_richiesta) { $query->where('dir', '=', $direzione_richiesta); diff --git a/include/top.php b/include/top.php index ff15aaf09..864c33903 100755 --- a/include/top.php +++ b/include/top.php @@ -238,7 +238,7 @@ if (Auth::check()) { { name: "tools", items : [ "Maximize", "ShowBlocks" ] }, { name: "about", items: [ "About" ] } ], - order_manager_id: "'.($dbo->isInstalled() ? (new Module())->getByField('title', 'Stato dei servizi', Models\Locale::getPredefined()->id) : '').'", + order_manager_id: "'.($dbo->isInstalled() ? Module::where('name', 'Stato dei servizi')->first()->id : '').'", dataload_page_buffer: '.setting('Lunghezza in pagine del buffer Datatables').', tempo_attesa_ricerche: '.setting('Tempo di attesa ricerche in secondi').', restrict_summables_to_selected: '.setting('Totali delle tabelle ristretti alla selezione').', diff --git a/mail.php b/mail.php index cd07b5621..eab40a1e9 100755 --- a/mail.php +++ b/mail.php @@ -164,7 +164,7 @@ if ($smtp['pec'] == 1 && $module->getTranslation('title') == 'Fatture di vendita echo '
- {[ "type": "select", "multiple": "1", "label": "'.tr('Allegati').'", "name": "uploads[]", "value": "'.implode(',', $uploads).'", "help": "'.tr('Allegati del documento o caricati nell\'anagrafica dell\'azienda.').'", "values": "query=SELECT `id`, `name` AS text FROM `zz_files` WHERE `id_module` = '.prepare($id_module).' AND `id_record` = '.prepare($id_record).' UNION SELECT `id`, CONCAT(`name`, \' (Azienda)\') AS text FROM `zz_files` WHERE `id_module` = '.(new Module())->getByField('title', 'Anagrafiche', Models\Locale::getPredefined()->id).' AND `id_record` = '.setting('Azienda predefinita').'", "link": "allegato" ]} + {[ "type": "select", "multiple": "1", "label": "'.tr('Allegati').'", "name": "uploads[]", "value": "'.implode(',', $uploads).'", "help": "'.tr('Allegati del documento o caricati nell\'anagrafica dell\'azienda.').'", "values": "query=SELECT `id`, `name` AS text FROM `zz_files` WHERE `id_module` = '.prepare($id_module).' AND `id_record` = '.prepare($id_record).' UNION SELECT `id`, CONCAT(`name`, \' (Azienda)\') AS text FROM `zz_files` WHERE `id_module` = '.Module::where('name', 'Anagrafiche')->first()->id.' AND `id_record` = '.setting('Azienda predefinita').'", "link": "allegato" ]}
'; diff --git a/modules/aggiornamenti/actions.php b/modules/aggiornamenti/actions.php index 2f3b449cd..11ac080f5 100755 --- a/modules/aggiornamenti/actions.php +++ b/modules/aggiornamenti/actions.php @@ -39,7 +39,7 @@ switch (filter('op')) { } // Salvataggio della versione nella cache - Cache::find((new Cache())->getByField('title', 'Ultima esecuzione del cron', Models\Locale::getPredefined()->id))->set($versione); + Cache::where('name', 'Ultima esecuzione del cron')->first()->set($versione); echo $versione; break; diff --git a/modules/aggiornamenti/src/UpdateHook.php b/modules/aggiornamenti/src/UpdateHook.php index 6987d5e09..ab7ece2eb 100755 --- a/modules/aggiornamenti/src/UpdateHook.php +++ b/modules/aggiornamenti/src/UpdateHook.php @@ -47,7 +47,7 @@ class UpdateHook extends CachedManager $update = null; } - $module = Module::find((new Module())->getByField('title', 'Aggiornamenti', \Models\Locale::getPredefined()->id)); + $module = Module::where('name', 'Aggiornamento')->first(); $link = base_path().'/controller.php?id_module='.$module->id; $message = tr("E' disponibile la versione _VERSION_ del gestionale", [ diff --git a/modules/aggiornamenti/upload_modules.php b/modules/aggiornamenti/upload_modules.php index a27fff848..56393891f 100755 --- a/modules/aggiornamenti/upload_modules.php +++ b/modules/aggiornamenti/upload_modules.php @@ -68,7 +68,7 @@ if (file_exists($extraction_dir.'/VERSION')) { $directory = 'modules'; $table = 'zz_modules'; - $installed = Module::find((new Module())->getByField('title', $info['name'])); + $installed = Module::where('name', $info['name'])->first(); } // Copia dei file nella cartella relativa @@ -86,7 +86,7 @@ if (file_exists($extraction_dir.'/VERSION')) { 'default' => 0, 'enabled' => 1, 'icon' => $info['icon'], - 'parent' => (new Module())->getByField('title', $info['parent']), + 'parent' => Module::where('name', $info['parent'])->first()->id, ])); $id_record = $dbo->lastInsertedID(); $dbo->insert($table.'_lang', array_merge($insert, [ @@ -122,9 +122,9 @@ if (file_exists($extraction_dir.'/VERSION')) { $directory = 'plugins'; $table = 'zz_plugins'; - $installed = Plugin::find((new Plugin())->getByField('title', $info['name'])); - $insert['idmodule_from'] = (new Module())->getByField('title', $info['module_from']); - $insert['idmodule_to'] = (new Module())->getByField('title', $info['module_to']); + $installed = Plugin::where('name', $info['name'])->first()->id; + $insert['idmodule_from'] = Module::where('name', $info['module_from'])->first()->id; + $insert['idmodule_to'] = Module::where('name', $info['module_to'])->first()->id; $insert['position'] = $info['position']; } @@ -134,7 +134,7 @@ if (file_exists($extraction_dir.'/VERSION')) { $table = 'zz_prints'; $installed = Prints::getPrints()[$info['name']]; - $insert['id_module'] = (new Module())->getByField('title', $info['module']); + $insert['id_module'] = Module::where('name', $info['module'])->first()->id; $insert['is_record'] = $info['is_record']; $insert_lang['filename'] = $info['filename']; $insert['icon'] = $info['icon']; diff --git a/modules/anagrafiche/add.php b/modules/anagrafiche/add.php index 17fc55997..2d001cd47 100755 --- a/modules/anagrafiche/add.php +++ b/modules/anagrafiche/add.php @@ -22,10 +22,10 @@ use Modules\Anagrafiche\Tipo; include_once __DIR__.'/../../core.php'; -$id_nazione_italia = (new Nazione())->getByField('title', 'Italia', Models\Locale::getPredefined()->id); +$id_nazione_italia = Nazione::where('name', 'Italia')->first()->id; $tipo = get('tipoanagrafica'); -$id_tipo = (new Tipo())->getByField('title', $tipo, Models\Locale::getPredefined()->id); -$id_tipo_azienda = (new Tipo())->getByField('title', 'Azienda', Models\Locale::getPredefined()->id); +$id_tipo = Tipo::where('name', $tipo)->first()->id; +$id_tipo_azienda = Tipo::where('name', 'Azienda')->first()->id; if (!empty($tipo)) { $rs = $dbo->fetchArray('SELECT `an_tipianagrafiche`.`id`, `an_tipianagrafiche_lang`.`title` 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`='.prepare($id_tipo)); diff --git a/modules/anagrafiche/ajax/search.php b/modules/anagrafiche/ajax/search.php index 2bef50813..06b1f64cb 100755 --- a/modules/anagrafiche/ajax/search.php +++ b/modules/anagrafiche/ajax/search.php @@ -24,7 +24,7 @@ use Models\Module; Anagrafiche */ -$link_id = (new Module())->getByField('title', 'Anagrafiche', Models\Locale::getPredefined()->id); +$link_id = Module::where('name', 'Anagrafiche')->first()->id; $fields = [ 'Codice' => 'codice', diff --git a/modules/anagrafiche/ajax/select.php b/modules/anagrafiche/ajax/select.php index 756e33250..f8d04bcd7 100755 --- a/modules/anagrafiche/ajax/select.php +++ b/modules/anagrafiche/ajax/select.php @@ -25,7 +25,7 @@ $filter_agente = Auth::user()['gruppo'] == 'Agenti'; switch ($resource) { case 'clienti': $id_azienda = setting('Azienda predefinita'); - $tipologia = Tipo::find((new Tipo())->getByField('title', 'Cliente', Models\Locale::getPredefined()->id))->id; + $tipologia = Tipo::where('name', 'Cliente')->first()->id; $query = "SELECT `an_anagrafiche`.`idanagrafica` AS id, @@ -103,7 +103,7 @@ switch ($resource) { case 'fornitori': $id_azienda = setting('Azienda predefinita'); - $tipologia = Tipo::find((new Tipo())->getByField('title', 'Fornitore', Models\Locale::getPredefined()->id))->id; + $tipologia = Tipo::where('name', 'Fornitore')->first()->id; $query = "SELECT `an_anagrafiche`.`idanagrafica` AS id, @@ -147,7 +147,7 @@ switch ($resource) { break; case 'vettori': - $tipologia = Tipo::find((new Tipo())->getByField('title', 'Vettore', Models\Locale::getPredefined()->id))->id; + $tipologia = Tipo::where('name', 'Vettore')->first()->id; $query = "SELECT `an_anagrafiche`.`idanagrafica` AS id, CONCAT(`ragione_sociale`, IF(`citta` IS NULL OR `citta` = '', '', CONCAT(' (', `citta`, ')')), IF(`an_anagrafiche`.`deleted_at` IS NULL, '', ' (".tr('eliminata').")'),' - ', `an_anagrafiche`.`codice`) AS descrizione, `idtipointervento_default` AS idtipointervento FROM `an_anagrafiche` INNER JOIN (`an_tipianagrafiche_anagrafiche` INNER JOIN `an_tipianagrafiche` ON `an_tipianagrafiche_anagrafiche`.`idtipoanagrafica`=`an_tipianagrafiche`.`id` 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).')) ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica` |where| ORDER BY `ragione_sociale`'; @@ -176,7 +176,7 @@ switch ($resource) { * - idanagrafica */ case 'agenti': - $tipologia = Tipo::find((new Tipo())->getByField('title', 'Agente', Models\Locale::getPredefined()->id))->id; + $tipologia = Tipo::where('name', 'Agente')->first()->id; $query = "SELECT `an_anagrafiche`.`idanagrafica` AS id, CONCAT(`ragione_sociale`, IF(`citta` IS NULL OR `citta` = '', '', CONCAT(' (', `citta`, ')')), IF(`an_anagrafiche`.`deleted_at` IS NULL, '', ' (".tr('eliminata').")'),' - ', `an_anagrafiche`.`codice`) AS descrizione, `idtipointervento_default` FROM `an_anagrafiche` INNER JOIN (`an_tipianagrafiche_anagrafiche` INNER JOIN `an_tipianagrafiche` ON `an_tipianagrafiche_anagrafiche`.`idtipoanagrafica`=`an_tipianagrafiche`.`id` 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).')) ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica` |where| ORDER BY `ragione_sociale`'; @@ -216,7 +216,7 @@ switch ($resource) { break; case 'tecnici': - $tipologia = Tipo::find((new Tipo())->getByField('title', 'Tecnico', Models\Locale::getPredefined()->id))->id; + $tipologia = Tipo::where('name', 'Tecnico')->first()->id; $query = "SELECT `an_anagrafiche`.`idanagrafica` AS id, CONCAT(`ragione_sociale`, IF(`citta` IS NULL OR `citta` = '', '', CONCAT(' (', `citta`, ')')), IF(`an_anagrafiche`.`deleted_at` IS NULL, '', ' (".tr('eliminata').")'),' - ', `an_anagrafiche`.`codice`) AS descrizione, `idtipointervento_default` FROM `an_anagrafiche` INNER JOIN (`an_tipianagrafiche_anagrafiche` INNER JOIN `an_tipianagrafiche` ON `an_tipianagrafiche_anagrafiche`.`idtipoanagrafica`=`an_tipianagrafiche`.`id` 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).')) ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica` |where| ORDER BY `ragione_sociale`'; @@ -250,9 +250,9 @@ switch ($resource) { break; case 'clienti_fornitori': - $id_cliente = Tipo::find((new Tipo())->getByField('title', 'Cliente', Models\Locale::getPredefined()->id))->id; - $id_fornitore = Tipo::find((new Tipo())->getByField('title', 'Fornitore', Models\Locale::getPredefined()->id))->id; - $id_azienda = Tipo::find((new Tipo())->getByField('title', 'Azienda', Models\Locale::getPredefined()->id))->id; + $id_cliente = Tipo::where('name', 'Cliente')->first()->id; + $id_fornitore = Tipo::where('name', 'Fornitore')->first()->id; + $id_azienda = Tipo::where('name', 'Azienda')->first()->id; $query = "SELECT `an_anagrafiche`.`idanagrafica` AS id, CONCAT_WS('', `ragione_sociale`, IF(`citta` !='' OR `provincia` != '', CONCAT(' (', `citta`, IF(`provincia`!='', CONCAT(' ', `provincia`), ''), ')'), ''), IF(`an_anagrafiche`.`deleted_at` IS NULL, '', ' (".tr('eliminata').")'),' - ', `an_anagrafiche`.`codice`) AS descrizione, `an_tipianagrafiche_lang`.`title` AS optgroup, `idtipointervento_default`, `an_tipianagrafiche`.`id` as id_tipo 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).') INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_tipianagrafiche`.`id`=`an_tipianagrafiche_anagrafiche`.`idtipoanagrafica` INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica` |where| ORDER BY `optgroup` ASC, `ragione_sociale` ASC'; diff --git a/modules/anagrafiche/buttons.php b/modules/anagrafiche/buttons.php index 482490c3a..d57df4e5e 100755 --- a/modules/anagrafiche/buttons.php +++ b/modules/anagrafiche/buttons.php @@ -32,7 +32,7 @@ if (in_array($id_cliente, $tipi_anagrafica) or in_array($id_fornitore, $tipi_ana // Aggiunta utente per i tecnici if (in_array($id_tecnico, $tipi_anagrafica)) { echo ' - + '.tr('Nuovo utente').' '; } @@ -40,35 +40,35 @@ if (in_array($id_cliente, $tipi_anagrafica) or in_array($id_fornitore, $tipi_ana if (in_array($id_cliente, $tipi_anagrafica)) { echo ' - + '.tr('Nuova attività').' - + '.tr('Nuovo preventivo').' - '.tr('Nuovo contratto').' + '.tr('Nuovo contratto').' - '.tr('Nuovo ordine cliente').' + '.tr('Nuovo ordine cliente').' - '.tr('Nuovo ddt in uscita').' + '.tr('Nuovo ddt in uscita').' - '.tr('Nuova fattura di vendita').' + '.tr('Nuova fattura di vendita').' - '.tr('Nuova registrazione contabile (cliente)').''; + '.tr('Nuova registrazione contabile (cliente)').''; } if (in_array($id_fornitore, $tipi_anagrafica)) { echo ' - '.tr('Nuovo ordine fornitore').' + '.tr('Nuovo ordine fornitore').' - '.tr('Nuovo ddt in entrata').' + '.tr('Nuovo ddt in entrata').' - '.tr('Nuova fattura di acquisto').' + '.tr('Nuova fattura di acquisto').' - '.tr('Nuova registrazione contabile (fornitore)').''; + '.tr('Nuova registrazione contabile (fornitore)').''; } echo ' diff --git a/modules/anagrafiche/edit.php b/modules/anagrafiche/edit.php index 15cd7fb13..f3abed7cb 100755 --- a/modules/anagrafiche/edit.php +++ b/modules/anagrafiche/edit.php @@ -32,9 +32,9 @@ $is_agente = in_array($id_agente, $tipi_anagrafica); $is_azienda = in_array($id_azienda, $tipi_anagrafica); if (!$is_cliente && !$is_fornitore && !$is_azienda && $is_tecnico) { - $ignore = Plugin::where('id', '=', (new Plugin())->getByField('title', 'Sedi', Models\Locale::getPredefined()->id)) - ->orWhere('id', '=', (new Plugin())->getByField('title', 'Referenti', Models\Locale::getPredefined()->id)) - ->orWhere('id', '=', (new Plugin())->getByField('title', 'Dichiarazioni d\'intento', Models\Locale::getPredefined()->id)) + $ignore = Plugin::where('name', 'Sedi') + ->orWhere('name', 'Referenti') + ->orWhere('name', 'Dichiarazioni d\'intento') ->get(); foreach ($ignore as $plugin) { @@ -46,9 +46,9 @@ if (!$is_cliente && !$is_fornitore && !$is_azienda && $is_tecnico) { } if (!$is_cliente) { - $ignore = Plugin::where('id', '=', (new Plugin())->getByField('title', 'Impianti del cliente', Models\Locale::getPredefined()->id)) - ->orWhere('id', '=', (new Plugin())->getByField('title', 'Contratti del cliente', Models\Locale::getPredefined()->id)) - ->orWhere('id', '=', (new Plugin())->getByField('title', 'Ddt del cliente', Models\Locale::getPredefined()->id)) + $ignore = Plugin::where('name', 'Impianti del cliente') + ->orWhere('name', 'Contratti del cliente') + ->orWhere('name', 'Ddt del cliente') ->get(); foreach ($ignore as $plugin) { @@ -228,7 +228,7 @@ if (in_array($id_azienda, $tipi_anagrafica)) {
- {[ "type": "select", "label": "", "name": "idzona", "values": "query=SELECT id, CONCAT_WS( ' - ', nome, descrizione) AS descrizione FROM an_zone ORDER BY descrizione ASC", "value": "$idzona$", "placeholder": "", "icon-after": "add|getByField('title', 'Zone', Models\Locale::getPredefined()->id); ?>" ]} + {[ "type": "select", "label": "", "name": "idzona", "values": "query=SELECT id, CONCAT_WS( ' - ', nome, descrizione) AS descrizione FROM an_zone ORDER BY descrizione ASC", "value": "$idzona$", "placeholder": "", "icon-after": "add|first()->id ?>" ]}
@@ -457,7 +457,7 @@ if ($is_cliente or $is_fornitore or $is_tecnico) {
- {[ "type": "select", "label": "'.tr('Relazione').'", "name": "idrelazione", "ajax-source": "relazioni", "value": "$idrelazione$", "icon-after": "add|'.(new Module())->getByField('title', 'Relazioni', Models\Locale::getPredefined()->id).'" ]} + {[ "type": "select", "label": "'.tr('Relazione').'", "name": "idrelazione", "ajax-source": "relazioni", "value": "$idrelazione$", "icon-after": "add|'.Module::where('name', 'Relazioni')->first()->id.'" ]}
@@ -471,7 +471,7 @@ if ($is_cliente or $is_fornitore or $is_tecnico) { $banche = Banca::where('id_anagrafica', $anagrafica->id)->get(); $banca_predefinita = $banche->first(fn ($item) => !empty($item['predefined'])); - $modulo_banche = (new Module())->getByField('title', 'Banche', Models\Locale::getPredefined()->id); + $modulo_banche = Module::where('name', 'Banche')->first()->id; if (!$banche->isEmpty()) { echo '
@@ -500,7 +500,7 @@ if ($is_cliente or $is_fornitore or $is_tecnico) {
- {[ "type": "select", "label": "'.tr('Provenienza cliente').'", "name": "id_provenienza", "ajax-source": "provenienze", "value": "$id_provenienza$", "icon-after": "add|'.(new Module())->getByField('title', 'Provenienze', Models\Locale::getPredefined()->id).'" ]} + {[ "type": "select", "label": "'.tr('Provenienza cliente').'", "name": "id_provenienza", "ajax-source": "provenienze", "value": "$id_provenienza$", "icon-after": "add|'.Module::where('name', 'Provenienze')->first()->id.'" ]}
@@ -684,7 +684,7 @@ if ($is_cliente or $is_fornitore or $is_tecnico) {
- {[ "type": "select", "label": "", "name": "id_settore", "ajax-source": "settori", "value": "$id_settore$", "icon-after": "add|getByField('title', 'Settori', Models\Locale::getPredefined()->id); ?>" ]} + {[ "type": "select", "label": "", "name": "id_settore", "ajax-source": "settori", "value": "$id_settore$", "icon-after": "add|first()->id; ?>" ]}
diff --git a/modules/anagrafiche/liquida_provvigioni.php b/modules/anagrafiche/liquida_provvigioni.php index 5196cbce0..ba727a71b 100644 --- a/modules/anagrafiche/liquida_provvigioni.php +++ b/modules/anagrafiche/liquida_provvigioni.php @@ -26,8 +26,8 @@ use Models\PrintTemplate; $id_record = filter('id_record'); $dir = filter('dir'); $nome_stampa = filter('nome_stampa'); -$id_print = (new PrintTemplate())->getByField('title', $nome_stampa, Models\Locale::getPredefined()->id); -$id_module = (new Module())->getByField('title', 'Stampe contabili', Models\Locale::getPredefined()->id); +$id_print = PrintTemplate::where('name', $nome_stampa)->first()->id; +$id_module = Module::where('name', 'Stampe contabili')->first()->id; $year = (new Carbon($_SESSION['period_end']))->format('Y'); diff --git a/modules/anagrafiche/plugins/allegati.php b/modules/anagrafiche/plugins/allegati.php index e60f7ce42..b8ca0927c 100755 --- a/modules/anagrafiche/plugins/allegati.php +++ b/modules/anagrafiche/plugins/allegati.php @@ -60,53 +60,53 @@ if (empty($_GET['visualizza_allegati'])) { } // Interventi dell'anagrafica - if ($user->is_admin || in_array((new Module())->getByField('title', 'Attività', Models\Locale::getPredefined()->id), $permessi)) { - $interventi = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Attività', Models\Locale::getPredefined()->id))." AS id_module, `id` AS id_record, CONCAT('Intervento num. ',codice,' del ',DATE_FORMAT(`data_richiesta`,'%d/%m/%Y')) AS descrizione FROM `in_interventi` WHERE `idanagrafica`=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Interventi')->first()->id, $permessi)) { + $interventi = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Interventi')->first()->id)." AS id_module, `id` AS id_record, CONCAT('Intervento num. ',codice,' del ',DATE_FORMAT(`data_richiesta`,'%d/%m/%Y')) AS descrizione FROM `in_interventi` WHERE `idanagrafica`=".prepare($id_record)); $documenti = array_merge($documenti, $interventi); } // Preventivi dell'anagrafica - if ($user->is_admin || in_array((new Module())->getByField('title', 'Preventivi', Models\Locale::getPredefined()->id), $permessi)) { - $preventivi = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Preventivi', Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Preventivo num. ',numero,' del ',DATE_FORMAT(data_bozza,'%d/%m/%Y')) AS descrizione FROM co_preventivi WHERE idanagrafica=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Preventivi')->first()->id, $permessi)) { + $preventivi = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Preventivi')->first()->id)." AS id_module, id AS id_record, CONCAT('Preventivo num. ',numero,' del ',DATE_FORMAT(data_bozza,'%d/%m/%Y')) AS descrizione FROM co_preventivi WHERE idanagrafica=".prepare($id_record)); $documenti = array_merge($documenti, $preventivi); } // Contratti dell'anagrafica - if ($user->is_admin || in_array((new Module())->getByField('title', 'Contratti', Models\Locale::getPredefined()->id), $permessi)) { - $contratti = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Contratti', Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Preventivo num. ',numero,' del ',DATE_FORMAT(data_bozza,'%d/%m/%Y')) AS descrizione FROM co_contratti WHERE idanagrafica=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Contratti')->first()->id, $permessi)) { + $contratti = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Contratti')->first()->id)." AS id_module, id AS id_record, CONCAT('Preventivo num. ',numero,' del ',DATE_FORMAT(data_bozza,'%d/%m/%Y')) AS descrizione FROM co_contratti WHERE idanagrafica=".prepare($id_record)); $documenti = array_merge($documenti, $contratti); } // DDT dell'anagrafica - if ($user->is_admin || in_array((new Module())->getByField('title', 'Ddt in uscita', Models\Locale::getPredefined()->id), $permessi)) { - $ddt_vendita = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Ddt in uscita', Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Ddt di vendita num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM dt_ddt WHERE idanagrafica=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Ddt di vendita')->first()->id, $permessi)) { + $ddt_vendita = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Ddt di vendita')->first()->id)." AS id_module, id AS id_record, CONCAT('Ddt di vendita num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM dt_ddt WHERE idanagrafica=".prepare($id_record)); $documenti = array_merge($documenti, $ddt_vendita); } - if ($user->is_admin || in_array((new Module())->getByField('title', 'Ddt in entrata', Models\Locale::getPredefined()->id), $permessi)) { - $ddt_acquisto = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Ddt in entrata', Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Ddt di acquisto num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM dt_ddt WHERE idanagrafica=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Ddt di acquisto')->first()->id, $permessi)) { + $ddt_acquisto = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Ddt di acquisto')->first()->id)." AS id_module, id AS id_record, CONCAT('Ddt di acquisto num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM dt_ddt WHERE idanagrafica=".prepare($id_record)); $documenti = array_merge($documenti, $ddt_acquisto); } // Fatture dell'anagrafica - if ($user->is_admin || in_array((new Module())->getByField('title', 'Fatture di vendita', Models\Locale::getPredefined()->id), $permessi)) { - $fatture_vendita = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Fatture di vendita', Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Fattura di vendita num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data_registrazione,'%d/%m/%Y')) AS descrizione FROM co_documenti WHERE idanagrafica=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Fatture di vendita')->first()->id, $permessi)) { + $fatture_vendita = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Fatture di vendita')->first()->id)." AS id_module, id AS id_record, CONCAT('Fattura di vendita num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data_registrazione,'%d/%m/%Y')) AS descrizione FROM co_documenti WHERE idanagrafica=".prepare($id_record)); $documenti = array_merge($documenti, $fatture_vendita); } - if ($user->is_admin || in_array((new Module())->getByField('title', 'Fatture di acquisto', Models\Locale::getPredefined()->id), $permessi)) { - $fatture_acquisto = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Fatture di acquisto', Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Fattura di acquisto num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data_registrazione,'%d/%m/%Y')) AS descrizione FROM co_documenti WHERE idanagrafica=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Fatture di acquisto')->first()->id, $permessi)) { + $fatture_acquisto = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Fatture di acquisto')->first()->id)." AS id_module, id AS id_record, CONCAT('Fattura di acquisto num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data_registrazione,'%d/%m/%Y')) AS descrizione FROM co_documenti WHERE idanagrafica=".prepare($id_record)); $documenti = array_merge($documenti, $fatture_acquisto); } // Ordini dell'anagrafica - if ($user->is_admin || in_array((new Module())->getByField('title', 'Ordini cliente', Models\Locale::getPredefined()->id), $permessi)) { - $ordini_vendita = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Ordini cliente', Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Ordine cliente num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM or_ordini WHERE idanagrafica=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Ordini cliente')->first()->id, $permessi)) { + $ordini_vendita = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Ordini cliente')->first()->id)." AS id_module, id AS id_record, CONCAT('Ordine cliente num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM or_ordini WHERE idanagrafica=".prepare($id_record)); $documenti = array_merge($documenti, $ordini_vendita); } - if ($user->is_admin || in_array((new Module())->getByField('title', 'Ordini fornitore', Models\Locale::getPredefined()->id), $permessi)) { - $ordini_acquisto = $dbo->fetcharray('SELECT '.prepare((new Module())->getByField('title', 'Ordini fornitore', Models\Locale::getPredefined()->id))." AS id_module, id AS id_record, CONCAT('Ordine fornitore num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM or_ordini WHERE idanagrafica=".prepare($id_record)); + if ($user->is_admin || in_array(Module::where('name', 'Ordini fornitore')->first()->id, $permessi)) { + $ordini_acquisto = $dbo->fetcharray('SELECT '.prepare(Module::where('name', 'Ordini fornitore')->first()->id)." AS id_module, id AS id_record, CONCAT('Ordine fornitore num. ',IFNULL(numero_esterno,numero),' del ',DATE_FORMAT(data,'%d/%m/%Y')) AS descrizione FROM or_ordini WHERE idanagrafica=".prepare($id_record)); $documenti = array_merge($documenti, $ordini_acquisto); } diff --git a/modules/anagrafiche/src/Anagrafica.php b/modules/anagrafiche/src/Anagrafica.php index 824a46f4b..be9429e19 100755 --- a/modules/anagrafiche/src/Anagrafica.php +++ b/modules/anagrafiche/src/Anagrafica.php @@ -89,7 +89,7 @@ class Anagrafica extends Model public static function fromTipo($type) { - $tipologia = (new TipoAnagrafica())->getByField('title', $type); + $tipologia = TipoAnagrafica::where('name', $type)->first()->id; $anagrafiche = self::whereHas('tipi', function ($query) use ($tipologia) { $query->where('an_tipianagrafiche.id', '=', $tipologia); @@ -156,7 +156,7 @@ class Anagrafica extends Model public function setTipologieAttribute(array $tipologie) { if ($this->isAzienda()) { - $tipologie[] = (new TipoAnagrafica())->getByField('title', 'Azienda', \Models\Locale::getPredefined()->id); + $tipologie[] = TipoAnagrafica::where('name', 'Azienda')->first()->id; } $tipologie = array_clean($tipologie); diff --git a/modules/anagrafiche/src/Import/CSV.php b/modules/anagrafiche/src/Import/CSV.php index ff0103ea7..75a623ea8 100644 --- a/modules/anagrafiche/src/Import/CSV.php +++ b/modules/anagrafiche/src/Import/CSV.php @@ -253,7 +253,7 @@ class CSV extends CSVImporter $tipi_selezionati = explode(',', (string) $record['tipologia']); foreach ($tipi_selezionati as $tipo) { - $id_tipo = (new Tipo())->getByField('title', $tipo); + $id_tipo = Tipo::where('name', $tipo)->first()->id; // Creo il tipo anagrafica se non esiste if (empty($id_tipo)) { @@ -264,7 +264,7 @@ class CSV extends CSVImporter 'name' => $tipo, ])['id']; - $id_tipo = (new Tipo())->getByField('title', $tipo); + $id_tipo = Tipo::where('name', $tipo)->first()->id; } $tipologie[] = $id_tipo; @@ -280,7 +280,7 @@ class CSV extends CSVImporter // Fix per campi con contenuti derivati da query implicite if (!empty($record['id_nazione'])) { - $record['id_nazione'] = (new Nazione())->getByField('title', 'Italia', \Models\Locale::getPredefined()->id); + $record['id_nazione'] = Nazione::where('name', 'Italia')->first()->id; } else { unset($record['id_nazione']); } diff --git a/modules/articoli/add.php b/modules/articoli/add.php index 7ddc0713f..ff64c75ae 100755 --- a/modules/articoli/add.php +++ b/modules/articoli/add.php @@ -46,11 +46,11 @@ $aliquota_predefinita = floatval(Aliquota::find($iva_predefinita)->percentuale);
- {[ "type": "select", "label": "", "name": "categoria", "required": 0, "ajax-source": "categorie", "icon-after": "add|getByField('title', 'Categorie articoli', Models\Locale::getPredefined()->id); ?>" ]} + {[ "type": "select", "label": "", "name": "categoria", "required": 0, "ajax-source": "categorie", "icon-after": "add|first()->id; ?>" ]}
- {[ "type": "select", "label": "", "name": "subcategoria", "id": "subcategoria_add", "ajax-source": "sottocategorie", "icon-after": "add|getByField('title', 'Categorie articoli', Models\Locale::getPredefined()->id); ?>||hide" ]} + {[ "type": "select", "label": "", "name": "subcategoria", "id": "subcategoria_add", "ajax-source": "sottocategorie", "icon-after": "add|first()->id; ?>||hide" ]}
@@ -104,7 +104,7 @@ $aliquota_predefinita = floatval(Aliquota::find($iva_predefinita)->percentuale);
- {[ "type": "select", "label": "", "name": "um", "value": "", "ajax-source": "misure", "icon-after": "add|getByField('title', 'Unità di misura articoli', Models\Locale::getPredefined()->id); ?>" ]} + {[ "type": "select", "label": "", "name": "um", "value": "", "ajax-source": "misure", "icon-after": "add|first()->id; ?>" ]}
{[ "type": "select", "label": "", "name": "um_secondaria", "value": "", "ajax-source": "misure", "help": "" ]} diff --git a/modules/articoli/ajax/complete.php b/modules/articoli/ajax/complete.php index bcc285a4d..72dd750ee 100755 --- a/modules/articoli/ajax/complete.php +++ b/modules/articoli/ajax/complete.php @@ -76,7 +76,7 @@ switch ($resource) { for ($i = 0; $i < sizeof($documenti); ++$i) { ($documenti[$i]['n2_documento'] != '') ? $n_documento = $documenti[$i]['n2_documento'] : $n_documento = $documenti[$i]['n_documento']; - $link_id = (new Module())->getByField('title', $documenti[$i]['modulo']); + $link_id = Module::where('name', $documenti[$i]['modulo'])->first()->id; echo "".$documenti[$i]['tipo'].'. n. '.$n_documento.' del '.Translator::dateToLocale($documenti[$i]['data_documento'])." \n"; echo "".moneyFormat($documenti[$i]['costo_unitario'])."\n"; $ids[] = '"'.$documenti[$i]['id'].'"'; @@ -137,7 +137,7 @@ switch ($resource) { for ($i = 0; $i < sizeof($documenti); ++$i) { ($documenti[$i]['n2_documento'] != '') ? $n_documento = $documenti[$i]['n2_documento'] : $n_documento = $documenti[$i]['n_documento']; - $link_id = (new Module())->getByField('title', $documenti[$i]['modulo']); + $link_id = Module::where('name', $documenti[$i]['modulo'])->first()->id; echo "".$documenti[$i]['tipo'].' n. '.$n_documento.' del '.Translator::dateToLocale($documenti[$i]['data_documento'])." \n"; echo "".moneyFormat($documenti[$i]['costo_unitario'])."\n"; $ids[] = '"'.$documenti[$i]['id'].'"'; @@ -197,7 +197,7 @@ switch ($resource) { for ($i = 0; $i < sizeof($documenti); ++$i) { ($documenti[$i]['n2_documento'] != '') ? $n_documento = $documenti[$i]['n2_documento'] : $n_documento = $documenti[$i]['n_documento']; - $link_id = (new Module())->getByField('title', $documenti[$i]['modulo']); + $link_id = Module::where('name', $documenti[$i]['modulo'])->first()->id; echo "".$documenti[$i]['tipo'].' n. '.$n_documento.' del '.Translator::dateToLocale($documenti[$i]['data_documento'])." \n"; echo "".moneyFormat($documenti[$i]['costo_unitario'])."\n"; $ids[] = '"'.$documenti[$i]['id'].'"'; diff --git a/modules/articoli/ajax/search.php b/modules/articoli/ajax/search.php index 8088f54f7..0ace3e74e 100755 --- a/modules/articoli/ajax/search.php +++ b/modules/articoli/ajax/search.php @@ -20,7 +20,7 @@ include_once __DIR__.'/../../../core.php'; use Models\Module; -$link_id = (new Module())->getByField('title', 'Articoli', Models\Locale::getPredefined()->id); +$link_id = Module::where('name', 'Articoli')->first()->id; $prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA'); $show_prezzi = Auth::user()['gruppo'] != 'Tecnici' || (Auth::user()['gruppo'] == 'Tecnici' && setting('Mostra i prezzi al tecnico')); diff --git a/modules/articoli/bulk.php b/modules/articoli/bulk.php index e6b4165b1..953bae10a 100755 --- a/modules/articoli/bulk.php +++ b/modules/articoli/bulk.php @@ -31,7 +31,7 @@ use Plugins\ListinoClienti\DettaglioPrezzo; include_once __DIR__.'/../../core.php'; // Segmenti -$id_preventivi = (new Module())->getByField('title', 'Preventivi', Models\Locale::getPredefined()->id); +$id_preventivi = Module::where('name', 'Preventivi')->first()->id; $id_segment = $_SESSION['module_'.$id_preventivi]['id_segment']; switch (post('op')) { diff --git a/modules/articoli/edit.php b/modules/articoli/edit.php index b1f555ca5..b754ceff9 100755 --- a/modules/articoli/edit.php +++ b/modules/articoli/edit.php @@ -53,11 +53,11 @@ use Modules\Iva\Aliquota;
- {[ "type": "select", "label": "", "name": "categoria", "required": 0, "value": "$id_categoria$", "ajax-source": "categorie", "icon-after": "add|getByField('title', 'Categorie articoli', Models\Locale::getPredefined()->id); ?>" ]} + {[ "type": "select", "label": "", "name": "categoria", "required": 0, "value": "$id_categoria$", "ajax-source": "categorie", "icon-after": "add|first()->id; ?>" ]}
- {[ "type": "select", "label": "", "name": "subcategoria", "value": "$id_sottocategoria$", "ajax-source": "sottocategorie", "select-options": $record['id_categoria']]); ?>, "icon-after": "add|getByField('title', 'Categorie articoli', Models\Locale::getPredefined()->id); ?>|id_original=" ]} + {[ "type": "select", "label": "", "name": "subcategoria", "value": "$id_sottocategoria$", "ajax-source": "sottocategorie", "select-options": $record['id_categoria']]); ?>, "icon-after": "add|first()->id; ?>|id_original=" ]}
@@ -86,7 +86,7 @@ use Modules\Iva\Aliquota;
- {[ "type": "select", "label": "", "name": "um", "value": "$um$", "ajax-source": "misure", "icon-after": "add|getByField('title', 'Unità di misura', Models\Locale::getPredefined()->id); ?>" ]} + {[ "type": "select", "label": "", "name": "um", "value": "$um$", "ajax-source": "misure", "icon-after": "add|first()->id; ?>" ]}
diff --git a/modules/articoli/plugins/articoli.movimenti.php b/modules/articoli/plugins/articoli.movimenti.php index f12e5c489..277f29091 100755 --- a/modules/articoli/plugins/articoli.movimenti.php +++ b/modules/articoli/plugins/articoli.movimenti.php @@ -49,7 +49,7 @@ echo '
'; echo ' - + '.tr('Movimenta articolo').' '; @@ -69,7 +69,7 @@ if (empty($_GET['movimentazione_completa'])) { } echo ' - + '.tr('Visualizza dettagli').' '; diff --git a/modules/articoli/src/Articolo.php b/modules/articoli/src/Articolo.php index ccaba25fd..b79a61876 100755 --- a/modules/articoli/src/Articolo.php +++ b/modules/articoli/src/Articolo.php @@ -207,7 +207,7 @@ class Articolo extends Model return null; } - $module = Module::find((new Module())->getByField('title', $this->module, \Models\Locale::getPredefined()->id)); + $module = Module::where('name', $this->module)->first(); $fileinfo = \Uploads::fileInfo($this->immagine); $directory = '/'.$module->upload_directory.'/'; diff --git a/modules/articoli/src/Import/CSV.php b/modules/articoli/src/Import/CSV.php index 6f716a905..29e3ff518 100644 --- a/modules/articoli/src/Import/CSV.php +++ b/modules/articoli/src/Import/CSV.php @@ -277,7 +277,7 @@ class CSV extends CSVImporter $sottocategoria = null; if (!empty($record['categoria'])) { // Categoria - $categoria = Categoria::where('id', '=', (new Categoria())->getByField('title', strtolower((string) $record['categoria'])))->first(); + $categoria = Categoria::where('id', '=', (new Categoria())->getByField('title', strtolower((string) $record['categoria'])))->orWhere('name', strtolower((string) $record['categoria']))->first(); if (empty($categoria)) { $categoria = Categoria::build(); @@ -287,7 +287,7 @@ class CSV extends CSVImporter // Sotto-categoria if (!empty($record['sottocategoria'])) { - $sottocategoria = Categoria::where('id', '=', (new Categoria())->getByField('title', strtolower((string) $record['sottocategoria'])))->first(); + $sottocategoria = Categoria::where('id', '=', (new Categoria())->getByField('title', strtolower((string) $record['sottocategoria'])))->orWhere('name', strtolower((string) $record['sottocategoria']))->first(); if (empty($sottocategoria)) { $sottocategoria = Categoria::build(); @@ -367,7 +367,7 @@ class CSV extends CSVImporter if (!empty($file_content)) { if ($record['import_immagine'] == 2 || $record['import_immagine'] == 4) { \Uploads::deleteLinked([ - 'id_module' => (new Module())->getByField('title', 'Articoli', \Models\Locale::getPredefined()->id), + 'id_module' => Module::where('name', 'Articoli')->first()->id, 'id_record' => $articolo->id, ]); @@ -384,7 +384,7 @@ class CSV extends CSVImporter 'name' => 'Immagine', 'category' => 'Immagini', 'original_name' => $name, - 'id_module' => (new Module())->getByField('title', 'Articoli', \Models\Locale::getPredefined()->id), + 'id_module' => Module::where('name', 'Articoli')->first()->id, 'id_record' => $articolo->id, ], [ 'thumbnails' => true, @@ -466,7 +466,7 @@ class CSV extends CSVImporter } if ($dettagli['dir']) { - $tipo = (new Tipo())->getByField('title', $dettagli['dir']); + $tipo = Tipo::where('name', $dettagli['dir'])->first()->id; $tipi = $anagrafica->tipi->pluck('id')->toArray(); $tipi[] = $tipo; diff --git a/modules/automezzi/add_articolo.php b/modules/automezzi/add_articolo.php index 18f20c790..82c205684 100644 --- a/modules/automezzi/add_articolo.php +++ b/modules/automezzi/add_articolo.php @@ -17,7 +17,7 @@ if (!empty($idarticolo) && !empty($idautomezzo)) { Form di inserimento riga documento */ echo ' -