From 7b182c1236ac736f9413bde1d148b5c9c4d8d659 Mon Sep 17 00:00:00 2001 From: Simone Palacino Date: Wed, 5 Jun 2019 17:17:43 +0200 Subject: [PATCH] Patch level : 12.0 812 Files correlati : cg2.exe Commento : - Riepilogo registrazioni con liquidazione periodo precedente [Fix #43] --- src/cg/cg2.cpp | 7 +- src/cg/cg2.h | 1 + src/cg/cg2300.cpp | 302 +++++++++++++++++++++++++++++++++++++++++++++ src/cg/cg2300a.h | 26 ++++ src/cg/cg2300a.uml | 200 ++++++++++++++++++++++++++++++ 5 files changed, 532 insertions(+), 4 deletions(-) create mode 100644 src/cg/cg2300.cpp create mode 100644 src/cg/cg2300a.h create mode 100644 src/cg/cg2300a.uml diff --git a/src/cg/cg2.cpp b/src/cg/cg2.cpp index f3ce34ace..a52a85b73 100755 --- a/src/cg/cg2.cpp +++ b/src/cg/cg2.cpp @@ -9,10 +9,9 @@ int main(int argc,char** argv) switch(n) { - case 1: - cg2200(argc, argv); break; - default: - cg2100(argc, argv); break; + case 1: cg2200(argc, argv); break; + case 2: cg2300(argc, argv); break; + default: cg2100(argc, argv); break; } return 0; } diff --git a/src/cg/cg2.h b/src/cg/cg2.h index a6a8dd19e..baed3b11b 100755 --- a/src/cg/cg2.h +++ b/src/cg/cg2.h @@ -3,5 +3,6 @@ int cg2100(int argc, char** argv); int cg2200(int argc, char** argv); +int cg2300(int argc, char** argv); #endif // __CG2_H diff --git a/src/cg/cg2300.cpp b/src/cg/cg2300.cpp new file mode 100644 index 000000000..e12836aa1 --- /dev/null +++ b/src/cg/cg2300.cpp @@ -0,0 +1,302 @@ +#include "cg2.h" +#include "applicat.h" +#include "automask.h" +#include "cg2300a.h" +#include "cg2103.h" +#include "lffiles.h" +#include "isam.h" +#include "mov.h" +#include +#include "rmov.h" +#include +#include "pconti.h" + +#define INI_ANNO "riep_anno" +#define INI_MESE "riep_mese" + +class TCompetenze_mask : public TAutomask +{ + std::vector _regs; + std::map _conts; + + const char* get_ini(bool dataini) const; + + bool on_field_event(TOperable_field& o, TField_event e, long jolly) override; + static void clear_map(const map& is); + + // Funzione becera di ordinamento della mappa _conts + void sort_conts(bool sort_by_imp = true); + static void swap_items(map::iterator& it, map::iterator& jt); + static bool is_minor_of(TToken_string* jt, TToken_string* it); + + void fill_contc(); + void fill(); + +public: + TCompetenze_mask() : TAutomask("cg2300a.msk") { } +}; + +const char* TCompetenze_mask::get_ini(bool dataini) const +{ + if (dataini) + return ini_get_string(CONFIG_DITTA, "cg", INI_ANNO, ""); + return ini_get_string(CONFIG_DITTA, "cg", INI_MESE, ""); +} + +bool TCompetenze_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) +{ + switch(o.dlg()) + { + case DLG_LINK: + if (e == fe_button) + if (get(F_ANNO).full() && get(F_MESE).full()) + fill(); + else if (get(F_ANNO).blank()) + message_box("Inserire un anno"); + else if (get(F_MESE).blank()) + message_box("Inserire un mese"); + break; + case DLG_USER: + if (e == fe_button && jolly > 0) + { + TSheet_field& sf = sfield(F_MOVS); + TToken_string& row = sf.row(sf.selected()); + TRectype mov(LF_MOV); + mov.put(MOV_NUMREG, row.get(sf.cid2index(F_NUMREG))); + if (mov.edit()) + fill(); + } + case F_ANNO: + if(e == fe_init) set(F_ANNO, get_ini(true)); + break; + case F_MESE: + if (e == fe_init) + set(F_MESE, get_ini(false)); + break; + default: break; + } + return true; +} + +void TCompetenze_mask::clear_map(const map& is) +{ + for(auto it = is.begin(); it != is.end(); ++it) + delete it->first; +} + +bool TCompetenze_mask::is_minor_of(TToken_string* jt, TToken_string* it) +{ + return jt->get_int(0) < it->get_int(0) + || (jt->get_int(0) == it->get_int(0) && jt->get_int(1) < it->get_int(1)) + || (jt->get_int(0) == it->get_int(0) && jt->get_int(1) == it->get_int(1) + && jt->get_int(2) < it->get_int(2)); +} + +void TCompetenze_mask::swap_items(map::iterator& it, + map::iterator& jt) +{ + TToken_string* appo = new TToken_string(); + for (int i = 0; i < it->first->items(); i++) + appo->add(it->first->get(i), i); + + const real appo_importo = it->second; + + for (int i = 0; i < jt->first->items(); i++) + it->first->add(jt->first->get(i), i); + it->second = jt->second; + + for (int i = 0; i < appo->items(); i++) + jt->first->add(appo->get(i), i); + jt->second = appo_importo; + + delete appo; +} + +void TCompetenze_mask::sort_conts(bool sort_by_imp) +{ + // Sopra cento rischia di essere leggermente lento + if( 1 < _conts.size() && _conts.size() < 100) + for (auto it = _conts.begin(); it != _conts.end(); ++it) + for (auto jt = it; jt != _conts.end(); ++jt) + if(sort_by_imp && jt->second > it->second || !sort_by_imp && is_minor_of(jt->first, it->first)) + swap_items(it, jt); +} + +void TCompetenze_mask::fill_contc() +{ + TSheet_field& sf = sfield(F_CONTC); + TLocalisamfile rmovs(LF_RMOV); + + sf.hide(); + sf.reset(); + + clear_map(_conts); + _conts.clear(); + // Per ogni registrazione + for (int i=0; i < _regs.size(); ++i) + { + const int numreg = _regs[i]; + rmovs.zero(); + rmovs.put(RMV_NUMREG, numreg); + rmovs.put(RMV_NUMRIG, 0); + int riga = 0; + if (rmovs.read()) + { + // Per ogni riga della registrazione + for (; rmovs.get_int(RMV_NUMREG) == numreg; rmovs.next()) + { + const int gruppo = rmovs.get_int(RMV_GRUPPOC); + const int numcontc = rmovs.get_int(RMV_CONTOC); + const int sottoconto = rmovs.get_int(RMV_SOTTOCONTOC); + const TString& tipocc = rmovs.get(RMV_TIPOCC); + const real importo(rmovs.get(RMV_IMPORTO)); + + if (tipocc.blank()) // Solo se il tipo di conto di contr. e' un conto, cioe' vuoto + { + // Cerco se ho già la chiave + auto it = _conts.begin(); + for (; it != _conts.end(); ++it) + { + if (it->first->get_int(0) == gruppo + && it->first->get_int(1) == numcontc + && it->first->get_int(2) == sottoconto) + break; + } + + if (it != _conts.end()) + it->second += importo; + else + { + TToken_string* contr = new TToken_string(); + contr->add(gruppo); + contr->add(numcontc); + contr->add(sottoconto); + _conts.insert(_conts.end(), { contr, importo }); + } + } + } + } + } + + sort_conts(get(F_ORDIN) == "X"); + + real tot; tot = 0; + for (auto it = _conts.begin(); it != _conts.end(); ++it) + { + TLocalisamfile pcont(LF_PCON); + const char* gruppo = it->first->get(0); + const char* conto = it->first->get(1); + const char* sottoconto = it->first->get(2); + TString tipoc = it->first->get(3); + pcont.put(PCN_GRUPPO, gruppo); + pcont.put(PCN_CONTO, conto); + pcont.put(PCN_SOTTOCONTO, sottoconto); + pcont.read(); + TToken_string& row = sf.row(-1); + row.add(gruppo); + row.add(conto); + row.add(sottoconto); + row.add(pcont.get(PCN_DESCR)); + row.add(it->second); + tot += it->second; + } + + sf.force_update(); + sf.show(); + + set(F_TOT, tot); +} + +void TCompetenze_mask::fill() +{ + const int anno = get_int(F_ANNO); + const int mese = get_int(F_MESE); + TSheet_field& sf = sfield(F_MOVS); + TLocalisamfile movs(LF_MOV); + + sf.hide(); + sf.reset(); + _regs.clear(); + movs.setkey(2); + + const TDate dataini(1, mese, anno); + TDate dataend(dataini); dataend.set_end_month(); + movs.put(MOV_DATAREG, dataini); + if(movs.read() != NULL) + { + for (; movs.next() == NOERR && movs.get_date(MOV_DATAREG) <= dataend; ) + { + const int month_liq = movs.get_int(MOV_MESELIQ); + TDate datareg(movs.get(MOV_DATAREG)); + TDate datacomp(movs.get(MOV_DATACOMP)); + if(month_liq == 0 && datacomp < datareg || month_liq != 0 && month_liq < datareg.month()) + { + _regs.insert(_regs.end(),movs.get_int(MOV_NUMREG)); + + TToken_string& row = sf.row(-1); + row.add(movs.get(MOV_NUMREG)); + row.add(datareg); + row.add(movs.get(MOV_DATADOC)); + row.add(TCausale(movs.get(MOV_CODCAUS)).tipo_doc()); + row.add(month_liq); + row.add(movs.get(MOV_NUMDOC)); + row.add(movs.get(MOV_PROTIVA)); + row.add(movs.get(MOV_DESCR)); + } + + } + } + sf.force_update(); + sf.show(); + + fill_contc(); +} + +/////////////////////////////////////////////////////////////////////////////// +// TCompetenze_app +/////////////////////////////////////////////////////////////////////////////// + +class TCompetenze_app : public TSkeleton_application +{ + TCompetenze_mask* _msk; +protected: + void set_ini(bool dataini, const TString& set) const; + void save_fields() const; + +public: + void main_loop() override; + + TCompetenze_app() : _msk() {}; +}; + +void TCompetenze_app::set_ini(bool dataini, const TString& set) const +{ + if(!set.empty()) + { + if (dataini) + ini_set_string(CONFIG_DITTA, "cg", INI_ANNO, set); + else + ini_set_string(CONFIG_DITTA, "cg", INI_MESE, set); + } +} + +void TCompetenze_app::save_fields() const +{ + set_ini(true, _msk->get(F_ANNO)); + set_ini(false, _msk->get(F_MESE)); +} + +void TCompetenze_app::main_loop() +{ + _msk = new TCompetenze_mask; + while (_msk->run() == K_ENTER) { } + save_fields(); +} + +int cg2300(int argc, char** argv) +{ + TCompetenze_app* app = new TCompetenze_app; + app->run(argc, argv, TR("Registrazioni Competenza Precedente")); + delete app; + return 0; +} diff --git a/src/cg/cg2300a.h b/src/cg/cg2300a.h new file mode 100644 index 000000000..1c367d6ce --- /dev/null +++ b/src/cg/cg2300a.h @@ -0,0 +1,26 @@ +#define START_MASK 501 +#define F_ANNO 501 +#define F_MESE 502 +#define F_TOT 503 +#define F_ORDIN 504 +#define END_MASK 599 + + +#define F_MOVS 201 + +#define F_NUMREG 101 +#define F_DATAREG 102 +#define F_DATADOC 103 +#define F_CODCAUS 104 +#define F_MESELIQ 105 +#define F_NUMDOC 106 +#define F_PROTIVA 107 +#define F_DESCR 108 + +#define F_CONTC 202 + +#define F_GRPCONTC 101 +#define F_NUMCONTC 102 +#define F_SOTCONTC 103 +#define F_DESCRCON 104 +#define F_TOTCONTC 105 \ No newline at end of file diff --git a/src/cg/cg2300a.uml b/src/cg/cg2300a.uml new file mode 100644 index 000000000..a0ad8f501 --- /dev/null +++ b/src/cg/cg2300a.uml @@ -0,0 +1,200 @@ +#include "cg2300a.h" + +TOOLBAR "topbar" 0 0 0 2 + +BUTTON DLG_LINK 2 2 +BEGIN + PROMPT 3 1 "Calcola" + PICTURE TOOL_ELABORA +END + +BUTTON DLG_NULL +BEGIN + PROMPT 2 2 "" +END + +BUTTON DLG_QUIT 2 2 +BEGIN + PROMPT 1 1 "" +END + +ENDPAGE + +PAGE "Movimenti" 0 4 0 0 + +NUMBER F_ANNO 4 +BEGIN + PROMPT 0 0 "Anno " + WARNING "Inserire un anno" +END + +NUMBER F_MESE 2 +BEGIN + PROMPT 24 0 "Mese " + SHEET " |Mese@30" + ITEM "|" + ITEM "1|Gennaio" + ITEM "2|Febbraio" + ITEM "3|Marzo" + ITEM "4|Aprile" + ITEM "5|Maggio" + ITEM "6|Giugno" + ITEM "7|Luglio" + ITEM "8|Agosto" + ITEM "9|Settembre" + ITEM "10|Ottobre" + ITEM "11|Novembre" + ITEM "12|Dicembre" + HELP "Mese dichiarazione" + FLAGS "" + CHECKTYPE REQUIRED +END + +SPREADSHEET F_MOVS 0 10 +BEGIN + PROMPT 1 1 "" + ITEMS "Numero" + ITEMS "Data" + ITEMS "Data Doc" + ITEMS "Causale" + ITEMS "Mese Liq.@7" + ITEMS "Documento" + ITEMS "Protoc." + ITEMS "Descrizione" +END + +RADIOBUTTON F_ORDIN 1 40 +BEGIN + PROMPT 1 11 "Ordina per " + ITEM "|Numero conto" + ITEM "X|Importo" + FLAGS "Z" +END + +SPREADSHEET F_CONTC 0 -1 +BEGIN + PROMPT 1 14 "" + ITEMS "Gruppo\nControp.@5" + ITEMS "Conto\nControp.@5" + ITEMS "Sottoconto\nControp.@7" + ITEMS "Descr. Conto" + ITEMS "Totale" +END + +NUMBER F_TOT 10 2 +BEGIN + PROMPT 1 -1 "Totale " +END + +ENDPAGE +ENDMASK + + +PAGE "Elementi" -1 -1 50 5 + +NUMBER F_NUMREG 7 +BEGIN + PROMPT 1 1 "Numero " + FLAGS "D" +END + +DATE F_DATAREG +BEGIN + PROMPT 1 2 "Data reg." + FLAGS "D" +END + +DATE F_DATADOC +BEGIN + PROMPT 1 3 "Data doc." + FLAGS "D" +END + +STRING F_CODCAUS 3 +BEGIN + PROMPT 1 4 "Causale " + FLAGS "D" +END + +NUMBER F_MESELIQ 2 +BEGIN + PROMPT 1 5 "Causale " + FLAGS "D" +END + +NUMBER F_NUMDOC 7 +BEGIN + PROMPT 1 6 "Documento" + FLAGS "D" +END + +NUMBER F_PROTIVA 6 +BEGIN + PROMPT 1 7 "Protoc." + FLAGS "D" +END + +STRING F_DESCR 50 +BEGIN + PROMPT 1 8 "Descrizione" + FLAGS "D" +END + +ENDPAGE + +TOOLBAR "Movimento" 0 0 0 2 + +BUTTON DLG_OK 2 2 +BEGIN + PROMPT 1 1 "" +END + +BUTTON DLG_USER 2 2 +BEGIN + PROMPT 1 1 "Collega" + PICTURE TOOL_LINK +END + +BUTTON DLG_CANCEL 2 2 +BEGIN + PROMPT 1 1 "" +END + +ENDPAGE +ENDMASK + + +PAGE "Elem CONTROP" -1 -1 50 5 + +NUMBER F_GRPCONTC 3 +BEGIN + PROMPT 1 1 "Gruppo di contropartita" + FLAGS "D" +END + +NUMBER F_NUMCONTC 3 +BEGIN + PROMPT 1 2 "Numero conto di contropartita" + FLAGS "D" +END + +NUMBER F_SOTCONTC 7 +BEGIN + PROMPT 1 2 "Numero sottoconto " + FLAGS "D" +END + +STRING F_DESCRCON 50 +BEGIN + PROMPT 1 3 "Descrizione conto contropartita" + FLAGS "D" +END + +NUMBER F_TOTCONTC 10 2 +BEGIN + PROMPT 1 4 "Totale conto contropartita" + FLAGS "D" +END + +ENDPAGE +ENDMASK \ No newline at end of file