diff --git a/cg/cg4300.cpp b/cg/cg4300.cpp index e52205022..61cd22dae 100755 --- a/cg/cg4300.cpp +++ b/cg/cg4300.cpp @@ -108,6 +108,7 @@ bool TLiquidazione_app::user_create() _iva = new TTable("%IVA"); _del = new TTable("%DEL"); _lia = new TTable("LIA"); + _rmb = new TTable("RMB"); _mov = &_cur->file(LF_MOV); _rmoviva = &_cur->file(LF_RMOVIVA); @@ -120,6 +121,7 @@ bool TLiquidazione_app::user_create() _lim_r = &(_lim->curr()); _pla_r = &(_pla->curr()); _ppa_r = &(_ppa->curr()); + _rmb_r = &(_rmb->curr()); _reg_r = &(_reg->curr()); _rmoviva_r = &(_cur->curr(LF_RMOVIVA)); _mov_r = &(_mov->curr()); @@ -154,6 +156,10 @@ bool TLiquidazione_app::user_create() _del_tipo = new TRecfield(*_del_r,"CODTAB",11,11); _lim_anno = new TRecfield(*_lim_r,"CODTAB",0,3); _lim_mese = new TRecfield(*_lim_r,"CODTAB",4,6); + _rmb_anno = new TRecfield(*_rmb_r,"CODTAB",0,3); + _rmb_mese = new TRecfield(*_rmb_r,"CODTAB",4,6); + _rmb_codiva = new TRecfield(*_rmb_r,"CODTAB",7,10); + __firm = TApplication::get_firm(); diff --git a/cg/cg4300.h b/cg/cg4300.h index b8c9d8b6a..11acec051 100755 --- a/cg/cg4300.h +++ b/cg/cg4300.h @@ -43,6 +43,10 @@ class TProgind; #define MIN_PARTE_ESENTE real(0.50) // percentuale IVA da versare in acconto a dicembre #define ACCONTO_DICEMBRE real(0.88) +// percentuale degli imponibili da usare nel calcolo aliquota +// media acquisti e vendite per controllo diritto al rimborso +// infraanuuale secondo norme 1994 +#define PERC_IMP_RIMBORSABILE real(0.51) // // ------------------------------------------------------------------ // Fine parametri modificabili @@ -224,7 +228,8 @@ class TLiquidazione_app : public TPrint_application TTable* _reg; TTable* _iva; TTable* _del; - TTable* _lia; + TTable* _lia; + TTable* _rmb; // a reference rectype per file/table TRectype* _mov_r; @@ -239,7 +244,8 @@ class TLiquidazione_app : public TPrint_application TRectype* _ppa_r; TRectype* _lim_r; TRectype* _del_r; - TRectype* _att_r; + TRectype* _att_r; + TRectype* _rmb_r; // recfields for each stronz codtab TRecfield* _pim_anno; @@ -267,7 +273,10 @@ class TLiquidazione_app : public TPrint_application TRecfield* _del_tipo; TRecfield* _lim_anno; TRecfield* _lim_mese; - + TRecfield* _rmb_anno; + TRecfield* _rmb_mese; + TRecfield* _rmb_codiva; + TRecfield* _rmb_tiporeg; protected: @@ -303,6 +312,7 @@ public: // ricalcolo progressivi mese bool update_firm (int month, bool recalc = TRUE); bool update_att (int month, const char* codatt, bool recalc = TRUE); + void zero_firm (int month); // TBI azzera i rimborsi e i LIM void zero_att (int month, const char* codatt); void zero_annual (int month); void recalc_att (int month, const char* codatt); @@ -395,6 +405,7 @@ public: bool look_iva(const char* cod); bool look_reg(const char* reg); bool look_lia(bool create = FALSE, int anno = 0); + bool look_rmb(int month, const char* codiva, tiporeg tr, bool create); _VendItem* look_vendita(int m, const char* codreg); _VentItem* look_ventilation(int m, const char* codreg); diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp index f0354634e..aec28e2a4 100755 --- a/cg/cg4301.cpp +++ b/cg/cg4301.cpp @@ -561,24 +561,33 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) } // operazioni per calcolo rimborso infracazzuale - if (tipomov == acquisto && - (tipoiva == "ES" || tipoiva == "NI") && - ivarimb) - { - /* - * solo determinati tipi costo (Scudler 1995) - */ - if (tipocr == 0 || tipocr == 1 || tipocr == 5) - { - /* - * se agricolo, vale solo se tipoagr == 2 - * cfr. disegnini Scudler 1995 - */ - if (!_isagricolo || (_isagricolo && tipoagr == 2)) - for_rimb += imponibile; - } - } - + // Scudler 1995 + if (ivarimb) + { + bool ok = _isagricolo ? tipoagr == 2 : FALSE; + + if (tipomov == acquisto && !ok) + ok = (tipocr == 0 || tipocr == 1 || tipocr == 5); + + if (tipomov == vendita && !ok) + ok = !tipoiva.empty() && tipodoc != "CR" && + tipodoc != "SC" && tipodoc != "RF"; + + if (ok) + { + // aggiurna tabedda + look_rmb(month, codiva, tipomov, TRUE); + real imp = _rmb->get_real("R0"); + real iva = _rmb->get_real("R1"); + imp += imponibile; + iva += imposta; + _rmb->put("R0", imp); + _rmb->put("R1", iva); + _rmb->put("R2", _iva->get_real("R0")); + _rmb->rewrite(); + } + } + // operazioni esenti if (tipoiva == "ES") { @@ -1396,75 +1405,3 @@ void TLiquidazione_app::recalc_annual(const char* att) _pla->rewrite(); } -_DescrItem* TLiquidazione_app::recalc_rimborso(int month, const char* codatts) -{ - bool rimborsami = FALSE; - _DescrItem* d = NULL; - TToken_string atts(codatts); - const char* tmpatt; - TString att; - - real iva_v = 0.0; - real iva_a = 0.0; - real imp_a = 0.0; - real es_ni = 0.0; - real vol_aff = 0.0;; - - while ((tmpatt = atts.get()) != NULL) - { - att = tmpatt; - for (int m = month - 3; m < month; m++) - { - if (!look_plm(m,att) || !look_ptm(m,att)) continue; - - real tvol(_ptm->get("S3")); - vol_aff += tvol; - real esni(_plm->get("S1")); - es_ni += esni; - iva_a += _plm->get_real("R1"); - iva_v += _plm->get_real("R0"); - real aax(_ptm->get("S2")); - imp_a += aax - // rilevanti per aliquota media - _ptm->get_real("R3") - // toglie ammortizz. etc - _ptm->get_real("R5") - // non detraibili non ci sono - _ptm->get_real("R8"); - } - } - - // condizione 1 - if (!vol_aff.is_zero() && (es_ni/vol_aff) > MIN_PARTE_ESENTE) - { - rimborsami = TRUE; - d = new _DescrItem(RIMBORSO); - d->_f0 = TRUE; - d->_r0 = es_ni; - d->_r1 = vol_aff; - } - - real alv = vol_aff.is_zero() ? real(0.0) : (iva_v / vol_aff); - real ala = imp_a.is_zero() ? real(0.0) : (iva_a / imp_a); - alv.round(2); - ala.round(2); - - // condizione 2 - if (ala > alv) - { - rimborsami = TRUE; - if (d == NULL) d = new _DescrItem(RIMBORSO); - d->_f1 = TRUE; - d->_r2 = vol_aff; - d->_r3 = imp_a; - d->_r4 = iva_v; - d->_r5 = iva_a; - d->_r6 = alv * CENTO; - d->_r7 = ala * CENTO; - } - - if (rimborsami) - { - look_lim(month); - _lim->put("B2", "X"); - _lim->rewrite(); - } - return d; -} \ No newline at end of file diff --git a/cg/cg4302.cpp b/cg/cg4302.cpp index 6cea8602a..8431d061c 100755 --- a/cg/cg4302.cpp +++ b/cg/cg4302.cpp @@ -320,6 +320,28 @@ bool TLiquidazione_app::look_ppa(int month, const char* codatt, int type, bool c return ok; } +bool TLiquidazione_app::look_rmb(int month, const char* codiva, tiporeg tr, bool create) +{ + _rmb->zero(); + (*_rmb_anno) = _year; + (*_rmb_mese) = month; + (*_rmb_codiva) = codiva; + (*_rmb_tiporeg) = (int)tr; + TString ctab = _rmb->get("CODTAB"); + _rmb->read(); + + bool ok = _rmb->good(); + + if (!ok && create) + { + _rmb->zero(); + _rmb->put("CODTAB",ctab); + _rmb->write(); + } + return ok; +} + + bool TLiquidazione_app::look_del(int month, int type, bool create) { long ditta = _nditte->curr().get_long("CODDITTA"); diff --git a/cg/cg4303.cpp b/cg/cg4303.cpp index dd43b6236..cf36d62eb 100755 --- a/cg/cg4303.cpp +++ b/cg/cg4303.cpp @@ -239,4 +239,204 @@ void TLiquidazione_app::recalc_ventilation(int month, const char* codatt) _ptm->put("S4",totacq.string()); _ptm->put("S5",totven.string()); _ptm->rewrite(); -} \ No newline at end of file +} + + +// questa serve per il rimborso secondo le +// nuove cazzonorme +class rObj : public TObject +{ +public: + real _imp; + real _iva; + real _perc; + + rObj() {} + virtual ~rObj() {} +}; + + +_DescrItem* TLiquidazione_app::recalc_rimborso(int month, const char* codatts) +{ + // calcola condizioni per il diritto al rimborso infracazzuale + // chiamata soltanto per i trimestri anche se annuale + // aggiornata a normative per anno liq. > 1994 + + bool rimborsami = FALSE; + _DescrItem* d = NULL; + TToken_string atts(codatts); + const char* tmpatt; + TString att; + + real es_ni = 0.0; + real vol_aff = 0.0;; + + while ((tmpatt = atts.get()) != NULL) + { + att = tmpatt; + for (int m = month - 2; m <= month; m++) + { + if (!look_plm(m,att) || !look_ptm(m,att)) continue; + + real tvol(_ptm->get("S3")); + vol_aff += tvol; + real esni(_plm->get("S1")); + es_ni += esni; + } + } + + // condizione 1 + if (!vol_aff.is_zero() && (es_ni/vol_aff) > MIN_PARTE_ESENTE) + { + rimborsami = TRUE; + d = new _DescrItem(RIMBORSO); + d->_f0 = TRUE; + d->_r0 = es_ni; + d->_r1 = vol_aff; + } + + + // ---------------------- condizione 2 + // u'casinu pazzescu d'u nuiu guvernu + + // due array dove ficcare i totali per + // codiva in ordine di imponibile + TArray varr, aarr; + real vtot = 0.0; + real atot = 0.0; + real ivav = 0.0; + real ivaa = 0.0; + + // scorri i bellissimi progressivi mensili rimborso + for (_rmb->first(); !_rmb->eof(); _rmb->next()) + { + if (_year != (const char*)_rmb_anno || + ( atoi((const char*)_rmb_mese) < month -2 || + atoi((const char*)_rmb_mese) > month)) + continue; + + real imp = _rmb->get("R0"); + real iva = _rmb->get("R1"); + real per = _rmb->get("R2"); + + rObj* rb = new rObj; + rb->_imp = imp; + rb->_iva = iva; + rb->_perc = per; + + TArray& arr = (tiporeg)atoi((const char*)_rmb_tiporeg) == vendita ? varr : aarr; + + for (int i = 0; i < arr.items(); i++) + { + rObj& robj = (rObj&)arr[i]; + if (robj._imp < imp) + break; + } + arr.insert(rb, i); + + // totali imponibili + if ((tiporeg)atoi((const char*)_rmb_tiporeg) == vendita) + vtot += imp; + else + atot += imp; + } + + // se ci sono due o piu' imponibili uguali devo + // sostituire l'imposta con la media delle aliquote + // ciclo uguale sui due array + for (int w = 0; w < 2; w++) + { + TArray& arr = w == 0 ? varr : aarr; + for (int i = 0; i < arr.items(); i++) + { + rObj& robj = (rObj&)arr[i]; + real impref = robj._imp; + real perc = robj._perc; + + for (int j = i+1; j < arr.items(); j++) + { + rObj& rbj = (rObj&)arr[j]; + if (rbj._imp != impref) + break; + perc += rbj._perc; + } + // riaggiustesbimo + if (j > i+1) + { + // funzionerebbe comunque ma risparmiamo una + // divisione per 1 + real ndiv(j-i); + perc /= ndiv; + for (; i < j; i++) + { + rObj& rbj = (rObj&)arr[i]; + rbj._iva = rbj._imp * (perc/CENTO); + rbj._iva.round(ROUND_LIRA); + } + i --; + } + } + } + + // 51 per cento + vtot *= PERC_IMP_RIMBORSABILE; + atot *= PERC_IMP_RIMBORSABILE; + + real alv = 0.0; // aliquota media vendite + real ala = 0.0; // aliquota media acquisti + + for (w = 0; w < 2; w++) + { + TArray& arr = w == 0 ? varr : aarr; + real timp = w == 0 ? vtot : atot; + real tiva = 0.0; + + for (int i = 0; i < arr.items(); i++) + { + rObj& robj = (rObj&)arr[i]; + if (timp >= robj._imp) + { + tiva += robj._iva; + timp -= robj._imp; + } + else + { + real perc = timp/robj._imp; + if (!perc.is_zero()) + { + real ttiv = robj._iva * perc; + ttiv.round(ROUND_LIRA); + tiva += ttiv; + } + break; + } + } + if (w == 0) ivav = tiva; + else ivaa = tiva; + } + + // finalmente + alv = vtot/ivav; + ala = atot/ivaa; + + if (ala > alv) + { + rimborsami = TRUE; + if (d == NULL) d = new _DescrItem(RIMBORSO); + d->_f1 = TRUE; + d->_r2 = vtot; + d->_r3 = atot; + d->_r4 = ivav; + d->_r5 = ivaa; + d->_r6 = alv * CENTO; + d->_r7 = ala * CENTO; + } + + if (rimborsami) + { + look_lim(month); + _lim->put("B2", "X"); + _lim->rewrite(); + } + return d; +} diff --git a/cg/cg4305.cpp b/cg/cg4305.cpp index 3608e614d..991487c8c 100755 --- a/cg/cg4305.cpp +++ b/cg/cg4305.cpp @@ -93,7 +93,7 @@ bool TLiquidazione_app::extract_deleghe() _prind->set_text(buf); - if (is_month_ok_strict(_month)) + if (is_month_ok_strict(_month) || _month == 13) { _isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74/4"); bool mens = _freqviva == "M"; diff --git a/cg/cg5.cpp b/cg/cg5.cpp index 522843f32..14eaf801b 100755 --- a/cg/cg5.cpp +++ b/cg/cg5.cpp @@ -23,6 +23,8 @@ int main(int argc,char** argv) cg5400(argc,argv) ; break; case 5: cg5500(argc,argv) ; break; + // case 6: + // cg5600(argc,argv) ; break; default: error_box(usage, argv[0]) ; } diff --git a/cg/cg5.h b/cg/cg5.h index 968e4a1d6..1ee785ae0 100755 --- a/cg/cg5.h +++ b/cg/cg5.h @@ -4,3 +4,4 @@ int cg5200 (int argc, char* argv[]); int cg5300 (int argc, char* argv[]); int cg5400 (int argc, char* argv[]); int cg5500 (int argc, char* argv[]); +// int cg5600 (int argc, char* argv[]);