From 1cc5cb6358988ca51746245fd1f74a1232d76e14 Mon Sep 17 00:00:00 2001 From: Alessandro Bonazzi Date: Mon, 7 Oct 2024 19:56:04 +0200 Subject: [PATCH] Patch level : 12.00 1360 Files correlati : ve0.exe ve2400.msk Commento: Agiunto il flag OnlyOnePaIV nel paragrafo cg ddi ditta.ini per bloccare l'inserimento dei clienti/fornitori per gli utenti che non sono supervisori. --- src/cg/cg0200.cpp | 263 ++++++++++++++++++++++++---------------------- 1 file changed, 135 insertions(+), 128 deletions(-) diff --git a/src/cg/cg0200.cpp b/src/cg/cg0200.cpp index c75e73420..c0e7ad05d 100755 --- a/src/cg/cg0200.cpp +++ b/src/cg/cg0200.cpp @@ -154,64 +154,92 @@ bool TClifo_application::get_next_key(TToken_string& key) HIDDEN bool no_dup_fis(TMask_field& f, KEY key) { - bool ok = true; + TMask& m = f.mask(); - TMask& msk = f.mask() ; - if (msk.query_mode() || !f.to_check(key)) - return ok; + if (f.full()) + { + const bool only_one_paiv = ini_get_bool(CONFIG_DITTA, "cg", "OnlyOnePaIV"); + TRectype from(LF_CLIFO); - TLocalisamfile& clifo = app().get_relation()->lfile(LF_CLIFO); - if (!f.empty() && !clifo.empty()) - { - clifo.zero() ; - const char t1 = msk.get(F_TIPOCF)[0] ; + from.put(CLI_TIPOCF, m.get(F_TIPOCF)); + from.put(CLI_COFI, m.get(F_COFI)); - clifo.put(CLI_TIPOCF, t1); - clifo.put(CLI_COFI, f.get()); - clifo.setkey(4) ; - clifo.read() ; - clifo.setkey(1) ; - const char t = clifo.get_char(CLI_TIPOCF); - const long s = clifo.get_long(CLI_CODCF); - const long s1 = msk.get_long(F_CODCF); + TCursor c(new TRelation(LF_CLIFO), "", 4, &from, &from); + const TString4 alleg = m.get(F_ALLEG); + const bool multi_clifo = c.items() > 1; + const bool not_dup = (alleg != "4" && alleg != "6" & alleg != "G"); - if (clifo.good() && (t1 != t || s1 != s)) - { - f.message_box(FR("Codice fiscale già utilizzato per il codice %c/%ld"), - t, s); - } - } - - return ok ; + c = 0L; + + const char * tipo = c.curr().get(CLI_TIPOCF) == "C" ? "cliente" : "fornitore"; + const long codice = c.curr().get_long(CLI_CODCF); + + if (only_one_paiv) + { + if (multi_clifo) + { + if (supervisor()) + { + if (not_dup) + return f.error_box(FR("Codice fiscale già utilizzato per il codice %s %ld\nsenza avere indicato il valore 4, 7 o G nell'inserimento in allegato"), + tipo, codice); + } + else + return f.error_box(FR("Codice fiscale già utilizzato per il codice %s %ld"), tipo, codice); + } + } + else + if (multi_clifo && not_dup) + return f.error_box(FR("Codice fiscale già utilizzato per il codice %s %ld\nsenza avere indicato il valore 4, 7 o G nell'inserimento in allegato"), + tipo, codice); + } + return true ; } HIDDEN bool no_dup_iva(TMask_field& f, KEY key) { - bool ok = true; + TMask& m = f.mask() ; - TMask& msk = f.mask() ; - if (msk.query_mode() || !f.to_check(key)) - return ok; - - if (!f.empty()) - { - TLocalisamfile clifo(LF_CLIFO) ; - clifo.put(CLI_TIPOCF, msk.get(F_TIPOCF)) ; - clifo.put(CLI_STATOPAIV, msk.get(F_STATOPAIV)) ; - clifo.put(CLI_PAIV, f.get()) ; - clifo.setkey(5) ; - const int err = clifo.read() ; - if (err == NOERR) - { - const long s = clifo.get_long(CLI_CODCF); - const long s1 = msk.get_long(F_CODCF); - if (s1 != s) - ok = f.error_box(FR("Partita IVA gia' utilizzata per il codice %ld" - "\nsenza avere indicato il valore 4, 7 o G nell'inserimento in allegato"), s); - } - } - - return ok; + if (f.full()) + { + const bool only_one_paiv = ini_get_bool(CONFIG_DITTA, "cg", "OnlyOnePaIV"); + TRectype from(LF_CLIFO); + + from.put(CLI_TIPOCF, m.get(F_TIPOCF)); + from.put(CLI_STATOPAIV, m.get(F_STATOPAIV)); + from.put(CLI_PAIV, m.get(F_PAIV)); + + TCursor c(new TRelation(LF_CLIFO), "", 5, &from, &from); + + const TString4 alleg = m.get(F_ALLEG); + const bool multi_clifo = c.items(); + const bool not_dup = (alleg != "4" && alleg != "7" & alleg != "G"); + + c = 0L; + + const char * tipo = c.curr().get(CLI_TIPOCF) == "C" ? "cliente" : "fornitore"; + const long codice = c.curr().get_long(CLI_CODCF); + + if (only_one_paiv) + { + if (multi_clifo) + { + if (supervisor()) + { + if (not_dup) + return f.error_box(FR("Partita IVA gia' utilizzata per il codice %s ld\nsenza avere indicato il valore 4, 7 o G nell'inserimento in allegato"), + tipo, codice); + } + else + return f.error_box(FR("Partita IVA gia' utilizzata per il codice %s %ld"), tipo, codice); + } + } + else + if (multi_clifo && not_dup) + return f.error_box(FR("Partita IVA gia' utilizzata per il codice %s %ld\nsenza avere indicato il valore 4, 7 o G nell'inserimento in allegato"), + tipo, codice); + } + return true; } // Controlla la presenza di Codice Fiscale e/o Partita IVA @@ -231,7 +259,7 @@ HIDDEN bool almeno_cf_o_pi(TMask_field& f) const TEdit_field& cofi = m.efield(F_COFI); if (cofi.empty()) // Dal 2007 serve il codice fiscale ok = cofi.yesno_box(TR("Codice fiscale assente per residente in Italia : lo accetto ugualmente ?")); - // Se NON sono privato (alleg!=6), serve partita IVA + // Se NON sono privato (alleg != 6), serve partita IVA if (ok) { const TEdit_field& paiv = m.efield(F_PAIV); @@ -245,56 +273,32 @@ HIDDEN bool almeno_cf_o_pi(TMask_field& f) } HIDDEN bool cofi_handler(TMask_field& f, KEY key) -{ - bool ok = true; +{ + TMask& m = f.mask(); - TMask& m = f.mask(); - if (key == K_ENTER && !f.dirty() && !m.query_mode()) - ok = ((TEdit_field&)f).validate(key); - - if (ok && f.to_check(key)) - { - if (key == K_TAB) - { - const TString& s1 = f.get(); - if (s1.full()) - m.set(F_TIPOPERS, isdigit(s1[0]) ? "G" : "F"); - } - const int alleg = m.get_int(F_ALLEG); - if (!m.query_mode() && key == K_ENTER && alleg != 4) - { - ok = no_dup_fis(f, key); - if (ok) - ok = almeno_cf_o_pi(f); - } - } - - return ok; + if (!m.query_mode()) + { + if (f.running_check(key)) + { + const TString& s1 = f.get(); + + if (s1.full()) + m.set(F_TIPOPERS, isdigit(s1[0]) ? "G" : "F"); + } + else + if (f.final_check(key)) + return f.validate(key) && no_dup_fis(f, key) && almeno_cf_o_pi(f); + } + return true; } HIDDEN bool paiv_handler(TMask_field& f, KEY key) { - bool ok = true; const TMask& m = f.mask(); - if (key == K_ENTER && !m.query_mode()) - { - if (!f.dirty()) - ok = ((TEdit_field&)f).validate(key); - - if (ok) - { - const TString4 alleg = m.get(F_ALLEG); - if (alleg != "4" && alleg != "7" && alleg != "G") - { - ok = no_dup_iva(f, key); - if (ok) - ok = almeno_cf_o_pi(f); - } - } - } - - return ok; + if (!m.query_mode() && f.final_check(key)) + return f.validate(key) && no_dup_iva(f, key) && almeno_cf_o_pi(f); + return true; } bool TClifo_application::tipocf_handler(TMask_field& f, KEY key) @@ -540,30 +544,39 @@ bool TClifo_application::comi_handler(TMask_field& f, KEY k) bool TClifo_application::rfso_handler(TMask_field& f, KEY key) { - if(f.get() == "G") + if (f.to_check(key)) { - f.mask().show(F_COD_RFSO_G); - f.mask().enable(F_COD_RFSO_G); - f.mask().set(F_COD_RFSO_F, ""); - f.mask().hide(F_COD_RFSO_F); - f.mask().disable(F_COD_RFSO_F); - } - else if(f.get() == "F") - { - f.mask().show(F_COD_RFSO_F); - f.mask().enable(F_COD_RFSO_F); - f.mask().set(F_COD_RFSO_G, ""); - f.mask().hide(F_COD_RFSO_G); - f.mask().disable(F_COD_RFSO_G); - } - else - { - f.mask().set(F_COD_RFSO_F, ""); - f.mask().set(F_COD_RFSO_G, ""); - f.mask().hide(F_COD_RFSO_F); - f.mask().hide(F_COD_RFSO_G); - f.mask().disable(F_COD_RFSO_F); - f.mask().disable(F_COD_RFSO_G); + TMask & m = f.mask(); + const TString & val = f.get(); + + if (val == "G") + { + m.show(F_COD_RFSO_G); + m.enable(F_COD_RFSO_G); + m.set(F_COD_RFSO_F, ""); + m.hide(F_COD_RFSO_F); + m.disable(F_COD_RFSO_F); + } + else + { + if (val == "F") + { + m.show(F_COD_RFSO_F); + m.enable(F_COD_RFSO_F); + m.set(F_COD_RFSO_G, ""); + m.hide(F_COD_RFSO_G); + m.disable(F_COD_RFSO_G); + } + else + { + f.mask().set(F_COD_RFSO_F, ""); + f.mask().set(F_COD_RFSO_G, ""); + f.mask().hide(F_COD_RFSO_F); + f.mask().hide(F_COD_RFSO_G); + f.mask().disable(F_COD_RFSO_F); + f.mask().disable(F_COD_RFSO_G); + } + } } return true; } @@ -608,12 +621,6 @@ HIDDEN bool alleg_handler(TMask_field& f, KEY key) TMask& m = f.mask(); - if (tipoall == 4) - { - TToken_string key; key.format("%c|%ld", m.get(F_TIPOCF)[0], m.get_long(F_CODALLEG)); - const TRectype& coll = cache().get(LF_CLIFO, key); - } - if (key == K_ENTER) { if (m.get_bool(F_OCCASIONALE)) @@ -656,16 +663,16 @@ HIDDEN bool codalleg_handler(TMask_field& f, KEY key) if (cod == m.get(F_CODCF)) return error_box(TR("Il codice per allegato coincide con il codice anagrafico")); - const char tipo = m.get(F_TIPOCF)[0]; + TToken_string key = m.get(F_TIPOCF); + + key.add(cod); - TString8 key; key.format("%c|%s", tipo, (const char*)cod); const TRectype& clifo = cache().get(LF_CLIFO, key); - if (clifo.empty()) - return false; - + + if (clifo.empty()) + return error_box(TR("Il codice per allegato assente")); if (clifo.get(CLI_CODALLEG).full()) return error_box(TR("Codice non utilizzabile: contiene a sua volta un codice per allegato")); - if (clifo.get(CLI_PAIV).blank() && clifo.get(CLI_COFI).blank()) return error_box(TR("Codice non utilizzabile: partita IVA e codice fiscale non specificati"));