From 314f22372df197727d8156ad7add048e7c10ba5f Mon Sep 17 00:00:00 2001 From: angelo Date: Wed, 13 Nov 1996 10:55:21 +0000 Subject: [PATCH] Aggiunto trasferimento per IVA11. Aggiunto caching codici iva e registri. git-svn-id: svn://10.65.10.50/trunk@3896 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg4300.cpp | 28 +++ cg/cg4300.h | 44 ++++- cg/cg4301.cpp | 539 ++++++++++++++++++++++++++++++++++++++++++++++++-- cg/cg4302.cpp | 34 +++- 4 files changed, 621 insertions(+), 24 deletions(-) diff --git a/cg/cg4300.cpp b/cg/cg4300.cpp index 52be9dabe..8d1e7e933 100755 --- a/cg/cg4300.cpp +++ b/cg/cg4300.cpp @@ -16,6 +16,26 @@ #include + +// Methods of _BolgArray +bool _BolgArray::add(const real& val, const char* fld_name, int num_file) +{ + _BolgItem bolg; + const bool is_key = TAssoc_array::is_key(fld_name); + _BolgItem& bi = is_key ? (_BolgItem&)find(fld_name) : bolg; + bi.value() += val; + if (num_file != LF_TAB1100A) bi.file() = num_file; + return TAssoc_array::add(fld_name,bi,is_key); +} + +bool _BolgArray::sub(const real& val, const char* fld_name, int num_file) +{ + const real v1 = val * (-1.0); + return add(v1,fld_name, num_file); +} + + +// Methods of application! real TLiquidazione_app::CENTO(100.0); inline TLiquidazione_app& app() @@ -69,6 +89,11 @@ bool TLiquidazione_app::user_create() "@1|Cod.@5R|Ragione Sociale@50|Vers."); _n_ditte = 0l; + // Caro tab11, ricordati che un giorno sarai un file unico! + _tab11 = new TRelation(LF_TAB1100A); + _tab11->add(LF_TAB1100B,"TADITT=TADITT|TACATT=TACATT"); + _tab11->write_enable(LF_TAB1100B); // Senno' col fischio che scrive i records + // prevediamo la data che usera'; se calcola la liq. di un altro anno // si fottera' la frequenza versamenti @@ -76,6 +101,8 @@ bool TLiquidazione_app::user_create() { TDate oggi(TODAY); _year.format("%d",oggi.year()); + TConfig conf(CONFIG_STUDIO); + _sind11 = conf.get_bool("Sind11"); } else // parse messaggio { @@ -346,6 +373,7 @@ bool TLiquidazione_app::user_destroy() delete _pla; delete _del; + delete _tab11; delete _nditte; delete _rel; delete _cur; diff --git a/cg/cg4300.h b/cg/cg4300.h index 0dd232f62..de0559260 100755 --- a/cg/cg4300.h +++ b/cg/cg4300.h @@ -174,6 +174,32 @@ public: virtual ~_ErrItem() {} }; +// _BolgItem e' una contrazione di Bolgia, serve per memorizzare gli elementi +// da trasferire su tab1100 +class _BolgItem : public TObject +{ + real _value; + int _file; +public: + virtual TObject* dup() const { return new _BolgItem(*this); } + real& value() { return _value; } + int& file() { return _file; } + void zero() { _value = 0.0; _file = LF_TAB1100A; } + _BolgItem() { _file = LF_TAB1100A; } + virtual ~_BolgItem() {} +}; + +// Definisco solo i metodi add e sub, per aggiungere elementi _BolgItem +// per il resto e' un normalissimo TAssoc_array +class _BolgArray : public TAssoc_array +{ +public: + bool add(const real& val, const char* fld_name, int num_file = LF_TAB1100A); + bool sub(const real& val, const char* fld_name, int num_file = LF_TAB1100A); + _BolgArray() {} + virtual ~_BolgArray() {} +}; + // ------------------------------------------------------------------------ // Application // ------------------------------------------------------------------------ @@ -216,6 +242,7 @@ class TLiquidazione_app : public TPrint_application bool _stampa_vers; // stampa trafiletto versamento; bool _stampa_acc; // stampa trafiletto saldo/acconto bool _riepilogo; // stampa riepilogo sul registro + bool _sind11; // somma imposte non detraibili in trasferimento IVA11 (da configurazione dati studio) tbc _basecalc; // tipo base di calcolo acconto TString _freqviva; // frequenza versamenti (M|T) long _n_ditte; // numero ditte @@ -229,7 +256,13 @@ class TLiquidazione_app : public TPrint_application TArray _vent_arr; // tabella acquisti per ventilazione TArray _descr_arr; // things to be printed TArray _errors; // errors to notify - + + + TAssoc_array _codiva_arr; // cache dei codici IVA. + TAssoc_array _reg_arr; // cache dei registri. + _BolgArray _iva11_arr; // array contenente le informazioni da trasferire. + // La chiave di ordinamento e' sul nome del campo. + // totali vari per attivita' real _p8, _p8b, _p9; // totali plafond real _prorata; // percentuale indetraibilita' (prorata) @@ -246,6 +279,7 @@ class TLiquidazione_app : public TPrint_application TCursor* _cur; // files, tables + TRelation* _tab11; // un giorno tab1100a e tab1100b sarano un unico file! TRelation* _nditte; TLocalisamfile* _mov; TLocalisamfile* _rmoviva; @@ -368,6 +402,14 @@ public: void recalc_annual (const char* codatt); _DescrItem* recalc_rimborso(int month, const char* codatts, bool print); + // Le funzioni che hanno come prefisso iva11 sono per creare il file di trasferimento per IVA11 + // Viene chiamata quando vengono scorsi tutti i movimenti, settando gli elementi di _iva11_arr. + void iva11_set_arr (const TString& codatt); + // Scorre tutti i PIM della ditta, per completare _iva11_arr prima di chiamare write_IVA11() + void iva11_set_arr_pim (const TString& codatt); + // Scrive per la ditta/attivita' corrente, i dati relativi al trasferimento IVA11 + void iva11_write (); + // ricalcolo liquidazioni dai progressivi mensili void write_liq (int month, const char* atts); diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp index 3ae5fc0bc..2b4471ec9 100755 --- a/cg/cg4301.cpp +++ b/cg/cg4301.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include "cg4300.h" // -------------------- QUI comincia l'avventura -------------------------- @@ -311,10 +314,19 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) atts.add(cattiv); cattivs.add(cattiv); } // for tipoatt - + // se attivita' 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 + // Scrive le informazioni per la ditta/attivita' corrente + if (_is_interactive && month == 13) + { + iva11_set_arr_pim(codatt); // scorre tutti i maledetti PIM di questa ditta per completare _iva11_arr + iva11_write(); // scrive su tab1100 at last. + } } while (_nditte->next_match(LF_ATTIV)); @@ -586,10 +598,8 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) TString codiva = _iva->get("CODTAB"); TString tipoiva = _iva->get("S1"); TString riga11_v = _iva->get("S0"); - //TString tipoes_v = _iva->get("S2"); - //TString tipoes_a = _iva->get("S9"); - int tipoes_v = (int)_iva->get_long("I3"); - int tipoes_a = (int)_iva->get_long("I4"); + TString tipoes_v = _iva->get("S2"); + TString tipoes_a = _iva->get("S9"); int tipoagr = atoi(_iva->get("S4")); int tipoag = atoi(_iva->get("S5")); int tipopla = atoi(_iva->get("S3")); @@ -641,6 +651,10 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) */ if (!(okc && (cond1 || cond2)) && !fattrit) continue; + + // Filling dell'array per IVA11 + if (_is_interactive) + iva11_set_arr(trueatt); } if (noninc) // non incassati: non devono entrare in nessun altro calcolo @@ -764,23 +778,17 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) { if (tipomov == vendita) { - switch(tipoes_v) - { - case 1: + if (tipoes_v == "B1") esenti_b1 += imponibile; - break; - case 2: + else if (tipoes_v == "B2") esenti_b2 += imponibile; - break; - case 3: + else if (tipoes_v == "B3") esenti_b3 += imponibile; - break; - } // se e' il caso sommare esenti per rimborso if (isrimbinfr) esni_rimb += imponibile; } - else if (tipoes_a == 14) + else if (tipoes_a == "14") esenti_b14 += imponibile; } @@ -1316,6 +1324,507 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) _pom->rewrite(); } +void TLiquidazione_app::iva11_set_arr(const TString& codatt) +// viene chiamata quando vengonon scorsi i movimenti del mese, settando gran parte degli elementi di _iva11_arr. +{ + const TString16 tipodoc = _mov->get("TIPODOC"); + const real imponibile = _rmoviva->get_real("IMPONIBILE"); + const real imposta = _rmoviva->get_real("IMPOSTA"); + const bool intra = _rmoviva->get_bool("INTRA"); + const int tipocr = _rmoviva->get_int("TIPOCR"); + const int tipodet = _rmoviva->get_int("TIPODET"); + const TString codiva = _iva->get("CODTAB"); + const TString tipoiva = _iva->get("S1"); + const real ali = _iva->get_real("R0"); + const TString tipoes_v = _iva->get("S2"); + const TString tipoes_a = _iva->get("S9"); + const int tipoagr = atoi(_iva->get("S4")); + const TRectype& rcs = _cur->curr(LF_CAUSALI); + const bool autofattura = rcs.get_bool("AUTOFATTURA"); + const bool sosp_imp = _reg->get_bool("B1"); + tiporeg tipomov = (tiporeg)_reg->get_long("I0"); + const bool is_vendita = tipomov == vendita; + const bool is_acquisto = tipomov == acquisto; + + // TAB11_RQA34 ovvero "RQA34" non viene trasferito! + // Sebbene per motivi di pieta' viene comunque lasciato nel tracciato record (esigenze PRASSI) + if (codiva.empty()) return; + + if (is_acquisto) + { + if (_isagricolo && tipodet == 0) + { + if (tipoagr == 2) + { + if (tipocr == 2 || tipocr == 3 || tipocr == 8) + { + _iva11_arr.sub(imponibile,TAB11_G30I,LF_TAB1100B); + _iva11_arr.sub(imposta,TAB11_G30V,LF_TAB1100B); + } + else + { + _iva11_arr.add(imponibile,TAB11_G30I,LF_TAB1100B); + _iva11_arr.add(imposta,TAB11_G30V,LF_TAB1100B); + } + } + else if (tipoagr == 3 && tipocr !=2 && tipocr != 3 && tipocr != 8) + { + _iva11_arr.add(imponibile,TAB11_G31I,LF_TAB1100B); + _iva11_arr.add(imposta,TAB11_G31V,LF_TAB1100B); + } + } + + if (!sosp_imp && tipodet == 0 && (tipocr == 2 || tipocr == 8)) + { + _iva11_arr.add(imposta,TAB11_R6,LF_TAB1100B); + } + + if (!sosp_imp && tipodet == 9) + if (tipodoc == "BD") + { + _iva11_arr.add(imponibile,TAB11_F76); + if (_sind11) + _iva11_arr.add(imposta,TAB11_F76); + } + else + { // Compila prima i campi FC1nn ed FC2nn, poi i campi SBFnn ed SBInn + if (ali == 2.00) + { + _iva11_arr.add(imponibile,TAB11_FC101); + _iva11_arr.add(imposta,TAB11_FC201); + } + else if (ali == 4.00) + { + _iva11_arr.add(imponibile,TAB11_FC102); + _iva11_arr.add(imposta,TAB11_FC202); + } + else if (ali == 8.50) + { + _iva11_arr.add(imponibile,TAB11_FC103); + _iva11_arr.add(imposta,TAB11_FC203); + } + else if (ali == 9.00) + { + _iva11_arr.add(imponibile,TAB11_FC104); + _iva11_arr.add(imposta,TAB11_FC204); + } + else if (ali == 10.00) + { + _iva11_arr.add(imponibile,TAB11_FC105); + _iva11_arr.add(imposta,TAB11_FC205); + } + else if (ali == 13.00) + { + _iva11_arr.add(imponibile,TAB11_FC106); + _iva11_arr.add(imposta,TAB11_FC206); + } + else if (ali == 16.00) + { + _iva11_arr.add(imponibile,TAB11_FC107); + _iva11_arr.add(imposta,TAB11_FC207); + } + else if (ali == 19.00) + { + _iva11_arr.add(imponibile,TAB11_FC108); + _iva11_arr.add(imposta,TAB11_FC208); + } + + if (tipoes_a == "01") + _iva11_arr.add(imponibile,TAB11_FC109); + else if (tipoes_a == "12") + _iva11_arr.add(imponibile,TAB11_FC110); + else if (tipoes_a == "13") + _iva11_arr.add(imponibile,TAB11_FC111); + else if (tipoes_a == "14") + _iva11_arr.add(imponibile,TAB11_FC112); + else if (tipoes_a == "15") + _iva11_arr.add(imponibile,TAB11_FC113); + + _iva11_arr.add(imponibile,TAB11_FC114); + if (_sind11) + _iva11_arr.add(imposta,TAB11_FC114); + + if (intra) // Compila i campi SBFnn + { + if (ali == 4.00) + { + _iva11_arr.add(imponibile,TAB11_SBF01); + _iva11_arr.add(imposta,TAB11_SBI01); + } + else if (ali == 9.00) + { + _iva11_arr.add(imponibile,TAB11_SBF02); + _iva11_arr.add(imposta,TAB11_SBI02); + } + else if (ali == 10.00) + { + _iva11_arr.add(imponibile,TAB11_SBF03); + _iva11_arr.add(imposta,TAB11_SBI03); + } + else if (ali == 13.00) + { + _iva11_arr.add(imponibile,TAB11_SBF04); + _iva11_arr.add(imposta,TAB11_SBI04); + } + else if (ali == 16.00) + { + _iva11_arr.add(imponibile,TAB11_SBF05); + _iva11_arr.add(imposta,TAB11_SBI05); + } + else if (ali == 19.00) + { + _iva11_arr.add(imponibile,TAB11_SBF06); + _iva11_arr.add(imposta,TAB11_SBI06); + } + + if (tipoes_a == "01") + _iva11_arr.add(imponibile,TAB11_SBF07); + else if (tipoes_a == "12") + _iva11_arr.add(imponibile,TAB11_SBF08); + else if (tipoes_a == "13") + _iva11_arr.add(imponibile,TAB11_SBF09); + else if (tipoes_a == "14") + _iva11_arr.add(imponibile,TAB11_SBF10); + + _iva11_arr.add(imponibile,TAB11_SBF11); + if (_sind11) + _iva11_arr.add(imposta,TAB11_SBF11); + } + } + } + + if (is_vendita) + { + if (!autofattura && tipoiva != "NS") + if (tipodoc == "AF") + { + _iva11_arr.add(imponibile,TAB11_A35); + _iva11_arr.add(imposta,TAB11_L2,LF_TAB1100B); + } + else if (rcs.get_bool("VALINTRA") && !intra) + { + _iva11_arr.add(imponibile,TAB11_A35BIS); + _iva11_arr.add(imposta,TAB11_L2BIS,LF_TAB1100B); + } + + if (!autofattura && !sosp_imp && intra && tipoes_v == "24B") + _iva11_arr.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) + { + _iva11_arr.add(imponibile,TAB11_AGME01,LF_TAB1100B); + _iva11_arr.add(imposta,TAB11_AGVE01,LF_TAB1100B); + } + if (intra && t1_3) + { + _iva11_arr.add(imponibile,TAB11_ABME01); + _iva11_arr.add(imposta,TAB11_ABVE01); + } + } + else if (ali == 4.00) + { + if (t1) + { + _iva11_arr.add(imponibile,TAB11_AGME02,LF_TAB1100B); + _iva11_arr.add(imposta,TAB11_AGVE02,LF_TAB1100B); + } + if (intra && t1_3) + { + _iva11_arr.add(imponibile,TAB11_ABME02); + _iva11_arr.add(imposta,TAB11_ABVE02); + } + } + else if (ali == 8.50) + { + if (t1) + { + _iva11_arr.add(imponibile,TAB11_AGME03,LF_TAB1100B); + _iva11_arr.add(imposta,TAB11_AGVE03,LF_TAB1100B); + } + if (intra && t1_3) + { + _iva11_arr.add(imponibile,TAB11_ABME03); + _iva11_arr.add(imposta,TAB11_ABVE03); + } + } + else if (ali == 9.00) + { + if (t1) + { + _iva11_arr.add(imponibile,TAB11_AGME04,LF_TAB1100B); + _iva11_arr.add(imposta,TAB11_AGVE04,LF_TAB1100B); + } + if (intra && t1_3) + { + _iva11_arr.add(imponibile,TAB11_ABME04); + _iva11_arr.add(imposta,TAB11_ABVE04); + } + } + } + } + + if (is_acquisto || is_vendita) + if (autofattura) + _iva11_arr.add(imponibile,TAB11_A35TER); +} + +void TLiquidazione_app::iva11_set_arr_pim(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 51 +// campi. Gli altri 74 sono compilati scorrendo i movimenti! (fatto prima della chiamata a questa funzione) + TString16 codiva, reg, tiva; + TString16 tpla, tvia; + TString16 v11, a11; + tiporeg treg; + int tipocr,tipodet,tagr; + real aliq, imp, iva, vtot, atot, ivav, ivaa; + TString cur_att; + + for (_pim->first(); !_pim->eof(); _pim->next()) + { + if (_year != *_pim_anno) 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("S4"); // tipo gestione regime agricolo + 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"); + + // I campi qui memorizzati sono tutti su TAB1100A + if (is_acquisto && tipocr == 2) + _iva11_arr.add(imp,TAB11_IMA01); + if (is_acquisto && tipocr == 8) + _iva11_arr.add(imp,TAB11_IMA02); + + if (is_acquisto && tipodet == 1 && tipocr == 0) + _iva11_arr.add(iva,TAB11_B14); + + if (is_acquisto && tipocr == 0 && aliq == 4.00) + { + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC101); + _iva11_arr.add(_pim->get_real("R10"),TAB11_FBC201); + } + if (is_acquisto && tipocr == 0 && aliq == 9.00) + { + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC102); + _iva11_arr.add(_pim->get_real("R10"),TAB11_FBC202); + } + if (is_acquisto && tipocr == 0 && aliq == 10.00) + { + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC103); + _iva11_arr.add(_pim->get_real("R10"),TAB11_FBC203); + } + if (is_acquisto && tipocr == 0 && aliq == 13.00) + { + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC104); + _iva11_arr.add(_pim->get_real("R10"),TAB11_FBC204); + } + if (is_acquisto && tipocr == 0 && aliq == 16.00) + { + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC105); + _iva11_arr.add(_pim->get_real("R10"),TAB11_FBC205); + } + if (is_acquisto && tipocr == 0 && aliq == 19.00) + { + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC106); + _iva11_arr.add(_pim->get_real("R10"),TAB11_FBC206); + } + if (is_acquisto && tipocr == 0 && a11 == "12") + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC107); + if (is_acquisto && tipocr == 0 && (a11 == "13" || a11 == "14")) + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC108); + if (is_acquisto && tipocr == 0 && a11 == "15") + _iva11_arr.add(_pim->get_real("R9"),TAB11_FBC109); + + if (is_vendita && tipocr == 0 && ((_isagricolo && tagr==2) || !_isagricolo)) + { + if (aliq == 4.00) + { + _iva11_arr.add(imp,TAB11_EC101); + _iva11_arr.add(iva,TAB11_EC201); + } + else if (aliq == 9.00) + { + _iva11_arr.add(imp,TAB11_EC102); + _iva11_arr.add(iva,TAB11_EC202); + } + else if (aliq == 10.00) + { + _iva11_arr.add(imp,TAB11_EC103); + _iva11_arr.add(iva,TAB11_EC203); + } + else if (aliq == 13.00) + { + _iva11_arr.add(imp,TAB11_EC104); + _iva11_arr.add(iva,TAB11_EC204); + } + else if (aliq == 16.00) + { + _iva11_arr.add(imp,TAB11_EC105); + _iva11_arr.add(iva,TAB11_EC205); + } + else if (aliq == 19.00) + { + _iva11_arr.add(imp,TAB11_EC106); + _iva11_arr.add(iva,TAB11_EC206); + } + } + if (is_vendita && tipocr == 0) + { + if (v11 == "10") + _iva11_arr.add(imp,TAB11_EC107); + if (v11 == "24") + _iva11_arr.add(imp,TAB11_EC108); + else if (v11 == "B1") + _iva11_arr.add(imp,TAB11_EC109); + else if (v11 == "B2") + _iva11_arr.add(imp,TAB11_EC110); + else if (v11 == "B3") + _iva11_arr.add(imp,TAB11_EC111); + else if (v11 == "26") + _iva11_arr.add(imp,TAB11_EC112); + else if (v11 == "24B") + _iva11_arr.add(imp,TAB11_EC114); + else if (v11 == "23") + _iva11_arr.add(imp,TAB11_EC115); + else if (v11 == "E50") + _iva11_arr.add(imp,TAB11_EC116); + else if (v11 == "E51") + _iva11_arr.add(imp,TAB11_EC117); + else if (v11 == "R9") + _iva11_arr.add(imp,TAB11_R9,LF_TAB1100B); + } + if (is_vendita && tipocr == 4) + _iva11_arr.add(imp,TAB11_EC113); + + if (is_vendita && _isagricolo && tipocr && (tagr == 1 || tagr == 3)) + { + if (aliq == 2.00) + { + _iva11_arr.add(imp,TAB11_AGME01,LF_TAB1100B); + _iva11_arr.add(iva,TAB11_AGVE01,LF_TAB1100B); + } + else if (aliq == 4.00) + { + _iva11_arr.add(imp,TAB11_AGME02,LF_TAB1100B); + _iva11_arr.add(iva,TAB11_AGVE02,LF_TAB1100B); + } + else if (aliq == 8.50) + { + _iva11_arr.add(imp,TAB11_AGME03,LF_TAB1100B); + _iva11_arr.add(iva,TAB11_AGVE03,LF_TAB1100B); + } + else if (aliq == 9.00) + { + _iva11_arr.add(imp,TAB11_AGME04,LF_TAB1100B); + _iva11_arr.add(iva,TAB11_AGVE04,LF_TAB1100B); + } + } + // Boia chi linka! + // 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 + atot += imp; ivaa+=iva; + } + } + } + + // Hisss... Rettifica l'importo di EC115: EC115 = EC116 + EC117 + EC115 + // Va beh... + real r16, r17; + if (_iva11_arr.is_key(TAB11_EC116)) + r16 = ((_BolgItem&)_iva11_arr[TAB11_EC116]).value(); + if (_iva11_arr.is_key(TAB11_EC117)) + r17 = ((_BolgItem&)_iva11_arr[TAB11_EC117]).value(); + r17+=r16; + _iva11_arr.add(r17,TAB11_EC115); + + + // 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); } + _iva11_arr.add(ala,TAB11_R1,LF_TAB1100B); + _iva11_arr.add(alv,TAB11_R2,LF_TAB1100B); + + // Uargh, Uargh. Mo' mi pappo i PLM per compilare T1, T1C, T2, T2C, T3, T5 e T6 + // Ah, Ah, Ah! + // ATTENZIONE: solo per i regimi 74ter (ag. viaggio) + for (_plm->first();!_plm->eof();_plm->next()) + { + if (_year != *_plm_anno || *_plm_mese == "13") continue; + cur_att = *_plm_codatt; + cur_att.rtrim(1); + if (codatt != cur_att) continue; + if (_isviaggio) + { + _iva11_arr.add(_plm->get_real("R5"),TAB11_T1,LF_TAB1100B); + _iva11_arr.add(_plm->get_real("R7"),TAB11_T1C,LF_TAB1100B); + _iva11_arr.add(_plm->get_real("R6"),TAB11_T2,LF_TAB1100B); + _iva11_arr.add(_plm->get_real("R8"),TAB11_T2C,LF_TAB1100B); + _iva11_arr.add(_plm->get_real("R9"),TAB11_T3,LF_TAB1100B); + _iva11_arr.add(_plm->get_real("R10"),TAB11_T5,LF_TAB1100B); + _iva11_arr.add(_plm->get_real("R11"),TAB11_T6,LF_TAB1100B); + } + _iva11_arr.add(_plm->get_real("R0"),TAB11_IVVENR); + } +} + +void TLiquidazione_app::iva11_write() +// Trasferisce i dati IVA11 annuali dall'assoc_array al file tab1100 +{ + const int items = _iva11_arr.items(); + if (items == 0) return; + + // Setta i campi chiave per entrambi i files della relazione + TString ditta,attiv; + ditta.format("%05ld",_nditte->curr().get_long(NDT_CODDITTA)); + attiv = _nditte->curr(LF_ATTIV).get(ATT_CODATT); + _tab11->lfile().zero(); + _tab11->lfile().put(TAB11_TADITT,ditta); + _tab11->lfile().put(TAB11_TACATT,attiv); + _tab11->lfile(LF_TAB1100B).zero(); + _tab11->lfile(LF_TAB1100B).put(TAB11_TADITT,ditta); + _tab11->lfile(LF_TAB1100B).put(TAB11_TACATT,attiv); + + _BolgItem * bolg; + int i=0,err; + for (bolg = (_BolgItem *)_iva11_arr.first_item(); bolg != NULL && ilfile(bolg->file()).put(_iva11_arr.get_hashobj()->key(),bolg->value()); + if (_tab11->write() != NOERR) + if ((err=_tab11->rewrite()) != NOERR) + error_box("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 diff --git a/cg/cg4302.cpp b/cg/cg4302.cpp index 5296c42b1..4411ff33e 100755 --- a/cg/cg4302.cpp +++ b/cg/cg4302.cpp @@ -381,19 +381,37 @@ bool TLiquidazione_app::look_pla(const char* a, bool create) bool TLiquidazione_app::look_reg(const char* reg) { - _reg_r->zero(); TString s(12); s << _year; s << format("%-3s",reg); - _reg_r->put("CODTAB",(const char*)s); - _reg->read(); - return _reg->good(); + bool rt = TRUE; + const bool is_key = _reg_arr.is_key(s); + if (is_key) + _reg->curr() = (TRectype&) _reg_arr[s]; + else + { + _reg_r->zero(); + _reg_r->put("CODTAB",(const char*)s); + _reg->read(); + _reg_arr.add(s,_reg->curr(),FALSE); + rt = _reg->good(); + } + return rt; } bool TLiquidazione_app::look_iva(const char* cod) { - _iva->zero(); - _iva->put("CODTAB",cod); - _iva->read(); - return _iva->good(); + bool rt = TRUE; + const bool is_key = _codiva_arr.is_key(cod); + if (is_key) + _iva->curr() = (TRectype&) _codiva_arr[cod]; + else + { + _iva->zero(); + _iva->put("CODTAB",cod); + _iva->read(); + _codiva_arr.add(cod,_iva->curr(),FALSE); + rt = _iva->good(); + } + return rt; } bool TLiquidazione_app::look_ppa(int month, const char* codatt, int type, bool create)