25 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
50 function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate = 0, $filesuffix =
'', $paymentbankid =
'', $thirdpartiesid =
'', $fileprefix =
'mergedpdf')
52 $sql =
"SELECT DISTINCT f.rowid, f.ref";
53 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
56 if (in_array(
'all', $filter))
58 $sqlorder =
" ORDER BY f.ref ASC";
60 if (in_array(
'date', $filter))
62 if (empty($sqlwhere)) $sqlwhere =
' WHERE ';
63 else $sqlwhere .=
" AND";
64 $sqlwhere .=
" f.fk_statut > 0";
65 $sqlwhere .=
" AND f.datef >= '".$db->idate($dateafterdate).
"'";
66 $sqlwhere .=
" AND f.datef <= '".$db->idate($datebeforedate).
"'";
67 $sqlorder =
" ORDER BY f.datef ASC";
69 if (in_array(
'nopayment', $filter))
71 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
72 if (empty($sqlwhere)) $sqlwhere =
' WHERE ';
73 else $sqlwhere .=
" AND";
74 $sqlwhere .=
" f.fk_statut > 0";
75 $sqlwhere .=
" AND pf.fk_paiement IS NULL";
77 if (in_array(
'payments', $filter) || in_array(
'bank', $filter))
79 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
80 if (in_array(
'bank', $filter)) $sql .=
", ".MAIN_DB_PREFIX.
"bank as b";
81 if (empty($sqlwhere)) $sqlwhere =
' WHERE ';
82 else $sqlwhere .=
" AND";
83 $sqlwhere .=
" f.fk_statut > 0";
84 $sqlwhere .=
" AND f.rowid = pf.fk_facture";
85 $sqlwhere .=
" AND pf.fk_paiement = p.rowid";
86 if (in_array(
'payments', $filter))
88 $sqlwhere .=
" AND p.datep >= '".$db->idate($paymentdateafter).
"'";
89 $sqlwhere .=
" AND p.datep <= '".$db->idate($paymentdatebefore).
"'";
91 if (in_array(
'bank', $filter))
93 $sqlwhere .=
" AND p.fk_bank = b.rowid";
94 $sqlwhere .=
" AND b.fk_account = ".$paymentbankid;
96 $sqlorder =
" ORDER BY p.datep ASC";
98 if (in_array(
'nodeposit', $filter))
100 if (empty($sqlwhere)) $sqlwhere =
' WHERE ';
101 else $sqlwhere .=
" AND";
102 $sqlwhere .=
' type <> 3';
104 if (in_array(
'noreplacement', $filter))
106 if (empty($sqlwhere)) $sqlwhere =
' WHERE ';
107 else $sqlwhere .=
" AND";
108 $sqlwhere .=
' type <> 1';
110 if (in_array(
'nocreditnote', $filter))
112 if (empty($sqlwhere)) $sqlwhere =
' WHERE ';
113 else $sqlwhere .=
" AND";
114 $sqlwhere .=
' type <> 2';
116 if (in_array(
'excludethirdparties', $filter) && is_array($thirdpartiesid))
118 if (empty($sqlwhere)) $sqlwhere =
' WHERE ';
119 else $sqlwhere .=
" AND";
120 $sqlwhere .=
' f.fk_soc NOT IN ('.join(
',', $thirdpartiesid).
')';
122 if (in_array(
'onlythirdparties', $filter) && is_array($thirdpartiesid))
124 if (empty($sqlwhere)) $sqlwhere =
' WHERE ';
125 else $sqlwhere .=
" AND";
126 $sqlwhere .=
' f.fk_soc IN ('.join(
',', $thirdpartiesid).
')';
128 if ($sqlwhere) $sql .= $sqlwhere;
129 if ($sqlorder) $sql .= $sqlorder;
132 dol_syslog(
"scripts/invoices/rebuild_merge.php:", LOG_DEBUG);
134 if ($usestdout)
print '--- start'.
"\n";
143 dol_syslog(
"scripts/invoices/rebuild_merge.php", LOG_DEBUG);
144 if (
$resql = $db->query($sql))
146 $num = $db->num_rows(
$resql);
159 $obj = $db->fetch_object(
$resql);
162 $result = $fac->fetch($obj->rowid);
165 $outputlangs = $langs;
166 if (!empty($newlangid))
168 if ($outputlangs->defaultlang != $newlangid)
171 $outputlangs->setDefaultLang($newlangid);
174 $filename = $conf->facture->dir_output.
'/'.$fac->ref.
'/'.$fac->ref.
'.pdf';
177 if ($usestdout)
print "Build PDF for invoice ".$obj->ref.
" - Lang = ".$outputlangs->defaultlang.
"\n";
178 $result = $fac->generateDocument($regenerate ? $regenerate : $fac->modelpdf, $outputlangs);
180 if ($usestdout)
print "PDF for invoice ".$obj->ref.
" already exists\n";
184 $files[] = $filename;
190 if ($usestdout)
print "Error: Failed to build PDF for invoice ".($fac->ref ? $fac->ref :
' id '.$obj->rowid).
"\n";
191 else dol_syslog(
"Failed to build PDF for invoice ".($fac->ref ? $fac->ref :
' id '.$obj->rowid), LOG_ERR);
200 $page_largeur = $formatarray[
'width'];
201 $page_hauteur = $formatarray[
'height'];
202 $format = array($page_largeur, $page_hauteur);
204 if ($usestdout)
print "Using output PDF format ".join(
'x', $format).
"\n";
205 else dol_syslog(
"Using output PDF format ".join(
'x', $format), LOG_ERR);
213 if (class_exists(
'TCPDF'))
215 $pdf->setPrintHeader(
false);
216 $pdf->setPrintFooter(
false);
220 if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(
false);
224 foreach ($files as $file)
226 if ($usestdout)
print "Merge PDF file for invoice ".$file.
"\n";
227 else dol_syslog(
"Merge PDF file for invoice ".$file);
230 $pagecount = $pdf->setSourceFile($file);
231 for ($i = 1; $i <= $pagecount; $i++)
233 $tplidx = $pdf->importPage($i);
234 $s = $pdf->getTemplatesize($tplidx);
235 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
236 $pdf->useTemplate($tplidx);
244 $filename = $fileprefix;
245 if (empty($filename)) $filename =
'mergedpdf';
246 if (!empty($filesuffix)) $filename .=
'_'.$filesuffix;
247 $file = $diroutputpdf.
'/'.$filename.
'.pdf';
249 if (!$error && $pagecount)
251 $pdf->Output($file,
'F');
252 if (!empty($conf->global->MAIN_UMASK))
253 @chmod($file, octdec($conf->global->MAIN_UMASK));
258 if (!$error)
print "Merged PDF has been built in ".$file.
"\n";
259 else print "Can't build PDF ".$file.
"\n";
264 if ($usestdout)
print "No invoices found for criteria.\n";
265 else dol_syslog(
"No invoices found for criteria");
270 dol_syslog(
"scripts/invoices/rebuild_merge.php: Error");
274 if ($error)
return -1;
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $filesuffix= '', $paymentbankid= '', $thirdpartiesid= '', $fileprefix= 'mergedpdf')
Function to build a compiled PDF.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage translations.
dol_is_file($pathoffile)
Return if path is a file.
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage invoices.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)