diff --git a/ha/ha0100.cpp b/ha/ha0100.cpp index 4e6dc5877..4e5819775 100755 --- a/ha/ha0100.cpp +++ b/ha/ha0100.cpp @@ -36,6 +36,9 @@ bool THA_table_mask::on_field_event(TOperable_field &o, TField_event e, long jol // applicazione per la gestione delle tabelle di lavanderia class THA_table_app : public TTable_module_application { +private: + int update_gcg(const TRectype& att); + protected: // TRelation_application virtual bool protected_record(TRectype& record); virtual void init_query_mode(TMask& m); @@ -43,6 +46,9 @@ protected: // TRelation_application virtual void init_insert_mode(TMask& m); virtual void init_modify_mode(TMask& m); + virtual int write(const TMask& m); + virtual int rewrite(const TMask& m); + virtual bool get_next_key(TToken_string& key); }; @@ -50,7 +56,7 @@ protected: // TRelation_application bool THA_table_app::get_next_key(TToken_string& key) { //casino per la tabella attrezzature "&ATT" - const TString4 name = get_relation()->file(0).name(); + const TFixed_string name = get_relation()->file(0).name(); if (name == "ATT") { const TString& codart = curr_mask().get(F_CODART); @@ -63,8 +69,8 @@ bool THA_table_app::get_next_key(TToken_string& key) key.add(codart); key.add(F_PROGRESSIVO); key.add(codtab.mid(5)); + return true; } - return true; } return TTable_module_application::get_next_key(key); @@ -72,7 +78,7 @@ bool THA_table_app::get_next_key(TToken_string& key) bool THA_table_app::protected_record(TRectype& record) { - const TString4 name = get_relation()->file(0).name(); + const TFixed_string name = get_relation()->file(0).name(); //tabella delle attrezzature //non si può eliminare una attrezzatura se la medesima ha una storia! rispettiamo gli anziani! @@ -97,7 +103,7 @@ bool THA_table_app::protected_record(TRectype& record) void THA_table_app::init_insert_mode(TMask& m) { - const TString4 name = get_relation()->file(0).name(); + const TFixed_string name = get_relation()->file(0).name(); if (name == "ATT") { m.hide(-2); @@ -107,7 +113,7 @@ void THA_table_app::init_insert_mode(TMask& m) void THA_table_app::init_modify_mode(TMask& m) { - const TString4 name = get_relation()->file(0).name(); + const TFixed_string name = get_relation()->file(0).name(); if (name == "ATT") { m.hide(-2); @@ -117,7 +123,7 @@ void THA_table_app::init_modify_mode(TMask& m) void THA_table_app::init_query_mode(TMask& m) { - const TString4 name = get_relation()->file(0).name(); + const TFixed_string name = get_relation()->file(0).name(); if (name == "CEL") { m.hide(F_CODCLI1); @@ -132,7 +138,7 @@ void THA_table_app::init_query_mode(TMask& m) void THA_table_app::init_query_insert_mode(TMask& m) { - const TString4 name = get_relation()->file(0).name(); + const TFixed_string name = get_relation()->file(0).name(); if (name == "CEL") { m.hide(F_CODCLI); @@ -145,6 +151,50 @@ void THA_table_app::init_query_insert_mode(TMask& m) } } +int THA_table_app::update_gcg(const TRectype& att) +{ + TTable gcg("GCG"); + TString str; + str << '1' << att.get("CODTAB"); + gcg.put("CODTAB", str); + + str = TR("Matricola "); + str << att.get("S0").mid(20,15); + gcg.put("S0", str); + + const int err = gcg.rewrite_write(); + return err; +} + +int THA_table_app::write(const TMask& m) +{ + const int err = TTable_module_application::write(m); + + if (err == NOERR) + { + const TFixed_string name = get_relation()->file(0).name(); + if (name == "ATT") + update_gcg(get_relation()->curr()); + } + + return err; +} + +int THA_table_app::rewrite(const TMask& m) +{ + const int err = TTable_module_application::rewrite(m); + + if (err == NOERR) + { + const TFixed_string name = get_relation()->file(0).name(); + if (name == "ATT") + update_gcg(get_relation()->curr()); + } + + return err; +} + + int ha0100(int argc, char* argv[]) { THA_table_app a; diff --git a/ha/ha3800.cpp b/ha/ha3800.cpp index 8af1a0d6b..1fa6220b5 100755 --- a/ha/ha3800.cpp +++ b/ha/ha3800.cpp @@ -7,6 +7,7 @@ #include #include +#include <../mg/rmovmag.h> #include <../ve/velib.h> #include "halib.h" @@ -68,20 +69,23 @@ TInserimento_storico_mask::TInserimento_storico_mask() : TAutomask("ha3800a") class TInserimento_storico : public TSkeleton_application { protected: + void elabora_aperture(const TMask& mask, TLog_report& log); + void elabora_chiusure(const TMask& mask, TLog_report& log); void elabora(const TMask& mask); + public: void main_loop(); }; - -void TInserimento_storico::elabora(const TMask& mask) +void TInserimento_storico::elabora_aperture(const TMask& mask, TLog_report& log) { //1) legge la configurazione per avere i parametri di query TConfig config(CONFIG_DITTA, "ha"); const TString4 tipo2elab = config.get("Doc2ElabTip"); const TString4 stato2elab = config.get("Doc2ElabSta"); const TString8 caus_open = config.get("CausOpen"); - const TString8 caus_close = config.get("CausClose"); + // const TString8 caus_close = config.get("CausClose"); Ignorata dal 19-06-2012 + //..e anche la maschera const long anno = mask.get_long(F_ANNO); const TDate da_data = mask.get_date(F_DADATA); @@ -95,12 +99,6 @@ void TInserimento_storico::elabora(const TMask& mask) ofstream numerazioni("c:/temp/numerazioni.txt", ios::app); #endif - //vogliono pure il log! che rompicazzo - TLog_report log("Righe storico aggiunte"); - log.kill_duplicates(); - log.log(0, ""); - log.log(0, "Anno-Num.-Ndoc--Art. Progres.--Matricola --Cliente"); - log.log(0, ""); //3) giro su ogni numerazione per trovare le righe che servono for (int n = 0; n < num_del_tipo; n++) @@ -135,10 +133,10 @@ void TInserimento_storico::elabora(const TMask& mask) TString8 caus = rdoc_recset.get(RDOC_CAUSMAG).as_string(); //se la causale non è sulla riga controlla quella di testata if (caus.empty()) - caus = rdoc_recset.get(DOC_CAUSMAG).as_string(); + caus = rdoc_recset.get("33."DOC_CAUSMAG).as_string(); //solo le righdoc con causale sensata proseguono - if (caus == caus_open || caus == caus_close) + if (caus == caus_open /*|| caus == caus_close*/) { //bool di scrimage const bool bopen = caus == caus_open; @@ -220,7 +218,7 @@ void TInserimento_storico::elabora(const TMask& mask) curr_ndoc = recset_his.get("S5[9,15]").as_int(); if (curr_ndoc == doc_ndoc) { - n_line_to_update = recset_his.get("CODTAB[13,17]").as_int(); + n_line_to_update = recset_his.get("CODTAB[9,13]").as_int(); break; } } @@ -267,10 +265,8 @@ void TInserimento_storico::elabora(const TMask& mask) tab_his.put("R0", qta); const real prezzo = rdoc_recset.get(RDOC_PREZZO).as_real(); const real importo = qta * prezzo; - tab_his.put("R1", importo); - //se è il documento di chiusura fa segnalato - if (!bopen) - tab_his.put("B0", true); + tab_his.put("R1", importo); + tab_his.put("B0", !bopen); //se è il documento di chiusura va segnalato const int written = tab_his.write_rewrite(); //segna sul log la riga aggiunta alla tabella storico &HIS @@ -279,7 +275,7 @@ void TInserimento_storico::elabora(const TMask& mask) TString msg; msg.format("%4d-%4s/%7d--%s--%s--%6d", doc_anno, (const char*)doc_codnum, doc_ndoc, - (const char*)new_codtab, (const char*)matricola, doc_clifo); + (const char*)codart, (const char*)matricola, doc_clifo); log.log(0, msg); } } //if (caus==caus_open || .. @@ -287,16 +283,168 @@ void TInserimento_storico::elabora(const TMask& mask) } //for (bool ok = rdoc_recset.move_first()... } //for (int n = 0; n < num_del_tipo... +} + +void TInserimento_storico::elabora_chiusure(const TMask& mask, TLog_report& log) +{ + TConfig config(CONFIG_DITTA, "ha"); + const TString8 caus_close = config.get("CausClose"); + + //..e anche la maschera + const long anno = mask.get_long(F_ANNO); + const TDate da_data = mask.get_date(F_DADATA); + const TDate a_data = mask.get_date(F_ADATA); + TString query; + query << "USE MOVMAG KEY 3 SELECT CODCAUS=#CODCAUS"; + query << "\nFROM DATAREG=#DADATA"; + query << "\nTO DATAREG=#ADATA"; + + TISAM_recordset mov_recset(query); + mov_recset.set_var("#CODCAUS", caus_close); + mov_recset.set_var("#DADATA", da_data); + mov_recset.set_var("#ADATA", a_data); + + for (bool ok = mov_recset.move_first(); ok; ok = mov_recset.move_next()) + { + const TDate mov_datareg = mov_recset.get(MOVMAG_DATAREG).as_date(); + const long mov_nreg = mov_recset.get(MOVMAG_NUMREG).as_int(); + + TToken_string key; key << mov_recset.get(MOVMAG_NUMREG); + TRecord_array rmovmag(key, LF_RMOVMAG); + for (int r = 1; r > 0 && r <= rmovmag.last_row(); r++) + { + const TRectype& row = rmovmag.row(r); + //controllo della causale + const TString& caus = row.get(RMOVMAG_CODCAUS); + if (caus.full() && caus != caus_close) + continue; + + const TString80 codart = row.get(RMOVMAG_CODART); + const TString16 matricola = row.get(RMOVMAG_LIVGIAC); + + TModule_table tab_att("&ATT"); + tab_att.put("CODTAB", matricola); + const int err = tab_att.read(); + if (err != NOERR) + { + TString msg; + msg << "Articolo " << codart << " senza matricola sul movimento " << mov_recset.get(MOVMAG_NUMREG) << " del " << mov_recset.get(MOVMAG_DATAREG); + log.log(1, msg); + continue; + } + + const long clifo = tab_att.get_long("I0"); + const int indsped = tab_att.get_int("I1"); + if (clifo <= 0) + { + TString msg; + msg << "Matricola " << matricola << " senza cliente: probabilmente l'articolo " << codart << " è già rientrato"; + log.log(1, msg); + continue; + } + + tab_att.put("I0", ""); // Azzera cliente + tab_att.put("I1", ""); // Azzera indsped + tab_att.put("D0", mov_datareg); + tab_att.write_rewrite(); + + TString query_his; + query_his << "USE &HIS"; + query_his << "\nFROM CODTAB=#CODTAB"; + query_his << "\nTO CODTAB=#CODTAB"; + TISAM_recordset recset_his(query_his); + recset_his.set_var("#CODTAB", matricola); + + const long recset_his_items = recset_his.items(); + + TModule_table tab_his("&HIS"); + int n_line_to_update = 0; + + //cerca se la riga esiste già nello storico e va solo aggiornata + for (bool ok = recset_his.move_last(); ok; ok = recset_his.move_prev()) + { + const long curr_anno = recset_his.get("S5[1,4]").as_int(); + const long curr_nreg = recset_his.get("S5[9,15]").as_int(); + if (curr_anno == anno && curr_nreg == mov_nreg) + { + n_line_to_update = recset_his.get("CODTAB[9,13]").as_int(); + break; + } + } //for (bool ok = recset_his.move... + + TString80 new_codtab; + //se la riga non c'era -> va aggiunta + if (n_line_to_update == 0) + { + n_line_to_update = recset_his_items + 1; + + //adesso ha il numero di riga da aggiornare e crea il nuovo record + new_codtab.format("%08s%05d", (const char*)matricola, n_line_to_update); + tab_his.put("CODTAB", new_codtab); + tab_his.write(); + } + + //rimette il codtab per riposizionarsi sul record corretto + new_codtab.format("%08s%05d", (const char*)matricola, n_line_to_update); + tab_his.put("CODTAB", new_codtab); + + //ed aggiunge tutti i campi + const TString& descr = mov_recset.get(MOVMAG_DESCR).as_string(); + tab_his.put("S0", descr); + + TString16 str_key_doc; + str_key_doc.format("%4d%4s%7d", anno, "", mov_nreg); + tab_his.put("S5", str_key_doc); + tab_his.put("S6", row.get(RMOVMAG_UM)); + const TString& codmag = row.get(RMOVMAG_CODMAG); + TString4 s7; //s7[1,1]=tipo s7[2,4]=codmag + s7 << "C" << codmag; + tab_his.put("S7", s7); + tab_his.put("I0", clifo); + tab_his.put("I1", indsped); + tab_his.put("D0", mov_datareg); + const real qta = row.get(RMOVMAG_QUANT); + tab_his.put("R0", qta); + const real prezzo = row.get(RMOVMAG_PREZZO); + const real importo = qta * prezzo; + tab_his.put("R1", importo); + tab_his.put("B0", true); // Chiusura + + const int written = tab_his.write_rewrite(); + //segna sul log la riga aggiunta alla tabella storico &HIS + if (written == NOERR) + { + TString msg; + msg.format("%4d-%4s/%7d--%s--%s--%6d", + anno, (const char*)caus_close, mov_nreg, + (const char*)codart, (const char*)matricola, clifo); + log.log(0, msg); + } + } + } +} + +void TInserimento_storico::elabora(const TMask& mask) +{ + //vogliono pure il log! che rompicazzo + TLog_report log(TR("Righe storico aggiunte")); + log.kill_duplicates(); + log.log(0, ""); + log.log(0, HR("Anno-Num.-Ndoc--Articolo --Matricola --Cliente")); + log.log(0, ""); + + elabora_aperture(mask, log); + elabora_chiusure(mask, log); + log.preview(); } + void TInserimento_storico::main_loop() { TInserimento_storico_mask mask; while (mask.run() == K_ENTER) - { elabora(mask); - } } int ha3800(int argc, char* argv[]) diff --git a/ha/ha3900a.uml b/ha/ha3900a.uml index 50e6697fe..bf6ce858c 100755 --- a/ha/ha3900a.uml +++ b/ha/ha3900a.uml @@ -325,7 +325,7 @@ BEGIN FIELD S4[5,8] END -NUMBER S_BOL_OPEN_NDOC 4 +NUMBER S_BOL_OPEN_NDOC 7 BEGIN PROMPT 35 5 "N.Doc. " USE DOC SELECT TIPOCF="C" @@ -367,7 +367,7 @@ BEGIN FIELD S5[5,8] END -NUMBER S_BOL_CLOSE_NDOC 4 +NUMBER S_BOL_CLOSE_NDOC 7 BEGIN PROMPT 35 8 "N.Doc. " USE DOC SELECT TIPOCF="C" diff --git a/ha/hatbatt.h b/ha/hatbatt.h index ef568f758..2eae75744 100755 --- a/ha/hatbatt.h +++ b/ha/hatbatt.h @@ -16,4 +16,7 @@ #define F_DATA_CONSEGNA 217 #define F_CODINDSP 218 #define F_INDSP 219 -#define F_RAGSOCINDSP 220 \ No newline at end of file +#define F_RAGSOCINDSP 220 + +#define F_LEASING 250 +#define F_REVISIONE 251 diff --git a/ha/hatbatt.uml b/ha/hatbatt.uml index 3af7d1bce..fa0d7c7c1 100755 --- a/ha/hatbatt.uml +++ b/ha/hatbatt.uml @@ -6,7 +6,7 @@ ENDPAGE PAGE "Attrezzature" 0 2 0 0 -GROUPBOX DLG_NULL 76 7 +GROUPBOX DLG_NULL 76 8 BEGIN PROMPT 1 0 "@bAttrezzatura" END @@ -17,7 +17,7 @@ BEGIN FLAGS "UZ" USE &ATT JOIN LF_ANAMAG INTO CODART=S0[1,20] - JOIN LF_CESPI INTO IDCESPITE=S1 + JOIN LF_CESPI INTO IDCESPITE==S1 INPUT CODTAB F_PROGRESSIVO DISPLAY "Matr.Hardy" CODTAB DISPLAY "Articolo@20" S0[1,20] @@ -64,7 +64,7 @@ BEGIN FLAGS "U" USE &ATT KEY 2 JOIN LF_ANAMAG INTO CODART=S0[1,20] - JOIN LF_CESPI INTO IDCESPITE=S1 + JOIN LF_CESPI INTO IDCESPITE==S1 INPUT S0[1,20] F_CODART INPUT S0[21,35] F_MATRICOLA DISPLAY "Articolo@20" S0[1,20] @@ -115,7 +115,7 @@ BEGIN PROMPT 2 4 "Cespite " FLAGS "UZ" USE &ATT - JOIN LF_CESPI INTO IDCESPITE=S1 + JOIN LF_CESPI INTO IDCESPITE==S1 JOIN LF_ANAMAG INTO CODART=S0[1,20] INPUT S1[1,10] F_CESPITE_SEARCH DISPLAY "Cespite@10" S1 @@ -138,7 +138,7 @@ BEGIN PROMPT 26 4 "" FLAGS "DU" /*USE &ATT - JOIN LF_CESPI INTO IDCESPITE=S1 + JOIN LF_CESPI INTO IDCESPITE==S1 INPUT S1 F_CESPITE_SEARCH DISPLAY "Descrizione cespite@50" LF_CESPI->DESC DISPLAY "Cespite@10" S1 @@ -162,14 +162,27 @@ BEGIN FIELD S3 END +BOOLEAN F_LEASING +BEGIN + PROMPT 12 6 "Leasing" + FIELD B0 +END + +BOOLEAN F_REVISIONE +BEGIN + PROMPT 26 6 "Revisione" + FIELD B1 +END + + GROUPBOX DLG_NULL 76 8 BEGIN - PROMPT 1 7 "@bCliente" + PROMPT 1 10 "@bCliente" END NUMBER F_CODCF 6 BEGIN - PROMPT 2 8 "Codice " + PROMPT 2 11 "Codice " FLAGS "U" USE LF_CLIFO INPUT TIPOCF "C" @@ -186,7 +199,7 @@ END STRING F_DESCF 50 BEGIN - PROMPT 2 9 "Rag. soc. " + PROMPT 2 12 "Ragione sociale " USE LF_CLIFO KEY 2 INPUT TIPOCF "C" INPUT RAGSOC F_DESCF @@ -200,19 +213,19 @@ END DATE F_DATA_CONSEGNA BEGIN - PROMPT 2 10 "Data presa in consegna " + PROMPT 2 13 "Data presa in consegna " CHECKTYPE REQUIRED FIELD D0 END TEXT DLG_NULL BEGIN - PROMPT 2 11 "@bIndirizzo di spedizione" + PROMPT 2 14 "@bIndirizzo di spedizione" END NUMBER F_CODINDSP 3 BEGIN - PROMPT 2 12 "Codice " + PROMPT 2 15 "Codice " USE LF_INDSP INPUT TIPOCF "C" INPUT CODCF F_CODCF SELECT @@ -227,16 +240,16 @@ BEGIN FIELD I1 END -STRING F_INDSP 35 +STRING F_INDSP 40 BEGIN - PROMPT 17 12 "Indirizzo " + PROMPT 18 15 "Indirizzo " FLAGS "D" CHECKTYPE SEARCH END STRING F_RAGSOCINDSP 50 BEGIN - PROMPT 2 13 "Ragsoc. " + PROMPT 2 16 "Ragione sociale " FLAGS "D" CHECKTYPE SEARCH END