2017-09-12 17:46:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
2019-01-10 17:27:19 +01:00
|
|
|
function findKey($array, $keySearch)
|
|
|
|
{
|
|
|
|
foreach ($array as $key => $item) {
|
|
|
|
if ($key == $keySearch) {
|
|
|
|
return true;
|
|
|
|
} elseif (is_array($item) && findKey($item, $keySearch)) {
|
2019-01-10 18:11:09 +01:00
|
|
|
echo $key;
|
2019-01-10 18:41:25 +01:00
|
|
|
|
2019-01-10 17:27:19 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-01-10 18:41:25 +01:00
|
|
|
|
2019-01-10 17:27:19 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$has_image = false;
|
2019-01-10 18:11:09 +01:00
|
|
|
|
2019-01-10 17:27:19 +01:00
|
|
|
// RIGHE ORDINE
|
|
|
|
$righe = $dbo->fetchArray("SELECT *,
|
|
|
|
IFNULL((SELECT `codice` FROM `mg_articoli` WHERE `id` = `or_righe_ordini`.`idarticolo`), '') AS codice_articolo,
|
|
|
|
IFNULL((SELECT `immagine` FROM `mg_articoli` WHERE `id` = `or_righe_ordini`.`idarticolo`), '') AS immagine_articolo,
|
|
|
|
(SELECT GROUP_CONCAT(`serial` SEPARATOR ', ') FROM `mg_prodotti` WHERE `id_riga_ordine` = `or_righe_ordini`.`id`) AS seriali,
|
|
|
|
(SELECT `percentuale` FROM `co_iva` WHERE `id` = `or_righe_ordini`.`idiva`) AS perc_iva
|
|
|
|
FROM `or_righe_ordini` WHERE idordine=".prepare($id_record).' ORDER BY `order`');
|
|
|
|
|
|
|
|
//controllo se gli articoli nell'ordine hanno un'immagine
|
2019-01-10 18:41:25 +01:00
|
|
|
if (findKey($righe, 'immagine_articolo')) {
|
|
|
|
if (!empty($righe[(findKey($righe, 'immagine_articolo') - 1)]['immagine_articolo'])) {
|
2019-01-10 18:11:09 +01:00
|
|
|
$has_image = true;
|
|
|
|
}
|
2019-01-10 17:27:19 +01:00
|
|
|
}
|
2017-09-12 17:46:19 +02:00
|
|
|
|
|
|
|
$autofill = [
|
|
|
|
'count' => 0, // Conteggio delle righe
|
|
|
|
'words' => 70, // Numero di parolo dopo cui contare una riga nuova
|
|
|
|
'rows' => 20, // Numero di righe massimo presente nella pagina
|
|
|
|
'additional' => 15, // Numero di righe massimo da aggiungere
|
2019-01-10 18:41:25 +01:00
|
|
|
'columns' => (($has_image) ? 6 : 5), // Numero di colonne della tabella
|
2017-09-12 17:46:19 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$sconto = [];
|
|
|
|
$imponibile = [];
|
|
|
|
$iva = [];
|
|
|
|
|
|
|
|
// Intestazione tabella per righe
|
|
|
|
echo "
|
|
|
|
<table class='table table-striped table-bordered' id='contents'>
|
|
|
|
<thead>
|
2019-01-10 17:27:19 +01:00
|
|
|
<tr>";
|
2019-01-10 18:11:09 +01:00
|
|
|
|
|
|
|
if ($has_image) {
|
2019-01-10 18:41:25 +01:00
|
|
|
echo " <th class='text-center' style='width:20%'>".tr('Immagine', [], ['upper' => true]).'</th>';
|
2019-01-10 17:27:19 +01:00
|
|
|
}
|
|
|
|
echo "
|
|
|
|
<th class='text-center' style='width:50%'>".tr('Descrizione', [], ['upper' => true])."</th>
|
2017-09-12 17:46:19 +02:00
|
|
|
<th class='text-center' style='width:10%'>".tr('Q.tà', [], ['upper' => true])."</th>
|
|
|
|
<th class='text-center' style='width:15%'>".tr('Prezzo unitario', [], ['upper' => true])."</th>
|
2018-02-09 15:27:43 +01:00
|
|
|
<th class='text-center' style='width:15%'>".tr('Importo', [], ['upper' => true])."</th>
|
2017-09-12 17:46:19 +02:00
|
|
|
<th class='text-center' style='width:10%'>".tr('IVA', [], ['upper' => true]).' (%)</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>';
|
|
|
|
|
|
|
|
foreach ($righe as $r) {
|
|
|
|
$count = 0;
|
|
|
|
$count += ceil(strlen($r['descrizione']) / $autofill['words']);
|
|
|
|
$count += substr_count($r['descrizione'], PHP_EOL);
|
|
|
|
|
|
|
|
echo '
|
2019-01-10 17:27:19 +01:00
|
|
|
<tr>';
|
2019-01-10 18:11:09 +01:00
|
|
|
|
|
|
|
if ($has_image) {
|
|
|
|
echo '
|
2019-01-10 17:27:19 +01:00
|
|
|
<td>';
|
2019-01-10 18:11:09 +01:00
|
|
|
if (!empty($r['immagine_articolo'])) {
|
|
|
|
echo '<img src="files/articoli/'.$r['immagine_articolo'].'" height="80"></img>';
|
|
|
|
}
|
|
|
|
echo '
|
2019-01-10 17:27:19 +01:00
|
|
|
</td>';
|
2019-01-10 18:11:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
2019-01-09 17:12:00 +01:00
|
|
|
<td>';
|
2019-01-10 18:11:09 +01:00
|
|
|
|
|
|
|
echo '
|
2017-09-12 17:46:19 +02:00
|
|
|
'.nl2br($r['descrizione']);
|
|
|
|
|
2018-02-15 14:25:27 +01:00
|
|
|
// Codice articolo
|
2017-09-12 17:46:19 +02:00
|
|
|
if (!empty($r['codice_articolo'])) {
|
|
|
|
echo '
|
|
|
|
<br><small>'.tr('COD. _COD_', [
|
|
|
|
'_COD_' => $r['codice_articolo'],
|
|
|
|
]).'</small>';
|
|
|
|
|
|
|
|
if ($count <= 1) {
|
|
|
|
$count += 0.4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:25:27 +01:00
|
|
|
// Seriali
|
|
|
|
if (!empty($r['seriali'])) {
|
|
|
|
echo '
|
|
|
|
<br><small>'.tr('SN').': '.$r['seriali'].'</small>';
|
|
|
|
|
|
|
|
if ($count <= 1) {
|
|
|
|
$count += 0.4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-12 17:46:19 +02:00
|
|
|
echo '
|
|
|
|
</td>';
|
|
|
|
|
|
|
|
echo "
|
2018-01-18 19:03:06 +01:00
|
|
|
<td class='text-center'>";
|
2018-02-15 17:41:09 +01:00
|
|
|
if (empty($r['is_descrizione'])) {
|
|
|
|
echo '
|
2018-06-29 13:35:39 +02:00
|
|
|
'.(empty($r['qta']) ? '' : Translator::numberToLocale($r['qta'], 'qta')).' '.$r['um'];
|
2018-01-18 19:03:06 +01:00
|
|
|
}
|
|
|
|
echo '
|
2017-09-12 17:46:19 +02:00
|
|
|
</td>';
|
|
|
|
|
2017-09-21 15:51:39 +02:00
|
|
|
if ($options['pricing']) {
|
2017-09-12 17:46:19 +02:00
|
|
|
// Prezzo unitario
|
|
|
|
echo "
|
2018-01-18 19:03:06 +01:00
|
|
|
<td class='text-right'>";
|
2018-02-15 17:41:09 +01:00
|
|
|
if (empty($r['is_descrizione'])) {
|
|
|
|
echo '
|
2019-04-13 02:56:39 +02:00
|
|
|
'.(empty($r['qta']) || empty($r['subtotale']) ? '' : moneyFormat($r['subtotale'] / $r['qta']));
|
2018-01-18 19:03:06 +01:00
|
|
|
|
|
|
|
if ($r['sconto'] > 0) {
|
|
|
|
echo "
|
2018-02-15 17:41:09 +01:00
|
|
|
<br><small class='text-muted'>- ".tr('sconto _TOT_ _TYPE_', [
|
|
|
|
'_TOT_' => Translator::numberToLocale($r['sconto_unitario']),
|
2019-04-13 00:09:48 +02:00
|
|
|
'_TYPE_' => ($r['tipo_sconto'] == 'PRC' ? '%' : currency()),
|
2018-02-15 17:41:09 +01:00
|
|
|
]).'</small>';
|
2018-01-18 19:03:06 +01:00
|
|
|
|
|
|
|
if ($count <= 1) {
|
|
|
|
$count += 0.4;
|
|
|
|
}
|
2017-09-21 10:01:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '
|
2017-09-12 17:46:19 +02:00
|
|
|
</td>';
|
|
|
|
|
|
|
|
// Imponibile
|
|
|
|
echo "
|
2018-01-18 19:03:06 +01:00
|
|
|
<td class='text-right'>";
|
2018-02-15 17:41:09 +01:00
|
|
|
if (empty($r['is_descrizione'])) {
|
|
|
|
echo '
|
2019-04-13 02:56:39 +02:00
|
|
|
'.(empty($r['subtotale']) ? '' : moneyFormat($r['subtotale']));
|
2018-01-18 19:03:06 +01:00
|
|
|
|
|
|
|
if ($r['sconto'] > 0) {
|
|
|
|
echo "
|
2018-02-15 17:41:09 +01:00
|
|
|
<br><small class='text-muted'>- ".tr('sconto _TOT_ _TYPE_', [
|
|
|
|
'_TOT_' => Translator::numberToLocale($r['sconto']),
|
2019-04-13 00:09:48 +02:00
|
|
|
'_TYPE_' => currency(),
|
2018-02-15 17:41:09 +01:00
|
|
|
]).'</small>';
|
2018-01-18 19:03:06 +01:00
|
|
|
|
|
|
|
if ($count <= 1) {
|
|
|
|
$count += 0.4;
|
|
|
|
}
|
2017-09-12 17:46:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '
|
|
|
|
</td>';
|
|
|
|
} else {
|
|
|
|
echo '
|
|
|
|
<td class="text-center">-</td>
|
|
|
|
<td class="text-center">-</td>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iva
|
|
|
|
echo '
|
2018-01-18 19:03:06 +01:00
|
|
|
<td class="text-center">';
|
2018-02-15 17:41:09 +01:00
|
|
|
if (empty($r['is_descrizione'])) {
|
|
|
|
echo '
|
2019-05-02 10:03:57 +02:00
|
|
|
'.Translator::numberToLocale($r['perc_iva'], 0);
|
2018-01-18 19:03:06 +01:00
|
|
|
}
|
|
|
|
echo '
|
2017-09-12 17:46:19 +02:00
|
|
|
</td>
|
|
|
|
</tr>';
|
|
|
|
|
|
|
|
$autofill['count'] += $count;
|
|
|
|
|
|
|
|
$sconto[] = $r['sconto'];
|
|
|
|
$imponibile[] = $r['subtotale'];
|
|
|
|
$iva[] = $r['iva'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$sconto = sum($sconto);
|
|
|
|
$imponibile = sum($imponibile);
|
2018-10-30 10:27:44 +01:00
|
|
|
$iva = sum($iva);
|
2017-09-12 17:46:19 +02:00
|
|
|
|
|
|
|
$totale = $imponibile - $sconto;
|
|
|
|
|
|
|
|
echo '
|
|
|
|
|autofill|
|
|
|
|
</tbody>';
|
|
|
|
|
|
|
|
// TOTALE COSTI FINALI
|
2017-09-21 15:51:39 +02:00
|
|
|
if ($options['pricing']) {
|
2017-09-12 17:46:19 +02:00
|
|
|
// Totale imponibile
|
|
|
|
echo '
|
|
|
|
<tr>
|
2019-01-10 18:41:25 +01:00
|
|
|
<td colspan="'.(($has_image) ? 4 : 3).'" class="text-right border-top">
|
2017-09-12 17:46:19 +02:00
|
|
|
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
|
|
|
</td>
|
|
|
|
|
2019-05-02 10:03:57 +02:00
|
|
|
<th colspan="2" class="text-right">
|
|
|
|
<b>'.moneyFormat($imponibile, 2).'</b>
|
2017-09-12 17:46:19 +02:00
|
|
|
</th>
|
|
|
|
</tr>';
|
|
|
|
|
|
|
|
// Eventuale sconto incondizionato
|
|
|
|
if (!empty($sconto)) {
|
|
|
|
echo '
|
|
|
|
<tr>
|
2019-01-10 18:41:25 +01:00
|
|
|
<td colspan="'.(($has_image) ? 4 : 3).'" class="text-right border-top">
|
2017-09-12 17:46:19 +02:00
|
|
|
<b>'.tr('Sconto', [], ['upper' => true]).':</b>
|
|
|
|
</td>
|
|
|
|
|
2019-05-02 10:03:57 +02:00
|
|
|
<th colspan="2" class="text-right">
|
|
|
|
<b>-'.moneyFormat($sconto, 2).'</b>
|
2017-09-12 17:46:19 +02:00
|
|
|
</th>
|
|
|
|
</tr>';
|
|
|
|
|
|
|
|
// Imponibile scontato
|
|
|
|
echo '
|
|
|
|
<tr>
|
2019-01-10 18:41:25 +01:00
|
|
|
<td colspan="'.(($has_image) ? 4 : 3).'" class="text-right border-top">
|
2017-09-12 17:46:19 +02:00
|
|
|
<b>'.tr('Imponibile scontato', [], ['upper' => true]).':</b>
|
|
|
|
</td>
|
|
|
|
|
2019-05-02 10:03:57 +02:00
|
|
|
<th colspan="2" class="text-right">
|
|
|
|
<b>'.moneyFormat($totale, 2).'</b>
|
2017-09-12 17:46:19 +02:00
|
|
|
</th>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// IVA
|
|
|
|
echo '
|
|
|
|
<tr>
|
2019-01-10 18:41:25 +01:00
|
|
|
<td colspan="'.(($has_image) ? 4 : 3).'" class="text-right border-top">
|
2017-09-12 17:46:19 +02:00
|
|
|
<b>'.tr('Totale IVA', [], ['upper' => true]).':</b>
|
|
|
|
</td>
|
|
|
|
|
2019-05-02 10:03:57 +02:00
|
|
|
<th colspan="2" class="text-right">
|
|
|
|
<b>'.moneyFormat($iva, 2).'</b>
|
2017-09-12 17:46:19 +02:00
|
|
|
</th>
|
|
|
|
</tr>';
|
|
|
|
|
|
|
|
$totale = sum($totale, $iva);
|
|
|
|
|
|
|
|
// TOTALE
|
|
|
|
echo '
|
|
|
|
<tr>
|
2019-01-10 18:41:25 +01:00
|
|
|
<td colspan="'.(($has_image) ? 4 : 3).'" class="text-right border-top">
|
2017-09-12 17:46:19 +02:00
|
|
|
<b>'.tr('Quotazione totale', [], ['upper' => true]).':</b>
|
|
|
|
</td>
|
2019-05-02 10:03:57 +02:00
|
|
|
<th colspan="2" class="text-right">
|
|
|
|
<b>'.moneyFormat($totale, 2).'</b>
|
2017-09-12 17:46:19 +02:00
|
|
|
</th>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
|
2018-02-15 17:41:09 +01:00
|
|
|
echo '
|
2017-09-12 17:46:19 +02:00
|
|
|
</table>';
|
|
|
|
|
|
|
|
if (!empty($records[0]['note'])) {
|
|
|
|
echo '
|
|
|
|
<br>
|
|
|
|
<p class="small-bold">'.tr('Note', [], ['upper' => true]).':</p>
|
|
|
|
<p>'.nl2br($records[0]['note']).'</p>';
|
|
|
|
}
|