127 public function write_file($_dir, $month, $year, $outputlangs)
130 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
132 global $conf, $hookmanager, $langs, $user;
136 $socid = $user->socid;
139 if (!is_object($outputlangs)) {
140 $outputlangs = $langs;
144 $outputlangs->charset_output =
'ISO-8859-1';
147 $this->month = $month;
149 $dir = $_dir.
'/'.$year;
154 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
159 $month = sprintf(
"%02d", $month);
160 $year = sprintf(
"%04d", $year);
162 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
163 switch ($this->doc_type) {
165 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
168 $file = $dir.
"/supplier_payments-".$year.
"-".$month.
".pdf";
174 if (!is_object($hookmanager)) {
175 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
178 $hookmanager->initHooks(array(
'pdfgeneration'));
179 $parameters = array(
'file'=>$file,
'object'=>$this,
'outputlangs'=>$outputlangs);
181 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $this, $action);
186 if (class_exists(
'TCPDF')) {
187 $pdf->setPrintHeader(
false);
188 $pdf->setPrintFooter(
false);
196 $sql =
"SELECT p.rowid as prowid";
197 switch ($this->doc_type) {
199 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
202 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
206 $sql .=
" AND p.entity = ".$conf->entity;
207 $result = $this->db->query($sql);
209 $numpaiement = $this->db->num_rows($result);
213 switch ($this->doc_type) {
215 $sql =
"SELECT p.datep as dp, f.ref";
216 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
217 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
218 $sql .=
", pf.amount as pf_amount";
219 if (isModEnabled(
"banque")) {
220 $sql .=
", ba.ref as bankaccount";
222 $sql .=
", p.rowid as prowid";
223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
224 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f,";
225 $sql .=
" ".MAIN_DB_PREFIX.
"paiement_facture as pf,";
226 if (isModEnabled(
"banque")) {
227 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
229 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
230 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
231 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
233 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
234 if (isModEnabled(
"banque")) {
235 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
237 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
239 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
240 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
242 if (!empty($socid)) {
243 $sql .=
" AND s.rowid = ".((int) $socid);
247 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiement ASC";
249 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiement ASC";
253 $sql =
"SELECT p.datep as dp, f.ref as ref";
254 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
255 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
256 $sql .=
", pf.amount as pf_amount";
257 if (isModEnabled(
"banque")) {
258 $sql .=
", ba.ref as bankaccount";
260 $sql .=
", p.rowid as prowid";
261 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
262 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f,";
263 $sql .=
" ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf,";
264 if (isModEnabled(
"banque")) {
265 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
267 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
268 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
269 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
271 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facturefourn = f.rowid AND pf.fk_paiementfourn = p.rowid";
272 if (isModEnabled(
"banque")) {
273 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
275 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
277 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
278 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
280 if (!empty($socid)) {
281 $sql .=
" AND s.rowid = ".((int) $socid);
285 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiementfourn ASC";
287 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiementfourn ASC";
292 dol_syslog(get_class($this).
"::write_file", LOG_DEBUG);
293 $result = $this->db->query($sql);
295 $num = $this->db->num_rows($result);
299 $objp = $this->db->fetch_object($result);
301 $lines[$i][0] = $objp->ref;
302 $lines[$i][1] =
dol_print_date($this->db->jdate($objp->dp),
"day",
false, $outputlangs,
true);
303 $lines[$i][2] = $langs->transnoentities(
"PaymentTypeShort".$objp->paiement_code);
304 $lines[$i][3] = $objp->num_payment;
305 $lines[$i][4] =
price($objp->paiement_amount);
306 $lines[$i][5] =
price($objp->facture_amount);
307 $lines[$i][6] =
price($objp->pf_amount);
308 $lines[$i][7] = $objp->prowid;
309 $lines[$i][8] = $objp->bankaccount;
310 $lines[$i][9] = $objp->paiement_amount;
317 $pages = intval(($num + $numpaiement) / $this->line_per_page);
319 if ((($num + $numpaiement) % $this->line_per_page) > 0) {
330 $pdf->SetDrawColor(128, 128, 128);
332 $pdf->SetTitle($outputlangs->transnoentities(
"Payments"));
333 $pdf->SetSubject($outputlangs->transnoentities(
"Payments"));
334 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
335 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
338 $pdf->SetCompression(
false);
341 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
342 $pdf->SetAutoPageBreak(1, 0);
347 $this->
_pagehead($pdf, $pagenb, 1, $outputlangs);
348 $pdf->SetFont(
'',
'', 9);
349 $pdf->MultiCell(0, 3,
'');
350 $pdf->SetTextColor(0, 0, 0);
353 $this->
Body($pdf, 1, $lines, $outputlangs);
355 if (method_exists($pdf,
'AliasNbPages')) {
356 $pdf->AliasNbPages();
361 $pdf->Output($file,
'F');
364 if (!is_object($hookmanager)) {
365 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
368 $hookmanager->initHooks(array(
'pdfgeneration'));
369 $parameters = array(
'file'=>$file,
'object'=>$this,
'outputlangs'=>$outputlangs);
371 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
373 $this->error = $hookmanager->error;
374 $this->errors = $hookmanager->errors;
379 $this->result = array(
'fullpath'=>$file);
394 protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
397 global $langs, $conf;
404 $title = $conf->global->MAIN_INFO_SOCIETE_NOM;
405 switch ($this->doc_type) {
407 $title .=
' - '.$outputlangs->transnoentities(
"ListOfCustomerPayments");
410 $title .=
' - '.$outputlangs->transnoentities(
"ListOfSupplierPayments");
413 $title .=
' - '.dol_print_date(
dol_mktime(0, 0, 0, $this->month, 1, $this->year),
"%B %Y",
false, $outputlangs,
true);
414 $pdf->SetFont(
'',
'B', $default_font_size + 1);
415 $pdf->SetXY($this->marge_gauche, 10);
416 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 2, $title, 0,
'C');
418 $pdf->SetFont(
'',
'', $default_font_size);
420 $pdf->SetXY($this->posxdate, 16);
421 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"DateBuild").
" : ".
dol_print_date(time(),
"day",
false, $outputlangs,
true), 0,
'L');
423 $pdf->SetXY($this->posxdate + 100, 16);
424 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"Page").
" : ".$page, 0,
'R');
428 $pdf->SetXY($this->posxdate, $this->tab_top + 2);
429 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate, 2,
'Date');
431 $pdf->line($this->posxpaymenttype - 1, $this->tab_top, $this->posxpaymenttype - 1, $this->tab_top + $this->tab_height + 10);
432 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 2);
433 $pdf->MultiCell($this->posxinvoice - $this->posxpaymenttype, 2, $outputlangs->transnoentities(
"PaymentMode"), 0,
'L');
435 $pdf->line($this->posxinvoice - 1, $this->tab_top, $this->posxinvoice - 1, $this->tab_top + $this->tab_height + 10);
436 $pdf->SetXY($this->posxinvoice, $this->tab_top + 2);
437 $pdf->MultiCell($this->posxbankaccount - $this->posxinvoice, 2, $outputlangs->transnoentities(
"Invoice"), 0,
'L');
439 $pdf->line($this->posxbankaccount - 1, $this->tab_top, $this->posxbankaccount - 1, $this->tab_top + $this->tab_height + 10);
440 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 2);
441 $pdf->MultiCell($this->posxinvoiceamount - $this->posxbankaccount, 2, $outputlangs->transnoentities(
"Account"), 0,
'L');
444 $pdf->line($this->posxinvoiceamount - 1, $this->tab_top, $this->posxinvoiceamount - 1, $this->tab_top + $this->tab_height + 10);
445 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 2);
446 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, 2, $outputlangs->transnoentities(
"AmountInvoice"), 0,
'R');
448 $pdf->line($this->posxpaymentamount - 1, $this->tab_top, $this->posxpaymentamount - 1, $this->tab_top + $this->tab_height + 10);
449 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 2);
450 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount - 1, 2, $outputlangs->transnoentities(
"AmountPayment"), 0,
'R');
452 $pdf->line($this->marge_gauche, $this->tab_top + 10, $this->page_largeur - $this->marge_droite, $this->tab_top + 10);
454 $pdf->Rect($this->marge_gauche, $this->tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->tab_height + 10);
468 public function Body(&$pdf, $page, $lines, $outputlangs)
471 global $langs, $conf;
474 $pdf->SetFont(
'',
'', $default_font_size - 1);
478 $pdf->SetFillColor(220, 220, 220);
480 $numlines = count($lines);
481 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
485 for ($j = 0; $j < $numlines; $j++) {
487 if ($yp > $this->tab_height - 5) {
490 $this->
_pagehead($pdf, $page, 0, $outputlangs);
491 $pdf->SetFont(
'',
'', $default_font_size - 1);
494 if ($oldprowid != $lines[$j][7]) {
495 if ($yp > $this->tab_height - 15) {
496 $pdf->SetFillColor(255, 255, 255);
497 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
498 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
499 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
500 $pdf->SetFont(
'',
'B', $default_font_size - 1);
501 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
502 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R', 1);
503 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
504 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R', 1);
505 $pdf->SetFont(
'',
'', $default_font_size - 1);
506 $pdf->SetFillColor(220, 220, 220);
509 $this->
_pagehead($pdf, $page, 0, $outputlangs);
510 $pdf->SetFont(
'',
'', $default_font_size - 1);
512 $total += $total_page;
516 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
517 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L', 1);
519 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
520 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L', 1);
522 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
523 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R', 1);
525 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
526 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R', 1);
528 $total_page += $lines[$j][9];
529 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
530 $total_mod += $lines[$j][9];
535 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
536 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L', 0);
539 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
540 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L', 0);
543 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
544 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R', 0);
547 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
548 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R', 0);
551 if ($oldprowid != $lines[$j][7]) {
552 $oldprowid = $lines[$j][7];
556 if ((($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) && ($mod != $lines[$j + 1][2])) {
557 $pdf->SetFillColor(245, 245, 245);
558 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
559 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
560 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
561 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
562 $pdf->SetFont(
'',
'I', $default_font_size - 1);
563 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R', 1);
564 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
565 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_mod), 0,
'R', 1);
566 $pdf->SetFont(
'',
'', $default_font_size - 1);
567 $mod = $lines[$j + 1][2];
570 if ($yp > $this->tab_height - 5) {
573 $this->
_pagehead($pdf, $page, 0, $outputlangs);
574 $pdf->SetFont(
'',
'', $default_font_size - 1);
577 $pdf->SetFillColor(220, 220, 220);
580 $total += $total_page;
581 $pdf->SetFillColor(255, 255, 255);
582 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
583 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
584 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
585 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
586 $pdf->SetFont(
'',
'B');
587 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R', 1);
588 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
589 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R', 1);
590 $pdf->SetFillColor(220, 220, 220);