Fix: Restore suffix
This commit is contained in:
parent
f3adcc311d
commit
70b7cb1fa3
@ -29,22 +29,23 @@ require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to build a compiled PDF
|
* Function to build a compiled PDF
|
||||||
*
|
*
|
||||||
* @param DoliDB $db Database handler
|
* @param DoliDB $db Database handler
|
||||||
* @param Translate $langs Object langs
|
* @param Translate $langs Object langs
|
||||||
* @param Conf $conf Object conf
|
* @param Conf $conf Object conf
|
||||||
* @param string $diroutputpdf Dir to output file
|
* @param string $diroutputpdf Dir to output file
|
||||||
* @param string $newlangid Lang id
|
* @param string $newlangid Lang id
|
||||||
* @param array $filter Array with filters
|
* @param array $filter Array with filters
|
||||||
* @param date $dateafterdate Invoice after date
|
* @param date $dateafterdate Invoice after date
|
||||||
* @param date $datebeforedate Invoice before date
|
* @param date $datebeforedate Invoice before date
|
||||||
* @param date $paymentdateafter Payment after date
|
* @param date $paymentdateafter Payment after date
|
||||||
* @param date $paymentdatebefore Payment before date
|
* @param date $paymentdatebefore Payment before date
|
||||||
* @param int $usestdout Add information onto standard output
|
* @param int $usestdout Add information onto standard output
|
||||||
* @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
|
||||||
* @return int Error code
|
* @param string $option Suffix to add into file name of generated PDF
|
||||||
|
* @return int Error code
|
||||||
*/
|
*/
|
||||||
function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0)
|
function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $option='')
|
||||||
{
|
{
|
||||||
$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";
|
||||||
@ -104,19 +105,19 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
|
|||||||
}
|
}
|
||||||
if ($sqlwhere) $sql.=$sqlwhere;
|
if ($sqlwhere) $sql.=$sqlwhere;
|
||||||
if ($sqlorder) $sql.=$sqlorder;
|
if ($sqlorder) $sql.=$sqlorder;
|
||||||
|
|
||||||
//print $sql; exit;
|
//print $sql; exit;
|
||||||
dol_syslog("scripts/invoices/rebuild_merge.php: sql=".$sql);
|
dol_syslog("scripts/invoices/rebuild_merge.php: sql=".$sql);
|
||||||
|
|
||||||
if ($usestdout) print '--- start'."\n";
|
if ($usestdout) print '--- start'."\n";
|
||||||
|
|
||||||
// Start of transaction
|
// Start of transaction
|
||||||
//$db->begin();
|
//$db->begin();
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
$result = 0;
|
$result = 0;
|
||||||
$files = array() ; // liste les fichiers
|
$files = array() ; // liste les fichiers
|
||||||
|
|
||||||
dol_syslog("scripts/invoices/rebuild_merge.php sql=".$sql);
|
dol_syslog("scripts/invoices/rebuild_merge.php sql=".$sql);
|
||||||
if ( $resql=$db->query($sql) )
|
if ( $resql=$db->query($sql) )
|
||||||
{
|
{
|
||||||
@ -125,16 +126,16 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
|
|||||||
$oldemail = '';
|
$oldemail = '';
|
||||||
$message = '';
|
$message = '';
|
||||||
$total = '';
|
$total = '';
|
||||||
|
|
||||||
if ($num)
|
if ($num)
|
||||||
{
|
{
|
||||||
// First loop on each resultset to build PDF
|
// First loop on each resultset to build PDF
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
while ($cpt < $num)
|
while ($cpt < $num)
|
||||||
{
|
{
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
$fac = new Facture($db);
|
$fac = new Facture($db);
|
||||||
$result=$fac->fetch($obj->rowid);
|
$result=$fac->fetch($obj->rowid);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
@ -157,35 +158,35 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
|
|||||||
else {
|
else {
|
||||||
if ($usestdout) print "PDF for invoice ".$obj->facnumber." already exists\n";
|
if ($usestdout) print "PDF for invoice ".$obj->facnumber." already exists\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add file into files array
|
// Add file into files array
|
||||||
$files[] = $filename;
|
$files[] = $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result <= 0)
|
if ($result <= 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
if ($usestdout) print "Error: Failed to build PDF for invoice ".$fac->ref."\n";
|
if ($usestdout) print "Error: Failed to build PDF for invoice ".$fac->ref."\n";
|
||||||
else dol_syslog("Failed to build PDF for invoice ".$fac->ref, LOG_ERR);
|
else dol_syslog("Failed to build PDF for invoice ".$fac->ref, LOG_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cpt++;
|
$cpt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Define format of output PDF
|
|
||||||
|
// Define format of output PDF
|
||||||
$formatarray=pdf_getFormat();
|
$formatarray=pdf_getFormat();
|
||||||
$page_largeur = $formatarray['width'];
|
$page_largeur = $formatarray['width'];
|
||||||
$page_hauteur = $formatarray['height'];
|
$page_hauteur = $formatarray['height'];
|
||||||
$format = array($page_largeur,$page_hauteur);
|
$format = array($page_largeur,$page_hauteur);
|
||||||
|
|
||||||
if ($usestdout) print "Using output PDF format ".join('x',$format)."\n";
|
if ($usestdout) print "Using output PDF format ".join('x',$format)."\n";
|
||||||
else dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR);
|
else dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR);
|
||||||
|
|
||||||
|
|
||||||
// Now, build a merged files with all files in $files array
|
// Now, build a merged files with all files in $files array
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
|
|
||||||
// Create empty PDF
|
// Create empty PDF
|
||||||
$pdf=pdf_getInstance($format);
|
$pdf=pdf_getInstance($format);
|
||||||
if (class_exists('TCPDF'))
|
if (class_exists('TCPDF'))
|
||||||
@ -194,11 +195,11 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
|
|||||||
$pdf->setPrintFooter(false);
|
$pdf->setPrintFooter(false);
|
||||||
}
|
}
|
||||||
$pdf->SetFont(pdf_getPDFFont($outputlangs));
|
$pdf->SetFont(pdf_getPDFFont($outputlangs));
|
||||||
|
|
||||||
if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
|
if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
|
||||||
//$pdf->SetCompression(false);
|
//$pdf->SetCompression(false);
|
||||||
|
|
||||||
|
|
||||||
//$pdf->Open();
|
//$pdf->Open();
|
||||||
//$pdf->AddPage();
|
//$pdf->AddPage();
|
||||||
//$title=$langs->trans("BillsCustomersUnpaid");
|
//$title=$langs->trans("BillsCustomersUnpaid");
|
||||||
@ -224,12 +225,12 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
|
|||||||
|
|
||||||
// Create output dir if not exists
|
// Create output dir if not exists
|
||||||
dol_mkdir($diroutputpdf);
|
dol_mkdir($diroutputpdf);
|
||||||
|
|
||||||
// Save merged file
|
// Save merged file
|
||||||
$filename='mergedpdf';
|
$filename='mergedpdf';
|
||||||
|
|
||||||
if (! empty($option)) $filename.='_'.$option;
|
if (! empty($option)) $filename.='_'.$option;
|
||||||
|
|
||||||
if ($pagecount)
|
if ($pagecount)
|
||||||
{
|
{
|
||||||
$file=$diroutputpdf.'/'.$filename.'.pdf';
|
$file=$diroutputpdf.'/'.$filename.'.pdf';
|
||||||
@ -237,7 +238,7 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
|
|||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($usestdout) print "Merged PDF has been built in ".$file."\n";
|
if ($usestdout) print "Merged PDF has been built in ".$file."\n";
|
||||||
$result = 1;
|
$result = 1;
|
||||||
}
|
}
|
||||||
@ -254,7 +255,7 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
|
|||||||
dol_syslog("scripts/invoices/rebuild_merge.php: Error");
|
dol_syslog("scripts/invoices/rebuild_merge.php: Error");
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error) return -1;
|
if ($error) return -1;
|
||||||
else return $result;
|
else return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,6 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
|
|||||||
// Include Dolibarr environment
|
// Include Dolibarr environment
|
||||||
require_once($path."../../htdocs/master.inc.php");
|
require_once($path."../../htdocs/master.inc.php");
|
||||||
// After this $db is an opened handler to database. We close it at end of file.
|
// After this $db is an opened handler to database. We close it at end of file.
|
||||||
require_once(DOL_DOCUMENT_ROOT."/cron/functions_cron.lib.php");
|
|
||||||
require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
|
require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT."/core/modules/facture/modules_facture.php");
|
require_once(DOL_DOCUMENT_ROOT."/core/modules/facture/modules_facture.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
|
require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
|
||||||
@ -179,7 +178,7 @@ if (in_array('payments',$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);
|
$result=rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user