diff --git a/cg/cg4300.cpp b/cg/cg4300.cpp index b3e46dfcc..c0d2227d5 100755 --- a/cg/cg4300.cpp +++ b/cg/cg4300.cpp @@ -194,8 +194,10 @@ bool TLiquidazione_app::user_create() to.put(MOV_DATAREG, t); _cur->setregion(from, to); - if (is_month_ok(_month)) update_firm(_month); - if (_isprint) print(); + if (is_month_ok_strict(_month)) + update_firm(_month); + if (_isprint && _descr_arr.items() > 0) + print(); TApplication::set_firm(__firm); end_wait(); } diff --git a/cg/cg4300.h b/cg/cg4300.h index 53abe6170..bdd54a226 100755 --- a/cg/cg4300.h +++ b/cg/cg4300.h @@ -131,7 +131,7 @@ public: _r6, _r7, _r8, _r9, _r10,_r11; TArray _arr; - + _DescrItem(word f) : _f0(0), _f1(0), _f2(0), _arr(4) { _flags = f; } virtual ~_DescrItem() @@ -162,6 +162,7 @@ class TLiquidazione_app : public TPrint_application int _month; // mese da calcolare TDate _date; // data di stampa bool _isprint; // vuoi stampare o no? + bool _canprint; // PUOI stampare o no? bool _printonly; // calcolo definitivo recalc _recalc; // tipo ricalcolo scelto bool _isplafond; // plafond importatori abituali @@ -182,7 +183,7 @@ class TLiquidazione_app : public TPrint_application long _n_ditte; // numero ditte bool _comp_acconto; // stiamo calcolando l'acconto TArray _nomiditte; // array descr. ditte per sheet - + TProgind* _prind; int _row; TArray _vend_arr; // tabella vendite per ventilazione @@ -197,7 +198,7 @@ class TLiquidazione_app : public TPrint_application long __firm; // ditta selezionata all'inizio bool _is_interactive; // lanciata da menu o da altro prog bool _is_visliq; // lanciata da visualizzazione liquidazione - + static real CENTO; // main cursor @@ -264,16 +265,16 @@ class TLiquidazione_app : public TPrint_application protected: - + long select_firm_range(long from, long to, wht freq); - + static bool ch_year_handler(TMask_field& f, KEY key); static bool to_ditt_handler(TMask_field& f, KEY key); static bool fr_ditt_handler(TMask_field& f, KEY key); static bool to_butt_handler(TMask_field& f, KEY key); static bool fr_butt_handler(TMask_field& f, KEY key); static bool what_freq_handler(TMask_field& f, KEY key); - + static TLiquidazione_app& app() { return (TLiquidazione_app&)main_app(); } public: @@ -301,21 +302,26 @@ public: void recalc_att (int month, const char* codatt); void recalc_annual (const char* codatt); _DescrItem* recalc_rimborso(int month, const char* codatts); - - // ricalcolo liquidazioni dai progressivi + + // ricalcolo liquidazioni dai progressivi mensili void write_liq (int month, const char* atts); - + + // ritorna l'eventuale ma sempre appropriato debito (< 50.000) + real debt_prec(int month); + // ritorna il risultato della liquidazione del mese + // non considera il conguaglio prorata (annuale) + real result_liq(int month); // ritorna l'appropriato credito precedente al mese in corso real credito_prec(int month); // ritorna l'appropriato credito di costo precedente al mese in corso // (travel agency only) - real credito_costo_prec(int month, const char* codatt); - // ritorna i versamenti effettuati nel mese passato + real credito_costo_prec(int month); + // ritorna i versamenti effettuati nel mese real versamenti_IVA(int month, bool acconto = FALSE); - + // supporto stampa void describe_firm(int month); - void describe_att(int month, const char* codatt); + void describe_att(int month, const char* codatt, bool isresult); void describe_name(int month, TToken_string& atts); void describe_plafond(int month, const char* codatt); void describe_ventilation(int month, const char* codatt); @@ -326,10 +332,10 @@ public: void describe_error(const char* errstr, const char* codatt); void describe_annual(const char* codatt); void describe_consistence(const char* codatt); - + // corrispettivi void recalc_corrispettivi (int month, const char* codatt); - + // ventilasiun void recalc_ventilation (int month, const char* codatt); @@ -337,14 +343,14 @@ public: void zero_plafond (int month, const char* codatt); void add_plafond (int month, const char* codatt, int type, real& howmuch, bool intra); - + // ritorna l'aliquota ordinaria dal // codice IVA apposito immesso nei parametri studio real aliquota_agvia(); - + // ritorna l'interesse per il mese in questione (dai parametri studio) real interesse_trimestrale(int month); - + // minchia di puro suino void add_vendite (int month, const char* codreg, int tipodet, real& r); void add_ventilation (real iva, real sum, const char* codiva); @@ -355,7 +361,7 @@ public: virtual void set_page(int file, int counter); virtual bool preprocess_page(int file, int counter); virtual print_action postprocess_page(int file, int counter); - + // settaggio righe per ogni elemento di _descr_arr void set_plafond(_DescrItem& d); void set_ventila(_DescrItem& d); @@ -381,19 +387,25 @@ public: bool look_iva(const char* cod); bool look_reg(const char* reg); bool look_lia(bool create = FALSE, int anno = 0); - + _VendItem* look_vendita(int m, const char* codreg); _VentItem* look_ventilation(int m, const char* codreg); // tutti i controlli del mondo sui mesi da calcolare static bool is_trim (int x); - static bool is_in_trim (int x, int t); - bool is_month_ok (int x, int month = -1); + // is_month_ok controlla che il mese passato sia + // da prendere in considerazione per la liquidazione + // controllando il regime trimestrale o mensile + bool is_month_ok(int x, int mtocalc); + // is_month_ok_strict controlla che il mese sia OK per la + // liquidazione, ma ritorna TRUE per le trimestrali solo + // se il mese cade ESATTAMENTE su un trimestre + bool is_month_ok_strict(int x, int month = -1); bool is_date_ok (TDate& d, int month); bool is_first_month (int m); int previous_month (int m); - bool check_month (int m, int mref); - + bool check_month(int m, int mref); + // Funzioni accessorie: estrazione deleghe bool set_deleghe(); bool extract_deleghe(); diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp index 6238c85d0..2cae35aed 100755 --- a/cg/cg4301.cpp +++ b/cg/cg4301.cpp @@ -10,9 +10,13 @@ #include "cg4300.h" // -------------------- QUI comincia l'avventura -------------------------- - -// che nel gennaio 1995 non solo non e' finita, ma si fa -// ogni giorno piu' odiosa e nevrastenica +// ----------------------------------------------------- ****************** +// che nel gennaio 1995 non solo non e' finita, ma si fa ****************** +// ogni giorno piu' odiosa e nevrastenica ****************** +// ----------------------------------------------------- ****************** +// Datemi un punto di appoggio ****************** +// e mi ci appoggero' ****************** +// ----------------------------------------------------- ****************** bool TLiquidazione_app::recalc_all() { @@ -41,50 +45,48 @@ bool TLiquidazione_app::recalc_all() TApplication::set_firm(nomeditta.get_long(1)); _prind->addstatus(1); - // trimestrali impropriamente selezionate per mesi intermedi - _freqviva = nomeditta.get(3); - if (!is_month_ok(_month)) continue; + _freqviva = nomeditta.get(3); + /* + * trimestrali impropriamente selezionate per mesi intermedi + * provocano il ricalcolo dei progressivi mensili ma non la stampa + */ + _canprint = is_month_ok_strict(_month); int need_refresh = FALSE; if (_recalc != ever) { for (int m = 1; m < _month; m++) - { - if (!is_month_ok(m)) continue; - if (!look_lim(m)) need_refresh = TRUE; - else if (!(_lim->get_bool("B0"))) need_refresh = TRUE; - } - if (need_refresh) - { - if (_is_interactive) + if (!look_lim(m) || !_lim->get_bool("B0")) { - if (yesno_box("Alcuni mesi precedenti non risultano ricalcolati. E' " - "consigliabile il ricalcolo. Si desidera eseguirlo?")) - _recalc = ever; + need_refresh = TRUE; + break; } - else _recalc = needed; - } - } + + if (need_refresh && yesno_box("Alcuni mesi precedenti non " + "risultano ricalcolati. E' consigliabile il ricalcolo. " + "Si desidera eseguirlo?")) + _recalc = ever; + } - if (_recalc == ever) - { - for (int m = 1; m < _month; m++) - if (is_month_ok(m)) - update_firm(m); - } - update_firm(_month); + for (int m = 1; m <= _month; m++) + if (is_month_ok(m, _month) || _recalc == ever) + { + if (_prind->iscancelled()) + break; + update_firm(m); + } - // se ci sono altri mesi dopo quello calcolato, invalida il + // 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 (int m = _month+1; m <= 13; m++) - if (is_month_ok(m) && look_lim(m)) + for (m = _month+1; m <= 13; m++) + if (is_month_ok_strict(m) && look_lim(m)) { _lim->put("B0",""); break; } - } - } + } + } bool canc = _prind->iscancelled(); if (!canc) _prind->addstatus(1); @@ -184,7 +186,6 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) _isvent = _reg->get_bool("B3"); } - if ((month != 13 || _isannual) && (calc || !recalc)) if (!update_att(month, cattiv)) describe_error("Attivita' non ricalcolate: possibili errori", @@ -196,11 +197,11 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) { look_plm(month,cattiv); gheravergot = !_plm->get_real("R0").is_zero() || - !_plm->get_real("R1").is_zero(); + !_plm->get_real("R1").is_zero(); } - if (month == _month && gheravergot) - describe_att(month,cattiv); + if (month == _month) + describe_att(month,cattiv,gheravergot); atts.add(cattiv); cattivs.add(cattiv); @@ -208,20 +209,20 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) // se attivita' mista stampa riepilogo if (_mixed && month == _month) - describe_att(month,cattivs); + describe_att(month,cattivs, TRUE); } while (_nditte->next_match(LF_ATTIV)); // se quater stampa riepilogo if (quater && month == _month) - describe_att(month,atts); + describe_att(month,atts, TRUE); // occorre poterla chiamare altre volte con mesi diversi _nditte->restore_status(); // aggiorna le liquidazioni mensili if ((_month != 13 || _isannual) && (calc || !recalc)) - write_liq (month, atts); + write_liq(month, atts); // rimborso infraannuale _DescrItem* rimb_d = NULL; @@ -242,31 +243,36 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) return ok || calc; } -bool TLiquidazione_app::update_att(int month, const char* codatt, bool recalc) +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 (ok && !recalc) return TRUE; - bool calc = _recalc == ever || (_recalc == one && month == _month) ; - - if (!calc && _recalc != never) calc = !ok; - if (_isannual && month == 13) month = 12; - - if (calc || !recalc) + if (month == 13) + recalc_annual(codatt); + else { - zero_att(month,codatt); - recalc_att(month,codatt); - recalc_ventilation(month, codatt); - recalc_corrispettivi(month, codatt); - if (month == 12) recalc_annual(codatt); + look_plm(month, codatt, TRUE); + bool ok = _plm->get_bool("B0"); + if (ok && !recalc) return TRUE; + bool calc = _recalc == ever || (_recalc == one && month == _month); + if (!calc && _recalc != never) calc = !ok; + + if (calc || !recalc) + { + zero_att(month,codatt); + recalc_att(month,codatt); + recalc_ventilation(month, codatt); + recalc_corrispettivi(month, codatt); + // per trimestrali + if (_isannual) recalc_annual(codatt); + } + return ok || calc; } - return ok || calc; + return TRUE; } void TLiquidazione_app::zero_att(int month, const char* codatt) @@ -289,6 +295,8 @@ void TLiquidazione_app::zero_att(int month, const char* codatt) 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; { real totintra = 0.0; real nond19_imp = 0.0; @@ -322,7 +330,6 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) real agr_acq = 0.0; real agr_conf = 0.0; real agr_acc = 0.0; - real cred_cost = 0.0; real for_rimb = 0.0; real acq_ies = 0.0; real acq_ies_iva = 0.0; @@ -409,7 +416,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) bool autodafe = (tipodoc == "AF" && tipocr == 4); /* - * puo' capitare per flags prassiani + * puo' capitare per motivi brutalmente prassici * SENSU Sergio 1995, Guido */ if (tipoatt == 0) tipoatt = 1; @@ -433,10 +440,10 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) // Altre cose di cui tener conto if (tipomov == acquisto && (tipocr == 1 || tipocr == 5)) /* - * Acquisto beni per rivendita sono comunque sommati, ma + * Acquisto beni per rivendita: sono comunque sommati, ma * vengono considerati in ventilazione solo se l'apposito * parametro ditta e' settato, piu' altre condizioni (vedi - * recalc_ventilation()) + * recalc_ventilation() for spulcing) */ { acq_riv += imponibile; @@ -457,15 +464,17 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) ult_detr += imponibile * real(DETRAZIONE_6PERCENTO); } else if (tipomov == vendita && tipocr == 4) - // Vendite strum. art 17 (cess. amm.) - // anche autofatture e anche nell'annuale - // (Sergio 1995) + /* + * Vendite strum. art 17 (cess. amm.) + * Comprende anche autofatture, anche nell'annuale + * (Sergio 1995) + */ { cess_amm += imponibile; cess_amm_iva += imposta; } else if (tipomov == acquisto && tipocr == 8) - // Acquisto beni strum. in leasing + // Acquisto beni strum. acquisiti in leasing { leasing += imponibile; leasing_iva += imposta; @@ -559,7 +568,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) acq_ies_iva += imposta; } - if (tipodet == 3) // passaggi interni (solo ventilaz) + if (tipodet == 3) // passaggi interni (solo per ventilaz) { acq_pint += imponibile; acq_pint_iva += imposta; @@ -598,14 +607,16 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) * 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 riportare il totale in R0 e R1. La stampa (describe_pim) - * dovra' scorporare + * a sommarle anche in R0 e R1. La stampa (describe_pim) + * dovra' scorporarle */ real ifs = _pim_r->get_real("R5"); // imponibile fatture con scontrino real vfs = _pim_r->get_real("R6"); // IVA fatt. con scontrino /* * le maledette autofatture non residenti art. 17 - * vedi al calcolo if (autodafe) + * vedi al calcolo if (autodafe) si tengono da parte + * La stampa le scorpora solo IN SEDE di dichiarazione annuale + * NELL'OTTICA di una PIU' CORRETTA e CONSONA ...................... */ real adf = _pim_r->get_real("R7"); real adi = _pim_r->get_real("R8"); @@ -628,14 +639,15 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) // corrispettivi 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. - if (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC" || - tipodoc == "SN" || tipodoc == "CN") + /* + * 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. + */ + if (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC") { // questi sono corrispettivi davvero; comportamento normale if (tipoiva == "VE") // da ventilare @@ -729,7 +741,9 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) // calcolati tutti i movimenti e aggiornati i pim // salviamo i totali antes que seja tarde - // calcola il lercio prorata + /* + * calcola il lercio prorata + */ real prorata; if (!_prorata.is_zero()) { @@ -740,10 +754,12 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) /* * ACHTUNG: l'iva sulle vendite e' calcolata sommando anche i - * corrispettivi; non tiene conto quindi delle imposte calcolate + * 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 - * sottratte per il calcolo del volume di affari) + * comunque sottratte nel calcolo del volume di affari) */ _plm->put("R2", prorata); @@ -756,41 +772,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) _plm->put("R8", acq_noCEE); _plm->put("R9", corr_misCEE); _plm->put("R10",acq_misCEE); - _plm->put("R11",acq_misnoCEE); - - /* - * calcola base da base e credito di costo - * indi abilmente trova il codiva e calcola l'iva del caso - */ - real rip = acq_misCEE / (acq_misCEE + acq_misnoCEE); - real corr_imp = corr_misCEE * rip; corr_imp.round(ROUND_LIRA); - corr_imp += corr_CEE; - real cost_detr = acq_misCEE * acq_CEE; - real base_imp = corr_imp - (cost_detr - + credito_costo_prec(month, codatt)); - real debito = 0.0; - - if (base_imp.sign() < 0) - { - // credito di costo - cred_cost = abs(base_imp); - // vendite_iva e' corretto cosi' visto che i corrispettivi - // sono registrati al lordo e l'imposta e' 0 - } - else - { - debito = base_imp * aliquota_agvia(); - vendite_iva += debito; - vendite_iva.round(ROUND_LIRA); - } - - // tutte ste minchie le mettiamo in lim anche se sarebbe - // assai piu' migliore metterle in plm - look_lim(month,TRUE); - _lim->put("R2", cred_cost); - _lim->put("R3", debito); - _lim->put("R4", rip); - _lim->rewrite(); + _plm->put("R11",acq_misnoCEE); } else if (_isagricolo) { @@ -804,12 +786,14 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) } // COSA MI TOCCA FARE (per campare, of course) - // due numeri nello stesso campo + // due numeri nello stesso campo ma e' sempre meglio + // del TIPO RECORD TToken_string s(40); _plm->put("R0", vendite_iva); _plm->put("R1", acquisti_iva); _plm->put("R3", ult_detr); + // probabilmente R4 serviva per il decalage e non si usera' _plm->put("R12", _prorata); // per comodita' in stampa _plm->put("B0", "X"); // calcolato (invalidato dalla primanota) _plm->put("S1", for_rimb.string()); @@ -817,18 +801,15 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) // si riempiano le stringhe di coppie di real s.add(acq_ies.string()); s.add(acq_ies_iva.string()); - _plm->put("S2", (const char*)s); - + _plm->put("S2", (const char*)s); s = ""; s.add(acq_pint.string()); s.add(acq_pint_iva.string()); - _plm->put("S3", (const char*)s); - + _plm->put("S3", (const char*)s); s = ""; s.add(spgen.string()); s.add(spgen_iva.string()); - _plm->put("S4", (const char*)s); - + _plm->put("S4", (const char*)s); _plm->rewrite(); // salva gli altri totali para no ponernos locos despues @@ -853,13 +834,6 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) _ptm->put("S2", acquisti.string()); _ptm->put("S3", vendite.string()); _ptm->rewrite(); - - // somma le ulteriori detrazioni - look_lim(month, TRUE); - real dt = _lim->get_real("R6"); - dt += ult_detr; - _lim->put("R6", dt); - _lim->rewrite(); } void TLiquidazione_app::write_liq(int month, const char* codatts) @@ -871,65 +845,89 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) real risultato = 0.0; real vol_aff = 0.0; real debito_prec = 0.0; - real ris_deb = 0.0; - real ris_cred = 0.0; + real detrazioni = 0.0; + + // totali per agenzie viaggio + real c_iCEE(0.0); + real c_eCEE(0.0); + real a_iCEE(0.0); + real a_eCEE(0.0); + real c_mCEE(0.0); + real a_mCEE(0.0); + real a_meCEE(0.0); + real cred_cost(0.0); + real deb_mens(0.0); + real perc_r(0.0); while ((tmpatt = atts.get()) != NULL) { TString att(tmpatt); - { - look_plm(month, att); look_ptm(month,att); - // a debito: IVA vendite, debito precedente, Prorata - // a credito: IVA acquisti, ulteriori detrazioni 1 e 2 - risultato += (_plm->get_real("R0") - _plm->get_real("R1") + - _plm->get_real("R2") - _plm->get_real("R3") - - _plm->get_real("R4")); - - ris_deb += (_plm->get_real("R0") + _plm->get_real("R2")); - ris_cred += (_plm->get_real("R1") + _plm->get_real("R3") + - _plm->get_real("R4")); - - if (month == 12) - { - look_pla(att); - vol_aff += _pla->get_real("R0"); - // a credito anche il conguaglio prorata - risultato -= _pla->get_real("R10"); - ris_cred += _pla->get_real("R10"); - } - } - } - // toglie credito precedente decrementato di ev. rimborsi chiesti - // e acconto versato e rettificato come da manuale - risultato -= credito_prec(month); - ris_cred += credito_prec(month); - // vedi se c'era un debito precedente - if (!is_first_month(month)) - { - if (look_lim(previous_month(month))) + for (int m = 1; m <= 12; m++) + { + // ciclo su tutti i mesi del caso (1 o 3) + // non porta via tempo anche cosi' + if (!_isannual && !is_month_ok(m, month)) + continue; + + look_plm(month, att); look_ptm(month,att); + // a debito: IVA vendite, debito precedente, Prorata + // a credito: IVA acquisti, ulteriori detrazioni 1 e 2 + risultato += (_plm->get_real("R0") - _plm->get_real("R1") + + _plm->get_real("R2") - _plm->get_real("R3") - + _plm->get_real("R4")); + detrazioni+= (_plm->get_real("R3") + _plm->get_real("R4")); + + 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"); + } + } // fine ciclo sul mese + + // toglie credito precedente considerando rimborsi + // e acconto versato e rettifiche, come da manuale + risultato -= credito_prec(month); + // vedi se c'era un debito precedente per debiti < 50.000 + risultato += debt_prec(month); + + if (_isviaggio) { - real r = _lim->get_real("R0"); - if (_lim->get_real("R5").sign() > 0) - r += _plm->get_real("R5"); - // non considera il rimborso in quanto se e' a debito - // non c'e' rimborso, e se e' rettificato pure - if (r.sign() > 0 && r < IVA_DA_RIPORTARE) - debito_prec += r; - } - } - risultato += debito_prec; - ris_deb += debito_prec; - + // calcolo credito costo, debito mensile, perc. ripart. + perc_r = (a_mCEE * CENTO)/(a_mCEE + a_meCEE); + real c = (c_mCEE * perc_r)/CENTO; c.round(ROUND_LIRA); + real tc = (c_iCEE + c); + 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); + cred_cost.round(ROUND_LIRA); + } + else + { + deb_mens = (bi /((CENTO + aliquota_agvia())/CENTO)) * + (aliquota_agvia()/CENTO); + deb_mens.round(ROUND_LIRA); + } + } + } look_lim(month,TRUE); - // scorpora ulteriori detrazioni - real dt = _lim->get_real("R6"); - risultato -= dt; - ris_cred += dt; - _lim->put("R0",risultato); - + _lim->put("R2",cred_cost); + _lim->put("R3",perc_r); + _lim->put("R4",deb_mens); + _lim->put("R6",detrazioni); + if (_freqviva == "T" && risultato.sign() > 0) { real interesse = interesse_trimestrale(_month); @@ -939,14 +937,6 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) _lim->put("B0","X"); _lim->rewrite(); - - if (month == 12) - { - if (!look_lia(TRUE)) - _lia->put("S7", (const char *) _freqviva); - _lia->put("R1", vol_aff); - _lia->rewrite(); - } } @@ -966,55 +956,58 @@ void TLiquidazione_app::recalc_annual(const char* att) real ven_lrd = 0.0; int tipoatt = att[strlen(att) -1] - '0'; + TString aaa(att); if (tipoatt == 2) { // istanzia ai valori precedenti, calcolati per l'attivita' 1 - look_pla(aaa); - vendite = _pla->get_real("R0"); - es_b1 = _pla->get_real("R1"); - es_b2 = _pla->get_real("R2"); - es_b3 = _pla->get_real("R3"); - cess_amm = _pla->get_real("R4"); - ivven = _pla->get_real("R11"); - ivlac = _pla->get_real("R12"); - ven_lrd = _pla->get_real("R13"); - acq = _pla->get_real("R14"); + // llok_pla forza a 1 il tipo attivita' + if (look_pla(aaa)) + { + vendite = _pla->get_real("R0"); + es_b1 = _pla->get_real("R1"); + es_b2 = _pla->get_real("R2"); + es_b3 = _pla->get_real("R3"); + cess_amm = _pla->get_real("R4"); + ivven = _pla->get_real("R11"); + ivlac = _pla->get_real("R12"); + ven_lrd = _pla->get_real("R13"); + acq = _pla->get_real("R14"); + } } for (int i = 1; i <= 12; i++) { - if (is_month_ok(i)) - { - // ricalcola se necessario - if (i != 12 && !update_att(i,aaa,FALSE)) - describe_error("Attivita' non ricalcolata: " - "possibili errori",att); - look_ptm(i,aaa); look_plm(i,aaa); - real vend(_ptm->get("S3")); - ven_lrd += vend; // lordo vendite - // non entra l'IVA per calcolo volume affari - vendite += (vend - _plm->get_real("R0")); - real eb3(_ptm->get("S0")); - es_b1 += _ptm->get_real("R13"); - es_b2 += _ptm->get_real("R14"); - es_b3 += eb3; - acq_iva += _plm->get_real("R1"); - cess_amm += _ptm->get_real("R10"); - pro_pag += _plm->get_real("R2"); - real aax(_ptm->get("S2")); - acq += 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"); - ivlac += _plm->get_real("R1") - // idem per IVE - _ptm->get_real("R4") - - _ptm->get_real("R9") - - _ptm->get_real("R12"); - ivven += _plm->get_real("R0"); - } + // ricalcola se necessario + if (i != 12 && !update_att(i,aaa,FALSE)) + describe_error("Attivita' non ricalcolata: " + "possibili errori",att); + look_ptm(i,aaa); look_plm(i,aaa); + real vend(_ptm->get("S3")); + ven_lrd += vend; // lordo vendite + + // non entra l'IVA per calcolo volume affari + vendite += (vend - _plm->get_real("R0")); + real eb3(_ptm->get("S0")); + es_b1 += _ptm->get_real("R13"); + es_b2 += _ptm->get_real("R14"); + es_b3 += eb3; + acq_iva += _plm->get_real("R1"); + cess_amm += _ptm->get_real("R10"); + pro_pag += _plm->get_real("R2"); + real aax(_ptm->get("S2")); + acq += 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"); + ivlac += _plm->get_real("R1") - // idem per IVE + _ptm->get_real("R4") - + _ptm->get_real("R9") - + _ptm->get_real("R12"); + ivven += _plm->get_real("R0"); } + // calcolo prorata real prorata = (es_b1/(vendite - cess_amm - es_b3)) * CENTO; real conguaglio = 0.0; @@ -1026,9 +1019,6 @@ void TLiquidazione_app::recalc_annual(const char* att) conguaglio = topay - pro_pag; } - // vediamo se la porca aliquota media acquisti e' superiore alla - // porca aliquota media vendite - look_pla(aaa); _pla->put("R0", vendite); _pla->put("R1", es_b1); @@ -1128,4 +1118,4 @@ _DescrItem* TLiquidazione_app::recalc_rimborso(int month, const char* codatts) } return d; -} +} \ No newline at end of file diff --git a/cg/cg4302.cpp b/cg/cg4302.cpp index bce6808b7..d15fb24ce 100755 --- a/cg/cg4302.cpp +++ b/cg/cg4302.cpp @@ -13,29 +13,7 @@ bool TLiquidazione_app::is_trim(int x) // TRUE se il mese passato e' un trimestre { return x == 3 || x == 6 || x == 9 || x == 12; } -bool TLiquidazione_app::is_in_trim(int x, int t) - // TRUE se il mese passato e' nel trimestre t -{ - bool ret = FALSE; - switch(t) - { - case 3: - ret = x >= 1 && x <= 3; - break; - case 6: - ret = x >= 4 && x <= 6; - break; - case 9: - ret = x >= 7 && x <= 9; - break; - case 12: - ret = x >= 10 && x <= 12; - break; - } - return ret; -} - -bool TLiquidazione_app::is_month_ok(int x, int month) +bool TLiquidazione_app::is_month_ok_strict(int x, int month) // TRUE se il mese passato e' compatibile con il regime // di liquidazione e (opz) non e' maggiore di quello scelto { @@ -45,6 +23,21 @@ bool TLiquidazione_app::is_month_ok(int x, int month) ( x <= month && is_trim(x)); } +bool TLiquidazione_app::is_month_ok(int x, int mtocalc) +// TRUE se il mese passato e' compatibile con il mese da calcolare +// rispetto al regime di liquidazione scelto +{ + bool ret = x == mtocalc; + if (!ret && _freqviva == "T") + { + // aggiusta al trimestre il mese da calcolare + mtocalc += 2 - ((mtocalc-1) % 3); + ret = x >= (mtocalc - 3) && x <= mtocalc; + } + return ret; +} + + bool TLiquidazione_app::is_first_month(int m) { return _freqviva == "M" ? @@ -69,16 +62,13 @@ bool TLiquidazione_app::check_month(int m, int m2) } bool TLiquidazione_app::is_date_ok(TDate& d, int month) - // TRUE se la data passata va considerata nel - // ricalcolo dei progressivi per il mese e anno - // selezionati +// TRUE se la data passata va considerata nel +// ricalcolo dei progressivi mensili per il mese e anno +// selezionati { if (d.month() > month || d.year() != atoi(_year)) return FALSE; - return _freqviva == "M" ? - (d.month() == month): - ((month - d.month()) >= 0 && - (month - d.month()) < 3); + return d.month() == month; } @@ -326,12 +316,13 @@ bool TLiquidazione_app::look_ppa(int month, const char* codatt, int type, bool c bool TLiquidazione_app::look_del(int month, int type, bool create) { - TString16 ditta = _nditte->curr().get("CODDITTA"); + long ditta = _nditte->curr().get_long("CODDITTA"); _del->zero(); - (*_del_ditta) = ditta; + (*_del_ditta) = format("%05ld", ditta); (*_del_anno) = _year; - (*_del_mese) = month; - (*_del_tipo) = type; + (*_del_mese) = format("%02d", month); + (*_del_tipo) = format("%1d", type); + TString16 ctab = _del->get("CODTAB"); _del->read(); @@ -365,106 +356,80 @@ bool TLiquidazione_app::look_lia(bool create, int year) return ok; } +real TLiquidazione_app::result_liq(int month) +// risultato esatto della liquidazione del mese month, <0 a credito +// >0 a debito; non comprende il conguaglio prorata (annuale) +{ + real r(0.0); + if (look_lim(month)) + { + r = _lim->get_real("R0") + + _lim->get_real("R1") + // rimborso + _lim->get_real("R5"); // rettifiche + // le ulteriori detrazioni sono gia' comprese in R0 + // eventuale acconto versato a dicembre + if (month == 12 && look_del(12,7) && _del->get_bool("B1")) + r -= _del->get_real("R0"); + } + return r; +} + +real TLiquidazione_app::debt_prec(int month) +{ + real r(0.0); + if (!is_first_month(month)) + { + if (look_lim(previous_month(month))) + { + r = result_liq(previous_month(month)); + if (!(r.sign() > 0 && r < IVA_DA_RIPORTARE)) + r = ZERO; + } + } + return r; +} + real TLiquidazione_app::credito_prec(int month) - // ritorna l'appropriato credito precedente al mese in corso - // lascia PLM posizionata sul mese passato +// ritorna l'appropriato credito precedente al mese in corso { real c(0.0); if (is_first_month(month)) { - look_lia(); - if (_lia->status() == NOERR) - c = _lia->get_real("R0"); -// int yr = atoi(_year) - 1; -// _lim->zero(); -// *_lim_anno = yr; -// *_lim_mese = 12; -// if (_lim->read() == NOERR) - // considera anche il rimborso -// c = _lim->get_real("R0") + _lim->get_real("R1"); - // e le eventuali rettifiche -// real rett = _lim->get_real("R5"); -// c += rett; - // e le ulteriori detrazioni -// real detr = _lim->get_real("R6"); -// c -= detr; - // e l'acconto versato a dicembre -// _del->zero(); - -// TString ditta = _nditte->curr().get("CODDITTA"); -// *_del_ditta = ditta; -// *_del_anno = yr; -// *_del_mese = 12; -// *_del_tipo = 7; -// if (_del->read() == NOERR) -// c -= _del->get_real("R0"); + if (look_lia()) + c = _lia->get_real("R0"); + // e' positivo } else { - bool ok = look_lim(previous_month(month)); - if (!ok || !_lim->get_bool("B0")) - { - if (_recalc != needed) - { - describe_error("Ricalcolo non eseguito: possibili errori " - "credito precedente","ALL"); - } - else - { - update_firm(previous_month(month), FALSE); - look_lim(previous_month(month)); - } - } - // toglie il rimborso chiesto - c = _lim->get_real("R0") + _lim->get_real("R1"); - // e le eventuali rettifiche - real rett = _lim->get_real("R5"); - c += rett; - // e le ulteriori detrazioni - real detr = _lim->get_real("R6"); - c -= detr; + c = result_liq(previous_month(month)); + if (c.sign() < 0) c = abs(c); + else c = real(0.0); } - look_lim(month); - - if (c.sign() < 0) c = abs(c); - else c = real(0.0); + return c; } -real TLiquidazione_app::credito_costo_prec(int month, const char* codatt) +real TLiquidazione_app::credito_costo_prec(int month) // ritorna l'appropriato credito di costo precedente al mese in corso // (travel agency only) { - real c = 0.0; + real c(0.0); if (is_first_month(month)) { - int yr = atoi(_year) - 1; + int yr = atoi(_year)-1; _lim->zero(); *_lim_anno = yr; *_lim_mese = 12; - if (_lim->read() == NOERR) c = _lim->get_real("R2"); + if (_lim->read() == NOERR) + c = _lim->get_real("R2"); } else { - bool ok = look_lim(previous_month(month)); - if (!ok || !_lim->get_bool("B0")) - { - if (_recalc != needed) - { - describe_error("Ricalcolo non eseguito: possibili errori " - "credito di costo","ALL"); - } - else - { - // Super Prassi a questo punto vorrebbe una update_firm - update_att(previous_month(month), codatt, FALSE); - look_lim(previous_month(month)); - } - } + if (look_lim(previous_month(month))) // qui il rimborso non c'e' - c = _lim->get_real("R2"); + c = _lim->get_real("R2"); } look_lim(month); return c; @@ -472,13 +437,19 @@ real TLiquidazione_app::credito_costo_prec(int month, const char* codatt) real TLiquidazione_app::versamenti_IVA(int month, bool acconto) -{ +{ + // se month e' 12 e acconto == TRUE somma anche + // l'eventuale acconto versato a dicembre real ret(0.0); - int typ = acconto ? 7 : 1; - - if (look_del(month,typ)) + + if (look_del(month,1)) if (_del->get_bool("B0")) // solo se stampata ret = _del->get_real("R0") + _del->get_real("R1"); + + if (month == 12 && acconto) + if (look_del(month,7)) + if (_del->get_bool("B0")) // solo se stampata + ret += _del->get_real("R0") + _del->get_real("R1"); return ret; } @@ -496,6 +467,6 @@ real TLiquidazione_app::interesse_trimestrale(int month) { month /= 3; month--; TConfig cnf(CONFIG_STUDIO); - real r = cnf.get("InTr", NULL, month); + real r(cnf.get("InTr", NULL, month)); return r; -} +} \ No newline at end of file diff --git a/cg/cg4303.cpp b/cg/cg4303.cpp index 29e5b344a..28229325b 100755 --- a/cg/cg4303.cpp +++ b/cg/cg4303.cpp @@ -17,23 +17,14 @@ void TLiquidazione_app::add_plafond(int month, const char* codatt, int type, real r1 = _ppa_r->get_real("R1"); real r2 = _ppa_r->get_real("R2"); - if (intra) - r1 += howmuch; - else - r0 += howmuch; + if (intra) r1 += howmuch; + else r0 += howmuch; if (r2 < (r0+r1)) - { describe_error("Acquisti in eccesso rispetto al plafond disponibile", att.cut(5)); - } - // r2 -= (r0+r1); - // if (r2.sign() < 0) r2 = 0.0; - _ppa_r->put("R0",r0); _ppa_r->put("R1",r1); - // _ppa_r->put("R2",r2); - _ppa->rewrite(); } @@ -128,62 +119,61 @@ void TLiquidazione_app::recalc_ventilation(int month, const char* codatt) TString att(codatt); // 1) ricalcola i pim dei mesi dal primo al corrente se necessario + recalc rcl = _recalc; + _recalc = needed; for (int m = 1; m < month; m++) - if (is_month_ok(m)) update_att(m,codatt, FALSE); - + update_att(m,codatt, FALSE); + _recalc = rcl; + _vent_arr.destroy(); for (m = 1; m <= month; m++) { - if (is_month_ok(m)) + // aggiunge gli acquisti del mese m operando sui pim + for (_pim->first(); !_pim->eof(); _pim->next()) { - // aggiunge gli acquisti del mese m operando sui pim - for (_pim->first(); !_pim->eof(); _pim->next()) + // se e' acquisto beni per rivendita + int tipocr = atoi(*_pim_tipocr); + int mese = atoi(*_pim_mese); + int tipodet = atoi(*_pim_tipodet); + + /* + * se non si e' settato il ricalcolo nei parametri ditta + * considera soltanto quelli con detraibilita' == 3 + * (passaggi interni) + * sensu Scudler 1994 + */ + if (!_isricacq && tipodet != 3) + continue; + + /* + * caso particolare SENSU Vladimiro (1995) #MI3001 + * questi vengono pero' conteggiati nel totale + * acquisti per rivendita + */ + if (tipocr == 5 && tipodet == 3) + continue; + + TString att(codatt); + if (tipocr == 1 && mese == m && + att == (const char*)(*_pim_codatt)) { - // se e' acquisto beni per rivendita - int tipocr = atoi(*_pim_tipocr); - int mese = atoi(*_pim_mese); - int tipodet = atoi(*_pim_tipodet); - - /* - * se non si e' settato il ricalcolo nei parametri ditta - * considera soltanto quelli con detraibilita' == 3 - * (passaggi interni) - * sensu Scudler 1994 - */ - if (!_isricacq && tipodet != 3) - continue; - - /* - * caso particolare SENSU Vladimiro (1995) #MI3001 - * questi vengono pero' conteggiati nel totale - * acquisti per rivendita - */ - if (tipocr == 5 && tipodet == 3) - continue; - - TString att(codatt); - if (tipocr == 1 && mese == m && - att == (const char*)(*_pim_codatt)) - - { - look_iva(*_pim_codiva); + look_iva(*_pim_codiva); - // soltanto normali ed esenti IVA sono base di riparto - if (_iva->get("S1").empty() || _iva->get("S1") == "ES") + // soltanto normali ed esenti IVA sono base di riparto + if (_iva->get("S1").empty() || _iva->get("S1") == "ES") + { + real lurd = _pim->get_real("R0"); + lurd += _pim->get_real("R1"); + real perc = _iva->get_real("R0"); + TString other = _iva->get("S6"); + if (!other.empty()) { - real lurd = _pim->get_real("R0"); - lurd += _pim->get_real("R1"); - real perc = _iva->get_real("R0"); - TString other = _iva->get("S6"); - if (!other.empty()) - { - // ventila a un altro codice - look_iva(other); - perc = _iva->get_real("R0"); - } - add_ventilation(perc / CENTO, lurd, *_pim_codiva); + // ventila a un altro codice + look_iva(other); + perc = _iva->get_real("R0"); } + add_ventilation(perc / CENTO, lurd, *_pim_codiva); } } } diff --git a/cg/cg4304.cpp b/cg/cg4304.cpp index fe4257858..fde34198b 100755 --- a/cg/cg4304.cpp +++ b/cg/cg4304.cpp @@ -67,11 +67,11 @@ bool TLiquidazione_app::preprocess_page(int file, int cnt) // Print description // ---------------------------------------------------------------- -void TLiquidazione_app::describe_att(int month, const char* codatt) +void TLiquidazione_app::describe_att(int month, const char* codatt, bool isresult) { TToken_string atts(codatt); - if (_isprint) + if (_isprint && _canprint) { describe_name(month, atts); if (atts.items() == 1 && _isplafond) @@ -82,7 +82,8 @@ void TLiquidazione_app::describe_att(int month, const char* codatt) describe_agricolo(month, codatt); if (atts.items() == 1 && _isviaggio) describe_viaggio(month, codatt); - describe_pims(month,codatt); + if (isresult) + describe_pims(month,codatt); if (atts.items() == 1) describe_consistence(codatt); } @@ -109,7 +110,7 @@ void TLiquidazione_app::describe_name(int month, TToken_string& codatts) void TLiquidazione_app::describe_firm(int month) { - if (!_isprint) return; + if (!_isprint || !_canprint) return; _DescrItem* d = new _DescrItem(SET_FIRM); @@ -123,7 +124,6 @@ void TLiquidazione_app::describe_firm(int month) void TLiquidazione_app::describe_plafond(int month, const char* codatt) { - if (month == 13) month = 12; // prepara la descrizione del riepilogo da stampare e lo accoda real t1, t2, t3; _DescrItem* d = new _DescrItem(PLAFOND); @@ -131,23 +131,27 @@ void TLiquidazione_app::describe_plafond(int month, const char* codatt) for (int jj = 1; jj <= 3; jj++) // three types of plafond { t1 = 0.0; t2 = 0.0; t3 = 0.0; - for (int m = 1; m <= month; m++) + for (int m = 1; m <= month && m < 13; m++) { - if (!is_month_ok(m)) continue; - - if (look_ppa(m,codatt,jj)) + if (is_month_ok(m,month) && look_ppa(m,codatt,jj)) { - t1 = _ppa->get_real("R0"); - t2 = _ppa->get_real("R1"); - t3 = _ppa->get_real("R2"); + t1 += _ppa->get_real("R0"); + t2 += _ppa->get_real("R1"); + t3 = _ppa->get_real("R2"); } } switch (jj) { - case 1: d->_r0 = t1; d->_r1 = t2; d->_r2 = t3; break; - case 2: d->_r3 = t1; d->_r4 = t2; d->_r5 = t3; break; - case 3: d->_r6 = t1; d->_r7 = t2; d->_r8 = t3; break; - } + case 1: + d->_r0 = t1; d->_r1 = t2; d->_r2 = t3; + break; + case 2: + d->_r3 = t1; d->_r4 = t2; d->_r5 = t3; + break; + case 3: + d->_r6 = t1; d->_r7 = t2; d->_r8 = t3; + break; + } } // for tipo esenzione plafond _descr_arr.add(d); @@ -212,7 +216,7 @@ void TLiquidazione_app::describe_ventilation(int month, const char* codatt) d->_arr.add(vd); } } - else if (check_month(mese,month) && corrisp + else if (is_month_ok(mese,month) && corrisp && _pim->get_bool("B1") && tipocr == 0 && tipomov == vendita) // non sono sicurissimo della above condition @@ -243,18 +247,13 @@ void TLiquidazione_app::describe_ventilation(int month, const char* codatt) void TLiquidazione_app::describe_agricolo(int month, const char* codatt) { - if (month != 13) - if (!(look_plm(month, codatt) && look_ptm(month,codatt))) - return; - _DescrItem* d = new _DescrItem(REGAGR); - for (int mese = 1; mese <= month; mese++) + for (int mese = 1; mese <= month && mese < 13; mese++) { - if (mese == 13) - break; - if (month != 13 && mese != month) + if (!(_isannual || _isriepilogo) && !is_month_ok(mese,month)) continue; + if (!(look_plm(mese, codatt) && look_ptm(mese,codatt))) continue; @@ -266,27 +265,21 @@ void TLiquidazione_app::describe_agricolo(int month, const char* codatt) d->_r5 += _plm->get_real("R1"); // IVA vendite rimasta d->_r6 += _ptm->get_real("R4") + _ptm->get_real("R12") + _ptm->get_real("R9"); // IVA acq. ammortizzabili - } - + } _descr_arr.add(d); } void TLiquidazione_app::describe_viaggio(int month, const char* codatt) { - if (month != 13) - if (!(look_plm(month, codatt) && look_lim(month))) - return; + if (month != 13 && !look_lim(month)) + return; _DescrItem* d = new _DescrItem(REGVIA); - for (int mese = 1; mese <= month; mese++) + for (int mese = 1; mese <= month && mese < 13; mese++) { - if (mese == 13) - break; - if (!check_month(mese,month)) - continue; - if (!(look_plm(mese, codatt) && look_lim(mese))) - continue; + if (!is_month_ok(mese,month) || !look_plm(mese, codatt)) + continue; d->_r0 += _plm->get_real("R5"); // corrispettivi CEE d->_r1 += _plm->get_real("R9"); // corrispettivi misti CEE @@ -295,11 +288,11 @@ void TLiquidazione_app::describe_viaggio(int month, const char* codatt) d->_r4 += _plm->get_real("R10"); // acquisti misti parte CEE d->_r5 += _plm->get_real("R8"); // acquisti fuori CEE d->_r6 += _plm->get_real("R11"); // acquisti misti parte fuori CEE - // questa e' sempre quella dell'ultimo mese - d->_r7 = _lim->get_real("R4"); // percentuale di ripartizione } + + d->_r7 = _lim->get_real("R4"); // perc. ripartizione // credito di costo precedente (CHECK annuale) - d->_r8 = credito_costo_prec(_isriepilogo || _isannual ? 12 : mese, codatt); + d->_r8 = credito_costo_prec(_isriepilogo || _isannual ? 12 : mese); // calcolera' imposte e crediti solo se e' annuale vera d->_f1 = _isriepilogo && !_isannual; @@ -360,7 +353,7 @@ void TLiquidazione_app::describe_pims(int month, const char* codatt) continue; if (strcmp((const char*)*_pim_codatt, att) == 0 && - check_month(atoi(*_pim_mese),month) && + is_month_ok(atoi(*_pim_mese),month) && _year == (const char*)*_pim_anno) { // vedi se c'e' gia' un item corrispondente @@ -371,13 +364,36 @@ void TLiquidazione_app::describe_pims(int month, const char* codatt) d->_s0 == ref && d->_s1 == (const char*)*_pim_codiva) break; + if (d->_s1 > (const char*)*_pim_codiva) + { + isnew = TRUE; + _DescrItem* dd = new _DescrItem(PIM_ROW); + // CiccioPrassi li vuole in ordine crescente + _descr_arr.insert(dd,i); + // che cazzo di due marroni: se quello dopo + // era il primo, quello prima e' dopo + if (d->_f0) + { + dd->_f0 = TRUE; + d->_f0 = FALSE; + } + else if (isfirst) + { + d->_f0 = TRUE; + isfirst = FALSE; + } + d = dd; + break; + } } - if (i == _descr_arr.items()) + if (!isnew && i == _descr_arr.items()) { isnew = TRUE; d = new _DescrItem(PIM_ROW); + if (isfirst) { d->_f0 = TRUE; isfirst = FALSE; } + _descr_arr.add(d); } - + if (tipomov == acquisto) { d->_r4 += _pim->get_real("R0"); @@ -426,13 +442,7 @@ void TLiquidazione_app::describe_pims(int month, const char* codatt) { d->_s0 = ref; d->_s1 = *_pim_codiva; - _descr_arr.add(d); // flag per stampare l'intestazione colonne - if (isfirst) - { - d->_f0 = TRUE; - isfirst = FALSE; - } } } } @@ -465,7 +475,7 @@ void TLiquidazione_app::describe_pims(int month, const char* codatt) for (int m = 1; m <= month && m < 13; m++) { - if (!is_month_ok(m) || !check_month(m,month)) continue; + if (!is_month_ok(m,month) && !(_isannual || _isriepilogo)) continue; atts.restart(); while ((tmpatt = atts.get()) != NULL) @@ -563,7 +573,7 @@ void TLiquidazione_app::describe_pims(int month, const char* codatt) void TLiquidazione_app::describe_liq(int month, const char* codatts, _DescrItem* di) { - if (!_isprint) return; + if (!_isprint || !_canprint) return; if (_isannual || _isriepilogo) month = 12; _DescrItem* d = new _DescrItem(THE_END); @@ -578,12 +588,16 @@ void TLiquidazione_app::describe_liq(int month, const char* codatts, while ((tmpatt = atts.get()) != NULL) { TString att(tmpatt); - look_plm(month, att); - d->_r0 += _plm->get_real("R0"); // IVA vendite - d->_r1 += _plm->get_real("R1"); // IVA acquisti - d->_r2 += _plm->get_real("R3"); // Detrazioni 1 - d->_r2 += _plm->get_real("R4"); // Detrazioni 2 - d->_r1 -= _plm->get_real("R2"); // pro-rata + for (int mm = 1; mm <= 12; mm++) + { + if (!is_month_ok(mm, month)) continue; + look_plm(mm, att); + d->_r0 += _plm->get_real("R0"); // IVA vendite + d->_r1 += _plm->get_real("R1"); // IVA acquisti + d->_r2 += _plm->get_real("R3"); // Detrazioni 1 + d->_r2 += _plm->get_real("R4"); // Detrazioni 2 + d->_r1 -= _plm->get_real("R2"); // pro-rata + } // ev. conguaglio prorata if (_isannual || _isriepilogo) { @@ -592,8 +606,10 @@ void TLiquidazione_app::describe_liq(int month, const char* codatts, } } look_lim(month); + d->_r3 += _lim->get_real("R0"); // risultato d->_r4 += _lim->get_real("R1"); // rimborso + if (_lim->get("S7") == "D") d->_r5 += abs(_lim->get_real("R5")); // rettifiche a debito else @@ -676,7 +692,8 @@ void TLiquidazione_app::describe_consistence(const char* codatt) void TLiquidazione_app::describe_error(const char* err, const char* codatt) -{ +{ + if (!_isprint || !_canprint) return; _errors.add(new _ErrItem(err,codatt,_nditte->curr().get("CODDITTA"))); } @@ -717,9 +734,9 @@ void TLiquidazione_app::set_firm(_DescrItem& d) { _ErrItem& s = (_ErrItem&)_errors[i]; if (s._att == "ALL" && s._firm == d._s0) - { j++; set_row(i+10, "@5g@b*** %s ***@r", (const char*)s._err); } + { j++; set_row(i+3, "@5g@b*** %s ***@r", (const char*)s._err); } } - if (j) set_auto_ff(TRUE); + if (j) set_row(i+3,""); } @@ -750,7 +767,7 @@ void TLiquidazione_app::set_att(_DescrItem& d) TString tipatt; if (d._f0 > 0) - tipatt.format("(att. %d)", d._f0); + tipatt.format(d._f0 == 1 ? "SERVIZI" : "ALTRE ATTIVITA'"); if (d._s3.empty()) { @@ -905,6 +922,7 @@ void TLiquidazione_app::set_plm(_DescrItem& d) &tot2); } + void TLiquidazione_app::set_ptm(_DescrItem& d) { @@ -938,6 +956,7 @@ void TLiquidazione_app::set_ptm(_DescrItem& d) } if (!(spgn.is_zero() && spgn_iva.is_zero())) { + printed = TRUE; set_row(row++, "Spese generali@50g%r@69g%r", &spgn, &spgn_iva); @@ -959,7 +978,7 @@ void TLiquidazione_app::set_ptm(_DescrItem& d) &(d._r3), &rn); } - if (d._f0 && !(d._r11.is_zero())) + if (d._f0) { printed = TRUE; set_row(row++, "%% PRO-RATA ed IVA non detraibile (%s%%)@69g%r", @@ -1048,8 +1067,6 @@ void TLiquidazione_app::set_grand(_DescrItem& d) set_row(rw++,"@11gRISULTATO@58g%r", &rc); - // TBI versamenti integrativi e non, e chissa' cos'altro - real iva = rd - rc; char how = iva.sign() < 0 ? 'c' : 'd'; iva = abs(iva); @@ -1302,7 +1319,6 @@ void TLiquidazione_app::set_viaggio(_DescrItem& d) "RELATIVI A VIAGGI MISTI"); set_row(18,""); - // la bella frazioncina della percentuale di ripartizione TString tmp(d._r4.string(REAL_PICTURE)); tmp.ltrim(); TString up = tmp; @@ -1313,7 +1329,7 @@ void TLiquidazione_app::set_viaggio(_DescrItem& d) int ln = max(up.len(), dn.len()) + 2; TString den(ln); den.fill('-'); up.center_just(ln); dn.center_just(ln); - real rip = d._r7 * CENTO; rip.round(2); + real rip = d._r7; rip.round(2); // la bella frazioncina degli imponibili viaggi misti TString tmp2 = d._r1.string(REAL_PICTURE); tmp2.ltrim(); @@ -1331,7 +1347,7 @@ void TLiquidazione_app::set_viaggio(_DescrItem& d) int rem2 = pos1+ den.len() + 11; int pos2 = rem2 + 20; - real cim = d._r1 * d._r7; cim.round(ROUND_LIRA); + real cim = (d._r1 * d._r7)/CENTO; cim.round(ROUND_LIRA); set_row(19,format("@%dg%%t@%dg%%t", pos1, pos2), &up, &up2); @@ -1355,20 +1371,20 @@ void TLiquidazione_app::set_viaggio(_DescrItem& d) &up, &den, &tmr); // se e' l'annuale non ha senso altro - if (d._f1) return; + // if (d._f1) return; - tmr = d._r3 + d._r4; + real tma = d._r3 + d._r4; tmp = d._r3.string(REAL_PICTURE); tmp.ltrim(); up = "("; up << tmp << " + "; tmp = d._r4.string(REAL_PICTURE); tmp.ltrim(); up << tmp << ")"; den.fill('.',59-up.len()); set_row(24,"Ammontare dei costi deducibili@40g%t %t@100g%r", - &up, &den, &tmr); + &up, &den, &tma); den.fill('.',60); set_row(25,"Credito di costo precedente @40g%t@100g%r", &den, &(d._r8)); - real bil = d._r0 - tmr - d._r8; + real bil = tmr - tma - d._r8; bool iscred = bil.sign() < 0; bil = abs(bil); @@ -1389,12 +1405,11 @@ void TLiquidazione_app::set_viaggio(_DescrItem& d) iscred ? "CREDITO DI COSTO " : "Base imponibile lorda", &up, &den, &bil); } - else + else if (bil.sign() > 0) { real aliva = aliquota_agvia(); - real dovuta = bil - (bil / (aliva+real(1.0))); - dovuta.ceil(ROUND_LIRA); - aliva *= 100.0; + real dovuta = (bil/((aliva+CENTO)/CENTO)) * (aliva/CENTO); + dovuta.round(ROUND_LIRA); tmp = bil.string(REAL_PICTURE); tmp.ltrim(); up = tmp; diff --git a/cg/cg4305.cpp b/cg/cg4305.cpp index 36cdd0985..059a8cdc0 100755 --- a/cg/cg4305.cpp +++ b/cg/cg4305.cpp @@ -15,6 +15,7 @@ bool TLiquidazione_app::set_deleghe() { TMask m("cg4300b.msk"); + m.field(FLD_CGB_YEAR).set(_year); m.field(FLD_CGB_YEAR).set_handler(ch_year_handler); int k = 0; @@ -61,8 +62,6 @@ bool TLiquidazione_app::set_deleghe() bool TLiquidazione_app::extract_deleghe() { char buf[256]; - - long firm = TApplication::get_firm(); _prind = new TProgind(_calcall ? _n_ditte : _selected.ones(), " Estrazione deleghe \n" " preparazione archivi \n " @@ -83,16 +82,19 @@ bool TLiquidazione_app::extract_deleghe() _nditte->curr().put("CODDITTA",_ditte->row(l).get(1)); _nditte->read(); + // must succeed + look_lia(); + _freqviva = _lia->get("S7"); + sprintf (buf,"Estrazione deleghe (%d):\nditta %s\n ", _month, (const char*)_nditte_r->get("RAGSOC")); _prind->set_text(buf); - if (is_month_ok(_month)) + if (is_month_ok_strict(_month)) { _isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74/4"); - _freqviva = look_lia() ? _lia->get("S7") : _nditte->curr().get("FREQVIVA"); bool mens = _freqviva == "M"; _isannual = (_month == 12 && !mens && !_isbenzinaro) || (_month == 13 && (mens || _isbenzinaro)); @@ -103,7 +105,7 @@ bool TLiquidazione_app::extract_deleghe() _prind->addstatus(1); } - TApplication::set_firm(firm); + TApplication::set_firm(__firm); delete _prind; return TRUE;