diff --git a/modules/fatture/actions.php b/modules/fatture/actions.php
index 77f374152..70e266b48 100755
--- a/modules/fatture/actions.php
+++ b/modules/fatture/actions.php
@@ -714,6 +714,9 @@ switch ($op) {
$riga = null;
}
+ // Ricalcolo inps, ritenuta e bollo
+ ricalcola_costiagg_fattura($id_record);
+
flash()->info(tr('Righe duplicate!'));
break;
@@ -1064,6 +1067,9 @@ switch ($op) {
flash()->info(tr('Nuovo articolo aggiunto!'));
}
+
+ // Ricalcolo inps, ritenuta e bollo
+ ricalcola_costiagg_fattura($id_record);
} else {
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
echo json_encode($response);
@@ -1113,6 +1119,9 @@ switch ($op) {
}
}
+ // Ricalcolo inps, ritenuta e bollo
+ ricalcola_costiagg_fattura($id_record);
+
if ($numero_totale > 1) {
flash()->info(tr('_NUM_ prezzi modificati!', [
'_NUM_' => $numero_totale,
@@ -1169,6 +1178,9 @@ switch ($op) {
++$numero_totale;
}
+ // Ricalcolo inps, ritenuta e bollo
+ ricalcola_costiagg_fattura($id_record);
+
if ($numero_totale > 1) {
flash()->info(tr('_NUM_ prezzi modificati!', [
'_NUM_' => $numero_totale,
@@ -1203,6 +1215,9 @@ switch ($op) {
flash()->info(tr('Riga aggiornata!'));
}
+ // Ricalcolo inps, ritenuta e bollo
+ ricalcola_costiagg_fattura($id_record);
+
break;
case 'cambia_stato':
diff --git a/modules/fatture/row-list.php b/modules/fatture/row-list.php
index d3ce46151..b35141484 100755
--- a/modules/fatture/row-list.php
+++ b/modules/fatture/row-list.php
@@ -66,6 +66,8 @@ foreach ($righe as $riga) {
$mancanti = 0;
$delete = 'delete_riga';
+ $row_disable = in_array($riga->id, [$fattura->rigaBollo->id, $fattura->id_riga_spese_incasso]);
+
// Individuazione dei seriali
if ($riga->isArticolo() && !empty($riga->abilita_serial)) {
$serials = $riga->serials;
@@ -115,7 +117,7 @@ foreach ($righe as $riga) {
echo '
';
- if (!$block_edit) {
+ if (!$block_edit && !$row_disable) {
echo '
';
}
@@ -220,7 +222,7 @@ foreach ($righe as $riga) {
// Quantità e unità di misura
echo '
|
- {[ "type": "number", "name": "qta_'.$riga->id.'", "value": "'.$riga->qta.'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "disabled": "'.($riga->isSconto() ? 1 : 0).'", "disabled": "'.($block_edit || $riga->isSconto()).'", "decimals": "qta" ]}
+ {[ "type": "number", "name": "qta_'.$riga->id.'", "value": "'.$riga->qta.'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "disabled": "'.($riga->isSconto() ? 1 : 0).'", "disabled": "'.($block_edit || $riga->isSconto() || $row_disable).'", "decimals": "qta" ]}
| ';
if ($riga->isArticolo()) {
@@ -236,7 +238,7 @@ foreach ($righe as $riga) {
} else {
echo '
- {[ "type": "number", "name": "costo_'.$riga->id.'", "value": "'.$riga->costo_unitario.'", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "'.currency().'", "disabled": "'.$block_edit.'" ]}
+ {[ "type": "number", "name": "costo_'.$riga->id.'", "value": "'.$riga->costo_unitario.'", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "'.currency().'", "disabled": "'.($block_edit || $row_disable).'" ]}
| ';
}
}
@@ -249,7 +251,7 @@ foreach ($righe as $riga) {
echo '
'.($show_notifica['show_notifica_prezzo'] ? '' : '').'
- {[ "type": "number", "name": "prezzo_'.$riga->id.'", "value": "'.$riga->prezzo_unitario_corrente.'", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-before": "'.(abs($riga->provvigione_unitaria) > 0 ? '' : '').'", "icon-after": "'.currency().'", "disabled": "'.$block_edit.'" ]}';
+ {[ "type": "number", "name": "prezzo_'.$riga->id.'", "value": "'.$riga->prezzo_unitario_corrente.'", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-before": "'.(abs($riga->provvigione_unitaria) > 0 ? '' : '').'", "icon-after": "'.currency().'", "disabled": "'.($block_edit || $row_disable).'" ]}';
// Prezzo inferiore al minimo consigliato
if ($riga->isArticolo()) {
@@ -303,7 +305,7 @@ foreach ($righe as $riga) {
}
if ($record['stato'] != 'Pagato' && $record['stato'] != 'Emessa') {
- if ($riga->id != $fattura->rigaBollo->id) {
+ if (!$row_disable) {
echo '
diff --git a/modules/fatture/src/Fattura.php b/modules/fatture/src/Fattura.php
index f69f4dd2f..63d468d91 100755
--- a/modules/fatture/src/Fattura.php
+++ b/modules/fatture/src/Fattura.php
@@ -441,6 +441,12 @@ class Fattura extends Document
return $this->hasOne(Components\Riga::class, 'iddocumento')->where('id', $this->id_riga_bollo);
}
+ public function rigaSpeseIncasso()
+ {
+ return $this->hasOne(Components\Riga::class, 'iddocumento')->where('id', $this->id_riga_spese_incasso);
+ }
+
+
public function scadenze()
{
return $this->hasMany(Scadenza::class, 'iddocumento')->orderBy('scadenza');
@@ -585,6 +591,7 @@ class Fattura extends Document
// Fix dei campi statici
$this->id_riga_bollo = $this->gestoreBollo->manageRigaMarcaDaBollo();
+ $this->id_riga_spese_incasso = $this->manageRigaSpeseIncasso();
// Generazione numero fattura se non presente (Bozza -> Emessa)
if ((($id_stato_precedente == $id_stato_bozza && $id_stato_attuale == $id_stato_emessa) or (!$is_fiscale)) && empty($this->numero_esterno)) {
@@ -723,6 +730,46 @@ class Fattura extends Document
return $new;
}
+ public function manageRigaSpeseIncasso() {
+ $riga = $this->rigaSpeseIncasso;
+ $first_riga_fattura = $this->getRighe()->where('id', '!=', $riga->id)->where('is_descrizione', '0')->first();
+
+ // Elimino la riga se non c'è più la descrizione dell'incasso o se la fattura non ha righe
+ if (!$this->pagamento->descrizione_incasso || !$first_riga_fattura) {
+ if (!empty($riga)) {
+ $riga->delete();
+ }
+
+ return null;
+ }
+
+ // Creazione riga se non presente
+ if (empty($riga)) {
+ $riga = Components\Riga::build($this);
+ }
+
+ $prezzo_unitario = $this->pagamento->importo_fisso_incasso;
+ if ($this->pagamento->importo_percentuale_incasso && ($this->totale - $riga->totale)) {
+ $prezzo_unitario += ($this->totale - $riga->totale) * $this->pagamento->importo_percentuale_incasso / 100;
+ }
+
+ if ($riga->tipo_sconto == 'PRC') {
+ $sconto = $riga->sconto_percentuale ?: 0;
+ } else {
+ $sconto = $riga->sconto_unitario;
+ }
+
+ $riga->qta = 1;
+ $riga->descrizione = $this->pagamento->descrizione_incasso;
+ $riga->id_iva = $first_riga_fattura->idiva;
+ $riga->idconto = setting("Conto predefinito per le spese d'incasso");
+ $riga->setPrezzoUnitario($prezzo_unitario, $first_riga_fattura->idiva);
+ $riga->setSconto($sconto, $riga->tipo_sconto);
+ $riga->save();
+
+ return $riga->id;
+ }
+
/**
* Restituisce l'elenco delle note di credito collegate.
*
diff --git a/modules/pagamenti/actions.php b/modules/pagamenti/actions.php
index 246b64ec9..29a041c05 100755
--- a/modules/pagamenti/actions.php
+++ b/modules/pagamenti/actions.php
@@ -60,6 +60,9 @@ switch (filter('op')) {
$pagamento->idconto_vendite = post('idconto_vendite') ?: null;
$pagamento->idconto_acquisti = post('idconto_acquisti') ?: null;
$pagamento->setTranslation('title', $descrizione);
+ $pagamento->descrizione_incasso = post('descrizione_incasso');
+ $pagamento->importo_fisso_incasso = post('importo_fisso_incasso');
+ $pagamento->importo_percentuale_incasso = post('importo_percentuale_incasso');
$pagamento->save();
}
diff --git a/modules/pagamenti/edit.php b/modules/pagamenti/edit.php
index 6e4881559..6bc660014 100755
--- a/modules/pagamenti/edit.php
+++ b/modules/pagamenti/edit.php
@@ -52,6 +52,28 @@ include_once __DIR__.'/../../core.php';
+
+
+
+
+
+
+ {[ "type": "text", "label": "", "name": "descrizione_incasso", "value": "$descrizione_incasso$" ]}
+
+
+
+ {[ "type": "number", "label": "", "name": "importo_fisso_incasso", "value": "$importo_fisso_incasso$", "icon-after": "" ]}
+
+
+
+ {[ "type": "number", "label": "", "name": "importo_percentuale_incasso", "value": "$importo_percentuale_incasso$", "icon-after": "%" ]}
+
+
+
+
+
|