1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-13 00:46:34 +01:00
openstamanager/templates/ddt/body.php
2017-09-12 16:45:18 +02:00

133 lines
3.7 KiB
PHP

<?php
include_once __DIR__.'/../../core.php';
$report_name = 'ddt_'.$numero.'.pdf';
$autofill = [
'count' => 0,
'words' => 70,
'rows' => 16,
'additional' => 15,
'columns' => $mostra_prezzi ? 6 : 2,
];
$v_iva = [];
$v_totale = [];
$totale_ddt = 0.00;
$totale_imponibile = 0.00;
$totale_iva = 0.00;
$sconto = 0.00;
$sconto_generico = 0.00;
// Intestazione tabella per righe
echo "
<table class='table table-striped table-bordered' id='contents'>
<thead>
<tr>
<th class='text-center'>".tr('Descrizione', [], ['upper' => true])."</th>
<th class='text-center' style='width:7%'>".tr('Q.tà', [], ['upper' => true]).'</th>';
if ($mostra_prezzi) {
echo "
<th class='text-center' style='width:15%'>".tr('Prezzo unitario', [], ['upper' => true])."</th>
<th class='text-center' style='width:15%'>".tr('Importo', [], ['upper' => true])."</th>
<th class='text-center' style='width:10%'>".tr('Sconto', [], ['upper' => true])."</th>
<th class='text-center' style='width:7%'>".tr('IVA', [], ['upper' => true]).' (%)</th>';
}
echo '
</tr>
</thead>
<tbody>';
// Righe
$rs_gen = $dbo->fetchArray("SELECT *, (SELECT percentuale FROM co_iva WHERE id=idiva) AS perc_iva FROM `dt_righe_ddt` WHERE idddt='$idddt'");
$imponibile_gen = 0.0;
$iva_gen = 0.0;
foreach ($rs_gen as $r) {
$autofill['count'] += ceil(strlen($r['descrizione']) / $autofill['words']);
$autofill['count'] += substr_count($r['descrizione'], PHP_EOL);
$descrizione = $r['descrizione'];
$qta = $r['qta'];
$subtot = $r['subtotale'] / $r['qta'];
$subtotale = $r['subtotale'];
$sconto = $r['sconto'];
$iva = $r['iva'];
if (empty($r['sconto_globale'])) {
$sconto_generico = $r['subtotale'];
$iva_gen += $r['iva'];
} else {
echo '
<tr>
<td>
'.nl2br($descrizione);
// Aggiunta riferimento a ordine
if (!empty($r['idordine'])) {
$rso = $dbo->fetchArray('SELECT numero, numero_esterno, data FROM or_ordini WHERE id='.prepare($r['idordine']));
$numero = !empty($rso[0]['numero_esterno']) ? $rso[0]['numero_esterno'] : $rso[0]['numero'];
echo '
<br/><small>'.tr('Rif. ordine n<sup>o</sup>_NUM_ del _DATE_', [
'_NUM_' => $numero,
'_DATE_' => Translator::dateToLocale($rso[0]['data']),
]).'</small>';
$autofill['count'] += 0.4;
}
echo '
</td>';
echo "
<td class='center' valign='top'>
".Translator::numberToLocale($qta, 2).'
</td>';
if ($mostra_prezzi) {
echo "
<td align='right' class='' valign='top'>
".Translator::numberToLocale($subtot, 2).' &euro;
</td>';
// Imponibile
echo "
<td align='right' class='' valign='top'>
".Translator::numberToLocale($subtotale, 2).' &euro;
</td>';
// Sconto
echo "
<td align='right' class='' valign='top'>
".Translator::numberToLocale($r['sconto_unitario'], 2).($r['tipo_sconto'] == 'PRC' ? '%' : ' &euro;').'
</td>';
// Iva
echo "
<td align='center' valign='top'>
".Translator::numberToLocale($r['perc_iva'], 2).'
</td>';
}
echo '
</tr>';
$imponibile_gen += $subtotale;
$iva_gen += $iva;
$sconto += $sconto;
}
}
echo '
|autofill|
</tbody>
</table>';
// Info per il footer
$imponibile_ddt = $imponibile_gen;
$totale_iva = $iva_gen;
$totale_ddt = $imponibile_gen;