2017-08-04 16:28:16 +02:00
|
|
|
<?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/>.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
2023-12-04 11:59:42 +01:00
|
|
|
use Modules\Anagrafiche\Sede;
|
2024-09-09 12:28:32 +02:00
|
|
|
use Modules\Anagrafiche\Anagrafica;
|
2023-12-04 11:59:42 +01:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
$operazione = filter('op');
|
|
|
|
|
|
|
|
switch ($operazione) {
|
|
|
|
case 'addsede':
|
2023-12-04 11:59:42 +01:00
|
|
|
if (!empty(post('nomesede'))) {
|
2024-05-30 10:53:28 +02:00
|
|
|
$opt_out_newsletter = post('disable_newsletter_add');
|
2024-09-02 17:10:22 +02:00
|
|
|
$sede = Sede::build(Anagrafica::find($id_parent));
|
|
|
|
|
|
|
|
$sede->nomesede = post('nomesede');
|
|
|
|
$sede->indirizzo = post('indirizzo');
|
|
|
|
$sede->citta = post('citta');
|
|
|
|
$sede->cap = post('cap');
|
|
|
|
$sede->provincia = strtoupper(post('provincia'));
|
|
|
|
$sede->km = post('km');
|
|
|
|
$sede->id_nazione = !empty(post('id_nazione')) ? post('id_nazione') : null;
|
|
|
|
$sede->idzona = !empty(post('idzona')) ? post('idzona') : 0;
|
|
|
|
$sede->cellulare = post('cellulare');
|
|
|
|
$sede->telefono = post('telefono');
|
|
|
|
$sede->email = post('email');
|
|
|
|
$sede->enable_newsletter = empty($opt_out_newsletter);
|
|
|
|
$sede->codice_destinatario = post('codice_destinatario');
|
|
|
|
$sede->is_automezzo = post('is_automezzo');
|
|
|
|
$sede->is_rappresentante_fiscale = post('is_rappresentante_fiscale');
|
|
|
|
$sede->targa = post('targa');
|
|
|
|
$sede->nome = post('nome');
|
|
|
|
$sede->descrizione = post('descrizione');
|
|
|
|
$sede->save();
|
|
|
|
|
|
|
|
$id_record = $sede->id;
|
2023-12-04 11:59:42 +01:00
|
|
|
|
|
|
|
$id_referenti = (array) post('id_referenti');
|
|
|
|
foreach ($id_referenti as $id_referente) {
|
|
|
|
$dbo->update('an_referenti', [
|
2024-03-22 15:52:24 +01:00
|
|
|
'idsede' => $id_record,
|
|
|
|
], [
|
|
|
|
'id' => $id_referente,
|
|
|
|
]);
|
2023-12-04 11:59:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'updatesede':
|
2021-09-23 17:55:58 +02:00
|
|
|
$opt_out_newsletter = post('disable_newsletter');
|
2023-12-04 11:59:42 +01:00
|
|
|
$sede = Sede::find($id_record);
|
2021-09-23 17:55:58 +02:00
|
|
|
|
2024-09-02 17:10:22 +02:00
|
|
|
$sede->nomesede = post('nomesede');
|
|
|
|
$sede->indirizzo = post('indirizzo');
|
|
|
|
$sede->citta = post('citta');
|
|
|
|
$sede->cap = post('cap');
|
|
|
|
$sede->provincia = strtoupper(post('provincia'));
|
|
|
|
$sede->km = post('km');
|
|
|
|
$sede->id_nazione = !empty(post('id_nazione')) ? post('id_nazione') : null;
|
|
|
|
$sede->idzona = !empty(post('idzona')) ? post('idzona') : 0;
|
|
|
|
$sede->cellulare = post('cellulare');
|
|
|
|
$sede->telefono = post('telefono');
|
|
|
|
$sede->email = post('email');
|
|
|
|
$sede->enable_newsletter = empty($opt_out_newsletter);
|
|
|
|
$sede->codice_destinatario = post('codice_destinatario');
|
|
|
|
$sede->is_automezzo = post('is_automezzo');
|
|
|
|
$sede->is_rappresentante_fiscale = post('is_rappresentante_fiscale');
|
|
|
|
$sede->targa = post('targa');
|
|
|
|
$sede->nome = post('nome');
|
|
|
|
$sede->descrizione = post('descrizione');
|
|
|
|
$sede->gaddress = post('gaddress');
|
|
|
|
$sede->lat = post('lat');
|
|
|
|
$sede->lng = post('lng');
|
|
|
|
$sede->save();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
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);
|
|
|
|
|
2023-10-06 12:44:54 +02:00
|
|
|
foreach ($id_referenti as $id_referente) {
|
|
|
|
$dbo->update('an_referenti', [
|
2023-10-27 10:35:05 +02:00
|
|
|
'idsede' => $id_record,
|
2023-10-06 12:44:54 +02:00
|
|
|
], [
|
2023-10-27 10:35:05 +02:00
|
|
|
'id' => $id_referente,
|
2023-10-06 12:44:54 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-11-08 16:43:04 +01:00
|
|
|
foreach ($refs as $ref) {
|
|
|
|
$dbo->update('an_referenti', [
|
|
|
|
'idsede' => 0,
|
|
|
|
], [
|
|
|
|
'id' => $ref,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-12-04 11:59:42 +01:00
|
|
|
$sede->save();
|
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Salvataggio completato!'));
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'deletesede':
|
2019-06-11 18:12:00 +02:00
|
|
|
$id = filter('id');
|
|
|
|
$dbo->query('DELETE FROM `an_sedi` WHERE `id` = '.prepare($id).'');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Sede eliminata!'));
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|