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
* 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 />.
*/
2017-08-04 16:28:16 +02:00
2020-07-08 10:40:04 +02:00
use Modules\Fatture\Fattura ;
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2017-09-05 17:31:58 +02:00
if ( $module [ 'name' ] == 'Fatture di vendita' ) {
$dir = 'entrata' ;
} else {
$dir = 'uscita' ;
}
2017-08-04 16:28:16 +02:00
if ( isset ( $id_record )) {
2020-07-08 10:40:04 +02:00
$fattura = Fattura :: with ( 'tipo' , 'stato' ) -> find ( $id_record );
2020-09-08 11:38:25 +02:00
$dir = $fattura -> direzione ;
2018-08-09 10:14:26 +02:00
2020-02-14 17:02:16 +01:00
$is_fiscale = false ;
if ( ! empty ( $fattura )) {
$is_fiscale = $fattura -> isFiscale ();
}
2019-07-23 16:12:46 +02:00
$record = $dbo -> fetchOne ( ' SELECT co_documenti .* ,
2018-11-23 16:48:30 +01:00
co_tipidocumento . reversed AS is_reversed ,
co_documenti . idagente AS idagente_fattura ,
co_documenti . note ,
co_documenti . note_aggiuntive ,
co_documenti . idpagamento ,
co_documenti . id AS iddocumento ,
2019-01-03 18:54:09 +01:00
co_documenti . split_payment AS split_payment ,
2018-11-23 16:48:30 +01:00
co_statidocumento . descrizione AS `stato` ,
2020-09-08 11:38:25 +02:00
co_tipidocumento . descrizione AS `descrizione_tipo` ,
2019-07-31 18:22:35 +02:00
co_pagamenti . riba AS `riba` ,
2018-11-23 16:48:30 +01:00
( SELECT is_fiscale FROM zz_segments WHERE id = id_segment ) AS is_fiscale ,
( SELECT descrizione FROM co_ritenutaacconto WHERE id = idritenutaacconto ) AS ritenutaacconto_desc ,
2019-01-22 15:52:22 +01:00
( SELECT descrizione FROM co_rivalse WHERE id = idrivalsainps ) AS rivalsainps_desc ,
2018-11-23 16:48:30 +01:00
( SELECT descrizione FROM dt_causalet WHERE id = idcausalet ) AS causale_desc
FROM co_documenti
LEFT OUTER JOIN co_statidocumento ON co_documenti . idstatodocumento = co_statidocumento . id
INNER JOIN an_anagrafiche ON co_documenti . idanagrafica = an_anagrafiche . idanagrafica
INNER JOIN co_tipidocumento ON co_documenti . idtipodocumento = co_tipidocumento . id
2019-04-11 16:04:08 +02:00
LEFT JOIN co_pagamenti ON co_documenti . idpagamento = co_pagamenti . id
2018-11-23 16:48:30 +01:00
WHERE co_tipidocumento . dir = '.prepare($dir).' AND co_documenti . id = ' . prepare ( $id_record ));
2018-07-04 12:57:53 +02:00
2020-09-08 11:38:25 +02:00
// Note di credito collegate
2018-07-04 12:57:53 +02:00
$note_accredito = $dbo -> fetchArray ( " SELECT co_documenti.id, IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM co_documenti JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE reversed = 1 AND ref_documento= " . prepare ( $id_record ));
2020-09-08 11:38:25 +02:00
// Blocco gestito dallo stato della Fattura Elettronica
$stato_fe = $database -> fetchOne ( 'SELECT * FROM fe_stati_documento WHERE codice = ' . prepare ( $fattura -> codice_stato_fe ));
$abilita_genera = empty ( $fattura -> codice_stato_fe ) || intval ( $stato_fe [ 'is_generabile' ]);
2017-08-04 16:28:16 +02:00
}