From 911e7fef3af113d197b15dedf322a5ed636d8a40 Mon Sep 17 00:00:00 2001 From: Kilian Saffran Date: Mon, 8 Oct 2018 14:04:55 +0200 Subject: [PATCH] =?utf8?q?bugfix=20d=C3=A9compte=20et=20ajout=20pour=20ver?= =?utf8?q?ifier=20l'int=C3=A9gartion=20de=20la=20b.d.=20creorga?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Tools/creorgadb.pl | 27 +- app_v3/chrome/content/js/database.js | 75 ++-- app_v3/chrome/content/js/system.js | 14 +- .../modules/accounting/accounting.html | 5 +- .../modules/accounting/accountingchild.html | 4 +- .../accounting/accountingopeninvoice.html | 15 +- .../modules/accounting/js/accounting.js | 29 +- .../modules/accounting/js/accountingchild.js | 328 +++++++++++------- .../accounting/js/accountingopeninvoice.js | 156 ++++++--- .../modules/presences/js/dailypresences.js | 26 +- .../content/modules/support/js/multisite.js | 44 ++- .../content/modules/support/multisite.html | 7 +- app_v3/defaults/profile/creorga.sqlite | Bin 71680 -> 72704 bytes install/create_setup_windows.pl | 2 +- 14 files changed, 455 insertions(+), 277 deletions(-) diff --git a/Tools/creorgadb.pl b/Tools/creorgadb.pl index 3a5d607..4966f1a 100644 --- a/Tools/creorgadb.pl +++ b/Tools/creorgadb.pl @@ -6,6 +6,8 @@ use Getopt::Long; use Data::Dumper; use File::Copy qw/copy/; use Time::Local; +use UUID::Generator::PurePerl; + use utf8; use lib ('.'); use sqlite; @@ -17,7 +19,7 @@ GetOptions("dbfile|db=s" => \$dbfile, "template|t=s" => \$templatedb ); #-db "C:\\Users\\ksaff\\DKS\\projects\\Creorga\\lechatpotte\\7c41cbd9-92b6-6d49-8682-a5404b726d10.sqlite" -t "C:\\Users\\ksaff\\Workspace\\creorga\\app\\defaults\\profile\\creorga.sqlite" - +my $ug = UUID::Generator::PurePerl->new(); sub getcoldef($){ my $strddl = shift; my $curddl = $strddl; @@ -107,7 +109,28 @@ foreach my $pd (sort {$a <=> $b} keys(%{$defdbschemacfg})){ $sql_tmptbl =~ s/CREATE\ TABLE\ /CREATE TABLE new_/; $sql_tmptbl =~ s/"//g; push(@ainssql,$sql_tmptbl); - push(@ainssql,"INSERT INTO new_".$defdbschemacfg->{$pd}->{tbl_name}." (".join(',',@copycols).") SELECT ".join(',',@copycols)." FROM ".$defdbschemacfg->{$pd}->{tbl_name}.";"); + + if ($defdbschemacfg->{$pd}->{tbl_name} ne "accounting"){ + push(@ainssql,"INSERT INTO new_".$defdbschemacfg->{$pd}->{tbl_name}." (".join(',',@copycols).") SELECT ".join(',',@copycols)." FROM ".$defdbschemacfg->{$pd}->{tbl_name}.";"); + }elsif ((index($sql_tmptbl,"PRIMARY KEY (uuid)") > 0) && ($defdbschemacfg->{$pd}->{tbl_name} eq "accounting")) { + # adding primary keys + my $data = $db->dbquerysorted("select * from ".$defdbschemacfg->{$pd}->{tbl_name}.";"); + push (@copycols,'uuid'); + foreach my $da ( keys(%{$data})){ + my @ndata = (); + foreach my $x (@copycols){ + if ($x eq "uuid"){ + push(@ndata,$ug->generate_v4()); + } else { + push(@ndata,$data->{$da}->{$x}); + } + } + push(@ainssql,"INSERT INTO new_".$defdbschemacfg->{$pd}->{tbl_name}." (".join(',',@copycols).") VALUES ('".join("','",@ndata)."');"); + } + } + else { + push(@ainssql,"INSERT INTO new_".$defdbschemacfg->{$pd}->{tbl_name}." (".join(',',@copycols).") SELECT ".join(',',@copycols)." FROM ".$defdbschemacfg->{$pd}->{tbl_name}.";"); + } push(@ainssql,"DROP TABLE ".$defdbschemacfg->{$pd}->{tbl_name}.";"); push(@ainssql,"ALTER TABLE new_".$defdbschemacfg->{$pd}->{tbl_name}. " RENAME TO ".$defdbschemacfg->{$pd}->{tbl_name}.";"); $bvaccum = 1; diff --git a/app_v3/chrome/content/js/database.js b/app_v3/chrome/content/js/database.js index df9792d..68d699a 100644 --- a/app_v3/chrome/content/js/database.js +++ b/app_v3/chrome/content/js/database.js @@ -266,16 +266,19 @@ var appdb = { return curdbfiles; }, - check_schema: function(){ - alert("TEST"); + check_schema: function(dbid){ + //alert("TEST"); + var dbconf = apppref.getpreference("support.database." + dbid); + var sitecfg = JSON.parse(dbconf); + var dbpath = sitecfg.path.local + system.sep() + sitecfg.uuid + ".sqlite"; var defdb = system.appdir() + system.sep() + 'defaults'+ system.sep() + 'profile' + system.sep() + 'creorga.sqlite'; - var dbfiles = appdb.getdatabases(); - alert(JSON.stringify(dbfiles)); - for (var cdb in dbfiles){ - if (system.fileexists(dbfiles[cdb])){ + // var dbfiles = appdb.getdatabases(); + alert(JSON.stringify(sitecfg)); + // for (var cdb in dbfiles){ + if (system.fileexists(dbpath)){ - var args = ["-db",dbfiles[cdb],"-t",defdb]; + var args = ["-db",dbpath,"-t",defdb]; var bincheck = system.toolsdir() + system.sep() + "creorgadb.exe"; if (system.os != "WINNT") { @@ -284,38 +287,38 @@ var appdb = { system.runcmdline(bincheck,args,null); } - } - OS.File.remove(system.profilerootdir() + system.sep() + '/checkschema.txt',{ignoreAbsent:true}); + // } + // OS.File.remove(system.profilerootdir() + system.sep() + '/checkschema.txt',{ignoreAbsent:true}); }//, } -var sync = { - //TODO: dynamic url and dynamic (curcfg) schema -> ident +// var sync = { +// //TODO: dynamic url and dynamic (curcfg) schema -> ident - //url: "http://localhost:6060/localsyncup", - up: function(ddlquery){ - //dump("dbfile" + + "\n"); - /*var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); - request.onload = function(aEvent) { - //dump("Response Text: " + aEvent.target.responseText + "\n"); - }; - request.onerror = function(aEvent) { - //dump("Error Msg:" + aEvent.target.responseText + "\n"); - //dump("Error Status: " + aEvent.target.status + "\n"); - }; - request.open("POST", sync.url, true); - request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");*/ - var cts = new Date(); - var milli = cts.getMilliseconds(); - if (milli < 10){ - milli = "00" + milli; - } else if (milli < 100){ - milli = "0" + milli; - } - var dbident = system.getFileName(appdb.dbFile.path).replace(/\.sqlite/,''); - dump("SQL;;"+ cts.toLocaleFormat('%Y%m%d%H%M%S')+ milli +";;" + dbident +";;"+ddlquery+ "\n"); - //request.send("ts="+ cts.toLocaleFormat('%Y-%m-%d %H:%M:%S') +"&q=" +encodeURIComponent(ddlquery)+ "&ident="+dbident+"&rh="+ system.hostname()); - } -} +// //url: "http://localhost:6060/localsyncup", +// up: function(ddlquery){ +// //dump("dbfile" + + "\n"); +// /*var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); +// request.onload = function(aEvent) { +// //dump("Response Text: " + aEvent.target.responseText + "\n"); +// }; +// request.onerror = function(aEvent) { +// //dump("Error Msg:" + aEvent.target.responseText + "\n"); +// //dump("Error Status: " + aEvent.target.status + "\n"); +// }; +// request.open("POST", sync.url, true); +// request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");*/ +// var cts = new Date(); +// var milli = cts.getMilliseconds(); +// if (milli < 10){ +// milli = "00" + milli; +// } else if (milli < 100){ +// milli = "0" + milli; +// } +// var dbident = system.getFileName(appdb.dbFile.path).replace(/\.sqlite/,''); +// dump("SQL;;"+ cts.toLocaleFormat('%Y%m%d%H%M%S')+ milli +";;" + dbident +";;"+ddlquery+ "\n"); +// //request.send("ts="+ cts.toLocaleFormat('%Y-%m-%d %H:%M:%S') +"&q=" +encodeURIComponent(ddlquery)+ "&ident="+dbident+"&rh="+ system.hostname()); +// } +// } diff --git a/app_v3/chrome/content/js/system.js b/app_v3/chrome/content/js/system.js index 4c37839..9cca41a 100644 --- a/app_v3/chrome/content/js/system.js +++ b/app_v3/chrome/content/js/system.js @@ -1,9 +1,9 @@ //Source-code licensed under EUPL v1.1 ( Copyright 2016 By DKS s.à r.l. - Kilian Saffran - Luxembourg ) -// function jsdump(str) { -// Components.classes['@mozilla.org/consoleservice;1'] -// .getService(Components.interfaces.nsIConsoleService) -// .logStringMessage(str); -// } +function jsdump(str) { + Components.classes['@mozilla.org/consoleservice;1'] + .getService(Components.interfaces.nsIConsoleService) + .logStringMessage(str); +} Components.utils["import"]("resource://gre/modules/FileUtils.jsm"); Components.utils["import"]("resource://gre/modules/Services.jsm"); @@ -315,10 +315,10 @@ var system = { runcmdline: function(cmdlapp,args,callback){ var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess); - dump(cmdlapp + " "+ JSON.stringify(args) + "\n"); + //dump(cmdlapp + " "+ JSON.stringify(args) + "\n"); file.initWithPath(cmdlapp); process.init(file); - dump(cmdlapp + " "+ JSON.stringify(args) + "\n"); + //dump(cmdlapp + " "+ JSON.stringify(args) + "\n"); process.runwAsync( args, args.length,callback); return true; }, diff --git a/app_v3/chrome/content/modules/accounting/accounting.html b/app_v3/chrome/content/modules/accounting/accounting.html index 530aa59..be04fec 100644 --- a/app_v3/chrome/content/modules/accounting/accounting.html +++ b/app_v3/chrome/content/modules/accounting/accounting.html @@ -60,10 +60,9 @@