New: Add option to exclude some thirdparties

This commit is contained in:
Laurent Destailleur 2013-07-15 18:44:59 +02:00
parent d637212dce
commit 17f3d98fb3
2 changed files with 19 additions and 2 deletions

View File

@ -43,9 +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
* @return int Error code
*/
function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $option='', $paymentbankid='')
function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $option='', $paymentbankid='', $excludethirdpartiesid='')
{
$sql = "SELECT DISTINCT f.rowid, f.facnumber";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
@ -111,6 +112,12 @@ 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 (empty($sqlwhere)) $sqlwhere=' WHERE ';
else $sqlwhere.=" AND";
$sqlwhere.=' f.fk_soc NOT IN ('.join(',',$excludethirdpartiesid).')';
}
if ($sqlwhere) $sql.=$sqlwhere;
if ($sqlorder) $sql.=$sqlorder;

View File

@ -183,6 +183,15 @@ foreach ($argv as $key => $value)
print 'Exclude credit note invoices'."\n";
}
if ($value == 'filter=excludethirdparties')
{
$found=true;
$filter[]='excludethirdparties';
$excludethirdpartiesid=explode(',',$argv[$key+1]);
print 'Exclude thirdparties with id in list ('.join(',',$excludethirdpartiesid).").\n";
}
if (! $found && preg_match('/filter=/i',$value))
{
usage();
@ -211,7 +220,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);
$result=rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $excludethirdpartiesid);
@ -258,6 +267,7 @@ function usage()
print "To exclude credit notes, use filter=nocreditnote\n";
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 regenerate existing PDF, use regenerate=crabe\n";
print "To generate invoices in a language, use lang=xx_XX\n";
print "\n";