2017-09-07 16:51:14 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-07 15:04:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-09-07 16:51:14 +02:00
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
|
|
|
$v_iva = [];
|
|
|
|
$v_totale = [];
|
|
|
|
|
2022-09-06 13:04:32 +02:00
|
|
|
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
|
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
// Creazione righe fantasma
|
2022-02-03 10:13:53 +01:00
|
|
|
$autofill = new \Util\Autofill(6, 40);
|
|
|
|
$rows_per_page = $fattura_accompagnatoria ? 13 : 18;
|
2019-07-29 16:54:20 +02:00
|
|
|
if (!empty($options['last-page-footer'])) {
|
2019-08-28 10:36:08 +02:00
|
|
|
$rows_per_page += 7;
|
2019-07-29 16:54:20 +02:00
|
|
|
}
|
|
|
|
$autofill->setRows($rows_per_page);
|
2019-07-12 12:40:13 +02:00
|
|
|
|
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>
|
2020-05-29 16:32:00 +02:00
|
|
|
<th class='text-center' style='width:5%'>".tr('#', [], ['upper' => true])."</th>
|
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>
|
2018-06-22 17:52:51 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
<tbody>';
|
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
// Righe documento
|
|
|
|
$righe = $documento->getRighe();
|
2020-09-11 09:04:06 +02:00
|
|
|
$num = 0;
|
2023-12-13 17:33:24 +01:00
|
|
|
|
|
|
|
if (!setting('Visualizza riferimento su ogni riga in stampa')) {
|
|
|
|
$riferimenti = [];
|
|
|
|
$id_rif = [];
|
|
|
|
|
|
|
|
foreach ($righe as $riga) {
|
|
|
|
$riferimento = ($riga->getOriginalComponent() ? $riga->getOriginalComponent()->getDocument()->getReference() : null);
|
|
|
|
if (!empty($riferimento)) {
|
|
|
|
if (!array_key_exists($riferimento, $riferimenti)) {
|
|
|
|
$riferimenti[$riferimento] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($riga->id, $riferimenti[$riferimento])) {
|
|
|
|
$id_rif[] = $riga->id;
|
|
|
|
$riferimenti[$riferimento][] = $riga->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-11 09:04:06 +02:00
|
|
|
foreach ($righe as $riga) {
|
|
|
|
++$num;
|
2019-07-11 18:10:38 +02:00
|
|
|
$r = $riga->toArray();
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
$autofill->count($r['descrizione']);
|
2018-12-12 18:42:41 +01:00
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
$v_iva[$r['desc_iva']] = sum($v_iva[$r['desc_iva']], $riga->iva);
|
|
|
|
$v_totale[$r['desc_iva']] = sum($v_totale[$r['desc_iva']], $riga->totale_imponibile);
|
2018-07-03 17:28:02 +02:00
|
|
|
|
2023-12-13 17:33:24 +01:00
|
|
|
echo '
|
|
|
|
<tr>
|
|
|
|
<td class="text-center" style="vertical-align: middle">';
|
|
|
|
|
|
|
|
$text = '';
|
|
|
|
|
|
|
|
foreach ($riferimenti as $key => $riferimento) {
|
|
|
|
if (in_array($riga->id, $riferimento)) {
|
|
|
|
if ($riga->id === $riferimento[0]) {
|
|
|
|
$riga_ordine = $database->fetchOne('SELECT numero_cliente, data_cliente FROM or_ordini WHERE id = '.prepare($riga->idordine));
|
|
|
|
if (!empty($riga_ordine['numero_cliente']) && !empty($riga_ordine['data_cliente'])) {
|
|
|
|
$text = $text.'<b>Ordine n. '.$riga_ordine['numero_cliente'].' del '.Translator::dateToLocale($riga_ordine['data_cliente']).'</b><br>';
|
|
|
|
}
|
|
|
|
$r['descrizione'] = str_replace('Rif. '.strtolower($key), '', $r['descrizione']);
|
|
|
|
preg_match("/Rif\.(.*)/s", $r['descrizione'], $rif2);
|
|
|
|
$r['descrizione'] = str_replace('Rif.'.strtolower($rif2[1]), '', $r['descrizione']);
|
|
|
|
if (!empty($rif2)) {
|
|
|
|
$text .= '<b>'.$rif2[0].'</b>';
|
|
|
|
}
|
|
|
|
$text .= '<b>'.$key.'</b></td><td></td><td></td><td></td><td></td></tr><tr><td class="text-center" nowrap="nowrap" style="vertical-align: middle">';
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
'.nl2br($text);
|
|
|
|
}
|
2021-09-17 10:44:33 +02:00
|
|
|
}
|
2023-12-13 17:33:24 +01:00
|
|
|
$r['descrizione'] = preg_replace("/Rif\.(.*)/s", '', $r['descrizione']);
|
|
|
|
$autofill->count($r['descrizione']);
|
2021-09-17 10:44:33 +02:00
|
|
|
}
|
|
|
|
|
2023-12-13 17:33:24 +01:00
|
|
|
$source_type = get_class($riga);
|
|
|
|
if (!setting('Visualizza riferimento su ogni riga in stampa')) {
|
|
|
|
echo $num.'
|
|
|
|
</td>
|
|
|
|
<td>'.$r['descrizione'];
|
|
|
|
} else {
|
|
|
|
echo $num.'
|
|
|
|
</td>
|
|
|
|
<td>'.nl2br($r['descrizione']);
|
|
|
|
}
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
if ($riga->isArticolo()) {
|
2023-12-13 17:33:24 +01:00
|
|
|
echo '<br><small>'.$riga->codice.'</small>';
|
|
|
|
} else {
|
|
|
|
echo '-';
|
|
|
|
}
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2023-12-13 17:33:24 +01:00
|
|
|
if ($riga->isArticolo()) {
|
2019-07-12 12:40:13 +02:00
|
|
|
// Seriali
|
|
|
|
$seriali = $riga->serials;
|
|
|
|
if (!empty($seriali)) {
|
2019-07-12 13:04:28 +02:00
|
|
|
$text = tr('SN').': '.implode(', ', $seriali);
|
2019-07-12 12:40:13 +02:00
|
|
|
echo '
|
2023-12-13 17:33:24 +01:00
|
|
|
<small>'.$text.'</small>';
|
2018-02-15 14:25:27 +01:00
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
$autofill->count($text, true);
|
2018-02-15 14:25:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 10:09:40 +02:00
|
|
|
// Informazioni su CIG, CUP, ...
|
2020-09-22 20:28:37 +02:00
|
|
|
if ($riga->hasOriginalComponent()) {
|
|
|
|
$documento_originale = $riga->getOriginalComponent()->getDocument();
|
2020-04-14 15:04:33 +02:00
|
|
|
|
|
|
|
$num_item = $documento_originale['num_item'];
|
2021-02-22 14:48:50 +01:00
|
|
|
$codice_commessa = $documento_originale['codice_commessa'];
|
2020-04-14 15:04:33 +02:00
|
|
|
$codice_cig = $documento_originale['codice_cig'];
|
|
|
|
$codice_cup = $documento_originale['codice_cup'];
|
|
|
|
$id_documento_fe = $documento_originale['id_documento_fe'];
|
|
|
|
|
2021-02-22 14:48:50 +01:00
|
|
|
$extra_riga = replace('_ID_DOCUMENTO__NUMERO_RIGA__CODICE_COMMESSA__CODICE_CIG__CODICE_CUP_', [
|
2020-04-14 15:04:33 +02:00
|
|
|
'_ID_DOCUMENTO_' => $id_documento_fe ? 'DOC: '.$id_documento_fe : null,
|
|
|
|
'_NUMERO_RIGA_' => $num_item ? ', NRI: '.$num_item : null,
|
2021-02-22 14:48:50 +01:00
|
|
|
'_CODICE_COMMESSA_' => $codice_commessa ? ', COM: '.$codice_commessa : null,
|
2020-04-14 15:04:33 +02:00
|
|
|
'_CODICE_CIG_' => $codice_cig ? ', CIG: '.$codice_cig : null,
|
|
|
|
'_CODICE_CUP_' => $codice_cup ? ', CUP: '.$codice_cup : null,
|
|
|
|
]);
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<br><small>'.$extra_riga.'</small>';
|
|
|
|
}
|
|
|
|
|
2017-09-13 11:15:31 +02:00
|
|
|
echo '
|
2023-12-13 17:33:24 +01:00
|
|
|
</td>';
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
if (!$riga->isDescrizione()) {
|
2018-02-15 17:41:09 +01:00
|
|
|
echo '
|
2019-07-12 12:40:13 +02:00
|
|
|
<td class="text-center">
|
2023-12-05 17:43:35 +01:00
|
|
|
'.Translator::numberToLocale(abs($riga->qta), $d_qta).' '.$r['um'].'
|
2017-09-07 16:51:14 +02:00
|
|
|
</td>';
|
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
// Prezzo unitario
|
2018-08-11 15:49:46 +02:00
|
|
|
echo '
|
2019-07-12 12:40:13 +02:00
|
|
|
<td class="text-right">
|
2023-12-05 17:43:35 +01:00
|
|
|
'.moneyFormat($prezzi_ivati ? $riga->prezzo_unitario_ivato : $riga->prezzo_unitario, $d_importi);
|
2018-01-18 19:03:06 +01:00
|
|
|
|
2019-07-11 18:10:38 +02:00
|
|
|
if ($riga->sconto > 0) {
|
2020-02-15 14:11:44 +01:00
|
|
|
$text = discountInfo($riga, false);
|
2019-07-12 12:40:13 +02:00
|
|
|
|
|
|
|
echo '
|
|
|
|
<br><small class="text-muted">'.$text.'</small>';
|
|
|
|
|
|
|
|
$autofill->count($text, true);
|
2017-09-21 10:01:07 +02:00
|
|
|
}
|
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
echo '
|
2017-09-07 16:51:14 +02:00
|
|
|
</td>';
|
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
// Imponibile
|
2018-08-11 15:49:46 +02:00
|
|
|
echo '
|
2019-07-12 12:40:13 +02:00
|
|
|
<td class="text-right">
|
2023-12-05 17:43:35 +01:00
|
|
|
'.moneyFormat($prezzi_ivati ? ($riga->totale_imponibile + $riga->iva) : $riga->totale_imponibile, $d_importi).'
|
2017-09-07 16:51:14 +02:00
|
|
|
</td>';
|
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
// Iva
|
2018-02-15 17:41:09 +01:00
|
|
|
echo '
|
2019-07-12 12:40:13 +02:00
|
|
|
<td class="text-center">
|
2023-12-05 17:43:35 +01:00
|
|
|
'.Translator::numberToLocale($riga->aliquota->percentuale, $d_qta).'
|
2019-07-12 12:40:13 +02:00
|
|
|
</td>';
|
|
|
|
} else {
|
|
|
|
echo '
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
<td></td>';
|
2018-01-18 19:03:06 +01:00
|
|
|
}
|
2019-07-12 12:40:13 +02:00
|
|
|
|
2018-01-18 19:03:06 +01:00
|
|
|
echo '
|
2017-09-07 16:51:14 +02:00
|
|
|
</tr>';
|
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
$autofill->next();
|
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
|
2019-07-12 12:40:13 +02:00
|
|
|
$dicitura = $dbo->fetchOne('SELECT diciturafissafattura AS dicitura FROM an_anagrafiche WHERE idanagrafica = '.prepare($id_cliente));
|
2018-04-03 12:10:58 +02:00
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
if (!empty($dicitura['dicitura'])) {
|
|
|
|
echo '
|
2020-07-17 17:34:06 +02:00
|
|
|
<p class="text-left">
|
|
|
|
<span>'.nl2br($dicitura['dicitura']).'</span>
|
2018-04-03 12:10:58 +02:00
|
|
|
</p>';
|
|
|
|
}
|
|
|
|
|
2017-09-12 11:10:16 +02:00
|
|
|
// Aggiungo diciture per condizioni iva particolari
|
|
|
|
foreach ($v_iva as $key => $value) {
|
2019-07-12 12:40:13 +02:00
|
|
|
$dicitura = $dbo->fetchOne('SELECT dicitura FROM co_iva WHERE descrizione = '.prepare($key));
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2019-07-12 12:40:13 +02:00
|
|
|
if (!empty($dicitura['dicitura'])) {
|
|
|
|
echo '
|
|
|
|
<p class="text-center">
|
|
|
|
<b>'.nl2br($dicitura['dicitura']).'</b>
|
2017-09-13 11:15:31 +02:00
|
|
|
</p>';
|
2017-09-07 16:51:14 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-22 19:10:29 +01:00
|
|
|
echo '
|
|
|
|
<table class="table">';
|
|
|
|
echo '
|
2019-04-19 17:31:52 +02:00
|
|
|
<tr>
|
2018-03-22 19:10:29 +01:00
|
|
|
<td width="100%">';
|
2019-04-19 17:31:52 +02:00
|
|
|
|
2018-09-27 16:19:25 +02:00
|
|
|
if (!empty($record['note'])) {
|
2018-03-22 19:10:29 +01:00
|
|
|
echo '
|
|
|
|
<p class="small-bold">'.tr('Note', [], ['upper' => true]).':</p>
|
2018-09-27 16:19:25 +02:00
|
|
|
<p>'.nl2br($record['note']).'</p>';
|
2018-03-22 19:10:29 +01:00
|
|
|
}
|
2019-07-12 12:40:13 +02:00
|
|
|
|
2018-03-22 19:10:29 +01:00
|
|
|
echo '
|
|
|
|
</td>';
|
2017-12-20 14:05:14 +01:00
|
|
|
|
2018-03-22 19:10:29 +01:00
|
|
|
echo '
|
|
|
|
</tr>';
|
|
|
|
echo '
|
|
|
|
</table>';
|