2019-07-09 16:43:08 +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/>.
|
|
|
|
*/
|
2019-07-09 16:43:08 +02:00
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
$dir = $_GET['dir'];
|
|
|
|
|
2020-07-01 18:33:21 +02:00
|
|
|
$id_sezionale = filter('id_sezionale');
|
2020-07-06 14:16:16 +02:00
|
|
|
$sezionale = $dbo->fetchOne('SELECT name FROM zz_segments WHERE id = '.$id_sezionale)['name'];
|
2020-07-01 18:10:00 +02:00
|
|
|
|
2020-07-02 17:30:09 +02:00
|
|
|
$date_start = filter('date_start');
|
|
|
|
$date_end = filter('date_end');
|
2019-07-09 16:43:08 +02:00
|
|
|
|
2019-07-09 18:29:40 +02:00
|
|
|
$tipo = $dir == 'entrata' ? 'vendite' : 'acquisti';
|
2019-07-09 16:43:08 +02:00
|
|
|
|
|
|
|
$v_iva = [];
|
|
|
|
$v_totale = [];
|
|
|
|
|
|
|
|
$query = 'SELECT *,
|
2020-10-09 18:08:24 +02:00
|
|
|
co_movimenti.id AS idmovimenti, co_documenti.id AS id,
|
|
|
|
IF(numero = "", numero_esterno, numero) AS numero,
|
2020-10-12 16:35:49 +02:00
|
|
|
(SELECT SUM(subtotale - sconto) FROM co_righe_documenti AS righe2 WHERE righe2.iddocumento=co_documenti.id AND righe2.idiva=co_righe_documenti.idiva GROUP BY iddocumento) AS subtotale,
|
|
|
|
(SELECT SUM(subtotale - sconto + iva + rivalsainps - ritenutaacconto) FROM co_righe_documenti AS righe2 WHERE righe2.iddocumento=co_documenti.id AND righe2.idiva=co_righe_documenti.idiva GROUP BY iddocumento) + co_documenti.iva_rivalsainps AS totale,
|
|
|
|
(SELECT SUM(iva) FROM co_righe_documenti AS righe2 WHERE righe2.iddocumento=co_documenti.id AND righe2.idiva=co_righe_documenti.idiva GROUP BY iddocumento) + co_documenti.iva_rivalsainps AS iva,
|
2020-10-09 18:08:24 +02:00
|
|
|
an_anagrafiche.ragione_sociale,
|
|
|
|
an_anagrafiche.codice AS codice_anagrafica
|
|
|
|
FROM co_movimenti
|
|
|
|
INNER JOIN co_documenti ON co_movimenti.iddocumento=co_documenti.id
|
2019-07-09 16:43:08 +02:00
|
|
|
INNER JOIN co_righe_documenti ON co_documenti.id=co_righe_documenti.iddocumento
|
|
|
|
INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id
|
|
|
|
INNER JOIN co_iva ON co_righe_documenti.idiva=co_iva.id
|
|
|
|
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_documenti.idanagrafica
|
2020-09-17 19:02:00 +02:00
|
|
|
WHERE dir = '.prepare($dir).' AND idstatodocumento NOT IN (SELECT id FROM co_statidocumento WHERE descrizione="Bozza" OR descrizione="Annullata") AND is_descrizione = 0 AND co_documenti.data_competenza >= '.prepare($date_start).' AND co_documenti.data_competenza <= '.prepare($date_end).' AND '.((!empty($id_sezionale)) ? 'co_documenti.id_segment = '.prepare($id_sezionale).'' : '1=1').'
|
2019-07-09 16:43:08 +02:00
|
|
|
GROUP BY co_documenti.id, co_righe_documenti.idiva
|
2020-07-01 18:45:41 +02:00
|
|
|
ORDER BY CAST(co_documenti.'.(($dir == 'entrata') ? 'data' : 'numero').' AS '.(($dir == 'entrata') ? 'DATE' : 'UNSIGNED').'), co_documenti.'.(($dir == 'entrata') ? 'numero_esterno' : 'data_competenza');
|
2019-07-09 16:43:08 +02:00
|
|
|
$records = $dbo->fetchArray($query);
|
2019-07-10 11:53:35 +02:00
|
|
|
|
|
|
|
// Sostituzioni specifiche
|
|
|
|
$custom = [
|
|
|
|
'tipo' => $tipo,
|
2020-10-16 08:31:10 +02:00
|
|
|
];
|