2017-09-12 17:46:19 +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-12 17:46:19 +02:00
2020-07-07 18:07:56 +02:00
use Carbon\CarbonInterval ;
2024-02-08 13:10:46 +01:00
use Modules\Pagamenti\Pagamento ;
2020-07-07 18:07:56 +02:00
2017-09-12 17:46:19 +02:00
include_once __DIR__ . '/../../core.php' ;
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
2024-01-15 15:30:45 +01:00
$autofill = new Util\Autofill ( $options [ 'pricing' ] ? 4 : 2 );
2019-07-12 12:40:13 +02:00
$autofill -> setRows ( 20 , 10 );
2017-09-12 17:46:19 +02:00
echo '
< div class = " row " >
< div class = " col-xs-6 " >
< div class = " text-center " style = " height:5mm; " >
2021-07-26 17:32:07 +02:00
< br >< br >
2017-09-21 11:02:31 +02:00
< b > '.tr(' Contratto num . _NUM_ del _DATE_ ' , [
2024-03-22 15:52:24 +01:00
'_NUM_' => $documento [ 'numero' ],
'_DATE_' => Translator :: dateToLocale ( $documento [ 'data_bozza' ]),
], [ 'upper' => true ]) . ' </ b >
2018-07-17 11:15:31 +02:00
</ div > ' ;
// 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' ]) . ')' );
if ( ! empty ( $impianti )) {
2018-07-17 11:15:31 +02:00
$list = [];
foreach ( $impianti as $impianto ) {
$list [] = $impianto [ 'nome' ] . " <span style='color:#777;'>( " . $impianto [ 'matricola' ] . ')</span>' ;
}
echo '
< br >
< p class = " small-bold " > '.tr(' Impianti ', [], [' upper ' => true]).' </ p >
< p >< small > '.implode(' , ', $list).' </ small ></ p > ' ;
}
2019-07-12 12:40:13 +02:00
2018-07-17 11:15:31 +02:00
echo '
2017-09-12 17:46:19 +02:00
</ div >
2019-07-12 12:56:46 +02:00
< div class = " col-xs-6 " style = " margin-left: 10px " >
2017-09-12 17:46:19 +02:00
< table class = " table " style = " width:100%;margin-top:5mm; " >
< tr >
< td colspan = 2 class = " border-full " style = " height:16mm; " >
< p class = " small-bold " > '.tr(' Spett . le ', [], [' upper ' => true]).' </ p >
< p > $c_ragionesociale $ </ p >
2021-07-26 17:32:07 +02:00
< p > $c_indirizzo $ </ p >
< p > $c_citta_full $ </ p >
2017-09-12 17:46:19 +02:00
</ td >
</ tr >
< tr >
< td class = " border-bottom border-left " >
< p class = " small-bold " > '.tr(' Partita IVA ', [], [' upper ' => true]).' </ p >
</ td >
< td class = " border-right border-bottom text-right " >
< small > $c_piva $ </ small >
</ td >
</ tr >
< tr >
< td class = " border-bottom border-left " >
< p class = " small-bold " > '.tr(' Codice fiscale ', [], [' upper ' => true]).' </ p >
</ td >
< td class = " border-right border-bottom text-right " >
< small > $c_codicefiscale $ </ small >
</ td >
2021-07-26 17:32:07 +02:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
if ( ! empty ( $destinazione )) {
echo '
2021-07-26 17:32:07 +02:00
< tr >
< td colspan = 2 class = " border-full " style = " height:16mm; " >
< p class = " small-bold " > '.tr(' Destinazione diversa ', [], [' upper ' => true]).' </ p >
< small > '.$destinazione.' </ small >
</ td >
</ tr > ' ;
2024-01-15 15:30:45 +01:00
}
echo '
2017-09-12 17:46:19 +02:00
</ table >
</ div >
</ div > ' ;
// Descrizione
2019-07-12 12:40:13 +02:00
if ( ! empty ( $documento [ 'descrizione' ])) {
2017-09-12 17:46:19 +02:00
echo '
2019-07-12 12:40:13 +02:00
< p > '.nl2br($documento[' descrizione ']).' </ p >
2017-09-12 17:46:19 +02:00
< br > ' ;
}
// Intestazione tabella per righe
echo "
< table class = 'table table-striped table-bordered' id = 'contents' >
< thead >
< tr >
< 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 "
2017-09-12 17:46:19 +02:00
< th class = 'text-center' style = 'width:20%' > " .tr('Prezzo unitario', [], ['upper' => true]). " </ th >
2019-07-12 12:40:13 +02:00
< th class = 'text-center' style = 'width:20%' > " .tr('Imponibile', [], ['upper' => true]).'</th>';
}
echo '
2017-09-12 17:46:19 +02:00
</ tr >
</ thead >
< tbody > ' ;
2019-07-12 12:40:13 +02:00
// Righe documento
$righe = $documento -> getRighe ();
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 ;
}
}
}
}
2019-07-12 12:40:13 +02:00
foreach ( $righe as $riga ) {
$r = $riga -> toArray ();
$autofill -> count ( $r [ 'descrizione' ]);
2017-09-12 17:46:19 +02:00
echo '
2023-12-13 17:33:24 +01:00
< tr >
< td > ' ;
$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 );
}
}
$r [ 'descrizione' ] = str_replace ( 'Rif. ' . strtolower ( $key ), '' , $r [ 'descrizione' ]);
}
2017-09-12 17:46:19 +02:00
2023-12-13 17:33:24 +01:00
$source_type = get_class ( $riga );
2017-09-12 17:46:19 +02:00
2023-12-13 17:33:24 +01:00
if ( ! setting ( 'Visualizza riferimento su ogni riga in stampa' )) {
echo $r [ 'descrizione' ];
} else {
echo nl2br ( $r [ 'descrizione' ]);
}
2023-11-13 15:38:27 +01:00
2023-12-13 17:33:24 +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 '
2023-12-13 17:33:24 +01:00
< small > '.$text.' </ small > ' ;
2023-11-13 15:38:27 +01:00
$autofill -> count ( $text , true );
}
2017-09-12 17:46:19 +02:00
}
echo '
2023-12-13 17:33:24 +01:00
</ td > ' ;
2017-09-12 17:46:19 +02:00
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 " >
2023-12-05 17:43:35 +01:00
'.Translator::numberToLocale(abs($riga->qta), $d_qta).' '.$r[' um '].'
2017-09-12 17:46:19 +02:00
</ 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 " >
2023-12-05 17:43:35 +01:00
' . moneyFormat ( $prezzi_ivati ? $riga -> prezzo_unitario_ivato : $riga -> prezzo_unitario , $d_importi );
2017-09-12 17:46:19 +02:00
2019-07-12 12:40:13 +02:00
if ( $riga -> sconto > 0 ) {
2020-02-15 14:11:44 +01:00
$text = discountInfo ( $riga , false );
2018-01-18 19:03:06 +01:00
echo '
2019-07-12 12:40:13 +02:00
< br >< small class = " text-muted " > '.$text.' </ small > ' ;
$autofill -> count ( $text , true );
2017-09-12 17:46:19 +02:00
}
2019-07-12 12:40:13 +02:00
echo '
</ td > ' ;
// Imponibile
echo '
< td class = " text-right " >
2023-12-05 17:43:35 +01:00
'.moneyFormat($prezzi_ivati ? $riga->totale : $riga->totale_imponibile, $d_importi).'
2017-09-12 17:46:19 +02:00
</ td > ' ;
2019-07-12 12:40:13 +02:00
}
2017-09-12 17:46:19 +02:00
} else {
echo '
2019-07-12 12:40:13 +02:00
< td ></ td > ' ;
if ( $options [ 'pricing' ]) {
echo '
< td ></ td >
< td ></ td > ' ;
}
2017-09-12 17:46:19 +02:00
}
echo '
</ tr > ' ;
2019-07-12 12:40:13 +02:00
$autofill -> next ();
2017-09-12 17:46:19 +02:00
}
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 ;
2021-04-06 15:44:51 +02:00
$sconto_finale = $documento -> getScontoFinale ();
$netto_a_pagare = $documento -> netto ;
2019-07-12 12:40:13 +02:00
$show_sconto = $sconto > 0 ;
2017-09-12 17:46:19 +02:00
// TOTALE COSTI FINALI
2017-09-21 15:51:39 +02:00
if ( $options [ 'pricing' ]) {
2019-07-12 12:40:13 +02:00
// Totale imponibile
echo '
2017-09-12 17:46:19 +02:00
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Imponibile ', [], [' upper ' => true]).' :</ b >
</ td >
2019-07-12 12:40:13 +02:00
< th colspan = " 2 " class = " text-right " >
2023-12-06 10:06:36 +01:00
< b > '.moneyFormat($show_sconto ? $imponibile : $totale_imponibile, $d_totali).' </ b >
2017-09-12 17:46:19 +02:00
</ th >
</ tr > ' ;
2019-07-12 12:40:13 +02:00
// Eventuale sconto incondizionato
if ( $show_sconto ) {
2017-09-12 17:46:19 +02:00
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Sconto ', [], [' upper ' => true]).' :</ b >
</ td >
2019-07-12 12:40:13 +02:00
< th colspan = " 2 " class = " text-right " >
2023-12-06 10:06:36 +01:00
< b > '.moneyFormat($sconto, $d_totali).' </ b >
2017-09-12 17:46:19 +02:00
</ th >
</ tr > ' ;
2019-07-12 12:40:13 +02:00
// Totale imponibile
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Totale imponibile ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-right " >
2023-12-06 10:06:36 +01:00
< b > '.moneyFormat($totale_imponibile, $d_totali).' </ b >
2019-07-12 12:40:13 +02:00
</ th >
</ tr > ' ;
2017-09-12 17:46:19 +02:00
}
2019-07-12 12:40:13 +02:00
// IVA
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Totale IVA ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-right " >
2023-12-06 10:06:36 +01:00
< b > '.moneyFormat($totale_iva, $d_totali).' </ b >
2019-07-12 12:40:13 +02:00
</ th >
</ tr > ' ;
2017-09-12 17:46:19 +02:00
// TOTALE
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
2019-07-12 12:40:13 +02:00
< b > '.tr(' Totale documento ', [], [' upper ' => true]).' :</ b >
2017-09-12 17:46:19 +02:00
</ td >
2019-07-12 12:40:13 +02:00
< th colspan = " 2 " class = " text-right " >
2023-12-06 10:06:36 +01:00
< b > '.moneyFormat($totale, $d_totali).' </ b >
2017-09-12 17:46:19 +02:00
</ th >
</ tr > ' ;
2021-04-06 15:44:51 +02:00
2021-04-12 15:51:27 +02:00
if ( $sconto_finale ) {
2022-01-15 17:30:49 +01:00
// SCONTO IN FATTURA
2021-04-06 15:44:51 +02:00
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
2022-01-15 17:30:49 +01:00
< b > '.tr(' Sconto in fattura ', [], [' upper ' => true]).' :</ b >
2021-04-06 15:44:51 +02:00
</ td >
< th colspan = " 2 " class = " text-right " >
2023-12-06 10:06:36 +01:00
< b > '.moneyFormat($sconto_finale, $d_totali).' </ b >
2021-04-06 15:44:51 +02:00
</ th >
</ tr > ' ;
// NETTO A PAGARE
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Netto a pagare ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-right " >
2023-12-06 10:06:36 +01:00
< b > '.moneyFormat($netto_a_pagare, $d_totali).' </ b >
2021-04-06 15:44:51 +02:00
</ th >
</ tr > ' ;
}
2017-09-12 17:46:19 +02:00
}
2021-02-18 18:48:44 +01:00
echo '
2017-09-12 17:46:19 +02:00
</ table > ' ;
// CONDIZIONI GENERALI DI FORNITURA
2024-02-08 13:10:46 +01:00
$pagamento = Pagamento :: find ( $documento [ 'idpagamento' ]);
2017-09-12 17:46:19 +02:00
echo '
< table class = " table table-bordered " >
< tr >
2017-09-13 11:15:31 +02:00
< th colspan = " 2 " class = " text-center " style = " font-size:13pt; " >
2017-09-12 17:46:19 +02:00
'.tr(' Condizioni generali di fornitura ', [], [' upper ' => true]).'
</ th >
</ tr >
< tr >
< th style = " width:25% " >
'.tr(' Pagamento ', [], [' upper ' => true]).'
</ th >
< td >
2024-03-20 11:13:28 +01:00
'.$pagamento->getTranslation(' name ').'
2017-09-12 17:46:19 +02:00
</ td >
</ tr >
< tr >
< th >
'.tr(' Validità offerta ', [], [' upper ' => true]).'
</ th >
2017-09-13 13:05:35 +02:00
< td > ' ;
2024-01-15 15:30:45 +01:00
if ( ! empty ( $documento -> validita ) && ! empty ( $documento -> tipo_validita )) {
$intervallo = CarbonInterval :: make ( $documento -> validita . ' ' . $documento -> tipo_validita );
2020-07-07 18:07:56 +02:00
2024-01-15 15:30:45 +01:00
echo $intervallo -> forHumans ();
} elseif ( ! empty ( $documento -> validita )) {
echo tr ( '_TOT_ giorni' , [
'_TOT_' => $documento -> validita ,
]);
} else {
echo '-' ;
}
2017-09-13 13:05:35 +02:00
2024-01-15 15:30:45 +01:00
echo '
2017-09-12 17:46:19 +02:00
</ td >
</ tr >
< tr >
< th >
'.tr(' Validità contratto ', [], [' upper ' => true]).'
</ th >
2017-09-13 13:05:35 +02:00
< td > ' ;
2024-01-15 15:30:45 +01:00
if ( ! empty ( $documento [ 'data_accettazione' ]) && ! empty ( $documento [ 'data_conclusione' ])) {
echo '
2017-09-12 17:46:19 +02:00
'.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 '-' ;
}
2017-09-13 13:05:35 +02:00
2024-01-15 15:30:45 +01:00
echo '
2017-09-12 17:46:19 +02:00
</ td >
</ tr >
< tr >
< th >
'.tr(' Esclusioni ', [], [' upper ' => true]).'
</ th >
< td >
2019-07-12 12:40:13 +02:00
'.nl2br($documento[' esclusioni ']).'
2017-09-12 17:46:19 +02:00
</ 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 '
2017-09-12 17:46:19 +02:00
< 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
}
2021-12-21 10:58:20 +01:00
if ( ! empty ( $documento -> condizioni_fornitura )) {
echo '<pagebreak>' . $documento -> condizioni_fornitura ;
2023-08-04 14:54:28 +02:00
}