mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-03-06 12:17:58 +01:00
Miglioramento del guadagno
@maicol07
This commit is contained in:
parent
cc2a95a39b
commit
a371c24f4b
@ -26,66 +26,61 @@ echo '
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
// Prezzo di acquisto unitario
|
||||
echo '
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
{[ "type": "number", "label": "'.tr('Prezzo di acquisto unitario').'", "name": "prezzo_acquisto", "value": "'.$result['prezzo_unitario_acquisto'].'", "required": 0, "icon-after": "€", "onkeyup": "aggiorna_guadagno()" ]}
|
||||
<div class="row">';
|
||||
|
||||
$width = $options['dir'] == 'entrata' ? 4 :6;
|
||||
if ($options['dir'] == 'entrata') {
|
||||
// Prezzo di acquisto unitario
|
||||
echo '
|
||||
<div class="col-md-'.$width.'">
|
||||
{[ "type": "number", "label": "'.tr('Prezzo di acquisto unitario').'", "name": "prezzo_acquisto", "value": "'.$result['prezzo_unitario_acquisto'].'", "icon-after": "€", "onkeyup": "aggiorna_guadagno()" ]}
|
||||
<span id="guadagno"></span>
|
||||
</div>';
|
||||
|
||||
// Funzione per l'aggiornamento in tempo reale del guadagno
|
||||
echo '
|
||||
<script>
|
||||
function aggiorna_guadagno() {
|
||||
var prezzo_acquisto = $("#prezzo_acquisto").val().toEnglish();
|
||||
var prezzo = $("#prezzo").val().toEnglish();
|
||||
var sconto = $("#sconto").val().toEnglish();
|
||||
if ($("#tipo_sconto").val() === "PRC") {
|
||||
sconto = sconto / 100 * prezzo
|
||||
}
|
||||
|
||||
var guadagno = prezzo - sconto - prezzo_acquisto;
|
||||
var parent = $("#prezzo_acquisto").closest("div").parent();
|
||||
var div = parent.find("div[id*=\"errors\"]");
|
||||
|
||||
div.html("'.tr('Guadagno').': " + guadagno.toLocale());
|
||||
if (guadagno < 0) {
|
||||
parent.addClass("has-error");
|
||||
div.addClass("text-danger").removeClass("text-success");
|
||||
} else {
|
||||
parent.removeClass("has-error");
|
||||
div.removeClass("text-danger").addClass("text-success");
|
||||
}
|
||||
}
|
||||
|
||||
aggiorna_guadagno();
|
||||
$("#tipo_sconto").change(aggiorna_guadagno);
|
||||
</script>';
|
||||
}
|
||||
|
||||
// Prezzo di vendita unitario
|
||||
echo '
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-'.$width.'">
|
||||
{[ "type": "number", "label": "'.tr('Prezzo di vendita unitario').'", "name": "prezzo", "value": "'.$result['prezzo'].'", "required": 1, "icon-after": "€", "onkeyup": "aggiorna_guadagno()" ]}
|
||||
</div>';
|
||||
|
||||
// Sconto unitario
|
||||
echo '
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-'.$width.'">
|
||||
{[ "type": "number", "label": "'.tr('Sconto unitario').'", "name": "sconto", "value": "'.$result['sconto_unitario'].'", "icon-after": "choice|untprc|'.$result['tipo_sconto'].'", "onkeyup": "aggiorna_guadagno()"]}
|
||||
</div>';
|
||||
|
||||
// Guadagno unitario
|
||||
echo '
|
||||
<div class="col-md-3">
|
||||
{[ "type": "number", "label": "'.tr('Guadagno unitario').'", "name": "guadagno", "value": "'.$result['sconto_unitario'].'", "icon-after": "€", "disabled": 1 ]}
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
// Funzione per l'aggiornamento in tempo reale del guadagno
|
||||
|
||||
echo '
|
||||
<script>
|
||||
function aggiorna_guadagno() {
|
||||
var prezzo_acquisto = parseFloat($("#prezzo_acquisto").val().replace(/\./g, ""));
|
||||
var prezzo = parseFloat($("#prezzo").val().replace(/\./g, ""));
|
||||
var sconto = parseFloat($("#sconto").val().replace(/\./g, ""));
|
||||
if ($("#tipo_sconto").val() === "PRC") {
|
||||
sconto = sconto / 100 * prezzo
|
||||
}
|
||||
var guadagno = $("#guadagno");
|
||||
var parentdiv = guadagno.parent();
|
||||
var errorsdiv = parentdiv.parent().find("div[id*=\'errors\']");
|
||||
guadagno.val(prezzo - sconto - prezzo_acquisto);
|
||||
if (parseFloat(guadagno.val().replace(/\./g, "")) < 0) {
|
||||
guadagno.css("color", "red");
|
||||
parentdiv.addClass("has-error");
|
||||
errorsdiv.addClass("has-error");
|
||||
if (errorsdiv.find(".help-block").length === 0) {
|
||||
errorsdiv.append("<span class=\'help-block\'>Il guadagno è negativo!</span>");
|
||||
}
|
||||
} else {
|
||||
guadagno.css("color", "black");
|
||||
parentdiv.removeClass("has-error");
|
||||
errorsdiv.removeClass("has-error");
|
||||
errorsdiv.find(".help-block").remove()
|
||||
}
|
||||
}
|
||||
aggiorna_guadagno();
|
||||
$("#tipo_sconto").change(aggiorna_guadagno)
|
||||
</script>
|
||||
';
|
||||
|
||||
if ($module['name'] == 'Fatture di vendita') {
|
||||
$collapsed = empty($result['data_inizio_periodo']) && empty($result['data_fine_periodo']) && empty($result['riferimento_amministrazione']);
|
||||
|
||||
|
@ -19,6 +19,10 @@ abstract class Description extends Model
|
||||
$builder->where('is_descrizione', '=', 0);
|
||||
});
|
||||
}
|
||||
|
||||
static::addGlobalScope('not_discount', function (Builder $builder) {
|
||||
$builder->where('sconto_globale', '=', 0);
|
||||
});
|
||||
}
|
||||
|
||||
public static function make($bypass = false)
|
||||
|
74
include/src/Discount.php
Normal file
74
include/src/Discount.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Common;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
abstract class Discount extends Model
|
||||
{
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope('is_discount', function (Builder $builder) {
|
||||
$builder->where('sconto_globale', '=', 1);
|
||||
});
|
||||
}
|
||||
|
||||
public static function make()
|
||||
{
|
||||
$model = parent::make();
|
||||
|
||||
$model->sconto_globale = 1;
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il totale dello sconto.
|
||||
*/
|
||||
public function getTotaleAttribute()
|
||||
{
|
||||
return $this->imponibile + $this->iva;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il netto dello sconto.
|
||||
*/
|
||||
public function getNettoAttribute()
|
||||
{
|
||||
return $this->totale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'imponibile scontato dello sconto.
|
||||
*/
|
||||
public function getImponibileScontatoAttribute()
|
||||
{
|
||||
return $this->imponibile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'imponibile dello sconto.
|
||||
*/
|
||||
public function getImponibileAttribute()
|
||||
{
|
||||
return $this->subtotale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il "guadagno" dello sconto.
|
||||
*/
|
||||
public function getGuadagnoAttribute()
|
||||
{
|
||||
return $this->imponibile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il totale dello sconto.
|
||||
*/
|
||||
public function getIvaAttribute()
|
||||
{
|
||||
return $this->attributes['iva'];
|
||||
}
|
||||
}
|
@ -9,9 +9,33 @@ abstract class Document extends Model
|
||||
*
|
||||
* @return iterable
|
||||
*/
|
||||
protected function getRighe()
|
||||
public function getRighe()
|
||||
{
|
||||
return $this->righe->merge($this->articoli);
|
||||
$descrizioni = $this->descrizioni;
|
||||
$righe = $this->righe;
|
||||
$articoli = $this->articoli;
|
||||
|
||||
return $descrizioni->merge($righe)->merge($articoli)->sortBy('order');
|
||||
}
|
||||
|
||||
abstract public function righe();
|
||||
|
||||
abstract public function articoli();
|
||||
|
||||
abstract public function descrizioni();
|
||||
|
||||
abstract public function scontoGlobale();
|
||||
|
||||
/**
|
||||
* Restituisce la collezione di righe e articoli con valori rilevanti per i conti.
|
||||
*
|
||||
* @return iterable
|
||||
*/
|
||||
protected function getRigheContabili()
|
||||
{
|
||||
$sconto = $this->scontoGlobale ? [$this->scontoGlobale] : [];
|
||||
|
||||
return $this->getRighe()->merge(collect($sconto));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,7 +59,7 @@ abstract class Document extends Model
|
||||
*/
|
||||
public function getImponibileAttribute()
|
||||
{
|
||||
return $this->round($this->getRighe()->sum('imponibile'));
|
||||
return $this->round($this->getRigheContabili()->sum('imponibile'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +69,7 @@ abstract class Document extends Model
|
||||
*/
|
||||
public function getScontoAttribute()
|
||||
{
|
||||
return $this->round($this->getRighe()->sum('sconto'));
|
||||
return $this->round($this->getRigheContabili()->sum('sconto'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,7 +79,7 @@ abstract class Document extends Model
|
||||
*/
|
||||
public function getImponibileScontatoAttribute()
|
||||
{
|
||||
return $this->round($this->getRighe()->sum('imponibile_scontato'));
|
||||
return $this->round($this->getRigheContabili()->sum('imponibile_scontato'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +89,7 @@ abstract class Document extends Model
|
||||
*/
|
||||
public function getIvaAttribute()
|
||||
{
|
||||
return $this->round($this->getRighe()->sum('iva'));
|
||||
return $this->round($this->getRigheContabili()->sum('iva'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,7 +99,7 @@ abstract class Document extends Model
|
||||
*/
|
||||
public function getRivalsaINPSAttribute()
|
||||
{
|
||||
return $this->round($this->getRighe()->sum('rivalsa_inps'));
|
||||
return $this->round($this->getRigheContabili()->sum('rivalsa_inps'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +109,7 @@ abstract class Document extends Model
|
||||
*/
|
||||
public function getRitenutaAccontoAttribute()
|
||||
{
|
||||
return $this->round($this->getRighe()->sum('ritenuta_acconto'));
|
||||
return $this->round($this->getRigheContabili()->sum('ritenuta_acconto'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +119,7 @@ abstract class Document extends Model
|
||||
*/
|
||||
public function getTotaleAttribute()
|
||||
{
|
||||
return $this->round($this->getRighe()->sum('totale'));
|
||||
return $this->round($this->getRigheContabili()->sum('totale'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,6 +129,26 @@ abstract class Document extends Model
|
||||
*/
|
||||
public function getNettoAttribute()
|
||||
{
|
||||
return $this->round($this->getRighe()->sum('netto'));
|
||||
return $this->round($this->getRigheContabili()->sum('netto'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcola la spesa totale relativa alla fattura.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getSpesaAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('spesa'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcola il netto a pagare della fattura.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getGuadagnoAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('guadagno'));
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,16 @@ abstract class Row extends Description
|
||||
return $this->imponibile_scontato + $this->iva + $this->rivalsa_inps;
|
||||
}
|
||||
|
||||
public function getSpesaAttribute()
|
||||
{
|
||||
return $this->prezzo_unitario_acquisto * $this->qta;
|
||||
}
|
||||
|
||||
public function getGuadagnoAttribute()
|
||||
{
|
||||
return $this->imponibile_scontato - $this->spesa;
|
||||
}
|
||||
|
||||
public function getNettoAttribute()
|
||||
{
|
||||
return $this->totale - $this->ritenuta_acconto;
|
||||
|
@ -567,6 +567,9 @@ switch (post('op')) {
|
||||
$articolo->id_rivalsa_inps = post('id_rivalsa_inps');
|
||||
}
|
||||
|
||||
if (post('prezzo_acquisto')) {
|
||||
$riga->prezzo_unitario_acquisto = post('prezzo_acquisto');
|
||||
}
|
||||
$articolo->prezzo_unitario_vendita = post('prezzo');
|
||||
$articolo->sconto_unitario = post('sconto');
|
||||
$articolo->tipo_sconto = post('tipo_sconto');
|
||||
@ -622,7 +625,9 @@ switch (post('op')) {
|
||||
$riga->id_rivalsa_inps = post('id_rivalsa_inps');
|
||||
}
|
||||
|
||||
$riga->prezzo_unitario_acquisto = post("prezzo_acquisto");
|
||||
if (post('prezzo_acquisto')) {
|
||||
$riga->prezzo_unitario_acquisto = post('prezzo_acquisto');
|
||||
}
|
||||
$riga->prezzo_unitario_vendita = post('prezzo');
|
||||
$riga->qta = $qta;
|
||||
$riga->sconto_unitario = post('sconto');
|
||||
|
@ -4,10 +4,13 @@ include_once __DIR__.'/../../core.php';
|
||||
|
||||
include_once Modules::filepath('Fatture di vendita', 'modutil.php');
|
||||
|
||||
/*
|
||||
Righe fattura
|
||||
*/
|
||||
$rs = $dbo->fetchArray('SELECT *, round(sconto_unitario,'.setting('Cifre decimali per importi').') AS sconto_unitario, round(sconto,'.setting('Cifre decimali per importi').') AS sconto, round(subtotale,'.setting('Cifre decimali per importi').') AS subtotale, IFNULL((SELECT codice FROM mg_articoli WHERE id=idarticolo),"") AS codice, (SELECT descrizione FROM co_pianodeiconti3 WHERE co_pianodeiconti3.id=IF(co_righe_documenti.idconto = 0, (SELECT idconto FROM co_documenti WHERE iddocumento='.prepare($id_record).' LIMIT 1), co_righe_documenti.idconto)) AS descrizione_conto FROM `co_righe_documenti` WHERE iddocumento='.prepare($id_record).' ORDER BY `order`');
|
||||
use Modules\Fatture\Descrizione;
|
||||
use Modules\Fatture\Articolo;
|
||||
use Modules\Fatture\Riga;
|
||||
|
||||
// Righe fattura
|
||||
//$rs = $dbo->fetchArray('SELECT *, round(sconto_unitario,'.setting('Cifre decimali per importi').') AS sconto_unitario, round(sconto,'.setting('Cifre decimali per importi').') AS sconto, round(subtotale,'.setting('Cifre decimali per importi').') AS subtotale, IFNULL((SELECT codice FROM mg_articoli WHERE id=idarticolo),"") AS codice, (SELECT descrizione FROM co_pianodeiconti3 WHERE co_pianodeiconti3.id=IF(co_righe_documenti.idconto = 0, (SELECT idconto FROM co_documenti WHERE iddocumento='.prepare($id_record).' LIMIT 1), co_righe_documenti.idconto)) AS descrizione_conto FROM `co_righe_documenti` WHERE iddocumento='.prepare($id_record).' ORDER BY `order`');
|
||||
$righe = $fattura->getRighe();
|
||||
|
||||
echo '
|
||||
<table class="table table-striped table-hover table-condensed table-bordered">
|
||||
@ -16,25 +19,22 @@ echo '
|
||||
<th>'.tr('Descrizione').'</th>
|
||||
<th width="120">'.tr('Q.tà').'</th>
|
||||
<th width="80">'.tr('U.m.').'</th>
|
||||
<th width="150">'.tr('Prezzo acq. unitario').'</th>
|
||||
<th width="160">'.tr('Prezzo vend. unitario').'</th>
|
||||
<th width="120">'.tr('Prezzo unitario').'</th>
|
||||
<th width="120">'.tr('Iva').'</th>
|
||||
<th width="120">'.tr('Importo').'</th>
|
||||
<th width="120">'.tr('Guadagno').'</th>
|
||||
<th width="60"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="sortable">';
|
||||
|
||||
if (!empty($rs)) {
|
||||
foreach ($rs as $r) {
|
||||
foreach ($righe as $riga) {
|
||||
// Valori assoluti
|
||||
$r['qta'] = abs($r['qta']);
|
||||
$r['prezzo_unitario_acquisto'] = abs($r['prezzo_unitario_acquisto']);
|
||||
$r['subtotale'] = abs($r['subtotale']);
|
||||
$r['sconto_unitario'] = abs($r['sconto_unitario']);
|
||||
$r['sconto'] = abs($r['sconto']);
|
||||
$r['iva'] = abs($r['iva']);
|
||||
$riga['qta'] = abs($riga['qta']);
|
||||
$riga['prezzo_unitario_acquisto'] = abs($riga['prezzo_unitario_acquisto']);
|
||||
$riga['subtotale'] = abs($riga['subtotale']);
|
||||
$riga['sconto_unitario'] = abs($riga['sconto_unitario']);
|
||||
$riga['sconto'] = abs($riga['sconto']);
|
||||
$riga['iva'] = abs($riga['iva']);
|
||||
|
||||
$extra = '';
|
||||
|
||||
@ -42,23 +42,23 @@ if (!empty($rs)) {
|
||||
$ref_id = null;
|
||||
|
||||
// Preventivi
|
||||
if (!empty($r['idpreventivo'])) {
|
||||
if (!empty($riga['idpreventivo'])) {
|
||||
$delete = 'unlink_preventivo';
|
||||
}
|
||||
// Contratti
|
||||
elseif (!empty($r['idcontratto'])) {
|
||||
elseif (!empty($riga['idcontratto'])) {
|
||||
$delete = 'unlink_contratto';
|
||||
}
|
||||
// Intervento
|
||||
elseif (!empty($r['idintervento'])) {
|
||||
elseif (!empty($riga['idintervento'])) {
|
||||
$delete = 'unlink_intervento';
|
||||
}
|
||||
// Articoli
|
||||
elseif (!empty($r['idarticolo'])) {
|
||||
elseif ($riga instanceof Articolo) {
|
||||
$ref_modulo = Modules::get('Articoli')['id'];
|
||||
$ref_id = $r['idarticolo'];
|
||||
$ref_id = $riga['idarticolo'];
|
||||
|
||||
$r['descrizione'] = (!empty($r['codice']) ? $r['codice'].' - ' : '').$r['descrizione'];
|
||||
$riga['descrizione'] = (!empty($riga['codice']) ? $riga['codice'].' - ' : '').$riga['descrizione'];
|
||||
|
||||
$delete = 'unlink_articolo';
|
||||
|
||||
@ -71,9 +71,9 @@ if (!empty($rs)) {
|
||||
}
|
||||
|
||||
// Individuazione dei seriali
|
||||
if (!empty($r['abilita_serial'])) {
|
||||
$serials = array_column($dbo->fetchArray('SELECT serial FROM mg_prodotti WHERE serial IS NOT NULL AND id_riga_documento='.prepare($r['id'])), 'serial');
|
||||
$mancanti = $r['qta'] - count($serials);
|
||||
if (!empty($riga['abilita_serial'])) {
|
||||
$serials = array_column($dbo->fetchArray('SELECT serial FROM mg_prodotti WHERE serial IS NOT NULL AND id_riga_documento='.prepare($riga['id'])), 'serial');
|
||||
$mancanti = $riga['qta'] - count($serials);
|
||||
|
||||
if ($mancanti > 0) {
|
||||
$extra = 'class="warning"';
|
||||
@ -83,12 +83,12 @@ if (!empty($rs)) {
|
||||
}
|
||||
|
||||
echo '
|
||||
<tr data-id="'.$r['id'].'" '.$extra.'>
|
||||
<tr data-id="'.$riga['id'].'" '.$extra.'>
|
||||
<td>
|
||||
'.Modules::link($ref_modulo, $ref_id, $r['descrizione']).'
|
||||
<small class="pull-right text-muted">'.$r['descrizione_conto'].'</small>';
|
||||
'.Modules::link($ref_modulo, $ref_id, $riga['descrizione']).'
|
||||
<small class="pull-right text-muted">'.$riga['descrizione_conto'].'</small>';
|
||||
|
||||
if (!empty($r['abilita_serial'])) {
|
||||
if (!empty($riga['abilita_serial'])) {
|
||||
if (!empty($mancanti)) {
|
||||
echo '
|
||||
<br><b><small class="text-danger">'.tr('_NUM_ serial mancanti', [
|
||||
@ -124,11 +124,11 @@ if (!empty($rs)) {
|
||||
</td>';
|
||||
|
||||
echo '
|
||||
<td class="text-right">';
|
||||
<td class="text-center">';
|
||||
|
||||
if (empty($r['is_descrizione'])) {
|
||||
if (!$riga instanceof Descrizione) {
|
||||
echo '
|
||||
'.Translator::numberToLocale($r['qta'], 'qta');
|
||||
'.Translator::numberToLocale($riga->qta, 'qta');
|
||||
}
|
||||
|
||||
echo '
|
||||
@ -138,36 +138,30 @@ if (!empty($rs)) {
|
||||
echo '
|
||||
<td class="text-center">';
|
||||
|
||||
if (empty($r['is_descrizione'])) {
|
||||
if (!$riga instanceof Descrizione) {
|
||||
echo '
|
||||
'.$r['um'];
|
||||
'.$riga['um'];
|
||||
}
|
||||
|
||||
echo '
|
||||
</td>';
|
||||
|
||||
// Prezzo di acquisto unitario
|
||||
// Prezzi unitari
|
||||
echo '
|
||||
<td class="text-right">';
|
||||
|
||||
if (empty($r['is_descrizione'])) {
|
||||
if (!$riga instanceof Descrizione) {
|
||||
echo '
|
||||
'.Translator::numberToLocale($r['prezzo_unitario_acquisto']).' €';
|
||||
}
|
||||
'.Translator::numberToLocale($riga->prezzo_unitario_vendita).' €
|
||||
<br><small>
|
||||
'.tr('Acquisto').': '.Translator::numberToLocale($riga->prezzo_unitario_acquisto).' €
|
||||
</small>';
|
||||
|
||||
// Prezzo di vendita unitario
|
||||
echo '
|
||||
<td class="text-right">';
|
||||
|
||||
if (empty($r['is_descrizione'])) {
|
||||
echo '
|
||||
'.Translator::numberToLocale($r['subtotale'] / $r['qta']).' €';
|
||||
|
||||
if ($r['sconto_unitario'] > 0) {
|
||||
if ($riga->sconto_unitario > 0) {
|
||||
echo '
|
||||
<br><small class="label label-danger">'.tr('sconto _TOT_ _TYPE_', [
|
||||
'_TOT_' => Translator::numberToLocale($r['sconto_unitario']),
|
||||
'_TYPE_' => ($r['tipo_sconto'] == 'PRC' ? '%' : '€'),
|
||||
'_TOT_' => Translator::numberToLocale($riga->sconto_unitario),
|
||||
'_TYPE_' => ($riga->tipo_sconto == 'PRC' ? '%' : '€'),
|
||||
]).'</small>';
|
||||
}
|
||||
}
|
||||
@ -179,10 +173,10 @@ if (!empty($rs)) {
|
||||
echo '
|
||||
<td class="text-right">';
|
||||
|
||||
if (empty($r['is_descrizione'])) {
|
||||
if (!$riga instanceof Descrizione) {
|
||||
echo '
|
||||
'.Translator::numberToLocale($r['iva']).' €
|
||||
<br><small class="help-block">'.$r['desc_iva'].'</small>';
|
||||
'.Translator::numberToLocale($riga->iva).' €
|
||||
<br><small class="help-block">'.$riga->desc_iva.'</small>';
|
||||
}
|
||||
|
||||
echo '
|
||||
@ -191,25 +185,12 @@ if (!empty($rs)) {
|
||||
// Importo
|
||||
echo '
|
||||
<td class="text-right">';
|
||||
if (empty($r['is_descrizione'])) {
|
||||
if (!$riga instanceof Descrizione) {
|
||||
echo '
|
||||
'.Translator::numberToLocale($r['subtotale'] - $r['sconto']).' €';
|
||||
}
|
||||
echo '
|
||||
</td>';
|
||||
|
||||
// Guadagno
|
||||
$guadagno = $r['subtotale'] - ($r['prezzo_unitario_acquisto'] * $r["qta"]) - ($r["sconto_unitario"] * $r["qta"]);
|
||||
if ($guadagno < 0) {
|
||||
$guadagno_style = "background-color: #FFC6C6; border: 3px solid red";
|
||||
} else {
|
||||
$guadagno_style = "";
|
||||
}
|
||||
echo '
|
||||
<td class="text-right" style="' . $guadagno_style . '">';
|
||||
if (empty($r['is_descrizione'])) {
|
||||
echo '
|
||||
'.Translator::numberToLocale($guadagno).' €';
|
||||
'.Translator::numberToLocale($riga->imponibile_scontato).' €
|
||||
<br><small class="text-'.($riga->guadagno > 0 ? 'success' : 'danger').'">
|
||||
'.tr('Guadagno').': '.Translator::numberToLocale($riga->guadagno).' €
|
||||
</small>';
|
||||
}
|
||||
echo '
|
||||
</td>';
|
||||
@ -218,93 +199,73 @@ if (!empty($rs)) {
|
||||
echo '
|
||||
<td class="text-center">';
|
||||
|
||||
if ($record['stato'] != 'Pagato' && $record['stato'] != 'Emessa' && empty($r['sconto_globale'])) {
|
||||
if ($record['stato'] != 'Pagato' && $record['stato'] != 'Emessa') {
|
||||
echo "
|
||||
<form action='".$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record."' method='post' id='delete-form-".$r['id']."' role='form'>
|
||||
<form action='".$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record."' method='post' id='delete-form-".$riga['id']."' role='form'>
|
||||
<input type='hidden' name='backto' value='record-edit'>
|
||||
<input type='hidden' name='idriga' value='".$r['id']."'>
|
||||
<input type='hidden' name='idriga' value='".$riga['id']."'>
|
||||
<input type='hidden' name='op' value='".$delete."'>";
|
||||
|
||||
if (!empty($r['idarticolo'])) {
|
||||
if ($riga instanceof Articolo) {
|
||||
echo "
|
||||
<input type='hidden' name='idarticolo' value='".$r['idarticolo']."'>";
|
||||
<input type='hidden' name='idarticolo' value='".$riga['idarticolo']."'>";
|
||||
}
|
||||
|
||||
echo "
|
||||
<div class='input-group-btn'>";
|
||||
|
||||
if (empty($record['is_reversed']) && !empty($r['idarticolo']) && $r['abilita_serial'] && (empty($r['idddt']) || empty($r['idintervento']))) {
|
||||
if (empty($record['is_reversed']) && $riga instanceof Articolo && $riga['abilita_serial'] && (empty($riga['idddt']) || empty($riga['idintervento']))) {
|
||||
echo "
|
||||
<a class='btn btn-primary btn-xs'data-toggle='tooltip' title='Aggiorna SN...' onclick=\"launch_modal( 'Aggiorna SN', '".$rootdir.'/modules/fatture/add_serial.php?id_module='.$id_module.'&id_record='.$id_record.'&idriga='.$r['id'].'&idarticolo='.$r['idarticolo']."', 1 );\"><i class='fa fa-barcode' aria-hidden='true'></i></a>";
|
||||
<a class='btn btn-primary btn-xs'data-toggle='tooltip' title='Aggiorna SN...' onclick=\"launch_modal( 'Aggiorna SN', '".$rootdir.'/modules/fatture/add_serial.php?id_module='.$id_module.'&id_record='.$id_record.'&idriga='.$riga['id'].'&idarticolo='.$riga['idarticolo']."', 1 );\"><i class='fa fa-barcode' aria-hidden='true'></i></a>";
|
||||
}
|
||||
|
||||
echo "
|
||||
<a class='btn btn-xs btn-warning' title='Modifica questa riga...' onclick=\"launch_modal( 'Modifica riga', '".$rootdir.'/modules/fatture/row-edit.php?id_module='.$id_module.'&id_record='.$id_record.'&idriga='.$r['id']."', 1 );\"><i class='fa fa-edit'></i></a>
|
||||
<a class='btn btn-xs btn-warning' title='Modifica questa riga...' onclick=\"launch_modal( 'Modifica riga', '".$rootdir.'/modules/fatture/row-edit.php?id_module='.$id_module.'&id_record='.$id_record.'&idriga='.$riga['id']."', 1 );\"><i class='fa fa-edit'></i></a>
|
||||
|
||||
<a class='btn btn-xs btn-danger' title='Rimuovi questa riga...' onclick=\"if( confirm('Rimuovere questa riga dalla fattura?') ){ $('#delete-form-".$r['id']."').submit(); }\"><i class='fa fa-trash'></i></a>
|
||||
<a class='btn btn-xs btn-danger' title='Rimuovi questa riga...' onclick=\"if( confirm('Rimuovere questa riga dalla fattura?') ){ $('#delete-form-".$riga['id']."').submit(); }\"><i class='fa fa-trash'></i></a>
|
||||
</div>
|
||||
</form>";
|
||||
}
|
||||
|
||||
if (empty($r['sconto_globale'])) {
|
||||
echo '
|
||||
<div class="handle clickable" style="padding:10px">
|
||||
<i class="fa fa-sort"></i>
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</td>
|
||||
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
$sconto_globale = $fattura->scontoGlobale;
|
||||
if (!empty($sconto_globale)) {
|
||||
echo '
|
||||
<tr>
|
||||
<td>'.$sconto_globale->descrizione.'</td>
|
||||
<td class="text-center">'.Translator::numberToLocale(1, 'qta').'</td>
|
||||
<td></td>
|
||||
<td class="text-right">'.Translator::numberToLocale($sconto_globale->totale).' €</td>
|
||||
<td class="text-right">'.Translator::numberToLocale($sconto_globale->iva).' €</td>
|
||||
<td class="text-right">'.Translator::numberToLocale($sconto_globale->totale).' €</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</tbody>';
|
||||
|
||||
// Calcoli
|
||||
$totale_acquisto = 0;
|
||||
foreach ($rs as $r) {
|
||||
$totale_acquisto += ($r["prezzo_unitario_acquisto"] * $r["qta"]);
|
||||
}
|
||||
$imponibile = sum(array_column($rs, 'subtotale'));
|
||||
$sconto = sum(array_column($rs, 'sconto'));
|
||||
$iva = sum(array_column($rs, 'iva'));
|
||||
|
||||
$imponibile_scontato = sum($imponibile, -$sconto);
|
||||
|
||||
$totale_iva = sum($iva, $record['iva_rivalsainps']);
|
||||
|
||||
$totale = sum([
|
||||
$imponibile_scontato,
|
||||
$record['rivalsainps'],
|
||||
$totale_iva,
|
||||
]);
|
||||
|
||||
$netto_a_pagare = sum([
|
||||
$totale,
|
||||
$record['bollo'],
|
||||
-$record['ritenutaacconto'],
|
||||
]);
|
||||
|
||||
$imponibile = abs($imponibile);
|
||||
$sconto = abs($sconto);
|
||||
$iva = abs($iva);
|
||||
$imponibile_scontato = abs($imponibile_scontato);
|
||||
$totale_iva = abs($totale_iva);
|
||||
$totale = abs($totale);
|
||||
$netto_a_pagare = abs($netto_a_pagare);
|
||||
|
||||
$totale_guadagno = sum([
|
||||
$imponibile_scontato
|
||||
-$totale_acquisto
|
||||
]);
|
||||
$imponibile = abs($fattura->imponibile);
|
||||
$sconto = abs($fattura->sconto);
|
||||
$imponibile_scontato = abs($fattura->imponibile_scontato);
|
||||
$iva = abs($fattura->iva);
|
||||
$totale = abs($fattura->totale);
|
||||
$netto_a_pagare = abs($fattura->netto);
|
||||
$guadagno = $fattura->guadagno;
|
||||
|
||||
// IMPONIBILE
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
@ -314,10 +275,10 @@ echo '
|
||||
</tr>';
|
||||
|
||||
// SCONTO
|
||||
if (abs($sconto) > 0) {
|
||||
if (!empty($sconto)) {
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Sconto', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
@ -329,7 +290,7 @@ if (abs($sconto) > 0) {
|
||||
// IMPONIBILE SCONTATO
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Imponibile scontato', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
@ -340,28 +301,28 @@ if (abs($sconto) > 0) {
|
||||
}
|
||||
|
||||
// RIVALSA INPS
|
||||
if (abs($record['rivalsainps']) > 0) {
|
||||
if (!empty($fattura->rivalsa_inps)) {
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Rivalsa INPS', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
'.Translator::numberToLocale($record['rivalsainps']).' €
|
||||
'.Translator::numberToLocale($fattura->rivalsa_inps).' €
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
// IVA
|
||||
if (abs($totale_iva) > 0) {
|
||||
if (!empty($iva)) {
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Iva', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
'.Translator::numberToLocale($totale_iva).' €
|
||||
'.Translator::numberToLocale($iva).' €
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>';
|
||||
@ -370,7 +331,7 @@ if (abs($totale_iva) > 0) {
|
||||
// TOTALE
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
@ -380,40 +341,38 @@ echo '
|
||||
</tr>';
|
||||
|
||||
// Mostra marca da bollo se c'è
|
||||
if (abs($record['bollo']) > 0) {
|
||||
if (!empty($fattura->bollo)) {
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Marca da bollo', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
'.Translator::numberToLocale($record['bollo']).' €
|
||||
'.Translator::numberToLocale($fattura->bollo).' €
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
// RITENUTA D'ACCONTO
|
||||
if (abs($record['ritenutaacconto']) > 0) {
|
||||
if (!empty($fattura->ritenuta_acconto)) {
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr("Ritenuta d'acconto", [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
'.Translator::numberToLocale($record['ritenutaacconto']).' €
|
||||
'.Translator::numberToLocale($fattura->ritenuta_acconto).' €
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>';
|
||||
|
||||
//$netto_a_pagare -= $record['ritenutaacconto'];
|
||||
}
|
||||
|
||||
// NETTO A PAGARE
|
||||
if ($totale != $netto_a_pagare) {
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right">
|
||||
@ -424,18 +383,18 @@ if ($totale != $netto_a_pagare) {
|
||||
}
|
||||
|
||||
// GUADAGNO TOTALE
|
||||
if ($totale_guadagno < 0) {
|
||||
$guadagno_style = "background-color: #FFC6C6; border: 3px solid red";
|
||||
if ($guadagno < 0) {
|
||||
$guadagno_style = 'background-color: #FFC6C6; border: 3px solid red';
|
||||
} else {
|
||||
$guadagno_style = "";
|
||||
$guadagno_style = '';
|
||||
}
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<b>'.tr('Guadagno totale', [], ['upper' => true]).':</b>
|
||||
<td colspan="5" class="text-right">
|
||||
<b>'.tr('Guadagno', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right" style="' . $guadagno_style . '">
|
||||
'.Translator::numberToLocale($totale_guadagno).' €
|
||||
<td align="right" style="'.$guadagno_style.'">
|
||||
'.Translator::numberToLocale($guadagno).' €
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>';
|
||||
|
@ -13,6 +13,15 @@ class Fattura extends Document
|
||||
|
||||
protected $table = 'co_documenti';
|
||||
|
||||
/**
|
||||
* The attributes that should be casted to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'bollo' => 'float',
|
||||
];
|
||||
|
||||
public function getModuleAttribute()
|
||||
{
|
||||
return $this->tipo->dir == 'entrata' ? 'Fatture di vendita' : 'Fatture di acquisto';
|
||||
@ -248,4 +257,9 @@ class Fattura extends Document
|
||||
{
|
||||
return $this->hasMany(Descrizione::class, 'iddocumento');
|
||||
}
|
||||
|
||||
public function scontoGlobale()
|
||||
{
|
||||
return $this->hasOne(Sconto::class, 'iddocumento');
|
||||
}
|
||||
}
|
||||
|
31
modules/fatture/src/Sconto.php
Normal file
31
modules/fatture/src/Sconto.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Fatture;
|
||||
|
||||
use Common\Discount;
|
||||
|
||||
class Sconto extends Discount
|
||||
{
|
||||
protected $table = 'co_righe_documenti';
|
||||
|
||||
/**
|
||||
* Crea una nuova riga collegata ad una fattura.
|
||||
*
|
||||
* @param Fattura $fattura
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function make(Fattura $fattura)
|
||||
{
|
||||
$model = parent::make();
|
||||
|
||||
$model->fattura()->associate($fattura);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function fattura()
|
||||
{
|
||||
return $this->belongsTo(Fattura::class, 'iddocumento');
|
||||
}
|
||||
}
|
@ -236,7 +236,7 @@ switch (post('op')) {
|
||||
|
||||
$qta = post('qta');
|
||||
$prezzo = post('prezzo');
|
||||
$prezzo_acquisto = post("prezzo_acquisto");
|
||||
$prezzo_acquisto = post('prezzo_acquisto');
|
||||
|
||||
// Calcolo dello sconto
|
||||
$sconto_unitario = post('sconto');
|
||||
@ -280,7 +280,7 @@ switch (post('op')) {
|
||||
|
||||
$qta = post('qta');
|
||||
$prezzo = post('prezzo');
|
||||
$prezzo_acquisto = post("prezzo_acquisto");
|
||||
$prezzo_acquisto = post('prezzo_acquisto');
|
||||
$subtot = $prezzo * $qta;
|
||||
|
||||
// Calcolo dello sconto
|
||||
|
@ -108,14 +108,14 @@ foreach ($rs as $r) {
|
||||
}
|
||||
|
||||
// Guadagno
|
||||
$guadagno = $r['subtotale'] - ($r['prezzo_unitario_acquisto'] * $r["qta"]) - ($r["sconto_unitario"] * $r["qta"]);
|
||||
$guadagno = $r['subtotale'] - ($r['prezzo_unitario_acquisto'] * $r['qta']) - ($r['sconto_unitario'] * $r['qta']);
|
||||
if ($guadagno < 0) {
|
||||
$guadagno_style = "background-color: #FFC6C6; border: 3px solid red";
|
||||
$guadagno_style = 'background-color: #FFC6C6; border: 3px solid red';
|
||||
} else {
|
||||
$guadagno_style = "";
|
||||
$guadagno_style = '';
|
||||
}
|
||||
echo '
|
||||
<td class="text-right" style="' . $guadagno_style . '">';
|
||||
<td class="text-right" style="'.$guadagno_style.'">';
|
||||
if (empty($r['is_descrizione'])) {
|
||||
echo '
|
||||
'.Translator::numberToLocale($guadagno).' €';
|
||||
@ -157,7 +157,7 @@ foreach ($rs as $r) {
|
||||
// Calcoli
|
||||
$totale_acquisto = 0;
|
||||
foreach ($rs as $r) {
|
||||
$totale_acquisto += ($r["prezzo_unitario_acquisto"] * $r["qta"]);
|
||||
$totale_acquisto += ($r['prezzo_unitario_acquisto'] * $r['qta']);
|
||||
}
|
||||
$imponibile = sum(array_column($rs, 'subtotale'));
|
||||
$sconto = sum(array_column($rs, 'sconto'));
|
||||
@ -171,10 +171,9 @@ $totale = sum([
|
||||
]);
|
||||
$totale_guadagno = sum([
|
||||
$imponibile_scontato
|
||||
-$totale_acquisto
|
||||
- $totale_acquisto,
|
||||
]);
|
||||
|
||||
|
||||
echo '
|
||||
</tbody>';
|
||||
|
||||
@ -253,16 +252,16 @@ echo '
|
||||
|
||||
// GUADAGNO TOTALE
|
||||
if ($totale_guadagno < 0) {
|
||||
$guadagno_style = "background-color: #FFC6C6; border: 3px solid red";
|
||||
$guadagno_style = 'background-color: #FFC6C6; border: 3px solid red';
|
||||
} else {
|
||||
$guadagno_style = "";
|
||||
$guadagno_style = '';
|
||||
}
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="7" class="text-right">
|
||||
<b>'.tr('Guadagno totale', [], ['upper' => true]).':</b>
|
||||
</td>
|
||||
<td align="right" style="' . $guadagno_style . '">
|
||||
<td align="right" style="'.$guadagno_style.'">
|
||||
'.Translator::numberToLocale($totale_guadagno).' €
|
||||
</td>
|
||||
<td></td>
|
||||
|
@ -23,11 +23,6 @@ UPDATE `zz_views` SET `query` = '(SELECT `descrizione` FROM `fe_stati_documento`
|
||||
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES
|
||||
(NULL, 'OSMCloud Services API Token', '', 'string', 1, 'Fatturazione Elettronica', 11);
|
||||
|
||||
-- Prezzo di acquisto nelle fatture di vendita e nei preventivi
|
||||
|
||||
ALTER TABLE `co_righe_documenti` ADD `prezzo_unitario_acquisto` DECIMAL(12,4) NOT NULL AFTER `descrizione`;
|
||||
ALTER TABLE `co_righe_preventivi` ADD `prezzo_unitario_acquisto` DECIMAL(12,4) NOT NULL AFTER `descrizione`;
|
||||
|
||||
-- Allineo valore Iva predefinita secondo nuovi codici tabella co_iva
|
||||
UPDATE `zz_settings` SET `valore` = (SELECT id FROM `co_iva` WHERE `codice` = 22 LIMIT 0,1) WHERE `nome` = 'Iva predefinita' AND `valore` = 91;
|
||||
|
||||
|
@ -5,3 +5,8 @@ UPDATE `fe_stati_documento` SET `icon` = 'fa fa-check text-success' WHERE `codic
|
||||
|
||||
-- Introduzione del flag split payment
|
||||
ALTER TABLE `an_anagrafiche` ADD `split_payment` BOOLEAN NOT NULL DEFAULT FALSE AFTER `codice_destinatario`;
|
||||
|
||||
-- Prezzo di acquisto in Fatture di vendita e Preventivi
|
||||
|
||||
ALTER TABLE `co_righe_documenti` ADD `prezzo_unitario_acquisto` DECIMAL(12,4) NOT NULL AFTER `descrizione`;
|
||||
ALTER TABLE `co_righe_preventivi` ADD `prezzo_unitario_acquisto` DECIMAL(12,4) NOT NULL AFTER `descrizione`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user