From 529cf6f5c507ea06a8901ab30871e0e2b5614089 Mon Sep 17 00:00:00 2001 From: Pek5892 Date: Wed, 27 Mar 2024 11:38:10 +0100 Subject: [PATCH] Fix import impianti --- modules/categorie_impianti/init.php | 2 +- modules/categorie_impianti/row-list.php | 15 +++++----- modules/impianti/src/Import/CSV.php | 40 ++++++++++++------------- modules/interventi/src/Import/CSV.php | 6 ++-- modules/interventi/src/Stato.php | 2 +- src/Models/Upload.php | 2 +- update/2_5.sql | 5 +++- 7 files changed, 37 insertions(+), 35 deletions(-) diff --git a/modules/categorie_impianti/init.php b/modules/categorie_impianti/init.php index 0451e6cd7..7546df7e4 100755 --- a/modules/categorie_impianti/init.php +++ b/modules/categorie_impianti/init.php @@ -21,7 +21,7 @@ include_once __DIR__.'/../../core.php'; use Modules\Impianti\Categoria; if (isset($id_record)) { - $record = $dbo->fetchOne('SELECT * FROM `my_impianti_categorie` LEFT JOIN `my_impianti_categorie_lang` ON (`my_impianti_categorie`.`id`=`my_impianti_categorie_lang`.`id_record` AND `my_impianti_categorie_lang`.`id_lang` = '.prepare(\Models\Locale::getDefault()->id).' WHERE `my_impianti_categorie`.`id`='.prepare($id_record)); + $record = $dbo->fetchOne('SELECT * FROM `my_impianti_categorie` LEFT JOIN `my_impianti_categorie_lang` ON (`my_impianti_categorie`.`id`=`my_impianti_categorie_lang`.`id_record` AND `my_impianti_categorie_lang`.`id_lang` = '.prepare(\Models\Locale::getDefault()->id).') WHERE `my_impianti_categorie`.`id`='.prepare($id_record)); $categoria = Categoria::find($id_record); } diff --git a/modules/categorie_impianti/row-list.php b/modules/categorie_impianti/row-list.php index 62a7423ae..ff17a8a9e 100644 --- a/modules/categorie_impianti/row-list.php +++ b/modules/categorie_impianti/row-list.php @@ -18,19 +18,20 @@ */ include_once __DIR__.'/../../core.php'; +use Modules\Impianti\Categoria; -$subcategorie = $dbo->fetchArray('SELECT `my_impianti_categorie`.*, `my_impianti_categorie_lang`.`name` FROM `my_impianti_categorie` LEFT JOIN `my_impianti_categorie_lang` ON (`my_impianti_categorie`.`id`=`my_impianti_categorie_lang`.`id_record` AND `my_impianti_categorie_lang`.`id_lang` = '.prepare(\Models\Locale::getDefault()->id).') WHERE `parent`='.prepare($id_record).' ORDER BY `name` ASC '); +$subcategorie = Categoria::where('parent', '=', $id_record)->get(); foreach ($subcategorie as $sub) { - $n_impianti = $dbo->fetchNum('SELECT * FROM `my_impianti` WHERE `id_sottocategoria`='.prepare($sub['id']).' AND deleted_at IS NULL'); + $n_impianti = $dbo->fetchNum('SELECT * FROM `my_impianti` WHERE `id_sottocategoria`='.prepare($sub->id).' AND deleted_at IS NULL'); echo ' - '.$sub['nome'].' - '.$sub['colore'].' - '.$sub['nota'].' + '.$sub->getTranslation('name').' + '.$sub->colore.' + '.$sub->nota.' - - + + diff --git a/modules/impianti/src/Import/CSV.php b/modules/impianti/src/Import/CSV.php index e6849714c..4c40be4a8 100644 --- a/modules/impianti/src/Import/CSV.php +++ b/modules/impianti/src/Import/CSV.php @@ -67,11 +67,11 @@ class CSV extends CSVImporter 'label' => 'Telefono', ], [ - 'field' => 'id_categoria', + 'field' => 'categoria', 'label' => 'Categoria', ], [ - 'field' => 'id_sottocategoria', + 'field' => 'sottocategoria', 'label' => 'Sottocategoria', ], [ @@ -105,27 +105,26 @@ class CSV extends CSVImporter // Gestione categoria e sottocategoria $categoria = null; $sottocategoria = null; + if (!empty($record['categoria'])) { + // Categoria + $categoria = Categoria::where('id', '=', (new Categoria())->getByField('name', strtolower($record['categoria'])))->first(); - if (empty($record['id_categoria'])) { - $record['id_categoria'] = 'Nessuna'; - } - // Categoria - $categoria = Categoria::where('nome', strtolower($record['id_categoria']))->first(); + if (empty($categoria)) { + $categoria = Categoria::build(); + $categoria->setTranslation('name', $record['categoria']); + $categoria->save(); + } - if (empty($categoria)) { - $categoria = Categoria::build($record['id_categoria']); - } + // Sotto-categoria + if (!empty($record['sottocategoria'])) { + $sottocategoria = Categoria::where('id', '=', (new Categoria())->getByField('name', strtolower($record['sottocategoria'])))->first(); - // Sotto-categoria - if (!empty($record['id_sottocategoria'])) { - $sottocategoria = Categoria::where('nome', $record['id_sottocategoria']) - ->where('parent', $categoria->id) - ->first(); - - if (empty($sottocategoria)) { - $sottocategoria = Categoria::build($record['id_sottocategoria']); - $sottocategoria->parent()->associate($categoria); - $sottocategoria->save(); + if (empty($sottocategoria)) { + $sottocategoria = Categoria::build(); + $sottocategoria->setTranslation('name', $record['sottocategoria']); + $sottocategoria->parent()->associate($categoria); + $sottocategoria->save(); + } } } @@ -145,7 +144,6 @@ class CSV extends CSVImporter $impianto->save(); } - $impianto->id_sottocategoria = $sottocategoria['id']; $impianto->idanagrafica = $anagrafica->idanagrafica; $impianto->save(); diff --git a/modules/interventi/src/Import/CSV.php b/modules/interventi/src/Import/CSV.php index 4a7bee43a..7b28cbab5 100644 --- a/modules/interventi/src/Import/CSV.php +++ b/modules/interventi/src/Import/CSV.php @@ -124,9 +124,9 @@ class CSV extends CSVImporter unset($record['tipo']); if (empty($record['stato'])) { - $stato = (new Stato())->getByField('name', 'Completato'); + $stato = Stato::find((new Stato())->getByField('name', 'Completato')); } else { - $stato = (new Stato())->getByField('name', $record['stato']); + $stato = Stato::find((new Stato())->getByField('name', $record['stato'])); } unset($record['stato']); @@ -188,7 +188,7 @@ class CSV extends CSVImporter { return [ ['Codice', 'Telefono', 'Data', 'Data richiesta', 'Ora inizio', 'Ora fine', 'Tecnico', 'Tipo', 'Note', 'Impianto', 'Richiesta', 'Descrizione', 'Stato'], - ['00001/2024', '+39 0429 60 25 12', '07/11/2024', '03/11/2024', '8:30', '9:30', 'Stefano Bianchi', '', '', '12345-85A22', 'Manutenzione ordinaria', 'eseguito intervento di manutenzione', 'Bozza'], + ['00001/2024', '+39 0429 60 25 12', '07/11/2024', '03/11/2024', '8:30', '9:30', 'Stefano Bianchi', '', '', '12345-85A22', 'Manutenzione ordinaria', 'eseguito intervento di manutenzione', 'Da programmare'], ['0002/2024', '+39 0429 60 25 12', '08/11/2024', '04/11/2024', '11:20', '', 'Stefano Bianchi', '', '', '12345-85B23', 'Manutenzione ordinaria', 'eseguito intervento di manutenzione', ''], ]; } diff --git a/modules/interventi/src/Stato.php b/modules/interventi/src/Stato.php index 61e5eb960..f9d832bc4 100755 --- a/modules/interventi/src/Stato.php +++ b/modules/interventi/src/Stato.php @@ -50,7 +50,7 @@ class Stato extends Model public function getModuleAttribute() { - return 'Stato dei contratti'; + return 'Stati di attività'; } public static function getTranslatedFields() diff --git a/src/Models/Upload.php b/src/Models/Upload.php index 765423902..563fcc862 100755 --- a/src/Models/Upload.php +++ b/src/Models/Upload.php @@ -153,7 +153,7 @@ class Upload extends Model { $parent = $this->plugin ?: $this->module; - return strtolower($parent->getTranslation('name')); + return strtolower($parent ? $parent->getTranslation('name') : ''); } /** diff --git a/update/2_5.sql b/update/2_5.sql index 5275c07ac..b94b1a7bc 100644 --- a/update/2_5.sql +++ b/update/2_5.sql @@ -2455,4 +2455,7 @@ INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `e (NULL, 'app-v1', 'retrieve', 'pagamento', 'API\\App\\v1\\Pagamenti', '1'); ALTER TABLE `mg_categorie` CHANGE `nota` `nota` VARCHAR(1000) NULL; -ALTER TABLE `mg_categorie` CHANGE `colore` `colore` VARCHAR(255) NULL; \ No newline at end of file +ALTER TABLE `mg_categorie` CHANGE `colore` `colore` VARCHAR(255) NULL; + +ALTER TABLE `my_impianti_categorie` CHANGE `nota` `nota` VARCHAR(1000) NULL; +ALTER TABLE `my_impianti_categorie` CHANGE `colore` `colore` VARCHAR(255) NULL; \ No newline at end of file