From 158582aa867f1b376c9a43015da073f327e126bc Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 15 Apr 2016 08:20:08 +0000 Subject: [PATCH] git-svn-id: svn://10.65.10.50/branches/R_10_00@23198 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- bs/bs0200.cpp | 238 +++++++++++++++++++++++++++++++++++++++++++++---- bs/bs0200a.uml | 50 +++++++++-- db/db0500a.uml | 4 +- db/dblib.cpp | 1 + 4 files changed, 270 insertions(+), 23 deletions(-) diff --git a/bs/bs0200.cpp b/bs/bs0200.cpp index cb466c936..2ccfb8ce0 100644 --- a/bs/bs0200.cpp +++ b/bs/bs0200.cpp @@ -1,14 +1,15 @@ #include -#include #include #include #include #include #include +#include #include #include "../mg/mglib.h" #include "../cg/cglib01.h" +#include "../cg/cg2101.h" #include "bs0.h" @@ -19,6 +20,7 @@ #include #include #include +#include #define BS_DTULTAGG "DtUltAgg" @@ -80,7 +82,38 @@ public: }; bool TBeeStore_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) -{ return true; } +{ + if (e == fe_modify && !o.empty()) + { + const TFieldref* fr = o.field(); + if (fr && fr->name() == "CODCAUSC") + { + // Configura righe aggiuntive causale corrispettivi + TRecord_array rcaus(o.get(), LF_RCAUSALI); + if (!rcaus.exist(15) && yesno_box(TR("Si desidera configurare la causale per il collegamento a BeeStore?"))) + { + const char* codice[] = { "BEECN", "BEEBM", "BEECC", "BEEAS", "BEEAL", NULL }; + const char* descr[] = { "Contanti", "Bancomat", "Carta di credito", "Assegni", "Altro", NULL }; + + TTable dpn("%DPN"); + for (int i = 0; codice[i]; i++) + { + dpn.put("CODTAB", codice[i]); + dpn.put("S0", descr[i]); + dpn.write(); + TRectype& row = rcaus.row(15+i, true); + row.put(RCA_CODDESC, codice[i]); + row.put(RCA_DESC, descr[i]); + } + rcaus.rewrite(); + TRectype caus(LF_CAUSALI); + caus.put(RCA_CODCAUS, o.get()); + caus.edit(); + } + } + } + return true; +} void TBeeStore_mask::autoload() { @@ -120,8 +153,9 @@ private: const TString& comune(const TRecordset& recset, const char* fld_cap, const char* fld_den) const; bool split_phone(const TRecordset& odbc, const char* number, TIsamfile& clifo, const char* pre, const char* num) const; void load_clifo(char tipocf); - void save_clifo(const TDate& dal, const TDate& al); - + void save_clifo(int cfmask, const TDate& dal, const TDate& al); + void add_rmov(TMovimentoPN& mov, const real& importo, const TCausale& caus, const char* cod) const; + protected: bool save_and_delete_doc(TMov_mag*& doc) const; @@ -143,7 +177,8 @@ protected: void sync_anamag (const TDate& dal, const TDate& al); void sync_barcode (const TDate& dal, const TDate& al); void sync_scontrini(const TDate& dal, const TDate& al); - void sync_clifo (const TDate& dal, const TDate& al); + void sync_corrisp (const TDate& dal, const TDate& al); + void sync_clifo (int cfmask, const TDate& dal, const TDate& al); void sync_listino (const TString& listino); public: @@ -665,8 +700,8 @@ void TBeeStore_sync::sync_barcode(const TDate& dal, const TDate& al) TString80 codprcf = cfv.get(CFV_CODPRCF); if (codprcf.blank() || codprcf[0] == 'C') // Anagrafica gestita da Campo { - const char t = cfv.get_char(CLI_TIPOCF); - const long c = cfv.get_long(CLI_CODCF); + const char t = rec.get(CLI_TIPOCF).as_string()[0]; + const long c = rec.get(CLI_CODCF).as_int(); TString8 cod_pk; cod_pk.format("C%06ld%c", c, t); if (cod_pk != codprcf) { @@ -692,7 +727,12 @@ void TBeeStore_sync::sync_barcode(const TDate& dal, const TDate& al) if (xvt_str_same(fldname, "Indirizzo")) { TString ind; - ind << a.via_residenza() << ',' << a.civico_residenza(); + ind = a.via_residenza(); + if (ind.full()) + { + const TString& civ = a.civico_residenza(); + if (civ.full()) ind << ',' << civ; + } const TString& loc = a.localita_residenza(); if (loc.full()) ind << ',' << loc; ind.strip_double_spaces(); @@ -915,7 +955,7 @@ void TBeeStore_sync::load_clifo(char tipocf) } } -void TBeeStore_sync::save_clifo(const TDate& dal, const TDate& al) +void TBeeStore_sync::save_clifo(int cfmask, const TDate& dal, const TDate& al) { TString_array fields; fields.add("Cod_PK|"CLI_CODCF); @@ -949,15 +989,19 @@ void TBeeStore_sync::save_clifo(const TDate& dal, const TDate& al) TString query = build_query(LF_CLIFO, dal, al); query << "\nJOIN " << LF_CFVEN << " INTO TIPOCF==TIPOCF CODCF==CODCF"; + if (cfmask == 1) + query << "\nFROM TIPOCF=C\nTO TIPOCF=C"; else + if (cfmask == 2) + query << "\nFROM TIPOCF=F\nTO TIPOCF=F"; TISAM_recordset clifo(query); save_origine_2(clifo, "tieAnagCFP", fields, ClifoEvaluator); } -void TBeeStore_sync::sync_clifo(const TDate& dal, const TDate& al) +void TBeeStore_sync::sync_clifo(int cfmask, const TDate& dal, const TDate& al) { - load_clifo('C'); - load_clifo('F'); + if (cfmask & 1) load_clifo('C'); + if (cfmask & 2) load_clifo('F'); TString str(255); str << "ODBC(" << _dsn << ")\n"; @@ -965,7 +1009,7 @@ void TBeeStore_sync::sync_clifo(const TDate& dal, const TDate& al) str << "DELETE FROM tieAnagCFP WHERE Origine=1;"; clifo.exec(str); // Elimina tutte le anagrafiche importate da BeeStore - save_clifo(dal, al); + save_clifo(cfmask, dal, al); } bool TBeeStore_sync::save_and_delete_doc(TMov_mag*& doc) const @@ -1108,6 +1152,163 @@ void TBeeStore_sync::sync_scontrini(const TDate& dal, const TDate& al) save_and_delete_doc(doc); // Salva ultimo documento in sospeso } +void TBeeStore_sync::add_rmov(TMovimentoPN& mov, const real& importo, const TCausale& caus, const char* cod_da) const +{ + if (!importo.is_zero()) + { + TRectype& rmov = mov.cg(-1); + rmov.put(RMV_SEZIONE, caus.sezione_clifo()); + rmov.put(RMV_IMPORTO, importo); + int i = caus.last(); + for (; i > 15; i--) + { + const char* cod = caus.cod_desc_agg(i); + if (xvt_str_same(cod, cod_da)) + break; + } + TBill zio1; caus.bill(1, zio1); + TBill zio2; caus.bill(i, zio2); + zio2.put(rmov); + zio1.put(rmov, true); + } +} + +void TBeeStore_sync::sync_corrisp(const TDate&, const TDate&) +{ + const TString8 codcaus = ini_get_string(CONFIG_DITTA, "bs", "CODCAUSC"); + if (codcaus.blank()) + { + _log->log(2, "Configurare la causale corrispettivi Bee Store"); + return; + } + + TString str(255); + str << "ODBC(" << _dsn << ")\n"; + str << "SELECT * FROM tieCorrispettivi WHERE Origine=1"; + str << "\nORDER BY DataCorr,CodCorrispettivo"; + + TODBC_recordset corr(str); + TProgress_monitor pi(corr.items(), str); + + TString num_mov, nm; + TMov_mag* doc = NULL; + + TMovimentoPN mov; + mov.read(_islast); + long numreg = mov.curr().get_long(MOV_NUMREG)+1; + + for (bool ok = corr.move_first(); ok; ok = corr.move_next()) + { + TRectype& mrec = mov.curr(); + mov.destroy_rows(numreg); + + const TDate datareg = corr.get("DataCorr").as_date(); + mrec.put(MOV_NUMREG, numreg); + mrec.put(MOV_DATAREG, datareg); + mrec.put(MOV_ANNOIVA, datareg.year()); + + mrec.put(MOV_DATADOC, datareg); + TString80 desc; desc.format(FR("Corrispettivi %s"), datareg.stringa()); + mrec.put(MOV_DESCR, desc); + + TEsercizi_contabili esc; + mrec.put(MOV_DATACOMP, datareg); + mrec.put(MOV_ANNOES, esc.date2esc(datareg)); + + const TCausale caus(codcaus, datareg.year()); + mrec.put(MOV_CODCAUS, codcaus); + mrec.put(MOV_REG, caus.reg().name()); + + const real totdoc = corr.get("Valore").as_real(); + mrec.put(MOV_TOTDOC, totdoc); + + str.cut(0) << "ODBC(" << _dsn << ")\n"; + str << "SELECT * FROM tieDCorrispettivi WHERE (Origine=1)"; + str << "AND(CodCorrispettivo='" << corr.get("CodCorrispettivo") << "')"; + TODBC_recordset dett(str); + + TBill zio1; caus.bill(1, zio1); + TBill zio2; caus.bill(2, zio2); + TBill zio3; caus.bill(3, zio3); + + int nriga = 0; + real imponibile, imposta; + for (bool dok = dett.move_first(); dok; dok = dett.move_next()) + { + const real imp = dett.get("ImportoReparto").as_real(); + const real iva = dett.get("ImportoIva").as_real(); + TRectype& irec = mov.iva(nriga++); + irec.put(RMI_IMPONIBILE, imp); + irec.put(RMI_CODIVA, dett.get("CodIva").as_string()); + irec.put(RMI_IMPOSTA, iva); + zio2.put(irec); + imponibile += imp; + imposta += iva; + } + + const char sez1 = caus.sezione_clifo(); + TRectype& r1 = mov.cg(0); + r1.put(RMV_SEZIONE, sez1); + r1.put(RMV_IMPORTO, totdoc); + zio1.put(r1); + zio2.put(r1, true); + r1.put(RMV_ROWTYPE, 'T'); + + const char sez2 = sez1=='D'?'A':'D'; + TRectype& r2 = mov.cg(1); + r2.put(RMV_SEZIONE, sez2); + r2.put(RMV_IMPORTO, imponibile); + zio2.put(r2); + zio1.put(r2, true); + r2.put(RMV_ROWTYPE, 'I'); + + TRectype& r3 = mov.cg(2); + r3.put(RMV_SEZIONE, sez2); + r3.put(RMV_IMPORTO, imposta); + zio3.put(r3); + zio1.put(r3, true); + r3.put(RMV_ROWTYPE, 'D'); + + TRectype& r4 = mov.cg(3); + r4.put(RMV_SEZIONE, sez2); + r4.put(RMV_IMPORTO, totdoc); + zio1.put(r4); + zio1.put(r4, true); + + const real contanti = corr.get("IncContanti").as_real(); + const real bancomat = corr.get("IncBancomat").as_real(); + const real credcard = corr.get("IncCarteCredito").as_real(); + const real assegni = corr.get("IncAssegni").as_real(); + real altro = corr.get("IncFinanziato").as_real(); + altro += corr.get("IncCrediti").as_real(); + altro += corr.get("IncBonifici").as_real(); + altro += corr.get("IncAltro").as_real(); + + add_rmov(mov, contanti, caus, "BEECN"); + add_rmov(mov, bancomat, caus, "BEEBM"); + add_rmov(mov, credcard, caus, "BEECC"); + add_rmov(mov, assegni, caus, "BEEAS"); + add_rmov(mov, altro, caus, "BEEAL"); + + while (mov.write() == _isreinsert) + mrec.put(MOV_NUMREG, numreg++); + + if (!pi.add_status()) + break; + } + + if (!pi.is_cancelled()) + { + TString str(255); + str << "ODBC(" << _dsn << ")\n"; + TODBC_recordset sco(str); + str = "DELETE FROM tieCorrispettivi WHERE Origine=1"; + sco.exec(str); + + str = "DELETE FROM tieDCorrispettivi WHERE Origine=1"; + sco.exec(str); + } +} bool TBeeStore_sync::create() { @@ -1159,12 +1360,19 @@ void TBeeStore_sync::main_loop() sync_barcode(dal, al); if (mask.get_bool("SyncVAL")) sync_val(dal, al); - if (mask.get_bool("SyncClifo")) - sync_clifo(dal, al); + + int cfmask = 0; + if (mask.get_bool("SyncClienti")) cfmask |= 1; + if (mask.get_bool("SyncFornitori")) cfmask |= 2; + if (cfmask) + sync_clifo(cfmask, dal, al); + if (mask.get("SyncListino").full()) sync_listino(mask.get("SyncListino")); if (mask.get_bool("SyncSontr")) sync_scontrini(dal, al); + if (mask.get_bool("SyncCorr")) + sync_corrisp(dal, al); _log->preview(); delete _log; diff --git a/bs/bs0200a.uml b/bs/bs0200a.uml index 2ccbdacfc..9d05ed81c 100644 --- a/bs/bs0200a.uml +++ b/bs/bs0200a.uml @@ -4,7 +4,7 @@ ENDPAGE PAGE "Sincronizzazione Bee Store" 0 2 0 0 -GROUPBOX DLG_NULL 78 8 +GROUPBOX DLG_NULL 78 9 BEGIN PROMPT 1 1 "@bArchivi" END @@ -63,6 +63,12 @@ BEGIN FIELD SyncScontr END +BOOLEAN 150 +BEGIN + PROMPT 2 8 "Corrispettivi " + FIELD SyncCorr +END + BOOLEAN 151 BEGIN PROMPT 40 2 "Valute" @@ -71,13 +77,19 @@ END BOOLEAN 152 BEGIN - PROMPT 40 3 "Clienti/Fornitori" - FIELD SyncClifo + PROMPT 40 3 "Clienti" + FIELD SyncClienti END BOOLEAN 153 BEGIN - PROMPT 40 4 "Codici a barre" + PROMPT 40 4 "Fornitori " + FIELD SyncFornitori +END + +BOOLEAN 154 +BEGIN + PROMPT 40 5 "Codici a barre" FIELD SyncBarCode END @@ -103,7 +115,7 @@ ENDPAGE PAGE "Parametri" 0 2 0 0 -GROUPBOX DLG_NULL 78 6 +GROUPBOX DLG_NULL 78 4 BEGIN PROMPT 1 1 "@bScontrini" END @@ -117,8 +129,9 @@ BEGIN DISPLAY "Descrizione@50" S0 OUTPUT 201 CODTAB OUTPUT 202 S0 - CHECKTYPE REQUIRED + CHECKTYPE NORMAL FIELD CODCAUS + ADD RUN mg0 -0 %CAU END STRING 202 50 46 @@ -127,6 +140,31 @@ BEGIN FLAGS "D" END +GROUPBOX DLG_NULL 78 4 +BEGIN + PROMPT 1 5 "@bCorrispettivi" +END + +STRING 301 4 +BEGIN + PROMPT 2 6 "Causale contabile " + USE LF_CAUSALI SELECT TIPODOC="CR" + INPUT CODCAUS 301 + DISPLAY "Codice" CODCAUS + DISPLAY "Descrizione@50" DESCR + OUTPUT 301 CODCAUS + OUTPUT 302 DESCR + CHECKTYPE NORMAL + FIELD CODCAUSC + ADD RUN cg0 -4 +END + +STRING 302 50 46 +BEGIN + PROMPT 30 6 "" + FLAGS "D" +END + ENDPAGE ENDMASK \ No newline at end of file diff --git a/db/db0500a.uml b/db/db0500a.uml index 5fff41cec..246f00513 100755 --- a/db/db0500a.uml +++ b/db/db0500a.uml @@ -80,7 +80,7 @@ BEGIN PROMPT 2 2 "Articolo " FIELD CODDIST KEY 1 - USE LF_ANAMAG SELECT SOSPESO!=#F_NOSOSP + USE LF_ANAMAG SELECT !((SOSPESO="X")&&(#F_NOSOSP="X")) JOIN LF_UMART INTO CODART=CODART NRIGA=1 INPUT CODART F_CODICEQ DISPLAY "Codice@20" CODART @@ -98,7 +98,7 @@ STRING F_DESCR 50 40 BEGIN KEY 2 PROMPT 34 2 "" - USE LF_ANAMAG KEY 2 SELECT SOSPESO!=#F_NOSOSP + USE LF_ANAMAG KEY 2 SELECT !((SOSPESO="X")&&(#F_NOSOSP="X")) JOIN LF_UMART INTO CODART=CODART NRIGA=1 INPUT DESCR F_DESCR DISPLAY "Descrizione@50" DESCR diff --git a/db/dblib.cpp b/db/dblib.cpp index b4c341314..08530f194 100755 --- a/db/dblib.cpp +++ b/db/dblib.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include "tabutil.h"