Migliorie plugin Impianti

This commit is contained in:
MatteoPistorello 2024-03-05 17:31:36 +01:00
parent 791d1431f4
commit c05cb17fb0
6 changed files with 561 additions and 1 deletions

View File

@ -49,6 +49,11 @@ switch ($resource) {
$where[] = 'my_impianti.idsede='.prepare($superselect['idsede_destinazione'] ?: 0);
}
if (!empty($superselect['idintervento'])) {
$where[] = 'my_impianti.id NOT IN(SELECT idimpianto FROM my_impianti_interventi WHERE idintervento='.prepare($superselect['idintervento']).')';
}
if (!empty($search)) {
$search_fields[] = 'my_impianti.nome LIKE '.prepare('%'.$search.'%');
$search_fields[] = 'my_impianti.matricola LIKE '.prepare('%'.$search.'%');

View File

@ -0,0 +1,93 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
use Modules\Checklists\Check;
$operazione = filter('op');
switch ($operazione) {
case 'add_impianto':
if (post('id_impianto')) {
$dbo->query('INSERT INTO my_impianti_interventi(idimpianto, idintervento) VALUES('.prepare(post('id_impianto')).', '.prepare($id_record).')');
$checks_impianti = $dbo->fetchArray('SELECT * FROM zz_checks WHERE id_module = '.prepare(Modules::get('Impianti')['id']).' AND id_record = '.prepare(post('id_impianto')));
foreach ($checks_impianti as $check_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'], Modules::get('Impianti')['id'], post('id_impianto'));
$check->id_module = $id_module;
$check->id_plugin = $id_plugin;
$check->note = $check_impianto['note'];
$check->save();
}
flash()->info(tr('Impianto aggiunto correttamente!'));
} else {
flash()->warning(tr('Selezionare un impianto!'));
}
break;
case 'update_impianto':
$components = (array) post('componenti');
$note = post('note');
$id_impianto = post('id_impianto');
$dbo->query('DELETE FROM my_componenti_interventi WHERE id_componente IN (SELECT id FROM my_componenti WHERE id_impianto = '.prepare($id_impianto).') AND id_intervento = '.prepare($id_record));
foreach ($components as $component) {
$dbo->query('INSERT INTO my_componenti_interventi(id_componente, id_intervento) VALUES ('.prepare($component).', '.prepare($id_record).')');
}
$dbo->update('my_impianti_interventi', [
'note' => $note
], [
'idintervento' => $id_record,
'idimpianto' => $id_impianto
]);
flash()->info(tr('Impianto modificato correttamente!'));
break;
case 'delete_impianto':
$dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record).' AND idimpianto = '.prepare(post('id')));
Check::deleteLinked([
'id_module' => $id_module,
'id_record' => $id_record,
'id_module_from' => Modules::get('Impianti')['id'],
'id_record_from' => post('id'),
]);
$components = $dbo->fetchArray('SELECT * FROM my_componenti WHERE id_impianto = '.prepare($matricola));
if (!empty($components)) {
foreach ($components as $component) {
$dbo->query('DELETE FROM my_componenti_interventi WHERE id_componente = '.prepare($component['id']).' AND id_intervento = '.prepare($id_record));
}
}
flash()->info(tr('Impianto rimosso correttamente!'));
break;
}

View File

