diff --git a/cg/cg0200a.uml b/cg/cg0200a.uml index 1eb607c1e..1e70c89e1 100755 --- a/cg/cg0200a.uml +++ b/cg/cg0200a.uml @@ -1176,7 +1176,7 @@ BEGIN END -SPREADSHEET F_SHEET_G_VEN 0 9 +SPREADSHEET F_SHEET_G_VEN 0 8 BEGIN PROMPT 0 3 "" ITEM "Ragione Sociale@50" diff --git a/cg/cg4300.cpp b/cg/cg4300.cpp index cd5b3dfda..95816462d 100755 --- a/cg/cg4300.cpp +++ b/cg/cg4300.cpp @@ -49,22 +49,26 @@ void _Iva11Array::zero(const char* fld_name) // Calcola prorata con percentuale identificata dall'anno passato // se la % prorata relativa all'anno indicato non esiste, ritorna 0 -real _ProrataItem::calc_prorata(const real& acq, const char * year) +real _ProrataItem::calc_prorata(const real& acq, const char* year) { - real perc = _percentuali.objptr(year) ? (real&) *_percentuali.objptr(year) : ZERO; - real prorata = (acq * perc) / CENTO; - prorata.round(TCurrency::get_firm_dec()); - return prorata; + const real* perc = (const real*)_percentuali.objptr(year); + if (perc) + { + real prorata = acq * (*perc) / CENTO; + prorata.round(TCurrency::get_firm_dec()); + return prorata; + } + return ZERO; } // Ritorna la % prorata relativa all'anno indicato. Se non esiste internamente // viene ritornato INVALID_PRORATA -real _ProrataItem::percentuale(const char * year) +const real& _ProrataItem::percentuale(const char * year) const { - real perc = _percentuali.objptr(year) ? (real&) *_percentuali.objptr(year) : INVALID_PRORATA; - if (perc == ZERO) //Se la % prorata vale 0 la percentuale non e' valida - perc = INVALID_PRORATA; - return perc; + const real* p = (real*)_percentuali.objptr(year); + if (p && !p->is_zero()) + return *p; + return INVALID_PRORATA; } inline TLiquidazione_app& app() @@ -354,7 +358,8 @@ bool TLiquidazione_app::user_create() break; } - if (need_refresh) _recalc = ever; + if (need_refresh) + _recalc = ever; // determina attivita' prevalente e istanzia cazzuole // per vedere che Kazzo di liquidazione calcolare @@ -386,13 +391,12 @@ bool TLiquidazione_app::user_create() // 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++) - if (look_lim(m)) - { - _lim->put("B0",""); - _lim->rewrite(); - break; - } + for (m = _month+1; m <= 13; m++) if (look_lim(m)) + { + _lim->zero("B0"); + _lim->rewrite(); + break; + } } TApplication::set_firm(__firm); diff --git a/cg/cg4300.h b/cg/cg4300.h index 86cecb47d..dbcfe3a6d 100755 --- a/cg/cg4300.h +++ b/cg/cg4300.h @@ -63,8 +63,8 @@ class TProgind; // Macro per riconoscere una eventuale percentuale pro-rata non presente in tabella // Siccome le % vanno da 0 a 100 vengono usati numeri a piacere. -#define INVALID_PRORATA real(1999.0) // A Guy piacciono gli 883... a me piace Spazio 1999 -#define INVALID_PRORATA_ASSERT real(883.0) // ...A little tribute 2 Max Pezzali +const real INVALID_PRORATA = 1999.0; // A Guy piacciono gli 883... a me piace Spazio 1999 +#define INVALID_PRORATA_ASSERT real(883.0) // ...A little tribute 2 Max Pezzali // // ------------------------------------------------------------------ @@ -231,10 +231,8 @@ class _ProrataItem : public TObject public: TAssoc_array& perc_array() { return _percentuali; } - real calc_prorata(const real& acq, const char * year); - real percentuale(const char * year); - _ProrataItem() {} - virtual ~_ProrataItem() {} + real calc_prorata(const real& acq, const char* year); + const real& percentuale(const char* year) const; }; // ------------------------------------------------------------------------ diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp index e0bfdbd06..9957f626b 100755 --- a/cg/cg4301.cpp +++ b/cg/cg4301.cpp @@ -130,13 +130,12 @@ bool TLiquidazione_app::recalc_all() // 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++) - if (look_lim(m)) - { - _lim->put("B0",""); - _lim->rewrite(); - break; - } + for (m = _month+1; m <= 13; m++) if (look_lim(m)) + { + _lim->zero("B0"); + _lim->rewrite(); + break; + } _month = save_month; } @@ -728,8 +727,8 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) delete regrel; } - TDate f(1, month == 13 ? 1 : month, year_int); - TDate fromdate(f); + //TDate f(1, month == 13 ? 1 : month, year_int); + const TDate fromdate(1, month == 13 ? 1 : month, year_int); TDate t; TDate f74; @@ -753,12 +752,10 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) t.set_month(month < 12 ? 12 : _freqviva == "M" ? 1 : 3); } t.set_end_month(); - TDate inizio(f); - - --inizio; + + const TDate inizio(fromdate - 1L); TDate todate(1, month == 13 ? 12 : month, year_int); - todate.set_end_month(); const TDate fine(todate); @@ -786,22 +783,14 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) TString16 trueatt(codatt); const int tipatt = atoi(trueatt.sub(5)); - //trueatt = trueatt.left(5); trueatt.cut(5); + TString pimsg; pimsg << TR("Ricalcolo attivitą ") << trueatt << " (" << month << ')'; + TProgind pi(items, pimsg, false, true); for (; _cur->pos() < items; ++(*_cur)) - { - if ((_cur->pos() & 0x7F) == 0) - { -#ifdef DBG - TString msgdbg; - msgdbg.format(FR("Ricalcolo attivita': %ld/%ld"),_cur->pos(),items); - long freespace = xvt_sys_get_free_memory_kb(); - msgdbg << TR(" Memoria libera: ") << freespace << TR(" Kbytes."); - xvtil_statbar_set(msgdbg); -#endif - do_events(); - } + { + if (!pi.setstatus(_cur->pos())) + break; TDate date(_mov->get(MOV_DATAREG)); const int liqmonth = _mov->get_int(MOV_MESELIQ); @@ -2053,10 +2042,10 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) else { // fatture a liquidazione differita - tab->put("R30", tab->get_real("R30") + diff_imp); - tab->put("R31", tab->get_real("R31") + diff_iva); - tab->put("R32", tab->get_real("R32") + incdiff_imp); - tab->put("R33", tab->get_real("R33") + incdiff_iva); + 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; @@ -2333,18 +2322,18 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) if (month == 13) { - TTable pem("PEM"); + TTable pem("PEM"); - for (int reg = 0; reg < 23; reg++) - { - look_pem(pem, reg); + for (int reg = 0; reg < 23; reg++) + { + look_pem(pem, reg); real r = pem.get_real("R0") + vt_imponibile[reg]; pem.put("R0", r); r = pem.get_real("R1") + vt_imposta[reg]; pem.put("R1", r); - pem.rewrite(); - } - } + pem.rewrite(); + } + } } } @@ -3129,7 +3118,7 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) // usa i totali del mese di dicembre dell'anno // precedente differita = TRUE; - const TString16 yr(_year); // Salvo anno corrente + const TString4 yr(_year); // Salvo anno corrente _year.format("%d", year_int-1); if (!look_lim(12)) //controlla solamente, il vero posizionamento lo fa dopo { @@ -3446,14 +3435,16 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) { // totalizza volumi affari e calcola nuovo prorata // per tutte le attivita' + atts.restart(); while ((tmpatt = atts.get()) != NULL) { - TString att(tmpatt); + const TString8 att(tmpatt); int tipoatt = att[att.len() -1] - '0'; if (tipoatt == 1) // su PLA l'attivita' e' sempre 1 { - if (!look_pla(att)) continue; + if (!look_pla(att)) + continue; real vf1 = _pla->get_real("R14"); real vf2(_pla->get("S1")); @@ -3484,29 +3475,28 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) const real rsa = ris - (es_c1a-es_c1a_am) - (es_c3-es_c3_am); const real rsn = rsa - es_c1; if (!rsa.is_zero()) - prorata = CENTO - ((rsn/rsa) * CENTO); // Percentuale di indetraibilita: reciproco della percentuale di detraibilita' + prorata = CENTO - (rsn * CENTO / rsa); // Percentuale di indetraibilita: reciproco della percentuale di detraibilita' } else { if (!ris.is_zero()) - prorata = (es_c1/ris) * CENTO; + prorata = es_c1 * CENTO / ris; } prorata.round(0); - //if (prorata != _prorata.current()) + // calcolo conguaglio -- se positivo e' a debito + if (prorata > ZERO) { - // calcolo conguaglio -- se positivo e' a debito - if (prorata > 0.0) - { - topay = (iaq + ppg) * (prorata / CENTO); - round_imposta(topay); - } - conguaglio = topay - ppg; - round_imposta(conguaglio); - } - - if (prorata < 0.0) prorata = 0.0; + 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); @@ -3519,7 +3509,7 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) _pla->rewrite(); // scrivi nuovo prorata in tabella anno successivo - const TString16 yr = _year; + const TString4 yr = _year; _year.format("%d", atoi(_year) + 1); look_pla(att, TRUE); _pla->put("R8", prorata); @@ -3537,6 +3527,18 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) _lia->rewrite(); } _year = yr; + + // Aggiusta DiffIncIVAAcq sul record della 13ma che non poteva ancora sapere il proata definitivo! + if (!prorata.is_zero() && look_plm(13, att)) + { + const real old_r33 = _plm->get("R33"); + real new_r33 = old_r33 * prorata / 100; + round_imposta(new_r33); + _plm->put("R33", new_r33); + _plm->rewrite(); + + fdiffinc_iva_acq = fdiffinc_iva_acq - old_r33 + new_r33; + } } } diff --git a/cg/cg4302.cpp b/cg/cg4302.cpp index 0b1acd94a..eda98bebe 100755 --- a/cg/cg4302.cpp +++ b/cg/cg4302.cpp @@ -249,7 +249,6 @@ bool TLiquidazione_app::look_pim(int month, const char* codatt, const char* codr // ritorna il PIM corrispondente alla chiave passata; se // create = TRUE lo crea se non lo trova. Ritorna se c'era { - bool ok = FALSE; _pim_r->zero(); (*_pim_anno) = _year; (*_pim_mese) = format("%02d", month); @@ -259,11 +258,8 @@ bool TLiquidazione_app::look_pim(int month, const char* codatt, const char* codr (*_pim_tipocr) = tipocr; (*_pim_tipodet) = tipodet; - TString s = _pim_r->get("CODTAB"); - - _pim->read(); - ok = _pim->good(); - + const TString80 s = _pim_r->get("CODTAB"); + bool ok = _pim->read() == NOERR; if (!ok && create) { _pim_r->zero(); @@ -280,7 +276,6 @@ bool TLiquidazione_app::look_pis(int month, const char* codatt, const char* codr const char* tipocr, const char* codiva, int tipodet, bool create) { - bool ok = FALSE; _pis_r->zero(); (*_pis_anno) = _year; (*_pis_mese) = format("%02d", month); @@ -289,11 +284,8 @@ bool TLiquidazione_app::look_pis(int month, const char* codatt, const char* codr (*_pis_codatt) = codatt; (*_pis_tipocr) = tipocr; (*_pis_tipodet) = tipodet; - - TString s = _pis_r->get("CODTAB"); - - _pis->read(); - ok = _pis->good(); + const TString80 s = _pis_r->get("CODTAB"); + bool ok = _pis->read() == NOERR; if (!ok && create) { @@ -309,7 +301,6 @@ bool TLiquidazione_app::look_prm(int month, const char* codatt, const char* codr const char* tipocr, const char* codiva, int tipodet, bool create) { - bool ok = FALSE; _prm_r->zero(); (*_prm_anno) = _year; (*_prm_mese) = format("%02d", month); @@ -319,10 +310,8 @@ bool TLiquidazione_app::look_prm(int month, const char* codatt, const char* codr (*_prm_tipocr) = tipocr; (*_prm_tipodet) = tipodet; - TString s = _prm_r->get("CODTAB"); - - _prm->read(); - ok = _prm->good(); + const TString80 s = _prm_r->get("CODTAB"); + bool ok = _prm->read() == NOERR; if (!ok && create) { @@ -362,19 +351,15 @@ bool TLiquidazione_app::look_prp(int month, const char* codatt, const char* codr return ok; } -bool TLiquidazione_app::look_plm(int m, const char* a, bool create) +bool TLiquidazione_app::look_plm(int m, const char* att, bool create) { - bool ok = FALSE; - _plm_r->zero(); - //(*_plm_codatt) = format("%06ld", atol(a)); - (*_plm_codatt) = format("%6s", a); + (*_plm_codatt) = format("%6s", att); (*_plm_mese) = format("%02d",m); (*_plm_anno) = _year; - TString s = _plm_r->get("CODTAB"); - _plm->read(); - ok = _plm->good(); + const TString16 s = _plm_r->get("CODTAB"); + bool ok = _plm->read() == NOERR; if (!ok && create) { @@ -383,9 +368,9 @@ bool TLiquidazione_app::look_plm(int m, const char* a, bool create) _plm->write(); } // crea/posiziona tabelle gemelle PAM, PUM, POM - look_pam(m,a,!ok); - look_pum(m,a,!ok); - look_pom(m,a,!ok); + look_pam(m,att,!ok); + look_pum(m,att,!ok); + look_pom(m,att,!ok); return ok; } @@ -531,8 +516,6 @@ bool TLiquidazione_app::look_lam(int m, bool create) bool TLiquidazione_app::look_pla(const char* a, bool create) { - _pla_r->zero(); - // forza il tipoatt a 1 TString16 buf(a); buf.ltrim(); @@ -558,7 +541,7 @@ bool TLiquidazione_app::look_pla(const char* a, bool create) bool TLiquidazione_app::look_reg(const char* reg) { - TString s(12); s << _year; s << format("%-3s",reg); + TString16 s; s << _year; s << format("%-3s",reg); bool rt = TRUE; const bool is_key = _reg_arr.is_key(s); if (is_key) @@ -569,7 +552,8 @@ bool TLiquidazione_app::look_reg(const char* reg) _reg_r->put("CODTAB",s); if (_reg->read() == NOERR) _reg_arr.add(s,_reg->curr()); - else rt = FALSE; + else + rt = FALSE; } return rt; } @@ -588,7 +572,8 @@ bool TLiquidazione_app::look_iva(const char* cod) _iva->put("CODTAB",s); if (_iva->read() == NOERR) _codiva_arr.add(s,_iva->curr()); - else rt = FALSE; + else + rt = FALSE; } return rt; } @@ -773,8 +758,8 @@ bool TLiquidazione_app::look_del(int month, int type, bool create) bool TLiquidazione_app::look_lia(long ditta, bool create, int year) { - if (year == 0) year = atoi(_year); - if (ditta == 0l) ditta = get_firm(); + if (year <= 0) year = atoi(_year); + if (ditta <= 0l) ditta = get_firm(); TString16 y; y.format("%05ld%04d", ditta, year); _lia->put("CODTAB", y); @@ -977,9 +962,9 @@ void TLiquidazione_app::round_alla_lira(real& d, bool sup) // Analogamente per l'anno bool TLiquidazione_app::is_differita(long firm, int year) { - long d = (firm == 0) ? _nditte->lfile().get_long("CODDITTA") : firm; - int y = (year == 0) ? atoi(_year) : year; - if (look_lia(d, atoi(_year) > 0), y) // 26/03/2012 aggiunto ,y) + long d = (firm <= 0) ? _nditte->curr().get_long("CODDITTA") : firm; + int y = (year <= 0) ? atoi(_year) : year; + if (look_lia(d, y > 0, y)) // 26/03/2012 aggiunto ,y) return _lia->get_bool("B1"); else return false; diff --git a/cg/cg4304.cpp b/cg/cg4304.cpp index 9bc49e7d9..1ea8414de 100755 --- a/cg/cg4304.cpp +++ b/cg/cg4304.cpp @@ -1144,12 +1144,12 @@ void TLiquidazione_app::describe_pims(int month, const char* codatt, const bool const real rsa = ris - (e3-e5) - (e4-e6); const real rsn = rsa - e1; if (!rsa.is_zero()) - pr = CENTO - ((rsn/rsa) * CENTO); // Percentuale di indetraibilita: reciproco della percentuale di detraibilita' + pr = CENTO - (rsn * CENTO / rsa); // Percentuale di indetraibilita: reciproco della percentuale di detraibilita' } else { if (!ris.is_zero()) - pr = (e1/ris) * CENTO; + pr = e1 * CENTO / ris; } pr.round(0); @@ -1160,7 +1160,7 @@ void TLiquidazione_app::describe_pims(int month, const char* codatt, const bool // calcolo conguaglio -- se positivo e' a debito if (pr > ZERO) { - topay = (iaq + ppg) * (pr / CENTO); + topay = (iaq + ppg) * pr / CENTO; round_imposta(topay); } co = topay - ppg; @@ -1220,7 +1220,8 @@ void TLiquidazione_app::describe_liq(int month, const char* codatts, _DescrItem* d->_r7 = _lim->get_real("R14"); d->_r9 = _lim->get_real("R9"); d->_r29 = _lim->get_real("R29"); - d->_r33 = _lim->get_real("R33"); + d->_r33 = _lim->get_real("R33"); // fdiffinc_iva_acq + if (atoi(_year) <= 1997) // Dal 1998 in poi il conguaglio prorata non va stampato, ma conglobato nell'iva acquisti d->_r10 = _lim->get_real("R7"); // totale conguaglio prorata @@ -1243,6 +1244,7 @@ void TLiquidazione_app::describe_liq(int month, const char* codatts, _DescrItem* d->_s5 = _lim->get("S1"); d->_s6 = _lim->get("S2"); } + d->_r11 = _lim->get_real("R10"); // tasso di interesse (Non arrotondare!) d->_r15 = _lim->get_real("R15"); // Credito utilizzato IVA @@ -2277,7 +2279,8 @@ void TLiquidazione_app::set_grand_2000(_DescrItem& d, int &rw) const real& versamenti = d._r8; const real& vers_int = d._r9; const real& diffinc_iva = d._r29; - const real& diffinc_iva_acq = d._r33; + const real& diffinc_iva_acq = d._r33; + TToken_string tt(d._s0); real iva_vend(tt.get(0)); real iva_acq(tt.get(1)); @@ -2600,7 +2603,7 @@ bool TLiquidazione_app::set_annual(_DescrItem& d) if (d._f0 & IS_PRORATA) { - // non lo ha stampato prima se annuale, perche' vladimiro il nefido + // non lo ha stampato prima se annuale, perche' Vladimiro il nefido // pretende l'assurdo aggiornamento della perc. a quella nuova const int year_int = atoi(_year);