126 public function write_file($_dir, $month, $year, $outputlangs)
129 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
131 global $conf, $hookmanager, $langs, $user;
135 $socid = $user->socid;
138 if (!is_object($outputlangs)) {
139 $outputlangs = $langs;
143 $outputlangs->charset_output =
'ISO-8859-1';
146 $this->month = $month;
148 $dir = $_dir.
'/'.$year;
153 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
158 $month = sprintf(
"%02d", $month);
159 $year = sprintf(
"%04d", $year);
161 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
162 switch ($this->doc_type) {
164 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
167 $file = $dir.
"/supplier_payments-".$year.
"-".$month.
".pdf";
173 if (!is_object($hookmanager)) {
174 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
177 $hookmanager->initHooks(array(
'pdfgeneration'));
178 $parameters = array(
'file' => $file,
'object' => $this,
'outputlangs' => $outputlangs);
180 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $this, $action);
185 if (class_exists(
'TCPDF')) {
186 $pdf->setPrintHeader(
false);
187 $pdf->setPrintFooter(
false);
195 $sql =
"SELECT p.rowid as prowid";
196 switch ($this->doc_type) {
198 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
201 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
205 $sql .=
" AND p.entity = ".$conf->entity;
206 $result = $this->db->query($sql);
208 $numpaiement = $this->db->num_rows($result);
212 switch ($this->doc_type) {
214 $sql =
"SELECT p.datep as dp, f.ref";
215 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
216 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
217 $sql .=
", pf.amount as pf_amount";
218 if (isModEnabled(
"bank")) {
219 $sql .=
", ba.ref as bankaccount";
221 $sql .=
", p.rowid as prowid";
222 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
223 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f,";
224 $sql .=
" ".MAIN_DB_PREFIX.
"paiement_facture as pf,";
225 if (isModEnabled(
"bank")) {
226 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
228 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
229 if (!$user->hasRight(
'societe',
'client',
'voir')) {
230 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
232 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
233 if (isModEnabled(
"bank")) {
234 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
236 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
238 if (!$user->hasRight(
'societe',
'client',
'voir')) {
239 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
241 if (!empty($socid)) {
242 $sql .=
" AND s.rowid = ".((int) $socid);
246 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiement ASC";
248 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiement ASC";
252 $sql =
"SELECT p.datep as dp, f.ref as ref";
253 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
254 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
255 $sql .=
", pf.amount as pf_amount";
256 if (isModEnabled(
"bank")) {
257 $sql .=
", ba.ref as bankaccount";
259 $sql .=
", p.rowid as prowid";
260 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
261 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f,";
262 $sql .=
" ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf,";
263 if (isModEnabled(
"bank")) {
264 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
266 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
267 if (!$user->hasRight(
'societe',
'client',
'voir')) {
268 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
270 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facturefourn = f.rowid AND pf.fk_paiementfourn = p.rowid";
271 if (isModEnabled(
"bank")) {
272 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
274 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
276 if (!$user->hasRight(
'societe',
'client',
'voir')) {
277 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
279 if (!empty($socid)) {
280 $sql .=
" AND s.rowid = ".((int) $socid);
284 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiementfourn ASC";
286 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiementfourn ASC";
291 dol_syslog(get_class($this).
"::write_file", LOG_DEBUG);
292 $result = $this->db->query($sql);
294 $num = $this->db->num_rows($result);
298 $objp = $this->db->fetch_object($result);
300 $lines[$i][0] = $objp->ref;
301 $lines[$i][1] =
dol_print_date($this->db->jdate($objp->dp),
"day",
false, $outputlangs,
true);
302 $lines[$i][2] = $langs->transnoentities(
"PaymentTypeShort".$objp->paiement_code);
303 $lines[$i][3] = $objp->num_payment;
304 $lines[$i][4] =
price($objp->paiement_amount);
305 $lines[$i][5] =
price($objp->facture_amount);
306 $lines[$i][6] =
price($objp->pf_amount);
307 $lines[$i][7] = $objp->prowid;
308 $lines[$i][8] = $objp->bankaccount;
309 $lines[$i][9] = $objp->paiement_amount;
316 $pages = intval(($num + $numpaiement) / $this->line_per_page);
318 if ((($num + $numpaiement) % $this->line_per_page) > 0) {
329 $pdf->SetDrawColor(128, 128, 128);
331 $pdf->SetTitle($outputlangs->transnoentities(
"Payments"));
332 $pdf->SetSubject($outputlangs->transnoentities(
"Payments"));
333 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
334 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
337 $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)
404 switch ($this->doc_type) {
406 $title .=
' - '.$outputlangs->transnoentities(
"ListOfCustomerPayments");
409 $title .=
' - '.$outputlangs->transnoentities(
"ListOfSupplierPayments");
412 $title .=
' - '.dol_print_date(
dol_mktime(0, 0, 0, $this->month, 1, $this->year),
"%B %Y",
false, $outputlangs,
true);
413 $pdf->SetFont(
'',
'B', $default_font_size + 1);
414 $pdf->SetXY($this->marge_gauche, 10);
415 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 2, $title, 0,
'C');
417 $pdf->SetFont(
'',
'', $default_font_size);
419 $pdf->SetXY($this->posxdate, 16);
420 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"DateBuild").
" : ".
dol_print_date(time(),
"day",
false, $outputlangs,
true), 0,
'L');
422 $pdf->SetXY($this->posxdate + 100, 16);
423 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"Page").
" : ".$page, 0,
'R');
427 $pdf->SetXY($this->posxdate, $this->tab_top + 2);
428 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate, 2,
'Date');
430 $pdf->line($this->posxpaymenttype - 1, $this->tab_top, $this->posxpaymenttype - 1, $this->tab_top + $this->tab_height + 10);
431 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 2);
432 $pdf->MultiCell($this->posxinvoice - $this->posxpaymenttype, 2, $outputlangs->transnoentities(
"PaymentMode"), 0,
'L');
434 $pdf->line($this->posxinvoice - 1, $this->tab_top, $this->posxinvoice - 1, $this->tab_top + $this->tab_height + 10);
435 $pdf->SetXY($this->posxinvoice, $this->tab_top + 2);
436 $pdf->MultiCell($this->posxbankaccount - $this->posxinvoice, 2, $outputlangs->transnoentities(
"Invoice"), 0,
'L');
438 $pdf->line($this->posxbankaccount - 1, $this->tab_top, $this->posxbankaccount - 1, $this->tab_top + $this->tab_height + 10);
439 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 2);
440 $pdf->MultiCell($this->posxinvoiceamount - $this->posxbankaccount, 2, $outputlangs->transnoentities(
"BankAccount"), 0,
'L');
443 $pdf->line($this->posxinvoiceamount - 1, $this->tab_top, $this->posxinvoiceamount - 1, $this->tab_top + $this->tab_height + 10);
444 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 2);
445 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, 2, $outputlangs->transnoentities(
"AmountInvoice"), 0,
'R');
447 $pdf->line($this->posxpaymentamount - 1, $this->tab_top, $this->posxpaymentamount - 1, $this->tab_top + $this->tab_height + 10);
448 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 2);
449 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount - 1, 2, $outputlangs->transnoentities(
"AmountPayment"), 0,
'R');
451 $pdf->line($this->marge_gauche, $this->tab_top + 10, $this->page_largeur - $this->marge_droite, $this->tab_top + 10);
453 $pdf->Rect($this->marge_gauche, $this->tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->tab_height + 10);
469 public function Body(&$pdf, $page, $lines, $outputlangs)
472 global $langs, $conf;
475 $pdf->SetFont(
'',
'', $default_font_size - 1);
479 $pdf->SetFillColor(220, 220, 220);
481 $numlines = count($lines);
482 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
486 for ($j = 0; $j < $numlines; $j++) {
488 if ($yp > $this->tab_height - 5) {
491 $this->
_pagehead($pdf, $page, 0, $outputlangs);
492 $pdf->SetFont(
'',
'', $default_font_size - 1);
495 if ($oldprowid != $lines[$j][7]) {
496 if ($yp > $this->tab_height - 15) {
497 $pdf->SetFillColor(255, 255, 255);
498 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
499 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
500 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
501 $pdf->SetFont(
'',
'B', $default_font_size - 1);
502 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
503 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R', 1);
504 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
505 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R', 1);
506 $pdf->SetFont(
'',
'', $default_font_size - 1);
507 $pdf->SetFillColor(220, 220, 220);
510 $this->
_pagehead($pdf, $page, 0, $outputlangs);
511 $pdf->SetFont(
'',
'', $default_font_size - 1);
513 $total += $total_page;
517 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
518 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L', 1);
520 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
521 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L', 1);
523 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
524 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R', 1);
526 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
527 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R', 1);
529 $total_page += $lines[$j][9];
530 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
531 $total_mod += $lines[$j][9];
536 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
537 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L', 0);
540 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
541 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L', 0);
544 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
545 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R', 0);
548 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
549 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R', 0);
552 if ($oldprowid != $lines[$j][7]) {
553 $oldprowid = $lines[$j][7];
557 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])) {
558 $pdf->SetFillColor(245, 245, 245);
559 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
560 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
561 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
562 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
563 $pdf->SetFont(
'',
'I', $default_font_size - 1);
564 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R', 1);
565 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
566 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_mod), 0,
'R', 1);
567 $pdf->SetFont(
'',
'', $default_font_size - 1);
568 $mod = $lines[$j + 1][2];
571 if ($yp > $this->tab_height - 5) {
574 $this->
_pagehead($pdf, $page, 0, $outputlangs);
575 $pdf->SetFont(
'',
'', $default_font_size - 1);
578 $pdf->SetFillColor(220, 220, 220);
581 $total += $total_page;
582 $pdf->SetFillColor(255, 255, 255);
583 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
584 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
585 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
586 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
587 $pdf->SetFont(
'',
'B');
588 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R', 1);
589 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
590 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R', 1);
591 $pdf->SetFillColor(220, 220, 220);