New: Add option excludethirdparties and onlythirdparties into merge pdf

scripts.
This commit is contained in:
Laurent Destailleur 2013-07-15 20:56:43 +02:00
parent dd10ff8a11
commit 28c28bd217
3 changed files with 23 additions and 7 deletions

View File

@ -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: [ 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: Can add an event automatically when a projet is create.
- New: Add option MAIN_GENERATE_DOCUMENT_WITH_PICTURE. - 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). - Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error).
For translators: For translators:

View File

@ -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 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 $option Suffix to add into file name of generated PDF
* @param string $paymentbankid Only if payment on this bank account id * @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 * @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 = "SELECT DISTINCT f.rowid, f.facnumber";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $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"; else $sqlwhere.=" AND";
$sqlwhere.=' type <> 2'; $sqlwhere.=' type <> 2';
} }
if (in_array('excludethirdparties',$filter) && is_array($excludethirdpartiesid)) if (in_array('excludethirdparties',$filter) && is_array($thirdpartiesid))
{ {
if (empty($sqlwhere)) $sqlwhere=' WHERE '; if (empty($sqlwhere)) $sqlwhere=' WHERE ';
else $sqlwhere.=" AND"; 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 ($sqlwhere) $sql.=$sqlwhere;
if ($sqlorder) $sql.=$sqlorder; if ($sqlorder) $sql.=$sqlorder;

View File

@ -188,8 +188,16 @@ foreach ($argv as $key => $value)
$found=true; $found=true;
$filter[]='excludethirdparties'; $filter[]='excludethirdparties';
$excludethirdpartiesid=explode(',',$argv[$key+1]); $thirdpartiesid=explode(',',$argv[$key+1]);
print 'Exclude thirdparties with id in list ('.join(',',$excludethirdpartiesid).").\n"; 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)) 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 // Define SQL and SQL request to select invoices
// Use $filter, $dateafterdate, datebeforedate, $paymentdateafter, $paymentdatebefore // 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 replacement invoices, use filter=noreplacement\n";
print "To exclude deposit invoices, use filter=nodeposit\n"; print "To exclude deposit invoices, use filter=nodeposit\n";
print "To exclude some thirdparties, use filter=excludethirdparties id1,id2...\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 regenerate existing PDF, use regenerate=crabe\n";
print "To generate invoices in a language, use lang=xx_XX\n"; print "To generate invoices in a language, use lang=xx_XX\n";
print "\n"; print "\n";