Skip to content

Commit eaace8c

Browse files
committed
fix: plugin Impianti in attività
1 parent a847c8a commit eaace8c

3 files changed

Lines changed: 296 additions & 156 deletions

File tree

plugins/impianti_intervento/actions.php

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
$operazione = filter('op');
2727
$id_modulo_impianti = Module::where('name', 'Impianti')->first()->id;
2828

29+
30+
2931
switch ($operazione) {
3032
case 'add_impianto':
3133
if (post('id_impianto')) {
@@ -84,24 +86,59 @@
8486
break;
8587

8688
case 'delete_impianto':
87-
$dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record).' AND idimpianto = '.prepare(post('id')));
88-
Check::deleteLinked([
89-
'id_module' => $id_module,
90-
'id_record' => $id_record,
91-
'id_module_from' => $id_modulo_impianti,
92-
'id_record_from' => post('id'),
93-
]);
89+
try {
90+
$id_impianto = post('id');
9491

95-
$components = $dbo->fetchArray('SELECT * FROM my_componenti WHERE id_impianto = '.prepare($matricola));
96-
if (!empty($components)) {
97-
foreach ($components as $component) {
98-
$dbo->query('DELETE FROM my_componenti_interventi WHERE id_componente = '.prepare($component['id']).' AND id_intervento = '.prepare($id_record));
92+
if (empty($id_impianto)) {
93+
throw new Exception(tr('ID impianto non specificato'));
9994
}
100-
}
10195

102-
flash()->info(tr('Impianto rimosso correttamente!'));
96+
// Verifica che l'impianto esista prima di rimuoverlo
97+
$exists = $dbo->fetchOne('SELECT COUNT(*) as count FROM my_impianti_interventi WHERE idintervento='.prepare($id_record).' AND idimpianto = '.prepare($id_impianto));
10398

104-
break;
99+
if ($exists['count'] == 0) {
100+
throw new Exception(tr('Impianto non trovato nell\'intervento'));
101+
}
102+
103+
$result = $dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record).' AND idimpianto = '.prepare($id_impianto));
104+
105+
// Verifica che l'eliminazione sia avvenuta
106+
$remaining = $dbo->fetchOne('SELECT COUNT(*) as count FROM my_impianti_interventi WHERE idintervento='.prepare($id_record).' AND idimpianto = '.prepare($id_impianto));
107+
if ($remaining['count'] > 0) {
108+
throw new Exception(tr('Errore durante l\'eliminazione dell\'impianto dal database'));
109+
}
110+
Check::deleteLinked([
111+
'id_module' => $id_module,
112+
'id_record' => $id_record,
113+
'id_module_from' => $id_modulo_impianti,
114+
'id_record_from' => $id_impianto,
115+
]);
116+
117+
$components = $dbo->fetchArray('SELECT * FROM my_componenti WHERE id_impianto = '.prepare($id_impianto));
118+
if (!empty($components)) {
119+
foreach ($components as $component) {
120+
$dbo->query('DELETE FROM my_componenti_interventi WHERE id_componente = '.prepare($component['id']).' AND id_intervento = '.prepare($id_record));
121+
}
122+
}
123+
124+
flash()->info(tr('Impianto rimosso correttamente!'));
125+
126+
// Risposta JSON per il client
127+
$response = ['status' => 'success', 'message' => tr('Impianto rimosso correttamente!')];
128+
} catch (Exception $e) {
129+
flash()->error(tr('Errore durante la rimozione dell\'impianto: _MSG_', [
130+
'_MSG_' => $e->getMessage(),
131+
]));
132+
133+
// Risposta JSON di errore per il client
134+
$response = ['status' => 'error', 'message' => $e->getMessage()];
135+
}
136+
137+
// Invia la risposta JSON se è stata impostata
138+
if (isset($response)) {
139+
header('Content-Type: application/json');
140+
echo json_encode($response);
141+
}
105142

106143
case 'load_checklist':
107144
$checks = Check::where('id_module_from', $id_modulo_impianti)->where('id_record_from', post('id_impianto'))->where('id_module', $id_module)->where('id_record', $id_record)->where('id_parent', null)->get();

plugins/impianti_intervento/edit.php

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,44 @@
4646
$sedi = $dbo->fetchArray('SELECT id, nomesede, citta FROM an_sedi WHERE idanagrafica='.prepare($record['idanagrafica'])." UNION SELECT 0, 'Sede legale', '' ORDER BY id");
4747

