From: Kilian Saffran Date: Tue, 27 Mar 2018 08:04:01 +0000 (+0200) Subject: reinsterted import PDF tools - pdfextract rename inv file to copy remove X-Git-Tag: 3.18.3 X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=f0e5c2bb6d88900538a835b24ce1fb13484c097a;p=creorga.git reinsterted import PDF tools - pdfextract rename inv file to copy remove --- diff --git a/app_v3/Tools/pdfextract.pl b/app_v3/Tools/pdfextract.pl index 3ca805c..34f054a 100644 --- a/app_v3/Tools/pdfextract.pl +++ b/app_v3/Tools/pdfextract.pl @@ -6,6 +6,7 @@ use Getopt::Long; use File::Basename; use File::Path qw/make_path/; use Data::Dumper; +use File::Copy qw/copy/; use lib('.'); use sqlite; use utf8; @@ -211,8 +212,17 @@ sub importinvoicedata(){ if (-e $nfname){ unlink($nfname); } - rename($fname,$nfname); - push @upd,"invoicefile='".basename($nfname)."'"; + copy($fname,$nfname); + print "Copy file to new name: ".$nfname."\n"; + my $insfname = basename($nfname); + if (-e $nfname){ + unlink($fname); + print "remove file: ".$fname."\n"; + } else{ + $insfname = basename($fname); + } + #rename($fname,$nfname); + push @upd,"invoicefile='".$insfname."'"; } if (exists($impdata->{totalamount})) { push @upd,"invoiceamount=".$impdata->{totalamount}.""; diff --git a/app_v3/chrome/content/js/tools.js b/app_v3/chrome/content/js/tools.js index 60adfa9..8309684 100644 --- a/app_v3/chrome/content/js/tools.js +++ b/app_v3/chrome/content/js/tools.js @@ -104,6 +104,86 @@ var tools = { }catch(ex){ system.popup("Erreur d'Export!","L'export des données n'a pas completement fonctionné !\n"); } - } + }, + readinvoicepdf: function(){ + try { + var lastdir = apppref.getpreference("support.lastfiledir"); + var nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); + fp.init(window, "selectionner fichier PDF", nsIFilePicker.modeOpen); + fp.appendFilter("PDF", "*.pdf"); + if (lastdir != '') { + var nsILocalFile= Components.interfaces.nsILocalFile; + var f = Components.classes["@mozilla.org/file/local;1"].createInstance(nsILocalFile); + f.initWithPath(lastdir); + fp.displayDirectory = f; + } + var res = fp.show(); + if (res != nsIFilePicker.returnCancel) { + var pdffile = fp.file; + apppref.setpreference("support.lastfiledir",system.getDirectory(pdffile.path)); + + var cname = appdb.dbquery("select uuid from creche LIMIT 1;"); + cruuid = cname.sqldata[0].uuid; + var importpath = FileUtils.File(curcfg.path.local + system.sep() +"imports" + system.sep() + cruuid); + var args = ["-db",'"' + appdb.dbFile.path + '"',"-p",'"' +pdffile.path + '"',"-o",'"' + importpath.path + '"',"-t",'"' + system.toolsdir() + '"',"-x","inv","-l", '"' + system.profiledir() + system.sep() + 'importerror.log"']; + + var binpdf = system.toolsdir() + system.sep() + "pdfextract.exe"; + if (system.os != "WINNT") { + binpdf = system.toolsdir() + system.sep() + "pdfextract"; + } + //dump(binpdf + " " +JSON.stringify(args) + "\n"); + system.popup("Import Factures!","Import du PDF '"+ pdffile.path +"' en cours!\n"); + system.runcmdline(binpdf,args,function(data){ + var strx = apppref.getpreference("pageconfig.lastpage"); + var x = JSON.parse(strx); + + if (x.module == 'accounting') { + navigation.load_appview(x.view,x.module,null,x.header); + } + system.popup("Import Factures!","Les factures ont été importées!\n"); + }); + + } + } catch(ex){ + system.popup("Erreur d'import!","Une Erreur s'est produite pendant l'import des factures!\n"); + //dump("Error importing invoice PDF! " + ex + "\n"); + } + }, + readbenefitstatement: function(){ + try { + var lastdir = apppref.getpreference("support.lastfiledir"); + var nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); + fp.init(window, "selectionner fichier PDF", nsIFilePicker.modeOpen); + fp.appendFilter("PDF", "*.pdf"); + if (lastdir != '') { + var nsILocalFile= Components.interfaces.nsILocalFile; + var f = Components.classes["@mozilla.org/file/local;1"].createInstance(nsILocalFile); + f.initWithPath(lastdir); + fp.displayDirectory = f; + } + var res = fp.show(); + if (res != nsIFilePicker.returnCancel) { + var pdffile = fp.file; + apppref.setpreference("support.lastfiledir",system.getDirectory(pdffile.path)); + + var cname = appdb.dbquery("select uuid from creche LIMIT 1;"); + cruuid = cname.sqldata[0].uuid; + var importpath = FileUtils.File(curcfg.path.local + system.sep() +"imports" + system.sep() + cruuid); + var args = ["-db",'"' + appdb.dbFile.path + '"',"-p",'"' + pdffile.path + '"',"-o",'"' + importpath.path +'"',"-t",'"' + system.toolsdir() + '"',"-x","stmt","-l",'"' + system.profiledir() + system.sep() + 'importerror.log"']; + var binpdf = system.toolsdir() + system.sep() + "pdfextract.exe"; + if (system.os != "WINNT") { + binpdf = system.toolsdir() + system.sep() + "pdfextract"; + } + system.runcmdline(binpdf,args,function(data){ + system.popup("Import Prestations!","Les Prestations ont été importées!\n"); + }); + } + } catch(ex){ + system.popup("Erreur d'import!","Une erreur s'est produite pendant l'import des prestations!\n"); + //dump("Error importing statement PDF! " + ex + "\n"); + } + } };