openstamanager/plugins/sedi/actions.php

142 lines
5.0 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* 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\Anagrafiche\Sede;
$operazione = filter('op');
switch ($operazione) {
case 'addsede':
if (!empty(post('nomesede'))) {
$opt_out_newsletter = post('disable_newsletter');
$dbo->insert('an_sedi', [
'idanagrafica' => $id_parent,
'nomesede' => post('nomesede'),
'indirizzo' => post('indirizzo'),
'citta' => post('citta'),
'cap' => post('cap'),
'provincia' => strtoupper(post('provincia')),
'km' => post('km'),
'id_nazione' => !empty(post('id_nazione')) ? post('id_nazione') : null,
'idzona' => !empty(post('idzona')) ? post('idzona') : 0,
'cellulare' => post('cellulare'),
'telefono' => post('telefono'),
'email' => post('email'),
'enable_newsletter' => empty($opt_out_newsletter),
'codice_destinatario' => post('codice_destinatario'),
'is_automezzo' => post('is_automezzo'),
'is_rappresentante_fiscale' => post('is_rappresentante_fiscale'),
'targa' => post('targa'),
'nome' => post('nome'),
'descrizione' => post('descrizione'),
]);
$id_record = $dbo->lastInsertedID();
$id_referenti = (array) post('id_referenti');
foreach ($id_referenti as $id_referente) {
$dbo->update('an_referenti', [
'idsede' => $id_record,
], [
'id' => $id_referente,
]);
}
if (isAjaxRequest() && !empty($id_record)) {
echo json_encode(['id' => $id_record, 'text' => post('nomesede').' - '.post('citta')]);
}
flash()->info(tr('Aggiunta una nuova sede!'));
} else {
flash()->warning(tr('Errore durante aggiunta della sede'));
}
2023-12-06 15:06:49 +01:00
2023-12-04 12:31:55 +01:00
$sede = Sede::find($id_record);
$sede->save();
break;
case 'updatesede':
$opt_out_newsletter = post('disable_newsletter');
$sede = Sede::find($id_record);
2020-03-06 16:27:02 +01:00
$dbo->update('an_sedi', [
2018-07-19 15:33:32 +02:00
'nomesede' => post('nomesede'),
'indirizzo' => post('indirizzo'),
'citta' => post('citta'),
'cap' => post('cap'),
2019-01-03 15:24:21 +01:00
'provincia' => strtoupper(post('provincia')),
'id_nazione' => !empty(post('id_nazione')) ? post('id_nazione') : null,
2018-07-19 15:33:32 +02:00
'telefono' => post('telefono'),
'cellulare' => post('cellulare'),
2018-07-19 15:33:32 +02:00
'email' => post('email'),
'enable_newsletter' => empty($opt_out_newsletter),
'codice_destinatario' => post('codice_destinatario'),
'is_rappresentante_fiscale' => post('is_rappresentante_fiscale'),
'piva' => post('piva'),
'codice_fiscale' => post('codice_fiscale'),
'is_automezzo' => post('is_automezzo'),
2018-07-19 15:33:32 +02:00
'idzona' => post('idzona'),
'km' => post('km'),
'note' => post('note'),
2018-07-19 15:33:32 +02:00
'gaddress' => post('gaddress'),
'lat' => post('lat'),
'lng' => post('lng'),
'targa' => post('targa'),
'nome' => post('nome'),
'descrizione' => post('descrizione'),
2020-03-06 16:27:02 +01:00
], ['id' => $id_record]);
2023-11-08 16:43:04 +01:00
$referenti = $dbo->fetchArray('SELECT id FROM an_referenti WHERE idsede = '.$id_record);
2023-10-27 10:35:05 +02:00
$id_referenti = (array) post('id_referenti');
2023-11-08 16:43:04 +01:00
$refs = array_diff($referenti, $id_referenti);
foreach ($id_referenti as $id_referente) {
$dbo->update('an_referenti', [
2023-10-27 10:35:05 +02:00
'idsede' => $id_record,
], [
2023-10-27 10:35:05 +02:00
'id' => $id_referente,
]);
}
2023-11-08 16:43:04 +01:00
foreach ($refs as $ref) {
$dbo->update('an_referenti', [
'idsede' => 0,
], [
'id' => $ref,
]);
}
$sede->save();
2018-07-19 17:29:21 +02:00
flash()->info(tr('Salvataggio completato!'));
break;
case 'deletesede':
2019-06-11 18:12:00 +02:00
$id = filter('id');
$dbo->query('DELETE FROM `an_sedi` WHERE `id` = '.prepare($id).'');
2018-07-19 17:29:21 +02:00
flash()->info(tr('Sede eliminata!'));
break;
}