openstamanager/templates/contratti/body.php

524 lines
16 KiB
PHP
Raw Normal View History

<?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/>.
*/
use Carbon\CarbonInterval;
2024-02-08 13:10:46 +01:00
use Modules\Pagamenti\Pagamento;
include_once __DIR__.'/../../core.php';
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
2024-05-14 17:09:49 +02:00
// Righe documento
$righe = $documento->getRighe();
$has_image = $righe->search(fn ($item) => !empty($item->articolo->immagine)) !== false && $options['images'] == true;
$columns = $options['no-iva'] ? 5 : 6;
$columns = $options['pricing'] ? $columns : 3;
if ($has_image) {
++$columns;
}
2019-07-12 12:40:13 +02:00
// Creazione righe fantasma
2024-05-14 17:09:49 +02:00
$autofill = new Util\Autofill($columns);
2019-07-12 12:40:13 +02:00
$autofill->setRows(20, 10);
2018-07-17 11:15:31 +02:00
// Elenco impianti
2019-07-12 12:40:13 +02:00
$impianti = $dbo->fetchArray('SELECT nome, matricola FROM my_impianti WHERE id IN (SELECT my_impianti_contratti.idimpianto FROM my_impianti_contratti WHERE idcontratto = '.prepare($documento['id']).')');
2018-07-17 11:15:31 +02:00
echo '
2024-05-23 16:05:30 +02:00
<div class="col-xs-5">
<div class="text-center" style="height:5mm;">
<b>CONTRATTO</b>
</div>
2024-05-23 16:05:30 +02:00
<br>
2024-05-23 16:05:30 +02:00
<table class="table text-center">
<tr>
<td valign="top" class="border-bottom border-top">
<p class="small-bold text-muted">'.tr('Nr. documento', [], ['upper' => true]).'</p>
<p>'.$documento['numero'].'</p>
</td>
2024-05-23 16:05:30 +02:00
<td class="border-bottom border-top">
<p class="small-bold text-muted">'.tr('Data documento', [], ['upper' => true]).'</p>
<p>'.Translator::dateToLocale($documento['data_bozza']).'</p>
</td>
2024-05-23 16:05:30 +02:00
<td class="border-bottom border-top">
<p class="small-bold text-muted">'.tr('Foglio', [], ['upper' => true]).'</p>
<p> {PAGENO}/{nb} </p>
</td>
</tr>';
if (!empty($impianti)) {
$list = [];
foreach ($impianti as $impianto) {
$list[] = $impianto['nome']." <span style='color:#777;'>(".$impianto['matricola'].')</span>';
}
echo '
<br>
<p class="small-bold text-muted">'.tr('Impianti', [], ['upper' => true]).'</p>
<p><small>'.implode(', ', $list).'</small></p>';
}
echo'
</table>
</div>
<div class="col-xs-6 pull-right">
<table class="table border-bottom">
<tr>
<td colspan=2 style="height:16mm;">
<p class="small-bold text-muted ">'.tr('Spett.le', [], ['upper' => true]).'</p>
<p>$c_ragionesociale$</p>
<p>$c_indirizzo$</p>
<p>$c_citta_full$</p>
</td>
</tr>
<tr>
<td class="border-bottom">
<p class="small-bold text-muted">'.tr('Partita IVA', [], ['upper' => true]).'</p>
</td>
<td class="border-bottom text-right">
<small>$c_piva$</small>
</td>
</tr>
<tr>
<td class="border-bottom">
<p class="small-bold text-muted">'.tr('Codice fiscale', [], ['upper' => true]).'</p>
</td>
<td class="border-bottom text-right">
<small>$c_codicefiscale$</small>
</td>
</tr>';
2024-01-15 15:30:45 +01:00
if (!empty($destinazione)) {
echo '
2024-05-23 16:05:30 +02:00
<tr>
<td class="border-bottom">
<p class="small-bold text-muted">'.tr('Destinazione diversa', [], ['upper' => true]).'</p>
</td>
<td class="border-bottom text-right">
<small>'.$destinazione.'</small>
</td>
</tr>';
2024-01-15 15:30:45 +01:00
}
echo '
</table>
</div>
</div>';
// Descrizione
2019-07-12 12:40:13 +02:00
if (!empty($documento['descrizione'])) {
echo '
2024-05-23 11:36:25 +02:00
<p>'.nl2br((string) $documento['descrizione']).'</p>
<br>';
}
// Intestazione tabella per righe
echo "
2024-05-22 15:54:53 +02:00
<table class='table table-striped border-bottom' id='contents'>
<thead>
<tr>
2024-05-14 17:09:49 +02:00
<th class='text-center' width='35' >#</th>";
if ($has_image) {
echo "
<th class='text-center' width='95' >Foto</th>";
}
echo "
<th class='text-center' style='width:50%'>".tr('Descrizione', [], ['upper' => true])."</th>
2019-07-12 12:40:13 +02:00
<th class='text-center' style='width:10%'>".tr('Q.tà', [], ['upper' => true]).'</th>';
if ($options['pricing']) {
echo "
2024-05-21 16:26:19 +02:00
<th class='text-center' style='width:15%'>".tr('Prezzo unitario', [], ['upper' => true]).'</th>';
2024-05-14 17:09:49 +02:00
if (!$options['no-iva']) {
echo "
2024-05-22 15:54:53 +02:00
<th class='text-center' style='width:10%'>".tr('IVA', [], ['upper' => true]).' (%)</th>';
2024-05-14 17:09:49 +02:00
}
echo "
2024-05-21 16:26:19 +02:00
<th class='text-center' style='width:15%'>".($options['hide-total'] ? tr('Importo ivato', [], ['upper' => true]) : tr('Importo', [], ['upper' => true])).'</th>';
2019-07-12 12:40:13 +02:00
}
echo '
</tr>
</thead>
<tbody>';
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;
}
}
}
}
2024-05-14 17:09:49 +02:00
$num = 0;
2019-07-12 12:40:13 +02:00
foreach ($righe as $riga) {
2024-05-14 17:09:49 +02:00
++$num;
2019-07-12 12:40:13 +02:00
$r = $riga->toArray();
$autofill->count($r['descrizione']);
2024-05-21 16:26:19 +02:00
echo '
<tr>
2024-05-14 17:09:49 +02:00
<td class="text-center" nowrap="nowrap" style="vertical-align: middle" width="25">
2024-05-21 16:26:19 +02:00
'.$num.'
2024-05-14 17:09:49 +02:00
</td>';
2024-05-21 16:26:19 +02:00
if ($has_image) {
if ($riga->isArticolo() && !empty($riga->articolo->image)) {
echo '
2024-05-14 17:09:49 +02:00
<td align="center">
<img src="'.$riga->articolo->image.'" style="max-height: 60px; max-width:80px">
</td>';
2024-05-21 16:26:19 +02:00
$autofill->set(5);
} else {
echo '
2024-05-14 17:09:49 +02:00
<td></td>';
}
2024-05-21 16:26:19 +02:00
}
2024-05-14 17:09:49 +02:00
2024-05-21 16:26:19 +02:00
echo '
<td>';
2024-05-14 17:09:49 +02:00
$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>';
}
$text = '<b>'.$key.'</b><br>';
if ($options['pricing']) {
$text = $text.'<td></td><td></td>';
}
$text = $text.'</td><td></td></tr><tr><td>';
echo nl2br($text);
}
}
2024-05-23 11:36:25 +02:00
$r['descrizione'] = str_replace('Rif. '.strtolower((string) $key), '', $r['descrizione']);
}
2024-05-23 11:36:25 +02:00
$source_type = $riga::class;
if (!setting('Visualizza riferimento su ogni riga in stampa')) {
echo $r['descrizione'];
} else {
2024-05-23 11:36:25 +02:00
echo nl2br((string) $r['descrizione']);
}
2023-11-13 15:38:27 +01:00
if ($riga->isArticolo()) {
echo nl2br('<br><small>'.$riga->codice.'</small>');
} else {
echo '-';
}
if ($riga->isArticolo()) {
2023-11-13 15:38:27 +01:00
// Seriali
$seriali = $riga->serials;
if (!empty($seriali)) {
$text = tr('SN').': '.implode(', ', $seriali);
echo '
<small>'.$text.'</small>';
2023-11-13 15:38:27 +01:00
$autofill->count($text, true);
}
}
echo '
</td>';
2019-07-12 12:40:13 +02:00
if (!$riga->isDescrizione()) {
2018-02-17 09:02:19 +01:00
echo '
2019-07-12 12:40:13 +02:00
<td class="text-center">
'.Translator::numberToLocale(abs($riga->qta), $d_qta).' '.$r['um'].'
</td>';
2019-07-12 12:40:13 +02:00
if ($options['pricing']) {
// Prezzo unitario
2018-02-17 09:02:19 +01:00
echo '
2019-07-12 12:40:13 +02:00
<td class="text-right">
'.moneyFormat($prezzi_ivati ? $riga->prezzo_unitario_ivato : $riga->prezzo_unitario, $d_importi);
2019-07-12 12:40:13 +02:00
if ($riga->sconto > 0) {
2020-02-15 14:11:44 +01:00
$text = discountInfo($riga, false);
echo '
2019-07-12 12:40:13 +02:00
<br><small class="text-muted">'.$text.'</small>';
$autofill->count($text, true);
}
2019-07-12 12:40:13 +02:00
echo '
</td>';
2024-05-22 15:54:53 +02:00
// IVA
echo '
<td class="text-right">
'.Translator::numberToLocale($riga->aliquota->percentuale, 0).'
</td>';
2019-07-12 12:40:13 +02:00
// Imponibile
echo '
<td class="text-right">
2024-05-22 15:54:53 +02:00
'.moneyFormat($riga->subtotale + $riga->iva, $d_importi).'
</td>';
2019-07-12 12:40:13 +02:00
}
} else {
echo '
2019-07-12 12:40:13 +02:00
<td></td>';
if ($options['pricing']) {
echo '
<td></td>
<td></td>';
}
}
echo '
</tr>';
2019-07-12 12:40:13 +02:00
$autofill->next();
}
echo '
|autofill|
</tbody>';
2019-07-12 12:40:13 +02:00
// Calcoli
$imponibile = $documento->imponibile;
$sconto = $documento->sconto;
$totale_imponibile = $documento->totale_imponibile;
$totale_iva = $documento->iva;
$totale = $documento->totale;
$sconto_finale = $documento->getScontoFinale();
$netto_a_pagare = $documento->netto;
2019-07-12 12:40:13 +02:00
$show_sconto = $sconto > 0;
// TOTALE COSTI FINALI
if (($options['pricing'] && !isset($options['hide-total'])) || $options['show-only-total']) {
2019-07-12 12:40:13 +02:00
// Totale imponibile
echo '
<tr>
2024-05-22 15:54:53 +02:00
<td colspan="'.($options['show-only-total'] ? (($has_image) ? 3 : 2) : 5).'" class="text-right text-muted">
2024-05-21 16:26:19 +02:00
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
2024-05-21 16:26:19 +02:00
<th colspan="'.($options['show-only-total'] ? (($has_image) ? ($options['no-iva'] ? 1 : 2) : 1) : (($has_image) ? 3 : 2)).'" class="text-right">
<b>'.moneyFormat($show_sconto ? $imponibile : $totale_imponibile, $d_totali).'</b>
</th>
</tr>';
2019-07-12 12:40:13 +02:00
// Eventuale sconto incondizionato
if ($show_sconto) {
echo '
<tr>
2024-05-22 15:54:53 +02:00
<td colspan="'.($options['show-only-total'] ? 2 : 5).'" class="text-right text-muted">
2024-05-21 16:26:19 +02:00
<b>'.tr('Sconto', [], ['upper' => true]).':</b>
</td>
2024-05-21 16:26:19 +02:00
<th colspan="'.($options['show-only-total'] ? (($has_image) ? 2 : 1) : (($has_image) ? 3 : 2)).'" class="text-right">
<b>'.moneyFormat($sconto, $d_totali).'</b>
</th>
</tr>';
2019-07-12 12:40:13 +02:00
// Totale imponibile
echo '
<tr>
2024-05-22 15:54:53 +02:00
<td colspan="'.($options['show-only-total'] ? 2 : 5).'" class="text-right text-muted">
2024-05-21 16:26:19 +02:00
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
2019-07-12 12:40:13 +02:00
</td>
2024-05-21 16:26:19 +02:00
<th colspan="'.($options['show-only-total'] ? (($has_image) ? 2 : 1) : (($has_image) ? 3 : 2)).'" class="text-right">
<b>'.moneyFormat($totale_imponibile, $d_totali).'</b>
2019-07-12 12:40:13 +02:00
</th>
</tr>';
}
if (!$options['no-iva']) {
// IVA
echo '
<tr>
2024-05-22 15:54:53 +02:00
<td colspan="'.($options['show-only-total'] ? 2 : 5).'" class="text-right text-muted">
2024-05-21 16:26:19 +02:00
<b>'.tr('Totale IVA', [], ['upper' => true]).':</b>
</td>
2024-05-21 16:26:19 +02:00
<th colspan="'.($options['show-only-total'] ? (($has_image) ? 2 : 1) : (($has_image) ? 3 : 2)).'" class="text-right">
<b>'.moneyFormat($totale_iva, $d_totali).'</b>
</th>
</tr>';
// TOTALE
echo '
<tr>
2024-05-22 15:54:53 +02:00
<td colspan="'.($options['show-only-total'] ? 2 : 5).'" class="text-right text-muted">
<b>'.tr('Totale documento', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-right">
<b>'.moneyFormat($totale, $d_totali).'</b>
</th>
</tr>';
if ($sconto_finale) {
// SCONTO IN FATTURA
echo '
<tr>
2024-05-23 16:05:30 +02:00
<td colspan="'.($options['show-only-total'] ? 2 : 5).'" class="text-right">
2024-05-21 16:26:19 +02:00
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
</td>
2024-05-21 16:26:19 +02:00
<th colspan="'.($options['show-only-total'] ? (($has_image) ? 2 : 1) : (($has_image) ? 3 : 2)).'" class="text-right">
<b>'.moneyFormat($sconto_finale, $d_totali).'</b>
</th>
</tr>';
// NETTO A PAGARE
echo '
<tr>
2024-05-23 16:05:30 +02:00
<td colspan="'.($options['show-only-total'] ? 2 : 5).'" class="text-right">
2024-05-21 16:26:19 +02:00
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
</td>
2024-05-21 16:26:19 +02:00
<th colspan="'.($options['show-only-total'] ? (($has_image) ? 2 : 1) : (($has_image) ? 3 : 2)).'" class="text-right">
<b>'.moneyFormat($netto_a_pagare, $d_totali).'</b>
</th>
</tr>';
}
}
}
2021-02-18 18:48:44 +01:00
echo '
</table>';
if ($options['no-iva']) {
echo '
<p colspan="3" class="text-right text-muted">
<small>Importo IVA esclusa</small>
</p>
';
}
// CONDIZIONI GENERALI DI FORNITURA
2024-02-08 13:10:46 +01:00
$pagamento = Pagamento::find($documento['idpagamento']);
echo '
2024-05-22 15:54:53 +02:00
<table class="table table-striped">
<tr>
2024-05-22 15:54:53 +02:00
<th colspan="6" class="text-left text-muted">
'.tr('Condizioni generali di fornitura', [], ['upper' => true]).'
</th>
</tr>
<tr>
2024-05-22 15:54:53 +02:00
<td class="text-muted small-bold border-bottom" style="width:25%">
'.tr('Pagamento', [], ['upper' => true]).'
2024-05-22 15:54:53 +02:00
</td>
2024-05-22 15:54:53 +02:00
<td class="border-bottom">
2024-04-18 17:44:05 +02:00
'.$pagamento->getTranslation('title').'
</td>
</tr>
<tr>
2024-05-22 15:54:53 +02:00
<td class="text-muted border-bottom small-bold">
'.tr('Validità offerta', [], ['upper' => true]).'
2024-05-22 15:54:53 +02:00
</td>
2024-05-22 15:54:53 +02:00
<td class="border-bottom">';
2024-01-15 15:30:45 +01:00
if (!empty($documento->validita) && !empty($documento->tipo_validita)) {
$intervallo = CarbonInterval::make($documento->validita.' '.$documento->tipo_validita);
2024-01-15 15:30:45 +01:00
echo $intervallo->forHumans();
} elseif (!empty($documento->validita)) {
echo tr('_TOT_ giorni', [
'_TOT_' => $documento->validita,
]);
} else {
echo '-';
}
2024-01-15 15:30:45 +01:00
echo '
</td>
</tr>
<tr>
2024-05-22 15:54:53 +02:00
<td class="text-muted border-bottom small-bold">
'.tr('Validità contratto', [], ['upper' => true]).'
2024-05-22 15:54:53 +02:00
</td>
2024-05-22 15:54:53 +02:00
<td class="border-bottom">';
2024-01-15 15:30:45 +01:00
if (!empty($documento['data_accettazione']) && !empty($documento['data_conclusione'])) {
echo '
'.tr('dal _START_ al _END_', [
2024-01-15 15:30:45 +01:00
'_START_' => Translator::dateToLocale($documento['data_accettazione']),
'_END_' => Translator::dateToLocale($documento['data_conclusione']),
]);
} else {
echo '-';
}
2024-01-15 15:30:45 +01:00
echo '
</td>
</tr>
<tr>
2024-05-22 15:54:53 +02:00
<td class="text-muted border-bottom small-bold">
'.tr('Esclusioni', [], ['upper' => true]).'
2024-05-22 15:54:53 +02:00
</td>
2024-05-22 15:54:53 +02:00
<td class="border-bottom">
2024-05-23 11:36:25 +02:00
'.nl2br((string) $documento['esclusioni']).'
</td>
</tr>
</table>';
// Conclusione
2019-07-12 12:40:13 +02:00
if (empty($documento->stato->fatturabile)) {
2018-07-17 11:15:31 +02:00
echo '
<p class="text-center"><b>'.tr('Il tutto S.E. & O.').'</b></p>
<p class="text-center">'.tr("In attesa di un Vostro Cortese riscontro, colgo l'occasione per porgere Cordiali Saluti").'</p>';
2018-07-17 11:15:31 +02:00
}
if (!empty($documento->condizioni_fornitura)) {
echo '<pagebreak>'.$documento->condizioni_fornitura;
2023-08-04 14:54:28 +02:00
}