From 500c9c1fe7eed8cff1b0ae8e23a656ae3ea7a141 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 18 Apr 1995 12:30:16 +0000 Subject: [PATCH] Corretta compattazione righe contabili vuote git-svn-id: svn://10.65.10.50/trunk@1260 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg2102.cpp | 64 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index cf346b9f0..cc8229bae 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -144,14 +144,20 @@ bool TPrimanota_application::detraibile(TToken_string& row) // Funzioni di ricerca /////////////////////////////////////////////////////////// +HIDDEN char row_type(const TToken_string& s) +{ + const int l = s.len()-1; + return l > 0 ? s[l] : ' '; +} + int TPrimanota_application::type2pos(char tipo) { TSheet_field& cg = app().cgs(); for (int i = 0; i < cg.items(); i++) { TToken_string& s = cg.row(i); - const int l = s.len()-1; - if (l > 0 && s[l] == tipo) + const char t = row_type(s); + if (t == tipo) return i; } return -1; @@ -165,8 +171,8 @@ int TPrimanota_application::bill2pos(const TBill& conto, char tipo) for (int i = 0; i < cg.items(); i++) { TToken_string& s = cg.row(i); - const int l = s.len()-1; - if (l > 0 && s[l] == tipo) + const char t = row_type(s); + if (t == tipo) { const TBill c(s, 3, 0x0); if (c == conto) @@ -396,33 +402,44 @@ HIDDEN int compare_rows(const TObject** o1, const TObject** o2) const TToken_string* r1 = (const TToken_string*)*o1; const TToken_string* r2 = (const TToken_string*)*o2; - const char c1 = r1->right(1)[0]; - const char c2 = r2->right(1)[0]; + const char c1 = row_type(*r1); + const char c2 = row_type(*r2); return int(strchr(sort_order, c1) - strchr(sort_order, c2)); } +HIDDEN bool can_remove(TToken_string& s) +{ + const char* dare = s.get(0); + bool yes = dare == NULL ; + if (!yes) + { + if (*dare == '\0' || *dare == ' ' || strcmp(dare,"0") == 0) + { + const char* avere = s.get(); + yes = (avere == NULL || *avere == '\0' || *avere == ' ' || strcmp(avere,"0") == 0); + } + } + return yes; +} + void TPrimanota_application::cgs_pack() -{ +{ TString_array& rows = cgs().rows_array(); - const int max = rows.items(); - for (int i = 0; i < max; i++) + const bool salda = is_saldaconto() && iva() == nessuna_iva; + + for (int i = rows.items()-1; i >= 0; i--) { TToken_string& r = rows.row(i); - bool del = FALSE; - if (r.empty_items()) // Remove all empty strings - del = TRUE; - else + if (can_remove(r)) { - const TImporto& imp = get_cgs_imp(i); - if (imp.valore() == ZERO) - del = TRUE; - } - if (del) - rows.destroy(i, FALSE); - } - - rows.sort(compare_rows); // Pack and sort array + if (salda && row_type(r) == ' ') + cg_notify(i, K_DEL); + rows.destroy(i, salda); + } + } + if (!salda) + rows.sort(compare_rows); // Pack and sort array } @@ -643,6 +660,9 @@ bool TPrimanota_application::cg_notify(int r, KEY k) case K_DEL: if (tipo > ' ') return error_box("La riga %d non puo' essere cancellata", r+1); + if (app().is_saldaconto() && app().iva() == nessuna_iva) + app().notify_cgline_deletion(r+1); + break; default: break; }