1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-02 17:07:01 +01:00

Aggiunta azione di gruppo Firma interventi

This commit is contained in:
MatteoPistorello 2023-03-31 17:24:59 +02:00
parent 5f4a04c0ef
commit 55ad1d1a1e
3 changed files with 452 additions and 76 deletions

View File

@ -762,6 +762,99 @@ switch (post('op')) {
break;
case 'firma_bulk':
if (directory(base_dir().'/files/interventi')) {
$firmati = 0;
$non_firmati = 0;
$id_records = filter('records') ? explode(';',filter('records')) : null;
if (post('firma_base64') != '') {
foreach ($id_records as $id_record) {
// Salvataggio firma
$firma_file = 'firma_'.time().'.jpg';
$firma_nome = post('firma_nome');
$data = explode(',', post('firma_base64'));
$img = Intervention\Image\ImageManagerStatic::make(base64_decode($data[1]));
$img->resize(680, 202, function ($constraint) {
$constraint->aspectRatio();
});
if (!$img->save(base_dir().'/files/interventi/'.$firma_file)) {
flash()->error(tr('Impossibile creare il file!'));
} elseif ($dbo->query('UPDATE in_interventi SET firma_file='.prepare($firma_file).', firma_data=NOW(), firma_nome = '.prepare($firma_nome).' WHERE id='.prepare($id_record))) {
++$firmati;
$id_stato = setting("Stato dell'attività dopo la firma");
$stato = $dbo->selectOne('in_statiintervento', '*', ['idstatointervento' => $id_stato]);
$intervento = Intervento::find($id_record);
if (!empty($stato)) {
$intervento = Intervento::find($id_record);
$intervento->idstatointervento = $stato['idstatointervento'];
$intervento->save();
}
// Notifica chiusura intervento
if (!empty($stato['notifica'])) {
$template = Template::find($stato['id_email']);
if (!empty($stato['destinatari'])) {
$mail = Mail::build(auth()->getUser(), $template, $id_record);
$mail->addReceiver($stato['destinatari']);
$mail->save();
}
if (!empty($stato['notifica_cliente'])) {
if (!empty($intervento->anagrafica->email)) {
$mail = Mail::build(auth()->getUser(), $template, $id_record);
$mail->addReceiver($intervento->anagrafica->email);
$mail->save();
}
}
if (!empty($stato['notifica_tecnici'])) {
$tecnici_intervento = $dbo->select('in_interventi_tecnici', 'idtecnico', ['idintervento' => $id_record]);
$tecnici_assegnati = $dbo->select('in_interventi_tecnici_assegnati', 'id_tecnico AS idtecnico', ['id_intervento' => $id_record]);
$tecnici = array_unique(array_merge($tecnici_intervento, $tecnici_assegnati), SORT_REGULAR);
foreach ($tecnici as $tecnico) {
$mail_tecnico = $dbo->selectOne('an_anagrafiche', '*', ['idanagrafica' => $tecnico]);
if (!empty($mail_tecnico['email'])) {
$mail = Mail::build(auth()->getUser(), $template, $id_record);
$mail->addReceiver($mail_tecnico['email']);
$mail->save();
}
}
}
}
} else {
++$non_firmati;
}
}
} else {
flash()->error(tr('Errore durante il salvataggio della firma!').tr('La firma risulta vuota').'...');
}
} else {
flash()->error(tr("Non è stato possibile creare la cartella _DIRECTORY_ per salvare l'immagine della firma!", [
'_DIRECTORY_' => '<b>/files/interventi</b>',
]));
}
if (!empty($firmati)) {
flash()->info(tr('_NUM_ interventi firmati correttamente!', [
'_NUM_' => $firmati,
]));
}
if (!empty($non_firmati)) {
flash()->info(tr('_NUM_ interventi non sono stati firmati correttamente!', [
'_NUM_' => $non_firmati,
]));
}
break;
// OPERAZIONI PER AGGIUNTA NUOVA SESSIONE DI LAVORO
case 'add_sessione':
$id_tecnico = post('id_tecnico');

View File

@ -267,103 +267,103 @@ switch (post('op')) {
break;
case 'delete-bulk':
foreach ($id_records as $id) {
$intervento = Intervento::find($id);
try {
// Eliminazione associazioni tra interventi e contratti
$dbo->query('UPDATE co_promemoria SET idintervento = NULL WHERE idintervento='.prepare($id_record));
case 'delete-bulk':
foreach ($id_records as $id) {
$intervento = Intervento::find($id);
try {
// Eliminazione associazioni tra interventi e contratti
$dbo->query('UPDATE co_promemoria SET idintervento = NULL WHERE idintervento='.prepare($id_record));
$intervento->delete();
$intervento->delete();
// Elimino il collegamento al componente
$dbo->query('DELETE FROM my_componenti WHERE id_intervento='.prepare($id_record));
// Elimino il collegamento al componente
$dbo->query('DELETE FROM my_componenti WHERE id_intervento='.prepare($id_record));
// Eliminazione associazione tecnici collegati all'intervento
$dbo->query('DELETE FROM in_interventi_tecnici WHERE idintervento='.prepare($id_record));
// Eliminazione associazione tecnici collegati all'intervento
$dbo->query('DELETE FROM in_interventi_tecnici WHERE idintervento='.prepare($id_record));
// Eliminazione associazione interventi e my_impianti
$dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record));
// Eliminazione associazione interventi e my_impianti
$dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record));
// Elimino anche eventuali file caricati
Uploads::deleteLinked([
'id_module' => $id_module,
'id_record' => $id_record,
]);
// Elimino anche eventuali file caricati
Uploads::deleteLinked([
'id_module' => $id_module,
'id_record' => $id_record,
]);
} catch (InvalidArgumentException $e) {
}
} catch (InvalidArgumentException $e) {
}
}
flash()->info(tr('Interventi eliminati!'));
flash()->info(tr('Interventi eliminati!'));
break;
break;
case 'stampa-riepilogo':
$_SESSION['superselect']['interventi'] = $id_records;
$id_print = Prints::getPrints()['Riepilogo interventi'];
case 'stampa-riepilogo':
$_SESSION['superselect']['interventi'] = $id_records;
$id_print = Prints::getPrints()['Riepilogo interventi'];
redirect(base_path().'/pdfgen.php?id_print='.$id_print.'&tipo='.post('tipo'));
exit();
redirect(base_path().'/pdfgen.php?id_print='.$id_print.'&tipo='.post('tipo'));
exit();
case 'send-mail':
$template = Template::find(post('id_template'));
case 'send-mail':
$template = Template::find(post('id_template'));
$list = [];
foreach ($id_records as $id) {
$intervento = Intervento::find($id);
$id_anagrafica = $intervento->idanagrafica;
// Selezione destinatari e invio mail
if (!empty($template)) {
$creata_mail = false;
$emails = [];
$list = [];
foreach ($id_records as $id) {
$intervento = Intervento::find($id);
$id_anagrafica = $intervento->idanagrafica;
// Aggiungo email anagrafica
if (!empty($intervento->anagrafica->email)) {
$emails[] = $intervento->anagrafica->email;
// Selezione destinatari e invio mail
if (!empty($template)) {
$creata_mail = false;
$emails = [];
// Aggiungo email anagrafica
if (!empty($intervento->anagrafica->email)) {
$emails[] = $intervento->anagrafica->email;
$mail = Mail::build(auth()->getUser(), $template, $id);
$mail->addReceiver($intervento->anagrafica->email);
$creata_mail = true;
}
// Aggiungo email referenti in base alla mansione impostata nel template
$mansioni = $dbo->select('em_mansioni_template', 'idmansione', ['id_template' => $template->id]);
foreach ($mansioni as $mansione) {
$referenti = $dbo->table('an_referenti')->where('idmansione', $mansione['idmansione'])->where('idanagrafica', $id_anagrafica)->where('email', '!=', '')->get();
if (!$referenti->isEmpty() && $creata_mail == false) {
$mail = Mail::build(auth()->getUser(), $template, $id);
$mail->addReceiver($intervento->anagrafica->email);
$creata_mail = true;
}
// Aggiungo email referenti in base alla mansione impostata nel template
$mansioni = $dbo->select('em_mansioni_template', 'idmansione', ['id_template' => $template->id]);
foreach ($mansioni as $mansione) {
$referenti = $dbo->table('an_referenti')->where('idmansione', $mansione['idmansione'])->where('idanagrafica', $id_anagrafica)->where('email', '!=', '')->get();
if (!$referenti->isEmpty() && $creata_mail == false) {
$mail = Mail::build(auth()->getUser(), $template, $id);
$creata_mail = true;
}
foreach ($referenti as $referente) {
if (!in_array($referente->email, $emails)) {
$emails[] = $referente->email;
$mail->addReceiver($referente->email);
}
}
}
if ($creata_mail == true) {
$mail->save();
OperationLog::setInfo('id_email', $mail->id);
OperationLog::setInfo('id_module', $id_module);
OperationLog::setInfo('id_record', $mail->id_record);
OperationLog::build('send-email');
array_push($list, $intervento->codice);
foreach ($referenti as $referente) {
if (!in_array($referente->email, $emails)) {
$emails[] = $referente->email;
$mail->addReceiver($referente->email);
}
}
}
if ($creata_mail == true) {
$mail->save();
OperationLog::setInfo('id_email', $mail->id);
OperationLog::setInfo('id_module', $id_module);
OperationLog::setInfo('id_record', $mail->id_record);
OperationLog::build('send-email');
array_push($list, $intervento->codice);
}
}
if ($list){
flash()->info(tr('Mail inviata per le attività _LIST_ !', [
'_LIST_' => implode(',', $list),
]));
}
break;
}
if ($list){
flash()->info(tr('Mail inviata per le attività _LIST_ !', [
'_LIST_' => implode(',', $list),
]));
}
break;
}
if (App::debug()) {
@ -446,4 +446,14 @@ if (App::debug()) {
],
];
$operations['firma-intervento'] = [
'text' => '<span><i class="fa fa-pencil"></i> '.tr('Firma interventi').'</span>',
'data' => [
'title' => tr('Firma'),
'type' => 'modal',
'origine' => 'interventi',
'url' => $module->fileurl('modals/firma.php'),
],
];
return $operations;

View File

@ -0,0 +1,273 @@
<?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\Interventi\Intervento;
$id_records = explode(';', get('id_records'));
$id_print = setting('Stampa per anteprima e firma');
$template = Prints::get($id_print)['name'];
$interventi_completati = [];
$interventi_firmati = [];
$interventi_da_firmare = [];
$records = [];
foreach ($id_records as $id) {
$intervento = Intervento::find($id);
if ($intervento->stato->is_completato) {
$interventi_completati[] = $id;
} elseif ($intervento->firma_file) {
$interventi_firmati[] = $id;
$records[] = $id;
} else {
$interventi_da_firmare[] = $id;
$records[] = $id;
}
}
echo '
<div class="row">
<div class="col-md-4">
<div class="box box-success">
<div class="box-header">
<h3 class="box-title">'.tr('Interventi da firmare').'</h3>
</div>
<div class="box-body">';
if ($interventi_da_firmare) {
echo '
<table class="table table-hover table-bordered table-condensed">
<thead>
<tr>
<th>'.tr('Interventi').'</th>
<th class="text-center">#</th>
</tr>
</thead>
<tbody>';
foreach ($interventi_da_firmare as $id) {
$intervento = Intervento::find($id);
echo '
<tr>
<td>
'.Modules::link('Interventi', $intervento->id, tr('Intervento num. _NUM_ del _DATE_', [
'_NUM_' => $intervento->codice,
'_DATE_' => Translator::dateToLocale($intervento->inizio),
])).'
</td>
<td class="text-center">
'.Prints::getLink($template, $id, 'btn btn-xs btn-primary', '', 'fa fa-print').'
</td>
<tr>';
}
echo '
</tbody>
</table>';
} else {
echo 'Nessun Intervento..';
}
echo '
</div>
</div>
</div>
<div class="col-md-4">
<div class="box box-warning">
<div class="box-header">
<h3 class="box-title">'.tr('Interventi firmati non completati').'</h3>
</div>
<div class="box-body">';
if ($interventi_firmati) {
echo '
<table class="table table-hover table-bordered table-condensed">
<thead>
<tr>
<th>'.tr('Interventi').'</th>
<th class="text-center">#</th>
</tr>
</thead>
<tbody>';
foreach ($interventi_firmati as $id) {
$intervento = Intervento::find($id);
echo '
<tr>
<td>
'.Modules::link('Interventi', $intervento->id, tr('Intervento num. _NUM_ del _DATE_', [
'_NUM_' => $intervento->codice,
'_DATE_' => Translator::dateToLocale($intervento->inizio),
])).'
</td>
<td class="text-center">
'.Prints::getLink($template, $id, 'btn btn-xs btn-primary', '', 'fa fa-print').'
</td>
<tr>';
}
echo '
</tbody>
</table>';
} else {
echo 'Nessun Intervento..';
}
echo '
</div>
</div>
</div>
<div class="col-md-4">
<div class="box box-danger">
<div class="box-header">
<h3 class="box-title">'.tr('Interventi completati').'</h3>
</div>
<div class="box-body">';
if ($interventi_completati) {
echo '
<table class="table table-hover table-bordered table-condensed">
<thead>
<tr>
<th>'.tr('Interventi').'</th>
<th class="text-center">#</th>
</tr>
</thead>
<tbody>';
foreach ($interventi_completati as $id) {
$intervento = Intervento::find($id);
echo '
<tr>
<td>
'.Modules::link('Interventi', $intervento->id, tr('Intervento num. _NUM_ del _DATE_', [
'_NUM_' => $intervento->codice,
'_DATE_' => Translator::dateToLocale($intervento->inizio),
])).'
</td>
<td class="text-center">
'.Prints::getLink($template, $id, 'btn btn-xs btn-primary', '', 'fa fa-print').'
</td>
<tr>';
}
echo '
</tbody>
</table>
<br>
<div class="alert alert-warning">
<i class="fa fa-warning"></i> '.tr("Questi interventi non verranno firmati").'
</div>';
} else {
echo 'Nessun Intervento..';
}
echo '
</div>
</div>
</div>
</div>';
// HTML per la visualizzazione
echo '
<div id="preview">
<button type="button" class="btn btn-success btn-block btn-lg" id="firma">
<i class="fa fa-pencil"></i> '.tr('Firma').'
</button>
<br>
<div class="clearfix"></div>
</div>';
?>
<form action="" method="post" id="form-firma" class="hide">
<input type="hidden" name="op" value="firma_bulk">
<input type="hidden" name="backto" value="record-list">
<input type="hidden" name="records" value="<?php echo implode(';', $records ?: ''); ?>">
<div class="row">
<div class="col-md-12">
{[ "type": "text", "label": "<?php echo tr('Nome e cognome'); ?>", "name": "firma_nome", "required": 1 ]}
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="signature-pad" class="signature-pad">
<canvas id="canvas" onselectstart="return false"></canvas>
<input type="hidden" name="firma_base64" id="firma_base64" value="">
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-danger" data-action="clear">
<i class="fa fa-eraser"></i> <?php echo tr('Cancella firma'); ?>
</button>
</div>
<div class="col-md-6">
<button type="submit" class="btn btn-success pull-right" data-action="save">
<i class="fa fa-check"></i> <?php echo tr('Salva firma'); ?>
</button>
</div>
</div>
</form>
<div class="clearfix"></div>
<script type="text/javascript">
$(document).ready( function() {
$('#firma').on('click', function() {
$('#preview').addClass('hide');
$('#form-firma').removeClass('hide');
})
var wrapper = document.getElementById("signature-pad"),
clearButton = document.querySelector("[data-action=clear]"),
saveButton = document.querySelector("[data-action=save]"),
canvas = document.getElementById("canvas");
var signaturePad = new SignaturePad(canvas, {
backgroundColor: 'rgb(255,255,255)'
});
function resizeCanvas() {
image_data = signaturePad.toDataURL();
var ratio = Math.max(window.devicePixelRatio || 1, 1);
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
signaturePad.clear();
signaturePad.fromDataURL(image_data);
}
window.addEventListener("resize", resizeCanvas);
$('#firma').click(resizeCanvas);
clearButton.addEventListener("click", function (event) {
signaturePad.clear();
});
saveButton.addEventListener("click", function (event) {
if (signaturePad.isEmpty()) {
alert(globals.translations.signatureMissing);
event.preventDefault();
return;
} else {
image_data = signaturePad.toDataURL("image/jpeg", 100);
$('#firma_base64').val(image_data);
}
});
});
</script>