='".$date_start."' AND co_documenti.data<='".$date_end."' GROUP BY co_documenti.id, co_righe_documenti.idiva"; } elseif ('uscita' == $dir) { $query = "SELECT *, SUM(subtotale-co_righe_documenti.sconto) AS subtotale, SUM(iva) AS iva, (SELECT ragione_sociale FROM an_anagrafiche WHERE an_anagrafiche.idanagrafica=co_documenti.idanagrafica) AS ragione_sociale FROM co_documenti INNER JOIN co_righe_documenti ON co_documenti.id=co_righe_documenti.iddocumento INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE dir='uscita' AND co_documenti.data>='".$date_start."' AND co_documenti.data<='".$date_end."' GROUP BY co_documenti.id, co_righe_documenti.idiva"; } $rs = $dbo->fetchArray($query); if ('entrata' == $dir) { $body .= "".tr('Registro iva vendita dal _START_ al _END_', [ '_START_' => Translator::dateToLocale($_SESSION['period_start']), '_END_' => Translator::dateToLocale($_SESSION['period_end']), ], ['upper' => true]).'

'; } elseif ('uscita' == $dir) { $body .= "".tr('Registro iva acquisto dal _START_ al _END_', [ '_START_' => Translator::dateToLocale($_SESSION['period_start']), '_END_' => Translator::dateToLocale($_SESSION['period_end']), ], ['upper' => true]).'

'; } $body .= " "; for ($i = 0; $i < sizeof($rs); ++$i) { $body .= ''; if ($rs[$i]['numero'] == $rs[$i - 1]['numero']) { $body .= " "; $body .= " "; } else { $body .= " '; $body .= " '; } if ('entrata' == $dir) { $body .= "'; } elseif ('uscita' == $dir) { $body .= "'; } $body .= " '; $body .= " '; $body .= " '; $body .= ''; $v_iva[$rs[$i]['desc_iva']] += $rs[$i]['iva']; $v_totale[$rs[$i]['desc_iva']] += $rs[$i]['subtotale']; $totale_iva += $rs[$i]['iva']; $totale_subtotale += $rs[$i]['subtotale']; } $body .= '
N° Documento Data Causale
Ragione sociale
Aliquota Imponibile Imposta
".(!empty($rs[$i]['numero_esterno']) ? $rs[$i]['numero_esterno'] : $rs[$i]['numero']).'".date('d/m/Y', strtotime($rs[$i]['data'])).' Fattura di vendita
".$rs[$i]['ragione_sociale'].'
Fattura di acquisto
".$rs[$i]['ragione_sociale'].'
".$rs[$i]['desc_iva'].'".Translator::numberToLocale($rs[$i]['subtotale'], 2).' €".Translator::numberToLocale($rs[$i]['iva'], 2).' €
'; $body .= "

RIEPILOGO IVA

"; $body .= " "; foreach ($v_iva as $desc_iva => $tot_iva) { if ('' != $desc_iva) { $body .= "\n"; $body .= "\n"; $body .= "\n"; } } $body .= " '; $body .= '
Cod. IVA Imponibile Imposta
\n"; $body .= $desc_iva."\n"; $body .= "\n"; $body .= Translator::numberToLocale($v_totale[$desc_iva], 2)." €\n"; $body .= "\n"; $body .= Translator::numberToLocale($v_iva[$desc_iva], 2)." €\n"; $body .= "
TOTALE ".Translator::numberToLocale($totale_subtotale, 2)." € ".Translator::numberToLocale($totale_iva, 2).' €
'; $orientation = 'L'; $report_name = 'registro_iva.pdf';