diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index 54f0edb01..4d54f6d7a 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -332,7 +332,7 @@ bool TPrimanota_application::read_caus(const char* cod, int year) ivasheet.sheet_mask().enable(IVA_NOTAVARECF, show_notevar); } - if (ins && !ci_sono_importi()) + if (ins && !ci_sono_importi(cgsheet)) { cgsheet.reset(); for (int i = 1; i < causale().size(); i++) @@ -1867,33 +1867,32 @@ void TPrimanota_application::dump_rec(TConfig & ini, const TRectype & rec, int r void TPrimanota_application::dump_fatt(TConfig& ini, TPartita & game, int rigafatt) { - if (rigafatt > 0) + CHECKD(rigafatt > 0 && rigafatt < 9999, "Riga fattura errata ", rigafatt); + + const TRiga_partite& riga = game.riga(rigafatt); + int r; + + for (r = 1; r <= riga.rate(); r++) { - const TRiga_partite& riga = game.riga(rigafatt); - int r; + TRiga_scadenze& rec = riga.rata(r); - for (r = 1; r <= riga.rate(); r++) - { - TRiga_scadenze& rec = riga.rata(r); - - rec.fill_array(); - const int lastrow = rec.last(); + rec.fill_array(); + const int lastrow = rec.last(); - dump_rec(ini, rec, r); - for (int rp = rec.first(); rp <= lastrow; rp = rec.succ(rp)) - { - const TRectype & recpag = rec.row(rp); + dump_rec(ini, rec, r); + for (int rp = rec.first(); rp <= lastrow; rp = rec.succ(rp)) + { + const TRectype & recpag = rec.row(rp); - dump_rec(ini, recpag, rp); - } - } - for ( ; ; r++) - { - if (ini.set_paragraph(format("%d,%d", LF_SCADENZE, r+1))) - ini.remove_all(); - else - break; - } + dump_rec(ini, recpag, rp); + } + } + for ( ; ; r++) + { + if (ini.set_paragraph(format("%d,%d", LF_SCADENZE, r+1))) + ini.remove_all(); + else + break; } } @@ -1905,7 +1904,6 @@ void TPrimanota_application::mask2ini(const TMask& msk, TConfig& ini) for (i = 0; i < _rel->cg_items(); i++) { const TRectype& rec = _rel->cg(i); - dump_rec(ini, rec, i + 1); } for ( ; ini.set_paragraph(format("%d,%d", LF_RMOV, i+1)); i++) @@ -1914,7 +1912,6 @@ void TPrimanota_application::mask2ini(const TMask& msk, TConfig& ini) for (i = 0; i < _rel->iva_items(); i++) { const TRectype& rec = _rel->iva(i); - dump_rec(ini, rec, i + 1); } for ( ; ini.set_paragraph(format("%d,%d", LF_RMOVIVA, i+1)); i++) @@ -1927,46 +1924,41 @@ void TPrimanota_application::mask2ini(const TMask& msk, TConfig& ini) if (is_fattura()) { TPartita* game = p.first(); - if (game) { const int rigafatt = game->prima_fattura(numreg); - - dump_fatt(ini, *game, rigafatt); + if (rigafatt > 0 && rigafatt < 9999) + dump_fatt(ini, *game, rigafatt); } } else { - TBit_array dumped; - for (TPartita* game = p.first(); game != NULL; game = p.next()) { + TBit_array dumped; const int rigapag = game->primo_pagamento(numreg); - if (rigapag > 0) { - TRiga_partite & riga = game->riga(rigapag); - TCursor pag(new TRelation(LF_PAGSCA)); - TRectype filter(pag.curr()); + // Ricava la lista dei pagamenti dal database invece di leggerli dalla struttura in memoria :-( + const TRiga_partite& riga = game->riga(rigapag); + TRelation rel(LF_PAGSCA); + TCursor pag(&rel); + TRectype& recpag = pag.curr(); - filter.put(PAGSCA_TIPOC, riga.get(PART_TIPOCF)); - filter.put(PAGSCA_GRUPPO, riga.get(PART_GRUPPO)); - filter.put(PAGSCA_CONTO, riga.get(PART_CONTO)); - filter.put(PAGSCA_SOTTOCONTO, riga.get(PART_SOTTOCONTO)); - filter.put(PAGSCA_ANNO, riga.get(PART_ANNO)); - filter.put(PAGSCA_NUMPART, riga.get(PART_NUMPART)); - pag.setregion(filter, filter); + recpag.put(PAGSCA_TIPOC, riga.get(PART_TIPOCF)); + recpag.put(PAGSCA_GRUPPO, riga.get(PART_GRUPPO)); + recpag.put(PAGSCA_CONTO, riga.get(PART_CONTO)); + recpag.put(PAGSCA_SOTTOCONTO, riga.get(PART_SOTTOCONTO)); + recpag.put(PAGSCA_ANNO, riga.get(PART_ANNO)); + recpag.put(PAGSCA_NUMPART, riga.get(PART_NUMPART)); + pag.setregion(recpag, recpag); const int items = pag.items(); - for (pag = 0L; pag.pos() < items; ++pag) { - const TRectype & recpag = pag.curr(); - if (rigapag == recpag.get_int(PAGSCA_NRIGP)) { const int rigafatt = recpag.get_int(PAGSCA_NRIGA); - - if (rigafatt >= 0 && !dumped[rigafatt]) + if (rigafatt > 0 && rigafatt < 9999 && !dumped[rigafatt]) { dump_fatt(ini, *game, rigafatt); dumped.set(rigafatt); diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 6b9109979..4c069366e 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -17,8 +17,6 @@ #include #include - - /////////////////////////////////////////////////////////// // Funzioni di decodifica/calcolo /////////////////////////////////////////////////////////// @@ -26,8 +24,14 @@ // Determina il tipo di una riga contabile in formato TToken_string char TPrimanota_application::row_type(const TToken_string& s) { - const int l = s.len()-1; - return l > 0 ? s[l] : ' '; + char t = ' '; + if (s.full()) + { + t = s[s.len()-1]; + if (t < 'A' || t > 'Z') + t = ' '; + } + return t; } // Determina il tipo IVA da causale+anno @@ -211,8 +215,7 @@ TSheet_field& TPrimanota_application::cgs() const { const TMask* m = _msk[_iva == nessuna_iva ? 1 : 2]; CHECK(m, "Null cgs() mask"); - TSheet_field& s = m->sfield(F_SHEETCG); - return s; + return m->sfield(F_SHEETCG); } @@ -459,33 +462,35 @@ void TPrimanota_application::cgs_pack() } -bool TPrimanota_application::ci_sono_importi() const +bool TPrimanota_application::ci_sono_importi(const TSheet_field& s) const { - const int rows = cgs().items(); - for (int i = 0; i < rows; i++) + if (s.items() > 0) { - const TImporto imp = get_cgs_imp(i); - if (!imp.is_zero()) - return true; - } + TImporto imp; + FOR_EACH_SHEET_ROW(s, r, riga); + { + imp = *riga; + if (!imp.is_zero()) + return true; + } + } return false; } real TPrimanota_application::calcola_saldo() const { - TImporto importo, bilancio, saldaconto; const bool pag = is_pagamento() && !_as400; + TImporto importo, bilancio, saldaconto; - TString_array& rows = cgs().rows_array(); - for (int i = rows.last(); i >= 0; i--) + TSheet_field& cgrows = cgs(); + FOR_EACH_SHEET_ROW_BACK(cgrows, i, r) { - TToken_string& r = rows.row(i); - importo = r; + importo = *r; bilancio += importo; if (pag) { - const char tipo = row_type(r); - if (strchr("ACGKP", tipo) != NULL) // Abbuoni attivi, differenze cambio, + const char tipo = row_type(*r); + if (strchr("ACGKP", tipo) != NULL) // Abbuoni attivi, differenze cambio, spese, ... saldaconto += importo; } } diff --git a/cg/cg2102.h b/cg/cg2102.h index 912c81f4a..84c2ad38f 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -245,7 +245,7 @@ protected: void ivas_pack(); void cgs_pack(); - bool ci_sono_importi() const; + bool ci_sono_importi(const TSheet_field& cgs) const; real calcola_saldo() const; real calcola_imp() const;