mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Miglioramento bollo
This commit is contained in:
parent
af459e1c69
commit
0d6d80dcf6
@ -40,85 +40,76 @@ switch (post('op')) {
|
||||
|
||||
case 'update':
|
||||
if (post('id_record') !== null) {
|
||||
$idstatodocumento = post('idstatodocumento');
|
||||
$idpagamento = post('idpagamento');
|
||||
$fattura->data=post('data');
|
||||
$fattura->data_ricezione=post('data_ricezione');
|
||||
$fattura->numero_esterno=post('numero_esterno');
|
||||
$fattura->note=post('note');
|
||||
$fattura->note_aggiuntive=post('note_aggiuntive');
|
||||
|
||||
$totale_imponibile = get_imponibile_fattura($id_record);
|
||||
$totale_fattura = get_totale_fattura($id_record);
|
||||
$fattura->idstatodocumento=post('idstatodocumento');
|
||||
$fattura->idtipodocumento=post('idtipodocumento');
|
||||
$fattura->idanagrafica=post('idanagrafica');
|
||||
$fattura->idagente=post('idagente');
|
||||
$fattura->idpagamento=post('idpagamento');
|
||||
$fattura->idbanca=post('idbanca');
|
||||
$fattura->idcausalet=post('idcausalet');
|
||||
$fattura->idspedizione=post('idspedizione');
|
||||
$fattura->idporto=post('idporto');
|
||||
$fattura->idaspettobeni=post('idaspettobeni');
|
||||
$fattura->idvettore=post('idvettore');
|
||||
$fattura->idsede=post('idsede');
|
||||
$fattura->idconto=post('idconto');
|
||||
$fattura->split_payment=post('split_payment') ?: 0;
|
||||
$fattura->is_fattura_conto_terzi=post('is_fattura_conto_terzi') ?: 0;
|
||||
$fattura->n_colli=post('n_colli');
|
||||
$fattura->tipo_resa=post('tipo_resa');
|
||||
|
||||
$fattura->rivalsainps=0;
|
||||
$fattura->ritenutaacconto=0;
|
||||
$fattura->iva_rivalsainps=0;
|
||||
|
||||
$fattura->codice_stato_fe=post('codice_stato_fe') ?: null;
|
||||
$fattura->id_ritenuta_contributi=post('id_ritenuta_contributi') ?: null;
|
||||
|
||||
$data = [];
|
||||
if ($dir == 'uscita') {
|
||||
$data = [
|
||||
'numero' => post('numero'),
|
||||
'numero_esterno' => post('numero_esterno'),
|
||||
'idrivalsainps' => post('id_rivalsa_inps'),
|
||||
'idritenutaacconto' => post('id_ritenuta_acconto'),
|
||||
];
|
||||
$fattura->numero = post('numero');
|
||||
$fattura->numero_esterno = post('numero_esterno');
|
||||
$fattura->idrivalsainps = post('id_rivalsa_inps');
|
||||
$fattura->idritenutaacconto = post('id_ritenuta_acconto');
|
||||
}
|
||||
|
||||
// Leggo la descrizione del pagamento
|
||||
$query = 'SELECT descrizione FROM co_pagamenti WHERE id='.prepare($idpagamento);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$pagamento = $rs[0]['descrizione'];
|
||||
$fattura->addebita_bollo=post('addebita_bollo');
|
||||
$bollo_automatico = post('bollo_automatico');
|
||||
if (empty($bollo_automatico)){
|
||||
$fattura->bollo = post('bollo');
|
||||
}else{
|
||||
$fattura->bollo = null;
|
||||
}
|
||||
|
||||
// Query di aggiornamento
|
||||
$dbo->update('co_documenti', array_merge([
|
||||
'data' => post('data'),
|
||||
'data_ricezione' => post('data_ricezione'),
|
||||
'numero_esterno' => post('numero_esterno'),
|
||||
'note' => post('note'),
|
||||
'note_aggiuntive' => post('note_aggiuntive'),
|
||||
|
||||
'idstatodocumento' => $idstatodocumento,
|
||||
'idtipodocumento' => post('idtipodocumento'),
|
||||
'idanagrafica' => post('idanagrafica'),
|
||||
'idagente' => post('idagente'),
|
||||
'idpagamento' => $idpagamento,
|
||||
'idbanca' => post('idbanca'),
|
||||
'idcausalet' => post('idcausalet'),
|
||||
'idspedizione' => post('idspedizione'),
|
||||
'idporto' => post('idporto'),
|
||||
'idaspettobeni' => post('idaspettobeni'),
|
||||
'idvettore' => post('idvettore'),
|
||||
'idsede' => post('idsede'),
|
||||
'idconto' => post('idconto'),
|
||||
'split_payment' => post('split_payment') ?: 0,
|
||||
'is_fattura_conto_terzi' => post('is_fattura_conto_terzi') ?: 0,
|
||||
'n_colli' => post('n_colli'),
|
||||
'tipo_resa' => post('tipo_resa'),
|
||||
'addebita_bollo' => post('addebita_bollo'),
|
||||
'bollo' => 0,
|
||||
'rivalsainps' => 0,
|
||||
'ritenutaacconto' => 0,
|
||||
'iva_rivalsainps' => 0,
|
||||
'codice_stato_fe' => post('codice_stato_fe') ?: null,
|
||||
'id_ritenuta_contributi' => post('id_ritenuta_contributi') ?: null,
|
||||
], $data), ['id' => $id_record]);
|
||||
|
||||
$query = 'SELECT descrizione FROM co_statidocumento WHERE id='.prepare($idstatodocumento);
|
||||
$rs = $dbo->fetchArray($query);
|
||||
$fattura->save();
|
||||
|
||||
// Ricalcolo inps, ritenuta e bollo (se la fattura non è stata pagata)
|
||||
ricalcola_costiagg_fattura($id_record);
|
||||
|
||||
$stato = $fattura->stato;
|
||||
// Elimino la scadenza e tutti i movimenti, poi se la fattura è emessa le ricalcolo
|
||||
if ($rs[0]['descrizione'] == 'Bozza' or $rs[0]['descrizione'] == 'Annullata') {
|
||||
if ($stato['descrizione'] == 'Bozza' or $stato['descrizione'] == 'Annullata') {
|
||||
elimina_scadenza($id_record);
|
||||
//elimina_movimento($id_record, 0);
|
||||
//elimino movimento anche prima nota (se pagata o parzialmente pagata)
|
||||
elimina_movimento($id_record, 1);
|
||||
} elseif ($rs[0]['descrizione'] == 'Emessa') {
|
||||
} elseif ($stato['descrizione'] == 'Emessa') {
|
||||
elimina_scadenza($id_record);
|
||||
elimina_movimento($id_record, 0);
|
||||
} elseif (($rs[0]['descrizione'] == 'Pagato' or $rs[0]['descrizione'] == 'Parzialmente pagato') and ($dbo->fetchNum('SELECT id FROM co_scadenziario WHERE iddocumento = '.prepare($id_record)) == 0)) {
|
||||
} elseif (($stato['descrizione'] == 'Pagato' or $stato['descrizione'] == 'Parzialmente pagato') and ($dbo->fetchNum('SELECT id FROM co_scadenziario WHERE iddocumento = '.prepare($id_record)) == 0)) {
|
||||
// aggiungo la scadenza come già pagata
|
||||
aggiungi_scadenza($id_record, $pagamento, 1);
|
||||
aggiungi_scadenza($id_record, null, 1);
|
||||
aggiungi_movimento($id_record, $dir);
|
||||
}
|
||||
|
||||
// Se la fattura è in stato "Emessa" posso inserirla in scadenzario e aprire il mastrino cliente
|
||||
if ($rs[0]['descrizione'] == 'Emessa') {
|
||||
aggiungi_scadenza($id_record, $pagamento);
|
||||
if ($stato['descrizione'] == 'Emessa') {
|
||||
aggiungi_scadenza($id_record);
|
||||
aggiungi_movimento($id_record, $dir);
|
||||
}
|
||||
|
||||
|
@ -256,11 +256,6 @@ if ($dir == 'uscita') {
|
||||
<div class="col-md-3">
|
||||
{[ "type": "select", "label": "<?php echo tr('Ritenuta contributi'); ?>", "name": "id_ritenuta_contributi", "value": "$id_ritenuta_contributi$", "values": "query=SELECT * FROM co_ritenuta_contributi" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
{[ "type": "checkbox", "label": "<?php echo tr('Addebita marca da bollo'); ?>", "name": "addebita_bollo", "value": "$addebita_bollo$" ]}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@ -278,6 +273,36 @@ if ($dir == 'uscita') {
|
||||
</div>
|
||||
|
||||
<?php
|
||||
echo '
|
||||
<div class="box box-info">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title"><i class="fa fa-file"></i> '.tr('Bollo').'</h3>
|
||||
</div>
|
||||
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
{[ "type": "checkbox", "label": "'.tr('Addebita marca da bollo').'", "name": "addebita_bollo", "value": "$addebita_bollo$" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{[ "type": "checkbox", "label": "'.tr('Bollo automatico').'", "name": "bollo_automatico", "value": "'.intval(!isset($record['bollo'])).'", "help": "'.tr("Seleziona per impostare automaticamente l'importo del bollo").'", "placeholder": "'.tr('Bollo automatico').'" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{[ "type": "number", "label": "'.tr('Importo bollo').'", "name": "bollo", "value": "$bollo$", "disabled": '.intval(!isset($record['bollo'])).' ]}
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#bollo_automatico").click(function(){
|
||||
$("#bollo").attr("disabled", $(this).is(":checked"));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
if ($tipodoc == 'Fattura accompagnatoria di vendita') {
|
||||
echo '
|
||||
|
@ -396,7 +396,11 @@ class Fattura extends Document
|
||||
public function save(array $options = [])
|
||||
{
|
||||
// Fix dei campi statici
|
||||
$this->calcolaMarcaDaBollo();
|
||||
$bollo =$this->bollo;
|
||||
if( $bollo == null)
|
||||
$bollo = $this->calcolaMarcaDaBollo();
|
||||
|
||||
$this->manageRigaMarcaDaBollo($bollo, $this->addebita_bollo);
|
||||
|
||||
$this->attributes['ritenutaacconto'] = $this->ritenuta_acconto;
|
||||
$this->attributes['iva_rivalsainps'] = $this->iva_rivalsa_inps;
|
||||
@ -529,12 +533,15 @@ class Fattura extends Document
|
||||
// Se l'importo è negativo può essere una nota di credito, quindi cambio segno alla marca da bollo
|
||||
$marca_da_bollo = abs($marca_da_bollo);
|
||||
|
||||
$this->bollo = $marca_da_bollo;
|
||||
return $marca_da_bollo;
|
||||
}
|
||||
|
||||
protected function manageRigaMarcaDaBollo($marca_da_bollo, $addebita_bollo){
|
||||
|
||||
$riga = $this->rigaBollo;
|
||||
|
||||
// Rimozione riga bollo se nullo
|
||||
if (empty($this->addebita_bollo) || empty($marca_da_bollo)) {
|
||||
if (empty($addebita_bollo) || empty($marca_da_bollo)) {
|
||||
if (!empty($riga)) {
|
||||
$this->id_riga_bollo = null;
|
||||
|
||||
|
@ -253,7 +253,8 @@ INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`
|
||||
ALTER TABLE `zz_settings` CHANGE `help` `help` varchar(255);
|
||||
UPDATE `zz_settings` SET `help` = NULL WHERE `help` = '';
|
||||
|
||||
ALTER TABLE `co_documenti` CHANGE `data_stato_fe` `data_stato_fe` TIMESTAMP NULL, ADD `addebita_bollo` BOOLEAN NOT NULL DEFAULT TRUE, ADD `id_riga_bollo` int(11), ADD FOREIGN KEY (`id_riga_bollo`) REFERENCES `co_righe_documenti`(`id`) ON DELETE SET NULL;
|
||||
ALTER TABLE `co_documenti` CHANGE `bollo` `bollo` decimal(12,4), CHANGE `data_stato_fe` `data_stato_fe` TIMESTAMP NULL, ADD `addebita_bollo` BOOLEAN NOT NULL DEFAULT TRUE, ADD `id_riga_bollo` int(11), ADD FOREIGN KEY (`id_riga_bollo`) REFERENCES `co_righe_documenti`(`id`) ON DELETE SET NULL;
|
||||
UPDATE `co_documenti` SET `bollo` = NULL;
|
||||
UPDATE `co_documenti` SET `data_ricezione` = NULL WHERE `data_ricezione` = '0000-00-00';
|
||||
UPDATE `co_documenti` SET `data_stato_fe` = NULL WHERE `data_stato_fe` = '0000-00-00 00:00:00';
|
||||
|
||||
@ -349,4 +350,4 @@ UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS('' '', REPLACE(REPLACE(REPLA
|
||||
|
||||
|
||||
-- Aggiornamento widget "Acquisti" (iva esclusa)
|
||||
UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS('' '', REPLACE(REPLACE(REPLACE(FORMAT((SELECT SUM(subtotale-sconto-co_righe_documenti.ritenutaacconto)), 2), '','', ''#''), ''.'', '',''), ''#'', ''.''), ''€'') AS dato FROM (co_righe_documenti INNER JOIN co_documenti ON co_righe_documenti.iddocumento=co_documenti.id) INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_tipidocumento.dir=''uscita'' |segment| AND data >= ''|period_start|'' AND data <= ''|period_end|'' AND 1=1', `help` = 'Fatturato IVA esclusa.' WHERE `zz_widgets`.`name` = 'Acquisti';
|
||||
UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS('' '', REPLACE(REPLACE(REPLACE(FORMAT((SELECT SUM(subtotale-sconto-co_righe_documenti.ritenutaacconto)), 2), '','', ''#''), ''.'', '',''), ''#'', ''.''), ''€'') AS dato FROM (co_righe_documenti INNER JOIN co_documenti ON co_righe_documenti.iddocumento=co_documenti.id) INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_tipidocumento.dir=''uscita'' |segment| AND data >= ''|period_start|'' AND data <= ''|period_end|'' AND 1=1', `help` = 'Fatturato IVA esclusa.' WHERE `zz_widgets`.`name` = 'Acquisti';
|
||||
|
Loading…
x
Reference in New Issue
Block a user