@ -0,0 +1,148 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
use Modules\Checklists\Check;
$modulo_impianti = Modules::get('Impianti');
// Blocco della modifica impianti se l'intervento è completato
$dati_intervento = $dbo->fetchArray('SELECT `in_statiintervento`.`is_completato` FROM `in_statiintervento` INNER JOIN `in_interventi` ON `in_statiintervento`.`id` = `in_interventi`.`idstatointervento` WHERE `in_interventi`.`id`='.prepare($id_record));
$is_completato = $dati_intervento[0]['is_completato'];
if ($is_completato) {
$readonly = 'readonly';
$disabled = 'disabled';
} else {
$readonly = '';
$disabled = '';
}
/*
* Aggiunta impianti all'intervento
*/
// Elenco impianti collegati all'intervento
$impianti = $dbo->fetchArray('SELECT idimpianto FROM my_impianti_interventi WHERE idintervento='.prepare($id_record));
$impianti = !empty($impianti) ? array_column($impianti, 'idimpianto') : [];
// Elenco sedi
$sedi = $dbo->fetchArray('SELECT id, nomesede, citta FROM an_sedi WHERE idanagrafica='.prepare($record['idanagrafica'])." UNION SELECT 0, 'Sede legale', '' ORDER BY id");
echo '
<div class="row">
<div class="col-md-offset-4 col-md-4">
<input type="text" class="form-control input-lg text-center unblockable" id="input-cerca" placeholder="'.tr('Cerca').'...">
</div>
<div class="col-md-1">
<button type="button" class="btn btn-lg btn-primary" onclick="caricaImpianti()">
<i class="fa fa-search"></i> '.tr('Cerca').'
</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
{[ "type": "select", "name": "id_impianto_add", "label": "'.tr('Impianto').'", "ajax-source": "impianti-cliente", "select-options": {"idanagrafica": '.$record['idanagrafica'].', "idsede_destinazione": '.($record['idsede_destinazione'] ?: '""').', "idintervento": '.$id_record.'}, "extra": "'.$readonly.'", "icon-after": "add|'.$modulo_impianti['id'].'|id_anagrafica='.$record['idanagrafica'].'" ]}
</div>
<div class="col-md-3" style="margin-top: 25px">
<button title="'.tr('Aggiungi impianto all\'attività').'" class="btn btn-default tip" type="button" onclick="addImpianto()" '.$disabled.'>
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
</button>
</div>
</div>';
if (!empty($impianti)) {
// IMPIANTI
echo '
<div class="row">
<div class="col-md-12" id="righe-impianti"></div>
</div>';
} else {
echo '
<div class="alert alert-info text-center">
<i class="fa fa-info-circle"></i> '.tr('Nessun impianto collegato a questo intervento').'
</div>';
}
echo '
<script>
function toggleDettagli(trigger) {
const tr = $(trigger).closest("tr");
const dettagli = tr.next();
if (dettagli.css("display") === "none"){
dettagli.show(500);
$(trigger).children().removeClass("fa-plus");
$(trigger).children().addClass("fa-minus");
} else {
dettagli.hide(500);
$(trigger).children().removeClass("fa-minus");
$(trigger).children().addClass("fa-plus");
}
}
</script>';
echo '
<script>$(document).ready(init)</script>
<script>
$(document).ready(function(){
$("[data-toggle=\'tooltip\']").tooltip();
caricaImpianti();
});
function caricaImpianti() {
let container = $("#righe-impianti");
let search = $("#input-cerca").val();;
localLoading(container, true);
return $.get("'.$structure->fileurl('row-impianti.php').'?id_module='.$id_module.'&id_record='.$id_record.'&id_plugin='.$id_plugin.'&search=" + search, function(data) {
container.html(data);
localLoading(container, false);
});
}
function addImpianto() {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
data: {
id_module: globals.id_module,
id_plugin: '.$id_plugin.',
id_record: globals.id_record,
op: "add_impianto",
id_impianto: input("id_impianto_add").get(),
},
success: function (response) {
renderMessages();
caricaImpianti();
},
error: function() {
renderMessages();
caricaImpianti();
}
});
$("#id_impianto_add").selectReset();
}
</script>';

View File

