diff --git a/build/AgaLib.vcxproj b/build/AgaLib.vcxproj index 95c71f700..30a458a36 100644 --- a/build/AgaLib.vcxproj +++ b/build/AgaLib.vcxproj @@ -233,6 +233,7 @@ + @@ -648,6 +649,7 @@ + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) diff --git a/cd/test/ba1086.txt b/cd/test/ba1086.txt new file mode 100644 index 000000000..36f230cfc --- /dev/null +++ b/cd/test/ba1086.txt @@ -0,0 +1,3 @@ +ba3.exe + +Importazione Bee Store \ No newline at end of file diff --git a/cd/test/ba1086a.ini b/cd/test/ba1086a.ini new file mode 100644 index 000000000..c4cc4280b --- /dev/null +++ b/cd/test/ba1086a.ini @@ -0,0 +1,33 @@ +[Main] +Demo=0 + +[ba3] +Edit_4 = ba3 -0 +Edit_5 = ba3 -0 +File(475) = ba3.exe|X +Patch = 1086 +Versione = 21511200 + +[ba99] +Kill(0) = wxmsw240.dll|x +Kill(1) = batbsce.txt|x +Kill(2) = bastfsc.rep|x +Kill(3) = bastfsc.msk|x +Kill(4) = bastcms.msk|x +Kill(5) = bastcms.rep|x +Kill(6) = bastuue.rep|x +Kill(7) = bastuue.msk|x + +[ba] +Data = 04-10-2021 +Descrizione = Base +Dischi = 1 +Moduli = sy +OEM = +Patch = 1086 +PostProcess = bainst -0 BA +PreProcess = +Prezzo(1) = +Prezzo(2) = +Versione = 21511200 + diff --git a/cd/test/ba1086a1.zip b/cd/test/ba1086a1.zip new file mode 100644 index 000000000..24315c96c Binary files /dev/null and b/cd/test/ba1086a1.zip differ diff --git a/cd/test/bs1086.txt b/cd/test/bs1086.txt new file mode 100644 index 000000000..825fded4c --- /dev/null +++ b/cd/test/bs1086.txt @@ -0,0 +1,4 @@ +bs0.exe +bs0500a.msk + +Importazione Bee Store \ No newline at end of file diff --git a/cd/test/bs1086a.ini b/cd/test/bs1086a.ini new file mode 100644 index 000000000..2e6c59066 --- /dev/null +++ b/cd/test/bs1086a.ini @@ -0,0 +1,26 @@ +[Main] +Demo=0 + +[bs0] +File(0) = bs0.exe|X +Patch = 1086 +Versione = 21511200 + +[bs1] +File(6) = bs0500a.msk|X +Patch = 1086 +Versione = 21511200 + +[bs] +Data = 04-10-2021 +Descrizione = Bee Store +Dischi = 1 +Moduli = ve +OEM = +Patch = 1086 +PostProcess = +PreProcess = +Prezzo(1) = +Prezzo(2) = +Versione = 21511200 + diff --git a/cd/test/bs1086a1.zip b/cd/test/bs1086a1.zip new file mode 100644 index 000000000..96fd50bf8 Binary files /dev/null and b/cd/test/bs1086a1.zip differ diff --git a/cd/test/cg1086.txt b/cd/test/cg1086.txt new file mode 100644 index 000000000..837f49497 --- /dev/null +++ b/cd/test/cg1086.txt @@ -0,0 +1,3 @@ +cg0.exe + +Importazione Bee Store \ No newline at end of file diff --git a/cd/test/cg1086a.ini b/cd/test/cg1086a.ini new file mode 100644 index 000000000..16f474712 --- /dev/null +++ b/cd/test/cg1086a.ini @@ -0,0 +1,98 @@ +[Main] +Demo=0 + +[cg0] +File(0) = cg0.exe|X +Patch = 1086 +Versione = 21511200 + +[cg99] +Kill(0) = batbins.msk|x +Kill(1) = bastpor.rep|x +Kill(2) = batbcfi.msk|x +Kill(3) = batbntb.msk|x +Kill(4) = bastleg.msk|x +Kill(5) = batbdel.msk|x +Kill(6) = bastnot.msk|x +Kill(7) = bastvet.rep|x +Kill(8) = bastpor.msk|x +Kill(9) = bastcve.msk|x +Kill(10) = batbpdb.msk|x +Kill(11) = batbpor.msk|x +Kill(12) = bastivd.msk|x +Kill(13) = batbind.msk|x +Kill(14) = batblbu.msk|x +Kill(15) = bastdpn.msk|x +Kill(16) = batbleg.msk|x +Kill(17) = bastcfi.msk|x +Kill(18) = batbdpn.msk|x +Kill(19) = bastcam.msk|x +Kill(20) = bastcco.msk|x +Kill(21) = batbvet.msk|x +Kill(22) = bastarb.msk|x +Kill(23) = bastesc.rep|x +Kill(24) = cg2fppro.msk|x +Kill(25) = bastver.msk|x +Kill(26) = batbtit.msk|x +Kill(27) = batbcco.msk|x +Kill(28) = bastzon.rep|x +Kill(29) = bastndo.msk|x +Kill(30) = bastreg.rep|x +Kill(31) = batbndo.msk|x +Kill(32) = bastscc.rep|x +Kill(33) = batbnot.msk|x +Kill(34) = batbscc.msk|x +Kill(35) = bastntb.rep|x +Kill(36) = batbivd.msk|x +Kill(37) = bastnot.rep|x +Kill(38) = batbtra.msk|x +Kill(39) = bastver.rep|x +Kill(40) = bastcam.rep|x +Kill(41) = batbmsp.msk|x +Kill(42) = bastmsp.rep|x +Kill(43) = bastvet.msk|x +Kill(44) = batbesc.msk|x +Kill(45) = bastpdb.msk|x +Kill(46) = bastleg.rep|x +Kill(47) = batblia.msk|x +Kill(48) = bastpdb.rep|x +Kill(49) = bastarb.rep|x +Kill(50) = bastcfi.rep|x +Kill(51) = bastntb.msk|x +Kill(52) = cgtbcon.msk|x +Kill(53) = bastcve.rep|x +Kill(54) = batbver.msk|x +Kill(55) = batbzon.msk|x +Kill(56) = batbcve.msk|x +Kill(57) = batbcam.msk|x +Kill(58) = bastesc.msk|x +Kill(59) = batbinl.msk|x +Kill(60) = bastivd.rep|x +Kill(61) = batbarb.msk|x +Kill(62) = bastmsp.msk|x +Kill(63) = bastscc.msk|x +Kill(64) = bastndo.rep|x +Kill(65) = bastdpn.rep|x +Kill(66) = bastzon.msk|x +Kill(67) = batblia.msk|x +Kill(68) = batbreg.msk|x +Kill(69) = bastreg.msk|x +Kill(70) = bastcco.rep|x + +[cg] +Data = 04-10-2021 +Descrizione = Contabilita' Generale +Dischi = 1 +Edit_19 = cg0 -0 +Edit_20 = cg0 -1 +Edit_26 = cg0 -4 +Edit_5 = cg0 -5 +Moduli = ba +OEM = +Patch = 1086 +PostProcess = bainst -0 CG +PreProcess = +Prezzo(1) = +Prezzo(2) = +Versione = 21511200 + diff --git a/cd/test/cg1086a1.zip b/cd/test/cg1086a1.zip new file mode 100644 index 000000000..b37170b63 Binary files /dev/null and b/cd/test/cg1086a1.zip differ diff --git a/cd/test/sy1086.txt b/cd/test/sy1086.txt new file mode 100644 index 000000000..c4360f9be --- /dev/null +++ b/cd/test/sy1086.txt @@ -0,0 +1,3 @@ +xvaga.dll + +Importazione Bee Store \ No newline at end of file diff --git a/cd/test/sy1086a.ini b/cd/test/sy1086a.ini new file mode 100644 index 000000000..7d07bdb39 --- /dev/null +++ b/cd/test/sy1086a.ini @@ -0,0 +1,24 @@ +[Main] +Demo=0 + +[sy1] +File(55) = xvaga.dll|X +Patch = 1086 +Versione = 21511200 + +[sy99] +Kill(0) = setup\teamviewerqs_it.exe|x + +[sy] +Data = 04-10-2021 +Descrizione = Sistema +Dischi = 1 +Moduli = +OEM = +Patch = 1086 +PostProcess = +PreProcess = +Prezzo(1) = +Prezzo(2) = +Versione = 21511200 + diff --git a/cd/test/sy1086a1.zip b/cd/test/sy1086a1.zip new file mode 100644 index 000000000..698033439 Binary files /dev/null and b/cd/test/sy1086a1.zip differ diff --git a/cd/test/ve1086.txt b/cd/test/ve1086.txt new file mode 100644 index 000000000..8d79fb94a --- /dev/null +++ b/cd/test/ve1086.txt @@ -0,0 +1,4 @@ +ve0.exe +ve2.exe + +Importazione Bee Store \ No newline at end of file diff --git a/cd/test/ve1086a.ini b/cd/test/ve1086a.ini new file mode 100644 index 000000000..9ff03361b --- /dev/null +++ b/cd/test/ve1086a.ini @@ -0,0 +1,137 @@ +[Main] +Demo=0 + +[ve0] +Edit_163 = ve0 -6 +Edit_4 = ve0 -4 +Edit_5 = ve0 -4 +File(20) = ve0.exe|X +Patch = 1086 +Versione = 21511200 + +[ve2] +File(230) = ve2.exe|X +Patch = 1086 +Versione = 21511200 + +[ve99] +Kill(0) = batbimb.msk|x +Kill(1) = batbacr.msk|x +Kill(2) = batbprv.msk|x +Kill(3) = bastgmc.rep|x +Kill(4) = ve7.exe|x +Kill(5) = bastums.rep|x +Kill(6) = efstbnp.rep|x +Kill(7) = bastgcg.rep|x +Kill(8) = bastctr.rep|x +Kill(9) = basttip.msk|x +Kill(10) = bastimb.msk|x +Kill(11) = batbmre.msk|x +Kill(12) = bastfca.rep|x +Kill(13) = bastgca.rep|x +Kill(14) = basteld.msk|x +Kill(15) = bastimb.rep|x +Kill(16) = batbfrd.msk|x +Kill(17) = bastnum.msk|x +Kill(18) = batbstd.msk|x +Kill(19) = batbfrm.msk|x +Kill(20) = batbfca.msk|x +Kill(21) = bastubi.msk|x +Kill(22) = bastgmc.msk|x +Kill(23) = batbprs.msk|x +Kill(24) = basteld.rep|x +Kill(25) = bastcau.msk|x +Kill(26) = bastrfa.rep|x +Kill(27) = ve7300a.msk|x +Kill(28) = bastprs.msk|x +Kill(29) = batbubi.msk|x +Kill(30) = bastgcg.msk|x +Kill(31) = batbtip.msk|x +Kill(32) = bastnum.rep|x +Kill(33) = batbabe.msk|x +Kill(34) = batbgsa.msk|x +Kill(35) = ve7600a.msk|x +Kill(36) = bastabe.msk|x +Kill(37) = bastubi.rep|x +Kill(38) = batbfrr.msk|x +Kill(39) = ve7400conf.ini|x +Kill(40) = batbcau.msk|x +Kill(41) = ve7200a.frm|x +Kill(42) = batbgmc.msk|x +Kill(43) = bastcaa.rep|x +Kill(44) = batbfid.msk|x +Kill(45) = bastfrd.msk|x +Kill(46) = bastcaa.msk|x +Kill(47) = batbtag.msk|x +Kill(48) = bastums.msk|x +Kill(49) = ve7300a.frm|x +Kill(50) = ve7100a.msk|x +Kill(51) = bastcau.rep|x +Kill(52) = bastabe.rep|x +Kill(53) = bastrfc.msk|x +Kill(54) = bastfca.msk|x +Kill(55) = batbcaa.msk|x +Kill(56) = eftbbnp.msk|x +Kill(57) = batbums.msk|x +Kill(58) = bastbnp.msk|x +Kill(59) = bastfrm.msk|x +Kill(60) = baststd.rep|x +Kill(61) = baststd.msk|x +Kill(62) = basttag.rep|x +Kill(63) = basttri.msk|x +Kill(64) = basttip.rep|x +Kill(65) = ve7701a.ini|x +Kill(66) = batbctr.msk|x +Kill(67) = batbspp.msk|x +Kill(68) = basttri.rep|x +Kill(69) = bastfrm.rep|x +Kill(70) = bastrfc.rep|x +Kill(71) = bastasf.msk|x +Kill(72) = batbfsa.msk|x +Kill(73) = bastfrr.rep|x +Kill(74) = batbnum.msk|x +Kill(75) = batbpro.msk|x +Kill(76) = bastcra.msk|x +Kill(77) = bastfrr.msk|x +Kill(78) = bastrfa.msk|x +Kill(79) = bastfrd.rep|x +Kill(80) = ve7400a.msk|x +Kill(81) = batbspt.msk|x +Kill(82) = bastprs.rep|x +Kill(83) = basttag.msk|x +Kill(84) = bastspp.msk|x +Kill(85) = batbbnp.msk|x +Kill(86) = batbgcg.msk|x +Kill(87) = bastgca.msk|x +Kill(88) = batbasf.msk|x +Kill(89) = ve7700a.msk|x +Kill(90) = ve7200a.msk|x +Kill(91) = bastcra.rep|x +Kill(92) = ve7400a.ini|x +Kill(93) = bastctr.msk|x +Kill(94) = batbtri.msk|x +Kill(95) = batbeld.msk|x +Kill(96) = batbcra.msk|x +Kill(97) = ve7500a.msk|x +Kill(98) = bastspp.rep|x +Kill(99) = batbcld.msk|x +Kill(100) = batbrfa.msk|x +Kill(101) = batbrfc.msk|x +Kill(102) = bastbnp.rep|x +Kill(103) = bastasf.rep|x +Kill(104) = efstbnp.msk|x +Kill(105) = batbgca.msk|x + +[ve] +Data = 04-10-2021 +Descrizione = Vendite +Dischi = 1 +Moduli = ba,cg9,pr9,mg9,sv9,in9,ef9 +OEM = +Patch = 1086 +PostProcess = bainst -0 VE +PreProcess = +Prezzo(1) = +Prezzo(2) = +Versione = 21511200 + diff --git a/cd/test/ve1086a1.zip b/cd/test/ve1086a1.zip new file mode 100644 index 000000000..b6eb459e3 Binary files /dev/null and b/cd/test/ve1086a1.zip differ diff --git a/cd/test/ve1088.txt b/cd/test/ve1088.txt new file mode 100644 index 000000000..6f6a03d64 --- /dev/null +++ b/cd/test/ve1088.txt @@ -0,0 +1,4 @@ +Aggiunto report e maschera con "Stampa clienti dato un metodo di pagamento" + +ve19001.rep +ve1900a.msk diff --git a/cd/test/ve1088a.ini b/cd/test/ve1088a.ini new file mode 100644 index 000000000..5a1149399 --- /dev/null +++ b/cd/test/ve1088a.ini @@ -0,0 +1,130 @@ +[Main] +Demo=0 + +[ve1] +File(64) = ve19001.rep|X +File(65) = ve1900a.msk|X +Patch = 1088 +Versione = 21511200 + +[ve99] +Kill(0) = batbimb.msk|x +Kill(1) = batbacr.msk|x +Kill(2) = bastcra.msk|x +Kill(3) = bastbnp.rep|x +Kill(4) = bastfrr.msk|x +Kill(5) = bastasf.rep|x +Kill(6) = bastctr.rep|x +Kill(7) = basttip.msk|x +Kill(8) = batbpro.msk|x +Kill(9) = efstbnp.msk|x +Kill(10) = bastfrm.rep|x +Kill(11) = batbgca.msk|x +Kill(12) = batbnum.msk|x +Kill(13) = batbrfa.msk|x +Kill(14) = basttri.rep|x +Kill(15) = batbrfc.msk|x +Kill(16) = batbgmc.msk|x +Kill(17) = bastabe.msk|x +Kill(18) = bastrfa.msk|x +Kill(19) = bastfrd.rep|x +Kill(20) = bastprs.rep|x +Kill(21) = bastgcg.msk|x +Kill(22) = bastubi.msk|x +Kill(23) = basttag.msk|x +Kill(24) = basteld.rep|x +Kill(25) = bastimb.rep|x +Kill(26) = batbabe.msk|x +Kill(27) = batbfca.msk|x +Kill(28) = ve7300a.msk|x +Kill(29) = basteld.msk|x +Kill(30) = ve7400a.ini|x +Kill(31) = bastcau.msk|x +Kill(32) = batbgcg.msk|x +Kill(33) = batbfrm.msk|x +Kill(34) = ve7400a.msk|x +Kill(35) = batbstd.msk|x +Kill(36) = batbspt.msk|x +Kill(37) = batbtip.msk|x +Kill(38) = ve7200a.msk|x +Kill(39) = bastspp.msk|x +Kill(40) = bastctr.msk|x +Kill(41) = bastgca.msk|x +Kill(42) = basttri.msk|x +Kill(43) = batbfrr.msk|x +Kill(44) = bastabe.rep|x +Kill(45) = batbums.msk|x +Kill(46) = bastcau.rep|x +Kill(47) = bastcaa.msk|x +Kill(48) = ve7100a.msk|x +Kill(49) = ve7600a.msk|x +Kill(50) = batbfid.msk|x +Kill(51) = batbubi.msk|x +Kill(52) = bastfrr.rep|x +Kill(53) = bastums.msk|x +Kill(54) = basttag.rep|x +Kill(55) = batbspp.msk|x +Kill(56) = baststd.msk|x +Kill(57) = eftbbnp.msk|x +Kill(58) = baststd.rep|x +Kill(59) = bastfrd.msk|x +Kill(60) = bastfca.msk|x +Kill(61) = ve7400conf.ini|x +Kill(62) = bastimb.msk|x +Kill(63) = bastbnp.msk|x +Kill(64) = batbfsa.msk|x +Kill(65) = batbmre.msk|x +Kill(66) = bastasf.msk|x +Kill(67) = batbctr.msk|x +Kill(68) = bastrfc.rep|x +Kill(69) = batbcaa.msk|x +Kill(70) = basttip.rep|x +Kill(71) = ve7300a.frm|x +Kill(72) = bastnum.rep|x +Kill(73) = batbprs.msk|x +Kill(74) = bastfca.rep|x +Kill(75) = bastrfa.rep|x +Kill(76) = bastnum.msk|x +Kill(77) = bastgca.rep|x +Kill(78) = bastgmc.msk|x +Kill(79) = ve7701a.ini|x +Kill(80) = batbfrd.msk|x +Kill(81) = bastfrm.msk|x +Kill(82) = bastcaa.rep|x +Kill(83) = bastubi.rep|x +Kill(84) = bastrfc.msk|x +Kill(85) = bastprs.msk|x +Kill(86) = batbtag.msk|x +Kill(87) = ve7200a.frm|x +Kill(88) = batbcau.msk|x +Kill(89) = batbgsa.msk|x +Kill(90) = efstbnp.rep|x +Kill(91) = bastgcg.rep|x +Kill(92) = ve7.exe|x +Kill(93) = bastums.rep|x +Kill(94) = batbprv.msk|x +Kill(95) = bastgmc.rep|x +Kill(96) = bastcra.rep|x +Kill(97) = batbbnp.msk|x +Kill(98) = bastspp.rep|x +Kill(99) = batbcld.msk|x +Kill(100) = batbtri.msk|x +Kill(101) = batbasf.msk|x +Kill(102) = batbeld.msk|x +Kill(103) = ve7700a.msk|x +Kill(104) = batbcra.msk|x +Kill(105) = ve7500a.msk|x + +[ve] +Data = 05-10-2021 +Descrizione = Vendite +Dischi = 1 +Moduli = ba,cg9,pr9,mg9,sv9,in9,ef9 +OEM = +Patch = 1088 +PostProcess = bainst -0 VE +PreProcess = +Prezzo(1) = +Prezzo(2) = +Versione = 21511200 + diff --git a/cd/test/ve1088a1.zip b/cd/test/ve1088a1.zip new file mode 100644 index 000000000..9514ad5cd Binary files /dev/null and b/cd/test/ve1088a1.zip differ diff --git a/src/bs/bs0.cpp b/src/bs/bs0.cpp index fd86ae6e5..311d24f99 100644 --- a/src/bs/bs0.cpp +++ b/src/bs/bs0.cpp @@ -9,7 +9,7 @@ int main(int argc, char** argv) case 1: bs0200(argc, argv); break; // Importazioni Beestore case 2: bs0300(argc, argv); break; // Importazione da SKNET case 3: bs0400(argc, argv); break; // Tabelle di transazione - case 4: bs0500(argc, argv); break; // Importazioni BeeStore Inmaven + case 4: bs0500(argc, argv); break; // Importazioni BeeStore Inmaven default: bs0100(argc, argv); break; // Trasferimento Beestore Impostazione } return 0; diff --git a/src/bs/bs0200.cpp b/src/bs/bs0200.cpp index 029963756..9969b3c8d 100644 --- a/src/bs/bs0200.cpp +++ b/src/bs/bs0200.cpp @@ -1061,13 +1061,13 @@ void TBeeStore_sync::sync_mov(int tipotestata, const TDate& dal, const TDate& al { str << " AND DataMov"; if (dal.ok() && al.ok()) - str << " BETWEEN " << date2sql(dal) << " AND " << date2sql(al); + str << " BETWEEN " << date2sql(dal, 1) << " AND " << date2sql(al, 2); else { if (dal.ok()) - str << ">=" << date2sql(dal); + str << ">=" << date2sql(dal, 1); else - str << "<=" << date2sql(al); + str << "<=" << date2sql(al, 2); } } str << "\nORDER BY NumMov,NumRiga"; diff --git a/src/bs/bs0300.cpp b/src/bs/bs0300.cpp index d17e72033..f130b3f63 100644 --- a/src/bs/bs0300.cpp +++ b/src/bs/bs0300.cpp @@ -492,7 +492,6 @@ void TSknet_sync::sync_anamag() } } } - { // Controllo se esistono varianti e le aggiungo query.cut(0) << "SELECT * FROM tieArtVarianti where origine=" << their_origin() << " AND " << where_time_import() << ";"; @@ -637,57 +636,11 @@ void TSknet_sync::sync_anamag() if (!flag) flag = yesno_box("Attenzione trovato articolo con categoria CONAI vuota: %s\nSopprimere eventuali prossimi messaggi?", (const char*)codart); } - /* - - art.first(); // Useless?? - rart.zero(); - rart.put(ANAMAG_CODART, odbc.get("Cod_PK").as_string()); - if (odbc.get("Cod_PK").as_string().blank()) - continue; - if (rart.read(art, _isequal) == NOERR) - { - static TString catCON; - // Metodo del cazzo, format crasha e non ho tempo, magari in un futuro sistemarlo (se non ho visto male funziona solo su linux) - TString a = odbc.get("CatAC").as_string().left(4); a.lpad(4); - TString b = odbc.get("CatAL").as_string().left(4); b.lpad(4); - TString c = odbc.get("CatCA").as_string().left(4); c.lpad(4); - TString d = odbc.get("CatLE").as_string().left(4); d.lpad(4); - TString e = odbc.get("CatPL").as_string().left(4); e.lpad(4); - TString f = odbc.get("CatVE").as_string().left(4); f.lpad(4); - catCON.cut(0) << a << b << c << d << e << f; - - / * - catCON.format("%4 s%4 s%4 s%4 s%4 s%4 s", - odbc.get("CatAC").as_string().left(4), // Categoria Acciaio - odbc.get("CatAL").as_string().left(4), // Categoria Alluminio - odbc.get("CatCA").as_string().left(4), // Categoria Carta - odbc.get("CatLE").as_string().left(4), // Categoria Legno - odbc.get("CatPL").as_string().left(4), // Categoria Plastica - odbc.get("CatVE").as_string().left(4) // Categoria Vetro - ); - * / - - rart.put(ANAMAG_CONAISC, catCON); - rart.put(ANAMAG_CONACC, odbc.get("PesoAC").as_real()); // Peso Acciaio - rart.put(ANAMAG_CONALL, odbc.get("PesoAL").as_real()); // Peso Alluminio - rart.put(ANAMAG_CONCAR, odbc.get("PesoCA").as_real()); // Peso Carta - rart.put(ANAMAG_CONLEG, odbc.get("PesoLE").as_real()); // Peso Legno - rart.put(ANAMAG_CONPLA, odbc.get("PesoPL").as_real()); // Peso Plastica - rart.put(ANAMAG_CONVET, odbc.get("PesoVE").as_real()); // Peso Vetro - art.rewrite(rart); - } - else - // EROR! EROR! - { - bool tolla = true; - } - - */ } } } -static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, const char* expr, TVariant& var) +/*static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, const char* expr, TVariant& var) { const TAnagrafica& a = _anagr.anag(rec); @@ -804,7 +757,7 @@ static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, cons } return false; -} +} */ const TString& TSknet_sync::comune(const TRecordset& recset, const char* fld_cap, const char* fld_den) const { @@ -910,12 +863,12 @@ void TSknet_sync::load_clifo(const char tipocf) cfv.put(CFV_PADESTIN, odbc.get("CodDest").as_string()); const int tipo = odbc.get("Tipo").as_int(); // 1=Fisica; 2=Giuridica; 3=Altro + if (tipo == 1) { clifo.put(CLI_SESSO, odbc.get("Sesso").as_string()); clifo.put(CLI_DATANASC, odbc.get("DTNascita").as_date()); - clifo.put(CLI_COMNASC, comune(odbc, "", "ComuneNascita")); - clifo.put(CLI_TIPOPERS, 'F'); + clifo.put(CLI_COMNASC, comune(odbc, "", "ComuneNascita"));(CLI_TIPOPERS, 'F'); } else clifo.put(CLI_TIPOPERS, 'G'); @@ -1375,54 +1328,7 @@ void TSknet_sync::sync_val() sync_table("%VAL", "tieValute", fields); } -//auto find_codalt_sknet = [](TRectype& rcodcor, TLocalisamfile& codcor, const TString& tipocf, long codcf, const TString& codart, TString& codartmag, bool& checked) -//{ -// // Testo quanti sono. Non ho altro modo? -// const bool items = rcodcor.next(codcor) == NOERR && rcodcor.get(CODCORR_CODARTALT) == codart; -// if (items) -// { -// rcodcor.prev(codcor); -// // Prima cerco subito se ho un codice per questo cliente. -// // Altrimenti prendo quello che non e' un codice di pack, se c'e' altrimenti riprendo sempre il primo. -// TSQL_recordset codici(TString() << "SELECT * FROM CODCORR WHERE CODARTALT = '" << codart << "' AND TIPOCF = '" << tipocf << "' AND CODCF = '" << codcf << "'"); -// if (codici.items() == 1) -// { -// codartmag = codici.get(codici.find_column(CODCORR_CODART)).as_string(); -// checked = true; -// } -// else -// { -// TString last_cod = rcodcor.get(CODCORR_CODART); -// -// // Codice di PACK di cinque cifre. -// static auto is_pack_code = [&]() -// { -// bool flag = last_cod.len() == 5; -// for (int i = 0; i < 5 && flag; ++i) flag &= xvt_chr_is_digit(last_cod[i]); -// return flag; -// }; -// -// checked = true; // Se va tutto bene ho il nuovo codartmag. -// while (is_pack_code()) -// { -// if (rcodcor.next(codcor) == NOERR && rcodcor.get(CODCORR_CODARTALT) == codart) -// { -// last_cod = rcodcor.get(CODCORR_CODART); -// continue; -// } -// checked = false; -// break; -// } -// if (checked) -// { -// if (rcodcor.next(codcor) != NOERR || rcodcor.get(CODCORR_CODARTALT) != codart) // Controllo che sia effettivamente l'unico altrimenenti ciaone. -// codartmag = last_cod; -// else -// checked = false; -// } -// } -// } -//}; + void TSknet_sync::sync_doc() { diff --git a/src/bs/bs0500.cpp b/src/bs/bs0500.cpp index fb241939a..ae1b0bbf8 100644 --- a/src/bs/bs0500.cpp +++ b/src/bs/bs0500.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -20,9 +21,12 @@ #include #include #include +#include #include "bsutility.h" #define BS_DTULTAGG "DtUltAgg" +#define BS_POSNUMDOC 4 +#define BS_FREEROW "-1" /////////////////////////////////////////////////////////// // TImporta_cache @@ -61,10 +65,10 @@ public: static TImporta_cache _anagr; /////////////////////////////////////////////////////////// -// TImporta_mask +// TImporta_Beestore_mask /////////////////////////////////////////////////////////// -class TImporta_mask : public TAutomask +class TImporta_Beestore_mask : public TAutomask { protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); @@ -83,11 +87,11 @@ public: TMask_field* f = find_by_fieldname(fld); return TDate(f ? f->get() : EMPTY_STRING); } - TImporta_mask() : TAutomask("bs0500a") { autoload(); } - ~TImporta_mask() { autosave(); } + TImporta_Beestore_mask() : TAutomask("BS0500A") { autoload(); } + ~TImporta_Beestore_mask() { autosave(); } }; -bool TImporta_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) +bool TImporta_Beestore_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { if (e == fe_modify && !o.empty()) { @@ -121,7 +125,7 @@ bool TImporta_mask::on_field_event(TOperable_field& o, TField_event e, long joll return true; } -void TImporta_mask::autoload() +void TImporta_Beestore_mask::autoload() { // Carica i valori default dei parametri dal [bs] in ditta,ini FOR_EACH_MASK_FIELD(*this, i, f) @@ -131,32 +135,78 @@ void TImporta_mask::autoload() { const TString & name = fr->name(); - if ( (name == "SyncIMPPARTDOC") || (name == "SyncDoc") ) - f->set(ini_get_bool(CONFIG_DITTA, "bs", name,true) ? "X" : " "); + if ( (name == "ImpIMPPARTDOC") || (name == "ImpDoc") || (name == "ImpDirectWrite") ) + f->set(ini_get_bool(CONFIG_DITTA, "BS0500A", name, true) ? "X" : " "); else - f->set(ini_get_string(CONFIG_DITTA, "bs", name)); + f->set(ini_get_string(CONFIG_DITTA, "BS0500A", name)); } } + + TSheet_field & s = sfield(F_CODNUM); + int i = 0; + TString16 suffisso = ini_get_string(CONFIG_DITTA, "BS0500A", "Suffisso", "", i); + + while (i == 0 || suffisso.full()) + { + s.set_row_cell(F_SUFFISSO, suffisso, i); + s.set_row_cell(F_COD_FATTURE, ini_get_string(CONFIG_DITTA, "BS0500A", "NumFatt", "", i), i); + s.set_row_cell(F_COD_NOTE, ini_get_string(CONFIG_DITTA, "BS0500A", "NumNote", "", i), i); + s.set_row_cell(F_COD_BOLLE, ini_get_string(CONFIG_DITTA, "BS0500A", "NumBolle", "", i), i); + s.set_row_cell(F_COD_CARSCAR, ini_get_string(CONFIG_DITTA, "BS0500A", "NumCarScar", "", i), i); + s.set_row_cell(F_COD_SCONTRINI, ini_get_string(CONFIG_DITTA, "BS0500A", "NumScontr", "", i), i); + s.set_row_cell(F_COD_GENERICI, ini_get_string(CONFIG_DITTA, "BS0500A", "NumGenerici", "", i), i); + s.set_row_cell(F_COD_ORDCLI, ini_get_string(CONFIG_DITTA, "BS0500A", "NumOrdcli", "", i), i); + suffisso = ini_get_string(CONFIG_DITTA, "BS0500A", "Suffisso", "", ++i); + } } -void TImporta_mask::autosave() const +void TImporta_Beestore_mask::autosave() const { // Salva i valori dei parametri in [bs] in ditta,ini FOR_EACH_MASK_FIELD(*this, i, f) { const TFieldref* fr = f->field(); if (fr != NULL) - ini_set_string(CONFIG_DITTA, "bs", fr->name(), f->get()); + ini_set_string(CONFIG_DITTA, "BS0500A", fr->name(), f->get()); + } + + TSheet_field & s = sfield(F_CODNUM); + int rows = s.items(); + int i = 0; + + for (; i < rows; i++) + { + ini_set_string(CONFIG_DITTA, "BS0500A", "Suffisso", s.get_str_row_cell(i, F_SUFFISSO), i); + ini_set_string(CONFIG_DITTA, "BS0500A", "NumFatt", s.get_str_row_cell(i, F_COD_FATTURE), i); + ini_set_string(CONFIG_DITTA, "BS0500A", "NumNote", s.get_str_row_cell(i, F_COD_NOTE), i); + ini_set_string(CONFIG_DITTA, "BS0500A", "NumBolle", s.get_str_row_cell(i, F_COD_BOLLE), i); + ini_set_string(CONFIG_DITTA, "BS0500A", "NumCarScar", s.get_str_row_cell(i, F_COD_CARSCAR), i); + ini_set_string(CONFIG_DITTA, "BS0500A", "NumScontr", s.get_str_row_cell(i, F_COD_SCONTRINI), i); + ini_set_string(CONFIG_DITTA, "BS0500A", "NumGenerici",s.get_str_row_cell(i, F_COD_GENERICI), i); + ini_set_string(CONFIG_DITTA, "BS0500A", "NumOrdCli", s.get_str_row_cell(i, F_COD_ORDCLI), i); + } + while ((ini_get_string(CONFIG_DITTA, "BS0500A", "Suffisso", "", i)).full()) + { + ini_remove(CONFIG_DITTA, "BS0500A", "Suffisso", i); + ini_remove(CONFIG_DITTA, "BS0500A", "NumFatt", i); + ini_remove(CONFIG_DITTA, "BS0500A", "NumNote", i); + ini_remove(CONFIG_DITTA, "BS0500A", "NumBolle", i); + ini_remove(CONFIG_DITTA, "BS0500A", "NumCarScar", i); + ini_remove(CONFIG_DITTA, "BS0500A", "NumScontr", i); + ini_remove(CONFIG_DITTA, "BS0500A", "NumGenerici", i); + ini_remove(CONFIG_DITTA, "BS0500A", "NumOrdCli", i); + i++; } } /////////////////////////////////////////////////////////// -// TImporta_sync +// TImporta_Beestore /////////////////////////////////////////////////////////// typedef bool TFieldEvaluator(const TISAM_recordset& rec, const char* fldname, const char* expr, TVariant& var); +typedef enum { imp_aggiungi = 1, imp_aggiorna, imp_entrambi } tipo_importazione; -class TImporta_sync : public TSkeleton_application +class TImporta_Beestore : public TSkeleton_application { TString _dsn; TString _usr; @@ -165,43 +215,48 @@ class TImporta_sync : public TSkeleton_application TLog_report* _log; bool _banche_pres_loaded; TAssoc_array _banche_pres; + bool _direct_write; + bool _interactive; + tipo_importazione _tipo_imp; -private: + TAssoc_array _nums; + + bool fill_rec(TRectype & rec, TODBC_recordset& odbc, TAssoc_array& pairs, TString & log_str, const TDate dtultagg, bool fill_key = false); + bool fill_transaction(TTransaction & transaction, TRectype & rec, TODBC_recordset& odbc, TAssoc_array& pairs, TDate dtultagg); + bool fill_transaction(TTransaction & transaction, const char * table, TODBC_recordset& odbc, TAssoc_array& pairs, TDate dtultagg); + const char * build_query(const char* table, TAssoc_array& pairs); 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); + bool split_phone(const TRecordset& odbc, const char* number, TLocalisamfile& clifo, const char* pre, const char* num) const; + bool split_phone(const TRecordset& odbc, const char* number, TTransaction& transaction, const char* pre, const char* num) const; + void direct_clifo(char tipocf); + void transaction_clifo(char tipocf); 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; + const char * get_num(const TString & suffix, int tipotestata); + int tipotestata2idx(int tipotestata); + void add_nomenclatura(const char * nomenclatura); protected: - bool save_and_delete_movmag(TMov_mag*& doc) const; - bool save_and_delete_doc(TDocumento*& doc) const; + bool save_and_delete_doc(TDocumento * doc) const; - void load_origine_1(TISAM_recordset& out_set, const char* in_table, const TString_array& pairs); - void save_origine_2(TISAM_recordset& in_set, const char* out_table, const TString_array& pairs, TFieldEvaluator* feval = NULL); + void import_table(int logicnum, const char* table, TAssoc_array& pairs); + void import_table(const char * tab, const char* table, TAssoc_array& pairs); + void direct_table(int logicnum, TODBC_recordset & odbc, TAssoc_array& pairs); + void direct_table(const char * table, TODBC_recordset & odbc, TAssoc_array& pairs); + void transaction_table(int logicnum, TODBC_recordset & odbc, TAssoc_array& pairs); + void transaction_table(const char * table, TODBC_recordset & odbc, TAssoc_array& pairs); - void sync_table(TISAM_recordset& in_set, const char* out_table, - const TString_array& pairs); - void sync_table(const char* in_table, const char* out_table, - const TString_array& fields, const TDate& dal, const TDate& al); - void sync_table(const int logicnum, const char* out_table, - const TString_array& fields, const TDate& dal, const TDate& al); + void import_iva(); + void import_ums(); + void import_lines(); + void import_catmer(); + void import_val(); + void import_anamag(); + void import_barcode(); - void sync_iva(const TDate& dal, const TDate& al); - void sync_ums(const TDate& dal, const TDate& al); - void sync_lines(const TDate& dal, const TDate& al); - void sync_catmer(const TDate& dal, const TDate& al); - void sync_val(const TDate& dal, const TDate& al); - void sync_anamag(const TDate& dal, const TDate& al); - void sync_barcode(const TDate& dal, const TDate& al); - void sync_corrisp(const TDate& dal, const TDate& al); - void sync_mov(int tipotestata, const TDate& dal, const TDate& al); - void sync_scontrini(const TDate& dal, const TDate& al) { sync_mov(3, dal, al); } - void sync_doc(const TDate& dal, const TDate& al, int tipotestata,const char* unitadefault, bool importadoc); - void sync_carscar(const TDate& dal, const TDate& al) { sync_mov(1, dal, al); } - void sync_generici(const TDate& dal, const TDate& al) { sync_mov(4, dal, al); } - void sync_clifo(int cfmask, const TDate& dal, const TDate& al); - void sync_listino(const TString& listino); + void direct_doc(TODBC_recordset & odbc, const char * table, const int tipotestata, const char* unitadefault, bool importadoc); + void transaction_doc(TODBC_recordset & odbc, const char * table, const int tipotestata, const char* unitadefault, bool importadoc); + void import_doc(const TDate& dal, const TDate& al, int tipotestata,const char* unitadefault, bool importadoc); + void import_clifo(int cfmask, const TDate& dal, const TDate& al); TToken_string & decode_presentazione(const char* IBAN); @@ -211,101 +266,211 @@ public: }; // Carica da BeeStore i record con Origine=1, cioè generati da lui ed eventualmente aggiorna i corrispondenti in Campo -void TImporta_sync::load_origine_1(TISAM_recordset& out_set, const char* in_table, const TString_array& pairs) +void TImporta_Beestore::add_nomenclatura(const char * nomenclatura) { - TString str(255); - str << "SELECT "; - FOR_EACH_ARRAY_ROW(pairs, f, row) - str << row->get(0) << ','; - str.rtrim(1); // toglie ultima virgola - str << "\nFROM " << in_table << " WHERE (Origine=1);"; - - TODBC_recordset odbc(str); - odbc.connect(_dsn, _usr, _psw); - const TRecnotype n = odbc.items(); - if (n > 0) + if (nomenclatura && *nomenclatura && strlen(nomenclatura) == 8) { - TLocalisamfile& file = out_set.cursor()->file(); - const RecDes& rd = file.curr().rec_des(); - TToken_string key_fields; - for (int i = 0; i < rd.Ky->NkFields; i++) + TRectype & rec = (TRectype &)cache().get("%NOC", nomenclatura); + + if (rec.empty()) { - const int nf = rd.Ky[0].FieldSeq[i] % MaxFields; - key_fields.add(rd.Fd[nf].Name); + rec.put("CODTAB", nomenclatura); + rec.put("S0", "Da definire"); + rec.write(); } + } +} - str.format(TR("Importazione %ld record dalla tabella %s"), n, in_table); - _log->log(0, ""); - _log->log(0, str); +bool TImporta_Beestore::fill_rec(TRectype & rec, TODBC_recordset& odbc, TAssoc_array& pairs, TString & log_str, const TDate dtultagg, bool fill_key) +{ + TString key_str(prefix().get_keyexpr(rec.num())); + bool dirty = false; - TProgress_monitor pi(n, str); - for (bool ok = odbc.move_first(); ok; ok = odbc.move_next()) - { - file.zero(); - TString80 cfld, bfld; // Campo field e BeeStore field - FOR_EACH_ARRAY_ROW(pairs, p, row) - { - bfld = row->get(0); - cfld = row->get(); - const int pos = key_fields.get_pos(cfld); - if (pos >= 0) + if (fill_key) + rec.zero(); + FOR_EACH_ASSOC_STRING(pairs, obj, odbc_fld, fld) + { + bool in_key = key_str.find(fld) >= 0; + + if ((fill_key && in_key) || (!fill_key && !in_key)) + { + TString val = odbc.get_string(odbc_fld); + + if (val.full()) + { + const bool update = val != rec.get(fld); + + dirty |= update; + if (odbc_fld == "codDogana") { - const TVariant& var = odbc.get(bfld); - if (!var.is_null()) - file.put(cfld, var.as_string()); - if (pos == key_fields.items() - 1) - break; + val.strip("."); + if (val.len() <= 8) + { + val.lpad(8, '0'); + add_nomenclatura(val); + } + else + { + _log->log(2, format(FR("Codice nomenclatura combinata %s errato, non e' stato importato"), (const char *)val)); + continue; + } + rec.put(fld, val); + if (update) + log_str << " " << fld << "=" << val; } - } + } + } + } + if (dirty) + { + if (rec.exist(CLI_UTENTE)) + rec.put(CLI_UTENTE, user()); + if (rec.exist(CLI_DATAAGG)) + rec.put(CLI_DATAAGG, dtultagg); + } + return dirty; +} - int err = file.read(_isequal, _lock); +bool TImporta_Beestore::fill_transaction(TTransaction & transaction, TRectype & rec, TODBC_recordset& odbc, TAssoc_array& pairs, TDate dtultagg) +{ + bool dirty = false; + + FOR_EACH_ASSOC_STRING(pairs, obj, odbc_fld, fld) + { + TString val = odbc.get_string(odbc_fld); + const bool update = val != rec.get(fld); + + if (val.full() && odbc_fld == "codDogana") + { + val.strip("."); + + if (val.len() <= 8) + { + val.lpad(8, '0'); + add_nomenclatura(val); + } + else + { + _log->log(2, format(FR("Codice nomenclatura combinata %s errato, non e' stato importato"), (const char *) val)); + continue; + } + } + dirty |= update; + transaction.set(fld, val, -1, rec.num()); + } + if (dirty) + { + if (rec.exist(CLI_UTENTE)) + transaction.set(CLI_UTENTE, user(), -1, rec.num()); + if (rec.exist(CLI_DATAAGG)) + transaction.set(CLI_DATAAGG, dtultagg, -1, rec.num()); + } + return dirty; +} + +bool TImporta_Beestore::fill_transaction(TTransaction & transaction, const char * table, TODBC_recordset& odbc, TAssoc_array& pairs, TDate dtultagg) +{ + FOR_EACH_ASSOC_STRING(pairs, obj, odbc_fld, fld) + { + const TString& val = odbc.get_string(odbc_fld); + transaction.set(fld, val, -1, table); + } + return true; +} + +const char * TImporta_Beestore::build_query(const char* table, TAssoc_array& pairs) +{ + TString_array fields; + TString & query = get_tmp_string(255); + + pairs.get_keys(fields); + query << "SELECT "; + FOR_EACH_ARRAY_ROW(fields, f, row) + query << *row << ','; + query.rtrim(1); // toglie ultima virgola + query << "\nFROM " << table << " WHERE (Origine=1);"; + return query; +} + +void TImporta_Beestore::import_table(int logicnum, const char* table, TAssoc_array& pairs) +{ + TString str; + TODBC_recordset odbc(build_query(table, pairs)); + + odbc.connect(_dsn, _usr, _psw); + + const TRecnotype n = odbc.items(); + + if (n > 0) + { + if (_direct_write) + direct_table(logicnum, odbc, pairs); + else + transaction_table(logicnum, odbc, pairs); + } +} + +void TImporta_Beestore::import_table(const char * tab, const char* table, TAssoc_array& pairs) +{ + TString str; + TODBC_recordset odbc(build_query(table, pairs)); + + odbc.connect(_dsn, _usr, _psw); + + const TRecnotype n = odbc.items(); + + if (n > 0) + { + if (_direct_write) + direct_table(tab, odbc, pairs); + else + transaction_table(tab, odbc, pairs); + } +} + +void TImporta_Beestore::direct_table(int logicnum, TODBC_recordset & odbc, TAssoc_array& pairs) +{ + TString str; + TLocalisamfile file(logicnum); + TRectype & rec = file.curr(); + + str.format(TR("Importazione %ld record dalla tabella %s"), odbc.items(), odbc.table_name()); + _log->log(0, ""); + _log->log(0, str); + + TProgress_monitor pi(odbc.items(), str); + + for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next()) + { + TDate dtultagg = odbc.get(BS_DTULTAGG).as_date(); + + if (!dtultagg.ok()) + dtultagg = TODAY; + str = "Record"; + fill_rec(rec, odbc, pairs, str, dtultagg, true); + int err = file.read(_isequal, _lock); + const bool elab = (err == NOERR && (_tipo_imp != imp_aggiungi)) || + (err != NOERR && (_tipo_imp != imp_aggiorna)); + + if (elab) + { if (err == NOERR) { bool dirty = false; - const TDate dataagg = file.get(CLI_DATAAGG); - TDate dtultagg = odbc.get(BS_DTULTAGG).as_date(); - if (!dtultagg.ok()) dtultagg = TODAY; - - str = "record"; - FOR_EACH_TOKEN(key_fields, f) - str << ' ' << file.get(f); + const TDate dataagg = rec.get(CLI_DATAAGG); if (dtultagg >= dataagg) { - FOR_EACH_ARRAY_ROW(pairs, r, row) - { - bfld = row->get(0); - cfld = row->get(); - if (cfld[0] >= 'A' && cfld.find("->") < 0 && key_fields.get_pos(cfld) < 0) // Aggiorno solo i campi NON chiave - { - const TString& vec = file.get(cfld); - const TString& nov = odbc.get(bfld).as_string(); - if (nov != vec) - { - if (!dirty) - str << ' ' << bfld << "='" << nov << '\''; - file.put(cfld, nov); - dirty = true; - } - } - } - if (dirty) - { - TRectype& rec = file.curr(); - if (rec.exist(CLI_UTENTE)) - rec.put(CLI_UTENTE, "BEESTORE"); - if (rec.exist(CLI_DATAAGG)) - rec.put(CLI_DATAAGG, dtultagg); - } - else + dirty = fill_rec(rec, odbc, pairs, str, dtultagg); + if (!dirty) str << " Nessuna variazione pertinente"; } else str << " Data di ultimo aggiornamento obsoleta"; if (dirty) { - if (file.rewrite() == 0) - _log->log(1, str); + if ((err = file.rewrite()) == NOERR) + _log->log(0, str); else { TString80 err; err << TR("ERRORE ") << err << TR(" aggiornando il "); @@ -322,18 +487,10 @@ void TImporta_sync::load_origine_1(TISAM_recordset& out_set, const char* in_tabl else if (err == _iskeynotfound) { - file.zero(); - FOR_EACH_ARRAY_ROW(pairs, r, row) - { - bfld = row->get(0); - cfld = row->get(); - if (cfld[0] >= 'A' && cfld.find("->")) - { - const TString& nov = odbc.get(bfld).as_string(); - file.put(cfld, nov); - } - } - if (file.write() == 0) + str = "Record"; + fill_rec(rec, odbc, pairs, str, dtultagg, true); + fill_rec(rec, odbc, pairs, str, dtultagg); + if ((err = file.write()) == NOERR) _log->log(1, str); else { @@ -343,240 +500,289 @@ void TImporta_sync::load_origine_1(TISAM_recordset& out_set, const char* in_tabl } } } - - str.cut(0) << "DELETE FROM " << in_table << " WHERE Origine=1;"; - odbc.exec(str); } } -void TImporta_sync::save_origine_2(TISAM_recordset& in_set, const char* out_table, const TString_array& fields, TFieldEvaluator* fval) +void TImporta_Beestore::direct_table(const char * tab, TODBC_recordset & odbc, TAssoc_array& pairs) { - const TRecnotype n = in_set.items(); - TString str(255); - TODBC_recordset odbc(str); - odbc.connect(_dsn, _usr, _psw); - str.cut(0) << "DELETE FROM " << out_table << " WHERE Origine=2;"; - odbc.exec(str); + TString str; + TTable table(tab); + TRectype & rec = table.curr(); - str.format(TR("Esportazione %ld record in %s"), n, out_table); - _log->log(0, ""); - _log->log(0, str); + str.format(TR("Importazione %ld record dalla tabella %s"), odbc.items(), odbc.table_name()); + _log->log(0, ""); + _log->log(0, str); - const TRectype& curr = in_set.cursor()->curr(); + TProgress_monitor pi(odbc.items(), str); - TProgress_monitor pi(n, str); - for (bool ok = in_set.move_first(); ok; ok = in_set.move_next()) - { + for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next()) + { + TDate dtultagg = odbc.get(BS_DTULTAGG).as_date(); - str.cut(0) << "INSERT INTO " << out_table << "\n("; - FOR_EACH_ARRAY_ROW(fields, sr, srow) - str << (sr ? ", " : "") << srow->get(0); - str << ", Origine, Errore, " BS_DTULTAGG; - str << ")\nVALUES ("; + if (!dtultagg.ok()) + dtultagg = TODAY; + str = "Record"; + fill_rec(rec, odbc, pairs, str, dtultagg, true); + int err = table.read(_isequal, _lock); + const bool elab = (err == NOERR && (_tipo_imp != imp_aggiungi)) || + (err != NOERR && (_tipo_imp != imp_aggiorna)); - FOR_EACH_ARRAY_ROW(fields, ir, irow) + if (elab) { - if (ir) str << ", "; - if (fval) + if (err == NOERR) { - const char* fname = irow->get(0); // BeeStore field name - const char* fexpr = irow->get(); // Campo expression - TVariant var; - if (fval(in_set, fname, fexpr, var)) - { - str << var2sql(var); - continue; - } - } + bool dirty = false; + const TDate dataagg = rec.get(CLI_DATAAGG); - const TFixed_string cfld = irow->get(1); - if (cfld.find("SCONTO") >= 0) - { - real sconto; - const TString& exp = curr.get(cfld); - if (exp.full()) + if (dtultagg >= dataagg) { - if (real::is_natural(exp)) - sconto = real(exp); + if (!(dirty = fill_rec(rec, odbc, pairs, str, dtultagg))) + str << " Nessuna variazione pertinente"; + } + else + str << " Data di ultimo aggiornamento obsoleta"; + if (dirty) + { + if ((err = table.rewrite()) == NOERR) + _log->log(0, str); else { - TString80 goodexp; real val_perc; - if (scontoexpr2perc(exp, false, goodexp, val_perc) && val_perc != UNO) - { - sconto = CENTO - CENTO * val_perc; - sconto.round(5); - } + TString80 err; err << TR("ERRORE ") << err << TR(" aggiornando il "); + str.insert(err); + _log->log(2, str); } } - str << var2sql(sconto); + else + { + _log->log(0, str); + table.reread(_unlock); + } } else - if ((cfld[0] >= 'A' && cfld[0] <= 'Z') || cfld.find("->") > 0) - str << expr2sql(in_set, cfld); - else - str << cfld; - } - - str << ", 2, 0, GETDATE()"; - str << ");"; - - const long err = odbc.exec(str); - if (err <= 0) - { - TParagraph_string par(str, 75); - if (par.items() > 4) - { - str.cut(0); - bool values = false; - FOR_EACH_TOKEN(par, s) + if (err == _iskeynotfound) { - if (str.full() && !values) + str = "Record"; + fill_rec(rec, odbc, pairs, str, dtultagg, true); + fill_rec(rec, odbc, pairs, str, dtultagg); + if ((err = table.write()) == NOERR) + _log->log(1, str); + else { - values = _strnicmp(s, "VALUES", 6) == 0; - if (!values) - continue; + TString80 msg; msg << TR("ERRORE ") << err << TR(" inserendo il "); + str.insert(msg); + _log->log(2, str); } - str << s << '\n'; } - str.trim(); - } - _log->log(1, str); - str.format("SQL error %d", abs(err)); - _log->log(2, str); } - if (!pi.add_status()) - break; - } - odbc.exec("COMMIT;"); + } } -void TImporta_sync::sync_table(TISAM_recordset& in_set, const char* out_table, const TString_array& fields) +// Carica da BeeStore i record con Origine=1, cioè generati da lui ed eventualmente aggiorna i corrispondenti in Campo +void TImporta_Beestore::transaction_table(int logicnum, TODBC_recordset & odbc, TAssoc_array& pairs) { - load_origine_1(in_set, out_table, fields); - //save_origine_2(in_set, out_table, fields); -} + TString str; + TLocalisamfile file(logicnum); + TRectype & rec = file.curr(); -static TString& build_query(const char* table, const TDate& dal, const TDate& al) -{ - TString& q = get_tmp_string(); - q << "USE " << table; - if (dal.ok() || al.ok()) - q << " SELECT BETWEEN(DATAAGG," << dal.date2ansi() << ',' << al.date2ansi() << ")"; - return q; -} + str.format(TR("Importazione %ld record dalla tabella %s"), odbc.items(), odbc.table_name()); + _log->log(0, ""); + _log->log(0, str); + + TProgress_monitor pi(odbc.items(), str); + + TArray transactions; -static TString& build_query(const int logicnum, const TDate& dal, const TDate& al) -{ - const TRectype rec(logicnum); - TString& q = get_tmp_string(); - q << "USE " << logicnum; - - if (rec.exist(CLI_UTENTE)) - q << " SELECT (UTENTE!=\"BEESTORE\")"; - - if ((dal.ok() || al.ok()) && rec.exist(CLI_DATAAGG)) + for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next()) { - if (q.find(" SELECT ") < 0) - q << " SELECT "; - else - q << "&&"; - q << "(BETWEEN(DATAAGG," << dal.date2ansi() << ',' << al.date2ansi() << "))"; + TString prefix("F"); prefix << logicnum; + TTransaction t(TFilename().temp(prefix)); + TDate dtultagg = odbc.get_date(BS_DTULTAGG); + + if (!dtultagg.ok()) dtultagg = TODAY; + + fill_rec(rec, odbc, pairs, str, dtultagg, true); + + const bool found = rec.read() == NOERR; + const TDate dataagg = rec.get(CLI_DATAAGG); + const bool elab = (found && (_tipo_imp != imp_aggiungi)) || + (!found && (_tipo_imp != imp_aggiorna)); + + if (elab) + { + if (found) + { + if (dtultagg > dataagg) + { + t.set_action(TRANSACTION_MODIFY); + t.set_mode(transaction_mode_automatic); + t.set_stop_on_error(false); + t.set_caller("BEESTORE"); + t.set_firm(get_firm()); + if (fill_transaction(t, rec, odbc, pairs, dtultagg)) + transactions.add(t); + else + { + str << " Nessuna variazione pertinente"; + _log->log(0, str); + } + } + else + { + str << " Data di ultimo aggiornamento obsoleta"; + _log->log(0, str); + } + } + else + { + t.set_action(TRANSACTION_INSERT); + t.set_mode(transaction_mode_automatic); + t.set_stop_on_error(false); + t.set_caller("BEESTORE"); + t.set_firm(get_firm()); + fill_transaction(t, rec, odbc, pairs, dtultagg); + transactions.add(t); + } + } + execute_transactions(transactions, *_log, _interactive); } - return q; } - -void TImporta_sync::sync_table(const char* table, const char* out_table, - const TString_array& fields, const TDate& dal, const TDate& al) +// Carica da BeeStore i record con Origine=1, cioè generati da lui ed eventualmente aggiorna i corrispondenti in Campo +void TImporta_Beestore::transaction_table(const char * table, TODBC_recordset & odbc, TAssoc_array& pairs) { - const TString& q = build_query(table, dal, al); - TISAM_recordset set(q); - sync_table(set, out_table, fields); + TString str; + TTable file(table); + TRectype & rec = file.curr(); + + str.format(TR("Importazione %ld record dalla tabella %s"), odbc.items(), odbc.table_name()); + _log->log(0, ""); + _log->log(0, str); + + TProgress_monitor pi(odbc.items(), str); + + TArray transactions; + + for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next()) + { + TString prefix("F"); prefix << table; + TTransaction t(TFilename().temp(prefix), table); + + fill_rec(rec, odbc, pairs, str, nulldate, true); + + const bool found = rec.read() == NOERR; + const bool elab = (found && (_tipo_imp != imp_aggiungi)) || + (!found && (_tipo_imp != imp_aggiorna)); + + if (elab) + { + if (found) + { + t.set_action(TRANSACTION_MODIFY); + t.set_mode(transaction_mode_automatic); + t.set_stop_on_error(false); + t.set_caller("BEESTORE"); + t.set_firm(get_firm()); + if (fill_transaction(t, rec, odbc, pairs, nulldate)) + transactions.add(t); + else + { + str << " Nessuna variazione pertinente"; + _log->log(0, str); + } + } + else + { + t.set_action(TRANSACTION_INSERT); + t.set_mode(transaction_mode_automatic); + t.set_stop_on_error(false); + t.set_caller("BEESTORE"); + t.set_firm(get_firm()); + fill_transaction(t, rec, odbc, pairs, nulldate); + transactions.add(t); + } + } + execute_transactions(transactions, *_log, _interactive); + } } -void TImporta_sync::sync_table(const int logicnum, const char* out_table, - const TString_array& fields, const TDate& dal, const TDate& al) +void TImporta_Beestore::import_ums() { - const TString& q = build_query(logicnum, dal, al); - TISAM_recordset set(q); - sync_table(set, out_table, fields); + TAssoc_array fields; + + fields.add("CodUntMis", "CODTAB"); + fields.add("DSUntMis", "S0"); + + import_table("%UMS", "tieUntMisura", fields); } -void TImporta_sync::sync_ums(const TDate& dal, const TDate& al) +void TImporta_Beestore::import_iva() +{ + TAssoc_array fields; + + fields.add("CodIva", "CODTAB"); + fields.add("CodIvaSt", "CODTAB"); + fields.add("DSIva", "S0"); + fields.add("Aliquota", "R0"); + + import_table("%IVA", "tieIva", fields); +} + +void TImporta_Beestore::import_lines() +{ + TAssoc_array fields; + + fields.add("CodLinea", "CODTAB"); + fields.add("DSLinea", "S0"); + + import_table("GMC", "tieLineeArt", fields); +} + +void TImporta_Beestore::import_catmer() +{ + TAssoc_array fields; + + fields.add("CodCategoriaMerceologica", "CODTAB"); + fields.add("DSCategoriaMerceologica", "S0"); +// fields.add("CodTipoEtichetta", ""); a che serviva ? + + import_table("GMC", "tieCategorieMerceologiche", fields); +} + +void TImporta_Beestore::import_anamag() +{ + TAssoc_array fields; + + fields.add("CodPadre", ANAMAG_CODART); + fields.add("DSArticolo", ANAMAG_DESCR); + fields.add("DSArticoloAgg", ANAMAG_DESCRAGG); + fields.add("CodIva", ANAMAG_CODIVA); + fields.add("CodCategMerceologica", ANAMAG_GRMERC); + fields.add("Bloccato", ANAMAG_SOSPESO); + fields.add("codDogana", ANAMAG_CLASSDOG); + + if (_direct_write) + { + import_table(LF_ANAMAG, "tieArticoli", fields); + fields.destroy(); + fields.add("CodPadre", ANAMAG_CODART); + fields.add("@1", UMART_NRIGA); + fields.add("CodUntMagazzino", UMART_UM); + import_table(LF_UMART, "tieArticoli", fields); + } + else + { + fields.add("CodPadre", FIELD_NAME(LF_UMART, UMART_CODART)); + fields.add("@1", FIELD_NAME(LF_UMART, UMART_NRIGA)); + fields.add("CodUntMagazzino", FIELD_NAME(LF_UMART, UMART_UM)); + import_table(LF_ANAMAG, "tieArticoli", fields); + } + import_barcode(); +} + +void TImporta_Beestore::import_barcode() { TString_array fields; - fields.add("CodUntMis|CODTAB"); - fields.add("DSUntMis|S0"); - sync_table("%UMS", "tieUntMisura", fields, dal, al); -} -void TImporta_sync::sync_iva(const TDate& dal, const TDate& al) -{ - TString_array fields; - fields.add("CodIva|CODTAB"); - fields.add("CodIvaSt|CODTAB"); - fields.add("DSIva|S0"); - fields.add("Aliquota|R0"); - - sync_table("%IVA", "tieIva", fields, dal, al); -} - -void TImporta_sync::sync_lines(const TDate& dal, const TDate& al) -{ - TString_array fields; - fields.add("CodLinea|CODTAB"); - fields.add("DSLinea|S0"); - - TString query = build_query("GMC", dal, al); - if (query.find(" SELECT") < 0) - query << " SELECT "; - else - query << "&&"; - query << "(CODTAB?='???')"; - - TISAM_recordset lin(query); - sync_table(lin, "tieLineeArt", fields); -} - -void TImporta_sync::sync_catmer(const TDate& dal, const TDate& al) -{ - TString_array fields; - fields.add("CodCategoriaMerceologica|CODTAB"); - fields.add("DSCategoriaMerceologica|S0"); - fields.add("CodTipoEtichetta|''"); - - sync_table("GMC", "tieCategorieMerceologiche", fields, dal, al); -} - -void TImporta_sync::sync_anamag(const TDate& dal, const TDate& al) -{ - TString_array fields; - fields.add("CodPadre|" ANAMAG_CODART); - fields.add("DSArticolo|" ANAMAG_DESCR); - fields.add("DSArticoloAgg|" ANAMAG_DESCRAGG"[1,70]"); - fields.add("CodUntMagazzino|49->UM"); - fields.add("CodIva|" ANAMAG_CODIVA); - - fields.add("CodCategMerceologica|" ANAMAG_GRMERC); - fields.add("Bloccato|" ANAMAG_SOSPESO); - - TString query = build_query(LF_ANAMAG, dal, al); - query << "\nJOIN " << LF_UMART << " INTO CODART==CODART"; - - TISAM_recordset art(query); - sync_table(art, "tieArticoli", fields); - - /* - fields.destroy(); - fields.add("CodArticolo|" ANAMAG_CODART); - fields.add("CodPadre|" ANAMAG_CODART); - save_origine_2(art, "tieArtVarianti", fields); - */ -} - -void TImporta_sync::sync_barcode(const TDate& dal, const TDate& al) -{ - TString_array fields; fields.add("CodArticolo|" ANAMAG_CODART); fields.add("BarCode|" ANAMAG_DESCR); @@ -628,7 +834,6 @@ void TImporta_sync::sync_barcode(const TDate& dal, const TDate& al) } } - static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, const char* expr, TVariant& var) { const TAnagrafica& a = _anagr.anag(rec); @@ -637,11 +842,13 @@ static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, cons { TLocalisamfile& cfv = rec.cursor()->file(LF_CFVEN); TString80 codprcf = cfv.get(CFV_CODPRCF); + if (codprcf.blank() || codprcf[0] == 'C') // Anagrafica gestita da Campo { - 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); + const TString & t = rec.get_string(CLI_TIPOCF); + const long c = rec.get_long(CLI_CODCF); + TString8 cod_pk; cod_pk.format("C%06ld%s", c, (const char *) t); + if (cod_pk != codprcf) { cfv.put(CFV_CODPRCF, codprcf = cod_pk); @@ -703,9 +910,13 @@ static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, cons const char* suff = (*fldname == 'C') ? (strlen(fldname) > 9 ? "3" : "2") : ""; TString8 pref; pref << "PTEL" << suff; TString80 tele; tele << "TEL" << suff; - TString80 str; rec.get(pref).as_string(str); str << ' ' << rec.get(tele).as_string(); + TString80 str = rec.get_string(pref); + + str << ' ' << rec.get_string(tele); str.strip_double_spaces(); + char* s = str.get_buffer(); + for (const char* f = s; *f; f++) { if (*f == ' ' || (*f >= '0' && *f <= '9')) @@ -724,14 +935,16 @@ static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, cons } if (xvt_str_same(fldname, " CLIente")) { - const char tipocf = rec.get(CLI_TIPOCF).as_string()[0]; - var = tipocf == 'C'; + const TString& tipocf = rec.get_string(CLI_TIPOCF); + + var = tipocf == "C"; return true; } if (xvt_str_same(fldname, "Fornitore")) { - const char tipocf = rec.get(CLI_TIPOCF).as_string()[0]; - var = tipocf == 'F'; + const TString& tipocf = rec.get_string(CLI_TIPOCF); + + var = tipocf == "F"; return true; } if (_strnicmp(fldname, " CLI_", 4) == 0) @@ -748,21 +961,29 @@ static bool ClifoEvaluator(const TISAM_recordset& rec, const char* fldname, cons return false; } -const TString& TImporta_sync::comune(const TRecordset& recset, const char* fld_cap, const char* fld_den) const +const TString& TImporta_Beestore::comune(const TRecordset& recset, const char* fld_cap, const char* fld_den) const { - TString8 cap; if (fld_cap && *fld_cap) cap = recset.get(fld_cap).as_string().left(5); - TString80 den; if (fld_den && *fld_den) den = recset.get(fld_den).as_string(); + TString8 cap; + + if (fld_cap && *fld_cap) cap = recset.get(fld_cap).as_string().left(5); + + TString80 den; + + if (fld_den && *fld_den) den = recset.get(fld_den).as_string(); return ::cap2comune(cap, den); } -bool TImporta_sync::split_phone(const TRecordset& odbc, const char* number, TIsamfile& clifo, const char* pre, const char* num) const +bool TImporta_Beestore::split_phone(const TRecordset& odbc, const char* number, TLocalisamfile& clifo, const char* pre, const char* num) const { - TString pn = odbc.get(number).as_string(); + TString pn = odbc.get_string(number); + if (pn.full()) { pn.strip_double_spaces(); + const int maxpref = clifo.curr().length(pre); int split = -1; + for (int i = 0; pn[i] && i <= maxpref; i++) { if (!isdigit(pn[i])) @@ -786,21 +1007,51 @@ bool TImporta_sync::split_phone(const TRecordset& odbc, const char* number, TIsa return pn.full(); } -void TImporta_sync::load_clifo(char tipocf) +bool TImporta_Beestore::split_phone(const TRecordset& odbc, const char* number, TTransaction& transaction, const char* pre, const char* num) const +{ + TString pn = odbc.get_string(number); + + if (pn.full()) + { + pn.strip_double_spaces(); + + const int len = pn.len(); + int split = -1; + + for (int i = 0; i <= len; i++) + { + if (!isdigit(pn[i])) + { + split = i; + break; + } + } + + if (split > 1) + { + transaction.set(pre, pn.left(split), -1, LF_CLIFO); + transaction.set(num, pn.mid(split + 1), -1, LF_CLIFO); + } + else + transaction.set(num, pn, -1, LF_CLIFO); + } + return pn.full(); +} +void TImporta_Beestore::direct_clifo(char tipocf) { TString str(255); str << "SELECT * FROM tieAnagCFP WHERE (Origine=1)AND"; str << '(' << (tipocf == 'F' ? "Fornitore" : " CLIente") << "=1);"; - TFast_isamfile clifo(LF_CLIFO); + TLocalisamfile clifo(LF_CLIFO); TODBC_recordset odbc(str); odbc.connect(_dsn, _usr, _psw); const TRecnotype n = odbc.items(); - str.cut(0) << TR("Importazione ") << (tipocf == 'F' ? TR("Fornitori") : TR(" CLIenti")); + str.cut(0) << TR("Importazione ") << (tipocf == 'F' ? TR("Fornitori") : TR(" Clienti")); TProgress_monitor pi(n, str); - for (bool ok = odbc.move_first(); ok; ok = odbc.move_next()) + for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next()) { long codcf = odbc.get(tipocf == 'F' ? "For_CodFor" : " CLI_CodCG").as_int(); if (codcf <= 0) @@ -810,738 +1061,797 @@ void TImporta_sync::load_clifo(char tipocf) codcf = atol(cod_pk.mid(1, 6)); } - if (codcf > 0) + clifo.zero(); + clifo.put(CLI_TIPOCF, tipocf); + clifo.put(CLI_CODCF, codcf); + + const int err = clifo.read(); + const bool elab = (err == NOERR && (_tipo_imp != imp_aggiungi)) || + (err != NOERR && (_tipo_imp != imp_aggiorna)); + + if (elab) { - clifo.put(CLI_TIPOCF, tipocf); - clifo.put(CLI_CODCF, codcf); - if (clifo.read(_isequal) != NOERR) + if (err != NOERR) { clifo.zero(); clifo.put(CLI_TIPOCF, tipocf); clifo.put(CLI_CODCF, codcf); + clifo.write(); + + TLocalisamfile cfv(LF_CFVEN); + cfv.put(CFV_TIPOCF, tipocf); + cfv.put(CFV_CODCF, codcf); + TString8 codprcf; codprcf.format("C%06ld%c", codcf, tipocf); + cfv.put(CFV_CODPRCF, codprcf); + cfv.write(); } - } - else - { - codcf = 1L; - if (tipocf == 'F') + clifo.put(CLI_RAGSOC, odbc.get("RagSoc").as_string()); + + const int tipo = odbc.get("Tipo").as_int(); // 1=Fisica; 2=Giuridica; 3=Altro + + if (tipo == 1) { - if (clifo.last() == NOERR && clifo.get_char(CLI_TIPOCF) == 'F') - codcf += clifo.get_long(CLI_CODCF); + clifo.put(CLI_SESSO, odbc.get("Sesso").as_string()); + clifo.put(CLI_DATANASC, odbc.get("DTNascita").as_date()); + clifo.put(CLI_COMNASC, comune(odbc, "", "ComuneNascita")); + clifo.put(CLI_TIPOPERS, 'F'); } else + clifo.put(CLI_TIPOPERS, 'G'); + + TToken_string indirizzo(odbc.get("Indirizzo").as_string(), ','); + TString ind = indirizzo.get(0); + TString civ = indirizzo.get(); + TString loc = indirizzo.get(); + if (civ.len() > 10) { - clifo.put(CLI_TIPOCF, 'F'); - clifo.put(CLI_CODCF, 0); - if (clifo.read(_isgteq) == NOERR) + if (loc.full()) + ind << ' ' << civ; + else + loc = civ; + civ.cut(0); + } + clifo.put(CLI_INDCF, ind.left(50)); + + split_phone(odbc, "Telefono", clifo, CLI_PTEL, CLI_TEL); + split_phone(odbc, "Cellulare", clifo, CLI_PTEL2, CLI_TEL2); + split_phone(odbc, "CellulareSMS", clifo, CLI_PTEL3, CLI_TEL3); + clifo.put(CLI_MAIL, odbc.get("EMail").as_string()); + + clifo.put(CLI_UTENTE, user()); + + TDate dua = odbc.get_date(BS_DTULTAGG); + + if (!dua.ok()) dua = TDate(TODAY); + clifo.put(CLI_DATAAGG, dua); + clifo.rewrite(); + } + } +} + +void TImporta_Beestore::transaction_clifo(char tipocf) // fare +{ + TString str(255); + TArray transactions; + + str << "SELECT * FROM tieAnagCFP WHERE (Origine=1)AND"; + str << '(' << (tipocf == 'F' ? "Fornitore" : " CLIente") << "=1);"; + + TLocalisamfile clifo(LF_CLIFO); + TRectype & rec = clifo.curr(); + TODBC_recordset odbc(str); + + odbc.connect(_dsn, _usr, _psw); + + const TRecnotype n = odbc.items(); + + str.cut(0) << TR("Importazione ") << (tipocf == 'F' ? TR("Fornitori") : TR(" CLIenti")); + + TProgress_monitor pi(n, str); + + for (bool ok = odbc.move_first(); pi.add_status() && ok; ok = odbc.move_next()) + { + TFilename f; f.temp("cf"); + TTransaction t(f); + TDate dtultagg = odbc.get(BS_DTULTAGG).as_date(); + long codcf = odbc.get_long(tipocf == 'F' ? "For_CodFor" : " CLI_CodCG"); + + if (!dtultagg.ok()) + dtultagg = TODAY; + if (codcf <= 0) + { + const TString& cod_pk = odbc.get("Cod_PK").as_string(); + if (cod_pk[0] == 'C' && cod_pk.len() == 8 && cod_pk[7] == tipocf) + codcf = atol(cod_pk.mid(1, 6)); + } + + rec.zero(); + rec.put(CLI_TIPOCF, tipocf); + if (codcf > 0L) + rec.put(CLI_CODCF, codcf); + + bool found = clifo.read() == NOERR; + const bool elab = (found && (_tipo_imp != imp_aggiungi)) || + (!found && (_tipo_imp != imp_aggiorna)); + + if (elab) + { + t.set_action(found ? TRANSACTION_MODIFY : TRANSACTION_INSERT); + t.set_mode(transaction_mode_automatic); + t.set_stop_on_error(false); + t.set_caller("BEESTORE"); + t.set_firm(get_firm()); + t.set(CLI_RAGSOC, odbc.get_string("RagSoc"), -1, LF_CLIFO); + + const int tipo = odbc.get_int("Tipo"); // 1=Fisica; 2=Giuridica; 3=Altro + + if (tipo == 1) + { + t.set(CLI_SESSO, odbc.get_string("Sesso"), -1, LF_CLIFO); + t.set(CLI_DATANASC, odbc.get_date("DTNascita"), -1, LF_CLIFO); + t.set(CLI_COMNASC, comune(odbc, "", "ComuneNascita"), -1, LF_CLIFO); + t.set(CLI_TIPOPERS, 'F', -1, LF_CLIFO); + } + else + t.set(CLI_TIPOPERS, 'G', -1, LF_CLIFO); + + TToken_string indirizzo(odbc.get("Indirizzo").as_string(), ','); + TString ind = indirizzo.get(0); + TString civ = indirizzo.get(); + TString loc = indirizzo.get(); + if (civ.len() > 10) + { + if (loc.full()) + ind << ' ' << civ; + else + loc = civ; + civ.cut(0); + } + t.set(CLI_INDCF, ind.left(50), -1, LF_CLIFO); + + split_phone(odbc, "Telefono", clifo, CLI_PTEL, CLI_TEL); + split_phone(odbc, "Cellulare", clifo, CLI_PTEL2, CLI_TEL2); + split_phone(odbc, "CellulareSMS", clifo, CLI_PTEL3, CLI_TEL3); + t.set(CLI_MAIL, odbc.get_string("EMail"), -1, LF_CLIFO); + t.set(CFV_CODPRCF, format("C%06ld%c", codcf, tipocf), -1, LF_CFVEN, 1); + t.set(CLI_UTENTE, "BEESTORE", -1, LF_CLIFO); + + TDate dataagg = odbc.get_date(BS_DTULTAGG); + + if (!dataagg.ok()) + dataagg = TDate(TODAY); + + t.set(CLI_DATAAGG, dataagg, -1, LF_CLIFO); + transactions.add(t); + } + execute_transactions(transactions, *_log, _interactive); + } +} + +void TImporta_Beestore::import_clifo(int cfmask, const TDate& dal, const TDate& al) +{ + if (_direct_write) + { + if (cfmask & 1) direct_clifo('C'); + if (cfmask & 2) direct_clifo('F'); + } + else + { + if (cfmask & 1) transaction_clifo('C'); + if (cfmask & 2) transaction_clifo('F'); + } +} + + +void TImporta_Beestore::import_val() +{ + TAssoc_array fields; + + fields.add("CodValuta", "CODTAB"); + fields.add("DSValuta2", "S0"); + fields.add("Simbolo", "CODTAB"); + import_table("%VAL", "tieValute", fields); +} + +int TImporta_Beestore::tipotestata2idx(int tipotestata) +{ + switch (tipotestata) + { + case 1: + return 2; + break; + case 2: + break; + case 6: + return 1; + break; + case 9: + return 6; + break; + case 11: + return 3; + break; + case 13: + return 4; + break; + case 14: + return 5; + break; + default: + break; + } + return 0; +} + +const char * TImporta_Beestore::get_num(const TString & suffix, int tipotestata) +{ + TString key(suffix); + + key.trim(); + + TToken_string * nums = (TToken_string *) _nums.objptr(key); + + if (nums == nullptr) + nums = (TToken_string *) _nums.objptr(EMPTY_STRING); + if (nums == nullptr) + fatal_box(TR("Array delle numerazioni non valido")); + return nums->get(tipotestata2idx(tipotestata)); +} + +bool TImporta_Beestore::save_and_delete_doc(TDocumento* doc) const +{ + int err = 0; + if (doc != nullptr) + { + if (doc->rows() > 0) + { + err = doc->write(); + if (err != NOERR) + { + TString msg; + + msg.format(FR("Errore %d in registrazione documento %s/%ld del %s"), err, + (const char *)doc->get(DOC_CODNUM), doc->get_long(DOC_NDOC), (const char*)doc->get(DOC_DATADOC)); + _log->log(2, msg); + msg << TR("\nSi desidera proseguire ugualmente?"); + if (noyes_box(msg)) + err = 0; + } + } + safe_delete(doc); + } + return err == 0; +} + +void TImporta_Beestore::direct_doc(TODBC_recordset & docs, const char * table, const int tipotestata, const char* unitadefault, bool importadoc) +{ + TString msg(TR("Importazione ")); msg << table; + TProgress_monitor pi(docs.items(), msg); + long last = -1, ndoc, codcf; + TString4 tipocf; + TToken_string codtestata("", '\\'); + TDocumento* doc = nullptr; + int contatore = 0; + int eccezioni_errori = 0; + TString codpk = ""; + bool elab = false; + + for (bool ok = docs.move_first(); ok; ok = docs.move_next()) + { + TString wrk = docs.get_string("CodCliente"); + + codtestata = docs.get_string("CodTestata"); + ndoc = codtestata.get_long(BS_POSNUMDOC); + while (wrk[0] >= 'A') + wrk.ltrim(1); + codcf = atol(wrk); + tipocf = docs.get("TipoIntestatario").as_string(); + + TToken_string key = tipocf; + + key.add(codcf); + if (cache().get(LF_CLIFO, key).empty()) + { + TString msg; msg.format("Attenzione! Per il doc n. %d e' presente il tipo C/F = '%s' con cod = %d \nIl documento verra' saltato.", ndoc, (const char*)tipocf, codcf); + _log->log(1, msg); + continue; + } + + TString8 tipodoc = tipotestata != 14 ? docs.get_string("TipoDocCE") : get_num("", 14); + + if (ndoc != last) + { + if (ndoc > 0) + { + elab = (!doc->nuovo() && (_tipo_imp != imp_aggiungi)) || + (doc->nuovo() && (_tipo_imp != imp_aggiorna)); + + if (elab) { - if (clifo.prev() == NOERR && clifo.get_char(CLI_TIPOCF) == 'C') - codcf += clifo.get_long(CLI_CODCF); + if (!save_and_delete_doc(doc)) + break; } - } - clifo.zero(); - clifo.put(CLI_TIPOCF, tipocf); - clifo.put(CLI_CODCF, codcf); - clifo.write(); + else + safe_delete(doc); + } + last = ndoc; - TLocalisamfile cfv(LF_CFVEN); - cfv.put(CFV_TIPOCF, tipocf); - cfv.put(CFV_CODCF, codcf); - TString8 codprcf; codprcf.format("C%06ld%c", codcf, tipocf); - cfv.put(CFV_CODPRCF, codprcf); - cfv.write(); - } - clifo.put(CLI_RAGSOC, odbc.get("RagSoc").as_string()); + const TDate datadoc = docs.get_date("DataDoc"); + TString cod_pk = docs.get_string("Cod_PK"); - const int tipo = odbc.get("Tipo").as_int(); // 1=Fisica; 2=Giuridica; 3=Altro - if (tipo == 1) - { - clifo.put(CLI_SESSO, odbc.get("Sesso").as_string()); - clifo.put(CLI_DATANASC, odbc.get("DTNascita").as_date()); - clifo.put(CLI_COMNASC, comune(odbc, "", "ComuneNascita")); - clifo.put(CLI_TIPOPERS, 'F'); - } - else - clifo.put(CLI_TIPOPERS, 'G'); + TString origine_dc = docs.get_string("Origine"); - TToken_string indirizzo(odbc.get("Indirizzo").as_string(), ','); - TString ind = indirizzo.get(0); - TString civ = indirizzo.get(); - TString loc = indirizzo.get(); - if (civ.len() > 10) - { - if (loc.full()) - ind << ' ' << civ; - else - loc = civ; - civ.cut(0); - } - clifo.put(CLI_INDCF, ind.left(50)); + if (tipodoc.full()) + { + TTipo_documento tipo(tipodoc); + const TString8 codcaus = tipo.caus_mov(); + TString str = docs.get_string("NumDoc"); + long numdoc = ndoc; - split_phone(odbc, "Telefono", clifo, CLI_PTEL, CLI_TEL); - split_phone(odbc, "Cellulare", clifo, CLI_PTEL2, CLI_TEL2); - split_phone(odbc, "CellulareSMS", clifo, CLI_PTEL3, CLI_TEL3); - clifo.put(CLI_MAIL, odbc.get("EMail").as_string()); + while (str[0] > 'A') + str.ltrim(1); + if (str.full()) + numdoc = atol(str); - clifo.put(CLI_UTENTE, "BEESTORE"); - TDate dua = odbc.get(BS_DTULTAGG).as_date(); - if (!dua.ok()) dua = TDate(TODAY); - clifo.put(CLI_DATAAGG, dua); + doc = new TDocumento('D', datadoc.year(), get_num(docs.get_string("SuffNum"), tipotestata), numdoc); + doc->destroy_rows(); + doc->put(DOC_DATADOC, datadoc); + doc->put(DOC_TIPODOC, tipodoc); + if (tipotestata != 14) + { + doc->put(DOC_TIPOCF, tipocf); + doc->put(DOC_CODCF, codcf); + doc->cli2doc(); - clifo.rewrite(); + const TString8 codval = docs.get_string("CodValuta"); + const real cambio = docs.get_string("CambioValuta"); + const TString asp = docs.get_string("AspettoBeni"); + const int ncolli = docs.get_int("NumeroColli"); + // inserire codice pagamento Es. BB02 + doc->put(DOC_CODVAL, codval); + doc->put(DOC_CAMBIO, cambio); - if (!pi.add_status()) - break; - } -} + doc->put(DOC_CODPAG, docs.get_string("CodPagamento_FP")); + doc->put(DOC_CODABIA, docs.get_string("ABI")); //banca di appoggio + doc->put(DOC_CODCABA, docs.get_string("CAB")); -void TImporta_sync::save_clifo(int cfmask, const TDate& dal, const TDate& al) -{ - TString_array fields; - fields.add("Cod_PK|" CLI_CODCF); - fields.add("RagSoc|" CLI_RAGSOC); - fields.add("Cognome|" CLI_RAGSOC); - fields.add("Nome|" CLI_RAGSOC); - fields.add("Indirizzo|" CLI_INDCF); - fields.add("Citta|" CLI_COMCF); - fields.add("Cap|" CLI_CAPCF); - fields.add("Provincia|"); - fields.add("Telefono|PTEL+TEL"); - fields.add("Cellulare|PTEL2+TEL2"); - fields.add("CellulareSMS|PTEL3+TEL3"); - fields.add("EMail|" CLI_MAIL); - fields.add("PartitaIva|" CLI_PAIV); - fields.add("CodFiscale|" CLI_COFI); - fields.add("Tipo|1"); - fields.add("Sesso|" CLI_SESSO); - fields.add("DTNascita|" CLI_DATANASC); - fields.add("ComuneNascita|" CLI_COMNASC); - fields.add("PVNascita|"); - fields.add(" CLIente|"); - fields.add("Fornitore|"); - fields.add("For_CodFor|" CLI_CODCF); - fields.add("For_Blocco|" CLI_SOSPESO); - fields.add(" CLI_CodCG|" CLI_CODCF); - fields.add(" CLI_Blocco|" CLI_SOSPESO); - fields.add("MagInserAnagrafica|1"); - fields.add("CodStato|" CLI_STATOCF); - fields.add("Annullato|0"); + TToken_string bnpkey = decode_presentazione(docs.get_string("NostroContoCorr")); - 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"; + doc->put(DOC_CODABIP, bnpkey.get()); //banca di presentazione + doc->put(DOC_CODCABP, bnpkey.get()); + doc->put(DOC_PROGBNP, bnpkey.get()); //banca di presentazione - TISAM_recordset clifo(query); - //save_origine_2(clifo, "tieAnagCFP", fields, ClifoEvaluator); -} + doc->put(DOC_NOTE, asp); // l'aspetto dei beni è una stringa la devo mettere nelle note + doc->put(DOC_NCOLLI, ncolli); + doc->put(DOC_CAUSMAG, codcaus); + } + contatore++; + } + else + { + eccezioni_errori++; + codpk = cod_pk; + TString dserrore = docs.get("DSErrore").as_string(); + dserrore.sleft(50); + dserrore << " TipoDocCe assente o invalido"; + TString update_str = ""; + update_str << "UPDATE tieTBolFat \n SET Errore = 1 , DSErrore = '" << dserrore << "' \n WHERE cod_pk= '" << codpk << "' "; + TODBC_recordset docs(update_str); + docs.connect(_dsn, _usr, _psw); + docs.exec(update_str); + } + } + if (tipodoc.full()) + { + const int tipoart = docs.get_int("TipoArticolo"); + TRectype& rdoc = doc->new_row("01"); + TString80 codart = docs.get_string("IDArticolo"); + if (codart.blank()) + codart = docs.get_string("CodArticolo"); + if (codart == BS_FREEROW) + codart = ""; -void TImporta_sync::sync_clifo(int cfmask, const TDate& dal, const TDate& al) -{ - if (cfmask & 1) load_clifo('C'); - if (cfmask & 2) load_clifo('F'); + TString descrizione = docs.get_string("Modello"); + if (descrizione.blank()) + descrizione = docs.get_string("DSRiga"); + if (codart.full()) + { + rdoc.put(RDOC_CODART, codart); + if (importadoc && tipoart == 0) + { + rdoc.put(RDOC_CODARTMAG, codart); + rdoc.put(RDOC_CHECKED, "X"); + if (cache().get(LF_ANAMAG, codart).empty()) + { + TArticolo articolo; + articolo.put(ANAMAG_CODART, codart); - TString str(255); - TODBC_recordset clifo(str); - clifo.connect(_dsn, _usr, _psw); - /* - str << "DELETE FROM tieAnagCFP WHERE Origine=1;"; - clifo.exec(str); // Elimina tutte le anagrafiche importate da BeeStore - */ - save_clifo(cfmask, dal, al); -} + articolo.put(ANAMAG_DESCR, descrizione); + TString nomenclatura = docs.get_string("CodDogana"); + if (nomenclatura.blank()) + nomenclatura = docs.get_string("CodCategoria"); + nomenclatura.strip("."); -bool TImporta_sync::save_and_delete_movmag(TMov_mag*& doc) const -{ - int err = 0; - if (doc != NULL) - { - if (doc->rows() > 0) - { - TLocalisamfile mm(LF_MOVMAG); - err = doc->write(mm); - if (err != NOERR) - { - TString msg; - msg.format(FR("Errore %d in registrazione scontrino %ld del %s"), err, - doc->get_long(MOVMAG_NUMREG), (const char*)doc->get(MOVMAG_DATAREG)); - _log->log(2, msg); - msg << TR("\nSi desidera proseguire ugualmente?"); - if (noyes_box(msg)) - err = 0; - } - } - delete doc; - doc = NULL; - } - return err == 0; -} + if (nomenclatura.len() <= 8) + { + nomenclatura.lpad(8, '0'); + add_nomenclatura(nomenclatura); + articolo.put(ANAMAG_CLASSDOG, nomenclatura); + } + else + _log->log(2, format(FR("Codice nomenclatura combinata %s errato, non e' stato importato"), (const char *) nomenclatura)); -bool TImporta_sync::save_and_delete_doc(TDocumento*& doc) const -{ - int err = 0; - if (doc != nullptr) - { - if (doc->rows() > 0) - { - err = doc->write(); - if (err != NOERR) - { - TString msg; + TRectype& umart = articolo.new_row(LF_UMART); + TString unitamisura = docs.get_string("CodUntMis"); + if (unitamisura.blank()) + unitamisura = unitadefault; + umart.put(UMART_UM, unitamisura); + umart.put(UMART_FC, 1); + articolo.write(); + } + } + if (tipoart == 2) //righe libere + { + if (cache().get("SPP", codart).not_empty()) + rdoc.put(RDOC_CODARTMAG, codart); + } + else //spese servizi e articoli + { + if (cache().get(LF_ANAMAG, codart).not_empty()) + rdoc.put(RDOC_CODARTMAG, codart); + } - msg.format(FR("Errore %d in registrazione dcoumento %s/%ld del %s"), err, - (const char *)doc->get(DOC_CODNUM), doc->get_long(DOC_NDOC), (const char*)doc->get(DOC_DATADOC)); - _log->log(2, msg); - msg << TR("\nSi desidera proseguire ugualmente?"); - if (noyes_box(msg)) - err = 0; - } - } + rdoc.put(RDOC_CODARTMAG, codart); + } + rdoc.put(RDOC_DESCR, descrizione.sleft(50)); + if (descrizione.len() > 50) + { + rdoc.put(RDOC_DESCLUNGA, "X"); + rdoc.put(RDOC_DESCEST, descrizione.smid(50)); + } + rdoc.put(RDOC_CODMAG, docs.get_string("CodMagazzino").left(5)); + rdoc.put(RDOC_CODMAGC, docs.get_string("CodMagazDest").left(5)); + + TString unitamisura = docs.get_string("CodUntMis"); + + if (unitamisura.blank()) + unitamisura = unitadefault; + rdoc.put(RDOC_UMQTA, docs.get_string("CodUntMis")); + rdoc.put(RDOC_QTA, docs.get_real("Quantita")); + rdoc.put(RDOC_PREZZO, docs.get_real("PrzNettoNeg")); // o PrzNettoValuta ?? + rdoc.put(RDOC_CODIVA, docs.get_string("CodIva")); + + } + else + { + TString dserrore = docs.get("DSErrore").as_string(); + dserrore.sleft(50); + dserrore << " TipoDocCe assente o invalido"; + TString update_str = ""; + update_str << "UPDATE tieDMovMag \n SET Errore = 1 , DSErrore = '" << dserrore << "' \n WHERE CodTestata= '" << codpk << "' "; + TODBC_recordset docs(update_str); + docs.connect(_dsn, _usr, _psw); + docs.exec(update_str); + } + if (!pi.add_status()) + break; + + } + elab = (!doc->nuovo() && (_tipo_imp != imp_aggiungi)) || + (doc->nuovo() && (_tipo_imp != imp_aggiorna)); + + if (elab) + save_and_delete_doc(doc); // Salva ultimo documento in sospeso + else safe_delete(doc); - } - return err == 0; + msg = TR("Documenti importati "); + msg << contatore << " in " << table; + _log->log(0, ""); + _log->log(0, msg); + if (eccezioni_errori > 0) + { + msg = TR("Errori in importazione "); + msg << eccezioni_errori << " in " << table; + _log->log(2, msg); + } } -void TImporta_sync::sync_val(const TDate& dal, const TDate& al) +void TImporta_Beestore::transaction_doc(TODBC_recordset & docs, const char * table, const int tipotestata, const char* unitadefault, bool importadoc) { - TString_array fields; - fields.add("CodValuta|CODTAB"); - fields.add("DSValuta|S0"); - fields.add("Simbolo|CODTAB"); - sync_table("%VAL", "tieValute", fields, dal, al); -} + TString msg(TR("Importazione ")); msg << table; + TProgress_monitor pi(docs.items(), msg); + long last = -1, ndoc, codcf; + TString4 tipocf; + TToken_string codtestata("", '\\'); + int contatore = 0; + int eccezioni_errori = 0; + int row = 0; + TString codpk; + TArray transactions; + TArray art_transactions; + TTransaction t(""); + TAssoc_array art_inserted; + bool nuovo = false; + bool elab = false; + + for (bool ok = docs.move_first(); pi.add_status() && ok; ok = docs.move_next()) + { + TString wrk = docs.get_string("CodCliente"); + TString8 tipodoc = tipotestata != 14 ? docs.get_string("TipoDocCE") : get_num("", 14); + TString cod_pk = docs.get_string("Cod_PK"); -void TImporta_sync::sync_listino(const TString& listino) -{ - TString str(255); - TODBC_recordset prz(str); - prz.connect(_dsn, _usr, _psw); - str = "DELETE FROM tiePrzVendita WHERE Origine=1"; - prz.exec(str); // Ignora tutti i listini di BeeStore - - str.cut(0) << "USE " << LF_RCONDV << " SELECT " << LF_ANAMAG << ".CODART!=\"\"" - << "\nJOIN " << LF_ANAMAG << " INTO CODART==CODRIGA" - << "\nFROM TIPO=L TIPORIGA=A COD=" << listino - << "\nTO TIPO=L TIPORIGA=A COD=" << listino; - TISAM_recordset lis(str); - if (lis.move_first()) - { - TString16 eur; eur << "CodValuta|'" << TCurrency::get_euro_val() << "'"; - - TString16 key; key << "L||||" << listino; - const TRectype& condv = cache().get(LF_CONDV, key); - - TDate dt_inizio = condv.get(CONDV_VALIN); - if (!dt_inizio.ok()) dt_inizio = TDate(1, 1, 2000); - TDate dt_fine = condv.get(CONDV_VALFIN); - if (dt_fine < dt_inizio) dt_fine = TDate(31, 12, 2100); - - TString descr; descr << "DSListino|'" << condv.get(CONDV_DESCR) << '\''; - TString dtini; dtini << "DTInizio|'" << dt_inizio.string() << '\''; - TString dtfin; dtfin << "DTFine|'" << dt_fine.string() << '\''; - - TString_array fields; - fields.add("Cod_PK|" RCONDV_CODRIGA); - fields.add("CodPadre|" RCONDV_CODRIGA); - //fields.add("CodArticolo|"RCONDV_CODRIGA); // NON metterlo! - fields.add("TipoPrezzo|'1'"); // 1=Listino - fields.add(eur); - fields.add("Prezzo|" RCONDV_PREZZO); - fields.add("Prezzo2|0"); - fields.add("Sconto|" RCONDV_SCONTO); - if (real::is_natural(listino)) - fields.add("NumListino|" RCONDV_COD); - fields.add(descr); - fields.add(dtini); - fields.add(dtfin); - - //save_origine_2(lis, "tiePrzVendita", fields); - } -} - -void TImporta_sync::sync_mov(int tipotestata, const TDate& dal, const TDate& al) -{ - const TString8 codcaus = ini_get_string(CONFIG_DITTA, "bs", MOVMAG_CODCAUS, "", tipotestata); - - if (codcaus.blank()) - { - _log->log(2, "Configurare parametri per movimenti Bee Store"); - return; - } - - TString str(255); - str << "SELECT * FROM tieDMovMag WHERE Origine=1 AND TipoTestata=" << tipotestata; - if (dal.ok() || al.ok()) - { - str << " AND DataMov"; - if (dal.ok() && al.ok()) - str << " BETWEEN " << date2sql(dal) << " AND " << date2sql(al); - else + if (tipodoc.full()) { - if (dal.ok()) - str << ">=" << date2sql(dal); - else - str << "<=" << date2sql(al); - } - } - str << "\nORDER BY NumMov,NumRiga"; - - TODBC_recordset mov(str); - mov.connect(_dsn, _usr, _psw); - TProgress_monitor pi(mov.items(), str); - - TString num_mov, nm; - TMov_mag* doc = NULL; - - for (bool ok = mov.move_first(); ok; ok = mov.move_next()) - { - nm = mov.get("NumMov").as_string(); - if (nm != num_mov) - { - if (!save_and_delete_movmag(doc)) - break; - num_mov = nm; - const TDate datadoc = mov.get("DataMov").as_date(); - doc = new TMov_mag; - doc->put(MOVMAG_CODCAUS, codcaus); - doc->put(MOVMAG_DATAREG, datadoc); - } - TRectype& rdoc = doc->new_row(); - rdoc.put(RMOVMAG_CODART, mov.get("CodArticolo").as_string()); - rdoc.put(RMOVMAG_UM, mov.get("CodUntMis").as_string()); - rdoc.put(RMOVMAG_PREZZO, mov.get("PrzCassaValuta").as_real()); - if (!pi.add_status()) - break; - } - save_and_delete_movmag(doc); // Salva ultimo documento in sospeso -} - -void TImporta_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 TImporta_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 << "SELECT * FROM tieCorrispettivi WHERE Origine=1"; - str << "\nORDER BY DataCorr,CodCorrispettivo"; - - TODBC_recordset corr(str); - corr.connect(_dsn, _usr, _psw); - 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 << "SELECT * FROM tieDCorrispettivi WHERE (Origine=1)"; - str << "AND(CodCorrispettivo='" << corr.get("CodCorrispettivo") << "')"; - TODBC_recordset dett(str); - dett.connect(_dsn, _usr, _psw); - - 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); - TODBC_recordset sco(str); - sco.connect(_dsn, _usr, _psw); - str = "DELETE FROM tieCorrispettivi WHERE Origine=1"; - sco.exec(str); - - str = "DELETE FROM tieDCorrispettivi WHERE Origine=1"; - sco.exec(str); - } -} - -void TImporta_sync::sync_doc(const TDate& dal, const TDate& al , int tipotestata, const char* unitadefault, bool importadoc) -{ - const TString8 codcausdef = ini_get_string(CONFIG_DITTA, "bs", MOVMAG_CODCAUS, "", 2); - TString str(255); - str << "SELECT tieDMovMag.*,tieTBolFat.* FROM tieDMovMag,tieTBolFat WHERE tieDMovMag.Origine=1 AND tieDMovMag.TipoTestata=" <=" << date2sql(dal); - else - str << "<=" << date2sql(al); - } - } - str << "\nORDER BY CodTestata,NumRiga"; - - TODBC_recordset docs(str); - docs.connect(_dsn, _usr, _psw); - TProgress_monitor pi(docs.items(), str); - - long num_doc = -1, nd, codcf; - TString test_doc = "", test_nd; - TString4 tipocf; - TDocumento* doc = nullptr; - int contatore = 0; - int eccezioni_errori = 0; - TString codpk = ""; - for (bool ok = docs.move_first(); ok; ok = docs.move_next()) - { - TString CodTesta = docs.get("CodTestata").as_string(); - TToken_string test(docs.get("CodTestata").as_string(), '\\'); - - test_nd = (docs.get("CodTestata").as_string()); - - nd = atol(test.get()); - TString wrk = docs.get("CodCliente").as_string(); - - while (wrk[0] >= 'A') - wrk.ltrim(1); - - codcf = atol(wrk); - tipocf = docs.get("TipoIntestatario").as_string(); - - if (tipocf != "C") // verificare - tipocf = "F"; - - if ((tipocf != "C" && tipocf != "F") || codcf == 0) - { - TString msg; msg.format("Attenzione! Per il doc n.%d e' presente il tipo C/F = '%s' con cod = %d \nIl documento verra' saltato.", nd, (const char*)tipocf, codcf); - _log->log(1, msg); - continue; - } - - TToken_string key = tipocf; - key.add(codcf); - const TRectype & clifor = cache().get(LF_CLIFO, key); - - if (clifor.empty()) - { - // eccezione su cliente inesistente in DSErrore errore=1 - } - - if (test_nd != test_doc) - // if (nd != num_doc) - { - if (num_doc > 0 && !save_and_delete_doc(doc)) - break; - /* - if (test_doc != "") - if (test_doc != test_nd) - save_and_delete_doc(doc); - */ - num_doc = nd; - test_doc = test_nd; - - TString tre = test_doc.right(3); - const TDate datadoc = docs.get("DataMov").as_date(); - TString cod_pk = docs.get("Cod_PK").as_string(); - TString8 numdoc = docs.get("NumDoc").as_string(); - TString8 tipodoc = docs.get("TipoDocCE").as_string(); - TString origine_dc = docs.get("Origine").as_string(); - - if (((tipodoc.not_empty()) && (tipodoc != " ")) ) - //&& ((docs.get("CodIva").as_string().not_empty() && (docs.get("CodIva").as_string() != " ")))) + codtestata = docs.get_string("CodTestata"); + ndoc = codtestata.get_long(BS_POSNUMDOC); + while (wrk[0] >= 'A') + wrk.ltrim(1); + codcf = atol(wrk); + tipocf = docs.get("TipoIntestatario").as_string(); + if (ndoc != last) { + elab = (!nuovo && (_tipo_imp != imp_aggiungi)) || + (nuovo && (_tipo_imp != imp_aggiorna)); + if (elab && last > 0 && row > 0) + transactions.add(t); + last = ndoc; + row = 0; + + TString str = docs.get_string("NumDoc"); + long numdoc = ndoc; + // TString origine_dc = docs.get_string("Origine"); TTipo_documento tipo(tipodoc); - const TString8 codcaus = tipo.caus_mov().blank() ? codcausdef : tipo.caus_mov(); + const TString8 codcaus = tipo.caus_mov(); + const TDate datadoc = docs.get_date("DataDoc"); + TToken_string key("D"); - //doc = new TDocumento('D', datadoc.year(), numdoc, nd); //meglio usare TDocumento(char provv, int anno, const char* codnum, long numdoc); - doc = new TDocumento('D', datadoc.year(), tipodoc, strtol(numdoc, nullptr, 0)); - doc->destroy_rows(); - doc->put(DOC_DATADOC, datadoc); - doc->put(DOC_TIPODOC, tipodoc); - doc->put(DOC_TIPOCF, tipocf); - doc->put(DOC_CODCF, codcf); - doc->cli2doc(); + while (str[0] > 'A') + str.ltrim(1); + if (str.full()) + numdoc = atol(str); - const TString8 codval = docs.get("CodValuta").as_string(); - const real cambio = docs.get("CambioValuta").as_real(); - const TString asp = docs.get("AspettoBeni").as_string(); - const int ncolli = docs.get("NumeroColli").as_int(); - // inserire codice pagamento Es. BB02 - doc->put(DOC_CODVAL, codval); - doc->put(DOC_CAMBIO, cambio); + const TString16 numerazione = get_num(docs.get_string("SuffNum"), tipotestata); - doc->put(DOC_CODPAG, docs.get("CodPagamento_FP").as_string() ); - doc->put(DOC_CODABIA, docs.get("ABI").as_string()); //banca di appoggio - doc->put(DOC_CODCABA, docs.get("CAB").as_string()); + t.new_transaction(TFilename().temp("doc")); + key.add(datadoc.year()); + key.add(numerazione); + key.add(numdoc); + nuovo = cache().get(LF_DOC, key).empty(); + t.set_action(nuovo ? TRANSACTION_INSERT : TRANSACTION_MODIFY); + t.set_mode(transaction_mode_automatic); + t.set_stop_on_error(true); + t.set_caller("BEESTORE"); + t.set_firm(get_firm()); - TToken_string bnpkey = decode_presentazione(docs.get("NostroContoCorr").as_string()); + t.set(DOC_PROVV, "D", -1, LF_DOC); + t.set(DOC_ANNO, datadoc.year(), -1, LF_DOC); + t.set(DOC_CODNUM, numerazione, -1, LF_DOC); + t.set(DOC_NDOC, numdoc, -1, LF_DOC); + t.set(DOC_DATADOC, datadoc, -1, LF_DOC); + t.set(DOC_TIPODOC, tipodoc, -1, LF_DOC); - doc->put(DOC_CODABIP, bnpkey.get() ); //banca di presentazione - doc->put(DOC_CODCABP, bnpkey.get() ); - doc->put(DOC_PROGBNP, bnpkey.get() ); //banca di presentazione + if (tipotestata != 14) + { + t.set(DOC_TIPOCF, tipocf, -1, LF_DOC); + t.set(DOC_CODCF, codcf, -1, LF_DOC); + const TString8 codval = docs.get_string("CodValuta"); + const real cambio = docs.get_real("CambioValuta"); + const TString asp = docs.get_string("AspettoBeni"); + const int ncolli = docs.get_int("NumeroColli"); - doc->put(DOC_ASPBENI1, asp.sleft(50)); - doc->put(DOC_ASPBENI2, asp.smid(50)); - doc->put(DOC_NCOLLI, ncolli); - doc->put(DOC_CAUSMAG, codcaus); + t.set(DOC_CODVAL, codval, -1, LF_DOC); + t.set(DOC_CAMBIO, cambio, -1, LF_DOC); + t.set(DOC_CODPAG, docs.get_string("CodPagamento_FP"), -1, LF_DOC); + t.set(DOC_CODABIA, docs.get_string("ABI"), -1, LF_DOC); //banca di appoggio + t.set(DOC_CODCABA, docs.get_string("CAB"), -1, LF_DOC); + + TToken_string bnpkey = decode_presentazione(docs.get_string("NostroContoCorr")); + + t.set(DOC_CODABIP, bnpkey.get(), -1, LF_DOC); //banca di presentazione + t.set(DOC_CODCABP, bnpkey.get(), -1, LF_DOC); + t.set(DOC_PROGBNP, bnpkey.get(), -1, LF_DOC); //banca di presentazione + t.set(DOC_ASPBENI1, asp.sleft(50), -1, LF_DOC); + t.set(DOC_ASPBENI2, asp.smid(50), -1, LF_DOC); + t.set(DOC_NCOLLI, ncolli, -1, LF_DOC); + t.set(DOC_CAUSMAG, codcaus, -1, LF_DOC); + } contatore++; } - else - { - eccezioni_errori++; - codpk = cod_pk; - TString dserrore = docs.get("DSErrore").as_string(); - dserrore.sleft(50); - dserrore << " TipoDocCe assente o invalido"; - TString update_str = ""; - update_str << "UPDATE tieTBolFat \n SET Errore = 1 , DSErrore = '" << dserrore << "' \n WHERE cod_pk= '" << codpk << "' "; - TODBC_recordset docs(update_str); - docs.connect(_dsn, _usr, _psw); - docs.exec(update_str); - } - } - TString8 tipodoc = docs.get("TipoDocCE").as_string(); - if ( ( (tipodoc.not_empty() ) && (tipodoc != " ") ) ) - //&& ( (docs.get("CodIva").as_string().not_empty() && (docs.get("CodIva").as_string() != " ") ) ) ) - { - const int tipoart = docs.get("TipoArticolo").as_int(); - TRectype& rdoc = doc->new_row("01"); - TString80 codart = docs.get("IDArticolo").as_string(); - if (codart.blank()) - codart = docs.get("CodArticolo").as_string(); - - rdoc.put(RDOC_CODART, codart); - TString descrizione = docs.get("Modello").as_string(); + const int tipoart = docs.get_int("TipoArticolo"); + TString80 codart = docs.get_string("IDArticolo"); + TString descrizione = docs.get_string("Modello"); if (descrizione.blank()) - descrizione = docs.get("DSRiga").as_string(); - if (importadoc && tipoart == 0) - { - rdoc.put(RDOC_CODARTMAG, codart); - rdoc.put(RDOC_CHECKED, "X"); - if (cache().get(LF_ANAMAG, codart).empty()) - { - TArticolo articolo; - articolo.put(ANAMAG_CODART, codart); - - articolo.put(ANAMAG_DESCR, descrizione); - TString nomenclatura = docs.get("CodDogana").as_string(); - if (nomenclatura.blank()) - nomenclatura = docs.get("CodCategoria").as_string(); + descrizione = docs.get_string("DSRiga"); - articolo.put(ANAMAG_CLASSDOG, nomenclatura); - TRectype& umart = articolo.new_row(LF_UMART); - TString unitamisura = docs.get("CodUntMis").as_string(); - if (unitamisura.blank()) + if (codart.blank()) + codart = docs.get_string("CodArticolo"); + if (codart == BS_FREEROW) + codart = ""; + t.set(RDOC_TIPORIGA, "01", -1, LF_RIGHEDOC, ++row); + if (codart.full()) + { + t.set(RDOC_CODART, codart, -1, LF_RIGHEDOC, row); + + t.set(RDOC_CHECKED, "X", -1, LF_RIGHEDOC, row); + if (tipoart == 1) //spese servizi + { + if (cache().get("SPP", codart).full()) { - unitamisura = unitadefault; + t.set(RDOC_TIPORIGA, "03", -1, LF_RIGHEDOC, ++row); + t.set(RDOC_CODARTMAG, codart, -1, LF_RIGHEDOC, row); } - umart.put(UMART_UM, unitamisura); - umart.put(UMART_FC, 1); - articolo.write(); + } + else + { + if (cache().get(LF_ANAMAG, codart).full()) + t.set(RDOC_CODARTMAG, codart, -1, LF_RIGHEDOC, row); + else + if (importadoc && tipoart == 0) + { + t.set(RDOC_CODARTMAG, codart, -1, LF_RIGHEDOC, row); + + if (!art_inserted.is_key(codart) && cache().get(LF_ANAMAG, codart).empty()) + { + TTransaction tart(TFilename().temp("art")); + + art_inserted.add(codart, codart); + tart.set_action(TRANSACTION_INSERT); + tart.set_mode(transaction_mode_automatic); + tart.set_stop_on_error(false); + tart.set_caller("BEESTORE"); + tart.set_firm(get_firm()); + tart.set(ANAMAG_CODART, codart, -1, LF_ANAMAG); + tart.set(ANAMAG_DESCR, descrizione, -1, LF_ANAMAG); + + TString nomenclatura = docs.get_string("CodDogana"); + + if (nomenclatura.blank()) + nomenclatura = docs.get_string("CodCategoria"); + nomenclatura.strip("."); + if (nomenclatura.len() <= 8) + { + nomenclatura.lpad(8, '0'); + add_nomenclatura(nomenclatura); + tart.set(ANAMAG_CLASSDOG, nomenclatura, -1, LF_ANAMAG); + } + else + _log->log(2, format(FR("Codice nomenclatura combinata %s errato, non e' stato importato"), (const char *) nomenclatura)); + + TString unitamisura = docs.get_string("CodUntMis"); + + if (unitamisura.blank()) + unitamisura = unitadefault; + tart.set(UMART_UM, unitamisura, -1, LF_UMART, 1); + tart.set(UMART_FC, 1, -1, LF_UMART, 1); + art_transactions.add(tart); + } + } } } - if (tipoart == 2) //righe libere - { - if (cache().get("SPP", codart).not_empty()) - rdoc.put(RDOC_CODARTMAG, codart); - } - else //spese servizi e articoli - { - if (cache().get(LF_ANAMAG, codart).not_empty()) - rdoc.put(RDOC_CODARTMAG, codart); - } - - rdoc.put(RDOC_CODARTMAG, codart); - //rdoc.check_row(); - - rdoc.put(RDOC_DESCR, descrizione.sleft(50)); + t.set(RDOC_DESCR, descrizione.sleft(50), -1, LF_RIGHEDOC, row); if (descrizione.len() > 50) { - rdoc.put(RDOC_DESCLUNGA, "X"); - rdoc.put(RDOC_DESCEST, descrizione.smid(50)); + t.set(RDOC_DESCLUNGA, "X", -1, LF_RIGHEDOC, row); + t.set(RDOC_DESCEST, descrizione.smid(50), -1, LF_RIGHEDOC, row); } - rdoc.put(RDOC_CODMAG, docs.get("CodMagazzino").as_string().left(5)); - rdoc.put(RDOC_CODMAGC, docs.get("CodMagazDest").as_string().left(5)); - TString unitamisura = docs.get("CodUntMis").as_string(); + t.set(RDOC_CODMAG, docs.get_string("CodMagazzino").left(5), -1, LF_RIGHEDOC, row); + t.set(RDOC_CODMAGC, docs.get_string("CodMagazDest").left(5), -1, LF_RIGHEDOC, row); + + TString unitamisura = docs.get_string("CodUntMis"); + if (unitamisura.blank()) - { unitamisura = unitadefault; - } - rdoc.put(RDOC_UMQTA, docs.get("CodUntMis").as_string()); - rdoc.put(RDOC_QTA, docs.get("Quantita").as_real()); - rdoc.put(RDOC_PREZZO, docs.get("PrzNettoNeg").as_real()); // o PrzNettoValuta ?? - - /* - real valsconto1(docs.get("Sconto1").as_real()); - real valsconto2(docs.get("Sconto2").as_real()); - real valsconto3(docs.get("Sconto3").as_real()); - TString80 sconto; - - if (valsconto1 != ZERO) - sconto << valsconto1.stringa(6, 2); - if (valsconto2 != ZERO) - { - if (sconto.full()) - sconto << "+"; - sconto << valsconto2.stringa(6, 2); - } - if (valsconto3 != ZERO) - { - if (sconto.full()) - sconto << "+"; - sconto << valsconto3.stringa(6, 2); - } - rdoc.put(RDOC_SCONTO, sconto); - */ - rdoc.put(RDOC_CODIVA, docs.get("CodIva").as_string()); - + t.set(RDOC_UMQTA, docs.get_string("CodUntMis"), -1, LF_RIGHEDOC, row); + t.set(RDOC_QTA, docs.get_real("Quantita"), -1, LF_RIGHEDOC, row); + t.set(RDOC_PREZZO, docs.get_real("PrzNettoNeg"), -1, LF_RIGHEDOC, row); // o PrzNettoValuta ?? + t.set(RDOC_CODIVA, docs.get_string("CodIva"), -1, LF_RIGHEDOC, row); } else { + eccezioni_errori++; + codpk = cod_pk; TString dserrore = docs.get("DSErrore").as_string(); dserrore.sleft(50); dserrore << " TipoDocCe assente o invalido"; TString update_str = ""; - update_str << "UPDATE tieDMovMag \n SET Errore = 1 , DSErrore = '" << dserrore << "' \n WHERE CodTestata= '" << codpk << "' "; + update_str << "UPDATE tieTBolFat \n SET Errore = 1 , DSErrore = '" << dserrore << "' \n WHERE cod_pk= '" << codpk << "' "; TODBC_recordset docs(update_str); docs.connect(_dsn, _usr, _psw); docs.exec(update_str); } - if (!pi.add_status()) - break; - - } - save_and_delete_doc(doc); // Salva ultimo documento in sospeso - str.cut(0); - str.format(TR("Documenti importati %ld record in %s"), contatore, "tieTBolFat"); - _log->log(0, ""); - _log->log(0, str); - if (eccezioni_errori > 0) - { - str.cut(0); - str.format(TR("Errori in importazione %ld record in %s"), eccezioni_errori, "tieTBolFat"); - _log->log(0, str); - } + } + elab = (!nuovo && (_tipo_imp != imp_aggiungi)) || + (nuovo && (_tipo_imp != imp_aggiorna)); + + if (elab && last > 0 && row > 0) + transactions.add(t); + execute_transactions(art_transactions, *_log, _interactive, "Importazione articoli"); + execute_transactions(transactions, *_log, _interactive, "Importazione documenti"); } -TToken_string & TImporta_sync::decode_presentazione(const char*IBAN) +void TImporta_Beestore::import_doc(const TDate& dal, const TDate& al, int tipotestata, const char* unitadefault, bool importadoc) +{ + TString str(255); + if (tipotestata < 10) + { + str << "SELECT tieDMovMag.*,tieTBolFat.* FROM tieDMovMag,tieTBolFat WHERE tieDMovMag.Origine=1 AND tieDMovMag.TipoTestata=2 AND TieTBolFat.TipoDoc=" << tipotestata << " AND tieDMovMag.CodTestata=tieTBolFat.Cod_PK"; + if (dal.ok() || al.ok()) + { + str << " AND tieTBolFat.DataDoc"; + if (dal.ok() && al.ok()) + str << " BETWEEN " << date2sql(dal, 1) << " AND " << date2sql(al, 2); + else + { + if (dal.ok()) + str << ">=" << date2sql(dal, 1); + else + str << "<=" << date2sql(al, 2); + } + } + str << "\nORDER BY CodTestata,NumRiga"; + } + else + { + if (tipotestata == 14) + str << "SELECT *, NumMov AS NumDoc, DataMov AS DataDoc, \"\" AS SuffNum FROM tieDMovMag"; + else + str << "SELECT tieDMovMag.*,tieTBolFat.* FROM tieDMovMag,tieTBolFat"; + str << "WHERE Origine=1 AND TipoTestata=" << tipotestata - 10; + if (dal.ok() || al.ok()) + { + str << " AND DataMov"; + if (dal.ok() && al.ok()) + str << " BETWEEN " << date2sql(dal, 1) << " AND " << date2sql(al, 2); + else + { + if (dal.ok()) + str << ">=" << date2sql(dal, 1); + else + str << "<=" << date2sql(al, 2); + } + } + str << "\nORDER BY NumMov,NumRiga"; + } + + TODBC_recordset docs(str); + + docs.connect(_dsn, _usr, _psw); + switch (tipotestata) + { + case 1: + str = TR("Bolle"); + break; + case 2: + str = TR("Fatture"); + break; + case 6: + str = TR("Note di credito"); + break; + case 9: + str = TR("Ordini"); + break; + case 11: + str = TR("Carichi e scarichi"); + break; + case 13: + str = TR("Scontrini"); + break; + case 14: + str = TR("Generici"); + break; + default: + str = TR("Documenti"); + break; + }; + if (_direct_write) + direct_doc(docs, str, tipotestata, unitadefault, importadoc); + else + transaction_doc(docs, str, tipotestata, unitadefault, importadoc); +} + +TToken_string & TImporta_Beestore::decode_presentazione(const char*IBAN) { TToken_string & key = get_tmp_string(20); if (IBAN && *IBAN) @@ -1571,12 +1881,16 @@ TToken_string & TImporta_sync::decode_presentazione(const char*IBAN) return key; } -bool TImporta_sync::create() +bool TImporta_Beestore::create() { - _dsn = ini_get_string(CONFIG_DITTA, "bs", "DSN", "BEESTORE"); - _sqlog = ini_get_string(CONFIG_DITTA, "bs", "Log", ""); - _usr = ini_get_string(CONFIG_DITTA, "bs", "USR", "BEESTORE"); - _psw = decode(ini_get_string(CONFIG_DITTA, "bs", "PSW", "BEESTORE")); + open_files(LF_RCAUSALI, LF_CAUSALI, LF_CFVEN, LF_CLIFO, LF_MOVMAG, LF_RMOVMAG, LF_DOC, LF_ANAMAG, LF_UMART, LF_RIGHEDOC, 0); + _dsn = ini_get_string(CONFIG_DITTA, "BS", "DSN", "BEESTORE"); + _sqlog = ini_get_string(CONFIG_DITTA, "BS", "Log", ""); + _usr = ini_get_string(CONFIG_DITTA, "BS", "USR", "BEESTORE"); + _psw = decode(ini_get_string(CONFIG_DITTA, "BS", "PSW", "BEESTORE")); + _direct_write = false; + _interactive = ini_get_bool(CONFIG_DITTA, "BS", "Interactive"); + _direct_write = ini_get_bool(CONFIG_DITTA, "BS", "DirectWrite"); _banche_pres_loaded = false; if (_dsn.full()) @@ -1584,6 +1898,7 @@ bool TImporta_sync::create() TProgress_monitor ti(1, TR("Connessione a SQL Server"), false); TString query; query << "SELECT * FROM tieValute;";//"ODBC(" << _dsn << ")\nSELECT * FROM tieValute;"; TODBC_recordset recset(query); + recset.connect(_dsn, _usr, _psw); // Dovrebbe connettersi anche con solo _dsn valorizzato recset.move_first(); if (_sqlog.full() && _sqlog.is_relative_path()) @@ -1596,66 +1911,73 @@ bool TImporta_sync::create() return TSkeleton_application::create(); } return error_box(FR("Impossibile connettersi al DSN '%s'"), (const char*)_dsn); - } -void TImporta_sync::main_loop() +void TImporta_Beestore::main_loop() { - TImporta_mask mask; + TImporta_Beestore_mask mask; + TSheet_field & s = mask.sfield(F_CODNUM); + + if (s.items() == 0) + s.row(); + s.disable_cell(0, F_SUFFISSO); while (mask.run() == K_ENTER) { + int rows = s.items(); + mask.autosave(); // Rende definitivi tutti i paramentri in [bs] + _nums.destroy(); + for (int i = 0; i < rows; i++) + { + TToken_string codnums; + TString16 key = s.get_str_row_cell(i, F_SUFFISSO); + + key.trim(); + for (short id = F_COD_FATTURE; id <= F_COD_ORDCLI; id++) + codnums.add(s.get_str_row_cell(i, id)); + _nums.add(key, codnums); + } _log = new TLog_report; - const TDate dal = mask.get_date("SyncDateFrom"); - const TDate al = mask.get_date("SyncDateTo"); - const bool importa_artdoc = mask.get_bool("SyncIMPPARTDOC"); - - if (mask.get_bool("SyncUMS")) - sync_ums(dal, al); - if (mask.get_bool("SyncIVA")) - sync_iva(dal, al); - if (mask.get_bool("SyncLinee")) - sync_lines(dal, al); - if (mask.get_bool("SyncCatMer")) - sync_catmer(dal, al); - if (mask.get_bool("SyncAnamag")) - sync_anamag(dal, al); - if (mask.get_bool("SyncBarCode")) - sync_barcode(dal, al); - if (mask.get_bool("SyncVAL")) - sync_val(dal, al); + const TDate dal = mask.get_date("ImpDateFrom"); + const TDate al = mask.get_date("ImpDateTo"); + const bool importa_artdoc = mask.get_bool("ImpIMPPARTDOC"); + + _tipo_imp = (tipo_importazione) atoi(mask.get("ImpTYPE")); + if (mask.get_bool("ImpUMS")) + import_ums(); + if (mask.get_bool("ImpIVA")) + import_iva(); + if (mask.get_bool("ImpLinee")) + import_lines(); + if (mask.get_bool("ImpCatMer")) + import_catmer(); + if (mask.get_bool("ImpAnamag")) + import_anamag(); + if (mask.get_bool("ImpVAL")) + import_val(); int cfmask = 0; - if (mask.get_bool("SyncClienti")) cfmask |= 1; - if (mask.get_bool("SyncFornitori")) cfmask |= 2; + if (mask.get_bool("ImpClienti")) cfmask |= 1; + if (mask.get_bool("ImpFornitori")) cfmask |= 2; if (cfmask) - sync_clifo(cfmask, dal, al); + import_clifo(cfmask, dal, al); + if (mask.get_bool("ImpDoc")) + { + const int tipotestata = mask.get_int(F_TIPODOC); - if (mask.get("SyncListino").full()) - sync_listino(mask.get("SyncListino")); - if (mask.get_bool("SyncScontr")) - sync_scontrini(dal, al); - if (mask.get_bool("SyncCorr")) - sync_corrisp(dal, al); - if (mask.get_bool("SyncDoc")) - sync_doc(dal, al, mask.get_int(F_TIPODOC), mask.get(F_UNITADEFAULT), importa_artdoc); - - if (mask.get_bool("SyncCarScar")) - sync_carscar(dal, al); - if (mask.get_bool("SyncGenerici")) - sync_generici(dal, al); + import_doc(dal, al, tipotestata, mask.get(F_UNITADEFAULT), importa_artdoc); + } _log->preview(); - delete _log; - _log = NULL; + safe_delete(_log); } } int bs0500(int argc, char* argv[]) { - TImporta_sync impf; + TImporta_Beestore impf; impf.run(argc, argv, TR("Import F/B/S")); return 0; -} +} \ No newline at end of file diff --git a/src/bs/bs0500a.h b/src/bs/bs0500a.h index e12f146e3..d9a879470 100644 --- a/src/bs/bs0500a.h +++ b/src/bs/bs0500a.h @@ -1,38 +1,43 @@ -#define F_DAL 101 -#define F_AL 102 +#define F_DAL 201 +#define F_AL 202 -#define F_UMS 103 -#define F_IVA 104 -#define F_LINEART 105 -#define F_CATMER 106 -#define F_ART 107 -#define F_LIST 108 -#define F_SCONTRINI 109 -#define F_CORRISPETTIVI 110 -#define F_DOCUMENTI 111 -#define F_CARSCAR 112 -#define F_GENERICI 113 -#define F_VALUTE 114 -#define F_CLIENTI 115 -#define F_FORNITORI 116 -#define F_BARCODE 117 +#define F_UMS 203 +#define F_IVA 204 +#define F_LINEART 205 +#define F_CATMER 206 +#define F_ART 207 +#define F_SCONTRINI 209 +#define F_CORRISPETTIVI 210 +#define F_DOCUMENTI 211 +#define F_CARSCAR 212 +#define F_GENERICI 213 +#define F_VALUTE 214 +#define F_CLIENTI 215 +#define F_FORNITORI 216 -#define F_FATTURE 121 -#define F_BOLLE 122 -#define F_ORDINI 123 -#define F_IMPPARTDOC 124 -#define F_CANCART 125 -#define F_TIPODOC 126 -#define F_UNITADEFAULT 127 +#define F_FATTURE 221 +#define F_BOLLE 222 +#define F_ORDINI 223 +#define F_IMPPARTDOC 224 +#define F_CANCART 225 +#define F_TIPODOC 226 +#define F_UNITADEFAULT 227 +#define F_IMPTYPE 228 -#define F_C_CARSCAR 201 -#define F_D_CARSCAR 202 -#define F_C_DOCUMENTI 203 -#define F_D_DOCUMENTI 204 -#define F_C_SCONTRINI 205 -#define F_D_SCONTRINI 206 -#define F_C_GENERICI 207 -#define F_D_GENERICI 208 +#define F_CODNUM 240 -#define F_C_CORRISPETTIVI 301 -#define F_D_CORRISPETTIVI 302 \ No newline at end of file +#define F_SUFFISSO 101 +#define F_COD_FATTURE 102 +#define F_DES_FATTURE 302 +#define F_COD_NOTE 103 +#define F_DES_NOTE 303 +#define F_COD_BOLLE 104 +#define F_DES_BOLLE 304 +#define F_COD_CARSCAR 105 +#define F_DES_CARSCAR 305 +#define F_COD_SCONTRINI 106 +#define F_DES_SCONTRINI 306 +#define F_COD_GENERICI 107 +#define F_DES_GENERICI 307 +#define F_COD_ORDCLI 108 +#define F_DES_ORDCLI 308 diff --git a/src/bs/bs0500a.uml b/src/bs/bs0500a.uml index 8af81d5ad..1bb551296 100644 --- a/src/bs/bs0500a.uml +++ b/src/bs/bs0500a.uml @@ -6,7 +6,7 @@ ENDPAGE PAGE "Importazioni da BeeStore" 0 2 0 0 -GROUPBOX DLG_NULL 78 9 +GROUPBOX DLG_NULL 78 6 BEGIN PROMPT 1 1 "@bArchivi" END @@ -14,279 +14,286 @@ END BOOLEAN F_UMS BEGIN PROMPT 2 2 "Unità di misura " - FIELD SyncUMS + FIELD ImpUMS END BOOLEAN F_IVA BEGIN PROMPT 2 3 "Codici IVA " - FIELD SyncIVA + FIELD ImpIVA END BOOLEAN F_LINEART BEGIN PROMPT 2 4 "Linee Articolo " - FIELD SyncLinee -END - -BOOLEAN F_CATMER -BEGIN - PROMPT 2 5 "Categorie Merceologiche" - FIELD SyncCatMer -END - -BOOLEAN F_ART -BEGIN - PROMPT 2 6 "Articoli " - FIELD SyncAnamag -END - -STRING F_LIST 3 -BEGIN - PROMPT 40 6 "Listino " - USE LF_CONDV - INPUT TIPO "L" - INPUT CATVEN "" - INPUT TIPOCF "" - INPUT CODCF "" - INPUT COD 148 - DISPLAY "Codice" COD - DISPLAY "Descrizione@50" DESCR - DISPLAY "Valuta@5" CODVAL - DISPLAY "Inizio@10" VALIN - DISPLAY "Fine@10" VALFIN - OUTPUT 148 COD - FIELD SyncListino -END - -BOOLEAN F_SCONTRINI -BEGIN - PROMPT 2 7 "Scontrini " - FIELD SyncScontr -END - -BOOLEAN F_CORRISPETTIVI -BEGIN - PROMPT 2 8 "Corrispettivi " - FIELD SyncCorr -END - -BOOLEAN F_CARSCAR -BEGIN - PROMPT 40 7 "Carichi/scarichi " - FIELD SyncCarScar -END - -BOOLEAN F_GENERICI -BEGIN - PROMPT 40 8 "Mov.generici " - FIELD SyncGenerici -END - -BOOLEAN F_VALUTE -BEGIN - PROMPT 40 2 "Valute" - FIELD SyncVAL -END - -BOOLEAN F_CLIENTI -BEGIN - PROMPT 40 3 "Clienti" - FIELD SyncClienti -END - -BOOLEAN F_FORNITORI -BEGIN - PROMPT 40 4 "Fornitori " - FIELD SyncFornitori -END - -BOOLEAN F_BARCODE -BEGIN - PROMPT 40 5 "Codici a barre" - FIELD SyncBarCode -END - -GROUPBOX DLG_NULL 78 4 -BEGIN - PROMPT 1 10 "@bDocumenti" + FIELD ImpLinee END BOOLEAN F_DOCUMENTI BEGIN - PROMPT 2 11 "Documenti " - FIELD SyncDoc + PROMPT 2 5 "Documenti " + FIELD ImpDoc MESSAGE FALSE CLEAR,F_TIPODOC MESSAGE TRUE ENABLE,F_TIPODOC END -LISTBOX F_TIPODOC 1 15 +LISTBOX F_TIPODOC 2 20 + BEGIN - PROMPT 2 12 "Tipo Documento" + PROMPT 20 5 "Tipo Documento" ITEM "2|Fatture" ITEM "6|Note di credito" ITEM "1|Bolle" ITEM "9|Ordini" - FIELD SyncTIPODOC + ITEM "11|Carichi e scarichi" + ITEM "13|Scontrini" + ITEM "14|Generici" + FIELD ImpTIPODOC END -GROUPBOX DLG_NULL 78 3 +BOOLEAN F_CATMER BEGIN - PROMPT 1 14 "@bFiltri" + PROMPT 30 2 "Categorie Merceologiche" + FIELD ImpCatMer +END + +BOOLEAN F_ART +BEGIN + PROMPT 30 3 "Articoli " + FIELD ImpAnamag +END + +BOOLEAN F_VALUTE +BEGIN + PROMPT 30 4 "Valute" + FIELD ImpVAL +END + +BOOLEAN F_CLIENTI +BEGIN + PROMPT 60 2 "Clienti" + FIELD ImpClienti +END + +BOOLEAN F_FORNITORI +BEGIN + PROMPT 60 3 "Fornitori " + FIELD ImpFornitori END DATE F_DAL BEGIN - PROMPT 2 15 "Dalla data di modifica " - FIELD SyncDateFrom + PROMPT 2 7 "Dalla data di modifica " + FIELD ImpDateFrom END DATE F_AL BEGIN - PROMPT 42 15 " al " - FIELD SyncDateTo -END - -ENDPAGE - -PAGE "Parametri" 0 2 0 0 - -GROUPBOX DLG_NULL 78 4 -BEGIN - PROMPT 1 1 "@bParametri" + PROMPT 42 7 " al " + FIELD ImpDateTo END BOOLEAN F_IMPPARTDOC BEGIN - PROMPT 2 2 "Importazione Articoli da Documenti" - FIELD SyncIMPPARTDOC + PROMPT 2 9 "Importazione Articoli da Documenti" + FIELD ImpIMPPARTDOC MESSAGE TRUE CLEAR,F_CANCART|CLEAR,F_ART MESSAGE FALSE ENABLE,F_CANCART|ENABLE,F_ART END -BOOLEAN F_UNITADEFAULT -BEGIN - PROMPT 2 3 "Unità di Misura (Default)" - FIELD SyncUNITADEFAULT -END - - BOOLEAN F_CANCART BEGIN - PROMPT 40 2 "Elimina Articoli Sospesi" - FIELD SyncCANCART + PROMPT 40 9 "Elimina Articoli Sospesi" + FIELD ImpCANCART END -GROUPBOX DLG_NULL 78 6 +BOOLEAN F_UNITADEFAULT BEGIN - PROMPT 1 5 "@bMovimenti" + PROMPT 2 10 "Unità di Misura (Default)" + FIELD ImpUNITADEFAULT END -STRING F_C_CARSCAR 4 +LIST F_IMPTYPE 1 20 BEGIN - PROMPT 2 6 "Causale magazzino car./scar. " - USE %CAU SELECT (S2[8,8]=1)&&(S6="P") - INPUT CODTAB F_C_CARSCAR - DISPLAY "Codice" CODTAB - DISPLAY "Descrizione@50" S0 - OUTPUT F_C_CARSCAR CODTAB - OUTPUT F_D_CARSCAR S0 - CHECKTYPE NORMAL - FIELD CODCAUS(1) - ADD RUN mg0 -0 %CAU + PROMPT 40 10 "Importa " + FIELD ImpTYPE + ITEM "1|Elementi nuovi" + ITEM "2|Elementi esistenti" + ITEM "3|Tutto" END -STRING F_D_CARSCAR 50 36 +SPREADSHEET F_CODNUM 80 10 BEGIN - PROMPT 40 6 "" - FLAGS "D" -END - -STRING F_C_DOCUMENTI 4 -BEGIN - PROMPT 2 7 "Causale magazzino documenti " - USE %CAU SELECT (S2[8,8]=1)&&(S6="P") - INPUT CODTAB F_C_DOCUMENTI - DISPLAY "Codice" CODTAB - DISPLAY "Descrizione@50" S0 - OUTPUT F_C_DOCUMENTI CODTAB - OUTPUT F_D_DOCUMENTI S0 - CHECKTYPE NORMAL - FIELD CODCAUS(2) - ADD RUN mg0 -0 %CAU -END - -STRING F_D_DOCUMENTI 50 36 -BEGIN - PROMPT 40 7 "" - FLAGS "D" -END - -STRING F_C_SCONTRINI 4 -BEGIN - PROMPT 2 8 "Causale magazzino scontrini " - USE %CAU SELECT (S2[8,8]=1)&&(S6="P") - INPUT CODTAB F_C_SCONTRINI - DISPLAY "Codice" CODTAB - DISPLAY "Descrizione@50" S0 - OUTPUT F_C_SCONTRINI CODTAB - OUTPUT F_D_SCONTRINI S0 - CHECKTYPE NORMAL - FIELD CODCAUS(3) - ADD RUN mg0 -0 %CAU -END - -STRING F_D_SCONTRINI 50 36 -BEGIN - PROMPT 40 8 "" - FLAGS "D" -END - -STRING F_C_GENERICI 4 -BEGIN - PROMPT 2 9 "Causale magazzino mov.generici " - USE %CAU SELECT (S2[8,8]=1)&&(S6="P") - INPUT CODTAB F_C_GENERICI - DISPLAY "Codice" CODTAB - DISPLAY "Descrizione@50" S0 - OUTPUT F_C_GENERICI CODTAB - OUTPUT F_D_GENERICI S0 - CHECKTYPE NORMAL - FIELD CODCAUS(4) - ADD RUN mg0 -0 %CAU -END - -STRING F_D_GENERICI 50 36 -BEGIN - PROMPT 40 9 "" - FLAGS "D" -END - -GROUPBOX DLG_NULL 78 3 -BEGIN - PROMPT 1 11 "@bCorrispettivi" -END - -STRING F_C_CORRISPETTIVI 4 -BEGIN - PROMPT 2 12 "Causale contabile " - USE LF_CAUSALI SELECT TIPODOC="CR" - INPUT CODCAUS F_C_CORRISPETTIVI - DISPLAY "Codice" CODCAUS - DISPLAY "Descrizione@50" DESCR - OUTPUT F_C_CORRISPETTIVI CODCAUS - OUTPUT F_D_CORRISPETTIVI DESCR - CHECKTYPE NORMAL - FIELD CODCAUSC - ADD RUN cg0 -4 -END - -STRING F_D_CORRISPETTIVI 50 36 -BEGIN - PROMPT 40 12 "" - FLAGS "D" + PROMPT 2 13 "Numerazioni" + ITEM "Suffisso" + ITEM "Fatture" + ITEM "Note di\ncredito@6" + ITEM "Bolle@6" + ITEM "Carichi\nScarichi" + ITEM "Scontrini" + ITEM "Generici" + ITEM "Ordini\nClienti" END ENDPAGE +ENDMASK + +PAGE "Numerazioni" -1 -1 78 19 + +STRING F_SUFFISSO 5 +BEGIN + PROMPT 1 1 "Suffisso numer." +END + +STRING F_COD_FATTURE 4 +BEGIN + PROMPT 1 3 "Num.Fatture " + USE %NUM SELECT I1=="2" + INPUT CODTAB F_COD_FATTURE + DISPLAY "Codice" CODTAB + DISPLAY "Descrizione@50" S0 + OUTPUT F_COD_FATTURE CODTAB + OUTPUT F_DES_FATTURE S0 + FLAG "UPA" + CHECKTYPE NORMAL + WARNING "Numerazione assente" +END + +STRING F_DES_FATTURE 50 +BEGIN + PROMPT 25 3 "" + FLAGS "D" +END + +STRING F_COD_NOTE 4 +BEGIN + PROMPT 1 5 "Num.Note cred. " + COPY USE F_COD_FATTURE + INPUT CODTAB F_COD_NOTE + DISPLAY "Codice" CODTAB + DISPLAY "Descrizione@50" S0 + OUTPUT F_COD_NOTE CODTAB + OUTPUT F_DES_NOTE S0 + FLAG "UPA" + CHECKTYPE NORMAL + WARNING "Numerazione assente" +END + +STRING F_DES_NOTE 50 +BEGIN + PROMPT 25 5 "" + FLAGS "D" +END +STRING F_COD_BOLLE 4 +BEGIN + PROMPT 1 7 "Num.Bolle " + USE %NUM SELECT I1=="1" + INPUT CODTAB F_COD_BOLLE + COPY DISPLAY F_COD_FATTURE + OUTPUT F_COD_BOLLE CODTAB + OUTPUT F_DES_BOLLE S0 + FLAG "UPA" + WARNING "Numerazione assente" +END + +STRING F_DES_BOLLE 50 +BEGIN + PROMPT 25 7 "" + FLAGS "D" +END + +STRING F_COD_CARSCAR 4 +BEGIN + PROMPT 1 9 "Num.Car.Scar. " + USE %NUM SELECT I1=="0" + INPUT CODTAB F_COD_CARSCAR + COPY DISPLAY F_COD_FATTURE + OUTPUT F_COD_CARSCAR CODTAB + OUTPUT F_DES_CARSCAR S0 + FLAG "UPA" + CHECKTYPE NORMAL + WARNING "Numerazione assente" +END + +STRING F_DES_CARSCAR 50 +BEGIN + PROMPT 25 9 "" + FLAGS "D" +END + +STRING F_COD_SCONTRINI 4 +BEGIN + PROMPT 1 11 "Num.Scontrini " + COPY USE F_COD_CARSCAR + INPUT CODTAB F_COD_SCONTRINI + COPY DISPLAY F_COD_FATTURE + OUTPUT F_COD_SCONTRINI CODTAB + OUTPUT F_DES_SCONTRINI S0 + FLAG "UPA" + CHECKTYPE NORMAL + WARNING "Numerazione assente" +END + +STRING F_DES_SCONTRINI 50 +BEGIN + PROMPT 25 11 "" + FLAGS "D" +END + +STRING F_COD_GENERICI 4 +BEGIN + PROMPT 1 13 "Num.Scontrini " + COPY USE F_COD_CARSCAR + INPUT CODTAB F_COD_GENERICI + COPY DISPLAY F_COD_FATTURE + OUTPUT F_COD_GENERICI CODTAB + OUTPUT F_DES_GENERICI S0 + FLAG "UPA" + CHECKTYPE NORMAL + WARNING "Numerazione assente" +END + +STRING F_DES_GENERICI 50 +BEGIN + PROMPT 25 13 "" + FLAGS "D" +END + + +STRING F_COD_ORDCLI 4 +BEGIN + PROMPT 1 15 "Num.Ordini Cli." + USE %NUM SELECT I1=="3" + INPUT CODTAB F_COD_ORDCLI + COPY DISPLAY F_COD_FATTURE + OUTPUT F_COD_ORDCLI CODTAB + OUTPUT F_DES_ORDCLI S0 + FLAG "UPA" + CHECKTYPE NORMAL + WARNING "Numerazione assente" +END + +STRING F_DES_ORDCLI 50 +BEGIN + PROMPT 25 15 "" + FLAGS "D" +END + +BUTTON DLG_OK 10 2 +BEGIN + PROMPT -13 -1 "" +END + +BUTTON DLG_DELREC 10 2 +BEGIN + PROMPT -23 -1 "" +END + +BUTTON DLG_CANCEL 10 2 +BEGIN + PROMPT -33 -1 "" +END + +ENDPAGE ENDMASK \ No newline at end of file diff --git a/src/include/applicat.cpp b/src/include/applicat.cpp index f420d7fbc..ed120e92b 100755 --- a/src/include/applicat.cpp +++ b/src/include/applicat.cpp @@ -136,6 +136,8 @@ long TApplication::task_eh(WINDOW win, EVENT *ep) { // Setta il vero menu principale se diverso dal default const int meno = _application->argc() > 1 ? atoi(_application->argv(1)+1) : 0; + + xvt_vobj_hide(win); ignore_xvt_errors(TRUE); MENU_ITEM* menu = xvt_res_get_menu(MENU_BAR_ID(meno)); ignore_xvt_errors(FALSE); @@ -187,6 +189,10 @@ long TApplication::handler(WINDOW win, EVENT* ep) _create_ok = create(); if (_create_ok) { + if (task_win_shown()) + xvt_vobj_show(TASK_WIN); + if (task_win_iconized()) + xvt_vobj_minimize(TASK_WIN); on_firm_change(); on_config_change(); return 1; @@ -296,12 +302,11 @@ void TApplication::stop_run() { if (_savefirm) prefix().set_codditta(_savefirm); - terminate(); + terminate(); xvt_app_destroy(); } - bool TApplication::add_menu(TString_array& menu, MENU_TAG id) { TTemp_window tw(TASK_WIN); @@ -316,15 +321,13 @@ bool TApplication::remove_menu(MENU_TAG id) TApplication::TApplication() - : _god_vars(NULL),_savefirm(0), _running(FALSE), _create_ok(FALSE) + : _god_vars(nullptr),_savefirm(0), _running(false), _create_ok(false), _force(false) { } - TApplication::~TApplication() { - if (_god_vars != NULL) - delete _god_vars; + SAFE_DELETE(_god_vars); } bool TApplication::create() @@ -341,7 +344,8 @@ void TApplication::terminate() if (_create_ok) destroy(); // Distruzione files e maschere - do_events(); + if(!_force) + do_events(); if (use_files()) { @@ -371,7 +375,8 @@ const char* TApplication::get_module_name() const const TDongle& d = dongle(); const TString4 modname = _name.left(2); word aut = d.module_name2code(modname); - if (aut == 0xFFFF && modname == "ps") + + if (aut == 0xFFFF && modname == "ps") { aut = 0; module = TR("Personalizzazioni"); @@ -404,19 +409,12 @@ const char* TApplication::get_module_name() const } } } - if (!ok) - { - if(is_power_station()) - { - warning_box("Attenzione! Non sei abilitato per l'utilizzo del modulo %s", static_cast(module)); - } - else - { - cantaccess_box(module); - module.cut(0); - } - } - } + if (!ok && !is_power_station()) + { + cantaccess_box(module); + module.cut(0); + } + } } return module; } @@ -769,7 +767,7 @@ void TApplication::open_files(int logicnum, ...) va_start(marker, logicnum); while (logicnum >= LF_USER && logicnum < LF_EXTERNAL) { - if (_used_files.objptr(logicnum) == NULL) + if (_used_files.objptr(logicnum) == nullptr) _used_files.add(new TLocalisamfile(logicnum), logicnum); logicnum = va_arg(marker, int); } @@ -880,9 +878,8 @@ bool TApplication::get_next_mail(TToken_string& to, TToken_string& cc, TToken_st bool TSkeleton_application::create() { -// dispatch_e_menu(BAR_ITEM_ID(1)); -// return TApplication::create(); const bool ok = TApplication::create(); + if (ok) dispatch_e_menu(BAR_ITEM_ID(1)); return ok; } diff --git a/src/include/applicat.h b/src/include/applicat.h index f2a0695f2..8e46d4be1 100755 --- a/src/include/applicat.h +++ b/src/include/applicat.h @@ -1,4 +1,3 @@ -#pragma once #ifndef __APPLICATION_H #define __APPLICATION_H @@ -51,6 +50,9 @@ class TApplication // @cmember:(INTERNAL) Codice della ditta long _savefirm; + // @cmember:(INTERNAL) Chiusura forzata per programmi senza interfaccia + bool _force; + // @cmember:(INTERNAL) Indica se l'applicazione e' partita bool _running; @@ -59,7 +61,7 @@ class TApplication // @cmember:(INTERNAL) Termine dell'applicazione void terminate(); - + // @access Protected Member protected: // @cmember Ritorna il nome del modulo dell'applicazione @@ -101,7 +103,7 @@ protected: void open_files(int logicnum, ...); // @cmember Percorso documenti archiviati - bool get_spotlite_path(TFilename& path) const; + bool get_spotlite_path(TFilename& path) const; // @access Public Member public: @@ -135,6 +137,8 @@ public: // @cmember Forza la chiusura dell'applicazione void stop_run(); + void TApplication::force_stop() {_force = true;} + // @cmember Mette il segno Check a fianco di una voce di menu void check_menu_item(MENU_TAG item, bool on = true); @@ -188,6 +192,10 @@ public: bool add_menu(TString_array& menu, MENU_TAG id = 0); // @cmember Elimina il menu'

