openstamanager/modules/ddt/init.php

57 lines
2.2 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
* Copyright (C) DevCode s.n.c.
*
* 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';
2019-02-14 17:49:58 +01:00
use Modules\DDT\DDT;
2019-06-20 17:35:16 +02:00
if ($module['name'] == 'Ddt di vendita') {
$dir = 'entrata';
} else {
$dir = 'uscita';
}
if (isset($id_record)) {
2019-02-14 17:49:58 +01:00
$ddt = DDT::with('tipo', 'stato')->find($id_record);
2020-09-07 15:04:06 +02:00
$record = $dbo->fetchOne('SELECT dt_ddt.*,
dt_ddt.id AS idddt,
dt_statiddt.descrizione AS `stato`,
dt_statiddt.completato AS `flag_completato`,
dt_tipiddt.descrizione AS `descrizione_tipodoc`,
an_anagrafiche.tipo AS tipo_anagrafica
2018-10-26 19:39:34 +02:00
FROM dt_ddt
2019-07-22 16:13:38 +02:00
LEFT OUTER JOIN dt_statiddt ON dt_ddt.idstatoddt=dt_statiddt.id
INNER JOIN an_anagrafiche ON dt_ddt.idanagrafica=an_anagrafiche.idanagrafica
INNER JOIN dt_tipiddt ON dt_ddt.idtipoddt=dt_tipiddt.id
2018-10-26 19:39:34 +02: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)) {
$record['idporto'] = $record['idporto'] ?: $dbo->fetchOne('SELECT id FROM dt_porto WHERE predefined = 1')['id'];
$record['idcausalet'] = $record['idcausalet'] ?: $dbo->fetchOne('SELECT id FROM dt_causalet WHERE predefined = 1')['id'];
$record['idspedizione'] = $record['idspedizione'] ?: $dbo->fetchOne('SELECT id FROM dt_spedizione WHERE predefined = 1')['id'];
}
// Se la sede del ddt non è di mia competenza, blocco il ddt in modifica
$field_name = ($dir == 'entrata') ? 'idsede_partenza' : 'idsede_destinazione';
if (!Auth::admin() && !in_array($record[$field_name], $user->sedi)) {
$record['flag_completato'] = 1;
}
}