168 public function write_file($_dir, $month, $year, $outputlangs, $day = 0)
171 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
173 global
$conf, $hookmanager, $langs, $user;
177 $socid = $user->socid;
180 if (!is_object($outputlangs)) {
181 $outputlangs = $langs;
185 $outputlangs->charset_output =
'ISO-8859-1';
188 $this->month = $month;
191 $dir = $_dir.
'/'.$year;
196 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
201 $month = sprintf(
"%02d", $month);
202 $year = sprintf(
"%04d", $year);
203 $day = sprintf(
"%02d", $day);
205 $file = $dir.
"/payments-".$year.
"-".$month.($this->day ?
"-".$day :
"").
".pdf";
206 switch ($this->doc_type) {
208 $file = $dir.
"/payments-".$year.
"-".$month.($this->day ?
"-".$day :
"").
".pdf";
211 $file = $dir.
"/supplier_payments-".$year.
"-".$month.($this->day ?
"-".$day :
"").
".pdf";
217 if (!is_object($hookmanager)) {
218 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
221 $hookmanager->initHooks(array(
'pdfgeneration'));
222 $parameters = array(
'file' => $file,
'object' => $this,
'outputlangs' => $outputlangs);
224 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $this, $action);
229 if (class_exists(
'TCPDF')) {
230 $pdf->setPrintHeader(
false);
231 $pdf->setPrintFooter(
false);
239 $sql =
"SELECT p.rowid as prowid";
240 switch ($this->doc_type) {
242 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
249 $sql .=
" WHERE p.datep BETWEEN '".$this->db->idate(
dol_mktime(0, 0, 0, (
int) $month, (
int) $day, (
int) $year)).
"' AND '".$this->db->idate(
dol_mktime(23, 59, 59, (
int) $month, (
int) $day, (
int) $year)).
"'";
251 $sql .=
" WHERE p.datep BETWEEN '".$this->db->idate(
dol_get_first_day((
int) $year, (
int) $month)).
"' AND '".$this->db->idate(
dol_get_last_day((
int) $year, (
int) $month)).
"'";
253 $sql .=
" AND p.entity = ".$conf->entity;
254 $result = $this->db->query($sql);
256 $numpaiement = $this->db->num_rows($result);
262 switch ($this->doc_type) {
264 $sql =
"SELECT p.datep as dp, f.ref";
265 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
266 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
267 $sql .=
", pf.amount as pf_amount";
269 $sql .=
", ba.ref as bankaccount";
271 $sql .=
", p.rowid as prowid";
272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
273 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f,";
274 $sql .=
" ".MAIN_DB_PREFIX.
"paiement_facture as pf,";
276 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
278 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
279 if (!$user->hasRight(
'societe',
'client',
'voir')) {
280 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
282 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
284 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
286 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
288 $sql .=
" AND p.datep BETWEEN '".$this->db->idate(
dol_mktime(0, 0, 0, (
int) $month, (
int) $day, (
int) $year)).
"' AND '".$this->db->idate(
dol_mktime(23, 59, 59, (
int) $month, (
int) $day, (
int) $year)).
"'";
290 $sql .=
" AND p.datep BETWEEN '".$this->db->idate(
dol_get_first_day((
int) $year, (
int) $month)).
"' AND '".$this->db->idate(
dol_get_last_day((
int) $year, (
int) $month)).
"'";
292 if (!$user->hasRight(
'societe',
'client',
'voir')) {
293 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
295 if (!empty($socid)) {
296 $sql .=
" AND s.rowid = ".((int) $socid);
300 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiement ASC";
302 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiement ASC";
306 $sql =
"SELECT p.datep as dp, f.ref as ref";
307 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
308 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
309 $sql .=
", pf.amount as pf_amount";
311 $sql .=
", ba.ref as bankaccount";
313 $sql .=
", p.rowid as prowid";
314 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
315 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f,";
316 $sql .=
" ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf,";
318 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
320 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
321 if (!$user->hasRight(
'societe',
'client',
'voir')) {
322 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
324 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facturefourn = f.rowid AND pf.fk_paiementfourn = p.rowid";
326 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
328 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
330 $sql .=
" AND p.datep BETWEEN '".$this->db->idate(
dol_mktime(0, 0, 0, (
int) $month, (
int) $day, (
int) $year)).
"' AND '".$this->db->idate(
dol_mktime(23, 59, 59, (
int) $month, (
int) $day, (
int) $year)).
"'";
332 $sql .=
" AND p.datep BETWEEN '".$this->db->idate(
dol_get_first_day((
int) $year, (
int) $month)).
"' AND '".$this->db->idate(
dol_get_last_day((
int) $year, (
int) $month)).
"'";
334 if (!$user->hasRight(
'societe',
'client',
'voir')) {
335 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
337 if (!empty($socid)) {
338 $sql .=
" AND s.rowid = ".((int) $socid);
342 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiementfourn ASC";
344 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiementfourn ASC";
349 dol_syslog(get_class($this).
"::write_file", LOG_DEBUG);
350 $result = $this->db->query($sql);
352 $num = $this->db->num_rows($result);
356 $objp = $this->db->fetch_object($result);
358 $lines[$i][0] = $objp->ref;
359 $lines[$i][1] =
dol_print_date($this->db->jdate($objp->dp),
"day",
false, $outputlangs,
true);
360 $lines[$i][2] = $langs->transnoentities(
"PaymentTypeShort".$objp->paiement_code);
361 $lines[$i][3] = $objp->num_payment;
362 $lines[$i][4] =
price($objp->paiement_amount);
363 $lines[$i][5] =
price($objp->facture_amount);
364 $lines[$i][6] =
price($objp->pf_amount);
365 $lines[$i][7] = $objp->prowid;
366 $lines[$i][8] = $objp->bankaccount;
367 $lines[$i][9] = $objp->paiement_amount;
374 $pages = intval(($num + $numpaiement) / $this->line_per_page);
376 if ((($num + $numpaiement) % $this->line_per_page) > 0) {
387 $pdf->SetDrawColor(128, 128, 128);
389 $pdf->SetTitle($outputlangs->transnoentities(
"Payments"));
390 $pdf->SetSubject($outputlangs->transnoentities(
"Payments"));
391 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
392 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
395 $pdf->SetCompression(
false);
399 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
400 $pdf->setAutoPageBreak(
true, 0);
405 $this->
_pagehead($pdf, $pagenb, 1, $outputlangs);
406 $pdf->SetFont(
'',
'', 9);
407 $pdf->MultiCell(0, 3,
'');
408 $pdf->SetTextColor(0, 0, 0);
411 $this->
Body($pdf, 1, $lines, $outputlangs);
413 if (method_exists($pdf,
'AliasNbPages')) {
414 $pdf->AliasNbPages();
419 $pdf->Output($file,
'F');
422 if (!is_object($hookmanager)) {
423 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
426 $hookmanager->initHooks(array(
'pdfgeneration'));
427 $parameters = array(
'file' => $file,
'object' => $this,
'outputlangs' => $outputlangs);
429 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
430 $this->warnings = $hookmanager->warnings;
432 $this->error = $hookmanager->error;
433 $this->errors = $hookmanager->errors;
440 $this->result = array(
'fullpath' => $file);
455 protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
465 switch ($this->doc_type) {
467 $title .=
' - '.$outputlangs->transnoentities(
"ListOfCustomerPayments");
470 $title .=
' - '.$outputlangs->transnoentities(
"ListOfSupplierPayments");
473 $title .=
' - '.dol_print_date(
dol_mktime(0, 0, 0, $this->month, 1, $this->year),
"%B %Y",
false, $outputlangs,
true);
474 $pdf->SetFont(
'',
'B', $default_font_size + 1);
475 $pdf->SetXY($this->marge_gauche, 10);
476 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 2, $title, 0,
'C');
478 $pdf->SetFont(
'',
'', $default_font_size);
480 $pdf->SetXY($this->posxdate, 16);
481 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"DateBuild").
" : ".
dol_print_date(time(),
"day",
false, $outputlangs,
true), 0,
'L');
483 $pdf->SetXY($this->posxdate + 100, 16);
484 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"Page").
" : ".$page, 0,
'R');
488 $pdf->SetXY($this->posxdate, $this->tab_top + 2);
489 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate, 2,
'Date');
491 $pdf->line($this->posxpaymenttype - 1, $this->tab_top, $this->posxpaymenttype - 1, $this->tab_top + $this->tab_height + 10);
492 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 2);
493 $pdf->MultiCell($this->posxinvoice - $this->posxpaymenttype, 2, $outputlangs->transnoentities(
"PaymentMode"), 0,
'L');
495 $pdf->line($this->posxinvoice - 1, $this->tab_top, $this->posxinvoice - 1, $this->tab_top + $this->tab_height + 10);
496 $pdf->SetXY($this->posxinvoice, $this->tab_top + 2);
497 $pdf->MultiCell($this->posxbankaccount - $this->posxinvoice, 2, $outputlangs->transnoentities(
"Invoice"), 0,
'L');
499 $pdf->line($this->posxbankaccount - 1, $this->tab_top, $this->posxbankaccount - 1, $this->tab_top + $this->tab_height + 10);
500 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 2);
501 $pdf->MultiCell($this->posxinvoiceamount - $this->posxbankaccount, 2, $outputlangs->transnoentities(
"BankAccount"), 0,
'L');
504 $pdf->line($this->posxinvoiceamount - 1, $this->tab_top, $this->posxinvoiceamount - 1, $this->tab_top + $this->tab_height + 10);
505 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 2);
506 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, 2, $outputlangs->transnoentities(
"AmountInvoice"), 0,
'R');
508 $pdf->line($this->posxpaymentamount - 1, $this->tab_top, $this->posxpaymentamount - 1, $this->tab_top + $this->tab_height + 10);
509 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 2);
510 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount - 1, 2, $outputlangs->transnoentities(
"AmountPayment"), 0,
'R');
512 $pdf->line($this->marge_gauche, $this->tab_top + 10, $this->page_largeur - $this->marge_droite, $this->tab_top + 10);
514 $pdf->Rect($this->marge_gauche, $this->tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->tab_height + 10);
530 public function Body(&$pdf, $page, $lines, $outputlangs)
533 global $langs,
$conf;
536 $pdf->SetFont(
'',
'', $default_font_size - 1);
542 $pdf->SetFillColor(220, 220, 220);
544 $numlines = count($lines);
545 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
548 for ($j = 0; $j < $numlines; $j++) {
550 if ($yp > $this->tab_height - 5) {
553 $this->
_pagehead($pdf, $page, 0, $outputlangs);
554 $pdf->SetFont(
'',
'', $default_font_size - 1);
557 if ($oldprowid != $lines[$j][7]) {
558 if ($yp > $this->tab_height - 15) {
559 $pdf->SetFillColor(255, 255, 255);
560 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
561 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
562 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
563 $pdf->SetFont(
'',
'B', $default_font_size - 1);
564 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
565 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R',
true);
566 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
567 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R',
true);
568 $pdf->SetFont(
'',
'', $default_font_size - 1);
569 $pdf->SetFillColor(220, 220, 220);
572 $this->
_pagehead($pdf, $page, 0, $outputlangs);
573 $pdf->SetFont(
'',
'', $default_font_size - 1);
575 $total += $total_page;
579 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
580 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L',
true);
582 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
583 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L',
true);
585 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
586 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R',
true);
588 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
589 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R',
true);
591 $total_page += (float) $lines[$j][9];
592 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
593 $total_mod += (float) $lines[$j][9];
598 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
599 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L',
false);
602 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
603 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L',
false);
606 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
607 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R',
false);
610 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
611 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R',
false);
614 if ($oldprowid != $lines[$j][7]) {
615 $oldprowid = $lines[$j][7];
619 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])) {
620 $pdf->SetFillColor(245, 245, 245);
621 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
622 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
623 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
624 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
625 $pdf->SetFont(
'',
'I', $default_font_size - 1);
626 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R',
true);
627 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
628 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_mod), 0,
'R',
true);
629 $pdf->SetFont(
'',
'', $default_font_size - 1);
630 $mod = $lines[$j + 1][2];
633 if ($yp > $this->tab_height - 5) {
636 $this->
_pagehead($pdf, $page, 0, $outputlangs);
637 $pdf->SetFont(
'',
'', $default_font_size - 1);
640 $pdf->SetFillColor(220, 220, 220);
643 $total += $total_page;
644 $pdf->SetFillColor(255, 255, 255);
645 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
646 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
647 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
648 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
649 $pdf->SetFont(
'',
'B');
650 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R',
true);
651 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
652 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R',
true);
653 $pdf->SetFillColor(220, 220, 220);