2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
// carica report html
$report = file_get_contents ( $docroot . '/templates/fatturato/fatturato.html' );
$body = file_get_contents ( $docroot . '/templates/fatturato/fatturato_body.html' );
2018-09-20 16:42:35 +02:00
$mesi = months ();
2017-08-04 16:28:16 +02:00
2018-09-20 16:42:35 +02:00
$dir = get ( 'dir' );
2017-08-04 16:28:16 +02:00
2018-07-08 15:41:38 +02:00
$date_start = $_SESSION [ 'period_start' ];
$date_end = $_SESSION [ 'period_end' ];
2017-08-04 16:28:16 +02:00
include_once $docroot . '/templates/pdfgen_variables.php' ;
$totale_imponibile = 0 ;
$totale_iva = 0 ;
$totale = 0 ;
if ( $dir == 'entrata' ) {
2018-02-03 14:31:01 +01:00
$addwhere = Modules :: getAdditionalsQuery ( 'Fatture di vendita' );
2017-08-04 16:28:16 +02:00
} else {
2018-02-03 14:31:01 +01:00
$addwhere = Modules :: getAdditionalsQuery ( 'Fatture di acquisto' );
2017-08-04 16:28:16 +02:00
}
// Ciclo tra le fatture selezionate
2018-07-08 15:41:38 +02:00
$query = " SELECT DATE_FORMAT( data, '%m-%Y' ) AS periodo, data FROM co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id GROUP BY periodo, dir HAVING (data BETWEEN ' " . $date_start . " ' AND ' " . $date_end . " ') AND dir=' " . $dir . " ' " . $add_where . ' ORDER BY data ASC' ;
2017-08-04 16:28:16 +02:00
$rs = $dbo -> fetchArray ( $query );
$totrows = sizeof ( $rs );
if ( $dir == 'entrata' ) {
2018-07-08 15:41:38 +02:00
$body .= '<h3>FATTURATO MENSILE DAL ' . Translator :: dateToLocale ( $date_start ) . ' AL ' . Translator :: dateToLocale ( $date_end ) . " </h3> \n " ;
2017-08-04 16:28:16 +02:00
} else {
2018-07-08 15:41:38 +02:00
$body .= '<h3>ACQUISTI MENSILI DAL ' . Translator :: dateToLocale ( $date_start ) . ' AL ' . Translator :: dateToLocale ( $date_end ) . " </h3> \n " ;
2017-08-04 16:28:16 +02:00
}
$body .= " <table cellspacing='0' style='table-layout:fixed;'> \n " ;
$body .= " <col width='320'><col width='100'><col width='100'><col width='100'> \n " ;
$body .= " <tr><th bgcolor='#dddddd' class='full_cell1 cell-padded' width='320'>Mese</th> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell cell-padded' width='100'>Imponibile</th> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell cell-padded' width='100'>Iva</th> \n " ;
$body .= " <th bgcolor='#dddddd' class='full_cell cell-padded' width='100'>Totale</th></tr> \n " ;
for ( $r = 0 ; $r < sizeof ( $rs ); ++ $r ) {
// Lettura totali
$rs2 = $dbo -> fetchArray ( " SELECT SUM(subtotale-co_righe_documenti.sconto) AS imponibile, SUM(iva) AS iva, (SELECT SUM(bollo) FROM co_documenti WHERE DATE_FORMAT(data,'%m-%Y') = \" " . $rs [ $r ][ 'periodo' ] . '" AND idtipodocumento IN(SELECT id FROM co_tipidocumento WHERE dir="' . $dir . " \" )) AS bollo, SUM(co_righe_documenti.rivalsainps) AS rivalsainps, SUM(co_righe_documenti.ritenutaacconto) AS ritenutaacconto FROM co_righe_documenti INNER JOIN co_documenti ON co_righe_documenti.iddocumento=co_documenti.id WHERE DATE_FORMAT(data,'%m-%Y') = \" " . $rs [ $r ][ 'periodo' ] . '" AND idtipodocumento IN(SELECT id FROM co_tipidocumento WHERE dir="' . $dir . '")' );
$body .= " <tr><td class='first_cell cell-padded'> " . $mesi [ intval ( date ( 'm' , strtotime ( $rs [ $r ][ 'data' ])))] . ' ' . date ( 'Y' , strtotime ( $rs [ $r ][ 'data' ])) . " </td> \n " ;
2019-04-13 02:56:39 +02:00
$body .= " <td class='table_cell cell-padded text-right'> " . moneyFormat ( $rs2 [ 0 ][ 'imponibile' ]) . " </td> \n " ;
$body .= " <td class='table_cell cell-padded text-right'> " . moneyFormat ( $rs2 [ 0 ][ 'iva' ]) . " </td> \n " ;
$body .= " <td class='table_cell cell-padded text-right'> " . moneyFormat ( $rs2 [ 0 ][ 'imponibile' ] + $rs2 [ 0 ][ 'iva' ] + $rs2 [ 0 ][ 'rivalsainps' ] + $rs2 [ 0 ][ 'bollo' ] + $rs2 [ 0 ][ 'ritenutaacconto' ]) . " </td></tr> \n " ;
2017-08-04 16:28:16 +02:00
$totale_imponibile += $rs2 [ 0 ][ 'imponibile' ];
$totale_iva += $rs2 [ 0 ][ 'iva' ];
$totale += $rs2 [ 0 ][ 'imponibile' ] + $rs2 [ 0 ][ 'iva' ] + $rs2 [ 0 ][ 'rivalsainps' ] + $rs2 [ 0 ][ 'bollo' ] + $rs2 [ 0 ][ 'ritenutaacconto' ];
}
// Totali
$body .= " <tr> \n " ;
$body .= " <td class='first_cell cell-padded text-right'><b>TOTALE:</b></td> \n " ;
2019-04-13 02:56:39 +02:00
$body .= " <td class='table_cell text-right cell-padded'><b> " . moneyFormat ( $totale_imponibile ) . " </b></td> \n " ;
$body .= " <td class='table_cell text-right cell-padded'><b> " . moneyFormat ( $totale_iva ) . " </b></td> \n " ;
$body .= " <td class='table_cell text-right cell-padded'><b> " . moneyFormat ( $totale ) . " </b></td> \n " ;
2017-08-04 16:28:16 +02:00
$body .= " </tr> \n " ;
$body .= " </table> \n " ;