From dae08285433bd6170f883565723c03b82970e388 Mon Sep 17 00:00:00 2001 From: delcroix Patrick Date: Wed, 5 Apr 2017 20:50:18 +0200 Subject: [PATCH 1/3] NEW : show files in the bank statement + download --- htdocs/compta/bank/releve.php | 134 +++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php index ffadceafb2e..2ab6df9047f 100644 --- a/htdocs/compta/bank/releve.php +++ b/htdocs/compta/bank/releve.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2017 Patrick Delcroix * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +35,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php'; +//show files +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; $langs->load("banks"); $langs->load("categories"); @@ -88,7 +92,36 @@ if ($id > 0 || ! empty($ref)) // Initialize technical object to manage context to save list fields $contextpage='banktransactionlist'.(empty($object->ref)?'':'-'.$object->id); +/* +*ZIP creation +*/ +if($action=="dl" && $num>0 && isset($_SESSION["releve"][$num])){ + unset($zip); + $log=''; + $filearray=$_SESSION["releve"][$num]; + $zipname = $num.'.zip'; + $zip = new ZipArchive; + $zip->open($zipname, ZipArchive::OVERWRITE); + foreach ($filearray as $key=> $files) { + if(is_array($files)){ + foreach ($files as $file) { + $zip->addFile($file["fullname"],$file["name"]);// + $log.=$key.','.$file["name"]."\n"; + } + }else{ + $log.=$key.','.$langs->trans("Nofile")."\n"; + } + } + $zip->addFromString('log.csv', $log); + $zip->close(); + ///Then download the zipped file. + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename='.$zipname); + header('Content-Length: ' . filesize($zipname)); + readfile($zipname); +} +unset($_SESSION["releve"][$num]); /* * View @@ -519,7 +552,7 @@ else dol_print_error($db); } } - + print Get_attach_files($db,$objp->rowid,$objp->label); print ""; if ($objp->amount < 0) @@ -568,3 +601,102 @@ else llxFooter(); $db->close(); + +/*Function to generate the HTML code used to show the file name & download link attached to the Item covered by the bank line + * @param $db Object database object + * @param $bankId int bank line id + * @param $label + * + */ +function Get_attach_files($db, $bankId,$label=''){ + $out=''; + global$conf; + $sql='SELECT u.url_id, u.type,ff.rowid as id , ff.`ref` AS reff, f.facnumber AS `ref`,'; + $sql.=' e.`ref` AS refe, sp.rowid AS ids, d.rowid AS idd'; + $sql.=' FROM '.MAIN_DB_PREFIX.'bank_url AS u'; + if ( !empty($label) || $label=='(CustomerInvoicePayment)'){ + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement AS p ON p.fk_bank = u.fk_bank'; + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture AS pf ON pf.fk_paiement = p.rowid'; + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'facture AS f ON f.rowid = pf.fk_facture'; + } + if( !empty($label) || $label=='(SupplierInvoicePayment)'){ + //invoice suplier (SupplierInvoicePayment) + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn AS fp ON fp.fk_bank = u.fk_bank'; + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS fpf ON fpf.fk_paiementfourn = fp.rowid'; + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS ff ON ff.rowid = fpf.fk_facturefourn'; + } + if( !empty($label) || $label=='(ExpenseReportPayment)'){ + //EXPENSEs (ExpenseReportPayment) + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_expensereport AS ep ON ep.fk_bank = u.fk_bank'; + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'expensereport AS e ON e.rowid = ep.fk_expensereport'; + } + if( !empty($label) || $label=='(DonationPayment)'){ + //donation + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_donation AS dp ON dp.fk_bank = u.fk_bank'; + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'don AS d ON d.rowid = dp.fk_donation'; + } + if( !empty($label) || $label=='(SalaryPayment)'){ + //loan +// $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_loan AS lp ON lp.fk_bank = u.fk_bank'; + //salary + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_salary AS sp ON sp.fk_bank = u.fk_bank'; + } + //END SQL + $sql.=" WHERE u.fk_bank in('".$bankId."')AND u.type in ('payment','payment_supplier','payment_expensereport','payment_salary','payment_donation' )"; + $resd = $db->query($sql); + $files=array(); + $link=''; + if ($resd) + { + $numd = $db->num_rows($resd); + $upload_dir =''; + $i=0; + if($numd>0) + { + + + $objd = $db->fetch_object($resd); + + switch($objd->type){ + case "payment": + $subdir=dol_sanitizeFileName($objd->ref); + $upload_dir = $conf->facture->dir_output.'/'.$subdir; + $link="../../document.php?modulepart=facture&file=".str_replace('/','%2F',$subdir).'%2F'; + break; + + case "payment_supplier": + $subdir=get_exdir($objd->id,2,0,0,$objd,'invoice_supplier').$objd->reff; + $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir; + $link="../../document.php?modulepart=facture_fournisseur&file=".str_replace('/','%2F',$subdir).'%2F'; + break; + case "payment_expensereport": + $subdir=dol_sanitizeFileName($objd->refe); + $upload_dir = $conf->expensereport->dir_output.'/'.$subdir; + $link="../../document.php?modulepart=expensereport&file=".str_replace('/','%2F',$subdir).'%2F'; + break; + case "payment_salary": + $subdir=dol_sanitizeFileName($objd->ids); + $upload_dir = $conf->salaries->dir_output.'/'.$subdir; + $link="../../document.php?modulepart=salaries&file=".str_replace('/','%2F',$subdir).'%2F'; + break; + case "payment_donation": + $subdir=get_exdir(null,2,0,1,$objd,'donation'). '/'. dol_sanitizeFileName($objd->idd); + $upload_dir = $conf->don->dir_output . '/' . $subdir; + $link="../../document.php?modulepart=don&file=".str_replace('/','%2F',$subdir).'%2F'; + break; + default: + break; + } + + if(!empty($upload_dir)){ + $files=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$','',SORT_ASC,1); + foreach ($files as $key => $file){ + $out.= '
'.$file['name'].''; + } + $_SESSION["releve"][$num][]=$files; + } + } + } + $db->free($resd); + return $out; +} From ca72e5e19f04dd908c7fcd542d2c610164fcd151 Mon Sep 17 00:00:00 2001 From: delcroix Patrick Date: Wed, 5 Apr 2017 20:53:41 +0200 Subject: [PATCH 2/3] NEW : download button --- htdocs/compta/bank/releve.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php index 2ab6df9047f..4eb52dd2178 100644 --- a/htdocs/compta/bank/releve.php +++ b/htdocs/compta/bank/releve.php @@ -595,6 +595,9 @@ else print ""; print "\n"; + // download button + echo ''.$langs->trans('DownloadFile')." \n"; + } From 337eac30c17a8f08d38f8eed856423cc0b3f8ee0 Mon Sep 17 00:00:00 2001 From: delcroix Patrick Date: Wed, 5 Apr 2017 21:14:41 +0200 Subject: [PATCH 3/3] Update releve.php --- htdocs/compta/bank/releve.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php index 4eb52dd2178..2acb0b327ce 100644 --- a/htdocs/compta/bank/releve.php +++ b/htdocs/compta/bank/releve.php @@ -552,7 +552,7 @@ else dol_print_error($db); } } - print Get_attach_files($db,$objp->rowid,$objp->label); + print Get_attach_files($db,$objp->rowid,$num,$objp->label); print ""; if ($objp->amount < 0) @@ -608,10 +608,11 @@ $db->close(); /*Function to generate the HTML code used to show the file name & download link attached to the Item covered by the bank line * @param $db Object database object * @param $bankId int bank line id - * @param $label + * @param $num int bank statement + * @param $label string label used to optimise the sql querry * */ -function Get_attach_files($db, $bankId,$label=''){ +function Get_attach_files($db, $bankId,$num,$label=''){ $out=''; global$conf; $sql='SELECT u.url_id, u.type,ff.rowid as id , ff.`ref` AS reff, f.facnumber AS `ref`,';