From 112077197ed3a63279f99fdc7de979e3e20a8231 Mon Sep 17 00:00:00 2001 From: Simone Palacino Date: Thu, 16 May 2019 09:34:21 +0200 Subject: [PATCH] Patch level : 12.0 790 Files correlati : fp044, cg2100, f1 Commento : - Tolta esportazione protocollo ingresso su movimento (verra' fatto con l'F9) - Aggiunto flag se registrazione collegata a FPPRO - Corretta eliminazione massiva movimenti - Cambiata modalita' modifica: non permetteva di salvare a prescindere dalle modifiche (mantenuto comunque il controllo preventivo) - Creazione libreria per F1 - Spostate funzioni strettamente legate all'F1 nella relativa lib - Aggiunto controllo per apertura automatica maschera FPPRO: Si apriva da sola quando eseguivo dal monitor delle fat. passive - Dati documento salvati internamente e non su maschera per passaggio da maschera FPPRO a maschera cg - fp-f1 passive: - Aggiunta contabilizzazione automatica da fp fatt. passive con protocollo ini - Corretta comportamento bottoni toolbar (abilita/disabilita) - Aggiunto range data per fatture contabilizzate - Aggiunto controllo se fornitore e' sospeso non lo propongo - Aggiunte causali di default per contabilizzazione - Salvate date e causali default su config. ditta --- build/f1lib.vcxproj | 173 +++++++++++++++++++++ build/f1lib.vcxproj.filters | 21 +++ build/f1lib.vcxproj.user | 4 + src/cg/cg2100.cpp | 12 +- src/cg/cg2100.h | 1 + src/cg/cg2100c.uml | 10 +- src/cg/cg2102.cpp | 69 ++++----- src/cg/cg2102.h | 24 ++- src/f1/f1lib.cpp | 141 +++++++++++++++++ src/f1/f1lib.h | 59 ++++++++ src/fp/fp0400.cpp | 293 ++++++++++++++++++++++++++++++++---- src/fp/fp0400a.h | 9 ++ src/fp/fp0400a.uml | 126 +++++++++++++++- 13 files changed, 869 insertions(+), 73 deletions(-) create mode 100644 build/f1lib.vcxproj create mode 100644 build/f1lib.vcxproj.filters create mode 100644 build/f1lib.vcxproj.user create mode 100644 src/f1/f1lib.cpp create mode 100644 src/f1/f1lib.h diff --git a/build/f1lib.vcxproj b/build/f1lib.vcxproj new file mode 100644 index 000000000..fa7086b48 --- /dev/null +++ b/build/f1lib.vcxproj @@ -0,0 +1,173 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {41F4C25F-6BD2-4FC9-A0D3-A68CD1C9E4FC} + fp + 10.0.17763.0 + + + + StaticLibrary + false + v141 + + + StaticLibrary + false + v141 + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\lib\ + ..\obj\$(SolutionName)\$(ProjectName)\ + false + ..\lib\ + ..\obj\$(SolutionName)\$(ProjectName)\ + false + false + false + .lib + .lib + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\..\debug/fplib.tlb + + + + + Disabled + ..\src\f1\;..\src\xvtdb\;..\src\cg;..\src\include;..\src\xvaga;%(AdditionalIncludeDirectories) + _DEBUG;WIN32;_WINDOWS;__LONGDOUBLE__;%(PreprocessorDefinitions) + false + MultiThreadedDebug + $(IntDir)$(TargetName).pch + $(IntDir) + $(IntDir) + $(IntDir)$(TargetName).pdb + Level3 + true + ProgramDatabase + true + + + _DEBUG;%(PreprocessorDefinitions) + 0x0410 + ..\wx28X\include;%(AdditionalIncludeDirectories) + + + wsock32.lib;%(AdditionalDependencies) + $(OutDir)$(TargetName)$(TargetExt) + true + %(IgnoreSpecificDefaultLibraries) + true + $(TargetDir)$(TargetName).pdb + Windows + false + + + MachineX86 + NotSet + + + true + .\..\debug/fplib.bsc + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\..\release/fplib.tlb + + + + + MaxSpeed + ..\src\xvtdb\;..\src\cg;..\src\include;..\src\xvaga;%(AdditionalIncludeDirectories) + NDEBUG;WIN32;_WINDOWS;%(PreprocessorDefinitions) + true + MultiThreaded + true + false + Level3 + true + + + NDEBUG;%(PreprocessorDefinitions) + 0x0410 + ..\wx28X\include;%(AdditionalIncludeDirectories) + + + wsock32.lib;%(AdditionalDependencies) + true + %(IgnoreSpecificDefaultLibraries) + Windows + + + MachineX86 + 12.0 + false + $(OutDir)$(TargetName)$(TargetExt) + $(TargetDir)$(TargetName).pdb + + + true + .\..\release/fplib.bsc + + + + + Document + true + + + Document + true + + + + + {2d38a763-3d74-4338-9362-b891784ec90e} + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/f1lib.vcxproj.filters b/build/f1lib.vcxproj.filters new file mode 100644 index 000000000..c61d72f6b --- /dev/null +++ b/build/f1lib.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + {afbf9839-55d1-46a9-9d8a-45e41e3d3d11} + + + {1ca586f9-1511-48e9-89db-65f13a861684} + + + + + Sources + + + + + Headers + + + \ No newline at end of file diff --git a/build/f1lib.vcxproj.user b/build/f1lib.vcxproj.user new file mode 100644 index 000000000..be2507870 --- /dev/null +++ b/build/f1lib.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/cg/cg2100.cpp b/src/cg/cg2100.cpp index f1291272d..e24c837f9 100755 --- a/src/cg/cg2100.cpp +++ b/src/cg/cg2100.cpp @@ -126,6 +126,7 @@ TMask* TPrimanota_application::load_mask(int n) if (!is_fp(m)) { m->hide(F_PROTFPPRO); + m->hide(F_COLFPPRO); if(m->find_by_id(DLG_LINK) != NULL) m->disable(DLG_LINK); } @@ -1051,7 +1052,12 @@ void TPrimanota_application::init_modify_mode(TMask& m) m.enable(F_BOLLARAGCLI, causale().tipo_doc() == "BD"); } if(m.find_by_id(F_PROTFPPRO) != NULL && !m.field(F_PROTFPPRO).hidden()) + { m.set(F_PROTFPPRO, mov.get(MOV_PROGFPPRO)); + m.set(F_COLFPPRO, mov.get(MOV_KEYFPPRO).empty() ? " " : "X"); + } + + } // Controlla sulla causale se il segno del totale documento (ritsoc=false) @@ -1573,7 +1579,7 @@ void TPrimanota_application::clean_fppro() // Controlli: solo in mod modifica; che abbia fp (no F8); che non sono in salvataggio if (_mode != MODE_MOD || !is_fp(&msk) - || last_key != K_DEL && last_key != K_SAVE) + || last_key != K_DEL && last_key != K_SAVE && last_key != K_ELIMMAS) return; const TString& numreg = msk.get(F_NUMREG); @@ -2372,8 +2378,6 @@ int TPrimanota_application::save_fppro() { message_box(TString("Attenzione!") << " E' stato modificato un movimento già collegato a un documento in ingresso."); clean_fppro(); // Pulisco db - msk.set(F_PROKEY, ""); - msk.set(F_PROTFPPRO, ""); save_dbmov(); // Svuoto riferimento doc ingresso sul mov } } @@ -2382,7 +2386,7 @@ int TPrimanota_application::save_fppro() } // Controllo che sto registrando un documento FA Fattura di Acquisto o NC Acquisto - if (!TPro_msk::check_causale(msk.get(F_CODCAUS))) + if (!check_causale(msk.get(F_CODCAUS))) return pro_notsaved; if (last != K_SAVE) { // Se sto uscendo avvertimento di non salvataggio e salto message_box("La registrazione del movimento non verrà salvata sul database."); diff --git a/src/cg/cg2100.h b/src/cg/cg2100.h index 9c9fb80d2..3389e89b5 100755 --- a/src/cg/cg2100.h +++ b/src/cg/cg2100.h @@ -22,6 +22,7 @@ #define F_PROTFPPRO 230 #define F_RITFATT 231 #define F_PROKEY 232 +#define F_COLFPPRO 233 #define F_CLIFO 128 #define F_CODCLIFOR 151 diff --git a/src/cg/cg2100c.uml b/src/cg/cg2100c.uml index e0930e3d0..88f5e2200 100755 --- a/src/cg/cg2100c.uml +++ b/src/cg/cg2100c.uml @@ -609,9 +609,16 @@ BEGIN DRIVENBY F_VALUTAINTRA END +BOOLEAN F_COLFPPRO +BEGIN + PROMPT 1 18 "Registrazione collegata a FPPRO" + FLAGS "D" +END + STRING F_PROTFPPRO 18 BEGIN - PROMPT 1 18 "Codice Protocollo FPPRO " + PROMPT 1 19 "Codice Protocollo FPPRO " + FIELD PROGFPPRO FLAGS "D" END @@ -619,6 +626,7 @@ STRING F_PROKEY 80 BEGIN PROMPT 1 18 "db key" HELP "Chiave database" + FIELD KEYFPPRO FLAGS "H" END diff --git a/src/cg/cg2102.cpp b/src/cg/cg2102.cpp index 194a829a7..c0dbd4002 100755 --- a/src/cg/cg2102.cpp +++ b/src/cg/cg2102.cpp @@ -20,6 +20,7 @@ #include #include #include "../fp/fplib.h" +#include "../f1/f1lib.h" /////////////////////////////////////////////////////////// // Funzioni di decodifica/calcolo @@ -2263,13 +2264,13 @@ void TPrimanota_application::check_fppro_fields(TMask& m) { if (app().is_fp(&m)) { - if (!TPro_msk::check_causale(m.get(F_CODCAUS)) && m.find_by_id(F_PROTFPPRO) != NULL) + if (!check_causale(m.get(F_CODCAUS)) && m.find_by_id(F_PROTFPPRO) != NULL) { m.hide(F_PROTFPPRO); m.disable(DLG_LINK); } else - if (TPro_msk::check_causale(m.get(F_CODCAUS)) && m.find_by_id(F_PROTFPPRO) != NULL && m.field(F_PROTFPPRO).hidden()) + if (check_causale(m.get(F_CODCAUS)) && m.find_by_id(F_PROTFPPRO) != NULL && m.field(F_PROTFPPRO).hidden()) { m.show(F_PROTFPPRO); m.enable(DLG_LINK); @@ -3006,7 +3007,8 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) const bool ic = ixc->active() && (alleg < 5 || alleg == 7) && paiv.full() && !m.get_bool(F_LIQDIFF); ixc->set(ic ? "X" : ""); } - fppro_mask(f, key); + if(m.get(F_PROKEY).empty()) + fppro_mask(f, key); } } @@ -3846,28 +3848,37 @@ bool TPrimanota_application::quadratura_handler(TMask_field& f, KEY key) bool TPrimanota_application::fppro_mask(TMask_field& f, KEY key) { TMask& cg_msk = f.mask(); - if (!app().get_isfp() || key != K_SPACE && key != K_TAB || !TPro_msk::check_causale(f.mask().get(F_CODCAUS))) + if (!app().get_isfp() || key != K_SPACE && key != K_TAB || !check_causale(f.mask().get(F_CODCAUS))) return true; auto msk = std::make_shared(cg_msk); + app()._pro_mask = msk; - //load_list(msk, key); - //if(load_fppro_mask(msk)) if (msk->load_fppro_mask(msk.get())) { msk->run(); // Riporto dati FPPRO su maschera Prima Nota - cg_msk.set(F_NUMDOCEXT, msk->get(F_NUMEROI)); - cg_msk.set(F_NUMDOC, TString(msk->get(F_NUMEROI)).right(7)); - cg_msk.set(F_DATADOC, msk->get(F_DATAI)); - cg_msk.set(F_TOTALE, msk->get(F_TOTDOCI)); - cg_msk.set(F_PROTFPPRO, msk->get(F_PROTFPPROI)); - cg_msk.set(F_PROKEY, msk->get(F_FPPROKEYSI)); + cg_msk.set(F_NUMDOCEXT, msk->get_numdoc()); + cg_msk.set(F_NUMDOC, msk->get_numdoc().right(7)); + cg_msk.set(F_DATADOC, msk->get_datadoc()); + cg_msk.set(F_TOTALE, msk->get_totdoc()); + //cg_msk.set(F_PROTFPPRO, msk->get_protocollo()); + cg_msk.set(F_PROKEY, msk->get_fpprokeys()); + is_collegato(cg_msk.field(F_COLFPPRO)); + cg_msk.set(F_ANNORIF, cg_msk.get(F_ANNOIVA)); } return true; } +bool TPrimanota_application::is_collegato(TMask_field& f) +{ + TMask& cg_msk = f.mask(); + const bool has_prokey = !cg_msk.get(F_PROKEY).empty(); + f.set(has_prokey ? "X" : " "); + return has_prokey; +} + bool TPro_msk::load_fppro_mask(TMask* msk, KEY k) { // Provo a vedere se hanno l'FP: se c'è l'indirizzo controllo che non sia F8 se non c'è non hanno l'FP @@ -3955,12 +3966,8 @@ bool TPro_msk::fppro_ok_handler(TMask_field& f, KEY k) { if(!loaded && *row->get(0) == 'X') { - msk.set(F_NUMEROI, row->get(5)); - msk.set(F_DATAI, row->get(3)); - msk.set(F_TOTDOCI, row->get(4)); - TString protocollo; protocollo << TDate(row->get(2)).year() << "-" << row->get(9) << "/" << row->get(10); - msk.set(F_PROTFPPROI, protocollo); - msk.set(F_FPPROKEYSI, row->get(11)); + //TProtocollo protocollo(TDate(row->get(2)).year(), row->get(9), row->get(10)); + app()._pro_mask->set_doc(row->get(5), row->get(3), row->get(4), "", row->get(11)); loaded = true; ok = true; break; @@ -3997,21 +4004,6 @@ bool TPro_msk::date_handler(TMask_field& f, KEY k) return ok; } -bool TPro_msk::check_causale(const TString& cod_caus) -{ - bool nc = false; - bool nc_acq = false; - bool fa = false; - TCausale caus(cod_caus); - - if ((nc = caus.tipo_doc() == "NC")) - nc_acq = caus.reg().tipo() == TIPO_REG_ACQ; - - fa = caus.tipo_doc() == "FA"; - - return fa || nc && nc_acq; -} - void TPro_msk::fppro_selfatt() const { const TMask& mask = *this; @@ -4059,6 +4051,15 @@ bool TPro_msk::on_field_event(TOperable_field& o, TField_event e, long jolly) return true; } +void TPro_msk::set_doc(const char* numero, const char* datadoc, const char* totdoc, const char* protfppro, const char* fpprokeys) +{ + _numero = numero; + _datadoc = datadoc; + _totdoc = totdoc; + _protfppro.sset(protfppro); + _fpprokeys = fpprokeys; +} + TString& TPro_msk::query_fppro(const TString& keyprginvio, const TString& keyheaderfatt, const TString& keybodyfatt, const TString& where_str) { @@ -4142,7 +4143,7 @@ void TPro_msk::abilita_piva(TMask* msk) } } -TPro_msk::TPro_msk(TMask& cg_msk) : TAutomask("cg2fppro"), _parent_mask(cg_msk) +TPro_msk::TPro_msk(TMask& cg_msk) : TAutomask("cg2fppro") { TMask::set_handler(DLG_CONFIG, fppro_handler); TMask::set_handler(DLG_LINK, fppro_ok_handler); diff --git a/src/cg/cg2102.h b/src/cg/cg2102.h index 598f032fb..7a8435c53 100755 --- a/src/cg/cg2102.h +++ b/src/cg/cg2102.h @@ -34,8 +34,10 @@ #endif #include +#include "../f1/f1lib.h" -#define TIPO_REG_ACQ 2 +#define TIPO_REG_ACQ 2 +#define K_ELIMMAS 0 // Key per eliminazione massima class TPro_msk; class TDati_mov_auto; @@ -96,6 +98,8 @@ class TPrimanota_application : public TRelation_application TAssoc_array _colori; // Colori delle righe bool _isfp; + shared_ptr _pro_mask; + friend class TPro_msk; static bool showpartite_handler(TMask_field& f, KEY k); static bool speserimb_handler(TMask_field& f, KEY k); @@ -180,6 +184,7 @@ class TPrimanota_application : public TRelation_application // Handlers per aggancio FPPRO // Bottone per maschera FPPRO static bool fppro_mask(TMask_field& f, KEY key); + static bool is_collegato(TMask_field& f); static void fppromask_set_handl(TMask* msk); static void load_list(TMask* msk, KEY k); @@ -376,7 +381,12 @@ public: class TPro_msk : public TAutomask { - TMask& _parent_mask; + TString _numero; + TDate _datadoc; + real _totdoc; + TProtocollo _protfppro; + TString _fpprokeys; + // Handlers per aggancio FPPRO // Bottone carica documenti in maschera FPPRO static bool fppro_handler(TMask_field& f, KEY k); @@ -388,6 +398,15 @@ class TPro_msk : public TAutomask void fppro_selfatt() const; bool on_field_event(TOperable_field& o, TField_event e, long jolly) override; public: + + void set_doc(const char* numero, const char* datadoc, const char* totdoc, const char* protfppro, const char* fpprokeys); + + TString get_numdoc() const { return _numero; } + TDate get_datadoc() const { return _datadoc; } + real get_totdoc() const { return _totdoc; } + TProtocollo& get_protocollo() { return _protfppro; } + TString get_fpprokeys() const { return _fpprokeys; } + static TString& query_fppro(const TString& keyprginvio, const TString& keyheaderfatt, const TString& keybodyfatt, const TString& where_str); static TString& query_fppro(const TString& codforn, const TString& date); static TString& query_fppro(const TString& stato_piva, const TString& piva, const TString& date); @@ -396,7 +415,6 @@ public: //bool is_fp(); // Carica documenti FPPRO sulla maschera static bool load_fppro_mask(TMask* msk, KEY k = 32); - static bool check_causale(const TString& cod_caus); TPro_msk() = delete; TPro_msk(TMask& cg_msk); }; diff --git a/src/f1/f1lib.cpp b/src/f1/f1lib.cpp new file mode 100644 index 000000000..db217e0c6 --- /dev/null +++ b/src/f1/f1lib.cpp @@ -0,0 +1,141 @@ +#include "f1lib.h" +#include "config.h" +#include "modaut.h" +#include "cg2103.h" +#include "cg2102.h" +#include "execp.h" +#include "cfven.h" +#include "../fp/fp0400a.h" + +TString& TProtocollo::prot_in(const int year, const char* tipoprot, const char* progres) +{ + static TString protocollo; + TString tipo(tipoprot); + if (tipo.empty()) + tipo << "no_prot"; + protocollo.cut(0) << year << "-" << tipo << "/" << progres; + return protocollo; +} + +void TProtocollo::set(const TProtocollo prot) +{ + _year = prot._year; + _tipoprot = prot._tipoprot; + _progres = prot._progres; +} + +void TProtocollo::sset(const char* prot) +{ + TToken_string tok(prot, '-'); + _year = tok.get_int(); + TToken_string p(tok.get(), '/'); + _tipoprot = p.get(); + _progres = p.get(); +} + +TString& TProtocollo::get_prot() const +{ + return prot_in(_year, _tipoprot, _progres); +} + +void set_ini_codcaus(const TString& codcaus, const bool nc) +{ + ini_set_string(FILE_CONFIG, FILE_SECTION, nc? F1_CAUSNC : F1_CAUSFA, codcaus); +} + +const char* get_ini_codcaus(const bool nc) +{ + return ini_get_string(FILE_CONFIG, FILE_SECTION, nc ? F1_CAUSNC : F1_CAUSFA); +} + +const char* get_codcaus(const char * tipodoc, const char* codcf) +{ + TLocalisamfile cfven(LF_CFVEN); + cfven.put(CFV_TIPOCF, "F"); + cfven.put(CFV_CODCF, codcf); + const char* codcaus = ""; + const char* codcausnc = ""; + const bool nc = TString(tipodoc) == "TD04"; + + if (cfven.read() == NOERR) + { + codcaus = cfven.get(CFV_CODCAUS); + codcausnc = cfven.get(CFV_CODCAUSNC); + } + + if (nc) + { + if (!TString(codcausnc).empty()) + return codcausnc; + } + else + { + if (!TString(codcaus).empty()) + return codcaus; + } + return get_ini_codcaus(nc); +} + +bool check_causale(const TString& cod_caus) +{ + return check_causale(cod_caus, "FA") || check_causale(cod_caus, "NC"); +} + +bool get_endatareg() +{ + return ini_get_bool(FILE_CONFIG, FILE_SECTION, "endatareg"); +} + +TString get_datainireg() +{ + return ini_get_string(FILE_CONFIG, FILE_SECTION, "datainireg"); +} + +TString get_dataendreg() +{ + return ini_get_string(FILE_CONFIG, FILE_SECTION, "dataendreg"); +} + +void set_endatareg(bool enable) +{ + ini_set_bool(FILE_CONFIG, FILE_SECTION, "endatareg", enable); +} + +void set_datainireg(const TString& date) +{ + ini_set_string(FILE_CONFIG, FILE_SECTION, "datainireg", date); +} + +void set_dataendreg(const TString& date) +{ + ini_set_string(FILE_CONFIG, FILE_SECTION, "dataendreg", date); +} + +bool check_causale(const TString& cod_caus, const TString& tipo_doc) +{ + TCausale caus(cod_caus); + + if(tipo_doc == "FA") + return caus.tipo_doc() == "FA"; + + if (tipo_doc == "NC") + { + bool nc; + bool nc_acq = false; + if ((nc = caus.tipo_doc() == "NC")) + nc_acq = caus.reg().tipo() == TIPO_REG_ACQ; + return nc && nc_acq; + } + return false; +} + +void run_cont_ini() +{ + static TString run_string; +#ifdef DBG + run_string.cut(0) << "cg2 -0 -i" << F1_INIREGCONT << "*" << ".ini" << " /u" << user(); +#else + run_string.cut(0) << "cg2 -0 -i" << tmp_dir << "\\" << F1_REGCONT << "*" << ".ini" << " /u" << user(); +#endif + TExternal_app(run_string).run(); +} \ No newline at end of file diff --git a/src/f1/f1lib.h b/src/f1/f1lib.h new file mode 100644 index 000000000..7c3d585b8 --- /dev/null +++ b/src/f1/f1lib.h @@ -0,0 +1,59 @@ +#ifndef _F1LIBH_ +#define _F1LIBH_ + +#include "strings.h" +#include "config.h" + +#define FILE_CONFIG CONFIG_DITTA +#define FILE_SECTION "f1" +#define F1_CAUSFA "causfa" +#define F1_CAUSNC "causnc" +#define F1_INIREGCONT "cg2CONTAB" + +enum err_cont +{ + no_codcaus = -1, + no_selected = -2, + is_already_cont = -3, + is_ready = 0 +}; + +class TProtocollo : TObject +{ + int _year{}; + TString _tipoprot; + TString _progres; + +public: + TProtocollo() = default; + TProtocollo(const int year, const char* tipoprot, const char* progres): _year(year), _tipoprot(tipoprot), _progres(progres) { } + + void set(TProtocollo prot); + void sset(const char* prot); + TString& get_prot() const; + int get_year() const { return _year; } + TString& get_tipoprot() { return _tipoprot; } + TString& get_progres() { return _progres; } + + static TString& prot_in(int year, const char* tipoprot, const char* progres); + + operator const char*() const { return static_cast(get_prot()); } + +}; + +void set_ini_codcaus(const TString& codcaus, bool nc = false); +const char* get_ini_codcaus(bool nc = false); +const char* get_codcaus(const char * tipodoc, const char* codcf); +bool get_endatareg(); +TString get_datainireg(); +TString get_dataendreg(); +void set_endatareg(bool enable); +void set_datainireg(const TString& date); +void set_dataendreg(const TString& date); +// Controlla se il "cod_caus" e' per Fatture d'acquisto o Note Credito d'Acquisto +bool check_causale(const TString& cod_caus); +// Controlla se il "cod_caus" ha come "tipo_doc" FA o NC (di acquisto) +bool check_causale(const TString& cod_caus, const TString& tipo_doc); +void run_cont_ini(); + +#endif \ No newline at end of file diff --git a/src/fp/fp0400.cpp b/src/fp/fp0400.cpp index d0c2bffb8..2e452943b 100644 --- a/src/fp/fp0400.cpp +++ b/src/fp/fp0400.cpp @@ -13,6 +13,8 @@ #include "execp.h" #include "dongle.h" #include +#include "../f1/f1lib.h" +#include "../ba/bafrm.h" enum { @@ -28,6 +30,7 @@ enum { filtri = 0, elenco_fe = 1, elenco_err = 2 }; // Enum per bottoni toolbar class TPassive_mask : public TAutomask { + bool _f1; protected: bool _filter_changed; TFilename tmp_dir; @@ -43,17 +46,26 @@ protected: void select_all(int sheet_field); // Tasto nuovo: apre nuovo fornitore valorizzando già i dati dalla fattura - void new_forn(); + void new_forn(); // Tasto aggiorna: aggiorna cliente che non corrisponde. - void aggiorna_forn(); - void salva_for() const; - void clean_cg0(const TString& filename) const; - void run_cg0(const TString& filename) const; + void aggiorna_forn(); + void salva_for() const; + void clean_ini(const TString& filename) const; + void run_cg0(const TString& filename) const; + void elenco_prots_sel(TString& string) const; + + // Gestione F1 + int prepara_contab(); + void contabilizza(); + TDate load_data() const; + // Handlers + static bool causfa_handler(TMask_field& f, KEY k); + static bool causnc_handler(TMask_field& f, KEY k); bool on_field_event(TOperable_field& o, TField_event e, long jolly) override; void next_page(int p) override; // Elenco dei protocolli selezionati - void elenco_prots_sel(TString& string) const; + void fill(); static int find_fornitore(TLocalisamfile& clifo); static void add_row_err_forn(int forn_code, TSheet_field& sf_err, TString& denom); @@ -66,11 +78,7 @@ protected: public: void save_all_fields() const; - TPassive_mask() : TAutomask("fp0400a"), _filter_changed(true) - { - tmp_dir = tmp_dir.tempdir(); - load_all_fields(); - } + TPassive_mask(bool f1); }; void TPassive_mask::set_filter_changed() @@ -80,7 +88,20 @@ void TPassive_mask::set_filter_changed() void TPassive_mask::next_page(int p) { - //if(true) + field(DLG_EXPORT).enable((curr_page() + p == 1 || p == 1001) && _f1); + field(DLG_SAVEREC).enable(curr_page() + p == 1 || p == 1001); + if(p >= 1000) + { + field(DLG_NEWREC).enable(p == 1002); + field(DLG_RECALC).enable(p == 1002); + } + else + { + field(DLG_NEWREC).enable(curr_page() + p == 2 || curr_page() + p == 3); + field(DLG_RECALC).enable(curr_page() + p == 2 || curr_page() + p == 3); + } + + if (_filter_changed && p != 1000) { fill(); @@ -179,7 +200,8 @@ void TPassive_mask::aggiungi_riga(TLocalisamfile& clifo, TSheet_field& sf, TShee clifo.put(CLI_TIPOCF, 'F'); const int forn_code = find_fornitore(clifo); - if( filter_elab.blank() && forn_code != 0 || filter_elab == "E" && forn_code == 0 || filter_elab == "A") + const bool data_range = !get_bool(F_ENDATAREG) || dataregcont >= TDate(get(F_DATAINIREG)) && dataregcont <= TDate(get(F_DATAENDREG)); + if( filter_elab.blank() && forn_code != 0 || filter_elab == "E" && forn_code == 0 && data_range || filter_elab == "A") { TToken_string& row = sf.row(-1); if (denom.blank()) { @@ -285,11 +307,11 @@ void TPassive_mask::add_row_err_forn(const int forn_code, TSheet_field& sf_err, int TPassive_mask::find_fornitore(TLocalisamfile& clifo) { - TString paa_codfisc = fp_db().sq_get("COD_FISC"); - const TString paa_piva = fp_db().sq_get("P_IVA"); - TString paa_codpaese = fp_db().sq_get("COD_PAESE"); - const TString fppro_tipocf = fp_db().sq_get("TIPO_CF"); - TString fppro_codcf = fp_db().sq_get("COD_CLIFOR"); + TString paa_codfisc = fp_db().sq_get("COD_FISC"); + const TString paa_piva = fp_db().sq_get("P_IVA"); + TString paa_codpaese = fp_db().sq_get("COD_PAESE"); + const TString fppro_tipocf = fp_db().sq_get("TIPO_CF"); + TString fppro_codcf = fp_db().sq_get("COD_CLIFOR"); // Cerco se il fornitore è presente in Campo int found_clifo = -1; @@ -338,6 +360,23 @@ int TPassive_mask::find_fornitore(TLocalisamfile& clifo) clifo.put(CLI_COFI, paa_codfisc); clifo.read() == NOERR ? found_clifo = 4 : found_clifo = -14; // Se il cod fisc corrisponde setto a 2 } + + // Se lo trovo controllo che non abbia il flag di sospeso se no ricerco ancora + bool noerr = true; + if (found_clifo == 2) + { + while (clifo.get_bool(CLI_SOSPESO) && noerr && clifo.get(CLI_PAIV) == paa_piva) + noerr = clifo.next() == NOERR; + if (clifo.get_bool(CLI_SOSPESO) || !noerr || clifo.get(CLI_PAIV) != paa_piva) + found_clifo = -5; + } + else if (found_clifo == 4) + { + while (clifo.get_bool(CLI_SOSPESO) && noerr && clifo.get(CLI_COFI) == paa_codfisc) + noerr = clifo.next() == NOERR; + if (clifo.get_bool(CLI_SOSPESO) || !noerr || clifo.get(CLI_COFI) != paa_codfisc) + found_clifo = -14; + } return found_clifo; } @@ -351,6 +390,44 @@ void TPassive_mask::load_all_fields() { } +bool TPassive_mask::causfa_handler(TMask_field& f, KEY k) +{ + if (k == K_TAB && f.focusdirty()) + { + TMask& msk = f.mask(); + TString codcaus(msk.get(F_CAUSFA)); + if (!check_causale(codcaus, "FA")) + { + warning_box("Impossibile selezionare questa causale registrazione.\nPrego inserire una causale di Fattura Acquisti"); + msk.field(F_CAUSFA).set(""); + msk.field(F_DESCAUSFA).set(""); + set_ini_codcaus(""); + return false; + } + set_ini_codcaus(codcaus); + } + return true; +} + +bool TPassive_mask::causnc_handler(TMask_field& f, KEY k) +{ + if (k == K_TAB && f.focusdirty()) + { + TMask& msk = f.mask(); + TString codcaus(msk.get(F_CAUSNC)); + if (!check_causale(codcaus, "NC")) + { + warning_box("Impossibile selezionare questa causale registrazione.\nPrego inserire una causale di Nota Credito Acquisti."); + msk.field(F_CAUSNC).set(""); + msk.field(F_DESCAUSNC).set(""); + set_ini_codcaus("", true); + return false; + } + set_ini_codcaus(codcaus, true); + } + return true; +} + void TPassive_mask::select_all(int sheet_field) { TSheet_field& docs = sfield(sheet_field); @@ -389,9 +466,9 @@ void TPassive_mask::salva_for() const { q_update = ""; TToken_string key(row->get(sf.cid2index(S_PROKEY)), ';'); - TString clifo_cofi = clifo.get(CLI_COFI); - TString clifo_paiv = clifo.get(CLI_PAIV); - if (clifo_cofi != "" && strcmp(row->get(sf.cid2index(S_CODFISC)), clifo_cofi) == 0 || clifo_paiv != "" && strcmp(row->get(sf.cid2index(S_PARIVA)), clifo_paiv) == 0) + const TString& clifo_cofi = clifo.get(CLI_COFI); + const TString& clifo_paiv = clifo.get(CLI_PAIV); + if (!clifo_cofi.empty() && strcmp(row->get(sf.cid2index(S_CODFISC)), clifo_cofi) == 0 || !clifo_paiv.empty() && strcmp(row->get(sf.cid2index(S_PARIVA)), clifo_paiv) == 0) { q_update << "UPDATE FPPRO00F SET PZ_TIPOCF = 'F', PZ_CLIFOR = '" << row->get(sf.cid2index(S_FORNITORE)) << "' WHERE PZ_KEYPRGINVIO = '" << key.get(0) << "' AND PZ_KEYHEADERFATT = '" << key.get(1) << "' AND PZ_KEYBODYFATT = '" << key.get(2) << "'"; fp_db().sq_set_exec(q_update, false); @@ -407,10 +484,14 @@ void TPassive_mask::salva_for() const } } -void TPassive_mask::clean_cg0(const TString& filename) const +void TPassive_mask::clean_ini(const TString& filename) const { static TString remove_string; +#ifdef DBG + remove_string.cut(0) << filename << "*.ini"; +#else remove_string.cut(0) << tmp_dir << "\\" << filename << "*.*"; +#endif remove_files(remove_string, false); } @@ -421,11 +502,110 @@ void TPassive_mask::run_cg0(const TString& filename) const TExternal_app(run_string).run(); } +int TPassive_mask::prepara_contab() +{ + int n_sel = 0; + TSheet_field& sf = sfield(F_DOCS); + sf.hide(); + + clean_ini(F1_INIREGCONT); + + FOR_EACH_SHEET_ROW(sf, n, row) { + if (row->starts_with("X")) + { + if(!TString(row->get(sf.cid2index(S_NUMREGCONT))).empty()) + return n+1000; + TString codcaus(get_codcaus(row->get(2), row->get(10))); + if (codcaus.empty()) + return no_codcaus; + + n_sel++; + TString num; num.format("%04d", n); + TFilename newf_ini; +#ifndef DBG + newf_ini.tempdir() << "\\" << regcont << num << ".ini"; +#else + newf_ini << F1_INIREGCONT << num << ".ini"; +#endif + TConfig contab_ini(newf_ini, "Transaction"); + + contab_ini.set("Action", "INSERT"); + + contab_ini.set_paragraph(LF_MOV); // [23] + contab_ini.set("CODCAUS", codcaus); + contab_ini.set("CODCF", row->get(sf.cid2index(S_FORNITORE))); + contab_ini.set("DATACOMP", TDate(TODAY)); + contab_ini.set("DATADOC", row->get(sf.cid2index(S_DATADOC))); + contab_ini.set("NUMDOCEXT", row->get(sf.cid2index(S_NDOC))); + contab_ini.set("NUMDOC", TString(row->get(sf.cid2index(S_NDOC))).right(7)); + contab_ini.set("TOTDOC", row->get(sf.cid2index(S_TOTDOC))); + contab_ini.set("PROGFPPRO", row->get(sf.cid2index(S_NPROT))); + contab_ini.set("KEYFPPRO", row->get(sf.cid2index(S_PROKEY))); + + row->add("", 0); + } + } + + sf.force_update(); + sf.show(); + + if (n_sel == 0) + return no_selected; + + return is_ready; +} + +void TPassive_mask::contabilizza() +{ + const int stato = prepara_contab(); + + switch(stato) + { + case is_ready: + run_cont_ini(); // Eseguo gli ini + fill(); // Ricarico sheet per togliere quelli contabilizzati + break; + case no_codcaus: + message_box("Attenzione, il fornitore non ha associato nessun codice causale predefinito.\nPrego selezionare un codice causale per la contabilizzazione."); + next_page(1000); + break; + case no_selected: + message_box("Selezionare almeno un documento."); + break; + default: break; + } + if(stato >= 1000) + { + TSheet_field& sf = sfield(F_DOCS); + TToken_string& row = sf.row(stato - 1000); + + const TString ndoc = row.get_int(sf.cid2index(S_NDOC)); + const TDate datadoc = row.get(sf.cid2index(S_DATADOC)); + const int nreg = row.get_int(sf.cid2index(S_NUMREGCONT)); + + TString msg; + msg << "Attenzione il doc " << ndoc << " del " << datadoc << " e' gia' stato registrato con numero reg. " << nreg; + warning_box(msg); + fill(); + } +} + +TDate TPassive_mask::load_data() const +{ + TString date; date << ini_get_string(CONFIG_DITTA, "fp", "dataini_fp04"); + TDate start_date(TODAY); + if(!date.empty()) + start_date = date; + else + start_date.set_day(1); + return start_date; +} + void TPassive_mask::new_forn() { TSheet_field& sf = sfield(F_ERR); static const TString newf = "fpnewf"; - clean_cg0(newf); + clean_ini(newf); FOR_EACH_SHEET_ROW(sf, nr, row) { const TString denom = row->get(sf.cid2index(S_RAGSERR)); @@ -478,7 +658,7 @@ void TPassive_mask::aggiorna_forn() { TSheet_field& sf = sfield(F_ERR); static const TString newf = "fpaggf"; - clean_cg0(newf); + clean_ini(newf); FOR_EACH_SHEET_ROW(sf, nr, row) { const TString denom = row->get(sf.cid2index(S_RAGSERR)); @@ -570,15 +750,23 @@ bool TPassive_mask::on_field_event(TOperable_field& o, TField_event e, long joll if (curr_page() == elenco_err) aggiorna_forn(); break; + case DLG_EXPORT: + if (e == fe_button && curr_page() == elenco_fe) + { + contabilizza(); + } + break; case F_DATAINI: if (e == fe_init) { - TDate inizio_mese = TDate(TODAY); inizio_mese.set_day(1); - o.set(inizio_mese); - //o.set(ini_get_string(CONFIG_DITTA, "fp", "LastXML", "01-01-2019")); + o.set(load_data()); + } + case F_ENDATAREG: + if (e == fe_modify) + { + field(F_DATAINIREG).enable(get_bool(F_ENDATAREG)); + field(F_DATAENDREG).enable(get_bool(F_ENDATAREG)); } - //else if (e == fe_close) - // ini_set_string(CONFIG_DITTA, "fp", "LastXML", o.get()); break; case F_DATAEND: if (e == fe_init) @@ -593,6 +781,14 @@ bool TPassive_mask::on_field_event(TOperable_field& o, TField_event e, long joll return true; } +TPassive_mask::TPassive_mask(bool f1) : TAutomask("fp0400a"), _f1(f1), _filter_changed(true) +{ + tmp_dir = tmp_dir.tempdir(); + load_all_fields(); + TMask::set_handler(F_CAUSFA, causfa_handler); + TMask::set_handler(F_CAUSNC, causnc_handler); +} + ///////////////////////////////////////////////////////////////////////////////////// // TPassive_app @@ -600,18 +796,55 @@ bool TPassive_mask::on_field_event(TOperable_field& o, TField_event e, long joll class TPassive_app : public TSkeleton_application { + void load_mask(const TPassive_mask& mask) const; + bool check_f1() const; + void save_field(const TPassive_mask& mask); + public: void main_loop() override; TPassive_app() = default; }; +void TPassive_app::load_mask(const TPassive_mask& mask) const +{ + if (check_f1()) + { + mask.field(F_CAUSFA).set(get_ini_codcaus()); + mask.field(F_CAUSNC).set(get_ini_codcaus(true)); + mask.field(F_ENDATAREG).set(get_endatareg()); + mask.field(F_DATAINIREG).enable(mask.get_bool(F_ENDATAREG)); + mask.field(F_DATAINIREG).set(get_datainireg()); + mask.field(F_DATAENDREG).enable(mask.get_bool(F_ENDATAREG)); + mask.field(F_DATAENDREG).set(get_dataendreg()); + } +} + +bool TPassive_app::check_f1() const +{ + return has_module(F1AUT); +} + +void TPassive_app::save_field(const TPassive_mask& mask) +{ + if (check_f1()) + { + set_ini_codcaus(mask.get(F_CAUSFA)); + set_endatareg(mask.get_bool(F_ENDATAREG)); + set_datainireg(mask.get(F_DATAINIREG)); + set_dataendreg(mask.get(F_DATAENDREG)); + } + ini_set_string(CONFIG_DITTA, "fp", "dataini_fp04", mask.get(F_DATAINI)); +} + void TPassive_app::main_loop() { - TPassive_mask mask; + TPassive_mask mask(check_f1()); + load_mask(mask); while(mask.run() == K_ENTER) { } + save_field(mask); } int fp0400(int argc, char * argv[]) diff --git a/src/fp/fp0400a.h b/src/fp/fp0400a.h index b6033d319..d7ba22f58 100644 --- a/src/fp/fp0400a.h +++ b/src/fp/fp0400a.h @@ -5,11 +5,20 @@ #define F_FATTSEL 504 #define F_FATTORD 505 #define F_VERSOORD 506 +#define F_CAUSFA 507 +#define F_DESCAUSFA 508 +#define F_CAUSNC 509 +#define F_DESCAUSNC 510 +#define F_F1CAUSALE 511 +#define F_ENDATAREG 512 +#define F_DATAINIREG 513 +#define F_DATAENDREG 514 #define END_MASK 599 #define F_PROT 401 + #define S_SELCODPROT 101 #define S_CODPROT 102 diff --git a/src/fp/fp0400a.uml b/src/fp/fp0400a.uml index b5bfc0412..7d8bd58ad 100644 --- a/src/fp/fp0400a.uml +++ b/src/fp/fp0400a.uml @@ -28,6 +28,12 @@ BEGIN PICTURE BMP_RECALC END +BUTTON DLG_EXPORT 10 2 +BEGIN + PROMPT 4 1 "Contabilizzaz." + PICTURE TOOL_EXPORT +END + #include ENDPAGE @@ -73,13 +79,131 @@ BEGIN FLAGS "" END -SPREADSHEET F_PROT 25 10 +SPREADSHEET F_PROT 25 6 BEGIN PROMPT 1 10 "Selezionare o aggiungere un filtro sul Tipo Progressivo" ITEM "@1" ITEM "Codice\nProtocol.@12" END +GROUPBOX DLG_NULL 32 5 +BEGIN + PROMPT 47 5 "" + MODULE F1 +END + +BOOLEAN F_ENDATAREG +BEGIN + PROMPT 48 6 "Abilita filtro per data registrazione contabile" + MODULE F1 +END + +DATE F_DATAINIREG +BEGIN + PROMPT 48 7 "Data iniziale" + CHECKTYPE REQUIRED + MODULE F1 +END + +DATE F_DATAENDREG +BEGIN + PROMPT 48 8 "Data finale " + VALIDATE DATE_CMP_FUNC >= F_DATAINIREG + WARNING "La data finale non può essere minore della data iniziale" + CHECKTYPE REQUIRED + MODULE F1 +END + +GROUPBOX F_F1CAUSALE 58 7 +BEGIN + PROMPT 31 10 "@BSelezionare Causale per Registrazione Contabile:" + MODULE F1 +END + +STRING F_CAUSFA 3 +BEGIN + PROMPT 32 11 "Causale per Fattura Acquisti (FA)" + FLAGS "UZ" + FIELD CODCAUS + USE LF_CAUSALI + INPUT CODCAUS F_CAUSFA + DISPLAY "Codice" CODCAUS + DISPLAY "Descrizione@50" DESCR + DISPLAY "Tipo" TIPODOC + DISPLAY "Registro" REG + DISPLAY "SC" TIPOMOV + DISPLAY "CA" MOVIND + DISPLAY "CE" COLLCESP + DISPLAY "770" M770 + OUTPUT F_CAUSFA CODCAUS + OUTPUT F_DESCAUSFA DESCR + ADD RUN cg0 -4 + CHECKTYPE NORMAL + WARNING "Causale assente" + MODULE F1 +END + +STRING F_DESCAUSFA 50 +BEGIN + PROMPT 32 12 "" + USE LF_CAUSALI KEY 2 + CHECKTYPE NORMAL + INPUT DESCR F_DESCAUSFA + DISPLAY "Descrizione@50" DESCR + DISPLAY "Codice" CODCAUS + DISPLAY "Tipo" TIPODOC + DISPLAY "Registro" REG + DISPLAY "SC" TIPOMOV + DISPLAY "CA" MOVIND + DISPLAY "CE" COLLCESP + DISPLAY "770" M770 + COPY OUTPUT F_CAUSFA + ADD RUN cg0 -4 + MODULE F1 +END + +STRING F_CAUSNC 3 +BEGIN + PROMPT 32 13 "Causale per Nota Credito Acquisti (NC)" + FLAGS "UZ" + FIELD CODCAUS + USE LF_CAUSALI + INPUT CODCAUS F_CAUSNC + DISPLAY "Codice" CODCAUS + DISPLAY "Descrizione@50" DESCR + DISPLAY "Tipo" TIPODOC + DISPLAY "Registro" REG + DISPLAY "SC" TIPOMOV + DISPLAY "CA" MOVIND + DISPLAY "CE" COLLCESP + DISPLAY "770" M770 + OUTPUT F_CAUSNC CODCAUS + OUTPUT F_DESCAUSNC DESCR + ADD RUN cg0 -4 + CHECKTYPE NORMAL + WARNING "Causale assente" + MODULE F1 +END + +STRING F_DESCAUSNC 50 +BEGIN + PROMPT 32 14 "" + USE LF_CAUSALI KEY 2 + CHECKTYPE NORMAL + INPUT DESCR F_DESCAUSNC + DISPLAY "Descrizione@50" DESCR + DISPLAY "Codice" CODCAUS + DISPLAY "Tipo" TIPODOC + DISPLAY "Registro" REG + DISPLAY "SC" TIPOMOV + DISPLAY "CA" MOVIND + DISPLAY "CE" COLLCESP + DISPLAY "770" M770 + COPY OUTPUT F_CAUSNC + ADD RUN cg0 -4 + MODULE F1 +END + ENDPAGE PAGE "Elenco Fatture" 0 2 0 0