From f2550d1fa0d753efedf2611e0cc40a11de4c143a Mon Sep 17 00:00:00 2001 From: Alessandro Bonazzi Date: Fri, 11 Apr 2025 15:19:57 +0200 Subject: [PATCH] Patch level : 12.00 1388 Files correlati : cg0.exe ve0.exe ve0100o.msk cg0700.msk Commento: Trasformazione occasionali in clienti/fornitori --- src/cg/cg0700.cpp | 198 ++++++++++++++++++++++++---------------------- 1 file changed, 103 insertions(+), 95 deletions(-) diff --git a/src/cg/cg0700.cpp b/src/cg/cg0700.cpp index f411b005a..89ff390ef 100755 --- a/src/cg/cg0700.cpp +++ b/src/cg/cg0700.cpp @@ -20,19 +20,49 @@ #include #include +class TOccasionali_mask; + +class TOccasionali_app : public TRelation_application +{ + TOccasionali_mask * _msk; + TRelation * _rel; + + bool user_create(); + bool user_destroy(); + virtual void init_query_mode(TMask&) override; + // @cmember Inizializza la maschera per il modo inserimento + virtual void init_insert_mode(TMask&) override; + // @cmember Inizializza la maschera per il modo modifica + virtual void init_modify_mode(TMask&) override; + virtual TMask* _get_mask(int mode) { return (TMask *) _msk; } + virtual bool changing_mask(int mode) { return false; } + virtual void ini2mask(TConfig& ini, TMask& m, bool query) override; + virtual void mask2ini(const TMask& m, TConfig& ini) override; + +public: + // @cmember Disabilita la verifica del modulo : essendo una anagrafica, va sempre abilitata + virtual bool check_autorization() const { return false; } + virtual TRelation* get_relation() const { return _rel; } +}; + +HIDDEN inline TOccasionali_app& app() { return (TOccasionali_app&)main_app(); } + /////////////////////////////////////////////////////////// -// TCheck_PIVA_mask +// TOccasionali_mask /////////////////////////////////////////////////////////// class TOccasionali_mask : public TAutomask { + long _codcf; + protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: void update_ban(const char * tipo, long codcf, const TRectype & recdoc); void occ2clifor(const char * tipo); - TOccasionali_mask() : TAutomask("cg0700a") { } + long codice() const { return _codcf; } + TOccasionali_mask() : TAutomask("cg0700a"), _codcf(0L) { } }; void TOccasionali_mask::update_ban(const char * tipo, long codcf, const TRectype & recdoc) @@ -117,10 +147,9 @@ void TOccasionali_mask::occ2clifor(const char * tipo) TToken_string key = tipo; bool italian = get(O_STATOPAIV).blank(); bool found = false; - long codcf = 0L; - TString8 para; TString ragsoc; + _codcf = 0L; if (get(O_PAIV).full()) { key.add(get(O_STATOPAIV)); @@ -129,7 +158,7 @@ void TOccasionali_mask::occ2clifor(const char * tipo) const TRectype & clifor = cache().get(LF_CLIFO, key, 5); ragsoc = clifor.get(CLI_RAGSOC); - codcf = clifor.get_long(CLI_CODCF); + _codcf = clifor.get_long(CLI_CODCF); found = clifor.full(); if (italian && !found) { @@ -138,7 +167,7 @@ void TOccasionali_mask::occ2clifor(const char * tipo) found = clifor.full(); ragsoc = clifor.get(CLI_RAGSOC); - codcf = clifor.get_long(CLI_CODCF); + _codcf = clifor.get_long(CLI_CODCF); } if (found) { @@ -155,7 +184,7 @@ void TOccasionali_mask::occ2clifor(const char * tipo) const TRectype & clifor = cache().get(LF_CLIFO, key, 4); found = clifor.full(); - codcf = clifor.get_long(CLI_CODCF); + _codcf = clifor.get_long(CLI_CODCF); ragsoc = clifor.get(CLI_RAGSOC); if (found) { @@ -166,79 +195,63 @@ void TOccasionali_mask::occ2clifor(const char * tipo) } if (!found) { - TFilename tmp; + TFilename tmp; tmp.temp("occcf", "ini"); + TTransaction t(tmp); - tmp.temp("occ", "ini"); + _codcf = 0L; + t.set_executer(LF_CLIFO); + t.set_firm(main_app().get_firm()); + t.set_user(); + t.set_hostname(); + t.set_version(); + t.set_mode(transaction_mode_automatic); + t.set_action(TRANSACTION_INSERT); + t.set(CLI_RAGSOC, get(O_RAGSOC), -1, LF_CLIFO); + t.set(CLI_STATOCF, get(O_STATO), -1, LF_CLIFO); + t.set(CLI_COMCF, get(O_COMUNE), -1, LF_CLIFO); + t.set(CLI_CAPCF, get(O_CAP), -1, LF_CLIFO); + t.set(CLI_INDCF, get(O_INDIRIZZO), -1, LF_CLIFO); + t.set(CLI_CIVCF, get(O_NUMERO), -1, LF_CLIFO); + t.set(CLI_COFI, get(O_COFI), -1, LF_CLIFO); + t.set(CLI_STATOPAIV, get(O_STATOPAIV), -1, LF_CLIFO); + t.set(CLI_PAIV, get(O_PAIV), -1, LF_CLIFO); + t.set(CLI_SESSO, get(O_SESSO), -1, LF_CLIFO); + t.set(CLI_DATANASC, get(O_DATANAS), -1, LF_CLIFO); + t.set(CLI_STATONASC, get(O_STATONAS), -1, LF_CLIFO); + t.set(CLI_COMNASC, get(O_COMUNENAS), -1, LF_CLIFO); + t.set(CLI_LOCCF, get(O_LOCALITA), -1, LF_CLIFO); + t.set(CLI_REFERENTE, get(O_REFERENTE), -1, LF_CLIFO); + t.set(CLI_BYMAIL, get(O_BYMAIL), -1, LF_CLIFO); + t.set(CLI_MAIL, get(O_MAIL), -1, LF_CLIFO); + t.set(CLI_DOCMAIL, get(O_DOCMAIL), -1, LF_CLIFO); + t.set(CLI_PEC, get(O_PEC), -1, LF_CLIFO); + t.set(CLI_PTEL, get(O_PTEL), -1, LF_CLIFO); + t.set(CLI_TEL, get(O_TEL), -1, LF_CLIFO); + t.set(CLI_PTEL2, get(O_PTEL2), -1, LF_CLIFO); + t.set(CLI_TEL2, get(O_TEL2), -1, LF_CLIFO); + t.set(CLI_PTEL3, get(O_PTEL3), -1, LF_CLIFO); + t.set(CLI_TEL3, get(O_TEL3), -1, LF_CLIFO); + t.set(CLI_TIPOPERS, get(O_TIPOPERS), -1, LF_CLIFO); + t.set(CLI_ALLEG, get(O_ALLEG), -1, LF_CLIFO); + t.set(CLI_PFAX, get(O_PFAX), -1, LF_CLIFO); + t.set(CLI_FAX, get(O_FAX), -1, LF_CLIFO); + t.set(CFV_PADESTIN, get(O_PADESTIN), -1, LF_CFVEN); + t.write(); + if (t.execute()) { - TConfig ini(tmp, "Transaction"); - ini.set("Firm", main_app().get_firm()); - ini.set("User", user()); - ini.set("HostName", get_hostname()); - - int year, release, tag, patch; - if (main_app().get_version_info(year, release, tag, patch)) - { - TString80 ver; - ver.format("%d %d.%d-%d", year, release, tag, patch); - ini.set("Version", ver); - } - char mode[2] = { transaction_mode_automatic, '\0' }; - - ini.set("Action", TRANSACTION_INSERT); - ini.set("Mode", mode); - para.format("%d", LF_CLIFO); - ini.set(CLI_RAGSOC, get(O_RAGSOC), para); - ini.set(CLI_STATOCF, get(O_STATO)); - ini.set(CLI_COMCF, get(O_COMUNE)); - ini.set(CLI_CAPCF, get(O_CAP)); - ini.set(CLI_INDCF, get(O_INDIRIZZO)); - ini.set(CLI_CIVCF, get(O_NUMERO)); - ini.set(CLI_COFI, get(O_COFI)); - ini.set(CLI_STATOPAIV, get(O_STATOPAIV)); - ini.set(CLI_PAIV, get(O_PAIV)); - ini.set(CLI_SESSO, get(O_SESSO)); - ini.set(CLI_DATANASC, get(O_DATANAS)); - ini.set(CLI_STATONASC, get(O_STATONAS)); - ini.set(CLI_COMNASC, get(O_COMUNENAS)); - ini.set(CLI_LOCCF, get(O_LOCALITA)); - ini.set(CLI_REFERENTE, get(O_REFERENTE)); - ini.set(CLI_BYMAIL, get(O_BYMAIL)); - ini.set(CLI_MAIL, get(O_MAIL)); - ini.set(CLI_DOCMAIL, get(O_DOCMAIL)); - ini.set(CLI_PEC, get(O_PEC)); - ini.set(CLI_PTEL, get(O_PTEL)); - ini.set(CLI_TEL, get(O_TEL)); - ini.set(CLI_PTEL2, get(O_PTEL2)); - ini.set(CLI_TEL2, get(O_TEL2)); - ini.set(CLI_PTEL3, get(O_PTEL3)); - ini.set(CLI_TEL3, get(O_TEL3)); - ini.set(CLI_TIPOPERS, get(O_TIPOPERS)); - ini.set(CLI_ALLEG, get(O_ALLEG)); - ini.set(CLI_PFAX, get(O_PFAX)); - ini.set(CLI_FAX, get(O_FAX)); - para.format("%d", LF_CFVEN); - ini.set(CFV_PADESTIN, get(O_PADESTIN), para); + t.read(); + _codcf = t.get_long(CLI_CODCF, -1, LF_CLIFO); } - - TString cmd("cg0 -1 -i"); cmd << tmp; - TExternal_app app(cmd); - - app.run(); - para.format("%d", LF_CLIFO); - - TConfig ini(tmp, para); - - codcf = ini.get_long(CLI_CODCF); tmp.fremove(); } - if (codcf > 0L) + if (_codcf > 0L) { TMask m("cg0700b"); TDate from = today; m.set(F_CODICE, get(O_CODICE)); - m.set(F_CODCF, codcf); + m.set(F_CODCF, _codcf); m.set(F_RAGSOC, ragsoc); from.set_start_year(); m.set(F_FROM, from); @@ -264,13 +277,13 @@ void TOccasionali_mask::occ2clifor(const char * tipo) { TDocumento doc(recdoc); - doc.put(DOC_CODCF, codcf); + doc.put(DOC_CODCF, _codcf); doc.zero(DOC_OCFPI); doc.zero(DOC_OCCAS); doc.rewrite(); } key = tipo; - key.add(codcf); + key.add(_codcf); TRectype & clifor = (TRectype &) cache().get(LF_CLIFO, key); clifor_recset.move_last(); @@ -278,7 +291,7 @@ void TOccasionali_mask::occ2clifor(const char * tipo) clifor.put(CLI_CODLIN, recdoc.get(DOC_CODLIN)); clifor.put(CLI_CODPAG, recdoc.get(DOC_CODPAG)); clifor.rewrite(); - update_ban(tipo, codcf, recdoc); + update_ban(tipo, _codcf, recdoc); TRectype & cfven = (TRectype &)cache().get(LF_CFVEN, key); @@ -295,6 +308,8 @@ void TOccasionali_mask::occ2clifor(const char * tipo) cfven.write_rewrite(); } } + if (app().is_transaction()) + stop_run(K_SAVE); } } @@ -347,29 +362,6 @@ bool TOccasionali_mask::on_field_event(TOperable_field& o, TField_event e, long return true; } -class TOccasionali_app : public TRelation_application -{ - TOccasionali_mask * _msk; - TRelation * _rel; - - bool user_create(); - bool user_destroy(); - virtual void init_query_mode(TMask&) override; - // @cmember Inizializza la maschera per il modo inserimento - virtual void init_insert_mode(TMask&) override; - // @cmember Inizializza la maschera per il modo modifica - virtual void init_modify_mode(TMask&) override; - virtual TMask* _get_mask(int mode) {return _msk;} - virtual bool changing_mask(int mode) {return false;} - void ini2mask(TConfig& ini, TMask& m, bool query); - -public: - // @cmember Disabilita la verifica del modulo : essendo una anagrafica, va sempre abilitata - virtual bool check_autorization() const { return false; } - virtual TRelation* get_relation() const {return _rel;} -}; - -HIDDEN inline TOccasionali_app& app() { return (TOccasionali_app&) main_app();} void TOccasionali_app::init_query_mode(TMask& m) { @@ -428,8 +420,24 @@ void TOccasionali_app::ini2mask(TConfig& ini, TMask& m, bool query) } TRelation_application::ini2mask(ini, m, query); + + const TString4 tipo = ini.get(CLI_TIPOCF, TOSTRING(LF_CLIFO)); + + if (tipo == "F") + m.disable(DLG_CLI); + else + if (tipo == "C") + m.disable(DLG_FOR); } +void TOccasionali_app::mask2ini(const TMask& m, TConfig& ini) +{ + const long codice = _msk->codice(); + + TRelation_application::mask2ini(m, ini); + if (codice > 0L) + ini.set(CLI_CODCF, codice, TOSTRING(LF_CLIFO)); +} int cg0700(int argc, char* argv[]) {