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

@ -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>