2017-09-07 16:51:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
$report_name = 'fattura_'.$numero.'.pdf';
|
|
|
|
|
2017-09-08 17:03:47 +02:00
|
|
|
$autofill = [
|
|
|
|
'count' => 0, // Conteggio delle righe
|
|
|
|
'words' => 70, // Numero di parolo dopo cui contare una riga nuova
|
2017-09-21 16:42:27 +02:00
|
|
|
'rows' => $fattura_accompagnatoria ? 15 : 20, // Numero di righe massimo presente nella pagina
|
|
|
|
'additional' => $fattura_accompagnatoria ? 10 : 15, // Numero di righe massimo da aggiungere
|
2017-09-13 11:15:31 +02:00
|
|
|
'columns' => 5, // Numero di colonne della tabella
|
2017-09-08 17:03:47 +02:00
|
|
|
];
|
2017-09-07 16:51:14 +02:00
|
|
|
|
|
|
|
$v_iva = [];
|
|
|
|
$v_totale = [];
|
|
|
|
|
2017-09-13 11:15:31 +02:00
|
|
|
$sconto = [];
|
|
|
|
$imponibile = [];
|
|
|
|
$iva = [];
|
2017-09-07 16:51:14 +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-07 16:51:14 +02:00
|
|
|
<thead>
|
|
|
|
<tr>
|
2017-09-10 14:35:41 +02:00
|
|
|
<th class='text-center' style='width:50%'>".tr('Descrizione', [], ['upper' => true])."</th>
|
2017-09-13 11:15:31 +02:00
|
|
|
<th class='text-center' style='width:14%'>".tr('Q.tà', [], ['upper' => true])."</th>
|
2017-09-12 16:45:18 +02:00
|
|
|
<th class='text-center' style='width:16%'>".tr('Prezzo unitario', [], ['upper' => true])."</th>
|
2017-09-10 14:35:41 +02:00
|
|
|
<th class='text-center' style='width:20%'>".tr('Importo', [], ['upper' => true])."</th>
|
2017-09-13 11:15:31 +02:00
|
|
|
<th class='text-center' style='width:10%'>".tr('IVA', [], ['upper' => true]).' (%)</th>
|
2017-09-07 16:51:14 +02:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>';
|
|
|
|
|
|
|
|
// RIGHE FATTURA CON ORDINAMENTO UNICO
|
2018-02-15 14:25:27 +01:00
|
|
|
$righe = $dbo->fetchArray("SELECT *,
|
|
|
|
IFNULL((SELECT `codice` FROM `mg_articoli` WHERE `id` = `co_righe_documenti`.`idarticolo`), '') AS codice_articolo,
|
|
|
|
(SELECT GROUP_CONCAT(`serial` SEPARATOR ', ') FROM `mg_prodotti` WHERE `id_riga_documento` = `co_righe_documenti`.`id`) AS seriali,
|
|
|
|
(SELECT `percentuale` FROM `co_iva` WHERE `id` = `co_righe_documenti`.`idiva`) AS perc_iva
|
2018-02-15 17:41:09 +01:00
|
|
|
FROM `co_righe_documenti` WHERE `iddocumento` = ".prepare($id_record).' ORDER BY `order`');
|
2017-09-08 17:03:47 +02:00
|
|
|
foreach ($righe as $r) {
|
2017-09-13 11:15:31 +02:00
|
|
|
$count = 0;
|
|
|
|
$count += ceil(strlen($r['descrizione']) / $autofill['words']);
|
|
|
|
$count += substr_count($r['descrizione'], PHP_EOL);
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2017-09-08 17:03:47 +02:00
|
|
|
echo '
|
2017-09-08 13:24:48 +02:00
|
|
|
<tr>
|
2017-09-08 17:03:47 +02:00
|
|
|
<td>
|
|
|
|
'.nl2br($r['descrizione']);
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2018-02-15 14:25:27 +01:00
|
|
|
// Codice articolo
|
2017-09-08 17:03:47 +02:00
|
|
|
if (!empty($r['codice_articolo'])) {
|
2017-09-07 16:51:14 +02:00
|
|
|
echo '
|
2017-09-10 14:35:41 +02:00
|
|
|
<br><small>'.tr('COD. _COD_', [
|
|
|
|
'_COD_' => $r['codice_articolo'],
|
|
|
|
]).'</small>';
|
2017-09-13 19:02:36 +02:00
|
|
|
|
|
|
|
if ($count <= 1) {
|
|
|
|
$count += 0.4;
|
|
|
|
}
|
2017-09-07 16:51:14 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 16:44:16 +01:00
|
|
|
// Aggiunta dei riferimenti ai documenti
|
|
|
|
$ref_modulo = null;
|
|
|
|
$ref_id = null;
|
|
|
|
|
|
|
|
// Ordine
|
|
|
|
if (!empty($r['idordine'])) {
|
|
|
|
$data = $dbo->fetchArray("SELECT IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM or_ordini WHERE id=".prepare($r['idordine']));
|
|
|
|
|
|
|
|
$ref_modulo = ($records[0]['dir'] == 'entrata') ? 'Ordini cliente' : 'Ordini fornitore';
|
|
|
|
$ref_id = $r['idordine'];
|
|
|
|
|
|
|
|
$documento = tr('Ordine');
|
|
|
|
}
|
|
|
|
// DDT
|
|
|
|
elseif (!empty($r['idddt'])) {
|
|
|
|
$data = $dbo->fetchArray("SELECT IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM dt_ddt WHERE id=".prepare($r['idddt']));
|
|
|
|
|
|
|
|
$ref_modulo = ($records[0]['dir'] == 'entrata') ? 'Ddt di vendita' : 'Ddt di acquisto';
|
|
|
|
$ref_id = $r['idddt'];
|
|
|
|
|
|
|
|
$documento = tr('Ddt');
|
|
|
|
}
|
|
|
|
// Preventivo
|
|
|
|
elseif (!empty($r['idpreventivo'])) {
|
|
|
|
$data = $dbo->fetchArray('SELECT numero, data_bozza AS data FROM co_preventivi WHERE id='.prepare($r['idpreventivo']));
|
|
|
|
|
|
|
|
$ref_modulo = 'Preventivi';
|
|
|
|
$ref_id = $r['idpreventivo'];
|
|
|
|
|
|
|
|
$documento = tr('Preventivo');
|
|
|
|
}
|
|
|
|
// Contratto
|
|
|
|
elseif (!empty($r['idcontratto'])) {
|
|
|
|
$data = $dbo->fetchArray('SELECT numero, data_bozza AS data FROM co_contratti WHERE id='.prepare($r['idcontratto']));
|
|
|
|
|
|
|
|
$ref_modulo = 'Contratti';
|
|
|
|
$ref_id = $r['idcontratto'];
|
|
|
|
|
|
|
|
$documento = tr('Contratto');
|
|
|
|
}
|
|
|
|
// Intervento
|
|
|
|
elseif (!empty($r['idintervento'])) {
|
|
|
|
$data = $dbo->fetchArray('SELECT codice AS numero, data_richiesta AS data FROM in_interventi WHERE id='.prepare($r['idintervento']));
|
|
|
|
|
|
|
|
$ref_modulo = 'Interventi';
|
|
|
|
$ref_id = $r['idintervento'];
|
|
|
|
|
|
|
|
$documento = tr('Intervento');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($ref_modulo) && !empty($ref_id)) {
|
|
|
|
$documento = Stringy\Stringy::create($documento)->toLowerCase();
|
|
|
|
|
|
|
|
if (!empty($data)) {
|
|
|
|
$descrizione = tr('Rif. _DOC_ num. _NUM_ del _DATE_', [
|
|
|
|
'_DOC_' => $documento,
|
|
|
|
'_NUM_' => $data[0]['numero'],
|
|
|
|
'_DATE_' => Translator::dateToLocale($data[0]['data']),
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$descrizione = tr('_DOC_ di riferimento _ID_ eliminato', [
|
|
|
|
'_DOC_' => $documento->upperCaseFirst(),
|
|
|
|
'_ID_' => $ref_id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 17:41:09 +01:00
|
|
|
// Stampa dei riferimenti
|
2018-02-15 16:44:16 +01:00
|
|
|
if (!empty($descrizione)) {
|
|
|
|
echo '
|
|
|
|
<br><small>'.$descrizione.'</small>';
|
|
|
|
if ($count <= 1) {
|
|
|
|
$count += 0.4;
|
|
|
|
}
|
2017-09-13 11:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
2017-09-07 16:51:14 +02:00
|
|
|
</td>';
|
|
|
|
|
2018-01-18 19:03:06 +01:00
|
|
|
echo '
|
|
|
|
<td class="text-center">';
|
2018-02-15 16:44:16 +01:00
|
|
|
if (empty($r['is_descrizione'])) {
|
2018-02-15 17:41:09 +01:00
|
|
|
echo '
|
|
|
|
'.Translator::numberToLocale($r['qta']).' '.$r['um'];
|
2018-01-18 19:03:06 +01:00
|
|
|
}
|
|
|
|
echo '
|
2017-09-07 16:51:14 +02:00
|
|
|
</td>';
|
|
|
|
|
2017-09-12 16:45:18 +02:00
|
|
|
// Prezzo unitario
|
2017-09-07 16:51:14 +02:00
|
|
|
echo "
|
2018-01-18 19:03:06 +01:00
|
|
|
<td class='text-right'>";
|
2018-02-15 16:44:16 +01:00
|
|
|
if (empty($r['is_descrizione'])) {
|
2018-02-15 17:41:09 +01:00
|
|
|
echo '
|
|
|
|
'.(empty($r['qta']) || empty($r['subtotale']) ? '' : Translator::numberToLocale($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']),
|
|
|
|
'_TYPE_' => ($r['tipo_sconto'] == 'PRC' ? '%' : '€'),
|
|
|
|
]).'</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-07 16:51:14 +02:00
|
|
|
</td>';
|
|
|
|
|
|
|
|
// Imponibile
|
|
|
|
echo "
|
2018-01-18 19:03:06 +01:00
|
|
|
<td class='text-right'>";
|
2018-02-15 16:44:16 +01:00
|
|
|
if (empty($r['is_descrizione'])) {
|
2018-02-15 17:41:09 +01:00
|
|
|
echo '
|
|
|
|
'.(empty($r['subtotale']) ? '' : Translator::numberToLocale($r['subtotale'] - $r['sconto'])).' €';
|
2018-02-15 16:44:16 +01:00
|
|
|
|
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 di _TOT_ _TYPE_', [
|
|
|
|
'_TOT_' => Translator::numberToLocale($r['sconto']),
|
|
|
|
'_TYPE_' => '€',
|
|
|
|
]).'</small>';
|
2018-01-18 19:03:06 +01:00
|
|
|
|
|
|
|
if ($count <= 1) {
|
|
|
|
$count += 0.4;
|
|
|
|
}
|
2017-09-13 11:15:31 +02:00
|
|
|
}
|
2017-09-07 16:51:14 +02:00
|
|
|
}
|
|
|
|
echo '
|
|
|
|
</td>';
|
|
|
|
|
|
|
|
// Iva
|
|
|
|
echo '
|
2018-01-18 19:03:06 +01:00
|
|
|
<td class="text-center">';
|
2018-02-15 16:44:16 +01:00
|
|
|
if (empty($r['is_descrizione'])) {
|
2018-02-15 17:41:09 +01:00
|
|
|
echo '
|
|
|
|
'.Translator::numberToLocale($r['perc_iva']);
|
2018-01-18 19:03:06 +01:00
|
|
|
}
|
|
|
|
echo '
|
2017-09-07 16:51:14 +02:00
|
|
|
</td>
|
|
|
|
</tr>';
|
|
|
|
|
2017-09-13 11:15:31 +02:00
|
|
|
$autofill['count'] += $count;
|
|
|
|
|
|
|
|
$imponibile[] = $r['subtotale'];
|
|
|
|
$iva[] = $r['iva'];
|
|
|
|
$sconto[] = $r['sconto'];
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2017-12-29 09:34:46 +01:00
|
|
|
$v_iva[$r['desc_iva']] = sum($v_iva[$r['desc_iva']], $r['iva']);
|
|
|
|
$v_totale[$r['desc_iva']] = sum($v_totale[$r['desc_iva']], [
|
|
|
|
$r['subtotale'], -$r['sconto'],
|
|
|
|
]);
|
2017-09-07 16:51:14 +02:00
|
|
|
}
|
|
|
|
|
2017-09-12 11:10:16 +02:00
|
|
|
echo '
|
|
|
|
|autofill|
|
|
|
|
</tbody>
|
|
|
|
</table>';
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2018-04-03 12:10:58 +02:00
|
|
|
|
|
|
|
// Aggiungo diciture particolari per l'anagrafica cliente
|
|
|
|
$dicitura = $dbo->fetchArray('SELECT diciturafissafattura FROM an_anagrafiche WHERE idanagrafica = '.prepare($id_cliente));
|
|
|
|
|
|
|
|
if (!empty($dicitura[0]['diciturafissafattura'])) {
|
|
|
|
$testo = $dicitura[0]['diciturafissafattura'];
|
|
|
|
|
|
|
|
echo "
|
|
|
|
<p class='text-center'>
|
|
|
|
<b>".nl2br($testo).'</b>
|
|
|
|
</p>';
|
|
|
|
}
|
|
|
|
|
2017-09-12 11:10:16 +02:00
|
|
|
// Aggiungo diciture per condizioni iva particolari
|
|
|
|
foreach ($v_iva as $key => $value) {
|
|
|
|
$dicitura = $dbo->fetchArray('SELECT dicitura FROM co_iva WHERE descrizione = '.prepare($key));
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2017-09-12 11:10:16 +02:00
|
|
|
if (!empty($dicitura[0]['dicitura'])) {
|
|
|
|
$testo = $dicitura[0]['dicitura'];
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2017-09-12 11:10:16 +02:00
|
|
|
echo "
|
|
|
|
<p class='text-center'>
|
2017-09-13 11:15:31 +02:00
|
|
|
<b>".nl2br($testo).'</b>
|
|
|
|
</p>';
|
2017-09-07 16:51:14 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-22 19:10:29 +01:00
|
|
|
echo '
|
|
|
|
<table class="table">';
|
|
|
|
echo '
|
|
|
|
<tr>';
|
|
|
|
if(abs($records[0]['bollo']) > 0){
|
2017-09-07 16:51:14 +02:00
|
|
|
echo '
|
2018-03-22 19:10:29 +01:00
|
|
|
<td width="85%">';
|
|
|
|
}else{
|
|
|
|
echo '
|
|
|
|
<td width="100%">';
|
|
|
|
}
|
|
|
|
if (!empty($records[0]['note'])) {
|
|
|
|
echo '
|
|
|
|
<p class="small-bold">'.tr('Note', [], ['upper' => true]).':</p>
|
|
|
|
<p>'.nl2br($records[0]['note']).'</p>';
|
|
|
|
}
|
|
|
|
echo '
|
|
|
|
</td>';
|
|
|
|
if(abs($records[0]['bollo']) > 0){
|
|
|
|
echo '
|
|
|
|
<td width="15%" align="right">';
|
2017-09-07 16:51:14 +02:00
|
|
|
}
|
2017-12-20 14:05:14 +01:00
|
|
|
if (abs($records[0]['bollo']) > 0) {
|
|
|
|
echo '
|
2018-03-22 19:10:29 +01:00
|
|
|
<table style="width: 20mm; font-size: 50%; text-align: center" class="table-bordered">
|
|
|
|
<tr>
|
|
|
|
<td style="height: 20mm;">
|
|
|
|
<br><br>
|
|
|
|
'.tr('Spazio per applicazione marca da bollo', [], ['upper' => true]).'
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>';
|
|
|
|
}
|
|
|
|
if(abs($records[0]['bollo']) > 0){
|
|
|
|
echo '
|
|
|
|
</td>';
|
2017-12-20 14:05:14 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 19:10:29 +01:00
|
|
|
echo '
|
|
|
|
</tr>';
|
|
|
|
echo '
|
|
|
|
</table>';
|
|
|
|
|
2017-09-08 17:03:47 +02:00
|
|
|
// Info per il footer
|
2017-09-13 11:15:31 +02:00
|
|
|
$imponibile = sum($imponibile);
|
2018-02-16 00:50:29 +01:00
|
|
|
$iva = sum($iva, null, 4) + $records[0]['iva_rivalsainps'];
|
2017-09-13 11:15:31 +02:00
|
|
|
$sconto = sum($sconto);
|
|
|
|
|
2017-12-20 14:05:14 +01:00
|
|
|
$totale = $imponibile + $iva - $sconto + $records[0]['rivalsainps'];
|