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(
"bank")) {
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(
"bank")) {
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')) {
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(
"bank")) {
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')) {
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(
"bank")) {
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(
"bank")) {
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')) {
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(
"bank")) {
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')) {
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);
342 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
343 $pdf->SetAutoPageBreak(1, 0);
348 $this->
_pagehead($pdf, $pagenb, 1, $outputlangs);
349 $pdf->SetFont(
'',
'', 9);
350 $pdf->MultiCell(0, 3,
'');
351 $pdf->SetTextColor(0, 0, 0);
354 $this->
Body($pdf, 1, $lines, $outputlangs);
356 if (method_exists($pdf,
'AliasNbPages')) {
357 $pdf->AliasNbPages();
362 $pdf->Output($file,
'F');
365 if (!is_object($hookmanager)) {
366 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
369 $hookmanager->initHooks(array(
'pdfgeneration'));
370 $parameters = array(
'file' => $file,
'object' => $this,
'outputlangs' => $outputlangs);
372 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
374 $this->error = $hookmanager->error;
375 $this->errors = $hookmanager->errors;
380 $this->result = array(
'fullpath' => $file);
395 protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
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(
"BankAccount"), 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);
470 public function Body(&$pdf, $page, $lines, $outputlangs)
473 global $langs, $conf;
476 $pdf->SetFont(
'',
'', $default_font_size - 1);
480 $pdf->SetFillColor(220, 220, 220);
482 $numlines = count($lines);
483 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
487 for ($j = 0; $j < $numlines; $j++) {
489 if ($yp > $this->tab_height - 5) {
492 $this->
_pagehead($pdf, $page, 0, $outputlangs);
493 $pdf->SetFont(
'',
'', $default_font_size - 1);
496 if ($oldprowid != $lines[$j][7]) {
497 if ($yp > $this->tab_height - 15) {
498 $pdf->SetFillColor(255, 255, 255);
499 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
500 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
501 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
502 $pdf->SetFont(
'',
'B', $default_font_size - 1);
503 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
504 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R', 1);
505 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
506 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R', 1);
507 $pdf->SetFont(
'',
'', $default_font_size - 1);
508 $pdf->SetFillColor(220, 220, 220);
511 $this->
_pagehead($pdf, $page, 0, $outputlangs);
512 $pdf->SetFont(
'',
'', $default_font_size - 1);
514 $total += $total_page;
518 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
519 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L', 1);
521 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
522 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L', 1);
524 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
525 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R', 1);
527 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
528 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R', 1);
530 $total_page += $lines[$j][9];
531 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
532 $total_mod += $lines[$j][9];
537 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
538 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L', 0);
541 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
542 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L', 0);
545 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
546 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R', 0);
549 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
550 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R', 0);
553 if ($oldprowid != $lines[$j][7]) {
554 $oldprowid = $lines[$j][7];
558 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])) {
559 $pdf->SetFillColor(245, 245, 245);
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->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
564 $pdf->SetFont(
'',
'I', $default_font_size - 1);
565 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R', 1);
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_mod), 0,
'R', 1);
568 $pdf->SetFont(
'',
'', $default_font_size - 1);
569 $mod = $lines[$j + 1][2];
572 if ($yp > $this->tab_height - 5) {
575 $this->
_pagehead($pdf, $page, 0, $outputlangs);
576 $pdf->SetFont(
'',
'', $default_font_size - 1);
579 $pdf->SetFillColor(220, 220, 220);
582 $total += $total_page;
583 $pdf->SetFillColor(255, 255, 255);
584 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
585 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
586 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
587 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
588 $pdf->SetFont(
'',
'B');
589 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R', 1);
590 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
591 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R', 1);
592 $pdf->SetFillColor(220, 220, 220);