mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-03-09 15:50:14 +01:00
feat: Gestione spese d'incasso in fattura
This commit is contained in:
parent
042deff0c0
commit
6a8598d0ef
@ -714,6 +714,9 @@ switch ($op) {
|
|||||||
$riga = null;
|
$riga = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ricalcolo inps, ritenuta e bollo
|
||||||
|
ricalcola_costiagg_fattura($id_record);
|
||||||
|
|
||||||
flash()->info(tr('Righe duplicate!'));
|
flash()->info(tr('Righe duplicate!'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1064,6 +1067,9 @@ switch ($op) {
|
|||||||
|
|
||||||
flash()->info(tr('Nuovo articolo aggiunto!'));
|
flash()->info(tr('Nuovo articolo aggiunto!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ricalcolo inps, ritenuta e bollo
|
||||||
|
ricalcola_costiagg_fattura($id_record);
|
||||||
} else {
|
} else {
|
||||||
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
|
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
@ -1113,6 +1119,9 @@ switch ($op) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ricalcolo inps, ritenuta e bollo
|
||||||
|
ricalcola_costiagg_fattura($id_record);
|
||||||
|
|
||||||
if ($numero_totale > 1) {
|
if ($numero_totale > 1) {
|
||||||
flash()->info(tr('_NUM_ prezzi modificati!', [
|
flash()->info(tr('_NUM_ prezzi modificati!', [
|
||||||
'_NUM_' => $numero_totale,
|
'_NUM_' => $numero_totale,
|
||||||
@ -1169,6 +1178,9 @@ switch ($op) {
|
|||||||
++$numero_totale;
|
++$numero_totale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ricalcolo inps, ritenuta e bollo
|
||||||
|
ricalcola_costiagg_fattura($id_record);
|
||||||
|
|
||||||
if ($numero_totale > 1) {
|
if ($numero_totale > 1) {
|
||||||
flash()->info(tr('_NUM_ prezzi modificati!', [
|
flash()->info(tr('_NUM_ prezzi modificati!', [
|
||||||
'_NUM_' => $numero_totale,
|
'_NUM_' => $numero_totale,
|
||||||
@ -1203,6 +1215,9 @@ switch ($op) {
|
|||||||
flash()->info(tr('Riga aggiornata!'));
|
flash()->info(tr('Riga aggiornata!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ricalcolo inps, ritenuta e bollo
|
||||||
|
ricalcola_costiagg_fattura($id_record);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'cambia_stato':
|
case 'cambia_stato':
|
||||||
|
@ -66,6 +66,8 @@ foreach ($righe as $riga) {
|
|||||||
$mancanti = 0;
|
$mancanti = 0;
|
||||||
$delete = 'delete_riga';
|
$delete = 'delete_riga';
|
||||||
|
|
||||||
|
$row_disable = in_array($riga->id, [$fattura->rigaBollo->id, $fattura->id_riga_spese_incasso]);
|
||||||
|
|
||||||
// Individuazione dei seriali
|
// Individuazione dei seriali
|
||||||
if ($riga->isArticolo() && !empty($riga->abilita_serial)) {
|
if ($riga->isArticolo() && !empty($riga->abilita_serial)) {
|
||||||
$serials = $riga->serials;
|
$serials = $riga->serials;
|
||||||
@ -115,7 +117,7 @@ foreach ($righe as $riga) {
|
|||||||
echo '
|
echo '
|
||||||
<tr data-id="'.$riga->id.'" data-type="'.$riga::class.'" '.$extra.'>
|
<tr data-id="'.$riga->id.'" data-type="'.$riga::class.'" '.$extra.'>
|
||||||
<td class="text-center">';
|
<td class="text-center">';
|
||||||
if (!$block_edit) {
|
if (!$block_edit && !$row_disable) {
|
||||||
echo '
|
echo '
|
||||||
<input class="check" type="checkbox"/>';
|
<input class="check" type="checkbox"/>';
|
||||||
}
|
}
|
||||||
@ -220,7 +222,7 @@ foreach ($righe as $riga) {
|
|||||||
// Quantità e unità di misura
|
// Quantità e unità di misura
|
||||||
echo '
|
echo '
|
||||||
<td>
|
<td>
|
||||||
{[ "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" ]}
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
if ($riga->isArticolo()) {
|
if ($riga->isArticolo()) {
|
||||||
@ -236,7 +238,7 @@ foreach ($righe as $riga) {
|
|||||||
} else {
|
} else {
|
||||||
echo '
|
echo '
|
||||||
<td>
|
<td>
|
||||||
{[ "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).'" ]}
|
||||||
</td>';
|
</td>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,7 +251,7 @@ foreach ($righe as $riga) {
|
|||||||
echo '
|
echo '
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
'.($show_notifica['show_notifica_prezzo'] ? '<i class="fa fa-info-circle notifica-prezzi"></i>' : '').'
|
'.($show_notifica['show_notifica_prezzo'] ? '<i class="fa fa-info-circle notifica-prezzi"></i>' : '').'
|
||||||
{[ "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 ? '<span class=\'tip text-info\' title=\''.provvigioneInfo($riga).'\'><small><i class=\'fa fa-handshake-o\'></i></small></span>' : '').'", "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 ? '<span class=\'tip text-info\' title=\''.provvigioneInfo($riga).'\'><small><i class=\'fa fa-handshake-o\'></i></small></span>' : '').'", "icon-after": "'.currency().'", "disabled": "'.($block_edit || $row_disable).'" ]}';
|
||||||
|
|
||||||
// Prezzo inferiore al minimo consigliato
|
// Prezzo inferiore al minimo consigliato
|
||||||
if ($riga->isArticolo()) {
|
if ($riga->isArticolo()) {
|
||||||
@ -303,7 +305,7 @@ foreach ($righe as $riga) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($record['stato'] != 'Pagato' && $record['stato'] != 'Emessa') {
|
if ($record['stato'] != 'Pagato' && $record['stato'] != 'Emessa') {
|
||||||
if ($riga->id != $fattura->rigaBollo->id) {
|
if (!$row_disable) {
|
||||||
echo '
|
echo '
|
||||||
<a class="btn btn-xs btn-info" title="'.tr('Aggiungi informazioni FE per questa riga').'" onclick="apriInformazioniFE(this)">
|
<a class="btn btn-xs btn-info" title="'.tr('Aggiungi informazioni FE per questa riga').'" onclick="apriInformazioniFE(this)">
|
||||||
<i class="fa fa-file-code-o"></i>
|
<i class="fa fa-file-code-o"></i>
|
||||||
|
@ -441,6 +441,12 @@ class Fattura extends Document
|
|||||||
return $this->hasOne(Components\Riga::class, 'iddocumento')->where('id', $this->id_riga_bollo);
|
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()
|
public function scadenze()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Scadenza::class, 'iddocumento')->orderBy('scadenza');
|
return $this->hasMany(Scadenza::class, 'iddocumento')->orderBy('scadenza');
|
||||||
@ -585,6 +591,7 @@ class Fattura extends Document
|
|||||||
|
|
||||||
// Fix dei campi statici
|
// Fix dei campi statici
|
||||||
$this->id_riga_bollo = $this->gestoreBollo->manageRigaMarcaDaBollo();
|
$this->id_riga_bollo = $this->gestoreBollo->manageRigaMarcaDaBollo();
|
||||||
|
$this->id_riga_spese_incasso = $this->manageRigaSpeseIncasso();
|
||||||
|
|
||||||
// Generazione numero fattura se non presente (Bozza -> Emessa)
|
// 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)) {
|
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;
|
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.
|
* Restituisce l'elenco delle note di credito collegate.
|
||||||
*
|
*
|
||||||
|
@ -60,6 +60,9 @@ switch (filter('op')) {
|
|||||||
$pagamento->idconto_vendite = post('idconto_vendite') ?: null;
|
$pagamento->idconto_vendite = post('idconto_vendite') ?: null;
|
||||||
$pagamento->idconto_acquisti = post('idconto_acquisti') ?: null;
|
$pagamento->idconto_acquisti = post('idconto_acquisti') ?: null;
|
||||||
$pagamento->setTranslation('title', $descrizione);
|
$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();
|
$pagamento->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,28 @@ include_once __DIR__.'/../../core.php';
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card card-primary">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3 class="card-title"><?php echo tr('Spese di incasso in fattura'); ?></h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
{[ "type": "text", "label": "<?php echo tr('Descrizione riga'); ?>", "name": "descrizione_incasso", "value": "$descrizione_incasso$" ]}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
{[ "type": "number", "label": "<?php echo tr('Importo fisso'); ?>", "name": "importo_fisso_incasso", "value": "$importo_fisso_incasso$", "icon-after": "<?php echo currency(); ?>" ]}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3">
|
||||||
|
{[ "type": "number", "label": "<?php echo tr('Importo percentuale'); ?>", "name": "importo_percentuale_incasso", "value": "$importo_percentuale_incasso$", "icon-after": "%" ]}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="card card-primary">
|
<div class="card card-primary">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h3 class="card-title"><?php echo tr('Rate'); ?></h3>
|
<h3 class="card-title"><?php echo tr('Rate'); ?></h3>
|
||||||
|
@ -121,4 +121,17 @@ INSERT INTO `zz_views_lang` (`id_lang`, `id_record`, `title`) VALUES
|
|||||||
(1, (SELECT `id` FROM `zz_views` WHERE `name` = 'Da rinnovare' AND `id_module` = @id_module), 'Da rinnovare'),
|
(1, (SELECT `id` FROM `zz_views` WHERE `name` = 'Da rinnovare' AND `id_module` = @id_module), 'Da rinnovare'),
|
||||||
(2, (SELECT `id` FROM `zz_views` WHERE `name` = 'Da rinnovare' AND `id_module` = @id_module), 'Renewable');
|
(2, (SELECT `id` FROM `zz_views` WHERE `name` = 'Da rinnovare' AND `id_module` = @id_module), 'Renewable');
|
||||||
|
|
||||||
UPDATE `zz_views` SET `query` = "IF(`co_contratti`.`rinnovabile`=1, 'Sì', 'No')" WHERE `zz_views`.`name` = "Rinnovabile" AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = "Contratti");
|
UPDATE `zz_views` SET `query` = "IF(`co_contratti`.`rinnovabile`=1, 'Sì', 'No')" WHERE `zz_views`.`name` = "Rinnovabile" AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = "Contratti");
|
||||||
|
|
||||||
|
-- Gestione spese d'incasso
|
||||||
|
ALTER TABLE `co_pagamenti` ADD `descrizione_incasso` TEXT NOT NULL, ADD `importo_fisso_incasso` DECIMAL(15,6) NOT NULL, ADD `importo_percentuale_incasso` DECIMAL(15,6) NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE `co_documenti` ADD `id_riga_spese_incasso` INT NOT NULL;
|
||||||
|
|
||||||
|
INSERT INTO `zz_settings` (`nome`, `valore`, `tipo`, `editable`, `sezione`, `order`, `is_user_setting`) VALUES
|
||||||
|
("Conto predefinito per le spese d'incasso", (SELECT `id` FROM `co_pianodeiconti3` WHERE `descrizione`='Ricavi vari'), "query=SELECT id, descrizione FROM co_pianodeiconti3 WHERE idpianodeiconti2=(SELECT id FROM co_pianodeiconti2 WHERE descrizione='Ricavi')", "1", "Fatturazione", NULL, 0);
|
||||||
|
|
||||||
|
SELECT @id_record := `id` FROM `zz_settings` WHERE `nome` = "Conto predefinito per le spese d'incasso";
|
||||||
|
INSERT INTO `zz_settings_lang` (`id_lang`, `id_record`, `title`, `help`) VALUES
|
||||||
|
('1', @id_record, "Conto predefinito per le spese d'incasso", ''),
|
||||||
|
('2', @id_record, 'Default account for collection costs', '');
|
Loading…
x
Reference in New Issue
Block a user