From 2b0c5f886e4a2d14482adb94cf65a6fc233668cc Mon Sep 17 00:00:00 2001 From: MatteoPistorello Date: Mon, 30 Oct 2023 13:12:24 +0100 Subject: [PATCH] Fix checks impianti parent --- modules/categorie_impianti/actions.php | 7 +++++- modules/impianti/actions.php | 24 ++++++++++++++++--- .../plugins/my_impianti.interventi.php | 13 ++++++---- modules/interventi/actions.php | 11 +++++++-- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/modules/categorie_impianti/actions.php b/modules/categorie_impianti/actions.php index eb0d367d0..7cb40fd70 100755 --- a/modules/categorie_impianti/actions.php +++ b/modules/categorie_impianti/actions.php @@ -89,7 +89,12 @@ switch (filter('op')) { 'id_record' => $impianto['id'], ]); foreach ($checks_categoria as $check_categoria) { - $check = Check::build($user, $structure, $impianto['id'], $check_categoria['content'], null, $check_categoria['is_titolo'], $check_categoria['order']); + $id_parent_new = null; + if ($check_categoria['id_parent']) { + $parent = $dbo->selectOne('zz_checks', '*', ['id' => $check_categoria['id_parent']]); + $id_parent_new = $dbo->selectOne('zz_checks', '*', ['content' => $parent['content'], 'id_module' => $modulo_impianti['id'], 'id_record' => $impianto['id']])['id']; + } + $check = Check::build($user, $structure, $impianto['id'], $check_categoria['content'], $id_parent_new, $check_categoria['is_titolo'], $check_categoria['order']); $check->id_module = $modulo_impianti['id']; $check->id_plugin = null; $check->note = $check_categoria['note']; diff --git a/modules/impianti/actions.php b/modules/impianti/actions.php index 3743c4666..fc284132e 100644 --- a/modules/impianti/actions.php +++ b/modules/impianti/actions.php @@ -102,13 +102,26 @@ switch ($op) { $id_categoria = post('id_categoria'); if (!empty($matricola)) { - $dbo->query('INSERT INTO my_impianti(matricola, idanagrafica, nome, data, idtecnico, idsede, id_categoria) VALUES ('.prepare($matricola).', '.prepare($idanagrafica).', '.prepare($nome).', NOW(), '.prepare($idtecnico).', '.prepare($idsede).', '.prepare($id_categoria).')'); + $dbo->insert('my_impianti', [ + 'matricola' => $matricola, + 'idanagrafica' => $idanagrafica, + 'nome' => $nome, + 'data' => date('Y-m-d'), + 'idtecnico' => $idtecnico ?: 0, + 'idsede' => $idsede ?: 0, + 'id_categoria' => $id_categoria ?: null + ]); $id_record = $dbo->lastInsertedID(); $checks_categoria = $dbo->fetchArray('SELECT * FROM zz_checks WHERE id_module = '.prepare($modulo_categorie_impianti['id']).' AND id_record = '.prepare($id_categoria)); foreach ($checks_categoria as $check_categoria) { - $check = Check::build($user, $structure, $id_record, $check_categoria['content'], null, $check_categoria['is_titolo'], $check_categoria['order']); + $id_parent_new = null; + if ($check_categoria['id_parent']) { + $parent = $dbo->selectOne('zz_checks', '*', ['id' => $check_categoria['id_parent']]); + $id_parent_new = $dbo->selectOne('zz_checks', '*', ['content' => $parent['content'], 'id_module' => $id_module, 'id_record' => $id_record])['id']; + } + $check = Check::build($user, $structure, $id_record, $check_categoria['content'], $id_parent_new, $check_categoria['is_titolo'], $check_categoria['order']); $check->id_plugin = null; $check->note = $check_categoria['note']; $check->save(); @@ -174,7 +187,12 @@ switch ($op) { $checks_categoria = $dbo->fetchArray('SELECT * FROM zz_checks WHERE id_module = '.prepare($modulo_categorie_impianti['id']).' AND id_record = '.prepare(post('id_categoria'))); foreach ($checks_categoria as $check_categoria) { - $check = Check::build($user, $structure, $id_record, $check_categoria['content'], null, $check_categoria['is_titolo'], $check_categoria['order']); + $id_parent_new = null; + if ($check_categoria['id_parent']) { + $parent = $dbo->selectOne('zz_checks', '*', ['id' => $check_categoria['id_parent']]); + $id_parent_new = $dbo->selectOne('zz_checks', '*', ['content' => $parent['content'], 'id_module' => $id_module, 'id_record' => $id_record])['id']; + } + $check = Check::build($user, $structure, $id_record, $check_categoria['content'], $id_parent_new, $check_categoria['is_titolo'], $check_categoria['order']); $check->id_plugin = null; $check->note = $check_categoria['note']; $check->save(); diff --git a/modules/impianti/plugins/my_impianti.interventi.php b/modules/impianti/plugins/my_impianti.interventi.php index 29464b3e4..6f89b6210 100644 --- a/modules/impianti/plugins/my_impianti.interventi.php +++ b/modules/impianti/plugins/my_impianti.interventi.php @@ -56,9 +56,14 @@ if (filter('op') == 'link_impianti') { $checks_impianti = $dbo->fetchArray('SELECT * FROM zz_checks WHERE id_module = '.prepare( $modulo_impianti['id']).' AND id_record = '.prepare($matricola)); foreach ($checks_impianti as $check_impianto) { - $check = Check::build($user, $structure, $id_record, $check_impianto['content'], null, $check_impianto['is_titolo'], $check_impianto['order'], $modulo_impianti['id'], $matricola); + $id_parent_new = null; + if ($check_impianto['id_parent']) { + $parent = $dbo->selectOne('zz_checks', '*', ['id' => $check_impianto['id_parent']]); + $id_parent_new = $dbo->selectOne('zz_checks', '*', ['content' => $parent['content'], 'id_module' => $id_module, 'id_record' => $id_record])['id']; + } + $check = Check::build($user, $structure, $id_record, $check_impianto['content'], $id_parent_new, $check_impianto['is_titolo'], $check_impianto['order'], $modulo_impianti['id'], $matricola); $check->id_module = $id_module; - $check->id_plugin = null; + $check->id_plugin = $id_plugin; $check->note = $check_impianto['note']; $check->save(); } @@ -138,7 +143,7 @@ echo ' $impianti_collegati = $dbo->fetchArray('SELECT * FROM my_impianti_interventi INNER JOIN my_impianti ON my_impianti_interventi.idimpianto = my_impianti.id WHERE idintervento = '.prepare($id_record)); foreach ($impianti_collegati as $impianto) { - $checks = Check::where('id_module_from', $modulo_impianti['id'])->where('id_record_from', $impianto['id'])->where('id_module', $id_module)->where('id_record', $id_record)->get(); + $checks = Check::where('id_module_from', $modulo_impianti['id'])->where('id_record_from', $impianto['id'])->where('id_module', $id_module)->where('id_record', $id_record)->where('id_parent', null)->get(); $type = 'muted'; $class = 'disabled'; @@ -179,7 +184,7 @@ echo ' - + '; foreach ($checks as $check) { diff --git a/modules/interventi/actions.php b/modules/interventi/actions.php index bee65eb90..68845043d 100644 --- a/modules/interventi/actions.php +++ b/modules/interventi/actions.php @@ -20,6 +20,7 @@ include_once __DIR__.'/../../core.php'; use Carbon\CarbonPeriod; +use Models\Plugin; use Modules\Anagrafiche\Anagrafica; use Modules\Articoli\Articolo as ArticoloOriginale; use Modules\Checklists\Check; @@ -39,6 +40,7 @@ use Plugins\ListinoClienti\DettaglioPrezzo; use Plugins\PianificazioneInterventi\Promemoria; $modulo_impianti = Modules::get('Impianti'); +$plugin_impianti = Plugin::pool('Impianti'); switch (post('op')) { case 'update': @@ -233,9 +235,14 @@ switch (post('op')) { $checks_impianti = $dbo->fetchArray('SELECT * FROM zz_checks WHERE id_module = '.prepare( $modulo_impianti['id']).' AND id_record = '.prepare($impianto)); foreach ($checks_impianti as $check_impianto) { - $check = Check::build($user, $structure, $id_record, $check_impianto['content'], null, $check_impianto['is_titolo'], $check_impianto['order'], $modulo_impianti['id'], $impianto); + $id_parent_new = null; + if ($check_impianto['id_parent']) { + $parent = $dbo->selectOne('zz_checks', '*', ['id' => $check_impianto['id_parent']]); + $id_parent_new = $dbo->selectOne('zz_checks', '*', ['content' => $parent['content'], 'id_module' => $id_module, 'id_record' => $id_record])['id']; + } + $check = Check::build($user, $structure, $id_record, $check_impianto['content'], $id_parent_new, $check_impianto['is_titolo'], $check_impianto['order'], $modulo_impianti['id'], $impianto); $check->id_module = $id_module; - $check->id_plugin = null; + $check->id_plugin = $plugin_impianti['id']; $check->note = $check_impianto['note']; $check->save(); }