a2de8ed91a
Files correlati : cg4.exe cg5.exe cg5300a.uml cg5500b.uml cg5500d.uml cg5500a.rep cg5500b.rep Ricompilazione Demo : [ ] Commento : Modifiche al prospetto della liquidazione iva. Implementare la gestione del credito iva infrannuale e modifiche a quello dell'anno precedente. Aggiunta stampa dei prospetti di liquidazione. Considerato il credito utilizzato a inizio anno come utilizzato e solo se il credito è compensabile in F24 a Gennaio. In realtà era già così git-svn-id: svn://10.65.10.50/branches/R_10_00@23221 c028cbd2-c16b-5b4b-a496-9718f37d4682
4488 lines
156 KiB
C++
Executable File
4488 lines
156 KiB
C++
Executable File
// ------------------------------------------------------------
|
||
// Calcolo liquidazioni
|
||
// Part 2: calcolo
|
||
// fv 21-1-94
|
||
// ------------------------------------------------------------
|
||
|
||
#include <config.h>
|
||
#include <modaut.h>
|
||
#include <recarray.h>
|
||
#include <recset.h>
|
||
#include <progind.h>
|
||
#include <sheet.h>
|
||
|
||
#include "cg4300.h"
|
||
#include "cgsaldac.h"
|
||
|
||
#include <nditte.h>
|
||
#include <attiv.h>
|
||
#include <causali.h>
|
||
#include <tab1100.h>
|
||
#include <mov.h>
|
||
#include <rmoviva.h>
|
||
#include <pconti.h>
|
||
#include <utility.h>
|
||
#include <clifo.h>
|
||
#include <occas.h>
|
||
#include <comuni.h>
|
||
|
||
// -------------------- QUI comincia l'avventura --------------------------
|
||
// Datemi un punto di appoggio ******************
|
||
// e mi ci appoggero' ******************
|
||
// ----------------------------------------------------- ******************
|
||
|
||
bool TLiquidazione_app::recalc_all()
|
||
{
|
||
TString msg;
|
||
msg = _printonly ? TR("Stampa") : TR("Calcolo");
|
||
msg << TR(" liquidazione:\npreparazione archivi...");
|
||
const int nSel = _selected.ones();
|
||
if (nSel > 1)
|
||
_prind = new TProgind(nSel, msg, true, true);
|
||
else
|
||
_prind = new TProgind(1, msg, false, false);
|
||
|
||
for (int l = 0; l < _ditte->items(); l++)
|
||
{
|
||
if (_selected[(long)l])
|
||
{
|
||
if (!_prind->addstatus(1))
|
||
break;
|
||
|
||
TToken_string& nomeditta = _ditte->row(l);
|
||
const long codditta = nomeditta.get_long(1);
|
||
const int save_month = _month;
|
||
|
||
/* -------------------------------------------------------------
|
||
* leggi parametri ditta necessari; stabilisci se annuale,
|
||
* se si' metti _month a 13
|
||
* istanzia _freqviva, _isbenzinaro, _isannual, _isriepilogo
|
||
* --------------------------------------------------------------
|
||
*/
|
||
|
||
_reg_arr.destroy(); // Azzera la cache dei registri per ogni ditta.
|
||
_nditte->zero();
|
||
_nditte->curr().put("CODDITTA",codditta);
|
||
_nditte->read();
|
||
_freqviva = nomeditta.get(3);
|
||
const bool mens = _freqviva == "M";
|
||
|
||
// determina attivita' prevalente e istanzia cazzuole
|
||
// per vedere che Kazzo di liquidazione calcolare
|
||
const TString8 attprev = _nditte->curr().get("CODATTPREV");
|
||
TString16 key;
|
||
|
||
key.format("%ld|%s", codditta, (const char *)attprev);
|
||
|
||
const TRectype & atts = cache().get(LF_ATTIV, key);
|
||
// istanzia benzinaro
|
||
_isbenzinaro = atts.get_bool("ART74_4");
|
||
|
||
// riaggiusta relazione
|
||
_nditte->read();
|
||
|
||
// strasemplificato: per l'annuale si sceglie annuale, altrimenti
|
||
// e' la 12ma anche per le trimestrali.
|
||
_isannual = _isriepilogo = _month == 13;
|
||
|
||
TApplication::set_firm(codditta);
|
||
|
||
// Imposta metodo arrotondamento imposte
|
||
TIva_round ir;
|
||
ir.set_default_iva_mode(atoi(_year), _isannual, codditta);
|
||
|
||
|
||
/*
|
||
* trimestrali impropriamente selezionate per mesi intermedi
|
||
* provocano il ricalcolo dei progressivi mensili ma non la stampa
|
||
*/
|
||
_canprint = is_month_ok_strict(_month) || _month == 13;
|
||
|
||
/* --------------------------------------------------------------
|
||
* Ricalcola i mesi necessari: annuale e' un mese unico da 1/1 al 31/12
|
||
* --------------------------------------------------------------
|
||
*/
|
||
|
||
int need_refresh = false;
|
||
if (_recalc != ever)
|
||
{
|
||
int m = _month == 13 ? _month : 1;
|
||
for (; m < _month; m++)
|
||
if (is_month_ok_strict(m))
|
||
{
|
||
const TRectype & lim = get_lim(m);
|
||
|
||
if (lim.empty() || !lim.get_bool("B0"))
|
||
{
|
||
need_refresh = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (need_refresh && yesno_box(TR("Alcuni mesi precedenti non "
|
||
"risultano ricalcolati. E' consigliabile il ricalcolo. "
|
||
"Si desidera eseguirlo?")))
|
||
_recalc = ever;
|
||
}
|
||
int m;
|
||
for (m = 1; m <= _month; m++) // fino a 13 compreso
|
||
{
|
||
if (is_month_plain(m) || _recalc == ever)
|
||
update_firm(m);
|
||
}
|
||
|
||
// se ci sono altri mesi dopo l'ultimo calcolato, invalida il
|
||
// flag 'calcolato' del primo, per causare il ricalcolo dei
|
||
// successivi (evitando problemi per credito precedente)
|
||
for (m = _month+1; m <= 13; m++)
|
||
{
|
||
TRectype lim = get_lim(m);
|
||
|
||
if (lim.not_empty())
|
||
{
|
||
lim.zero("B0");
|
||
put_lim(lim);
|
||
break;
|
||
}
|
||
}
|
||
|
||
_month = save_month;
|
||
}
|
||
}
|
||
const bool good = _prind->addstatus(1);
|
||
|
||
TApplication::set_firm(__firm);
|
||
delete _prind; _prind = NULL;
|
||
|
||
return good;
|
||
}
|
||
|
||
bool TLiquidazione_app::update_firm(int month, bool recalc)
|
||
{
|
||
// Se recalc e' true considera la necessita' di ricalcolare e le
|
||
// opzioni utente. Se false se ne impipa dell'utente e ricalcola
|
||
// se necessario (serve nelle chiamate ricorsive)
|
||
// Ritorna false soltanto se il ricalcolo era necessario e non e'
|
||
// stato effettuato per scelta dello stronzo commercialista.
|
||
|
||
// Gestione IVA differita, da non confondere con _isdifferita
|
||
_isdiff = ini_get_bool(CONFIG_DITTA, "cg", "GesLiqDiff");
|
||
|
||
if (month == 13 && recalc)
|
||
{
|
||
TTable pem("PEM");
|
||
for (int reg = 0; reg < 23; reg++)
|
||
{
|
||
look_pem(pem, reg);
|
||
pem.zero("R0");
|
||
pem.zero("R1");
|
||
pem.rewrite();
|
||
}
|
||
}
|
||
|
||
_isdiffacc = is_acconto_differito(); // Gestione differimento acconto IVA
|
||
_isdifferita = _isdiffacc;
|
||
|
||
const TRectype & lia = get_lia();
|
||
|
||
_isintr = _freqviva == "T" && !lia.get_bool("B3"); // was CNF_DITTA->InTrtr
|
||
_gest4 = _isbenzinaro && lia.get_bool("B4"); // was CNF_DITTA->Gest74
|
||
|
||
const bool has_single_activity = count_activities() == 1;
|
||
|
||
// controlla che il periodo corrente non sia l'inizio dell'attivita'
|
||
// nel caso, differita va a false
|
||
_monthinatt = 1;
|
||
const TDate inatt = _nditte->curr().get(NDT_DINIZIOATT);
|
||
if (is_in_liq_period(inatt))
|
||
_isdifferita = false;
|
||
if (inatt.year() == atoi(_year))
|
||
_monthinatt = inatt.month();
|
||
|
||
_isricacq = (month == 13) && ini_get_bool(CONFIG_STUDIO, "cg", "RicAcq");
|
||
|
||
// ricalcolo normale
|
||
// lim c'e' solo per i trimestri
|
||
const TRectype & lim = get_lim(liq_month(month), true);
|
||
|
||
bool ok = lim.get_bool("B0");
|
||
if (ok && !recalc)
|
||
return true;
|
||
if (_recalc_regis)
|
||
ok = false; // Se sta ricalcolando i PRM/PRP se ne sbatte delle LIM
|
||
bool calc = (_recalc == ever || (_recalc == one && is_month_ok(month,_month)));
|
||
if (!calc && _recalc != never) calc = !ok;
|
||
bool gheravergot = false;
|
||
bool quater = false;
|
||
|
||
TToken_string atts;
|
||
TToken_string cattivs;
|
||
|
||
// casini per stampa minchie in coda ai registri
|
||
bool riepliq = _isregis ? _riepilogo : false;
|
||
bool stliq = true;
|
||
|
||
_nditte->save_status();
|
||
if (_nditte->is_first_match(LF_ATTIV))
|
||
{
|
||
const TRectype& ndt_att = _nditte->curr(LF_ATTIV);
|
||
do
|
||
{
|
||
const TString8 codatt = ndt_att.get("CODATT");
|
||
const TString80 desatt = ndt_att.get("DESCR");
|
||
quater = _nditte->curr().get_bool("FLIVA11Q");
|
||
|
||
// attivit<69> mista: ce ne sono in realt<6C> due
|
||
// viene calcolato nel ciclo su tipoatt (che viene ripetuto solo se diventa true);
|
||
_mixed = false;
|
||
|
||
if (_prind)
|
||
{
|
||
TString buf(127);
|
||
buf.format( _printonly ? FR("Stampa liquidazione %s %d...\n%s:\n%s\n") :
|
||
FR("Calcolo liquidazione %s %d...\n%s:\n%s\n"),
|
||
itom(month), atoi(_year), (const char*)_nditte_r->get(NDT_RAGSOC), (const char*)desatt);
|
||
_prind->set_text(buf);
|
||
}
|
||
|
||
// se ricalcola l'annuale si tiene tutte le vendite e corrispettivi di
|
||
// tutti i lerci mesi. Analogamente se sta calcolando una trimestrale.
|
||
// Nel caso di trimestrale con ricalcolo trimestri precedenti azzera
|
||
// ad ogni inizio di trimestre.
|
||
if (!(_freqviva == "T" && (month != 1 && month != 4 && month != 7 && month != 10 && month != 13)))
|
||
{
|
||
_vend_arr.destroy();
|
||
_corr_arr.destroy();
|
||
}
|
||
|
||
cattivs = "";
|
||
|
||
for (int tipoatt = 1; tipoatt <= (_mixed ? 2 : 1); tipoatt++)
|
||
{
|
||
TString8 cattiv(codatt);
|
||
cattiv << tipoatt;
|
||
|
||
const bool waspla = look_pla(cattiv, has_single_activity);
|
||
if (!waspla)
|
||
break; // Non calcolare attivit<69> inesistenti 29-11-2012
|
||
|
||
if (tipoatt == 1 && waspla)
|
||
{
|
||
_p8 = _pla->get_real("R5");
|
||
_p8b = _pla->get_real("R6");
|
||
_p9 = _pla->get_real("R7");
|
||
_isplafond = !(_p8.is_zero() && _p8b.is_zero() && _p9.is_zero());
|
||
const char s7 = _pla->get_char("S7");
|
||
_isservizio = (s7 == 'S');
|
||
_mixed = (s7 == 'M') || (s7 == 'E');
|
||
|
||
const TString4 yr(_year);
|
||
TAssoc_array& pa = _prorata.perc_array();
|
||
|
||
pa.destroy();
|
||
pa.add("DEF", _pla->get_real("R8")); // Percentuale di default, anno corrente
|
||
|
||
const int anno = atoi(_year) - 2;
|
||
|
||
for (int i = atoi(_year); i>=anno; i--)
|
||
{
|
||
_year.format("%d", i);
|
||
if (look_pla(cattiv, false)) // Reperisce percentuale prorata anno indicato (se esiste la tabella)
|
||
pa.add(_year, _pla->get_real("R8"));
|
||
}
|
||
_year = yr; // Risetta l'anno corretto e riposiziona la tabella...
|
||
look_pla(cattiv, false);
|
||
}
|
||
else
|
||
_isservizio = ndt_att.get("TIPOATT") == "S";
|
||
|
||
_isviaggio = ndt_att.get_bool("REG74TER");
|
||
_isagricolo = ndt_att.get_bool("REGAGR");
|
||
_isvent = false;
|
||
|
||
if (!_recalc_regis && tipoatt == 1 && waspla && month == 13)
|
||
{
|
||
// azzera pla dove serve
|
||
_pla->zero("R0");
|
||
_pla->zero("R1");
|
||
_pla->zero("R2");
|
||
_pla->zero("R3");
|
||
_pla->zero("R4");
|
||
_pla->zero("R13");
|
||
_pla->zero("R9");
|
||
_pla->zero("R10");
|
||
_pla->zero("R11");
|
||
_pla->zero("R12");
|
||
_pla->zero("R14");
|
||
_pla->zero("R15");
|
||
_pla->zero("R16");
|
||
_pla->zero("R17");
|
||
_pla->zero("R18");
|
||
_pla->put("S1","0");
|
||
_pla->put("S2","0");
|
||
_pla->put("S3","0");
|
||
_pla->rewrite();
|
||
}
|
||
|
||
for (_reg->first(); _reg->good(); _reg->next())
|
||
{
|
||
if (codatt == _reg->get("S8"))
|
||
{
|
||
if (_reg->get_int("I0") == 2)
|
||
if (!_isvent) _isvent = _reg->get_bool("B3");
|
||
}
|
||
}
|
||
|
||
if (!_isregis)
|
||
stliq = riepliq = true;
|
||
|
||
if (_comp_acconto)
|
||
stliq = riepliq = false;
|
||
|
||
if (calc || !recalc)
|
||
if (!update_att(month, cattiv) && stliq)
|
||
describe_error(TR("Attivit<EFBFBD> non ricalcolate: possibili errori"),
|
||
codatt);
|
||
if (_recalc_regis)
|
||
continue;
|
||
|
||
if (month == 13)
|
||
recalc_annual(cattiv);
|
||
|
||
// vediamo se c'e' qualcosa da raccontare
|
||
gheravergot = _isannual || _isriepilogo;
|
||
if (!gheravergot)
|
||
{
|
||
look_plm(month,cattiv);
|
||
gheravergot = !_plm->get_real("R0").is_zero() || !_plm->get_real("R1").is_zero();
|
||
}
|
||
|
||
if (month == _month && riepliq)
|
||
describe_att(month, cattiv, gheravergot, '0' + (_mixed ? tipoatt : 0));
|
||
|
||
atts.add(cattiv);
|
||
cattivs.add(cattiv);
|
||
} // for tipoatt
|
||
|
||
if (_recalc_regis)
|
||
continue;
|
||
|
||
// se attivit<69> mista stampa riepilogo
|
||
if (_mixed && month == _month && riepliq)
|
||
describe_att(month,cattivs, true, 'M');
|
||
|
||
// se sta calcolando l'annuale, scrive tutti i dati calcolati per il trasferimento
|
||
// sui files adibiti a mantenere le informazioni per IVA 11: tab1100a e tab1100b
|
||
if (_is_interactive && month == 13)
|
||
iva11_set_arr_phase_2(codatt); // scorre tutti i maledetti PIM di questa ditta/attivita' per completare _iva11_arr
|
||
}
|
||
while (_nditte->next_match(LF_ATTIV));
|
||
|
||
if (_recalc_regis)
|
||
{
|
||
_nditte->restore_status();
|
||
|
||
// Se trattasi di ricalcolo per registri, setta il flag relativo, onde evitare ricalcoli
|
||
// nel caso di registro riepilogativo: se i PRM esistono gi<67> (perch<63> creati
|
||
// da stampa bollato precedente o altro riepilogo) non vanno ricalcolati.
|
||
|
||
TRectype lim = get_lim(month, true); // Crea se non esiste
|
||
|
||
lim.put("B1","X");
|
||
put_lim(lim);
|
||
return true;
|
||
}
|
||
|
||
// se quater stampa riepilogo
|
||
if (quater && month == _month && riepliq)
|
||
describe_att(month,atts, true, 'Q');
|
||
|
||
// occorre poterla chiamare altre volte con mesi diversi
|
||
_nditte->restore_status();
|
||
|
||
// aggiorna le liquidazioni
|
||
//13/12/1995.
|
||
//Concordato con Ferdinando che, visto che qualche
|
||
//calcoluccio viene fatto anche in write_liq, essa
|
||
//verra' sempre richiamata.
|
||
//if (calc || !recalc)
|
||
//fine
|
||
|
||
// Se siamo in annuale e se non e' stato indicato di ricalcolare (stampa liquidazione chiamata
|
||
// dalla stampa registri) non riscrivere i risultati delle liquidazioni,
|
||
if ((is_month_ok_strict(month) && _month != 13 && _recalc != never) || _is_interactive /*month == 13*/ )
|
||
write_liq(month, atts);
|
||
|
||
// occorre poterla chiamare altre volte con mesi diversi
|
||
_nditte->restore_status();
|
||
|
||
// rimborso infraannuale
|
||
_DescrItem* rimb_d = NULL;
|
||
if (month == _month)
|
||
{
|
||
// unica nel suo genere, recalc_rimborso ritorna
|
||
// un bel descritem (NULL se non si rimborsa un cas)
|
||
// da passare a describe_liq
|
||
rimb_d = recalc_rimborso(month,atts, stliq);
|
||
if (stliq)
|
||
{
|
||
describe_firm(month);
|
||
//describe_liq(_month, atts, _isregis ? NULL : rimb_d);
|
||
describe_liq(_month, atts, rimb_d);
|
||
}
|
||
if (_month == 13) // scrive i risultati solo in annuale
|
||
{
|
||
const TRectype & lim = get_lim(_month);
|
||
|
||
if (lim.not_empty()) // scrive i risultati solo in annuale
|
||
{
|
||
const real r0 = lim.get_real("R0");
|
||
|
||
iva11_write(rimb_d == NULL || r0 >= ZERO); // scrive su tab1100 at last.
|
||
}
|
||
}
|
||
}
|
||
|
||
//in caso di stampa registri e in caso sia
|
||
//stato calcolato l'acconto (metodo analitico)
|
||
//deve essere stampato il prospetto di liquidazione
|
||
//dell'acconto in coda al resto
|
||
if (_isregis && stliq)
|
||
{
|
||
if ((month == 12 && _freqviva == "M") ||
|
||
(month == 12 && _isbenzinaro && _gest4) ||
|
||
(month == 13 && _freqviva == "T" && !_isbenzinaro) ||
|
||
(month == 13 && _isbenzinaro && !_gest4))
|
||
describe_liqacc();
|
||
}
|
||
}
|
||
return ok || calc;
|
||
}
|
||
|
||
bool TLiquidazione_app::update_att(int month, const char* codatt, bool recalc)
|
||
// viene passato un codice attivita' con codatt+tipoatt
|
||
// vedi update_firm per il burdel dei calc e recalc
|
||
// occhecasino. Se _comp_acconto e' true, i movimenti considerati
|
||
// saranno solo quelli di dicembre per data <= 20/12;
|
||
// il ricalcolo e' FORZATO da _recalc messo a one
|
||
{
|
||
look_plm(month, codatt, true);
|
||
bool ok = _plm->get_bool("B0");
|
||
if (_recalc_regis)
|
||
ok = false; // Se sta ricalcolando i PRM/PRP se ne sbatte dei PLM
|
||
if (ok && !recalc)
|
||
return true;
|
||
bool calc = _recalc == ever || (_recalc == one && is_month_ok(month,_month));
|
||
if (!calc && _recalc != never)
|
||
calc = !ok;
|
||
|
||
if (calc || !recalc)
|
||
{
|
||
zero_att(month,codatt);
|
||
recalc_att(month,codatt);
|
||
if (!_recalc_regis)
|
||
{
|
||
// Ricalcolo ventilazione e ag. viaggio:
|
||
// - tutti i mesi se e' mensile
|
||
// - nei mesi 3,6,9,12,13 se trimestrale
|
||
if (_freqviva == "M" || (_freqviva == "T" && (is_trim(month) || month == 13)))
|
||
{
|
||
recalc_ventilation(month, codatt);
|
||
recalc_viaggio(month, codatt);
|
||
}
|
||
recalc_corrispettivi(month, codatt);
|
||
}
|
||
}
|
||
|
||
return ok || calc;
|
||
}
|
||
|
||
void TLiquidazione_app::zero_att(int month, const char* codatt)
|
||
{
|
||
TTable *arr[4] = { _pim, _pis, _prm, _prp };
|
||
const char* flds[] = { "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9",
|
||
"R10", "R11", "R12", "R13", "R14", "R15", "R16", "R17", "R18", "R19",
|
||
"R20", "R21", "R22", "R23", "R24", "R25", "R26", "R27", "R28", "R29",
|
||
"R30", "R31", "R32", "R33",
|
||
"S0", "S1", "S2", NULL };
|
||
|
||
TString80 codtab;
|
||
TString16 att;
|
||
TString4 year;
|
||
int m, start, stop;
|
||
|
||
start = 0; stop = 1;
|
||
|
||
if (_recalc_regis)
|
||
{
|
||
// Se stiamo ricalcolando per registri(_recalc_regis) azzera PRM e PRP
|
||
start = 2; stop = 3;
|
||
}
|
||
// PIM / PIS
|
||
for (int i = start; i <= stop; i++) // Ciclo per le tabelle da azzerare
|
||
{
|
||
TTable * tab = (TTable*) arr[i];
|
||
CHECK(tab, "Invalid table element");
|
||
tab->zero(); tab->put("CODTAB", _year);
|
||
for (int err = tab->read(_isgteq); err == NOERR; err = tab->next()) // Ciclo per i record di tabella
|
||
{
|
||
codtab = tab->get("CODTAB");
|
||
m = atoi(codtab.mid(13,2));
|
||
att = codtab.mid(4,6);
|
||
year = codtab.mid(0,4);
|
||
if (m == month && att == codatt && year == _year)
|
||
{
|
||
for (int j = 0; flds[j]; j++) // Ciclo per i campi del record da azzerare (34 + 3)
|
||
tab->zero(flds[j]);
|
||
tab->rewrite();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!_recalc_regis)
|
||
{
|
||
if (look_plm(month, codatt))
|
||
{
|
||
// zero PLM, POM, PAM, PUM
|
||
const TString16 codtab = _plm->get("CODTAB");
|
||
_plm->zero();
|
||
_pom->zero();
|
||
_pam->zero();
|
||
_pum->zero();
|
||
_plm->put("CODTAB", codtab);
|
||
_pom->put("CODTAB", codtab);
|
||
_pam->put("CODTAB", codtab);
|
||
_pum->put("CODTAB", codtab);
|
||
_plm->rewrite();
|
||
_pam->rewrite();
|
||
_pom->rewrite();
|
||
_pum->rewrite();
|
||
}
|
||
|
||
// Azzera i progressivi per il prospetto agricolo dal 1998
|
||
if (_isagricolo)
|
||
{
|
||
for (_pia->first(); !_pia->eof(); _pia->next())
|
||
{
|
||
const int m = atoi(*_pia_mese);
|
||
const TString8 att = (const char*)*_pia_codatt;
|
||
if (m == month && att == codatt && (_year == *_pia_anno))
|
||
{
|
||
_pia->zero("R0"); // Imponibile
|
||
_pia->zero("R1"); // Imposta
|
||
_pia->rewrite();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (_isplafond && month != 13)
|
||
zero_plafond(month,codatt);
|
||
|
||
if (!_recalc_regis) // Aggiunto test per evitare azzeramenti in stampa registri 19-06-2013
|
||
zero_diff(month,codatt);
|
||
}
|
||
|
||
bool TLiquidazione_app::ivadiff_chiusa(const TRectype& mov, const TDate& fine) const
|
||
{
|
||
bool chiusa = false;
|
||
const long numreg = mov.get_long(MOV_NUMREG);
|
||
TLocalisamfile id(LF_IVADIFF);
|
||
TRectype& rid = id.curr();
|
||
rid.put(MOV_NUMREG, numreg);
|
||
int err = id.read(_isgteq);
|
||
if (err == NOERR && rid.get_long(MOV_NUMREG) == numreg)
|
||
{
|
||
bool some_pag = false; // Ci sono pagamenti?
|
||
TImporto tot;
|
||
for (; err == NOERR && rid.get_long(MOV_NUMREG) == numreg; err = id.next())
|
||
{
|
||
const TDate data = rid.get("DATAREGP");
|
||
if (data > fine)
|
||
continue;
|
||
if (data == fine && rid.get_long("NUMREGP") == numreg)
|
||
continue; // Ignora pagamento automatico dopo un anno
|
||
|
||
const real imp = rid.get(RMI_IMPOSTA);
|
||
if (!imp.is_zero())
|
||
{
|
||
const char sez = rid.get_char("SEZIONE");
|
||
tot += TImporto(sez, imp);
|
||
if (!some_pag && rid.get_int(MOV_TIPOMOV) > 1)
|
||
some_pag = true;
|
||
}
|
||
}
|
||
chiusa = some_pag && tot.valore() < 0.01;
|
||
}
|
||
return chiusa;
|
||
}
|
||
|
||
static TDate data_maturazione_IVA_diff(const TRectype& mov)
|
||
{
|
||
const TDate data_reg = mov.get(MOV_DATAREG);
|
||
const TDate data_doc = mov.get(MOV_DATADOC);
|
||
TDate data_rif = data_doc.ok() && data_doc < data_reg ? data_doc : data_reg;
|
||
data_rif.addyear(1); data_rif.set_end_month();
|
||
return data_rif;
|
||
}
|
||
|
||
// Fattura pi<70> vecchia di un anno a ente NON pubblico
|
||
bool TLiquidazione_app::sarebbe_maturata(const TRectype& mov, const TDate& inizio, const TDate& fine) const
|
||
{
|
||
if (mov.get_int(MOV_TIPOMOV) != tm_fattura)
|
||
return false;
|
||
|
||
const TDate data_lim = data_maturazione_IVA_diff(mov); // Data limite (un anno dopo quella di riferimento)
|
||
if (data_lim < inizio || data_lim > fine)
|
||
return false; // maturazione fuori range
|
||
|
||
// La data di riferimento sarebbe quella di consegna della merce, ma non avendola usiamo la data documento.
|
||
// In assenza della data documento siamo costretti ad usare la data di registrazione
|
||
const TDate data_reg = mov.get(MOV_DATAREG);
|
||
const TDate data_doc = mov.get(MOV_DATADOC);
|
||
const TDate data_rif = data_doc.ok() && data_doc < data_reg ? data_doc : data_reg;
|
||
|
||
const long giorni = fine - data_rif;
|
||
if (giorni < 0 || fine < data_reg) // Diana 2000 registra a Settebre 2014 fatture con data ducumento nel 2013!
|
||
return false;
|
||
|
||
if (mov.get_bool(MOV_LIQDIFF))
|
||
{
|
||
const TDate datainc = mov.get(MOV_DATAINC);
|
||
if (datainc.ok() && datainc <= fine)
|
||
return false; // Gi<47> pagata senza saldaconto
|
||
} else
|
||
if (mov.get_bool(MOV_IVAXCASSA))
|
||
{
|
||
if (_isviaggio || !gestione_IVAxCassa(fine)) // Le agenzie viaggio non posso aderire al regime IVA per cassa
|
||
return true; // Ho superato la soglia di applicabilit<69> dell'IVA per cassa
|
||
}
|
||
else
|
||
return true; // Regime IVA normale
|
||
|
||
const TRectype& clifo = cache().get_rec(LF_CLIFO, mov.get_char(MOV_TIPO), mov.get_long(MOV_CODCF));
|
||
int alleg = clifo.get_int(CLI_ALLEG);
|
||
if (alleg == 7 || alleg == 8) // Ente pubblico e amministrazione controllata ...
|
||
return false; // ... possono aspettare le calende greche
|
||
|
||
if (mov.get_bool(MOV_IVAXCASSA))
|
||
{
|
||
if (alleg == 6) // privato?
|
||
{
|
||
TString16 paiv, cofi;
|
||
if (clifo.get_bool(CLI_OCCAS))
|
||
{
|
||
const TRectype& occas = cache().get(LF_OCCAS, mov.get(MOV_OCFPI));
|
||
paiv = occas.get(OCC_PAIV);
|
||
cofi = occas.get(OCC_COFI);
|
||
}
|
||
else
|
||
{
|
||
paiv = clifo.get(CLI_PAIV);
|
||
cofi = clifo.get(CLI_COFI);
|
||
}
|
||
if (paiv.full())
|
||
alleg = 0; // Falso allarme: NON <20> un privato avendo partita IVA
|
||
}
|
||
if (alleg == 5 || alleg == 6 || alleg == 9) // Privati, import ed export non hanno IVA per cassa
|
||
return true;
|
||
}
|
||
|
||
if (ivadiff_chiusa(mov, min(data_lim,fine)))
|
||
return false;
|
||
|
||
return true; // E' passato pi<70> di un anno!
|
||
}
|
||
|
||
bool TLiquidazione_app::residuo_da_liquidare(const TRectype& lastid, real& importo_res, real& imponib_res, real& imposta_res) const
|
||
{
|
||
const long numreg = lastid.get_long(RMI_NUMREG);
|
||
const int numrig = lastid.get_int(RMI_NUMRIG);
|
||
CHECKD(numreg > 0 && numrig > 0, "Numero registrazione non valido ", numreg);
|
||
const long lastpro = lastid.get_long("NUMPRO");
|
||
|
||
bool found = false;
|
||
|
||
if (!found) // dummy bracketing test
|
||
{
|
||
TString query;
|
||
query << "USE IVADIFF"
|
||
<< "\nFROM NUMREG=" << numreg << " NUMRIG=" << numrig
|
||
<< "\nTO NUMREG=" << numreg << " NUMRIG=" << numrig;
|
||
TISAM_recordset id(query);
|
||
found = id.items() >= 2; // riga fattura ed almeno un pagamento o nota di credito
|
||
if (found)
|
||
{
|
||
TImporto importo, imponib, imposta;
|
||
for (bool ok = id.move_first(); ok; ok = id.move_next())
|
||
{
|
||
const char sez = id.get("SEZIONE").as_string()[0];
|
||
const long numpro = id.get("NUMPRO").as_int();
|
||
if (numpro != lastpro)
|
||
{
|
||
importo += TImporto(sez, id.get(PAGSCA_IMPORTO).as_real());
|
||
imponib += TImporto(sez, id.get(RMI_IMPONIBILE).as_real());
|
||
imposta += TImporto(sez, id.get(RMI_IMPOSTA).as_real());
|
||
}
|
||
}
|
||
|
||
bool is_good = imponib.valore() > ZERO;
|
||
if (!is_good)
|
||
{
|
||
const TRectype& mov_head = cache().get(LF_MOV, numreg);
|
||
int good_sign = +1;
|
||
if (mov_head.get_int(MOV_TIPOMOV) == tm_fattura && mov_head.get(MOV_TIPODOC) == "NC")
|
||
good_sign = -1;
|
||
const real totdoc = mov_head.get(MOV_TOTDOC);
|
||
is_good = totdoc.sign() == good_sign;
|
||
}
|
||
if (is_good)
|
||
{
|
||
importo_res = importo.valore();
|
||
imponib_res = imponib.valore();
|
||
imposta_res = imposta.valore();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!found)
|
||
{
|
||
TLocalisamfile rmi(LF_RMOVIVA);
|
||
rmi.put(RMI_NUMREG, numreg);
|
||
rmi.put(RMI_NUMRIG, numrig);
|
||
found = rmi.read() == NOERR;
|
||
if (found)
|
||
{
|
||
imposta_res = rmi.get_real(RMI_IMPOSTA);
|
||
imponib_res = rmi.get_real(RMI_IMPONIBILE);
|
||
importo_res = imponib_res + imposta_res;
|
||
}
|
||
}
|
||
|
||
return found;
|
||
}
|
||
|
||
static bool partita_chiusa_al(const TPartita& p, const TDate& d)
|
||
{
|
||
bool c = p.chiusa();
|
||
if (c)
|
||
{
|
||
const TImporto imp = p.calcola_saldo_al(true, d, d, d);
|
||
c = imp.is_zero();
|
||
}
|
||
return c;
|
||
}
|
||
|
||
|
||
static void LOG_IVA_DIFF(const TRectype& id)
|
||
{
|
||
#ifndef NDEBUG
|
||
static FILE* file[3] = { NULL, NULL, NULL };
|
||
|
||
if (id.get_int(PART_TIPOMOV) < 3)
|
||
return;
|
||
int nf = 0;
|
||
if (id.get_int("TIPOIVA") == 2) // Acquisti
|
||
nf += 2;
|
||
else
|
||
nf += id.get_int("TIPODIFF") == 1; // Differita
|
||
FILE*& f = file[nf];
|
||
if (f == NULL)
|
||
{
|
||
const char* name = NULL;
|
||
switch (nf)
|
||
{
|
||
case 0: name = "IVA_Ven_xCas.log"; break;
|
||
case 1: name = "IVA_Ven_Diff.log"; break;
|
||
case 2: name = "IVA_Acq_xCas.log"; break;
|
||
default: break;
|
||
}
|
||
fopen_s(&f, name, "w");
|
||
if (f == NULL)
|
||
{
|
||
cantwrite_box(name);
|
||
fopen_s(&f, name, "w");
|
||
}
|
||
if (f != NULL)
|
||
fprintf(f, "NUMREG\tNUMRIG\tNUMPRO\tNUMREGP\tDATAPAG\t \tGen\tFeb\tMar\tApr\tMag\tGiu\tLug\tAgo\tSet\tOtt\tNov\tDic\n");
|
||
}
|
||
if (f != NULL)
|
||
{
|
||
TToken_string msg(255, '\t');
|
||
msg.add(id.get(RMI_NUMREG));
|
||
msg.add(id.get(RMI_NUMRIG));
|
||
msg.add(id.get("NUMPRO"));
|
||
msg.add(id.get("NUMREGP"));
|
||
msg.add(id.get("DATAREGP"));
|
||
for (int i = id.get_int("MESELIQ"); i > 0; i--)
|
||
msg.add(" ");
|
||
msg.add(id.get_real(RMI_IMPOSTA).stringa(0,2));
|
||
fprintf(f, "%s\n", (const char*)msg);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
static void LOG_PIM_DIFF(const TRectype& pim)
|
||
{
|
||
#ifndef NDEBUG
|
||
static FILE* file[2] = { NULL, NULL };
|
||
|
||
const real iva_ven = pim.get("R29");
|
||
const real iva_acq = pim.get("R33");
|
||
|
||
int nf = -1;
|
||
if (!iva_ven.is_zero())
|
||
nf = 0; else
|
||
if (!iva_acq.is_zero())
|
||
nf = 1;
|
||
if (nf < 0)
|
||
return;
|
||
|
||
FILE*& f = file[nf];
|
||
if (f == NULL)
|
||
{
|
||
const char* name = NULL;
|
||
switch (nf)
|
||
{
|
||
case 0: name = "PIM_Ven_Diff.log"; break;
|
||
case 1: name = "PIM_Acq_Diff.log"; break;
|
||
default: break;
|
||
}
|
||
fopen_s(&f, name, "w");
|
||
if (f == NULL)
|
||
{
|
||
cantwrite_box(name);
|
||
fopen_s(&f, name, "w");
|
||
}
|
||
if (f != NULL)
|
||
fprintf(f, "CODTAB\tGen\tFeb\tMar\tApr\tMag\tGiu\tLug\tAgo\tSet\tOtt\tNov\tDic\n");
|
||
}
|
||
if (f != NULL)
|
||
{
|
||
TToken_string msg(255, '\t');
|
||
const TString& codtab = pim.get("CODTAB");
|
||
msg = codtab;
|
||
const int mese = atoi(codtab.mid(14, 2));
|
||
for (int i = mese; i > 0; i--)
|
||
msg.add(" ");
|
||
if (!iva_ven.is_zero())
|
||
msg.add(iva_ven.stringa(0,2));
|
||
else
|
||
msg.add(iva_acq.stringa(0,2));
|
||
fprintf(f, "%s\n", (const char*)msg);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
static bool is_autofattura_articolo_17(const TRectype& mov)
|
||
{
|
||
// E' giusto prendere il tipo documento dal movimento senza fidarsi della causale? si.
|
||
bool af = mov.get(MOV_TIPODOC) == "AF"; // Semplice autofattura (Adesso il tipocr==4 non c'entra piu' un tubo)
|
||
// Dal 24-02-2014 controlliamo meglio
|
||
if (af)
|
||
{
|
||
const TRectype& clifo = cache().get_rec(LF_CLIFO, mov.get(MOV_TIPO), mov.get(MOV_CODCF));
|
||
const int tp = clifo.get_int(CLI_ALLEG);
|
||
af = tp == 5 || tp == 9; // cliente estero CEE o non CEE
|
||
}
|
||
|
||
return af;
|
||
}
|
||
|
||
void TLiquidazione_app::recalc_att(int month, const char* codatt)
|
||
// il codatt passato e' codice att + tipo att ( IN {1|2} )
|
||
// occhecasino. Se _comp_acconto e' true, i movimenti considerati
|
||
// saranno solo quelli di dicembre per data <= 20/12;
|
||
{
|
||
const bool has_sc = has_module(SCAUT, CHK_DONGLE) && ini_get_bool(CONFIG_DITTA, "cg", "GesSal");
|
||
real totintra = ZERO;
|
||
real nond19_imp = ZERO;
|
||
real nond19_iva = ZERO;
|
||
real ammort_det = ZERO;
|
||
real ammort_det_iva = ZERO;
|
||
real ammort_indet = ZERO;
|
||
real ammort_indet_iva = ZERO;
|
||
real ammort_6 = ZERO;
|
||
real ammort_6_iva = ZERO;
|
||
real acq_riv = ZERO;
|
||
real acq_riv_iva = ZERO;
|
||
real leasing = ZERO;
|
||
real leasing_iva = ZERO;
|
||
real cess_amm = ZERO;
|
||
real cess_amm_iva = ZERO;
|
||
real acquisti = ZERO;
|
||
real acquisti_iva = ZERO;
|
||
real vendite = ZERO;
|
||
real vendite_iva = ZERO;
|
||
real esenti_c1 = ZERO;
|
||
real esenti_c2 = ZERO;
|
||
real esenti_c3 = ZERO;
|
||
real esenti_c1a = ZERO;
|
||
real esenti_c3_bam = ZERO; // Beni ammorizzabili esenti c3
|
||
real esenti_c1a_bam = ZERO; // Beni ammorizzabili esenti c1a
|
||
real esenti_b14 = ZERO;
|
||
real vendite_rev = ZERO; // Vendire in reverse charge (da escludere in prorata)
|
||
|
||
/* Comunicazione dati iva annuale dal 2016 calcolata in cg5
|
||
// Comunicazione dati iva annuale (dal 2003)
|
||
real cessioni_cd1_1 = ZERO; // Totale operazioni attive
|
||
real cessioni_cd1_2 = ZERO; // non imponibili
|
||
real cessioni_cd1_3 = ZERO; // esenti
|
||
real cessioni_cd1_4 = ZERO; // intra
|
||
real cessioni_cd1_5 = ZERO; // beni strumentali
|
||
real acquisti_cd2_1 = ZERO; // Totale operazioni passive
|
||
real acquisti_cd2_2 = ZERO; // non imponibili
|
||
real acquisti_cd2_3 = ZERO; // esenti
|
||
real acquisti_cd2_4 = ZERO; // intra
|
||
real acquisti_cd2_5 = ZERO; // beni strumentali
|
||
real oroargento_cd3_1 = ZERO; // imponibile acquisto oro e argento
|
||
real oroargento_cd3_2 = ZERO; // imposta acquisto oro e argento
|
||
real rottami_cd3_3 = ZERO; // imponibile acquisto rottami
|
||
real rottami_cd3_4 = ZERO; // imposta acquisto rottami
|
||
real cessioni_cd1_1s = ZERO; // Totale operazioni attive in split payment
|
||
*/
|
||
|
||
real esni_rimb = ZERO; // ci sommo tutti esenti e ni validi per rimborso
|
||
real corr_CEE = ZERO;
|
||
real corr_noCEE = ZERO;
|
||
real acq_CEE = ZERO;
|
||
real acq_noCEE = ZERO;
|
||
real corr_misCEE = ZERO;
|
||
real acq_misCEE = ZERO;
|
||
real acq_misnoCEE = ZERO;
|
||
real agr_detIA = ZERO;
|
||
real agr_1i = ZERO;
|
||
real agr_2i = ZERO;
|
||
real agr_1 = ZERO;
|
||
real agr_2 = ZERO;
|
||
real agr_3 = ZERO;
|
||
real agr_4 = ZERO;
|
||
real agr_5 = ZERO;
|
||
real agr_6 = ZERO;
|
||
real agr_7 = ZERO;
|
||
real acq_ies = ZERO;
|
||
real acq_ies_iva = ZERO;
|
||
real ult_detr = ZERO;
|
||
real acq_pint = ZERO;
|
||
real acq_pint_iva = ZERO;
|
||
real spgen = ZERO;
|
||
real spgen_iva = ZERO;
|
||
real assp_imp = ZERO;
|
||
real assp_iva = ZERO;
|
||
real vssp_imp = ZERO;
|
||
real vssp_iva = ZERO;
|
||
real assl_imp = ZERO;
|
||
real assl_iva = ZERO;
|
||
real vssl_imp = ZERO;
|
||
real vssl_iva = ZERO;
|
||
real bdog_imp = ZERO;
|
||
real bdog_iva = ZERO;
|
||
real agr_imp = ZERO;
|
||
real agr_iva = ZERO;
|
||
|
||
real fdiff_imp = ZERO;
|
||
real fdiff_iva = ZERO;
|
||
real fdiffinc_imp = ZERO;
|
||
real fdiffinc_iva = ZERO;
|
||
real fdiff_imp_acq = ZERO;
|
||
real fdiff_iva_acq = ZERO;
|
||
real fdiffinc_imp_acq = ZERO;
|
||
real fdiffinc_iva_acq = ZERO;
|
||
|
||
_diff_ven_ap = ZERO;
|
||
_diff_ven_ap_iva = ZERO;
|
||
_diff_acq_ap = ZERO;
|
||
_diff_acq_ap_iva = ZERO;
|
||
|
||
// PEM
|
||
real vt_imponibile[23];
|
||
real vt_imposta[23];
|
||
for (int j = 0; j < 23; j++)
|
||
{
|
||
vt_imponibile[j] = ZERO;
|
||
vt_imposta[j] = ZERO;
|
||
}
|
||
|
||
// Nel seguente assoc, vengono memorizzati gli acquisti iva registrati quest'anno
|
||
// ma con anno documento precedente. Di conseguenza per un corretto calcolo prorata
|
||
// e' necessario distinguire gli importi, appunto, per anno.
|
||
// Questo nuovo calcolo prorata, vale solo per gli anni oltre il 1998.
|
||
TAssoc_array acq_iva_anni_prec;
|
||
|
||
TTable *arr[4] = { _pim, _pis, _prm, _prp }; //Tabelle con la stessa struttura
|
||
|
||
const int year_int = atoi(_year); // Basta con le atoi()...
|
||
|
||
// Nuova selezione filtro dal 1998. Rende molto piu' pesante il calcolo, complimenti a tutti.
|
||
// Il campo MESELIQ sulla testata dei movimenti indica il mese di liquidazione in cui considerare
|
||
// il movimento stesso. Tale campo e' un intero che va da 0 a 12, dove i numeri da 1 a 12 rappresentano
|
||
// i rispettivi mesi (Gennaio...Dicembre) e lo zero significa che questo movimento va considerato
|
||
// seguendo la data di registrazione, ovvero NORMALMENTE.
|
||
// Questo significa che:
|
||
// si includano nel cursore tutti i movimenti da questo inizio mese fino all fine dell'anno
|
||
// Il primo periodo dell'anno successivo (1 o 3 mesi se Trim.) va incluso se sto calcolando dicembre o l'annuale:
|
||
// puo' esistere un doc. con DATAREG di gennaio dell'anno dopo ma MESELIQ==12; tale movimento va considerato in dicembre
|
||
// dell'anno precedente (4 trimestre nel cazo di trimestruali).
|
||
// Ovviamente un tale movimento siffatto andra' considerato allo stesso modo anche in liquidazione annuale.
|
||
// Default date per agenzie viaggio: da inizio anno fino per considerare la DATA74TER
|
||
// Esemplificazione dei cursori nei vari casi:
|
||
// month < 12 : la regione andra' dal 01/month/_year al 31/12/_year
|
||
// selezione movimenti: datareg.month() == month && meseliq == 0 || meseliq == month
|
||
// month == 12 : la regione andra' dal 01/month/_year al lastday/firstperiod/_year+1
|
||
// selezione movimenti: datareg.month() == month && meseliq == 0 || meseliq == month
|
||
// month == 13 : la regione andra' dal 01/01/_year al lastday/firstperiod/_year+1
|
||
// selezione movimenti: datareg.year() == _year && meseliq != 12 || datareg.year() == _year+1 && meseliq == 12
|
||
// Attenzione: nel caso si tratti di ricalcolo chiamato dalla stampa registri bollati, il cursore
|
||
// sara' leggermente diverso: i movimenti sono solo quelli del mese, tutto l'anno se annuale (month == 13).
|
||
// I movimenti del periodo selezionato dovranno essere tutti inclusi; in particolare quelli che
|
||
// avranno il mese liquidazione != 0 dovranno essere messi nella tabella PRP, come riferimento
|
||
// a Progressivi Registri periodo Precedente.
|
||
|
||
TRectype from(_cur->curr()); from.zero();
|
||
TRectype to(from);
|
||
TString8 fromreg("~"), toreg("0");
|
||
|
||
{
|
||
TRelation regrel("REG");
|
||
TCursor reg(®rel);
|
||
TString4 codreg;
|
||
const int items = reg.items();
|
||
|
||
for (reg = 0L; reg.pos() < items; ++reg)
|
||
{
|
||
codreg = reg.curr().get("CODTAB").mid(4);
|
||
|
||
if (codreg < fromreg)
|
||
fromreg = codreg;
|
||
if (codreg > toreg)
|
||
toreg = codreg;
|
||
}
|
||
}
|
||
|
||
const TDate fromdate(1, month == 13 ? 1 : month, year_int);
|
||
TDate t;
|
||
|
||
if (_recalc_regis) // Vecchia selezione prima del 1998 o calcolo progressivi per stampa registri bollati
|
||
{
|
||
t.set_month(month == 13 ? 12 : month);
|
||
t.set_year(year_int);
|
||
}
|
||
else //Nuova selezione dal 1998 in poi
|
||
{
|
||
t.set_year(month < 12 ? year_int : year_int+1);
|
||
t.set_month(month < 12 ? 12 : _freqviva == "M" ? 1 : 3);
|
||
}
|
||
t.set_end_month();
|
||
|
||
const TDate inizio(fromdate - 1L);
|
||
|
||
TDate todate(1, month == 13 ? 12 : month, year_int);
|
||
todate.set_end_month();
|
||
const TDate fine(todate);
|
||
|
||
from.put(MOV_REG, fromreg);
|
||
to.put(MOV_REG, toreg);
|
||
|
||
_cur->freeze(false);
|
||
_cur->setregion(from, to);
|
||
|
||
TString filter;
|
||
filter.format("(BETWEEN(DATAREG,%ld,%ld))", fromdate.date2ansi(), t.date2ansi());
|
||
if (_isviaggio)
|
||
{
|
||
// Spiegazione dell'arcano segreto sulle agenzie viaggio:
|
||
// non viene applicato lo stesso metodo delle ditte normali perche' si deve
|
||
// tenere conto della DATA74TER se presente.
|
||
// Per le agenzie di viaggio si parte da inizio anno precedente
|
||
const TDate f74(1, 1, year_int-1);
|
||
filter << format("||(BETWEEN(DATA74TER,%ld,%ld))", f74.date2ansi(), t.date2ansi());
|
||
}
|
||
if (_isdiff)
|
||
filter << "||(NUM(LIQDIFF==\"X\"))";
|
||
if (has_sc && gestione_IVAxCassa(fromdate))
|
||
filter << "||(NUM(IVAXCASSA==\"X\"))";
|
||
|
||
_cur->setfilter(filter);
|
||
const long items = _cur->items();
|
||
_cur->freeze();
|
||
|
||
*_cur = 0;
|
||
|
||
TString8 trueatt(codatt);
|
||
const int tipatt = trueatt[5] - '0';
|
||
trueatt.cut(5);
|
||
|
||
TString pimsg;
|
||
pimsg << TR("Ricalcolo attivit<69> ") << trueatt << " (";
|
||
if (month > 12)
|
||
pimsg << "13ma ";
|
||
else
|
||
pimsg << TR("mese ") << itom(month);
|
||
pimsg << ' ' << year_int << ')';
|
||
|
||
TProgress_monitor pi(items, pimsg, false);
|
||
for (; _cur->pos() < items; ++(*_cur))
|
||
{
|
||
if (!pi.set_status(_cur->pos()))
|
||
break;
|
||
|
||
TDate date = _mov->get(MOV_DATAREG);
|
||
const int liqmonth = _mov->get_int(MOV_MESELIQ);
|
||
const TString4 reg = _mov->get("REG");
|
||
const bool isreg = look_reg(reg);
|
||
const TString4 tipodoc = _mov->get(MOV_TIPODOC);
|
||
const bool corrisp = _reg->get_bool("B0");
|
||
const tiporeg tipomov = (tiporeg)_reg->get_int("I0"); // 1=Vendite; 2=Acquisti
|
||
|
||
tipo_movimento tm = (tipo_movimento)_mov->get_int(MOV_TIPOMOV);
|
||
if (tm == tm_nessuno)
|
||
{
|
||
if (tipodoc == "FV" || tipodoc == "FA")
|
||
tm = tm_fattura; else
|
||
if (tipodoc == "NC")
|
||
tm = tm_nota_credito;
|
||
}
|
||
|
||
#ifndef NDEBUG
|
||
if (_mov->get_long(MOV_NUMREG) == 23353)
|
||
int cazzone = 1;
|
||
#endif
|
||
|
||
if (_isviaggio)
|
||
{
|
||
if (tipomov == vendita && _mov->get_date(MOV_DATA74TER).ok())
|
||
date = _mov->get_date(MOV_DATA74TER);
|
||
if (date.year() != year_int) // Controlla anno di appartenenza, altrimenti is_date_ok potrebbe non funzionare
|
||
continue;
|
||
}
|
||
const TRectype& rcs = _cur->curr(LF_CAUSALI);
|
||
const bool fattrit = rcs.get_bool(CAU_RITFATT);
|
||
const bool cau_intra = rcs.get_bool(CAU_INTRACOM);
|
||
const bool cau_valintra = rcs.get_bool(CAU_VALINTRA);
|
||
|
||
// Gestione SPLIT PAYMENT dal 01-01-2015: movimenti a enti pubblici senza ritenuta e senza reverse charge
|
||
if (tipomov == vendita && (tm == tm_fattura || tm == tm_nota_credito) &&
|
||
!cau_intra && date.year() >= 2015 && is_split_payment(_mov->curr()))
|
||
{
|
||
/* Dal 2016 calcoliamo comunicazione annuale in cg5
|
||
// aggiunto il 27-01-2016: in tredicesima devo compilare anche CD1_1
|
||
if (month == 13 && date.year() == year_int)
|
||
{
|
||
do // scansione semplificata delle righe IVA
|
||
{
|
||
const int rmi_tipoatt = max(_rmoviva->get_int(RMI_TIPOATT), 1); // Poteva capitare tipoatt == 0
|
||
if (rmi_tipoatt != tipatt)
|
||
continue;
|
||
const TString& codiva = _rmoviva->get(RMI_CODIVA);
|
||
if (!look_iva(codiva))
|
||
continue;
|
||
const TString& iva_vpn = _iva->get("S10");
|
||
if (iva_vpn.full())
|
||
{
|
||
const real imponibile_orig = _rmoviva->get(RMI_IMPONIBILE);
|
||
cessioni_cd1_1s += imponibile_orig;
|
||
cessioni_cd1_1 += imponibile_orig;
|
||
}
|
||
} while (_cur->next_match(LF_RMOVIVA));
|
||
}
|
||
*/
|
||
continue; // Ignora movimento di split payment
|
||
}
|
||
|
||
// Inizio gestione IVA differita
|
||
const bool iva_diff = _mov->get_bool(MOV_LIQDIFF) && is_IVA_diff(_mov->curr());
|
||
const bool iva_cass = !iva_diff && !_isviaggio && tm > tm_nessuno && is_IVAxCassa(_mov->curr());
|
||
const bool bIsMovDiff = (iva_diff || iva_cass) && !_recalc_regis; // Aggiunto test su ricalcolo da registri 13-12-2012
|
||
bool dok = is_date_ok(date, month, liqmonth, year_int);
|
||
|
||
TPartite_array arrpart; // Partite interessate
|
||
TPointer_array pagscatt; // Righe di pagsca interessate
|
||
|
||
if (bIsMovDiff && tm == tm_fattura)
|
||
{
|
||
// const bool id_chiusa = ivadiff_chiusa(_mov->curr(), inizio);
|
||
const bool id_chiusa = ivadiff_chiusa(_mov->curr(), TDate(31,12,inizio.year()-1));
|
||
if (!dok && id_chiusa)
|
||
continue; // Salta vecchi movimenti differiti gi<67> chiusi
|
||
|
||
// Sezione preferita per fatture decisa in base a vendita->'A' o acquisto->'D'
|
||
const char sezfat = tipomov == vendita ? 'D' : 'A';
|
||
const char sezpag = (sezfat=='D') ? 'A' : 'D';
|
||
const long numreg = _mov->get_long(MOV_NUMREG);
|
||
TDate datainc;
|
||
real tot_incassato, tot_da_incassare;
|
||
int flag_pg_nc = 0; // Ci sono pagamenti (0x1) e/o note di credito(0x2) ?
|
||
bool game_found = false;
|
||
if (has_sc)
|
||
{
|
||
arrpart.add_numreg(numreg);
|
||
const TPartita* p = arrpart.first();
|
||
const int row = p ? p->mov2rig(numreg, 0) : 0;
|
||
game_found = row > 0;
|
||
if (game_found && !id_chiusa)
|
||
{
|
||
const TRiga_partite& rp = p->riga(row);
|
||
|
||
TDate orizzonte = fine; // caso tradizionale
|
||
|
||
// esperimento del 15-02-2016
|
||
if (1)
|
||
{
|
||
TDate data_rif = data_maturazione_IVA_diff(_mov->curr());
|
||
if (data_rif < fine)
|
||
orizzonte = data_rif;
|
||
}
|
||
|
||
TImporto pg_per, nc_per;
|
||
flag_pg_nc = rp.calcola_pagato_periodo(inizio+1L, orizzonte, pg_per, nc_per, &pagscatt);
|
||
if (pagscatt.items() >= 2)
|
||
{
|
||
// Fondo tra loro le righe generate dallo stesso pagamento
|
||
for (int p = pagscatt.last(); p > 0; p--)
|
||
{
|
||
const TRectype& p0 = (const TRectype&)pagscatt[p];
|
||
const TRectype& p1 = (const TRectype&)pagscatt[p-1];
|
||
if (p0.get_int(PAGSCA_NRIGP) == p1.get_int(PAGSCA_NRIGP))
|
||
{
|
||
const real imp = p0.get_real(PAGSCA_IMPORTO);
|
||
((TRectype&)p1).add(PAGSCA_IMPORTO, imp);
|
||
pagscatt.destroy(p, true);
|
||
}
|
||
}
|
||
}
|
||
if (sarebbe_maturata(_mov->curr(), inizio+1L, fine))
|
||
{
|
||
TPointer_array pagscaold;
|
||
TImporto pg_tot, nc_tot;
|
||
rp.calcola_pagato_periodo(TDate(0L), orizzonte, pg_tot, nc_tot, &pagscaold);
|
||
|
||
// Controllo se ci siam persi delle note di credito negli anni scorsi
|
||
if (!nc_tot.is_zero() && pagscaold.items() > pagscatt.items())
|
||
{
|
||
FOR_EACH_ARRAY_ITEM(pagscaold, i, obj)
|
||
{
|
||
const TRectype& pagsca = *(const TRectype*)obj;
|
||
const int anno = pagsca.get_int(PAGSCA_ANNO);
|
||
const int nrigp = pagsca.get_int(PAGSCA_NRIGP);
|
||
// Appartiene all'anno scorso?
|
||
if (anno < year_int && nrigp < 999) // 9999 on pagsca -> 999 on ivadiff
|
||
{
|
||
const TPartita& p = arrpart.partita(pagsca);
|
||
const TRiga_partite& rp = p.riga(nrigp);
|
||
// E' veramente una nota di credito?
|
||
if (rp.tipo() == tm_nota_credito)
|
||
{
|
||
bool found = false;
|
||
FOR_EACH_ARRAY_ITEM(pagscatt, j, ps)
|
||
{
|
||
if (ps == obj)
|
||
{
|
||
found = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!found)
|
||
{
|
||
TLocalisamfile id(LF_IVADIFF);
|
||
id.put(RMI_NUMREG, _rmoviva->get(RMI_NUMREG));
|
||
id.put(RMI_NUMRIG, _rmoviva->get(RMI_NUMRIG));
|
||
id.put("NUMPRO", nrigp);
|
||
if (id.read(_isequal) != NOERR || id.get_int("ANNOLIQ") == 0)
|
||
pagscatt.add(obj);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
TImporto saldo = rp.importo(false);
|
||
saldo += pg_tot; saldo += nc_tot;
|
||
saldo.normalize(sezfat);
|
||
if (saldo.valore() > ZERO)
|
||
tot_da_incassare = saldo.valore();
|
||
}
|
||
}
|
||
}
|
||
if (!game_found) // No saldaconto o partita assente
|
||
{
|
||
datainc = iva_diff ? _mov->get_date(MOV_DATAINC) : TDate();
|
||
if (datainc.ok() && datainc <= fine)
|
||
tot_incassato = _mov->get_real(MOV_TOTDOC);
|
||
else
|
||
{
|
||
// Fattura pi<70> vecchia di un anno a ente NON pubblico
|
||
if (sarebbe_maturata(_mov->curr(), inizio+1L, fine))
|
||
tot_da_incassare = _mov->get_real(MOV_TOTDOC);
|
||
}
|
||
}
|
||
// Simulo incasso se necessario
|
||
if (!tot_da_incassare.is_zero()) // gi<67> controllato se sarebbe_maturata(_mov->curr(), fine)
|
||
{
|
||
tot_incassato = tot_da_incassare;
|
||
|
||
datainc = data_maturazione_IVA_diff(_mov->curr());
|
||
_mov->put(MOV_DATAINC, datainc);
|
||
}
|
||
if (tot_incassato > ZERO && is_date_ok(datainc, month, liqmonth, year_int))
|
||
{
|
||
flag_pg_nc = 0x1;
|
||
TRectype* pagsca = new TRectype(LF_PAGSCA);
|
||
pagsca->put(PAGSCA_TIPOC, _mov->get(MOV_TIPO));
|
||
pagsca->put(PAGSCA_SOTTOCONTO, _mov->get(MOV_CODCF));
|
||
pagsca->put(PAGSCA_ANNO, year_int);
|
||
pagsca->put(PAGSCA_NRIGA, 1);
|
||
pagsca->put(PAGSCA_NRATA, 1);
|
||
pagsca->put(PAGSCA_NRIGP, 9999);
|
||
pagsca->put(PAGSCA_IMPORTO, tot_incassato);
|
||
pagscatt.add(pagsca);
|
||
}
|
||
if (flag_pg_nc)
|
||
dok = true;
|
||
}
|
||
/*
|
||
* check register present, rmoviva present and date OK
|
||
*
|
||
* In un futuro prossimo, molto remoto, quando implementeremo il Client/Server, questo
|
||
* filtro sulla data registrazione/mese liq. andra' nel cursore stesso.
|
||
* Ora viene implementato qui [is_date_ok()] per non appesantire ulteriormente
|
||
* la lettura dei movimenti.
|
||
*/
|
||
|
||
const bool sreg = !isreg;
|
||
const bool rs8 = _reg->get("S8") != trueatt;
|
||
const bool cmt = !_cur->is_first_match(LF_RMOVIVA);
|
||
|
||
if (!dok || sreg || rs8 || cmt)
|
||
continue;
|
||
|
||
const tipo_sospensione sosp_imp = _reg->get_bool("B1") ? (tipo_sospensione) _reg->get_int("I9") : nessuna;
|
||
|
||
/*
|
||
* Tipo documento da eliminare (Scudler 1994)
|
||
* Trattasi per lo piu' di non incassati
|
||
* Da oggi vengono sommati nei real di S2 in pim
|
||
* assieme alle FS per stampa registri
|
||
*/
|
||
const bool noninc = (tipodoc == "SN" || tipodoc == "CN" || tipodoc == "RN" || tipodoc == "IN" || tipodoc == "PG");
|
||
|
||
/*
|
||
* check date: se si calcola l'acconto, solo da 1/12 a 20/12
|
||
*/
|
||
const int accmonth = _isdifferita ? 11 : 12;
|
||
|
||
/*
|
||
* Patrizia: se <20> differita i mov. vanno da 1/11 a 30/11
|
||
* potrei allora andarmi a leggere i risultati della liq di 11
|
||
* ma il cliente potrebbe voler calcolare l'acconto prima
|
||
* di aver calcolato la liquidazione (perche' cosi' complicato?)
|
||
*/
|
||
if (_comp_acconto && !_isdifferita && date.month() == accmonth && date.day() > 20)
|
||
continue;
|
||
|
||
// Ciclo sulle righe IVA del movimento
|
||
do
|
||
{
|
||
const int rmi_tipoatt = max(_rmoviva->get_int(RMI_TIPOATT), 1); // Poteva capitare tipoatt == 0
|
||
if (rmi_tipoatt != tipatt)
|
||
continue;
|
||
|
||
// totali parziali registrati nei pim per motivi ignoti
|
||
real bolld_imp = ZERO; // imponibile bolle doganali
|
||
real bolld_iva = ZERO; // imposta bolle doganali
|
||
real asimp_imp = ZERO; // imponibile acquisti sosp. imposta
|
||
real asimp_iva = ZERO; // imposta acquisti sosp. imposta
|
||
real vsimp_imp = ZERO; // imponibile vendite sosp. imposta
|
||
real vsimp_iva = ZERO; // imposta vendite sosp. imposta
|
||
real rit_imp = ZERO; // imponibile fatture in ritardo
|
||
real rit_iva = ZERO; // imposta fatture in ritardo
|
||
real nin_imp = ZERO; // imponibile non incassati
|
||
real nin_iva = ZERO; // imposta non incassati
|
||
|
||
const TString4 codiva = _rmoviva->get(RMI_CODIVA);
|
||
if (!look_iva(codiva))
|
||
{
|
||
error_box(FR("Codice IVA \"%s\" non riconosciuto alla riga %d del movimento %ld."),
|
||
(const char*)codiva, _rmoviva->get_int(RMI_NUMRIG), _rmoviva->get_long(RMI_NUMREG));
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
CHECKS(codiva == _iva->get("CODTAB"), "Codice IVA simile ", (const char*)codiva);
|
||
}
|
||
|
||
const TString4 tipoiva = _iva->get("S1");
|
||
const TString4 tipoes_v = _iva->get("S2");
|
||
const TString4 tipoes_a = _iva->get("S9");
|
||
const int tipoagr = _iva->get_int("I4"); // 2/9/2015 was S4
|
||
const int tipoag = _iva->get_int("S5");
|
||
const int tipopla = _iva->get_int("S3");
|
||
int isrimbinfr = _iva->get_bool("B3"); // vale per calcolo rimborso se ES o NI
|
||
const real perciva = _iva->get_real("R0") / CENTO;
|
||
int ivarimb = !_iva->get_bool("B4"); // non escluso calcolo rimb. per al. media
|
||
|
||
const TString4 tipocr_s = _rmoviva->get(RMI_TIPOCR);
|
||
const int tipocr = atoi(tipocr_s);
|
||
const bool intra = _rmoviva->get_bool(RMI_INTRA);
|
||
|
||
// autofatture art. 17 per non residenti, con trattamento speciale in liquidazione annuale
|
||
const bool autodafe = (tipodoc == "AF") && is_autofattura_articolo_17(_mov->curr());
|
||
// vendite art. 40 c. 5/6/8 acq.intra., con trattamento
|
||
// speciale in liquidazione annuale (VA7 in stampa)
|
||
const bool art40 = (tipodoc != "AF" && tipoiva != "NS" && !rcs.get_bool("AUTOFATT") && rcs.get_bool("VALINTRA") && !intra);
|
||
// indica acquisti per rivendita; viene messo in B4 di PIM per
|
||
// indicare che e' soggetto al ricalcolo IVA (se voluto) in modo
|
||
// da evitare di dover controllare mese e anno sul PIM
|
||
const bool was_riv = (tipoiva != "NS") && (tipocr == 1 || tipocr ==5);
|
||
real percind;
|
||
const int tipoind = get_tipodet_from_rmi(_rmoviva->curr(), _mov->curr(), percind, true);
|
||
const int decimals = TCurrency::get_firm_dec();
|
||
|
||
const real imponibile_orig = _rmoviva->get_real(RMI_IMPONIBILE);
|
||
const real imposta_orig = _rmoviva->get_real(RMI_IMPOSTA);
|
||
|
||
real diff_imp; // Liquidazione differita imponibile
|
||
real diff_iva; // Liquidazione differita imposta
|
||
real incdiff_imp; // Liquidazione differita incassate imponibile
|
||
real incdiff_iva; // Liquidazione differita incassate imposta
|
||
real impon_ind; // Imponibile indetraibile
|
||
real impos_ind; // Imposta indetraibile
|
||
real impon_det; // Imponibile detraibile
|
||
real impos_det; // Imposta detraibile
|
||
|
||
if (bIsMovDiff && tm == tm_fattura)
|
||
{
|
||
const char sezfat = tipomov == vendita ? 'D' : 'A';
|
||
const TDate datareg = _mov->get(MOV_DATAREG);
|
||
|
||
TLocalisamfile id(LF_IVADIFF);
|
||
id.put(RMI_NUMREG, _rmoviva->get(RMI_NUMREG));
|
||
id.put(RMI_NUMRIG, _rmoviva->get(RMI_NUMRIG));
|
||
id.put("NUMPRO", 0);
|
||
id.put(PART_TIPOMOV, tm);
|
||
CHECKD(rmi_tipoatt > 0, "Invalid tipo att ", rmi_tipoatt);
|
||
id.put("TIPOATT", rmi_tipoatt);
|
||
id.put("ANNOLIQ", datareg.year());
|
||
|
||
int mesereg = datareg.month();
|
||
if (_freqviva[0] == 'T')
|
||
{
|
||
const int resto = mesereg % 3;
|
||
if (resto > 0)
|
||
mesereg += 3-resto;
|
||
}
|
||
|
||
id.put("MESELIQ", mesereg);
|
||
id.put("TIPOIVA", tipomov == 2 ? 2 : 1);
|
||
id.put("TIPODIFF", iva_cass ? 2 : 1);
|
||
id.put(MOV_DATAREG, _mov->get(MOV_DATADOC));
|
||
id.put(RMI_CODIVA, codiva);
|
||
id.put("SEZIONE", sezfat);
|
||
|
||
id.put("IMPORTO", imponibile_orig+imposta_orig);
|
||
id.put(RMI_IMPONIBILE, imponibile_orig);
|
||
|
||
/* cazzata?
|
||
if (percind > ZERO) // Nel caso di IVA indetraibile memorizza solo la parte detraibile!
|
||
{
|
||
real imp_det, iva_det, imp_ind, iva_ind;
|
||
analizza_IVA(imponibile_orig, imposta_orig, percind, corrisp, false, codiva,
|
||
imp_det, iva_det, imp_ind, iva_ind);
|
||
id.put(RMI_IMPOSTA, iva_det);
|
||
}
|
||
else
|
||
*/
|
||
id.put(RMI_IMPOSTA, imposta_orig);
|
||
|
||
const int ew = id.write_rewrite();
|
||
if (ew != NOERR)
|
||
cantwrite_box(id.description());
|
||
}
|
||
|
||
if (!pagscatt.empty())
|
||
{
|
||
const char sezpag = tipomov == vendita ? 'A' : 'D';
|
||
const real totfat = _mov->get(MOV_TOTDOC);
|
||
|
||
#ifndef NDEBUG
|
||
if (_mov->get_long(MOV_NUMREG) == 23353)
|
||
int cazzone = 1;
|
||
#endif
|
||
|
||
TLocalisamfile id(LF_IVADIFF);
|
||
TRectype& idcurr = id.curr();
|
||
FOR_EACH_ARRAY_ITEM(pagscatt, r, obj)
|
||
{
|
||
const TRectype& pagsca = *(TRectype*)obj;
|
||
const int nrigp = pagsca.get_int(PAGSCA_NRIGP);
|
||
|
||
id.zero();
|
||
idcurr.put(RMI_NUMREG, _rmoviva->get(RMI_NUMREG));
|
||
idcurr.put(RMI_NUMRIG, _rmoviva->get(RMI_NUMRIG));
|
||
CHECKD(nrigp > 0, "Invalid NRIGP ", nrigp);
|
||
idcurr.put("NUMPRO", min(nrigp, 999));
|
||
if (id.read(_isequal, _lock) != NOERR)
|
||
{
|
||
id.zero();
|
||
idcurr.put(RMI_NUMREG, _rmoviva->get(RMI_NUMREG));
|
||
idcurr.put(RMI_NUMRIG, _rmoviva->get(RMI_NUMRIG));
|
||
idcurr.put("NUMPRO", min(nrigp, 999));
|
||
if (id.write() != NOERR)
|
||
error_box("Errore %d in creazione record IVADIFF", id.status());
|
||
}
|
||
|
||
idcurr.put(MOV_DATAREG, _mov->get(MOV_DATADOC));
|
||
CHECKD(rmi_tipoatt > 0, "Invalid tipo att ", rmi_tipoatt);
|
||
idcurr.put("TIPOATT", rmi_tipoatt);
|
||
idcurr.put("TIPOIVA", tipomov == 2 ? 2 : 1);
|
||
idcurr.put("TIPODIFF", iva_cass ? 2 : 1);
|
||
idcurr.put(RMI_CODIVA, codiva);
|
||
|
||
TImporto pagtmp;
|
||
bool ultimo = false;
|
||
tipo_movimento tipomov_pag = tm_pagamento;
|
||
if (nrigp > 0 && nrigp < 9999)
|
||
{
|
||
const TPartita& p = arrpart.partita(pagsca);
|
||
const TRiga_partite& rp = p.riga(nrigp);
|
||
tipomov_pag = rp.tipo();
|
||
idcurr.put(PART_TIPOMOV, tipomov_pag);
|
||
idcurr.put("NUMREGP", rp.get(PART_NREG));
|
||
idcurr.put("NUMRIGP", rp.get(PART_NUMRIG));
|
||
TDate d = rp.get(PART_DATAPAG);
|
||
if (!d.ok())
|
||
d = rp.get(PART_DATADOC);
|
||
if (!d.ok())
|
||
d = rp.get(PART_DATAREG);
|
||
idcurr.put("DATAREGP", d);
|
||
idcurr.put("ANNOLIQ", d.year());
|
||
pagtmp = p.importo_pagsca(pagsca);
|
||
pagtmp.normalize(sezpag);
|
||
ultimo = (r == pagscatt.last()) && partita_chiusa_al(p, fine);
|
||
}
|
||
else
|
||
{
|
||
// Falso record generato da datainc
|
||
idcurr.put(PART_TIPOMOV, tipomov_pag);
|
||
idcurr.put("NUMREGP", _mov->get(MOV_NUMREG));
|
||
idcurr.put("NUMRIGP", nrigp);
|
||
idcurr.put("DATAREGP", _mov->get(MOV_DATAINC));
|
||
idcurr.put("ANNOLIQ", year_int);
|
||
pagtmp.set(sezpag, pagsca.get_real(PAGSCA_IMPORTO));
|
||
ultimo = true;
|
||
}
|
||
|
||
int meseliq = id.get_date("DATAREGP").month();
|
||
if (_freqviva[0] == 'T')
|
||
{
|
||
const int resto = meseliq % 3;
|
||
if (resto > 0)
|
||
meseliq += 3-resto;
|
||
}
|
||
idcurr.put("MESELIQ", meseliq);
|
||
idcurr.put("SEZIONE", pagtmp.sezione());
|
||
if (ultimo)
|
||
{
|
||
real importo, imponibile, imposta;
|
||
residuo_da_liquidare(idcurr, importo, imponibile, imposta);
|
||
idcurr.put("IMPORTO", importo);
|
||
idcurr.put(RMI_IMPONIBILE, imponibile);
|
||
idcurr.put(RMI_IMPOSTA, imposta);
|
||
if (tipomov_pag >= tm_pagamento) // 5-3-2014 incremento incdiff_imp solo coi pagamenti! Coerentemente con !ultimo
|
||
{
|
||
incdiff_imp += imponibile;
|
||
incdiff_iva += imposta;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
const real perc = pagtmp.valore() / totfat;
|
||
|
||
real val_imp = imponibile_orig * perc;
|
||
round_al_centesimo(val_imp);
|
||
|
||
real val_iva = imposta_orig * perc;
|
||
round_al_centesimo(val_iva);
|
||
|
||
idcurr.put("IMPORTO", val_imp + val_iva);
|
||
idcurr.put(RMI_IMPONIBILE, val_imp);
|
||
idcurr.put(RMI_IMPOSTA, val_iva);
|
||
|
||
if (tipomov_pag >= tm_pagamento)
|
||
{
|
||
incdiff_imp += val_imp;
|
||
incdiff_iva += val_iva;
|
||
}
|
||
}
|
||
|
||
int err = id.rewrite();
|
||
if (err != NOERR)
|
||
error_box("Errore %d in aggiornamento file IVADIFF", err);
|
||
LOG_IVA_DIFF(id.curr());
|
||
|
||
// 18-06-2014 Aggiorna flag di chiusura IVADIFF solo nei mesi normali, ma lascialo stare se _isannual
|
||
const long numreg = _rmoviva->get_long(RMI_NUMREG);
|
||
if (numreg > 0 && !_isannual) // Chiude o riapre la partita
|
||
{
|
||
TISAM_recordset recset("USE IVADIFF\nFROM NUMREG=#NR\nTO NUMREG=#NR");
|
||
recset.set_var("#NR", numreg);
|
||
TLocalisamfile& id = recset.cursor()->file();
|
||
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
|
||
{
|
||
const bool chiusa = id.get_bool("CHIUSA");
|
||
if (chiusa != ultimo)
|
||
{
|
||
id.put("CHIUSA", ultimo);
|
||
id.rewrite();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (is_date_ok(date, month, liqmonth, year_int)) // 5-3-2014
|
||
{
|
||
diff_imp = imponibile_orig;
|
||
diff_iva = imposta_orig;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (bIsMovDiff)
|
||
{
|
||
if (is_date_ok(date, month, liqmonth, year_int)) // 5-3-2014
|
||
{
|
||
diff_imp = imponibile_orig;
|
||
diff_iva = imposta_orig;
|
||
}
|
||
}
|
||
else
|
||
analizza_IVA(imponibile_orig, imposta_orig, percind, corrisp, false, codiva,
|
||
impon_det, impos_det, impon_ind, impos_ind);
|
||
}
|
||
|
||
|
||
// Filling dell'array per IVA11
|
||
if (_is_interactive && month == 13)
|
||
iva11_set_arr_phase_1(trueatt);
|
||
|
||
|
||
// Cumula l'ammontare delle operazioni attive/passive
|
||
// per la dichiarazione annuale dati iva e quadro VT
|
||
if (month == 13 && !fattrit)
|
||
{
|
||
|
||
if (tipomov == vendita)
|
||
{
|
||
const long codcf = _mov->get_long(MOV_CODCF);
|
||
|
||
if (tipoiva.empty() && codcf != 0)
|
||
{
|
||
TString8 key; key.format("%c|%ld", _mov->get_char(MOV_TIPO), codcf);
|
||
const TRectype& clifo = cache().get(LF_CLIFO, key);
|
||
int codreg = 0; // codice regione x privati 22 == partite iva 0 == senza codice
|
||
const int tipoalleg = clifo.get_int(CLI_ALLEG);
|
||
|
||
if (tipoalleg == 6) // privato
|
||
{
|
||
if (clifo.get_bool(CLI_OCCAS))
|
||
{
|
||
const TString& key_occ = _mov->get(MOV_OCFPI);
|
||
const TRectype& occas = cache().get(LF_OCCAS, key_occ);
|
||
|
||
key = occas.get(OCC_STATO);
|
||
key << "|" << occas.get(OCC_COM);
|
||
}
|
||
else
|
||
{
|
||
key = clifo.get(CLI_STATOCF);
|
||
key << "|" << clifo.get(CLI_COMCF);
|
||
}
|
||
|
||
const TRectype& comune = cache().get(LF_COMUNI, key);
|
||
codreg = comune.get_int(COM_CODREG) + 1;
|
||
}
|
||
|
||
if (bIsMovDiff)
|
||
{
|
||
vt_imponibile[codreg] += incdiff_imp;
|
||
vt_imposta[codreg] += incdiff_iva;
|
||
}
|
||
else
|
||
{
|
||
vt_imponibile[codreg] += imponibile_orig;
|
||
vt_imposta[codreg] += imposta_orig;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* Calcoli sprecati: dal 2016 calcolimao la comuncazione annuale direttamente in cg5
|
||
const TString& iva_vpn = _iva->get(tipomov == vendita ? "S10" : "S11");
|
||
|
||
// Aggiunto "&& is_detraibile==0" al test altrimenti somma due volte imponibile_orig (22/01/2015)
|
||
if (!bIsMovDiff && iva_vpn.full() && _mov->get_int(MOV_ANNOIVA) == year_int && is_detraibile == 0)
|
||
{
|
||
switch (tipomov)
|
||
{
|
||
case vendita: // CD1 - 1 2 3 4
|
||
{
|
||
// bool is_valid = !corrisp && tipodoc != "AF" && (cau_intra || !cau_valintra) &&
|
||
// sosp_imp != normale && sosp_imp != liquidazione;
|
||
bool is_valid = tipodoc != "AF" && sosp_imp != normale && sosp_imp != liquidazione;
|
||
if (is_valid)
|
||
{
|
||
cessioni_cd1_1 += imponibile_orig;
|
||
if (iva_vpn.starts_with("CD1"))
|
||
{
|
||
if (tipocr == 4)
|
||
cessioni_cd1_5 += imponibile_orig;
|
||
}
|
||
if (!cau_intra)
|
||
{
|
||
if (iva_vpn == "CD12")
|
||
cessioni_cd1_2 += imponibile_orig; else
|
||
if (iva_vpn == "CD13")
|
||
cessioni_cd1_3 += imponibile_orig;
|
||
}
|
||
else
|
||
{
|
||
if (iva_vpn == "CD14")
|
||
cessioni_cd1_4 += imponibile_orig;
|
||
}
|
||
}
|
||
|
||
}
|
||
break;
|
||
case acquisto: // CD2 - 1 2 3 4
|
||
{
|
||
acquisti_cd2_1 += imponibile_orig;
|
||
if (iva_vpn.starts_with("CD2"))
|
||
{
|
||
if (tipocr == 2 || tipocr == 3 || tipocr == 8)
|
||
acquisti_cd2_5 += imponibile_orig;
|
||
}
|
||
if (!cau_intra)
|
||
{
|
||
if (iva_vpn == "CD22")
|
||
acquisti_cd2_2 += imponibile_orig;
|
||
else
|
||
if (iva_vpn == "CD23")
|
||
acquisti_cd2_3 += imponibile_orig;
|
||
}
|
||
else
|
||
{
|
||
if (iva_vpn == "CD24")
|
||
acquisti_cd2_4 += imponibile_orig;
|
||
}
|
||
if (iva_vpn == "CD31")
|
||
{
|
||
oroargento_cd3_1 += imponibile_orig;
|
||
oroargento_cd3_2 += imposta_orig;
|
||
}
|
||
if (iva_vpn == "CD33")
|
||
{
|
||
rottami_cd3_3 += imponibile_orig;
|
||
rottami_cd3_4 += imposta_orig;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
*/
|
||
}
|
||
|
||
for (int is_detraibile = 0; is_detraibile < 2; is_detraibile++)
|
||
{
|
||
const int tipodet = is_detraibile ? 0 : tipoind;
|
||
const real imponibile = is_detraibile ? impon_det : impon_ind;
|
||
const real imposta = is_detraibile ? impos_det : impos_ind;
|
||
|
||
//qui da verificare
|
||
|
||
if ((imponibile.is_zero() && imposta.is_zero()) &&
|
||
(bIsMovDiff &&
|
||
(is_detraibile > 0 ||
|
||
(diff_imp.is_zero() && diff_iva.is_zero() &&
|
||
incdiff_imp.is_zero() && incdiff_iva.is_zero())
|
||
)
|
||
)
|
||
)
|
||
continue;
|
||
|
||
/* Riga imponibile > 9 = ritenute; non si considerano (Scudler 1994) */
|
||
|
||
|
||
if (noninc) // non incassati: non devono entrare in nessun altro calcolo
|
||
{
|
||
nin_imp = imponibile;
|
||
nin_iva = imposta;
|
||
}
|
||
else if (sosp_imp != nessuna) // sospensione di imposta
|
||
{
|
||
if (tipomov == vendita)
|
||
{
|
||
vsimp_imp = imponibile;
|
||
vsimp_iva = imposta;
|
||
}
|
||
else
|
||
{
|
||
asimp_imp = imponibile;
|
||
asimp_iva = imposta;
|
||
}
|
||
|
||
switch (sosp_imp)
|
||
{
|
||
case normale:
|
||
assp_imp += asimp_imp;
|
||
assp_iva += asimp_iva;
|
||
vssp_imp += vsimp_imp;
|
||
vssp_iva += vsimp_iva;
|
||
break;
|
||
case liquidazione:
|
||
assl_imp += asimp_imp;
|
||
assl_iva += asimp_iva;
|
||
vssl_imp += vsimp_imp;
|
||
vssl_iva += vsimp_iva;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
else if (fattrit) // Possono essere solo acquisti
|
||
{
|
||
rit_imp = imponibile;
|
||
rit_iva = imposta;
|
||
}
|
||
|
||
// Le fatture in ritardo non vanno considerate nel periodo ma solo nell'annuale
|
||
if (!fattrit || (fattrit /*&& _isagricolo*/ && _month == 13)) // normale
|
||
{
|
||
|
||
// *****************************************
|
||
// casi particolari
|
||
// *****************************************
|
||
|
||
// imposta acquisti intracomunitari
|
||
if (tipomov == acquisto && intra)
|
||
totintra += imposta;
|
||
|
||
// Altre cose di cui tener conto
|
||
// Separo pazientemente per movimenti d'acquisto e movimenti di vendita
|
||
// onde evitare rompicapi, rompicazzi ecc...
|
||
|
||
switch (tipomov)
|
||
{
|
||
case acquisto: // ACQUISTO (per chi non l'avesse capito)
|
||
// Per le anguille delle Antille e le Saracche delle Molucche...
|
||
// Gli acquisti con tipocr 1,2,3,5,8 vanno totalizzati se e solo se
|
||
// il tipo iva e' diverso da NON SOGGETTO,
|
||
if (tipoiva != "NS")
|
||
{
|
||
if (tipocr == 1 || tipocr ==5)
|
||
// Acquisto beni per rivendita
|
||
{
|
||
acq_riv += imponibile;
|
||
acq_riv_iva += imposta;
|
||
}
|
||
else if (tipocr == 2 && tipodet == 0)
|
||
// Acquisto beni ammortizzabili detraibili
|
||
{
|
||
ammort_det += imponibile;
|
||
ammort_det_iva += imposta;
|
||
}
|
||
else if (tipocr == 2 && tipodet != 0)
|
||
// Acquisto beni ammortizzabili indetraibili
|
||
{
|
||
ammort_indet += imponibile;
|
||
ammort_indet_iva += imposta;
|
||
}
|
||
else if (tipocr == 3)
|
||
// Acquisto beni ammortizzabili detr. 6%
|
||
{
|
||
ammort_6 += imponibile;
|
||
ammort_6_iva += imposta;
|
||
// ult_detr += imponibile * real(DETRAZIONE_6PERCENTO); // CM500159
|
||
}
|
||
else if (tipocr == 8)
|
||
// Acquisto beni strum. acquisiti in leasing
|
||
{
|
||
leasing += imponibile;
|
||
leasing_iva += imposta;
|
||
}
|
||
} // fine if per tipo iva != da NON SOGGETTO
|
||
|
||
// Mi chiedo se effettivamente il tipo 9 sia esente da qualsiasi criterio...
|
||
if (tipocr == 9)
|
||
// Spese generali
|
||
{
|
||
spgen += imponibile;
|
||
spgen_iva += imposta;
|
||
}
|
||
// else fuck it up, dirty dick head.
|
||
break;
|
||
case vendita: // VENDITA
|
||
if (tipoiva != "NS") /* Segnalazione CM000219: I non soggetti non vanno considerati */
|
||
{
|
||
if (tipocr == 4)
|
||
/*
|
||
* Vendite strum. art 17 (cess. amm.)
|
||
* Comprende anche autofatture, anche nell'annuale
|
||
* (Sergio 1995)
|
||
*/
|
||
{
|
||
// Invece non le deve comprendere nell'annuale (Vladimiro 1995, piu' tardi)
|
||
if (!(_month == 13 && autodafe))
|
||
{
|
||
cess_amm += imponibile;
|
||
cess_amm_iva += imposta;
|
||
}
|
||
}
|
||
|
||
if (is_detraibile && !imponibile.is_zero() && is_reverse_charge(_mov->curr()))
|
||
vendite_rev += imponibile;
|
||
}
|
||
break;
|
||
default: // Chissa'... forse in futuro vi sara' un ulteriore tipo di movimento...
|
||
break;
|
||
} // Fine del malefico switch
|
||
|
||
|
||
// operazioni per calcolo rimborso infraanale
|
||
// Scudler 1995 e molti dopo di lei
|
||
// La breve estate vissuta dal metodo del 51% rende
|
||
// oramai superflua la tabella rimborsi, eliminata
|
||
// senza entusiasmo ed interrogandomi sul senso della vita
|
||
if (ivarimb)
|
||
{
|
||
bool ok = _isagricolo ? tipoagr == 2 : false;
|
||
|
||
if (tipomov == acquisto && !ok)
|
||
ok = (tipocr == 0 || tipocr == 1 || tipocr == 5 || tipocr == 9);
|
||
|
||
if (tipomov == vendita && !ok)
|
||
ok = tipoiva != "NS" && tipocr != 4;
|
||
|
||
ivarimb = ok;
|
||
}
|
||
|
||
// operazioni esenti
|
||
if (tipoiva == "ES" && !imponibile.is_zero())
|
||
{
|
||
if (tipomov == vendita)
|
||
{
|
||
if (sosp_imp != normale && sosp_imp != vol_affari) // CM500308
|
||
{
|
||
if (tipoes_v == "B1") // C1
|
||
esenti_c1 += imponibile;
|
||
else if (tipoes_v == "B2") // C2
|
||
esenti_c2 += imponibile;
|
||
else if (tipoes_v == "B3") // C3
|
||
{
|
||
esenti_c3 += imponibile;
|
||
if (tipocr == 4)
|
||
esenti_c3_bam += imponibile;
|
||
}
|
||
else if (tipoes_v == "B4") // C1A
|
||
{
|
||
esenti_c1a += imponibile;
|
||
if (tipocr == 4)
|
||
esenti_c1a_bam += imponibile;
|
||
}
|
||
// se e' il caso sommare esenti per rimborso
|
||
if (isrimbinfr)
|
||
esni_rimb += imponibile;
|
||
}
|
||
}
|
||
else if (tipoes_a == "14")
|
||
esenti_b14 += imponibile;
|
||
}
|
||
|
||
// non imponibili per rimborso
|
||
if (tipoiva == "NI" && tipomov == vendita && isrimbinfr)
|
||
esni_rimb += imponibile;
|
||
|
||
// bolle doganali
|
||
if (tipodoc == "BD")
|
||
{
|
||
bolld_imp = imponibile;
|
||
bolld_iva = imposta;
|
||
|
||
bdog_imp += bolld_imp;
|
||
bdog_iva += bolld_iva;
|
||
}
|
||
|
||
// plafond
|
||
if (_isplafond && tipomov == acquisto && month != 13 &&
|
||
tipoiva == "NI" && tipopla != 0)
|
||
{
|
||
add_plafond(month, codatt, tipopla, imponibile, tipodoc == "BD");
|
||
}
|
||
|
||
// agenzie viaggio (CHECK imponibili etc.)
|
||
if (_isviaggio)
|
||
switch (tipoag)
|
||
{
|
||
case 1:
|
||
if (tipomov == acquisto) acq_CEE += imponibile + imposta;
|
||
else corr_CEE += imponibile + imposta;
|
||
break;
|
||
case 2:
|
||
if (tipomov == acquisto) acq_noCEE += imponibile + imposta;
|
||
else corr_noCEE += imponibile + imposta;
|
||
break;
|
||
case 3: if (tipomov == vendita)
|
||
corr_misCEE += imponibile + imposta;
|
||
break;
|
||
case 4: if (tipomov == acquisto)
|
||
acq_misCEE += imponibile + imposta;
|
||
break;
|
||
case 5: if (tipomov == acquisto)
|
||
acq_misnoCEE += imponibile + imposta;
|
||
break;
|
||
}
|
||
|
||
|
||
if (_isagricolo)
|
||
{
|
||
/*
|
||
* rifatto sensu Scudler 1995 con invidiabile sicurezza
|
||
* senza porsi domande e mettendo NUMERI uguali
|
||
* al TIPO RECORD del frigorifero
|
||
*/
|
||
if (tipomov == vendita)
|
||
{
|
||
if (!noninc) // Salta i non incassati
|
||
{
|
||
agr_imp = imponibile;
|
||
agr_iva = imposta;
|
||
const real p = perciva;
|
||
const bool is_not_fs = tipodoc != "FS";
|
||
|
||
// Se si tratta di Fattura Fiscale o Fattura Scontrino, non scorpora
|
||
// In particolare le FS non vengono incluse ne' nello specchietto ne' nel totale
|
||
if (corrisp && tipodoc != "FF" && is_not_fs)
|
||
lordo2netto(agr_imp,agr_iva,p);
|
||
|
||
if (tipoagr == 1 && is_not_fs) // Ora si utilizza solo il segnalino 1
|
||
{
|
||
agr_1 += agr_iva;
|
||
agr_1i += agr_imp;
|
||
|
||
// Nuovo regime agricolo dal 1998: si sommino per codice iva di compensazione (da reperire su PCON)
|
||
TString ivacomp("00"); // Se non esiste o non si trova il conto questo e' il default (fa un poco schifo ma e' cosi')
|
||
|
||
if (_cur->is_first_match(-AGR_PCON1)) // Esiste il conto ?
|
||
// Bien, allora controlliamo se e' un ricavo...
|
||
if (_pcon_1_r->get_int(PCN_INDBIL) == 4)
|
||
if (_cur->is_first_match(-AGR_PCON2)) // Esiste il sottoconto ?
|
||
{
|
||
if (look_iva(_pcon_2_r->get(PCN_IVACOMP)))
|
||
ivacomp = _iva->get("CODTAB"); // Ecco il codice IVA di compensazione
|
||
}
|
||
look_pia(month, codatt, codiva, ivacomp, true); // Crea il record in tabella se non esiste
|
||
real pia_imp = _pia->get_real("R0") + agr_imp; // Aggiorna...
|
||
_pia->put("R0", pia_imp);
|
||
_pia->put("B0", true); // Seguo l'esempio dei PIM per il ricalcolo acquisti alla fine del ciclo
|
||
_pia->rewrite(); // infine scrive
|
||
}
|
||
else if (tipoagr == 2 && is_not_fs)
|
||
{
|
||
agr_2 += agr_iva;
|
||
agr_2i += agr_imp;
|
||
}
|
||
}
|
||
}
|
||
else if (tipodet == 0)
|
||
{
|
||
if (tipoagr == 2)
|
||
{
|
||
if (tipocr != 2 && tipocr != 3 && tipocr != 8)
|
||
agr_3 += imposta;
|
||
else
|
||
agr_4 += imposta;
|
||
}
|
||
else if (tipoagr == 3)
|
||
{
|
||
if (tipocr != 2 && tipocr != 3 && tipocr != 8)
|
||
agr_7 += imposta;
|
||
}
|
||
else // ne' 2 ne' 3
|
||
{
|
||
if (tipocr != 2 && tipocr != 3 && tipocr != 8)
|
||
agr_5 += imposta;
|
||
else
|
||
agr_6 += imposta;
|
||
}
|
||
}
|
||
} // __end of _agricolo
|
||
|
||
if (tipodet == 1) // acquisti indeducibili su ricavi esenti art. 10
|
||
{
|
||
acq_ies += imponibile;
|
||
acq_ies_iva += imposta;
|
||
}
|
||
|
||
if (tipodet == 3) // passaggi interni (solo per ventilaz)
|
||
{
|
||
acq_pint += imponibile;
|
||
acq_pint_iva += imposta;
|
||
}
|
||
|
||
// acquisti non detraibili art. 19
|
||
// possono valere per la ventilazione
|
||
if (tipodet == 9)
|
||
{
|
||
nond19_imp += imponibile;
|
||
nond19_iva += imposta;
|
||
}
|
||
|
||
// *****************************************
|
||
// Fine casi particolari
|
||
// Non che i casi normali siano tanto meglio
|
||
// *****************************************
|
||
} // non sosp_imp ne' altre casistiche che escludono la liq.
|
||
|
||
/*
|
||
* se ign == true non bisogna neppure PROGRESSIVARLI
|
||
*/
|
||
const bool sosp_vaf = sosp_imp == vol_affari;
|
||
const bool sosp_liq = sosp_imp == liquidazione;
|
||
bool ign = sosp_imp == normale || (fattrit && month != 13) || noninc;
|
||
|
||
/*
|
||
* se liq == false gli importi non contano ai fini
|
||
* del calcolo liquidazione
|
||
*/
|
||
bool liq = !(tipodet == 1 || tipodet == 3 || tipodet == 9 || ign || sosp_vaf);
|
||
|
||
real imp; // imponibile
|
||
real ivp; // IVA su imp.
|
||
real lor; // lordo
|
||
real lorcor; // lordo corrispettivi (da non ventilare)
|
||
|
||
/*
|
||
* le maledette fatture con scontrino sono sul registro dei
|
||
* corrispettivi, ma vanno riportate nelle vendite in stampa;
|
||
* dunque, le sommiamo in R5 e R6 di PIM anche se continuiamo
|
||
* a sommarle anche in R0 e R1. La stampa (describe_pim)
|
||
* dovra' scorporarle.
|
||
*
|
||
* 5.7.1996. Mi permetto di aggiungere una cosa: le bastardissime fatture con scontrino
|
||
* possono anche essere sul registro vendite. Indi le schiaffo dentro
|
||
* a R5 e R6 anche nel caso vi sia un documento FS registrato sul registro
|
||
* delle vendite. Nel caso in futuro si accorgessero finalmente della puttanata
|
||
* galattica che mi hanno fatto fare basta eliminare il controllo su FS
|
||
* nel caso si tratti di non corrispettivi (vedi sotto).
|
||
* Da togliere anche nella :describe_pim() in cg4304.cpp.
|
||
*
|
||
*/
|
||
real ifs; // imponibile fatture con scontrino
|
||
real vfs; // IVA fatt. con scontrino
|
||
|
||
/*
|
||
* le maledette autofatture non residenti art. 17
|
||
* vedi al calcolo if (autodafe) si tengono da parte
|
||
* La stampa le scorpora solo IN SEDE di dichiarazione annuale
|
||
*/
|
||
real adf;
|
||
real adi;
|
||
|
||
/* le fottute fatture in sospensione di imposta */
|
||
real fsi;
|
||
real fsv;
|
||
|
||
/* le putride bolle doganali */
|
||
real bdi;
|
||
real bdv;
|
||
|
||
/* i luridi falsi corrispettivi */
|
||
real fci;
|
||
real fcv;
|
||
|
||
/* i conturbanti art. 40 c. 5/6/8 a.i. */
|
||
real va7i;
|
||
real va7v;
|
||
|
||
/* le porche fatture in ritardo */
|
||
real rti;
|
||
real rtv;
|
||
|
||
/*
|
||
* la stramadonna dei corrispettivi gia' scorporati
|
||
* Gli si aggiungono i non incassati, sperando in bene
|
||
*/
|
||
real csi;
|
||
real csv;
|
||
/* incrociamm'e dituozz' */
|
||
csi += nin_imp;
|
||
csv += nin_iva;
|
||
|
||
rti += rit_imp;
|
||
rtv += rit_iva;
|
||
|
||
if (tipomov == vendita)
|
||
{
|
||
fsi += vsimp_imp;
|
||
fsv += vsimp_iva;
|
||
}
|
||
else
|
||
{
|
||
fsi += asimp_imp;
|
||
fsv += asimp_iva;
|
||
bdi += bolld_imp;
|
||
bdv += bolld_iva;
|
||
}
|
||
|
||
if (tipomov == vendita && liq && !corrisp)
|
||
// i corrispettivi sono gestiti a parte
|
||
{
|
||
// totale vendite
|
||
vendite += imponibile;
|
||
vendite_iva += imposta;
|
||
}
|
||
else if (tipomov == acquisto && (liq || fattrit && month == 13))
|
||
{
|
||
// totale acquisti
|
||
acquisti += imponibile;
|
||
acquisti_iva += imposta;
|
||
|
||
// Controlla se la data del documento si riferisce all'anno precedente (PRORATA 1998)
|
||
const TDate datedoc = _mov->get_date(MOV_DATADOC);
|
||
const int yr = datedoc.year();
|
||
if (!imposta.is_zero() && (yr < (year_int-1) && yr > (year_int-4))) // Prende un intervallo di 2 anni al massimo
|
||
{ // Quelli relativi all'anno in corso e precedente vanno assieme.
|
||
// Se abilitato, somma l'iva acquisti relativi ai documenti memorizzati con anni precedenti
|
||
TString4 yy; yy << yr;
|
||
const bool is_key = acq_iva_anni_prec.is_key(yy);
|
||
if (!is_key)
|
||
acq_iva_anni_prec.add(yy, new real, is_key);
|
||
real& aip = (real&) acq_iva_anni_prec[yy];
|
||
aip += imposta;
|
||
}
|
||
}
|
||
|
||
// corrispettivi
|
||
bool true_corrisp = false;
|
||
if (corrisp)
|
||
{
|
||
/*
|
||
* ennesimo casino: non tutti i corrispettivi sono
|
||
* corrispettivi; in effetti, alcuni corrispettivi
|
||
* non sono corrispettivi. Ci si potrebbe domandare
|
||
* se gli altri corrispettivi sono corrispettivi o
|
||
* no; ebbene, gli altri corrispettivi risultano
|
||
* fortunatamente essere corrispettivi, a meno di
|
||
* indicazioni contrarie.
|
||
*/
|
||
if (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC")
|
||
{
|
||
true_corrisp = true;
|
||
_pim->put("I0",LORDO);
|
||
// questi sono corrispettivi davvero; comportamento normale
|
||
if (tipoiva == "VE") // da ventilare
|
||
{
|
||
lor += imponibile;
|
||
add_vendite(month, reg, tipodet, imponibile);
|
||
}
|
||
else // non da ventilare, con imposta gia' conteggiata
|
||
{
|
||
lor += imponibile + imposta;
|
||
lorcor += imponibile+imposta;
|
||
real tot = imponibile+imposta;
|
||
if (liq)
|
||
add_corrisp(month, reg, tot, perciva, tipodet, codiva, codatt);
|
||
}
|
||
}
|
||
else if (tipodoc == "FF") // CM500415: prima non c'era questo if
|
||
{
|
||
// queste sono fatture fiscali
|
||
true_corrisp = true;
|
||
|
||
real tot = imponibile + imposta;
|
||
lor += tot;
|
||
lorcor += tot;
|
||
if (liq)
|
||
add_corrisp(month, reg, tot, perciva, tipodet, codiva, codatt);
|
||
}
|
||
else if (tipodoc == "FS")
|
||
{
|
||
// queste sono fatture che seguono scontrino, il lordo va detratto
|
||
// perche' si e' gia' registrato lo scontrino medesimo
|
||
true_corrisp = true; // non e' vero ma non devono essere sommate ai falsi
|
||
// corrispettivi
|
||
if (tipoiva == "VE")
|
||
{
|
||
const real rr = imponibile + imposta;
|
||
imp += rr;
|
||
if (liq)
|
||
vendite += rr;
|
||
add_vendite(month, reg, tipodet, rr);
|
||
}
|
||
if (liq)
|
||
{
|
||
csi += imponibile;
|
||
csv += imposta;
|
||
}
|
||
imp -= imponibile;
|
||
ivp -= imposta;
|
||
lor -= imponibile + imposta;
|
||
ifs += imponibile;
|
||
vfs += imposta;
|
||
}
|
||
else // vendite normali a tutti gli effetti
|
||
{
|
||
if (liq)
|
||
{
|
||
vendite += imponibile;
|
||
vendite_iva += imposta;
|
||
csi += imponibile;
|
||
csv += imposta;
|
||
}
|
||
imp += imponibile;
|
||
ivp += imposta;
|
||
_pim->put("I0",NETTO);
|
||
}
|
||
} // if corrisp
|
||
else // non corrisp
|
||
{ // imponibile e imposta separata
|
||
imp += imponibile;
|
||
ivp += imposta;
|
||
if (tipodoc == "FS") // Questo e' per l'errore MI3404
|
||
{
|
||
ifs += imponibile;
|
||
vfs += imposta;
|
||
}
|
||
_pim->put("I0",NETTO);
|
||
}
|
||
|
||
// Rettifica il valore da memorizzare in PAM->R1, utilizzato nel calcolo Vol.Affari
|
||
// Solo nel caso in cui l'importo corrente deve far parte di tale calcolo
|
||
// Se e' valido per calcolo solo vol.aff aggiunge gli importi non aggiunti a causa del !liq
|
||
// Se e' valido per calcolo solo liq. sottrae gli importi aggiunti a causa del liq.
|
||
// Nel caso di sosp. normale non viene ne progressivato ne liquidato e ne considerato per vol. aff.
|
||
if (sosp_vaf || sosp_liq)
|
||
{
|
||
real iii = imponibile;
|
||
real iiimmm = imponibile + imposta;
|
||
|
||
if (sosp_liq)
|
||
{
|
||
iii *= -1;
|
||
iiimmm *= -1;
|
||
}
|
||
|
||
if (corrisp)
|
||
if (tipodoc == "FS")
|
||
{
|
||
if (tipoiva == "VE")
|
||
vendite += iiimmm;
|
||
}
|
||
else
|
||
vendite += iii;
|
||
else
|
||
if (tipomov == vendita)
|
||
vendite += iii;
|
||
}
|
||
|
||
if (autodafe) // autofatture non residenti art.17
|
||
{
|
||
/*
|
||
* Si devono riportare a parte in annuale
|
||
* e non comparire nel riepilogo del codice IVA
|
||
* corrispondente, solo se la liq. e' annuale
|
||
* Li metto in R7/R8 di pim e li sommo anche nelle
|
||
* vendite; la describe_pim() dovra' sommarli su tutti i
|
||
* pim, scorporarli dalle rispettive vendite
|
||
* e assegnarli al codice IVA AF in caso di liq. annuale
|
||
*/
|
||
adf += imponibile;
|
||
adi += imposta;
|
||
}
|
||
|
||
if (art40) // ammontare acq. intr. art40 c. 5/6/8
|
||
{ // Analogamente alle autofatture, si devono riportare a parte in annuale
|
||
// Vengono piazzati in una TToken_string con separatore = a '!'.
|
||
// La TToken_string viene registrata in S0.
|
||
// La describe_pim() sommera' tutte le storie, scorporandoli
|
||
// dalle vendite e assegnandoli al codice VA7 in caso di liq annuale.
|
||
va7i += imponibile;
|
||
va7v += imposta;
|
||
}
|
||
|
||
if (corrisp && !true_corrisp)
|
||
{
|
||
fci += imponibile;
|
||
fcv += imposta;
|
||
}
|
||
|
||
/*
|
||
* Calcolo e aggiornamento
|
||
* cerca o crea progressivo IVA.
|
||
* Onde evitare ripetizioni di codice adotto il metodo sottoindicato,
|
||
* come nell'azzeramento di zero_att().
|
||
*/
|
||
int start = 0, stop = 1;
|
||
if (_recalc_regis) // ricalcolo solo per registri.
|
||
{
|
||
start = 2;
|
||
stop = 3;
|
||
}
|
||
|
||
for (int i=start; i<=stop; i++) // Ciclo per le tabelle
|
||
{
|
||
if (i == 1 || i == 3) //Is it a valid PIS/PRP (vedi anche sel. cursore & date_ok())?
|
||
if ((liqmonth == 0 && month < 13) || (month == 13 && liqmonth != 12))
|
||
continue;
|
||
|
||
switch (i)
|
||
{
|
||
case 1: // Progressivi Iva mensili da periodo Successivo
|
||
look_pis(month, codatt, reg, tipocr_s, codiva, tipodet, true);
|
||
break;
|
||
case 2: // Progressivi Registri iva Mensili
|
||
look_prm(month, codatt, reg, tipocr_s, codiva, tipodet, true);
|
||
break;
|
||
case 3: // Progressivi Registri iva Mensili da periodo Precedente
|
||
look_prp(month, codatt, reg, tipocr_s, codiva, tipodet, true);
|
||
break;
|
||
default: // Progressivi Iva Mensili normali
|
||
look_pim(month, codatt, reg, tipocr_s, codiva, tipodet, true);
|
||
break;
|
||
}
|
||
|
||
TTable *tab = arr[i];
|
||
TRectype& curr = tab->curr();
|
||
|
||
if (!ign)
|
||
{
|
||
curr.add("R0", imp);
|
||
curr.add("R1", ivp);
|
||
curr.add("R2", lor);
|
||
curr.add("R3", lorcor); // Corrispettivi, non inclusi quelli da ventilare
|
||
curr.add("R5", ifs);
|
||
curr.add("R6", vfs);
|
||
curr.add("R7", adf);
|
||
curr.add("R8", adi);
|
||
curr.add("R9", bdi);
|
||
curr.add("R10", bdv);
|
||
curr.add("R13", fci);
|
||
curr.add("R14", fcv);
|
||
}
|
||
// questi servono per i ricalcoli altrui (classify_pim) o
|
||
// per trucchetti di ricalcolo successivi
|
||
curr.add("R11",fsi);
|
||
curr.add("R12",fsv);
|
||
|
||
curr.put("I1", (long)tipomov);
|
||
curr.put("B3", ivarimb ? "X" : "");
|
||
curr.put("B4", (_isricacq && was_riv) ? "X" : "");
|
||
curr.put("S5", tipoiva);
|
||
|
||
// art 40 c. 5/6/8 per VA7.
|
||
real r,v;
|
||
TToken_string kr(tab->get("S0"),'!');
|
||
r = real(kr.get(0)) + va7i;
|
||
v = real(kr.get(1)) + va7v;
|
||
kr.add(r.string(), 0);
|
||
kr.add(v.string(), 1);
|
||
tab->put("S0",kr);
|
||
|
||
// fatture in ritardo
|
||
TToken_string fr(tab->get("S1"),'!');
|
||
r = real(fr.get(0)) + rti;
|
||
v = real(fr.get(1)) + rtv;
|
||
fr.add(r.string(), 0);
|
||
fr.add(v.string(), 1);
|
||
tab->put("S1",fr);
|
||
|
||
// corrispettivi gia' scorporati; anche questi servono per
|
||
// non cannare la stampa dei registri; contengono anche
|
||
// tutti i non incassati (vedi definizione di bool nonimp)
|
||
TToken_string cs(tab->get("S2"),'!');
|
||
r = real(cs.get(0)) + csi;
|
||
v = real(cs.get(1)) + csv;
|
||
cs.add(r.string(), 0);
|
||
cs.add(v.string(), 1);
|
||
tab->put("S2",cs);
|
||
|
||
if (is_detraibile == 0 && // eseguire solo una volta (is_detraibile <20> in un ciclo da 0 a 1)
|
||
(!diff_imp.is_zero() || !diff_iva.is_zero() ||
|
||
!incdiff_imp.is_zero() || !incdiff_iva.is_zero()))
|
||
{
|
||
if (tipomov == vendita)
|
||
{
|
||
#ifndef NDEBUG
|
||
if (codiva=="10" && !incdiff_iva.is_zero())
|
||
{
|
||
const real oldv = tab->get("R29");
|
||
const real newv = oldv + incdiff_iva;
|
||
const long numreg = _mov->get_long(MOV_NUMREG);
|
||
__trace("%s %s\t%s\t%s\t%7ld\t%s\t+\t%s\t=\t%s", tab->name(), (const char*)tab->curr().get("CODTAB"), (const char*)reg, (const char*)tipocr_s,
|
||
numreg, oldv.stringa(12, 2), incdiff_iva.stringa(12, 2), newv.stringa(12, 2));
|
||
}
|
||
#endif
|
||
// fatture vendita a liquidazione differita
|
||
tab->curr().add("R26", diff_imp);
|
||
tab->curr().add("R27", diff_iva);
|
||
tab->curr().add("R28", incdiff_imp);
|
||
tab->curr().add("R29", incdiff_iva);
|
||
|
||
fdiff_imp += diff_imp;
|
||
fdiff_iva += diff_iva;
|
||
fdiffinc_imp += incdiff_imp;
|
||
fdiffinc_iva += incdiff_iva;
|
||
if (_mov->get_int(MOV_ANNOIVA) < year_int)
|
||
{
|
||
_diff_ven_ap += incdiff_imp;
|
||
_diff_ven_ap_iva += incdiff_iva;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// fatture acquisto a liquidazione differita
|
||
tab->curr().add("R30", diff_imp);
|
||
tab->curr().add("R31", diff_iva);
|
||
tab->curr().add("R32", incdiff_imp);
|
||
tab->curr().add("R33", incdiff_iva);
|
||
fdiff_imp_acq += diff_imp;
|
||
fdiff_iva_acq += diff_iva;
|
||
fdiffinc_imp_acq += incdiff_imp;
|
||
fdiffinc_iva_acq += incdiff_iva;
|
||
if (_mov->get_int(MOV_ANNOIVA) < year_int)
|
||
{
|
||
_diff_acq_ap += incdiff_imp;
|
||
_diff_acq_ap_iva += incdiff_iva;
|
||
}
|
||
}
|
||
}
|
||
|
||
tab->rewrite(); // rewrite current table
|
||
} // for per tabelle
|
||
} // for is_detraibile
|
||
} while (_cur->next_match(LF_RMOVIVA));
|
||
} // fine calcolo progressivi IVA
|
||
|
||
|
||
if (!_recalc_regis)
|
||
{
|
||
/*
|
||
* calcolati tutti i movimenti e aggiornati i pim
|
||
* se necessario risistema le imposte acquisti beni
|
||
* per rivendita
|
||
*/
|
||
|
||
if (_isricacq) // flag settato parametri studio
|
||
{
|
||
for (_pim->first(); !_pim->eof(); _pim->next())
|
||
{
|
||
// this is much furber than doing all of the checks
|
||
if (_pim->get_bool("B4"))
|
||
{
|
||
// ricalcola l'imposta a partire dal codice IVA
|
||
look_iva(*_pim_codiva);
|
||
real old_iva = _pim->get_real("R1");
|
||
real perc = _iva->get_real("R0");
|
||
|
||
real new_iva = _pim->get_real("R0") * perc / CENTO;
|
||
round_al_centesimo(new_iva);
|
||
|
||
if (new_iva != old_iva)
|
||
{
|
||
// ricalcola: acquisti_iva, acq_riv_iva
|
||
acquisti_iva -= old_iva;
|
||
acquisti_iva += new_iva;
|
||
acq_riv_iva -= old_iva;
|
||
acq_riv_iva += new_iva;
|
||
_pim->put("R1", new_iva);
|
||
// resetta in modo da non vederlo il mese dopo
|
||
_pim->put("B4", "");
|
||
_pim->rewrite();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// Ricalcola le imposte per regime agricolo dal 1998 (PIA)
|
||
if (_isagricolo)
|
||
{
|
||
for (_pia->first(); !_pia->eof(); _pia->next())
|
||
{
|
||
if (_pia->get_bool("B0"))
|
||
{
|
||
// calcola l'imposta a partire dal codice IVA di compensazione
|
||
look_iva(*_pia_codcom);
|
||
real perc = _iva->get_real("R0");
|
||
|
||
real iva = _pia->get_real("R0") * perc / CENTO;
|
||
round_al_centesimo(iva);
|
||
agr_detIA += iva;
|
||
_pia->put("R1",iva);
|
||
// resetta in modo da non vederlo il mese dopo
|
||
_pia->put("B0", "");
|
||
_pia->rewrite();
|
||
}
|
||
}
|
||
}
|
||
|
||
/* calcola il lercio prorata solo se liq. periodica */
|
||
real prorata, prorata_precedente1, prorata_precedente2;
|
||
real percentuale1, percentuale2;
|
||
if (month != 13)
|
||
{
|
||
TString4 yy;
|
||
// Prorata per documenti registrati con anno doc 2 anni fa...
|
||
yy.format("%d", year_int - 2);
|
||
real* rr1 = (real*)acq_iva_anni_prec.objptr(yy);
|
||
yy.format("%d", year_int - 1); // Reperire la % prorata dell'anno successivo a quello del documento
|
||
percentuale1 = _prorata.percentuale(yy);
|
||
prorata_precedente1 = rr1 ? _prorata.calc_prorata(*rr1, yy) : ZERO;
|
||
// Se sono presenti documenti di anni precedenti senza % prorata, si deve segnalare l'incongruenza (solo in prova)
|
||
if (percentuale1 == INVALID_PRORATA && rr1 && !rr1->is_zero())
|
||
percentuale1 = INVALID_PRORATA_ASSERT;
|
||
|
||
// Prorata per documenti registrati con anno doc 3 anni fa...
|
||
yy.format("%d", year_int - 3);
|
||
real *rr2 = (real*)acq_iva_anni_prec.objptr(yy);
|
||
yy.format("%d", year_int - 2); // Reperire la % prorata dell'anno successivo a quello del documento
|
||
percentuale2 = _prorata.percentuale(yy);
|
||
prorata_precedente2 = rr2 ? _prorata.calc_prorata(*rr2, yy) : ZERO;
|
||
// Se sono presenti documenti di anni precedenti senza % prorata, si deve segnalare l'incongruenza (solo in prova)
|
||
if (percentuale2 == INVALID_PRORATA && rr2 && !rr2->is_zero())
|
||
percentuale2 = INVALID_PRORATA_ASSERT;
|
||
|
||
// Prorata per l'anno corrente + quelli eventuali dello scorso anno e quelli che sono oltre 3 anni fa...
|
||
// E quelli che non hanno la % prorata settata in tabella
|
||
real aaa = acquisti_iva;
|
||
|
||
// E'una questione molto dibattuta il fatti di escludere i beni ammortizzabili o no:
|
||
// Nella versione precedente (10.0) non venivano esclusi, poi dal 4-9-2014 sono stati esclusi ed infine nuovamente ignorati dal 17-2-2015
|
||
// Arriviamo al 17-09-2015 (data epica per altri motivi) e torniamo a tenerne conto per Pragma
|
||
aaa -= ammort_det_iva; // Scarta gli acquisti di beni ammortizzabili
|
||
|
||
if (percentuale1 != INVALID_PRORATA && percentuale1 != INVALID_PRORATA_ASSERT)
|
||
aaa -= rr1 ? *rr1 : ZERO;
|
||
if (percentuale2 != INVALID_PRORATA && percentuale2 != INVALID_PRORATA_ASSERT)
|
||
aaa -= rr2 ? *rr2 : ZERO;
|
||
prorata = _prorata.calc_prorata(aaa, _year);
|
||
|
||
const real prorata_diff = _prorata.calc_prorata(fdiffinc_iva_acq, _year);
|
||
|
||
// Somma i vari prorata calcolati per gli anni precedenti
|
||
prorata += prorata_precedente1 + prorata_precedente2;
|
||
|
||
acquisti_iva -= prorata; // Rettifica acquisti_iva
|
||
|
||
prorata += prorata_diff;
|
||
fdiffinc_iva_acq -= prorata_diff; // Rettifica acquisti_iva differiti incassati
|
||
}
|
||
look_plm(month, codatt, true);
|
||
|
||
/*
|
||
* ACHTUNG: l'iva sulle vendite e' calcolata sommando anche i
|
||
* corrispettivi che sono corrispettivi, a differenza dei corrispettivi
|
||
* che non sono corrispettivi, ma tanto quelli (come si sa) non sono
|
||
* corrispettivi. Dunque, non si tiene conto delle imposte calcolate
|
||
* con la ventilazione (che vanno sottratte) ne' di quelle
|
||
* calcolate per le agenzie di viaggio (che sembra non vadano
|
||
* comunque sottratte nel calcolo del volume di affari)
|
||
*/
|
||
|
||
/*
|
||
* Il prorata pagato in annuale viene scritto a 0, perche' in realta' sarebbe
|
||
* la somma di quelli pagati nei mesi precedenti.
|
||
*/
|
||
_plm->put("R2", prorata); // Prorata complessivo (acq. rif. anno attuale + acq. rif. anni precedenti)
|
||
_plm->put("R14", prorata_precedente1); // Prorata acq. rif. anno addietro
|
||
_plm->put("R15", prorata_precedente2); // Prorata acq. rif. 2 anni addietro
|
||
|
||
if (_isviaggio)
|
||
{
|
||
_plm->put("R5", corr_CEE);
|
||
_plm->put("R6", corr_noCEE);
|
||
_plm->put("R7", acq_CEE);
|
||
_plm->put("R8", acq_noCEE);
|
||
_plm->put("R9", corr_misCEE);
|
||
_plm->put("R10",acq_misCEE);
|
||
_plm->put("R11",acq_misnoCEE);
|
||
|
||
// ---- NOTA BENE ------------------------
|
||
// l'iva vendite nei plm non comprende
|
||
// l'iva agenzie di viaggio, calcolata
|
||
// in liquidazione (mensile o trimestrale): recalc_viaggio()
|
||
}
|
||
else if (_isagricolo)
|
||
{
|
||
_plm->put("R5", agr_1);
|
||
_plm->put("R6", agr_2);
|
||
_plm->put("R7", agr_3);
|
||
_plm->put("R8", agr_4);
|
||
_plm->put("R9", agr_5);
|
||
_plm->put("R10", agr_6);
|
||
_plm->put("R11", agr_7);
|
||
_pum->put("R10", agr_1i);
|
||
_pum->put("R11", agr_2i);
|
||
|
||
// Il porco agricoltore spende poco e paga meno
|
||
vendite_iva = agr_2;
|
||
acquisti_iva = agr_1 + agr_3;
|
||
|
||
// nuovo calcolo IVA detraibile
|
||
if (!agr_7.is_zero())
|
||
{
|
||
real pdetr = (agr_2i / (agr_1i + agr_2i));
|
||
pdetr.round(2);
|
||
acquisti_iva += agr_7 * pdetr;
|
||
round_al_centesimo(acquisti_iva);
|
||
}
|
||
|
||
// Dal 1998
|
||
_plm->put("R13", agr_detIA);
|
||
acquisti_iva += agr_detIA;
|
||
}
|
||
|
||
_plm->put("R12", _prorata.percentuale(_year)); // per comodita' in stampa
|
||
_plm->put("R4", percentuale1);
|
||
_plm->put("R16", percentuale2);
|
||
_plm->put("R0", vendite_iva);
|
||
_plm->put("R1", acquisti_iva);
|
||
_plm->put("R3", ult_detr);
|
||
_plm->put("B0", "X"); // calcolato (invalidato dalla primanota)
|
||
// Setta il flag di stampa errore: se siamo oltre 1997 e non esiste tabella anno prec e vi sono docs con tale riferimento
|
||
_pom->put("R9", acq_ies);
|
||
_pom->put("R10", acq_ies_iva);
|
||
_pum->put("R8", acq_pint);
|
||
_pum->put("R9", acq_pint_iva);
|
||
_pam->put("R10", spgen);
|
||
_pam->put("R11", spgen_iva);
|
||
_pom->put("R0", totintra);
|
||
_pom->put("R1", nond19_imp);
|
||
_pom->put("R2", nond19_iva);
|
||
_pom->put("R3", ammort_det);
|
||
_pom->put("R4", ammort_det_iva);
|
||
_pom->put("R5", acq_riv);
|
||
_pom->put("R6", acq_riv_iva);
|
||
_pom->put("R7", leasing);
|
||
_pom->put("R8", leasing_iva);
|
||
_pom->put("R11", ammort_indet);
|
||
_pom->put("R12", ammort_indet_iva);
|
||
|
||
_pum->put("R0", cess_amm);
|
||
_pum->put("R1", cess_amm_iva);
|
||
_pum->put("R2", ammort_6);
|
||
_pum->put("R3", ammort_6_iva);
|
||
_pum->put("R4", esenti_c1);
|
||
_pum->put("R5", esenti_c2);
|
||
_pum->put("R6", esenti_c3);
|
||
_pum->put("R13", esenti_c1a);
|
||
_pum->put("S4", esenti_c3_bam);
|
||
_pum->put("S5", esenti_c1a_bam);
|
||
_pum->put("R7", esenti_b14);
|
||
_pum->put("R12", esni_rimb);
|
||
|
||
/* Dal 2016 calcoliamo comunicazione annuale in cg5
|
||
_pum->put("R14", cessioni_cd1_1);
|
||
_pum->put("R15", cessioni_cd1_2);
|
||
_pum->put("R16", cessioni_cd1_3);
|
||
_pum->put("R17", cessioni_cd1_4);
|
||
_pum->put("R18", acquisti_cd2_1);
|
||
_pum->put("R19", acquisti_cd2_2);
|
||
_pum->put("R20", acquisti_cd2_3);
|
||
_pum->put("R21", acquisti_cd2_4);
|
||
_pum->put("R22", oroargento_cd3_1);
|
||
_pum->put("R23", oroargento_cd3_2);
|
||
_pum->put("R24", rottami_cd3_3);
|
||
_pum->put("R25", rottami_cd3_4);
|
||
_pum->put("R26", acquisti_cd2_5);
|
||
_pum->put("R27", cessioni_cd1_5);
|
||
_pum->put("R28", vendite_rev); // Vendite in reverse charge da escludere da prorata
|
||
_pum->put("R29", cessioni_cd1_1s); // cessioni in split
|
||
*/
|
||
|
||
_pam->put("R0", acquisti);
|
||
_pam->put("R1", vendite);
|
||
_pam->put("R6", assp_imp);
|
||
_pam->put("R7", assp_iva);
|
||
_pam->put("R8", vssp_imp);
|
||
_pam->put("R9", vssp_iva);
|
||
_pam->put("R4", bdog_imp);
|
||
_pam->put("R5", bdog_iva);
|
||
_pam->put("R12", assl_imp);
|
||
_pam->put("R13", assl_iva);
|
||
_pam->put("R14", vssl_imp);
|
||
_pam->put("R15", vssl_iva);
|
||
|
||
_plm->put("R26", fdiff_imp);
|
||
_plm->put("R27", fdiff_iva);
|
||
_plm->put("R28", fdiffinc_imp);
|
||
_plm->put("R29", fdiffinc_iva);
|
||
_plm->put("R30", fdiff_imp_acq);
|
||
_plm->put("R31", fdiff_iva_acq);
|
||
_plm->put("R32", fdiffinc_imp_acq);
|
||
_plm->put("R33", fdiffinc_iva_acq);
|
||
|
||
_plm->rewrite();
|
||
_pam->rewrite();
|
||
_pum->rewrite();
|
||
_pom->rewrite();
|
||
|
||
if (month == 13)
|
||
{
|
||
TTable pem("PEM");
|
||
for (int reg = 0; reg < 23; reg++)
|
||
{
|
||
look_pem(pem, reg);
|
||
pem.curr().add("R0", vt_imponibile[reg]);
|
||
pem.curr().add("R1", vt_imposta[reg]);
|
||
pem.rewrite();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void TLiquidazione_app::iva11_set_arr_phase_1(const TString& codatt)
|
||
// viene chiamata quando vengono scorsi i movimenti del mese, settando gran parte degli elementi di _iva11_arr.
|
||
{
|
||
// My God! Che 2 palle riestrarre tutte le informazioni
|
||
const TString4 tipodoc = _mov->get(MOV_TIPODOC);
|
||
const bool intra = _rmoviva->get_bool(RMI_INTRA);
|
||
const int tipocr = _rmoviva->get_int(RMI_TIPOCR);
|
||
// A partire dalla versione 3.1 la gestione dell'IVA 11 non viene piu' supportata ...
|
||
// ... ergo non stiamo a gestire la indetraibilita' parziale
|
||
real percind;
|
||
const int tipodet = get_tipodet_from_rmi(_rmoviva->curr(), _mov->curr(), percind);
|
||
real imponibile = _rmoviva->get_real(RMI_IMPONIBILE);
|
||
real imposta = _rmoviva->get_real(RMI_IMPOSTA);
|
||
const TString4 codiva = _iva->get("CODTAB");
|
||
const TString4 tipoiva = _iva->get("S1");
|
||
const real ali = _iva->get_real("R0");
|
||
const TString4 tipoes_v = _iva->get("S2");
|
||
const TString4 tipoes_a = _iva->get("S9");
|
||
const int tipoagr = _iva->get_int("I4"); // 2/9/2015 was S4
|
||
const TRectype& rcs = _cur->curr(LF_CAUSALI);
|
||
const bool autofattura = rcs.get_bool("AUTOFATT");
|
||
const bool valintra = rcs.get_bool("VALINTRA");
|
||
const bool intracom = rcs.get_bool("INTRACOM");
|
||
const tipo_sospensione sosp_imp = _reg->get_bool("B1") ? (tipo_sospensione) _reg->get_int("I9") : nessuna;
|
||
const bool corrisp = _reg->get_bool("B0");
|
||
const tiporeg tipomov = (tiporeg)_reg->get_long("I0");
|
||
const bool is_vendita = tipomov == vendita;
|
||
const bool is_acquisto = tipomov == acquisto;
|
||
|
||
const bool is_key = _iva11_arr.is_key(codatt);
|
||
if (!is_key) // Aggiunge l'elemento se non c'e'
|
||
_iva11_arr.add(codatt,(_Iva11Array*)new _Iva11Array,is_key);
|
||
_Iva11Array& array = (_Iva11Array&)_iva11_arr[codatt] ;
|
||
|
||
|
||
// TAB11_RQA34 ovvero "RQA34" non viene trasferito!
|
||
// Sebbene per motivi di piet<65> viene comunque lasciato nel tracciato record (esigenze PRASSI)
|
||
if (codiva.blank())
|
||
return;
|
||
|
||
if (is_acquisto)
|
||
{
|
||
if (_isagricolo && tipodet == 0)
|
||
{
|
||
if (tipoagr == 2)
|
||
{
|
||
if (tipocr == 2 || tipocr == 3 || tipocr == 8)
|
||
{
|
||
array.sub(imponibile,TAB11_G30I,LF_TAB1100B);
|
||
array.sub(imposta,TAB11_G30V,LF_TAB1100B);
|
||
}
|
||
else
|
||
{
|
||
array.add(imponibile,TAB11_G30I,LF_TAB1100B);
|
||
array.add(imposta,TAB11_G30V,LF_TAB1100B);
|
||
}
|
||
}
|
||
else if (tipoagr == 3 && tipocr !=2 && tipocr != 3 && tipocr != 8)
|
||
{
|
||
array.add(imponibile,TAB11_G31I,LF_TAB1100B);
|
||
array.add(imposta,TAB11_G31V,LF_TAB1100B);
|
||
}
|
||
}
|
||
|
||
if (sosp_imp == nessuna && tipodet == 0 && (tipocr == 2 || tipocr == 8))
|
||
{
|
||
array.add(imposta,TAB11_R6,LF_TAB1100B);
|
||
}
|
||
|
||
if (sosp_imp == nessuna || sosp_imp == vol_affari)
|
||
{
|
||
if (tipodoc == "BD" && tipodet == 9)
|
||
{
|
||
array.add(imponibile,TAB11_F76);
|
||
if (_sind11)
|
||
array.add(imposta,TAB11_F76);
|
||
}
|
||
|
||
if (tipodoc != "BD")
|
||
{ // Compila prima i campi FC1nn ed FC2nn, poi i campi SBFnn ed SBInn
|
||
if (tipodet != 9)
|
||
{
|
||
if (ali == 2.00)
|
||
{
|
||
array.add(imponibile,TAB11_FC101);
|
||
array.add(imposta,TAB11_FC201);
|
||
}
|
||
else if (ali == 4.00)
|
||
{
|
||
array.add(imponibile,TAB11_FC102);
|
||
array.add(imposta,TAB11_FC202);
|
||
}
|
||
else if (ali == 6.00)
|
||
{
|
||
array.add(imponibile,TAB11_FC103);
|
||
array.add(imposta,TAB11_FC203);
|
||
}
|
||
else if (ali == 7.50)
|
||
{
|
||
array.add(imponibile,TAB11_FC104);
|
||
array.add(imposta,TAB11_FC204);
|
||
}
|
||
else if (ali == 8.50)
|
||
{
|
||
array.add(imponibile,TAB11_FC105);
|
||
array.add(imposta,TAB11_FC205);
|
||
}
|
||
else if (ali == 9.00)
|
||
{
|
||
array.add(imponibile,TAB11_FC106);
|
||
array.add(imposta,TAB11_FC206);
|
||
}
|
||
else if (ali == 10.00)
|
||
{
|
||
array.add(imponibile,TAB11_FC107);
|
||
array.add(imposta,TAB11_FC207);
|
||
}
|
||
else if (ali == 16.00)
|
||
{
|
||
array.add(imponibile,TAB11_FC108);
|
||
array.add(imposta,TAB11_FC208);
|
||
}
|
||
else if (ali == 19.00)
|
||
{
|
||
array.add(imponibile,TAB11_FC109);
|
||
array.add(imposta,TAB11_FC209);
|
||
}
|
||
else if (ali == 20.00)
|
||
{
|
||
array.add(imponibile,TAB11_FC110);
|
||
array.add(imposta,TAB11_FC210);
|
||
}
|
||
|
||
if (tipoes_a == "15")
|
||
array.add(imponibile,TAB11_FC111);
|
||
else if (tipoes_a == "12")
|
||
array.add(imponibile,TAB11_FC112);
|
||
else if (tipoes_a == "13")
|
||
array.add(imponibile,TAB11_FC113);
|
||
else if (tipoes_a == "14")
|
||
array.add(imponibile,TAB11_FC114);
|
||
else if (tipoes_a == "16")
|
||
array.add(imponibile,TAB11_FC115);
|
||
}
|
||
else
|
||
{
|
||
array.add(imponibile,TAB11_FC116);
|
||
if (_sind11)
|
||
array.add(imposta,TAB11_FC116);
|
||
}
|
||
|
||
if (intra) // Compila i campi SBFnn
|
||
{
|
||
if (tipodet != 9)
|
||
{
|
||
if (ali == 4.00)
|
||
{
|
||
array.add(imponibile,TAB11_SBF01);
|
||
array.add(imposta,TAB11_SBI01);
|
||
}
|
||
else if (ali == 6.00)
|
||
{
|
||
array.add(imponibile,TAB11_SBF02);
|
||
array.add(imposta,TAB11_SBI02);
|
||
}
|
||
else if (ali == 7.50)
|
||
{
|
||
array.add(imponibile,TAB11_SBF03);
|
||
array.add(imposta,TAB11_SBI03);
|
||
}
|
||
else if (ali == 9.00)
|
||
{
|
||
array.add(imponibile,TAB11_SBF04);
|
||
array.add(imposta,TAB11_SBI04);
|
||
}
|
||
else if (ali == 10.00)
|
||
{
|
||
array.add(imponibile,TAB11_SBF05);
|
||
array.add(imposta,TAB11_SBI05);
|
||
}
|
||
else if (ali == 16.00)
|
||
{
|
||
array.add(imponibile,TAB11_SBF06);
|
||
array.add(imposta,TAB11_SBI06);
|
||
}
|
||
else if (ali == 19.00)
|
||
{
|
||
array.add(imponibile,TAB11_SBF07);
|
||
array.add(imposta,TAB11_SBI07);
|
||
}
|
||
else if (ali == 20.00)
|
||
{
|
||
array.add(imponibile,TAB11_SBF08);
|
||
array.add(imposta,TAB11_SBI08);
|
||
}
|
||
|
||
if (tipoes_a == "15")
|
||
array.add(imponibile,TAB11_SBF09);
|
||
else if (tipoes_a == "12")
|
||
array.add(imponibile,TAB11_SBF10);
|
||
else if (tipoes_a == "13")
|
||
array.add(imponibile,TAB11_SBF11);
|
||
else if (tipoes_a == "14")
|
||
array.add(imponibile,TAB11_SBF12);
|
||
}
|
||
else
|
||
{
|
||
array.add(imponibile,TAB11_SBF13);
|
||
if (_sind11)
|
||
array.add(imposta,TAB11_SBF13);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (is_vendita)
|
||
{
|
||
if (tipodoc == "CN" || tipodoc == "SN" || tipodoc == "RN") // salta i non incassati
|
||
return;
|
||
|
||
if (intracom || !valintra)
|
||
{
|
||
if (tipoes_v.full()) // Inutile fare troppi controlli...
|
||
{
|
||
if (tipoes_v == "24")
|
||
array.add(imponibile,TAB11_EC106);
|
||
if (tipoes_v == "21")
|
||
array.add(imponibile,TAB11_EC107);
|
||
else if (tipoes_v == "B1")
|
||
array.add(imponibile,TAB11_EC108);
|
||
else if (tipoes_v == "B2")
|
||
array.add(imponibile,TAB11_EC109);
|
||
else if (tipoes_v == "B3")
|
||
array.add(imponibile,TAB11_EC110);
|
||
else if (tipoes_v == "25")
|
||
array.add(imponibile,TAB11_EC111);
|
||
else if (tipoes_v == "22")
|
||
array.add(imponibile,TAB11_EC113);
|
||
else if (tipoes_v == "20")
|
||
array.add(imponibile,TAB11_EC114);
|
||
else if (tipoes_v == "G7A")
|
||
array.add(imponibile,TAB11_EC115);
|
||
else if (tipoes_v == "G7B")
|
||
array.add(imponibile,TAB11_EC116);
|
||
else if (tipoes_v == "R9") // Divenuto obsoleto prima ancora di utilizzarlo...
|
||
array.add(imponibile,TAB11_R9,LF_TAB1100B);
|
||
}
|
||
|
||
if (tipocr == 4 && tipodoc != "AF" && (sosp_imp == nessuna || sosp_imp == vol_affari))
|
||
array.add(imponibile,TAB11_EC112);
|
||
}
|
||
|
||
if (!(corrisp && tipoiva != "VE" && (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC")))
|
||
{
|
||
if (!autofattura && tipoiva != "NS")
|
||
if (tipodoc == "AF")
|
||
{
|
||
array.add(imponibile,TAB11_A35);
|
||
array.add(imposta,TAB11_L2,LF_TAB1100B);
|
||
}
|
||
else if (valintra && !intra)
|
||
{
|
||
array.add(imponibile,TAB11_A35BIS);
|
||
array.add(imposta,TAB11_L2BIS,LF_TAB1100B);
|
||
}
|
||
|
||
if (!autofattura && (sosp_imp == nessuna || sosp_imp == vol_affari) && intra && tipoes_v == "22")
|
||
array.add(imponibile,TAB11_E52);
|
||
|
||
if (_isagricolo && (tipodoc != "CR" && tipodoc != "SC" && tipodoc != "RF" && tipodoc != "FS"))
|
||
{
|
||
const bool t1 = tipoagr == 1;
|
||
const bool t1_3 = tipoagr == 1 || tipoagr == 3;
|
||
if (ali == 2.00)
|
||
{
|
||
if (t1)
|
||
{
|
||
array.add(imponibile,TAB11_AGME01,LF_TAB1100B);
|
||
array.add(imposta,TAB11_AGVE01,LF_TAB1100B);
|
||
}
|
||
if (intra && t1_3)
|
||
{
|
||
array.add(imponibile,TAB11_ABME01,LF_TAB1100B);
|
||
array.add(imposta,TAB11_ABVE01,LF_TAB1100B);
|
||
}
|
||
}
|
||
else if (ali == 4.00)
|
||
{
|
||
if (t1)
|
||
{
|
||
array.add(imponibile,TAB11_AGME02,LF_TAB1100B);
|
||
array.add(imposta,TAB11_AGVE02,LF_TAB1100B);
|
||
}
|
||
if (intra && t1_3)
|
||
{
|
||
array.add(imponibile,TAB11_ABME02,LF_TAB1100B);
|
||
array.add(imposta,TAB11_ABVE02,LF_TAB1100B);
|
||
}
|
||
}
|
||
else if (ali == 6.00)
|
||
{
|
||
if (t1)
|
||
{
|
||
array.add(imponibile,TAB11_AGME03,LF_TAB1100B);
|
||
array.add(imposta,TAB11_AGVE03,LF_TAB1100B);
|
||
}
|
||
if (intra && t1_3)
|
||
{
|
||
array.add(imponibile,TAB11_ABME03,LF_TAB1100B);
|
||
array.add(imposta,TAB11_ABVE03,LF_TAB1100B);
|
||
}
|
||
}
|
||
else if (ali == 7.50)
|
||
{
|
||
if (t1)
|
||
{
|
||
array.add(imponibile,TAB11_AGME04,LF_TAB1100B);
|
||
array.add(imposta,TAB11_AGVE04,LF_TAB1100B);
|
||
}
|
||
if (intra && t1_3)
|
||
{
|
||
array.add(imponibile,TAB11_ABME04,LF_TAB1100B);
|
||
array.add(imposta,TAB11_ABVE04,LF_TAB1100B);
|
||
}
|
||
}
|
||
else if (ali == 8.50)
|
||
{
|
||
if (t1)
|
||
{
|
||
array.add(imponibile,TAB11_AGME05,LF_TAB1100B);
|
||
array.add(imposta,TAB11_AGVE05,LF_TAB1100B);
|
||
}
|
||
if (intra && t1_3)
|
||
{
|
||
array.add(imponibile,TAB11_ABME05,LF_TAB1100B);
|
||
array.add(imposta,TAB11_ABVE05,LF_TAB1100B);
|
||
}
|
||
}
|
||
else if (ali == 9.00)
|
||
{
|
||
if (t1)
|
||
{
|
||
array.add(imponibile,TAB11_AGME06,LF_TAB1100B);
|
||
array.add(imposta,TAB11_AGVE06,LF_TAB1100B);
|
||
}
|
||
if (intra && t1_3)
|
||
{
|
||
array.add(imponibile,TAB11_ABME06,LF_TAB1100B);
|
||
array.add(imposta,TAB11_ABVE06,LF_TAB1100B);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (is_acquisto || is_vendita)
|
||
if (autofattura)
|
||
array.add(imponibile,TAB11_A35TER);
|
||
}
|
||
|
||
void TLiquidazione_app::iva11_set_arr_phase_2(const TString& codatt)
|
||
// scorre (guarda un poco) tutti i PIM della ditta per COMPLETARE _iva11_arr
|
||
// Ribadisco: questa funzione COMPLETA solamente l'array scorrendo i PIM e memorizzando i rimanenti
|
||
// campi. Gli altri sono compilati scorrendo i movimenti! (fatto prima della chiamata a questa funzione)
|
||
// Il motivo per cui il trasferimento e' fatto in 2 fasi (iva11_set_arr_phase_1 ed iva11_set_arr_phase_2)
|
||
// e' perche' alcune operazioni di calcolo (scorporo corrispettivi, ventilazione...) vengono effettuate
|
||
// dopo la recalc_att(), punto in cui viene chiamata la phase_1.
|
||
{
|
||
TString4 codiva, reg, tiva;
|
||
TString16 tpla, tvia;
|
||
TString16 v11, a11;
|
||
TToken_string tt("",'!');
|
||
tiporeg treg;
|
||
int tipocr,tipodet,tagr;
|
||
real aliq, imp, iva, lor, vtot, atot, ivav, ivaa, adf, adi, va7i, va7v;
|
||
TString16 cur_att;
|
||
|
||
const bool is_key = _iva11_arr.is_key(codatt);
|
||
if (!is_key)
|
||
_iva11_arr.add(codatt,(_Iva11Array*)new _Iva11Array,is_key);
|
||
_Iva11Array& array = (_Iva11Array&)_iva11_arr[codatt];
|
||
|
||
// Scorporo corretto dei corrispettivi in R3
|
||
TAssoc_array corr_ann;
|
||
bool is_present;
|
||
|
||
for (_pim->first(); !_pim->eof(); _pim->next())
|
||
{
|
||
if (_year != *_pim_anno) continue;
|
||
if (atoi(*_pim_mese) != 13) continue;
|
||
cur_att = *_pim_codatt;
|
||
cur_att.rtrim(1);
|
||
if (codatt != cur_att) continue; // considera solo quelli dell'anno, obviously.
|
||
// Must consider current activity too...
|
||
codiva = *_pim_codiva;
|
||
reg = *_pim_codreg;
|
||
look_iva(codiva); look_reg(reg); // posiziona la tabella registri e quella IVA
|
||
tiva = _iva->get("S1"); // tipo IVA
|
||
tpla = _iva->get("S3"); // tipo gestione plafond
|
||
tagr = _iva->get_int("I4"); // tipo gestione regime agricolo 2/9/2015 was S4
|
||
tvia = _iva->get("S5"); // tipo gestione ag. viaggio
|
||
v11 = _iva->get("S2"); // n.ro riga vendite per mod. IVA11
|
||
a11 = _iva->get("S9"); // n.ro riga acquisti per mod. IVA11
|
||
aliq = _iva->get_real("R0"); // aliquota
|
||
treg = (tiporeg)_reg->get_long("I0");
|
||
const bool is_vendita = treg == vendita;
|
||
const bool is_acquisto = treg == acquisto;
|
||
tipocr = atoi(*_pim_tipocr);
|
||
tipodet = atoi(*_pim_tipodet);
|
||
imp = _pim->get_real("R0");
|
||
iva = _pim->get_real("R1");
|
||
lor = _pim->get_real("R3");
|
||
|
||
if (is_acquisto)
|
||
{
|
||
if (tiva != "NS")
|
||
switch (tipocr)
|
||
{
|
||
case 2:
|
||
array.add(imp,TAB11_IMA01);
|
||
break;
|
||
case 8:
|
||
array.add(imp,TAB11_IMA02);
|
||
break;
|
||
case 1:
|
||
case 5:
|
||
array.add(imp,TAB11_IMA03);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
if (tipodet == 1)
|
||
array.add(iva,TAB11_B14);
|
||
|
||
// XC???: tipo detr != 9
|
||
if (tipodet != 9)
|
||
{
|
||
if (aliq == 4.00)
|
||
{
|
||
array.add(_pim->get_real("R9"),TAB11_XC101);
|
||
array.add(_pim->get_real("R10"),TAB11_XC201);
|
||
}
|
||
else if (aliq == 6.00)
|
||
{
|
||
array.add(_pim->get_real("R9"),TAB11_XC102);
|
||
array.add(_pim->get_real("R10"),TAB11_XC202);
|
||
}
|
||
else if (aliq == 7.50)
|
||
{
|
||
array.add(_pim->get_real("R9"),TAB11_XC103);
|
||
array.add(_pim->get_real("R10"),TAB11_XC203);
|
||
}
|
||
else if (aliq == 9.00)
|
||
{
|
||
array.add(_pim->get_real("R9"),TAB11_XC104);
|
||
array.add(_pim->get_real("R10"),TAB11_XC204);
|
||
}
|
||
else if (aliq == 10.00)
|
||
{
|
||
array.add(_pim->get_real("R9"),TAB11_XC105);
|
||
array.add(_pim->get_real("R10"),TAB11_XC205);
|
||
}
|
||
else if (aliq == 16.00)
|
||
{
|
||
array.add(_pim->get_real("R9"),TAB11_XC106);
|
||
array.add(_pim->get_real("R10"),TAB11_XC206);
|
||
}
|
||
else if (aliq == 19.00)
|
||
{
|
||
array.add(_pim->get_real("R9"),TAB11_XC107);
|
||
array.add(_pim->get_real("R10"),TAB11_XC207);
|
||
}
|
||
else if (aliq == 20.00)
|
||
{
|
||
array.add(_pim->get_real("R9"),TAB11_XC108);
|
||
array.add(_pim->get_real("R10"),TAB11_XC208);
|
||
}
|
||
|
||
if (a11 == "12")
|
||
array.add(_pim->get_real("R9"),TAB11_XC109);
|
||
if (a11 == "13" || a11 == "14")
|
||
array.add(_pim->get_real("R9"),TAB11_XC110);
|
||
if (a11 == "16")
|
||
array.add(_pim->get_real("R9"),TAB11_XC111);
|
||
}
|
||
} // is_acquisto
|
||
|
||
if (is_vendita)
|
||
{
|
||
if ((_isagricolo && tagr==2) || !_isagricolo)
|
||
{
|
||
// Accumula i corrispettivi da scorporare per codice iva
|
||
if (lor != ZERO)
|
||
{
|
||
is_present = corr_ann.is_key(codiva);
|
||
if (!is_present) // Aggiungilo se non c'e'
|
||
corr_ann.add(codiva,(_CorrItem*)new _CorrItem,is_present);
|
||
_CorrItem& ca = (_CorrItem&) corr_ann[codiva];
|
||
ca._totale += lor;
|
||
if (!is_present)
|
||
ca._aliquota = _iva->get_real("R0"); // Se e' nuovo setta l'aliquota
|
||
}
|
||
|
||
tt = _pim->get("S0");
|
||
va7i = tt.get(0);
|
||
va7v = tt.get(1);
|
||
adf = imp - _pim->get_real("R7") - va7i + _pim->get_real("R5");
|
||
adi = iva - _pim->get_real("R8") - va7v + _pim->get_real("R6");
|
||
if (aliq == 4.00)
|
||
{
|
||
array.add(adf,TAB11_EC101);
|
||
array.add(adi,TAB11_EC201);
|
||
}
|
||
else if (aliq == 10.00)
|
||
{
|
||
array.add(adf,TAB11_EC102);
|
||
array.add(adi,TAB11_EC202);
|
||
}
|
||
else if (aliq == 16.00)
|
||
{
|
||
array.add(adf,TAB11_EC103);
|
||
array.add(adi,TAB11_EC203);
|
||
}
|
||
else if (aliq == 19.00)
|
||
{
|
||
array.add(adf,TAB11_EC104);
|
||
array.add(adi,TAB11_EC204);
|
||
}
|
||
else if (aliq == 20.00)
|
||
{
|
||
array.add(adf,TAB11_EC105);
|
||
array.add(adi,TAB11_EC205);
|
||
}
|
||
}
|
||
} // is_vendita
|
||
|
||
// Sommatoria per il calcolo aliquote medie vendite/acquisti...
|
||
if (_pim->get_bool("B3")) // E' un record valido per fare questa cosa?
|
||
{
|
||
if ((tiporeg)_pim->get_long("I1") == vendita)
|
||
{ //vendite
|
||
vtot += imp;
|
||
ivav += iva;
|
||
}
|
||
else
|
||
{
|
||
//acquisti
|
||
if (tipodet != 9) // Evita di sommare quelli con tipo detraibilita' 9 (MI2209)
|
||
{
|
||
atot += imp;
|
||
ivaa += iva;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Scorre i corrispettivi lordi accumulati, li scorpora ed aggiorna i righi relativi
|
||
_CorrItem* cc;
|
||
for (cc = (_CorrItem *)corr_ann.first_item(); cc != NULL; cc = (_CorrItem *)corr_ann.succ_item())
|
||
{
|
||
lordo2netto(cc->_totale,imp,iva,cc->_aliquota/CENTO);
|
||
vtot += imp; ivav += iva;
|
||
if (cc->_aliquota == 4.00)
|
||
{
|
||
array.add(imp,TAB11_EC101);
|
||
array.add(iva,TAB11_EC201);
|
||
}
|
||
else if (cc->_aliquota == 10.00)
|
||
{
|
||
array.add(imp,TAB11_EC102);
|
||
array.add(iva,TAB11_EC202);
|
||
}
|
||
else if (cc->_aliquota == 16.00)
|
||
{
|
||
array.add(imp,TAB11_EC103);
|
||
array.add(iva,TAB11_EC203);
|
||
}
|
||
else if (cc->_aliquota == 19.00)
|
||
{
|
||
array.add(imp,TAB11_EC104);
|
||
array.add(iva,TAB11_EC204);
|
||
}
|
||
else if (cc->_aliquota == 20.00)
|
||
{
|
||
array.add(imp,TAB11_EC105);
|
||
array.add(iva,TAB11_EC205);
|
||
}
|
||
}
|
||
|
||
|
||
// Mmmhh.. Rettifica l'importo di EC114: EC114 = EC115 + EC116 + EC114
|
||
real r15, r16;
|
||
if (array.is_key(TAB11_EC115))
|
||
r15 = ((_Iva11Item&)array[TAB11_EC115]).value();
|
||
if (array.is_key(TAB11_EC116))
|
||
r16 = ((_Iva11Item&)array[TAB11_EC116]).value();
|
||
r16+=r15;
|
||
array.add(r16,TAB11_EC114);
|
||
|
||
|
||
// Calcola le maledette aliquote medie...
|
||
real alv,ala;
|
||
if (vtot != 0.0) { alv = ivav/vtot; alv *= CENTO; alv.round(2); }
|
||
if (atot != 0.0) { ala = ivaa/atot; ala *= CENTO; ala.round(2); }
|
||
array.add(ala,TAB11_R1,LF_TAB1100B);
|
||
array.add(alv,TAB11_R2,LF_TAB1100B);
|
||
|
||
// Mo' si pappa i PLM per compilare T1, T1C, T2, T2C, T3, T5 e T6
|
||
// ATTENZIONE: solo per i regimi 74ter (ag. viaggio)
|
||
for (_plm->first();!_plm->eof();_plm->next())
|
||
{
|
||
if (_year != *_plm_anno || atoi(*_plm_mese) != 13)
|
||
continue;
|
||
cur_att = *_plm_codatt;
|
||
cur_att.rtrim(1);
|
||
if (codatt != cur_att)
|
||
continue;
|
||
if (_isviaggio)
|
||
{
|
||
array.add(_plm->get_real("R5"),TAB11_T1,LF_TAB1100B);
|
||
array.add(_plm->get_real("R7"),TAB11_T1C,LF_TAB1100B);
|
||
array.add(_plm->get_real("R6"),TAB11_T2,LF_TAB1100B);
|
||
array.add(_plm->get_real("R8"),TAB11_T2C,LF_TAB1100B);
|
||
array.add(_plm->get_real("R9"),TAB11_T3,LF_TAB1100B);
|
||
array.add(_plm->get_real("R10"),TAB11_T5,LF_TAB1100B);
|
||
array.add(_plm->get_real("R11"),TAB11_T6,LF_TAB1100B);
|
||
}
|
||
array.add(_plm->get_real("R0"),TAB11_IVVENR);
|
||
}
|
||
}
|
||
|
||
void TLiquidazione_app::iva11_write(bool reset_r1r2)
|
||
// Trasferisce i dati IVA11 annuali dall'assoc_array al file tab1100
|
||
{
|
||
const int items = _iva11_arr.items();
|
||
if (items == 0) return;
|
||
|
||
TString ditta,attiv,fld_name;
|
||
|
||
_Iva11Array * iva11_arr;
|
||
_Iva11Item * iva11;
|
||
TLocalisamfile& tab1100a = _tab11->lfile();
|
||
TLocalisamfile& tab1100b = _tab11->lfile(LF_TAB1100B);
|
||
|
||
int err;
|
||
// Ciclo sulle attivita'
|
||
for (iva11_arr = (_Iva11Array *) _iva11_arr.first_item(); iva11_arr != NULL; iva11_arr = (_Iva11Array*)_iva11_arr.succ_item())
|
||
{
|
||
// Setta i campi chiave per entrambi i files della relazione
|
||
ditta.format("%05ld",_nditte->curr().get_long(NDT_CODDITTA));
|
||
attiv = _iva11_arr.get_hashobj()->key();
|
||
tab1100a.zero();
|
||
tab1100a.put(TAB11_TADITT,ditta);
|
||
tab1100a.put(TAB11_TACATT,attiv);
|
||
tab1100b.zero();
|
||
tab1100b.put(TAB11_TADITT,ditta);
|
||
tab1100b.put(TAB11_TACATT,attiv);
|
||
|
||
const int iva11_items = iva11_arr->items();
|
||
// Ciclo sugli elementi per compilare i campi della relazione
|
||
for (iva11 = (_Iva11Item *)iva11_arr->first_item(); iva11 != NULL;iva11 = (_Iva11Item *)iva11_arr->succ_item())
|
||
{
|
||
fld_name = iva11_arr->get_hashobj()->key();
|
||
if (reset_r1r2 && (fld_name == TAB11_R1 || fld_name == TAB11_R2)) continue; // salta R1/R2 se devono rimanere a zero
|
||
_tab11->lfile(iva11->file()).put(fld_name,iva11->value());
|
||
}
|
||
|
||
if (_tab11->write() != NOERR)
|
||
if ((err=_tab11->rewrite()) != NOERR)
|
||
error_box(TR("Errore %d tentando di scrivere sul file tab1100."),err);
|
||
}
|
||
|
||
_iva11_arr.destroy(); // resetta l'array.
|
||
}
|
||
|
||
void TLiquidazione_app::write_liq(int month, const char* codatts)
|
||
// Calcolo liq. mensili e liq. annuali. Scrive le lim
|
||
{
|
||
TToken_string atts(codatts);
|
||
const int year_int = atoi(_year);
|
||
|
||
if (_ver->read(year_int, _month)!=NOERR)
|
||
warning_box(TR("Errore %d in lettura tabella versamenti ed interessi."),_ver->status());
|
||
|
||
/* Cazzata galattica: gi<67> gestito BENE da update_firm, prima di chiamare questa funzione
|
||
// evita casino se differita ma si sta ricalcolando il primo mese con ricalcolo di piu' mesi
|
||
const bool wasdifferita = (_isdifferita && month <= _monthinatt && _month > _monthinatt);
|
||
if (wasdifferita) _isdifferita = false;
|
||
*/
|
||
// liq. differita: considera mese precedente (solo per i risultati)
|
||
int deltam = month;
|
||
if (_isdifferita && !is_first_month(month) && month != 13)
|
||
month -= (_freqviva == "T" ? 3 : 1);
|
||
deltam -= month;
|
||
|
||
const TRectype & lia = get_lia();
|
||
|
||
const bool credito_compensabile = (lia.get("S9") == "CM");
|
||
|
||
real risultato = ZERO;
|
||
|
||
real detrazioni = ZERO;
|
||
real versamenti = ZERO;
|
||
real vers_int = ZERO;
|
||
real rimborsi = ZERO;
|
||
real rettifiche = ZERO;
|
||
real res_debt = ZERO;
|
||
real res_cred = ZERO;
|
||
real cred_prec = ZERO;
|
||
real cred_trasf = ZERO;
|
||
real debt_precd = ZERO;
|
||
real acc_dec = ZERO;
|
||
real iva_vend = ZERO;
|
||
real iva_acq = ZERO;
|
||
real conguaglio = ZERO;
|
||
real variazioni_imposta = ZERO;
|
||
real imposta_non_versata = ZERO;
|
||
real crediti_speciali = ZERO;
|
||
|
||
// totali per regimi agricoli
|
||
real acq_noCEE = ZERO;
|
||
real imp_agr1 = ZERO;
|
||
real imp_agr2 = ZERO;
|
||
|
||
// totali per agenzie viaggio
|
||
real c_iCEE = ZERO;
|
||
real c_eCEE = ZERO;
|
||
real a_iCEE = ZERO;
|
||
real a_eCEE = ZERO;
|
||
real c_mCEE = ZERO;
|
||
real a_mCEE = ZERO;
|
||
real a_meCEE = ZERO;
|
||
real cred_cost = ZERO;
|
||
real deb_mens = ZERO;
|
||
real perc_r = ZERO;
|
||
real fdiff_imp = ZERO;
|
||
real fdiff_iva = ZERO;
|
||
real fdiffinc_imp = ZERO;
|
||
real fdiffinc_iva = ZERO;
|
||
real fdiff_imp_acq = ZERO;
|
||
real fdiff_iva_acq = ZERO;
|
||
real fdiffinc_imp_acq = ZERO;
|
||
real fdiffinc_iva_acq = ZERO;
|
||
|
||
// totali per annuali
|
||
real vol_aff_1 = ZERO;
|
||
real vol_aff_2 = ZERO;
|
||
real vol_aff_l = ZERO;
|
||
real tot_cong = ZERO;
|
||
|
||
bool differita = false;
|
||
bool almeno_una_agricola = false;
|
||
bool almeno_una_normale = false;
|
||
int attc = 0; // counter attivita'
|
||
|
||
// nuova liquidazione
|
||
real credito_utilizzabile_inizio_anno = ZERO;
|
||
real credito_utilizzato_inizio_anno = ZERO;
|
||
real credito_utilizzato_iva = ZERO;
|
||
if (credito_compensabile)
|
||
{
|
||
credito_utilizzato_inizio_anno = lia.get_real("R15");
|
||
credito_utilizzabile_inizio_anno = lia.get_real("R0") - credito_utilizzato_inizio_anno;
|
||
if (credito_utilizzabile_inizio_anno < ZERO)
|
||
credito_utilizzabile_inizio_anno = ZERO;
|
||
}
|
||
|
||
TLocalisamfile& attiv = _nditte->lfile(LF_ATTIV);
|
||
FOR_EACH_TOKEN (atts, tmpatt)
|
||
{
|
||
const TString16 att = tmpatt;
|
||
|
||
// Reperisce il flag di regime agricolo per ogni attivita'...
|
||
attiv.put(ATT_CODATT,att);
|
||
attiv.read();
|
||
const bool attivita_agricola = attiv.get_bool(ATT_REGAGR);
|
||
almeno_una_agricola |= attivita_agricola;
|
||
almeno_una_normale |= !attivita_agricola;
|
||
|
||
if (_isdifferita && is_first_month(month+deltam))
|
||
{
|
||
// usa i totali del mese di dicembre dell'anno
|
||
// precedente
|
||
differita = true;
|
||
const TString4 yr(_year); // Salvo anno corrente
|
||
_year.format("%d", year_int-1);
|
||
const TRectype & lim = get_lim(12);
|
||
|
||
if (lim.empty()) //controlla solamente, il vero posizionamento lo fa dopo
|
||
{
|
||
_year = yr; // Ripristino anno corrente
|
||
differita = false;
|
||
}
|
||
}
|
||
|
||
for (int m = 1; m <= 13; m++)
|
||
{
|
||
// ciclo su tutti i mesi del caso (1 o 3; tutti se annuale)
|
||
if (!is_month_ok(m, month))
|
||
continue;
|
||
|
||
look_plm(differita ? 12 : m, att);
|
||
TRectype lim = get_lim(_isdifferita ? m+deltam : m);
|
||
bool is_lim = lim.not_empty();
|
||
|
||
// Se trattasi di annuale considera solo PLM/PUM del mese 13
|
||
if ((month == 13 && m == 13) || month != 13)
|
||
{
|
||
// gia' conteggiato: prorata
|
||
// da conteggiare: IVA vendite ag. viaggio
|
||
// a debito: IVA vendite, debito precedente
|
||
// a credito: IVA acquisti, ulteriori detrazioni 1 e 2
|
||
|
||
if (!attivita_agricola)
|
||
{
|
||
const real vend = _plm->get_real("R0");
|
||
const real acq = _plm->get_real("R1");
|
||
const real diff_imp = _plm->get_real("R26");
|
||
const real diff_iva = _plm->get_real("R27");
|
||
const real diffinc_imp = _plm->get_real("R28");
|
||
const real diffinc_iva = _plm->get_real("R29");
|
||
const real diff_imp_acq = _plm->get_real("R30");
|
||
const real diff_iva_acq = _plm->get_real("R31");
|
||
const real diffinc_imp_acq = _plm->get_real("R32");
|
||
const real diffinc_iva_acq = _plm->get_real("R33");
|
||
|
||
iva_vend += vend;
|
||
iva_acq += acq;
|
||
risultato += (vend - acq + diffinc_iva - diffinc_iva_acq);
|
||
|
||
res_debt += vend + diffinc_iva;
|
||
res_cred += acq;
|
||
fdiff_imp += diff_imp;
|
||
fdiff_iva += diff_iva;
|
||
fdiffinc_imp += diffinc_imp;
|
||
fdiffinc_iva += diffinc_iva;
|
||
fdiff_imp_acq += diff_imp_acq;
|
||
fdiff_iva_acq += diff_iva_acq;
|
||
fdiffinc_imp_acq += diffinc_imp_acq;
|
||
fdiffinc_iva_acq += diffinc_iva_acq;
|
||
}
|
||
else
|
||
{
|
||
// Tiene aggiornata l'iva vendite
|
||
iva_vend += _plm->get_real("R6") + _plm->get_real("R5");
|
||
// Tiene aggiornata l'iva acquisti, che andra' rettificata all'uscita del mese
|
||
// secondo la formula:
|
||
// iva_acq = iva_acq + iva detraibile calcolata + iva compensazione
|
||
// L'iva di compensazione e' tratta dall'iva vendite agricole con segnalino 1 (vedi tabella PIA)
|
||
// il cui totale e' memorizzato in plm->R13
|
||
// l'iva detraibile calcolata e' a sua volta fatta cosi'
|
||
// sum(plm->R11) * { sum(pum->R11) / [sum(pum->R11) + sum(pum->R10)]}
|
||
// dove plm->R11 = acquisti misti fuori CEE
|
||
// pum->R10 = tot. imponibile reg agr. 1
|
||
// pum->R11 = tot. imponibile reg agr. 2
|
||
// L'iva acquisti viene calcolata in modo diverso se siamo dal 1998 in poi:
|
||
// somma l'iva ammessa in detr. I parte tab. A (R13) anziche' iva vendite (R5)
|
||
iva_acq += _plm->get_real("R7") + _plm->get_real(year_int > 1997 ? "R13" : "R5");
|
||
acq_noCEE += _plm->get_real("R11");
|
||
imp_agr1 += _pum->get_real("R10");
|
||
imp_agr2 += _pum->get_real("R11");
|
||
|
||
const real diff_imp = _plm->get_real("R26");
|
||
const real diff_iva = _plm->get_real("R27");
|
||
const real diffinc_imp = _plm->get_real("R28");
|
||
const real diffinc_iva = _plm->get_real("R29");
|
||
const real diff_imp_acq = _plm->get_real("R30");
|
||
const real diff_iva_acq = _plm->get_real("R31");
|
||
const real diffinc_imp_acq = _plm->get_real("R32");
|
||
const real diffinc_iva_acq = _plm->get_real("R33");
|
||
|
||
fdiff_imp += diff_imp;
|
||
fdiff_iva += diff_iva;
|
||
fdiffinc_imp += diffinc_imp;
|
||
fdiffinc_iva += diffinc_iva;
|
||
fdiff_imp_acq += diff_imp_acq;
|
||
fdiff_iva_acq += diff_iva_acq;
|
||
fdiffinc_imp_acq += diffinc_imp_acq;
|
||
fdiffinc_iva_acq += diffinc_iva_acq;
|
||
}
|
||
detrazioni+= (_plm->get_real("R3"));
|
||
|
||
// detrazioni solo non in regime agricolo
|
||
if (!attivita_agricola)
|
||
{
|
||
const real r3 = _plm->get_real("R3");
|
||
risultato -= r3;
|
||
res_cred += r3;
|
||
}
|
||
/* totalizza importi 74 ter */
|
||
if (_isviaggio)
|
||
{
|
||
// somma totali per calcolo successivo
|
||
c_iCEE += _plm->get_real("R5");
|
||
c_eCEE += _plm->get_real("R6");
|
||
a_iCEE += _plm->get_real("R7");
|
||
a_eCEE += _plm->get_real("R8");
|
||
c_mCEE += _plm->get_real("R9");
|
||
a_mCEE += _plm->get_real("R10");
|
||
a_meCEE += _plm->get_real("R11");
|
||
}
|
||
} // endif per considerare solo PLM del mese 13
|
||
|
||
// Le seguenti cose (versamenti, rettifiche e rimborsi)
|
||
// vanno considerate per tutti i mesi (tabella lim)
|
||
|
||
/* se annuale, somma versamenti mesi 1-12
|
||
* solo una volta (non per tutte le attivita')
|
||
*/
|
||
if (attc == 0 && month == 13)
|
||
{
|
||
// l'acconto a dicembre si conteggia a parte solo
|
||
// nei casi previsti e non in annuale (vedi sotto)
|
||
real vs(versamenti_IVA(m , m == 12 ? "1" : "1|7"));
|
||
real vi(versamenti_IVA(m,"5"));
|
||
versamenti += vs;
|
||
vers_int += vi;
|
||
res_cred += vs + vi;
|
||
}
|
||
|
||
/*
|
||
* rimborso se chiesto e previsto
|
||
* in annuale non si chiede e non va sommato se no lo cumula
|
||
*/
|
||
if (attc == 0 && is_lim && m < 13 && is_month_ok_strict(m,month))
|
||
{
|
||
const real rimborso_richiesto = lim.get_real("R1");
|
||
|
||
risultato += rimborso_richiesto;
|
||
rimborsi += rimborso_richiesto;
|
||
res_debt += rimborso_richiesto;
|
||
}
|
||
|
||
/*
|
||
* rettifiche gia' col loro bravo segno
|
||
*/
|
||
if (attc == 0 && is_lim && is_month_ok_strict(m,month))
|
||
{
|
||
const bool somma_rettifiche = month < 13 || m < 13; // CM00278
|
||
if (somma_rettifiche)
|
||
{
|
||
const real rett = lim.get_real("R5");
|
||
|
||
if (rett.not_zero())
|
||
{
|
||
risultato += rett;
|
||
rettifiche += rett;
|
||
if (rett < ZERO)
|
||
res_cred -= rett;
|
||
else
|
||
res_debt += rett;
|
||
}
|
||
}
|
||
}
|
||
|
||
/*
|
||
* Somme varie per 13a
|
||
*/
|
||
if (attc == 0 && is_lim && m < 13 && is_month_ok_strict(m,month))
|
||
{
|
||
const real r17 = lim.get_real("R17");
|
||
|
||
variazioni_imposta += r17;
|
||
risultato += r17;
|
||
if (r17 >= ZERO)
|
||
res_debt += r17;
|
||
else
|
||
res_cred -= r17;
|
||
|
||
const real r18 = lim.get_real("R18");
|
||
|
||
imposta_non_versata += r18;
|
||
risultato += r18;
|
||
res_debt += r18;
|
||
|
||
const real r19 = lim.get_real("R19");
|
||
|
||
crediti_speciali += r19;
|
||
risultato -= r19;
|
||
res_cred += r19;
|
||
}
|
||
} // fine ciclo sul mese
|
||
|
||
// counter attivita' per evitare troppi versamenti
|
||
attc++;
|
||
if (differita)
|
||
_year.format("%d", atoi(_year)+1);
|
||
|
||
if (!(_isdifferita && is_first_month(month+deltam)))
|
||
{
|
||
if (_isviaggio)
|
||
{
|
||
// calcolo credito costo, debito mensile, perc. ripart.
|
||
perc_r = a_mCEE.is_zero() ? ZERO : (a_mCEE * CENTO)/(a_mCEE + a_meCEE); perc_r.round(2);
|
||
real ivm = (c_mCEE * perc_r)/CENTO; round_al_centesimo(ivm);
|
||
real tc = (c_iCEE + ivm);
|
||
real ta = (a_iCEE + a_mCEE);
|
||
real bi = tc - ta - credito_costo_prec(month);
|
||
|
||
if (bi.sign() < 0)
|
||
// credito di costo
|
||
{
|
||
cred_cost = abs(bi);
|
||
round_imposta(cred_cost);
|
||
}
|
||
else
|
||
{
|
||
const real ali_via = aliquota_agvia();
|
||
// deb_mens = (bi /((CENTO + ali_via)/CENTO)) * (ali_via/CENTO);
|
||
deb_mens = bi * ali_via / (ali_via+CENTO);
|
||
round_al_centesimo(deb_mens); // ceil voluto MI3074
|
||
risultato += deb_mens;
|
||
res_debt += deb_mens;
|
||
iva_vend += deb_mens;
|
||
}
|
||
}
|
||
}
|
||
if (attivita_agricola)
|
||
{
|
||
// percentuale di deducibilita'
|
||
real perc = imp_agr2.is_zero() ? ZERO : imp_agr2 / (imp_agr1 + imp_agr2);
|
||
perc.round(2);
|
||
real iva_ded = acq_noCEE * perc; // iva deducibile
|
||
round_al_centesimo(iva_ded);
|
||
iva_acq += iva_ded;
|
||
res_debt += iva_vend;
|
||
res_cred += iva_acq;
|
||
risultato += (iva_vend - iva_acq);
|
||
} // __ end of agricolo
|
||
} // end ciclo su attivita'
|
||
|
||
real credito_utilizzabile = ZERO;
|
||
const bool utilizza_credito_autorizzato = lia.get_bool("B6");
|
||
|
||
if (month < 13) // va bene anche se differita sommando deltam (che e' 0 normalmente)
|
||
{
|
||
// toglie credito precedente
|
||
cred_prec = credito_prec(month+deltam);
|
||
risultato -= cred_prec;
|
||
res_cred += cred_prec;
|
||
// vedi se c'era un debito precedente per debiti < 50.000
|
||
debt_precd = debt_prec(month+deltam);
|
||
risultato += debt_precd;
|
||
res_debt += debt_precd;
|
||
|
||
|
||
if (credito_compensabile && credito_utilizzabile_inizio_anno > ZERO &&
|
||
(_freqviva == "M" || is_trim(month + deltam)))
|
||
{
|
||
real debiti = res_debt; round_imposta(debiti);
|
||
real crediti = res_cred; round_imposta(crediti);
|
||
const real risul = debiti - crediti;
|
||
TRectype lim = get_lim(month+deltam);
|
||
const real cred_util_F24 = lim.get_real("R16");
|
||
|
||
credito_utilizzabile = credito_utilizzabile_inizio_anno;
|
||
credito_utilizzabile -= credito_utilizzato(month + deltam);
|
||
if (utilizza_credito_autorizzato)
|
||
credito_utilizzabile += credito_autorizzato(month + deltam);
|
||
|
||
credito_utilizzabile -= cred_util_F24;
|
||
if (utilizza_credito_autorizzato)
|
||
{
|
||
const real cred_aut_F24 = lim.get_real("R20");
|
||
|
||
credito_utilizzabile += cred_aut_F24;
|
||
}
|
||
|
||
|
||
if (credito_utilizzabile < ZERO)
|
||
credito_utilizzabile = ZERO;
|
||
if (risul > ZERO)
|
||
{
|
||
|
||
credito_utilizzato_iva = min(risul, credito_utilizzabile);
|
||
res_cred += credito_utilizzato_iva;
|
||
risultato -= credito_utilizzato_iva;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (credito_compensabile)
|
||
{
|
||
cred_prec = ZERO;
|
||
if (credito_utilizzabile_inizio_anno > ZERO)
|
||
{
|
||
credito_utilizzato_iva = credito_utilizzato_IVA(13); // CM00285
|
||
res_cred += credito_utilizzato_iva;
|
||
risultato -= credito_utilizzato_iva;
|
||
|
||
// Calcola credito utilizzabile da riportare nell'anno successivo
|
||
credito_utilizzabile = credito_utilizzabile_inizio_anno;
|
||
credito_utilizzabile -= credito_utilizzato(13);
|
||
credito_utilizzabile += credito_autorizzato(13);
|
||
if (credito_utilizzabile < ZERO)
|
||
credito_utilizzabile = ZERO;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// per l'annuale considera solo il credito a inizio anno
|
||
cred_prec = credito_prec(_freqviva == "M" ? 1 : 3);
|
||
cred_trasf = lia.get_real("R15");
|
||
const real cred_res = cred_prec - cred_trasf;
|
||
risultato -= cred_res;
|
||
res_cred += cred_res;
|
||
}
|
||
}
|
||
|
||
if (month == 13)
|
||
{
|
||
// totalizza volumi affari e calcola nuovo prorata per tutte le attivit<69>
|
||
FOR_EACH_TOKEN(atts, tmpatt)
|
||
{
|
||
const TString8 att = tmpatt;
|
||
const int tipoatt = att.right(1)[0] - '0';
|
||
if (tipoatt == 1) // su PLA l'attivita' e' sempre 1
|
||
{
|
||
if (!look_pla(att))
|
||
continue;
|
||
|
||
const real vf1 = _pla->get("R14");
|
||
const real vf2 = _pla->get("S1");
|
||
const real iaq = _pla->get("R11"); // IVA acquisti
|
||
const real ppg = _pla->get("R12"); // pro-rata pagato
|
||
|
||
vol_aff_1 += vf1;
|
||
vol_aff_2 += vf2;
|
||
vol_aff_l += _pla->get_real("R0"); // volume affari lordo
|
||
|
||
real es_c1 = _pla->get_real("R1"); // Tipo esenzione B1
|
||
real es_c2 = _pla->get_real("R2");
|
||
real es_c3 = _pla->get_real("R3");
|
||
real es_c1a = _pla->get_real("R15");
|
||
real es_c3_am = _pla->get_real("R16");
|
||
real es_c1a_am = _pla->get_real("R17");
|
||
real csamm = _pla->get_real("R4");
|
||
real ven_rev = _pla->get_real("R18");
|
||
real prorata;
|
||
real conguaglio;
|
||
real topay;
|
||
const real ris = vf1 + vf2; // gia' esclusi: NS, B3, cess. amm
|
||
|
||
// calcola nuovo prorata dal 1998 per ogni attivita' (miste: 1+2)
|
||
const real rsa = ris - (es_c1a-es_c1a_am) - (es_c3-es_c3_am) - ven_rev;
|
||
const real rsn = rsa - es_c1;
|
||
if (!rsa.is_zero())
|
||
{
|
||
prorata = CENTO - (rsn * CENTO / rsa); // Percentuale di indetraibilit<69>: reciproco della detraibilit<69>
|
||
prorata.round(0);
|
||
}
|
||
|
||
// calcolo conguaglio -- se positivo e' a debito
|
||
if (prorata > ZERO)
|
||
{
|
||
topay = (iaq + ppg) * prorata / CENTO;
|
||
round_imposta(topay);
|
||
}
|
||
else
|
||
prorata = ZERO;
|
||
|
||
conguaglio = topay - ppg;
|
||
round_imposta(conguaglio);
|
||
|
||
_pla->put("R9", conguaglio);
|
||
_pla->put("R10", prorata);
|
||
|
||
// Prorata delle mie brame...
|
||
// Chi e' il piu' sfatto del reame?
|
||
// Non va considerata la differenza tra topay e pro-rata pagato
|
||
// ma semplicemente topay. (Vedi cg4304.cpp in set_annual())
|
||
//tot_cong += conguaglio;
|
||
tot_cong += topay;
|
||
_pla->rewrite();
|
||
|
||
// scrivi nuovo prorata in tabella anno successivo
|
||
const TString4 yr = _year;
|
||
_year.format("%d", atoi(_year) + 1);
|
||
look_pla(att, true);
|
||
_pla->put("R8", prorata);
|
||
_pla->rewrite();
|
||
TRectype lia = get_lia(0l, true);
|
||
|
||
if (lia.not_empty())
|
||
{
|
||
real cc = cred_cost;
|
||
round_imposta(cc);
|
||
lia.put("R5", cc);
|
||
put_lia(lia);
|
||
}
|
||
_year = yr;
|
||
|
||
// Aggiusta DiffIncIVAAcq sul record della 13ma che non poteva ancora sapere il prorata definitivo!
|
||
if (!prorata.is_zero() && look_plm(13, att))
|
||
{
|
||
const real old_r33 = _plm->get("R33");
|
||
real new_r33 = old_r33 * prorata / CENTO;
|
||
round_imposta(new_r33);
|
||
_plm->put("R33", new_r33);
|
||
_plm->rewrite();
|
||
|
||
fdiffinc_iva_acq = fdiffinc_iva_acq - old_r33 + new_r33;
|
||
}
|
||
}
|
||
}
|
||
|
||
TRectype lia = get_lia();
|
||
|
||
lia.put("R1", vol_aff_l);
|
||
lia.put("R2", vol_aff_1);
|
||
lia.put("R3", vol_aff_2);
|
||
put_lia(lia);
|
||
}
|
||
|
||
// comprende anche il conguaglio prorata
|
||
risultato += tot_cong;
|
||
|
||
// Nuovo prorata dal 1998, congloba il conguaglio pro-rata nell'IVA ammessa in detrazione
|
||
if (tot_cong.sign() > 0)
|
||
{
|
||
iva_acq -= tot_cong;
|
||
res_cred -= tot_cong;
|
||
}
|
||
else
|
||
{
|
||
iva_acq += abs(tot_cong);
|
||
res_cred += abs(tot_cong);
|
||
}
|
||
|
||
TRectype lim = get_lim(month+deltam, true);
|
||
const TString16 codtab = lim.get("CODTAB");
|
||
|
||
/*
|
||
// azzeriamo tutto (tranne r1, r5, s1, s0, s7)
|
||
const real rimborso = _lim->get("R1");
|
||
const real r5 = _lim->get("R5"); // Rettifiche
|
||
const real credito_utilizzato_f24 = _lim->get("R16");
|
||
const real r17 = _lim->get("R17");
|
||
const real r18 = _lim->get("R18");
|
||
const real r19 = _lim->get("R19");
|
||
const real credito_autorizzato_f24 = _lim->get_real("R20");
|
||
const TDate data_autorizzazione = _lim->get_date("D1");
|
||
const TString s7 = _lim->get("S7");
|
||
const TString s0 = _lim->get("S0"); // Descrizioni rettifiche
|
||
const TString s1 = _lim->get("S1");
|
||
const TString s2 = _lim->get("S2");
|
||
const TString s3 = _lim->get("S3");
|
||
const bool wasb0 = _lim->get_bool("B0");
|
||
const bool wasb1 = _lim->get_bool("B1");
|
||
|
||
_lim->zero();
|
||
_lim->put("CODTAB", codtab);
|
||
_lim->put("R1", rimborso);
|
||
_lim->put("R5", r5); // Rettifiche
|
||
_lim->put("R16", credito_utilizzato_f24);
|
||
_lim->put("R17", r17);
|
||
_lim->put("R18", r18);
|
||
_lim->put("R19", r19);
|
||
_lim->put("R20", credito_autorizzato_f24);
|
||
_lim->put("D1", data_autorizzazione);
|
||
_lim->put("S0", s0);
|
||
_lim->put("S1", s1);
|
||
_lim->put("S2", s2);
|
||
_lim->put("S3", s3);
|
||
_lim->put("S7", s7);
|
||
_lim->put("B0", wasb0 ? "X" : "");
|
||
_lim->put("B1", wasb1 ? "X" : ""); */
|
||
|
||
|
||
/*
|
||
* versamenti effettuati: si conteggiano in R0,
|
||
* sono > 0 solo se andavano calcolati (vedi sopra)
|
||
*/
|
||
risultato -= versamenti + vers_int;
|
||
/*
|
||
* acconto dicembre se previsto
|
||
*/
|
||
if (((month+deltam) >= 12 && _freqviva == "M") || // solo freq. M puo' essere differita
|
||
(month == 12 && _isbenzinaro && _gest4) ||
|
||
(month >= (atoi(_year) >= 2000 ? 12 : 13) && _freqviva == "T"))
|
||
{
|
||
acc_dec = versamenti_IVA(12,"7");
|
||
risultato -= acc_dec;
|
||
res_cred += acc_dec;
|
||
}
|
||
|
||
// in annuale si arrotondera' a 1000 in stampa
|
||
// se no il conguaglio prorata fa casino
|
||
round_al_centesimo(risultato);
|
||
|
||
lim.put("R0", risultato);
|
||
lim.put("R2", cred_cost);
|
||
lim.put("R3", deb_mens);
|
||
lim.put("R4", perc_r);
|
||
|
||
if (almeno_una_normale)
|
||
lim.put("R6", detrazioni);
|
||
else // per evitare sbagli nei ricalcoli esterni
|
||
lim.zero("R6");
|
||
|
||
if (month == 13 || differita)
|
||
{
|
||
// Arrotonda totali in quanto possono avere un arrotondamento diverso dal mensile
|
||
TIva_round ir;
|
||
|
||
ir.round(rimborsi);
|
||
ir.round(rettifiche);
|
||
ir.round(variazioni_imposta);
|
||
ir.round(imposta_non_versata);
|
||
ir.round(crediti_speciali);
|
||
|
||
// scrivi totali rettifiche e rimborsi
|
||
// nella finale oppure se copiati da
|
||
// anno precedente
|
||
lim.put("R1",rimborsi);
|
||
lim.put("R5",rettifiche);
|
||
|
||
lim.put("R17", variazioni_imposta);
|
||
lim.put("R18", imposta_non_versata);
|
||
lim.put("R19", crediti_speciali);
|
||
}
|
||
|
||
/*
|
||
* Interessi dovuti solo da trimestrali in periodica,
|
||
* Era anche non benzinari, smentito da Cinzia (MI0853);
|
||
* Ora gestito esplicitamente nei parametri ditta, forzato
|
||
* false per ditte mensili e liq. annuale
|
||
* Ulteriormente smentito e rettificato
|
||
*/
|
||
bool true_trim = (month == 3 || month == 6 || month == 9);
|
||
if (_isintr && ( true_trim || (month == 12 && _isbenzinaro && _gest4)
|
||
|| (month == 13 && !(_isbenzinaro && _gest4)) ))
|
||
{
|
||
const real interesse = interesse_trimestrale(_month);
|
||
const real r = risultato - imposta_non_versata; // CM 26-09-2000
|
||
real ivi = r.sign() > 0 ? (r * interesse / CENTO) : ZERO;
|
||
round_al_centesimo(ivi);
|
||
lim.put("R14", ivi);
|
||
}
|
||
|
||
//questo serve anche per la visualizzazione e per l'estrazione deleghe
|
||
if (_isintr && ( true_trim || (month == 12 && _isbenzinaro && _gest4)
|
||
|| (month == 13 && !(_isbenzinaro && _gest4)) ))
|
||
lim.put("R10", interesse_trimestrale(_month));
|
||
|
||
lim.put("R7", tot_cong); // totale conguaglio su tutte le attivita'
|
||
lim.put("R8", versamenti);
|
||
lim.put("R9", vers_int);
|
||
lim.put("R11", acc_dec);
|
||
lim.put("R12", res_cred);
|
||
lim.put("R13", res_debt);
|
||
|
||
lim.put("R26", fdiff_imp); // Imponibile IVA diff Fatture di vendita
|
||
lim.put("R27", fdiff_iva); // Imposta IVA diff Fatture di vendita
|
||
lim.put("R28", fdiffinc_imp); // Imponibile IVA diff Incassi
|
||
lim.put("R29", fdiffinc_iva); // Imposta IVA diff Incassi
|
||
|
||
lim.put("R30", fdiff_imp_acq); // Imponibile IVA diff Fatture di acquisto
|
||
lim.put("R31", fdiff_iva_acq); // Imposta IVA diff Fatture di acquisto
|
||
lim.put("R32", fdiffinc_imp_acq); // Imponibile IVA diff Pagamenti
|
||
lim.put("R33", fdiffinc_iva_acq); // Imposta IVA diff Pagamenti
|
||
|
||
look_lam(month+deltam, true);
|
||
_lam->put("R0", iva_vend);
|
||
_lam->put("R1", iva_acq);
|
||
_lam->put("R2", cred_prec);
|
||
_lam->put("R3", debt_precd);
|
||
|
||
if (!_recalc_only && _recalc != never)
|
||
lim.put("B0","X");
|
||
|
||
if (_recalc_only)
|
||
lim.put("B1", "X");
|
||
|
||
/* Cazzata galattica: vedi sopra
|
||
if (wasdifferita) _isdifferita = true;
|
||
*/
|
||
|
||
// AWFUL! se siamo in annuale, occorre arrotondare alle 1000 lire
|
||
// schiaffo tutto il codice nell'IF che segue, e se lo si vuole togliere
|
||
// non si fara' che scancellare tutto il blocco
|
||
|
||
//const bool after2000 = atoi(_year) >= 2000; // Nel 2014 mi pare una formalit<69>
|
||
//if (month == 13 || after2000)
|
||
{
|
||
// molto codice duplicato, ma ne val la pena (vedi sopra)
|
||
round_imposta(iva_vend);
|
||
round_imposta(iva_acq);
|
||
round_imposta(detrazioni);
|
||
round_imposta(versamenti);
|
||
round_imposta(vers_int);
|
||
round_imposta(rimborsi);
|
||
round_imposta(rettifiche);
|
||
round_imposta(deb_mens);
|
||
round_imposta(cred_prec);
|
||
round_imposta(cred_trasf);
|
||
round_imposta(tot_cong);
|
||
round_imposta(acc_dec);
|
||
round_imposta(debt_precd);
|
||
round_imposta(variazioni_imposta);
|
||
round_imposta(imposta_non_versata);
|
||
round_imposta(credito_utilizzato_iva);
|
||
round_imposta(crediti_speciali);
|
||
round_imposta(fdiff_iva);
|
||
round_imposta(fdiffinc_iva);
|
||
round_imposta(fdiff_iva_acq);
|
||
round_imposta(fdiffinc_iva_acq);
|
||
|
||
res_cred = iva_acq + versamenti + vers_int + cred_prec - cred_trasf + acc_dec + credito_utilizzato_iva + crediti_speciali + fdiffinc_iva_acq;
|
||
res_debt = iva_vend + rimborsi + debt_precd + imposta_non_versata + fdiffinc_iva;
|
||
|
||
/* Obsolescenza pura nel 2014
|
||
if (atoi(_year) < 1998) // Non vale piu' dal 1998 in poi; iva_acq e' gia' ok e cosi' res_cred.
|
||
{
|
||
if (tot_cong.sign() > 0)
|
||
res_debt += tot_cong;
|
||
else
|
||
res_cred -= tot_cong;
|
||
}
|
||
*/
|
||
|
||
if (rettifiche.sign() >= 0)
|
||
res_debt += rettifiche;
|
||
else
|
||
res_cred -= rettifiche;
|
||
|
||
if (variazioni_imposta.sign() >= 0)
|
||
res_debt += variazioni_imposta;
|
||
else
|
||
res_cred -= variazioni_imposta;
|
||
|
||
if (almeno_una_normale)
|
||
res_cred += detrazioni;
|
||
|
||
risultato = res_debt - res_cred;
|
||
|
||
// tut ricalcule', riscrivem
|
||
_lam->put("R0", iva_vend);
|
||
_lam->put("R1", iva_acq);
|
||
_lam->put("R2", cred_prec);
|
||
_lam->put("R3", debt_precd);
|
||
_lam->put("R4", cred_trasf);
|
||
|
||
lim.put("R0", risultato);
|
||
lim.put("R1", rimborsi);
|
||
lim.put("R2", cred_cost);
|
||
lim.put("R3", deb_mens);
|
||
lim.put("R5", rettifiche);
|
||
lim.put("R6", detrazioni);
|
||
lim.put("R7", tot_cong);
|
||
lim.put("R8", versamenti);
|
||
lim.put("R9", vers_int);
|
||
lim.put("R11", acc_dec);
|
||
lim.put("R12", res_cred);
|
||
lim.put("R13", res_debt);
|
||
|
||
real ivi = lim.get("R14"); round_imposta(ivi);
|
||
lim.put("R14", ivi);
|
||
lim.put("R15", credito_utilizzato_iva);
|
||
|
||
if (month == 13)
|
||
{
|
||
// Riporta eventuale credito nella tabella parametri liquidazione dell'anno successivo
|
||
real riporto = credito_utilizzabile - risultato;
|
||
|
||
if (riporto < ZERO)
|
||
riporto = ZERO;
|
||
|
||
const int anno_prossimo = atoi(_year) + 1;
|
||
TRectype lia = get_lia(0l, true, anno_prossimo);
|
||
|
||
lia.put("R0", riporto);
|
||
put_lia(lia);
|
||
}
|
||
lim.put("R26", fdiff_imp);
|
||
lim.put("R27", fdiff_iva);
|
||
lim.put("R28", fdiffinc_imp);
|
||
lim.put("R29", fdiffinc_iva);
|
||
lim.put("R30", fdiff_imp_acq);
|
||
lim.put("R31", fdiff_iva_acq);
|
||
lim.put("R32", fdiffinc_imp_acq);
|
||
lim.put("R33", fdiffinc_iva_acq);
|
||
// ciapa
|
||
}
|
||
put_lim(lim);
|
||
_lam->rewrite();
|
||
}
|
||
|
||
void TLiquidazione_app::recalc_annual(const char* att)
|
||
{
|
||
// viene chiamata 2 volte per le att. miste; PLA e' stata
|
||
// azzerata dove serve da update_firm se siamo all'annuale
|
||
real es_c1 = 0.0;
|
||
real es_c2 = 0.0;
|
||
real es_c3 = 0.0;
|
||
real es_c1a = 0.0;
|
||
real es_c3_am = 0.0;
|
||
real es_c1a_am= 0.0;
|
||
real cess_amm = 0.0;
|
||
real vendite = 0.0;
|
||
real pro_pag = 0.0;
|
||
real iva_acq = 0.0;
|
||
real ven_lrd = 0.0;
|
||
real volaff1 = 0.0;
|
||
real volaff2 = 0.0;
|
||
real ven_rev = 0.0;
|
||
|
||
TString4 codiva,reg,tiva;
|
||
TToken_string va7("",'!');
|
||
|
||
const TString8 aaa(att);
|
||
const int tipoatt = aaa.right(1)[0] - '0';
|
||
CHECKD(tipoatt > 0, "Tipo att non valido ", tipoatt);
|
||
|
||
look_pla(aaa);
|
||
volaff1 = _pla->get_real("R14");
|
||
volaff2 = (const char*)_pla->get("S1");
|
||
vendite = _pla->get_real("R0");
|
||
es_c1 = _pla->get_real("R1");
|
||
es_c2 = _pla->get_real("R2");
|
||
es_c3 = _pla->get_real("R3");
|
||
es_c1a = _pla->get_real("R15");
|
||
es_c3_am = _pla->get_real("R16");
|
||
es_c1a_am= _pla->get_real("R17");
|
||
cess_amm = _pla->get_real("R4");
|
||
pro_pag = _pla->get_real("R12");
|
||
iva_acq = _pla->get_real("R11");
|
||
ven_rev = _pla->get_real("R18");
|
||
|
||
// Per avere un risultato corretto, si deve totalizzare PIM->R3 per codice iva
|
||
// e quindi effettuare lo scorporo dell'imponibile e aggiungere al relativo volume d'affari
|
||
TAssoc_array corr_ann;
|
||
_CorrItem *cc;
|
||
bool is_key;
|
||
|
||
_pim->zero(); _pim->put("CODTAB", _year); // 24-02-2014 Partiamo dall'anno giusto
|
||
for (int err = _pim->read(_isgteq); err == NOERR; err = _pim->next())
|
||
{
|
||
if (_year != *_pim_anno || _month != atoi(*_pim_mese)) // In questo caso _month vale sempre 13
|
||
continue;
|
||
|
||
const int tipocr = atoi(*_pim_tipocr);
|
||
codiva = *_pim_codiva;
|
||
reg = *_pim_codreg;
|
||
look_iva(codiva); look_reg(reg);
|
||
tiva = _iva->get("S1");
|
||
const tiporeg treg = (tiporeg)_reg->get_long("I0");
|
||
const bool corrisp = _reg->get_bool("B0");
|
||
const tipo_sospensione simp = _reg->get_bool("B1") ? (tipo_sospensione) _reg->get_int("I9") : nessuna;
|
||
|
||
if ( // ESCLUSI:
|
||
strcmp(att,*_pim_codatt) != 0 ||
|
||
treg != vendita || // non vendite
|
||
tipocr == 4 || // cessioni beni ammortizzabili
|
||
tiva == "NS" || // non soggetti
|
||
simp == normale ||
|
||
simp == liquidazione) // sospensione di imposta
|
||
continue;
|
||
|
||
real imp_ifs = _pim->get("R0"); // Imponibile
|
||
real imp_af = _pim->get("R7"); // Autofatture
|
||
va7 = _pim->get("S0");
|
||
real imp_va7 = va7.get(0); // operazioni VA7
|
||
imp_ifs -= imp_af + imp_va7; // Toglie le autofatture e le op. VA7
|
||
|
||
if (corrisp)
|
||
{
|
||
imp_ifs += _pim->get_real("R5"); // Se corrisp. aggiunge le FS
|
||
is_key = corr_ann.is_key(codiva);
|
||
if (!is_key) // Aggiunge se non esiste
|
||
corr_ann.add(codiva, (_CorrItem*) new _CorrItem,is_key);
|
||
_CorrItem& ca = (_CorrItem&) corr_ann[codiva];
|
||
ca._totale += _pim->get_real("R3");
|
||
if (!is_key) // se non c'e' lo aggiunge
|
||
ca._aliquota = _iva->get_real("R0")/CENTO; // Se <20> nuovo setta l'aliquota
|
||
}
|
||
if (tipoatt == 1)
|
||
volaff1 += imp_ifs;
|
||
else
|
||
volaff2 += imp_ifs;
|
||
}
|
||
|
||
// Ora si scorporano i corrispettivi raggruppati per codice IVA e si totalizzano gli imponibili
|
||
// calcolati, da aggiungere poi a volaff1 o volaff2
|
||
real imp,iva;
|
||
for (cc = (_CorrItem *)corr_ann.first_item(); cc != NULL; cc = (_CorrItem *)corr_ann.succ_item())
|
||
{
|
||
lordo2netto(cc->_totale,imp,iva,cc->_aliquota);
|
||
if (tipoatt == 1)
|
||
volaff1 += imp;
|
||
else
|
||
volaff2 += imp;
|
||
}
|
||
|
||
// calcola esenti, cessioni, lordo vendite, prorata pagato
|
||
// e IVA acquisti dai plm/ptm/pum/pam/pom
|
||
|
||
for (int i = 1; i <= 12; i++)
|
||
{
|
||
if (!look_plm(i,aaa))
|
||
continue;
|
||
pro_pag += _plm->get_real("R2"); // Can't do anyway else...
|
||
}
|
||
|
||
// Modifiche per PIM13
|
||
if (look_plm(13,aaa))
|
||
{
|
||
vendite += _pam->get_real("R1");
|
||
iva_acq += _plm->get_real("R1");
|
||
es_c1 += _pum->get_real("R4");
|
||
es_c2 += _pum->get_real("R5");
|
||
es_c3 += _pum->get_real("R6");
|
||
es_c1a += _pum->get_real("R13");
|
||
es_c3_am += _pum->get_real("S4");
|
||
es_c1a_am += _pum->get_real("S5");
|
||
cess_amm += _pum->get_real("R0");
|
||
ven_rev += _pum->get_real("R28");
|
||
|
||
// Nota:
|
||
// l'iva acquisti del mese 13 memorizzata in PLM->R1, e' si' la sommatoria
|
||
// di tutte le imposte relative agli acquisti di tutti i mesi, ma andrebbe sottratto il
|
||
// totale prorata pagato (pro_pag), reperibile dai mesi precedenti (PLM->R2)
|
||
//real iv = _plm->get_real("R1"); // Iva acquisti annuale
|
||
//iv -= pro_pag;
|
||
iva_acq -= pro_pag; // Si sottraggano i prorata pagati
|
||
//_plm->put("R1",iva_acq); // Si riscriva il tutto
|
||
//_plm->rewrite();
|
||
}
|
||
|
||
_pla->put("R0", vendite);
|
||
_pla->put("R1", es_c1);
|
||
_pla->put("R2", es_c2);
|
||
_pla->put("R3", es_c3);
|
||
_pla->put("R15", es_c1a);
|
||
_pla->put("R16", es_c3_am);
|
||
_pla->put("R17", es_c1a_am);
|
||
_pla->put("R4", cess_amm);
|
||
_pla->put("R11", iva_acq);
|
||
_pla->put("R12", pro_pag);
|
||
_pla->put("R14", volaff1);
|
||
_pla->put("S1", volaff2.string());
|
||
_pla->put("R18", ven_rev);
|
||
_pla->rewrite();
|
||
}
|
||
|