4848
echo '
49-
<div class="row">
50-
<div class="offset-md-4 col-md-4">
51-
<input type="text" class="form-control form-control-lg text-center unblockable" id="input-cerca" placeholder="'.tr('Cerca').'...">
52-
</div>
53-
54-
<div class="col-md-1">
55-
<button type="button" class="btn btn-lg btn-primary" onclick="caricaImpianti()">
56-
<i class="fa fa-search"></i> '.tr('Cerca').'
57-
</button>
58-
</div>
49+
<div class="card card-outline card-primary shadow mb-4">
50+
<div class="card-header">
51+
<h3 class="card-title">
52+
<i class="fa fa-cogs text-primary mr-2"></i>
53+
'.tr('Gestione Impianti').'
54+
</h3>
5955
</div>
60-
61-
<div class="row">
62-
<div class="col-md-4">
63-
{[ "type": "select", "name": "id_impianto_add", "label": "'.tr('Impianto').'", "ajax-source": "impianti-cliente", "select-options": {"idanagrafica": '.$record['idanagrafica'].', "idsede_destinazione": '.($record['idsede_destinazione'] ?: '0').', "idintervento": '.$id_record.', "idcontratto": "'.$record['idcontratto'].'"}, "extra": "'.$readonly.'", "icon-after": "add|'.$id_modulo_impianti.'|id_anagrafica='.$record['idanagrafica'].'" ]}
64-
</div>
65-
66-
<div class="col-md-3" style="margin-top: 25px">
67-
<button title="'.tr('Aggiungi impianto all\'attività').'" class="btn btn-default tip" type="button" onclick="addImpianto()" '.$disabled.'>
68-
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
69-
</button>
56+
<div class="card-body">
57+
<div class="row align-items-center">
58+
<div class="col-md-4">
59+
<label class="control-label">'.tr('Seleziona Impianto').'</label>
60+
<div style="margin-top: 5px;">
61+
{[ "type": "select", "name": "id_impianto_add", "ajax-source": "impianti-cliente", "select-options": {"idanagrafica": '.$record['idanagrafica'].', "idsede_destinazione": '.($record['idsede_destinazione'] ?: '0').', "idintervento": '.$id_record.', "idcontratto": "'.$record['idcontratto'].'"}, "extra": "'.$readonly.'", "icon-after": "add|'.$id_modulo_impianti.'|id_anagrafica='.$record['idanagrafica'].'" ]}
62+
</div>
63+
</div>
64+
65+
<div class="col-md-2">
66+
<button title="'.tr('Aggiungi impianto all\'attività').'" class="btn btn-success btn-block tip" type="button" onclick="addImpianto()" '.$disabled.' style="margin-top: 25px;">
67+
<i class="fa fa-plus mr-1"></i> '.tr('Aggiungi').'
68+
</button>
69+
</div>
70+
<div class="col-md-2">
71+
72+
</div>
73+
<div class="col-md-4">
74+
<label class="control-label">'.tr('Cerca negli impianti collegati').'</label>
75+
<div class="input-group">
76+
<input type="text" class="form-control unblockable" id="input-cerca" placeholder="'.tr('Matricola o nome').'...">
77+
<div class="input-group-append">
78+
<button type="button" class="btn btn-outline-primary" onclick="caricaImpianti()">
79+
<i class="fa fa-search"></i>
80+
</button>
81+
</div>
82+
</div>
83+
</div>
7084
</div>
71-
</div>';
85+
</div>
86+
</div>';
7287

7388
// IMPIANTI
7489
echo '
@@ -84,11 +99,11 @@ function toggleDettagli(trigger) {
8499
85100
if (dettagli.css("display") === "none"){
86101
dettagli.show(500);
87-
$(trigger).children().removeClass("fa-plus");
102+
$(trigger).children().removeClass("fa-plus");
88103
$(trigger).children().addClass("fa-minus");
89104
} else {
90105
dettagli.hide(500);
91-
$(trigger).children().removeClass("fa-minus");
106+
$(trigger).children().removeClass("fa-minus");
92107
$(trigger).children().addClass("fa-plus");
93108
}
94109
}

0 commit comments

Comments
 (0)