26 if (!defined(
'NOSESSION')) define(
'NOSESSION',
'1');
28 $sapi_type = php_sapi_name();
29 $script_file = basename(__FILE__);
33 if (substr($sapi_type, 0, 3) ==
'cgi') {
34 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
39 require_once $path.
"../../htdocs/master.inc.php";
41 require_once DOL_DOCUMENT_ROOT.
"/compta/facture/class/facture.class.php";
42 require_once DOL_DOCUMENT_ROOT.
"/core/modules/facture/modules_facture.php";
43 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
44 require_once DOL_DOCUMENT_ROOT.
'/core/lib/invoice2.lib.php';
50 $version = DOL_VERSION;
59 dol_syslog($script_file.
" launched with arg ".join(
',', $argv));
62 if (!isset($argv[1])) {
67 $diroutputpdf = $conf->facture->dir_output.
'/temp';
72 $fileprefix =
'mergedpdf';
74 foreach ($argv as $key => $value) {
78 if (preg_match(
'/^lang=/i', $value)) {
80 $valarray = explode(
'=', $value);
81 $newlangid = $valarray[1];
82 print 'Use language '.$newlangid.
".\n";
84 if (preg_match(
'/^prefix=/i', $value)) {
86 $valarray = explode(
'=', $value);
87 $fileprefix = $valarray[1];
88 print 'Use prefix for filename '.$fileprefix.
".\n";
91 if (preg_match(
'/^regenerate=(.*)/i', $value, $reg)) {
92 if (!in_array($reg[1], array(
'',
'0',
'no'))) {
94 $regenerate = $reg[1];
95 print 'Regeneration of PDF is requested with template '.$regenerate.
"\n";
99 if ($value ==
'filter=all') {
101 $option .= (empty($option) ?
'' :
'_').
'all';
104 print 'Rebuild PDF for all invoices'.
"\n";
107 if ($value ==
'filter=date') {
109 $option .= (empty($option) ?
'' :
'_').
'date_'.$argv[$key + 1].
'_'.$argv[$key + 2];
114 print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,
'day',
'gmt').
" and ".
dol_print_date($datebeforedate,
'day',
'gmt').
".\n";
117 if ($value ==
'filter=payments') {
119 $option .= (empty($option) ?
'' :
'_').
'payments_'.$argv[$key + 1].
'_'.$argv[$key + 2];
120 $filter[] =
'payments';
124 if (empty($paymentdateafter) || empty($paymentdatebefore)) {
125 print 'Error: Bad date format or value'.
"\n";
128 print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,
'day',
'gmt').
" and ".
dol_print_date($paymentdatebefore,
'day',
'gmt').
".\n";
131 if ($value ==
'filter=nopayment') {
133 $option .= (empty($option) ?
'' :
'_').
'nopayment';
134 $filter[] =
'nopayment';
136 print 'Rebuild PDF for invoices with no payment done yet.'.
"\n";
139 if ($value ==
'filter=bank') {
141 $option .= (empty($option) ?
'' :
'_').
'bank_'.$argv[$key + 1];
144 $paymentonbankref = $argv[$key + 1];
145 $bankaccount =
new Account($db);
146 $result = $bankaccount->fetch(0, $paymentonbankref);
148 print 'Error: Bank account with ref "'.$paymentonbankref.
'" not found'.
"\n";
151 $paymentonbankid = $bankaccount->id;
152 print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref.
"\n";
155 if ($value ==
'filter=nodeposit') {
157 $option .= (empty($option) ?
'' :
'_').
'nodeposit';
158 $filter[] =
'nodeposit';
160 print 'Exclude deposit invoices'.
"\n";
162 if ($value ==
'filter=noreplacement') {
164 $option .= (empty($option) ?
'' :
'_').
'noreplacement';
165 $filter[] =
'noreplacement';
167 print 'Exclude replacement invoices'.
"\n";
169 if ($value ==
'filter=nocreditnote') {
171 $option .= (empty($option) ?
'' :
'_').
'nocreditnote';
172 $filter[] =
'nocreditnote';
174 print 'Exclude credit note invoices'.
"\n";
177 if ($value ==
'filter=excludethirdparties') {
179 $filter[] =
'excludethirdparties';
181 $thirdpartiesid = explode(
',', $argv[$key + 1]);
182 print 'Exclude thirdparties with id in list ('.join(
',', $thirdpartiesid).
").\n";
184 $option .= (empty($option) ?
'' :
'_').
'excludethirdparties'.join(
'-', $thirdpartiesid);
186 if ($value ==
'filter=onlythirdparties') {
188 $filter[] =
'onlythirdparties';
190 $thirdpartiesid = explode(
',', $argv[$key + 1]);
191 print 'Only thirdparties with id in list ('.join(
',', $thirdpartiesid).
").\n";
193 $option .= (empty($option) ?
'' :
'_').
'onlythirdparty'.join(
'-', $thirdpartiesid);
196 if (!$found && preg_match(
'/filter=/i', $value)) {
203 if (empty($option) && count($filter) <= 0) {
208 if (in_array(
'payments', $filter) && in_array(
'nopayment', $filter)) {
212 if (in_array(
'bank', $filter) && in_array(
'nopayment', $filter)) {
219 $result =
rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, 1, $regenerate, $option, $paymentonbankid, $thirdpartiesid, $fileprefix);
225 print '--- end ok'.
"\n";
228 print '--- end error code='.$error.
"\n";
244 print "Rebuild PDF files for some invoices and merge PDF files into one.\n";
246 print "To build/merge PDF for invoices in a date range:\n";
247 print "Usage: ".$script_file.
" filter=date dateafter datebefore\n";
248 print "To build/merge PDF for invoices with at least one payment in a date range:\n";
249 print "Usage: ".$script_file.
" filter=payments dateafter datebefore\n";
250 print "To build/merge PDF for invoices with at least one payment onto a bank account:\n";
251 print "Usage: ".$script_file.
" filter=bank bankref\n";
252 print "To build/merge PDF for all invoices, use filter=all\n";
253 print "Usage: ".$script_file.
" filter=all\n";
254 print "To build/merge PDF for invoices with no payments, use filter=nopayment\n";
255 print "Usage: ".$script_file.
" filter=nopayment\n";
256 print "To exclude credit notes, use filter=nocreditnote\n";
257 print "To exclude replacement invoices, use filter=noreplacement\n";
258 print "To exclude deposit invoices, use filter=nodeposit\n";
259 print "To exclude some thirdparties, use filter=excludethirdparties id1,id2...\n";
260 print "To limit to some thirdparties, use filter=onlythirdparties id1,id2...\n";
261 print "To regenerate existing PDF, use regenerate=templatename\n";
262 print "To generate invoices in a language, use lang=xx_XX\n";
263 print "To set prefix of generated file name, use prefix=myfileprefix\n";
265 print "Example: ".$script_file.
" filter=payments 20080101 20081231 lang=fr_FR regenerate=crabe\n";
266 print "Example: ".$script_file.
" filter=all lang=en_US\n";
268 print "Note that some filters can be cumulated.\n";
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Class to manage bank accounts.
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.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
usage($path, $script_file)
script cron usage