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';
|
|
|
|
|
2021-07-20 10:01:59 +02:00
|
|
|
use Modules\Anagrafiche\Anagrafica;
|
2019-02-14 17:49:58 +01:00
|
|
|
use Modules\DDT\DDT;
|
|
|
|
|
2021-07-20 10:01:59 +02:00
|
|
|
$azienda = Anagrafica::find(setting('Azienda predefinita'));
|
|
|
|
|
2024-04-22 16:51:27 +02:00
|
|
|
$module_name = $module ? $module->name : '';
|
2024-03-26 17:22:40 +01:00
|
|
|
|
2024-06-13 09:31:40 +02:00
|
|
|
if ($module_name == 'Ddt in entrata') {
|
2019-06-20 17:35:16 +02:00
|
|
|
$dir = 'uscita';
|
2024-03-26 17:22:40 +01:00
|
|
|
} else {
|
|
|
|
$dir = 'entrata';
|
2019-06-20 17:35:16 +02:00
|
|
|
}
|
|
|
|
|
2024-04-12 16:59:19 +02:00
|
|
|
if (!empty($id_record)) {
|
2024-04-23 12:01:59 +02:00
|
|
|
$ddt = DDT::find($id_record);
|
2019-01-01 11:39:20 +01:00
|
|
|
|
2024-03-28 12:10:13 +01:00
|
|
|
$record = $dbo->fetchOne('SELECT
|
|
|
|
`dt_ddt`.*,
|
2024-02-27 12:55:27 +01:00
|
|
|
`dt_ddt`.`id` AS idddt,
|
2024-04-18 17:44:05 +02:00
|
|
|
`dt_statiddt_lang`.`title` AS `stato`,
|
2024-02-27 12:55:27 +01:00
|
|
|
`dt_statiddt`.`completato` AS `flag_completato`,
|
2024-04-18 17:44:05 +02:00
|
|
|
`dt_tipiddt_lang`.`title` AS `descrizione_tipodoc`,
|
2024-02-27 12:55:27 +01:00
|
|
|
`an_anagrafiche`.`tipo` AS tipo_anagrafica
|
|
|
|
FROM `dt_ddt`
|
2024-04-23 12:01:59 +02:00
|
|
|
INNER JOIN `dt_statiddt` ON `dt_ddt`.`idstatoddt`=`dt_statiddt`.`id`
|
2024-03-22 15:52:24 +01:00
|
|
|
LEFT JOIN `dt_statiddt_lang` ON (`dt_statiddt_lang`.`id_record` = `dt_statiddt`.`id` AND `dt_statiddt_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
|
2024-02-27 12:55:27 +01:00
|
|
|
INNER JOIN `an_anagrafiche` ON `dt_ddt`.`idanagrafica`=`an_anagrafiche`.`idanagrafica`
|
|
|
|
INNER JOIN `dt_tipiddt` ON `dt_ddt`.`idtipoddt`=`dt_tipiddt`.`id`
|
2024-03-22 15:52:24 +01:00
|
|
|
LEFT JOIN `dt_tipiddt_lang` ON (`dt_tipiddt_lang`.`id_record` = `dt_tipiddt`.`id` AND `dt_tipiddt_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
|
2024-02-27 12:55:27 +01:00
|
|
|
WHERE
|
|
|
|
`dt_ddt`.`id`='.prepare($id_record));
|
2018-09-26 10:49:38 +02:00
|
|
|
|
2018-10-26 19:39:34 +02:00
|
|
|
if (!empty($record)) {
|
2024-02-27 11:29:48 +01:00
|
|
|
$record['idporto'] = $record['idporto'] ?: $dbo->fetchOne('SELECT `id` FROM `dt_porto` WHERE `predefined` = 1')['id'];
|
2024-02-27 11:10:40 +01:00
|
|
|
$record['idcausalet'] = $record['idcausalet'] ?: $dbo->fetchOne('SELECT `id` FROM `dt_causalet` WHERE `predefined` = 1')['id'];
|
2024-02-27 11:29:48 +01:00
|
|
|
$record['idspedizione'] = $record['idspedizione'] ?: $dbo->fetchOne('SELECT `id` FROM `dt_spedizione` WHERE `predefined` = 1')['id'];
|
2018-10-26 19:39:34 +02:00
|
|
|
}
|
2019-06-20 16:44:45 +02:00
|
|
|
|
|
|
|
// Se la sede del ddt non è di mia competenza, blocco il ddt in modifica
|
2019-06-29 11:01:26 +02:00
|
|
|
$field_name = ($dir == 'entrata') ? 'idsede_partenza' : 'idsede_destinazione';
|
2019-07-29 16:54:20 +02:00
|
|
|
if (!Auth::admin() && !in_array($record[$field_name], $user->sedi)) {
|
2019-06-20 16:44:45 +02:00
|
|
|
$record['flag_completato'] = 1;
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|