(Ritorna se ce l'ha fatta???) bool remove_menu(MENU_TAG id); + // @cmember imposta la visibità della finestra principale + virtual bool task_win_shown() const { return true; } + // @cmember imposta la riduzione a icona della finestra principale + virtual bool task_win_iconized() const { return false; } // @cmember Costruttore TApplication(); diff --git a/src/include/array.h b/src/include/array.h index 8a9deb63c..0e48db804 100755 --- a/src/include/array.h +++ b/src/include/array.h @@ -230,7 +230,7 @@ TArray& objptr2array(TObject* obj); class TToken_string; #endif -#define STRING_TOKEN(obj) (obj == nullptr ? EMPTY_STRING : *(TToken_string *) obj) +#define STRING_TOKEN(obj) ((TToken_string &)(obj == nullptr ? EMPTY_STRING : *(TToken_string *) obj)) // @doc EXTERNAL diff --git a/src/include/assoc.cpp b/src/include/assoc.cpp index 03c33a441..1c46ecace 100755 --- a/src/include/assoc.cpp +++ b/src/include/assoc.cpp @@ -1,19 +1,25 @@ #include #include +#include // @ccost:(INTERNAL) HASH_SIZE | 883 | Dimensione della tabella hash const int HASH_SIZE = 883; THash_object::~THash_object() { - if (_obj != NULL) - delete _obj; + safe_delete(_obj); } +// @doc EXTERNAL + +// @class TAssoc_array | Tabella hash di oggetti generici +// +// @base public |TObject + TArray& TAssoc_array::bucket(int index) { TArray* arr = (TArray*)_bucket.objptr(index); - if (arr == NULL) + if (arr == nullptr) { arr = new TArray; _bucket.add(arr, index); @@ -41,7 +47,7 @@ THash_object* TAssoc_array::_lookup( const TFixed_string key(k); const word hv = key.hash() % HASH_SIZE; TArray& arr = bucket(hv); - THash_object* o = NULL; + THash_object* o = nullptr; isnew = false; int i; @@ -54,7 +60,7 @@ THash_object* TAssoc_array::_lookup( break; } - if (o == NULL) + if (o == nullptr) { if (insert) { @@ -85,7 +91,7 @@ TObject* TAssoc_array::last_item() { _rowitem = _bucket.last(); if( _rowitem < 0 ) - return NULL; + return nullptr; _colitem = bucket(_rowitem).items() - 1; return pred_item( ); } @@ -105,9 +111,9 @@ TObject* TAssoc_array::succ_item() } } if (_rowitem >= HASH_SIZE) - return NULL; + return nullptr; THash_object* o = (THash_object*)arr->objptr(_colitem++); - return (o == NULL || o->_obj == NULL) ? NULL : o->_obj; + return (o == nullptr || o->_obj == nullptr) ? nullptr : o->_obj; } TObject* TAssoc_array::pred_item() @@ -125,28 +131,28 @@ TObject* TAssoc_array::pred_item() } } if (_rowitem < 0 ) - return NULL; + return nullptr; THash_object* o = (THash_object*)arr->objptr(_colitem--); - return (o == NULL || o->_obj == NULL) ? NULL : o->_obj; + return (o == nullptr || o->_obj == nullptr) ? nullptr : o->_obj; } THash_object* TAssoc_array::random_hash_object() { - THash_object* o = NULL; + THash_object* o = nullptr; if (items() > 0) { int bucket = rand() % _bucket.size(); - if (_bucket.objptr(bucket) == NULL) + if (_bucket.objptr(bucket) == nullptr) bucket = _bucket.succ(bucket); - if (_bucket.objptr(bucket) == NULL) + if (_bucket.objptr(bucket) == nullptr) bucket = _bucket.pred(bucket); const TArray* arr = (const TArray*)_bucket.objptr(bucket); - if (arr != NULL) + if (arr != nullptr) { const int item = rand() % arr->size(); o = (THash_object*)arr->objptr(item); - if (o != NULL) + if (o != nullptr) { _rowitem = bucket; _colitem = item; @@ -162,7 +168,7 @@ THash_object* TAssoc_array::random_hash_object() // @rdesc Ritorna TRUE se esisteva gia' un elemento con la stessa chiave bool TAssoc_array::add( const char* key, // @parm Chiave d'ordinamento - TObject* obj, // @parm Oggetto da inserire (default=NULL) + TObject* obj, // @parm Oggetto da inserire (default=nullptr) bool force) // @parm Permette di forzare l'inserimento se esiste gia' // un oggetto con la stessa chiave @@ -185,7 +191,7 @@ bool TAssoc_array::add( { if (force) { - if (o->_obj != NULL) + if (o->_obj != nullptr) delete o->_obj; o->_obj = obj; } @@ -197,6 +203,27 @@ bool TAssoc_array::add( return false; } +bool TAssoc_array::add(const char* key, // @parm Chiave d'ordinamento + const char * str, // @parm stringa da inserire + bool force) // @parm Permette di forzare l'inserimento se esiste gia' +{ + bool isnew = false; + THash_object* o = _lookup(key, isnew, true); + + if (!isnew) + { + if (force) + { + if (o->_obj != nullptr) + delete o->_obj; + o->_obj = new TString(str); + } + return true; + } + o->_obj = new TString(str); + return false; +} + bool TAssoc_array::add(const char* key, const TObject& obj, bool force) { /* @@ -216,7 +243,7 @@ bool TAssoc_array::add(const char* key, const TObject& obj, bool force) } if (force && o->_obj != &obj) // Tolla 2017: Aggiunto controllo sugli indirizzi, perchè c'è questo problema? { - if (o->_obj != NULL) + if (o->_obj != nullptr) delete o->_obj; o->_obj = obj.dup(); } @@ -239,7 +266,7 @@ bool TAssoc_array::remove( const TFixed_string key(k); const word hv = key.hash() % HASH_SIZE; TArray& arr = bucket(hv); - THash_object* o = NULL; + THash_object* o = nullptr; int i; for (i = 0; i < arr.items(); i++) @@ -250,7 +277,7 @@ bool TAssoc_array::remove( if (ob->_key > key) break; } - if (o != NULL) + if (o != nullptr) { arr.destroy(i,TRUE); _cnt--; @@ -280,13 +307,13 @@ TObject& TAssoc_array::find( // @doc EXTERNAL // @mfunc Ritorna l'oggetto con chiave

-// @rdesc Se l'oggetto esiste ne ritorna il puntatore, altrimenti ritorna NULL +// @rdesc Se l'oggetto esiste ne ritorna il puntatore, altrimenti ritorna nullptr TObject* TAssoc_array::objptr( const char* key) const // @parm Chiave dell'oggetto da ritornare { bool isnew = false; THash_object* o = ((TAssoc_array*)this)->_lookup(key,isnew); - return o ? o->_obj : NULL; + return o ? o->_obj : nullptr; } // @doc EXTERNAL @@ -302,14 +329,14 @@ bool TAssoc_array::is_key( { bool isnew = FALSE; THash_object* o = ((TAssoc_array *)this)->_lookup(key,isnew); - return o != NULL; + return o != nullptr; } // @doc EXTERNAL // @mfunc Ritorna solo l'oggetto // -// @rdesc Ritorna il puntatore all'oggetto (se diverso da NULL), altrimenti +// @rdesc Ritorna il puntatore all'oggetto (se diverso da nullptr), altrimenti // ritorna error object TObject* TAssoc_array::get() // @xref @@ -326,17 +353,17 @@ TObject* TAssoc_array::get() if (_row >= HASH_SIZE) { _row = 0; - return NULL; + return nullptr; } THash_object* o = (THash_object*)arr->objptr(_col++); - return (o == NULL || o->_obj == NULL) ? &error_object : o->_obj; + return (o == nullptr || o->_obj == nullptr) ? &error_object : o->_obj; } // @doc EXTERNAL // @mfunc Ritorna l'oggetto e la relativa chiave // -// @rdesc Se l'oggetto esiste ne ritorna il puntatore, altrimenti ritorna NULL +// @rdesc Se l'oggetto esiste ne ritorna il puntatore, altrimenti ritorna nullptr THash_object* TAssoc_array::get_hashobj() // @comm Se l'oggetto viene trovato viene richiamata la funzione @@ -356,7 +383,7 @@ THash_object* TAssoc_array::get_hashobj() if (_row >= HASH_SIZE) { _row = 0; - return NULL; + return nullptr; } return (THash_object*)arr->objptr(_col++); } @@ -368,11 +395,13 @@ int TAssoc_array::get_keys(TString_array& kl, bool add_values) { kl.destroy(); restart(); - THash_object* o = NULL; + THash_object* o = nullptr; TString tmp(80); + while ((o = get_hashobj())) { TToken_string* tt = new TToken_string(o->key()); + if (add_values) { tmp = ""; @@ -389,7 +418,7 @@ const TString& TAssoc_array::get_str(const char* key) const { bool isnew = false; THash_object* o = ((TAssoc_array *)this)->_lookup(key,isnew); - if (o != NULL && o->obj().is_kind_of(CLASS_STRING)) + if (o != nullptr && o->obj().is_kind_of(CLASS_STRING)) return (const TString&)o->obj(); return EMPTY_STRING; } @@ -397,7 +426,7 @@ const TString& TAssoc_array::get_str(const char* key) const bool TAssoc_array::get_bool(const char* key) const { const TString& str = get_str(key); - return str.full() && strchr("1XY", str[0]) != NULL; + return str.full() && strchr("1XY", str[0]) != nullptr; } int TAssoc_array::get_int(const char* key) const @@ -442,17 +471,18 @@ TObject* TCache::objptr(const TString& key) { const int hv = key.hash() % _data.size(); THash_object* ho = (THash_object*)_data.objptr(hv); - TObject* obj = NULL; - if (ho != NULL && ho->key() == key) + TObject* obj = nullptr; + + if (ho != nullptr && ho->key() == key) { obj = &ho->obj(); } else { obj = key2obj(key); - if (obj != NULL) + if (obj != nullptr) { - if (ho != NULL) + if (ho != nullptr) { discarding(ho); _data.destroy(hv); diff --git a/src/include/assoc.h b/src/include/assoc.h index 4d2861174..5e78455c1 100755 --- a/src/include/assoc.h +++ b/src/include/assoc.h @@ -14,6 +14,7 @@ // @class THash_object | Classe per la definizione degli elementi di una tabella hash. // // @base public | TObject + class THash_object : public TObject // @author:(INTERNAL) Villa { @@ -37,10 +38,10 @@ public: TObject& obj() const { return *_obj; } - TObject* remove_obj() { TObject* o = _obj; _obj = NULL; return o; } + TObject* remove_obj() { TObject* o = _obj; _obj = nullptr; return o; } // @cmember Costruttore (inizializza la chiave ed opzionalmente l'oggetto) - THash_object(const char* k, TObject* o = NULL) : _key(k), _obj(o) + THash_object(const char* k, TObject* o = nullptr) : _key(k), _obj(o) {} // @cmember Distruttore virtual ~THash_object(); @@ -109,6 +110,9 @@ public: // @cmember Aggiunge una copia dell'oggetto bool add(const char* key, const TObject& obj, bool force = false); + // @cmember Aggiunge una stringa. Se era gia' presente guarda il parametro force + bool add(const char* key, const char * str, bool force = false); + // @cmember Elimina un oggetto bool remove(const char* key); diff --git a/src/include/bagn010.uml b/src/include/bagn010.uml index 585d5f6ae..6212fb1f5 100644 --- a/src/include/bagn010.uml +++ b/src/include/bagn010.uml @@ -41,7 +41,7 @@ END STRING F_KEYFIELD2 30 BEGIN - PROMPT 42 2 "Campo 2 " + PROMPT 44 2 "Campo 2 " FLAGS "D" END @@ -53,7 +53,7 @@ END STRING F_KEYFIELD4 30 BEGIN - PROMPT 42 3 "Campo 4 " + PROMPT 44 3 "Campo 4 " FLAGS "D" END @@ -65,7 +65,7 @@ END STRING F_KEYFIELD6 30 BEGIN - PROMPT 42 4 "Campo 6 " + PROMPT 44 4 "Campo 6 " FLAGS "D" END @@ -77,7 +77,7 @@ END STRING F_KEYFIELD8 30 BEGIN - PROMPT 42 5 "Campo 8 " + PROMPT 44 5 "Campo 8 " FLAGS "D" END @@ -89,7 +89,7 @@ END STRING F_KEYFIELD10 30 BEGIN - PROMPT 42 6 "Campo 10 " + PROMPT 44 6 "Campo 10 " FLAGS "D" END @@ -101,7 +101,7 @@ END STRING F_KEYFIELD12 30 BEGIN - PROMPT 42 7 "Campo 12 " + PROMPT 44 7 "Campo 12 " FLAGS "D" END @@ -113,7 +113,7 @@ END STRING F_KEYFIELD14 30 BEGIN - PROMPT 42 8 "Campo 14 " + PROMPT 44 8 "Campo 14 " FLAGS "D" END @@ -125,7 +125,7 @@ END STRING F_KEYFIELD16 30 BEGIN - PROMPT 42 9 "Campo 16 " + PROMPT 44 9 "Campo 16 " FLAGS "D" END @@ -137,7 +137,7 @@ END STRING F_KEYFIELD18 30 BEGIN - PROMPT 42 10 "Campo 18 " + PROMPT 44 10 "Campo 18 " FLAGS "D" END @@ -149,7 +149,7 @@ END STRING F_KEYFIELD20 30 BEGIN - PROMPT 42 11 "Campo 20 " + PROMPT 44 11 "Campo 20 " FLAGS "D" END diff --git a/src/include/checks.cpp b/src/include/checks.cpp index 1d37258a2..8a540a34c 100755 --- a/src/include/checks.cpp +++ b/src/include/checks.cpp @@ -52,7 +52,10 @@ bool fatal_box( { buildmsg(); if (__batch) - __errors.add(msg); + { + if (__errors.find(msg) < 0) + __errors.add(msg); + } else xvt_dm_post_fatal_exit(msg); return false; @@ -69,7 +72,10 @@ bool error_box( { buildmsg(); if (__batch) - __errors.add(msg); + { + if (__errors.find(msg) < 0) + __errors.add(msg); + } else xvt_dm_post_error(msg); return false; @@ -85,7 +91,10 @@ bool warning_box( { buildmsg(); if (__batch) - __warnings.add(msg); + { + if (__warnings.find(msg) < 0) + __warnings.add(msg); + } else xvt_dm_post_warning(msg); return 0; @@ -117,7 +126,10 @@ bool message_box( { buildmsg(); if (__batch) - __warnings.add(msg); + { + if (__warnings.find(msg) < 0) + __warnings.add(msg); + } else xvt_dm_post_message(msg); return false; @@ -133,7 +145,10 @@ bool sorry_box( { buildmsg(); if (__batch) - __warnings.add(msg); + { + if (__warnings.find(msg) < 0) + __warnings.add(msg); + } else xvt_dm_post_note(msg); return false; @@ -147,7 +162,8 @@ bool noyes_box( buildmsg(); if (__batch) { - __errors.add(msg); + if (__errors.find(msg) < 0) + __errors.add(msg); return true; } ASK_RESPONSE r = xvt_dm_post_ask("No", "Si", NULL, msg); @@ -162,7 +178,8 @@ int noyesall_box( buildmsg(); if (__batch) { - __errors.add(msg); + if (__errors.find(msg) < 0) + __errors.add(msg); return K_NO; } ASK_RESPONSE r = xvt_dm_post_ask("No", "Si", "Si Tutti", msg); @@ -180,7 +197,8 @@ int custom_box( buildmsg(); if (__batch) { - __errors.add(msg); + if (__errors.find(msg) < 0) + __errors.add(msg); return K_NO; } ASK_RESPONSE r = xvt_dm_post_ask(buttons, buttonc, buttond, msg); @@ -203,7 +221,8 @@ bool yesno_box( buildmsg(); if (__batch) { - __errors.add(msg); + if (__errors.find(msg) < 0) + __errors.add(msg); return false; } ASK_RESPONSE r = xvt_dm_post_ask("Si", "No", NULL, msg); @@ -218,7 +237,8 @@ int yesnoall_box( buildmsg(); if (__batch) { - __errors.add(msg); + if (__errors.find(msg) < 0) + __errors.add(msg); return K_NO; } ASK_RESPONSE r = xvt_dm_post_ask("No", "Si", "No Tutti", msg); @@ -277,7 +297,8 @@ int yesnocancel_box( buildmsg(); if (__batch) { - __errors.add(msg); + if (__errors.find(msg) < 0) + __errors.add(msg); return K_NO; } ASK_RESPONSE r = xvt_dm_post_ask("Si", "No", "Annulla", msg); diff --git a/src/include/classes.h b/src/include/classes.h index d1bac02dc..027a08065 100755 --- a/src/include/classes.h +++ b/src/include/classes.h @@ -25,6 +25,7 @@ #define CLASS_CONTAINER 100 #define CLASS_ARRAY 101 #define CLASS_STACK 102 +#define CLASS_INDEXED_ARRAY 103 #define CLASS_WINDOW 200 #define CLASS_SHEET 201 diff --git a/src/include/config.cpp b/src/include/config.cpp index 82110982e..efc479018 100755 --- a/src/include/config.cpp +++ b/src/include/config.cpp @@ -255,17 +255,40 @@ bool TConfig::exist( // @flag TRUE | Se la variabile esiteva // @flag FALSE | Se la variabile non esiteva bool TConfig::remove( - const char* var, // @parm Nome della variabile - int index) // @parm Indice dell'elemento dell'array (default -1) + const char* var, // @parm Nome della variabile + int index) // @parm Indice dell'elemento dell'array (default -1) // @comm Se

e' = 0 viene costruito il nome dell'elemento // dell'array da cercare, diversamente viene cercata la variabile // normale passata in

. { - const char* key = get_varkey(var, index); - const bool ok = _data.remove(key); - if (ok) _dirty = true; - return ok; + const char* key = get_varkey(var, index); + const bool ok = _data.remove(key); + if (ok) _dirty = true; + return ok; +} + +// @mfunc Elimina una variabile dal paragrafo section +// +// @rdesc Ritorna i seguenti valori: +// +// @flag TRUE | Se la variabile esiteva +// @flag FALSE | Se la variabile non esiteva +bool TConfig::remove( + const char* var, // @parm Nome della variabile + const char* section, // @parm Sezione della variabile + int index) // @parm Indice dell'elemento dell'array (default -1) + +// @comm Se

e' = 0 viene costruito il nome dell'elemento +// dell'array da cercare, diversamente viene cercata la variabile +// normale passata in

. +{ + if (section && *section) // Cambia paragrafo se necessario + set_paragraph(section); + const char* key = get_varkey(var, index); + const bool ok = _data.remove(key); + if (ok) _dirty = true; + return ok; } // @doc EXTERNAL @@ -972,9 +995,14 @@ bool ini_set_string(const char* file, const char* paragraph, const char* name, c bool ini_remove(const char* file, const char* para, const char* name, int idx) { - TConfig c(file,para); +#ifndef DIRECT + DECLARE_VARNAME(name, idx); + return xvt_sys_remove_profile_string(file, para, varname) != 0; +#else + TConfig c(file, para); return c.remove(name, idx); +#endif } bool ini_get_bool(const char* file, const char* para, const char* name, bool defval, int idx) diff --git a/src/include/config.h b/src/include/config.h index 15a410d0f..ea98da7c6 100755 --- a/src/include/config.h +++ b/src/include/config.h @@ -128,6 +128,9 @@ public: // @cmember Elimina una variabile nel paragrafo attivo bool remove(const char* var, int index = -1); + // @cmember Elimina una variabile nel paragrafo attivo + bool remove(const char* var, const char * section, int index = -1); + // @cmember Elimina una array di variabili nel paragrafo attivo bool remove_array(const char* var); diff --git a/src/include/currency.cpp b/src/include/currency.cpp index b3675a3a2..a2b5c0c40 100755 --- a/src/include/currency.cpp +++ b/src/include/currency.cpp @@ -86,7 +86,6 @@ TObject* TDowJones::rec2obj(const TRectype& rec) const data->_chg = UNO; } } - if (codval.full()) { data->_dec = rec.get_int("I0"); diff --git a/src/include/date.cpp b/src/include/date.cpp index 0c79dfe24..d69efbd5d 100755 --- a/src/include/date.cpp +++ b/src/include/date.cpp @@ -107,10 +107,14 @@ TDate::TDate(int day, int month, int year) { if (day >= 1 && day <= 31 && month >= 1 && month <= 12 && year > 0) { - // 01/06/07 Tolla: Se passo il giorno 31 sicuramente voglio l'ultimo! Così passando 31/02/xx mi torna - if(day == 31) +/* // 01/06/07 Tolla: Se passo il giorno 31 sicuramente voglio l'ultimo! Così passando 31/02/xx mi torna che cazzata esiste last_day qui sotto + if (day == 31) +#ifdef DBG + error_box("Mattia sei un imbecille"); +#else _val = makedata(last_day(month,year), month, year); - else +#endif + else */ _val = makedata(day, month, year); } else diff --git a/src/include/execp.h b/src/include/execp.h index 12a974a5f..9c82d702b 100755 --- a/src/include/execp.h +++ b/src/include/execp.h @@ -36,7 +36,7 @@ public: // @cmember Controlla se l'utente puo' eseguire il programma bool can_run() const; // @cmember Esegue il processo - long run(bool async = FALSE, byte user = TRUE, bool iconizetask = true); + long run(bool async = false, byte user = true, bool iconizetask = true); // @cmember Ritorna l'ultimo codice di uscita int exitcode() const { return _exitcode; } diff --git a/src/include/expr.cpp b/src/include/expr.cpp index 6749f7cc8..f5ba4dd41 100755 --- a/src/include/expr.cpp +++ b/src/include/expr.cpp @@ -1230,7 +1230,7 @@ TCodesym TExpression::__factor(TCodesym startsym) _code.add(_number, real(parms_found)); val = real(index); _code.add(startsym, val); - _user_func_defined = TRUE; + _user_func_defined = true; } } } diff --git a/src/include/files.h b/src/include/files.h index 9a2743bfc..b1937098c 100755 --- a/src/include/files.h +++ b/src/include/files.h @@ -225,7 +225,7 @@ public: // @cmember Ritorna una token string contenente la descrizione del campo const char* fielddef(int fld) const; // @cmember Ritorna una stringa contenente la chiave - const char* keydef(int key) const; + const char* keydef(int key = 0) const; // @cmember Ritorna la lunghezza del record int len() const; diff --git a/src/include/keys.h b/src/include/keys.h index 2528df61d..a90a7cb75 100755 --- a/src/include/keys.h +++ b/src/include/keys.h @@ -6,6 +6,7 @@ #endif /* @M */ +#define K_UNDEF 0 #define K_BACKSPACE 8 #define K_TAB 9 #define K_ENTER 13 diff --git a/src/include/mask.cpp b/src/include/mask.cpp index b0781d46f..aa56652d1 100755 --- a/src/include/mask.cpp +++ b/src/include/mask.cpp @@ -797,7 +797,7 @@ bool TMask::stop_run( } } } - if (i >= last) + if (i >= last) return false; } @@ -2802,12 +2802,12 @@ void TMask::post_error_message(const char* msg, int sev) } } +// @comm Check_mask fatta per la relapp chiamate in modo batch verifica la consistenza della maschera senza visualizzare l'interfaccia. +// @comm Se la finestra non era aperta la apre in modo modale KEY TMask::check_mask() - - // @comm Se la finestra non era aperta la apre in modo modale { start_run(); - return stop_run(K_ENTER) ? K_ENTER : K_ESC; + return stop_run(K_AUTO_ENTER) ? K_ENTER : K_QUIT; } // @cmember ritorna la posizione del primo campo di una cella di uno sheet diff --git a/src/include/multirec.h b/src/include/multirec.h index 495774b0b..f17787831 100755 --- a/src/include/multirec.h +++ b/src/include/multirec.h @@ -32,8 +32,6 @@ class TMultiple_rectype : public TAuto_variable_rectype protected: const TArray & files() const { return _files;} - // @cmember Documento nuovo (non presente sul database). - bool nuovo() const { return _nuovo; } // @cmember funzione per costruire la chiave delle righe virtual void set_body_key(TRectype & rowrec); // @cmember verifica se la chiave della testata e' completa @@ -73,7 +71,9 @@ public: void set_nuovo(bool nuovo) { _nuovo = nuovo; } // @cmember restituisce il record di testata - const TAuto_variable_rectype& head() const { return *this; } // Ritorna la testata del documento + // @cmember Documento nuovo (non presente sul database). + bool nuovo() const { return _nuovo; } + const TAuto_variable_rectype& head() const { return *this; } // Ritorna la testata del documento // @cmember restituisce il record di testata TAuto_variable_rectype& head() { return *this; } // Ritorna la testata del documento diff --git a/src/include/odbcrset.cpp b/src/include/odbcrset.cpp index 82cb28818..12cffac81 100755 --- a/src/include/odbcrset.cpp +++ b/src/include/odbcrset.cpp @@ -707,6 +707,20 @@ void TODBC_recordset::remove_rec(const TISAM_recordset& dbfset) upd.exec(query); } +const char * TODBC_recordset::table_name() +{ + TString & s = get_tmp_string(255); + int pos = _sql.find("FROM"); + + if (pos >= 0) + { + s = _sql.ltrim(pos + 5); + pos = s.find(" "); + if (pos > 0) + s = s.left(pos); + } + return s; +} void TODBC_recordset::set(const char* sql) { if (not_frozen() || !_loaded || _sql != sql) diff --git a/src/include/odbcrset.h b/src/include/odbcrset.h index 548f4b1e7..675547b9d 100755 --- a/src/include/odbcrset.h +++ b/src/include/odbcrset.h @@ -69,6 +69,7 @@ public: void remove_rec(const TISAM_recordset& dbfset); const TString& dsn() const { return _dsn; } + const char * table_name(); TODBC_recordset(const char* sql, const bool freezed = false); virtual ~TODBC_recordset(); diff --git a/src/include/postman.cpp b/src/include/postman.cpp index 8d33b6960..a65f467ad 100755 --- a/src/include/postman.cpp +++ b/src/include/postman.cpp @@ -495,7 +495,7 @@ void TPostman::load_filters() // Inserisce un elemento fasullo per segnalare l'avvenuta lettura if (_expr.items() == 0) - _expr.add("", NULL); + _expr.add("", new TObject); } TExpression* TPostman::get_filter_expr(const char* flt) diff --git a/src/include/prefix.cpp b/src/include/prefix.cpp index a02b96837..e794c23d1 100755 --- a/src/include/prefix.cpp +++ b/src/include/prefix.cpp @@ -789,6 +789,13 @@ TDirtype TFile_manager::get_dirtype(int logicnum) return i.dir_type(); } +const char * TFile_manager::get_keydef(int logicnum, int key) const +{ + TTrec r(logicnum); + + return r.keydef(key - 1); +} + void TFile_manager::notify_change(TIsam_handle name) { TFile_info& i = fileinfo(name); @@ -1036,12 +1043,14 @@ void TPrefix::set( { const TString saved_prf = __ptprf; // Salvo __ptprf che viene cambiato da CGetPref char* prfx = (char*)CGetPref(); // Safe non const cast for StPath cprefix + strcpy_s(__ptprf, saved_prf); xvt_fsys_build_pathname(prfx, NULL, __ptprf, _prefix, NULL, NULL); } else { char* prfx = (char*)CGetPref(); // Safe non const cast for StPath cprefix + *prfx = '\0'; } } diff --git a/src/include/prefix.h b/src/include/prefix.h index 8f3e15be6..eb0bb7e45 100755 --- a/src/include/prefix.h +++ b/src/include/prefix.h @@ -50,7 +50,7 @@ public: TCodeb_handle get_handle(TIsam_handle name, int key); int get_reclen(int logicnum); - + const char * get_keydef(int logicnum, int key = 1) const ; void notify_change(TIsam_handle name); long last_change(TIsam_handle name) const; @@ -208,6 +208,9 @@ public: const TFilename& get_filename(TIsam_handle name) const { return _manager.get_filename(name); } + const char * get_keyexpr(int logicnum, int key = 1) const + { return TToken_string(_manager.get_keydef(logicnum, key)).get(); } + void notify_change(TIsam_handle name) { _manager.notify_change(name); } diff --git a/src/include/relapp.cpp b/src/include/relapp.cpp index 6a941e6ca..3a33576f7 100755 --- a/src/include/relapp.cpp +++ b/src/include/relapp.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -15,9 +16,10 @@ /////////////////////////////////////////////////////////// TRelation_application::TRelation_application() - : _mask(NULL), _search_id(-1), _lnflag(0), + : _mask(nullptr), _search_id(-1), _lnflag(0), _autodelete(0), _navigating(false), - _locked(false) + _locked(false), _stop_on_error(0), + _curr_transaction(transaction_mode_interactive), _transaction_batch(false) { } TRelation_application::~TRelation_application() @@ -29,7 +31,8 @@ bool TRelation_application::has_filtered_cursor() const if (yes) { const TEdit_field& f = get_search_field(); - yes = f.browse() != NULL; + + yes = f.browse() != nullptr; } return yes; } @@ -44,7 +47,7 @@ TCursor * TRelation_application::get_filtered_cursor() const return f.browse()->cursor(); } else - return NULL; + return nullptr; } void TRelation_application::setkey() @@ -103,7 +106,7 @@ void TRelation_application::set_limits( if (has_filtered_cursor()) { const TEdit_field& f = get_search_field(); - if (f.browse() != NULL) + if (f.browse() != nullptr) f.browse()->do_input(true); TCursor* cur = get_filtered_cursor(); @@ -267,7 +270,7 @@ void TRelation_application::enable_query() if (c.is_edit()) { TEdit_field& e = (TEdit_field&)c; - if (e.browse() != NULL) + if (e.browse() != nullptr) e.enable_check(query); } } @@ -285,7 +288,7 @@ bool TRelation_application::can_I_read(const TRelation* rel) const void TRelation_application::set_toolbar() { const int mode = _mask->mode(); - const bool can_edit_some = can_I_write(NULL); + const bool can_edit_some = can_I_write(nullptr); const bool can_nav = _lnflag == 0 && _curr_transaction != TRANSACTION_LINK; bool enabsave = can_edit_some; @@ -337,7 +340,7 @@ void TRelation_application::set_toolbar() { // Prima: can_edit_some = can_I_write(NULL) // Adesso: user_can_write() -> a me interessa che l'utente possa scrivere senza controllare che sia bloccato il record, si può sempre creare un record (se abilitati) nuovo anche in visualizzazione - bool enabins = (mode == MODE_QUERY || _lnflag == 0) && user_can_write(NULL); + bool enabins = (mode == MODE_QUERY || _lnflag == 0) && user_can_write(nullptr); _mask->fld(pos).enable(enabins); } @@ -359,7 +362,7 @@ bool TRelation_application::save_and_new() const bool TRelation_application::save_and_quit() const { - return (_autoins_caller.full() || _curr_transaction.not_empty()) && _curr_trans_mode != TM_REMAIN; + return (_autoins_caller.full() || _curr_transaction.not_empty()) && _curr_trans_mode != transaction_mode_remain; } int TRelation_application::set_mode(int mode) @@ -421,12 +424,12 @@ bool TRelation_application::autonum( for (const char* n = k.get(0); n && *n; n = k.get()) { - TMask_field* fld = NULL; + TMask_field* fld = nullptr; if (isdigit(*n)) fld = m->find_by_id(atoi(n)); else fld = m->find_by_fieldname(n); - if (fld == NULL) + if (fld == nullptr) { NFCHECK("Identificatore di autonumerazione errato"); return false; @@ -454,7 +457,7 @@ void TRelation_application::query_mode( // @flag FALSE | Entra in modo MODE_QUERY (default) { TMask* old = _mask; - const bool was_open = old != NULL && old->is_open(); + const bool was_open = old != nullptr && old->is_open(); const bool changing = changing_mask(MODE_QUERY); if (changing && was_open) @@ -721,7 +724,7 @@ int TRelation_application::delete_mode() { FOR_EACH_TOKEN(inplist, tok) { - if (*tok != '"' && strchr(tok, '@') == NULL) + if (*tok != '"' && strchr(tok, '@') == nullptr) { TMask_field& e = _mask->field(short(atoi(tok))); if (e.active()) @@ -747,7 +750,7 @@ int TRelation_application::delete_mode() FOR_EACH_TOKEN(inplist, tok) { - if (*tok != '"' && strchr(tok, '@') == NULL) + if (*tok != '"' && strchr(tok, '@') == nullptr) { TMask_field& e = _mask->field(short(atoi(tok))); if (!e.active()) @@ -893,7 +896,7 @@ int TRelation_application::delete_mode() { cur = pos; brw->do_output(); - bool can_delete = FALSE; + bool can_delete = false; if (find(1)) { TRelation& r = *get_relation(); @@ -909,14 +912,14 @@ int TRelation_application::delete_mode() query_mode(); cur.freeze(true); } - _autodelete = FALSE; + _autodelete = false; } if (!can_delete) skipped++; deleting--; } } - cur.freeze(FALSE); + cur.freeze(false); set_limits(); // Riaggiorno il numero del primo/ultimo record if (skipped > 0) @@ -930,9 +933,9 @@ int TRelation_application::delete_mode() else { if (search_mode()) - _autodelete = TRUE; + _autodelete = true; } - return TRUE; + return true; } // @doc INTERNAL @@ -947,7 +950,7 @@ bool TRelation_application::test_key( bool onereq = false, onefill = false; for (TEditable_field* e = _mask->get_key_field(k, true); - e != NULL; + e != nullptr; e = _mask->get_key_field(k, false)) { if (e->required() && e->shown()) @@ -962,7 +965,7 @@ bool TRelation_application::test_key( #ifdef DBG msg << "\nChiave " << int(k) << " - Campo " << e->dlg(); const TFieldref* fr = e->field(); - if (fr != NULL) + if (fr != nullptr) { msg << " - " << fr->name(); if (fr->to() > 0) @@ -1163,6 +1166,9 @@ bool TRelation_application::save(bool check_dirty) was_dirty = false; TWait_cursor hourglass; + + if (batch_transaction_in_error()) + return true; if (mode == MODE_INS) { bool changed = true; @@ -1268,6 +1274,7 @@ int TRelation_application::write(const TMask& m) int TRelation_application::rewrite(const TMask& m) { + TRelation& r = *get_relation(); m.autosave(r); r.curr().set_modify_info(); @@ -1356,13 +1363,19 @@ bool TRelation_application::remove() bool TRelation_application::firm_change_enabled() const { bool ok = TApplication::firm_change_enabled(); - ok &= (_mask == NULL || _mask->query_mode()) && _lnflag == 0; + ok &= (_mask == nullptr || _mask->query_mode()) && _lnflag == 0; return ok; } void TRelation_application::main_loop() { - KEY k; + KEY k = K_UNDEF; + TProgress_monitor * p = nullptr; + + if (_prog_message.full()) + p = new TProgress_monitor(_ntransactions, _prog_message); + if (_transaction_batch) + batch(); do { // ciclo delle transazioni _recins = -1; @@ -1381,11 +1394,14 @@ void TRelation_application::main_loop() { // la transazione necessita di autopremimento _autodelete = _curr_transaction == TRANSACTION_DELETE; - if (_curr_transaction == TRANSACTION_INSERT ) - _mask->send_key(K_CTRL+'N', 0); + if (_curr_transaction == TRANSACTION_INSERT) + _mask->send_key(K_CTRL + 'N', 0); else _mask->send_key(K_AUTO_ENTER, 0); - } + if (_transaction_batch) + do_events(); + } + } else // la transazione non è sul .ini { @@ -1411,18 +1427,26 @@ void TRelation_application::main_loop() _mask->send_key(K_CTRL+'E', 0); else error_box(TR("Elemento non eliminabile.")); - _autodelete = FALSE; + _autodelete = false; } } - if (_curr_trans_mode == TM_BATCH) + if (is_transaction() && _transaction_batch) { - batch(); - k = _mask->check_mask(); - batch(false); + KEY k_tmp = _mask->check_mask(); + + if (k_tmp == K_ENTER) + { + if (k != K_UNDEF) + k_tmp = K_SAVE; + } + else + if (_stop_on_error > 0) + _stop_on_error++; + k = k_tmp; } else - k = _mask->run(); + k = _mask->run(); switch (k) { @@ -1439,7 +1463,7 @@ void TRelation_application::main_loop() } break; case K_QUIT: - if (!save(TRUE)) + if (!is_batch_transaction() && !save(TRUE)) k = K_ENTER; break; case K_F1: @@ -1472,8 +1496,11 @@ void TRelation_application::main_loop() else insert_mode(); } - if (_curr_trans_mode == TM_AUTOMATIC || _curr_trans_mode == TM_BATCH) - _mask->send_key(K_CTRL+'R', 0); + if (_curr_trans_mode == transaction_mode_automatic && !_transaction_batch) + { + _mask->send_key(K_CTRL + 'R', 0); + do_events(); + } break; case K_SAVE: if (save(FALSE)) @@ -1484,7 +1511,7 @@ void TRelation_application::main_loop() } else { - if (save_and_new() && can_I_write(NULL)) + if (save_and_new() && can_I_write(nullptr)) { if (_mask->insert_mode()) insert_mode(); @@ -1516,7 +1543,7 @@ void TRelation_application::main_loop() else insert_mode(); } - if (_curr_trans_mode == TM_AUTOMATIC || _curr_trans_mode == TM_BATCH) + if (_curr_trans_mode == transaction_mode_automatic || _transaction_batch) _mask->send_key(K_CTRL+'R', 0); break; case K_DEL: @@ -1526,6 +1553,8 @@ void TRelation_application::main_loop() } else { + if (batch_transaction_in_error()) + break; if (relation_remove()) { query_mode(); @@ -1559,7 +1588,7 @@ void TRelation_application::main_loop() { for (TEdit_field* e = (TEdit_field *) _mask->get_key_field(1, TRUE); e; e = (TEdit_field *) _mask->get_key_field(1, FALSE)) { - if (e->is_kind_of(CLASS_EDIT_FIELD) && e->shown() && e->browse() != NULL) // Ignora campi invisibili o senza check + if (e->is_kind_of(CLASS_EDIT_FIELD) && e->shown() && e->browse() != nullptr) // Ignora campi invisibili o senza check { TCursor* b = e->browse()->cursor(); @@ -1574,7 +1603,7 @@ void TRelation_application::main_loop() TCursor* cur = c ; - if (c == NULL) + if (c == nullptr) cur = new TCursor(get_relation()); err = file().reread(); @@ -1586,8 +1615,8 @@ void TRelation_application::main_loop() file().curr() = cur->curr(); if (can_I_read(cur->relation())) err = get_relation()->read(_isequal, _testandlock); - if (c == NULL) - delete cur; + if (c == nullptr) + safe_delete(cur); } break; case K_PREV: @@ -1598,7 +1627,7 @@ void TRelation_application::main_loop() { for (TEdit_field* e = (TEdit_field *) _mask->get_key_field(1, TRUE); e; e = (TEdit_field *) _mask->get_key_field(1, FALSE)) { - if (e->is_kind_of(CLASS_EDIT_FIELD) && e->shown() && e->browse() != NULL) // Ignora campi invisibili o senza check + if (e->is_kind_of(CLASS_EDIT_FIELD) && e->shown() && e->browse() != nullptr) // Ignora campi invisibili o senza check { TCursor* b = e->browse()->cursor(); @@ -1611,28 +1640,28 @@ void TRelation_application::main_loop() } } - TCursor* cur = c ; + TCursor* cur = c ; - if (c == NULL) - cur = new TCursor(get_relation()); + if (c == nullptr) + cur = new TCursor(get_relation()); - file().reread(); + file().reread(); cur->curr() = file().curr(); cur->read(); --(*cur); - while (cur->pos() > 0 && !can_I_read(cur->relation())) + while (cur->pos() > 0 && !can_I_read(cur->relation())) --(*cur); file().curr() = cur->curr(); if (can_I_read(cur->relation())) - err = get_relation()->read(_isequal, _testandlock); - if (c == NULL) - delete cur; + err = get_relation()->read(_isequal, _testandlock); + if (c == nullptr) + safe_delete(cur); } break; - case K_END: + case K_END: err = file().readat(_last, _testandlock); break; - default: + default: break; } if (err == NOERR || err == _islocked) @@ -1649,7 +1678,7 @@ void TRelation_application::main_loop() } while (k != K_QUIT); if (_mask->is_open()) - _mask->close_modal(); + _mask->close_modal(); _mask->set_mode(NO_MODE); @@ -1675,25 +1704,40 @@ void TRelation_application::main_loop() else { const int err = get_relation()->status(); - ini.set("Result", err == NOERR ? "CANCEL" : "ERROR"); - ini.set("Error", err); + ini.set("Result", (err == NOERR && !is_batch_transaction()) ? "CANCEL" : "ERROR"); + ini.set("Error", !is_batch_transaction() ? err : -1); } - if (_curr_trans_mode == TM_BATCH) + if (_transaction_batch) { - TString_array & errs = errors(); + TString_array & errs = errors(); FOR_EACH_ARRAY_ROW(errs, r, s) - ini.set("ErrMsg", *s, "Main", false, r); + ini.set("ErrorMsg", *s, "Transaction", true, r); + for (int r = errs.items(); ini.exist("ErrorMsg", "Transaction", r); r++) + ini.remove("ErrorMsg", "Transaction", r); TString_array & warns = warnings(); FOR_EACH_ARRAY_ROW(warns, r1, s1) - ini.set("WarningMsg", *s1, "Main", false, r1); + ini.set("WarningMsg", *s1, "Transaction", true, r1); + for (int r = warns.items(); ini.exist("WarningMsg", "Transaction", r); r++) + ini.remove("WarningMsg", "Transaction", r); + errs.destroy(); + warns.destroy(); } } _trans_counter++; + if (p != nullptr) + p->addstatus(1L); + k = K_UNDEF; } while ( _trans_counter < _ntransactions); + if (_transaction_batch) + { + batch(false); + force_stop(); + } + safe_delete(p); } bool TRelation_application::filter() @@ -1720,7 +1764,7 @@ bool TRelation_application::filter() TString80 t; const char* s; - while((s = body.get()) != NULL) + while((s = body.get()) != nullptr) { t = s; const int u = t.find('='); @@ -1732,12 +1776,12 @@ bool TRelation_application::filter() _fixed.add(t); const short fid = atoi(t.left(u)); const TFieldref* campo = _mask->field(fid).field(); - if (campo != NULL) + if (campo != nullptr) campo->write(t.mid(u+1), rec); } cur->setfilter(""); cur->setregion(rec, rec, 0x2); - if (s == NULL) id = 0; + if (s == nullptr) id = 0; } } @@ -1757,7 +1801,7 @@ bool TRelation_application::filter() TString str, tmp; const char* v = body.get(); - for (int i = 0; v != NULL && i < _mask->fields(); i++) + for (int i = 0; v != nullptr && i < _mask->fields(); i++) { TMask_field& f = _mask->fld(i); if (f.active() && f.dlg() > 0 && f.in_key(key)) @@ -1785,7 +1829,7 @@ bool TRelation_application::filter() const char * s; TString t, v; - while((s = body.get()) != NULL) + while((s = body.get()) != nullptr) { t = s; const int u = t.find('='); @@ -1816,7 +1860,7 @@ bool TRelation_application::filter() const TString * v = (const TString *) field_values.objptr(field_name); TString val; - if (v == NULL && to >= 0) + if (v == nullptr && to >= 0) { v = (const TString *)field_values.objptr(field->name()); if (v) @@ -1834,23 +1878,22 @@ bool TRelation_application::filter() } } } - - return TRUE; + return true; } void TRelation_application::set_link(TMask & m, const char * keyexpr) { - CHECK(keyexpr != NULL, "Invalid expression"); + CHECK(keyexpr != nullptr, "Invalid expression"); TToken_string body(keyexpr); const int key = body.get_int(); - _lnflag = TRUE; + _lnflag = true; const char* v = body.get(); TString16 tmp; const int max = m.fields(); - for (int i = 0; i < max && v != NULL; i++) + for (int i = 0; i < max && v != nullptr; i++) { TMask_field& f = m.fld(i); @@ -1871,14 +1914,15 @@ bool TRelation_application::parse_command_line() _trans_ini.destroy(); _trans_counter=0; _curr_transaction = ""; - _curr_trans_mode = 'I'; + _curr_trans_mode = transaction_mode_interactive; TFilename ini; for (int i = argc()-1; i > 0; i--) { ini = argv(i); - if ((ini[0] == '-' || ini[0] == '/') && (ini[1] == 'I' || ini[1] == 'i')) + if ((ini[0] == '-' || ini[0] == '/') && ((toupper(ini[1]) == 'I') || (toupper(ini[1]) == 'B'))) { + _transaction_batch = (toupper(ini[1]) == 'B'); ini.ltrim(2); if (ini.starts_with("=")) ini.ltrim(1); @@ -1895,6 +1939,16 @@ bool TRelation_application::parse_command_line() else cantread_box(ini); } + + TString msg = argv(i + 1); + + if (msg.starts_with("-m") || msg.starts_with("-M")) + { + i++; + msg.ltrim(2); + msg.strip("\""); + _prog_message = msg; + } break; } } @@ -1915,7 +1969,8 @@ bool TRelation_application::load_transaction() TConfig cnf(_trans_ini.row(_trans_counter), "Transaction"); _curr_transaction = cnf.get("Action"); _curr_transaction.upper(); - _curr_trans_mode = toupper(cnf.get("Mode")[0]); + _curr_trans_mode = (transaction_mode) toupper(cnf.get("Mode")[0]); + _stop_on_error = cnf.get_bool("StopOnError") ? 1 : 0; _curr_trans_from = cnf.get("From"); const long firm = cnf.get_long("Firm"); if (firm > 0) @@ -1937,10 +1992,8 @@ bool TRelation_application::load_transaction() void TRelation_application::on_firm_change() { TApplication::on_firm_change(); - if (_mask != NULL) - { + if (_mask != nullptr) set_limits(0x3); - } } void TRelation_application::ini2query_mask() @@ -1959,6 +2012,7 @@ void TRelation_application::ini2insert_mask() { TString8 n; n.format("%d", get_relation()->lfile().num()); TConfig ini(_trans_ini.row(_trans_counter), n); + ini2mask(ini, *_mask, FALSE); } } @@ -1994,6 +2048,7 @@ void TRelation_application::ini2mask(TConfig& ini, TMask& m, bool query) if (!query && campo.is_sheet()) { TSheet_field &sheet=(TSheet_field &)campo; + ini2sheet(ini, sheet); } } @@ -2017,7 +2072,7 @@ void TRelation_application::edit_mask2ini() void TRelation_application::ini2sheet(TConfig& ini,TSheet_field &sheet) { - if (sheet.record() != NULL) + if (sheet.record() != nullptr) { const int lognum = sheet.record()->logic_num(); const TMask& sm = sheet.sheet_mask(); @@ -2027,8 +2082,17 @@ void TRelation_application::ini2sheet(TConfig& ini,TSheet_field &sheet) for (int r = 1; ;r++) { + bool found = false; + defpar.format("%d,%d", lognum, r); - if (ini.set_paragraph(defpar)) + for (int i = 0; i < 3 && !(found = ini.set_paragraph(defpar)); i++) + { + const int pos = defpar.find(','); + + if (pos > 0) + defpar.insert("0", pos + 1); + } + if (found) { TToken_string& row = sheet.row(r-1); for (int sf = sm.fields()-1; sf >= 0; sf--) @@ -2051,7 +2115,7 @@ void TRelation_application::ini2sheet(TConfig& ini,TSheet_field &sheet) void TRelation_application::sheet2ini(TSheet_field &sheet,TConfig& ini) { - if (sheet.record() != NULL) + if (sheet.record() != nullptr) { const int lognum = sheet.record()->logic_num(); const TMask& sm = sheet.sheet_mask(); @@ -2063,25 +2127,38 @@ void TRelation_application::sheet2ini(TSheet_field &sheet,TConfig& ini) for (r = 1 ; r <= sheet.items(); r++) { + bool found = false; + defpar.format("%d,%d", lognum, r); - + for (int i = 0; i < 3 && !(found = ini.set_paragraph(defpar)); i++) + { + const int pos = defpar.find(','); + + if (pos > 0) + defpar.insert("0", pos + 1); + } + if (found) + if (ini.set_paragraph(defpar)) + ini.remove_all(); + defpar.format("%d,%04d", lognum, r); + TMask_field* fkey; + sheet.restart_key(); while ((fkey = sheet.get_key(str))) - { ini.set(str, fkey->get(), defpar); - } TToken_string& row = sheet.row(r-1); const char* value; int i; + for (i = 0, value = row.get(0); value; i++, value = row.get()) { const TMask_field& campo = sm.field(FIRST_FIELD+i); const TFieldref* fr = campo.field(); if (fr) { - if (value == NULL || *value == '\0') + if (value == nullptr || *value == '\0') value = " "; // ini.set(fr->name(), value, defpar); fr->write(ini, defpar, value); @@ -2091,6 +2168,16 @@ void TRelation_application::sheet2ini(TSheet_field &sheet,TConfig& ini) for (r = sheet.items()+1; ; r++) { defpar.format("%d,%d", lognum, r); + bool found = false; + + defpar.format("%d,%d", lognum, r); + for (int i = 0; i < 3 && !(found = ini.set_paragraph(defpar)); i++) + { + const int pos = defpar.find(','); + + if (pos > 0) + defpar.insert("0", pos + 1); + } if (ini.set_paragraph(defpar)) ini.remove_all(); else @@ -2172,7 +2259,7 @@ bool TRelation_application::mask2mail(const TMask& m) { TConfig ini(ininame, "Transaction"); const char* action = ""; - char mode[2] = { TM_AUTOMATIC, '\0' }; + char mode[2] = { transaction_mode_automatic, '\0' }; switch (m.mode()) { case NO_MODE: diff --git a/src/include/relapp.h b/src/include/relapp.h index 9f3333f71..56b02778a 100755 --- a/src/include/relapp.h +++ b/src/include/relapp.h @@ -13,19 +13,14 @@ #include #endif -#ifndef __MASK_H -#include +#ifndef __AUTOMASK_H +#include +#endif + +#ifndef __TRANSACTION_H +#include #endif -#define TRANSACTION_RUN "RUN" // Run application (eventually sets firm) -#define TRANSACTION_INSERT "INSERT" // Create a new record and fill it -#define TRANSACTION_MODIFY "MODIFY" // Load and modify an existing record -#define TRANSACTION_DELETE "DELETE" // Delete an existing record -#define TRANSACTION_LINK "LINK" // Load an existing record and interactively edit it -#define TM_INTERACTIVE 'I' -#define TM_AUTOMATIC 'A' -#define TM_REMAIN 'R' -#define TM_BATCH 'B' // @doc EXTERNAL // @class TRelation_application | Classe per la gestione di una applicazione di manutenzione di uno @@ -68,14 +63,20 @@ class TRelation_application : public TSkeleton_application // @cmember:(INTERNAL) Azione della transazione corrente TString _curr_transaction; // @cmember:(INTERNAL) Modalità di esecuzione della transazione corrente (Automatica o interattiva) - char _curr_trans_mode; + transaction_mode _curr_trans_mode; + // @cmember:(INTERNAL) Modalità di esecuzione batch della transazione corrente + bool _transaction_batch; // @cmember:(INTERNAL) Transazione ricevuta da ..... TString _curr_trans_from; + // @cmember:(INTERNAL) Messaggio progress monitor transazioni + TString _prog_message; // @cmember:(INTERNAL) Flag di cancellazione automatica veloce int _autodelete; // @cmember:(INTERNAL) Flag di navigazione tramite toolbar bool _navigating; bool _locked; + // @cmember:(INTERNAL) Flag di controllo scritt ura su errore per le transizioni batch + int _stop_on_error; private: // @cmember:(INTERNAL) Carica la transazione corrente (protocollo via .ini) @@ -96,7 +97,7 @@ private: void set_key_filter(); // @cmember:(INTERNAL) Posiziona l'applicazione in modo richiesta/inserimento (chiama ) void query_insert_mode() - { query_mode(TRUE); } + { query_mode(true); } // @cmember:(INTERNAL) Entra in modo inserimento void insert_mode(); // @cmember:(INTERNAL) Cancella il record corrente @@ -283,9 +284,13 @@ public: bool lnflag() const { return _lnflag != 0;} // @cmember Ritorna TRUE se e' una transazione virtual bool is_transaction() const { return _curr_transaction.not_empty(); } + virtual bool is_batch_transaction() const { return is_transaction() && _transaction_batch; } + virtual bool batch_transaction_in_error() const { return is_batch_transaction() && _stop_on_error > 1; } virtual word class_id() const { return CLASS_RELATION_APPLICATION; } + virtual bool task_win_shown() const { return !_transaction_batch; } + // @cmember Costruttore TRelation_application(); // @cmember Distruttore diff --git a/src/include/transaction.cpp b/src/include/transaction.cpp index 89a4b565e..32e298197 100644 --- a/src/include/transaction.cpp +++ b/src/include/transaction.cpp @@ -727,8 +727,10 @@ bool file2app(TString & file ,TString& app) return app.full(); } -void execute_transactions(TArray & transactions, TLog_report & log) +void execute_transactions(TArray & transactions, TLog_report & log, bool interactive, const char * msg) { + TString prog_msg(msg); + if (transactions.items() > 0) { TBit_array processed; @@ -748,11 +750,14 @@ void execute_transactions(TArray & transactions, TLog_report & log) break; if (table.full()) { - TFilename path = t.name().path(); + TFilename pref = t.name(); + pref.ext(""); + while (isdigit(pref[pref.len() - 1])) + pref.rtrim(1); while (i >= 0) { - if (t.executer() == table && path == t.name().path()) + if (t.executer() == table && t.name().starts_with(pref)) { t.write(); processed.set(i); @@ -768,11 +773,14 @@ void execute_transactions(TArray & transactions, TLog_report & log) if (file2app(table, app)) { - TFilename filemask(path); + TFilename filemask(pref); TString_array files; filemask << "*" << "." << t.ext(); - app << " -i" << filemask << " -u" << user(); + app << (interactive ? " -i" : " -b") << filemask; + if (prog_msg.full()) + app << " -m\"" << prog_msg << "\""; + app << " -u" << user(); TExternal_app cmd(app); cmd.run(); diff --git a/src/include/transaction.h b/src/include/transaction.h index fed1977b8..867f46cf6 100644 --- a/src/include/transaction.h +++ b/src/include/transaction.h @@ -186,6 +186,6 @@ public: virtual ~TTransaction() {} }; -void execute_transactions(TArray & transactions, TLog_report & log); +void execute_transactions(TArray & transactions, TLog_report & log, bool interactive = true, const char * msg = nullptr); #endif diff --git a/src/include/validate.cpp b/src/include/validate.cpp index 9aaaf5764..da52298a4 100755 --- a/src/include/validate.cpp +++ b/src/include/validate.cpp @@ -517,8 +517,8 @@ HIDDEN bool _fixlen_val(TMask_field& f, KEY) const int length = get_int_val_param(0); const bool ok = s.len() == length; if (!ok) - f.error_box(FR("La lunghezza del campo deve essere %d %s"), - length, f.is_kind_of(CLASS_REAL_FIELD) ? TR("cifre") : TR("caratteri")); + f.error_box(FR("La lunghezza del campo %s deve essere %d %s"), + f.prompt(), length, f.is_kind_of(CLASS_REAL_FIELD) ? TR("cifre") : TR("caratteri")); return ok; } @@ -703,7 +703,7 @@ HIDDEN bool _alpha_val(TMask_field& f, KEY k) const TString& s = f.get(); for (int i = 0; s[i]; i++) if (!isalpha(s[i])) - return f.error_box(TR("Sono ammessi solo caratteri alfabetici")); + return f.error_box(FR("Sono ammessi solo caratteri alfabetici nel campo %s"), f.prompt()); } return true; } @@ -822,7 +822,7 @@ HIDDEN bool _ora_val(TMask_field& f, KEY key) if ( ok ) f.set( ora ); else - return f.error_box(TR("Ora errata o formato non valido")); + return f.error_box(FR("Ora errata o formato non valido nel campo %s"), f.prompt()); } } return true; diff --git a/src/include/xml.h b/src/include/xml.h index 15300ac64..fbadfbb8a 100755 --- a/src/include/xml.h +++ b/src/include/xml.h @@ -57,6 +57,7 @@ public: bool GetEnclosedReal(const char* strAttr, real & r) const; TXmlItem& SetAttr(const char* strAttr, const char* strVal); + void ListAttrs(TString_array & attrs) const { attrs.destroy(); if (m_Attributes) m_Attributes->get_keys(attrs); } const TString& GetAttr(const char* strAttr) const; TXmlItem& SetAttr(const char* strAttr, int n); TXmlItem& SetColorAttr(const char* strAttr, COLOR rgb); diff --git a/src/ve/ve0100.cpp b/src/ve/ve0100.cpp index b893b128f..f384af3b3 100755 --- a/src/ve/ve0100.cpp +++ b/src/ve/ve0100.cpp @@ -1173,10 +1173,7 @@ void TMotore_application::ini2mask(TConfig& ini, TMask& msk, bool query) { const TRectype& art = cache().get(LF_ANAMAG, codart); if (art.empty()) - { - error_box(FR("Articolo non valido sulla riga %d: %s"), f.items(), (const char*)codart); rec.zero(RDOC_CODARTMAG); - } } } else diff --git a/src/xvaga/xvaga.cpp b/src/xvaga/xvaga.cpp index 6e15803ea..c826be031 100755 --- a/src/xvaga/xvaga.cpp +++ b/src/xvaga/xvaga.cpp @@ -3742,6 +3742,28 @@ BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, cons #endif } +XVTDLL BOOLEAN xvt_sys_remove_profile_string(const char* file, const char* paragraph, const char* name) +{ + if (file == NULL || *file == '\0') + file = xvt_fsys_get_campo_ini(); + + if (paragraph == NULL || *paragraph == '\0') + paragraph = "Main"; + +#ifdef __WXMSW__ + return ::WritePrivateProfileString(paragraph, name, nullptr, file) > 0; +#else + wxFileConfig ini("", "", file, "", wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH); + ini.SetUmask(0x0); + + wxString path; + path << "/" << paragraph; + ini.SetPath(path); + + return ini.DeleteEntry(name); +#endif +} + BOOLEAN xvt_sys_find_editor(const char* file, char* editor) { BOOLEAN ok = FALSE; diff --git a/src/xvaga/xvt.h b/src/xvaga/xvt.h index 288d91009..b442c9074 100755 --- a/src/xvaga/xvt.h +++ b/src/xvaga/xvt.h @@ -432,6 +432,7 @@ XVTDLL int xvt_sys_get_profile_string(const char* file, const char* paragra const char* defval, char* value, int maxsize); XVTDLL BOOLEAN xvt_sys_set_profile_int(const char* file, const char* paragraph, const char* name, long value); XVTDLL BOOLEAN xvt_sys_set_profile_string(const char* file, const char* paragraph, const char* name, const char* value); +XVTDLL BOOLEAN xvt_sys_remove_profile_string(const char* file, const char* paragraph, const char* name); XVTDLL int xvt_sys_get_session_id(); XVTDLL unsigned long xvt_sys_get_free_memory();