From 28c28bd21747e5eba0b9593945413c43390543d3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Jul 2013 20:56:43 +0200 Subject: [PATCH] New: Add option excludethirdparties and onlythirdparties into merge pdf scripts. --- ChangeLog | 1 + htdocs/core/lib/invoice2.lib.php | 14 ++++++++++---- scripts/invoices/rebuild_merge_pdf.php | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index e586d1ac36a..1de4a404620 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,7 @@ For users: - New: [ task #286 ] Enhance rounding function of prices to allow round of sum instead of sum of rounding. - New: Can add an event automatically when a projet is create. - New: Add option MAIN_GENERATE_DOCUMENT_WITH_PICTURE. +- New: Add option excludethirdparties and onlythirdparties into merge pdf scripts. - Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error). For translators: diff --git a/htdocs/core/lib/invoice2.lib.php b/htdocs/core/lib/invoice2.lib.php index 7a90d55ad5c..dcf98c9a70e 100644 --- a/htdocs/core/lib/invoice2.lib.php +++ b/htdocs/core/lib/invoice2.lib.php @@ -43,10 +43,10 @@ require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'); * @param int $regenerate ''=Use existing PDF files, 'nameofpdf'=Regenerate all PDF files using the template * @param string $option Suffix to add into file name of generated PDF * @param string $paymentbankid Only if payment on this bank account id - * @param array $excludethirdpartiesid Exclude thirdparties from select + * @param array $thirdpartiesid List of thirdparties id when using filter excludethirdpartiesid or onlythirdpartiesid * @return int Error code */ -function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $option='', $paymentbankid='', $excludethirdpartiesid='') +function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $option='', $paymentbankid='', $thirdpartiesid='') { $sql = "SELECT DISTINCT f.rowid, f.facnumber"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; @@ -112,11 +112,17 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte else $sqlwhere.=" AND"; $sqlwhere.=' type <> 2'; } - if (in_array('excludethirdparties',$filter) && is_array($excludethirdpartiesid)) + if (in_array('excludethirdparties',$filter) && is_array($thirdpartiesid)) { if (empty($sqlwhere)) $sqlwhere=' WHERE '; else $sqlwhere.=" AND"; - $sqlwhere.=' f.fk_soc NOT IN ('.join(',',$excludethirdpartiesid).')'; + $sqlwhere.=' f.fk_soc NOT IN ('.join(',',$thirdpartiesid).')'; + } + if (in_array('onlythirdparties',$filter) && is_array($thirdpartiesid)) + { + if (empty($sqlwhere)) $sqlwhere=' WHERE '; + else $sqlwhere.=" AND"; + $sqlwhere.=' f.fk_soc IN ('.join(',',$thirdpartiesid).')'; } if ($sqlwhere) $sql.=$sqlwhere; if ($sqlorder) $sql.=$sqlorder; diff --git a/scripts/invoices/rebuild_merge_pdf.php b/scripts/invoices/rebuild_merge_pdf.php index fca2a32ce13..213c52c034f 100755 --- a/scripts/invoices/rebuild_merge_pdf.php +++ b/scripts/invoices/rebuild_merge_pdf.php @@ -188,8 +188,16 @@ foreach ($argv as $key => $value) $found=true; $filter[]='excludethirdparties'; - $excludethirdpartiesid=explode(',',$argv[$key+1]); - print 'Exclude thirdparties with id in list ('.join(',',$excludethirdpartiesid).").\n"; + $thirdpartiesid=explode(',',$argv[$key+1]); + print 'Exclude thirdparties with id in list ('.join(',',$thirdpartiesid).").\n"; + } + if ($value == 'filter=onlythirdparties') + { + $found=true; + $filter[]='onlythirdparties'; + + $thirdpartiesid=explode(',',$argv[$key+1]); + print 'Only thirdparties with id in list ('.join(',',$thirdpartiesid).").\n"; } if (! $found && preg_match('/filter=/i',$value)) @@ -220,7 +228,7 @@ if (in_array('bank',$filter) && in_array('nopayment',$filter)) // Define SQL and SQL request to select invoices // Use $filter, $dateafterdate, datebeforedate, $paymentdateafter, $paymentdatebefore -$result=rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $excludethirdpartiesid); +$result=rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $thirdpartiesid); @@ -268,6 +276,7 @@ function usage() print "To exclude replacement invoices, use filter=noreplacement\n"; print "To exclude deposit invoices, use filter=nodeposit\n"; print "To exclude some thirdparties, use filter=excludethirdparties id1,id2...\n"; + print "To limit to some thirdparties, use filter=onlythirdparties id1,id2...\n"; print "To regenerate existing PDF, use regenerate=crabe\n"; print "To generate invoices in a language, use lang=xx_XX\n"; print "\n";