openstamanager/templates/fatturato/init.php

45 lines
2.0 KiB
PHP
Raw Normal View History

2020-03-14 14:32:47 +01: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/>.
*/
2020-03-14 14:32:47 +01:00
include_once __DIR__.'/../../core.php';
$dir = get('dir');
$date_start = $_SESSION['period_start'];
$date_end = $_SESSION['period_end'];
// Raggruppamento
2023-05-15 10:52:54 +02:00
$raggruppamenti = $dbo->fetchArray('
SELECT
2023-05-22 11:51:23 +02:00
data_competenza,
2023-05-15 10:52:54 +02:00
DATE_FORMAT(data_competenza, \'%m-%Y\') AS periodo,
2023-05-22 11:51:23 +02:00
SUM((subtotale-sconto+co_righe_documenti.rivalsainps) *percentuale/100 *(100-indetraibile)/100 *(IF(co_tipidocumento.reversed = 0, 1,-1 ))) AS iva,
2023-05-15 10:52:54 +02:00
SUM((co_righe_documenti.subtotale - co_righe_documenti.sconto + co_righe_documenti.rivalsainps) *(IF(co_tipidocumento.reversed = 0,1,-1))) AS imponibile
FROM
co_iva
INNER JOIN co_righe_documenti ON co_righe_documenti.idiva = co_iva.id
INNER JOIN co_documenti ON co_documenti.id = co_righe_documenti.iddocumento
INNER JOIN co_tipidocumento ON co_tipidocumento.id = co_documenti.idtipodocumento
WHERE
co_tipidocumento.dir = '.prepare($dir).' AND co_righe_documenti.is_descrizione = 0 AND idstatodocumento NOT IN(SELECT id FROM co_statidocumento WHERE descrizione = "Bozza" OR descrizione = "Annullata") AND co_documenti.data_competenza >= '.prepare($date_start).' AND co_documenti.data_competenza <= '.prepare($date_end).'
GROUP BY
2023-05-22 11:51:23 +02:00
periodo
ORDER BY
periodo ASC');