openstamanager/templates/ddt/body.php

170 lines
4.4 KiB
PHP
Raw Normal View History

2017-09-08 17:03:47 +02:00
<?php
include_once __DIR__.'/../../core.php';
2018-07-17 12:05:21 +02:00
include_once Modules::filepath('Fatture di vendita', 'modutil.php');
2017-09-08 17:03:47 +02:00
$report_name = 'ddt_'.$numero.'.pdf';
$autofill = [
'count' => 0,
'words' => 70,
'rows' => 16,
'additional' => 15,
2017-09-21 15:51:39 +02:00
'columns' => $options['pricing'] ? 5 : 2,
2017-09-08 17:03:47 +02:00
];
$imponibile = [];
$iva = [];
$sconto = [];
2017-09-08 17:03:47 +02:00
// Intestazione tabella per righe
echo "
2017-09-12 16:45:18 +02:00
<table class='table table-striped table-bordered' id='contents'>
2017-09-08 17:03:47 +02:00
<thead>
<tr>
<th class='text-center'>".tr('Descrizione', [], ['upper' => true])."</th>
<th class='text-center' style='width:10%'>".tr('Q.tà', [], ['upper' => true]).'</th>';
2017-09-08 17:03:47 +02:00
2017-09-21 15:51:39 +02:00
if ($options['pricing']) {
2017-09-08 17:03:47 +02:00
echo "
2017-09-12 16:45:18 +02:00
<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('IVA', [], ['upper' => true]).' (%)</th>';
2017-09-08 17:03:47 +02:00
}
echo '
</tr>
</thead>
<tbody>';
// Righe
2018-02-15 14:25:27 +01:00
$rs_gen = $dbo->fetchArray("SELECT *,
IFNULL((SELECT `codice` FROM `mg_articoli` WHERE `id` = `dt_righe_ddt`.`idarticolo`), '') AS codice_articolo,
(SELECT GROUP_CONCAT(`serial` SEPARATOR ', ') FROM `mg_prodotti` WHERE `id_riga_ddt` = `dt_righe_ddt`.`id`) AS seriali,
(SELECT `percentuale` FROM `co_iva` WHERE `id` = `dt_righe_ddt`.`idiva`) AS perc_iva,
IFNULL((SELECT peso_lordo FROM mg_articoli WHERE id=idarticolo),0) * qta AS peso_lordo,
IFNULL((SELECT volume FROM mg_articoli WHERE id=idarticolo),0) * qta AS volume
FROM `dt_righe_ddt` WHERE idddt=".prepare($id_record).' ORDER BY `order`');
2017-09-08 17:03:47 +02:00
foreach ($rs_gen as $r) {
$count = 0;
$count += ceil(strlen($r['descrizione']) / $autofill['words']);
$count += substr_count($r['descrizione'], PHP_EOL);
2017-09-08 17:03:47 +02:00
echo '
<tr>
<td>
'.nl2br($r['descrizione']);
2018-02-15 14:25:27 +01:00
// Codice articolo
if (!empty($r['codice_articolo'])) {
echo '
<br><small>'.tr('COD. _COD_', [
'_COD_' => $r['codice_articolo'],
]).'</small>';
if ($count <= 1) {
$count += 0.4;
}
}
// Seriali
if (!empty($r['seriali'])) {
echo '
<br><small>'.tr('SN').': '.$r['seriali'].'</small>';
if ($count <= 1) {
$count += 0.4;
}
}
// Aggiunta dei riferimenti ai documenti
$ref = doc_references($r, $records[0]['dir'], ['idddt']);
2017-09-08 17:03:47 +02:00
if (!empty($ref)) {
2017-09-08 17:03:47 +02:00
echo '
<br><small>'.$ref['description'].'</small>';
if ($count <= 1) {
$count += 0.4;
}
}
2017-09-08 17:03:47 +02:00
echo '
</td>';
2017-09-08 17:03:47 +02:00
echo '
<td class="text-center">';
if (empty($r['is_descrizione'])) {
2018-02-15 17:41:09 +01:00
echo '
2018-06-29 13:35:39 +02:00
'.Translator::numberToLocale($r['qta'], 'qta').' '.$r['um'];
}
echo '
</td>';
2017-09-08 17:03:47 +02:00
2017-09-21 15:51:39 +02:00
if ($options['pricing']) {
2018-02-03 13:55:09 +01:00
// Prezzo unitario
echo "
2018-02-03 13:55:09 +01:00
<td class='text-right'>";
if (empty($r['is_descrizione'])) {
echo '
'.Translator::numberToLocale($r['subtotale'] / $r['qta']).' &euro;';
}
echo '
</td>';
2017-09-08 17:03:47 +02:00
// Imponibile
echo "
<td class='text-right'>";
if (empty($r['is_descrizione'])) {
2018-02-15 17:41:09 +01:00
echo '
'.Translator::numberToLocale($r['subtotale']).' &euro;';
if ($r['sconto'] > 0) {
if ($count <= 1) {
$count += 0.4;
}
echo '
2018-02-15 17:41:09 +01:00
<br><small class="help-block">- '.tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator::numberToLocale($r['sconto_unitario']),
'_TYPE_' => ($r['tipo_sconto'] == 'PRC' ? '%' : '&euro;'),
]).'</small>';
}
2017-09-08 17:03:47 +02:00
}
echo '
</td>';
2017-09-08 17:03:47 +02:00
// Iva
echo "
<td class='text-center'>";
if (empty($r['is_descrizione'])) {
2018-02-15 17:41:09 +01:00
echo '
'.Translator::numberToLocale($r['perc_iva']);
}
echo '
</td>';
2017-09-08 17:03:47 +02:00
}
echo '
</tr>';
$autofill['count'] += $count;
$imponibile[] = $r['subtotale'];
$iva[] = $r['iva'];
$sconto[] = $r['sconto'];
2017-09-08 17:03:47 +02:00
}
echo '
|autofill|
</tbody>
</table>';
// Info per il footer
$imponibile = sum($imponibile) - sum($sconto);
2018-05-11 16:57:34 +02:00
$iva = sum($iva, null, 2);
$totale = $imponibile + $iva;
$volume = sum(array_column($rs_gen, 'volume'));
$peso_lordo = sum(array_column($rs_gen, 'peso_lordo'));