// cg4305: liquidazione IVA // funzionalita' accessorie (calcolo acconto, estrazione deleghe) #include #include #include #include #include #include #include #include #include #include #include "cg4300.h" #include "cg4300b.h" #include "cg4300c.h" #include "cg4800b.h" // -------------------------------------------- calcolo acconto dicembre bool TLiquidazione_app::set_acconto(real& inf, real& ina) { TMask m("cg4300c"); m.set(CHK_CGC_PRINT,"X"); m.field(FLD_CGC_YEAR).set_handler(ch_year_handler); m.field(FLD_CGC_YEAR).set(_year); int k = 0; long j; _calcall = FALSE; for (;;) { if (k == K_ESC || k == K_ENTER || k == K_QUIT) break; k = m.run(); _year = m.get(FLD_CGC_YEAR); _isprint = m.get_bool(CHK_CGC_PRINT); _isbase = m.get_bool(CHK_CGC_BASE); _basecalc = (tbc)m.get_long(RDB_CGC_BASE); inf = ina = ZERO; switch (k) { case DLG_SELECT: // scegli ditte _ditte->run(); for (j = 0l; j < _ditte->items(); j++) if (_ditte->checked(j)) _selected.set(j); break; case BUT_CGC_ALL: _ditte->check(-1); for (j = 0l; j < _ditte->items(); j++) if (_ditte->checked(j) && !_ditte->row_disabled(j)) _selected.set(j); _calcall = TRUE; k = K_ENTER; break; } } return k == K_ENTER; } bool TLiquidazione_app::recalc_acconti(real& inf, real& ina) { TString buf(256); bool onemade = FALSE; const long firm = TApplication::get_firm(); _prind = new TProgind(_n_ditte, TR(" Calcolo acconto " "\n Preparazione archivi " "\n "), TRUE,TRUE); if (_ver->read(atoi(_year),(_month > 12) ? 12 : _month) != NOERR) warning_box(FR("Errore %d in lettura tabella versamenti ed interessi."),_ver->status()); for (int l = 0; l < _ditte->items(); l++) { if (_prind->iscancelled()) break; if ((_calcall || _selected[l]) && !_ditte->row_disabled(l)) { if (onemade == FALSE && _isprint) { _DescrItem* d = new _DescrItem(ACCHEAD); d->_f0 = _basecalc == incorso; d->_f1 = _isbase; _descr_arr.add(d); } _nditte->curr().zero(); _nditte->curr().put("CODDITTA",_ditte->row(l).get(1)); _nditte->read(); const long ditta = _nditte->curr().get_long("CODDITTA"); TApplication::set_firm(ditta); TIva_round ir; ir.set_default_iva_mode(atoi(_year), _month > 12, ditta); _isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74_4"); const TRectype & lia = get_lia(); _freqviva = lia.get("S7"); inf = lia.get_real("R13"); ina = lia.get_real("R14"); buf.format(FR("Calcolo acconto:\nditta %s"), (const char*)_nditte_r->get("RAGSOC")); _prind->set_text(buf); recalc_acconto(inf, ina); onemade = TRUE; } _prind->addstatus(1); } TApplication::set_firm(firm); delete _prind; return TRUE; } bool TLiquidazione_app::recalc_acconto(real& inf, real& ina) { real bc = 0.0; real acc = 0.0; real cre = 0.0; real deb = 0.0; real iva_ven = 0.0; real iva_acq = 0.0; real iva_ret = 0.0; real iva_rim = 0.0; real ult_det = 0.0; real iva_pro = 0.0; real cre_pre = 0.0; real acq_intr = 0.0; const bool isdifferita = is_acconto_differito(); // MI3262... int error = FALSE; TString16 tipo_acc; // TBI rewrite from scratch // this is absolutely fundamental if (_basecalc == precedente) { // determina casistica enum { mm, tt, mt, tm, boh } history = boh; real divide_by_three = 1.0; const char thh = *_freqviva; const TString4 thyear = _year; _year.format("%d", atoi(_year)-1); const TRectype & lia = get_lia(); if (lia.empty()) error = 3; else { char ohh = lia.get_char("S7"); if (ohh == 'M') history = thh == 'M' ? mm : mt; if (ohh == 'T') history = thh == 'M' ? tm : tt; if (history == boh) { _year = thyear; return FALSE; } // casino benzinari TString attprev = _nditte->curr().get("CODATTPREV"); long codd = _nditte->curr().get_long("CODDITTA"); TString16 key; key.format("%ld|%s", codd, (const char *) attprev); const TRectype & atts = cache().get(LF_ATTIV, key); if (atts.get_bool("ART74_4")) // e' proprio un gran benzinaro history = lia.get_bool("B4") ? mm : tt; // Was CNF_DITTA->GesT74 switch (history) { case mm: { // base calcolo: 12a anno preced, Rideterminare a seconda dell'acconto // versato; ris = 88% del debito (0 se credito const TRectype & lim = get_lim(12); if (lim.empty()) error = 2; else { bc += lim.get_real("R0"); const real av = lim.get_real("R11"); bc += av; } } break; case tt: case tm: { // base calcolo: 13a anno precedente. Rideterm. per eventuale acconto const TRectype & lim = get_lim(13); // TBC sara' 13a davvero? Secondo me e' 12 if (lim.empty()) error = 2; else { bc += lim.get_real("R0"); const real av = lim.get_real("R11"); bc += av; } if (history == tm) // tm come tt ma si divide per 3 la base di calcolo prima di calcolare l'88% divide_by_three = 3.0; } break; case mt: { // basecalcolo: 10, 11, 12 anno prec., 10 e 11 se a debito, 12 vedi acconto; // sommare e prendi 88% se a debito const TRectype & lim10 = get_lim(10); const TRectype & lim11 = get_lim(11); const TRectype & lim12 = get_lim(12); if (lim10.empty()) error = 2; else { const real app = lim10.get_real("R0"); if (app > ZERO) //a debito bc += app; } if (lim11.empty()) error = 2; else { const real app = lim11.get_real("R0"); if (app > ZERO) //a debito bc += app; } if (lim12.empty()) error = 2; else { bc += lim12.get_real("R0"); const real av = lim12.get_real("R11"); bc += av; } } break; } round_imposta(bc); if (bc > ZERO) //debito { acc = ((bc / divide_by_three) * _ver->get(isdifferita ? B_LIQ_DIFF : B_LIQ_NORM)) / CENTO; acc.round(TCurrency::get_firm_dec()); } tipo_acc = "S"; } _year = thyear; } else if (_basecalc == incorso) { // that's pazzesc but as it turns out there's no better way _comp_acconto = TRUE; // force recalc of current month _recalc = one; int need_refresh = FALSE; for (int mese = 1; mese < _month; mese++) if (is_month_ok_strict(mese)) { const TRectype & lim = get_lim(mese); if (lim.empty() || !lim.get_bool("B0")) { need_refresh = true; break; } } if (need_refresh && yesno_box(FR("Alcuni mesi precedenti non risultano ricalcolati:\n" "è consigliabile il ricalcolo. Si desidera eseguirlo?"))) _recalc = ever; for (int m = 1; m <= _month; m++) if (is_month_plain(m) || _recalc == ever) { if (_prind->iscancelled()) break; update_firm(m); } // calcola l'acconto TRectype lim = get_lim(12); if (lim.not_empty()) { cre = lim.get_real("R12"); cre -= lim.get_real("R19"); deb = lim.get_real("R13") + inf + ina; deb -= lim.get_real("R18"); // CM600446 deb -= lim.get_real("R1"); // CM600446 if (lim.get_real("R17") > ZERO) deb -= lim.get_real("R17"); else cre += lim.get_real("R17"); bc = deb - cre; if (bc > ZERO) acc = bc; look_lam(12); //posiziona anche la tabella lam iva_ven = _lam->get_real("R0"); //iva sulle vendite annotate fino al 20/12 iva_acq = _lam->get_real("R1"); //iva sugli acquisti annotati fino al 20/12 cre_pre = _lam->get_real("R2"); //credito precedente iva_ret = lim.get_real("R5"); //rettifica iva_rim = lim.get_real("R1"); //iva chiesta a rimborso ult_det = lim.get_real("R6"); //ulteriori detrazioni //iva_pro: //iva relativa alla percentuale di prorata TTable plm ("PLM"); plm.zero(); plm.put("CODTAB",_year); TRectype rec (plm.curr()); plm.read(_isgteq); for (; !plm.eof(); plm.next()) { if (plm.curr() != rec) break; iva_pro += plm.get_real("R2"); } //acq_intr TTable pom ("POM"); pom.zero(); pom.put("CODTAB",_year); rec = pom.curr(); pom.read(_isgteq); for (; !pom.eof(); pom.next()) { if (pom.curr() != rec) break; acq_intr += pom.get_real("R0"); } tipo_acc = "A"; //flag per dire che si e' utilizzato il metodo analitico //stop } else error = 1; // pulisci il water _comp_acconto = FALSE; _isprint = FALSE; for (int i = 1; i <= _month; i++) if (is_month_plain(i)) update_firm(i); lim.put("B0",""); put_lim(lim); lim = get_lim(13); if (lim.not_empty()) { lim.put("B0",""); put_lim(lim); } //fine _isprint = true; } // sbatti l'acconto (e non solo!) in LIA TRectype lia = get_lia(); if (lia.not_empty()) { if (isdifferita && _basecalc == incorso) { acc *= real(2.0); acc /= real(3.0); } lia.put("R4",acc); lia.put("R7",iva_ven); lia.put("R8",iva_acq); lia.put("R9",iva_ret); lia.put("R10",iva_rim); lia.put("R11",ult_det); lia.put("R12",iva_pro); TToken_string rr("",'!'); rr.add(cre_pre.string(),0); rr.add(acq_intr.string(),1); lia.put("S1",rr); lia.put("S8",tipo_acc); put_lia(lia); } // per questa volta lasciamo perdere la describe_acconto if (_isprint) { // segnalazioni di errore da gesticolare: // error = 0: no error // error = 1: manca tabella risultati liquidazione per l'anno indicato // error = 2: manca tabella risultati liquidazione per l'anno precedente // error = 3: manca tabella dichiarazione annuale per l'anno precedente _DescrItem* d = new _DescrItem(ACCONTO); d->_r0 = bc; d->_r1 = acc; d->_r2 = cre; d->_r3 = deb; d->_f0 = _basecalc == incorso; d->_f1 = _isbase; d->_f2 = error; d->_f3 = isdifferita; d->_s0 = _nditte->curr().get("CODDITTA"); d->_s1 = _nditte->curr().get("RAGSOC"); _descr_arr.add(d); } return TRUE; }