From 248edcbe1e9fbf6a9aeff995778471d2924bf3ef Mon Sep 17 00:00:00 2001 From: valentina Date: Mon, 30 Sep 2024 17:32:35 +0200 Subject: [PATCH] Miglioria footer fatture di vendita --- templates/fatture/footer.php | 177 ++++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 74 deletions(-) diff --git a/templates/fatture/footer.php b/templates/fatture/footer.php index 124edc00d..e7f03421b 100755 --- a/templates/fatture/footer.php +++ b/templates/fatture/footer.php @@ -21,21 +21,10 @@ return; } -// Calcoli -// $imponibile = abs($documento->imponibile); -// $sconto = $documento->sconto; -// $totale_imponibile = abs($documento->totale_imponibile); -// $totale_iva = abs($documento->iva); -// $totale = abs($documento->totale) - $rivalsa; - -$totale_imponibile = 0; -foreach ($v_totale as $key => $v) { - $totale_imponibile += $v; -} -$totale_iva = 0; -foreach ($v_iva as $key => $v) { - $totale_iva += $v; +$imponibile = 0; +foreach ($v_totale as $key => $v) { + $totale_scontato += $v; } $sconto = 0; @@ -43,8 +32,21 @@ $sconto += floatval($riga->sconto); } -$rivalsa = floatval($record['rivalsainps']); -$imponibile = $totale_imponibile + $sconto; +$imponibile = $totale_scontato+$sconto; + +$rivalsa = 0; +foreach ($righe as $riga) { + $rivalsa += floatval($riga->rivalsainps); +} + +$totale_imponibile = $totale_scontato + $rivalsa; + +$totale_iva = 0; +foreach ($righe as $riga) { + $aliquota = $database->fetchOne('SELECT percentuale FROM co_iva WHERE id = '.prepare($riga->idiva))['percentuale']; + $totale_iva += $totale_imponibile * $aliquota / 100; +} + $totale = $totale_iva + $totale_imponibile; $show_sconto = $sconto > 0; @@ -54,14 +56,14 @@ $width = round(100 / ($show_sconto ? 5 : 3), 2); -$has_rivalsa = !empty($record['rivalsainps']); +$has_rivalsa = !empty($rivalsa); $has_ritenuta = !empty($record['ritenutaacconto']) || !empty($documento->totale_ritenuta_contributi) || !empty($record['split_payment']); $has_split_payment = !empty($record['split_payment']); $has_sconto_finale = !empty($sconto_finale); $etichette = [ - 'totale' => tr('Totale', [], ['upper' => true]), - 'totale_parziale' => tr('Totale parziale', [], ['upper' => true]), + 'totale' => tr('Totale imponibile', [], ['upper' => true]), + 'totale_parziale' => tr('Totale documento', [], ['upper' => true]), 'totale_finale' => tr('Netto a pagare', [], ['upper' => true]), ]; @@ -206,12 +208,18 @@ * Se sconto: Imponibile | Sconto | Totale imponibile | Totale IVA | Totale * Altrimenti: Imponibile | Totale IVA | Totale */ +if ($has_ritenuta || $show_sconto || $has_rivalsa) { echo " - ".tr('Imponibile', [], ['upper' => true]).' - '; - + ".tr('Imponibile', [], ['upper' => true])." + "; +} else { + echo " + + + "; +} if ($show_sconto) { echo " @@ -219,90 +227,112 @@ - ".tr('Totale imponibile', [], ['upper' => true]).' + ".tr('Totale scontato', [], ['upper' => true]).' '; } - +if ($has_rivalsa) { echo " - ".tr('Totale IVA', [], ['upper' => true])." - - + ".tr('Cassa Previdenziale', [], ['upper' => true])." + "; +} else { + echo " + + "; +} +echo " - ".(!$has_rivalsa && !$has_ritenuta && !$has_split_payment && !$has_sconto_finale ? $etichette['totale'] : $etichette['totale_parziale'])." + ".(($show_sconto) ? $etichette['totale_parziale'] : $etichette['totale'])." - + "; +if ($has_ritenuta || $show_sconto) { + echo " - ".moneyFormat($show_sconto ? $imponibile : $totale_imponibile, $d_totali).' + ".moneyFormat($imponibile, $d_totali).' '; +} else { + echo " + + + "; +} if ($show_sconto) { echo " - ".moneyFormat(abs($sconto), $d_totali)." - - ".moneyFormat($totale_imponibile, $d_totali).' + ".moneyFormat($totale_scontato, $d_totali).' '; -} - -echo " - - ".moneyFormat($totale_iva, $d_totali)." - - +} else if (!$has_rivalsa) { + echo " - ".moneyFormat($totale, $d_totali).' - - '; + "; +} /* * Riga di riepilogo della Rivalsa INPS. * Rivalsa INPS | Totale (+ Rivalsa INPS) */ if ($has_rivalsa) { - $rs2 = $dbo->fetchArray('SELECT percentuale FROM co_rivalse WHERE id=(SELECT idrivalsainps FROM co_righe_documenti WHERE iddocumento='.prepare($id_record).' AND idrivalsainps!=0 LIMIT 0,1)'); + $rs2 = $dbo->fetchOne('SELECT percentuale, descrizione FROM co_rivalse WHERE id=(SELECT idrivalsainps FROM co_righe_documenti WHERE iddocumento='.prepare($id_record).' AND idrivalsainps!=0)'); - $first_colspan = 3; - $second_colspan = 2; + echo ' + + '.moneyFormat($rivalsa, 2).' +

'.$rs2['descrizione'].'

+ + + '.moneyFormat($totale_imponibile, $d_totali).' + + '; +} else if ($show_sconto) { + echo ' + + + + '.moneyFormat($totale_imponibile, $d_totali).' + + '; +} else { + echo ' + + '.moneyFormat($totale_imponibile, $d_totali).' + '; +} - if (empty($sconto)) { - --$first_colspan; - --$second_colspan; - } +$first_colspan = 3; +$second_colspan = 2; - echo ' - - - '.tr('Rivalsa _PRC_%', [ - '_PRC_' => Translator::numberToLocale($rs2[0]['percentuale'], 0), - ], ['upper' => true]).' - '; +if (empty($sconto)) { + --$first_colspan; + --$second_colspan; +} - echo ' +echo ' + + + '.tr('Totale IVA', [], ['upper' => true]).' + - - '.(!$has_ritenuta && !$has_split_payment && !$has_sconto_finale ? $etichette['totale_finale'] : $etichette['totale_parziale']).' - - + + '.(!$has_ritenuta && !$has_split_payment && !$has_sconto_finale ? $etichette['totale_finale'] : $etichette['totale_parziale']).' + + - + - '.moneyFormat($rivalsa, 2).' - '; - - $totale = $totale + $rivalsa; - echo ' + '.moneyFormat($totale_iva, $d_totali).' + - - '.moneyFormat($totale, 2).' + + '.moneyFormat($totale, $d_totali).' - '; -} +'; + /* * Riga di riepilogo di Ritenuta d'acconto e Ritenuta contributi. @@ -443,8 +473,7 @@ '.moneyFormat($sconto_finale, 2).' - - + '.moneyFormat($totale, 2).' ';