. */ include_once __DIR__.'/../../core.php'; $date_start = $_SESSION['period_start']; $date_end = $_SESSION['period_end']; // Intestazione tabella per righe echo "

".tr('Spesometro dal _START_ al _END_', [ '_START_' => Translator::dateToLocale($date_start), '_END_' => Translator::dateToLocale($date_end), ], ['upper' => true])."

'; $imponibile = []; $iva = []; $totale = []; $anagrafiche = $dbo->fetchArray('SELECT idanagrafica, piva, ragione_sociale FROM `an_anagrafiche` WHERE `idanagrafica` IN (SELECT DISTINCT `idanagrafica` FROM `co_documenti` WHERE co_documenti.data>='.prepare($date_start).' AND co_documenti.data<='.prepare($date_end).' AND `co_documenti`.`id` IN (SELECT `iddocumento` FROM co_movimenti WHERE primanota = 1)) ORDER BY `ragione_sociale`'); foreach ($anagrafiche as $i => $anagrafica) { $fatture = $dbo->fetchArray('SELECT `co_documenti`.*, `co_tipidocumento`.`descrizione` AS tipo_documento, `co_tipidocumento`.`dir` FROM `co_documenti` JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`idanagrafica` = '.prepare($anagrafica['idanagrafica']).' AND `co_documenti`.`id` IN (SELECT `iddocumento` FROM co_movimenti WHERE primanota = 1) AND co_documenti.data>='.prepare($date_start).' AND co_documenti.data<='.prepare($date_end).' ORDER BY `data`'); $num = 0; foreach ($fatture as $key => $fattura) { $righe = $dbo->fetchArray('SELECT `idiva`, `desc_iva`, SUM(subtotale) - SUM(sconto) AS imponibile, SUM(iva) AS iva, SUM(subtotale) - SUM(sconto) + SUM(iva) AS totale FROM `co_righe_documenti` WHERE iddocumento='.prepare($fattura['id']).' GROUP BY `idiva`, `desc_iva` ORDER BY `idiva`'); $fatture[$key]['righe'] = $righe; $num += count($righe); } $extra = ($i % 2) != 0 ? ' class="row-bg"' : ''; if ($num > 0) { echo ' '; // Partita IVA echo ' '; $count = 0; foreach ($fatture as $fattura) { $descrizione = tr('_DOC_ num. _NUM_ del _DATE_', [ '_DOC_' => $fattura['tipo_documento'], '_NUM_' => !empty($fattura['numero_esterno']) ? $fattura['numero_esterno'] : $fattura['numero'], '_DATE_' => Translator::dateToLocale($fattura['data']), ]); // Documenti replicati per IVA foreach ($fattura['righe'] as $riga) { if ($count != 0) { echo ' '; } ++$count; // Documento echo ' '; // Descrizione IVA echo ' '; // Imponible echo ' '; // IVA echo ' '; // Totale echo ' '; if (empty($iva[$riga['desc_iva']])) { $iva[$riga['desc_iva']] = []; } $imponibile[] = $riga['imponibile']; $iva[$riga['desc_iva']][] = $riga['iva']; $totale[] = $riga['totale']; } } } } echo ' '; // Totale imponibile echo ' '; foreach ($iva as $desc => $values) { $sum = sum($values); // Totale IVA echo ' '; $totale_iva += $sum; } // Totale IVA echo ' '; // TOTALE echo ' '; echo '
".tr('Ragione sociale', [], ['upper' => true])." ".tr('P.Iva', [], ['upper' => true])." ".tr('Documento', [], ['upper' => true])." ".tr('Aliquota', [], ['upper' => true])." ".tr('Imponibile', [], ['upper' => true])." ".tr('IVA', [], ['upper' => true])." ".tr('Totale', [], ['upper' => true]).'
'.$anagrafica['ragione_sociale'].' '.$anagrafica['piva'].' '.$descrizione.' '.$riga['desc_iva'].' '.moneyFormat($riga['imponibile']).' '.moneyFormat($riga['iva']).' '.moneyFormat($riga['totale']).'
'.tr('Imponibile', [], ['upper' => true]).': '.moneyFormat(sum($imponibile)).'
'.tr('IVA "_TYPE_"', [ '_TYPE_' => $desc, ], ['upper' => true]).': '.moneyFormat($sum).'
'.tr('Totale IVA', [], ['upper' => true]).': '.moneyFormat($totale_iva).'
'.tr('Totale', [], ['upper' => true]).': '.moneyFormat(sum($totale)).'
';