From a2de8ed91a91bfe9aa1479ad2207220e7f7d2f85 Mon Sep 17 00:00:00 2001 From: bonazzi Date: Mon, 5 Sep 2016 22:01:25 +0000 Subject: [PATCH] Patch level : 10.0 278 Files correlati : cg4.exe cg5.exe cg5300a.uml cg5500b.uml cg5500d.uml cg5500a.rep cg5500b.rep Ricompilazione Demo : [ ] Commento : MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modifiche al prospetto della liquidazione iva. Implementare la gestione del credito iva infrannuale e modifiche a quello dell'anno precedente. Aggiunta stampa dei prospetti di liquidazione. Considerato il credito utilizzato a inizio anno come utilizzato e solo se il credito è compensabile in F24 a Gennaio. In realtà era già così git-svn-id: svn://10.65.10.50/branches/R_10_00@23221 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg4300.cpp | 107 +- cg/cg4300.h | 63 +- cg/cg4301.cpp | 397 +-- cg/cg4302.cpp | 2142 +++++++-------- cg/cg4303.cpp | 7 +- cg/cg4304.cpp | 6884 ++++++++++++++++++++++++------------------------ cg/cg4305.cpp | 612 +---- cg/cg5300.cpp | 54 - cg/cg5300a.h | 1 + cg/cg5300a.uml | 32 +- cg/cg5500.cpp | 647 +++-- cg/cg5500.h | 13 +- cg/cg5500a.h | 65 +- cg/cg5500a.rep | 197 ++ cg/cg5500b.rep | 129 + cg/cg5500b.uml | 102 +- cg/cg5500d.uml | 33 + 17 files changed, 5890 insertions(+), 5595 deletions(-) create mode 100644 cg/cg5500a.rep create mode 100644 cg/cg5500b.rep diff --git a/cg/cg4300.cpp b/cg/cg4300.cpp index 0db0ce13d..e838889e6 100755 --- a/cg/cg4300.cpp +++ b/cg/cg4300.cpp @@ -114,11 +114,13 @@ bool TLiquidazione_app::user_create() #ifdef DBG else if (argv(2)[1] == 'C') { - subj = "2012|12|9058|R|12-12-2012|c:/Temp/110|X|60"; + subj = "2016|9|1|R|01-01-2016|c:/Temp/110|X|60"; _is_interactive = false; } #endif + open_files(LF_TAB, LF_TABCOM, LF_NDITTE, LF_MOV, LF_ATTIV, LF_CLIFO, LF_OCCAS, LF_RMOV, LF_RMOVIVA, + LF_COMUNI, LF_ANAG, LF_UNLOC, LF_CAUSALI, LF_RMOVIVA, LF_INDLIB, 0); TProgress_monitor pnd(3, TR("Preparazione archivi"), false); @@ -194,13 +196,11 @@ bool TLiquidazione_app::user_create() _ppa = new TTable("PPA"); _plm = new TTable("PLM"); _pia = new TTable("PIA"); - _lim = new TTable("LIM"); _lam = new TTable("LAM"); _pla = new TTable("%PLA"); _reg = new TTable("REG"); _iva = new TTable("%IVA"); _del = new TTable("%DEL"); - _lia = new TTable("%LIA"); _mov = &_cur->file(LF_MOV); _rmoviva = &_cur->file(LF_RMOVIVA); @@ -218,7 +218,6 @@ bool TLiquidazione_app::user_create() _pom_r = &(_pom->curr()); _iva_r = &(_iva->curr()); _del_r = &(_del->curr()); - _lim_r = &(_lim->curr()); _lam_r = &(_lam->curr()); _pla_r = &(_pla->curr()); _ppa_r = &(_ppa->curr()); @@ -294,8 +293,6 @@ bool TLiquidazione_app::user_create() _del_mese = new TRecfield(*_del_r,"CODTAB",9,10); _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); _lam_anno = new TRecfield(*_lam_r,"CODTAB",0,3); _lam_mese = new TRecfield(*_lam_r,"CODTAB",4,6); @@ -314,13 +311,13 @@ bool TLiquidazione_app::user_create() TApplication::set_firm(__firm); set_real_picture(REAL_PICTURE); - set_magic_currency(TRUE); + set_magic_currency(true); if (!_is_interactive) { TTemp_window w(TASK_WIN); if (_recalc_only) - _isprint = FALSE; + _isprint = false; //else printer().set_export_file(filename, is_header, headerlen); else printer().set_export_file(filename, is_header); @@ -330,7 +327,9 @@ bool TLiquidazione_app::user_create() _recalc = nocalc ? never : needed; TApplication::set_firm(ditta); - if (!look_lia()) + const TRectype & lia = get_lia(); + + if (lia.empty()) return false; TIva_round ir; // Imposta arrotondamento iva @@ -339,7 +338,7 @@ bool TLiquidazione_app::user_create() _nditte->zero(); _nditte_r->put("CODDITTA", ditta); _nditte->read(); - _freqviva = _lia->get("S7"); + _freqviva = lia.get("S7"); TRectype& mov = _cur->curr(); TRectype from(_cur->curr()); from.zero(); @@ -359,7 +358,9 @@ bool TLiquidazione_app::user_create() bool need_refresh = false; for (int m = 1; m < _month; m++) { - if (is_month_ok_strict(m) && (!look_lim(m) || !_lim->get_bool("B0"))) + const TRectype & lim = get_lim(m) ; + + if (is_month_ok_strict(m) && !lim.get_bool("B0")) { need_refresh = true; break; @@ -399,12 +400,17 @@ 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 (int m = _month+1; m <= 13; m++) if (look_lim(m)) - { - _lim->zero("B0"); - _lim->rewrite(); - break; - } + for (int m = _month+1; m <= 13; m++) + { + TRectype lim = get_lim(m); + + if (lim.not_empty()) + { + lim.zero("B0"); + put_lim(lim); + break; + } + } } TApplication::set_firm(__firm); @@ -467,8 +473,6 @@ bool TLiquidazione_app::user_destroy() delete _pom_codatt; delete _pom_anno; delete _pom_mese; - delete _lim_anno; - delete _lim_mese; delete _lam_anno; delete _lam_mese; delete _pla_anno; @@ -489,7 +493,6 @@ bool TLiquidazione_app::user_destroy() delete _ppa; delete _plm; delete _pia; - delete _lim; delete _lam; delete _pla; delete _del; @@ -523,9 +526,9 @@ bool TLiquidazione_app::set_print(int) break; /* case 2: // estrazione deleghe - _isprint = FALSE; + _isprint = false; _selected.reset(); - _ditte->check(-1, FALSE); + _ditte->check(-1, false); build_ditte_sheet(all); while (set_deleghe()) { @@ -540,10 +543,10 @@ bool TLiquidazione_app::set_print(int) */ case 3: // calcolo acconto { - _isprint = TRUE; + _isprint = true; _month = 12; _selected.reset(); - _ditte->check(-1, FALSE); + _ditte->check(-1, false); build_ditte_sheet(all); real inf; real ina; // cotale obbrobrio non fu da me cercato, ne' mai condiviso while (set_acconto(inf, ina)) @@ -561,6 +564,7 @@ bool TLiquidazione_app::set_print(int) break; } return false; + } long TLiquidazione_app::select_firm_range(long from, long to, wht freq) @@ -586,7 +590,7 @@ long TLiquidazione_app::select_firm_range(long from, long to, wht freq) } else { - _selected.set(i,FALSE); + _selected.set(i,false); _ditte->uncheck(i); } } @@ -618,33 +622,26 @@ void TLiquidazione_app::build_nomiditte() for (dt.first(); !dt.eof(); dt.next()) { - // check no archivi - bool good = prefix().exist(dt.get_long("CODDITTA")); + if (prefix().exist(dt.get_long("CODDITTA"))) // check no archivi + { + const TRectype & lia = get_lia(dt.get_long("CODDITTA")); + TToken_string d(63); - if (good) - { - // check no parametri liquidazione - good = look_lia(dt.get_long("CODDITTA")); - } - else - continue; - - TToken_string* d = new TToken_string(63); - - // add record - d->add(dt.get("CODDITTA")); - d->add(dt.get("RAGSOC")); - if (good) - { - d->add(_lia->get("S7")); - d->add(_lia->get("B5")); // IVA per cassa - } - else - { - d->add("??"); - d->add("??"); - } - _nomiditte.add(d); + // add record + d.add(dt.get("CODDITTA")); + d.add(dt.get("RAGSOC")); + if (lia.not_empty()) + { + d.add(lia.get("S7")); + d.add(lia.get("B5")); // IVA per cassa + } + else + { + d.add("??"); + d.add("??"); + } + _nomiditte.add(d); + } } } @@ -797,7 +794,7 @@ bool TLiquidazione_app::chk_final_handler(TMask_field& f, KEY key) void TLiquidazione_app::reset_choices(TMask& m) { _selected.reset(); - _ditte->check(-1, FALSE); + _ditte->check(-1, false); if (m.source_file().ends_with("cg4300a.msk")) { const long ditta = get_firm(); @@ -805,9 +802,11 @@ void TLiquidazione_app::reset_choices(TMask& m) m.set(CG43_FLD_DTO, ditta, 0x2); wht freq = all; - if (look_lia(ditta, false, m.get_int(CG43_FLD_ANNO))) + const TRectype & lia = get_lia(ditta, false, m.get_int(CG43_FLD_ANNO)); + + if (lia.not_empty()) { - freq = _lia->get_char("S7") == 'T' ? trimestre : mnt; + freq = lia.get_char("S7") == 'T' ? trimestre : mnt; if (m.get_int(CG43_RDB_VERS) != freq) m.set(CG43_RDB_VERS, freq, 0x3); } diff --git a/cg/cg4300.h b/cg/cg4300.h index 2975d1194..256c4ae95 100755 --- a/cg/cg4300.h +++ b/cg/cg4300.h @@ -169,7 +169,7 @@ public: _r20, _r21, _r22, _r23, _r24, _r25, _r26, _r27, _r28, _r29, _r30, _r31, _r32, _r33; TArray _arr; - TDate _d0; + TDate _d0, _d1; real _diff_ven_ap, _diff_ven_ap_iva, _diff_acq_ap, _diff_acq_ap_iva; _DescrItem(word f) : _flags(f), _f0(0), _f1(0), _f2(0) { } @@ -326,14 +326,12 @@ class TLiquidazione_app : public TPrint_application TTable* _pom; TTable* _plm; TTable* _pia; - TTable* _lim; TTable* _lam; TTable* _pla; TTable* _ppa; TTable* _reg; TTable* _iva; TTable* _del; - TTable* _lia; // a reference rectype per file/table TRectype* _mov_r; @@ -354,7 +352,6 @@ class TLiquidazione_app : public TPrint_application TRectype* _plm_r; TRectype* _pia_r; TRectype* _ppa_r; - TRectype* _lim_r; TRectype* _lam_r; TRectype* _del_r; TRectype* _att_r; @@ -418,8 +415,6 @@ class TLiquidazione_app : public TPrint_application TRecfield* _del_anno; TRecfield* _del_mese; TRecfield* _del_tipo; - TRecfield* _lim_anno; - TRecfield* _lim_mese; TRecfield* _lam_anno; TRecfield* _lam_mese; @@ -468,8 +463,8 @@ public: bool recalc_all(); // ricalcolo progressivi mese - bool update_firm (int month, bool recalc = TRUE); - bool update_att (int month, const char* codatt, bool recalc = TRUE); + bool update_firm (int month, bool recalc = true); + bool update_att (int month, const char* codatt, bool recalc = true); void zero_att (int month, const char* codatt); void zero_annual (int month); void recalc_att (int month, const char* codatt); @@ -482,8 +477,8 @@ public: // Scorre tutti i PIM della ditta, per completare _iva11_arr prima di chiamare write_IVA11() void iva11_set_arr_phase_2 (const TString& codatt); // Scrive per la ditta/attivita' corrente, i dati relativi al trasferimento IVA11 - // Se viene passato TRUE come parametro, azzera i campi R1 ed R2. - void iva11_write (bool reset_r1r2 = FALSE); + // Se viene passato true come parametro, azzera i campi R1 ed R2. + void iva11_write (bool reset_r1r2 = false); // ricalcolo liquidazioni dai progressivi mensili void write_liq (int month, const char* atts); @@ -500,8 +495,8 @@ public: real credito_costo_prec(int month); // ritorna i versamenti effettuati nel mese per // i tipi delega passati (stile tokenstring) sommando - // gli interessi se interesse = TRUE - real versamenti_IVA(int month, const char* types, bool interesse = FALSE); + // gli interessi se interesse = true + real versamenti_IVA(int month, const char* types, bool interesse = false); // Ritorna il valore dell'iva da riportare (solitamente 50500) real iva_da_riportare(int month); @@ -596,31 +591,33 @@ public: void set_liqacc_2000(_DescrItem& d); // Utility per stampare nella colonna debito o credito - void print_importo(int rw, const char* prompt, real imp, bool red = FALSE); + void print_importo(int rw, const char* prompt, real imp, bool red = false); // cercapalle in tabelle con opzione di creazione se serve bool look_pim(int m, const char* a, const char* r, const char* cr, - const char* i, int tipodet = 0, bool create = FALSE); + const char* i, int tipodet = 0, bool create = false); bool look_pis(int m, const char* a, const char* r, const char* cr, - const char* i, int tipodet = 0, bool create = FALSE); + const char* i, int tipodet = 0, bool create = false); bool look_prm(int m, const char* a, const char* r, const char* cr, - const char* i, int tipodet = 0, bool create = FALSE); + const char* i, int tipodet = 0, bool create = false); bool look_prp(int m, const char* a, const char* r, const char* cr, - const char* i, int tipodet = 0, bool create = FALSE); - bool look_pum(int m, const char* a, bool create = FALSE); - bool look_pam(int m, const char* a, bool create = FALSE); + const char* i, int tipodet = 0, bool create = false); + bool look_pum(int m, const char* a, bool create = false); + bool look_pam(int m, const char* a, bool create = false); bool look_pem(TTable & pem, int codreg); - bool look_pom(int m, const char* a, bool create = FALSE); - bool look_plm(int m, const char* a, bool create = FALSE); - bool look_pia(int m, const char* a, const char* cod1, const char* cod2, bool create = FALSE); - bool look_lim(int m, bool create = FALSE); - bool look_lam(int m, bool create = FALSE); - bool look_pla(const char* a, bool create = FALSE); - bool look_ppa(int m, const char* a, int t, bool create = FALSE); - bool look_del(int month, int type, bool create = FALSE); + bool look_pom(int m, const char* a, bool create = false); + bool look_plm(int m, const char* a, bool create = false); + bool look_pia(int m, const char* a, const char* cod1, const char* cod2, bool create = false); + const TRectype & get_lim(int month, bool create = false); + const int put_lim(const TRectype & lim, bool re = true); + bool look_lam(int m, bool create = false); + bool look_pla(const char* a, bool create = false); + bool look_ppa(int m, const char* a, int t, bool create = false); + bool look_del(int month, int type, bool create = false); bool look_iva(const char* cod); bool look_reg(const char* reg); - bool look_lia(long ditta = 0l, bool create = FALSE, int anno = 0); + const TRectype & get_lia(long ditta = 0l, bool create = false, int anno = 0); + const int put_lia(const TRectype & lia, bool re = true); int count_activities() const; @@ -641,7 +638,7 @@ public: // il ricalcolo annuale bool is_month_ok(int x, int mtocalc) const; // is_month_ok_strict controlla che il mese sia OK per la - // liquidazione, ma ritorna TRUE per le trimestrali solo + // 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) const; // questa e' la piu' semplice, per vedere se devo @@ -661,7 +658,7 @@ public: bool set_deleghe(); bool extract_deleghe(); bool extract_delega(int m, TArray& desc); - bool video_conferma(const real&, const real&, const real&, bool to_del = FALSE); + bool video_conferma(const real&, const real&, const real&, bool to_del = false); */ // stampa @@ -679,7 +676,11 @@ public: void set_acconto_p(_DescrItem& d); void set_acchead_p(_DescrItem& d); - real credito_utilizzato(int month, bool iva, bool f24) const; + + const real credito_utilizzato_F24(int month) const; + const real credito_utilizzato_IVA(int month) const; + const real credito_utilizzato(int month) const { return credito_utilizzato_F24(month) + credito_utilizzato_IVA(month);} + const real credito_autorizzato(int month) const; // cippiuppiu' TLiquidazione_app(int men); diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp index a3d9b32b5..2b7aa4123 100755 --- a/cg/cg4301.cpp +++ b/cg/cg4301.cpp @@ -108,11 +108,16 @@ bool TLiquidazione_app::recalc_all() { int m = _month == 13 ? _month : 1; for (; m < _month; m++) - if (is_month_ok_strict(m) && (!look_lim(m) || !_lim->get_bool("B0"))) - { - need_refresh = true; - break; - } + if (is_month_ok_strict(m)) + { + const TRectype & lim = get_lim(m); + + if (lim.empty() || !lim.get_bool("B0")) + { + need_refresh = true; + break; + } + } if (need_refresh && yesno_box(TR("Alcuni mesi precedenti non " "risultano ricalcolati. E' consigliabile il ricalcolo. " @@ -129,11 +134,16 @@ 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->zero("B0"); - _lim->rewrite(); - break; + for (m = _month+1; m <= 13; m++) + { + TRectype lim = get_lim(m); + + if (lim.not_empty()) + { + lim.zero("B0"); + put_lim(lim); + break; + } } _month = save_month; @@ -149,10 +159,10 @@ bool TLiquidazione_app::recalc_all() bool TLiquidazione_app::update_firm(int month, bool recalc) { - // Se recalc e' TRUE considera la necessita' di ricalcolare e le - // opzioni utente. Se FALSE se ne impipa dell'utente e ricalcola + // Se recalc e' true considera la necessita' di ricalcolare e le + // opzioni utente. Se false se ne impipa dell'utente e ricalcola // se necessario (serve nelle chiamate ricorsive) - // Ritorna FALSE soltanto se il ricalcolo era necessario e non e' + // Ritorna false soltanto se il ricalcolo era necessario e non e' // stato effettuato per scelta dello stronzo commercialista. // Gestione IVA differita, da non confondere con _isdifferita @@ -170,18 +180,18 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) } } - look_lim(liq_month(month), true); _isdiffacc = is_acconto_differito(); // Gestione differimento acconto IVA _isdifferita = _isdiffacc; - look_lia(); - _isintr = _freqviva == "T" && !_lia->get_bool("B3"); // was CNF_DITTA->InTrtr - _gest4 = _isbenzinaro && _lia->get_bool("B4"); // was CNF_DITTA->Gest74 + const TRectype & lia = get_lia(); + + _isintr = _freqviva == "T" && !lia.get_bool("B3"); // was CNF_DITTA->InTrtr + _gest4 = _isbenzinaro && lia.get_bool("B4"); // was CNF_DITTA->Gest74 const bool has_single_activity = count_activities() == 1; // controlla che il periodo corrente non sia l'inizio dell'attivita' - // nel caso, differita va a FALSE + // nel caso, differita va a false _monthinatt = 1; const TDate inatt = _nditte->curr().get(NDT_DINIZIOATT); if (is_in_liq_period(inatt)) @@ -193,7 +203,9 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) // ricalcolo normale // lim c'e' solo per i trimestri - bool ok = _lim->get_bool("B0"); + const TRectype & lim = get_lim(liq_month(month), true); + + bool ok = lim.get_bool("B0"); if (ok && !recalc) return true; if (_recalc_regis) @@ -207,8 +219,8 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) TToken_string cattivs; // casini per stampa minchie in coda ai registri - bool riepliq = _isregis ? _riepilogo : FALSE; - bool stliq = TRUE; + bool riepliq = _isregis ? _riepilogo : false; + bool stliq = true; _nditte->save_status(); if (_nditte->is_first_match(LF_ATTIV)) @@ -221,7 +233,7 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) quater = _nditte->curr().get_bool("FLIVA11Q"); // attività mista: ce ne sono in realtà due - // viene calcolato nel ciclo su tipoatt (che viene ripetuto solo se diventa TRUE); + // viene calcolato nel ciclo su tipoatt (che viene ripetuto solo se diventa true); _mixed = false; if (_prind) @@ -369,18 +381,21 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) if (_recalc_regis) { _nditte->restore_status(); + // Se trattasi di ricalcolo per registri, setta il flag relativo, onde evitare ricalcoli // nel caso di registro riepilogativo: se i PRM esistono già (perchè creati // da stampa bollato precedente o altro riepilogo) non vanno ricalcolati. - look_lim(month, TRUE); // Crea se non esiste - _lim->put("B1","X"); - _lim->rewrite(); - return TRUE; + + TRectype lim = get_lim(month, true); // Crea se non esiste + + lim.put("B1","X"); + put_lim(lim); + return true; } // se quater stampa riepilogo if (quater && month == _month && riepliq) - describe_att(month,atts, TRUE, 'Q'); + describe_att(month,atts, true, 'Q'); // occorre poterla chiamare altre volte con mesi diversi _nditte->restore_status(); @@ -415,11 +430,17 @@ bool TLiquidazione_app::update_firm(int month, bool recalc) //describe_liq(_month, atts, _isregis ? NULL : rimb_d); describe_liq(_month, atts, rimb_d); } - if (_month == 13 && look_lim(_month)) // scrive i risultati solo in annuale - { - real r0 = _lim->get_real("R0"); - iva11_write(rimb_d == NULL || r0.sign() >= 0); // scrive su tab1100 at last. - } + if (_month == 13) // scrive i risultati solo in annuale + { + const TRectype & lim = get_lim(_month); + + if (lim.not_empty()) // scrive i risultati solo in annuale + { + const real r0 = lim.get_real("R0"); + + iva11_write(rimb_d == NULL || r0 >= ZERO); // scrive su tab1100 at last. + } + } } //in caso di stampa registri e in caso sia @@ -441,14 +462,14 @@ bool TLiquidazione_app::update_firm(int month, 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 + // 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 (_recalc_regis) - ok = FALSE; // Se sta ricalcolando i PRM/PRP se ne sbatte dei PLM + ok = false; // Se sta ricalcolando i PRM/PRP se ne sbatte dei PLM if (ok && !recalc) return true; bool calc = _recalc == ever || (_recalc == one && is_month_ok(month,_month)); @@ -869,7 +890,7 @@ static bool is_autofattura_articolo_17(const TRectype& mov) 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 +// occhecasino. Se _comp_acconto e' true, i movimenti considerati // saranno solo quelli di dicembre per data <= 20/12; { const bool has_sc = has_module(SCAUT, CHK_DONGLE) && ini_get_bool(CONFIG_DITTA, "cg", "GesSal"); @@ -2119,14 +2140,14 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) } // non sosp_imp ne' altre casistiche che escludono la liq. /* - * se ign == TRUE non bisogna neppure PROGRESSIVARLI + * se ign == true non bisogna neppure PROGRESSIVARLI */ const bool sosp_vaf = sosp_imp == vol_affari; const bool sosp_liq = sosp_imp == liquidazione; bool ign = sosp_imp == normale || (fattrit && month != 13) || noninc; /* - * se liq == FALSE gli importi non contano ai fini + * se liq == false gli importi non contano ai fini * del calcolo liquidazione */ bool liq = !(tipodet == 1 || tipodet == 3 || tipodet == 9 || ign || sosp_vaf); @@ -2252,7 +2273,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) */ if (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC") { - true_corrisp = TRUE; + true_corrisp = true; _pim->put("I0",LORDO); // questi sono corrispettivi davvero; comportamento normale if (tipoiva == "VE") // da ventilare @@ -2272,7 +2293,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) else if (tipodoc == "FF") // CM500415: prima non c'era questo if { // queste sono fatture fiscali - true_corrisp = TRUE; + true_corrisp = true; real tot = imponibile + imposta; lor += tot; @@ -2413,16 +2434,16 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) switch (i) { case 1: // Progressivi Iva mensili da periodo Successivo - look_pis(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE); + look_pis(month, codatt, reg, tipocr_s, codiva, tipodet, true); break; case 2: // Progressivi Registri iva Mensili - look_prm(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE); + look_prm(month, codatt, reg, tipocr_s, codiva, tipodet, true); break; case 3: // Progressivi Registri iva Mensili da periodo Precedente - look_prp(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE); + look_prp(month, codatt, reg, tipocr_s, codiva, tipodet, true); break; default: // Progressivi Iva Mensili normali - look_pim(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE); + look_pim(month, codatt, reg, tipocr_s, codiva, tipodet, true); break; } @@ -2652,7 +2673,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) prorata += prorata_diff; fdiffinc_iva_acq -= prorata_diff; // Rettifica acquisti_iva differiti incassati } - look_plm(month, codatt, TRUE); + look_plm(month, codatt, true); /* * ACHTUNG: l'iva sulle vendite e' calcolata sommando anche i @@ -3505,7 +3526,7 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) /* Cazzata galattica: già gestito BENE da update_firm, prima di chiamare questa funzione // evita casino se differita ma si sta ricalcolando il primo mese con ricalcolo di piu' mesi const bool wasdifferita = (_isdifferita && month <= _monthinatt && _month > _monthinatt); - if (wasdifferita) _isdifferita = FALSE; + if (wasdifferita) _isdifferita = false; */ // liq. differita: considera mese precedente (solo per i risultati) int deltam = month; @@ -3513,8 +3534,9 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) month -= (_freqviva == "T" ? 3 : 1); deltam -= month; - look_lia(); - const bool new_age_2000 = (_lia->get("S9") == "NV"); + const TRectype & lia = get_lia(); + + const bool credito_compensabile = (lia.get("S9") == "CM"); real risultato = ZERO; @@ -3567,19 +3589,19 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) real vol_aff_l = ZERO; real tot_cong = ZERO; - bool differita = FALSE; - bool almeno_una_agricola = FALSE; - bool almeno_una_normale = FALSE; + bool differita = false; + bool almeno_una_agricola = false; + bool almeno_una_normale = false; int attc = 0; // counter attivita' // nuova liquidazione real credito_utilizzabile_inizio_anno = ZERO; real credito_utilizzato_inizio_anno = ZERO; real credito_utilizzato_iva = ZERO; - if (new_age_2000) + if (credito_compensabile) { - credito_utilizzato_inizio_anno = _lia->get_real("R15"); - credito_utilizzabile_inizio_anno = _lia->get_real("R0") - credito_utilizzato_inizio_anno; + credito_utilizzato_inizio_anno = lia.get_real("R15"); + credito_utilizzabile_inizio_anno = lia.get_real("R0") - credito_utilizzato_inizio_anno; if (credito_utilizzabile_inizio_anno < ZERO) credito_utilizzabile_inizio_anno = ZERO; } @@ -3600,13 +3622,15 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) { // usa i totali del mese di dicembre dell'anno // precedente - differita = TRUE; + differita = true; 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 + const TRectype & lim = get_lim(12); + + if (lim.empty()) //controlla solamente, il vero posizionamento lo fa dopo { _year = yr; // Ripristino anno corrente - differita = FALSE; + differita = false; } } @@ -3617,7 +3641,8 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) continue; look_plm(differita ? 12 : m, att); - bool is_lim = look_lim(_isdifferita ? m+deltam : m); + TRectype lim = get_lim(_isdifferita ? m+deltam : m); + bool is_lim = lim.not_empty(); // Se trattasi di annuale considera solo PLM/PUM del mese 13 if ((month == 13 && m == 13) || month != 13) @@ -3740,8 +3765,9 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) */ if (attc == 0 && is_lim && m < 13 && is_month_ok_strict(m,month)) { - const real rimborso_richiesto = _lim->get_real("R1"); - risultato += rimborso_richiesto; + const real rimborso_richiesto = lim.get_real("R1"); + + risultato += rimborso_richiesto; rimborsi += rimborso_richiesto; res_debt += rimborso_richiesto; } @@ -3754,12 +3780,13 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) const bool somma_rettifiche = month < 13 || m < 13; // CM00278 if (somma_rettifiche) { - const real rett = _lim->get_real("R5"); - if (!rett.is_zero()) + const real rett = lim.get_real("R5"); + + if (rett.not_zero()) { risultato += rett; rettifiche += rett; - if (rett.sign() < 0) + if (rett < ZERO) res_cred -= rett; else res_debt += rett; @@ -3772,20 +3799,23 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) */ if (attc == 0 && is_lim && m < 13 && is_month_ok_strict(m,month)) { - const real r17 = _lim->get_real("R17"); + const real r17 = lim.get_real("R17"); + variazioni_imposta += r17; risultato += r17; - if (r17.sign() >= 0) + if (r17 >= ZERO) res_debt += r17; else res_cred -= r17; - const real r18 = _lim->get_real("R18"); + const real r18 = lim.get_real("R18"); + imposta_non_versata += r18; risultato += r18; res_debt += r18; - const real r19 = _lim->get_real("R19"); + const real r19 = lim.get_real("R19"); + crediti_speciali += r19; risultato -= r19; res_cred += r19; @@ -3841,7 +3871,8 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) } // end ciclo su attivita' real credito_utilizzabile = ZERO; - + const bool utilizza_credito_autorizzato = lia.get_bool("B6"); + if (month < 13) // va bene anche se differita sommando deltam (che e' 0 normalmente) { // toglie credito precedente @@ -3852,18 +3883,36 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) debt_precd = debt_prec(month+deltam); risultato += debt_precd; res_debt += debt_precd; + - if (new_age_2000 && credito_utilizzabile_inizio_anno > ZERO && - (_freqviva == "M" || is_trim(month+deltam))) + if (credito_compensabile && credito_utilizzabile_inizio_anno > ZERO && + (_freqviva == "M" || is_trim(month + deltam))) { real debiti = res_debt; round_imposta(debiti); real crediti = res_cred; round_imposta(crediti); const real risul = debiti - crediti; + TRectype lim = get_lim(month+deltam); + const real cred_util_F24 = lim.get_real("R16"); + + credito_utilizzabile = credito_utilizzabile_inizio_anno; + credito_utilizzabile -= credito_utilizzato(month + deltam); + if (utilizza_credito_autorizzato) + credito_utilizzabile += credito_autorizzato(month + deltam); + + credito_utilizzabile -= cred_util_F24; + if (utilizza_credito_autorizzato) + { + const real cred_aut_F24 = lim.get_real("R20"); + + credito_utilizzabile += cred_aut_F24; + } + + + if (credito_utilizzabile < ZERO) + credito_utilizzabile = ZERO; if (risul > ZERO) { - credito_utilizzabile = credito_utilizzabile_inizio_anno; - credito_utilizzabile -= credito_utilizzato(month+deltam, TRUE, TRUE); - if (credito_utilizzabile < ZERO) credito_utilizzabile = ZERO; + credito_utilizzato_iva = min(risul, credito_utilizzabile); res_cred += credito_utilizzato_iva; risultato -= credito_utilizzato_iva; @@ -3872,18 +3921,19 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) } else { - if (new_age_2000) + if (credito_compensabile) { cred_prec = ZERO; if (credito_utilizzabile_inizio_anno > ZERO) { - credito_utilizzato_iva = credito_utilizzato(13, TRUE, FALSE); // CM00285 + credito_utilizzato_iva = credito_utilizzato_IVA(13); // CM00285 res_cred += credito_utilizzato_iva; risultato -= credito_utilizzato_iva; // Calcola credito utilizzabile da riportare nell'anno successivo credito_utilizzabile = credito_utilizzabile_inizio_anno; - credito_utilizzabile -= credito_utilizzato(13, TRUE, TRUE); + credito_utilizzabile -= credito_utilizzato(13); + credito_utilizzabile += credito_autorizzato(13); if (credito_utilizzabile < ZERO) credito_utilizzabile = ZERO; } @@ -3892,7 +3942,7 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) { // per l'annuale considera solo il credito a inizio anno cred_prec = credito_prec(_freqviva == "M" ? 1 : 3); - cred_trasf = _lia->get_real("R15"); + cred_trasf = lia.get_real("R15"); const real cred_res = cred_prec - cred_trasf; risultato -= cred_res; res_cred += cred_res; @@ -3928,9 +3978,9 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) real es_c1a_am = _pla->get_real("R17"); real csamm = _pla->get_real("R4"); real ven_rev = _pla->get_real("R18"); - real prorata = 0.0; - real conguaglio = 0.0; - real topay = 0.0; + real prorata; + real conguaglio; + real topay; const real ris = vf1 + vf2; // gia' esclusi: NS, B3, cess. amm // calcola nuovo prorata dal 1998 per ogni attivita' (miste: 1+2) @@ -3971,13 +4021,15 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) look_pla(att, true); _pla->put("R8", prorata); _pla->rewrite(); - if (look_lia(0l, true)) - { + TRectype lia = get_lia(0l, true); + + if (lia.not_empty()) + { real cc = cred_cost; round_imposta(cc); - _lia->put("R5", cc); - _lia->rewrite(); - } + lia.put("R5", cc); + put_lia(lia); + } _year = yr; // Aggiusta DiffIncIVAAcq sul record della 13ma che non poteva ancora sapere il prorata definitivo! @@ -3994,12 +4046,13 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) } } - look_lia(); - _lia->put("R1", vol_aff_l); - _lia->put("R2", vol_aff_1); - _lia->put("R3", vol_aff_2); - _lia->rewrite(); - } + TRectype lia = get_lia(); + + lia.put("R1", vol_aff_l); + lia.put("R2", vol_aff_1); + lia.put("R3", vol_aff_2); + put_lia(lia); + } // comprende anche il conguaglio prorata risultato += tot_cong; @@ -4016,23 +4069,26 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) res_cred += abs(tot_cong); } - look_lim(month+deltam,TRUE); - // azzeriamo tutto (tranne r1, r5, s1, s0, s7) - const TString16 codtab = _lim->get("CODTAB"); + TRectype lim = get_lim(month+deltam, true); + const TString16 codtab = lim.get("CODTAB"); - real rimborso = _lim->get("R1"); - real r5 = _lim->get("R5"); // Rettifiche - real credito_utilizzato_f24 = _lim->get("R16"); - real r17 = _lim->get("R17"); - real r18 = _lim->get("R18"); - real r19 = _lim->get("R19"); - TString s7 = _lim->get("S7"); +/* + // azzeriamo tutto (tranne r1, r5, s1, s0, s7) + const real rimborso = _lim->get("R1"); + const real r5 = _lim->get("R5"); // Rettifiche + const real credito_utilizzato_f24 = _lim->get("R16"); + const real r17 = _lim->get("R17"); + const real r18 = _lim->get("R18"); + const real r19 = _lim->get("R19"); + const real credito_autorizzato_f24 = _lim->get_real("R20"); + const TDate data_autorizzazione = _lim->get_date("D1"); + const TString s7 = _lim->get("S7"); const TString s0 = _lim->get("S0"); // Descrizioni rettifiche const TString s1 = _lim->get("S1"); const TString s2 = _lim->get("S2"); const TString s3 = _lim->get("S3"); - bool wasb0 = _lim->get_bool("B0"); - bool wasb1 = _lim->get_bool("B1"); + const bool wasb0 = _lim->get_bool("B0"); + const bool wasb1 = _lim->get_bool("B1"); _lim->zero(); _lim->put("CODTAB", codtab); @@ -4042,13 +4098,15 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) _lim->put("R17", r17); _lim->put("R18", r18); _lim->put("R19", r19); + _lim->put("R20", credito_autorizzato_f24); + _lim->put("D1", data_autorizzazione); _lim->put("S0", s0); _lim->put("S1", s1); _lim->put("S2", s2); _lim->put("S3", s3); _lim->put("S7", s7); _lim->put("B0", wasb0 ? "X" : ""); - _lim->put("B1", wasb1 ? "X" : ""); + _lim->put("B1", wasb1 ? "X" : ""); */ /* @@ -4072,20 +4130,21 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) // se no il conguaglio prorata fa casino round_al_centesimo(risultato); - _lim->put("R0",risultato); - _lim->put("R2",cred_cost); - _lim->put("R3",deb_mens); - _lim->put("R4",perc_r); + lim.put("R0", risultato); + lim.put("R2", cred_cost); + lim.put("R3", deb_mens); + lim.put("R4", perc_r); if (almeno_una_normale) - _lim->put("R6",detrazioni); + lim.put("R6", detrazioni); else // per evitare sbagli nei ricalcoli esterni - _lim->put("R6",""); + lim.zero("R6"); if (month == 13 || differita) { // Arrotonda totali in quanto possono avere un arrotondamento diverso dal mensile TIva_round ir; + ir.round(rimborsi); ir.round(rettifiche); ir.round(variazioni_imposta); @@ -4095,19 +4154,19 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) // scrivi totali rettifiche e rimborsi // nella finale oppure se copiati da // anno precedente - _lim->put("R1",rimborsi); - _lim->put("R5",rettifiche); + lim.put("R1",rimborsi); + lim.put("R5",rettifiche); - _lim->put("R17", variazioni_imposta); - _lim->put("R18", imposta_non_versata); - _lim->put("R19", crediti_speciali); + lim.put("R17", variazioni_imposta); + lim.put("R18", imposta_non_versata); + lim.put("R19", crediti_speciali); } /* * Interessi dovuti solo da trimestrali in periodica, * Era anche non benzinari, smentito da Cinzia (MI0853); * Ora gestito esplicitamente nei parametri ditta, forzato - * FALSE per ditte mensili e liq. annuale + * false per ditte mensili e liq. annuale * Ulteriormente smentito e rettificato */ bool true_trim = (month == 3 || month == 6 || month == 9); @@ -4118,44 +4177,45 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) const real r = risultato - imposta_non_versata; // CM 26-09-2000 real ivi = r.sign() > 0 ? (r * interesse / CENTO) : ZERO; round_al_centesimo(ivi); - _lim->put("R14", ivi); + lim.put("R14", ivi); } //questo serve anche per la visualizzazione e per l'estrazione deleghe if (_isintr && ( true_trim || (month == 12 && _isbenzinaro && _gest4) || (month == 13 && !(_isbenzinaro && _gest4)) )) - _lim->put("R10",interesse_trimestrale(_month)); + lim.put("R10", interesse_trimestrale(_month)); - _lim->put("R7", tot_cong); // totale conguaglio su tutte le attivita' - _lim->put("R8", versamenti); - _lim->put("R9", vers_int); - _lim->put("R11", acc_dec); - _lim->put("R12", res_cred); - _lim->put("R13", res_debt); + lim.put("R7", tot_cong); // totale conguaglio su tutte le attivita' + lim.put("R8", versamenti); + lim.put("R9", vers_int); + lim.put("R11", acc_dec); + lim.put("R12", res_cred); + lim.put("R13", res_debt); - _lim->put("R26", fdiff_imp); // Imponibile IVA diff Fatture di vendita - _lim->put("R27", fdiff_iva); // Imposta IVA diff Fatture di vendita - _lim->put("R28", fdiffinc_imp); // Imponibile IVA diff Incassi - _lim->put("R29", fdiffinc_iva); // Imposta IVA diff Incassi + lim.put("R26", fdiff_imp); // Imponibile IVA diff Fatture di vendita + lim.put("R27", fdiff_iva); // Imposta IVA diff Fatture di vendita + lim.put("R28", fdiffinc_imp); // Imponibile IVA diff Incassi + lim.put("R29", fdiffinc_iva); // Imposta IVA diff Incassi - _lim->put("R30", fdiff_imp_acq); // Imponibile IVA diff Fatture di acquisto - _lim->put("R31", fdiff_iva_acq); // Imposta IVA diff Fatture di acquisto - _lim->put("R32", fdiffinc_imp_acq); // Imponibile IVA diff Pagamenti - _lim->put("R33", fdiffinc_iva_acq); // Imposta IVA diff Pagamenti + lim.put("R30", fdiff_imp_acq); // Imponibile IVA diff Fatture di acquisto + lim.put("R31", fdiff_iva_acq); // Imposta IVA diff Fatture di acquisto + lim.put("R32", fdiffinc_imp_acq); // Imponibile IVA diff Pagamenti + lim.put("R33", fdiffinc_iva_acq); // Imposta IVA diff Pagamenti + look_lam(month+deltam, true); _lam->put("R0", iva_vend); _lam->put("R1", iva_acq); _lam->put("R2", cred_prec); _lam->put("R3", debt_precd); if (!_recalc_only && _recalc != never) - _lim->put("B0","X"); + lim.put("B0","X"); if (_recalc_only) - _lim->put("B1", "X"); + lim.put("B1", "X"); /* Cazzata galattica: vedi sopra - if (wasdifferita) _isdifferita = TRUE; + if (wasdifferita) _isdifferita = true; */ // AWFUL! se siamo in annuale, occorre arrotondare alle 1000 lire @@ -4223,49 +4283,48 @@ void TLiquidazione_app::write_liq(int month, const char* codatts) _lam->put("R3", debt_precd); _lam->put("R4", cred_trasf); - _lim->put("R0", risultato); - _lim->put("R1", rimborsi); - _lim->put("R2", cred_cost); - _lim->put("R3", deb_mens); - _lim->put("R5", rettifiche); - _lim->put("R6", detrazioni); - _lim->put("R7", tot_cong); - _lim->put("R8", versamenti); - _lim->put("R9", vers_int); - _lim->put("R11", acc_dec); - _lim->put("R12", res_cred); - _lim->put("R13", res_debt); + lim.put("R0", risultato); + lim.put("R1", rimborsi); + lim.put("R2", cred_cost); + lim.put("R3", deb_mens); + lim.put("R5", rettifiche); + lim.put("R6", detrazioni); + lim.put("R7", tot_cong); + lim.put("R8", versamenti); + lim.put("R9", vers_int); + lim.put("R11", acc_dec); + lim.put("R12", res_cred); + lim.put("R13", res_debt); - real ivi = _lim->get("R14"); round_imposta(ivi); - _lim->put("R14", ivi); - _lim->put("R15", credito_utilizzato_iva); + real ivi = lim.get("R14"); round_imposta(ivi); + lim.put("R14", ivi); + lim.put("R15", credito_utilizzato_iva); if (month == 13) { // Riporta eventuale credito nella tabella parametri liquidazione dell'anno successivo - const real riporto = credito_utilizzabile - risultato; - if (riporto >= ZERO) // Risultato a credito - { - const int anno_prossimo = atoi(_year) + 1; - if (look_lia(0l, TRUE, anno_prossimo)) - { - _lia->put("R0", riporto); - _lia->rewrite(); - } - } + real riporto = credito_utilizzabile - risultato; + + if (riporto < ZERO) + riporto = ZERO; + + const int anno_prossimo = atoi(_year) + 1; + TRectype lia = get_lia(0l, true, anno_prossimo); + + lia.put("R0", riporto); + put_lia(lia); } - _lim->put("R26", fdiff_imp); - _lim->put("R27", fdiff_iva); - _lim->put("R28", fdiffinc_imp); - _lim->put("R29", fdiffinc_iva); - _lim->put("R30", fdiff_imp_acq); - _lim->put("R31", fdiff_iva_acq); - _lim->put("R32", fdiffinc_imp_acq); - _lim->put("R33", fdiffinc_iva_acq); + lim.put("R26", fdiff_imp); + lim.put("R27", fdiff_iva); + lim.put("R28", fdiffinc_imp); + lim.put("R29", fdiffinc_iva); + lim.put("R30", fdiff_imp_acq); + lim.put("R31", fdiff_iva_acq); + lim.put("R32", fdiffinc_imp_acq); + lim.put("R33", fdiffinc_iva_acq); // ciapa } - - _lim->rewrite(); + put_lim(lim); _lam->rewrite(); } diff --git a/cg/cg4302.cpp b/cg/cg4302.cpp index 33d0eec34..51372cd93 100755 --- a/cg/cg4302.cpp +++ b/cg/cg4302.cpp @@ -1,1052 +1,1090 @@ -// ------------------------------------------------------------- -// calcolo liquidazioni -// part 3: utilities -// fv 2-2-94 -// -------------------------------------------------------------- - -#include -#include -#include -#include - -#include "cglib03.h" -#include "cg4300.h" - -#include -#include - -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_month_ok_strict(int x, int month) const - // TRUE se il mese passato e' compatibile con il regime - // di liquidazione e (opz) non e' maggiore di quello scelto -{ - if (month == -1) month = x; - return _freqviva == "M" ? ( x > 0 && x <= month) : ( x <= month && is_trim(x)); -} - -bool TLiquidazione_app::is_month_plain(int x) const - // la piu' semplice: vero se mese == _month o se fa parte del - // trimestre indicato da month -{ - bool ok = x == _month; - if (!ok && _freqviva == "T") - { - // aggiusta al trimestre il mese da calcolare - int mto = _month; - mto += 2 - ((mto-1) % 3); - ok = x > (mto - 3) && x <= mto; - } - return ok; -} - -bool TLiquidazione_app::is_month_ok(int x, int mtocalc) const - // 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" && mtocalc != 13) - { - // aggiusta al trimestre il mese da calcolare - mtocalc += 2 - ((mtocalc-1) % 3); - ret = x > (mtocalc - 3) && x <= mtocalc; - } - else if (!ret && mtocalc == 13) - { - // per l'annuale ritorna TRUE per tutti i mesi da liquidare - ret = x <= 13; - } - return ret; -} - -int TLiquidazione_app::liq_month(int x) - // ritorna il mese da liquidare (= LIM presente) - // che corrisponde al mese passato -{ - if (x == 13 || _freqviva == "M") - return x; - else - return next_trim(x); -} - -int TLiquidazione_app::next_trim(int x) -{ - if (x == 13) - x = 12; - return x + (2 - ((x-1) % 3)); -} - -bool TLiquidazione_app::is_in_liq_period(const TDate& d) -{ - bool ok = FALSE; - const int y = atoi(_year); - if (_freqviva == "M") - { - ok = d.month() == _month && d.year() == y; - } - else - { - const int m = liq_month(_month); - ok = d.month() > m - 3 && d.month() <= m && d.year() == y; - } - return ok; -} - -bool TLiquidazione_app::is_first_month(int m) -{ - return _freqviva == "M" ? m == 1 : m == 3; -} - -int TLiquidazione_app::previous_month(int m) const -{ - // vale per LIM (mese o trimestre precedente) - if (_freqviva == "M") - return m == 1 ? 1 : m - 1; - else - //return m == 3 ? 3 : m - 3; // Cambiato il 10/11/2014 - return m <= 6 ? 3 : m >= 10 ? 9 : 6; -} - -bool TLiquidazione_app::is_date_ok(const TDate& d, int month, int liqmonth, int year) const - // TRUE se la data passata va considerata nel - // ricalcolo dei progressivi mensili per il mese e anno - // selezionati. Vedi cg4301.cpp per maggiori informazioni - // sul nuovo filtro di selezione movimenti. -{ - CHECKD(year > 2000, "Invalid year ", year); - const int regmonth = d.month(); - const int regyear = d.year(); - - // if (regyear() != year) return false; - if (year < 1998 || _recalc_regis) // Vecchia selezione o calcolo progressivi per stampa registri bollati - { - if (regyear != year || regmonth > month) - return false; - - if (month == 13) - return true; // was regmonth <= month; - else - { - if (_freqviva == "M") // Guy!!! - return regmonth == month; - else - return regmonth >= month-2 && regmonth <= month; - } - } - else // Nuova selezione dal 1998 in poi - { - if (month <= 12) - return (regyear == year) && ((regmonth == month && liqmonth == 0) || (liqmonth == month)); - else // Annuale, month == 13 - return (regyear == year && liqmonth != 12) || (regyear == year + 1 && liqmonth == 12); - } - return false; -} - - -void TLiquidazione_app::add_ventilation(real iva, real howmuch, - const char* codiva, const char* other) -{ - _VentItem* vi = NULL; - int i; - for (i = 0; i < _vent_arr.items(); i++) - { - vi = (_VentItem*)&_vent_arr[i]; - if (vi->_codiva == codiva) - break; - } - if (i == _vent_arr.items()) - { - _vent_arr.add(vi = new _VentItem); - vi->_aliquota = iva; - vi->_codiva = codiva; - vi->_other = other; - } - vi->_totale += howmuch; -} - -void TLiquidazione_app::add_vendite(int month, const char* codreg, - int tipodet, const real& r) -{ - _VendItem* vi = NULL; - int i; - for (i = 0; i < _vend_arr.items(); i++) - { - vi = (_VendItem*)&_vend_arr[i]; - if (vi->_codreg == codreg && vi->_month == month && vi->_tipodet == tipodet) - break; - } - if (i == _vend_arr.items()) - { - _vend_arr.add(vi = new _VendItem); - vi->_codreg = codreg; - vi->_month = month; - vi->_tipodet = tipodet; - } - vi->_totale += r; -} - -void TLiquidazione_app::add_corrisp(int month, const char* codreg, const real& r, - const real& p, int tipodet, const char* codiva, - const char* codatt) -{ - _CorrItem* ci = NULL; - const int nitems = _corr_arr.items(); - int i; - for (i = 0; i < nitems; i++) - { - ci = (_CorrItem*)&_corr_arr[i]; - if (ci->_codreg == codreg && ci->_month == month && - ci->_codiva == codiva && ci->_tipodet == tipodet && - ci->_codatt == codatt) - break; - } - if (i == nitems) - { - _corr_arr.add(ci = new _CorrItem); - ci->_codreg = codreg; - ci->_month = month; - ci->_codiva = codiva; - ci->_codatt = codatt; - ci->_tipodet = tipodet; - ci->_aliquota = p; - } - ci->_totale += r; -} - -void TLiquidazione_app::lordo2netto(const real& totale, real& imponibile, real& imposta, const real& aliquota) -{ - const int dec = TCurrency::get_firm_dec(); - if (dec == 0) // Lire - { - imposta = (abs(totale) * aliquota)/(aliquota + 1.00); - imposta.ceil(); - if (totale.sign() < 0) imposta = -imposta; - imponibile = totale - imposta; - // Qui si entra nel regno del mistero: delta e' SEMPRE zero - const real delta = totale - imponibile - imposta; - if (!delta.is_zero()) - imposta += delta; - } - else // Euro - { - imposta = (totale * aliquota)/(aliquota + 1.00); - imposta.round(dec); - imponibile = totale - imposta; - } -} - -void TLiquidazione_app::lordo2netto(real& imponibile, real& imposta, const real& aliquota) -{ - const real totale = imponibile; - lordo2netto(totale, imponibile, imposta, aliquota); -} - -// Funzione per trovare i PIM: Progressivi liquidazione Iva Mensili. -bool TLiquidazione_app::look_pim(int month, const char* codatt, const char* codreg, - const char* tipocr, const char* codiva, int tipodet, - bool create) - // ritorna il PIM corrispondente alla chiave passata; se - // create = TRUE lo crea se non lo trova. Ritorna se c'era -{ - _pim_r->zero(); - (*_pim_anno) = _year; - (*_pim_mese) = format("%02d", month); - (*_pim_codreg) = codreg; - (*_pim_codiva) = codiva; - (*_pim_codatt) = codatt; - (*_pim_tipocr) = tipocr; - (*_pim_tipodet) = tipodet; - - const TString80 s = _pim_r->get("CODTAB"); - const bool ok = _pim->read() == NOERR; - if (!ok && create) - { - _pim_r->zero(); - _pim_r->put("CODTAB",s); - _pim->write(); - } - return ok; -} - -// Le tabelle seguenti (PIS, PRM, PRP) sono vengono introdotte solo dal 1998 in poi. -// Pertanto il loro utilizzo e' significativo in tale periodo. -// Funzione per trovare i PIS: Progressivi liquidazione Iva mensili di cui periodo Successivo -bool TLiquidazione_app::look_pis(int month, const char* codatt, const char* codreg, - const char* tipocr, const char* codiva, int tipodet, - bool create) -{ - _pis_r->zero(); - (*_pis_anno) = _year; - (*_pis_mese) = format("%02d", month); - (*_pis_codreg) = codreg; - (*_pis_codiva) = codiva; - (*_pis_codatt) = codatt; - (*_pis_tipocr) = tipocr; - (*_pis_tipodet) = tipodet; - const TString80 s = _pis_r->get("CODTAB"); - bool ok = _pis->read() == NOERR; - - if (!ok && create) - { - _pis_r->zero(); - _pis_r->put("CODTAB",s); - _pis->write(); - } - return ok; -} - -// Funzione per trovare i PRM: Progressivi Registri iva Mensili. -bool TLiquidazione_app::look_prm(int month, const char* codatt, const char* codreg, - const char* tipocr, const char* codiva, int tipodet, - bool create) -{ - _prm_r->zero(); - (*_prm_anno) = _year; - (*_prm_mese) = format("%02d", month); - (*_prm_codreg) = codreg; - (*_prm_codiva) = codiva; - (*_prm_codatt) = codatt; - (*_prm_tipocr) = tipocr; - (*_prm_tipodet) = tipodet; - - const TString80 s = _prm_r->get("CODTAB"); - bool ok = _prm->read() == NOERR; - - if (!ok && create) - { - _prm_r->zero(); - _prm_r->put("CODTAB",s); - _prm->write(); - } - return ok; -} - -// Funzione per trovare i PRP: Progressivi Registri iva mensili di cui da periodo Precedente -bool TLiquidazione_app::look_prp(int month, const char* codatt, const char* codreg, - const char* tipocr, const char* codiva, int tipodet, - bool create) -{ - bool ok = false; - - _prp_r->zero(); - (*_prp_anno) = _year; - (*_prp_mese) = format("%02d", month); - (*_prp_codreg) = codreg; - (*_prp_codiva) = codiva; - (*_prp_codatt) = codatt; - (*_prp_tipocr) = tipocr; - (*_prp_tipodet) = tipodet; - - const TString80 s = _prp_r->get("CODTAB"); - ok = _prp->read() == NOERR; - if (!ok && create) - { - _prp_r->zero(); - _prp_r->put("CODTAB",s); - ok = _prp->write() == NOERR; - } - return ok; -} - -bool TLiquidazione_app::look_plm(int m, const char* att, bool create) -{ - _plm_r->zero(); - (*_plm_codatt) = format("%6s", att); - (*_plm_mese) = format("%02d",m); - (*_plm_anno) = _year; - - const TString16 s = _plm_r->get("CODTAB"); - const bool ok = _plm->read() == NOERR; - - if (!ok && create) - { - _plm_r->zero(); - _plm_r->put("CODTAB",s); - _plm->write(); - } - // crea/posiziona tabelle gemelle PAM, PUM, POM - look_pam(m, att, !ok); - look_pum(m, att, !ok); - look_pom(m, att, !ok); - - return ok; -} - -bool TLiquidazione_app::look_pia(int m, const char* a, const char* cod1, const char* cod2, bool create) -{ - bool ok = FALSE; - - (*_pia_codatt) = format("%6s", a); - (*_pia_mese) = format("%02d",m); - (*_pia_anno) = _year; - (*_pia_codord) = cod1; - (*_pia_codcom) = cod2; - - TString s = _pia_r->get("CODTAB"); - _pia->read(); - ok = _pia->good(); - - if (!ok && create) - { - _pia_r->zero(); - _pia_r->put("CODTAB",s); - _pia->write(); - } - return ok; -} - -bool TLiquidazione_app::look_pum(int m, const char* a, bool create) -{ - bool ok = FALSE; - - _pum->zero(); - (*_pum_codatt) = format("%6s", a); - (*_pum_mese) = format("%02d",m); - (*_pum_anno) = _year; - - TString s = _pum->get("CODTAB"); - _pum->read(); - ok = _pum->good(); - - if (!ok && create) - { - _pum->zero(); - _pum->put("CODTAB",s); - _pum->write(); - } - return ok; -} - -bool TLiquidazione_app::look_pem(TTable & pem, int codreg) -{ - TString8 key; - - key.format("%04d%02d", atoi((const char *) _year), codreg); - pem.put("CODTAB", key); - bool ok = pem.read() == NOERR; - if (!ok) - { - pem.zero(); - pem.put("CODTAB", key); - ok = pem.write() == NOERR; - } - return ok; -} - -bool TLiquidazione_app::look_pom(int m, const char* a, bool create) -{ - _pom->zero(); - (*_pom_codatt) = format("%6s", a); - (*_pom_mese) = format("%02d",m); - (*_pom_anno) = _year; - - const TString16 s = _pom->get("CODTAB"); - bool ok = _pom->read() == NOERR; - - if (!ok && create) - { - _pom->zero(); - _pom->put("CODTAB",s); - ok = _pom->write() == NOERR; - } - return ok; -} - -bool TLiquidazione_app::look_pam(int m, const char* a, bool create) -{ - _pam->zero(); - (*_pam_codatt) = format("%6s", a); - (*_pam_mese) = format("%02d",m); - (*_pam_anno) = _year; - - const TString16 s = _pam->get("CODTAB"); - - const bool ok = _pam->read() == NOERR; - - if (!ok && create) - { - _pam->zero(); - _pam->put("CODTAB",s); - _pam->write(); - } - return ok; -} - -bool TLiquidazione_app::look_lim(int m, bool create) -{ - _lim_r->zero(); - (*_lim_mese) = format("%02d",m); - (*_lim_anno) = _year; - - const TString8 s = _lim_r->get("CODTAB"); - const bool ok = _lim->read() == NOERR; - - if (!ok && create) - { - _lim_r->zero(); - _lim_r->put("CODTAB",s); - _lim->write(); - } - - // crea o posiziona la tabella gemella LAM - look_lam(m, !ok); - - return ok; -} - -bool TLiquidazione_app::look_lam(int m, bool create) -{ - _lam_r->zero(); - (*_lam_mese) = format("%02d",m); - (*_lam_anno) = _year; - - const TString8 s = _lam_r->get("CODTAB"); - const bool ok = _lam->read() == NOERR; - if (!ok && create) - { - _lam_r->zero(); - _lam_r->put("CODTAB",s); - _lam->write(); - } - return ok; -} - -int TLiquidazione_app::count_activities() const -{ - TRelation rel(LF_ATTIV); - TRectype& rec = rel.curr(); - rec.put(ATT_CODDITTA, get_firm()); - TCursor cur(&rel, "", 1, &rec, &rec); - return cur.items(); -} - -bool TLiquidazione_app::look_pla(const char* a, bool create) -{ - // forza il tipoatt a 1 - TString16 buf(a); - buf.ltrim(); - buf.rtrim(1); - buf << "1"; - //while (buf.len() < 6) buf.insert("0"); - buf.right_just(6, '0'); - - _pla_r->zero(); - (*_pla_ditta) = format("%05ld", get_firm()); - (*_pla_anno) = _year; - (*_pla_codatt) = buf; - - const TString16 s = _pla_r->get("CODTAB"); - bool ok = _pla->read() == NOERR; - if (!ok && create) - { - _pla->zero(); - _pla_r->put("CODTAB",s); - _pla->write(); - } - return ok; -} - -bool TLiquidazione_app::look_reg(const char* reg) -{ - TString16 s; s << _year; s << format("%-3s",reg); - 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",s); - if (_reg->read() == NOERR) - _reg_arr.add(s,_reg->curr()); - else - rt = FALSE; - } - return rt; -} - -bool TLiquidazione_app::look_iva(const char* cod) -{ - bool rt = true; - - TString4 s = cod; s.trim(); - const bool is_key = _codiva_arr.is_key(s); - - if (is_key) - _iva->curr() = (const TRectype&)_codiva_arr[s]; - else - { - _iva->zero(); - _iva->put("CODTAB", s); - rt = _iva->read() == NOERR; - if (rt) - _codiva_arr.add(s, _iva->curr()); - } - - return rt; -} - -bool TLiquidazione_app::look_ppa(int month, const char* codatt, int type, bool create) -{ - _ppa->zero(); - (*_ppa_year) = _year; - (*_ppa_month) = format("%02d",month); - (*_ppa_codatt) = format("%6s", codatt); - (*_ppa_kind) = type; - TString ctab = _ppa_r->get("CODTAB"); - _ppa->read(); - - bool ok = _ppa->good(); - - if (!ok && create) - { - _ppa_r->zero(); - _ppa_r->put("CODTAB",ctab); - _ppa->write(); - } - return ok; -} - - -bool TLiquidazione_app::look_del(int month, int type, bool create) -{ - // se chiamata con il flag di creazione, aggiorna le info su - // codici tributo, concessione, conto fiscale anche se la - // delega esiste gia' - - // Molto pericoloso chiamare con create = TRUE: - // se e' gia' stata fatta l'estrazione versamenti - // e l'utente cambia titcf e isdel sull'anagrafica - // sono c... suoi!!! (Maurizio) - // deve rifarsi la delega con l'ESTRAZIONE VERSAMENTI - // io l'ho lasciato per rispetto del lavoro altrui - - const long ditta = _nditte->curr().get_long("CODDITTA"); - _del->zero(); - (*_del_ditta) = format("%05ld", ditta); - (*_del_anno) = _year; - (*_del_mese) = format("%02d", month); - (*_del_tipo) = format("%1d", type); - - const TString16 ctab = _del->get("CODTAB"); - bool ok = _del->read() == NOERR; - - if (!ok && create) - { - _del->zero(); - _del->put("CODTAB",ctab); - } - - if (create) - { - // vedi se titolare conto fiscale - bool titcf = FALSE; - bool isdel = FALSE; - int uffiva; - TString16 key; - - key.format("%s|%s", (const char *)_nditte->lfile().get("TIPOA"), (const char *) _nditte->lfile().get("CODANAGR")); - - const TRectype & anag = cache().get(LF_ANAG, key); - if (!anag.empty()) - { - titcf = anag.get_bool("TITCF"); - isdel = anag.get_long("TIPOSTDEL") == 0l; - uffiva = anag.get_int("UFFIVA"); - } - - TString16 con; - TString uva; - if (titcf) - look_conc(con, uva); // Legge la concessione se titolare conto fiscale - - if (!titcf || isdel) - { - // non titolare conto fiscale oppure paga con delega: - // cerca banca - // codici ABI e CAB da anagrafica ditte - TString16 abi, cab; - abi = _nditte->lfile().get("ABIBAN"); - cab = _nditte->lfile().get("CABBAN"); - if (abi.empty()) - { - TConfig c (CONFIG_STUDIO, "cg"); - abi = c.get("CodABI"); - cab = c.get("CodCAB"); - } - _del->put("S7", abi); - _del->put("S8", cab); - if (titcf && isdel) // Se e' titolare CF e stampa la delega, va riportata anche la conc - { - _del->put("S9", con); - _del->put("S2", uva); - } - else - _del->put("S9", ""); - } - else - { - // non usa delega bensi' bollettino o distinta: - // cerca concessione comune - // infila ufficio concessione in S9 - // e descrizione comune in S2 - _del->put("S9", con); - _del->put("S2", uva); - _del->put("S7", ""); - _del->put("S8", ""); - } - } //fine create - - // le descrizioni sulla delega non vengono - // memorizzate dai vari programmi di gestione - // e estrazione ma solo qui. - if (ok) - { - int uffiva; - TString16 key; - - key.format("%s|%s", (const char *)_nditte->lfile().get("TIPOA"), (const char *) _nditte->lfile().get("CODANAGR")); - - const TRectype & anag = cache().get(LF_ANAG, key); - if (!anag.empty()) - uffiva = anag.get_int("UFFIVA"); - - TString16 abi = _del->get("S7"); - TString16 cab = _del->get("S8"); - TString16 con = _del->get("S9"); - - // descrizione banca - if (abi.not_empty()) - { - TString codban = format("%05ld", atol(abi)); - if (!cab.empty()) codban << format("%05ld", atol(cab)); - const TRectype & ban = cache().get("%BAN", codban); - if (!ban.empty()) - { - TString desban(ban.get("S0")); - _del->put("S1", desban); - } - //che rottura: ogni giorno alla prassi cambiano idea!!! - TString16 coduff = format("%03d", uffiva); - const TRectype & uiv = cache().get("%UIV", coduff); - if (!uiv.empty()) - { - TString desiva(uiv.get("S0")); - _del->put("S2", desiva); - } - } - // Descrizione cod. concessione - if (con.not_empty()) - { - TString uva; - if (look_conc(con, uva)) - _del->put("S2", uva); - } - } - // scrive codice tributo - int ctri = 6000; - if (month == 13 && type == 7) - ctri = 6035; // acconto IVA annuale (trimestrali?) - else if (month == 13 && type == 1) - ctri = 6099; // IVA annuale - else if (month < 13 && type == 7) - ctri = 6013; // acconto mensile - else if (month < 13 && type == 1) // regular - ctri = _freqviva == "M" ? 6000 + month : 6030 + (month/3); - - _del->put("S6", format("%d",ctri)); - - if (!ok) _del->write(); - else _del->rewrite(); - - return ok; -} - -bool TLiquidazione_app::look_lia(long ditta, bool create, int year) -{ - if (year <= 0) year = atoi(_year); - if (ditta <= 0l) ditta = get_firm(); - - TString16 y; y.format("%05ld%04d", ditta, year); - _lia->put("CODTAB", y); - const bool ok = _lia->read() == NOERR; - if (!ok) - { - _lia->zero(); - _lia->put("CODTAB", y); - _lia->put("S7", _freqviva); - if (create) - _lia->write(); - } - return ok; -} - -real TLiquidazione_app::result_liq(int month) - // risultato esatto della liquidazione del mese month, <0 a credito - // > 0 a debito; comprende TUTTI, anche il conguaglio prorata in annuale -{ - real r; - // ulteriori detrazioni, acconti, versamenti, - // rettifiche, conguagli sono gia' compresi in R0 - if (look_lim(month)) - r = _lim->get_real("R0"); - return r; -} - -real TLiquidazione_app::iva_da_riportare(int month) -{ - real idr; - const int anno = atoi(_year); - if (month > 12) - { - if (_ver->read(anno, 12) == NOERR) - idr = _ver->get(I_ANNUALE); - } - else - { - if (_ver->read(anno, month) == NOERR) - idr = _ver->get(I_PERIODICO); - } - return idr; -} - -real TLiquidazione_app::debt_prec(int month) -{ - real r; - if (!is_first_month(month)) - { - if (look_lim(previous_month(month))) - { - r = result_liq(previous_month(month)); - if (!(r > ZERO && r < iva_da_riportare(month))) - r = ZERO; - } - } - return r; -} - - -real TLiquidazione_app::credito_prec(int month) - // ritorna l'appropriato credito precedente al mese in corso -{ - real c = ZERO; - if (!(_freqviva =="M" || is_trim(month))) // Aggiunto il 10/11/2014 - return c; - - const bool lia_ok = look_lia(); - const bool credito_visibile = _lia->get("S9") != "NV"; - - if (is_first_month(month)) - { - // credito inizio anno - if (lia_ok) - { - // Dal 2000 se S9="NV" il credito precedente non esiste piu' - if (credito_visibile) - c = _lia->get_real("R0"); - } - // e' positivo o 0 - } - else - { - c = result_liq(previous_month(month)); - if (c < ZERO) - c = -c; - else - c = ZERO; - - // Dal 2000 se S9="NV" il credito trasferito non esiste piu' - if (credito_visibile) - { - // Nel caso di trimestrali considera dal trimestre corrispondente a - // quello impostato+1. Ad es. se m == 1 considera dal I trim. (m=3) - // se m == 2 idem (m=3). Se m == 3 considera dal II trim. (m=6). - const int crm = _lia->get_int("I0") + 1; - if (lia_ok && crm > 1) // Vale dal mese successivo a quello impostato - { - // Toglie il Credito Trasferito - if (month == liq_month(crm)) - c -= _lia->get_real("R15"); - } - } - } - - return c; -} - -real TLiquidazione_app::credito_costo_prec(int month) - // ritorna l'appropriato credito di costo precedente al mese in corso - // (travel agency only) -{ - real c = ZERO; - if (is_first_month(month) || month == 13) - { - // credito inizio anno - if (look_lia()) - c = _lia->get_real("R5"); - } - else - { - if (look_lim(previous_month(month))) - // qui il rimborso non c'e' - c = _lim->get_real("R2"); - } - look_lim(month); - return c; -} - - -real TLiquidazione_app::versamenti_IVA(int month, const char* types, bool intr) -{ - real ret(0.0); TToken_string typ(types); - - for (int i = 0; i < typ.items(); i++) - { - int tp = typ.get_int(i); - if (look_del(month,tp)) - { - real importo_dovuto_non_arrotondato(_del->get_real("R2")); - real interessi(_del->get_real("R1")); - real importo_dovuto_arrotondato(_del->get_real("R0")); - real work(importo_dovuto_non_arrotondato); - - round_imposta(work); - if (_month == 13 && _freqviva == "T" && importo_dovuto_arrotondato == work) - ret += importo_dovuto_non_arrotondato; // Questo e' l'importo lordo non arrotondato!! - else - ret += importo_dovuto_arrotondato; - //gli interessi vengono memorizzati solo se si - //devono pagare (=> nessun controllo su intra) - if (!(_is_visliq && _freqviva == "T" && _month != 13)) // toglie gli interessi se non siamo in visualiz. o la ditta non e' TRIM o siamo in annuale - ret -= interessi; // al netto degli interessi - // In caso di 13a liq e per trimestrali... devo fare la somma - // degli importi netti dovuti, ecco perche' leggo R2, - // perche togliendo poi gli interessi ottengo il dovuto netto! - // Questa casistica vale pero' solo se in R2 c'e' qualcosa(!=0) ed - // e' relativo all'importo presente in R0. Ovvero: - // nel caso si estraggano i versamenti trimestrali, i campi R2 - // vengono correttamente compilati. Se poi si modificano a mano i - // valori di R0 (tramite gestione versamenti, visualizzazione o - // calcolo acconti) tale importo non e' piu' consistente, ecco quindi - // il controllo effettuato tra R0 e ROUND(R2). In realta' sarebbe piu' - // oppurtuno che in gestione versamenti, visualizzazione liquidazione e - // calcolo acconti, vi sia la possibilita' di modificare anche R2. - // Tutto cio' e' relativo all'errore MI3386. - } - } - return ret; -} - -// Arrotonda intelligentemente alle 1000 Lire, al centesimo di Euro o all'unità di Euro -void TLiquidazione_app::round_imposta(real& d) const -{ - TIva_round ir; - ir.round(d); -} - -void TLiquidazione_app::round_al_centesimo(real& d) const -{ d.round(2); } - - -// Ritorna il parametro della liquidazione differita per la ditta corrente, cosi come -// e' scritto sui parametri liquidazione (LIA) -// Se si passa 0 (default) vede prende la ditta correntemente in corso di calcolo -// Analogamente per l'anno -bool TLiquidazione_app::is_acconto_differito(long firm, int year) -{ - bool diff = false; - const long d = (firm <= 0) ? _nditte->curr().get_long(NDT_CODDITTA) : firm; - const int y = (year <= 0) ? atoi(_year) : year; - if (look_lia(d, y > 0, y)) // 26/03/2012 aggiunto ,y) - diff = _lia->get_bool("B1"); - - return diff; -} - -real TLiquidazione_app::aliquota_agvia() -{ - real r; - const TString& codagv = ini_get_string(CONFIG_STUDIO, "cg", "CodAgv"); - if (codagv.full() && look_iva(codagv)) // Controlla se è vuoto! CM600475 - r = _iva->get_real("R0"); - return r; -} - - -real TLiquidazione_app::interesse_trimestrale(int month) -{ - month--; month /= 3; - real r(_ver->get(month)); // month varia da 0 a 4, proprio come da P_1_TRIMESTRE... in poi - return r; -} - -bool TLiquidazione_app::look_conc(TString& uffcon, TString& uffiva) -{ - // piazza nelle TString passate: l'ufficio concessioni - // l'ufficio IVA. Quest'ultimo e' preso dall'anagrafica se - // c'e', dal comune (primo non vuoto) se non - - // Assume _nditte correctly positioned - const TString4 ana(_nditte->lfile().get("TIPOA")); - const TString8 codana(_nditte->lfile().get("CODANAGR")); - // look anagrafica - TString16 key; - key.format("%s|%s", (const char *) ana, (const char *) codana); - - const TRectype & anag = cache().get(LF_ANAG, key); - if (anag.empty()) return false; - - // becca comune residenza fiscale - TString4 com(anag.get("COMRF")); - // se non c'e', residenza - if (com.empty()) - com = anag.get("COMRES"); - - if (com.empty()) - return false; - - // becca comune - key.format("|%s", (const char *) com); - - const TRectype comuni = cache().get(LF_COMUNI, key); - - if (comuni.empty()) return FALSE; - - const int uffa = comuni.get_int("UFFCONC"); - if (uffcon.empty()) - uffcon = format("%03d",uffa); - if (uffcon.not_empty()) - { - const TRectype & ucc = cache().get("%UCC", uffcon); - if (!ucc.empty()) - uffiva = ucc.get("S0"); - } - - return true; -} - -real TLiquidazione_app::credito_utilizzato(int month, bool iva, bool f24) const -{ - real credito; - - TTable lim("LIM"); - TString16 cod; - for (int m = 1; m <= month; m++) - { - cod.format("%s%02d", (const char*)_year, m); - lim.put("CODTAB", cod); - if (lim.read() == NOERR) - { - if (iva && m < month) - credito += lim.get_real("R15"); // Credito utilizzato IVA - if (f24 && m < 13) - credito += lim.get_real("R16"); // Credito utilizzato F24 - } - } - - return credito; -} - +// ------------------------------------------------------------- +// calcolo liquidazioni +// part 3: utilities +// fv 2-2-94 +// -------------------------------------------------------------- + +#include +#include +#include +#include + +#include "cglib03.h" +#include "cg4300.h" + +#include +#include + +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_month_ok_strict(int x, int month) const + // true se il mese passato e' compatibile con il regime + // di liquidazione e (opz) non e' maggiore di quello scelto +{ + if (month == -1) month = x; + return _freqviva == "M" ? ( x > 0 && x <= month) : ( x <= month && is_trim(x)); +} + +bool TLiquidazione_app::is_month_plain(int x) const + // la piu' semplice: vero se mese == _month o se fa parte del + // trimestre indicato da month +{ + bool ok = x == _month; + if (!ok && _freqviva == "T") + { + // aggiusta al trimestre il mese da calcolare + int mto = _month; + mto += 2 - ((mto-1) % 3); + ok = x > (mto - 3) && x <= mto; + } + return ok; +} + +bool TLiquidazione_app::is_month_ok(int x, int mtocalc) const + // 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" && mtocalc != 13) + { + // aggiusta al trimestre il mese da calcolare + mtocalc += 2 - ((mtocalc-1) % 3); + ret = x > (mtocalc - 3) && x <= mtocalc; + } + else if (!ret && mtocalc == 13) + { + // per l'annuale ritorna true per tutti i mesi da liquidare + ret = x <= 13; + } + return ret; +} + +int TLiquidazione_app::liq_month(int x) + // ritorna il mese da liquidare (= LIM presente) + // che corrisponde al mese passato +{ + if (x == 13 || _freqviva == "M") + return x; + else + return next_trim(x); +} + +int TLiquidazione_app::next_trim(int x) +{ + if (x == 13) + x = 12; + return x + (2 - ((x-1) % 3)); +} + +bool TLiquidazione_app::is_in_liq_period(const TDate& d) +{ + bool ok = false; + const int y = atoi(_year); + if (_freqviva == "M") + { + ok = d.month() == _month && d.year() == y; + } + else + { + const int m = liq_month(_month); + ok = d.month() > m - 3 && d.month() <= m && d.year() == y; + } + return ok; +} + +bool TLiquidazione_app::is_first_month(int m) +{ + return _freqviva == "M" ? m == 1 : m == 3; +} + +int TLiquidazione_app::previous_month(int m) const +{ + // vale per LIM (mese o trimestre precedente) + if (_freqviva == "M") + return m == 1 ? 1 : m - 1; + else + //return m == 3 ? 3 : m - 3; // Cambiato il 10/11/2014 + return m <= 6 ? 3 : m >= 10 ? 9 : 6; +} + +bool TLiquidazione_app::is_date_ok(const TDate& d, int month, int liqmonth, int year) const + // true se la data passata va considerata nel + // ricalcolo dei progressivi mensili per il mese e anno + // selezionati. Vedi cg4301.cpp per maggiori informazioni + // sul nuovo filtro di selezione movimenti. +{ + CHECKD(year > 2000, "Invalid year ", year); + const int regmonth = d.month(); + const int regyear = d.year(); + + // if (regyear() != year) return false; + if (year < 1998 || _recalc_regis) // Vecchia selezione o calcolo progressivi per stampa registri bollati + { + if (regyear != year || regmonth > month) + return false; + + if (month == 13) + return true; // was regmonth <= month; + else + { + if (_freqviva == "M") // Guy!!! + return regmonth == month; + else + return regmonth >= month-2 && regmonth <= month; + } + } + else // Nuova selezione dal 1998 in poi + { + if (month <= 12) + return (regyear == year) && ((regmonth == month && liqmonth == 0) || (liqmonth == month)); + else // Annuale, month == 13 + return (regyear == year && liqmonth != 12) || (regyear == year + 1 && liqmonth == 12); + } + return false; +} + + +void TLiquidazione_app::add_ventilation(real iva, real howmuch, + const char* codiva, const char* other) +{ + _VentItem* vi = NULL; + int i; + for (i = 0; i < _vent_arr.items(); i++) + { + vi = (_VentItem*)&_vent_arr[i]; + if (vi->_codiva == codiva) + break; + } + if (i == _vent_arr.items()) + { + _vent_arr.add(vi = new _VentItem); + vi->_aliquota = iva; + vi->_codiva = codiva; + vi->_other = other; + } + vi->_totale += howmuch; +} + +void TLiquidazione_app::add_vendite(int month, const char* codreg, + int tipodet, const real& r) +{ + _VendItem* vi = NULL; + int i; + for (i = 0; i < _vend_arr.items(); i++) + { + vi = (_VendItem*)&_vend_arr[i]; + if (vi->_codreg == codreg && vi->_month == month && vi->_tipodet == tipodet) + break; + } + if (i == _vend_arr.items()) + { + _vend_arr.add(vi = new _VendItem); + vi->_codreg = codreg; + vi->_month = month; + vi->_tipodet = tipodet; + } + vi->_totale += r; +} + +void TLiquidazione_app::add_corrisp(int month, const char* codreg, const real& r, + const real& p, int tipodet, const char* codiva, + const char* codatt) +{ + _CorrItem* ci = NULL; + const int nitems = _corr_arr.items(); + int i; + for (i = 0; i < nitems; i++) + { + ci = (_CorrItem*)&_corr_arr[i]; + if (ci->_codreg == codreg && ci->_month == month && + ci->_codiva == codiva && ci->_tipodet == tipodet && + ci->_codatt == codatt) + break; + } + if (i == nitems) + { + _corr_arr.add(ci = new _CorrItem); + ci->_codreg = codreg; + ci->_month = month; + ci->_codiva = codiva; + ci->_codatt = codatt; + ci->_tipodet = tipodet; + ci->_aliquota = p; + } + ci->_totale += r; +} + +void TLiquidazione_app::lordo2netto(const real& totale, real& imponibile, real& imposta, const real& aliquota) +{ + const int dec = TCurrency::get_firm_dec(); + if (dec == 0) // Lire + { + imposta = (abs(totale) * aliquota)/(aliquota + 1.00); + imposta.ceil(); + if (totale.sign() < 0) imposta = -imposta; + imponibile = totale - imposta; + // Qui si entra nel regno del mistero: delta e' SEMPRE zero + const real delta = totale - imponibile - imposta; + if (!delta.is_zero()) + imposta += delta; + } + else // Euro + { + imposta = (totale * aliquota)/(aliquota + 1.00); + imposta.round(dec); + imponibile = totale - imposta; + } +} + +void TLiquidazione_app::lordo2netto(real& imponibile, real& imposta, const real& aliquota) +{ + const real totale = imponibile; + lordo2netto(totale, imponibile, imposta, aliquota); +} + +// Funzione per trovare i PIM: Progressivi liquidazione Iva Mensili. +bool TLiquidazione_app::look_pim(int month, const char* codatt, const char* codreg, + const char* tipocr, const char* codiva, int tipodet, + bool create) + // ritorna il PIM corrispondente alla chiave passata; se + // create = true lo crea se non lo trova. Ritorna se c'era +{ + _pim_r->zero(); + (*_pim_anno) = _year; + (*_pim_mese) = format("%02d", month); + (*_pim_codreg) = codreg; + (*_pim_codiva) = codiva; + (*_pim_codatt) = codatt; + (*_pim_tipocr) = tipocr; + (*_pim_tipodet) = tipodet; + + const TString80 s = _pim_r->get("CODTAB"); + const bool ok = _pim->read() == NOERR; + if (!ok && create) + { + _pim_r->zero(); + _pim_r->put("CODTAB",s); + _pim->write(); + } + return ok; +} + +// Le tabelle seguenti (PIS, PRM, PRP) sono vengono introdotte solo dal 1998 in poi. +// Pertanto il loro utilizzo e' significativo in tale periodo. +// Funzione per trovare i PIS: Progressivi liquidazione Iva mensili di cui periodo Successivo +bool TLiquidazione_app::look_pis(int month, const char* codatt, const char* codreg, + const char* tipocr, const char* codiva, int tipodet, + bool create) +{ + _pis_r->zero(); + (*_pis_anno) = _year; + (*_pis_mese) = format("%02d", month); + (*_pis_codreg) = codreg; + (*_pis_codiva) = codiva; + (*_pis_codatt) = codatt; + (*_pis_tipocr) = tipocr; + (*_pis_tipodet) = tipodet; + const TString80 s = _pis_r->get("CODTAB"); + bool ok = _pis->read() == NOERR; + + if (!ok && create) + { + _pis_r->zero(); + _pis_r->put("CODTAB",s); + _pis->write(); + } + return ok; +} + +// Funzione per trovare i PRM: Progressivi Registri iva Mensili. +bool TLiquidazione_app::look_prm(int month, const char* codatt, const char* codreg, + const char* tipocr, const char* codiva, int tipodet, + bool create) +{ + _prm_r->zero(); + (*_prm_anno) = _year; + (*_prm_mese) = format("%02d", month); + (*_prm_codreg) = codreg; + (*_prm_codiva) = codiva; + (*_prm_codatt) = codatt; + (*_prm_tipocr) = tipocr; + (*_prm_tipodet) = tipodet; + + const TString80 s = _prm_r->get("CODTAB"); + bool ok = _prm->read() == NOERR; + + if (!ok && create) + { + _prm_r->zero(); + _prm_r->put("CODTAB",s); + _prm->write(); + } + return ok; +} + +// Funzione per trovare i PRP: Progressivi Registri iva mensili di cui da periodo Precedente +bool TLiquidazione_app::look_prp(int month, const char* codatt, const char* codreg, + const char* tipocr, const char* codiva, int tipodet, + bool create) +{ + bool ok = false; + + _prp_r->zero(); + (*_prp_anno) = _year; + (*_prp_mese) = format("%02d", month); + (*_prp_codreg) = codreg; + (*_prp_codiva) = codiva; + (*_prp_codatt) = codatt; + (*_prp_tipocr) = tipocr; + (*_prp_tipodet) = tipodet; + + const TString80 s = _prp_r->get("CODTAB"); + ok = _prp->read() == NOERR; + if (!ok && create) + { + _prp_r->zero(); + _prp_r->put("CODTAB",s); + ok = _prp->write() == NOERR; + } + return ok; +} + +bool TLiquidazione_app::look_plm(int m, const char* att, bool create) +{ + _plm_r->zero(); + (*_plm_codatt) = format("%6s", att); + (*_plm_mese) = format("%02d",m); + (*_plm_anno) = _year; + + const TString16 s = _plm_r->get("CODTAB"); + const bool ok = _plm->read() == NOERR; + + if (!ok && create) + { + _plm_r->zero(); + _plm_r->put("CODTAB",s); + _plm->write(); + } + // crea/posiziona tabelle gemelle PAM, PUM, POM + look_pam(m, att, !ok); + look_pum(m, att, !ok); + look_pom(m, att, !ok); + + return ok; +} + +bool TLiquidazione_app::look_pia(int m, const char* a, const char* cod1, const char* cod2, bool create) +{ + bool ok = false; + + (*_pia_codatt) = format("%6s", a); + (*_pia_mese) = format("%02d",m); + (*_pia_anno) = _year; + (*_pia_codord) = cod1; + (*_pia_codcom) = cod2; + + TString s = _pia_r->get("CODTAB"); + _pia->read(); + ok = _pia->good(); + + if (!ok && create) + { + _pia_r->zero(); + _pia_r->put("CODTAB",s); + _pia->write(); + } + return ok; +} + +bool TLiquidazione_app::look_pum(int m, const char* a, bool create) +{ + bool ok = false; + + _pum->zero(); + (*_pum_codatt) = format("%6s", a); + (*_pum_mese) = format("%02d",m); + (*_pum_anno) = _year; + + TString s = _pum->get("CODTAB"); + _pum->read(); + ok = _pum->good(); + + if (!ok && create) + { + _pum->zero(); + _pum->put("CODTAB",s); + _pum->write(); + } + return ok; +} + +bool TLiquidazione_app::look_pem(TTable & pem, int codreg) +{ + TString8 key; + + key.format("%04d%02d", atoi((const char *) _year), codreg); + pem.put("CODTAB", key); + bool ok = pem.read() == NOERR; + if (!ok) + { + pem.zero(); + pem.put("CODTAB", key); + ok = pem.write() == NOERR; + } + return ok; +} + +bool TLiquidazione_app::look_pom(int m, const char* a, bool create) +{ + _pom->zero(); + (*_pom_codatt) = format("%6s", a); + (*_pom_mese) = format("%02d",m); + (*_pom_anno) = _year; + + const TString16 s = _pom->get("CODTAB"); + bool ok = _pom->read() == NOERR; + + if (!ok && create) + { + _pom->zero(); + _pom->put("CODTAB",s); + ok = _pom->write() == NOERR; + } + return ok; +} + +bool TLiquidazione_app::look_pam(int m, const char* a, bool create) +{ + _pam->zero(); + (*_pam_codatt) = format("%6s", a); + (*_pam_mese) = format("%02d",m); + (*_pam_anno) = _year; + + const TString16 s = _pam->get("CODTAB"); + + const bool ok = _pam->read() == NOERR; + + if (!ok && create) + { + _pam->zero(); + _pam->put("CODTAB",s); + _pam->write(); + } + return ok; +} + +const TRectype & TLiquidazione_app::get_lim(int month, bool create) +{ + TString key = _year ; key << format("%02d", month); + + TRectype & lim = (TRectype &) cache().get("LIM", key); + + if (lim.empty() && create) + { + TRectype l(lim); + + l.put("CODTAB", key); + put_lim(l, false); + } + + // crea o posiziona la tabella gemella LAM +// look_lam(m, !ok); + + return (const TRectype &) lim; +} + +const int TLiquidazione_app::put_lim(const TRectype & lim, bool re) +{ + TTable tablim("LIM"); + + tablim.curr() = lim; + if (re) + { + const int err = tablim.rewrite(); + + cache().discard("LIM", lim.get("CODTAB")); + return err; + } + else + return tablim.write(); +} + +bool TLiquidazione_app::look_lam(int m, bool create) +{ + _lam_r->zero(); + (*_lam_mese) = format("%02d",m); + (*_lam_anno) = _year; + + const TString8 s = _lam_r->get("CODTAB"); + const bool ok = _lam->read() == NOERR; + if (!ok && create) + { + _lam_r->zero(); + _lam_r->put("CODTAB",s); + _lam->write(); + } + return ok; +} + +int TLiquidazione_app::count_activities() const +{ + TRelation rel(LF_ATTIV); + TRectype& rec = rel.curr(); + rec.put(ATT_CODDITTA, get_firm()); + TCursor cur(&rel, "", 1, &rec, &rec); + return cur.items(); +} + +bool TLiquidazione_app::look_pla(const char* a, bool create) +{ + // forza il tipoatt a 1 + TString16 buf(a); + buf.ltrim(); + buf.rtrim(1); + buf << "1"; + //while (buf.len() < 6) buf.insert("0"); + buf.right_just(6, '0'); + + _pla_r->zero(); + (*_pla_ditta) = format("%05ld", get_firm()); + (*_pla_anno) = _year; + (*_pla_codatt) = buf; + + const TString16 s = _pla_r->get("CODTAB"); + bool ok = _pla->read() == NOERR; + if (!ok && create) + { + _pla->zero(); + _pla_r->put("CODTAB",s); + _pla->write(); + } + return ok; +} + +bool TLiquidazione_app::look_reg(const char* reg) +{ + TString16 s; s << _year; s << format("%-3s",reg); + 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",s); + if (_reg->read() == NOERR) + _reg_arr.add(s,_reg->curr()); + else + rt = false; + } + return rt; +} + +bool TLiquidazione_app::look_iva(const char* cod) +{ + bool rt = true; + + TString4 s = cod; s.trim(); + const bool is_key = _codiva_arr.is_key(s); + + if (is_key) + _iva->curr() = (const TRectype&)_codiva_arr[s]; + else + { + _iva->zero(); + _iva->put("CODTAB", s); + rt = _iva->read() == NOERR; + if (rt) + _codiva_arr.add(s, _iva->curr()); + } + + return rt; +} + +bool TLiquidazione_app::look_ppa(int month, const char* codatt, int type, bool create) +{ + _ppa->zero(); + (*_ppa_year) = _year; + (*_ppa_month) = format("%02d",month); + (*_ppa_codatt) = format("%6s", codatt); + (*_ppa_kind) = type; + TString ctab = _ppa_r->get("CODTAB"); + _ppa->read(); + + bool ok = _ppa->good(); + + if (!ok && create) + { + _ppa_r->zero(); + _ppa_r->put("CODTAB",ctab); + _ppa->write(); + } + return ok; +} + + +bool TLiquidazione_app::look_del(int month, int type, bool create) +{ + // se chiamata con il flag di creazione, aggiorna le info su + // codici tributo, concessione, conto fiscale anche se la + // delega esiste gia' + + // Molto pericoloso chiamare con create = true: + // se e' gia' stata fatta l'estrazione versamenti + // e l'utente cambia titcf e isdel sull'anagrafica + // sono c... suoi!!! (Maurizio) + // deve rifarsi la delega con l'ESTRAZIONE VERSAMENTI + // io l'ho lasciato per rispetto del lavoro altrui + + const long ditta = _nditte->curr().get_long("CODDITTA"); + _del->zero(); + (*_del_ditta) = format("%05ld", ditta); + (*_del_anno) = _year; + (*_del_mese) = format("%02d", month); + (*_del_tipo) = format("%1d", type); + + const TString16 ctab = _del->get("CODTAB"); + bool ok = _del->read() == NOERR; + + if (!ok && create) + { + _del->zero(); + _del->put("CODTAB",ctab); + } + + if (create) + { + // vedi se titolare conto fiscale + bool titcf = false; + bool isdel = false; + int uffiva; + TString16 key; + + key.format("%s|%s", (const char *)_nditte->lfile().get("TIPOA"), (const char *) _nditte->lfile().get("CODANAGR")); + + const TRectype & anag = cache().get(LF_ANAG, key); + if (!anag.empty()) + { + titcf = anag.get_bool("TITCF"); + isdel = anag.get_long("TIPOSTDEL") == 0l; + uffiva = anag.get_int("UFFIVA"); + } + + TString16 con; + TString uva; + if (titcf) + look_conc(con, uva); // Legge la concessione se titolare conto fiscale + + if (!titcf || isdel) + { + // non titolare conto fiscale oppure paga con delega: + // cerca banca + // codici ABI e CAB da anagrafica ditte + TString16 abi, cab; + abi = _nditte->lfile().get("ABIBAN"); + cab = _nditte->lfile().get("CABBAN"); + if (abi.empty()) + { + TConfig c (CONFIG_STUDIO, "cg"); + abi = c.get("CodABI"); + cab = c.get("CodCAB"); + } + _del->put("S7", abi); + _del->put("S8", cab); + if (titcf && isdel) // Se e' titolare CF e stampa la delega, va riportata anche la conc + { + _del->put("S9", con); + _del->put("S2", uva); + } + else + _del->put("S9", ""); + } + else + { + // non usa delega bensi' bollettino o distinta: + // cerca concessione comune + // infila ufficio concessione in S9 + // e descrizione comune in S2 + _del->put("S9", con); + _del->put("S2", uva); + _del->put("S7", ""); + _del->put("S8", ""); + } + } //fine create + + // le descrizioni sulla delega non vengono + // memorizzate dai vari programmi di gestione + // e estrazione ma solo qui. + if (ok) + { + int uffiva; + TString16 key; + + key.format("%s|%s", (const char *)_nditte->lfile().get("TIPOA"), (const char *) _nditte->lfile().get("CODANAGR")); + + const TRectype & anag = cache().get(LF_ANAG, key); + if (!anag.empty()) + uffiva = anag.get_int("UFFIVA"); + + TString16 abi = _del->get("S7"); + TString16 cab = _del->get("S8"); + TString16 con = _del->get("S9"); + + // descrizione banca + if (abi.not_empty()) + { + TString codban = format("%05ld", atol(abi)); + if (!cab.empty()) codban << format("%05ld", atol(cab)); + const TRectype & ban = cache().get("%BAN", codban); + if (!ban.empty()) + { + TString desban(ban.get("S0")); + _del->put("S1", desban); + } + //che rottura: ogni giorno alla prassi cambiano idea!!! + TString16 coduff = format("%03d", uffiva); + const TRectype & uiv = cache().get("%UIV", coduff); + if (!uiv.empty()) + { + TString desiva(uiv.get("S0")); + _del->put("S2", desiva); + } + } + // Descrizione cod. concessione + if (con.not_empty()) + { + TString uva; + if (look_conc(con, uva)) + _del->put("S2", uva); + } + } + // scrive codice tributo + int ctri = 6000; + if (month == 13 && type == 7) + ctri = 6035; // acconto IVA annuale (trimestrali?) + else if (month == 13 && type == 1) + ctri = 6099; // IVA annuale + else if (month < 13 && type == 7) + ctri = 6013; // acconto mensile + else if (month < 13 && type == 1) // regular + ctri = _freqviva == "M" ? 6000 + month : 6030 + (month/3); + + _del->put("S6", format("%d",ctri)); + + if (!ok) _del->write(); + else _del->rewrite(); + + return ok; +} + +const TRectype & TLiquidazione_app::get_lia(long ditta, bool create, int year) +{ + if (year <= 0) year = atoi(_year); + if (ditta <= 0l) ditta = get_firm(); + + TString16 key; key.format("%05ld%04d", ditta, year); + TRectype & lia = (TRectype &) cache().get("%LIA", key); + + if (lia.empty()) + { + lia.zero(); + lia.put("CODTAB", key); + lia.put("S7", _freqviva); + if (create) + put_lia(lia, false); + } + return (const TRectype &) lia; +} + +const int TLiquidazione_app::put_lia(const TRectype & lia, bool re) +{ + TTable tablia("%LIA"); + + tablia.curr() = lia; + if (re) + { + const int err = tablia.rewrite(); + + cache().discard("%LIA", lia.get("CODTAB")); + return err; + } + else + return tablia.write(); +} + + + + +real TLiquidazione_app::result_liq(int month) + // risultato esatto della liquidazione del mese month, <0 a credito + // > 0 a debito; comprende TUTTI, anche il conguaglio prorata in annuale +{ + // ulteriori detrazioni, acconti, versamenti, + // rettifiche, conguagli sono gia' compresi in R0 + const TRectype & lim = get_lim(month); + + return lim.get_real("R0"); +} + +real TLiquidazione_app::iva_da_riportare(int month) +{ + real idr; + const int anno = atoi(_year); + if (month > 12) + { + if (_ver->read(anno, 12) == NOERR) + idr = _ver->get(I_ANNUALE); + } + else + { + if (_ver->read(anno, month) == NOERR) + idr = _ver->get(I_PERIODICO); + } + return idr; +} + +real TLiquidazione_app::debt_prec(int month) +{ + real r; + if (!is_first_month(month)) + { + r = result_liq(previous_month(month)); + if (!(r > ZERO && r < iva_da_riportare(month))) + r = ZERO; + } + return r; +} + + +real TLiquidazione_app::credito_prec(int month) + // ritorna l'appropriato credito precedente al mese in corso +{ + real c = ZERO; + if (!(_freqviva =="M" || is_trim(month))) // Aggiunto il 10/11/2014 + return c; + + if (is_first_month(month)) // credito inizio anno + { + const TRectype & lia = get_lia(); + const bool credito_compensabile = (lia.get("S9") == "CM"); + + c = lia.get_real("R0"); + if (credito_compensabile) + { + const real cred_util = lia.get_real("R15"); + + c -= cred_util; + } + if (c < ZERO) + c = ZERO; + } + else + { + c = result_liq(previous_month(month)); + if (c < ZERO) + c = -c; + else + c = ZERO; + } + + return c; +} + +real TLiquidazione_app::credito_costo_prec(int month) + // ritorna l'appropriato credito di costo precedente al mese in corso + // (travel agency only) +{ + real c = ZERO; + if (is_first_month(month) || month == 13) + { + // credito inizio anno + const TRectype & lia = get_lia(); + + c = lia.get_real("R5"); + } + else + { + const TRectype & lim = get_lim(previous_month(month)); + + c = lim.get_real("R2"); // qui il rimborso non c'e' + } +// look_lim(month); + return c; +} + + +real TLiquidazione_app::versamenti_IVA(int month, const char* types, bool intr) +{ + real ret(0.0); TToken_string typ(types); + + for (int i = 0; i < typ.items(); i++) + { + int tp = typ.get_int(i); + if (look_del(month,tp)) + { + real importo_dovuto_non_arrotondato(_del->get_real("R2")); + real interessi(_del->get_real("R1")); + real importo_dovuto_arrotondato(_del->get_real("R0")); + real work(importo_dovuto_non_arrotondato); + + round_imposta(work); + if (_month == 13 && _freqviva == "T" && importo_dovuto_arrotondato == work) + ret += importo_dovuto_non_arrotondato; // Questo e' l'importo lordo non arrotondato!! + else + ret += importo_dovuto_arrotondato; + //gli interessi vengono memorizzati solo se si + //devono pagare (=> nessun controllo su intra) + if (!(_is_visliq && _freqviva == "T" && _month != 13)) // toglie gli interessi se non siamo in visualiz. o la ditta non e' TRIM o siamo in annuale + ret -= interessi; // al netto degli interessi + // In caso di 13a liq e per trimestrali... devo fare la somma + // degli importi netti dovuti, ecco perche' leggo R2, + // perche togliendo poi gli interessi ottengo il dovuto netto! + // Questa casistica vale pero' solo se in R2 c'e' qualcosa(!=0) ed + // e' relativo all'importo presente in R0. Ovvero: + // nel caso si estraggano i versamenti trimestrali, i campi R2 + // vengono correttamente compilati. Se poi si modificano a mano i + // valori di R0 (tramite gestione versamenti, visualizzazione o + // calcolo acconti) tale importo non e' piu' consistente, ecco quindi + // il controllo effettuato tra R0 e ROUND(R2). In realta' sarebbe piu' + // oppurtuno che in gestione versamenti, visualizzazione liquidazione e + // calcolo acconti, vi sia la possibilita' di modificare anche R2. + // Tutto cio' e' relativo all'errore MI3386. + } + } + return ret; +} + +// Arrotonda intelligentemente alle 1000 Lire, al centesimo di Euro o all'unità di Euro +void TLiquidazione_app::round_imposta(real& d) const +{ + TIva_round ir; + ir.round(d); +} + +void TLiquidazione_app::round_al_centesimo(real& d) const +{ d.round(2); } + + +// Ritorna il parametro della liquidazione differita per la ditta corrente, cosi come +// e' scritto sui parametri liquidazione (LIA) +// Se si passa 0 (default) vede prende la ditta correntemente in corso di calcolo +// Analogamente per l'anno +bool TLiquidazione_app::is_acconto_differito(long firm, int year) +{ + const long d = (firm <= 0) ? _nditte->curr().get_long(NDT_CODDITTA) : firm; + const int y = (year <= 0) ? atoi(_year) : year; + const TRectype & lia = get_lia(d, y > 0, y); // 26/03/2012 aggiunto ,y) + + return lia.get_bool("B1"); +} + +real TLiquidazione_app::aliquota_agvia() +{ + real r; + const TString& codagv = ini_get_string(CONFIG_STUDIO, "cg", "CodAgv"); + if (codagv.full() && look_iva(codagv)) // Controlla se è vuoto! CM600475 + r = _iva->get_real("R0"); + return r; +} + + +real TLiquidazione_app::interesse_trimestrale(int month) +{ + month--; month /= 3; + real r(_ver->get(month)); // month varia da 0 a 4, proprio come da P_1_TRIMESTRE... in poi + return r; +} + +bool TLiquidazione_app::look_conc(TString& uffcon, TString& uffiva) +{ + // piazza nelle TString passate: l'ufficio concessioni + // l'ufficio IVA. Quest'ultimo e' preso dall'anagrafica se + // c'e', dal comune (primo non vuoto) se non + + // Assume _nditte correctly positioned + const TString4 ana(_nditte->lfile().get("TIPOA")); + const TString8 codana(_nditte->lfile().get("CODANAGR")); + // look anagrafica + TString16 key; + key.format("%s|%s", (const char *) ana, (const char *) codana); + + const TRectype & anag = cache().get(LF_ANAG, key); + if (anag.empty()) return false; + + // becca comune residenza fiscale + TString4 com(anag.get("COMRF")); + // se non c'e', residenza + if (com.empty()) + com = anag.get("COMRES"); + + if (com.empty()) + return false; + + // becca comune + key.format("|%s", (const char *) com); + + const TRectype comuni = cache().get(LF_COMUNI, key); + + if (comuni.empty()) return false; + + const int uffa = comuni.get_int("UFFCONC"); + if (uffcon.empty()) + uffcon = format("%03d",uffa); + if (uffcon.not_empty()) + { + const TRectype & ucc = cache().get("%UCC", uffcon); + if (!ucc.empty()) + uffiva = ucc.get("S0"); + } + + return true; +} + +const real TLiquidazione_app::credito_utilizzato_F24(int month) const +{ + real credito; + TString16 cod; + + for (int m = 1; (m < month && m < 13); m++) + { + cod.format("%s%02d", (const char*)_year, m); + const TRectype & lim = cache().get("LIM", cod); + + credito += lim.get_real("R16"); // Credito utilizzato F24 + } + return credito; +} + +const real TLiquidazione_app::credito_utilizzato_IVA(int month) const +{ + real credito; + TString16 cod; + + for (int m = 1; m < month; m++) + { + cod.format("%s%02d", (const char*)_year, m); + const TRectype & lim = cache().get("LIM", cod); + + credito += lim.get_real("R15"); // Credito utilizzato IVA + } + return credito; +} + +const real TLiquidazione_app::credito_autorizzato(int month) const +{ + real credito; + TString16 cod; + + for (int m = 1; m < month; m++) + { + cod.format("%s%02d", (const char*)_year, m); + const TRectype & lim = cache().get("LIM", cod); + + credito += lim.get_real("R20"); // Credito autorizzato F24 + } + + return credito; +} + diff --git a/cg/cg4303.cpp b/cg/cg4303.cpp index 6ecd80cc4..976e280e2 100755 --- a/cg/cg4303.cpp +++ b/cg/cg4303.cpp @@ -611,9 +611,10 @@ _DescrItem* TLiquidazione_app::recalc_rimborso(int month, const char* codatts, if (rimborsami && is_month_ok_strict(month)) { - look_lim(month); - _lim->put("B2", "X"); - _lim->rewrite(); + TRectype lim = get_lim(month); + + lim.put("B2", "X"); + put_lim(lim); } return d; } diff --git a/cg/cg4304.cpp b/cg/cg4304.cpp index 269db078e..fcdca2867 100755 --- a/cg/cg4304.cpp +++ b/cg/cg4304.cpp @@ -1,3396 +1,3488 @@ -// ------------------------------------------------------------ -// Calcolo liquidazioni -// Part 5: stampa -// fv 21-1-94 -// ------------------------------------------------------------ - -#include -#include -#include -#include - -#include "cg4300.h" - -#include -#include -#include - -// flags per annuale -#define IS_PRORATA 0x0001 - -// minchietta per prospetto ventilazione -struct _vDesc : public TObject -{ - TString4 _codiva; - real _acq, _vnd, _viv; -}; - -const char* const sep = -"------------------------------------------------------------------" -"------------------------------------------------------------------"; - -void TLiquidazione_app::set_page(int file, int cnt) -{ - _DescrItem& d = (_DescrItem&)_descr_arr[cnt]; - - set_auto_ff(FALSE); - reset_print(); - - switch(d._flags) - { - case CHG_PARMS: - set_att(d); - break; - case SET_FIRM: - set_firm(d); - break; - case PIS_ROW: - case PIM_ROW: - case PIS_ROW_D: - case PIM_ROW_D: - case PIS_ROW_DI: - case PIM_ROW_DI: - set_pim(d); - break; - case PIS_HEAD: - case PIM_HEAD: - case PIS_HEAD_D: - case PIM_HEAD_D: - case PIS_HEAD_DI: - case PIM_HEAD_DI: - set_pim_head(d); - break; - case MISC_LIQ: - set_pumpam(d); - break; - case TOT_ROW: - set_plm(d); - break; - case TOT_ROW_D: - case TOT_ROW_DI: - set_plm_diff(d); - break; - case PLAFOND: - set_plafond(d); - break; - case VENTILA: - set_ventila(d); - break; - case REGAGR: - set_regagr(d); - break; - case REGVIA: - set_viaggio(d); - break; - case THE_END: - set_grand(d); - break; - case LIQACC: - set_liqacc_2000(d); - break; - case ACCONTO: - set_acconto_p(d); - break; - case ACCHEAD: - set_acchead_p(d); - break; - case DELDEB: - set_deltab(d, false); - break; - case DELCRED: - set_deltab(d, true); - break; - default: - break; - } -} - -print_action TLiquidazione_app::postprocess_page(int file, int cnt) -{ - if (_descr_arr.items() == 0 || cnt == _descr_arr.items()-1) - return NEXT_PAGE; - return REPEAT_PAGE; -} - -bool TLiquidazione_app::preprocess_page(int file, int cnt) -{ - return _descr_arr.items() != 0; -} - -// ---------------------------------------------------------------- -// Print description -// ---------------------------------------------------------------- - -void TLiquidazione_app::describe_att(int month, const char* codatt, bool /*isresult*/, char flags) -{ - if (_isprint && _canprint) - { - TToken_string atts(codatt); - const bool single_att = atts.items() == 1; - - describe_name(month, atts, flags); - - if (single_att) - { - if (_isplafond) - describe_plafond(month, codatt); - if (_isvent) - describe_ventilation(month, codatt); - if (_isagricolo) - describe_agricolo(month, codatt); - if (_isviaggio) - describe_viaggio(month, codatt); - } - - describe_pims(month, codatt, false); // PIM - describe_pims(month, codatt, true); // PIS - - if (single_att) - describe_consistence(codatt); - } -} - -void TLiquidazione_app::describe_name(int month, const TToken_string& codatts, char flags) -{ - const bool single_att = codatts.items() == 1; - - _DescrItem* d = new _DescrItem(CHG_PARMS); - - d->_s0 = _nditte->curr().get(NDT_CODDITTA); - d->_s1 = _nditte->curr().get(NDT_RAGSOC); - - const TRectype& ndt_att = _nditte->curr(LF_ATTIV); - d->_s2 = ndt_att.get(ATT_CODATECO); - if (d->_s2.blank()) - d->_s2 = ndt_att.get(ATT_CODATT); - d->_s3 = single_att ? (const char*)ndt_att.get(ATT_DESCR) : ""; - d->_s4 = _freqviva; - - d->_f1 = month; - d->_f2 = _isbenzinaro; - d->_f3 = (word)flags; - - d->_f0 = 0; - if (_mixed && single_att) - d->_f0 = atoi(codatts.mid(5)); - - _descr_arr.add(d); -} - -void TLiquidazione_app::describe_firm(int month) -{ - if (!_isprint || !_canprint) return; - - _DescrItem* d = new _DescrItem(SET_FIRM); - - d->_s0 = _nditte->curr().get("CODDITTA"); - d->_s1 = _nditte->curr().get("RAGSOC"); - d->_s2 = _freqviva; - d->_f1 = month; - _descr_arr.add(d); -} - -void TLiquidazione_app::describe_liqacc() -{ - if (!_isprint || !_canprint) return; - - if (!look_lia()) return; - - if (_lia->get("S8") != "A") return; - - _DescrItem* d = new _DescrItem(LIQACC); - - d->_r0 = _lia->get_real("R7"); - d->_r1 = _lia->get_real("R13"); - d->_r2 = _lia->get_real("R14"); - d->_r3 = _lia->get_real("R9"); - d->_r4 = _lia->get_real("R10"); - d->_r5 = _lia->get_real("R8"); - d->_r6 = _lia->get_real("R12"); - d->_r7 = _lia->get_real("R11"); - d->_r8 = _lia->get_real("R4"); - d->_r29 = _lia->get_real("R29"); - d->_r33 = _lia->get_real("R33"); - TToken_string ff(_lia->get("S1"),'!'); - real cre_pre (ff.get(0)); - real acq_intr (ff.get(1)); - d->_r9 = cre_pre; - d->_r10 = acq_intr; - - _descr_arr.add(d); -} - -void TLiquidazione_app::describe_plafond(int month, const char* codatt) -{ - TString att(codatt); - // prepara la descrizione del riepilogo da stampare e lo accoda - real t1, t2, t3; - _DescrItem* d = new _DescrItem(PLAFOND); - - if (month == 13) - look_pla(codatt); - for (int jj = 1; jj <= 3; jj++) // three types of plafond - { - t1 = 0.0; t2 = 0.0; t3 = 0.0; - - if (month < 13) - { - look_ppa(_freqviva == "M" ? month : next_trim(month) -2, codatt,jj); - t3 = _ppa->get_real("R2"); - } - for (int m = 1; m <= month && m < 13; m++) - { - if (is_month_ok(m,month) && look_ppa(m,codatt,jj)) - { - t1 += _ppa->get_real("R0"); - t2 += _ppa->get_real("R1"); - } - } - switch (jj) - { - case 1: - d->_r0 = t1; d->_r1 = t2; - d->_r2 = month < 13 ? t3 : _pla->get_real("R5"); - break; - case 2: - d->_r3 = t1; d->_r4 = t2; - d->_r5 = month < 13 ? t3 : _pla->get_real("R6"); - break; - case 3: - d->_r6 = t1; d->_r7 = t2; - d->_r8 = month < 13 ? t3 : _pla->get_real("R7"); - break; - } - } // for tipo esenzione plafond - - _descr_arr.add(d); - - // bookmark -} - -void TLiquidazione_app::describe_ventilation(int month, const char* codatt) -{ - if (!_isvent || _isagricolo || _isviaggio) - return; - - _DescrItem* d = new _DescrItem(VENTILA); - TString16 att = codatt; - - look_plm(month, att); - - for (_pim->first(); !_pim->eof(); _pim->next()) - { - if (strcmp(*_pim_codatt,att) != 0) - continue; - - look_reg(*_pim_codreg); - look_iva(*_pim_codiva); - - int tipocr = atoi(*_pim_tipocr); - int tipodet = atoi(*_pim_tipodet); - int mese = atoi(*_pim_mese); - bool corrisp = _reg->get_bool("B0"); - real imponibile = _pim->get_real("R0"); - real imposta = _pim->get_real("R1"); - tiporeg tipomov = (tiporeg)_reg->get_long("I0"); - TString4 tipoiva = _iva->get("S1"); - - if (_year != *_pim_anno || (month == 13 && mese < 13)) - continue; - - if (imponibile.is_zero() && imposta.is_zero()) continue; - - // questi non vanno in liquidazione, i totali sono - // gia' calcolati altrove - if (tipodet == 1 || (tipodet == 3 && tipocr == 5) || tipodet == 9) - continue; - - // questi non si devono vedere perche' so' bbrutti - if (tipoiva == "NS" || tipoiva == "ES" || tipoiva == "NI") - continue; - - if (mese <= month) - { - if (tipocr == 1 && tipomov == acquisto) - { - // somma agli acquisti - _vDesc* vd = NULL; - for (int i = 0; i < d->_arr.items(); i++) - { - _vDesc* vv = (_vDesc*)&(d->_arr[i]); - if (strcmp(vv->_codiva,*_pim_codiva) == 0) - { vd = vv; break; } - } - if (vd == NULL) { vd = new _vDesc; } - - vd->_acq += (imponibile+imposta); - d->_r0 += (imponibile+imposta); - - if (vd->_codiva.empty()) - { - vd->_codiva = *_pim_codiva; - d->_arr.add(vd); - } - } - else if ((is_month_ok(mese,month) || month == 13) && corrisp - && _pim->get_bool("B1") && - tipocr == 0 && tipomov == vendita) - // non sono sicurissimo della above condition - { - // somma alle vendite - _vDesc* vd = NULL; - for (int i = 0; i < d->_arr.items(); i++) - { - _vDesc* vv = (_vDesc*)&(d->_arr[i]); - if (strcmp(vv->_codiva,*_pim_codiva) == 0) - { vd = vv; break; } - } - if (vd == NULL) { vd = new _vDesc; } - - vd->_vnd += imponibile; - vd->_viv += imposta; - - d->_r1 += imponibile+imposta; - - if (vd->_codiva.empty()) - { - vd->_codiva = *_pim_codiva; - d->_arr.add(vd); - } - } - } - } - - d->_r0 = _pam->get_real("R2"); // Totale acquisti - d->_r1 = _pam->get_real("R3"); // Totale vendite - - if (d->_r1.is_zero() || d->_r0.is_zero()) - delete d; - else - { - // Questo e' il fantastico moltiplicatore - d->_r2 = d->_r1 / d->_r0; - _descr_arr.add(d); - } -} - -void TLiquidazione_app::describe_agricolo(int month, const char* codatt) -{ - _DescrItem* d = new _DescrItem(REGAGR); - - // Setta l'array interno con tutti gli items relativi alla tabella PIA - TArray& agr_array = d->_arr; - for (_pia->first(); !_pia->eof(); _pia->next()) // Scorre i progressivi agricoli - { - if (strcmp((const char*)*_pia_codatt, codatt) == 0 && - is_month_plain(atoi(*_pia_mese)) && _year == *_pia_anno) // E sono gia' in ordine di codice... - { - _DescrItem* p = new _DescrItem(PROGAGR); - p->_r0 = _pia->get_real("R0"); // Imponibile - p->_r1 = _pia->get_real("R1"); // Imposta - p->_s0 = *_pia_codord; // Codice iva ordinario - p->_s1 = *_pia_codcom; // Codice iva compensazione - if (p->_r0 != ZERO || p->_r1 != ZERO) - agr_array.add(p); // Aggiunge il fottuto item agricolo - } - } - - for (int mese = month == 13 ? 13 : 1; mese <= month; mese++) - { - if (!is_month_ok(mese,month)) - continue; - - if (!look_plm(mese, codatt)) - continue; - - d->_r0 += _plm->get_real("R5"); - d->_r1 += _plm->get_real("R6"); - d->_r2 += _plm->get_real("R7"); - d->_r3 += _plm->get_real("R8"); - d->_r4 += _plm->get_real("R9"); - d->_r5 += _plm->get_real("R10"); - d->_r6 += _plm->get_real("R11"); - d->_r7 += _pum->get_real("R10"); - d->_r8 += _pum->get_real("R11"); - d->_r11 += _plm->get_real("R13"); - } - // Aggiungo anche questi per comodita' futura. - // in caso di ditta a regime agricolo - // alias: - // _r9 mantiene la percentuale (gia' arrotondata!) - // _r10 mantiene l'iva detraibile calcolata! - d->_r9 = d->_r8 / (d->_r7 + d->_r8); - round_al_centesimo(d->_r9); - d->_r10 = d->_r6 * d->_r9; - d->_r9 *= CENTO; - round_al_centesimo(d->_r10); - - _descr_arr.add(d); -} - -void TLiquidazione_app::describe_viaggio(int month, const char* codatt) -{ - if (!look_lim(month)) return; - - _DescrItem* d = new _DescrItem(REGVIA); - - - for (int mese = month == 13 ? 13 : 1; mese <= month; mese++) - { - 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 - d->_r2 += _plm->get_real("R6"); // corrispettivi fuori CE - d->_r3 += _plm->get_real("R7"); // acquisti CEE - 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 - } - - // credito di costo precedente (CHECK annuale) - d->_r8 = credito_costo_prec(month); - - // Solita minchiatina dell'arrotondamento alle 1000 lirette se siamo in annuale - if (month == 13 || atoi(_year) >= 2000) // CM500314 e CM500315 - { - round_imposta(d->_r0); - round_imposta(d->_r1); - round_imposta(d->_r2); - round_imposta(d->_r3); - round_imposta(d->_r4); - round_imposta(d->_r5); - round_imposta(d->_r6); - round_imposta(d->_r8); - } - - d->_r7 = d->_r4.is_zero() ? ZERO : (d->_r4 * CENTO)/(d->_r4 + d->_r6); d->_r7.round(2); // percentuale - d->_r9 = (d->_r1 * d->_r7)/CENTO; - - if (month == 13) - round_imposta(d->_r9); - else - round_al_centesimo(d->_r9); - - // Calcola l'iva a debito, visto che servira' anche nel calcolo liquidazione (solo annuale) - const real aliva = aliquota_agvia(); - const real alcnt = aliva + CENTO; - d->_r10 = (d->_r0 + d->_r9) - (d->_r3 + d->_r4 + d->_r8); // base imponibile lorda - if (d->_r10.sign() > 0) - { -// d->_r11 = (d->_r10/(alcnt/CENTO)) * (aliva/CENTO); // iva dovuta - d->_r11 = d->_r10 * aliva / alcnt; // iva dovuta - if (month == 13) - round_imposta(d->_r11); - else - round_al_centesimo(d->_r11); - } - _descr_arr.add(d); -} - -void TLiquidazione_app::describe_pims(int month, const char* codatt, const bool describe_pis) - // le si passa una tokenstring (o un codatt) e lei, da brava, calcola - // cumulando per tutte le attività nominatele - // ogni riga riguarda un codiva ma tutti i registri - // se il mese e' 13 si guarda tutto l'anno - // se si tratta di una sola attività in att. mista evidenziata o servizievole, - // stampa solo vendite e corrispettivi - // L'ultimo parametro serve per calcolare i PIS (progressivi del periodo successivo) -{ - TToken_string atts(codatt); - const TString8 ref(atts.items() == 1 ? codatt : "ALL"); - int last = _descr_arr.last(); - bool issosp = false; - real t0, t1, t2, t3, t4, t5, t26, t27, t28, t29, t30, t31, t32, t33; - real rt0, rt1, rt2, rt3, rt4, rt5; - real autodafe, autodafe_iva, art40, art40_iva; - real diffimp, diffiva, diffincimp, diffinciva; - real diffimp_acq, diffiva_acq, diffincimp_acq, diffinciva_acq; - const bool skip_acq = atts.items() == 1 && _mixed; - - // descrittore riga autodafe' - _DescrItem* ads = NULL; - // descrittore riga iva dovuta ag. viaggio' - _DescrItem* iads = NULL; - - // Seleziona la tabella corretta: PIM o PIS e l'identificatore - TTable* tab = describe_pis ? _pis : _pim; - const word PIM_PIS = describe_pis ? PIS_ROW : PIM_ROW; - - // questa cazzata serve per far apparire l'intestazione delle colonne - // anche se le colonne non ci sono; in tal modo si ottiene una peggior - // chiarezza, una peggiore efficienza, una gran rottura di coglioni, - // ma risulta identico al dio Sistema. - _DescrItem * hea = NULL; - _DescrItem * head = NULL; - _DescrItem * headi = NULL; - _DescrItem * tot = NULL; - _DescrItem * totd = NULL; - _DescrItem * totdi = NULL; - int totpos = 0; - - // Assoc array per memorizzare i corrispettivi da scorporare. Tali corrispettivi verranno - // aggiunti alla fine del ciclo, scorrendo tutte le righe generate. - TAssoc_array corr_ann; - _CorrItem cx; - - FOR_EACH_TOKEN(atts, tmpatt) - { - const TString8 att(tmpatt); - - tab->zero(); tab->put("CODTAB", _year); // 24-02-2014 partiamo dall'anno giusto! - for (int terr = tab->read(_isgteq); terr == NOERR; terr = tab->next()) - { - _DescrItem* d = NULL; - // compute - const TString80 codtab = tab->get("CODTAB"); - const TString4 anno = codtab.mid(0,4); - - if (anno != _year) - break; // 27-02-2014 finiamo con l'anno sbagliato! - - const TString8 activity= codtab.mid(4,6); - const int mese = atoi(codtab.mid(13,2)); - const int tipodet = atoi(codtab.mid(20,1)); - - const TString4 codreg = codtab.mid(10,3); - if (!look_reg(codreg)) - continue; - - TString4 codiva = codtab.mid(16,4); codiva.trim(); - if (!look_iva(codiva)) - continue; - - tiporeg tipomov = (tiporeg)_reg->get_int("I0"); - bool corrisp = _reg->get_bool("B0"); - const TString4 tipoiva = _iva->get("S1"); - const TString4 other = tab->get("S4"); - TToken_string s1(tab->get("S1"), '!'); // Imponibile/iva fatture in ritardo - real rit_imp(s1.get(0)); - real rit_iva(s1.get(1)); - - /* Perchè _pim invece di tab ? 17-10-2012 - diffimp = _pim->get_real("R26"); - diffiva = _pim->get_real("R27"); - diffincimp = _pim->get_real("R28"); - diffinciva = _pim->get_real("R29"); - - diffimp_acq = _pim->get_real("R30"); - diffiva_acq = _pim->get_real("R31"); - diffincimp_acq = _pim->get_real("R32"); - diffinciva_acq = _pim->get_real("R33"); */ - - diffimp = tab->get_real("R26"); - diffiva = tab->get_real("R27"); - diffincimp = tab->get_real("R28"); - diffinciva = tab->get_real("R29"); - - diffimp_acq = tab->get_real("R30"); - diffiva_acq = tab->get_real("R31"); - diffincimp_acq = tab->get_real("R32"); - diffinciva_acq = tab->get_real("R33"); - - const bool is_rit= tipodet != 0 && month == 13 && !rit_imp.is_zero(); //Se fattura in ritardo con tipo detr. != 0 e si sta calcolando l'annuale - const tipo_sospensione sosp_imp = _reg->get_bool("B1") ? (tipo_sospensione) _reg->get_int("I9") : nessuna; - issosp |= (sosp_imp != nessuna); // Setta il flag di presenza registri in sospensione (qualsiasi tipo: normale, vol_affari, liquidazione) - - // ACHTUNG! Corrispettivi da ventileer possono ventilare ad un altro codiva; in tal caso si scrive quello - if (corrisp && other.full()) - { - look_iva(other); - codiva = other; - } - // se e' corrispettivo da ventilare non scrivo un cannolo ripieno visto che e' stato ventilato - if (tipomov == vendita && tipoiva == "VE" && !describe_pis) - continue; - - // se e' il dettaglio di una attivita' mista non stampa gli acquisti, il perche' losalamadonna - if (tipomov == acquisto && skip_acq) - continue; - - // questi non vanno in liquidazione, i totali sono gia' calcolati altrove - if ((tipodet == 1 || tipodet == 3 || tipodet == 9) && !is_rit) - continue; - - // se ha tutti gli importi nulli viene da un annullamento di - // progressivi esistenti (achtung fatture con scontrino) - if (tab->get_real("R0").is_zero() && - tab->get_real("R1").is_zero() && - tab->get_real("R2").is_zero() && - tab->get_real("R5").is_zero() && - tab->get_real("R6").is_zero() && - tab->get_real("R26").is_zero() && - tab->get_real("R27").is_zero() && - tab->get_real("R28").is_zero() && - tab->get_real("R29").is_zero() && - tab->get_real("R30").is_zero() && - tab->get_real("R31").is_zero() && - tab->get_real("R32").is_zero() && - tab->get_real("R33").is_zero()) - continue; - - if (activity == att && is_month_plain(mese) /*&& _year == anno*/) // commentato 27-02-2015 - { - // vedi se c'e' gia' un item corrispondente - int i; - for(i = last+1; i < _descr_arr.items(); i++) - { - _DescrItem& wd = (_DescrItem&)_descr_arr[i]; - if (wd._flags == PIM_PIS && wd._s0 == ref && wd._s1 == codiva) - { - d = &wd; - break; - } - if (wd._flags == TOT_ROW) - break; - if (wd._flags == PIM_PIS && - wd._s0 == ref && - wd._s1 > codiva) - break; - } - if (d == NULL) - { - const bool isfirst = (hea == NULL); - - if (isfirst) - { - hea = new _DescrItem(describe_pis ? PIS_HEAD : PIM_HEAD); - hea->_f0 = skip_acq; // così non compare nemmeno la colonnina! contento? - hea->_f1 = true; - _descr_arr.insert(hea, i++); - tot = new _DescrItem(TOT_ROW); - totpos = _descr_arr.insert(tot, i); - } - else - totpos++; - d = new _DescrItem(PIM_PIS); - d->_f0 = isfirst; - d->_s0 = ref; - d->_s1 = codiva; - _descr_arr.insert(d, i); - } - - if (tipomov == acquisto) - { - // Ci sono anche le fatture in ritardo (solo in annuale)! Con tipo detraibilita' 1,3,9 - if (sosp_imp != vol_affari) - { - d->_r4 += is_rit ? rit_imp : tab->get_real("R0"); - d->_r5 += is_rit ? rit_iva : tab->get_real("R1"); - t4 += is_rit ? rit_imp : tab->get_real("R0"); - t5 += is_rit ? rit_iva : tab->get_real("R1"); - } - // Totalizza anche quelli valevoli per vol. affari. - if (sosp_imp != liquidazione) - { - rt4 += is_rit ? rit_imp : tab->get_real("R0"); - rt5 += is_rit ? rit_iva : tab->get_real("R1"); - } - } - else // vendita - { - const bool is_key = corr_ann.is_key(codiva); - cx._totale = 0; - _CorrItem& ca = is_key ? (_CorrItem&) corr_ann[codiva] : cx; - if (sosp_imp != vol_affari) - ca._totale += tab->get_real(tipoiva == "VE" ? "R2" : "R3"); // Se e' codice IVA da Vent. stiamo scorrendo i PIS: va stampato il lordo dei progressivi successivi - if (sosp_imp != liquidazione) - ca._totale_vf += tab->get_real(tipoiva == "VE" ? "R2" : "R3"); - if (!is_key) // se non c'e' lo aggiunge - { - ca._aliquota = _iva->get_real("R0")/CENTO; // Se e' nuovo setta l'aliquota - corr_ann.add(codiva,ca); - } - // vedi corrispettivi veri e falsi - real cvi = tab->get_real("R0"); // imp. totale - real cvv = tab->get_real("R1"); // iva totale - real cfi = tab->get_real("R13"); // imp. falsi corrispettivi - real cfv = tab->get_real("R14"); // iva falsi corrispettivi - // MI3404... - // Giochiamo sopra la particolarita' che se non e' un registro di corrispettivi - // allora se R5 o R6 sono <> 0 significa che trattasi di documento FS, - // che pertanto va stornato dal totale corrispettivi. (Cosi' volle Vladimiro) - const real ifs(tab->get_real("R5")); // imp. fatture con scontrino - const real vfs(tab->get_real("R6")); // iva fatture con scontrino - if (!corrisp) - { - if (sosp_imp != vol_affari) - { - d->_r2 -= ifs; // tolgo FS dai corrispettivi - d->_r3 -= vfs; - t2 -= ifs; // idem per i totali - t3 -= vfs; - } - if (sosp_imp != liquidazione) - { - rt2 -= ifs; - rt3 -= vfs; - } - } - - if (corrisp) - { - cvi -= cfi; - cvv -= cfv; - } - - if (corrisp) - { - // usa R0 e R1 visto che la ventilazione e' gia' - // stata calcolata - if (sosp_imp != vol_affari) - { - d->_r2 += (cvi /* - ifs */); // tolgo FS dai corrispettivi - d->_r3 += (cvv /* - vfs */); - d->_r0 += ifs; // aggiungo FS alle vendite - d->_r1 += vfs; - t2 += (cvi /* - ifs */); // idem per i totali - t3 += (cvv /* - vfs */); // non sono molto convinto ma vogliono cio' - t0 += ifs; // ...avevo ragione e infatti l'ho cambiato - t1 += vfs; - } - if (sosp_imp != liquidazione) - { - rt2 += cvi; - rt3 += cvv; - rt0 += ifs; - rt1 += vfs; - } - } - - if (!corrisp || (!cfv.is_zero() || !cfi.is_zero())) - { - real adf, adi; // autofatture non residenti art. 17 - real va7i, va7v; // ammontare art 40 c. 5/6/8 - - real vendi = corrisp ? cfi : tab->get_real("R0"); - real vendv = corrisp ? cfv : tab->get_real("R1"); - - // si scorporano solo per l'annuale, altrimenti - // vengono normalmente considerati nelle vendite - if (month == 13) - { - TToken_string kr(tab->get("S0"),'!'); - va7i = kr.get(0); - va7v = kr.get(1); - adf = tab->get_real("R7"); - adi = tab->get_real("R8"); - } - - if (sosp_imp != vol_affari) - { - d->_r0 += vendi - adf - va7i; - d->_r1 += vendv - adi - va7v; - t0 += vendi /* - adf */; - t1 += vendv /* - adi */; - } - if (sosp_imp != liquidazione) - { - rt0 += vendi; - rt1 += vendv; - } - - autodafe += adf; - art40 += va7i; - art40_iva += va7v; - } - } -// if (tipomov == vendita) // ci sono anche gli acquisti per cassa! - { - /* Non voglio piu' il riepilogo delle fatture emesse IVA diff - if (!diffimp.is_zero() || !diffiva.is_zero() || - !diffimp_acq.is_zero() || !diffiva_acq.is_zero()) - { - const word id = describe_pis ? PIS_ROW_D : PIM_ROW_D; - int j; - - d = NULL; - for (j = totpos + 1; j < _descr_arr.items(); j++) - { - _DescrItem * wd = (_DescrItem*)&_descr_arr[j]; - const bool found = wd->_flags == id && wd->_s0 == ref; - - if (found && wd->_s1 == codiva) - { - d = wd; - break; - } - if (wd->_flags == TOT_ROW_D) - break; - if (found && wd->_s1 > codiva) - break; - } - if (d == NULL) - { - const bool isfirst = head == NULL; - - if (isfirst) - { - head = new _DescrItem(describe_pis ? PIS_HEAD_D : PIM_HEAD_D); - _descr_arr.insert(head, j++); - head->_f0 = false; - head->_f1 = true; - head->_f2 = atoi(activity.right(1)); // Tipo attività = 1 (servizi) o 2 (mista) - head->_f3 = tipomov; - totd = new _DescrItem(TOT_ROW_D); - _descr_arr.insert(totd, j); - } - d = new _DescrItem(id); - _descr_arr.insert(d, j); - d->_f0 = isfirst; - d->_s0 = ref; - d->_s1 = codiva; - } - d->_r26 += diffimp; - d->_r27 += diffiva; - t26 += diffimp; - t27 += diffiva; - d->_r30 += diffimp_acq; - d->_r31 += diffiva_acq; - t30 += diffimp_acq; - t31 += diffiva_acq; - } - */ - if (!diffincimp.is_zero() || !diffinciva.is_zero() || - !diffincimp_acq.is_zero() || !diffinciva_acq.is_zero()) - { - const word id = describe_pis ? PIS_ROW_DI : PIM_ROW_DI; - d = NULL; - int j; - for (j = totpos + 1; j < _descr_arr.items(); j++) - { - _DescrItem& wd = (_DescrItem&)_descr_arr[j]; - const bool found = wd._flags == id && wd._s0 == ref; - - if (found && wd._s1 == codiva) - { - d = &wd; - break; - } - if (wd._flags == TOT_ROW_DI) - break; - if (found && wd._s1 > codiva) - break; - } - if (d == NULL) - { - const bool isfirst = headi == NULL; - if (isfirst) - { - headi = new _DescrItem(describe_pis ? PIS_HEAD_DI : PIM_HEAD_DI); - _descr_arr.insert(headi, j++); - headi->_f0 = false; - headi->_f1 = true; - headi->_f2 = atoi(activity.right(1)); // Tipo attività = 1 (servizi) o 2 (mista) - headi->_f3 = tipomov; - totdi = new _DescrItem(TOT_ROW_DI); - _descr_arr.insert(totdi, j); - } - d = new _DescrItem(id); - _descr_arr.insert(d, j); - d->_f0 = isfirst; - d->_s0 = ref; - d->_s1 = codiva; - } - d->_r28 += diffincimp; - d->_r29 += diffinciva; - t28 += diffincimp; - t29 += diffinciva; - d->_r32 += diffincimp_acq; - d->_r33 += diffinciva_acq; - t32 += diffincimp_acq; - t33 += diffinciva_acq; - } - } - } - } // End of _pim cycle - - real impc,ivac; // Aggiunge lo scorporo dei corrispettivi - const int ditems = _descr_arr.items(); - for (int i=last+1;iget_real("R13"); - if (!describe_pis && iva74t > ZERO) - { - if(iads == NULL) iads = new _DescrItem(PIM_ROW); - iads->_s0 = "74TER"; // cosi' vollero - iads->_s1 = "IVA "; // cosi' vollero - iads->_s2 = " dovuta - 74 ter"; // cosi' vollero - iads->_r1 += iva74t; - t1 += iva74t; - rt1 += iva74t; - iads->_f0 = false; - } - } // fine while (codatt) - - if (!describe_pis && (art40 > ZERO || art40_iva > ZERO)) - { - _DescrItem* ads = new _DescrItem(PIM_ROW); - ads->_s0 = ref; - ads->_s1 = "VA7"; - ads->_r0 = art40; - ads->_r1 = art40_iva; - ads->_f0 = false; - _descr_arr.insert(ads, totpos++); - } - - if (!describe_pis && (autodafe > ZERO || autodafe_iva > ZERO)) - { - _DescrItem* ads = new _DescrItem(PIM_ROW); - ads->_s0 = ref; - ads->_s1 = "AF"; // così vollero, inoltre non è più A35 ma AF, come sul dio sistema - ads->_r0 = autodafe; - ads->_r1 = autodafe_iva; - ads->_f0 = false; - _descr_arr.insert(ads, totpos++); - } - - // ag. viaggio: iva dovuta 74 ter la vogliono in mezzo ai progressivi - if (iads != NULL) - _descr_arr.insert(iads, totpos++); - - - // prepara una bella riga di totali - if (tot != NULL) - { - tot->_r0 = t0; tot->_r1 = t1; - tot->_r2 = t2; tot->_r3 = t3; - tot->_r4 = t4; tot->_r5 = t5; - } - if (totd != NULL) - { - totd->_r26 = t26; - totd->_r27 = t27; - totd->_r30 = t30; - totd->_r31 = t31; - } - if (totdi != NULL) - { - totdi->_r28 = t28; - totdi->_r29 = t29; - totdi->_r32 = t32; - totdi->_r33 = t33; - totdi->_diff_ven_ap = _diff_ven_ap; - totdi->_diff_ven_ap_iva = _diff_ven_ap_iva; - totdi->_diff_acq_ap = _diff_acq_ap; - totdi->_diff_acq_ap_iva = _diff_acq_ap_iva; - } - // Totali progressivi da registri, comprensivi dei valori per calcolo vol affari. - if (tot != NULL && issosp) // Setta i valori (e la conseguente stampa della riga) solo se presenti registri in sospensione - { - tot->_r11 = rt0; tot->_r12 = rt1; - tot->_r13 = rt2; tot->_r14 = rt3; - tot->_s2 = rt4.string(); tot->_s3 = rt5.string(); - } - - // aggiunge dati ptm - _DescrItem* t = new _DescrItem(MISC_LIQ); - t->_f2 = describe_pis; //isfirst; // per il form feed o meno alla fine - - if (!describe_pis) - { - TToken_string ttm("0|0|0"); - - const bool annual = month == 13; - const int limit = annual ? 13 : month; - int m = annual ? month : 1; - for (; m <= limit; m++) - { - if (!is_month_ok(m,month)) - continue; - - FOR_EACH_TOKEN (atts, tmpatt) - { - const TString8 att(tmpatt); - look_plm(m, att); - real ad1, ad2; - - if (tot == NULL) - { - tot = new _DescrItem(TOT_ROW); - _descr_arr.insert(tot, -1); - } - - tot->_r6 += _pom->get_real("R0"); // acq. intracomunitari - tot->_r7 += _pom->get_real("R1"); // inded. art 19 - tot->_r8 += _pom->get_real("R2"); // IVA su inded. art. 19 - t->_r0 += _pom->get_real("R3"); // acq. ammortizz. detr - t->_r1 += _pom->get_real("R4"); // IVA acq. ammort. detr - t->_r2 += _pum->get_real("R2"); // ammort. detr. 6% - t->_r3 += _pum->get_real("R3"); // IVA ammort detr. 6% - t->_r4 += _pom->get_real("R5"); // acq. beni rivendita - t->_r5 += _pom->get_real("R6"); // IVA acq. beni rivendita - t->_r6 += _pom->get_real("R7"); // acq. leasing - t->_r7 += _pom->get_real("R8"); // IVA acq. leasing - t->_r8 += _pum->get_real("R0"); // cessioni beni ammort. - t->_r9 += _pum->get_real("R1"); // IVA su cessioni ammort. - t->_r10 += _pum->get_real("R4"); // tot. esenti IVA - if (!annual) // Se non siamo in annuale prende il prorata su doc. acq. anno precedente - { - t->_r12 += _plm->get_real("R14"); - t->_r13 = _plm->get_real("R4"); // percentuale prorata anno precedente - t->_r14 += _plm->get_real("R15"); - t->_r15 = _plm->get_real("R16"); // percentuale prorata 2 anni addietro - } - - // pro-rata indetraibile sui doc. acq. anno attuale - // in caso di liq. annuale prende il totale (tutto R2) - t->_r11 += _plm->get_real("R2"); - t->_r11 -= _plm->get_real("R14") + _plm->get_real("R15"); - - ad1 = real(ttm.get(1)); - ad2 = real(ttm.get(2)); - ad1 += _pom->get_real("R11"); - ad2 += _pom->get_real("R12"); - ttm.add(_plm->get("R12"), 0); // % pro-rata anno corrente - ttm.add(ad1.string(),1); // imp. acq. amm. indetr. - ttm.add(ad2.string(),2); // IVA acq. amm. indetr - t->_s0 = ttm; - - t->_f0 = _prorata.percentuale(_year)!=INVALID_PRORATA && (month != 13); // flag per segnalare l'esistenza - tot->_r9 += _pom->get_real("R9"); // acq. inded. su ricavi esenti - tot->_r10 += _pom->get_real("R10"); // IVA acq. inded. su ricavi esenti - - // passaggi interni - real aipip(tot->_s0); // progressivo ... - real aipivp(tot->_s1); // ... (che mazzata sulle palle...) - aipip += _pum->get_real("R8"); // acq. inded. per pass. int - aipivp += _pum->get_real("R9"); // IVA acq. inded. per pass. int - tot->_s0 = aipip.string(); // risbatto ... - tot->_s1 = aipivp.string(); // .. - - // spese generali. - real spgnp(t->_s2); // progressivo ... - real spgnvp(t->_s3); // ... (che doppia mazzata sulle palle...) - spgnp += _pam->get_real("R10"); // spese generali. - spgnvp += _pam->get_real("R11"); // IVA spese generali. - t->_s2 = spgnp.string(); // risbatto ... - t->_s3 = spgnvp.string(); // .. - - // sospensione imposta: non piu' due palle, ma QUATTRO... - // caro Ferdinando... ora son divenute ben OTTO... - // grazie all'iva ad esigibilità differita da pagare/de"TRARRE" - TToken_string tt(t->_s4); - real aqsi(tt.get(0)); - real aqsv(tt.get(1)); - real vnsi(tt.get(2)); - real vnsv(tt.get(3)); - real aqli(tt.get(4)); - real aqlv(tt.get(5)); - real vnli(tt.get(6)); - real vnlv(tt.get(7)); - - aqsi += _pam->get_real("R6"); - aqsv += _pam->get_real("R7"); - vnsi += _pam->get_real("R8"); - vnsv += _pam->get_real("R9"); - aqli += _pam->get_real("R12"); - aqlv += _pam->get_real("R13"); - vnli += _pam->get_real("R14"); - vnlv += _pam->get_real("R15"); - - tt = ""; - tt.add(aqsi.string()); - tt.add(aqsv.string()); - tt.add(vnsi.string()); - tt.add(vnsv.string()); - tt.add(aqli.string()); - tt.add(aqlv.string()); - tt.add(vnli.string()); - tt.add(vnlv.string()); - t->_s4 = tt; - - } // while (attivita') - } // for (mese ok) - - // Cazzata orrenda ma necessaria CM500308 - if (tot != NULL && issosp) - { - rt4 += tot->_r7; rt5 += tot->_r8; // Det 1 - rt4 += tot->_r9; rt5 += tot->_r10; // Det 3 - rt4 += real(tot->_s0); rt5 += real(tot->_s1); // Det 9 - tot->_s2 = rt4.string(); tot->_s3 = rt5.string(); - } - - // annual follows in _arr - if (month == 13 && ref != "ALL") - { - // tutte quelle cose che vanno alla liquidazione annuale, come il - // calcolo del prorata o del nuovo plafond o .... - if (look_pla(codatt)) - { - real v1 = _pla->get_real("R14"); // Totale imponibile vendite - real v2 = _pla->get_real("S1"); // Volume d'affari II attività - real ris = v1 + v2; - real e1 = _pla->get_real("R1"); // Totale vendite esenti C1 - real e2 = _pla->get_real("R2"); // Totale vendite esenti C2 - real e3 = _pla->get_real("R3"); // Totale vendite esenti C3 - real e4 = _pla->get_real("R15"); // Totale vendite esenti C1A - real e5 = _pla->get_real("R16"); // Totale vendite beni ammortizzabili esenti C3 - real e6 = _pla->get_real("R17"); // Totale vendite beni ammortizzabili esenti C1A - real bam = _pla->get_real("R4"); // Cessione beni ammortizzabili - real vrc = _pla->get_real("R18"); // Vendite reverse charge - real iaq = _pla->get_real("R11"); // IVA acquisti - real ppg = _pla->get_real("R12"); // pro-rata pagato - - // calcola nuovo prorata per ogni attivita' (miste: 1+2) - real pr; - const real rsa = ris - (e3-e5) - (e4-e6) - vrc; - if (!rsa.is_zero()) - { - const real rsn = rsa - e1; - pr = CENTO - (rsn * CENTO / rsa); // Percentuale di indetraibilita: reciproco della percentuale di detraibilita' - pr.round(0); - } - - real co = 0.0; - real topay = 0.0; - //if (pr != _prorata.current()) - { - // calcolo conguaglio -- se positivo e' a debito - if (pr > ZERO) - { - topay = (iaq + ppg) * pr / CENTO; - round_imposta(topay); - } - co = topay - ppg; - round_imposta(co); - } - - _DescrItem* dd = new _DescrItem(ANNUAL); - - // MonsterFish: arrotonda all'Euro C1,C2,C3,C1A - round_imposta(e1); - round_imposta(e2); - round_imposta(e3); - round_imposta(e4); - round_imposta(e5); - round_imposta(e6); - round_imposta(bam); - round_imposta(ris); - round_imposta(vrc); - - // segna flag prorata - if ((e1+e2+e3+e4) > ZERO) - { - dd->_f0 |= IS_PRORATA; - } - dd->_r0 = ris; - dd->_r1 = e1; - dd->_r2 = pr > ZERO ? pr : ZERO; - dd->_r3 = co; - dd->_r4 = e2; - dd->_r5 = e3; - dd->_r6 = topay; - dd->_r7 = e4; - dd->_r8 = e5; - dd->_r9 = e6; - dd->_r10 = vrc; - t->_arr.add(dd); - } - } - } - _descr_arr.add(t); -} - -void TLiquidazione_app::describe_liq(int month, const char* codatts, _DescrItem* di) -{ - if (!_isprint || !_canprint) - return; - - if (!look_lim(month)) - return; - - _DescrItem* d = new _DescrItem(THE_END); - - // gli diamo la stessa struttura di LIM - d->_r0 = _lim->get_real("R0"); // Risultato - d->_r1 = _lim->get_real("R1"); // Rimborso - d->_r2 = _lim->get_real("R2"); - d->_r3 = _lim->get_real("R3"); - d->_r4 = _lim->get_real("R4"); - d->_r5 = _lim->get_real("R5"); // rettifiche - d->_r6 = _lim->get_real("R6"); - d->_r7 = _lim->get_real("R14"); - d->_r9 = _lim->get_real("R9"); - d->_r29 = _lim->get_real("R29"); // fdiffinc_iva_ven - d->_r33 = _lim->get_real("R33"); // fdiffinc_iva_acq - - TToken_string tt(80); - tt.add(_lam->get("R0")); // IVA Vendite - tt.add(_lam->get("R1")); // IVA Acquisti - tt.add(_lam->get("R2")); // Credito precedente - tt.add(_lam->get("R3")); // Debito precedente - tt.add(_lam->get("R4")); - - d->_s0 = tt; - d->_s1 = _lim->get("R11"); // Acc. dec. - d->_s2 = _lim->get("R12"); - d->_s3 = _lim->get("R13"); - - // descrizione rettifiche - if (month < 13) - { - d->_s4 = _lim->get("S0"); - 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 - d->_r16 = _lim->get_real("R16"); // Credito utilizzato F24 - d->_r17 = _lim->get_real("R17"); // Variazioni d'imposta - d->_r18 = _lim->get_real("R18"); // Imposta non versata - d->_r19 = _lim->get_real("R19"); // Crediti speciali - - d->_f1 = is_first_month(month); - - // rispettiamo tutte le casistiche per i versamenti se non siamo in visualizzazione - // analogamente in Visualizzazione ma solo nel caso dell'annuale. - // In tutti gli altri casi va a cercare la delega - d->_r8 = (_month == 13 || !_is_visliq) ? _lim->get_real("R8") : versamenti_IVA(_month, "1"); - - if (_month == 13) - { - const int anno = atoi(_year); - // Credito utilizzato inizio anno (aggiunto 29-07-2014) - if (look_lia(0l, false, anno)) - { - if (_lia->get("S6") != "NV") - d->_r15 = _lia->get_real("R15"); - } - - if (look_lia(0l, false, anno+1)) - d->_r20 = _lia->get_real("R0"); // Credito da riportare all'anno prossimo - } - - // aggiunge eventuale satellite per rimborso infraannuale - if (di != NULL) - { - if (d->_r0.sign() < 0) - d->_arr.add(di); - else - delete di; - } - - if (!_is_visliq) - { - _DescrItem* dv = describe_deleghe(month); - if (dv != NULL) d->_arr.add(dv); - } - - _descr_arr.add(d); -} - -_DescrItem* TLiquidazione_app::describe_deleghe(int month) -{ - _stampa_vers = _stampa_acc = FALSE; - - if (_lim->get_real("R0") > ZERO) - { - real iva = _lim->get_real("R0") + _lim->get_real("R14"); - if (month == 13) - round_imposta(iva); - if (iva >= iva_da_riportare(_month)) - _stampa_vers = TRUE; - } - - _stampa_acc = (month == 12 && (_freqviva == "M" || (_isbenzinaro && _gest4))) - ||(month == 13 && _freqviva == "T" && !(_isbenzinaro && _gest4)); - - if (!_stampa_vers && !(_stampa_acc && look_del(12,7))) return NULL; - - _DescrItem* d = new _DescrItem(DELEGA); - - d->_f0 = 0; - - //prospettino versamento - if (_stampa_vers) //solo se sono a debito - if (look_del(month,month == 13 ? 2 : 1)) - { - if (_del->get_bool("B0")) // Stampata? - { - //_del->S2 descr. ufficio iva/concessione - //_del->S1 descrizione banca - d->_s0 = _del->get("S9"); // Cod Ufficio concessione - d->_s1 = _del->get("S7"); // Cod ABI - d->_s2 = _del->get("S8"); // Cod CAB - d->_r0 = _del->get_real("R0"); - d->_d0 = _del->get_date("D0"); - } // altrimenti lascia tutto in bianco e ci scriveranno i dati a mano - } - - //prospettino acconto - if ( (month == 12 && (_freqviva == "M" || (_isbenzinaro && _gest4))) - || (month == 13 && _freqviva == "T" && !(_isbenzinaro && _gest4)) ) - if (look_del(12,7)) //sia che sia a debito che a credito - { - d->_s4 = "ACC"; - TToken_string t; - if (_del->get_bool("B0")) // Stampata? - { - //_del->S2 descr. ufficio iva/concessione - //_del->S1 descrizione banca - t.add(_del->get("S9")); // Cod Conc - t.add(_del->get("S7")); // Cod ABI - t.add(_del->get("S8")); // Cod CAB - t.add(_del->get_real("R0").string()); - t.add(_del->get("D0")); - } - d->_s5 = t; - } - - return d; -} - -void TLiquidazione_app::describe_consistence(const char* codatt) -{ - // controlla eventuali condizioni di conflitto con le normative - // per la ditta e crea i messaggi appropriati - // tutte le condizioni sono valutate sull'esercizio precedente - int pryear = atoi(_year) - 1; - TString att = codatt; - - _pla->zero(); - *_pla_ditta = get_firm(); - *_pla_anno = pryear; - *_pla_codatt = att; - - if (_pla->read() == NOERR) - { - real va = _pla->get_real("R0"); - - // 1) consistenza volume d'affari <-> frequenza versamenti - // deve essere: trimestrale ammesso solo se < 360.000.000 - // per servizi, < 1.000.000.000 per altre imprese - // a meno che non sia benzinaro che ha diritto comunque - - if (_freqviva == "T" && !_isbenzinaro) - { - bool err = FALSE; - if (_isservizio) err = va > SOGLIA_TRIM_SERVIZI; - else err = va > SOGLIA_TRIM_ALTRE; - if (err) - describe_error(TR("Incoerenza volume affari/frequenza versamenti"), - att); - } - } -} - -void TLiquidazione_app::describe_error(const char* err, const char* codatt) -{ - if (!_isprint || !_canprint || (_isregis && _isfinal)) - return; - _errors.add(new _ErrItem(err, codatt, _nditte->curr().get(NDT_CODDITTA))); -} - -// ---------------------------------------------------------------- -// Setrows -// ---------------------------------------------------------------- - -void TLiquidazione_app::set_firm(_DescrItem& d) -{ - TString tim_title(80); - tim_title << TR("Liquidazione IVA"); - - if (d._f1 == 13) - tim_title << format(FR(": Riepilogo Annuale %s"), (const char*)_year); - else - { - if (d._s2 == "T") - tim_title << format(FR(" del %d° Trimestre %s"), d._f1/3, (const char*) _year); - else - tim_title << format(FR(" del mese di %s %s"), itom(d._f1), (const char*)_year); - } - - reset_header(); - int soh = 1; - if (!_isregis) - { - set_header(soh++,FR("Ditta %s %s@107gData @>@125gPag. @#"), - (const char*)d._s0, (const char*)d._s1); - set_header(soh++,""); - } - set_header(soh++,sep); - set_header(soh++,FR("%s@102gFrequenza %s"), - (const char*)tim_title, d._s2 == "T" ? TR("Trimestrale") : TR("Mensile")); - set_header(soh++,sep); - set_header(soh++,""); - - // notify errors if any - int j = 0; - int i = 0; - for (i = 0; i < _errors.items(); i++) - { - _ErrItem& s = (_ErrItem&)_errors[i]; - if (s._att == "ALL" && s._firm == d._s0) - { j++; set_row(i+3, "@5g@b*** %s ***@r", (const char*)s._err); } - } - if (j) set_row(i+3,""); -} - -static int _tipo_attivita_corrente = 0; - -void TLiquidazione_app::set_att(_DescrItem& d) -{ - // set header - TString tim_title(78); - TString att_title(48); - - // Bookmark - TString book_name(d._s3); - const char flags = (char)d._f3; - - if (flags == '1') book_name << TR(" (servizi)"); - else if (flags == '2') book_name << TR(" (altre)"); - else if (flags == 'M') book_name = TR("Riepilogo att. mista"); - else if (flags == 'Q') book_name = TR("Riepilogo quater"); - - if (_firm_bookmark == -1) - _firm_bookmark = set_bookmark(d._s1); - _att_bookmark = set_bookmark(book_name, _firm_bookmark); - - tim_title << TR("Liquidazione IVA"); - - if (d._f1 == 13) - { - tim_title << format(FR(": Riepilogo Annuale %s"),(const char*)_year); - } - else - { - if (d._s4 == "T") - tim_title << format(FR(" del %d° Trimestre %s"), d._f1/3, (const char*)_year); - else - tim_title << format(FR(" del mese di %s %s"), itom(d._f1), (const char*)_year); - } - - const char* tipatt = ""; - if (d._f0 > 0) - tipatt = d._f0 == 1 ? TR("SERVIZI") : TR("ALTRE ATTIVITA'"); - - if (d._s3.empty()) - { - att_title = flags == 'M' ? TR("Riepilogo attività mista") : TR("Riepilogo quater"); - // att_title << d._s2; - } - else - att_title = format(FR("Attività %s %s %s"), (const char*)(d._s2), (const char*)(d._s3), tipatt); - - reset_header(); - int soh = 1; - if (!_isregis) - { - set_header(soh++,FR("Ditta %s %s@107gData @>@125gPag. @#"), - (const char*)(d._s0), (const char*)(d._s1)); - set_header(soh++,""); - } - set_header(soh++,sep); - set_header(soh++,"%s@55g%s", (const char*)tim_title, (const char*)att_title); - set_header(soh++,sep); - set_header(soh++,""); - - // notify errors if any - int j = 0; - for (int i = 0; i < _errors.items(); i++) - { - _ErrItem& s = (_ErrItem&)_errors[i]; - if (d._s2 == s._att && s._firm == d._s0) - { j++; set_row(i+10, "@5g@b*** %s ***@r", (const char*)s._err); } - } - if (j) - set_auto_ff(TRUE); -} - -void TLiquidazione_app::set_plafond(_DescrItem& d) -{ - // In caso di stampa liquidazione da stampa registri, il prospetto plafond - // complessivo va evidenziato in testa; solo nel caso di trimestrali. - - if (_isregis && _freqviva == "M") return; - - set_bookmark(TR("Quadro plafond"), _att_bookmark); - - real r1 = d._r1 + d._r0; - real r2 = d._r4 + d._r3; - real r3 = d._r7 + d._r6; - - real disponibile = d._r2 + d._r5 + d._r8; - real riporto = disponibile - r1 - r2 -r3; - - set_print_zero(TRUE); - - set_row(1,TR("QUADRO RELATIVO ALLA DISPONIBILITA' ED ALL'UTILIZZO MENSILE DEI PLAFONDS")); - - set_row(2,""); - set_row(3,FR("@31gDisponibile@48g%r"), &(disponibile)); - set_row(4,TR("Art. 8 1° comma lettere a-b")); - set_row(5,FR("Utilizzato all'interno@48g%r"), &(d._r0)); - set_row(6,FR("Utilizzato per l'importazione@48g%r"),&(d._r1)); - - set_row(7,""); - set_row(8,TR("Art. 8bis 1° comma")); - set_row(9,FR("Utilizzato all'interno@48g%r"), &(d._r3)); - set_row(10,FR("Utilizzato per l'importazione@48g%r"), &(d._r4)); - - set_row(11,""); - set_row(12,TR("Art. 9 1° comma")); - set_row(13,FR("Utilizzato all'interno@48g%r"), &(d._r6)); - set_row(14,FR("Utilizzato per l'importazione@48g%r"), &(d._r7) ); - set_row(15,FR("@31gRiporto@48g%r"), &(riporto)); - - set_print_zero(FALSE); - set_auto_ff(); -} - -/* Obsoleto - -void TLiquidazione_app::set_liqacc_1999(_DescrItem& d) -{ - real r1 = d._r0 + d._r1 + d._r2 + d._r4; - //real r2 = d._r5 + d._r10; - real r2 = d._r5; //MI2258 (A me sembra una cagata, ma con certa gente non si riesce a parlare) - real r3 = r2 + d._r9 + d._r7; - if ((d._r3).sign() > 0) r1 += d._r3; - else r3 += abs(d._r3); - - set_row(1,""); set_row(2,""); set_row(3,""); set_row(4,""); - set_row(5,FR("@11gCALCOLO ACCONTO SU OPERAZIONI EFFETTUATE")); - - set_row(6,""); - set_row(7,FR("@72gCredito@90gDebito")); set_row(8,""); - if (!_isdiffacc) - set_row(9,FR("@11gIva sulle operazioni annotate fino al 20 Dicembre@81g%r"), &(d._r0)); - else - set_row(9,FR("@11gIva sulle operazioni di vendita@81g%r"), &(d._r0)); - int i = 10; - if (!_isdiffacc) - { - set_row(i++,FR("@11gIva su operazioni fino al 20 Dic., ma non fatturate@81g%r"), &(d._r1)); - set_row(i++,FR("@11gIva su operazioni fino al 20 Dic., ma non annotate@81g%r"), &(d._r2)); - } - set_row(i,FR("@11gRettifiche iva a debito")); - if (d._r3.sign() > 0) - set_row(i,"@81g%r", &(d._r3)); - i++; - set_row(i++,FR("@11gIva chiesta a rimborso@81g%r"), &(d._r4)); - set_row(i++,FR("@11gRISULTATO@81g%r"), &r1); - - if (!_isdiffacc) - set_row(i++,FR("@11gIva sugli acquisti annotati fino al 20 Dicembre@64g%r"), &r2); - else - set_row(i++,FR("@11gIva sulle operazioni di acquisto@64g%r"), &r2); - if (d._r6 != ZERO) - set_row(i++,FR("@11gmeno perc. di prorata pari a lire %r"), &(d._r6)); - set_row(i++, FR("@11gCredito precedente@64g%r"), &(d._r9)); - set_row(i, FR("@11gRettifiche iva a credito")); - if ((d._r3).sign() <= 0) - { - real ab = abs(d._r3); - set_row(i,"@64g%r", &ab); - } - i++; - set_row(i++,FR("@11gRISULTATO@64g%r"), &r3); - if ((d._r8).sign() < 0) - { - real ab = abs(d._r8); - set_row(i++,FR("@23gCREDITO DA EVIDENZIARE@64g%r"), &ab); - } - else if ((d._r8).sign() > 0 && d._r8 > _ver->get(I_ACCONTOIVA)) - set_row(i++,FR("@23gACCONTO DA VERSARE@81g%r"), &(d._r8)); - else if ((d._r8).sign() > 0 && d._r8 <= _ver->get(I_ACCONTOIVA)) - set_row(i++,FR("@23gACCONTO DA NON VERSARE@64g%r"), &(d._r8)); - - set_auto_ff(); -} -*/ - -int TLiquidazione_app::calc_inc_diff(int tipoiva, real& imponibile_diff, real& imposta_diff, real& imponibile_xcas, real& imposta_xcas) const -{ - CHECKD(tipoiva == 1 || tipoiva == 2, "Bad tipo iva:", tipoiva); - int flag = 0; - - imponibile_diff = imposta_diff = imponibile_xcas = imposta_xcas = ZERO; - - TString limit; limit << "ANNOLIQ=" << _year; - if (_month < 13) limit << " MESELIQ=" << _month; - TString query; // righe pagamento (TIPOMOV>=3) ed escluse NC! - query << "USE IVADIFF KEY 2 SELECT (TIPOMOV>2)&&(TIPOIVA=" << tipoiva << ')' - << "\nFROM " << limit << "\nTO " << limit; - - TISAM_recordset id(query); - const TRectype& rec = id.cursor()->curr(); - for (bool ok = id.move_first(); ok; ok = id.move_next()) - { - const real iva = rec.get_real(RMI_IMPOSTA); - const real imp = rec.get_real(RMI_IMPONIBILE); - if (!iva.is_zero() || !imp.is_zero()) - { - const int tipodiff = rec.get_int("TIPODIFF"); - switch (tipodiff) - { - case 1: imponibile_diff += imp; imposta_diff += iva; break; - case 2: imponibile_xcas += imp; imposta_xcas += iva; break; - default: break; - } - flag |= tipodiff; - } - } - - return flag; -} - -int TLiquidazione_app::print_acc_diff_xcassa(const _DescrItem& d) -{ - int i = 9; - - const real& totiva = d._r0; - const real ivadiff_inc = d._r29; - const real ivadiff_pag = d._r33; - - real ivaxcas_inc, ivaxcas_pag; - - if (has_module(ICAUT)) - { - // Calcolare qui la quota per cassa e toglierla a quella differita gloable - } - - if (!_isdiffacc) - { - set_row(i++,FR("@11gIva esigibile fino al 20/12@81g%r"), &totiva); - - if (ivadiff_inc > ZERO) - set_row(i++,FR("@11gIVA a liquidazione differita incassata fino al 20/12@75g%r"), &ivadiff_inc); - if (ivadiff_pag > ZERO) - set_row(i++,FR("@11gIVA a liquidazione differita pagata fino al 20/12@64g%r"), &ivadiff_pag); - - if (ivaxcas_inc > ZERO) - set_row(i++,FR("@11gIVA per cassa incassata fino al 20/12@75g%r"), &ivaxcas_inc); - if (ivaxcas_pag > ZERO) - set_row(i++,FR("@11gIVA per cassa pagata fino al 20/12@64g%r"), &ivaxcas_pag); - } - else - { - set_row(i++,FR("@11gIva sulle operazioni di vendita@81g%r"), &totiva); - - if (ivadiff_inc > ZERO) - set_row(i++,FR("@11gIVA a liquidazione differita incassata@75g%r"), &ivadiff_inc); - if (ivadiff_pag > ZERO) - set_row(i++,FR("@11gIVA a liquidazione differita pagata@64g%r"), &ivadiff_pag); - - if (ivadiff_inc > ZERO) - set_row(i++,FR("@11gIVA per cassa incassata@75g%r"), &ivadiff_inc); - if (ivadiff_pag > ZERO) - set_row(i++,FR("@11gIVA per cassa pagata@64g%r"), &ivadiff_pag); - } - return i; -} - -void TLiquidazione_app::set_liqacc_2000(_DescrItem& d) -{ - set_row(1,""); set_row(2,""); set_row(3,""); set_row(4,""); - set_row(5,FR("@11gCALCOLO ACCONTO SU OPERAZIONI EFFETTUATE")); - if (!_isdiffacc) - set_row(5,TR(" FINO AL 20 DICEMBRE")); - - set_row(6,""); - set_row(7,FR("@72gCredito@90gDebito")); set_row(8,""); - - if (d._r3 > ZERO) - d._r0 += d._r3; // Aggiungi rettifiche a debito - - int i = print_acc_diff_xcassa(d); - - if (!_isdiffacc) - { - set_row(i++,FR("@11gIva esigibile fino al 20/12 di cui non fatturata@81g%r"), &d._r1); - set_row(i++,FR("@11gIva esigibile fino al 20/12 di cui non annotata@81g%r"), &d._r2); - } - if (d._r3 < ZERO) - d._r5 -= d._r3; // Aggiungi rettifiche a credito - if (!_isdiffacc) - set_row(i++,FR("@11gIva che si detrae fino al 20/12@64g%r"), &d._r5); - else - set_row(i++,FR("@11gIva sulle operazioni di acquisto@64g%r"), &d._r5); - - set_row(i,FR("@11gIVA a debito/credito per il periodo")); - real iva_dov_cre = d._r0 + d._r1 + d._r2 - d._r5; - if (iva_dov_cre >= ZERO) - set_row(i++,"@81g%r", &iva_dov_cre); - else - { - const real tmp = -iva_dov_cre; - set_row(i++,"@64g%r", &tmp); - } - - set_row(i++, FR("@11gDebito/Credito da periodo precedente@64g%r"), &d._r9); - - set_row(i,FR("@11gIVA Dovuta o a Credito")); - const real risultato = iva_dov_cre - d._r9; - if (risultato >= ZERO) - set_row(i++,"@81g%r", &risultato); - else - { - const real tmp = -risultato; - set_row(i++,"@64g%r", &tmp); - } - - // Acconto - if (d._r8 < ZERO) - { - const real ab = abs(d._r8); - set_row(i++,FR("@23gCREDITO DA EVIDENZIARE@64g%r"), &ab); - } - else if (d._r8 > ZERO) - { - const real acconto_minimo = _ver->get(I_ACCONTOIVA); - if (d._r8 > acconto_minimo) - set_row(i++,FR("@23gACCONTO DA VERSARE@81g%r"), &d._r8); - else - set_row(i++,FR("@23gACCONTO DA NON VERSARE@81g%r"), &d._r8); - } - - set_auto_ff(); -} - -/* - -bool TLiquidazione_app::print_dainc_diff_log(int& rw, int tipoatt, int tipoiva) -{ - TString limit; limit << "ANNOLIQ=" << _year; - if (_month < 13) limit << " MESELIQ=" << _month; - TString query; - query << "USE IVADIFF KEY 2 SELECT (TIPOMOV==1)"; - //if (_isregis && tipoiva > 0) query << "&&(TIPOIVA==" << tipoiva << ')'; - if (tipoatt > 0) - query << " &&(TIPOATT==" << tipoatt << ")"; - query << "\nBY TIPOIVA DATAREG"; - query << "\nJOIN MOV INTO NUMREG==NUMREG"; - query << "\nJOIN CLIFO TO MOV INTO TIPOCF==TIPO CODCF==CODCF"; - query << "\nFROM " << limit << "\nTO " << limit; - - int header = 0; - - TISAM_recordset id(query); - const int rfat = id.items(); - if (rfat > 0) - { - const TRectype& rec = id.cursor()->curr(); - bool header_printed = false; - for (bool ok = id.move_first(); ok; ok = id.move_next()) - { - real importo, imponibile, imposta; - const TDate nulldate; - residuo_da_liquidare(rec.get_long(RMI_NUMREG), rec.get_int(RMI_NUMRIG), nulldate, - importo, imponibile, imposta); - const int ti = rec.get_int("TIPOIVA"); - if (ti != header) - { - if (ti < 2) - set_row(rw++, TR("Fatture da incassare")); - else - set_row(rw++, TR("Fatture da pagare")); - set_row(rw++, "IVA@17gImporto@30gImponibile@49gImposta@57gC/D@74gProt.@80gN. Doc.@89gData reg.@100gCodice@107gRagione sociale"); - header = ti; - } - - const TString4 codiva = rec.get("CODIVA"); - const int protiva = id.get("MOV.PROTIVA").as_int(); - const TString8 numfat = id.get("MOV.NUMDOC").as_string(); - const TString16 datafat = rec.get("DATAREG"); - const char* tipolog = id.get("TIPODIFF").as_int() == 2 ? TR("C") : TR("D"); - - const long codcf = id.get("CLIFO.CODCF").as_int(); - TParagraph_string clifo(id.get("CLIFO.RAGSOC").as_string(), 25); - - set_row(rw++, "%s@9g%r@25g%r@41g%r@58g%s@74g%5d@80g%s@89g%s@100g%6ld@107g%s", - (const char*)codiva, &importo, &imponibile, &imposta, - tipolog, protiva, (const char*)numfat, (const char*)datafat, - codcf, clifo.get()); - const char* ragsoc2 = clifo.get(); - if (ragsoc2 != NULL && strlen(ragsoc2) > 3) - set_row(rw++, "@107g%s", ragsoc2); - } - } - - return rfat > 0; -} - -bool TLiquidazione_app::print_inc_diff_log(int& rw, int tipoatt, int tipoiva) -{ - TString limit; limit << "ANNOLIQ=" << _year; - if (_month < 13) limit << " MESELIQ=" << _month; - TString query; - query << "USE IVADIFF KEY 2 SELECT (TIPOMOV>2)"; - // if (_isregis && tipoiva > 0) query << "&&(TIPOIVA==" << tipoiva << ')'; - if (tipoatt > 0) - query << " &&(TIPOATT==" << tipoatt << ")"; - query << "\nBY TIPOIVA DATAREGP"; - query << "\nJOIN MOV INTO NUMREG==NUMREG"; - query << "\nJOIN CLIFO TO MOV INTO TIPOCF==TIPO CODCF==CODCF"; - query << "\nFROM " << limit << "\nTO " << limit; - - TISAM_recordset id(query); - const int rpag = id.items(); - if (rpag > 0) - { - const TRectype& rec = id.cursor()->curr(); - int header = 0; - for (bool ok = id.move_first(); ok; ok = id.move_next()) - { - const int ti = rec.get_int("TIPOIVA"); - if (ti != header) - { - if (ti < 2) - set_row(rw++, TR("Fatture incassate")); - else - set_row(rw++, TR("Fatture pagate")); - set_row(rw++, "IVA@17gImporto@30gImponibile@49gImposta@57gC/D@61gPagamento@74gProt.@80gN. Doc.@89gData reg.@100gCodice@107gRagione sociale"); - header = ti; - } - - const TString4 codiva = rec.get(RMI_CODIVA); - const real importo = rec.get("IMPORTO"); - const real imponibile = rec.get(RMI_IMPONIBILE); - const real imposta = rec.get(RMI_IMPOSTA); - const char* tipolog = id.get("TIPODIFF").as_int() == 2 ? TR("C") : TR("D"); - const TString16 datapag = rec.get("DATAREGP"); - const int protiva = id.get("MOV.PROTIVA").as_int(); - const TString16 numfat = id.get("MOV.NUMDOC").as_string(); - const TString16 datafat = rec.get("DATAREG"); - - const long codcf = id.get("CLIFO.CODCF").as_int(); - TParagraph_string clifo(id.get("CLIFO.RAGSOC").as_string(), 25); - - set_row(rw++, "%s@9g%r@25g%r@41g%r@58g%s@61g%s@74g%5d@80g%s@89g%s@100g%6ld@107g%s", - (const char*)codiva, &importo, &imponibile, &imposta, - tipolog, (const char*)datapag, protiva, (const char*)numfat, (const char*)datafat, - codcf, clifo.get()); - const char* ragsoc2 = clifo.get(); - if (ragsoc2 != NULL && strlen(ragsoc2) > 3) - set_row(rw++, "@107g%s", ragsoc2); - } - } - - return rpag > 0; -} -*/ - -void TLiquidazione_app::set_pim_head(_DescrItem& d) -{ - int r = 1; - - if (d._flags == PIM_HEAD) - set_bookmark(TR("Riepilogo progressivi"), _att_bookmark); - else - { - set_row(r++,""); - if (d._flags == PIM_HEAD_D) - { - TString msg; - msg = TR("Movimenti registrati nel periodo a liquidazione differita"); - const TDate data(1, _month <= 12 ? _month : 12 , atoi(_year)); - if (gestione_IVAxCassa(data)) - msg << TR(" o per cassa"); - set_row(r++, msg); - set_bookmark(TR("Riepilogo progressivi a liquidazione differita"), _att_bookmark); - // print_dainc_diff_log(r, d._f2, d._f3); // 15-03-2013 obosleto in quanto stampato su registri? - } - else - if (d._flags == PIM_HEAD_DI) - { - TString msg; - msg = TR("Incassi/pagamenti a liquidazione differita"); - - const TDate data(1, _month <= 12 ? _month : 12 , atoi(_year)); - if (gestione_IVAxCassa(data)) - msg << TR(" o per cassa"); - - set_row(r++, msg); - set_bookmark(TR("Riepilogo progressivi a liquidazione differita incassati"), _att_bookmark); -// print_inc_diff_log(r, d._f2, d._f3); - } - else // PIS_HEAD - { - if (d._flags == PIS_HEAD) - { - set_row(r++,TR(" Di cui da periodo successivo")); - set_row(r++,""); - set_bookmark(TR("Riepilogo progressivi successivi"), _att_bookmark); - } - else - if (d._flags == PIS_HEAD_D) - { - set_row(r++, TR("Fatture a liquidazione differita da incassare")); - set_bookmark(TR("Riepilogo progressivi successivi a liquidazione differita"), _att_bookmark); - } - else - if (d._flags == PIS_HEAD_DI) - { - set_row(r++, TR("Fatture a liquidazione differita incassate")); - set_bookmark(TR("Riepilogo progressivi successivi a liquidazione differita incassati"), _att_bookmark); - } - } - set_row(r++,""); - } - if (d._f0) - { - if (d._flags == PIM_HEAD || d._flags == PIS_HEAD) - { - set_row(r++,FR(" Cod.@41gVENDITE@71gCORRISPETTIVI")); - set_row(r++,FR(" IVA Descrizione@30gImponibile@49gImposta@63gImponibile@82gImposta")); - set_row(r,""); - } -/* else - { - set_row(r++,FR(" Cod.@41gVENDITE")); - set_row(r++,FR(" IVA Descrizione@30gImponibile@49gImposta")); - } */ - } - else - { - if (d._flags == PIM_HEAD || d._flags == PIS_HEAD) - { - set_row(r++,FR(" Cod.@41gVENDITE@71gCORRISPETTIVI@106gACQUISTI")); - set_row(r++,FR(" IVA Descrizione@30gImponibile@49gImposta@63gImponibile" - "@82gImposta@96gImponibile@115gImposta")); - set_row(r,""); - } -/* else - { - set_row(r++,FR(" Cod.@41gVENDITE")); - set_row(r++,FR(" IVA Descrizione@30gImponibile@49gImposta")); - } */ - } -} - -void TLiquidazione_app::set_pim(_DescrItem& d) -{ - // succede con le autocazzate non residenti non movimentate eccetera - const bool a = (d._r0 + d._r1) == ZERO; - const bool b = (d._r2 + d._r3) == ZERO; - const bool c = (d._r4 + d._r5) == ZERO; - const bool e = (d._r26 + d._r27) == ZERO; - const bool f = (d._r28 + d._r29) == ZERO; - const bool g = (d._r30 + d._r31) == ZERO; - const bool h = (d._r32 + d._r33) == ZERO; - - if (a && b && c && e && f && g && h) - return; - - int rw = 1; - if (d._s1 == "AF") //Il dio sistema colpisce ancora, non va bene A35, ma AF... - d._s2 = TR("Artt.17c3/74c1"); // La descrizione non la metto uguale perche' cosi e' piu' fika - else if (d._s1 == "VA7") // Sempre per merito del dio sistema ho dovuto aggiungere VA7. - d._s2 = TR("Art.40c5/6/8 a.i."); - else if (d._s0 == "74TER") - rw++; - else - { - look_iva(d._s1); - d._s2 = _iva->get("S0"); - if (d._s2.len() > 19) d._s2.cut(19); - } - - if (d._flags == PIM_ROW || d._flags == PIS_ROW) - { - set_row(rw++,"%-4s %s@25g%r@41g%r@58g%r@74g%r@91g%r@107g%r", - (const char*)d._s1, (const char*)d._s2, - &(d._r0), &(d._r1), &(d._r2), &(d._r3), &(d._r4), &(d._r5)); - } - else - if (d._flags == PIM_ROW_D || d._flags == PIS_ROW_D) - { - set_row(rw++,"%-4s %s@25g%r@41g%r@91g%r@107g%r", - (const char*)d._s1, (const char*)d._s2, - &(d._r26), &(d._r27), &(d._r30), &(d._r31)); - } - else - if (d._flags == PIM_ROW_DI || d._flags == PIS_ROW_DI) - { - set_row(rw++,"%-4s %s@25g%r@41g%r@91g%r@107g%r", - (const char*)d._s1, (const char*)d._s2, - &(d._r28), &(d._r29), &(d._r32), &(d._r33)); - } - - } - -void TLiquidazione_app::set_plm_diff(const _DescrItem& d) -{ - int rw = 1; - - set_row(rw++,""); set_row(rw++,""); - if (d._flags == TOT_ROW_D) - { - set_row(rw++,FR("Totale@25g%r@41g%r@91g%r@107g%r"), &(d._r26), &(d._r27), &(d._r30), &(d._r31)); - } - else - { - // Totale incassi/pagamenti ad IVA differita o per cassa - set_row(rw++,FR("Totale@25g%r@41g%r@91g%r@107g%r"), &(d._r28), &(d._r29), &(d._r32), &(d._r33)); - if (_isannual) - { - rw++; - set_row(rw++,FR("Totale anni prec. @25g%r@41g%r@91g%r@107g%r"), &(d._diff_ven_ap), &(d._diff_ven_ap_iva), &(d._diff_acq_ap), &(d._diff_acq_ap_iva)); - } - } - set_row(rw++,""); -} - -void TLiquidazione_app::set_plm(_DescrItem& d) -{ - int rw = 1; - if (!(d._r0.is_zero() && d._r1.is_zero() && d._r2.is_zero() && - d._r3.is_zero() && d._r4.is_zero() && d._r5.is_zero())) - { - set_row(rw++,""); set_row(rw++,""); - set_row(rw++,FR("Totale@25g%r@41g%r@58g%r@74g%r@91g%r@107g%r"), - &(d._r0), &(d._r1), &(d._r2), &(d._r3), &(d._r4), &(d._r5)); - set_row(rw++,""); - } - if (!(d._r7.is_zero() && d._r8.is_zero())) - { - set_row(rw++,FR("Totale acquisti indeducibili per art.19@91g%r@107g%r"), - &(d._r7), &(d._r8)); - } - if (! (d._r9.is_zero() && d._r10.is_zero())) - { - set_row(rw++, FR("Totale acquisti indeducibili su ricavi esenti@91g%r@107g%r"), - &(d._r9), &(d._r10)); - } - - real acq_pint(d._s0); - real acq_pint_iva(d._s1); - - if (! (acq_pint.is_zero() && acq_pint_iva.is_zero())) - { - set_row(rw++, FR("Totale acquisti indeducibili per passaggi interni@91g%r@107g%r"), - &acq_pint, - &acq_pint_iva); - } - - real tot1 = d._r7 + d._r4 + d._r9 + acq_pint; - real tot2 = d._r8 + d._r5 + d._r10 + acq_pint_iva; - - if (tot1 != d._r4 || tot2 != d._r5) - { - // i corrispettivi finiscono nelle vendite - d._r0 += d._r2; - d._r1 += d._r3; - d._r2 = ZERO; - d._r3 = ZERO; - // per ora lascio r2 e r3 anche se sono sempre 0 - set_row(rw++, ""); - set_row(rw++,FR("Totale Generale IVA@25g%r@41g%r@58g%r@74g%r@91g%r@107g%r"), - &(d._r0), &(d._r1), &(d._r2), &(d._r3), &tot1, &tot2); - } - - // Stampa il totale progressivo da registri, comprensivo dei movimenti valevoli per il calcolo vol. affari. - real pr_imp(d._s2); - real pr_iva(d._s3); - if (!(d._r11.is_zero() && d._r12.is_zero() && d._r13.is_zero() && - d._r14.is_zero() && pr_imp.is_zero() && pr_iva.is_zero())) - { - set_row(rw++,""); set_row(rw++,""); - set_row(rw++,FR("Totale Prog. da registri@25g%r@41g%r@58g%r@74g%r@91g%r@107g%r"), - &(d._r11), &(d._r12), &(d._r13), &(d._r14), &(pr_imp), &(pr_iva)); - set_row(rw++,""); - } -} - - -void TLiquidazione_app::set_pumpam(const _DescrItem& d) -{ - bool printed = false; - - // d._f1 dice se c'era qualcosa sopra nella stessa pagina - real spgn(d._s2); - real spgn_iva(d._s3); - - TToken_string tt(d._s4); // Token String - TToken_string dp(d._s0); // Due Palle - real aqsi(tt.get(0)); - real aqsv(tt.get(1)); - real vnsi(tt.get(2)); - real vnsv(tt.get(3)); - real aqli(tt.get(4)); - real aqlv(tt.get(5)); - real vnli(tt.get(6)); - real vnlv(tt.get(7)); - real ammindi(dp.get(1)); - real ammindv(dp.get(2)); - - int row = 5; - - if (!(aqsi.is_zero() && aqsv.is_zero())) - { - printed = TRUE; - set_row(row++, FR("Acquisti in sospensione di imposta@50g%r@69g%r"), - &aqsi, - &aqsv); - } - if (!(vnsi.is_zero() && vnsv.is_zero())) - { - printed = TRUE; - set_row(row++, FR("Vendite in sospensione di imposta@50g%r@69g%r"), - &vnsi, - &vnsv); - } - if (!(aqli.is_zero() && aqlv.is_zero())) - { - printed = TRUE; - set_row(row++, FR("IVA ad esigibilità differ. da detrarre nel periodo@50g%r@69g%r"), - &aqli, - &aqlv); - } - if (!(vnli.is_zero() && vnlv.is_zero())) - { - printed = TRUE; - set_row(row++, FR("IVA ad esigibilità differ. da pagare nel periodo@50g%r@69g%r"), - &vnli, - &vnlv); - } - if (!(d._r8.is_zero() && d._r9.is_zero())) - { - printed = TRUE; - set_row(row++, FR("Cessione beni ammortizzabili@50g%r@69g%r"), - &(d._r8), - &(d._r9)); - } - if (! (d._r4.is_zero() && d._r5.is_zero())) - { - printed = TRUE; - set_row(row++, FR("Acquisto beni destinati alla rivendita@50g%r@69g%r"), - &(d._r4), - &(d._r5)); - } - if (! (ammindi.is_zero() && ammindv.is_zero())) - { - printed = TRUE; - set_row(row++, FR("Acquisto beni ammortizzabili IVA indetraibile@50g%r@69g%r"), - &ammindi, - &ammindv); - } - if (! (d._r0.is_zero() && d._r1.is_zero())) - { - printed = true; - set_row(row++, FR("Acquisto beni ammortizzabili IVA detraibile@50g%r@69g%r"), - &(d._r0), - &(d._r1)); - } - if (!(d._r6.is_zero() && d._r7.is_zero())) - { - printed = TRUE; - set_row(row++, FR("Altri beni strumentali acquisiti in leasing@50g%r@69g%r"), - &(d._r6), - &(d._r7)); - } - if (!(d._r2.is_zero() && d._r3.is_zero())) - { - printed = TRUE; -// real rn = d._r2 * real(DETRAZIONE_6PERCENTO); // Detrazione obsoleta CM500344 - set_row(row++, FR("Acquisto beni soggetti a detrazione (6%%)" - "@50g%r@69g%r"), &(d._r2), &(d._r3)); - } - if (!(spgn.is_zero() && spgn_iva.is_zero())) - { - printed = TRUE; - set_row(row++, FR("Spese generali@50g%r@69g%r"), - &spgn, - &spgn_iva); - } - // Prorata... - int yy = atoi(_year); - if (d._f0) - { - printed = TRUE; - - real prc(dp.get(0)); - real rprc = CENTO - prc; - TString ss(rprc.string()); - - set_row(row++, FR("%% PRO-RATA (%s%%) ed IVA non detraibile (%s%%)@69g%r"), - (const char*) ss, (const char*)prc.string(), &(d._r11)); - yy-=2; - if (d._r13 != INVALID_PRORATA && d._r12 != ZERO) - { - rprc = CENTO - d._r13; - ss = rprc.string(); - set_row(row++, FR("%% PRO-RATA %d (%s%%) ed IVA non detraibile (%s%%)@69g%r"), - yy, (const char*) ss, (const char*)d._r13.string(), &(d._r12)); - } - else - if (!_isfinal && d._r13 == INVALID_PRORATA_ASSERT) - set_row(row++, FR("Impossibile reperire la %% PRO-RATA relativa all'anno %d."), yy); - - yy--; - if (d._r15 != INVALID_PRORATA && d._r14 != ZERO) - { - rprc = CENTO - d._r15; - ss = rprc.string(); - set_row(row++, FR("%% PRO-RATA %d (%s%%) ed IVA non detraibile (%s%%)@69g%r"), - yy, (const char*) ss, (const char*)d._r15.string(), &(d._r14)); - } - else - if (!_isfinal && d._r15 == INVALID_PRORATA_ASSERT) - set_row(row++, FR("Impossibile reperire la %% PRO-RATA relativa all'anno %d."), yy); - } - - // items vari per dichiarazione annuale - for (int i = 0; i < d._arr.items(); i++) - { - _DescrItem& dd = (_DescrItem&)d._arr[i]; - printed |= set_annual(dd); - } - - if (printed) - { - set_bookmark(TR("Altri dati"), _att_bookmark); - - set_row(1,""); - set_row(2,""); - set_row(3,FR("ALTRI DATI RELATIVI ALLA DICHIARAZIONE@55gimponibile" - "@77gimposta@91gdetrazione")); - set_row(4,""); - set_row(row++,""); - set_row(row,""); - } - else - set_row(1,""); - - // form feed - if (d._f2) - set_auto_ff(TRUE); -} - -/* -void TLiquidazione_app::set_grand_1999(_DescrItem& d, int& rw) -{ - real& risultato = d._r0; - real& rimborso = d._r1; - real& cred_cost = d._r2; - real& deb_mens = d._r3; - real& rettifiche = d._r5; - real& detrazioni = d._r6; - real& interessi = d._r7; - real& versamenti = d._r8; - real& vers_int = d._r9; - real& conguaglio = d._r10; - TToken_string tt(d._s0); - real iva_vend(tt.get(0)); - real iva_acq(tt.get(1)); - real cred_prec(tt.get(2)); - real debt_prec(tt.get(3)); - real cred_trasf(tt.get(4)); cred_trasf = -cred_trasf; - - real acc_dec(d._s1); - real res_cred(d._s2); - real res_debt(d._s3); - real rett_debt(0.0); - real rett_cred(0.0); - real& interesse = d._r11; - - if (rettifiche.sign() > 0) rett_debt = rettifiche; - if (rettifiche.sign() < 0) rett_cred = -rettifiche; - - set_row(rw++,FR(" @66gCredito@84gDebito")); set_row(rw++,""); - set_row(rw++,FR("@11gIva sulle operazioni di vendita@75g%r"), &iva_vend); - set_row(rw++,FR("%s@11gRettifiche IVA a debito%s@75g%r"), - _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rett_debt); - set_row(rw++,FR("%s@11gIva chiesta a rimborso%s@75g%r"), - _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rimborso); - - // conguaglio prorata - if (conguaglio.sign() > 0) - set_row(rw++,FR("@11gConguaglio pro-rata@75g%r"), &conguaglio); - - // debito liq. precedente < 50000 - if (debt_prec > ZERO) - set_row(rw++,FR("@11gDebito da liquidazione precedente@75g%r"), &debt_prec); - - set_row(rw++,FR("@11gRISULTATO@75g%r"), &res_debt); - set_row(rw++,FR("@11gIva ammessa in detrazione@58g%r"), &iva_acq); - if (_isannual || d._f1) - { - set_row(rw++,FR("@11gCredito inizio anno@58g%r"), &cred_prec); - if (cred_trasf != ZERO) - set_row(rw++,FR("@11gCredito trasferito @58g%r"), &cred_trasf); - } - else - set_row(rw++,FR("@11gCredito precedente@58g%r"), &cred_prec); - - if (!acc_dec.is_zero()) - set_row(rw++,FR("%s@11gVersamento acconto dicembre%s@58g%r"), - _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &acc_dec); - - if (!detrazioni.is_zero()) - set_row(rw++,FR("@11gUlteriori detrazioni@58g%r"), &detrazioni); - - set_row(rw++,FR("%s@11gRettifiche IVA a credito%s@58g%r"), - _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rett_cred); - - // versamenti effettuati - if (!versamenti.is_zero() && (_month==13 || !_is_visliq)) - { - set_row(rw++,FR("@11gVersamenti effettuati@58g%r"), &versamenti); - } - // versamenti integrativi - if (!vers_int.is_zero() && !_is_visliq) - { - set_row(rw++,FR("@11gVersamenti integrativi@58g%r"), &vers_int); - } - if (conguaglio.sign() < 0) - { - real cg = conguaglio; - cg = -cg; - set_row(rw++,FR("@11gConguaglio pro-rata@58g%r"), &cg); - } - - set_row(rw++,FR("@11gRISULTATO@58g%r"), &res_cred); - - // se non c'e' nulla da versare stampa solo una riga vuota - // Serve, non toglierla, stronzo. - if (risultato.is_zero()) - set_row(rw++,""); - else - { - if (risultato.sign() < 0) - { - real iva = abs(risultato); - if (_isannual || _isriepilogo) - round_imposta(iva); - set_row(rw++,FR("@23gCREDITO ATTUALE@58g%r"),&iva); - if (_is_visliq) - { // se chiamata dalla visualizzazione mette 2 righe vuote se non vi sono interessi - // poiche' con le rettifiche a credito/debito posso volerle visualizzare - set_row(rw++,""); - set_row(rw++,""); - } - } - else - { - if (_month == 13) - round_imposta(interessi); - real iva = risultato + interessi; - if (_isannual || _isriepilogo) - round_imposta(iva); - if (!iva.is_zero()) - { - if (!interessi.is_zero()) - { - set_row(rw++,FR("@23gIVA DOVUTA@75g%r"),&risultato); - set_row(rw++,FR("@23gInteresse @33g%6.2r @41g%%@75g%r"),&interesse, &interessi); - } - else - if (_is_visliq) - { // vedi sopra... - set_row(rw++,""); - set_row(rw++,""); - } - if (iva >= iva_da_riportare(_month)) - set_row(rw++,FR("@23gIVA DA VERSARE@75g%r"),&iva); - else - set_row(rw++,FR("@23gIVA A DEBITO DA NON VERSARE@75g%r"),&iva); - } - } - } - - if (_is_visliq && _month != 13) - { - // stampa versamenti (anche 0) ad uso visualizzazione liquidazione IVA - rw++; - set_row(rw++,FR("@11g$[r]Versamenti effettuati$[n]@58g%r"), &versamenti); - set_row(rw++, ""); - set_row(rw++, ""); - } - - if (!_is_visliq) - { - // descrizione rettifiche - if (d._s4.not_empty() || d._s5.not_empty()) - { - rw++; - set_row(rw++, FR("@11g@bDESCRIZIONE RETTIFICHE@r")); - rw++; - if (d._s4.not_empty()) { set_row(rw++, "@11g%t", &(d._s4)); } - if (d._s5.not_empty()) { set_row(rw++, "@11g%t", &(d._s5)); } - } - } -} -*/ - -void TLiquidazione_app::print_importo(int rw, const char* prompt, real imp, bool red) -{ - int tab = 75; - if (imp < ZERO) - { imp = -imp; tab = 58; } - TString256 str; - str << "@11g"; - if (red) str << "$[r]"; - str << prompt; - if (red) str << "$[n]"; - str << '@' << tab << "g%r"; - set_row(rw, str, &imp); -} - -// d._flags == THE_END -void TLiquidazione_app::set_grand_2000(_DescrItem& d, int &rw) -{ - const real risultato = d._r0; // Figuccia lo poteva cambiare, ora tornato const :-) - const real& rimborso = d._r1; - const real& cred_cost = d._r2; - const real& deb_mens = d._r3; - const real& rettifiche = d._r5; - const real& detrazioni = d._r6; - const real& interessi = d._r7; - const real& versamenti = d._r8; - const real& vers_int = d._r9; - - real diffinc_iva = d._r29; - real diffinc_iva_acq = d._r33; - real xcasinc_iva = ZERO; - real xcasinc_iva_acq = ZERO; - - if (has_module(ICAUT) && (!diffinc_iva.is_zero() || !diffinc_iva_acq.is_zero())) - { - real dimp, diva, ximp, xiva; - - if (!diffinc_iva.is_zero() && calc_inc_diff(1, dimp, diva, ximp, xiva)) - { - diffinc_iva = diva; - xcasinc_iva = xiva; - } - if (!diffinc_iva_acq.is_zero() && calc_inc_diff(2, dimp, diva, ximp, xiva)) - { - diffinc_iva_acq = diva; - xcasinc_iva_acq = xiva; - } - } - - TToken_string tt(d._s0); - real iva_vend(tt.get(0)); - real iva_acq(tt.get(1)); - real cred_prec(tt.get(2)); - real debt_prec(tt.get(3)); - real cred_trasf(tt.get(4)); cred_trasf = -cred_trasf; - - real acc_dec(d._s1); - real res_cred(d._s2); - real res_debt(d._s3); - real rett_debt(0.0); - real rett_cred(0.0); - real& interesse = d._r11; - - real& credito_utilizzato_iva = d._r15; - real& credito_utilizzato_f24 = d._r16; - real& variazioni_imposta = d._r17; - real& imposta_non_versata = d._r18; - real& crediti_speciali = d._r19; - - if (rettifiche.sign() > 0) rett_debt = rettifiche; - if (rettifiche.sign() < 0) rett_cred =-rettifiche; - - set_row(rw++,FR(" @66gCredito@84gDebito")); set_row(rw++,""); - - // Se sono in visualizzazione stampo i due importi separati, altrimenti li sommo - if (!_is_visliq) - iva_vend += rett_debt; - set_row(rw++, FR("@11g@bIVA esigibile@r per il periodo@75g%r"), &iva_vend); - if (!diffinc_iva.is_zero()) - set_row(rw++,FR("@11g a liquidazione differita@75g%r"), &diffinc_iva); - if (!xcasinc_iva.is_zero()) - set_row(rw++,FR("@11g per cassa@75g%r"), &xcasinc_iva); - if (_is_visliq) - set_row(rw++,FR("@11g$[r]Rettifiche IVA a debito$[n]@75g%r"), &rett_debt); // Rettifiche modificabili - - // Se sono in visualizzazione stampo i due importi separati, altrimenti li sommo - if (!_is_visliq) - iva_acq += rett_cred; - set_row(rw++, FR("@11g@bIVA detraibile@r per il periodo@58g%r"), &iva_acq); - if (!diffinc_iva_acq.is_zero()) - set_row(rw++,FR("@11g a liquidazione differita@58g%r"), &diffinc_iva_acq); - if (!xcasinc_iva_acq.is_zero()) - set_row(rw++,FR("@11g per cassa@58g%r"), &xcasinc_iva_acq); - if (_is_visliq) - set_row(rw++,FR("@11g$[r]Rettifiche IVA a credito$[n]@58g%r"), &rett_cred); - - real iva_deb_cred = iva_vend - iva_acq + diffinc_iva - diffinc_iva_acq + xcasinc_iva - xcasinc_iva_acq; - if (_is_visliq) - iva_deb_cred += rett_debt - rett_cred; - if (_isannual) - iva_deb_cred.round(0); - - print_importo(rw++, TR("IVA a debito o a credito per il periodo"), iva_deb_cred); - - rw++; - print_importo(rw++, TR("Variazioni d'imposta"), variazioni_imposta, _is_visliq); - print_importo(rw++, TR("Imposta non versata"), imposta_non_versata, _is_visliq); - - if (debt_prec > ZERO) - set_row(rw++,FR("@11gDebito o credito da liquidazione precedente@75g%r"), &debt_prec); - else - { - cred_prec -= rimborso; - if (cred_prec > ZERO) - set_row(rw++,FR("@11gDebito o credito da liquidazione precedente@58g%r"), &cred_prec); - } - set_row(rw++,FR("%s@11gRimborsi%s@75g%r"), - _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rimborso); - set_row(rw++, FR("@11gCredito IVA compensabile detratto@58g%r"), &credito_utilizzato_iva); - - real cre_deb_per = risultato + crediti_speciali + acc_dec + vers_int; - if (_month == 13) cre_deb_per += versamenti; - - print_importo(rw++, TR("IVA dovuta o a credito per il periodo"), cre_deb_per); - - if (crediti_speciali != ZERO || _is_visliq) - set_row(rw++,FR("%s@11gCrediti speciali%s@58g%r"), - _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &crediti_speciali); - - if (_freqviva == "T" && !interessi.is_zero()) - set_row(rw++,FR("@11gInteressi dovuti per liquidazioni trimestrali %6.2r%%@75g%r"),&interesse, &interessi); - else - if (_is_visliq) rw++; - - if (!acc_dec.is_zero()) - set_row(rw++,FR("%s@11gAcconto versato%s@58g%r"), - _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &acc_dec); - else - if (_is_visliq) rw++; - - // versamenti effettuati - if (!versamenti.is_zero() && (_month==13 || !_is_visliq)) - set_row(rw++,FR("@11gVersamenti effettuati@58g%r"), &versamenti); - else - if (_is_visliq) rw++; - - // versamenti integrativi - if (!vers_int.is_zero() && !_is_visliq) - set_row(rw++,FR("@11gVersamenti integrativi@58g%r"), &vers_int); - else - if (_is_visliq) rw++; - - const real iva = risultato + interessi; - if (iva > ZERO) - { - if (iva >= iva_da_riportare(_month)) - set_row(rw++,FR("@23gIMPORTO DA VERSARE@75g%r"),&iva); - else - set_row(rw++,FR("@23gIMPORTO DA NON VERSARE@75g%r"),&iva); - } - else - { - if (_isannual) - { - const real& credito = d._r20; - if (credito > ZERO) - set_row(rw++,FR("@11gCREDITO RIPORTATO NELL'ANNO SUCCESSIVO@58g%r"), &credito); - } - if (_is_visliq) - rw++; - } - - if (_is_visliq && _month != 13) - { - rw++; - set_row(rw++,FR("@11g$[r]Descrizione$[n]")); - - // stampa versamenti (anche 0) ad uso visualizzazione liquidazione IVA - rw++; - set_row(rw++,FR("@11g$[r]Versamenti effettuati$[n]@58g%r"), &versamenti); - set_row(rw++, ""); - set_row(rw++, ""); - } - - if (!_is_visliq) - { - // descrizione rettifiche - if (d._s6.not_empty()) - { - rw++; - set_row(rw++, FR("@11g@bDESCRIZIONE RETTIFICHE@r")); - rw++; - if (d._s6.not_empty()) { set_row(rw++, "@11g%t", &(d._s6)); } - } - } -} - -static void imp2string(const real& n, TString& str) -{ - if (!n.is_zero()) - { - const TCurrency c(n); - str = c.string(true); - str.right_just(15); - } - else - str.spaces(15); -} - -void TLiquidazione_app::set_iva_succ(int& rw) -{ - TString query; - query << "USE IVADIFF KEY 2 SELECT (BETWEEN(DATAREG,#DAL,#AL))&&(BETWEEN(DATAREGP,0,#AL))" - << "\nFROM ANNOLIQ=" << _year; - TISAM_recordset id(query); - const TDate da_datareg(1, 1, atoi(_year)); - const TDate a_datareg(31, 12, atoi(_year)); - id.set_var("#DAL", da_datareg); - id.set_var("#AL", a_datareg); - - TImporto ven_diff, ven_xcas, acq_xcas; - long cur_numreg = 0; - int cur_tipodif = 0; - int cur_tipoiva = 0; - - for (bool ok = id.move_first(); ok; ok = id.move_next()) - { - const long numreg = id.get(RMI_NUMREG).as_int(); - if (numreg != cur_numreg) - { - cur_numreg = numreg; - cur_tipodif = id.get("TIPODIFF").as_int(); - cur_tipoiva = id.get("TIPOIVA").as_int(); - } - const char sezione = id.get("SEZIONE").as_string()[0]; - const TImporto imp(sezione, id.get(RMI_IMPONIBILE).as_real()); - if (!imp.is_zero()) - { - if (cur_tipoiva == 1) // Vendite - { - if (cur_tipodif == 1) - ven_diff += imp; - else - ven_xcas += imp; - } - else - acq_xcas += imp; - } - } - - if (!ven_diff.is_zero() || !ven_xcas.is_zero() || !acq_xcas.is_zero()) - { - set_row(rw++,FR("@11g@bOPERAZIONI EFFETTUATE NELL'ANNO CON IMPOSTA ESIGIBILE NEGLI ANNI SUCCESSIVI@r")); - const real vd = ven_diff.valore(); - const real vc = ven_xcas.valore(); - const real vt = vc+vd; - const real at = acq_xcas.valore(); - - set_row(rw++, "Totale vendite con IVA esigibile negli anni successivi@66g%r", &vt); - set_row(rw++, "Di cui con IVA per cassa@66g%r", &vc); - set_row(rw++, "Totale acquisti con IVA detraibile negli anni successivi@66g%r", &at); - set_row(rw++, "Di cui con IVA per cassa@66g%r", &at); - } -} - -void TLiquidazione_app::set_grand(_DescrItem& d) -{ - int rw = 1; - - if (_isannual) // Stampa annuale evidenzia importi esigibili l'anno dopo - set_iva_succ(rw); - - set_bookmark(TR("Riepilogativo liquidazione"), _firm_bookmark); - set_row(rw++,""); set_row(rw++,""); set_row(rw++,""); set_row(rw++,""); - set_row(rw++,FR("@11g@bCALCOLO LIQUIDAZIONE D'IMPOSTA@r")); - - /* - const bool new_print = atoi(_year) >= 2000; - if (new_print) - set_grand_2000(d, rw); - else - set_grand_1999(d, rw); - */ - set_grand_2000(d, rw); - - - // rapportini per rimborso infraannuale - // non si stampano se la stampa serve per la visualizz. - // solo in st.di prova in coda ai registri deve scendere - // il prospetto di rimborso - // sempre (cioe' in bollato e in prova) deve scendere - // il prospettino versamento - if (d._arr.items() > 0 && !_is_visliq) - { - for (int i = 0; i < d._arr.items(); i++) - { - const _DescrItem& di = (_DescrItem&)d._arr[i]; - - if (di._flags == RIMBORSO) - { - if (!_isregis || (_isregis && !_isfinal)) - { - set_print_zero(TRUE); - set_row(rw++,""); - set_row(rw++,""); - - set_bookmark(TR("Prospetto di rimborso"), _firm_bookmark); - - set_row(rw++, TR(" PROSPETTO DI RIMBORSO")); - - if (di._f0) - { - // esenti e non imponibili - set_row(rw++,""); - set_row(rw++,TR("1) Soggetto con quota di operazioni esenti e non imponibili superiore al 25%%")); - - real perc = di._r0 * CENTO / di._r1; perc.round(0); - - TString sep(strlen(REAL_PICTURE)+2); sep.fill('-'); - set_row(rw++,""); - set_row(rw++,FR("@26gTotale operazioni esenti e non imp.@66g%r"), - &(di._r0)); - set_row(rw++,FR("@66g%t x 100 = %3r%%"), &sep, &perc); - set_row(rw++,FR("@26gVolume di affari lordo@66g%r"), &(di._r1)); - set_row(rw++,""); - } - - if (di._f1) - { - set_row(rw++,""); - set_row(rw++,TR("2) Soggetto con acquisti ad aliquota media superiore a quella delle vendite")); - TString sep(strlen(REAL_PICTURE)+2); sep.fill('-'); - set_row(rw++,""); - set_row(rw++,FR("@26gTotale imposte sugli acquisti@66g%r"), &(di._r5)); - set_row(rw++,"@66g%t x 100 = %5.2r%%", &sep, &(di._r7)); - set_row(rw++,FR("@26gTotale imponibili sugli acquisti@66g%r"), - &(di._r3)); - set_row(rw++,""); - set_row(rw++,FR("@26gTotale imposte sulle vendite@66g%r"), &(di._r4)); - set_row(rw++,"@66g%t x 100 = %5.2r%%", &sep, &(di._r6)); - set_row(rw++,FR("@26gTotale imponibili sulle vendite@66g%r"), &(di._r2)); - } - - set_print_zero(false); - } - } - // prospettino versamento - else if (di._flags == DELEGA) - { - const bool acconto = di._s4 == "ACC"; - int rr = rw; - int cont = 10; - if (acconto) - { - TToken_string ac(di._s5); - if (!ac.empty_items() && _stampa_vers) - cont = 14; - } - if (rw < (printer().formlen() - cont)) - rw = printer().formlen() - cont; - - for (int i = rr; i < rw; i++) - set_row(i,""); - - set_bookmark(TR("Riepilogo versamenti"), _firm_bookmark); - - if (acconto) // Acconto - { - TToken_string ac(di._s5); - if (!ac.empty_items()) - { - TString16 dt (ac.get(4)); - real app (ac.get(3)); - TString16 vr; imp2string(app, vr); - TString4 con (ac.get(0)); - TString8 abi (ac.get(1)); - TString8 cab (ac.get(2)); - - set_row(rw++, TR("- ACCONTO DICEMBRE -")); - set_row(rw, FR(" Versamento di %s effettuato il %s"), - (const char*)vr, - (const char*)dt); - set_row(rw++, FR("@68gCod Conc.: %3s"),(const char*)con); - set_row(rw++, FR("@68gCod. ABI: %5s Cod. CAB o Cod. Dipendenza: %5s"),(const char*)abi,(const char*)cab); - } - } - - if (_stampa_acc && _stampa_vers) - set_row(rw++, "- SALDO -"); - - if (_stampa_vers) - { - TString16 dt = di._d0.string(); - TString16 vr; imp2string(di._r0, vr); - set_row(rw, FR(" Versamento di %s effettuato il %s"), - (const char*)vr, (const char*)dt); - set_row(rw++, FR("@68gCod Conc.: %3s"),(const char*)di._s0); - set_row(rw++, FR("@68gCod. ABI: %5s Cod. CAB o Cod. Dipendenza: %5s"),(const char*)di._s1,(const char*)di._s2); - } - } - } - } - - if (!_is_visliq) set_auto_ff(TRUE); - else set_auto_ff(FALSE); - - _firm_bookmark = -1; -} - - -bool TLiquidazione_app::set_annual(_DescrItem& d) -{ - // chiamata internamente a set_pims - bool ret = false; - - int row = get_maxrow()+1; - if (row == 1) row = 4; - - if (d._f0 & IS_PRORATA) - { - // 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); - - row++; - set_row(++row, TR("CALCOLO DELLA PERCENTUALE DI DETRAIBILITA'")); - row++; - - set_bookmark(TR("Calcolo pro-rata"), _att_bookmark); - - ret = true; - set_print_zero(true); - set_row(row++,""); - - const real perc_det = CENTO - d._r2; - const real vol_aff = d._r0 - d._r10; // Valutare se eliminare d._r10 come valore e sottrarlo a monte - const TString16 s1 = perc_det.stringa(); - const TString16 s2 = d._r2.stringa(); - set_row(row++, FR("%% PRO-RATA (%s%%) ed IVA non detraibile (%s%%)@69g%r"), - (const char*)s1, (const char*)s2, &(d._r6)); - - set_row(row++,FR("C1 - Operazioni esenti escluse da nr. 1 a 9 e 11 art. 10 @69g%r"), &(d._r1)); - set_row(row++,FR("C2 - Operazioni esenti di cui nr. 11 art. 10 @69g%r"), &(d._r4)); - set_row(row++,FR("C3 - Operazioni esenti da nr. 1 a 9 art. 10 @69g%r"), &(d._r5)); - set_row(row++,FR("@6gdi cui cessione beni ammortizzabili @69g%r"), &(d._r8)); - set_row(row++,FR("C1A - Operazioni esenti di cui all'art.10 n. 27 quinquies @69g%r"), &(d._r7)); - set_row(row++,FR("@6gdi cui cessione beni ammortizzabili @69g%r"), &(d._r9)); - set_row(row++,FR("Totale vendite al fine del calcolo del pro-rata @69g%r"), &vol_aff); - set_row(row++,FR("Detraibilità @69g%r%%"), &perc_det); - - set_print_zero(FALSE); - } - return ret; -} - - -void TLiquidazione_app::set_ventila(_DescrItem& d) -{ - if (d._arr.items() == 0 || d._r0.is_zero()) - return; - - set_bookmark(TR("Prospetto ventilazione"), _att_bookmark); - - set_row(1,FR("@54gPROSPETTO VENTILAZIONE")); - set_row(2,""); - set_row(3,""); - set_row(4,FR("@10gTotale acquisti destinati alla rivendita@55g%r"), - &(d._r0)); - set_row(5,FR("@10gTotale dei corrispettivi da ventilare@55g%r"), - &(d._r1)); - set_row(6,FR("@10gMoltiplicatore@59g%3.9r"),&(d._r2)); - set_row(7,""); - set_row(8,FR("@10gCod.")); - set_row(9,FR("@10gIVA@17gDescrizione@48gAcquisti" - "@65gImponibile vendite@89gImposta vendite")); - set_row(10,""); - int row = 11; - real t1, t2, t3; - TString80 s0; - int i; - - for(i = 0; i < d._arr.items(); i++) - { - _vDesc& vd = (_vDesc&)d._arr[i]; - look_iva(vd._codiva); - s0 = _iva->get("S0"); s0.cut(23); - - set_row(row+i,"@8g%5s@17g%-23s@41g%r@68g%r@89g%r", - (const char*)vd._codiva, - (const char*)s0, - &(vd._acq), - &(vd._vnd), - &(vd._viv)); - t1 += vd._acq; - t2 += vd._vnd; - t3 += vd._viv; - } - set_row(row+i+1,""); - set_row(row+i+2,FR("@10gTotale@41g%r@68g%r@89g%r"), - &t1, &t2, &t3); - set_auto_ff(TRUE); -} - -static void real2string(const real& r, TString& str) -{ - TCurrency cur(r); - str = cur.string(TRUE); -} - -void TLiquidazione_app::set_regagr(_DescrItem& d) -{ - set_print_zero(TRUE); - - real& agr_1 = d._r0; - real& agr_2 = d._r1; - real& agr_3 = d._r2; - real& agr_4 = d._r3; - real& agr_5 = d._r4; - real& agr_6 = d._r5; - real& agr_7 = d._r6; - real& agr_1i = d._r7; - real& agr_2i = d._r8; - real& pdetr = d._r9; - real& ivadt = d._r10; - real& iva_detIA = d._r11; - - real ara = agr_5 + agr_6; - real arn = agr_3 + agr_4; - real agr_ven = agr_1 + agr_2; - real ivadt_amm = agr_3 + ivadt + iva_detIA; - - set_bookmark(TR("Prospetto regime agricolo"), _att_bookmark); - int r = 1; - - set_row(r++,FR("@50gPROSPETTO REGIME AGRICOLO")); - set_row(r++,""); - - // percentuale detraibilita' - set_row(r++, FR("Iva vendite beni I parte Tabella A @56g%r"),&agr_1); - set_row(r++, ""); - set_row(r++, FR("Iva vendite beni diversi da I parte Tabella A @56g%r"),&agr_2); - set_row(r++, ""); - set_row(r++, FR("Totale iva sulle operazioni di vendita @56g%r"), &agr_ven); - set_row(r++, ""); - set_row(r++, FR("Iva acquisti in regime agricolo@56g%r"),&ara); - set_row(r++, ""); - set_row(r++, FR("Iva acquisti per operazioni diverse I parte Tabella A@56g%r"),&arn); - set_row(r++, FR("... di cui beni ammortizzabili@56g%r"),&agr_4); - set_row(r++, ""); - set_row(r++, FR("Iva acquisti ad uso promiscuo@56g%r"),&agr_7); - - TString dn,riga; - if (agr_1i != ZERO) - { - real2string(agr_1i, riga); - dn << riga << " + "; - } - real2string(agr_2i, riga); - dn << riga; - int ln = max(riga.len(),dn.len()) + 2; - int corr = ln % 2 == 0 ? 0 : 1; - TString middle(ln); middle.fill('-'); - int xl = 71 - riga.len()/2; - int times_sign = xl + ln/2 + 3; // per allineare i segni moltiplicativi - middle << "@" << times_sign << "gx 100 = " << pdetr.string(".") << " %"; - - set_row(r++, ""); - set_row(r++, "@56g%r",&agr_2i); - riga.format(FR("Percentuale delle operazioni diverse@%dg%%s"),xl - corr - ln/2); - set_row(r++, riga, (const char*)middle); - corr = dn.len() % 2 == 0 ? 0 : 1; - riga.format("@%dg%%s",xl - corr - dn.len()/2); - set_row(r++, riga, (const char*)dn); - - real2string(agr_7, riga); - dn = "100"; - ln = max(riga.len(),dn.len()) + 2; - xl = 71 - riga.len()/2; - corr = ln % 2 == 0 ? 0 : 1; - - middle.fill('-',ln); - middle << "@" << times_sign << "gx " << pdetr.string("."); - middle << " = " << TCurrency(ivadt).string(TRUE); - - set_row(r++, ""); - set_row(r++, "@56g%r", &agr_7); - riga.format(FR("IVA ammessa in detrazione sugli acquisti promiscui@%dg%%s"),xl - corr - ln/2); - set_row(r++, riga, (const char*)middle); - corr = dn.len() % 2 == 0 ? 0 : 1; - riga.format("@%dg%%s",xl - corr - dn.len()/2); - set_row(r++, riga, (const char*)dn); - set_row(r++, ""); - set_row(r++, FR("Iva ammessa in detrazione I parte tabella A@56g%r"),&iva_detIA); - set_row(r++, ""); - set_row(r++, FR("Totale iva ammessa in detrazione@56g%r"),&ivadt_amm); - - // Last pain... - TArray& agr_array = d._arr; - const int pia_items = agr_array.items(); - - if (pia_items) // Se non siamo ancora nel 1998 questo vale 0, ossia non vi sono items. - { - real t1,t2; // Totale imponibile/imposta - TString des; // Descrizione codice iva ordinario - real al; // Aliquota IVA - r+=2; - // Stampa l' intestazione... - set_row(r++,FR(" Codice IVA@45gAliquota IVA@73gCodice IVA@88gAliquota IVA")); - set_row(r++,FR(" Ordinario@45gOrdinaria@61gImponibile@73gCompensazione@88gCompensazione@108gImposta")); - set_row(r++,""); - for (int i=0; iget("S0"); des.cut(25); - al = _iva->get_real("R0"); - set_row(r,"%4s %-25s@48g%s %%", (const char*) di._s0, (const char*) des, al.string("#@,@@")); - set_row(r,"@56g%r@75g%4s",&di._r0, (const char*)di._s1); - look_iva(di._s1); - al = _iva->get_real("R0"); - set_row(r++,"@92g%s %%@100g%r", al.string("#@,@@"), &di._r1); - t1 += di._r0; - t2 += di._r1; - } - // ... ed il totale minchiativo - r++; - set_row(r++,FR("Totale@56g%r@100g%r"),&t1,&t2); - } - - set_auto_ff(TRUE); - set_print_zero(FALSE); -} - -void TLiquidazione_app::set_viaggio(_DescrItem& d) -{ - // the longest & stronzest - // Nel corso della scrittura di questa funzione - // Berlusconi + Fini + Bossi hanno vinto le elezioni - // ... lungo commento cancellato - - real& corr_CEE = d._r0; - real& corr_misCEE = d._r1; - real& corr_noCEE = d._r2; - real& acq_CEE = d._r3; - real& acq_misCEE = d._r4; - real& acq_noCEE = d._r5; - real& acq_misnoCEE = d._r6; - real& perc_r = d._r7; - real& cred_cos = d._r8; - real& ivm = d._r9; - - real tc = (corr_CEE + ivm); - real ta = (acq_CEE + acq_misCEE); - real& bi = d._r10; - real& dovuta = d._r11; - - real tcc = corr_CEE + corr_noCEE + corr_misCEE; - real tco = acq_CEE + acq_noCEE + acq_misCEE + acq_misnoCEE; - real tma = acq_CEE + acq_misCEE; - - set_print_zero(TRUE); - - set_bookmark(FR("Prospetto 74 ter"), _att_bookmark); - - set_row(1,""); - set_row(2,FR("@54gRIEPILOGO 74 TER")); - set_row(3,""); - set_row(4,FR("Ammontare dei corrispettivi relativi a viaggi eseguiti" - " interamente nella CEE .....................@100g%r"), &(corr_CEE)); - set_row(5,FR("Ammontare dei corrispettivi relativi a viaggi misti (dentro" - " e fuori CEE) ......................... @100g%r"), &(corr_misCEE)); - set_row(6,FR("Ammontare dei corrispettivi relativi a viaggi eseguiti" - " interamente fuori CEE ..................... @100g%r"), &(corr_noCEE)); - - - set_row(7,""); - set_row(8,FR("@56gTotale corrispettivi@100g%r"), &tcc); - set_row(9,""); - - set_row(10,FR("Ammontare dei costi relativi a viaggi interamente" - " svolti nella CEE ............................... @100g%r"), - &(acq_CEE)); - set_row(11,FR("Ammontare dei costi relativi a viaggi misti (per la" - " parte CEE) ................................... @100g%r"), - &(acq_misCEE)); - set_row(12,FR("Ammontare dei costi relativi a viaggi interamente" - " svolti fuori CEE ............................... @100g%r"), - &(acq_noCEE)); - set_row(13,FR("Ammontare dei costi relativi a viaggi misti (per la" - " parte fuori CEE) .............................@100g%r"), - &(acq_misnoCEE)); - - set_row(14,""); - set_row(15,FR("@64gTotale costi@100g%r"), &tco); - - set_row(16,""); - set_row(17,TR("DETERMINAZIONE CORRISPETTIVI IMPONIBILI " - "RELATIVI A VIAGGI MISTI")); - set_row(18,""); - - // la bella frazioncina della percentuale di ripartizione - TString tmp; real2string(acq_misCEE, tmp); - TString up = tmp; - up << " x 100"; - TString dn = tmp; - real2string(acq_misnoCEE, tmp); - dn << " + " << tmp; - int ln = max(up.len(), dn.len()) + 2; - TString den(ln); den.fill('-'); - up.center_just(ln); dn.center_just(ln); - - // la bella frazioncina degli imponibili viaggi misti - TString tmp2; real2string(corr_misCEE, tmp2); - TString up2 = tmp2; - const TString16 perc_r_str = perc_r.string("###,@@"); - up2 << " x" << perc_r_str; - TString dn2 = "100"; - int ln2 = max(up2.len(), 3) + 2; - TString den2(ln2); den2.fill('-'); - up2.center_just(ln2); dn2.center_just(ln2); - - // la gran frazionazza centrata e stupenda - int tot = 35 + ln + ln2; - int rem1 = (100 - tot)/2; if (rem1 < 0) rem1 = 0; - int pos1 = rem1 + 13; - int rem2 = pos1+ den.len() + 11; - int pos2 = rem2 + 20; - - set_row(19,format("@%dg%%t@%dg%%t", pos1, pos2), - &up, &up2); - set_row(20,format(FR("@%dgPerc. rip. = %%t = %%t; @%dg" - "Imp. viaggi misti = %%t = @100g%%r"), - rem1, rem2), - &den, &perc_r_str, &den2, &ivm); - set_row(21,format("@%dg%%t@%dg%%t", pos1, pos2), - &dn, &dn2); - - real tmr = corr_CEE + ivm; - - // whew, come dicono su Topolino - - real2string(corr_CEE, tmp); - up = "("; up << tmp << " + "; - real2string(ivm, tmp); - up << tmp << ")"; - den.fill('.',59-up.len()); - set_row(23,FR("Ammontare dei corrispettivi imponibili@40g%t %t@100g%r"), - &up, &den, &tmr); - - // se e' l'annuale non ha senso altro - if (d._f1) return; - - real2string(acq_CEE, tmp); - up = "("; up << tmp << " + "; - real2string(acq_misCEE, tmp); - up << tmp << ")"; - den.fill('.',59-up.len()); - set_row(24,FR("Ammontare dei costi deducibili@40g%t %t@100g%r"), - &up, &den, &tma); - den.fill('.',60); - set_row(25,FR("Credito di costo precedente @40g%t@100g%r"), &den, &(cred_cos)); - - real2string(tmr, tmp); - up = "["; up << tmp << " - ("; - real2string(tma, tmp); - up << tmp << " + "; - real2string(d._r8, tmp); - up << tmp << ")]"; - den.fill('.',59-up.len()); - - set_row(26,FR("Base imponibile lorda@40g%t %t@100g%r"), &up, &den, &bi); - set_row(27,""); - - if (bi > ZERO) - { - const real aliva = aliquota_agvia(); - const real alcnt = aliva + CENTO; - - real2string(bi, tmp); - up = tmp; - up << " x" << aliva.string("###,@@"); - dn = alcnt.string("###,@@"); - ln = max(up.len(), 3) + 2; - den.fill('-',ln); - up.center_just(ln); dn.center_just(ln); - - tmp.fill('.', 59 - den.len()); - - set_row(28,"@40g%t",&up); - set_row(29,FR("IVA A DEBITO@40g%t %t@100g%r"), &den, &tmp, &dovuta); - set_row(30,"@40g%t", &dn); - } - else if (bi.sign() < 0) - { - bi = abs(bi); - set_row(28,""); - set_row(29,FR("CREDITO DI COSTO DA RIPORTARE@100g%r"), &bi); - } - - set_print_zero(FALSE); - set_auto_ff(TRUE); -} - -void TLiquidazione_app::set_acconto_p(_DescrItem& d) -{ - const char* errmsg[3] = { - {TR("manca la tabella risultati liquidazione per l'anno corrente")}, - {TR("manca la tabella risultati liquidazione per l'anno precedente")}, - {TR("manca la tabella dichiarazione annuale per l'anno precedente")}}; - - set_row(1,"%t@7g%t",&(d._s0), &(d._s1)); - if (d._f2) - set_row(1,"@50g@b*** %s ***@r", errmsg[d._f2 -1]); - else - { - if (d._f0) // base anno in corso - { - if (d._f1) // stampa base di calcolo - { - set_row(1,"@58g%r@74g%r@96g%r@122g%s", &(d._r3), - &(d._r2), &(d._r1), d._f3 ? "Si" : "No"); - } - else - set_row(1,"@62g%r@91g%s", &(d._r1), d._f3 ? "Si" : "No"); - } - else //metodo storico - { - if (d._f1 && (d._r0).sign()>0) // stampa base di calcolo - set_row(1,"@58g%r@88g%r", &(d._r0), &(d._r1)); - else - set_row(1,"@87g%r",&(d._r1)); - } - } -} - -void TLiquidazione_app::set_acchead_p(_DescrItem& d) -{ - reset_header(); - set_header(1,FR("Gestione IVA@107gData @>@125gPag. @#")); - set_header(3,sep); - - if (d._f0) // base anno in corso - { - set_header(2,FR("@40gCALCOLO ACCONTI IVA DICEMBRE %s " - "(base anno in corso)"), (const char*) _year); - if (d._f1) // stampa base calcolo - { - set_header(4,FR("@58g------- Base di calcolo -------")); - set_header(5,FR("Ditta@7gDenominazione@62gDebito@78gCredito" - "@94gACCONTO calcolato@115gLiq. differita")); - set_header(6,sep); - set_header(7,""); - } - else - { - set_header(4,FR("Ditta@7gDenominazione@60gACCONTO calcolato" - "@84gLiq. differita")); - set_header(5,sep); - set_header(6,""); - } - } - else - { - set_header(2,FR("@40gCALCOLO ACCONTI IVA DICEMBRE %s"), (const char*) _year); - set_header(5,sep); - set_header(6,""); - if (d._f1) - set_header(4,FR("Ditta@7gDenominazione@58gBase di calcolo" - "@86gACCONTO calcolato")); - else - set_header(4,FR("Ditta@7gDenominazione@85gACCONTO calcolato")); - } -} - - -// --------------------------------------------------------------------- -// Tabulato deleghe -// --------------------------------------------------------------------- - -void TLiquidazione_app::set_deltab(_DescrItem& d, bool iscred) -{ - reset_header(); - int rw = 1; - static bool credpr; - - if (iscred) - { - // set header - set_header(1,FR("ELENCO DITTE A CREDITO@30g%s %s@107gData @>@125gPag. @#"), - d._f0 == 13 ? TR("Annuale ") : itom(d._f0), (const char*)_year); - set_header(2,sep); - set_header(3,FR("@40gF@60gImporto a")); - set_header(4,FR("Cod.@8gDenominazione@40gR@62gcredito")); - set_header(5,sep); - set_header(6,""); - - // set rows - for (int i = 0; i < d._arr.items(); i++) - { - TToken_string& tt = (TToken_string&)(d._arr)[i]; - TString cod(tt.get(0)); - TParagraph_string rgs(tt.get(1), 30); - TString diocantaro(rgs.get(0)); - TString frq(tt.get(2)); - real tp (tt.get(3)); - real in (tt.get(4)); - tp -= in; - tp = -tp; - set_row(rw++, "%-5s@8g%-30s@40g%1s@54g%r", - (const char*)cod, (const char*)diocantaro, - (const char*)frq, &tp); - for (int i = 1; i < rgs.items(); i++) - set_row(rw++, "@8g%-30s", (const char*)rgs.get(i)); - } - } - else - { - // set header - set_header(1,FR("ELENCO DITTE A DEBITO@30g%s %s@107gData @>@125gPag. @#"), - d._f0 == 13 ? TR("Annuale ") : itom(d._f0), (const char*)_year); - set_header(2,sep); - set_header(3,FR("@40gF@60gImporto da@73gCodice@83gCod.")); - set_header(4,FR("Cod.@8gDenominazione@40gR Numero telefonico@63gversare Banca Dip. Con.")); - set_header(5,sep); - set_header(6,""); - - - // set rows - for (int i = 0; i < d._arr.items(); i++) - { - TToken_string& tt = (TToken_string&)(d._arr)[i]; - TString cod(tt.get(0)); - TParagraph_string rgs(tt.get(1), 30); - TString diocantaro(rgs.get(0)); - TString frq(tt.get(2)); - real tp (tt.get(3)); - real in (tt.get(4)); - TString abi(tt.get(5)); - TString cab(tt.get(6)); - TString con(tt.get(7)); - TString tel(tt.get(8)); - if (!tel.blank()) - tel << '/'; - tel << tt.get(9); - TString desc(tt.get(10)); - - set_row(rw++, "%-5s@8g%-30s@40g%1s %s @55g%r %5s %5s %3s %-.45s", - (const char*)cod, (const char*)diocantaro, (const char*)frq, - (const char*)tel, &tp, (const char*)abi, - (const char*)cab, (const char*)con, (const char*)desc); - - for (int i = 1; i < rgs.items(); i++) - set_row(rw++, "@8g%-30s", (const char*)rgs.get(i)); - } - } - set_auto_ff(TRUE); -} - +// ------------------------------------------------------------ +// Calcolo liquidazioni +// Part 5: stampa +// fv 21-1-94 +// ------------------------------------------------------------ + +#include +#include +#include +#include + +#include "cg4300.h" + +#include +#include +#include + +// flags per annuale +#define IS_PRORATA 0x0001 + +// minchietta per prospetto ventilazione +struct _vDesc : public TObject +{ + TString4 _codiva; + real _acq, _vnd, _viv; +}; + +const char* const sep = +"------------------------------------------------------------------" +"------------------------------------------------------------------"; + +void TLiquidazione_app::set_page(int file, int cnt) +{ + _DescrItem& d = (_DescrItem&)_descr_arr[cnt]; + + set_auto_ff(false); + reset_print(); + + switch(d._flags) + { + case CHG_PARMS: + set_att(d); + break; + case SET_FIRM: + set_firm(d); + break; + case PIS_ROW: + case PIM_ROW: + case PIS_ROW_D: + case PIM_ROW_D: + case PIS_ROW_DI: + case PIM_ROW_DI: + set_pim(d); + break; + case PIS_HEAD: + case PIM_HEAD: + case PIS_HEAD_D: + case PIM_HEAD_D: + case PIS_HEAD_DI: + case PIM_HEAD_DI: + set_pim_head(d); + break; + case MISC_LIQ: + set_pumpam(d); + break; + case TOT_ROW: + set_plm(d); + break; + case TOT_ROW_D: + case TOT_ROW_DI: + set_plm_diff(d); + break; + case PLAFOND: + set_plafond(d); + break; + case VENTILA: + set_ventila(d); + break; + case REGAGR: + set_regagr(d); + break; + case REGVIA: + set_viaggio(d); + break; + case THE_END: + set_grand(d); + break; + case LIQACC: + set_liqacc_2000(d); + break; + case ACCONTO: + set_acconto_p(d); + break; + case ACCHEAD: + set_acchead_p(d); + break; + case DELDEB: + set_deltab(d, false); + break; + case DELCRED: + set_deltab(d, true); + break; + default: + break; + } +} + +print_action TLiquidazione_app::postprocess_page(int file, int cnt) +{ + if (_descr_arr.items() == 0 || cnt == _descr_arr.items()-1) + return NEXT_PAGE; + return REPEAT_PAGE; +} + +bool TLiquidazione_app::preprocess_page(int file, int cnt) +{ + return _descr_arr.items() != 0; +} + +// ---------------------------------------------------------------- +// Print description +// ---------------------------------------------------------------- + +void TLiquidazione_app::describe_att(int month, const char* codatt, bool /*isresult*/, char flags) +{ + if (_isprint && _canprint) + { + TToken_string atts(codatt); + const bool single_att = atts.items() == 1; + + describe_name(month, atts, flags); + + if (single_att) + { + if (_isplafond) + describe_plafond(month, codatt); + if (_isvent) + describe_ventilation(month, codatt); + if (_isagricolo) + describe_agricolo(month, codatt); + if (_isviaggio) + describe_viaggio(month, codatt); + } + + describe_pims(month, codatt, false); // PIM + describe_pims(month, codatt, true); // PIS + + if (single_att) + describe_consistence(codatt); + } +} + +void TLiquidazione_app::describe_name(int month, const TToken_string& codatts, char flags) +{ + const bool single_att = codatts.items() == 1; + + _DescrItem* d = new _DescrItem(CHG_PARMS); + + d->_s0 = _nditte->curr().get(NDT_CODDITTA); + d->_s1 = _nditte->curr().get(NDT_RAGSOC); + + const TRectype& ndt_att = _nditte->curr(LF_ATTIV); + d->_s2 = ndt_att.get(ATT_CODATECO); + if (d->_s2.blank()) + d->_s2 = ndt_att.get(ATT_CODATT); + d->_s3 = single_att ? (const char*)ndt_att.get(ATT_DESCR) : ""; + d->_s4 = _freqviva; + + d->_f1 = month; + d->_f2 = _isbenzinaro; + d->_f3 = (word)flags; + + d->_f0 = 0; + if (_mixed && single_att) + d->_f0 = atoi(codatts.mid(5)); + + _descr_arr.add(d); +} + +void TLiquidazione_app::describe_firm(int month) +{ + if (!_isprint || !_canprint) return; + + _DescrItem* d = new _DescrItem(SET_FIRM); + + d->_s0 = _nditte->curr().get("CODDITTA"); + d->_s1 = _nditte->curr().get("RAGSOC"); + d->_s2 = _freqviva; + d->_f1 = month; + _descr_arr.add(d); +} + +void TLiquidazione_app::describe_liqacc() +{ + if (!_isprint || !_canprint) return; + + const TRectype & lia = get_lia(); + + if (lia.not_empty() && lia.get("S8") == "A") + { + + _DescrItem* d = new _DescrItem(LIQACC); + + d->_r0 = lia.get_real("R7"); + d->_r1 = lia.get_real("R13"); + d->_r2 = lia.get_real("R14"); + d->_r3 = lia.get_real("R9"); + d->_r4 = lia.get_real("R10"); + d->_r5 = lia.get_real("R8"); + d->_r6 = lia.get_real("R12"); + d->_r7 = lia.get_real("R11"); + d->_r8 = lia.get_real("R4"); + d->_r29 = lia.get_real("R29"); + d->_r33 = lia.get_real("R33"); + TToken_string ff(lia.get("S1"),'!'); + real cre_pre (ff.get(0)); + real acq_intr (ff.get(1)); + d->_r9 = cre_pre; + d->_r10 = acq_intr; + + _descr_arr.add(d); + } +} + +void TLiquidazione_app::describe_plafond(int month, const char* codatt) +{ + TString att(codatt); + // prepara la descrizione del riepilogo da stampare e lo accoda + real t1, t2, t3; + _DescrItem* d = new _DescrItem(PLAFOND); + + if (month == 13) + look_pla(codatt); + for (int jj = 1; jj <= 3; jj++) // three types of plafond + { + t1 = 0.0; t2 = 0.0; t3 = 0.0; + + if (month < 13) + { + look_ppa(_freqviva == "M" ? month : next_trim(month) -2, codatt,jj); + t3 = _ppa->get_real("R2"); + } + for (int m = 1; m <= month && m < 13; m++) + { + if (is_month_ok(m,month) && look_ppa(m,codatt,jj)) + { + t1 += _ppa->get_real("R0"); + t2 += _ppa->get_real("R1"); + } + } + switch (jj) + { + case 1: + d->_r0 = t1; d->_r1 = t2; + d->_r2 = month < 13 ? t3 : _pla->get_real("R5"); + break; + case 2: + d->_r3 = t1; d->_r4 = t2; + d->_r5 = month < 13 ? t3 : _pla->get_real("R6"); + break; + case 3: + d->_r6 = t1; d->_r7 = t2; + d->_r8 = month < 13 ? t3 : _pla->get_real("R7"); + break; + } + } // for tipo esenzione plafond + + _descr_arr.add(d); + + // bookmark +} + +void TLiquidazione_app::describe_ventilation(int month, const char* codatt) +{ + if (!_isvent || _isagricolo || _isviaggio) + return; + + _DescrItem* d = new _DescrItem(VENTILA); + TString16 att = codatt; + + look_plm(month, att); + + for (_pim->first(); !_pim->eof(); _pim->next()) + { + if (strcmp(*_pim_codatt,att) != 0) + continue; + + look_reg(*_pim_codreg); + look_iva(*_pim_codiva); + + int tipocr = atoi(*_pim_tipocr); + int tipodet = atoi(*_pim_tipodet); + int mese = atoi(*_pim_mese); + bool corrisp = _reg->get_bool("B0"); + real imponibile = _pim->get_real("R0"); + real imposta = _pim->get_real("R1"); + tiporeg tipomov = (tiporeg)_reg->get_long("I0"); + TString4 tipoiva = _iva->get("S1"); + + if (_year != *_pim_anno || (month == 13 && mese < 13)) + continue; + + if (imponibile.is_zero() && imposta.is_zero()) continue; + + // questi non vanno in liquidazione, i totali sono + // gia' calcolati altrove + if (tipodet == 1 || (tipodet == 3 && tipocr == 5) || tipodet == 9) + continue; + + // questi non si devono vedere perche' so' bbrutti + if (tipoiva == "NS" || tipoiva == "ES" || tipoiva == "NI") + continue; + + if (mese <= month) + { + if (tipocr == 1 && tipomov == acquisto) + { + // somma agli acquisti + _vDesc* vd = NULL; + for (int i = 0; i < d->_arr.items(); i++) + { + _vDesc* vv = (_vDesc*)&(d->_arr[i]); + if (strcmp(vv->_codiva,*_pim_codiva) == 0) + { vd = vv; break; } + } + if (vd == NULL) { vd = new _vDesc; } + + vd->_acq += (imponibile+imposta); + d->_r0 += (imponibile+imposta); + + if (vd->_codiva.empty()) + { + vd->_codiva = *_pim_codiva; + d->_arr.add(vd); + } + } + else if ((is_month_ok(mese,month) || month == 13) && corrisp + && _pim->get_bool("B1") && + tipocr == 0 && tipomov == vendita) + // non sono sicurissimo della above condition + { + // somma alle vendite + _vDesc* vd = NULL; + for (int i = 0; i < d->_arr.items(); i++) + { + _vDesc* vv = (_vDesc*)&(d->_arr[i]); + if (strcmp(vv->_codiva,*_pim_codiva) == 0) + { vd = vv; break; } + } + if (vd == NULL) { vd = new _vDesc; } + + vd->_vnd += imponibile; + vd->_viv += imposta; + + d->_r1 += imponibile+imposta; + + if (vd->_codiva.empty()) + { + vd->_codiva = *_pim_codiva; + d->_arr.add(vd); + } + } + } + } + + d->_r0 = _pam->get_real("R2"); // Totale acquisti + d->_r1 = _pam->get_real("R3"); // Totale vendite + + if (d->_r1.is_zero() || d->_r0.is_zero()) + delete d; + else + { + // Questo e' il fantastico moltiplicatore + d->_r2 = d->_r1 / d->_r0; + _descr_arr.add(d); + } +} + +void TLiquidazione_app::describe_agricolo(int month, const char* codatt) +{ + _DescrItem* d = new _DescrItem(REGAGR); + + // Setta l'array interno con tutti gli items relativi alla tabella PIA + TArray& agr_array = d->_arr; + for (_pia->first(); !_pia->eof(); _pia->next()) // Scorre i progressivi agricoli + { + if (strcmp((const char*)*_pia_codatt, codatt) == 0 && + is_month_plain(atoi(*_pia_mese)) && _year == *_pia_anno) // E sono gia' in ordine di codice... + { + _DescrItem* p = new _DescrItem(PROGAGR); + p->_r0 = _pia->get_real("R0"); // Imponibile + p->_r1 = _pia->get_real("R1"); // Imposta + p->_s0 = *_pia_codord; // Codice iva ordinario + p->_s1 = *_pia_codcom; // Codice iva compensazione + if (p->_r0 != ZERO || p->_r1 != ZERO) + agr_array.add(p); // Aggiunge il fottuto item agricolo + } + } + + for (int mese = month == 13 ? 13 : 1; mese <= month; mese++) + { + if (!is_month_ok(mese,month)) + continue; + + if (!look_plm(mese, codatt)) + continue; + + d->_r0 += _plm->get_real("R5"); + d->_r1 += _plm->get_real("R6"); + d->_r2 += _plm->get_real("R7"); + d->_r3 += _plm->get_real("R8"); + d->_r4 += _plm->get_real("R9"); + d->_r5 += _plm->get_real("R10"); + d->_r6 += _plm->get_real("R11"); + d->_r7 += _pum->get_real("R10"); + d->_r8 += _pum->get_real("R11"); + d->_r11 += _plm->get_real("R13"); + } + // Aggiungo anche questi per comodita' futura. + // in caso di ditta a regime agricolo + // alias: + // _r9 mantiene la percentuale (gia' arrotondata!) + // _r10 mantiene l'iva detraibile calcolata! + d->_r9 = d->_r8 / (d->_r7 + d->_r8); + round_al_centesimo(d->_r9); + d->_r10 = d->_r6 * d->_r9; + d->_r9 *= CENTO; + round_al_centesimo(d->_r10); + + _descr_arr.add(d); +} + +void TLiquidazione_app::describe_viaggio(int month, const char* codatt) +{ + const TRectype & lim = get_lim(month); + + if (lim.not_empty()) + { + _DescrItem* d = new _DescrItem(REGVIA); + + + for (int mese = month == 13 ? 13 : 1; mese <= month; mese++) + { + 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 + d->_r2 += _plm->get_real("R6"); // corrispettivi fuori CE + d->_r3 += _plm->get_real("R7"); // acquisti CEE + 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 + } + + // credito di costo precedente (CHECK annuale) + d->_r8 = credito_costo_prec(month); + + // Solita minchiatina dell'arrotondamento alle 1000 lirette se siamo in annuale + if (month == 13 || atoi(_year) >= 2000) // CM500314 e CM500315 + { + round_imposta(d->_r0); + round_imposta(d->_r1); + round_imposta(d->_r2); + round_imposta(d->_r3); + round_imposta(d->_r4); + round_imposta(d->_r5); + round_imposta(d->_r6); + round_imposta(d->_r8); + } + + d->_r7 = d->_r4.is_zero() ? ZERO : (d->_r4 * CENTO)/(d->_r4 + d->_r6); d->_r7.round(2); // percentuale + d->_r9 = (d->_r1 * d->_r7)/CENTO; + + if (month == 13) + round_imposta(d->_r9); + else + round_al_centesimo(d->_r9); + + // Calcola l'iva a debito, visto che servira' anche nel calcolo liquidazione (solo annuale) + const real aliva = aliquota_agvia(); + const real alcnt = aliva + CENTO; + d->_r10 = (d->_r0 + d->_r9) - (d->_r3 + d->_r4 + d->_r8); // base imponibile lorda + if (d->_r10.sign() > 0) + { + // d->_r11 = (d->_r10/(alcnt/CENTO)) * (aliva/CENTO); // iva dovuta + d->_r11 = d->_r10 * aliva / alcnt; // iva dovuta + if (month == 13) + round_imposta(d->_r11); + else + round_al_centesimo(d->_r11); + } + _descr_arr.add(d); + } +} + +void TLiquidazione_app::describe_pims(int month, const char* codatt, const bool describe_pis) + // le si passa una tokenstring (o un codatt) e lei, da brava, calcola + // cumulando per tutte le attività nominatele + // ogni riga riguarda un codiva ma tutti i registri + // se il mese e' 13 si guarda tutto l'anno + // se si tratta di una sola attività in att. mista evidenziata o servizievole, + // stampa solo vendite e corrispettivi + // L'ultimo parametro serve per calcolare i PIS (progressivi del periodo successivo) +{ + TToken_string atts(codatt); + const TString8 ref(atts.items() == 1 ? codatt : "ALL"); + int last = _descr_arr.last(); + bool issosp = false; + real t0, t1, t2, t3, t4, t5, t26, t27, t28, t29, t30, t31, t32, t33; + real rt0, rt1, rt2, rt3, rt4, rt5; + real autodafe, autodafe_iva, art40, art40_iva; + real diffimp, diffiva, diffincimp, diffinciva; + real diffimp_acq, diffiva_acq, diffincimp_acq, diffinciva_acq; + const bool skip_acq = atts.items() == 1 && _mixed; + + // descrittore riga autodafe' + _DescrItem* ads = NULL; + // descrittore riga iva dovuta ag. viaggio' + _DescrItem* iads = NULL; + + // Seleziona la tabella corretta: PIM o PIS e l'identificatore + TTable* tab = describe_pis ? _pis : _pim; + const word PIM_PIS = describe_pis ? PIS_ROW : PIM_ROW; + + // questa cazzata serve per far apparire l'intestazione delle colonne + // anche se le colonne non ci sono; in tal modo si ottiene una peggior + // chiarezza, una peggiore efficienza, una gran rottura di coglioni, + // ma risulta identico al dio Sistema. + _DescrItem * hea = NULL; + _DescrItem * head = NULL; + _DescrItem * headi = NULL; + _DescrItem * tot = NULL; + _DescrItem * totd = NULL; + _DescrItem * totdi = NULL; + int totpos = 0; + + // Assoc array per memorizzare i corrispettivi da scorporare. Tali corrispettivi verranno + // aggiunti alla fine del ciclo, scorrendo tutte le righe generate. + TAssoc_array corr_ann; + _CorrItem cx; + + FOR_EACH_TOKEN(atts, tmpatt) + { + const TString8 att(tmpatt); + + tab->zero(); tab->put("CODTAB", _year); // 24-02-2014 partiamo dall'anno giusto! + for (int terr = tab->read(_isgteq); terr == NOERR; terr = tab->next()) + { + _DescrItem* d = NULL; + // compute + const TString80 codtab = tab->get("CODTAB"); + const TString4 anno = codtab.mid(0,4); + + if (anno != _year) + break; // 27-02-2014 finiamo con l'anno sbagliato! + + const TString8 activity= codtab.mid(4,6); + const int mese = atoi(codtab.mid(13,2)); + const int tipodet = atoi(codtab.mid(20,1)); + + const TString4 codreg = codtab.mid(10,3); + if (!look_reg(codreg)) + continue; + + TString4 codiva = codtab.mid(16,4); codiva.trim(); + if (!look_iva(codiva)) + continue; + + tiporeg tipomov = (tiporeg)_reg->get_int("I0"); + bool corrisp = _reg->get_bool("B0"); + const TString4 tipoiva = _iva->get("S1"); + const TString4 other = tab->get("S4"); + TToken_string s1(tab->get("S1"), '!'); // Imponibile/iva fatture in ritardo + real rit_imp(s1.get(0)); + real rit_iva(s1.get(1)); + + /* Perchè _pim invece di tab ? 17-10-2012 + diffimp = _pim->get_real("R26"); + diffiva = _pim->get_real("R27"); + diffincimp = _pim->get_real("R28"); + diffinciva = _pim->get_real("R29"); + + diffimp_acq = _pim->get_real("R30"); + diffiva_acq = _pim->get_real("R31"); + diffincimp_acq = _pim->get_real("R32"); + diffinciva_acq = _pim->get_real("R33"); */ + + diffimp = tab->get_real("R26"); + diffiva = tab->get_real("R27"); + diffincimp = tab->get_real("R28"); + diffinciva = tab->get_real("R29"); + + diffimp_acq = tab->get_real("R30"); + diffiva_acq = tab->get_real("R31"); + diffincimp_acq = tab->get_real("R32"); + diffinciva_acq = tab->get_real("R33"); + + const bool is_rit= tipodet != 0 && month == 13 && !rit_imp.is_zero(); //Se fattura in ritardo con tipo detr. != 0 e si sta calcolando l'annuale + const tipo_sospensione sosp_imp = _reg->get_bool("B1") ? (tipo_sospensione) _reg->get_int("I9") : nessuna; + issosp |= (sosp_imp != nessuna); // Setta il flag di presenza registri in sospensione (qualsiasi tipo: normale, vol_affari, liquidazione) + + // ACHTUNG! Corrispettivi da ventileer possono ventilare ad un altro codiva; in tal caso si scrive quello + if (corrisp && other.full()) + { + look_iva(other); + codiva = other; + } + // se e' corrispettivo da ventilare non scrivo un cannolo ripieno visto che e' stato ventilato + if (tipomov == vendita && tipoiva == "VE" && !describe_pis) + continue; + + // se e' il dettaglio di una attivita' mista non stampa gli acquisti, il perche' losalamadonna + if (tipomov == acquisto && skip_acq) + continue; + + // questi non vanno in liquidazione, i totali sono gia' calcolati altrove + if ((tipodet == 1 || tipodet == 3 || tipodet == 9) && !is_rit) + continue; + + // se ha tutti gli importi nulli viene da un annullamento di + // progressivi esistenti (achtung fatture con scontrino) + if (tab->get_real("R0").is_zero() && + tab->get_real("R1").is_zero() && + tab->get_real("R2").is_zero() && + tab->get_real("R5").is_zero() && + tab->get_real("R6").is_zero() && + tab->get_real("R26").is_zero() && + tab->get_real("R27").is_zero() && + tab->get_real("R28").is_zero() && + tab->get_real("R29").is_zero() && + tab->get_real("R30").is_zero() && + tab->get_real("R31").is_zero() && + tab->get_real("R32").is_zero() && + tab->get_real("R33").is_zero()) + continue; + + if (activity == att && is_month_plain(mese) /*&& _year == anno*/) // commentato 27-02-2015 + { + // vedi se c'e' gia' un item corrispondente + int i; + for(i = last+1; i < _descr_arr.items(); i++) + { + _DescrItem& wd = (_DescrItem&)_descr_arr[i]; + if (wd._flags == PIM_PIS && wd._s0 == ref && wd._s1 == codiva) + { + d = &wd; + break; + } + if (wd._flags == TOT_ROW) + break; + if (wd._flags == PIM_PIS && + wd._s0 == ref && + wd._s1 > codiva) + break; + } + if (d == NULL) + { + const bool isfirst = (hea == NULL); + + if (isfirst) + { + hea = new _DescrItem(describe_pis ? PIS_HEAD : PIM_HEAD); + hea->_f0 = skip_acq; // così non compare nemmeno la colonnina! contento? + hea->_f1 = true; + _descr_arr.insert(hea, i++); + tot = new _DescrItem(TOT_ROW); + totpos = _descr_arr.insert(tot, i); + } + else + totpos++; + d = new _DescrItem(PIM_PIS); + d->_f0 = isfirst; + d->_s0 = ref; + d->_s1 = codiva; + _descr_arr.insert(d, i); + } + + if (tipomov == acquisto) + { + // Ci sono anche le fatture in ritardo (solo in annuale)! Con tipo detraibilita' 1,3,9 + if (sosp_imp != vol_affari) + { + d->_r4 += is_rit ? rit_imp : tab->get_real("R0"); + d->_r5 += is_rit ? rit_iva : tab->get_real("R1"); + t4 += is_rit ? rit_imp : tab->get_real("R0"); + t5 += is_rit ? rit_iva : tab->get_real("R1"); + } + // Totalizza anche quelli valevoli per vol. affari. + if (sosp_imp != liquidazione) + { + rt4 += is_rit ? rit_imp : tab->get_real("R0"); + rt5 += is_rit ? rit_iva : tab->get_real("R1"); + } + } + else // vendita + { + const bool is_key = corr_ann.is_key(codiva); + cx._totale = 0; + _CorrItem& ca = is_key ? (_CorrItem&) corr_ann[codiva] : cx; + if (sosp_imp != vol_affari) + ca._totale += tab->get_real(tipoiva == "VE" ? "R2" : "R3"); // Se e' codice IVA da Vent. stiamo scorrendo i PIS: va stampato il lordo dei progressivi successivi + if (sosp_imp != liquidazione) + ca._totale_vf += tab->get_real(tipoiva == "VE" ? "R2" : "R3"); + if (!is_key) // se non c'e' lo aggiunge + { + ca._aliquota = _iva->get_real("R0")/CENTO; // Se e' nuovo setta l'aliquota + corr_ann.add(codiva,ca); + } + // vedi corrispettivi veri e falsi + real cvi = tab->get_real("R0"); // imp. totale + real cvv = tab->get_real("R1"); // iva totale + real cfi = tab->get_real("R13"); // imp. falsi corrispettivi + real cfv = tab->get_real("R14"); // iva falsi corrispettivi + // MI3404... + // Giochiamo sopra la particolarita' che se non e' un registro di corrispettivi + // allora se R5 o R6 sono <> 0 significa che trattasi di documento FS, + // che pertanto va stornato dal totale corrispettivi. (Cosi' volle Vladimiro) + const real ifs(tab->get_real("R5")); // imp. fatture con scontrino + const real vfs(tab->get_real("R6")); // iva fatture con scontrino + if (!corrisp) + { + if (sosp_imp != vol_affari) + { + d->_r2 -= ifs; // tolgo FS dai corrispettivi + d->_r3 -= vfs; + t2 -= ifs; // idem per i totali + t3 -= vfs; + } + if (sosp_imp != liquidazione) + { + rt2 -= ifs; + rt3 -= vfs; + } + } + + if (corrisp) + { + cvi -= cfi; + cvv -= cfv; + } + + if (corrisp) + { + // usa R0 e R1 visto che la ventilazione e' gia' + // stata calcolata + if (sosp_imp != vol_affari) + { + d->_r2 += (cvi /* - ifs */); // tolgo FS dai corrispettivi + d->_r3 += (cvv /* - vfs */); + d->_r0 += ifs; // aggiungo FS alle vendite + d->_r1 += vfs; + t2 += (cvi /* - ifs */); // idem per i totali + t3 += (cvv /* - vfs */); // non sono molto convinto ma vogliono cio' + t0 += ifs; // ...avevo ragione e infatti l'ho cambiato + t1 += vfs; + } + if (sosp_imp != liquidazione) + { + rt2 += cvi; + rt3 += cvv; + rt0 += ifs; + rt1 += vfs; + } + } + + if (!corrisp || (!cfv.is_zero() || !cfi.is_zero())) + { + real adf, adi; // autofatture non residenti art. 17 + real va7i, va7v; // ammontare art 40 c. 5/6/8 + + real vendi = corrisp ? cfi : tab->get_real("R0"); + real vendv = corrisp ? cfv : tab->get_real("R1"); + + // si scorporano solo per l'annuale, altrimenti + // vengono normalmente considerati nelle vendite + if (month == 13) + { + TToken_string kr(tab->get("S0"),'!'); + va7i = kr.get(0); + va7v = kr.get(1); + adf = tab->get_real("R7"); + adi = tab->get_real("R8"); + } + + if (sosp_imp != vol_affari) + { + d->_r0 += vendi - adf - va7i; + d->_r1 += vendv - adi - va7v; + t0 += vendi /* - adf */; + t1 += vendv /* - adi */; + } + if (sosp_imp != liquidazione) + { + rt0 += vendi; + rt1 += vendv; + } + + autodafe += adf; + art40 += va7i; + art40_iva += va7v; + } + } +// if (tipomov == vendita) // ci sono anche gli acquisti per cassa! + { + /* Non voglio piu' il riepilogo delle fatture emesse IVA diff + if (!diffimp.is_zero() || !diffiva.is_zero() || + !diffimp_acq.is_zero() || !diffiva_acq.is_zero()) + { + const word id = describe_pis ? PIS_ROW_D : PIM_ROW_D; + int j; + + d = NULL; + for (j = totpos + 1; j < _descr_arr.items(); j++) + { + _DescrItem * wd = (_DescrItem*)&_descr_arr[j]; + const bool found = wd->_flags == id && wd->_s0 == ref; + + if (found && wd->_s1 == codiva) + { + d = wd; + break; + } + if (wd->_flags == TOT_ROW_D) + break; + if (found && wd->_s1 > codiva) + break; + } + if (d == NULL) + { + const bool isfirst = head == NULL; + + if (isfirst) + { + head = new _DescrItem(describe_pis ? PIS_HEAD_D : PIM_HEAD_D); + _descr_arr.insert(head, j++); + head->_f0 = false; + head->_f1 = true; + head->_f2 = atoi(activity.right(1)); // Tipo attività = 1 (servizi) o 2 (mista) + head->_f3 = tipomov; + totd = new _DescrItem(TOT_ROW_D); + _descr_arr.insert(totd, j); + } + d = new _DescrItem(id); + _descr_arr.insert(d, j); + d->_f0 = isfirst; + d->_s0 = ref; + d->_s1 = codiva; + } + d->_r26 += diffimp; + d->_r27 += diffiva; + t26 += diffimp; + t27 += diffiva; + d->_r30 += diffimp_acq; + d->_r31 += diffiva_acq; + t30 += diffimp_acq; + t31 += diffiva_acq; + } + */ + if (!diffincimp.is_zero() || !diffinciva.is_zero() || + !diffincimp_acq.is_zero() || !diffinciva_acq.is_zero()) + { + const word id = describe_pis ? PIS_ROW_DI : PIM_ROW_DI; + d = NULL; + int j; + for (j = totpos + 1; j < _descr_arr.items(); j++) + { + _DescrItem& wd = (_DescrItem&)_descr_arr[j]; + const bool found = wd._flags == id && wd._s0 == ref; + + if (found && wd._s1 == codiva) + { + d = &wd; + break; + } + if (wd._flags == TOT_ROW_DI) + break; + if (found && wd._s1 > codiva) + break; + } + if (d == NULL) + { + const bool isfirst = headi == NULL; + if (isfirst) + { + headi = new _DescrItem(describe_pis ? PIS_HEAD_DI : PIM_HEAD_DI); + _descr_arr.insert(headi, j++); + headi->_f0 = false; + headi->_f1 = true; + headi->_f2 = atoi(activity.right(1)); // Tipo attività = 1 (servizi) o 2 (mista) + headi->_f3 = tipomov; + totdi = new _DescrItem(TOT_ROW_DI); + _descr_arr.insert(totdi, j); + } + d = new _DescrItem(id); + _descr_arr.insert(d, j); + d->_f0 = isfirst; + d->_s0 = ref; + d->_s1 = codiva; + } + d->_r28 += diffincimp; + d->_r29 += diffinciva; + t28 += diffincimp; + t29 += diffinciva; + d->_r32 += diffincimp_acq; + d->_r33 += diffinciva_acq; + t32 += diffincimp_acq; + t33 += diffinciva_acq; + } + } + } + } // End of _pim cycle + + real impc,ivac; // Aggiunge lo scorporo dei corrispettivi + const int ditems = _descr_arr.items(); + for (int i=last+1;iget_real("R13"); + if (!describe_pis && iva74t > ZERO) + { + if(iads == NULL) iads = new _DescrItem(PIM_ROW); + iads->_s0 = "74TER"; // cosi' vollero + iads->_s1 = "IVA "; // cosi' vollero + iads->_s2 = " dovuta - 74 ter"; // cosi' vollero + iads->_r1 += iva74t; + t1 += iva74t; + rt1 += iva74t; + iads->_f0 = false; + } + } // fine while (codatt) + + if (!describe_pis && (art40 > ZERO || art40_iva > ZERO)) + { + _DescrItem* ads = new _DescrItem(PIM_ROW); + ads->_s0 = ref; + ads->_s1 = "VA7"; + ads->_r0 = art40; + ads->_r1 = art40_iva; + ads->_f0 = false; + _descr_arr.insert(ads, totpos++); + } + + if (!describe_pis && (autodafe > ZERO || autodafe_iva > ZERO)) + { + _DescrItem* ads = new _DescrItem(PIM_ROW); + ads->_s0 = ref; + ads->_s1 = "AF"; // così vollero, inoltre non è più A35 ma AF, come sul dio sistema + ads->_r0 = autodafe; + ads->_r1 = autodafe_iva; + ads->_f0 = false; + _descr_arr.insert(ads, totpos++); + } + + // ag. viaggio: iva dovuta 74 ter la vogliono in mezzo ai progressivi + if (iads != NULL) + _descr_arr.insert(iads, totpos++); + + + // prepara una bella riga di totali + if (tot != NULL) + { + tot->_r0 = t0; tot->_r1 = t1; + tot->_r2 = t2; tot->_r3 = t3; + tot->_r4 = t4; tot->_r5 = t5; + } + if (totd != NULL) + { + totd->_r26 = t26; + totd->_r27 = t27; + totd->_r30 = t30; + totd->_r31 = t31; + } + if (totdi != NULL) + { + totdi->_r28 = t28; + totdi->_r29 = t29; + totdi->_r32 = t32; + totdi->_r33 = t33; + totdi->_diff_ven_ap = _diff_ven_ap; + totdi->_diff_ven_ap_iva = _diff_ven_ap_iva; + totdi->_diff_acq_ap = _diff_acq_ap; + totdi->_diff_acq_ap_iva = _diff_acq_ap_iva; + } + // Totali progressivi da registri, comprensivi dei valori per calcolo vol affari. + if (tot != NULL && issosp) // Setta i valori (e la conseguente stampa della riga) solo se presenti registri in sospensione + { + tot->_r11 = rt0; tot->_r12 = rt1; + tot->_r13 = rt2; tot->_r14 = rt3; + tot->_s2 = rt4.string(); tot->_s3 = rt5.string(); + } + + // aggiunge dati ptm + _DescrItem* t = new _DescrItem(MISC_LIQ); + t->_f2 = describe_pis; //isfirst; // per il form feed o meno alla fine + + if (!describe_pis) + { + TToken_string ttm("0|0|0"); + + const bool annual = month == 13; + const int limit = annual ? 13 : month; + int m = annual ? month : 1; + for (; m <= limit; m++) + { + if (!is_month_ok(m,month)) + continue; + + FOR_EACH_TOKEN (atts, tmpatt) + { + const TString8 att(tmpatt); + look_plm(m, att); + real ad1, ad2; + + if (tot == NULL) + { + tot = new _DescrItem(TOT_ROW); + _descr_arr.insert(tot, -1); + } + + tot->_r6 += _pom->get_real("R0"); // acq. intracomunitari + tot->_r7 += _pom->get_real("R1"); // inded. art 19 + tot->_r8 += _pom->get_real("R2"); // IVA su inded. art. 19 + t->_r0 += _pom->get_real("R3"); // acq. ammortizz. detr + t->_r1 += _pom->get_real("R4"); // IVA acq. ammort. detr + t->_r2 += _pum->get_real("R2"); // ammort. detr. 6% + t->_r3 += _pum->get_real("R3"); // IVA ammort detr. 6% + t->_r4 += _pom->get_real("R5"); // acq. beni rivendita + t->_r5 += _pom->get_real("R6"); // IVA acq. beni rivendita + t->_r6 += _pom->get_real("R7"); // acq. leasing + t->_r7 += _pom->get_real("R8"); // IVA acq. leasing + t->_r8 += _pum->get_real("R0"); // cessioni beni ammort. + t->_r9 += _pum->get_real("R1"); // IVA su cessioni ammort. + t->_r10 += _pum->get_real("R4"); // tot. esenti IVA + if (!annual) // Se non siamo in annuale prende il prorata su doc. acq. anno precedente + { + t->_r12 += _plm->get_real("R14"); + t->_r13 = _plm->get_real("R4"); // percentuale prorata anno precedente + t->_r14 += _plm->get_real("R15"); + t->_r15 = _plm->get_real("R16"); // percentuale prorata 2 anni addietro + } + + // pro-rata indetraibile sui doc. acq. anno attuale + // in caso di liq. annuale prende il totale (tutto R2) + t->_r11 += _plm->get_real("R2"); + t->_r11 -= _plm->get_real("R14") + _plm->get_real("R15"); + + ad1 = real(ttm.get(1)); + ad2 = real(ttm.get(2)); + ad1 += _pom->get_real("R11"); + ad2 += _pom->get_real("R12"); + ttm.add(_plm->get("R12"), 0); // % pro-rata anno corrente + ttm.add(ad1.string(),1); // imp. acq. amm. indetr. + ttm.add(ad2.string(),2); // IVA acq. amm. indetr + t->_s0 = ttm; + + t->_f0 = _prorata.percentuale(_year)!=INVALID_PRORATA && (month != 13); // flag per segnalare l'esistenza + tot->_r9 += _pom->get_real("R9"); // acq. inded. su ricavi esenti + tot->_r10 += _pom->get_real("R10"); // IVA acq. inded. su ricavi esenti + + // passaggi interni + real aipip(tot->_s0); // progressivo ... + real aipivp(tot->_s1); // ... (che mazzata sulle palle...) + aipip += _pum->get_real("R8"); // acq. inded. per pass. int + aipivp += _pum->get_real("R9"); // IVA acq. inded. per pass. int + tot->_s0 = aipip.string(); // risbatto ... + tot->_s1 = aipivp.string(); // .. + + // spese generali. + real spgnp(t->_s2); // progressivo ... + real spgnvp(t->_s3); // ... (che doppia mazzata sulle palle...) + spgnp += _pam->get_real("R10"); // spese generali. + spgnvp += _pam->get_real("R11"); // IVA spese generali. + t->_s2 = spgnp.string(); // risbatto ... + t->_s3 = spgnvp.string(); // .. + + // sospensione imposta: non piu' due palle, ma QUATTRO... + // caro Ferdinando... ora son divenute ben OTTO... + // grazie all'iva ad esigibilità differita da pagare/de"TRARRE" + TToken_string tt(t->_s4); + real aqsi(tt.get(0)); + real aqsv(tt.get(1)); + real vnsi(tt.get(2)); + real vnsv(tt.get(3)); + real aqli(tt.get(4)); + real aqlv(tt.get(5)); + real vnli(tt.get(6)); + real vnlv(tt.get(7)); + + aqsi += _pam->get_real("R6"); + aqsv += _pam->get_real("R7"); + vnsi += _pam->get_real("R8"); + vnsv += _pam->get_real("R9"); + aqli += _pam->get_real("R12"); + aqlv += _pam->get_real("R13"); + vnli += _pam->get_real("R14"); + vnlv += _pam->get_real("R15"); + + tt = ""; + tt.add(aqsi.string()); + tt.add(aqsv.string()); + tt.add(vnsi.string()); + tt.add(vnsv.string()); + tt.add(aqli.string()); + tt.add(aqlv.string()); + tt.add(vnli.string()); + tt.add(vnlv.string()); + t->_s4 = tt; + + } // while (attivita') + } // for (mese ok) + + // Cazzata orrenda ma necessaria CM500308 + if (tot != NULL && issosp) + { + rt4 += tot->_r7; rt5 += tot->_r8; // Det 1 + rt4 += tot->_r9; rt5 += tot->_r10; // Det 3 + rt4 += real(tot->_s0); rt5 += real(tot->_s1); // Det 9 + tot->_s2 = rt4.string(); tot->_s3 = rt5.string(); + } + + // annual follows in _arr + if (month == 13 && ref != "ALL") + { + // tutte quelle cose che vanno alla liquidazione annuale, come il + // calcolo del prorata o del nuovo plafond o .... + if (look_pla(codatt)) + { + real v1 = _pla->get_real("R14"); // Totale imponibile vendite + real v2 = _pla->get_real("S1"); // Volume d'affari II attività + real ris = v1 + v2; + real e1 = _pla->get_real("R1"); // Totale vendite esenti C1 + real e2 = _pla->get_real("R2"); // Totale vendite esenti C2 + real e3 = _pla->get_real("R3"); // Totale vendite esenti C3 + real e4 = _pla->get_real("R15"); // Totale vendite esenti C1A + real e5 = _pla->get_real("R16"); // Totale vendite beni ammortizzabili esenti C3 + real e6 = _pla->get_real("R17"); // Totale vendite beni ammortizzabili esenti C1A + real bam = _pla->get_real("R4"); // Cessione beni ammortizzabili + real vrc = _pla->get_real("R18"); // Vendite reverse charge + real iaq = _pla->get_real("R11"); // IVA acquisti + real ppg = _pla->get_real("R12"); // pro-rata pagato + + // calcola nuovo prorata per ogni attivita' (miste: 1+2) + real pr; + const real rsa = ris - (e3-e5) - (e4-e6) - vrc; + if (!rsa.is_zero()) + { + const real rsn = rsa - e1; + pr = CENTO - (rsn * CENTO / rsa); // Percentuale di indetraibilita: reciproco della percentuale di detraibilita' + pr.round(0); + } + + real co = 0.0; + real topay = 0.0; + //if (pr != _prorata.current()) + { + // calcolo conguaglio -- se positivo e' a debito + if (pr > ZERO) + { + topay = (iaq + ppg) * pr / CENTO; + round_imposta(topay); + } + co = topay - ppg; + round_imposta(co); + } + + _DescrItem* dd = new _DescrItem(ANNUAL); + + // MonsterFish: arrotonda all'Euro C1,C2,C3,C1A + round_imposta(e1); + round_imposta(e2); + round_imposta(e3); + round_imposta(e4); + round_imposta(e5); + round_imposta(e6); + round_imposta(bam); + round_imposta(ris); + round_imposta(vrc); + + // segna flag prorata + if ((e1+e2+e3+e4) > ZERO) + { + dd->_f0 |= IS_PRORATA; + } + dd->_r0 = ris; + dd->_r1 = e1; + dd->_r2 = pr > ZERO ? pr : ZERO; + dd->_r3 = co; + dd->_r4 = e2; + dd->_r5 = e3; + dd->_r6 = topay; + dd->_r7 = e4; + dd->_r8 = e5; + dd->_r9 = e6; + dd->_r10 = vrc; + t->_arr.add(dd); + } + } + } + _descr_arr.add(t); +} + +void TLiquidazione_app::describe_liq(int month, const char* codatts, _DescrItem* di) +{ + if (!_isprint || !_canprint) + return; + + const TRectype & lim = get_lim(month); + + if (lim.not_empty()) + { + _DescrItem* d = new _DescrItem(THE_END); + + // gli diamo la stessa struttura di LIM + d->_r0 = lim.get_real("R0"); // Risultato + d->_r1 = lim.get_real("R1"); // Rimborso + d->_r2 = lim.get_real("R2"); + d->_r3 = lim.get_real("R3"); + d->_r4 = lim.get_real("R4"); + d->_r5 = lim.get_real("R5"); // rettifiche + d->_r6 = lim.get_real("R6"); + d->_r7 = lim.get_real("R14"); + d->_r9 = lim.get_real("R9"); + d->_r29 = lim.get_real("R29"); // fdiffinc_iva_ven + d->_r33 = lim.get_real("R33"); // fdiffinc_iva_acq + + look_lam(month); + + TToken_string tt(80); + + tt.add(_lam->get("R0")); // IVA Vendite + tt.add(_lam->get("R1")); // IVA Acquisti + tt.add(_lam->get("R2")); // Credito precedente + tt.add(_lam->get("R3")); // Debito precedente + tt.add(_lam->get("R4")); + + d->_s0 = tt; + d->_s1 = lim.get("R11"); // Acc. dec. + d->_s2 = lim.get("R12"); + d->_s3 = lim.get("R13"); + + // descrizione rettifiche + if (month < 13) + { + d->_s4 = lim.get("S0"); + 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 + d->_r16 = lim.get_real("R16"); // Credito utilizzato F24 + d->_r17 = lim.get_real("R17"); // Variazioni d'imposta + d->_r18 = lim.get_real("R18"); // Imposta non versata + d->_r19 = lim.get_real("R19"); // Crediti speciali + d->_r20 = lim.get_real("R20"); // Credito autorizzato in F24 + + d->_d1 = lim.get_date("D1"); // Data autorizzazione + + d->_f1 = is_first_month(month); + + // rispettiamo tutte le casistiche per i versamenti se non siamo in visualizzazione + // analogamente in Visualizzazione ma solo nel caso dell'annuale. + // In tutti gli altri casi va a cercare la delega + d->_r8 = (_month == 13 || !_is_visliq) ? lim.get_real("R8") : versamenti_IVA(_month, "1"); + + if (_month == 13) + { + const int anno = atoi(_year); + const TRectype & lia = get_lia(0L, false, anno); + // Credito utilizzato inizio anno (aggiunto 29-07-2014) + if (lia.not_empty()) + d->_r15 = lia.get_real("R15"); + + const TRectype & liasucc = get_lia(0L, false, anno + 1); + + if (liasucc.not_empty()) + d->_r20 = liasucc.get_real("R0"); // Credito da riportare all'anno prossimo + } + + // aggiunge eventuale satellite per rimborso infraannuale + if (di != NULL) + { + if (d->_r0.sign() < 0) + d->_arr.add(di); + else + delete di; + } + + if (!_is_visliq) + { + _DescrItem* dv = describe_deleghe(month); + if (dv != NULL) d->_arr.add(dv); + } + + _descr_arr.add(d); + } +} + +_DescrItem* TLiquidazione_app::describe_deleghe(int month) +{ + _stampa_vers = _stampa_acc = false; + + const TRectype & lim = get_lim(month); + + if (lim.get_real("R0") > ZERO) + { + real iva = lim.get_real("R0") + lim.get_real("R14"); + if (month == 13) + round_imposta(iva); + if (iva >= iva_da_riportare(_month)) + _stampa_vers = true; + } + + _stampa_acc = (month == 12 && (_freqviva == "M" || (_isbenzinaro && _gest4))) + ||(month == 13 && _freqviva == "T" && !(_isbenzinaro && _gest4)); + + if (!_stampa_vers && !(_stampa_acc && look_del(12,7))) return NULL; + + _DescrItem* d = new _DescrItem(DELEGA); + + d->_f0 = 0; + + //prospettino versamento + if (_stampa_vers) //solo se sono a debito + if (look_del(month,month == 13 ? 2 : 1)) + { + if (_del->get_bool("B0")) // Stampata? + { + //_del->S2 descr. ufficio iva/concessione + //_del->S1 descrizione banca + d->_s0 = _del->get("S9"); // Cod Ufficio concessione + d->_s1 = _del->get("S7"); // Cod ABI + d->_s2 = _del->get("S8"); // Cod CAB + d->_r0 = _del->get_real("R0"); + d->_d0 = _del->get_date("D0"); + } // altrimenti lascia tutto in bianco e ci scriveranno i dati a mano + } + + //prospettino acconto + if ( (month == 12 && (_freqviva == "M" || (_isbenzinaro && _gest4))) + || (month == 13 && _freqviva == "T" && !(_isbenzinaro && _gest4)) ) + if (look_del(12,7)) //sia che sia a debito che a credito + { + d->_s4 = "ACC"; + TToken_string t; + if (_del->get_bool("B0")) // Stampata? + { + //_del->S2 descr. ufficio iva/concessione + //_del->S1 descrizione banca + t.add(_del->get("S9")); // Cod Conc + t.add(_del->get("S7")); // Cod ABI + t.add(_del->get("S8")); // Cod CAB + t.add(_del->get_real("R0").string()); + t.add(_del->get("D0")); + } + d->_s5 = t; + } + + return d; +} + +void TLiquidazione_app::describe_consistence(const char* codatt) +{ + // controlla eventuali condizioni di conflitto con le normative + // per la ditta e crea i messaggi appropriati + // tutte le condizioni sono valutate sull'esercizio precedente + int pryear = atoi(_year) - 1; + TString att = codatt; + + _pla->zero(); + *_pla_ditta = get_firm(); + *_pla_anno = pryear; + *_pla_codatt = att; + + if (_pla->read() == NOERR) + { + real va = _pla->get_real("R0"); + + // 1) consistenza volume d'affari <-> frequenza versamenti + // deve essere: trimestrale ammesso solo se < 360.000.000 + // per servizi, < 1.000.000.000 per altre imprese + // a meno che non sia benzinaro che ha diritto comunque + + if (_freqviva == "T" && !_isbenzinaro) + { + bool err = false; + if (_isservizio) err = va > SOGLIA_TRIM_SERVIZI; + else err = va > SOGLIA_TRIM_ALTRE; + if (err) + describe_error(TR("Incoerenza volume affari/frequenza versamenti"), + att); + } + } +} + +void TLiquidazione_app::describe_error(const char* err, const char* codatt) +{ + if (!_isprint || !_canprint || (_isregis && _isfinal)) + return; + _errors.add(new _ErrItem(err, codatt, _nditte->curr().get(NDT_CODDITTA))); +} + +// ---------------------------------------------------------------- +// Setrows +// ---------------------------------------------------------------- + +void TLiquidazione_app::set_firm(_DescrItem& d) +{ + TString tim_title(80); + tim_title << TR("Liquidazione IVA"); + + if (d._f1 == 13) + tim_title << format(FR(": Riepilogo Annuale %s"), (const char*)_year); + else + { + if (d._s2 == "T") + tim_title << format(FR(" del %d° Trimestre %s"), d._f1/3, (const char*) _year); + else + tim_title << format(FR(" del mese di %s %s"), itom(d._f1), (const char*)_year); + } + + reset_header(); + int soh = 1; + if (!_isregis) + { + set_header(soh++,FR("Ditta %s %s@107gData @>@125gPag. @#"), + (const char*)d._s0, (const char*)d._s1); + set_header(soh++,""); + } + set_header(soh++,sep); + set_header(soh++,FR("%s@102gFrequenza %s"), + (const char*)tim_title, d._s2 == "T" ? TR("Trimestrale") : TR("Mensile")); + set_header(soh++,sep); + set_header(soh++,""); + + // notify errors if any + int j = 0; + int i = 0; + for (i = 0; i < _errors.items(); i++) + { + _ErrItem& s = (_ErrItem&)_errors[i]; + if (s._att == "ALL" && s._firm == d._s0) + { j++; set_row(i+3, "@5g@b*** %s ***@r", (const char*)s._err); } + } + if (j) set_row(i+3,""); +} + +static int _tipo_attivita_corrente = 0; + +void TLiquidazione_app::set_att(_DescrItem& d) +{ + // set header + TString tim_title(78); + TString att_title(48); + + // Bookmark + TString book_name(d._s3); + const char flags = (char)d._f3; + + if (flags == '1') book_name << TR(" (servizi)"); + else if (flags == '2') book_name << TR(" (altre)"); + else if (flags == 'M') book_name = TR("Riepilogo att. mista"); + else if (flags == 'Q') book_name = TR("Riepilogo quater"); + + if (_firm_bookmark == -1) + _firm_bookmark = set_bookmark(d._s1); + _att_bookmark = set_bookmark(book_name, _firm_bookmark); + + tim_title << TR("Liquidazione IVA"); + + if (d._f1 == 13) + { + tim_title << format(FR(": Riepilogo Annuale %s"),(const char*)_year); + } + else + { + if (d._s4 == "T") + tim_title << format(FR(" del %d° Trimestre %s"), d._f1/3, (const char*)_year); + else + tim_title << format(FR(" del mese di %s %s"), itom(d._f1), (const char*)_year); + } + + const char* tipatt = ""; + if (d._f0 > 0) + tipatt = d._f0 == 1 ? TR("SERVIZI") : TR("ALTRE ATTIVITA'"); + + if (d._s3.empty()) + { + att_title = flags == 'M' ? TR("Riepilogo attività mista") : TR("Riepilogo quater"); + // att_title << d._s2; + } + else + att_title = format(FR("Attività %s %s %s"), (const char*)(d._s2), (const char*)(d._s3), tipatt); + + reset_header(); + int soh = 1; + if (!_isregis) + { + set_header(soh++,FR("Ditta %s %s@107gData @>@125gPag. @#"), + (const char*)(d._s0), (const char*)(d._s1)); + set_header(soh++,""); + } + set_header(soh++,sep); + set_header(soh++,"%s@55g%s", (const char*)tim_title, (const char*)att_title); + set_header(soh++,sep); + set_header(soh++,""); + + // notify errors if any + int j = 0; + for (int i = 0; i < _errors.items(); i++) + { + _ErrItem& s = (_ErrItem&)_errors[i]; + if (d._s2 == s._att && s._firm == d._s0) + { j++; set_row(i+10, "@5g@b*** %s ***@r", (const char*)s._err); } + } + if (j) + set_auto_ff(true); +} + +void TLiquidazione_app::set_plafond(_DescrItem& d) +{ + // In caso di stampa liquidazione da stampa registri, il prospetto plafond + // complessivo va evidenziato in testa; solo nel caso di trimestrali. + + if (_isregis && _freqviva == "M") return; + + set_bookmark(TR("Quadro plafond"), _att_bookmark); + + real r1 = d._r1 + d._r0; + real r2 = d._r4 + d._r3; + real r3 = d._r7 + d._r6; + + real disponibile = d._r2 + d._r5 + d._r8; + real riporto = disponibile - r1 - r2 -r3; + + set_print_zero(true); + + set_row(1,TR("QUADRO RELATIVO ALLA DISPONIBILITA' ED ALL'UTILIZZO MENSILE DEI PLAFONDS")); + + set_row(2,""); + set_row(3,FR("@31gDisponibile@48g%r"), &(disponibile)); + set_row(4,TR("Art. 8 1° comma lettere a-b")); + set_row(5,FR("Utilizzato all'interno@48g%r"), &(d._r0)); + set_row(6,FR("Utilizzato per l'importazione@48g%r"),&(d._r1)); + + set_row(7,""); + set_row(8,TR("Art. 8bis 1° comma")); + set_row(9,FR("Utilizzato all'interno@48g%r"), &(d._r3)); + set_row(10,FR("Utilizzato per l'importazione@48g%r"), &(d._r4)); + + set_row(11,""); + set_row(12,TR("Art. 9 1° comma")); + set_row(13,FR("Utilizzato all'interno@48g%r"), &(d._r6)); + set_row(14,FR("Utilizzato per l'importazione@48g%r"), &(d._r7) ); + set_row(15,FR("@31gRiporto@48g%r"), &(riporto)); + + set_print_zero(false); + set_auto_ff(); +} + +/* Obsoleto + +void TLiquidazione_app::set_liqacc_1999(_DescrItem& d) +{ + real r1 = d._r0 + d._r1 + d._r2 + d._r4; + //real r2 = d._r5 + d._r10; + real r2 = d._r5; //MI2258 (A me sembra una cagata, ma con certa gente non si riesce a parlare) + real r3 = r2 + d._r9 + d._r7; + if ((d._r3).sign() > 0) r1 += d._r3; + else r3 += abs(d._r3); + + set_row(1,""); set_row(2,""); set_row(3,""); set_row(4,""); + set_row(5,FR("@11gCALCOLO ACCONTO SU OPERAZIONI EFFETTUATE")); + + set_row(6,""); + set_row(7,FR("@72gCredito@90gDebito")); set_row(8,""); + if (!_isdiffacc) + set_row(9,FR("@11gIva sulle operazioni annotate fino al 20 Dicembre@81g%r"), &(d._r0)); + else + set_row(9,FR("@11gIva sulle operazioni di vendita@81g%r"), &(d._r0)); + int i = 10; + if (!_isdiffacc) + { + set_row(i++,FR("@11gIva su operazioni fino al 20 Dic., ma non fatturate@81g%r"), &(d._r1)); + set_row(i++,FR("@11gIva su operazioni fino al 20 Dic., ma non annotate@81g%r"), &(d._r2)); + } + set_row(i,FR("@11gRettifiche iva a debito")); + if (d._r3.sign() > 0) + set_row(i,"@81g%r", &(d._r3)); + i++; + set_row(i++,FR("@11gIva chiesta a rimborso@81g%r"), &(d._r4)); + set_row(i++,FR("@11gRISULTATO@81g%r"), &r1); + + if (!_isdiffacc) + set_row(i++,FR("@11gIva sugli acquisti annotati fino al 20 Dicembre@64g%r"), &r2); + else + set_row(i++,FR("@11gIva sulle operazioni di acquisto@64g%r"), &r2); + if (d._r6 != ZERO) + set_row(i++,FR("@11gmeno perc. di prorata pari a lire %r"), &(d._r6)); + set_row(i++, FR("@11gCredito precedente@64g%r"), &(d._r9)); + set_row(i, FR("@11gRettifiche iva a credito")); + if ((d._r3).sign() <= 0) + { + real ab = abs(d._r3); + set_row(i,"@64g%r", &ab); + } + i++; + set_row(i++,FR("@11gRISULTATO@64g%r"), &r3); + if ((d._r8).sign() < 0) + { + real ab = abs(d._r8); + set_row(i++,FR("@23gCREDITO DA EVIDENZIARE@64g%r"), &ab); + } + else if ((d._r8).sign() > 0 && d._r8 > _ver->get(I_ACCONTOIVA)) + set_row(i++,FR("@23gACCONTO DA VERSARE@81g%r"), &(d._r8)); + else if ((d._r8).sign() > 0 && d._r8 <= _ver->get(I_ACCONTOIVA)) + set_row(i++,FR("@23gACCONTO DA NON VERSARE@64g%r"), &(d._r8)); + + set_auto_ff(); +} +*/ + +int TLiquidazione_app::calc_inc_diff(int tipoiva, real& imponibile_diff, real& imposta_diff, real& imponibile_xcas, real& imposta_xcas) const +{ + CHECKD(tipoiva == 1 || tipoiva == 2, "Bad tipo iva:", tipoiva); + int flag = 0; + + imponibile_diff = imposta_diff = imponibile_xcas = imposta_xcas = ZERO; + + TString limit; limit << "ANNOLIQ=" << _year; + if (_month < 13) limit << " MESELIQ=" << _month; + TString query; // righe pagamento (TIPOMOV>=3) ed escluse NC! + query << "USE IVADIFF KEY 2 SELECT (TIPOMOV>2)&&(TIPOIVA=" << tipoiva << ')' + << "\nFROM " << limit << "\nTO " << limit; + + TISAM_recordset id(query); + const TRectype& rec = id.cursor()->curr(); + for (bool ok = id.move_first(); ok; ok = id.move_next()) + { + const real iva = rec.get_real(RMI_IMPOSTA); + const real imp = rec.get_real(RMI_IMPONIBILE); + if (!iva.is_zero() || !imp.is_zero()) + { + const int tipodiff = rec.get_int("TIPODIFF"); + switch (tipodiff) + { + case 1: imponibile_diff += imp; imposta_diff += iva; break; + case 2: imponibile_xcas += imp; imposta_xcas += iva; break; + default: break; + } + flag |= tipodiff; + } + } + + return flag; +} + +int TLiquidazione_app::print_acc_diff_xcassa(const _DescrItem& d) +{ + int i = 9; + + const real& totiva = d._r0; + const real ivadiff_inc = d._r29; + const real ivadiff_pag = d._r33; + + real ivaxcas_inc, ivaxcas_pag; + + if (has_module(ICAUT)) + { + // Calcolare qui la quota per cassa e toglierla a quella differita gloable + } + + if (!_isdiffacc) + { + set_row(i++,FR("@11gIva esigibile fino al 20/12@81g%r"), &totiva); + + if (ivadiff_inc > ZERO) + set_row(i++,FR("@11gIVA a liquidazione differita incassata fino al 20/12@75g%r"), &ivadiff_inc); + if (ivadiff_pag > ZERO) + set_row(i++,FR("@11gIVA a liquidazione differita pagata fino al 20/12@64g%r"), &ivadiff_pag); + + if (ivaxcas_inc > ZERO) + set_row(i++,FR("@11gIVA per cassa incassata fino al 20/12@75g%r"), &ivaxcas_inc); + if (ivaxcas_pag > ZERO) + set_row(i++,FR("@11gIVA per cassa pagata fino al 20/12@64g%r"), &ivaxcas_pag); + } + else + { + set_row(i++,FR("@11gIva sulle operazioni di vendita@81g%r"), &totiva); + + if (ivadiff_inc > ZERO) + set_row(i++,FR("@11gIVA a liquidazione differita incassata@75g%r"), &ivadiff_inc); + if (ivadiff_pag > ZERO) + set_row(i++,FR("@11gIVA a liquidazione differita pagata@64g%r"), &ivadiff_pag); + + if (ivadiff_inc > ZERO) + set_row(i++,FR("@11gIVA per cassa incassata@75g%r"), &ivadiff_inc); + if (ivadiff_pag > ZERO) + set_row(i++,FR("@11gIVA per cassa pagata@64g%r"), &ivadiff_pag); + } + return i; +} + +void TLiquidazione_app::set_liqacc_2000(_DescrItem& d) +{ + set_row(1,""); set_row(2,""); set_row(3,""); set_row(4,""); + set_row(5,FR("@11gCALCOLO ACCONTO SU OPERAZIONI EFFETTUATE")); + if (!_isdiffacc) + set_row(5,TR(" FINO AL 20 DICEMBRE")); + + set_row(6,""); + set_row(7,FR("@72gCredito@90gDebito")); set_row(8,""); + + if (d._r3 > ZERO) + d._r0 += d._r3; // Aggiungi rettifiche a debito + + int i = print_acc_diff_xcassa(d); + + if (!_isdiffacc) + { + set_row(i++,FR("@11gIva esigibile fino al 20/12 di cui non fatturata@81g%r"), &d._r1); + set_row(i++,FR("@11gIva esigibile fino al 20/12 di cui non annotata@81g%r"), &d._r2); + } + if (d._r3 < ZERO) + d._r5 -= d._r3; // Aggiungi rettifiche a credito + if (!_isdiffacc) + set_row(i++,FR("@11gIva che si detrae fino al 20/12@64g%r"), &d._r5); + else + set_row(i++,FR("@11gIva sulle operazioni di acquisto@64g%r"), &d._r5); + + set_row(i,FR("@11gIVA a debito/credito per il periodo")); + real iva_dov_cre = d._r0 + d._r1 + d._r2 - d._r5; + if (iva_dov_cre >= ZERO) + set_row(i++,"@81g%r", &iva_dov_cre); + else + { + const real tmp = -iva_dov_cre; + set_row(i++,"@64g%r", &tmp); + } + + set_row(i++, FR("@11gDebito/Credito da periodo precedente@64g%r"), &d._r9); + + set_row(i,FR("@11gIVA Dovuta o a Credito")); + const real risultato = iva_dov_cre - d._r9; + if (risultato >= ZERO) + set_row(i++,"@81g%r", &risultato); + else + { + const real tmp = -risultato; + set_row(i++,"@64g%r", &tmp); + } + + // Acconto + if (d._r8 < ZERO) + { + const real ab = abs(d._r8); + set_row(i++,FR("@23gCREDITO DA EVIDENZIARE@64g%r"), &ab); + } + else if (d._r8 > ZERO) + { + const real acconto_minimo = _ver->get(I_ACCONTOIVA); + if (d._r8 > acconto_minimo) + set_row(i++,FR("@23gACCONTO DA VERSARE@81g%r"), &d._r8); + else + set_row(i++,FR("@23gACCONTO DA NON VERSARE@81g%r"), &d._r8); + } + + set_auto_ff(); +} + +/* + +bool TLiquidazione_app::print_dainc_diff_log(int& rw, int tipoatt, int tipoiva) +{ + TString limit; limit << "ANNOLIQ=" << _year; + if (_month < 13) limit << " MESELIQ=" << _month; + TString query; + query << "USE IVADIFF KEY 2 SELECT (TIPOMOV==1)"; + //if (_isregis && tipoiva > 0) query << "&&(TIPOIVA==" << tipoiva << ')'; + if (tipoatt > 0) + query << " &&(TIPOATT==" << tipoatt << ")"; + query << "\nBY TIPOIVA DATAREG"; + query << "\nJOIN MOV INTO NUMREG==NUMREG"; + query << "\nJOIN CLIFO TO MOV INTO TIPOCF==TIPO CODCF==CODCF"; + query << "\nFROM " << limit << "\nTO " << limit; + + int header = 0; + + TISAM_recordset id(query); + const int rfat = id.items(); + if (rfat > 0) + { + const TRectype& rec = id.cursor()->curr(); + bool header_printed = false; + for (bool ok = id.move_first(); ok; ok = id.move_next()) + { + real importo, imponibile, imposta; + const TDate nulldate; + residuo_da_liquidare(rec.get_long(RMI_NUMREG), rec.get_int(RMI_NUMRIG), nulldate, + importo, imponibile, imposta); + const int ti = rec.get_int("TIPOIVA"); + if (ti != header) + { + if (ti < 2) + set_row(rw++, TR("Fatture da incassare")); + else + set_row(rw++, TR("Fatture da pagare")); + set_row(rw++, "IVA@17gImporto@30gImponibile@49gImposta@57gC/D@74gProt.@80gN. Doc.@89gData reg.@100gCodice@107gRagione sociale"); + header = ti; + } + + const TString4 codiva = rec.get("CODIVA"); + const int protiva = id.get("MOV.PROTIVA").as_int(); + const TString8 numfat = id.get("MOV.NUMDOC").as_string(); + const TString16 datafat = rec.get("DATAREG"); + const char* tipolog = id.get("TIPODIFF").as_int() == 2 ? TR("C") : TR("D"); + + const long codcf = id.get("CLIFO.CODCF").as_int(); + TParagraph_string clifo(id.get("CLIFO.RAGSOC").as_string(), 25); + + set_row(rw++, "%s@9g%r@25g%r@41g%r@58g%s@74g%5d@80g%s@89g%s@100g%6ld@107g%s", + (const char*)codiva, &importo, &imponibile, &imposta, + tipolog, protiva, (const char*)numfat, (const char*)datafat, + codcf, clifo.get()); + const char* ragsoc2 = clifo.get(); + if (ragsoc2 != NULL && strlen(ragsoc2) > 3) + set_row(rw++, "@107g%s", ragsoc2); + } + } + + return rfat > 0; +} + +bool TLiquidazione_app::print_inc_diff_log(int& rw, int tipoatt, int tipoiva) +{ + TString limit; limit << "ANNOLIQ=" << _year; + if (_month < 13) limit << " MESELIQ=" << _month; + TString query; + query << "USE IVADIFF KEY 2 SELECT (TIPOMOV>2)"; + // if (_isregis && tipoiva > 0) query << "&&(TIPOIVA==" << tipoiva << ')'; + if (tipoatt > 0) + query << " &&(TIPOATT==" << tipoatt << ")"; + query << "\nBY TIPOIVA DATAREGP"; + query << "\nJOIN MOV INTO NUMREG==NUMREG"; + query << "\nJOIN CLIFO TO MOV INTO TIPOCF==TIPO CODCF==CODCF"; + query << "\nFROM " << limit << "\nTO " << limit; + + TISAM_recordset id(query); + const int rpag = id.items(); + if (rpag > 0) + { + const TRectype& rec = id.cursor()->curr(); + int header = 0; + for (bool ok = id.move_first(); ok; ok = id.move_next()) + { + const int ti = rec.get_int("TIPOIVA"); + if (ti != header) + { + if (ti < 2) + set_row(rw++, TR("Fatture incassate")); + else + set_row(rw++, TR("Fatture pagate")); + set_row(rw++, "IVA@17gImporto@30gImponibile@49gImposta@57gC/D@61gPagamento@74gProt.@80gN. Doc.@89gData reg.@100gCodice@107gRagione sociale"); + header = ti; + } + + const TString4 codiva = rec.get(RMI_CODIVA); + const real importo = rec.get("IMPORTO"); + const real imponibile = rec.get(RMI_IMPONIBILE); + const real imposta = rec.get(RMI_IMPOSTA); + const char* tipolog = id.get("TIPODIFF").as_int() == 2 ? TR("C") : TR("D"); + const TString16 datapag = rec.get("DATAREGP"); + const int protiva = id.get("MOV.PROTIVA").as_int(); + const TString16 numfat = id.get("MOV.NUMDOC").as_string(); + const TString16 datafat = rec.get("DATAREG"); + + const long codcf = id.get("CLIFO.CODCF").as_int(); + TParagraph_string clifo(id.get("CLIFO.RAGSOC").as_string(), 25); + + set_row(rw++, "%s@9g%r@25g%r@41g%r@58g%s@61g%s@74g%5d@80g%s@89g%s@100g%6ld@107g%s", + (const char*)codiva, &importo, &imponibile, &imposta, + tipolog, (const char*)datapag, protiva, (const char*)numfat, (const char*)datafat, + codcf, clifo.get()); + const char* ragsoc2 = clifo.get(); + if (ragsoc2 != NULL && strlen(ragsoc2) > 3) + set_row(rw++, "@107g%s", ragsoc2); + } + } + + return rpag > 0; +} +*/ + +void TLiquidazione_app::set_pim_head(_DescrItem& d) +{ + int r = 1; + + if (d._flags == PIM_HEAD) + set_bookmark(TR("Riepilogo progressivi"), _att_bookmark); + else + { + set_row(r++,""); + if (d._flags == PIM_HEAD_D) + { + TString msg; + msg = TR("Movimenti registrati nel periodo a liquidazione differita"); + const TDate data(1, _month <= 12 ? _month : 12 , atoi(_year)); + if (gestione_IVAxCassa(data)) + msg << TR(" o per cassa"); + set_row(r++, msg); + set_bookmark(TR("Riepilogo progressivi a liquidazione differita"), _att_bookmark); + // print_dainc_diff_log(r, d._f2, d._f3); // 15-03-2013 obosleto in quanto stampato su registri? + } + else + if (d._flags == PIM_HEAD_DI) + { + TString msg; + msg = TR("Incassi/pagamenti a liquidazione differita"); + + const TDate data(1, _month <= 12 ? _month : 12 , atoi(_year)); + if (gestione_IVAxCassa(data)) + msg << TR(" o per cassa"); + + set_row(r++, msg); + set_bookmark(TR("Riepilogo progressivi a liquidazione differita incassati"), _att_bookmark); +// print_inc_diff_log(r, d._f2, d._f3); + } + else // PIS_HEAD + { + if (d._flags == PIS_HEAD) + { + set_row(r++,TR(" Di cui da periodo successivo")); + set_row(r++,""); + set_bookmark(TR("Riepilogo progressivi successivi"), _att_bookmark); + } + else + if (d._flags == PIS_HEAD_D) + { + set_row(r++, TR("Fatture a liquidazione differita da incassare")); + set_bookmark(TR("Riepilogo progressivi successivi a liquidazione differita"), _att_bookmark); + } + else + if (d._flags == PIS_HEAD_DI) + { + set_row(r++, TR("Fatture a liquidazione differita incassate")); + set_bookmark(TR("Riepilogo progressivi successivi a liquidazione differita incassati"), _att_bookmark); + } + } + set_row(r++,""); + } + if (d._f0) + { + if (d._flags == PIM_HEAD || d._flags == PIS_HEAD) + { + set_row(r++,FR(" Cod.@41gVENDITE@71gCORRISPETTIVI")); + set_row(r++,FR(" IVA Descrizione@30gImponibile@49gImposta@63gImponibile@82gImposta")); + set_row(r,""); + } +/* else + { + set_row(r++,FR(" Cod.@41gVENDITE")); + set_row(r++,FR(" IVA Descrizione@30gImponibile@49gImposta")); + } */ + } + else + { + if (d._flags == PIM_HEAD || d._flags == PIS_HEAD) + { + set_row(r++,FR(" Cod.@41gVENDITE@71gCORRISPETTIVI@106gACQUISTI")); + set_row(r++,FR(" IVA Descrizione@30gImponibile@49gImposta@63gImponibile" + "@82gImposta@96gImponibile@115gImposta")); + set_row(r,""); + } +/* else + { + set_row(r++,FR(" Cod.@41gVENDITE")); + set_row(r++,FR(" IVA Descrizione@30gImponibile@49gImposta")); + } */ + } +} + +void TLiquidazione_app::set_pim(_DescrItem& d) +{ + // succede con le autocazzate non residenti non movimentate eccetera + const bool a = (d._r0 + d._r1) == ZERO; + const bool b = (d._r2 + d._r3) == ZERO; + const bool c = (d._r4 + d._r5) == ZERO; + const bool e = (d._r26 + d._r27) == ZERO; + const bool f = (d._r28 + d._r29) == ZERO; + const bool g = (d._r30 + d._r31) == ZERO; + const bool h = (d._r32 + d._r33) == ZERO; + + if (a && b && c && e && f && g && h) + return; + + int rw = 1; + if (d._s1 == "AF") //Il dio sistema colpisce ancora, non va bene A35, ma AF... + d._s2 = TR("Artt.17c3/74c1"); // La descrizione non la metto uguale perche' cosi e' piu' fika + else if (d._s1 == "VA7") // Sempre per merito del dio sistema ho dovuto aggiungere VA7. + d._s2 = TR("Art.40c5/6/8 a.i."); + else if (d._s0 == "74TER") + rw++; + else + { + look_iva(d._s1); + d._s2 = _iva->get("S0"); + if (d._s2.len() > 19) d._s2.cut(19); + } + + if (d._flags == PIM_ROW || d._flags == PIS_ROW) + { + set_row(rw++,"%-4s %s@25g%r@41g%r@58g%r@74g%r@91g%r@107g%r", + (const char*)d._s1, (const char*)d._s2, + &(d._r0), &(d._r1), &(d._r2), &(d._r3), &(d._r4), &(d._r5)); + } + else + if (d._flags == PIM_ROW_D || d._flags == PIS_ROW_D) + { + set_row(rw++,"%-4s %s@25g%r@41g%r@91g%r@107g%r", + (const char*)d._s1, (const char*)d._s2, + &(d._r26), &(d._r27), &(d._r30), &(d._r31)); + } + else + if (d._flags == PIM_ROW_DI || d._flags == PIS_ROW_DI) + { + set_row(rw++,"%-4s %s@25g%r@41g%r@91g%r@107g%r", + (const char*)d._s1, (const char*)d._s2, + &(d._r28), &(d._r29), &(d._r32), &(d._r33)); + } + + } + +void TLiquidazione_app::set_plm_diff(const _DescrItem& d) +{ + int rw = 1; + + set_row(rw++,""); set_row(rw++,""); + if (d._flags == TOT_ROW_D) + { + set_row(rw++,FR("Totale@25g%r@41g%r@91g%r@107g%r"), &(d._r26), &(d._r27), &(d._r30), &(d._r31)); + } + else + { + // Totale incassi/pagamenti ad IVA differita o per cassa + set_row(rw++,FR("Totale@25g%r@41g%r@91g%r@107g%r"), &(d._r28), &(d._r29), &(d._r32), &(d._r33)); + if (_isannual) + { + rw++; + set_row(rw++,FR("Totale anni prec. @25g%r@41g%r@91g%r@107g%r"), &(d._diff_ven_ap), &(d._diff_ven_ap_iva), &(d._diff_acq_ap), &(d._diff_acq_ap_iva)); + } + } + set_row(rw++,""); +} + +void TLiquidazione_app::set_plm(_DescrItem& d) +{ + int rw = 1; + if (!(d._r0.is_zero() && d._r1.is_zero() && d._r2.is_zero() && + d._r3.is_zero() && d._r4.is_zero() && d._r5.is_zero())) + { + set_row(rw++,""); set_row(rw++,""); + set_row(rw++,FR("Totale@25g%r@41g%r@58g%r@74g%r@91g%r@107g%r"), + &(d._r0), &(d._r1), &(d._r2), &(d._r3), &(d._r4), &(d._r5)); + set_row(rw++,""); + } + if (!(d._r7.is_zero() && d._r8.is_zero())) + { + set_row(rw++,FR("Totale acquisti indeducibili per art.19@91g%r@107g%r"), + &(d._r7), &(d._r8)); + } + if (! (d._r9.is_zero() && d._r10.is_zero())) + { + set_row(rw++, FR("Totale acquisti indeducibili su ricavi esenti@91g%r@107g%r"), + &(d._r9), &(d._r10)); + } + + real acq_pint(d._s0); + real acq_pint_iva(d._s1); + + if (! (acq_pint.is_zero() && acq_pint_iva.is_zero())) + { + set_row(rw++, FR("Totale acquisti indeducibili per passaggi interni@91g%r@107g%r"), + &acq_pint, + &acq_pint_iva); + } + + real tot1 = d._r7 + d._r4 + d._r9 + acq_pint; + real tot2 = d._r8 + d._r5 + d._r10 + acq_pint_iva; + + if (tot1 != d._r4 || tot2 != d._r5) + { + // i corrispettivi finiscono nelle vendite + d._r0 += d._r2; + d._r1 += d._r3; + d._r2 = ZERO; + d._r3 = ZERO; + // per ora lascio r2 e r3 anche se sono sempre 0 + set_row(rw++, ""); + set_row(rw++,FR("Totale Generale IVA@25g%r@41g%r@58g%r@74g%r@91g%r@107g%r"), + &(d._r0), &(d._r1), &(d._r2), &(d._r3), &tot1, &tot2); + } + + // Stampa il totale progressivo da registri, comprensivo dei movimenti valevoli per il calcolo vol. affari. + real pr_imp(d._s2); + real pr_iva(d._s3); + if (!(d._r11.is_zero() && d._r12.is_zero() && d._r13.is_zero() && + d._r14.is_zero() && pr_imp.is_zero() && pr_iva.is_zero())) + { + set_row(rw++,""); set_row(rw++,""); + set_row(rw++,FR("Totale Prog. da registri@25g%r@41g%r@58g%r@74g%r@91g%r@107g%r"), + &(d._r11), &(d._r12), &(d._r13), &(d._r14), &(pr_imp), &(pr_iva)); + set_row(rw++,""); + } +} + + +void TLiquidazione_app::set_pumpam(const _DescrItem& d) +{ + bool printed = false; + + // d._f1 dice se c'era qualcosa sopra nella stessa pagina + real spgn(d._s2); + real spgn_iva(d._s3); + + TToken_string tt(d._s4); // Token String + TToken_string dp(d._s0); // Due Palle + real aqsi(tt.get(0)); + real aqsv(tt.get(1)); + real vnsi(tt.get(2)); + real vnsv(tt.get(3)); + real aqli(tt.get(4)); + real aqlv(tt.get(5)); + real vnli(tt.get(6)); + real vnlv(tt.get(7)); + real ammindi(dp.get(1)); + real ammindv(dp.get(2)); + + int row = 5; + + if (!(aqsi.is_zero() && aqsv.is_zero())) + { + printed = true; + set_row(row++, FR("Acquisti in sospensione di imposta@50g%r@69g%r"), + &aqsi, + &aqsv); + } + if (!(vnsi.is_zero() && vnsv.is_zero())) + { + printed = true; + set_row(row++, FR("Vendite in sospensione di imposta@50g%r@69g%r"), + &vnsi, + &vnsv); + } + if (!(aqli.is_zero() && aqlv.is_zero())) + { + printed = true; + set_row(row++, FR("IVA ad esigibilità differ. da detrarre nel periodo@50g%r@69g%r"), + &aqli, + &aqlv); + } + if (!(vnli.is_zero() && vnlv.is_zero())) + { + printed = true; + set_row(row++, FR("IVA ad esigibilità differ. da pagare nel periodo@50g%r@69g%r"), + &vnli, + &vnlv); + } + if (!(d._r8.is_zero() && d._r9.is_zero())) + { + printed = true; + set_row(row++, FR("Cessione beni ammortizzabili@50g%r@69g%r"), + &(d._r8), + &(d._r9)); + } + if (! (d._r4.is_zero() && d._r5.is_zero())) + { + printed = true; + set_row(row++, FR("Acquisto beni destinati alla rivendita@50g%r@69g%r"), + &(d._r4), + &(d._r5)); + } + if (! (ammindi.is_zero() && ammindv.is_zero())) + { + printed = true; + set_row(row++, FR("Acquisto beni ammortizzabili IVA indetraibile@50g%r@69g%r"), + &ammindi, + &ammindv); + } + if (! (d._r0.is_zero() && d._r1.is_zero())) + { + printed = true; + set_row(row++, FR("Acquisto beni ammortizzabili IVA detraibile@50g%r@69g%r"), + &(d._r0), + &(d._r1)); + } + if (!(d._r6.is_zero() && d._r7.is_zero())) + { + printed = true; + set_row(row++, FR("Altri beni strumentali acquisiti in leasing@50g%r@69g%r"), + &(d._r6), + &(d._r7)); + } + if (!(d._r2.is_zero() && d._r3.is_zero())) + { + printed = true; +// real rn = d._r2 * real(DETRAZIONE_6PERCENTO); // Detrazione obsoleta CM500344 + set_row(row++, FR("Acquisto beni soggetti a detrazione (6%%)" + "@50g%r@69g%r"), &(d._r2), &(d._r3)); + } + if (!(spgn.is_zero() && spgn_iva.is_zero())) + { + printed = true; + set_row(row++, FR("Spese generali@50g%r@69g%r"), + &spgn, + &spgn_iva); + } + // Prorata... + int yy = atoi(_year); + if (d._f0) + { + printed = true; + + real prc(dp.get(0)); + real rprc = CENTO - prc; + TString ss(rprc.string()); + + set_row(row++, FR("%% PRO-RATA (%s%%) ed IVA non detraibile (%s%%)@69g%r"), + (const char*) ss, (const char*)prc.string(), &(d._r11)); + yy-=2; + if (d._r13 != INVALID_PRORATA && d._r12 != ZERO) + { + rprc = CENTO - d._r13; + ss = rprc.string(); + set_row(row++, FR("%% PRO-RATA %d (%s%%) ed IVA non detraibile (%s%%)@69g%r"), + yy, (const char*) ss, (const char*)d._r13.string(), &(d._r12)); + } + else + if (!_isfinal && d._r13 == INVALID_PRORATA_ASSERT) + set_row(row++, FR("Impossibile reperire la %% PRO-RATA relativa all'anno %d."), yy); + + yy--; + if (d._r15 != INVALID_PRORATA && d._r14 != ZERO) + { + rprc = CENTO - d._r15; + ss = rprc.string(); + set_row(row++, FR("%% PRO-RATA %d (%s%%) ed IVA non detraibile (%s%%)@69g%r"), + yy, (const char*) ss, (const char*)d._r15.string(), &(d._r14)); + } + else + if (!_isfinal && d._r15 == INVALID_PRORATA_ASSERT) + set_row(row++, FR("Impossibile reperire la %% PRO-RATA relativa all'anno %d."), yy); + } + + // items vari per dichiarazione annuale + for (int i = 0; i < d._arr.items(); i++) + { + _DescrItem& dd = (_DescrItem&)d._arr[i]; + printed |= set_annual(dd); + } + + if (printed) + { + set_bookmark(TR("Altri dati"), _att_bookmark); + + set_row(1,""); + set_row(2,""); + set_row(3,FR("ALTRI DATI RELATIVI ALLA DICHIARAZIONE@55gimponibile" + "@77gimposta@91gdetrazione")); + set_row(4,""); + set_row(row++,""); + set_row(row,""); + } + else + set_row(1,""); + + // form feed + if (d._f2) + set_auto_ff(true); +} + +/* +void TLiquidazione_app::set_grand_1999(_DescrItem& d, int& rw) +{ + real& risultato = d._r0; + real& rimborso = d._r1; + real& cred_cost = d._r2; + real& deb_mens = d._r3; + real& rettifiche = d._r5; + real& detrazioni = d._r6; + real& interessi = d._r7; + real& versamenti = d._r8; + real& vers_int = d._r9; + real& conguaglio = d._r10; + TToken_string tt(d._s0); + real iva_vend(tt.get(0)); + real iva_acq(tt.get(1)); + real cred_prec(tt.get(2)); + real debt_prec(tt.get(3)); + real cred_trasf(tt.get(4)); cred_trasf = -cred_trasf; + + real acc_dec(d._s1); + real res_cred(d._s2); + real res_debt(d._s3); + real rett_debt(0.0); + real rett_cred(0.0); + real& interesse = d._r11; + + if (rettifiche.sign() > 0) rett_debt = rettifiche; + if (rettifiche.sign() < 0) rett_cred = -rettifiche; + + set_row(rw++,FR(" @66gCredito@84gDebito")); set_row(rw++,""); + set_row(rw++,FR("@11gIva sulle operazioni di vendita@75g%r"), &iva_vend); + set_row(rw++,FR("%s@11gRettifiche IVA a debito%s@75g%r"), + _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rett_debt); + set_row(rw++,FR("%s@11gIva chiesta a rimborso%s@75g%r"), + _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rimborso); + + // conguaglio prorata + if (conguaglio.sign() > 0) + set_row(rw++,FR("@11gConguaglio pro-rata@75g%r"), &conguaglio); + + // debito liq. precedente < 50000 + if (debt_prec > ZERO) + set_row(rw++,FR("@11gDebito da liquidazione precedente@75g%r"), &debt_prec); + + set_row(rw++,FR("@11gRISULTATO@75g%r"), &res_debt); + set_row(rw++,FR("@11gIva ammessa in detrazione@58g%r"), &iva_acq); + if (_isannual || d._f1) + { + set_row(rw++,FR("@11gCredito inizio anno@58g%r"), &cred_prec); + if (cred_trasf != ZERO) + set_row(rw++,FR("@11gCredito trasferito @58g%r"), &cred_trasf); + } + else + set_row(rw++,FR("@11gCredito precedente@58g%r"), &cred_prec); + + if (!acc_dec.is_zero()) + set_row(rw++,FR("%s@11gVersamento acconto dicembre%s@58g%r"), + _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &acc_dec); + + if (!detrazioni.is_zero()) + set_row(rw++,FR("@11gUlteriori detrazioni@58g%r"), &detrazioni); + + set_row(rw++,FR("%s@11gRettifiche IVA a credito%s@58g%r"), + _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rett_cred); + + // versamenti effettuati + if (!versamenti.is_zero() && (_month==13 || !_is_visliq)) + { + set_row(rw++,FR("@11gVersamenti effettuati@58g%r"), &versamenti); + } + // versamenti integrativi + if (!vers_int.is_zero() && !_is_visliq) + { + set_row(rw++,FR("@11gVersamenti integrativi@58g%r"), &vers_int); + } + if (conguaglio.sign() < 0) + { + real cg = conguaglio; + cg = -cg; + set_row(rw++,FR("@11gConguaglio pro-rata@58g%r"), &cg); + } + + set_row(rw++,FR("@11gRISULTATO@58g%r"), &res_cred); + + // se non c'e' nulla da versare stampa solo una riga vuota + // Serve, non toglierla, stronzo. + if (risultato.is_zero()) + set_row(rw++,""); + else + { + if (risultato.sign() < 0) + { + real iva = abs(risultato); + if (_isannual || _isriepilogo) + round_imposta(iva); + set_row(rw++,FR("@23gCREDITO ATTUALE@58g%r"),&iva); + if (_is_visliq) + { // se chiamata dalla visualizzazione mette 2 righe vuote se non vi sono interessi + // poiche' con le rettifiche a credito/debito posso volerle visualizzare + set_row(rw++,""); + set_row(rw++,""); + } + } + else + { + if (_month == 13) + round_imposta(interessi); + real iva = risultato + interessi; + if (_isannual || _isriepilogo) + round_imposta(iva); + if (!iva.is_zero()) + { + if (!interessi.is_zero()) + { + set_row(rw++,FR("@23gIVA DOVUTA@75g%r"),&risultato); + set_row(rw++,FR("@23gInteresse @33g%6.2r @41g%%@75g%r"),&interesse, &interessi); + } + else + if (_is_visliq) + { // vedi sopra... + set_row(rw++,""); + set_row(rw++,""); + } + if (iva >= iva_da_riportare(_month)) + set_row(rw++,FR("@23gIVA DA VERSARE@75g%r"),&iva); + else + set_row(rw++,FR("@23gIVA A DEBITO DA NON VERSARE@75g%r"),&iva); + } + } + } + + if (_is_visliq && _month != 13) + { + // stampa versamenti (anche 0) ad uso visualizzazione liquidazione IVA + rw++; + set_row(rw++,FR("@11g$[r]Versamenti effettuati$[n]@58g%r"), &versamenti); + set_row(rw++, ""); + set_row(rw++, ""); + } + + if (!_is_visliq) + { + // descrizione rettifiche + if (d._s4.not_empty() || d._s5.not_empty()) + { + rw++; + set_row(rw++, FR("@11g@bDESCRIZIONE RETTIFICHE@r")); + rw++; + if (d._s4.not_empty()) { set_row(rw++, "@11g%t", &(d._s4)); } + if (d._s5.not_empty()) { set_row(rw++, "@11g%t", &(d._s5)); } + } + } +} +*/ + +void TLiquidazione_app::print_importo(int rw, const char* prompt, real imp, bool red) +{ + int tab = 75; + if (imp < ZERO) + { imp = -imp; tab = 58; } + TString256 str; + str << "@11g"; + if (red) str << "$[r]"; + str << prompt; + if (red) str << "$[n]"; + str << '@' << tab << "g%r"; + set_row(rw, str, &imp); +} + +// d._flags == THE_END +void TLiquidazione_app::set_grand_2000(_DescrItem& d, int &rw) +{ + const real risultato = d._r0; // Figuccia lo poteva cambiare, ora tornato const :-) + const real& rimborso = d._r1; + const real& cred_cost = d._r2; + const real& deb_mens = d._r3; + const real& rettifiche = d._r5; + const real& detrazioni = d._r6; + const real& interessi = d._r7; + const real& versamenti = d._r8; + const real& vers_int = d._r9; + + real diffinc_iva = d._r29; + real diffinc_iva_acq = d._r33; + real xcasinc_iva = ZERO; + real xcasinc_iva_acq = ZERO; + + if (has_module(ICAUT) && (!diffinc_iva.is_zero() || !diffinc_iva_acq.is_zero())) + { + real dimp, diva, ximp, xiva; + + if (!diffinc_iva.is_zero() && calc_inc_diff(1, dimp, diva, ximp, xiva)) + { + diffinc_iva = diva; + xcasinc_iva = xiva; + } + if (!diffinc_iva_acq.is_zero() && calc_inc_diff(2, dimp, diva, ximp, xiva)) + { + diffinc_iva_acq = diva; + xcasinc_iva_acq = xiva; + } + } + + TToken_string tt(d._s0); + real iva_vend(tt.get(0)); + real iva_acq(tt.get(1)); + real cred_prec(tt.get(2)); + real debt_prec(tt.get(3)); + real cred_trasf(tt.get(4)); cred_trasf = -cred_trasf; + + real acc_dec(d._s1); + real res_cred(d._s2); + real res_debt(d._s3); + real rett_debt(0.0); + real rett_cred(0.0); + real& interesse = d._r11; + + real& credito_utilizzato_IVA = d._r15; + real& credito_utilizzato_F24 = d._r16; + real& variazioni_imposta = d._r17; + real& imposta_non_versata = d._r18; + real& crediti_speciali = d._r19; + real& credito_autorizzato_F24 = d._r20; + const TDate &data_autorizzazione = d._d1; + + if (credito_autorizzato_F24 < ZERO) credito_autorizzato_F24 = ZERO; + if (rettifiche > ZERO) rett_debt = rettifiche; + if (rettifiche < ZERO) rett_cred =-rettifiche; + + const TRectype & lia = get_lia(); + const bool utilizza_credito_autorizzato = lia.get_bool("B6"); + const bool credito_compensabile = lia.get("S9") == "CM"; + + + set_row(rw++,FR(" @66gCredito@84gDebito")); set_row(rw++,""); + + // Se sono in visualizzazione stampo i due importi separati, altrimenti li sommo + if (!_is_visliq) + iva_vend += rett_debt; + set_row(rw++, FR("@11g@bIVA esigibile@r per il periodo@75g%r"), &iva_vend); + if (!diffinc_iva.is_zero()) + set_row(rw++,FR("@11g a liquidazione differita@75g%r"), &diffinc_iva); + if (!xcasinc_iva.is_zero()) + set_row(rw++,FR("@11g per cassa@75g%r"), &xcasinc_iva); + if (_is_visliq) + set_row(rw++,FR("@11g$[r]Rettifiche IVA a debito$[n]@75g%r"), &rett_debt); // Rettifiche modificabili + + // Se sono in visualizzazione stampo i due importi separati, altrimenti li sommo + if (!_is_visliq) + iva_acq += rett_cred; + set_row(rw++, FR("@11g@bIVA detraibile@r per il periodo@58g%r"), &iva_acq); + if (!diffinc_iva_acq.is_zero()) + set_row(rw++,FR("@11g a liquidazione differita@58g%r"), &diffinc_iva_acq); + if (!xcasinc_iva_acq.is_zero()) + set_row(rw++,FR("@11g per cassa@58g%r"), &xcasinc_iva_acq); + if (_is_visliq) + set_row(rw++,FR("@11g$[r]Rettifiche IVA a credito$[n]@58g%r"), &rett_cred); + + real iva_deb_cred = iva_vend - iva_acq + diffinc_iva - diffinc_iva_acq + xcasinc_iva - xcasinc_iva_acq; + if (_is_visliq) + iva_deb_cred += rett_debt - rett_cred; + if (_isannual) + iva_deb_cred.round(0); + + print_importo(rw++, TR("IVA a debito o a credito per il periodo"), iva_deb_cred); + + rw++; + print_importo(rw++, TR("Variazioni d'imposta"), variazioni_imposta, _is_visliq); + print_importo(rw++, TR("Imposta non versata"), imposta_non_versata, _is_visliq); + + if (debt_prec > ZERO) + { + set_row(rw++,FR("@11gDebito da liquidazione precedente@75g%r"), &debt_prec); + set_row(rw++,FR("%s@11gRimborsi%s@75g%r"), _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rimborso); + + } + else + { + if (cred_prec > ZERO) + set_row(rw++,FR("@11gCredito da liquidazione precedente@58g%r"), &cred_prec); + + if (_month < 13 && credito_compensabile && credito_autorizzato_F24 > ZERO) + { + cred_prec -= credito_autorizzato_F24; + set_row(rw++,FR("%s@11gCredito IVA autorizzato in F24%s@75g%r@100gil %s"), _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &credito_autorizzato_F24, (const char *) data_autorizzazione); + } + cred_prec -= rimborso; + set_row(rw++,FR("%s@11gRimborsi%s@75g%r"), _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &rimborso); + if (cred_prec > ZERO) + set_row(rw++,FR("@11gCredito utilizzabile@58g%r"), &cred_prec); + if (_month < 13) + set_row(rw++, FR("@11gCredito IVA compensabile detratto@58g%r"), &credito_utilizzato_IVA); + } + + real cre_deb_per = risultato + crediti_speciali + acc_dec + vers_int; + if (_month == 13) cre_deb_per += versamenti; + + print_importo(rw++, TR("IVA dovuta o a credito per il periodo"), cre_deb_per); + + if (crediti_speciali != ZERO || _is_visliq) + set_row(rw++,FR("%s@11gCrediti speciali%s@58g%r"), + _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &crediti_speciali); + + if (_freqviva == "T" && !interessi.is_zero()) + set_row(rw++,FR("@11gInteressi dovuti per liquidazioni trimestrali %6.2r%%@75g%r"),&interesse, &interessi); + else + if (_is_visliq) rw++; + + if (!acc_dec.is_zero()) + set_row(rw++,FR("%s@11gAcconto versato%s@58g%r"), + _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &acc_dec); + else + if (_is_visliq) rw++; + + // versamenti effettuati + if (!versamenti.is_zero() && (_month==13 || !_is_visliq)) + set_row(rw++,FR("@11gVersamenti effettuati@58g%r"), &versamenti); + else + if (_is_visliq) rw++; + + // versamenti integrativi + if (!vers_int.is_zero() && !_is_visliq) + set_row(rw++,FR("@11gVersamenti integrativi@58g%r"), &vers_int); + else + if (_is_visliq) rw++; + + const real iva = risultato + interessi; + if (_month == 13 && credito_compensabile) + { + real credito_utilizzabile = lia.get_real("R0"); + + credito_utilizzabile -= lia.get_real("R15"); + credito_utilizzabile -= credito_utilizzato(13); + credito_utilizzabile += credito_autorizzato(13); + if (credito_utilizzabile < ZERO) + credito_utilizzabile = ZERO; + set_row(rw++,FR("@11gCredito compensabile attuale@58g%r"), &credito_utilizzabile); + } + if (iva > ZERO) + { + if (iva >= iva_da_riportare(_month)) + set_row(rw++,FR("@23gIMPORTO DA VERSARE@75g%r"),&iva); + else + set_row(rw++,FR("@23gIMPORTO DA NON VERSARE@75g%r"),&iva); + } + else + { + if (_isannual) + { + const real& credito = d._r20; + if (credito > ZERO) + set_row(rw++,FR("@11gCREDITO RIPORTATO NELL'ANNO SUCCESSIVO@58g%r"), &credito); + } + if (_is_visliq) + rw++; + } + + if (_is_visliq && _month != 13) + { + rw++; + set_row(rw++,FR("@11g$[r]Descrizione$[n]")); + + // stampa versamenti (anche 0) ad uso visualizzazione liquidazione IVA + rw++; + set_row(rw++,FR("@11g$[r]Versamenti effettuati$[n]@58g%r"), &versamenti); + set_row(rw++, ""); + set_row(rw++, ""); + } + + if (!_is_visliq) + { + // descrizione rettifiche + if (d._s6.not_empty()) + { + rw++; + set_row(rw++, FR("@11g@bDESCRIZIONE RETTIFICHE@r")); + rw++; + if (d._s6.not_empty()) { set_row(rw++, "@11g%t", &(d._s6)); } + } + } + if (credito_compensabile) + { + real credito_utilizzabile = lia.get_real("R0"); + + rw++; + credito_utilizzabile -= lia.get_real("R15"); + if (_month < 13) + { + credito_utilizzabile -= credito_utilizzato(_month); + credito_utilizzabile += credito_autorizzato(_month); + if (credito_utilizzabile < ZERO) + credito_utilizzabile = ZERO; + + set_row(rw++,FR("@11gCredito compensabile da liquidazione precedente@58g%r"), &credito_utilizzabile); + if (credito_autorizzato_F24 > ZERO) + { + credito_utilizzabile += credito_autorizzato_F24; + set_row(rw++,FR("%s@11gCredito IVA autorizzato in F24%s@75g%r@100gil %s"), _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &credito_autorizzato_F24, (const char *) data_autorizzazione); + } + set_row(rw++, FR("@11gCredito IVA compensabile detratto@75g%r"), &credito_utilizzato_IVA); + credito_utilizzabile -= credito_utilizzato_IVA; + set_row(rw++, FR("%s@11gCredito IVA compensabile detratto in F24%s@75g%r"), _is_visliq ? "$[r]" : "", _is_visliq ? "$[n]" : "", &credito_utilizzato_F24); + credito_utilizzabile -= credito_utilizzato_F24; + set_row(rw++,FR("@11gCredito compensabile attuale@58g%r"), &credito_utilizzabile); + } + else + { + const real credito_utilizzato_annuale_IVA = TLiquidazione_app::credito_utilizzato_IVA(13); + const real credito_utilizzato_annuale_F24 = TLiquidazione_app::credito_utilizzato_F24(13); + const real credito_autorizzato_annuale_F24 = credito_autorizzato(13); + + set_row(rw++,FR("@11gCredito compensabile da liquidazione precedente@58g%r"), &credito_utilizzabile); + if (credito_autorizzato_annuale_F24 > ZERO) + { + credito_utilizzabile += credito_autorizzato_annuale_F24; + set_row(rw++,FR("@11gCredito IVA autorizzato in F24@58g%r"), &credito_autorizzato_annuale_F24); + } + set_row(rw++, FR("@11gCredito IVA compensabile detratto@75g%r"), &credito_utilizzato_annuale_IVA); + credito_utilizzabile -= credito_utilizzato_annuale_IVA; + set_row(rw++, FR("@11gCredito IVA compensabile detratto in F24@75g%r"), &credito_utilizzato_annuale_F24); + credito_utilizzabile -= credito_utilizzato_annuale_F24; + if (credito_utilizzabile < ZERO) + credito_utilizzabile = ZERO; + set_row(rw++,FR("@11gCredito compensabile attuale@58g%r"), &credito_utilizzabile); + } + } +} + +static void imp2string(const real& n, TString& str) +{ + if (!n.is_zero()) + { + const TCurrency c(n); + str = c.string(true); + str.right_just(15); + } + else + str.spaces(15); +} + +void TLiquidazione_app::set_iva_succ(int& rw) +{ + TString query; + query << "USE IVADIFF KEY 2 SELECT (BETWEEN(DATAREG,#DAL,#AL))&&(BETWEEN(DATAREGP,0,#AL))" + << "\nFROM ANNOLIQ=" << _year; + TISAM_recordset id(query); + const TDate da_datareg(1, 1, atoi(_year)); + const TDate a_datareg(31, 12, atoi(_year)); + id.set_var("#DAL", da_datareg); + id.set_var("#AL", a_datareg); + + TImporto ven_diff, ven_xcas, acq_xcas; + long cur_numreg = 0; + int cur_tipodif = 0; + int cur_tipoiva = 0; + + for (bool ok = id.move_first(); ok; ok = id.move_next()) + { + const long numreg = id.get(RMI_NUMREG).as_int(); + if (numreg != cur_numreg) + { + cur_numreg = numreg; + cur_tipodif = id.get("TIPODIFF").as_int(); + cur_tipoiva = id.get("TIPOIVA").as_int(); + } + const char sezione = id.get("SEZIONE").as_string()[0]; + const TImporto imp(sezione, id.get(RMI_IMPONIBILE).as_real()); + if (!imp.is_zero()) + { + if (cur_tipoiva == 1) // Vendite + { + if (cur_tipodif == 1) + ven_diff += imp; + else + ven_xcas += imp; + } + else + acq_xcas += imp; + } + } + + if (!ven_diff.is_zero() || !ven_xcas.is_zero() || !acq_xcas.is_zero()) + { + set_row(rw++,FR("@11g@bOPERAZIONI EFFETTUATE NELL'ANNO CON IMPOSTA ESIGIBILE NEGLI ANNI SUCCESSIVI@r")); + const real vd = ven_diff.valore(); + const real vc = ven_xcas.valore(); + const real vt = vc+vd; + const real at = acq_xcas.valore(); + + set_row(rw++, "Totale vendite con IVA esigibile negli anni successivi@66g%r", &vt); + set_row(rw++, "Di cui con IVA per cassa@66g%r", &vc); + set_row(rw++, "Totale acquisti con IVA detraibile negli anni successivi@66g%r", &at); + set_row(rw++, "Di cui con IVA per cassa@66g%r", &at); + } +} + +void TLiquidazione_app::set_grand(_DescrItem& d) +{ + int rw = 1; + + if (_isannual) // Stampa annuale evidenzia importi esigibili l'anno dopo + set_iva_succ(rw); + + set_bookmark(TR("Riepilogativo liquidazione"), _firm_bookmark); + set_row(rw++,""); set_row(rw++,""); set_row(rw++,""); set_row(rw++,""); + set_row(rw++,FR("@11g@bCALCOLO LIQUIDAZIONE D'IMPOSTA@r")); + + /* + const bool new_print = atoi(_year) >= 2000; + if (new_print) + set_grand_2000(d, rw); + else + set_grand_1999(d, rw); + */ + set_grand_2000(d, rw); + + + // rapportini per rimborso infraannuale + // non si stampano se la stampa serve per la visualizz. + // solo in st.di prova in coda ai registri deve scendere + // il prospetto di rimborso + // sempre (cioe' in bollato e in prova) deve scendere + // il prospettino versamento + if (d._arr.items() > 0 && !_is_visliq) + { + for (int i = 0; i < d._arr.items(); i++) + { + const _DescrItem& di = (_DescrItem&)d._arr[i]; + + if (di._flags == RIMBORSO) + { + if (!_isregis || (_isregis && !_isfinal)) + { + set_print_zero(true); + set_row(rw++,""); + set_row(rw++,""); + + set_bookmark(TR("Prospetto di rimborso"), _firm_bookmark); + + set_row(rw++, TR(" PROSPETTO DI RIMBORSO")); + + if (di._f0) + { + // esenti e non imponibili + set_row(rw++,""); + set_row(rw++,TR("1) Soggetto con quota di operazioni esenti e non imponibili superiore al 25%%")); + + real perc = di._r0 * CENTO / di._r1; perc.round(0); + + TString sep(strlen(REAL_PICTURE)+2); sep.fill('-'); + set_row(rw++,""); + set_row(rw++,FR("@26gTotale operazioni esenti e non imp.@66g%r"), + &(di._r0)); + set_row(rw++,FR("@66g%t x 100 = %3r%%"), &sep, &perc); + set_row(rw++,FR("@26gVolume di affari lordo@66g%r"), &(di._r1)); + set_row(rw++,""); + } + + if (di._f1) + { + set_row(rw++,""); + set_row(rw++,TR("2) Soggetto con acquisti ad aliquota media superiore a quella delle vendite")); + TString sep(strlen(REAL_PICTURE)+2); sep.fill('-'); + set_row(rw++,""); + set_row(rw++,FR("@26gTotale imposte sugli acquisti@66g%r"), &(di._r5)); + set_row(rw++,"@66g%t x 100 = %5.2r%%", &sep, &(di._r7)); + set_row(rw++,FR("@26gTotale imponibili sugli acquisti@66g%r"), + &(di._r3)); + set_row(rw++,""); + set_row(rw++,FR("@26gTotale imposte sulle vendite@66g%r"), &(di._r4)); + set_row(rw++,"@66g%t x 100 = %5.2r%%", &sep, &(di._r6)); + set_row(rw++,FR("@26gTotale imponibili sulle vendite@66g%r"), &(di._r2)); + } + + set_print_zero(false); + } + } + // prospettino versamento + else if (di._flags == DELEGA) + { + const bool acconto = di._s4 == "ACC"; + int rr = rw; + int cont = 10; + if (acconto) + { + TToken_string ac(di._s5); + if (!ac.empty_items() && _stampa_vers) + cont = 14; + } + if (rw < (printer().formlen() - cont)) + rw = printer().formlen() - cont; + + for (int i = rr; i < rw; i++) + set_row(i,""); + + set_bookmark(TR("Riepilogo versamenti"), _firm_bookmark); + + if (acconto) // Acconto + { + TToken_string ac(di._s5); + if (!ac.empty_items()) + { + TString16 dt (ac.get(4)); + real app (ac.get(3)); + TString16 vr; imp2string(app, vr); + TString4 con (ac.get(0)); + TString8 abi (ac.get(1)); + TString8 cab (ac.get(2)); + + set_row(rw++, TR("- ACCONTO DICEMBRE -")); + set_row(rw, FR(" Versamento di %s effettuato il %s"), + (const char*)vr, + (const char*)dt); + set_row(rw++, FR("@68gCod Conc.: %3s"),(const char*)con); + set_row(rw++, FR("@68gCod. ABI: %5s Cod. CAB o Cod. Dipendenza: %5s"),(const char*)abi,(const char*)cab); + } + } + + if (_stampa_acc && _stampa_vers) + set_row(rw++, "- SALDO -"); + + if (_stampa_vers) + { + TString16 dt = di._d0.string(); + TString16 vr; imp2string(di._r0, vr); + set_row(rw, FR(" Versamento di %s effettuato il %s"), + (const char*)vr, (const char*)dt); + set_row(rw++, FR("@68gCod Conc.: %3s"),(const char*)di._s0); + set_row(rw++, FR("@68gCod. ABI: %5s Cod. CAB o Cod. Dipendenza: %5s"),(const char*)di._s1,(const char*)di._s2); + } + } + } + } + + if (!_is_visliq) set_auto_ff(true); + else set_auto_ff(false); + + _firm_bookmark = -1; +} + + +bool TLiquidazione_app::set_annual(_DescrItem& d) +{ + // chiamata internamente a set_pims + bool ret = false; + + int row = get_maxrow()+1; + if (row == 1) row = 4; + + if (d._f0 & IS_PRORATA) + { + // 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); + + row++; + set_row(++row, TR("CALCOLO DELLA PERCENTUALE DI DETRAIBILITA'")); + row++; + + set_bookmark(TR("Calcolo pro-rata"), _att_bookmark); + + ret = true; + set_print_zero(true); + set_row(row++,""); + + const real perc_det = CENTO - d._r2; + const real vol_aff = d._r0 - d._r10; // Valutare se eliminare d._r10 come valore e sottrarlo a monte + const TString16 s1 = perc_det.stringa(); + const TString16 s2 = d._r2.stringa(); + set_row(row++, FR("%% PRO-RATA (%s%%) ed IVA non detraibile (%s%%)@69g%r"), + (const char*)s1, (const char*)s2, &(d._r6)); + + set_row(row++,FR("C1 - Operazioni esenti escluse da nr. 1 a 9 e 11 art. 10 @69g%r"), &(d._r1)); + set_row(row++,FR("C2 - Operazioni esenti di cui nr. 11 art. 10 @69g%r"), &(d._r4)); + set_row(row++,FR("C3 - Operazioni esenti da nr. 1 a 9 art. 10 @69g%r"), &(d._r5)); + set_row(row++,FR("@6gdi cui cessione beni ammortizzabili @69g%r"), &(d._r8)); + set_row(row++,FR("C1A - Operazioni esenti di cui all'art.10 n. 27 quinquies @69g%r"), &(d._r7)); + set_row(row++,FR("@6gdi cui cessione beni ammortizzabili @69g%r"), &(d._r9)); + set_row(row++,FR("Totale vendite al fine del calcolo del pro-rata @69g%r"), &vol_aff); + set_row(row++,FR("Detraibilità @69g%r%%"), &perc_det); + + set_print_zero(false); + } + return ret; +} + + +void TLiquidazione_app::set_ventila(_DescrItem& d) +{ + if (d._arr.items() == 0 || d._r0.is_zero()) + return; + + set_bookmark(TR("Prospetto ventilazione"), _att_bookmark); + + set_row(1,FR("@54gPROSPETTO VENTILAZIONE")); + set_row(2,""); + set_row(3,""); + set_row(4,FR("@10gTotale acquisti destinati alla rivendita@55g%r"), + &(d._r0)); + set_row(5,FR("@10gTotale dei corrispettivi da ventilare@55g%r"), + &(d._r1)); + set_row(6,FR("@10gMoltiplicatore@59g%3.9r"),&(d._r2)); + set_row(7,""); + set_row(8,FR("@10gCod.")); + set_row(9,FR("@10gIVA@17gDescrizione@48gAcquisti" + "@65gImponibile vendite@89gImposta vendite")); + set_row(10,""); + int row = 11; + real t1, t2, t3; + TString80 s0; + int i; + + for(i = 0; i < d._arr.items(); i++) + { + _vDesc& vd = (_vDesc&)d._arr[i]; + look_iva(vd._codiva); + s0 = _iva->get("S0"); s0.cut(23); + + set_row(row+i,"@8g%5s@17g%-23s@41g%r@68g%r@89g%r", + (const char*)vd._codiva, + (const char*)s0, + &(vd._acq), + &(vd._vnd), + &(vd._viv)); + t1 += vd._acq; + t2 += vd._vnd; + t3 += vd._viv; + } + set_row(row+i+1,""); + set_row(row+i+2,FR("@10gTotale@41g%r@68g%r@89g%r"), + &t1, &t2, &t3); + set_auto_ff(true); +} + +static void real2string(const real& r, TString& str) +{ + TCurrency cur(r); + str = cur.string(true); +} + +void TLiquidazione_app::set_regagr(_DescrItem& d) +{ + set_print_zero(true); + + real& agr_1 = d._r0; + real& agr_2 = d._r1; + real& agr_3 = d._r2; + real& agr_4 = d._r3; + real& agr_5 = d._r4; + real& agr_6 = d._r5; + real& agr_7 = d._r6; + real& agr_1i = d._r7; + real& agr_2i = d._r8; + real& pdetr = d._r9; + real& ivadt = d._r10; + real& iva_detIA = d._r11; + + real ara = agr_5 + agr_6; + real arn = agr_3 + agr_4; + real agr_ven = agr_1 + agr_2; + real ivadt_amm = agr_3 + ivadt + iva_detIA; + + set_bookmark(TR("Prospetto regime agricolo"), _att_bookmark); + int r = 1; + + set_row(r++,FR("@50gPROSPETTO REGIME AGRICOLO")); + set_row(r++,""); + + // percentuale detraibilita' + set_row(r++, FR("Iva vendite beni I parte Tabella A @56g%r"),&agr_1); + set_row(r++, ""); + set_row(r++, FR("Iva vendite beni diversi da I parte Tabella A @56g%r"),&agr_2); + set_row(r++, ""); + set_row(r++, FR("Totale iva sulle operazioni di vendita @56g%r"), &agr_ven); + set_row(r++, ""); + set_row(r++, FR("Iva acquisti in regime agricolo@56g%r"),&ara); + set_row(r++, ""); + set_row(r++, FR("Iva acquisti per operazioni diverse I parte Tabella A@56g%r"),&arn); + set_row(r++, FR("... di cui beni ammortizzabili@56g%r"),&agr_4); + set_row(r++, ""); + set_row(r++, FR("Iva acquisti ad uso promiscuo@56g%r"),&agr_7); + + TString dn,riga; + if (agr_1i != ZERO) + { + real2string(agr_1i, riga); + dn << riga << " + "; + } + real2string(agr_2i, riga); + dn << riga; + int ln = max(riga.len(),dn.len()) + 2; + int corr = ln % 2 == 0 ? 0 : 1; + TString middle(ln); middle.fill('-'); + int xl = 71 - riga.len()/2; + int times_sign = xl + ln/2 + 3; // per allineare i segni moltiplicativi + middle << "@" << times_sign << "gx 100 = " << pdetr.string(".") << " %"; + + set_row(r++, ""); + set_row(r++, "@56g%r",&agr_2i); + riga.format(FR("Percentuale delle operazioni diverse@%dg%%s"),xl - corr - ln/2); + set_row(r++, riga, (const char*)middle); + corr = dn.len() % 2 == 0 ? 0 : 1; + riga.format("@%dg%%s",xl - corr - dn.len()/2); + set_row(r++, riga, (const char*)dn); + + real2string(agr_7, riga); + dn = "100"; + ln = max(riga.len(),dn.len()) + 2; + xl = 71 - riga.len()/2; + corr = ln % 2 == 0 ? 0 : 1; + + middle.fill('-',ln); + middle << "@" << times_sign << "gx " << pdetr.string("."); + middle << " = " << TCurrency(ivadt).string(true); + + set_row(r++, ""); + set_row(r++, "@56g%r", &agr_7); + riga.format(FR("IVA ammessa in detrazione sugli acquisti promiscui@%dg%%s"),xl - corr - ln/2); + set_row(r++, riga, (const char*)middle); + corr = dn.len() % 2 == 0 ? 0 : 1; + riga.format("@%dg%%s",xl - corr - dn.len()/2); + set_row(r++, riga, (const char*)dn); + set_row(r++, ""); + set_row(r++, FR("Iva ammessa in detrazione I parte tabella A@56g%r"),&iva_detIA); + set_row(r++, ""); + set_row(r++, FR("Totale iva ammessa in detrazione@56g%r"),&ivadt_amm); + + // Last pain... + TArray& agr_array = d._arr; + const int pia_items = agr_array.items(); + + if (pia_items) // Se non siamo ancora nel 1998 questo vale 0, ossia non vi sono items. + { + real t1,t2; // Totale imponibile/imposta + TString des; // Descrizione codice iva ordinario + real al; // Aliquota IVA + r+=2; + // Stampa l' intestazione... + set_row(r++,FR(" Codice IVA@45gAliquota IVA@73gCodice IVA@88gAliquota IVA")); + set_row(r++,FR(" Ordinario@45gOrdinaria@61gImponibile@73gCompensazione@88gCompensazione@108gImposta")); + set_row(r++,""); + for (int i=0; iget("S0"); des.cut(25); + al = _iva->get_real("R0"); + set_row(r,"%4s %-25s@48g%s %%", (const char*) di._s0, (const char*) des, al.string("#@,@@")); + set_row(r,"@56g%r@75g%4s",&di._r0, (const char*)di._s1); + look_iva(di._s1); + al = _iva->get_real("R0"); + set_row(r++,"@92g%s %%@100g%r", al.string("#@,@@"), &di._r1); + t1 += di._r0; + t2 += di._r1; + } + // ... ed il totale minchiativo + r++; + set_row(r++,FR("Totale@56g%r@100g%r"),&t1,&t2); + } + + set_auto_ff(true); + set_print_zero(false); +} + +void TLiquidazione_app::set_viaggio(_DescrItem& d) +{ + // the longest & stronzest + // Nel corso della scrittura di questa funzione + // Berlusconi + Fini + Bossi hanno vinto le elezioni + // ... lungo commento cancellato + + real& corr_CEE = d._r0; + real& corr_misCEE = d._r1; + real& corr_noCEE = d._r2; + real& acq_CEE = d._r3; + real& acq_misCEE = d._r4; + real& acq_noCEE = d._r5; + real& acq_misnoCEE = d._r6; + real& perc_r = d._r7; + real& cred_cos = d._r8; + real& ivm = d._r9; + + real tc = (corr_CEE + ivm); + real ta = (acq_CEE + acq_misCEE); + real& bi = d._r10; + real& dovuta = d._r11; + + real tcc = corr_CEE + corr_noCEE + corr_misCEE; + real tco = acq_CEE + acq_noCEE + acq_misCEE + acq_misnoCEE; + real tma = acq_CEE + acq_misCEE; + + set_print_zero(true); + + set_bookmark(FR("Prospetto 74 ter"), _att_bookmark); + + set_row(1,""); + set_row(2,FR("@54gRIEPILOGO 74 TER")); + set_row(3,""); + set_row(4,FR("Ammontare dei corrispettivi relativi a viaggi eseguiti" + " interamente nella CEE .....................@100g%r"), &(corr_CEE)); + set_row(5,FR("Ammontare dei corrispettivi relativi a viaggi misti (dentro" + " e fuori CEE) ......................... @100g%r"), &(corr_misCEE)); + set_row(6,FR("Ammontare dei corrispettivi relativi a viaggi eseguiti" + " interamente fuori CEE ..................... @100g%r"), &(corr_noCEE)); + + + set_row(7,""); + set_row(8,FR("@56gTotale corrispettivi@100g%r"), &tcc); + set_row(9,""); + + set_row(10,FR("Ammontare dei costi relativi a viaggi interamente" + " svolti nella CEE ............................... @100g%r"), + &(acq_CEE)); + set_row(11,FR("Ammontare dei costi relativi a viaggi misti (per la" + " parte CEE) ................................... @100g%r"), + &(acq_misCEE)); + set_row(12,FR("Ammontare dei costi relativi a viaggi interamente" + " svolti fuori CEE ............................... @100g%r"), + &(acq_noCEE)); + set_row(13,FR("Ammontare dei costi relativi a viaggi misti (per la" + " parte fuori CEE) .............................@100g%r"), + &(acq_misnoCEE)); + + set_row(14,""); + set_row(15,FR("@64gTotale costi@100g%r"), &tco); + + set_row(16,""); + set_row(17,TR("DETERMINAZIONE CORRISPETTIVI IMPONIBILI " + "RELATIVI A VIAGGI MISTI")); + set_row(18,""); + + // la bella frazioncina della percentuale di ripartizione + TString tmp; real2string(acq_misCEE, tmp); + TString up = tmp; + up << " x 100"; + TString dn = tmp; + real2string(acq_misnoCEE, tmp); + dn << " + " << tmp; + int ln = max(up.len(), dn.len()) + 2; + TString den(ln); den.fill('-'); + up.center_just(ln); dn.center_just(ln); + + // la bella frazioncina degli imponibili viaggi misti + TString tmp2; real2string(corr_misCEE, tmp2); + TString up2 = tmp2; + const TString16 perc_r_str = perc_r.string("###,@@"); + up2 << " x" << perc_r_str; + TString dn2 = "100"; + int ln2 = max(up2.len(), 3) + 2; + TString den2(ln2); den2.fill('-'); + up2.center_just(ln2); dn2.center_just(ln2); + + // la gran frazionazza centrata e stupenda + int tot = 35 + ln + ln2; + int rem1 = (100 - tot)/2; if (rem1 < 0) rem1 = 0; + int pos1 = rem1 + 13; + int rem2 = pos1+ den.len() + 11; + int pos2 = rem2 + 20; + + set_row(19,format("@%dg%%t@%dg%%t", pos1, pos2), + &up, &up2); + set_row(20,format(FR("@%dgPerc. rip. = %%t = %%t; @%dg" + "Imp. viaggi misti = %%t = @100g%%r"), + rem1, rem2), + &den, &perc_r_str, &den2, &ivm); + set_row(21,format("@%dg%%t@%dg%%t", pos1, pos2), + &dn, &dn2); + + real tmr = corr_CEE + ivm; + + // whew, come dicono su Topolino + + real2string(corr_CEE, tmp); + up = "("; up << tmp << " + "; + real2string(ivm, tmp); + up << tmp << ")"; + den.fill('.',59-up.len()); + set_row(23,FR("Ammontare dei corrispettivi imponibili@40g%t %t@100g%r"), + &up, &den, &tmr); + + // se e' l'annuale non ha senso altro + if (d._f1) return; + + real2string(acq_CEE, tmp); + up = "("; up << tmp << " + "; + real2string(acq_misCEE, tmp); + up << tmp << ")"; + den.fill('.',59-up.len()); + set_row(24,FR("Ammontare dei costi deducibili@40g%t %t@100g%r"), + &up, &den, &tma); + den.fill('.',60); + set_row(25,FR("Credito di costo precedente @40g%t@100g%r"), &den, &(cred_cos)); + + real2string(tmr, tmp); + up = "["; up << tmp << " - ("; + real2string(tma, tmp); + up << tmp << " + "; + real2string(d._r8, tmp); + up << tmp << ")]"; + den.fill('.',59-up.len()); + + set_row(26,FR("Base imponibile lorda@40g%t %t@100g%r"), &up, &den, &bi); + set_row(27,""); + + if (bi > ZERO) + { + const real aliva = aliquota_agvia(); + const real alcnt = aliva + CENTO; + + real2string(bi, tmp); + up = tmp; + up << " x" << aliva.string("###,@@"); + dn = alcnt.string("###,@@"); + ln = max(up.len(), 3) + 2; + den.fill('-',ln); + up.center_just(ln); dn.center_just(ln); + + tmp.fill('.', 59 - den.len()); + + set_row(28,"@40g%t",&up); + set_row(29,FR("IVA A DEBITO@40g%t %t@100g%r"), &den, &tmp, &dovuta); + set_row(30,"@40g%t", &dn); + } + else if (bi.sign() < 0) + { + bi = abs(bi); + set_row(28,""); + set_row(29,FR("CREDITO DI COSTO DA RIPORTARE@100g%r"), &bi); + } + + set_print_zero(false); + set_auto_ff(true); +} + +void TLiquidazione_app::set_acconto_p(_DescrItem& d) +{ + const char* errmsg[3] = { + {TR("manca la tabella risultati liquidazione per l'anno corrente")}, + {TR("manca la tabella risultati liquidazione per l'anno precedente")}, + {TR("manca la tabella dichiarazione annuale per l'anno precedente")}}; + + set_row(1,"%t@7g%t",&(d._s0), &(d._s1)); + if (d._f2) + set_row(1,"@50g@b*** %s ***@r", errmsg[d._f2 -1]); + else + { + if (d._f0) // base anno in corso + { + if (d._f1) // stampa base di calcolo + { + set_row(1,"@58g%r@74g%r@96g%r@122g%s", &(d._r3), + &(d._r2), &(d._r1), d._f3 ? "Si" : "No"); + } + else + set_row(1,"@62g%r@91g%s", &(d._r1), d._f3 ? "Si" : "No"); + } + else //metodo storico + { + if (d._f1 && (d._r0).sign()>0) // stampa base di calcolo + set_row(1,"@58g%r@88g%r", &(d._r0), &(d._r1)); + else + set_row(1,"@87g%r",&(d._r1)); + } + } +} + +void TLiquidazione_app::set_acchead_p(_DescrItem& d) +{ + reset_header(); + set_header(1,FR("Gestione IVA@107gData @>@125gPag. @#")); + set_header(3,sep); + + if (d._f0) // base anno in corso + { + set_header(2,FR("@40gCALCOLO ACCONTI IVA DICEMBRE %s " + "(base anno in corso)"), (const char*) _year); + if (d._f1) // stampa base calcolo + { + set_header(4,FR("@58g------- Base di calcolo -------")); + set_header(5,FR("Ditta@7gDenominazione@62gDebito@78gCredito" + "@94gACCONTO calcolato@115gLiq. differita")); + set_header(6,sep); + set_header(7,""); + } + else + { + set_header(4,FR("Ditta@7gDenominazione@60gACCONTO calcolato" + "@84gLiq. differita")); + set_header(5,sep); + set_header(6,""); + } + } + else + { + set_header(2,FR("@40gCALCOLO ACCONTI IVA DICEMBRE %s"), (const char*) _year); + set_header(5,sep); + set_header(6,""); + if (d._f1) + set_header(4,FR("Ditta@7gDenominazione@58gBase di calcolo" + "@86gACCONTO calcolato")); + else + set_header(4,FR("Ditta@7gDenominazione@85gACCONTO calcolato")); + } +} + + +// --------------------------------------------------------------------- +// Tabulato deleghe +// --------------------------------------------------------------------- + +void TLiquidazione_app::set_deltab(_DescrItem& d, bool iscred) +{ + reset_header(); + int rw = 1; + static bool credpr; + + if (iscred) + { + // set header + set_header(1,FR("ELENCO DITTE A CREDITO@30g%s %s@107gData @>@125gPag. @#"), + d._f0 == 13 ? TR("Annuale ") : itom(d._f0), (const char*)_year); + set_header(2,sep); + set_header(3,FR("@40gF@60gImporto a")); + set_header(4,FR("Cod.@8gDenominazione@40gR@62gcredito")); + set_header(5,sep); + set_header(6,""); + + // set rows + for (int i = 0; i < d._arr.items(); i++) + { + TToken_string& tt = (TToken_string&)(d._arr)[i]; + TString cod(tt.get(0)); + TParagraph_string rgs(tt.get(1), 30); + TString diocantaro(rgs.get(0)); + TString frq(tt.get(2)); + real tp (tt.get(3)); + real in (tt.get(4)); + tp -= in; + tp = -tp; + set_row(rw++, "%-5s@8g%-30s@40g%1s@54g%r", + (const char*)cod, (const char*)diocantaro, + (const char*)frq, &tp); + for (int i = 1; i < rgs.items(); i++) + set_row(rw++, "@8g%-30s", (const char*)rgs.get(i)); + } + } + else + { + // set header + set_header(1,FR("ELENCO DITTE A DEBITO@30g%s %s@107gData @>@125gPag. @#"), + d._f0 == 13 ? TR("Annuale ") : itom(d._f0), (const char*)_year); + set_header(2,sep); + set_header(3,FR("@40gF@60gImporto da@73gCodice@83gCod.")); + set_header(4,FR("Cod.@8gDenominazione@40gR Numero telefonico@63gversare Banca Dip. Con.")); + set_header(5,sep); + set_header(6,""); + + + // set rows + for (int i = 0; i < d._arr.items(); i++) + { + TToken_string& tt = (TToken_string&)(d._arr)[i]; + TString cod(tt.get(0)); + TParagraph_string rgs(tt.get(1), 30); + TString diocantaro(rgs.get(0)); + TString frq(tt.get(2)); + real tp (tt.get(3)); + real in (tt.get(4)); + TString abi(tt.get(5)); + TString cab(tt.get(6)); + TString con(tt.get(7)); + TString tel(tt.get(8)); + if (!tel.blank()) + tel << '/'; + tel << tt.get(9); + TString desc(tt.get(10)); + + set_row(rw++, "%-5s@8g%-30s@40g%1s %s @55g%r %5s %5s %3s %-.45s", + (const char*)cod, (const char*)diocantaro, (const char*)frq, + (const char*)tel, &tp, (const char*)abi, + (const char*)cab, (const char*)con, (const char*)desc); + + for (int i = 1; i < rgs.items(); i++) + set_row(rw++, "@8g%-30s", (const char*)rgs.get(i)); + } + } + set_auto_ff(true); +} + diff --git a/cg/cg4305.cpp b/cg/cg4305.cpp index 7b5ff518c..44e60f0dd 100755 --- a/cg/cg4305.cpp +++ b/cg/cg4305.cpp @@ -17,410 +17,6 @@ #include "cg4300c.h" #include "cg4800b.h" -/* - -// -------------------------------------------------- estrazione deleghe -bool TLiquidazione_app::set_deleghe() -{ - TMask m("cg4300b.msk"); - m.field(FLD_CGB_YEAR).set_handler(ch_year_handler); - - m.field(FLD_CGB_YEAR).set(_year); - m.field(CHK_CGB_PRINT).set(_isprint ? "X" : ""); - - int k = 0; - long j; - _calcall = FALSE; - - for (;;) - { - if (k == K_ESC || k == K_QUIT || k == K_ENTER) - break; - - k = m.run(); - - _isprint = m.get_bool(CHK_CGB_PRINT); - - switch (k) - { - case DLG_SELECT: - - _ditte->run(); - for (j = 0l; j < _ditte->items(); j++) - if (_ditte->checked(j)) _selected.set(j); - break; - - case BUT_CGB_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; - } - } - - if (k == K_ENTER) - { - _year = m.get(FLD_CGB_YEAR); - _month = atoi(m.get(FLD_CGB_MONTH)); - } - - return k == K_ENTER; -} - -bool TLiquidazione_app::extract_deleghe() -{ - TString buf(256); TArray desc; - _prind = new TProgind(_calcall ? _n_ditte : _selected.ones(), - TR(" Estrazione deleghe \n" - " preparazione archivi \n " - " \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)) - continue; - - const long ditta = _ditte->row(l).get_long(1); - TApplication::set_firm(ditta); - TIva_round ir; ir.set_default_iva_mode(atoi(_year), _month > 12, ditta); - - _nditte->curr().zero(); - _nditte->curr().put("CODDITTA", ditta); - _nditte->read(); - - // must succeed - look_lia(); - _freqviva = _lia->get("S7"); - - buf.format(FR("Estrazione deleghe (%d):\nditta %s\n "), - _month, (const char*)_nditte_r->get("RAGSOC")); - _prind->set_text(buf); - - if (is_month_ok_strict(_month) || _month == 13) - { - const bool mens = _freqviva == "M"; - _isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74_4"); - _isriepilogo = _month == 13; - _isendliq = _isannual || _isriepilogo; - if (mens || _isbenzinaro || _month!=12) - extract_delega(_month, desc); - } - _prind->addstatus(1); - } - - TApplication::set_firm(__firm); - delete _prind; - - if (_isprint) - { - _DescrItem* ddeb = NULL; - _DescrItem* dcrd = NULL; - - // scorri desc e prepara descritems - for (int i = 0; i < desc.items(); i++) - { - TToken_string& tt = (TToken_string&)desc[i]; - - real tp(tt.get(3)); - if (tp.sign() > 0) - { - if (ddeb == NULL) - { - ddeb = new _DescrItem(DELDEB); - ddeb->_f0 = _month; - } - ddeb->_arr.add(tt); - } - else - { - if (dcrd == NULL) - { - dcrd = new _DescrItem(DELCRED); - dcrd->_f0 = _month; - } - dcrd->_arr.add(tt); - } - } - if (dcrd != NULL) _descr_arr.add(dcrd); - if (ddeb != NULL) _descr_arr.add(ddeb); - } - - return TRUE; -} - -bool TLiquidazione_app::extract_delega(int month, TArray& desc) -{ - const bool has_f24 = main_app().has_module(GVAUT); - TToken_string* tt = NULL; - bool versare = FALSE; - bool skip_print = FALSE; - - if (look_lim(month)) - { - real topay = result_liq(month); // TBC non si puo' fa' accussi'!!!!! pena il casino! - if (month == 12) - { - if (topay > _ver->get(I_ANNUALE)) - versare = TRUE; - } - else if (topay > _ver->get(I_PERIODICO)) - versare = TRUE; - - real intr = _lim->get_real("R14"); - topay += intr; // lo vogliono registrato con interessi - real nrnd = topay; - round_imposta(topay); // importo totale del versamento arrotondato - - bool wasdel = look_del(month, 1); - - //la stampa deve essere fatta sia se a credito che a debito - if (!topay.is_zero()) - { - tt = new TToken_string(80); - tt->add(_nditte->curr().get("CODDITTA")); - tt->add(_nditte->curr().get("RAGSOC")); - tt->add(_freqviva); - tt->add(topay.string()); - tt->add(""); - } - - if (versare) - { - look_del(month, 1, TRUE); //ci mette abi, cab o con - //che legge dall'anagrafica!!! - bool stampato = _del->get_bool("B0"); - if (stampato) //se esiste e stampato si richiede conferma aggiornamento - { - if (topay != _del->get_real("R0")) - skip_print = !video_conferma(topay, intr, nrnd); // se non conferma o annulla, salta il tabulato - else - skip_print = true; // Se l'importo e' lo stesso e la delega era gia' stampata, salta il tabulato - } - else //aggiorna importo versamento - { - _del->put("R0",topay); - _del->put("R1",intr); - _del->put("R2",nrnd); // non arrotondato, per calcolo risultato a debito/cr - _del->rewrite(); - } - - if (has_f24) - { - TLocalisamfile f24(LF_RIGHEF24); - TTable trib("%TRB"); - long progr = 0L; - TString descr("IVA annuale"); - const bool mensile = _freqviva == "M"; - const int codtrib = mensile ? 6000 + month : 6031 + (month / 3); - - TDate scad(16, (mensile ? month : ((month + 2) / 3) * 3), atoi(_year)); - const long codditta = _nditte->lfile().get_long("CODDITTA"); - - if (month < 13) - scad.addmonth(mensile ? 1 : 2); - while (scad.wday() > 5) - ++scad; - - if (month < 13) - { - if (mensile) - descr.format("IVA mese di %s %s", itom(month), (const char *)_year); - else - descr.format("IVA %s Trimestre %s", itor(month / 3 + 1), (const char *)_year); - } - trib.put("CODTAB", codtrib); - if (trib.read() != NOERR) - { - int g = 0, c = 0; - long s = 0; - trib.put("CODTAB", 6001); - if (trib.read(_isgteq) == NOERR) - { - const int cod = trib.get_int("CODTAB"); - if (cod > 6000 && cod < 6036) - { - g = trib.get_int("I0"); - c = trib.get_int("I1"); - s = trib.get_long("I2"); - } - } - trib.zero(); - trib.put("CODTAB", codtrib); - TString d(descr); - trib.put("S0", d.rtrim(5)); - trib.put("S6", "E"); - trib.put("I0", g); - trib.put("I1", c); - trib.put("I2", s); - trib.write(); - } - f24.setkey(4); - f24.put(F24_TIPOINTEST, "D"); - f24.put(F24_INTEST, codditta); - f24.put(F24_ANNO, _year); - f24.put(F24_TRIBUTO, codtrib); - if (f24.read() == NOERR) - { - if (f24.get(F24_DATAVERS).blank() || skip_print) - { - f24.put(F24_IMPORTODEB, topay); - f24.put(F24_INTIVATRIM, intr); - f24.put(F24_DATASCAD, scad); - - const int err = f24.rewrite(); - - if (err != NOERR) - error_box(FR("Ditta %ld\n%s\nerrore %d"), codditta, (const char *) descr, err); - } - } - else - { - f24.setkey(1); - if (f24.last() == NOERR) - progr = f24.get_long(F24_PROGR); - progr++; - f24.zero(); - f24.put(F24_PROGR, progr); - - - f24.put(F24_TRIBUTO, codtrib); - f24.put(F24_TIPOINTEST, "D"); - f24.put(F24_INTEST, codditta); - f24.put(F24_DESCR, descr); - f24.put(F24_DATASCAD, scad); - f24.put(F24_ANNO, _year); - f24.put(F24_IMPORTODEB, topay); - f24.put(F24_INTIVATRIM, intr); - - const int err = f24.write(); - - if (err != NOERR) - error_box(FR("Ditta %ld\n%s\nerrore %d"), codditta, (const char *) descr, err); - } - } - - tt->add(_del->get("S7")); - tt->add(_del->get("S8")); - tt->add(_del->get("S9")); - tt->add(_nditte->curr().get("PTEL")); - tt->add(_nditte->curr().get("TEL")); - TString desc; - if (_del->get("S9").not_empty()) - { - const TRectype & ucc = cache().get("%UCC", _del->get("S9")); - if (!ucc.empty()) - desc = ucc.get("S0"); - } - if (_del->get("S7").not_empty()) - { - TString16 cod; - cod = _del->get("S7"); - if (_del->get("S8").not_empty()) cod << _del->get("S8"); - - const TRectype & ban = cache().get("%BAN", cod); - - if (!ban.empty()) - desc = ban.get("S0"); - } - tt->add(desc); - } - else if (wasdel) //se esiste e no versare - { - bool stampato = _del->get_bool("B0"); - TString buf; - buf.format(FR("Il versamento relativo alla ditta %ld e' gia' stato stampato. Si desidera eliminare il flag di stampa definitiva?"),_nditte->lfile().get_long("CODDITTA")); - if (stampato && yesno_box(buf)) - { // Se la delega e' gia' stampata in definitva, chiede se deve eliminare il flag di stampa - _del->put("B0",FALSE); - _del->rewrite(); - } - // Se non e' stampata invece visualizza la delega presente su file e l'importo a credito che ha calcolato - // chiedendo cosa fare: Registra elimina fisicamente la delega dal file, Annulla lo fa proseguire - if (!stampato) - video_conferma(topay, intr, nrnd, TRUE); - } - } - - if (tt != NULL && !skip_print) // Se il tabulato deve essere stampato per questa delega... - desc.add(tt); - - return true; -} - -bool TLiquidazione_app::video_conferma(const real& newimp, const real& intr, - const real& narr, bool to_del) -{ - TMask m("cg4800b"); - - m.set_caption(to_del ? TR("Conferma eliminazione") : TR("Estrazione versamenti")); // Modifica il titolo... - m.field(F_CODDITTA).set(_nditte->lfile().get("CODDITTA")); - m.field(F_RAGSOC).set(_nditte->lfile().get("RAGSOC")); - m.field(F_DATAVER).set(_del->get_date("D0")); - m.field(F_ABI).set(_del->get("S7")); - m.field(F_CAB).set(_del->get("S8")); - m.field(F_CON).set(_del->get("S9")); - m.field(F_IMPVER).set(_del->get("R0")); - if (to_del) - { - real xr = abs(newimp); - m.hide(F_NEWIMP); - m.show(F_NEWIMPCRED);m.disable(F_NEWIMPCRED); - m.field(F_NEWIMPCRED).set(xr.string()); - } - else - m.field(F_NEWIMP).set(newimp.string()); - - KEY k; - for (bool stop = FALSE; !stop;) - { - k = m.run(); - - switch(k) - { - case K_SAVE: - { - k = yesnocancel_box(to_del ? - TR("Si desidera veramente confermare l'eliminazione?") - : - TR("Delega gia' stampata. Si desidera ugualmente confermare l'aggiornamento?")); - if (k == K_YES) - { - if (to_del) - _del->remove(); - else - { - _del->put("B0", false); - _del->put("R0",newimp); - _del->put("R1",intr); - _del->put("R2",narr); - _del->rewrite(); - } - } - if (k == K_YES || k == K_NO) - stop = TRUE; - } - break; - case K_ESC: - //case K_QUIT: - stop = TRUE; - break; - } - } - return k == K_YES; -} - -*/ - // -------------------------------------------- calcolo acconto dicembre bool TLiquidazione_app::set_acconto(real& inf, real& ina) @@ -513,10 +109,11 @@ bool TLiquidazione_app::recalc_acconti(real& inf, real& ina) _isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74_4"); - look_lia(); - _freqviva = _lia->get("S7"); - inf = _lia->get_real("R13"); - ina = _lia->get_real("R14"); + 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")); @@ -563,11 +160,13 @@ bool TLiquidazione_app::recalc_acconto(real& inf, real& ina) const TString4 thyear = _year; _year.format("%d", atoi(_year)-1); - if (!look_lia()) + const TRectype & lia = get_lia(); + + if (lia.empty()) error = 3; else { - char ohh = _lia->get_char("S7"); + char ohh = lia.get_char("S7"); if (ohh == 'M') history = thh == 'M' ? mm : mt; if (ohh == 'T') history = thh == 'M' ? tm : tt; @@ -587,69 +186,88 @@ bool TLiquidazione_app::recalc_acconto(real& inf, real& ina) 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 + 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) - if (!look_lim(12)) error = 2; - else - { - bc += _lim->get_real("R0"); - real av = _lim->get_real("R11"); - bc += av; - } + // 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 - if (!look_lim(13)) error = 2; // TBC sara' 13a davvero? Secondo me e' 12 - else - { - bc += _lim->get_real("R0"); - 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; + { + // 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 - if (!look_lim(10)) error = 2; - else - { - real app = _lim->get_real("R0"); - if (app.sign() > 0) //a debito - bc += app; - } - if (!look_lim(11)) error = 2; - else - { - real app = _lim->get_real("R0"); - if (app.sign() > 0) //a debito - bc += app; - } - if (!look_lim(12)) error = 2; - else - { - bc += _lim->get_real("R0"); - real av = _lim->get_real("R11"); - bc += av; - } + 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.sign() > 0) //debito + if (bc > ZERO) //debito { - acc = ((bc / divide_by_three) * _ver->get(isdifferita ? B_LIQ_DIFF : B_LIQ_NORM))/CENTO; + 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; @@ -663,11 +281,16 @@ bool TLiquidazione_app::recalc_acconto(real& inf, real& ina) _recalc = one; int need_refresh = FALSE; for (int mese = 1; mese < _month; mese++) - if (is_month_ok_strict(mese) && (!look_lim(mese) || !_lim->get_bool("B0"))) - { - need_refresh = TRUE; - break; - } + 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; @@ -681,28 +304,34 @@ bool TLiquidazione_app::recalc_acconto(real& inf, real& ina) } // calcola l'acconto - if (look_lim(12)) //posiziona anche la tabella lam + TRectype lim = get_lim(12); + + if (lim.not_empty()) { - cre = _lim->get_real("R12"); - cre -= _lim->get_real("R19"); + cre = lim.get_real("R12"); + cre -= lim.get_real("R19"); - deb = _lim->get_real("R13") + inf + ina; - deb -= _lim->get_real("R18") + _lim->get_real("R1"); // CM600446 + 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"); + if (lim.get_real("R17") > ZERO) + deb -= lim.get_real("R17"); else - cre += _lim->get_real("R17"); + cre += lim.get_real("R17"); bc = deb - cre; - if (bc.sign() > 0) acc = bc; + 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_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(); @@ -736,40 +365,43 @@ bool TLiquidazione_app::recalc_acconto(real& inf, real& ina) for (int i = 1; i <= _month; i++) if (is_month_plain(i)) update_firm(i); - - _lim->put("B0",""); - _lim->rewrite(); - if (look_lim(13)) + lim.put("B0",""); + put_lim(lim); + + lim = get_lim(13); + if (lim.not_empty()) { - _lim->put("B0",""); - _lim->rewrite(); + lim.put("B0",""); + put_lim(lim); } //fine - _isprint = TRUE; + _isprint = true; } // sbatti l'acconto (e non solo!) in LIA - if (look_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); + 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); - _lia->rewrite(); - } + lia.put("S1",rr); + lia.put("S8",tipo_acc); + put_lia(lia); +} // per questa volta lasciamo perdere la describe_acconto diff --git a/cg/cg5300.cpp b/cg/cg5300.cpp index c6c2e38e8..07d7fd55c 100755 --- a/cg/cg5300.cpp +++ b/cg/cg5300.cpp @@ -30,7 +30,6 @@ protected: // Applicat static bool agrmin_handler(TMask_field& f, KEY k); static bool credres_handler(TMask_field& f, KEY k); static bool credpreccost_handler(TMask_field& f, KEY k); - static bool utcred_handler(TMask_field& f, KEY k); protected: // Relapp virtual bool user_create(); @@ -132,18 +131,6 @@ bool TParaliq_app::credres_handler(TMask_field& f, KEY k) r.round(euro ? m.get_int(F_ROUNDDIC) : -3); f.set(r.string()); } - - if (k == K_ENTER) // In uscita dalla maschera - { - const TMask& m = f.mask(); - const short id = f.dlg(); - const real r = m.get_real(F_CRED_RES); - const int i = m.get_int(F_MESE_RES_AL); - if (id == F_MESE_RES_AL && r != 0.0 && i == 0) - return f.error_box(TR("Impostare anche il mese.")); - if (id == F_CRED_RES && i != 0 && r == 0.0) - return f.error_box(TR("Impostare anche il credito residuo.")); - } return true; } @@ -161,46 +148,6 @@ bool TParaliq_app::credpreccost_handler(TMask_field& f, KEY k) return true; } -bool TParaliq_app::utcred_handler(TMask_field& f, KEY k) -{ - TMask & m = f.mask(); - if ((k == K_TAB && f.focusdirty()) || !m.is_running()) - { - const int anno_liq = m.get_int(F_YEAR); - TString80 cod_mesi; - TString des_mesi(128); - TString8 mese; - TList_field& mese_res = m.lfield(F_MESE_RES_AL); - - if (anno_liq >= 2000 && !f.get().not_empty()) - { - m.field(F_CRED_PREC).set_prompt(TR("Credito compensabile inizio anno ")); - m.field(F_CRED_RES).set_prompt(TR("Credito in compensaz.utilizzato ")); - m.enable(F_UTCR_IVA); - cod_mesi = "0|-1"; - des_mesi = FR(" |Inizio Anno"); - mese = !m.field(F_CRED_RES).empty() ? "-1" : "0"; - } - else - { - m.field(F_CRED_PREC).set_prompt(TR("Credito precedente ")); - m.field(F_CRED_RES).set_prompt(TR("Credito residuo ")); - cod_mesi = "0|1|2|3|4|5|6|7|8|9|10|11|12"; - des_mesi = FR(" |Gennaio|Febbraio|Marzo|Aprile|Maggio|Giugno|Luglio|Agosto|Settembre|Ottobre|Novembre|Dicembre"); - mese = app().rel().lfile().get("I0"); - if (!m.edit_mode() || atoi(mese) < 0) - mese.cut(0); - } - const TString16 oldmese = m.get(F_MESE_RES_AL); - mese_res.replace_items(cod_mesi, des_mesi); - if (m.is_running()) - m.set(F_MESE_RES_AL, mese); - else - m.set(F_MESE_RES_AL, oldmese); - } - return true; -} - void TParaliq_app::check_registers(int year) { // controlla che per ogni data attività esistano almeno un registro @@ -298,7 +245,6 @@ bool TParaliq_app::user_create() _msk->set_handler(F_CRED_PREC,credpreccost_handler); _msk->set_handler(F_CRED_COST,credpreccost_handler); _msk->set_handler(F_CODDITTA,ditta_handler); - _msk->set_handler(F_UTCR_IVA,utcred_handler); _msk->sfield(F_SHEET_PLA).set_notify(sheet_action); return true; diff --git a/cg/cg5300a.h b/cg/cg5300a.h index 1dfc8b8df..85237fac8 100755 --- a/cg/cg5300a.h +++ b/cg/cg5300a.h @@ -16,6 +16,7 @@ #define F_GESIC 216 #define F_ICDAL 217 #define F_ICAL 218 +#define F_UTILAUT 219 #define F_ROUNDLIQ 221 #define F_ROUNDDIC 222 diff --git a/cg/cg5300a.uml b/cg/cg5300a.uml index 3d99f7958..cdd22932f 100755 --- a/cg/cg5300a.uml +++ b/cg/cg5300a.uml @@ -107,8 +107,8 @@ BOOLEAN F_GESIC BEGIN PROMPT 4 7 "Gestione IVA per cassa" FIELD B5 - MESSAGE false DISABLE,F_ICDAL|DISABLE,F_ICAL - MESSAGE true ENABLE,F_ICDAL|ENABLE,F_ICAL + MESSAGE FALSE DISABLE,F_ICDAL|DISABLE,F_ICAL + MESSAGE TRUE ENABLE,F_ICDAL|ENABLE,F_ICAL MODULE IC END @@ -128,6 +128,12 @@ BEGIN MODULE IC END +BOOLEAN F_UTILAUT +BEGIN + PROMPT 4 8 "Riutilizza il credito autorizzato in IVA" + FIELD B6 +END + GROUPBOX DLG_NULL 78 6 BEGIN PROMPT 1 10 "@bCredito" @@ -136,7 +142,7 @@ END CURRENCY F_CRED_COST 18 BEGIN - PROMPT 4 11 "Credito di costo " + PROMPT 4 11 "Credito di costo " HELP "Eventuale credito di costo dell'anno precedente" FIELD R5 DRIVENBY F_CODVAL @@ -144,15 +150,18 @@ END LISTBOX F_UTCR_IVA 2 34 BEGIN - PROMPT 4 12 "Utilizzo credito IVA " - ITEM " |Visibile e utilizzato solo in IVA" - ITEM "NV|Non visibile ma compensabile" + PROMPT 4 12 "Utilizzo credito IVA " + ITEM " |Utilizzato solo in IVA" + MESSAGE CLEAR,F_CRED_RES + ITEM "CM|Compensabile con altre imposte" + MESSAGE ENABLE,F_CRED_RES + FIELD S9 END CURRENCY F_CRED_PREC 18 BEGIN - PROMPT 4 13 "Credito compensabile inizio anno " + PROMPT 4 13 "Credito IVA inizio anno " HELP "Eventuale credito di imposta dell'anno precedente" FIELD R0 DRIVENBY F_CODVAL @@ -160,20 +169,13 @@ END CURRENCY F_CRED_RES 18 BEGIN - PROMPT 4 14 "Credito in compensaz.utilizzato " + PROMPT 4 14 "Credito IVA utilizzato a Gennaio " FIELD R15 DRIVENBY F_CODVAL NUM_EXPR #THIS<=#F_CRED_PREC WARNING "L'importo non puo' essere maggiore del Credito Precedente" END -LISTBOX F_MESE_RES_AL 2 14 -BEGIN - PROMPT 57 14 "A " - ITEM "0|" - FIELD I0 -END - SPREADSHEET F_SHEET_PLA 78 BEGIN PROMPT 1 16 "Parametri attività" diff --git a/cg/cg5500.cpp b/cg/cg5500.cpp index e6546ac5f..5f8cb4520 100755 --- a/cg/cg5500.cpp +++ b/cg/cg5500.cpp @@ -1,10 +1,13 @@ #include +#include +#include #include #include #include #include #include #include +#include #include #include @@ -115,7 +118,6 @@ bool Visliq_app::ch_year_handler(TMask_field& f, KEY key) return true; } - void Visliq_app::build_ditte_sheet() { // build sheet @@ -249,6 +251,10 @@ const char* Visliq_app::link_handler(TMask& m, { group = -7; firstfoc = F_IMPNONVER; } if (st.find(TR("Crediti")) >= 0) { group = -8; firstfoc = F_CREDSPEC; } + if (st.find(TR("Credito IVA compensabile detratto in F24")) >= 0) + { group = -9; firstfoc = F_CREDUTIL; } + if (st.find(TR("Credito IVA autorizzato in F24")) >= 0) + { group = -10; firstfoc = F_CREDAUT; } m.show(group); if (app()._is_annual && (group != -3 || app()._freqviva == "M")) @@ -343,6 +349,34 @@ bool Visliq_app::set_ragsoc(TMask_field& f, KEY k) return found; } +void Visliq_app::print() +{ + TReport_book book("Stampa prospetti liquidazione"); + TProgram_report rep; + + rep.load("cg5500a"); + + TRecordset* r = rep.recordset(); + TString key ; key.format("%05ld%04d", get_firm(), year()); + TString key1; key1 << "\"" << key << "\""; + + r->set_var("#FILTER", key1, true); + r->set_var("#ANNO", TVariant((long)year()), true); + book.add(rep); + rep.load("cg5500b"); + r = rep.recordset(); + r->set_var("#FILTER", key, true); + r->set_var("#ANNO", TVariant((long)year()), true); + book.add(rep); + book.print_or_preview(); +} + +bool Visliq_app::print_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + app().print(); + return true; +} bool Visliq_app::sel_mese_sh1 (TMask_field& f, KEY k) { @@ -372,13 +406,14 @@ bool Visliq_app::sel_mese_sh1 (TMask_field& f, KEY k) else ok = true; + TMask& sm = sh.sheet_mask(); if (ok) { if (sm.is_running()) sm.stop_run(K_ENTER); app().vis_one(month); - const bool non_vis_ma_comp = app()._lia->get("S9") == "NV"; - if (non_vis_ma_comp) + const bool compensabile = app()._lia->get("S9") == "CM"; + if (compensabile) app().read_general(m); } @@ -412,6 +447,33 @@ bool Visliq_app::sel_mese_sh1 (TMask_field& f, KEY k) return true; } +bool Visliq_app::enable_date(TMask_field& f, KEY k) +{ + if (k == K_TAB && (f.focusdirty()|| !f.mask().is_running())) + { + const bool enable = f.mask().get(104).full() || f.mask().get(109).full(); + + f.mask().enable(110, enable); + if (!enable) + f.mask().set(110, ""); + } + return true; +} + +bool Visliq_app::check_date(TMask_field& f, KEY k) +{ + if (k == K_TAB && (f.focusdirty()|| !f.mask().is_running())) + { + const TDate d(f.get()); + const int row = f.mask().get_sheet()->selected(); + + if (d.year() != app().year()) + return f.error_box(FR("L'anno deve essere %d"), app().year()); + if (d.month() != row + 1) + return f.error_box(FR("Il mese deve essere %s"), itom(row + 1)); + } + return true; +} bool Visliq_app::sel_mese_sh2 (TMask_field& f, KEY k) { @@ -445,14 +507,14 @@ bool Visliq_app::sel_mese_sh2 (TMask_field& f, KEY k) { if (sv.is_running()) sv.stop_run(K_ENTER); app().vis_one(month); - const bool new_age_2000 = (app()._year >= 2000) && (app()._lia->get("S9") == "NV"); - if (new_age_2000) + const bool compensabile = app()._lia->get("S9") == "CM"; + if ((app()._year >= 2000) && compensabile) app().read_general(m); } app().set_vers_rows(sh); - if (app().look_del(month, /* sel == (sh.items() - 1) ? 7 : */ 1)) + if (app().look_del(month, 1)) { TToken_string& tv = sh.row(sel); tv.add(app().del()->get("D0"),1); @@ -528,24 +590,33 @@ bool Visliq_app::vis_all() // qui occorre modificare le deleghe sv.set_notify(vers_action); - sh.sheet_mask().set_handler(100,sel_mese_sh1); - sv.sheet_mask().set_handler(100,sel_mese_sh2); + _mask->set_handler(DLG_PRINT, print_handler); + sh.sheet_mask().set_handler(100, sel_mese_sh1); + sh.sheet_mask().set_handler(104, enable_date); + sh.sheet_mask().set_handler(109, enable_date); + sh.sheet_mask().set_handler(110, check_date); + + sv.sheet_mask().set_handler(100, sel_mese_sh2); const bool new_print_2000 = true; // _year >= 2000; - const bool new_age_2000 = _lia->get("S9") == "NV"; + const bool compensabile = _lia->get("S9") == "CM"; TMask& shm = sh.sheet_mask(); - for (int id = 103; shm.id2pos(id) > 0; id++) - { - TMask_field& f = shm.field(id); - if ((f.in_group(11) && new_print_2000) || (f.in_group(12) && !new_print_2000)) + if (compensabile) + for (int id = 103; shm.id2pos(id) > 0; id++) + { +/* + TMask_field& f = shm.field(id); + + if ((f.in_group(11) && true) || (f.in_group(12) && !true)) { f.hide(); sh.delete_column(id); - } - if (id == 108 || id == 110) - sh.enable_column(id, new_age_2000); - } + } +*/ + if ((id >= 107 && id <= 110) || id == 112) + sh.enable_column(id, true); + } // fill the mask in read_general(*_mask); @@ -643,47 +714,44 @@ bool Visliq_app::vis_one(int m) if (_lim->get_bool("B2")) nomem << TR(" (diritto al rimborso infraannuale)"); - real acconto(0.0); + real acconto; if (m == 12 && look_del(12,7)) - acconto = _del->get_real("R0"); else - if (m == 13) - acconto = _lim->get_real("R11"); + acconto = _del->get_real("R0"); + else + if (m == 13) + acconto = _lim->get_real("R11"); - msk.field(F_YEAR).set(nomem); + msk.set(F_YEAR, nomem); msk.set(F_RIMBORSO, rimborso); // Ottima procedura di 16 righe, di cui 14 inutili! - if (rettifica.sign() < 0) - { - real rabs = abs(rettifica); - msk.field(F_RETTIFICA).set(rabs.string()); - msk.field(F_DEBCRE).set("C"); - } - else if (rettifica.sign() > 0) - { - msk.field(F_RETTIFICA).set(rettifica.string()); - msk.field(F_DEBCRE).set("D"); - } - else - { - msk.field(F_RETTIFICA).set(""); - msk.field(F_DEBCRE).set(""); - } + if (!rettifica.is_zero()) + { + msk.set(F_DEBCRE, rettifica > ZERO ? "D" : "C"); + rettifica = abs(rettifica); + msk.set(F_RETTIFICA, rettifica); + } - TString desc1 = _lim->get("S0"), desc2 = _lim->get("S1"), desc3 = _lim->get("S2"); - msk.field(F_DESCR1).set(desc1); - msk.field(F_DESCR2).set(desc2); - msk.field(F_DESCR3).set(desc3); + TString desc1 = _lim->get("S0"), desc2 = _lim->get("S1"), desc3 = _lim->get("S2"), desc4 = _lim->get("S3"); + + msk.set(F_DESCR1, desc1); + msk.set(F_DESCR2, desc2); + msk.set(F_DESCR3, desc3); + msk.set(F_DESCR4, desc4); msk.set(F_ACCONTO, acconto); real varimp = _lim->get("R17"); real impnonver= _lim->get("R18"); real credspec = _lim->get("R19"); - msk.set(F_VARIMP, varimp >= ZERO ? varimp : -varimp); - msk.set(F_VARIMP_DC, varimp >= ZERO ? "D" : "C"); + if (!varimp.is_zero()) + { + msk.set(F_VARIMP_DC, varimp > ZERO ? "D" : "C"); + varimp = abs(varimp); + msk.set(F_VARIMP, varimp); + } msk.set(F_IMPNONVER, impnonver); msk.set(F_CREDSPEC, credspec); @@ -695,7 +763,7 @@ bool Visliq_app::vis_one(int m) TViswin & vsw = brw.vis_win(); bool is_delega = false; - real vers; TDate date; TString abi(5), cab(5), con(3); + real vers; TDate date; TString8 abi, cab, con; if (is_delega = look_del(m,1)) { @@ -706,141 +774,95 @@ bool Visliq_app::vis_one(int m) con = _del->get("S9"); } - msk.field(F_DELDATE).set(date.string()); - msk.field(F_DELIMP).set(vers.string()); - msk.field(F_DELABI).set(abi); - msk.field(F_DELCAB).set(cab); - msk.field(F_DELCON).set(con); + msk.set(F_DELDATE, date); + msk.set(F_DELIMP, vers); + msk.set(F_DELABI, abi); + msk.set(F_DELCAB, cab); + msk.set(F_DELCON, con); - bool l_mod = false; - bool d_mod = false; + real cred_util = _lim->get_real("R16"); + + msk.set(F_CREDUTIL, cred_util); + + real cred_aut = _lim->get_real("R20"); + TDate data_aut = _lim->get_date("D1"); + + msk.set(F_CREDAUT, cred_aut); + msk.set(F_DATAAUT, data_aut); _from_one = true; - for(;;) - { - KEY k = msk.run(); - - if (k == K_ESC) break; - - real n_acconto (msk.get(F_ACCONTO)); - real n_rimborso (msk.get(F_RIMBORSO)); - real n_rettifica(msk.get(F_RETTIFICA)); - real n_delimp(msk.get(F_DELIMP)); - TString n_desc1 (msk.get(F_DESCR1)); - TString n_desc2 (msk.get(F_DESCR2)); - TString n_desc3 (msk.get(F_DESCR3)); - real n_vers (msk.get(F_DELIMP)); - TDate n_date (msk.get(F_DELDATE)); - TString n_abi (msk.get(F_DELABI)); - TString n_cab (msk.get(F_DELCAB)); - TString n_con (msk.get(F_DELCON)); - real n_varimp(msk.get(F_VARIMP)); - real n_impnonver(msk.get(F_IMPNONVER)); - real n_credspec(msk.get(F_CREDSPEC)); - - if (msk.field(F_DEBCRE).get()[0] == 'C') - n_rettifica = -n_rettifica; - - if (msk.get(F_VARIMP_DC)[0] == 'C') - n_varimp = -n_varimp; + KEY k; + + while ((k = msk.run()) != K_ESC && msk.dirty()) + { + acconto = msk.get_real(F_ACCONTO); + rettifica = msk.get_real(F_RETTIFICA); + if (msk.field(F_DEBCRE).get()[0] == 'C') + rettifica = -rettifica; + if (msk.get(F_VARIMP_DC)[0] == 'C') + varimp = -varimp; + desc1 = msk.get(F_DESCR1); + desc2 = msk.get(F_DESCR2); + desc3 = msk.get(F_DESCR3); + desc4 = msk.get(F_DESCR4); + vers = msk.get_real(F_DELIMP); + date = msk.get_date(F_DELDATE); + abi = msk.get(F_DELABI); + cab = msk.get(F_DELCAB); + con = msk.get(F_DELCON); + varimp = msk.get_real(F_VARIMP); + impnonver = msk.get_real(F_IMPNONVER); + credspec = msk.get_real(F_CREDSPEC); + cred_util = msk.get_real(F_CREDUTIL); + cred_aut = msk.get_real(F_CREDAUT); + data_aut = msk.get_date(F_DATAAUT); + + bool l_mod = msk.field(F_ACCONTO).dirty() || + msk.field(F_RETTIFICA).dirty() || msk.field(F_DEBCRE).dirty() || + msk.field(F_VARIMP).dirty() || msk.field(F_VARIMP_DC).dirty() || + msk.field(F_DESCR1).dirty() || + msk.field(F_DESCR2).dirty() || + msk.field(F_DESCR3).dirty() || + msk.field(F_CREDSPEC).dirty() || + msk.field(F_CREDUTIL).dirty() || + msk.field(F_CREDAUT).dirty() || + msk.field(F_DATAAUT).dirty() ? true : false; + bool d_mod = msk.field(F_DELDATE).dirty() || + msk.field(F_DELIMP).dirty() || + msk.field(F_DELABI).dirty() || + msk.field(F_DELCAB).dirty() || + msk.field(F_DELCON).dirty() ? true : false; - if (msk.field(F_RETTIFICA).dirty() || msk.field(F_DEBCRE).dirty()) - { - rettifica = n_rettifica; - l_mod = true; - } - if (msk.field(F_ACCONTO).dirty()) - { - acconto = n_acconto; - l_mod = true; - } if (msk.field(F_RIMBORSO).dirty()) { + // check diritto (se non ce n'era già uno prima) + const bool old_rim = !rimborso.is_zero(); + real nuovo_rimborso = msk.get_real(F_RIMBORSO); bool ok = true; - if (!n_rimborso.is_zero()) - { - const bool old_rim = !rimborso.is_zero(); - // check diritto (se non ce n'era già uno prima) - if (!_lim->get_bool("B2") && !old_rim) + + if (!nuovo_rimborso.is_zero() && !_lim->get_bool("B2") && !old_rim) ok = yesno_box(FR("Non risulta diritto al rimborso per il mese %d. Si desidera " "confermare ugualmente?"), m); - } if (ok) - { - rimborso = n_rimborso; - l_mod = true; - } - else - { - msk.field(F_RIMBORSO).set(rimborso.string()); + { + rimborso = nuovo_rimborso; + l_mod = true; + } + else + { + msk.set(F_RIMBORSO, rimborso); msk.field(F_RIMBORSO).set_dirty(false); } } - if (msk.field(F_DESCR1).dirty()) - { - desc1 = n_desc1; - l_mod = true; - } - if (msk.field(F_DESCR2).dirty()) - { - desc2 = n_desc2; - l_mod = true; - } - if (msk.field(F_DESCR3).dirty()) - { - desc3 = n_desc3; - l_mod = true; - } - if (msk.field(F_DELDATE).dirty()) - { - date = n_date; - d_mod = true; - } - if (msk.field(F_DELIMP).dirty()) - { - real itt = _lim->get_real("R10"); - vers = n_vers; - d_mod = true; - } - if (msk.field(F_DELABI).dirty()) - { - abi = n_abi; - d_mod = true; - } - if (msk.field(F_DELCAB).dirty()) - { - cab = n_cab; - d_mod = true; - } - if (msk.field(F_DELCON).dirty()) - { - con = n_con; - d_mod = true; - } - if (msk.field(F_VARIMP).dirty() || msk.field(F_VARIMP_DC).dirty()) - { - varimp = n_varimp; - l_mod = true; - } - if (msk.field(F_IMPNONVER).dirty()) - { - impnonver = n_impnonver; - l_mod = true; - } - - if (msk.field(F_CREDSPEC).dirty()) - { - credspec = n_credspec; - l_mod = true; - } - - if (recorded) recorded = !(d_mod || l_mod); + if (recorded) + recorded = !(d_mod || l_mod); if (k == K_INS || k == K_SAVE) { recalc_liq_data(&vsw, rimborso, rettifica, vers, acconto, varimp, impnonver, credspec, - desc1, desc2, desc3, date, abi, cab, con); + desc1, desc2, desc3, desc4, date, abi, cab, con, + cred_util, cred_aut, data_aut); } if (k == K_SAVE) { @@ -877,20 +899,35 @@ bool Visliq_app::vis_one(int m) real Visliq_app::credito_utilizzato(int year, int month) const { real credito; - - TTable lim("LIM"); TString16 cod; - for (int m = 1; m <= month; m++) + + for (int m = 1; m <= month; m++) { cod.format("%04d%02d", year, m); - lim.put("CODTAB", cod); - if (lim.read() == NOERR) - { - if (m < month) - credito += lim.get_real("R15"); // Credito utilizzato IVA - if (m < 13) - credito += lim.get_real("R16"); // Credito utilizzato F24 - } + + const TRectype& lim = cache().get("LIM", cod); + + if (m < month) + credito += lim.get_real("R15"); // Credito utilizzato IVA + if (m < 13) + credito += lim.get_real("R16"); // Credito utilizzato F24 + } + + return credito; +} + +real Visliq_app::credito_autorizzato(int year, int month) const +{ + real credito; + TString16 cod; + + for (int m = 1; m <= month; m++) + { + cod.format("%04d%02d", year, m); + + const TRectype& lim = cache().get("LIM", cod); + + credito += lim.get_real("R20"); // Credito utilizzato IVA } return credito; @@ -929,8 +966,10 @@ real Visliq_app::min_vers(int anno, int month) void Visliq_app::recalc_liq_data(TViswin* vsw, real& rimb, real& rett, real& vers, real& acc, real& varimp, real& impnonver, real & credspec, - TString& d1, TString& d2, TString& d3, TDate& date, - TString& abi, TString& cab, TString& con) + TString& d1, TString& d2, TString& d3, TString& d4, + TDate& date, TString& abi, TString& cab, TString& con, + real & credito_utilizzato_F24, + real & credito_autorizzato_F24, TDate & data_autorizzazione) { // ricalcola tutto, scrive nei lim, NON salva e riaggiusta // la paginata della liquidazione @@ -952,7 +991,7 @@ void Visliq_app::recalc_liq_data(TViswin* vsw, real& rimb, real& rett, real& ver real crd = _lim->get_real("R12"); // totale a credito si real dbt = _lim->get_real("R13"); // totale a debito si real itr = _lim->get_real("R14"); // interesse totale si - real cui = _lim->get_real("R15"); // Credito utilizzato iva si + real cui = _lim->get_real("R15"); // Credito util.IVA prec. si real var = _lim->get_real("R17"); // Variazioni d'imposta no real inv = _lim->get_real("R18"); // Imposta non versata no real crs = _lim->get_real("R19"); // Crediti speciali no @@ -983,31 +1022,24 @@ void Visliq_app::recalc_liq_data(TViswin* vsw, real& rimb, real& rett, real& ver // calcola vecchio risultato: se e' diverso da R0 ci sono cazzi strani // e invalidiamo B0 cosi' impara real risul = iva_ven - iva_acq - udt + rmb + cgp - vri + rtt - act - cre_pre + deb_pre + - var + inv - cui - crs; - - if (risul != ris) - { -#ifdef DBG - yesnofatal_box("Porca vacca: Risultato non coincidente!"); -#endif - _lim->put("B0", "X"); - } - + var + inv - cui - crs; //qui // calcola nuovi dati real riscr = iva_acq + udt + acc + cre_pre + credspec; real risdb = iva_ven + rimb + deb_pre + impnonver; - if (rett.sign() < 0) riscr -= rett; + if (rett < ZERO) riscr -= rett; else risdb += rett; - if (cgp.sign() < 0) riscr -= cgp; - else riscr += cgp; - if (varimp.sign() < 0) riscr -= varimp; + if (cgp < ZERO) riscr -= cgp; + else riscr += cgp; + if (varimp < ZERO) riscr -= varimp; else risdb += varimp; real credito_utilizzato_iva = ZERO; - const bool new_age_2000 = (_year >= 2000) && look_lia() && (_lia->get("S9") == "NV"); - if (new_age_2000) + const bool compensabile = _lia->get("S9") == "CM"; + + // if ((_year >= 2000) && look_lia() && compensabile) + if (look_lia() && compensabile) { real credito_utilizzabile_inizio_anno = _lia->get_real("R0") - _lia->get_real("R15"); if (credito_utilizzabile_inizio_anno < ZERO) @@ -1018,6 +1050,7 @@ void Visliq_app::recalc_liq_data(TViswin* vsw, real& rimb, real& rett, real& ver { real credito_utilizzabile = credito_utilizzabile_inizio_anno; + credito_utilizzabile += credito_autorizzato(year, month); credito_utilizzabile -= credito_utilizzato(year, month); if (credito_utilizzabile < ZERO) credito_utilizzabile = ZERO; if (month < 13) @@ -1030,13 +1063,24 @@ void Visliq_app::recalc_liq_data(TViswin* vsw, real& rimb, real& rett, real& ver } risul = risdb - riscr; - - real intr(0.0); - if (!itt.is_zero() && risul.sign() > 0) + const real check01 = risul.round(2); + const real check02 = ris.round(2); + + if (check01 != check02) + { +#ifdef DBG + yesnofatal_box("Porca vacca: Risultato non coincidente!"); +#endif + _lim->put("B0", "X"); + } + + real intr; + + if (!itt.is_zero() && risul > ZERO) { // calcola interesse - intr = risul * itt / real(100.0); + intr = risul * itt / CENTO; intr.ceil(); if (after2000) round_imposta(intr); @@ -1052,13 +1096,19 @@ void Visliq_app::recalc_liq_data(TViswin* vsw, real& rimb, real& rett, real& ver _lim->put("R13", risdb); _lim->put("R14", intr); _lim->put("R15", credito_utilizzato_iva); + _lim->put("R16", credito_utilizzato_F24); + _lim->put("R17", varimp); _lim->put("R18", impnonver); _lim->put("R19", credspec); + _lim->put("R20", credito_autorizzato_F24); + + _lim->put("D1", data_autorizzazione); _lim->put("S0", d1); _lim->put("S1", d2); _lim->put("S2", d3); + _lim->put("S3", d4); // i dati dei versamenti si schiaffano in LIM: // D0 la data, S4/5/6 le tre cazzate ABI CAB CON @@ -1303,7 +1353,11 @@ void Visliq_app::recalc_next_liq(int start_month, TSheet_field* sl, TSheet_field int step = _freqviva == "M" ? 1 : 3; real rstart = _lim->get("R0"); - + real cr_res = _lia->get_real("R0"); + const bool compensabile = _lia->get("S9") == "CM"; + + cr_res -= _lia->get_real("R15"); + for (int i = start_month; i < 13; i += step) { int row = (i/step) - 1; @@ -1322,6 +1376,7 @@ void Visliq_app::recalc_next_liq(int start_month, TSheet_field* sl, TSheet_field real risd = _lim->get_real("R13"); real intt = _lim->get_real("R10"); real crf24 = _lim->get_real("R16"); + real autf24 = _lim->get_real("R20"); // toglie vecchio credito e debito risl += cred; @@ -1352,7 +1407,7 @@ void Visliq_app::recalc_next_liq(int start_month, TSheet_field* sl, TSheet_field _lim->put("R0", risl); _lim->put("R12", risc); _lim->put("R13", risd); - if (intt.sign() > 0) // interessi + if (intt > ZERO) // interessi { real intr = risl * intt / real(100.0); if (_year >= 2000) @@ -1360,6 +1415,7 @@ void Visliq_app::recalc_next_liq(int start_month, TSheet_field* sl, TSheet_field _lim->put("R14",intr); } _lim->put("R16", crf24); + _lim->put("R20", autf24); _lim->rewrite(); _lam->rewrite(); @@ -1372,27 +1428,62 @@ void Visliq_app::recalc_next_liq(int start_month, TSheet_field* sl, TSheet_field TToken_string& t = sl->row(row); t.add(itoname(i),0); - int sr0 = (_lim->get_real("R0")).sign(); - int sr5 = (_lim->get_real("R5")).sign(); - - real r0abs = abs(_lim->get_real("R0")); - real r5abs = abs(_lim->get_real("R5")); - t.add(r0abs.string(),1); - t.add(sr0 == 0 ? "" : (sr0 > 0 ? "D" : "C"), 2); - t.add((_lim->get_real("R1")).string(),3); - t.add(r5abs.string(),4); + const real r0 = _lim->get_real("R0"); + const real r1 = _lim->get_real("R1"); + bool enable_date = !r1.is_zero(); + const real r5 = _lim->get_real("R5"); - t.add(sr5 == 0 ? "" : (sr5 > 0 ? "D" : "C"),5); - + real absv = abs(r0); + t.add(absv, 1); + if (!r0.is_zero()) + t.add(r0 > ZERO ? "D" : "C", 2); + t.add(r1, 3); + absv = abs(r5); + t.add(absv, 4); + if (!r5.is_zero()) + t.add(r5 >ZERO ? "D" : "C", 5); + + const real criva = _lim->get_real("R15"); + const real crf24 = _lim->get_real("R16"); + const real autf24 = _lim->get_real("R20"); + TDate dautf24 = _lim->get_date("D1"); + + enable_date |= !autf24.is_zero(); + t.add(criva, 6); + t.add(crf24, 7); + t.add(autf24, 8); + if (enable_date) + t.add(dautf24, 9); + if (compensabile) + { + cr_res += autf24; + cr_res -= crf24; + cr_res -= criva; + if (cr_res < ZERO) + { + sl->set_back_and_fore_color(COLOR_LTYELLOW, COLOR_DKRED, row, 7); + t.add("", 10); + } + else + { + sl->set_back_and_fore_color(NORMAL_BACK_COLOR, NORMAL_COLOR, row, 7); + t.add(cr_res, 10); + } + } + else + t.add("", 10); + t.add(_lim->get("S3"), 11); + for (int kk = 3; kk < 6 ; kk++) sl->enable_cell(row, kk); sl->enable_cell(row, 7); + sl->enable_cell(row, 8); sl->enable_cell(row, 9); - - sl->force_update(row); + sl->enable_cell(row, 9, enable_date); + sl->enable_cell(row, 12); } } - + sl->force_update(); // se non si fa questa non scrive una delega, // bensi' una bovazza (escremento bovino) look_lim(start_month); @@ -1459,20 +1550,23 @@ void Visliq_app::read_general(TMask& m) TString8 cab; TString4 cnc; const int step = _freqviva == "M" ? 1 : 3; - const bool new_age_2000 = _lia->get("S9") == "NV"; + const bool compensabile = _lia->get("S9") == "CM"; TSheet_field& sh = m.sfield(F_VISLIQ1); TSheet_field& sv = m.sfield(F_VISLIQ2); - TMask_field& crprec = m.field(F_CREDPREC); - if (new_age_2000) +/* if (compensabile) crprec.set_prompt(TR("Credito compensabile inizio anno ")); else - crprec.set_prompt(TR("Credito inizio anno ")); - real cr_res = _lia->get_real("R0"); - crprec.set(cr_res.string()); - if (new_age_2000) - cr_res -= _lia->get_real("R15"); + crprec.set_prompt(TR("Credito inizio anno ")); */ + + real cr_res = _lia->get_real("R0"); + real cr_util = _lia->get_real("R15"); + + m.set(F_CREDPREC, cr_res); + m.set(F_CREDUTILIN, cr_util); + + cr_res -= cr_util; // set sheet for (int i = step; i < 13; i+=step) @@ -1498,8 +1592,10 @@ void Visliq_app::read_general(TMask& m) else tt = &(sh.row(row)); - real r0abs = abs(_lim->get_real("R0")); - real r5abs = abs(_lim->get_real("R5")); + const real r0abs = abs(_lim->get_real("R0")); + const real r1 = _lim->get_real("R1"); + const real r5abs = abs(_lim->get_real("R5")); + tt->add(itoname(i),0); tt->add(r0abs.string(),1); @@ -1507,31 +1603,47 @@ void Visliq_app::read_general(TMask& m) int sr5 = (_lim->get_real("R5")).sign(); tt->add(sr0 == 0 ? "" : (sr0 > 0 ? "D" : "C"),2); - tt->add(_lim->get_real("R1").string(),3); + tt->add(r1.string(),3); tt->add(r5abs.string(),4); + bool enable_date = !r1.is_zero(); tt->add(sr5 == 0 ? "" : (sr5 > 0 ? "D" : "C"),5); const real criva = _lim->get_real("R15"); tt->add(criva.string(), 6); const real crf24 = _lim->get_real("R16"); tt->add(crf24.string(),7); - if (new_age_2000) + const real autf24 = _lim->get_real("R20"); + tt->add(autf24.string(),8); + enable_date |= !autf24.is_zero(); + TDate dautf24 = _lim->get_date("D1"); + if (enable_date) + tt->add(dautf24.string(),9); + sh.enable_cell(row, 9, enable_date); + if (compensabile) { - if (cr_res > ZERO) - { - cr_res -= crf24; - cr_res -= criva; - } - if (cr_res < ZERO) - cr_res = ZERO; - tt->add(cr_res.string(), 8); +// if (cr_res > ZERO) +// { + cr_res += autf24; + cr_res -= crf24; + cr_res -= criva; + if (cr_res < ZERO) + { + sh.set_back_and_fore_color(COLOR_LTYELLOW, COLOR_DKRED, row, 7); + tt->add("", 10); + } + else + { + sh.set_back_and_fore_color(NORMAL_BACK_COLOR, NORMAL_COLOR, row, 7); + tt->add(cr_res.string(), 10); + } } else - tt->add("", 8); - tt->add(_lim->get("S3"), 9); - + tt->add("", 10); + tt->add(_lim->get("S3"), 11); sh.row(row) = (*tt); + // sh.force_update(row); } + sh.force_update(); // calcola versamenti real versamenti[13]; @@ -1611,25 +1723,23 @@ void Visliq_app::write_general(TMask& m) { TSheet_field& sh = m.sfield(F_VISLIQ1); TSheet_field& sv = m.sfield(F_VISLIQ2); - const bool new_age_2000 = _lia->get("S9") == "NV"; + const bool compensabile = _lia->get("S9") == "CM"; - if (m.field(F_CREDPREC).dirty()) - { - const real r = m.get(F_CREDPREC); - _lia->put("R0",r); - _lia->rewrite(); - } + real rstart = m.get_real(F_CREDPREC); + real rutil = m.get_real(F_CREDUTILIN); + + _lia->put("R0", rstart); + _lia->put("R15", rutil); + _lia->rewrite(); // credito iniziale - real rstart = _lia->get_real("R0"); real cr_res; - if (!new_age_2000) - { - if (!rstart.is_zero()) - rstart = -rstart; - } + + rstart -= rutil; + if (!compensabile) + rstart = -rstart; else - cr_res = rstart - _lia->get_real("R15"); + cr_res = rstart; // indicatore ricalcolo crediti e debiti OK int step = _freqviva == "M" ? 1 : 3; @@ -1652,7 +1762,7 @@ void Visliq_app::write_general(TMask& m) // risolve menata del dettaglio si'/no if (lfrommask) { - for (int i = 1; i <= 9; i++) + for (int i = 1; i <= 11; i++) tt_ln.add(shm.get(101+i),i); } @@ -1674,6 +1784,8 @@ void Visliq_app::write_general(TMask& m) real overs(tt_vo.get(5)); real nvers(tt_vn.get(5)); real crf24(tt_ln.get(7)); + real autf24(tt_ln.get(8)); + TDate dautf24(tt_ln.get(9)); TDate odate(tt_vo.get(1)); TDate ndate(tt_vn.get(1)); TString odbcr(tt_lo.get(5)); @@ -1684,7 +1796,7 @@ void Visliq_app::write_general(TMask& m) TString8 ncab (tt_vn.get(3)); TString ocon (tt_vo.get(4)); TString ncon (tt_vn.get(4)); - TString descr(tt_ln.get(9)); + TString descr(tt_ln.get(11)); if (odbcr == "C") orett = -orett; if (ndbcr == "C") nrett = -nrett; @@ -1868,16 +1980,23 @@ void Visliq_app::write_general(TMask& m) } _lim->put("R16", crf24); - if (new_age_2000) + _lim->put("R20", autf24); + _lim->put("D1", dautf24); + if (compensabile) { const real criva(tt_ln.get(6)); - if (cr_res > ZERO) - { +// if (cr_res > ZERO) +// { + cr_res += autf24; cr_res -= crf24; cr_res -= criva; - } - if (cr_res < ZERO) - cr_res = ZERO; +// } +// if (cr_res < ZERO) +// cr_res = ZERO; + if (cr_res < ZERO) + sh.set_back_and_fore_color(COLOR_LTYELLOW, COLOR_DKRED, row, 7); + else + sh.set_back_and_fore_color(NORMAL_BACK_COLOR, NORMAL_COLOR, row, 7); } _lim->put("S3", descr); @@ -1897,8 +2016,10 @@ void Visliq_app::write_general(TMask& m) if (orimb != nrimb) _lim->put("R1", nrimb); _lim->put("R16", crf24); - _lim->put("S3", descr); - _lim->put("B0", ""); + _lim->put("R20", autf24); + _lim->put("D1", dautf24); + _lim->put("S3", descr); + _lim->zero("B0"); _lim->rewrite(); } } @@ -1914,12 +2035,14 @@ void Visliq_app::write_general(TMask& m) tt_ln.add(r0abs.string(),1); tt_ln.add(sr0 == 0 ? "" : (sr0 > 0 ? "D" : "C"), 2); + tt_ln.add((_lim->get_real("R1")).string(),3); tt_ln.add(r5abs.string(),4); tt_ln.add(sr5 == 0 ? "" : (sr5 > 0 ? "D" : "C"),5); - tt_ln.add(cr_res.string(),8); - - // sh.force_update(row); + if ( cr_res < ZERO) + tt_ln.add("",10); + else + tt_ln.add(cr_res.string(),10); } _from_one = false; } // for mese liq. (riga sheet) diff --git a/cg/cg5500.h b/cg/cg5500.h index 849e402a7..858008180 100755 --- a/cg/cg5500.h +++ b/cg/cg5500.h @@ -56,7 +56,10 @@ protected: // handlers static bool set_ditta(TMask_field&, KEY); static bool set_ragsoc(TMask_field&, KEY); + static bool print_handler(TMask_field&, KEY); static bool sel_mese_sh1 (TMask_field&, KEY); + static bool enable_date (TMask_field&, KEY); + static bool check_date (TMask_field&, KEY); static bool sel_mese_sh2 (TMask_field&, KEY); static bool ch_year_handler(TMask_field& f, KEY key); @@ -64,6 +67,7 @@ protected: static bool sheet_action(TSheet_field& s, int r, KEY k); static bool vers_action(TSheet_field& s, int r, KEY k); + virtual void print(); public: virtual bool firm_change_enabled() const { return false; } @@ -95,6 +99,7 @@ public: // 2 palle TMask* get_main_mask() { return _mask; } + int year() { return _year;} bool select_butt(TMask& m); TTable* del() { return _del; } @@ -102,11 +107,15 @@ public: // riaggiusta la liquidazione del mese dato void recalc_liq_data(TViswin* v, real& rimb, real& rett, real& vers, real& acc, real& varimp, real& impnonver, real& credspec, - TString& d1, TString& d2, TString& d3, TDate& date, - TString& abi, TString& cab, TString& con); + TString& d1, TString& d2, TString& d3, TString& d4, + TDate& date, TString& abi, TString& cab, TString& con, + real & credito_utilizzato_F24, + real & credito_autorizzato_F24, TDate & data_autorizzazione); // Calcolo del credito utilizzato IVA ed F24 real credito_utilizzato(int year, int month) const; + // Calcolo del credito autorizzato F24 + real credito_autorizzato(int year, int month) const; // riaggiusta le liquidazioni successive se serve void recalc_next_liq(int start_month, TSheet_field* sl, TSheet_field* sv); diff --git a/cg/cg5500a.h b/cg/cg5500a.h index cccaa55ee..9eb5cd22e 100755 --- a/cg/cg5500a.h +++ b/cg/cg5500a.h @@ -1,32 +1,37 @@ -#define F_CODDITTA 151 -#define F_RAGSOC 152 -#define F_MONTHS 153 -#define F_TRIMS 154 -#define F_YEAR 155 -#define F_VISLIQ1 156 -#define F_VISLIQ2 157 -#define F_CREDPREC 158 -#define F_VISFLQ 109 -#define F_ACCONTO 110 -#define F_RIMBORSO 111 -#define F_RETTIFICA 112 -#define F_DESCR1 113 -#define F_DESCR2 114 -#define F_DEBCRE 115 -#define F_SELECT 116 -#define F_DELDATE 117 -#define F_DELIMP 118 -#define F_DELABI 119 -#define F_DELCAB 120 -#define F_DELCON 121 -#define F_PERIODOM 122 -#define F_PERIODOT 123 -#define F_DESCR3 124 -#define F_VARIMP 125 -#define F_VARIMP_DC 126 -#define F_IMPNONVER 127 -#define F_CREDSPEC 128 +#define F_CODDITTA 151 +#define F_RAGSOC 152 +#define F_MONTHS 153 +#define F_TRIMS 154 +#define F_YEAR 155 +#define F_VISLIQ1 156 +#define F_VISLIQ2 157 +#define F_CREDPREC 158 +#define F_CREDUTILIN 159 +#define F_VISFLQ 109 +#define F_ACCONTO 110 +#define F_RIMBORSO 111 +#define F_RETTIFICA 112 +#define F_DESCR1 113 +#define F_DESCR2 114 +#define F_DEBCRE 115 +#define F_SELECT 116 +#define F_DELDATE 117 +#define F_DELIMP 118 +#define F_DELABI 119 +#define F_DELCAB 120 +#define F_DELCON 121 +#define F_PERIODOM 122 +#define F_PERIODOT 123 +#define F_DESCR3 124 +#define F_VARIMP 125 +#define F_VARIMP_DC 126 +#define F_IMPNONVER 127 +#define F_CREDSPEC 128 +#define F_CREDUTIL 129 +#define F_CREDAUT 130 +#define F_DATAAUT 131 +#define F_DESCR4 132 -#define F_CODDITTA2 201 -#define F_RAGSOC2 202 +#define F_CODDITTA2 201 +#define F_RAGSOC2 202 diff --git a/cg/cg5500a.rep b/cg/cg5500a.rep new file mode 100644 index 000000000..a13aeffde --- /dev/null +++ b/cg/cg5500a.rep @@ -0,0 +1,197 @@ + + + Stampa prospetto liquidazione + +
+ + + + "Stampa Prospetto Liquidazione " +#ANNO @ ++ +#THIS ! + + + + + + #SYSTEM.DATE + + + + + + #PAGE + + + + #SYSTEM.RAGSOC + + + + "!CF" +GET_FIRM_DATA + + + + "!IVA" +GET_FIRM_DATA + + + + + + + + + + + + + + + + + #108 @ +#109 @ +- +#THIS ! + +
+
+
+
+ + + + + + + + + + + + + CODTAB[5,7] + +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • + + + + R0 + #THIS @ +0 +E; +IF +"D" +ELSE +0 +#THIS @ +- +#THIS ! +"C" +THEN +#201 ! + + + R1 + + + R5 + #THIS @ +0 +E; +IF +"D" +ELSE +0 +#THIS @ +- +#THIS ! +"C" +THEN +#202 ! + + + R15 + + + R16 + + + R20 + + + D1 + + + #H0.110 @ +#113 @ - +#114 @ - +#115 @ + +DUP +#THIS ! +#H0.110 ! + + + S3 + + + +
  • +
    + + + + + + + + + + + + +
    +
    + + + + + + + + + + + + + +
    + USE LIM +FROM CODTAB=#ANNO +TO CODTAB=#ANNO + \ No newline at end of file diff --git a/cg/cg5500b.rep b/cg/cg5500b.rep new file mode 100644 index 000000000..7081327b3 --- /dev/null +++ b/cg/cg5500b.rep @@ -0,0 +1,129 @@ + + + Stampa prospetto versamenti + +
    + + + + "Stampa Prospetto Versamenti " +#ANNO @ ++ +#THIS ! + + + + + + #SYSTEM.DATE + + + + + + + #PAGE + + + + #SYSTEM.RAGSOC + + + + "!CF" +GET_FIRM_DATA + + + + "!IVA" +GET_FIRM_DATA + + + + + + + +
    +
    +
    +
    + + + + + + + + + CODTAB[10,11] + +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
  • + + + + D0 + + + S7 + + + S8 + + + S9 + + + R0 + #THIS @ +0 +E; +IF +"D" +ELSE +0 +#THIS @ +- +#THIS ! +"C" +THEN +#201 ! + +
  • +
    + + + + + + + + +
    +
    + + + + + + + + + +
    + USE %DEL +FROM CODTAB=#FILTER +TO CODTAB=#FILTER + \ No newline at end of file diff --git a/cg/cg5500b.uml b/cg/cg5500b.uml index f283e9d09..3d89a5f6d 100755 --- a/cg/cg5500b.uml +++ b/cg/cg5500b.uml @@ -9,6 +9,18 @@ PICTURE TOOL_SAVEREC MESSAGE EXIT,K_SAVE END +BUTTON DLG_PRINT 2 2 +BEGIN + PROMPT 1 1 "Stampa" + PICTURE TOOL_PRINT +END + +BUTTON DLG_SETPRINT 2 2 +BEGIN + PROMPT 2 1 "Imposta" + PICTURE TOOL_SETPRINT +END + #include ENDPAGE @@ -39,7 +51,12 @@ END CURRENCY F_CREDPREC 15 BEGIN - PROMPT 1 5 "Credito compensabile inizio anno " + PROMPT 1 5 "Credito inizio anno " +END + +CURRENCY F_CREDUTILIN 15 +BEGIN + PROMPT 1 6 "Credito utilizzato a inizio anno " END SPREADSHEET F_VISLIQ1 -2 -1 @@ -52,7 +69,9 @@ BEGIN ITEM "IVA rettifiche@15" ITEM "D/C@3" ITEM "Credito\nutilizzato IVA@15" - ITEM "Credito\nutilizzato F24@15" + ITEM "Credito utilizzato F24@20" + ITEM "Credito anno in corso\nautorizzato F24@20" + ITEM "Data autorizzazione@20" ITEM "Credito IVA\nresiduo@15" ITEM "Descrizione@50" END @@ -93,24 +112,30 @@ END ENDPAGE ENDMASK -PAGE "Prospetto mensile" -1 -1 50 10 +TOOLBAR "topbar" 0 0 0 2 + +#include + +ENDPAGE + +PAGE "Prospetto mensile" -1 -1 75 22 STRING 101 20 BEGIN - PROMPT 1 1 "Mese " + PROMPT 1 1 "Mese " FLAGS "D" END CURRENCY 102 15 BEGIN - PROMPT 1 2 "Risultato " + PROMPT 1 2 "Risultato " FLAGS "D" END LIST 103 1 10 BEGIN - PROMPT 35 2 "" + PROMPT 57 2 "" ITEM " | " ITEM "D|Debito" ITEM "C|Credito" @@ -119,20 +144,20 @@ END CURRENCY 104 15 BEGIN - PROMPT 1 3 "IVA rimborso " + PROMPT 1 3 "IVA rimborso " PICTURE "." GROUP 11 END CURRENCY 105 15 BEGIN - PROMPT 1 4 "IVA rettifiche " + PROMPT 1 4 "IVA rettifiche " GROUP 11 END LIST 106 1 10 BEGIN - PROMPT 35 4 "" + PROMPT 57 4 "" ITEM " | " ITEM "D|Debito" ITEM "C|Credito" @@ -142,48 +167,62 @@ END CURRENCY 107 15 BEGIN - PROMPT 1 3 "Credito utilizzato IVA " + PROMPT 1 5 "Credito utilizzato IVA " FLAGS "D" GROUP 12 END CURRENCY 108 15 BEGIN - PROMPT 1 4 "Credito utilizzato F24 " + PROMPT 1 6 "Credito utilizzato F24 anno precedente " GROUP 12 + FLAGS "D" END CURRENCY 109 15 BEGIN - PROMPT 1 5 "Credito IVA residuo " + PROMPT 1 7 "Credito autorizzato F24 anno in corso " + GROUP 12 + FLAGS "D" +END + +DATE 110 +BEGIN + PROMPT 1 8 "Data di autorizzazione " + GROUP 12 + CHECTYPE REQUIRED + WARNING "La data è obbligatoria" + FLAGS "D" +END + +CURRENCY 111 15 +BEGIN + PROMPT 1 9 "Credito IVA residuo " FLAGS "D" GROUP 12 END -STRING 110 50 35 +STRING 112 50 35 BEGIN - PROMPT 1 6 "Descr. " + PROMPT 1 10 "Descr. " GROUP 12 -END - -BUTTON DLG_OK 10 2 -BEGIN - PROMPT -13 -1 "" -END - -BUTTON DLG_CANCEL 10 2 -BEGIN - PROMPT -23 -1 "" + FLAGS "D" END BUTTON 100 10 2 BEGIN - PROMPT -33 -1 "Dettaglio" + PROMPT -11 -1 "Dettaglio" END ENDPAGE ENDMASK +TOOLBAR "topbar" 0 0 0 2 + +#include + +ENDPAGE + PAGE "Prospetto versamenti" -1 -1 50 12 STRING 101 20 @@ -254,20 +293,9 @@ BEGIN PROMPT 1 6 "Versamenti " END -BUTTON DLG_OK 10 2 -BEGIN - PROMPT -13 -1 "" -END - -BUTTON DLG_CANCEL 10 2 -BEGIN - PROMPT -23 -1 "" -END - BUTTON 100 10 2 BEGIN - PROMPT -33 -1 "Dettaglio" -// FLAGS "H" + PROMPT -11 -1 "Dettaglio" END ENDPAGE diff --git a/cg/cg5500d.uml b/cg/cg5500d.uml index 37404e554..1e5f79ec5 100755 --- a/cg/cg5500d.uml +++ b/cg/cg5500d.uml @@ -237,6 +237,39 @@ BEGIN PICTURE "." END +/* gruppo 9: edit credito IVA utilizzato un F24*/ + +CURRENCY F_CREDUTIL 15 +BEGIN + PROMPT 2 17 "Credito IVA compensabile detratto in F24 : " + GROUP 9 + FLAGS "H" + PICTURE "." +END + +/* gruppo 9: edit credito IVA autorizzato in F24 */ + +CURRENCY F_CREDAUT 15 +BEGIN + PROMPT 2 17 "Credito IVA autorizzato in F24 : " + GROUP 10 + FLAGS "H" + PICTURE "." +END + +DATE F_DATAAUT +BEGIN + PROMPT 50 17 "il " + GROUP 10 + FLAGS "H" +END + +STRING F_DESCR4 60 +BEGIN + PROMPT 2 18 "Descrizione " + GROUP 10 + FLAGS "H" +END ENDPAGE