From 948465ced7cbf13b875443d2c97c1bfc90db4ec6 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 21 Dec 2012 06:57:15 +0000 Subject: [PATCH] Nuova stampa registri IVA con IVA per cassa Correzione nc in prima nota git-svn-id: svn://10.65.10.50/branches/R_10_00@22771 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg0500.cpp | 12 +- cg/cg2100.cpp | 9 +- cg/cg2100c.uml | 2 + cg/cg2102.cpp | 119 +-- cg/cg2102.h | 5 +- cg/cg2103.h | 24 +- cg/cg2106.cpp | 3 + cg/cg2107.cpp | 163 +++-- cg/cg4300.cpp | 1902 ++++++++++++++++++++++++------------------------ cg/cg4301.cpp | 82 ++- cg/cg4400.cpp | 378 ++++++---- cg/cg4400.h | 9 +- cg/cglib01.h | 5 +- cg/cglib03.cpp | 4 +- 14 files changed, 1471 insertions(+), 1246 deletions(-) diff --git a/cg/cg0500.cpp b/cg/cg0500.cpp index 6f7b1b753..a6673c478 100755 --- a/cg/cg0500.cpp +++ b/cg/cg0500.cpp @@ -196,12 +196,13 @@ void TCaus_app::causale_vendite() set_descr(i++, TR("C Di ricavo")); set_descr(i++, TR("C Iva vendite")); set_descr(i++, TR("C Iva non detraibile")); - set_descr(i++, TR("C Imp. esenti")); + set_descr(i++, TR("C Imp. esenti")); // 5 set_descr(i++, TR("C Imp. non imponibili")); set_descr(i++, TR("C Imp. non soggetti")); set_descr(i++, TR("C Ritenute fiscali")); set_descr(i++, TR("C Ritenute soc.")); - set_descr(i++, TR("C Iva ad esig.diff.")); + set_descr(i++, TR("C Iva ad esig.diff.")); // 10 + set_descr(i++, TR("C Iva per cassa")); _tipo_des = vendita; carica_righe_libere(i); } @@ -216,13 +217,14 @@ void TCaus_app::causale_acquisti() set_descr(i++, TR("C Fornitori")); set_descr(i++, TR("C Di costo")); set_descr(i++, TR("C Iva acquisti")); - set_descr(i++, TR("C Iva non detraibile")); - set_descr(i++, TR("C Imp. esenti")); + set_descr(i++, TR("C Iva non detraibile")); + set_descr(i++, TR("C Imp. esenti")); // 5 set_descr(i++, TR("C Imp. non imponibili")); set_descr(i++, TR("C Imp. non soggetti")); set_descr(i++, TR("C Ritenute fiscali")); set_descr(i++, TR("C Ritenute soc.")); - set_descr(i++, TR("C Iva ad esig.diff.")); + set_descr(i++, TR("C Iva ad esig.diff.")); // 10 + set_descr(i++, TR("C Iva per cassa")); _tipo_des = acquisto; carica_righe_libere(i); } diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index 2a38463c9..811757a93 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -90,6 +90,7 @@ TMask* TPrimanota_application::load_mask(int n) m->set_handler(F_CODIVA, main_codiva_handler); if (_liqdiff) m->set_handler(F_LIQDIFF, liqdiff_handler); + m->set_handler(F_IVAXCASSA, ivaxcassa_handler); m->set_handler(F_OCCASEDIT, occas_handler); m->set_handler(F_SOLAIVA, solaiva_handler); m->set_handler(F_SHEETIVA, iva_handler); @@ -395,7 +396,7 @@ bool TPrimanota_application::read_caus(const char* cod, int year) } else { - if (nriga >= 2 && nriga <= RIGA_IVA_DIFFERITA) + if (nriga >= 2 && nriga <= RIGA_IVA_PER_CASSA) continue; // Conti per IVA detraibile e non, ritenute sociali e fiscali const char tipo = nriga == 1 ? 'T' : ' '; @@ -800,8 +801,10 @@ void TPrimanota_application::init_insert_mode(TMask& m) { occas_mask().reset(); m.hide(F_OCCASEDIT); +#ifdef PRORATA100 m.hide(F_ADJUST_PRORATA); // In inserimento non puo' esistere un pro-rata errato! - if (causale().soloiva()) +#endif + if (causale().soloiva()) m.set(F_SOLAIVA, "X", true); // Propone movimento di sola iva if (iva() == iva_acquisti && causale().intra()) m.field(F_RITFIS).set_prompt(PR("IVA intracomun. ")); @@ -905,6 +908,7 @@ void TPrimanota_application::init_modify_mode(TMask& m) m.disable(SK_TIPORIGA); // Disabilita la sua modifica } + #ifdef PRORATA100 // Non controllare il prorata durante la cancellazione automatica if (autodeleting() != 0x3) { @@ -927,6 +931,7 @@ void TPrimanota_application::init_modify_mode(TMask& m) } } } +#endif const TRectype& mov = get_relation()->curr(); if (!mov.empty()) diff --git a/cg/cg2100c.uml b/cg/cg2100c.uml index 824dfd4ee..6edff7bf1 100755 --- a/cg/cg2100c.uml +++ b/cg/cg2100c.uml @@ -703,11 +703,13 @@ BEGIN CHECKTYPE NORMAL END +#ifdef PRORATA100 BUTTON F_ADJUST_PRORATA 40 BEGIN PROMPT 1 -1 "Corre~zione automatica righe contabili" FLAGS "H" END +#endif ENDPAGE diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index a1e8f42f0..66d3fe677 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -1487,7 +1487,9 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k) if (d) { if (iva.mask().get_bool(F_LIQDIFF)) - cau.bill(ri = RIGA_IVA_DIFFERITA, c); + cau.bill(ri = RIGA_IVA_DIFFERITA, c); else + if (iva.mask().get_bool(F_IVAXCASSA)) + cau.bill(ri = RIGA_IVA_PER_CASSA, c); if (!c.ok()) cau.bill(ri = RIGA_IVA_DETRAIBILE, c); } @@ -1612,21 +1614,23 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k) if (!imposta.is_zero()) // Se c'e' imposta ... { // ... crea nuova riga per l'IVA TBill contoiva; - int ri; + int ri = 0; if (d) { if (iva.mask().get_bool(F_LIQDIFF)) - cau.bill(ri = RIGA_IVA_DIFFERITA, contoiva); + cau.bill(ri = RIGA_IVA_DIFFERITA, contoiva); else + if (iva.mask().get_bool(F_IVAXCASSA)) + cau.bill(ri = RIGA_IVA_PER_CASSA, contoiva); if (!contoiva.ok()) cau.bill(ri = RIGA_IVA_DETRAIBILE, contoiva); } else cau.bill(ri = RIGA_IVA_NON_DETRAIBILE, contoiva); - - const TString desc(cau.desc_agg(ri)); - cau.bill(ri, contoiva); - newposiva = a.set_cgs_row(-1, newiva, contoiva, desc, tipod); + + const TString desc(cau.desc_agg(ri)); + cau.bill(ri, contoiva); + newposiva = a.set_cgs_row(-1, newiva, contoiva, desc, tipod); } } else @@ -2242,7 +2246,14 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) const TDate oggi(TODAY); TDate dr(f.get()); // Data dell'operazione if (dr > oggi) + { +#ifdef DBG + if (!yesno_box(TR("La data dell'operazione è superiore quella di sistema:\nContinuare ugualmente?"))) + return false; +#else return f.error_box(TR("La data dell'operazione è superiore quella di sistema")); +#endif + } TMask& m = f.mask(); if (dr == oggi && m.query_mode() && !m.field(F_NUMREG).empty()) @@ -2922,46 +2933,53 @@ bool TPrimanota_application::main_codiva_handler(TMask_field& f, KEY key) return true; } +// Scandisce le righe IVA detraibili e forza il conto corretto in base ai flag IVA in testata +static void force_iva_det_bill() +{ + TSheet_field& cgs = app().cgs(); + TMask& mask = cgs.mask(); + + const TCausale& cau = app().causale(); + TBill contoiva; + int ri = 0; + if (mask.get_bool(F_LIQDIFF)) + cau.bill(ri = RIGA_IVA_DIFFERITA, contoiva); else + if (mask.get_bool(F_IVAXCASSA)) + cau.bill(ri = RIGA_IVA_PER_CASSA, contoiva); + if (ri <= 0 || !contoiva.ok()) + cau.bill(ri = RIGA_IVA_DETRAIBILE, contoiva); + + TToken_string conto(contoiva.string(0x3)); + const TString80 descragg(cau.desc_agg(ri)); + const int rowtype = cgs.cid2index(CG_ROWTYPE); + const int tp = cgs.cid2index(CG_TIPO); + const int gr = cgs.cid2index(CG_GRUPPO); + const int co = cgs.cid2index(CG_CONTO); + const int sc = cgs.cid2index(CG_SOTTOCONTO); + const int des = cgs.cid2index(CG_DESCR); + + FOR_EACH_SHEET_ROW(cgs, r, row) + { + const TString4 type(row->get(rowtype)); + if (type == "D") + { + row->add(conto.get(0), tp); + row->add(conto.get(), gr); + row->add(conto.get(), co); + row->add(conto.get(), sc); + row->add(conto.get(), sc + 1); + row->add(descragg, des); + } + } + cgs.force_update(); +} + // Handler of the F_LIQDIFF // Certified 99% bool TPrimanota_application::liqdiff_handler(TMask_field& f, KEY key) { if (key == K_SPACE && f.mask().is_running()) - { - TSheet_field & cgs = app().cgs(); - const bool liqdiff = f.get().full(); - const TCausale& cau = app().causale(); - TBill contoiva; - int ri; - - if (f.mask().get_bool(F_LIQDIFF)) - cau.bill(ri = RIGA_IVA_DIFFERITA, contoiva); - if (!contoiva.ok()) - cau.bill(ri = RIGA_IVA_DETRAIBILE, contoiva); - TToken_string conto(contoiva.string(0x3)); - const TString80 descragg(cau.desc_agg(ri)); - int rowtype = cgs.cid2index(CG_ROWTYPE); - int tp = cgs.cid2index(CG_TIPO); - int gr = cgs.cid2index(CG_GRUPPO); - int co = cgs.cid2index(CG_CONTO); - int sc = cgs.cid2index(CG_SOTTOCONTO); - int des = cgs.cid2index(CG_DESCR); - - FOR_EACH_SHEET_ROW(cgs, r, row) - { - const TString4 type(row->get(rowtype)); - if (type == "D") - { - row->add(conto.get(0), tp); - row->add(conto.get(), gr); - row->add(conto.get(), co); - row->add(conto.get(), sc); - row->add(conto.get(), sc + 1); - row->add(descragg, des); - } - } - cgs.force_update(); - } + force_iva_det_bill(); if (key == K_ENTER) { @@ -2972,6 +2990,23 @@ bool TPrimanota_application::liqdiff_handler(TMask_field& f, KEY key) return true; } +// Handler of the F_IVAXCASSA +// Certified 99% +bool TPrimanota_application::ivaxcassa_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE && f.mask().is_running()) + force_iva_det_bill(); + + if (key == K_ENTER) + { + if (f.get().full() && f.mask().get_bool(F_LIQDIFF)) + return f.error_box(TR("Non è ammesso selezionare IVA per cassa e liquidazione differita")); + } + + return true; +} + + // Riempie i campi valuta a zero in base agli altri void TPrimanota_application::gioca_cambi(int force) { diff --git a/cg/cg2102.h b/cg/cg2102.h index dacffd59f..24b3d59ad 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -103,6 +103,7 @@ class TPrimanota_application : public TRelation_application static bool ritsoc_handler(TMask_field& f, KEY key); static bool main_codiva_handler(TMask_field& f, KEY key); static bool liqdiff_handler(TMask_field& f, KEY key); + static bool ivaxcassa_handler(TMask_field& f, KEY key); static bool dataintra_handler(TMask_field& f, KEY key); static bool corrlire_handler(TMask_field& f, KEY key); static bool corrvaluta_handler(TMask_field& f, KEY key); @@ -137,7 +138,6 @@ class TPrimanota_application : public TRelation_application static bool recalc_handler(TMask_field& f, KEY key); static bool codcab_handler(TMask_field& f, KEY key); static bool tipopag_handler(TMask_field& f, KEY key); - static bool prorata_handler(TMask_field& f, KEY k); static bool linkdoc_handler(TMask_field& f, KEY k); static bool mastrino_handler(TMask_field& f, KEY k); @@ -278,8 +278,11 @@ protected: void renumber_partita(TMask& m, const char* oldp, const char* newp); void recalc_scadenze(const TDate& d); +#ifdef PRORATA100 + static bool prorata_handler(TMask_field& f, KEY k); bool test_prorata(); bool aggiusta_prorata(); +#endif int cerca_conto_cf(TBill& bill) const; diff --git a/cg/cg2103.h b/cg/cg2103.h index dc57007af..ccbdacf32 100755 --- a/cg/cg2103.h +++ b/cg/cg2103.h @@ -73,20 +73,20 @@ public: virtual ~TCausale() {} }; -#define RIGA_IVA_DETRAIBILE 3 -#define RIGA_IVA_NON_DETRAIBILE 4 -#define RIGA_IVA_DIFFERITA 10 - // Fatture -#define RIGA_RITENUTE_FISCALI 8 -#define RIGA_RITENUTE_SOCIALI 9 +#define RIGA_IVA_DETRAIBILE 3 +#define RIGA_IVA_NON_DETRAIBILE 4 +#define RIGA_RITENUTE_FISCALI 8 +#define RIGA_RITENUTE_SOCIALI 9 +#define RIGA_IVA_DIFFERITA 10 +#define RIGA_IVA_PER_CASSA 11 // Pagamenti -#define RIGA_ABBUONI_PASSIVI 9 -#define RIGA_ABBUONI_ATTIVI 10 -#define RIGA_SPESE 11 -#define RIGA_PAG_RITFIS 12 -#define RIGA_DIFFCAM 13 -#define RIGA_PAG_RITSOC 14 +#define RIGA_ABBUONI_PASSIVI 9 +#define RIGA_ABBUONI_ATTIVI 10 +#define RIGA_SPESE 11 +#define RIGA_PAG_RITFIS 12 +#define RIGA_DIFFCAM 13 +#define RIGA_PAG_RITSOC 14 #endif \ No newline at end of file diff --git a/cg/cg2106.cpp b/cg/cg2106.cpp index e94b88563..2ecec3c17 100755 --- a/cg/cg2106.cpp +++ b/cg/cg2106.cpp @@ -254,6 +254,8 @@ bool TPrimanota_application::colors_handler(TMask_field& f, KEY k) return true; } +#ifdef PRORATA100 + /////////////////////////////////////////////////////////// // Gestione cambiamento prorata /////////////////////////////////////////////////////////// @@ -348,3 +350,4 @@ bool TPrimanota_application::prorata_handler(TMask_field& f, KEY k) return TRUE; } +#endif diff --git a/cg/cg2107.cpp b/cg/cg2107.cpp index 7383f83dd..52e57d9e5 100755 --- a/cg/cg2107.cpp +++ b/cg/cg2107.cpp @@ -626,40 +626,87 @@ bool TEasySolder_mask::on_field_event(TOperable_field& o, TField_event e, long j static int nrigp_pagamento_locale(const TSolder_tree& st) { - const long nreg_mov = st.num_reg(); - const int nrig_mov = st.num_rig(); - const TToken_string& curr = *(TToken_string*)st.curr_node(); const int level = curr.items(); - if (level == 3) + if (level >= 3) { - const TRiga_scadenze* scad = st.scadenza(); - if (scad != NULL) // Vera scadenza + const long nreg_mov = st.num_reg(); + const int nrig_mov = st.num_rig(); + if (level == 3) { - for (int nrigp = scad->last(); nrigp > 0; nrigp = scad->pred(nrigp)) + const TRiga_scadenze* scad = st.scadenza(); + if (scad != NULL) // Vera scadenza { - const TRiga_partite& riga = scad->partita().riga(nrigp); - const long nreg_riga = riga.get_long(PART_NREG); - const int nrig_riga = riga.get_int(PART_NUMRIG); - if (nreg_riga == nreg_mov && nrig_riga == nrig_mov) - return nrigp; + for (int nrigp = scad->last(); nrigp > 0; nrigp = scad->pred(nrigp)) + { + const TRiga_partite& riga = scad->partita().riga(nrigp); + const long nreg_riga = riga.get_long(PART_NREG); + const int nrig_riga = riga.get_int(PART_NUMRIG); + if (nreg_riga == nreg_mov && nrig_riga == nrig_mov) + return nrigp; + } } + } else + if (level == 4) + { + // const int nrigp = st.pagamento()->get_int(PAGSCA_NRIGP); + int nrigp = 0; curr.get(3, nrigp); + const TRiga_partite& riga = st.partita()->riga(nrigp); + const long nreg_riga = riga.get_long(PART_NREG); + const int nrig_riga = riga.get_int(PART_NUMRIG); + if (nreg_riga == nreg_mov && nrig_riga == nrig_mov) + return nrigp; } - } else - if (level == 4) - { - const int nrigp = st.pagamento()->get_int(PAGSCA_NRIGP); - const TRiga_partite& riga = st.partita()->riga(nrigp); - const long nreg_riga = riga.get_long(PART_NREG); - const int nrig_riga = riga.get_int(PART_NUMRIG); - if (nreg_riga == nreg_mov && nrig_riga == nrig_mov) - return nrigp; } return 0; } -static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) +// Aggiunge una nota di credito non associata a fattura +static bool add_lonely_nc(TPartita& game, TSheet_field& sheet, int rigasheet) +{ + const int nrigp = game.first(); + if (nrigp <= 0) + return false; + + const TRiga_partite& riga = game.riga(nrigp); + if (riga.tipo() != tm_nota_credito) + return false; + + TToken_string& row = sheet.row(rigasheet); + row.add(game.codice_valuta(), sheet.cid2index(S_VALUTA)); + + const char expected_section = riga.get_char(PART_TIPOCF) == 'C' ? 'D' : 'A'; + + TImporto res = game.calcola_saldo(true); + res.normalize(expected_section); + set_row_currency(sheet, row, S_RESIDUO, res.valore()); + + TImporto tot = riga.importo(true); + tot.normalize(expected_section); + set_row_currency(sheet, row, S_TOTALE, tot.valore()); + + set_row_int(sheet, row, S_ANNO, game.anno()); + set_row_str(sheet, row, S_PARTITA, game.numero()); + set_row_int(sheet, row, S_RIGAF, TPartita::UNASSIGNED); + set_row_int(sheet, row, S_RATA, TPartita::UNASSIGNED); + set_row_int(sheet, row, S_RIGAP, 0); // Lasciare 0 e NON mettere assultamente nrigp o la scambia per pagamento! + set_row_str(sheet, row, S_DATASCAD, riga.get(PART_DATAPAG)); + if (game.in_valuta()) + { + TImporto reseur = riga.importo(false); + reseur.normalize(expected_section); + set_row_currency(sheet, row, S_RESIDUO_EUR, reseur.valore()); + } + set_row_str(sheet, row, S_NUMDOC, riga.get(PART_NUMDOC)); + set_row_str(sheet, row, S_DATADOC, riga.get(PART_DATADOC)); + const int nrow = sheet.items()-1; + sheet.disable_cell(nrow, S_SALDO); + + return true; +} + +static bool sheet_rate_filler(TTree& tree, void* jolly, word /* flags */) { const TSolder_tree& st = (const TSolder_tree&)tree; const TToken_string& curr = *(TToken_string*)st.curr_node(); @@ -667,30 +714,27 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) if (level < 3) return false; - const tipo_movimento tm = app().causale().tipomov(); - int nriga; curr.get(1, nriga); int nrata; curr.get(2, nrata); + if (level == 3 && nrata >= TPartita::UNASSIGNED) + return false; // Falso nodo dell'albero padre dei non assegnati + + TPartita& game = *st.partita(); + if (!same_values(st.codval(), game.codice_valuta())) + return false; // Scadenza in valuta diversa da quella selezionata + int nrigp = nrigp_pagamento_locale(st); - bool good_rat = level >= 3 && nrata > 0 && nrata < TPartita::UNASSIGNED; bool good_pag = level == 4 && nrigp > 0; - + const TRiga_scadenze* scad = good_rat ? st.scadenza() : NULL; - if (scad != NULL) + if (good_rat && scad == NULL) { - if (!same_values(st.codval(), scad->codice_valuta())) - return false; // Scadenza in valuta diversa da quella selezionata - } - else - { - if (good_rat) - { - CHECKD(false, "Rata nulla inattesa ", nrata); // Segnalazione 1867 - return false; - } + CHECKD(false, "Rata nulla inattesa ", nrata); // Segnalazione 1867 + return false; } + const tipo_movimento tm = app().causale().tipomov(); switch (tm) { case tm_nota_credito: @@ -701,13 +745,16 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) if (good_rat) { good_rat = nrigp <= 0 && !scad->chiusa() && !scad->get_bool(SCAD_BLOCCATA); + /* Commentato in quanto impedisce di saldare le note di credito if (good_rat) { + const char expected_section = scad->get_char(SCAD_TIPOCF) == 'C' ? 'D' : 'A'; TImporto res = scad->residuo(true); - res.normalize(scad->riga().sezione()); - if (res.valore() <= ZERO) // In realtà ha residuo negativo, per cui è chiusa! + res.normalize(expected_section); // res.normalize(scad->riga().sezione()); + if (res.valore () <= ZERO) // In realtà è chiusa! good_rat = false; } + */ } } else @@ -729,17 +776,24 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) break; } + TSheet_field& sheet = *(TSheet_field*)jolly; if (good_rat || good_pag) // Creo una nuova riga solo se necessario { - TPartita& game = *st.partita(); - TSheet_field& sheet = *(TSheet_field*)jolly; TToken_string& row = sheet.row(-1); - row.add(game.codice_valuta(), sheet.cid2index(S_VALUTA)); - if (good_rat) { - const TImporto res = tm == tm_insoluto ? scad->importo_pagato(true) : scad->residuo(true); + TImporto res; + if (tm == tm_insoluto) + { + res = scad->importo_pagato(true); + } + else + { + const char expected_section = scad->get_char(SCAD_TIPOCF) == 'C' ? 'D' : 'A'; + res = scad->residuo(true); + res.normalize(expected_section); + } set_row_currency(sheet, row, S_RESIDUO, res.valore()); const TImporto tot = scad->importo(true); set_row_currency(sheet, row, S_TOTALE, tot.valore()); @@ -749,7 +803,7 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) set_row_int(sheet, row, S_RATA, nrata); set_row_str(sheet, row, S_DATASCAD, scad->get(SCAD_DATASCAD)); set_row_str(sheet, row, S_MODOPAG, scad->get(SCAD_TIPOPAG)); // Solo proposta - if (scad->in_valuta()) + if (game.in_valuta()) { // Calcola il residuo rata utilizzando il cambio della fattura e non quello del pagamento const TImporto reseur = tm == tm_insoluto ? scad->importo_pagato(false) : scad->residuo(false); @@ -777,6 +831,9 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) } if (good_pag) { + if (!good_rat && nrigp > 1 && game.prima_riga(-1, tm_nota_credito) < nrigp) + add_lonely_nc(game, sheet, sheet.items()-1); + const TRiga_partite& rigp = game.riga(nrigp); set_row_int(sheet, row, S_RIGAP, nrigp); set_row_int(sheet, row, S_NREG, rigp.get_long(PART_NREG)); @@ -787,9 +844,7 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) if (!imp.is_zero()) { set_row_bool(sheet, row, S_SPUNTA, true); - - const TString& codval = rigp.get(PART_CODVAL); - if (is_true_value(codval)) + if (rigp.in_valuta()) { const real impval = pag.get_real(PAGSCA_IMPORTOVAL); set_row_currency(sheet, row, S_IMPORTO, impval); @@ -798,7 +853,7 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) else set_row_currency(sheet, row, S_IMPORTO, imp); } - set_row_str(sheet, row, S_SALDO, pag.get_char(PAGSCA_ACCSAL)=='S'?"X":""); + set_row_str(sheet, row, S_SALDO, (good_rat && pag.get_char(PAGSCA_ACCSAL)=='S') ? "X" : ""); set_row_int(sheet, row, S_MODOPAG, rigp.get_int(PART_TIPOPAG)); set_row_currency(sheet, row, S_RITFIS, pag.get_real(PAGSCA_RITENUTE)); set_row_currency(sheet, row, S_RITSOC, pag.get_real(PAGSCA_RITSOC)); @@ -820,6 +875,12 @@ static bool sheet_rate_filler(TTree& tree, void* jolly, word flags) } } } + else + { + // Nota di credito non assegnata e senza pagamenti successivi + if (level == 4 && nriga == TPartita::UNASSIGNED && game.last() == game.first()) + add_lonely_nc(game, sheet, -1); + } return false; } @@ -1039,9 +1100,9 @@ void TEasySolder_mask::init(const TBill& conto, long numreg, int numrig) } else app().causale().bill(2, controbill); - if (controbill.ok()) + if (controbill.gruppo() > 0) // con controbill.ok() non presentava assolutamente i conti parziali { - controbill.set(*this, G_GRUPPOC, G_CONTOC, G_SOTTOCONTOC); + controbill.set(*this, G_GRUPPOC, G_CONTOC, G_SOTTOCONTOC, 0, G_DESCONTOC); } else { diff --git a/cg/cg4300.cpp b/cg/cg4300.cpp index aff31412a..65ab3592f 100755 --- a/cg/cg4300.cpp +++ b/cg/cg4300.cpp @@ -1,946 +1,956 @@ -// ------------------------------------------------------------ -// Calcolo liquidazioni -// Part 1: interfaccia -// fv 21-1-94 -// ------------------------------------------------------------ - -#include "cg4300.h" -#include "cg4300a.h" - -#include -#include -#include -#include -#include - -#include - -// Methods of _Iva11Array -bool _Iva11Array::add(const real& val, const char* fld_name, int num_file) -{ - const bool is_key = TAssoc_array::is_key(fld_name); - if (!is_key) - TAssoc_array::add(fld_name,(_Iva11Item*)new _Iva11Item,is_key); - _Iva11Item& bi = (_Iva11Item&)find(fld_name); - bi.value() += val; - if (num_file != LF_TAB1100A) - bi.file() = num_file; - - return true; -} - -bool _Iva11Array::sub(const real& val, const char* fld_name, int num_file) -{ - const real v1 = -val; - return add(v1,fld_name, num_file); -} - - -void _Iva11Array::zero(const char* fld_name) -{ - const bool is_key = TAssoc_array::is_key(fld_name); - if (!is_key) - TAssoc_array::add(fld_name,(_Iva11Item*) new _Iva11Item,is_key); - _Iva11Item& bi = (_Iva11Item&)find(fld_name); - bi.value() = ZERO; -} - -// Methods of _ProrataItem - -// Calcola prorata con percentuale identificata dall'anno passato -// se la % prorata relativa all'anno indicato non esiste, ritorna 0 -real _ProrataItem::calc_prorata(const real& acq, const char* year) -{ - real prorata; - const real& perc = percentuale(year); - if (perc != INVALID_PRORATA && perc > ZERO) - { - if (perc < CENTO) - { - prorata = acq * perc / CENTO; - prorata.round(TCurrency::get_firm_dec()); - } - else - prorata = acq; - } - return prorata; -} - -// Ritorna la % prorata relativa all'anno indicato. Se non esiste internamente -// viene ritornato INVALID_PRORATA -const real& _ProrataItem::percentuale(const char* year) const -{ - const real* p = (const real*)_percentuali.objptr(year); - if (p && !p->is_zero()) - return *p; - return INVALID_PRORATA; -} - -inline TLiquidazione_app& app() -{ return (TLiquidazione_app&)main_app(); } - -TLiquidazione_app::TLiquidazione_app(int m) : -_ditte(NULL), _selected(16), -_year(4), _nomiditte(100), _menu(m), _firm_bookmark(-1) -{ - _isprint = _is_interactive = _canprint = true; - _isplafond = _printonly = _is_visliq = false; - _isvent = _isagricolo = _isbenzinaro = _isviaggio = _isdiff = false; - _row = 1; _what = all; _comp_acconto = false; - _isriepilogo = FALSE; _calcall = false; - _recalc_only = _recalc_regis = _isfinal = _isregis = false; - _stampa_vers = _stampa_acc = false; - _recalc = needed; -} - -bool TLiquidazione_app::user_create() -{ - // vediamo se c'e' il messaggio per calcolare in batch - TMailbox mail; - TProgind* pnd = NULL; - TMessage* msg = mail.next_s("RCL"); - TToken_string subj(36); - _is_interactive = msg == NULL; - bool is_header = TRUE; - int bodylen; - TDate printdate; - TString filename; - long ditta; - bool nocalc = FALSE; - - _prind = NULL; - - if (msg != NULL) subj = msg->body(); - - if (_is_interactive) - pnd = new TProgind (3,TR("Preparazione archivi"), false, true); - else - begin_wait(); - - _nditte = new TRelation(LF_NDITTE); - _nditte->add(LF_ATTIV,"CODDITTA=CODDITTA"); - _nditte_r = &(_nditte->curr()); - _att_r = &(_nditte->curr(LF_ATTIV)); - - _ditte = new TArray_sheet(-1, -1, -4, -4, TR("Selezione Ditte"), - HR("@1|Cod.@5R|Ragione Sociale@50|Vers.|Agr.Min")); - _n_ditte = 0l; - - // Caro tab11, ricordati che un giorno sarai un file unico! - _tab11 = new TRelation(LF_TAB1100A); - _tab11->add(LF_TAB1100B,"TADITT=TADITT|TACATT=TACATT"); - _tab11->write_enable(LF_TAB1100B); // Senno' col fischio che scrive i records - - // prevediamo la data che usera'; se calcola la liq. di un altro anno - // si fottera' la frequenza versamenti - - if (_is_interactive) - { - TDate oggi(TODAY); - _year.format("%d",oggi.year()); - _month = oggi.month(); - TConfig conf(CONFIG_STUDIO); - _sind11 = conf.get_bool("Sind11"); - } - else // parse messaggio - { - _year = subj.get(0); - _month = subj.get_int(1); - ditta = subj.get_long(2); - char rcl = *(subj.get(3)); - _recalc_only = rcl == 'C'; - _recalc_regis = rcl == 'R' && atoi(_year) > 1997; - _is_visliq = rcl == 'V'; - // S/s = stampa senza ricalcolo (minuscolo = definitivo) - // L/l = stampa con ricalcolo se necessario (minuscolo = definitivo) - // C = solo ricalcolo - // R = solo ricalcolo per registri: aggiorna solo progressivi PRM e PRP. Non fa niente altro ne write_liq() ne pim, ne stampe... - // V = stampa ed ev. ricalcolo per visualizzazione - // s o l minuscoli = registro bollato - _isregis = (rcl == 'l' || rcl == 'L' || - rcl == 'S' || rcl == 's'); // stampa per registri - _isfinal = rcl == 'l' || rcl == 's'; // se l minuscolo, definitivo - nocalc = rcl == 'S' || rcl == 's'; - printdate = subj.get(4); - filename = subj.get(5); - char rliq = *(subj.get(6)); - _riepilogo = rliq == 'X'; - bodylen = subj.get_int(7); - is_header = subj.items() == 8; - printer().formlen(bodylen); - } - - if(pnd) pnd->addstatus(1); - - _rel = new TRelation(LF_MOV); - _rel->add(LF_RMOVIVA,"NUMREG=NUMREG"); - _rel->add(LF_PCON,"GRUPPO=GRUPPO|CONTO=CONTO",1,LF_RMOVIVA,AGR_PCON1); - _rel->add(LF_PCON,"GRUPPO=GRUPPO|CONTO=CONTO|SOTTOCONTO=SOTTOCONTO",1,LF_RMOVIVA,AGR_PCON2); - _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS"); - -// _cur = new TCursor(_rel, "", 2); - _cur = new TCursor(_rel, "", 4); - - _ver = new TInteressi_IVA_table(); - _pim = new TTable("PIM"); - _pis = new TTable("PIS"); - _prm = new TTable("PRM"); - _prp = new TTable("PRP"); - _pum = new TTable("PUM"); - _pam = new TTable("PAM"); - _pom = new TTable("POM"); - _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); - _pcon_1 = &_cur->file(-AGR_PCON1); - _pcon_2 = &_cur->file(-AGR_PCON2); - - _pim_r = &(_pim->curr()); - _pis_r = &(_pis->curr()); - _prm_r = &(_prm->curr()); - _prp_r = &(_prp->curr()); - _plm_r = &(_plm->curr()); - _pia_r = &(_pia->curr()); - _pum_r = &(_pum->curr()); - _pam_r = &(_pam->curr()); - _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()); - _reg_r = &(_reg->curr()); - _mov_r = &(_mov->curr()); - _rmoviva_r = &(_cur->curr(LF_RMOVIVA)); - _pcon_1_r = &(_cur->curr(-AGR_PCON1)); - _pcon_2_r = &(_cur->curr(-AGR_PCON2)); - - // ACHTUNG: tutti i _codatt (codici attivita') sono - // in realta' composti dal codice attivita' piu' il - // tipo attivita' (1 o 2) - // sarebbe piu' saggio fare 2 campi ma ci vuole 1 vita - - _pim_anno = new TRecfield(*_pim_r,"CODTAB",0,3); - _pim_codatt = new TRecfield(*_pim_r,"CODTAB",4,9); - _pim_codreg = new TRecfield(*_pim_r,"CODTAB",10,12); - _pim_mese = new TRecfield(*_pim_r,"CODTAB",13,14); - _pim_tipocr = new TRecfield(*_pim_r,"CODTAB",15,15); - _pim_codiva = new TRecfield(*_pim_r,"CODTAB",16,19); - _pim_tipodet = new TRecfield(*_pim_r,"CODTAB",20,20); - _pis_anno = new TRecfield(*_pis_r,"CODTAB",0,3); - _pis_codatt = new TRecfield(*_pis_r,"CODTAB",4,9); - _pis_codreg = new TRecfield(*_pis_r,"CODTAB",10,12); - _pis_mese = new TRecfield(*_pis_r,"CODTAB",13,14); - _pis_tipocr = new TRecfield(*_pis_r,"CODTAB",15,15); - _pis_codiva = new TRecfield(*_pis_r,"CODTAB",16,19); - _pis_tipodet = new TRecfield(*_pis_r,"CODTAB",20,20); - _prm_anno = new TRecfield(*_prm_r,"CODTAB",0,3); - _prm_codatt = new TRecfield(*_prm_r,"CODTAB",4,9); - _prm_codreg = new TRecfield(*_prm_r,"CODTAB",10,12); - _prm_mese = new TRecfield(*_prm_r,"CODTAB",13,14); - _prm_tipocr = new TRecfield(*_prm_r,"CODTAB",15,15); - _prm_codiva = new TRecfield(*_prm_r,"CODTAB",16,19); - _prm_tipodet = new TRecfield(*_prm_r,"CODTAB",20,20); - _prp_anno = new TRecfield(*_prp_r,"CODTAB",0,3); - _prp_codatt = new TRecfield(*_prp_r,"CODTAB",4,9); - _prp_codreg = new TRecfield(*_prp_r,"CODTAB",10,12); - _prp_mese = new TRecfield(*_prp_r,"CODTAB",13,14); - _prp_tipocr = new TRecfield(*_prp_r,"CODTAB",15,15); - _prp_codiva = new TRecfield(*_prp_r,"CODTAB",16,19); - _prp_tipodet = new TRecfield(*_prp_r,"CODTAB",20,20); - _pum_anno = new TRecfield(*_pum_r,"CODTAB",0,3); - _pum_codatt = new TRecfield(*_pum_r,"CODTAB",4,9); - _pum_mese = new TRecfield(*_pum_r,"CODTAB",10,11); - _pam_anno = new TRecfield(*_pam_r,"CODTAB",0,3); - _pam_codatt = new TRecfield(*_pam_r,"CODTAB",4,9); - _pam_mese = new TRecfield(*_pam_r,"CODTAB",10,11); - _pom_anno = new TRecfield(*_pom_r,"CODTAB",0,3); - _pom_codatt = new TRecfield(*_pom_r,"CODTAB",4,9); - _pom_mese = new TRecfield(*_pom_r,"CODTAB",10,11); - _ppa_year = new TRecfield(*_ppa_r,"CODTAB",0,3); - _ppa_codatt = new TRecfield(*_ppa_r,"CODTAB",4,9); - _ppa_month = new TRecfield(*_ppa_r,"CODTAB",10,11); - _ppa_kind = new TRecfield(*_ppa_r,"CODTAB",12,12); - - _plm_anno = new TRecfield(*_plm_r,"CODTAB",0,3); - _plm_codatt = new TRecfield(*_plm_r,"CODTAB",4,9); - _plm_mese = new TRecfield(*_plm_r,"CODTAB",10,11); - - _pia_anno = new TRecfield(*_pia_r,"CODTAB",0,3); - _pia_codatt = new TRecfield(*_pia_r,"CODTAB",4,9); - _pia_mese = new TRecfield(*_pia_r,"CODTAB",10,11); - _pia_codord = new TRecfield(*_pia_r,"CODTAB",12,15); - _pia_codcom = new TRecfield(*_pia_r,"CODTAB",16,19); - - _pla_ditta = new TRecfield(*_pla_r,"CODTAB",0,4); - _pla_anno = new TRecfield(*_pla_r,"CODTAB",5,8); - _pla_codatt = new TRecfield(*_pla_r,"CODTAB",9,14); - - _del_ditta = new TRecfield(*_del_r,"CODTAB",0,4); - _del_anno = new TRecfield(*_del_r,"CODTAB",5,8); - _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); - - __firm = TApplication::get_firm(); - - if (pnd) pnd->addstatus(1); - - if (_is_interactive) - { - build_nomiditte(pnd); - build_ditte_sheet(all); - } - - if (pnd) pnd->addstatus(1); - - TApplication::set_firm(__firm); - set_real_picture(REAL_PICTURE); - set_magic_currency(TRUE); - - if (!_is_interactive) - { - TTemp_window w(TASK_WIN); - if (_recalc_only) - _isprint = FALSE; - //else printer().set_export_file(filename, is_header, headerlen); - else printer().set_export_file(filename, is_header); - - // calcola liquidazione - printer().setdate(printdate); - _recalc = nocalc ? never : needed; - TApplication::set_firm(ditta); - - if (!look_lia()) - { end_wait(); return FALSE; } - - TIva_round ir; // Imposta arrotondamento iva - ir.set_default_iva_mode(atoi(_year), _month > 12, ditta); - - _nditte->zero(); - _nditte_r->put("CODDITTA", ditta); - _nditte->read(); - _freqviva = _lia->get("S7"); - - TRectype& mov = _cur->curr(); - TRectype from(_cur->curr()); from.zero(); - TRectype to(from); - TDate f(1, 1, atoi(_year)); - TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); - -// qui se liquidazione diff. su ditta si parte da year-4 e filtro su anno o data liquid diff sul movim nel periodo - t.set_end_month(); - from.put(MOV_DATAREG, f); - to.put(MOV_DATAREG, t); - _cur->setregion(from, to); - _canprint = is_month_ok_strict(_month) || _month == 13; - _isannual = _isriepilogo = _month == 13; - - //modifica del 03/05/1995 - bool need_refresh = false; - for (int m = 1; m < _month; m++) - { - if (is_month_ok_strict(m) && (!look_lim(m) || !_lim->get_bool("B0"))) - { - need_refresh = true; - break; - } - } - if (need_refresh) - _recalc = ever; - - // determina attivita' prevalente e istanzia cazzuole - // per vedere che Kazzo di liquidazione calcolare - const TString8 attprev = _nditte->curr().get("CODATTPREV"); - TString16 key; - - key.format("%ld|%s", ditta, (const char *) attprev); - - const TRectype & atts = cache().get(LF_ATTIV, key); - - // istanzia benzinaro - _isbenzinaro = atts.get_bool("ART74_4"); - - // riaggiusta relazione - _nditte->read(); - - for (int mese = 1; mese < _month; mese++) - { - if ((is_month_plain(mese) && !(_freqviva == "T" && _recalc_regis)) || _recalc == ever) - update_firm(mese); - } - if (is_month_plain(_month) || _month == 13) - update_firm(_month); - - if (_isprint && _descr_arr.items() > 0) - print(); - - if (!nocalc) - { - // 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; - } - } - - TApplication::set_firm(__firm); - end_wait(); - user_destroy(); - } - else - delete pnd; - - return _is_interactive; -} - -bool TLiquidazione_app::user_destroy() -{ - delete _ditte; - - delete _pim_anno; - delete _pim_codreg; - delete _pim_mese; - delete _pim_tipocr; - delete _pim_codiva; - delete _pim_codatt; - delete _pim_tipodet; - delete _pis_anno; - delete _pis_codreg; - delete _pis_mese; - delete _pis_tipocr; - delete _pis_codiva; - delete _pis_codatt; - delete _pis_tipodet; - delete _prm_anno; - delete _prm_codreg; - delete _prm_mese; - delete _prm_tipocr; - delete _prm_codiva; - delete _prm_codatt; - delete _prm_tipodet; - delete _prp_anno; - delete _prp_codreg; - delete _prp_mese; - delete _prp_tipocr; - delete _prp_codiva; - delete _prp_codatt; - delete _prp_tipodet; - delete _ppa_year; - delete _ppa_codatt; - delete _ppa_month; - delete _ppa_kind; - delete _plm_anno; - delete _plm_codatt; - delete _plm_mese; - delete _pia_anno; - delete _pia_codatt; - delete _pia_mese; - delete _pia_codord; - delete _pia_codcom; - delete _pum_anno; - delete _pum_codatt; - delete _pum_mese; - delete _pam_codatt; - delete _pam_anno; - delete _pam_mese; - delete _pom_codatt; - delete _pom_anno; - delete _pom_mese; - delete _lim_anno; - delete _lim_mese; - delete _lam_anno; - delete _lam_mese; - delete _pla_anno; - delete _pla_codatt; - delete _del_ditta; - delete _del_anno; - delete _del_mese; - delete _del_tipo; - - delete _ver; - delete _pim; - delete _pis; - delete _prm; - delete _prp; - delete _pum; - delete _pam; - delete _pom; - delete _ppa; - delete _plm; - delete _pia; - delete _lim; - delete _lam; - delete _pla; - delete _del; - - delete _tab11; - delete _nditte; - delete _rel; - delete _cur; - - return true; -} - -bool TLiquidazione_app::set_print(int) -{ - _descr_arr.destroy(); - _errors.destroy(); - _reg_arr.destroy(); - _codiva_arr.destroy(); - - switch(_menu) - { - case 1: // liquidazione - _isprint = true; - while (set_liquidazione()) - { - if (_selected.ones()) - return recalc_all() && _isprint; - else - warning_box(TR("Nessuna ditta selezionata!")); - } - break; - case 2: // estrazione deleghe - _isprint = FALSE; - _selected.reset(); - _ditte->check(-1, FALSE); - build_ditte_sheet(all); - while (set_deleghe()) - { - if (_calcall || _selected.ones() > 0l) - { - extract_deleghe(); - return _isprint; - } - else warning_box(TR("Nessuna ditta selezionata!")); - } - break; - case 3: // calcolo acconto - _isprint = TRUE; - _month = 12; - _selected.reset(); - _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)) - { - if (_calcall || _selected.ones() > 0l) - { - recalc_acconti(inf, ina); - return _isprint; - } - else warning_box(TR("Nessuna ditta selezionata!")); - } - break; - } - return FALSE; -} - -long TLiquidazione_app::select_firm_range(long from, long to, wht freq) -{ - if (to < from) - to = 99999L; - - for (int i = 0; i < _ditte->items(); i++) - { - if (_ditte->row_disabled(i)) - continue; - - TToken_string& d = _ditte->row(i); - const char vers = d.get_char(3); - if (vers == '?' || (freq == mnt && vers == 'T') || (freq == trimestre && vers == 'M')) - continue; - - const long cod = d.get_long(1); - if (cod >= from && cod <= to) - { - _selected.set(i); - _ditte->check(i); - } - else - { - _selected.set(i,FALSE); - _ditte->uncheck(i); - } - } - - return _selected.ones(); -} - -// ----------------------------------------------- handlers - -bool TLiquidazione_app::ch_year_handler(TMask_field& f, KEY key) -{ - if (key == K_TAB && f.focusdirty()) - { - TWait_cursor hourglass; - app().reset_choices(f.mask()); - app().set_year(f.get()); - app().build_nomiditte(); - app().build_ditte_sheet(f.mask().source_file().ends_with("cg4300a.msk") ? - (wht)f.mask().get_int(CG43_RDB_VERS) : all); - } - return true; -} - -void TLiquidazione_app::build_nomiditte(TProgind* pnd) -{ - _nomiditte.destroy(); - // ricostruire _nomiditte e rifare build_ditte_sheet - TLocalisamfile& dt = _nditte->lfile(); - - for (dt.first(); !dt.eof(); dt.next()) - { - // check no archivi - bool good = prefix().exist(dt.get_long("CODDITTA")); - - if (good) - { - // check no parametri liquidazione - if (!look_lia(dt.get_long("CODDITTA"))) - good = FALSE; - } - 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("B2")); - } - else - { - d->add("??"); - d->add("??"); - } - _nomiditte.add(d); - } - if (pnd) - pnd->addstatus(1); -} - -bool TLiquidazione_app::to_ditt_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (key == K_F9) - { - TArray_sheet* sh = app().get_ditte_sheet(); - - sh->disable_check(); - sh->disable(DLG_USER); - if (sh->run() == K_ENTER) - { - app().select_firm_range(m.get_long(CG43_FLD_DFR),sh->row(sh->selected()).get_long(1), - (wht)m.get_int(CG43_RDB_VERS)); - app().set_choice_limits(m); - } - sh->enable(DLG_USER); - } - if (key == K_TAB && f.focusdirty()) - { - const long l = app().select_firm_range(m.get_long(CG43_FLD_DFR), - m.get_long(CG43_FLD_DTO), - (wht)m.get_int(CG43_RDB_VERS)); - app().set_choice_limits(m); - m.set(CG43_FLD_SELECTED, l); - } - return true; -} - -bool TLiquidazione_app::fr_ditt_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (key == K_F9) - { - TArray_sheet* sh = app().get_ditte_sheet(); - - sh->disable_check(); - sh->disable(DLG_USER); - if (sh->run() == K_ENTER) - { - app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(CG43_FLD_DTO), - (wht)m.get_int(CG43_RDB_VERS)); - app().set_choice_limits(m); - } - sh->enable(DLG_USER); - } - else if (key == K_TAB && f.focusdirty()) - { - const long l = app().select_firm_range(m.get_long(CG43_FLD_DFR), - m.get_long(CG43_FLD_DTO), - (wht)m.get_int(CG43_RDB_VERS)); - - app().set_choice_limits(m); - m.set(CG43_FLD_SELECTED, l); - } - return true; -} - -bool TLiquidazione_app::what_freq_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - int month = f.mask().get_int(CG43_LST_MESE); - if (f.get()[0] == '3') // trimestre intelligente - { - if (month > 3) - while (!is_trim(month)) month--; - else - month = 3; - - f.mask().set(CG43_LST_TRIM,month); - } - app().set_month(month); - app().build_ditte_sheet((wht)atoi(f.get())); - app().reset_choices(f.mask()); - } - return true; -} - -bool TLiquidazione_app::lst_tm_handler(TMask_field& f, KEY key) -{ - if (f.to_check(key)) - { - const int m = atoi(f.get()); - TMask& msk = f.mask(); - - if (m == 13) - { - msk.field(CG43_LST_CALC).set("2"); - msk.field(CG43_LST_CALC).disable(); - } - else - // Abilita il ricalcolo solo se non e' richiesta esplicitamente la sola stampa - if (!msk.get_bool(CG43_CHK_FINAL)) - msk.field(CG43_LST_CALC).enable(); - - const bool change = (app()._month != 13 && m == 13) || (app()._month == 13 && m != 13); - if (change) - { - TWait_cursor hourglass; - app().reset_choices(f.mask()); - app().set_month(m); - app().build_ditte_sheet(f.mask().source_file().ends_with("cg4300a.msk") ? - (wht)f.mask().get_int(CG43_RDB_VERS) : all); - } - } - return true; -} - -bool TLiquidazione_app::select_button(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - app()._ditte->enable_check(); - // seleziona e aggiungi alle gia' selezionate - if (app()._ditte->run() == K_ENTER) - { - const long itms = app()._ditte->items(); - for (long j = 0l; j < itms; j++) - app()._selected.set(j, app()._ditte->checked(j)); - app().set_choice_limits(f.mask()); - } - } - return true; -} - -bool TLiquidazione_app::reset_button(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - app().reset_choices(f.mask()); - return true; -} - -bool TLiquidazione_app::chk_final_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - TMask& m = f.mask(); - // Abilita solo se il mese di ricalcolo e' != 13 (annuale) e non e' checkkato il campo - const int vers = m.get_int(CG43_RDB_VERS); - const int mese = vers == 3 ? m.get_int(CG43_LST_TRIM) : m.get_int(CG43_LST_MESE); - const bool abilita = !m.get_bool(CG43_CHK_FINAL) && mese != 13; - m.enable(CG43_LST_CALC, abilita); - } - return true; -} - -void TLiquidazione_app::reset_choices(TMask& m) -{ - _selected.reset(); - _ditte->check(-1, FALSE); - if (m.source_file().ends_with("cg4300a.msk")) - { - const long ditta = get_firm(); - m.set(CG43_FLD_DFR, ditta, 0x2); - m.set(CG43_FLD_DTO, ditta, 0x2); - - wht freq = all; - if (look_lia(ditta, false, m.get_int(CG43_FLD_ANNO))) - { - freq = _lia->get_char("S7") == 'T' ? trimestre : mnt; - if (m.get_int(CG43_RDB_VERS) != freq) - m.set(CG43_RDB_VERS, freq, 0x3); - } - else - freq = (wht)m.get_int(CG43_RDB_VERS); - select_firm_range(ditta, ditta, freq); - set_choice_limits(m); - } -} - -void TLiquidazione_app::set_choice_limits(TMask& m) -{ - long first = 0, last = 0; - for (int i = 0; i < _ditte->items(); i++) - { - if (_selected[i]) - { - const long dit = _ditte->row(i).get_long(1); - if (first <= 0) first = dit; - if (last < dit) last = dit; - } - } - m.set(CG43_FLD_DFR, first, 0x2); - m.set(CG43_FLD_DTO, last, 0x2); - m.set(CG43_FLD_SELECTED, _selected.ones()); -} - -void TLiquidazione_app::build_ditte_sheet(wht what) -{ - // build sheet - const int items = _nomiditte.items(); - _ditte->destroy(); - _what = what; - for (int i = 0; i < items; i++) - { - TToken_string* d = new TToken_string(64); - *d = (TToken_string&)_nomiditte[i]; - const char vers = d->get_char(2); - const bool agr = d->get_char(3) == 'X'; - - bool unselectable = vers == '?' || (_year > "1997" && _month < 13 && agr); - if ((what == mnt && vers == 'T') || (what == trimestre && vers == 'M')) - continue; - - d->insert(" |", 0); - - const long pos = _ditte->add(d); - if (unselectable) - _ditte->disable_row(pos); - else - { - _ditte->enable_row(pos); - if (_selected[i]) - _ditte->check(pos); - } - } -} - - -// ---------------------------------------------------- - -bool TLiquidazione_app::set_liquidazione() -{ - TMask m("cg4300a"); - - m.set_handler(CG43_FLD_DTO, to_ditt_handler); - m.set_handler(CG43_FLD_DFR, fr_ditt_handler); - m.set_handler(CG43_RDB_VERS, what_freq_handler); - m.set_handler(CG43_FLD_ANNO, ch_year_handler); - m.set_handler(CG43_LST_MESE, lst_tm_handler); - m.set_handler(CG43_LST_TRIM, lst_tm_handler); - m.set_handler(CG43_BUT_SEL, select_button); - m.set_handler(CG43_BUT_ANN, reset_button); - m.set_handler(CG43_CHK_FINAL, chk_final_handler); - - m.set(CG43_FLD_ANNO, _year); - - // stampa abilitata per default - m.set(CG43_CHK_STAMPA,"X"); - - _month = m.get_int(CG43_LST_MESE); - - m.set(CG43_RDB_VERS, _what); - - const KEY k = m.run(); - if (k == K_ENTER) - { - // handlers have set everything - _month = _what == trimestre ? m.get_int(CG43_LST_TRIM) : - m.get_int(CG43_LST_MESE); - - _year = m.get(CG43_FLD_ANNO); - _date = m.get(CG43_FLD_DATA); - _isprint = m.get_bool(CG43_CHK_STAMPA); - _recalc = (recalc)m.get_long(CG43_LST_CALC); - _printonly = m.get_bool(CG43_CHK_FINAL); - - if (_isprint) printer().setdate(_date); - if (_printonly) _recalc = never; - } - return k == K_ENTER; -} - -int cg4300(int argc, char* argv[]) -{ - TApplication::check_parameters(argc, argv); - - const char* title = TR("Liquidazione IVA"); - int menu = 1; - - if (argc > 2) - { - const char mode = argv[2][1]; - switch (mode) - { - case 'A': - title = TR("Calcolo acconti"); - menu = 3; - break; - case 'C': - title = TR("Ricalcolo progressivi IVA"); - break; - case 'D': - title = TR("Estrazione versamenti"); - menu = 2; - break; - case 'S': - title = TR("Stampa liquidazione"); - break; - default: - break; - } - } - - TLiquidazione_app* main_app = new TLiquidazione_app(menu); - main_app->run(argc, argv, title); - delete main_app; - return true; -} +// ------------------------------------------------------------ +// Calcolo liquidazioni +// Part 1: interfaccia +// fv 21-1-94 +// ------------------------------------------------------------ + +#include "cg4300.h" +#include "cg4300a.h" + +#include +#include +#include +#include +#include + +#include + +// Methods of _Iva11Array +bool _Iva11Array::add(const real& val, const char* fld_name, int num_file) +{ + const bool is_key = TAssoc_array::is_key(fld_name); + if (!is_key) + TAssoc_array::add(fld_name,(_Iva11Item*)new _Iva11Item,is_key); + _Iva11Item& bi = (_Iva11Item&)find(fld_name); + bi.value() += val; + if (num_file != LF_TAB1100A) + bi.file() = num_file; + + return true; +} + +bool _Iva11Array::sub(const real& val, const char* fld_name, int num_file) +{ + const real v1 = -val; + return add(v1,fld_name, num_file); +} + + +void _Iva11Array::zero(const char* fld_name) +{ + const bool is_key = TAssoc_array::is_key(fld_name); + if (!is_key) + TAssoc_array::add(fld_name,(_Iva11Item*) new _Iva11Item,is_key); + _Iva11Item& bi = (_Iva11Item&)find(fld_name); + bi.value() = ZERO; +} + +// Methods of _ProrataItem + +// Calcola prorata con percentuale identificata dall'anno passato +// se la % prorata relativa all'anno indicato non esiste, ritorna 0 +real _ProrataItem::calc_prorata(const real& acq, const char* year) +{ + real prorata; + const real& perc = percentuale(year); + if (perc != INVALID_PRORATA && perc > ZERO) + { + if (perc < CENTO) + { + prorata = acq * perc / CENTO; + prorata.round(TCurrency::get_firm_dec()); + } + else + prorata = acq; + } + return prorata; +} + +// Ritorna la % prorata relativa all'anno indicato. Se non esiste internamente +// viene ritornato INVALID_PRORATA +const real& _ProrataItem::percentuale(const char* year) const +{ + const real* p = (const real*)_percentuali.objptr(year); + if (p && !p->is_zero()) + return *p; + return INVALID_PRORATA; +} + +inline TLiquidazione_app& app() +{ return (TLiquidazione_app&)main_app(); } + +TLiquidazione_app::TLiquidazione_app(int m) : +_ditte(NULL), _selected(16), +_year(4), _nomiditte(100), _menu(m), _firm_bookmark(-1) +{ + _isprint = _is_interactive = _canprint = true; + _isplafond = _printonly = _is_visliq = false; + _isvent = _isagricolo = _isbenzinaro = _isviaggio = _isdiff = false; + _row = 1; _what = all; _comp_acconto = false; + _isriepilogo = false; _calcall = false; + _recalc_only = _recalc_regis = _isfinal = _isregis = false; + _stampa_vers = _stampa_acc = false; + _recalc = needed; +} + +bool TLiquidazione_app::user_create() +{ + bool is_header = true; + int bodylen = 60; + TDate printdate; + TString filename; + long ditta = 0; + bool nocalc = false; + + _prind = NULL; + + // vediamo se c'e' il messaggio per calcolare in batch + TMailbox mail; + TMessage* msg = mail.next_s("RCL"); + _is_interactive = msg == NULL; + + TToken_string subj; + if (!_is_interactive) + subj = msg->body(); +#ifdef DBG + else if (argv(2)[1] == 'C') + { + subj = "2012|12|9058|R|12-12-2012|c:/Temp/110|X|60"; + _is_interactive = false; + } +#endif + + + TProgind* pnd = NULL; + if (_is_interactive) + pnd = new TProgind (3,TR("Preparazione archivi"), false, true); + else + begin_wait(); + + _nditte = new TRelation(LF_NDITTE); + _nditte->add(LF_ATTIV,"CODDITTA=CODDITTA"); + _nditte_r = &(_nditte->curr()); + _att_r = &(_nditte->curr(LF_ATTIV)); + + _ditte = new TArray_sheet(-1, -1, -4, -4, TR("Selezione Ditte"), + HR("@1|Cod.@5R|Ragione Sociale@50|Vers.|Agr.Min")); + _n_ditte = 0l; + + // Caro tab11, ricordati che un giorno sarai un file unico! + _tab11 = new TRelation(LF_TAB1100A); + _tab11->add(LF_TAB1100B,"TADITT=TADITT|TACATT=TACATT"); + _tab11->write_enable(LF_TAB1100B); // Senno' col fischio che scrive i records + + // prevediamo la data che usera'; se calcola la liq. di un altro anno + // si fottera' la frequenza versamenti + + if (_is_interactive) + { + TDate oggi(TODAY); + _year.format("%d",oggi.year()); + _month = oggi.month(); + TConfig conf(CONFIG_STUDIO); + _sind11 = conf.get_bool("Sind11"); + } + else // parse messaggio + { + _year = subj.get(0); + _month = subj.get_int(1); + ditta = subj.get_long(2); + char rcl = *(subj.get(3)); + _recalc_only = rcl == 'C'; + _recalc_regis = rcl == 'R' && atoi(_year) > 1997; + _is_visliq = rcl == 'V'; + // S/s = stampa senza ricalcolo (minuscolo = definitivo) + // L/l = stampa con ricalcolo se necessario (minuscolo = definitivo) + // C = solo ricalcolo + // R = solo ricalcolo per registri: aggiorna solo progressivi PRM e PRP. Non fa niente altro ne write_liq() ne pim, ne stampe... + // V = stampa ed ev. ricalcolo per visualizzazione + // s o l minuscoli = registro bollato + _isregis = (rcl == 'l' || rcl == 'L' || + rcl == 'S' || rcl == 's'); // stampa per registri + _isfinal = rcl == 'l' || rcl == 's'; // se l minuscolo, definitivo + nocalc = rcl == 'S' || rcl == 's'; + printdate = subj.get(4); + filename = subj.get(5); + char rliq = *(subj.get(6)); + _riepilogo = rliq == 'X'; + bodylen = subj.get_int(7); + is_header = subj.items() == 8; + printer().formlen(bodylen); + } + + if(pnd) pnd->addstatus(1); + + _rel = new TRelation(LF_MOV); + _rel->add(LF_RMOVIVA,"NUMREG=NUMREG"); + _rel->add(LF_PCON,"GRUPPO=GRUPPO|CONTO=CONTO",1,LF_RMOVIVA,AGR_PCON1); + _rel->add(LF_PCON,"GRUPPO=GRUPPO|CONTO=CONTO|SOTTOCONTO=SOTTOCONTO",1,LF_RMOVIVA,AGR_PCON2); + _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS"); + + _cur = new TCursor(_rel, "", 4); // Was _cur = new TCursor(_rel, "", 2); + + _ver = new TInteressi_IVA_table(); + _pim = new TTable("PIM"); + _pis = new TTable("PIS"); + _prm = new TTable("PRM"); + _prp = new TTable("PRP"); + _pum = new TTable("PUM"); + _pam = new TTable("PAM"); + _pom = new TTable("POM"); + _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); + _pcon_1 = &_cur->file(-AGR_PCON1); + _pcon_2 = &_cur->file(-AGR_PCON2); + + _pim_r = &(_pim->curr()); + _pis_r = &(_pis->curr()); + _prm_r = &(_prm->curr()); + _prp_r = &(_prp->curr()); + _plm_r = &(_plm->curr()); + _pia_r = &(_pia->curr()); + _pum_r = &(_pum->curr()); + _pam_r = &(_pam->curr()); + _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()); + _reg_r = &(_reg->curr()); + _mov_r = &(_mov->curr()); + _rmoviva_r = &(_cur->curr(LF_RMOVIVA)); + _pcon_1_r = &(_cur->curr(-AGR_PCON1)); + _pcon_2_r = &(_cur->curr(-AGR_PCON2)); + + // ACHTUNG: tutti i _codatt (codici attivita') sono + // in realta' composti dal codice attivita' piu' il + // tipo attivita' (1 o 2) + // sarebbe piu' saggio fare 2 campi ma ci vuole 1 vita + + _pim_anno = new TRecfield(*_pim_r,"CODTAB",0,3); + _pim_codatt = new TRecfield(*_pim_r,"CODTAB",4,9); + _pim_codreg = new TRecfield(*_pim_r,"CODTAB",10,12); + _pim_mese = new TRecfield(*_pim_r,"CODTAB",13,14); + _pim_tipocr = new TRecfield(*_pim_r,"CODTAB",15,15); + _pim_codiva = new TRecfield(*_pim_r,"CODTAB",16,19); + _pim_tipodet = new TRecfield(*_pim_r,"CODTAB",20,20); + _pis_anno = new TRecfield(*_pis_r,"CODTAB",0,3); + _pis_codatt = new TRecfield(*_pis_r,"CODTAB",4,9); + _pis_codreg = new TRecfield(*_pis_r,"CODTAB",10,12); + _pis_mese = new TRecfield(*_pis_r,"CODTAB",13,14); + _pis_tipocr = new TRecfield(*_pis_r,"CODTAB",15,15); + _pis_codiva = new TRecfield(*_pis_r,"CODTAB",16,19); + _pis_tipodet = new TRecfield(*_pis_r,"CODTAB",20,20); + _prm_anno = new TRecfield(*_prm_r,"CODTAB",0,3); + _prm_codatt = new TRecfield(*_prm_r,"CODTAB",4,9); + _prm_codreg = new TRecfield(*_prm_r,"CODTAB",10,12); + _prm_mese = new TRecfield(*_prm_r,"CODTAB",13,14); + _prm_tipocr = new TRecfield(*_prm_r,"CODTAB",15,15); + _prm_codiva = new TRecfield(*_prm_r,"CODTAB",16,19); + _prm_tipodet = new TRecfield(*_prm_r,"CODTAB",20,20); + _prp_anno = new TRecfield(*_prp_r,"CODTAB",0,3); + _prp_codatt = new TRecfield(*_prp_r,"CODTAB",4,9); + _prp_codreg = new TRecfield(*_prp_r,"CODTAB",10,12); + _prp_mese = new TRecfield(*_prp_r,"CODTAB",13,14); + _prp_tipocr = new TRecfield(*_prp_r,"CODTAB",15,15); + _prp_codiva = new TRecfield(*_prp_r,"CODTAB",16,19); + _prp_tipodet = new TRecfield(*_prp_r,"CODTAB",20,20); + _pum_anno = new TRecfield(*_pum_r,"CODTAB",0,3); + _pum_codatt = new TRecfield(*_pum_r,"CODTAB",4,9); + _pum_mese = new TRecfield(*_pum_r,"CODTAB",10,11); + _pam_anno = new TRecfield(*_pam_r,"CODTAB",0,3); + _pam_codatt = new TRecfield(*_pam_r,"CODTAB",4,9); + _pam_mese = new TRecfield(*_pam_r,"CODTAB",10,11); + _pom_anno = new TRecfield(*_pom_r,"CODTAB",0,3); + _pom_codatt = new TRecfield(*_pom_r,"CODTAB",4,9); + _pom_mese = new TRecfield(*_pom_r,"CODTAB",10,11); + _ppa_year = new TRecfield(*_ppa_r,"CODTAB",0,3); + _ppa_codatt = new TRecfield(*_ppa_r,"CODTAB",4,9); + _ppa_month = new TRecfield(*_ppa_r,"CODTAB",10,11); + _ppa_kind = new TRecfield(*_ppa_r,"CODTAB",12,12); + + _plm_anno = new TRecfield(*_plm_r,"CODTAB",0,3); + _plm_codatt = new TRecfield(*_plm_r,"CODTAB",4,9); + _plm_mese = new TRecfield(*_plm_r,"CODTAB",10,11); + + _pia_anno = new TRecfield(*_pia_r,"CODTAB",0,3); + _pia_codatt = new TRecfield(*_pia_r,"CODTAB",4,9); + _pia_mese = new TRecfield(*_pia_r,"CODTAB",10,11); + _pia_codord = new TRecfield(*_pia_r,"CODTAB",12,15); + _pia_codcom = new TRecfield(*_pia_r,"CODTAB",16,19); + + _pla_ditta = new TRecfield(*_pla_r,"CODTAB",0,4); + _pla_anno = new TRecfield(*_pla_r,"CODTAB",5,8); + _pla_codatt = new TRecfield(*_pla_r,"CODTAB",9,14); + + _del_ditta = new TRecfield(*_del_r,"CODTAB",0,4); + _del_anno = new TRecfield(*_del_r,"CODTAB",5,8); + _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); + + __firm = TApplication::get_firm(); + + if (pnd) pnd->addstatus(1); + + if (_is_interactive) + { + build_nomiditte(pnd); + build_ditte_sheet(all); + } + + if (pnd) pnd->addstatus(1); + + TApplication::set_firm(__firm); + set_real_picture(REAL_PICTURE); + set_magic_currency(TRUE); + + if (!_is_interactive) + { + TTemp_window w(TASK_WIN); + if (_recalc_only) + _isprint = FALSE; + //else printer().set_export_file(filename, is_header, headerlen); + else + printer().set_export_file(filename, is_header); + + // calcola liquidazione + printer().setdate(printdate); + _recalc = nocalc ? never : needed; + TApplication::set_firm(ditta); + + if (!look_lia()) + { end_wait(); return FALSE; } + + TIva_round ir; // Imposta arrotondamento iva + ir.set_default_iva_mode(atoi(_year), _month > 12, ditta); + + _nditte->zero(); + _nditte_r->put("CODDITTA", ditta); + _nditte->read(); + _freqviva = _lia->get("S7"); + + TRectype& mov = _cur->curr(); + TRectype from(_cur->curr()); from.zero(); + TRectype to(from); + TDate f(1, 1, atoi(_year)); + TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); + +// qui se liquidazione diff. su ditta si parte da year-4 e filtro su anno o data liquid diff sul movim nel periodo + t.set_end_month(); + from.put(MOV_DATAREG, f); + to.put(MOV_DATAREG, t); + _cur->setregion(from, to); + _canprint = is_month_ok_strict(_month) || _month == 13; + _isannual = _isriepilogo = _month == 13; + + //modifica del 03/05/1995 + bool need_refresh = false; + for (int m = 1; m < _month; m++) + { + if (is_month_ok_strict(m) && (!look_lim(m) || !_lim->get_bool("B0"))) + { + need_refresh = true; + break; + } + } + if (need_refresh) + _recalc = ever; + + // determina attivita' prevalente e istanzia cazzuole + // per vedere che Kazzo di liquidazione calcolare + const TString8 attprev = _nditte->curr().get("CODATTPREV"); + TString16 key; + + key.format("%ld|%s", ditta, (const char *) attprev); + + const TRectype & atts = cache().get(LF_ATTIV, key); + + // istanzia benzinaro + _isbenzinaro = atts.get_bool("ART74_4"); + + // riaggiusta relazione + _nditte->read(); + + for (int mese = 1; mese < _month; mese++) + { + if ((is_month_plain(mese) && !(_freqviva == "T" && _recalc_regis)) || _recalc == ever) + update_firm(mese); + } + if (is_month_plain(_month) || _month == 13) + update_firm(_month); + + if (_isprint && _descr_arr.items() > 0) + print(); + + if (!nocalc) + { + // 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; + } + } + + TApplication::set_firm(__firm); + end_wait(); + user_destroy(); + } + else + delete pnd; + + return _is_interactive; +} + +bool TLiquidazione_app::user_destroy() +{ + delete _ditte; + + delete _pim_anno; + delete _pim_codreg; + delete _pim_mese; + delete _pim_tipocr; + delete _pim_codiva; + delete _pim_codatt; + delete _pim_tipodet; + delete _pis_anno; + delete _pis_codreg; + delete _pis_mese; + delete _pis_tipocr; + delete _pis_codiva; + delete _pis_codatt; + delete _pis_tipodet; + delete _prm_anno; + delete _prm_codreg; + delete _prm_mese; + delete _prm_tipocr; + delete _prm_codiva; + delete _prm_codatt; + delete _prm_tipodet; + delete _prp_anno; + delete _prp_codreg; + delete _prp_mese; + delete _prp_tipocr; + delete _prp_codiva; + delete _prp_codatt; + delete _prp_tipodet; + delete _ppa_year; + delete _ppa_codatt; + delete _ppa_month; + delete _ppa_kind; + delete _plm_anno; + delete _plm_codatt; + delete _plm_mese; + delete _pia_anno; + delete _pia_codatt; + delete _pia_mese; + delete _pia_codord; + delete _pia_codcom; + delete _pum_anno; + delete _pum_codatt; + delete _pum_mese; + delete _pam_codatt; + delete _pam_anno; + delete _pam_mese; + delete _pom_codatt; + delete _pom_anno; + delete _pom_mese; + delete _lim_anno; + delete _lim_mese; + delete _lam_anno; + delete _lam_mese; + delete _pla_anno; + delete _pla_codatt; + delete _del_ditta; + delete _del_anno; + delete _del_mese; + delete _del_tipo; + + delete _ver; + delete _pim; + delete _pis; + delete _prm; + delete _prp; + delete _pum; + delete _pam; + delete _pom; + delete _ppa; + delete _plm; + delete _pia; + delete _lim; + delete _lam; + delete _pla; + delete _del; + + delete _tab11; + delete _nditte; + delete _rel; + delete _cur; + + return true; +} + +bool TLiquidazione_app::set_print(int) +{ + _descr_arr.destroy(); + _errors.destroy(); + _reg_arr.destroy(); + _codiva_arr.destroy(); + + switch(_menu) + { + case 1: // liquidazione + _isprint = true; + while (set_liquidazione()) + { + if (_selected.ones()) + return recalc_all() && _isprint; + else + warning_box(TR("Nessuna ditta selezionata!")); + } + break; + case 2: // estrazione deleghe + _isprint = FALSE; + _selected.reset(); + _ditte->check(-1, FALSE); + build_ditte_sheet(all); + while (set_deleghe()) + { + if (_calcall || _selected.ones() > 0l) + { + extract_deleghe(); + return _isprint; + } + else warning_box(TR("Nessuna ditta selezionata!")); + } + break; + case 3: // calcolo acconto + _isprint = TRUE; + _month = 12; + _selected.reset(); + _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)) + { + if (_calcall || _selected.ones() > 0l) + { + recalc_acconti(inf, ina); + return _isprint; + } + else warning_box(TR("Nessuna ditta selezionata!")); + } + break; + } + return FALSE; +} + +long TLiquidazione_app::select_firm_range(long from, long to, wht freq) +{ + if (to < from) + to = 99999L; + + for (int i = 0; i < _ditte->items(); i++) + { + if (_ditte->row_disabled(i)) + continue; + + TToken_string& d = _ditte->row(i); + const char vers = d.get_char(3); + if (vers == '?' || (freq == mnt && vers == 'T') || (freq == trimestre && vers == 'M')) + continue; + + const long cod = d.get_long(1); + if (cod >= from && cod <= to) + { + _selected.set(i); + _ditte->check(i); + } + else + { + _selected.set(i,FALSE); + _ditte->uncheck(i); + } + } + + return _selected.ones(); +} + +// ----------------------------------------------- handlers + +bool TLiquidazione_app::ch_year_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB && f.focusdirty()) + { + TWait_cursor hourglass; + app().reset_choices(f.mask()); + app().set_year(f.get()); + app().build_nomiditte(); + app().build_ditte_sheet(f.mask().source_file().ends_with("cg4300a.msk") ? + (wht)f.mask().get_int(CG43_RDB_VERS) : all); + } + return true; +} + +void TLiquidazione_app::build_nomiditte(TProgind* pnd) +{ + _nomiditte.destroy(); + // ricostruire _nomiditte e rifare build_ditte_sheet + TLocalisamfile& dt = _nditte->lfile(); + + for (dt.first(); !dt.eof(); dt.next()) + { + // check no archivi + bool good = prefix().exist(dt.get_long("CODDITTA")); + + if (good) + { + // check no parametri liquidazione + if (!look_lia(dt.get_long("CODDITTA"))) + good = FALSE; + } + 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("B2")); + } + else + { + d->add("??"); + d->add("??"); + } + _nomiditte.add(d); + } + if (pnd) + pnd->addstatus(1); +} + +bool TLiquidazione_app::to_ditt_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + if (key == K_F9) + { + TArray_sheet* sh = app().get_ditte_sheet(); + + sh->disable_check(); + sh->disable(DLG_USER); + if (sh->run() == K_ENTER) + { + app().select_firm_range(m.get_long(CG43_FLD_DFR),sh->row(sh->selected()).get_long(1), + (wht)m.get_int(CG43_RDB_VERS)); + app().set_choice_limits(m); + } + sh->enable(DLG_USER); + } + if (key == K_TAB && f.focusdirty()) + { + const long l = app().select_firm_range(m.get_long(CG43_FLD_DFR), + m.get_long(CG43_FLD_DTO), + (wht)m.get_int(CG43_RDB_VERS)); + app().set_choice_limits(m); + m.set(CG43_FLD_SELECTED, l); + } + return true; +} + +bool TLiquidazione_app::fr_ditt_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + if (key == K_F9) + { + TArray_sheet* sh = app().get_ditte_sheet(); + + sh->disable_check(); + sh->disable(DLG_USER); + if (sh->run() == K_ENTER) + { + app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(CG43_FLD_DTO), + (wht)m.get_int(CG43_RDB_VERS)); + app().set_choice_limits(m); + } + sh->enable(DLG_USER); + } + else if (key == K_TAB && f.focusdirty()) + { + const long l = app().select_firm_range(m.get_long(CG43_FLD_DFR), + m.get_long(CG43_FLD_DTO), + (wht)m.get_int(CG43_RDB_VERS)); + + app().set_choice_limits(m); + m.set(CG43_FLD_SELECTED, l); + } + return true; +} + +bool TLiquidazione_app::what_freq_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + int month = f.mask().get_int(CG43_LST_MESE); + if (f.get()[0] == '3') // trimestre intelligente + { + if (month > 3) + while (!is_trim(month)) month--; + else + month = 3; + + f.mask().set(CG43_LST_TRIM,month); + } + app().set_month(month); + app().build_ditte_sheet((wht)atoi(f.get())); + app().reset_choices(f.mask()); + } + return true; +} + +bool TLiquidazione_app::lst_tm_handler(TMask_field& f, KEY key) +{ + if (f.to_check(key)) + { + const int m = atoi(f.get()); + TMask& msk = f.mask(); + + if (m == 13) + { + msk.field(CG43_LST_CALC).set("2"); + msk.field(CG43_LST_CALC).disable(); + } + else + // Abilita il ricalcolo solo se non e' richiesta esplicitamente la sola stampa + if (!msk.get_bool(CG43_CHK_FINAL)) + msk.field(CG43_LST_CALC).enable(); + + const bool change = (app()._month != 13 && m == 13) || (app()._month == 13 && m != 13); + if (change) + { + TWait_cursor hourglass; + app().reset_choices(f.mask()); + app().set_month(m); + app().build_ditte_sheet(f.mask().source_file().ends_with("cg4300a.msk") ? + (wht)f.mask().get_int(CG43_RDB_VERS) : all); + } + } + return true; +} + +bool TLiquidazione_app::select_button(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + app()._ditte->enable_check(); + // seleziona e aggiungi alle gia' selezionate + if (app()._ditte->run() == K_ENTER) + { + const long itms = app()._ditte->items(); + for (long j = 0l; j < itms; j++) + app()._selected.set(j, app()._ditte->checked(j)); + app().set_choice_limits(f.mask()); + } + } + return true; +} + +bool TLiquidazione_app::reset_button(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + app().reset_choices(f.mask()); + return true; +} + +bool TLiquidazione_app::chk_final_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + TMask& m = f.mask(); + // Abilita solo se il mese di ricalcolo e' != 13 (annuale) e non e' checkkato il campo + const int vers = m.get_int(CG43_RDB_VERS); + const int mese = vers == 3 ? m.get_int(CG43_LST_TRIM) : m.get_int(CG43_LST_MESE); + const bool abilita = !m.get_bool(CG43_CHK_FINAL) && mese != 13; + m.enable(CG43_LST_CALC, abilita); + } + return true; +} + +void TLiquidazione_app::reset_choices(TMask& m) +{ + _selected.reset(); + _ditte->check(-1, FALSE); + if (m.source_file().ends_with("cg4300a.msk")) + { + const long ditta = get_firm(); + m.set(CG43_FLD_DFR, ditta, 0x2); + m.set(CG43_FLD_DTO, ditta, 0x2); + + wht freq = all; + if (look_lia(ditta, false, m.get_int(CG43_FLD_ANNO))) + { + freq = _lia->get_char("S7") == 'T' ? trimestre : mnt; + if (m.get_int(CG43_RDB_VERS) != freq) + m.set(CG43_RDB_VERS, freq, 0x3); + } + else + freq = (wht)m.get_int(CG43_RDB_VERS); + select_firm_range(ditta, ditta, freq); + set_choice_limits(m); + } +} + +void TLiquidazione_app::set_choice_limits(TMask& m) +{ + long first = 0, last = 0; + for (int i = 0; i < _ditte->items(); i++) + { + if (_selected[i]) + { + const long dit = _ditte->row(i).get_long(1); + if (first <= 0) first = dit; + if (last < dit) last = dit; + } + } + m.set(CG43_FLD_DFR, first, 0x2); + m.set(CG43_FLD_DTO, last, 0x2); + m.set(CG43_FLD_SELECTED, _selected.ones()); +} + +void TLiquidazione_app::build_ditte_sheet(wht what) +{ + // build sheet + const int items = _nomiditte.items(); + _ditte->destroy(); + _what = what; + for (int i = 0; i < items; i++) + { + TToken_string* d = new TToken_string(64); + *d = (TToken_string&)_nomiditte[i]; + const char vers = d->get_char(2); + const bool agr = d->get_char(3) == 'X'; + + bool unselectable = vers == '?' || (_year > "1997" && _month < 13 && agr); + if ((what == mnt && vers == 'T') || (what == trimestre && vers == 'M')) + continue; + + d->insert(" |", 0); + + const long pos = _ditte->add(d); + if (unselectable) + _ditte->disable_row(pos); + else + { + _ditte->enable_row(pos); + if (_selected[i]) + _ditte->check(pos); + } + } +} + + +// ---------------------------------------------------- + +bool TLiquidazione_app::set_liquidazione() +{ + TMask m("cg4300a"); + + m.set_handler(CG43_FLD_DTO, to_ditt_handler); + m.set_handler(CG43_FLD_DFR, fr_ditt_handler); + m.set_handler(CG43_RDB_VERS, what_freq_handler); + m.set_handler(CG43_FLD_ANNO, ch_year_handler); + m.set_handler(CG43_LST_MESE, lst_tm_handler); + m.set_handler(CG43_LST_TRIM, lst_tm_handler); + m.set_handler(CG43_BUT_SEL, select_button); + m.set_handler(CG43_BUT_ANN, reset_button); + m.set_handler(CG43_CHK_FINAL, chk_final_handler); + + m.set(CG43_FLD_ANNO, _year); + + // stampa abilitata per default + m.set(CG43_CHK_STAMPA,"X"); + + _month = m.get_int(CG43_LST_MESE); + + m.set(CG43_RDB_VERS, _what); + + const KEY k = m.run(); + if (k == K_ENTER) + { + // handlers have set everything + _month = _what == trimestre ? m.get_int(CG43_LST_TRIM) : + m.get_int(CG43_LST_MESE); + + _year = m.get(CG43_FLD_ANNO); + _date = m.get(CG43_FLD_DATA); + _isprint = m.get_bool(CG43_CHK_STAMPA); + _recalc = (recalc)m.get_long(CG43_LST_CALC); + _printonly = m.get_bool(CG43_CHK_FINAL); + + if (_isprint) printer().setdate(_date); + if (_printonly) _recalc = never; + } + return k == K_ENTER; +} + +int cg4300(int argc, char* argv[]) +{ + TApplication::check_parameters(argc, argv); + + const char* title = TR("Liquidazione IVA"); + int menu = 1; + + if (argc > 2) + { + const char mode = argv[2][1]; + switch (mode) + { + case 'A': + title = TR("Calcolo acconti"); + menu = 3; + break; + case 'C': + title = TR("Ricalcolo progressivi IVA"); + break; + case 'D': + title = TR("Estrazione versamenti"); + menu = 2; + break; + case 'S': + title = TR("Stampa liquidazione"); + break; + default: + break; + } + } + + TLiquidazione_app* main_app = new TLiquidazione_app(menu); + main_app->run(argc, argv, title); + delete main_app; + return true; +} diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp index 84c6530a8..9e2636f73 100755 --- a/cg/cg4301.cpp +++ b/cg/cg4301.cpp @@ -618,20 +618,23 @@ bool TLiquidazione_app::sarebbe_da_pagare(const TRectype& mov, const TDate& fine const TRectype& clifo = cache().get(LF_CLIFO, key); const int alleg = clifo.get_int(CLI_ALLEG); - if (alleg == 5 || alleg == 6 || alleg == 9) // Privati, import ed export non hanno IVA per cassa - return true; - if (alleg == 7 || alleg == 8) // Ente pubblico e amministrazione controllata ... return false; // ... possono aspettare le calende greche - TString16 paiv = clifo.get(CLI_PAIV); - if (paiv.empty() && clifo.get_bool(CLI_OCCAS)) + if (mov.get_bool(MOV_IVAXCASSA)) { - const TRectype& occas = cache().get(LF_OCCAS, mov.get(MOV_OCFPI)); - paiv = occas.get(OCC_PAIV); + if (alleg == 5 || alleg == 6 || alleg == 9) // Privati, import ed export non hanno IVA per cassa + return true; + + TString16 paiv = clifo.get(CLI_PAIV); + if (paiv.empty() && clifo.get_bool(CLI_OCCAS)) + { + const TRectype& occas = cache().get(LF_OCCAS, mov.get(MOV_OCFPI)); + paiv = occas.get(OCC_PAIV); + } + if (paiv.blank()) + return true; // In assenza di Partita IVA non c'è IVA per cassa } - if (paiv.blank()) - return true; // In assenza di Partita IVA non c'è IVA per cassa if (ivadiff_chiusa(mov, fine)) return false; @@ -944,7 +947,16 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) const TString4 tipodoc = _mov->get(MOV_TIPODOC); const bool corrisp = _reg->get_bool("B0"); const tiporeg tipomov = (tiporeg)_reg->get_int("I0"); - const tipo_movimento tm = (tipo_movimento)_mov->get_int(MOV_TIPOMOV); + + tipo_movimento tm = (tipo_movimento)_mov->get_int(MOV_TIPOMOV); + if (tm == tm_nessuno) + { + if (tipodoc == "FV" || tipodoc == "FA") + tm = tm_fattura; else + if (tipodoc == "NC") + tm = tm_nota_credito; + } + // Controlla se la data del documento si riferisce all'anno precedente (PRORATA 1998) const TDate datedoc = _mov->get(MOV_DATADOC); @@ -960,13 +972,13 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) const bool cau_intra = rcs.get_bool("INTRACOM"); const bool cau_valintra = rcs.get_bool("VALINTRA"); - if (_mov->get_long(MOV_NUMREG) == 20339) + if (_mov->get_long(MOV_NUMREG) == 31838) int cazzone = 1; // Inizio gestione IVA differita const bool iva_diff = _isdiff && _mov->get_bool(MOV_LIQDIFF); const bool iva_cass = !iva_diff && _mov->get_bool(MOV_IVAXCASSA) && tm > 0; - const bool movdiff = iva_diff || iva_cass; + const bool movdiff = (iva_diff || iva_cass) && !_recalc_regis; // Aggiunto test su ricalcolo da registri 13-12-2012 bool dok = is_date_ok(date, month, liqmonth, year_int); TPartite_array arrpart; // Partite interessate @@ -1153,7 +1165,7 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) CHECKD(rmi_tipoatt > 0, "Invalid tipo att ", rmi_tipoatt); id.put("TIPOATT", rmi_tipoatt); id.put("ANNOLIQ", datareg.year()); - int mesereg = mesereg = datareg.month(); + int mesereg = datareg.month(); if (_freqviva[0] == 'T') { const int resto = mesereg % 3; @@ -2072,9 +2084,10 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) stop = 3; } else + { if (year_int < 1998) stop = 0; // Solo PIM - + } for (int i=start; i<=stop; i++) // Ciclo per le tabelle { if (i == 1 || i == 3) //Is it a valid PIS/PRP (vedi anche sel. cursore & date_ok())? @@ -2098,31 +2111,32 @@ void TLiquidazione_app::recalc_att(int month, const char* codatt) } TTable *tab = arr[i]; + TRectype& curr = tab->curr(); if (!ign) { - tab->put("R0", tab->get_real("R0") + imp); - tab->put("R1", tab->get_real("R1") + ivp); - tab->put("R2", tab->get_real("R2") + lor); - tab->put("R3", tab->get_real("R3") + lorcor); // Corrispettivi, non inclusi quelli da ventilare - tab->put("R5", tab->get_real("R5") + ifs); - tab->put("R6", tab->get_real("R6") + vfs); - tab->put("R7", tab->get_real("R7") + adf); - tab->put("R8", tab->get_real("R8") + adi); - tab->put("R9", tab->get_real("R9") + bdi); - tab->put("R10", tab->get_real("R10") + bdv); - tab->put("R13", tab->get_real("R13") + fci); - tab->put("R14", tab->get_real("R14") + fcv); - } - + curr.add("R0", imp); + curr.add("R1", ivp); + curr.add("R2", lor); + curr.add("R3", lorcor); // Corrispettivi, non inclusi quelli da ventilare + curr.add("R5", ifs); + curr.add("R6", vfs); + curr.add("R7", adf); + curr.add("R8", adi); + curr.add("R9", bdi); + curr.add("R10", bdv); + curr.add("R13", fci); + curr.add("R14", fcv); + } // questi servono per i ricalcoli altrui (classify_pim) o // per trucchetti di ricalcolo successivi - tab->put("R11",tab->get_real("R11")+fsi); - tab->put("R12",tab->get_real("R12")+fsv); - tab->put("I1", (long)tipomov); - tab->put("B3", ivarimb ? "X" : ""); - tab->put("B4", (_isricacq && was_riv) ? "X" : ""); - tab->put("S5", tipoiva); + curr.add("R11",fsi); + curr.add("R12",fsv); + + curr.put("I1", (long)tipomov); + curr.put("B3", ivarimb ? "X" : ""); + curr.put("B4", (_isricacq && was_riv) ? "X" : ""); + curr.put("S5", tipoiva); // art 40 c. 5/6/8 per VA7. real r,v; diff --git a/cg/cg4400.cpp b/cg/cg4400.cpp index b149fd00d..8f76e1148 100755 --- a/cg/cg4400.cpp +++ b/cg/cg4400.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -66,8 +67,6 @@ HIDDEN int compare_rows(const TObject** o1, const TObject** o2) { const TRiga& r1 = *(const TRiga*)*o1; const TRiga& r2 = *(const TRiga*)*o2; - - //return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva)); return r1._codiva.compare(r2._codiva); } @@ -121,7 +120,7 @@ const char* TStampa_registri_app::desc_attivita(const TString& cod) const TRectype& TStampa_registri_app::ricerca_cf(char tipocf, long codcf) { - TString16 key; + TString8 key; key.format("%c|%ld", tipocf, codcf); return cache().get(LF_CLIFO, key); } @@ -1066,7 +1065,7 @@ int TStampa_registri_app::riga_rmoviva() _riga_rmi.add_riga(iva); if (!mov.get_bool(MOV_LIQDIFF) && !(mov.get_bool(MOV_IVAXCASSA) && mov.get_int(MOV_TIPOMOV)>0)) - _riga_prospettoXcassa.add_riga(impo, impos, ZERO, ZERO, codiva, 0, 0, false, 0); + _riga_prospettoXcassa.add_riga(impo, impos, ZERO, ZERO, ZERO, ZERO, codiva); //stampa di prova, cumula progressivi dai movimenti, anziche' dalle tabelle (solo bollato) if (_tipo_stampa == prova) @@ -1299,7 +1298,8 @@ int TStampa_registri_app::stampa_prospetto(int rr, bool print_prec) if (_auto_intraf) riga << TR("; 3=intra e AF art.34 comma 3"); riga << TR("; 4=liquidazione differita"); - riga << TR("; 5=IVA per cassa"); + if (has_module(ICAUT)) + riga << TR("; 5=IVA per cassa"); set_row(rr++, riga); _stampa = _st_tot_fin; @@ -1496,22 +1496,24 @@ int TStampa_registri_app::stampa_acquisti(int row) } } if (_iva_array.items() > 0) + { if (tdetprec == 1 || tdetprec == 3 || tdetprec == 9) { - set_row(++rw, TR("TOTALE")); - if (tot_imponib != ZERO) - set_row(rw, "@29g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rw, "@45g%r", &tot_imposta); - if (_tipo_stampa != prova) - { - if (tot_imponibp != ZERO) - set_row(rw, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rw, "@98g%r", &tot_impostap); - } + set_row(++rw, TR("TOTALE")); + if (tot_imponib != ZERO) + set_row(rw, "@29g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rw, "@45g%r", &tot_imposta); + if (_tipo_stampa != prova) + { + if (tot_imponibp != ZERO) + set_row(rw, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rw, "@98g%r", &tot_impostap); + } } - _iva_array.destroy(); + _iva_array.destroy(); + } rw++; return rw; } @@ -1900,25 +1902,11 @@ real TStampa_registri_app::stampa_valori_plafonds(const real& r1, const int mese return r; } -bool TStampa_registri_app::some_IVAxCassa() const +bool TStampa_registri_app::some_IVAxCassa(int da_mese, int a_mese) const { if (_tipo_reg != vendita && _tipo_reg != acquisto) return false; - int da_mese = _data_da.month(); - int a_mese = _data_a.month(); - - if (_frequiva == 'T') - { - const int dr = da_mese % 3; - if (dr != 1) - da_mese -= (dr == 0 ? 2 : 1); - - const int ar = a_mese % 3; - if (ar != 0) - a_mese += (ar == 1 ? 2 : 1); - } - TString query; query = "USE IVADIFF KEY 2 SELECT (TIPOMOV>2)"; query << "\nFROM ANNOLIQ=" << _data_da.year() << " MESELIQ=" << da_mese; @@ -1927,7 +1915,7 @@ bool TStampa_registri_app::some_IVAxCassa() const return id.items() > 0; } -bool TStampa_registri_app::print_IVAxCassa(int month) +bool TStampa_registri_app::print_IVAxCassa(int da_month, int a_month) { if (_tipo_reg != vendita && _tipo_reg != acquisto) return false; @@ -1935,17 +1923,27 @@ bool TStampa_registri_app::print_IVAxCassa(int month) TPrinter& pr = printer(); TPrintrow riga; const TString linea(_stampa_width, '-'); - + + TDate data_da(1, da_month, _data_da.year()); + if (data_da < _data_da) + data_da = _data_da; + + TDate data_a = _data_a; + if (a_month < data_a.month()) + { + data_a = TDate(1, a_month, _data_da.year()); + data_a.set_end_month(); + } + TString query; - query = "USE IVADIFF SELECT (BETWEEN(DATAREGP,#DAL,#AL))&&(MOV.REG=#REG)&&(TIPOMOV>2)&&(STR(IMPONIBILE>0))&&(STR(MESELIQ==#MON))"; + query = "USE IVADIFF SELECT (BETWEEN(DATAREGP,#DAL,#AL))&&(MOV.REG=#REG)&&(TIPOMOV>2)&&(STR(IMPONIBILE>0))"; query << "\nBY DATAREGP DATAREG"; query << "\nJOIN MOV INTO NUMREG==NUMREG"; query << "\nJOIN CLIFO TO MOV INTO TIPOCF==TIPO CODCF==CODCF"; TISAM_recordset id(query); - id.set_var("#DAL", _data_da); - id.set_var("#AL", _data_a); + id.set_var("#DAL", data_da); + id.set_var("#AL", data_a); id.set_var("#REG", _codreg); - id.set_var("#MON", long(month)); // Sporco trucco per evitare intestazioni inutili const bool il = _intesta_liq; @@ -1953,8 +1951,12 @@ bool TStampa_registri_app::print_IVAxCassa(int month) if (id.items() > 0) { - riga.reset(); - riga.put(linea, 0); + riga.reset(); + if (pr.rows_left() < id.items()+8) + { + pr.formfeed(); + riga.put(linea, 0); + } pr.print(riga); riga.reset(); @@ -1972,7 +1974,8 @@ bool TStampa_registri_app::print_IVAxCassa(int month) riga.put(TR("Documento"), 19); riga.put(TR("T Tipo"), 66); riga.put(TR("Forz"), 123); - riga.put(TR("Num"), 128); + if (_tipo_stampa == prova) + riga.put(TR("Num"), 128); pr.print(riga); riga.reset(); @@ -1985,7 +1988,8 @@ bool TStampa_registri_app::print_IVAxCassa(int month) riga.put(TR("IVA"), 102); riga.put(TR("Imposta"), 115); riga.put(TR("Scad"), 123); - riga.put(TR("Reg"), 128); + if (_tipo_stampa == prova) + riga.put(TR("Reg"), 128); pr.print(riga); riga.put(linea, 0); pr.print(riga); @@ -1997,8 +2001,11 @@ bool TStampa_registri_app::print_IVAxCassa(int month) const real importo = rec.get("IMPORTO"); const real imponibile = rec.get("IMPONIBILE"); const real imposta = rec.get("IMPOSTA"); + const int tipodiff = rec.get_int("TIPODIFF"); - TParagraph_string clifo(id.get("CLIFO.RAGSOC").as_string(), 27); + TString rs = id.get("CLIFO.RAGSOC").as_string(); + rs.strip_double_spaces(); + TParagraph_string clifo(rs, 27); riga.reset(); riga.put(rec.get_date("DATAREGP").string(brief, '/'), 0); @@ -2007,75 +2014,137 @@ bool TStampa_registri_app::print_IVAxCassa(int month) riga.put(id.get("MOV.NUMDOC").as_string(), 24); riga.put(format("%6ld", id.get("CLIFO.CODCF").as_int()), 31); riga.put(clifo.get(), 38); - riga.put(rec.get_int("TIPODIFF") == 2 ? "5" : "4", 66); // 4 = Differita; 5 = x Cassa + riga.put(tipodiff == 2 ? "5" : "4", 66); // 4 = Differita; 5 = x Cassa riga.put(id.get("MOV.TIPODOC").as_string(), 68); print_real(riga, importo, 70); print_real(riga, imponibile, 85); riga.put(rec.get("CODIVA"), 102); print_real(riga, imposta, 107); riga.put(rec.get_int("NUMPRO") >= 999 ? "X" : "", 123); - riga.put(format("%6ld", rec.get_long(MOV_NUMREG)), 125); + if (_tipo_stampa == prova) + riga.put(format("%6ld", rec.get_long(MOV_NUMREG)), 125); pr.print(riga); - _riga_prospettoXcassa.add_riga(ZERO, ZERO, imponibile, imposta, codiva, 0, 0, false, 0); + switch (tipodiff) + { + case 1: _riga_prospettoXcassa.add_riga(ZERO, ZERO, imponibile, imposta, ZERO, ZERO, codiva); break; + case 2: _riga_prospettoXcassa.add_riga(ZERO, ZERO, ZERO, ZERO, imponibile, imposta, codiva); break; + default: break; + } } } - - if (_riga_prospettoXcassa.items() <= 0) - return id.items() > 0; // Ho stampato qualcosa? - - riga.reset(); - if (pr.rows_left() < _riga_prospettoXcassa.items()+5) + else { - pr.formfeed(); - riga.put(linea, 0); + _intesta_liq = il; // Ripristina flag intestazioni + return false; // Ho stampato qualcosa? } - pr.print(riga); - riga.reset(); - riga.put(TR("PROSPETTO IMPORTI CON IVA ORDINARIA ED IVA DIFFERITA O PER CASSA"), 40); - pr.print(riga); - - riga.reset(); - pr.print(riga); - - riga.reset(); - riga.put(TR("IVA Descrizione"), 0); - riga.put(TR("Imponibile"), 34); - riga.put(TR("Imposta"), 53); - riga.put(TR("Imponibile diff."), 84); - riga.put(TR("Imposta diff."), 109); - pr.print(riga); - - real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; - _riga_prospettoXcassa.sort(compare_righeiva); - for (int s = 0; s < _riga_prospettoXcassa.items(); s++) + int flags = 0x0; + FOR_EACH_ARRAY_ITEM(_riga_prospettoXcassa, r, obj) { - const TRigaiva& ri = _riga_prospettoXcassa.riga(s); + const TRiga& ri = *(const TRiga*)obj; + if (!ri._implordo.is_zero()) + flags |= 0x1; + if (!ri._impostap.is_zero()) + flags |= 0x2; + } - riga.reset(); - riga.put(ri._codiva, 0); - riga.put(descr_iva(ri._codiva), 5); - print_real(riga, ri._imponibile, 29); - print_real(riga, ri._imposta, 45); - print_real(riga, ri._imponibilep,85); - print_real(riga, ri._impostap, 107); + if (flags != 0x0) + { + riga.reset(); + if (pr.rows_left() < _riga_prospettoXcassa.items()+8) + { + pr.formfeed(); + riga.put(linea, 0); + } pr.print(riga); - tot_imponib += ri._imponibile; - tot_imposta += ri._imposta; - tot_imponibp+= ri._imponibilep; - tot_impostap+= ri._impostap; - } + riga.reset(); + pr.print(riga); - riga.reset(); - pr.print(riga); - riga.put(TR("TOTALE"), 0); - print_real(riga, tot_imponib, 29); - print_real(riga, tot_imposta, 45); - print_real(riga, tot_imponibp, 85); - print_real(riga, tot_impostap,107); - pr.print(riga); + TString str = TR("PROSPETTO IMPORTI CON IVA NORMALE"); + if (flags & 0x1) + str << ((flags == 0x1) ? TR(" ED ") : ", ") << TR("IVA DIFFERITA"); + if (flags & 0x2) + str << " ED " << TR("IVA PER CASSA"); + + riga.put(str, (132-str.len())/2); + pr.print(riga); + + riga.reset(); + pr.print(riga); + + riga.put(TR("NORMALE"), 45); + if (flags & 0x1) + riga.put(TR("DIFFERITA"), 78); + if (flags & 0x2) + riga.put(TR("PER CASSA"), 112); + pr.print(riga); + + riga.reset(); + riga.put(TR("IVA Descrizione"), 0); + riga.put(TR("Imponibile"), 34); + riga.put(TR("Imposta"), 53); + if (flags & 0x1) + { + riga.put(TR("Imponibile"), 68); + riga.put(TR("Imposta"), 87); + } + if (flags & 0x2) + { + riga.put(TR("Imponibile"), 102); + riga.put(TR("Imposta"), 121); + } + pr.print(riga); + + real tot_imponib0, tot_imposta0, tot_imponib1, tot_imposta1, tot_imponib2, tot_imposta2; + _riga_prospettoXcassa.sort(compare_rows); + for (int s = 0; s < _riga_prospettoXcassa.items(); s++) + { + const TRiga& ri = _riga_prospettoXcassa.riga(s); + + riga.reset(); + riga.put(ri._codiva, 0); + riga.put(descr_iva(ri._codiva), 5); + print_real(riga, ri._imponibile, 29); + print_real(riga, ri._imposta, 45); + if (flags & 0x1) + { + print_real(riga, ri._implordo, 63); + print_real(riga, ri._imponibilep, 79); + } + if (flags & 0x2) + { + print_real(riga, ri._impostap, 97); + print_real(riga, ri._implordop, 113); + } + pr.print(riga); + + tot_imponib0 += ri._imponibile; + tot_imposta0 += ri._imposta; + tot_imponib1 += ri._implordo; + tot_imposta1 += ri._imponibilep; + tot_imponib2 += ri._impostap; + tot_imposta2 += ri._implordop; + } + + riga.reset(); + pr.print(riga); + riga.put(TR("TOTALI"), 0); + print_real(riga, tot_imponib0, 29); + print_real(riga, tot_imposta0, 45); + if (flags & 0x1) + { + print_real(riga, tot_imponib1, 63); + print_real(riga, tot_imposta1, 79); + } + if (flags & 0x2) + { + print_real(riga, tot_imponib2, 97); + print_real(riga, tot_imposta2, 113); + } + pr.print(riga); + } _riga_prospettoXcassa.destroy(); @@ -2228,7 +2297,7 @@ bool TStampa_registri_app::preprocess_page(int file, int counter) if (ocfpi.empty()) { TRectype dep = ricerca_cf(tipocf, codcf); - ragsoc = dep.get (CLI_RAGSOC); + ragsoc = dep.get (CLI_RAGSOC); ragsoc.strip_double_spaces(); viacf = dep.get (CLI_INDCF); civcf = dep.get (CLI_CIVCF); capcf = dep.get (CLI_CAPCF); @@ -2248,7 +2317,7 @@ bool TStampa_registri_app::preprocess_page(int file, int counter) nome = ragsoc.mid(30,20); cognome.trim(); nome.trim(); ragsoc = cognome; - ragsoc << " " << nome; + ragsoc << ' ' << nome; } } else @@ -2522,19 +2591,36 @@ print_action TStampa_registri_app::postprocess_page (int file, int counter) _datareg = save_date; } - if (last_mov) + const int a_mese = _datareg.month(); + int da_mese = 0; + if (_frequiva == 'T') { - printer().formfeed(); - print_IVAxCassa(_datareg.month()); + if (a_mese % 3 == 0) + da_mese = a_mese-2; + } + else + da_mese = a_mese; + if (da_mese > 0) + { + if (some_IVAxCassa(da_mese, a_mese)) + { + printer().formfeed(); + print_IVAxCassa(da_mese, a_mese); + da_mese = 0; // vieta ristampa! + } + else + _riga_prospettoXcassa.destroy(); // Elimina comunque tracking movimenti } if (_liquidazione) { - if (!_st_liq[_datareg.month()] && stampo_liquidazione(_datareg.month())) + if (!_st_liq[a_mese] && stampo_liquidazione(a_mese)) { - _st_liq[_datareg.month()] = true; + _st_liq[a_mese] = true; if (_scelta == B0_settato) liq_b0_settato(); + + if (_scelta == prosegui_stampa || _scelta == prosegui_cal_stampa) { if (_t.exist()) @@ -2762,20 +2848,20 @@ void TStampa_registri_app::preprocess_header() set_header(r++,TR("RIEPILOGO TOTALI REGISTRI IVA")); else { - if (_stampa_width == 132) - { - set_header(r,FR("@10gNum.@19gDocumento@61gMese@66gT Tipo@102gCod %c@123gT %c@128gNum"), nd1, tipo); - r++; - set_header(r, FR("Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descr. liq.@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c@128gReg"), nd2, cor, type); - r++; - } - else //stampa a 198 - { - set_header(r,FR("Registrazione Documento@61gMese@66gT Tipo@110gCod %c@132g%c T@139gNum."), nd1, tipo, cor); - r++; - set_header(r, FR("Data Protocollo Data@24gNumero Codice Ragione sociale/descr. liq.@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c@139gReg."), nd2, type, cor); - r++; - } + if (_stampa_width == 132) + { + set_header(r,FR("@10gNum.@19gDocumento@61gMese@66gT Tipo@102gCod %c@123gT %c@128gNum"), nd1, tipo); + r++; + set_header(r, FR("Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descr. liq.@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c@128gReg"), nd2, cor, type); + r++; + } + else //stampa a 198 + { + set_header(r,FR("Registrazione Documento@61gMese@66gT Tipo@110gCod %c@132g%c T@139gNum."), nd1, tipo, cor); + r++; + set_header(r, FR("Data Protocollo Data@24gNumero Codice Ragione sociale/descr. liq.@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c@139gReg."), nd2, type, cor); + r++; + } } } else if (!_intesta_vidi) @@ -2906,8 +2992,9 @@ void TStampa_registri_app::liq_b0_settato() TFilename f; f.temp("rg"); if (_tipo_stampa == prova) - send_message('S',f, _datareg.month()); - else send_message('s',f, _datareg.month()); + send_message('S', f, _datareg.month()); + else + send_message('s', f, _datareg.month()); if (f.exist()) { @@ -2955,14 +3042,13 @@ void TStampa_registri_app::liq_other_case() // sarebbe necessario un ricalcolo progressivi per sicurezza. if (ricalcola(_fino_a_mese) || calc_reg) { - TFilename app; - app.temp(); - int mese = _fino_a_mese; - //se la frequenza e' trimestrale - //aggiusta il mese al trimestre a cui appartiene - if (_frequiva == 'T') - mese += 2 - ((mese-1) % 3); - send_message(calc_reg ? 'R' : 'C', app, calc_reg ? _datareg.month() : mese); + TFilename app; app.temp(); + int mese = _fino_a_mese; + //se la frequenza e' trimestrale + //aggiusta il mese al trimestre a cui appartiene + if (_frequiva == 'T') + mese += 2 - ((mese-1) % 3); + send_message(calc_reg ? 'R' : 'C', app, calc_reg ? _datareg.month() : mese); } } } @@ -3248,7 +3334,7 @@ void TStampa_registri_app::no_movimenti() { TRecnotype rec = _tabreg->recno(); _mov_empty = true; - int da, a; + int da = 1, a = _fino_a_mese; if (_tipo_stampa == bollato || _tipo_stampa == rif_giornale) da = 1; if (_tipo_stampa == libro_unico) @@ -3257,7 +3343,8 @@ void TStampa_registri_app::no_movimenti() da = _data_da.month(); if (_tipo_stampa == prova) a = _data_a.month(); - else a = _fino_a_mese; + else + a = _fino_a_mese; //RICALCOLO PROGRESSIVI per registro riepilogativo //il ricalcolo dei progressivi mensili viene sempre @@ -3288,15 +3375,11 @@ void TStampa_registri_app::no_movimenti() send_message(calc ? 'R' : 'C', app, calc ? a : mese); } - if (some_IVAxCassa()) + if (some_IVAxCassa(da, a)) { if (! printer().isopen()) printer().open(); - - int mese = a; - if (_frequiva == 'T') - mese += 2 - ((mese-1) % 3); - print_IVAxCassa(mese); + print_IVAxCassa(da, a); } if (_tipo_reg == riepilogativo || _liquidazione || _stampa_plafonds) @@ -3433,13 +3516,14 @@ void TStampa_registri_app::stampa_liq_mesi_succ() void TStampa_registri_app::send_message(char tipo, const TFilename& nome, int mese) { - const char* app; + const char* app = "cg4 -2"; if (tipo == 'S' || tipo == 's') app = "cg4 -2 -S"; else if (tipo == 'C' || tipo == 'R') app = "cg4 -2 -C"; - else app = "cg4 -2"; + else + app = "cg4 -2"; TToken_string ss(36); ss.add(_annoes); @@ -3451,10 +3535,7 @@ void TStampa_registri_app::send_message(char tipo, const TFilename& nome, int me ss.add(tipo); ss.add(_data_stampa.string()); ss.add(nome); - if (_riep_liq) - ss.add('X'); - else ss.add(' '); - + ss.add(_riep_liq ? 'X' : ' '); ss.add(printer().formlen() - _size_header - RIGHE_FOOTER); TMessage liq (app, "RCL", ss); @@ -3666,6 +3747,10 @@ bool TStampa_registri_app::stampa_registri_IVA(const TMask& m) } else //stampa tutti i registri { + _scelta = controlla_liquidazione(); + if (_scelta == non_proseguire) + return false; + TDate sca_vid; bool one_printed = false; // Flag per vedere se ha stampato almeno un registro (solo per rif. al libro giornale) for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) @@ -3711,7 +3796,7 @@ bool TStampa_registri_app::stampa_registri_IVA(const TMask& m) one_printed = true; else continue; - } + } else if (_tipo_stampa == libro_unico) //stampa su libro unico { if (cod_lib_un != _codlib) @@ -3747,7 +3832,8 @@ bool TStampa_registri_app::stampa_registri_IVA(const TMask& m) if (_liquidazione) { _size_header = 3; - if ((_tipo_stampa == bollato || _tipo_stampa == rif_giornale) && !_stampa_ind_ditta) _size_header++; + if ((_tipo_stampa == bollato || _tipo_stampa == rif_giornale) && !_stampa_ind_ditta) + _size_header++; clear_stliq(); //N.B. E' fondamentale che _scelta venga ri-inizializzata ad ogni //registro(cioe' dopo la stampa di ciascuno). Infatti il B0 di un @@ -3806,9 +3892,11 @@ bool TStampa_registri_app::stampa_riepilogo(int m) TRiga_array vect, vect_prec; TRigaiva_array vect_det; bool stampato = false; - if (!printer().isopen()) printer().open(); - - for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) // Scorre i registri + if (!printer().isopen()) + printer().open(); + + _tabreg->put("CODTAB", _annoes); + for (int err = _tabreg->read(_isgteq); err == NOERR; err = _tabreg->next()) // Scorre i registri { const TString8 codtab = _tabreg->get("CODTAB"); const int a = atoi(codtab.mid(0,4)); diff --git a/cg/cg4400.h b/cg/cg4400.h index 9305bd5d9..93a8be968 100755 --- a/cg/cg4400.h +++ b/cg/cg4400.h @@ -35,10 +35,9 @@ class TStampa_registri_app : public TPrintapp { TSorted_cursor * _cur; TRelation *_rel, *_nditte; -// TLocalisamfile *_clifo, *_occas, *_com, *_anag, *_unloc, *_attiv, *_indlib; -// TTable *_tablia, *_tabpim, *_tabprm, *_tabprp, *_table; TTable *_tabreg; - TRigaiva_array _iva_array, _riga_rmi, _riga_prospettoXcassa; + TRigaiva_array _iva_array, _riga_rmi; + TRiga_array _riga_prospettoXcassa; TTipodoc_array _doc_array; TRiga_array _tot_iva_array, _tot_prec_iva_array; TBit_array _selected; @@ -147,8 +146,8 @@ public: int stampa_acquisti(int); real stampa_valori_plafonds(const real&, const int, TTable&, const char*); - bool some_IVAxCassa() const; // C'e' IVA per cassa o differita da stampare? - bool print_IVAxCassa(int month); + bool some_IVAxCassa(int da_month, int a_month) const; // C'e' IVA per cassa o differita da stampare? + bool print_IVAxCassa(int da_month, int a_month); void build_nomiditte(TProgind* pnd = NULL); void set_year(int y) { _annoes = y; } diff --git a/cg/cglib01.h b/cg/cglib01.h index 7aea29e62..e19ef5c9d 100755 --- a/cg/cglib01.h +++ b/cg/cglib01.h @@ -116,8 +116,9 @@ public: void set_prorata(int annodoc, const real& pro); real prorata(int annodoc); - bool prorata100(int annodoc) { return prorata(annodoc) >= 100.0; } - +#ifdef PRORATA100 + bool prorata100(int annodoc) { return prorata(annodoc) >= CENTO; } +#endif bool update(long uprotiva, const TDate& lastreg); TRegistro(const char* code = "", int year = 0); diff --git a/cg/cglib03.cpp b/cg/cglib03.cpp index b1d490c43..13c97b3ae 100755 --- a/cg/cglib03.cpp +++ b/cg/cglib03.cpp @@ -42,13 +42,15 @@ real indetraibile_al(const TString& codind, const TCausale& caus, int annodoc, i case iva_acquisti: case nessuna_iva: case iva_errata: +#ifdef PRORATA100 if (!is_liq && caus.reg().prorata100(annodoc)) // Se prorata = 100% e' indetraibile { perc = CENTO; tipodet = 9; } else - tipodet = codind2tipodet(codind, perc); +#endif + tipodet = codind2tipodet(codind, perc); break; default: tipodet = 0; // Vendite sempre detraibili