@ -0,0 +1,307 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
use Modules\Checklists\Check;
$checklist_module = Modules::get('Checklists');
// Blocco della modifica impianti se l'intervento è completato
$dati_intervento = $dbo->fetchArray('SELECT `in_statiintervento`.`is_completato` FROM `in_statiintervento` INNER JOIN `in_interventi` ON `in_statiintervento`.`id` = `in_interventi`.`idstatointervento` WHERE `in_interventi`.`id`='.prepare($id_record));
$is_completato = $dati_intervento[0]['is_completato'];
if ($is_completato) {
$readonly = 'readonly';
$disabled = 'disabled';
} else {
$readonly = '';
$disabled = '';
}
$where = get('search') ? 'AND (my_impianti.matricola LIKE '.prepare('%'.get('search').'%').' OR my_impianti.nome LIKE '.prepare('%'.get('search').'%').')' : '';
$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).' '.$where);
$n_impianti = count($impianti_collegati);
$impianti_non_completati = 0;
$impianti_completati = 0;
$impianti_non_previsti = 0;
foreach ($impianti_collegati as $impianto) {
$checks = Check::where('id_module_from', Modules::get('Impianti')['id'])->where('id_record_from', $impianto['id'])->where('id_module', $id_module)->where('id_record', $id_record)->where('id_parent', null)->get();
if (sizeof($checks)) {
$has_checks_not_verified = $checks->where('checked_at', null)->count();
if ($has_checks_not_verified) {
$impianti_non_completati += 1;
} else {
$impianti_completati += 1;
}
} else {
$impianti_non_previsti += 1;
}
}
$percentuale_completati = $n_impianti ? round(($impianti_completati * 100) / $n_impianti) : 0;
$percentuale_non_completati = $n_impianti ? round(($impianti_non_completati * 100) / $n_impianti) : 0;
$percentuale_non_previsti = $n_impianti ? round(($impianti_non_previsti * 100) / $n_impianti) : 0;
echo '
<div class="row">
<div class="col-md-offset-4 col-md-4 text-center">
<h4>'.strtoupper( tr('Impianti') ).': '.$n_impianti.'</h4>
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-success" role="progressbar" style="width:'.$percentuale_completati.'%"><i class="fa fa-check"></i> <b>'.$impianti_completati.'</b></div>
<div class="progress-bar progress-bar-striped progress-bar-danger" role="progressbar" style="width:'.$percentuale_non_completati.'%"><i class="fa fa-clock-o"></i> <b>'.$impianti_non_completati.'</b></div>
<div class="progress-bar progress-bar-striped progress-bar-warning" role="progressbar" style="width:'.$percentuale_non_previsti.'%"><i class="fa fa-times"></i> <b>'.$impianti_non_previsti.'</b></div>
</div>
</div>
<div class="col-md-4 text-left">
<br><br>
<button type="button" class="btn btn-sm btn-default" onclick="caricaImpianti()">
<i class="fa fa-refresh"></i> '.tr('Aggiorna').'
</button>
</div>
</div>
<table class="table table-hover table-condensed table-striped">
<tr>
<th class="text-center" width="1%"></th>
<th class="text-center" width="10%">'.tr('Matricola').'</th>
<th class="text-center" width="20%">'.tr('Nome').'</th>
<th class="text-center" width="7%">'.tr('Data').'</th>
<th class="text-center">'.tr('Note').'</th>
<th class="text-center" width="25%">'.tr("Componenti soggetti all'intervento").'</th>
<th class="text-center" width="5%">Checklist</th>
<th class="text-center" width="2%"></th>
</tr>';
foreach ($impianti_collegati as $impianto) {
$checks = Check::where('id_module_from', Modules::get('Impianti')['id'])->where('id_record_from', $impianto['id'])->where('id_module', $id_module)->where('id_record', $id_record)->where('id_parent', null)->get();
$type = 'warning';
$class = 'disabled';
$icon = 'circle-o';
$icon2 = 'remove';
if (sizeof($checks)) {
$class = '';
$icon = 'plus';
$checks_not_verified = $checks->where('checked_at', null)->count();
$type = $checks_not_verified ? 'danger' : 'success';
$icon2 = $checks_not_verified ? 'clock-o' : 'check';
}
echo '
<tr data-id="'.$impianto['id'].'">
<td class="text-left">
<button type="button" class="btn btn-xs btn-default '.$class.'" onclick="toggleDettagli(this)">
<i class="fa fa-'.$icon.'"></i>
</button>
</td>
<td>'.$impianto['matricola'].'</td>
<td>'.Modules::link('Impianti', $impianto['id'], $impianto['nome']).'</td>
<td class="text-center">'.Translator::dateToLocale($impianto['data']).'</td>
<td>
{[ "type": "textarea", "name": "note", "id": "note_imp_'.$impianto['id'].'", "value": "'.$impianto['note'].'", "onchange": "updateImpianto($(this).closest(\'tr\').data(\'id\'))", "readonly": "'.!empty($readonly).'", "disabled": "'.!empty($disabled).'" ]}
</td>
<td>';
$inseriti = $dbo->fetchArray('SELECT * FROM my_componenti_interventi WHERE id_intervento = '.prepare($id_record));
$ids = array_column($inseriti, 'id_componente');
echo '
{[ "type": "select", "multiple": 1, "name": "componenti[]", "id": "componenti_imp_'.$impianto['id'].'", "ajax-source": "componenti", "select-options": {"matricola": '.$impianto['id'].'}, "value": "'.implode(',', $ids).'", "onchange": "updateImpianto($(this).closest(\'tr\').data(\'id\'))", "readonly": "'.!empty($readonly).'", "disabled": "'.!empty($disabled).'" ]}
</form>
</td>
<td class="text-center"><i class="fa fa-'.$icon2.' fa-2x text-'.$type.'"></i></td>
<td class="text-center"><button class="btn btn-sm btn-danger '.$disabled.'" onclick="rimuoviImpianto($(this).closest(\'tr\').data(\'id\'))"><i class="fa fa-trash"></i></button></td>
</tr>
<tr style="display: none">
<td colspan="7">
<table class="table">
<tbody class="sort check-impianto" data-sonof="0">';
foreach ($checks as $check) {
echo renderChecklist($check);
}
echo '
</tbody>
</table>
</td>
</tr>';
}
echo '
</table>
<script>
$(document).ready(init);
function rimuoviImpianto(id) {
swal({
title: "'.tr('Rimuovere questo impianto?').'",
html: "'.tr('Sei sicuro di volere rimuovere questo impianto dal documento?').' '.tr("L'operazione è irreversibile").'.",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "json",
data: {
id_module: globals.id_module,
id_record: globals.id_record,
id_plugin: '.$id_plugin.',
op: "delete_impianto",
id: id,
},
success: function (response) {
renderMessages();
caricaImpianti();
},
error: function() {
renderMessages();
caricaImpianti();
}
});
}).catch(swal.noop);
}
function updateImpianto(id) {
var note = $("#note_imp_"+ id).val();
var componenti = $("#componenti_imp_"+ id).val();
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
data: {
id_module: globals.id_module,
id_plugin: '.$id_plugin.',
id_record: globals.id_record,
op: "update_impianto",
id_impianto: id,
note: note,
componenti: componenti
},
success: function (response) {
renderMessages();
},
error: function() {
renderMessages();
}
});
}
sortable("#tab_checks .sort", {
axis: "y",
handle: ".handle",
cursor: "move",
dropOnEmpty: true,
scroll: true,
});
sortable_table = sortable("#tab_checks .sort").length;
for(i=0; i<sortable_table; i++){
sortable("#tab_checks .sort")[i].addEventListener("sortupdate", function(e) {
var sonof = $(this).data("sonof");
let order = $(this).find(".sonof_"+sonof+"[data-id]").toArray().map(a => $(a).data("id"))
$.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "update_position",
order: order.join(","),
});
});
}
$("textarea[name=\'note_checklist\']").keyup(function() {
$(this).parent().parent().parent().find(".save-nota").removeClass("btn-default");
$(this).parent().parent().parent().find(".save-nota").addClass("btn-success");
});
function saveNota(id) {
$.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "save_note",
note: $("#note_" + id).val(),
id: id
}, function() {
alertPush();
$("#note_" + id).parent().parent().parent().find(".save-nota").removeClass("btn-success");
$("#note_" + id).parent().parent().parent().find(".save-nota").addClass("btn-default");
});
}
$(".check-impianto .checkbox").click(function(){
if($(this).is(":checked")){
$.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "save_checkbox",
id: $(this).attr("data-id"),
},function(result){
});
$(this).parent().parent().find(".text").css("text-decoration", "line-through");
parent = $(this).attr("data-id");
$("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){
if(!$(this).is(":checked")){
$(this).click();
}
});
$(this).parent().parent().find(".verificato").removeClass("hidden");
$(this).parent().parent().find(".verificato").text("'.tr('Verificato da _USER_ il _DATE_', [
'_USER_' => $user->username,
'_DATE_' => dateFormat(date('Y-m-d')).' '.date('H:i'),
]).'");
}else{
$.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "remove_checkbox",
id: $(this).attr("data-id"),
},function(result){
});
$(this).parent().parent().find(".text").css("text-decoration", "none");
parent = $(this).attr("data-id");
$("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){
if($(this).is(":checked")){
$(this).click();
}
});
$(this).parent().parent().find(".verificato").addClass("hidden");
}
})
function delete_check(id){
if(confirm("Eliminare questa checklist?")){
$.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "delete_check",
id: id,
}, function(){
location.reload();
});
}
}
function edit_check(id){
launch_modal("Modifica checklist", "'.$checklist_module->fileurl('components/edit-check.php').'?id_record="+id, 1);
}
</script>';

View File

@ -5,6 +5,7 @@ include __DIR__.'/../config.inc.php';
// File e cartelle deprecate
$files = [
'assets/src/js/wacom/sigCaptDialog/libs/',
'modules/impianti/plugins/'
];
foreach ($files as $key => $value) {

View File

@ -1922,4 +1922,10 @@ WHERE
HAVING
2=2
ORDER BY
`id`, `nome` ASC' WHERE `zz_modules`.`id` = (SELECT `id_record` FROM `zz_modules_lang` WHERE `name` = 'Utenti e permessi');
`id`, `nome` ASC' WHERE `zz_modules`.`id` = (SELECT `id_record` FROM `zz_modules_lang` WHERE `name` = 'Utenti e permessi');
-- Aggiunte note in impianto-intervento
ALTER TABLE `my_impianti_interventi` ADD `note` TEXT NOT NULL AFTER `idimpianto`;
-- Aggiornato plugin Impianti
UPDATE `zz_plugins` SET `script` = '', `directory` = 'impianti_intervento', `options` = 'custom' WHERE `zz_plugins`.`id` = (SELECT `id_record` FROM `zz_plugins_lang` WHERE `name` = 'Impianti');