diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 0a829b436..bef736716 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -19,18 +19,18 @@ inline TPrimanota_application& app() // Certified 50% TipoIVA TPrimanota_application::cau2IVA(const char* causale, int annoiva) { - TipoIVA i = iva_errata; + TipoIVA i = iva_errata; - if (*causale > ' ') - { - TCausale c; - if (c.read(causale, annoiva)) - i = c.iva(); - else - error_box("Causale errata: '%s'", causale); - } else i = nessuna_iva; + if (*causale > ' ') + { + TCausale c; + if (c.read(causale, annoiva)) + i = c.iva(); + else + error_box("Causale errata: '%s'", causale); + } else i = nessuna_iva; - return i; + return i; } // Calcola l'anno di esercizio di una data @@ -55,23 +55,24 @@ int TPrimanota_application::date2esc(const TDate& d, int* prevesc) // Certified 99% const real& TPrimanota_application::cod2IVA(const char* codiva) { - static TString16 _codiva; + static TString16 _codiva; static real _percent; - if (_codiva != codiva) - { - _codiva = codiva; - TCodiceIVA c(_codiva); - _percent = c.percentuale(); - } + if (_codiva != codiva) + { + _codiva = codiva; + TCodiceIVA c(_codiva); + _percent = c.percentuale(); + } - return _percent; + return _percent; } real TPrimanota_application::scorpora(real& imponibile, const real& percent) { - real imposta = imponibile * percent / (percent + 100.0); imposta.ceil(); - imponibile -= imposta; + real imposta = abs(imponibile) * percent / (percent + 100.0); imposta.ceil(); + if (imponibile.sign() < 0) imposta = -imposta; + imponibile -= imposta; return imposta; } @@ -104,35 +105,23 @@ bool TPrimanota_application::suspended_handler(TMask_field& f, KEY k) // Certified 70% bool TPrimanota_application::detraibile(int tipodet) { - if (tipodet) - return FALSE; - if (app().iva() != iva_acquisti) - return TRUE; + if (tipodet) + return FALSE; + if (app().iva() != iva_acquisti) + return TRUE; - const TSheet_field& iva = app().ivas(); + const TSheet_field& iva = app().ivas(); - TString16 chiave; - chiave = iva.mask().get(F_ANNOIVA); - chiave << iva.mask().get(F_CODREG); - TTable reg("REG"); - reg.put("CODTAB", chiave); - reg.read(); -#ifdef DBG - if(reg.status() != NOERR) - error_box("La minchia che trovo il registro '%s'", (const char*)chiave); -#endif + TString16 chiave(iva.mask().get(F_ANNOIVA)); chiave << app().causale().reg().attivita(); - const char* att = reg.get("S8"); - chiave.cut(4); chiave << att; + TTable pla("PLA"); + pla.put("CODTAB", chiave); + const int err = pla.read(); + real prorata; + if (err == NOERR) + prorata = pla.get_real("R8"); - TTable pla("PLA"); - pla.put("CODTAB", chiave); - const int err = pla.read(); - real prorata; - if (err == NOERR) - prorata = pla.get_real("R8"); - - return prorata != 100.0; + return prorata != 100.0; } /////////////////////////////////////////////////////////// @@ -141,62 +130,63 @@ bool TPrimanota_application::detraibile(int tipodet) 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); - if (s[s.len()-1] == tipo) - return i; - } - return -1; + TSheet_field& cg = app().cgs(); + for (int i = 0; i < cg.items(); i++) + { + TToken_string& s = cg.row(i); + if (s[s.len()-1] == tipo) + return i; + } + return -1; } int TPrimanota_application::bill2pos(const TConto& conto, char tipo) { - TSheet_field& cg = app().cgs(); - for (int i = 0; i < cg.items(); i++) - { - TToken_string& s = cg.row(i); - if (s[s.len()-1] == tipo) + TSheet_field& cg = app().cgs(); + for (int i = 0; i < cg.items(); i++) { - const TConto c(s, 3, 0x0); - if (c == conto) - return i; + TToken_string& s = cg.row(i); + if (s[s.len()-1] == tipo) + { + const TConto c(s, 3, 0x0); + if (c == conto) + return i; + } } - } - return -1; + return -1; } int TPrimanota_application::bill2contr(const TConto& conto, char sezione) const { - const TArray& rows = cgs().rows_array(); - for (int i = 0; i < rows.items(); i++) - { - TToken_string& row = (TToken_string&)rows[i]; - const char sez = row.get(0)[0] > ' ' ? 'D' : 'A'; - if (sez == sezione) // Devo cercare sezione contraria - continue; - const TConto c(row, 3, 0x0); - if (conto == c) - return i; - } - return -1; + const TArray& rows = cgs().rows_array(); + for (int i = 0; i < rows.items(); i++) + { + TToken_string& row = (TToken_string&)rows[i]; + const char sez = row.get(0)[0] > ' ' ? 'D' : 'A'; + if (sez == sezione) // Devo cercare sezione contraria + continue; + const TConto c(row, 3, 0x0); + if (conto == c) + return i; + } + return -1; } - + +// Controlla se un conto e' usato nelle righe IVA bool TPrimanota_application::bill_used(const TConto& conto) const { - const TArray& rows = ivas().rows_array(); - for (int i = 0; i < rows.items(); i++) - { - TToken_string& row = (TToken_string&)rows[i]; - const TConto c(row, 6, 0x0); - if (conto == c) - return TRUE; - } - return FALSE; + const TArray& rows = ivas().rows_array(); + for (int i = 0; i < rows.items(); i++) + { + TToken_string& row = (TToken_string&)rows[i]; + const TConto c(row, 6, 0x0); + if (conto == c) + return TRUE; + } + return FALSE; } @@ -213,8 +203,8 @@ TMask& TPrimanota_application::mask() const TSheet_field& TPrimanota_application::cgs() const { - TSheet_field& s = (TSheet_field&)mask().field(F_SHEETCG); - return s; + TSheet_field& s = (TSheet_field&)mask().field(F_SHEETCG); + return s; } @@ -223,8 +213,8 @@ TSheet_field& TPrimanota_application::cgs() const // ritornandolo poi col segno opportuno + o - real TPrimanota_application::imp2sez(const real& imp) { - const int dare = (imp >= 0.0) ^ (app().iva() == iva_vendite); - return abs(imp) * (dare ? +1.0 : -1.0); + const int dare = (imp >= 0.0) ^ (app().iva() == iva_vendite); + return abs(imp) * (dare ? +1.0 : -1.0); } @@ -232,19 +222,19 @@ real TPrimanota_application::imp2sez(const real& imp) // Scrive l'importo imp nella opportuna sezione della riga n void TPrimanota_application::set_cgs_imp(int n, const real& imp) { - TToken_string& row = cgs().row(n); - const char* val = imp.string(); - if (*val == '-') - { - row.add(" ", 0); - row.add(val+1, 1); - } - else - { - row.add(val, 0); - row.add(" ", 1); - } - cgs().force_update(n); + TToken_string& row = cgs().row(n); + const char* val = imp.string(); + if (*val == '-') + { + row.add(" ", 0); + row.add(val+1, 1); + } + else + { + row.add(val, 0); + row.add(" ", 1); + } + cgs().force_update(n); } @@ -252,121 +242,121 @@ void TPrimanota_application::set_cgs_imp(int n, const real& imp) // Certified 99% real TPrimanota_application::get_cgs_imp(int n) { - TToken_string& row = cgs().row(n); - const real dare(row.get(0)); - if (dare > 0.0) return dare; - const real avere(row.get()); - return -avere; + TToken_string& row = cgs().row(n); + const real dare(row.get(0)); + if (dare > 0.0) return dare; + const real avere(row.get()); + return -avere; } // Certified 90% void TPrimanota_application::add_cgs_imp(int n, const real& imp) { - const real tot = get_cgs_imp(n) + imp; - set_cgs_imp(n, tot); + const real tot = get_cgs_imp(n) + imp; + set_cgs_imp(n, tot); } // Disabilita le celle della riga contabile n in base al suo tipo void TPrimanota_application::disable_cgs_cells(int n, char tipo) { - int last; - switch(tipo) - { + int last; + switch(tipo) + { case 'F': // Ritenute Fiscali case 'S': // Ritenute Sociali case 'D': // IVA Detraibile case 'N':last = 3; break; // IVA Non detraibile - case 'T': // Totale documento - case 'I':last = 6; break; // Imponibile - default :last = 0; break; // Solo contabile - } + case 'T': // Totale documento + case 'I':last = 6; break; // Imponibile + default :last = 0; break; // Solo contabile + } - TSheet_field& cg = cgs(); - for (int i = 0; i < last; i++) - cg.disable_cell(n, i); + TSheet_field& cg = cgs(); + for (int i = 0; i < last; i++) + cg.disable_cell(n, i); - if (tipo == 'T') - { - cg.enable_cell(n, 3); - cg.enable_cell(n, 4); - } + if (tipo == 'T') + { + cg.enable_cell(n, 3); + cg.enable_cell(n, 4); + } } int TPrimanota_application::set_cgs_row(int n, const real& imp, - TConto& conto, const char* desc, - char tipo) + TConto& conto, const char* desc, + char tipo) { - TSheet_field& cg = cgs(); - if (n < 0) n = cg.first_empty(); - TToken_string& row = cg.row(n); - row = ""; - set_cgs_imp(n, imp); - row.add(conto.string(0x3)); - row.add(""); - row.add(desc); + TSheet_field& cg = cgs(); + if (n < 0) n = cg.first_empty(); + TToken_string& row = cg.row(n); + row = ""; + set_cgs_imp(n, imp); + row.add(conto.string(0x3)); + row.add(""); + row.add(desc); int pos = 0; - if (tipo == 'I' && (pos = type2pos('T')) >= 0) - { - TConto contro(cg.row(pos), 2, 0x3); - row.add(contro.string(0x3)); - } - else - { - row.add(" | | | | "); // Contropartita - } - row << '|' << tipo; - disable_cgs_cells(n, tipo); - cg.force_update(n); - - return n; + if (tipo == 'I' && (pos = type2pos('T')) >= 0) + { + TConto contro(cg.row(pos), 2, 0x3); + row.add(contro.string(0x3)); + } + else + { + row.add(" | | | | "); // Contropartita + } + row << '|' << tipo; + disable_cgs_cells(n, tipo); + cg.force_update(n); + + return n; } HIDDEN int compare_rows(const TObject** o1, const TObject** o2) { // Totale, Rit.Fisc., Rit.Soc., da riga IVA, riga contabile, IVA detr., IVA non detr. - static char* sort_order = "TFSI DN"; + static char* sort_order = "TFSI DN"; - 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]; - return int(strchr(sort_order, c1) - strchr(sort_order, c2)); + 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]; + return int(strchr(sort_order, c1) - strchr(sort_order, c2)); } void TPrimanota_application::cgs_pack() { - TArray& rows = cgs().rows_array(); + TArray& rows = cgs().rows_array(); - const int max = rows.items(); - for (int i = 0; i < max; i++) - { - TToken_string& r = (TToken_string&)rows[i]; - bool del = FALSE; - if (r.empty_items()) // Remove all empty strings - del = TRUE; - else + const int max = rows.items(); + for (int i = 0; i < max; i++) { - const real imp = get_cgs_imp(i); - if (imp == 0.0) - { - del = TRUE; -/* - const TConto c(r, 6, 0x0); // Remove if import=0 and Bill not used - del = !bill_used(c); -*/ - } - + TToken_string& r = (TToken_string&)rows[i]; + bool del = FALSE; + if (r.empty_items()) // Remove all empty strings + del = TRUE; + else + { + const real imp = get_cgs_imp(i); + if (imp == 0.0) + { + del = TRUE; + /* + const TConto c(r, 6, 0x0); // Remove if import=0 and Bill not used + del = !bill_used(c); + */ + } + + } + if (del) + rows.destroy(i, FALSE); } - if (del) - rows.destroy(i, FALSE); - } - rows.sort(compare_rows); // Pack and sort array + rows.sort(compare_rows); // Pack and sort array } @@ -374,27 +364,27 @@ void TPrimanota_application::cgs_pack() // Certified 90% bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) { - if (k == K_ENTER) - { - TSheet_field& cg = app().cgs(); - bool empty = TRUE; - real saldo; - for (int i = 0; i < cg.items(); i++) + if (k == K_ENTER) { - const real imp = app().get_cgs_imp(i); - if (empty) empty = imp == 0.0; - saldo += imp; - } - if (saldo != 0.0) - { - const char* ss = saldo.string("."); - return f.error_box("Il movimento e' sbilanciato di %s lire.", ss); - } - else - if (empty) - return f.error_box("Il movimento non contiene nessuna riga contabile!"); - } - return TRUE; + TSheet_field& cg = app().cgs(); + bool empty = TRUE; + real saldo; + for (int i = 0; i < cg.items(); i++) + { + const real imp = app().get_cgs_imp(i); + if (empty) empty = imp == 0.0; + saldo += imp; + } + if (saldo != 0.0) + { + const char* ss = saldo.string("."); + return f.error_box("Il movimento e' sbilanciato di %s lire.", ss); + } + else + if (empty) + return f.error_box("Il movimento non contiene nessuna riga contabile!"); + } + return TRUE; } @@ -404,17 +394,17 @@ bool TPrimanota_application::cg_notify(int r, KEY k) TToken_string& row = cg.row(r); const char tipo = row.empty() ? ' ' : row.right(1)[0]; - if (k == K_SPACE) - { - TMask& m = cg.sheet_mask(); - m.enable(DLG_DELREC, tipo == ' '); - } else - if (k == K_DEL) - { - if (tipo != ' ') - return error_box("La riga %d non puo' essere cancellata", r+1); - } - return TRUE; + if (k == K_SPACE) + { + TMask& m = cg.sheet_mask(); + m.enable(DLG_DELREC, tipo == ' '); + } else + if (k == K_DEL) + { + if (tipo != ' ') + return error_box("La riga %d non puo' essere cancellata", r+1); + } + return TRUE; } bool TPrimanota_application::descr_handler(TMask_field& f, KEY k) @@ -446,151 +436,159 @@ bool TPrimanota_application::dareavere_handler(TMask_field& f, KEY k) TSheet_field& TPrimanota_application::ivas() const { - TSheet_field& s = (TSheet_field&)_msk[2]->field(F_SHEETIVA); - return s; + TSheet_field& s = (TSheet_field&)_msk[2]->field(F_SHEETIVA); + return s; } void TPrimanota_application::set_ivas_row(int nriga, const char* codiva, TConto& tc, - const char* desc) + const char* desc) { - TToken_string& riga = ivas().row(nriga); - riga = " "; // Importo - riga.add (codiva); // codiva - riga.add (" | | "); // Imposta - C/R - Det - riga.add(tc.string(0x3)); // Conto - riga.add(desc); // Descrizione + TToken_string& riga = ivas().row(nriga); + riga = " "; // Importo + riga.add (codiva); // codiva + riga.add (" | | "); // Det - Imposta - C/R + riga.add(tc.string(0x3)); // Conto + riga.add(desc); // Descrizione } bool TPrimanota_application::imponibile_handler(TMask_field& f, KEY key) { - if (key == K_TAB && f.dirty()) - { - const TString& iva = f.mask().get(102); - if (iva.not_empty()) // Se c'e' il codice IVA + if (key == K_TAB && f.dirty()) { - const real& percent = cod2IVA(iva); - const real imponibile(f.get()); - real imposta = imponibile * percent / 100.0; imposta.ceil(); - f.mask().set(103, imposta.string()); + TString16 iva(f.mask().get(102)); + if (iva.empty()) + { + iva = app().mask().get(F_CODIVA); + f.mask().set(102, iva); + } + if (iva.not_empty()) // Se c'e' il codice IVA + { + const real& percent = cod2IVA(iva); + const real imponibile(f.get()); + real imposta = abs(imponibile) * percent / 100.0; imposta.ceil(); + if (imponibile.sign() < 0) imposta = -imposta; + f.mask().set(104, imposta.string()); + } } - } - return TRUE; + return TRUE; } bool TPrimanota_application::codiva_handler(TMask_field& f, KEY key) { - if (key == K_TAB && f.dirty()) - { - TMask_field& i = f.mask().field(101); - i.set_dirty(); - return imponibile_handler(i, key); - } - return TRUE; + if (key == K_TAB && f.dirty()) + { + TMask_field& i = f.mask().field(101); + i.set_dirty(); + return imponibile_handler(i, key); + } + return TRUE; } bool TPrimanota_application::imposta_handler(TMask_field& f, KEY key) { - if (key == K_ENTER) - { - const real imponibile(f.mask().get(101)); - const real& percent = cod2IVA(f.mask().get(102)); - real imposta = imponibile * percent / 100.0; imposta.ceil(); - const real val(f.get()); - if (val != imposta) + if (key == K_ENTER) { - const TString16 wrong(val.string(".")); - const TString16 right(imposta.string(".")); - if (f.yesno_box("Imposta di '%s' errata: modificare in '%s'?", - (const char*)wrong, (const char*)right)) - f.set(imposta.string()); - } - } else - if (key == K_F8 && f.get().empty()) - { - real imponibile(f.mask().get(101)); - const real& percent = cod2IVA(f.mask().get(102)); - const real imposta = scorpora(imponibile, percent); - f.set(imposta.string()); - f.mask().set(101, imponibile.string()); - } + const real imponibile(f.mask().get(101)); + const real& percent = cod2IVA(f.mask().get(102)); + real imposta = abs(imponibile) * percent / 100.0; + imposta.ceil(); + if (imponibile.sign() < 0) imposta = -imposta; + + const real val(f.get()); + if (val != imposta) + { + const TString16 wrong(val.string(".")); + const TString16 right(imposta.string(".")); + if (f.warning_box("Imposta di '%s' errata: dovrebbe essere '%s'", + (const char*)wrong, (const char*)right)); + } + } else + if (key == K_F8 && f.get().empty()) + { + real imponibile(f.mask().get(101)); + const real& percent = cod2IVA(f.mask().get(102)); + const real imposta = scorpora(imponibile, percent); + f.mask().set(101, imponibile.string()); + f.set(imposta.string()); + } - return TRUE; + return TRUE; } // Certified 50% bool TPrimanota_application::iva_notify(int r, KEY k) { - static int oldpos; - static real oldimp; + static int oldpos; + static real oldimp; - static int oldposiva; - static real oldiva; + static int oldposiva; + static real oldiva; - TSheet_field& iva = app().ivas(); - TToken_string& row = iva.row(r); + TSheet_field& iva = app().ivas(); + TToken_string& row = iva.row(r); - if (k == K_SPACE) - { - const TConto oldconto(row, 5, 0x1); - oldpos = bill2pos(oldconto, 'I'); - oldimp = imp2sez(real(row.get(0))); - oldposiva = type2pos(detraibile(row.get_int(4)) ? 'D' : 'N'); - oldiva = imp2sez(real(row.get(2))); - } - if (k == K_DEL) - { - row.add("0", 0); // Azzera imponibile - row.add("0", 2); // Azzera imposta - k = K_ENTER; // Elegante o Sporco trucco - } - if (k == K_ENTER) - { - if (oldpos >= 0) // Il conto esisteva anche prima + if (k == K_SPACE) { - app().add_cgs_imp(oldpos, -oldimp); - oldimp = 0.0; + const TConto oldconto(row, 5, 0x1); + oldpos = bill2pos(oldconto, 'I'); + oldimp = imp2sez(real(row.get(0))); + oldposiva = type2pos(detraibile(row.get_int(4)) ? 'D' : 'N'); + oldiva = imp2sez(real(row.get(3))); } - if (oldposiva >= 0) // Il conto IVA esisteva anche prima + if (k == K_DEL) { - app().add_cgs_imp(oldposiva, -oldiva); - oldiva = 0.0; + row.add("0", 0); // Azzera imponibile + row.add("0", 3); // Azzera imposta + k = K_ENTER; // Elegante o Sporco trucco + } + if (k == K_ENTER) + { + if (oldpos >= 0) // Il conto esisteva anche prima + { + app().add_cgs_imp(oldpos, -oldimp); + oldimp = 0.0; + } + if (oldposiva >= 0) // Il conto IVA esisteva anche prima + { + app().add_cgs_imp(oldposiva, -oldiva); + oldiva = 0.0; } -// Aggiorna conto sulla riga contabile - real imp = imp2sez(real(row.get(0))); // Imponibile - TConto conto(row, 5, 0x3); - oldpos = bill2pos(conto, 'I'); + // Aggiorna conto sulla riga contabile + real imp = imp2sez(real(row.get(0))); // Imponibile + TConto conto(row, 5, 0x3); + oldpos = bill2pos(conto, 'I'); - if (oldpos < 0) - app().set_cgs_row(-1, imp-oldimp, conto, "", 'I'); - else - app().add_cgs_imp(oldpos, imp-oldimp); - oldimp = imp; - -// Aggiorna conto IVA sulla riga contabile + if (oldpos < 0) + app().set_cgs_row(-1, imp-oldimp, conto, "", 'I'); + else + app().add_cgs_imp(oldpos, imp-oldimp); + oldimp = imp; + + // Aggiorna conto IVA sulla riga contabile - imp = imp2sez(real(row.get(2))); // Imposta - const bool detrarre = detraibile(row.get_int(4)); // Determina se IVA detraibile - app().causale().bill(detrarre ? 3 : 4, conto); - const char tipod = detrarre ? 'D' : 'N'; - oldposiva = type2pos(tipod); - if (oldposiva < 0) - { - const real val = imp-oldiva; - if (!val.is_zero()) - app().set_cgs_row(-1, val, conto, "", tipod); + imp = imp2sez(real(row.get(3))); // Imposta + const bool detrarre = detraibile(row.get_int(4)); // Determina se IVA detraibile + app().causale().bill(detrarre ? 3 : 4, conto); + const char tipod = detrarre ? 'D' : 'N'; + oldposiva = type2pos(tipod); + if (oldposiva < 0) + { + const real val = imp-oldiva; + if (!val.is_zero()) + app().set_cgs_row(-1, val, conto, "", tipod); + } + else + app().add_cgs_imp(oldposiva, imp-oldiva); + oldiva = imp; } - else - app().add_cgs_imp(oldposiva, imp-oldiva); - oldiva = imp; - } - return TRUE; + return TRUE; } @@ -605,10 +603,9 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) { TToken_string& row = app().ivas().row(r); imp += real(row.get(0)); // imponibile - row.get(); // IVA - imp += real(row.get()); // imposta + imp += real(row.get(3)); // imposta } - + const TMask& m = f.mask(); real tot(m.get(F_TOTALE)); tot += real(m.get(F_RITFIS)); @@ -619,7 +616,7 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) TString16 t(tot.string(".")); TString16 i(imp.string(".")); return error_box("La somma del totale documento e delle ritenute (%s) e' diverso dalla " - "somma degli imponibili e delle imposte (%s)", t, i); + "somma degli imponibili e delle imposte (%s)", (const char*)t, (const char*)i); } return TRUE; @@ -635,62 +632,62 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) // Certified 90% bool TPrimanota_application::num_handler(TMask_field& f, KEY key) { - if (!f.mask().is_running()) return TRUE; + if (!f.mask().is_running()) return TRUE; - if (key == K_TAB && f.get().not_empty()) - { - if (app().find(1)) - dispatch_e_char(f.parent(), K_SHIFT_ENTER); - } - return TRUE; + if (key == K_TAB && f.get().not_empty()) + { + if (app().find(1)) + dispatch_e_char(f.parent(), K_SHIFT_ENTER); + } + return TRUE; } // Handler of the F_CODCAUS field on the query mask -// Certified 90% +// Certified 99% bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key) { - if (!f.mask().is_running()) return TRUE; + if (!f.mask().is_running()) return TRUE; - if (key == K_TAB && f.focusdirty()) - { - const int ann = f.mask().get_int(F_ANNOIVA); - const char* cau = f.get(); - - const TipoIVA i = cau2IVA(cau, ann); - if (i != iva_errata) + if (key == K_TAB && f.focusdirty()) { - const bool ok = suspended_handler(f, key); - if (ok) - dispatch_e_char(f.parent(), K_INS); - } - } + const int ann = f.mask().get_int(F_ANNOIVA); + const char* cau = f.get(); + + const TipoIVA i = cau2IVA(cau, ann); // Cerca causale e suo tipo + if (i != iva_errata) + { + const bool ok = suspended_handler(f, key); // Controlla sospensione + if (ok) + dispatch_e_char(f.parent(), K_INS); // Entra in modo inserimento + } + } - return TRUE; + return TRUE; } // Handler of the F_CODCAUS field on the modify mask // Certified 99% bool TPrimanota_application::caus_modify_handler(TMask_field& f, KEY key) { - if (f.to_check(key)) - { - bool ok = suspended_handler(f, key); - if (!ok) return FALSE; - - const int ann = f.mask().get_int(F_ANNOIVA); - const char* cau = f.get(); - TCausale c(cau, ann); - ok = app().causale().similar(c); - if (!ok) + if (f.to_check(key)) { - f.error_box("Causale incongruente con quella precedentemente inserita"); - return FALSE; - } - app().read_caus(cau, ann); - } - - return TRUE; + bool ok = suspended_handler(f, key); + if (!ok) return FALSE; + + const int ann = f.mask().get_int(F_ANNOIVA); + const char* cau = f.get(); + TCausale c(cau, ann); + ok = app().causale().similar(c); + if (!ok) + { + f.error_box("Causale incongruente con quella precedentemente inserita"); + return FALSE; + } + app().read_caus(cau, ann); + } + + return TRUE; } @@ -711,34 +708,36 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) if (m.query_mode()) { - if (ae == 0) return f.error_box("La data dell'operazione non appartiene a nessun esercizio"); + if (ae == 0) + return f.error_box("La data dell'operazione non appartiene a nessun esercizio"); ok = app().giornale().read(ae); - if (!ok) return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae); + if (!ok) + return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae); } if (dr < app().giornale().last_print()) return f.error_box("La data dell'operazione e' antecedente alla " - "data di stampa del libro giornale dell'esercizio %d", ae); - - if (!m.query_mode() && app().iva() != nessuna_iva) - { - const int annoiva = m.get_int(F_ANNOIVA); - if (dr.year() != annoiva) + "data di stampa del libro giornale dell'esercizio %d", ae); + + if (!m.query_mode() && app().iva() != nessuna_iva) { - TRegistro& reg = app().causale().reg(); - const TString16 codreg(reg.name()); - ok = reg.read(codreg, dr.year()); - if (ok && dr < reg.last_reg()) - warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione " - "sul registro '%s' del %d", - reg.last_reg().string(), (const char*)codreg, dr.year()); + const int annoiva = m.get_int(F_ANNOIVA); + if (dr.year() != annoiva) + { + TRegistro& reg = app().causale().reg(); + const TString16 codreg(reg.name()); + ok = reg.read(codreg, dr.year()); + if (ok && dr < reg.last_reg()) + warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione " + "sul registro '%s' del %d", + reg.last_reg().string(), (const char*)codreg, dr.year()); + } } - } } return ok; } // Handler of the F_DATACOMP field on the modify mask -// Certified 70% +// Certified 90% bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) { if (!f.to_check(key, TRUE)) @@ -747,7 +746,7 @@ bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) const TDate dc(f.get()); // Data di competenza const int ae = date2esc(dc); // Esercizio corrispondente TMask& m = f.mask(); - + if (ae) { if (f.dlg() == F_DATACOMP) @@ -769,9 +768,9 @@ bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) return TRUE; } - + // Handler of the F_DATA74TER field on the modify mask -// Certified 70% +// Certified 90% bool TPrimanota_application::data74ter_handler(TMask_field& f, KEY key) { if (!f.to_check(key)) return TRUE; @@ -784,44 +783,44 @@ bool TPrimanota_application::data74ter_handler(TMask_field& f, KEY key) { ok = f.error_box("La data per il 74/ter e' antecedente alla data di stampa " "del libro giornale dell'esercizio %d", g.year()); - } + } } return ok; } - + // Handler of the F_CODREG field on the modify mask // Certified 99% bool TPrimanota_application::reg_handler(TMask_field& f, KEY key) { - if (f.to_check(key, TRUE)) - { -// if (!suspended_handler(f, key)) return FALSE; - - const int ai = f.mask().get_int(F_ANNOIVA); - const char* r = f.get(); - TRegistro reg(r, ai); - - const TipoIVA i = reg.iva(); - if (i == iva_errata) - return f.error_box("Tipo registro errato"); + if (f.to_check(key, TRUE)) + { + // if (!suspended_handler(f, key)) return FALSE; + + const int ai = f.mask().get_int(F_ANNOIVA); + const char* r = f.get(); + TRegistro reg(r, ai); + + const TipoIVA i = reg.iva(); + if (i == iva_errata) + return f.error_box("Tipo registro errato"); - if (reg.iva() != app().iva()) - { - const TString16 i1(iva2name(reg.iva())); - const TString16 i2(iva2name(app().iva())); - return f.error_box("Tipo registro (%s) incongruente col tipo di registrazione (%s)", - (const char*)i1, (const char*)i2); + if (reg.iva() != app().iva()) + { + const TString16 i1(iva2name(reg.iva())); + const TString16 i2(iva2name(app().iva())); + return f.error_box("Tipo registro (%s) incongruente col tipo di registrazione (%s)", + (const char*)i1, (const char*)i2); + } + + const bool av = reg.agenzia_viaggi(); + f.mask().show(F_DATA74TER, av); + if (!av) f.mask().reset(F_DATA74TER); + + if (key == K_TAB) + app().causale().reg() = reg; } - const bool av = reg.agenzia_viaggi(); - f.mask().show(F_DATA74TER, av); - if (!av) f.mask().reset(F_DATA74TER); - - if (key == K_TAB) - app().causale().reg() = reg; - } - - return TRUE; + return TRUE; } bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key) @@ -851,7 +850,7 @@ bool TPrimanota_application::occas_handler(TMask_field& f, KEY key) TMask& om = app().occas_mask(); om.run(); } - return TRUE; + return TRUE; } // Crea o aggiorna la riga contabile col totale documento @@ -859,51 +858,56 @@ bool TPrimanota_application::occas_handler(TMask_field& f, KEY key) void TPrimanota_application::add_cgs_tot(TMask& m) { // Lettura del conto dalla maschera - const char tipo = m.get(F_CLIFO)[0]; - int gruppo = m.get_int(F_GRUPPOCLIFO); - int conto = m.get_int(F_CONTOCLIFO); - long codice = m.get_long(tipo == 'C' ? F_CLIENTE : F_FORNITORE); - - // Se l'utente non ha ancora specificato un conto lo prendo dalla prima riga della causale - if (conto == 0) - { - TConto bill; _causale.bill(1, bill); - gruppo = bill.gruppo(); m.set(F_GRUPPOCLIFO, gruppo); - conto = bill.conto(); m.set(F_CONTOCLIFO, conto); - } - - TConto c(gruppo, conto, codice, tipo); - real tot(m.get(F_TOTALE)); - - // Creazione/Aggiornamento riga totale - int pos = type2pos('T'); - pos = set_cgs_row(pos, -imp2sez(tot), c, "Totale documento", 'T'); - - TToken_string& row = ivas().row(0); + const char tipo = m.get(F_CLIFO)[0]; + int gruppo = m.get_int(F_GRUPPOCLIFO); + int conto = m.get_int(F_CONTOCLIFO); + long codice = m.get_long(tipo == 'C' ? F_CLIENTE : F_FORNITORE); + + // Se l'utente non ha ancora specificato un conto lo prendo dalla prima riga della causale + if (conto == 0) + { + TConto bill; _causale.bill(1, bill); + gruppo = bill.gruppo(); m.set(F_GRUPPOCLIFO, gruppo); + conto = bill.conto(); m.set(F_CONTOCLIFO, conto); + } + + TConto c(gruppo, conto, codice, tipo); + real tot(m.get(F_TOTALE)); + + // Creazione/Aggiornamento riga totale + int pos = type2pos('T'); + pos = set_cgs_row(pos, -imp2sez(tot), c, "Totale documento", 'T'); + + TToken_string& row = ivas().row(0); const TCodiceIVA iva(m.get(F_CODIVA)); if (iva.ok()) { iva_notify(0, K_SPACE); const real imposta = scorpora(tot, iva.percentuale()); - row.add(tot.string(), 0); - row.add(iva.codice(), 1); - row.add(imposta.string(), 2); - row.add(" | "); - - TConto bill; // Conto della prima riga IVA + + row.add(tot.string(), 0); // imponibile + row.add(iva.codice(), 1); // imposta + row.add(imposta.string(), 3); // imposta + + TConto bill; // Conto della prima riga IVA const TString& tipo = iva.tipo(); if (tipo.not_empty()) { if (tipo == "ES") _causale.bill(5, bill); else - if (tipo == "NI") _causale.bill(6, bill); else - if (tipo == "NS") _causale.bill(7, bill); + if (tipo == "NI") _causale.bill(6, bill); else + if (tipo == "NS") _causale.bill(7, bill); } if (!bill.ok()) bill.set(m.get_int(F_GRUPPORIC), m.get_int(F_CONTORIC), m.get_long(F_SOTTOCONTORIC)); if (!bill.ok()) _causale.bill(2, bill); - row.add(bill.string(0x3)); + row.add(bill.tipo(), 5); + row.add(bill.gruppo(), 6); + row.add(bill.conto(), 7); + row.add(bill.sottoconto(), 8); + row.add(bill.descrizione(), 9); + app().ivas().force_update(0); iva_notify(0, K_ENTER); } @@ -917,15 +921,15 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) if (!suspended_handler(f, key)) return FALSE; - if (key == K_TAB && f.focusdirty()) - { - app().add_cgs_tot(f.mask()); - TLocalisamfile clifo(LF_CLIFO); - const int alleg = clifo.get_int("ALLEG"); - TEdit_field& upi = (TEdit_field&)f.mask().field(F_RIEPILOGO); - upi.check_type(alleg == 3 ? CHECK_REQUIRED : CHECK_NORMAL); - } - return TRUE; + if (key == K_TAB && f.focusdirty()) + { + app().add_cgs_tot(f.mask()); + TLocalisamfile clifo(LF_CLIFO); + const int alleg = clifo.get_int("ALLEG"); + TEdit_field& upi = (TEdit_field&)f.mask().field(F_RIEPILOGO); + upi.check_type(alleg == 3 ? CHECK_REQUIRED : CHECK_NORMAL); + } + return TRUE; } @@ -933,34 +937,34 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) // Certified 99% bool TPrimanota_application::totale_handler(TMask_field& f, KEY key) { - if (key == K_TAB && f.focusdirty()) - { - app().add_cgs_tot(f.mask()); - } else - if (key == K_ENTER && f.get().empty()) - return f.yesno_box("Totale documento nullo: continuare ugualmente?"); - return TRUE; + if (key == K_TAB && f.focusdirty()) + { + app().add_cgs_tot(f.mask()); + } else + if (key == K_ENTER && f.get().empty()) + return f.yesno_box("Totale documento nullo: continuare ugualmente?"); + return TRUE; } void TPrimanota_application::add_cgs_rit(bool fiscali) { - const real imp(_msk[2]->get(fiscali ? F_RITFIS : F_RITSOC)); + const real imp(_msk[2]->get(fiscali ? F_RITFIS : F_RITSOC)); - const char tipo = fiscali ? 'F' : 'S'; - int pos = type2pos(tipo); - if (pos < 0) - { - const int riga = fiscali ? 8 : 9; - TConto conto; _causale.bill(riga, conto); + const char tipo = fiscali ? 'F' : 'S'; + int pos = type2pos(tipo); + if (pos < 0) + { + const int riga = fiscali ? 8 : 9; + TConto conto; _causale.bill(riga, conto); - TString80 desc("Ritenute "); - desc << (fiscali ? "fiscali" : "sociali"); + TString80 desc("Ritenute "); + desc << (fiscali ? "fiscali" : "sociali"); - set_cgs_row(-1, -imp2sez(imp), conto, desc, tipo); - } - else - set_cgs_imp(pos, -imp2sez(imp)); + set_cgs_row(-1, -imp2sez(imp), conto, desc, tipo); + } + else + set_cgs_imp(pos, -imp2sez(imp)); } @@ -968,9 +972,9 @@ void TPrimanota_application::add_cgs_rit(bool fiscali) // Certified 99% bool TPrimanota_application::ritfis_handler(TMask_field& f, KEY key) { - if (key == K_TAB && f.focusdirty()) - app().add_cgs_rit(TRUE); - return TRUE; + if (key == K_TAB && f.focusdirty()) + app().add_cgs_rit(TRUE); + return TRUE; } @@ -978,9 +982,9 @@ bool TPrimanota_application::ritfis_handler(TMask_field& f, KEY key) // Certified 99% bool TPrimanota_application::ritsoc_handler(TMask_field& f, KEY key) { - if (key == K_TAB && f.focusdirty()) - app().add_cgs_rit(FALSE); - return TRUE; + if (key == K_TAB && f.focusdirty()) + app().add_cgs_rit(FALSE); + return TRUE; } @@ -1011,24 +1015,24 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key) if (m.is_running() && anchecg) { TSheet_field& iva = app().ivas(); - const int righe = iva.items(); - TProgind pi(righe, "Generazione righe contabilita'", FALSE, TRUE, 16); - - app().cgs().reset(); + const int righe = iva.items(); + TProgind pi(righe, "Generazione righe contabilita'", FALSE, TRUE, 16); + + app().cgs().reset(); app().add_cgs_tot(m); if (m.get(F_RITFIS).not_empty()) app().add_cgs_rit(TRUE); if (m.get(F_RITSOC).not_empty()) app().add_cgs_rit(FALSE); - - for (int i = 0; i < righe; i++) - { - if (!iva.row(i).empty_items()) - { - iva_notify(i, K_SPACE); - iva_notify(i, K_ENTER); - } - pi.setstatus(i+1); - } - app().fill_sheet(m); + + for (int i = 0; i < righe; i++) + { + if (!iva.row(i).empty_items()) + { + iva_notify(i, K_SPACE); + iva_notify(i, K_ENTER); + } + pi.setstatus(i+1); + } + app().fill_sheet(m); } } return TRUE; @@ -1054,24 +1058,24 @@ bool TPrimanota_application::conto_handler(TMask_field& f, KEY k) TConto conto; cod = iva.get("S1"); if (cod == "ES") riga = 5; else - if (cod == "NI") riga = 6; else - if (cod == "NS") riga = 7; else - { - TMask& m = app().mask(); - const char tipocf = m.get(F_CLIFO)[0]; - const long codcf = m.get_long(F_CLIENTE); - TLocalisamfile clifo(LF_CLIFO); - clifo.put("TIPOCF", tipocf); - clifo.put("CODCF", codcf); - clifo.read(); // Try Jolly bill - conto.set(clifo.get_int("GRUPPORIC"), - clifo.get_int("CONTORIC"), - clifo.get_long("SOTTOCRIC")); - riga = conto.ok() ? -1 : 2; // else use second row - } + if (cod == "NI") riga = 6; else + if (cod == "NS") riga = 7; else + { + TMask& m = app().mask(); + const char tipocf = m.get(F_CLIFO)[0]; + const long codcf = m.get_long(F_CLIENTE); + TLocalisamfile clifo(LF_CLIFO); + clifo.put("TIPOCF", tipocf); + clifo.put("CODCF", codcf); + clifo.read(); // Try Jolly bill + conto.set(clifo.get_int("GRUPPORIC"), + clifo.get_int("CONTORIC"), + clifo.get_long("SOTTOCRIC")); + riga = conto.ok() ? -1 : 2; // else use second row + } if (riga > 0) app().causale().bill(riga, conto); - + if (conto.ok()) { m.set(106, " ");