162 public function write_file($_dir, $month, $year, $outputlangs)
165 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
167 global
$conf, $hookmanager, $langs, $user;
171 $socid = $user->socid;
174 if (!is_object($outputlangs)) {
175 $outputlangs = $langs;
179 $outputlangs->charset_output =
'ISO-8859-1';
182 $this->month = $month;
184 $dir = $_dir.
'/'.$year;
189 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
194 $month = sprintf(
"%02d", $month);
195 $year = sprintf(
"%04d", $year);
197 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
198 switch ($this->doc_type) {
200 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
203 $file = $dir.
"/supplier_payments-".$year.
"-".$month.
".pdf";
209 if (!is_object($hookmanager)) {
210 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
213 $hookmanager->initHooks(array(
'pdfgeneration'));
214 $parameters = array(
'file' => $file,
'object' => $this,
'outputlangs' => $outputlangs);
216 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $this, $action);
221 if (class_exists(
'TCPDF')) {
222 $pdf->setPrintHeader(
false);
223 $pdf->setPrintFooter(
false);
231 $sql =
"SELECT p.rowid as prowid";
232 switch ($this->doc_type) {
234 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
237 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
240 $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)).
"'";
241 $sql .=
" AND p.entity = ".$conf->entity;
242 $result = $this->db->query($sql);
244 $numpaiement = $this->db->num_rows($result);
250 switch ($this->doc_type) {
252 $sql =
"SELECT p.datep as dp, f.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.
"paiement as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
261 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f,";
262 $sql .=
" ".MAIN_DB_PREFIX.
"paiement_facture 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_facture = f.rowid AND pf.fk_paiement = 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').
")";
275 $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)).
"'";
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_paiement ASC";
286 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiement ASC";
290 $sql =
"SELECT p.datep as dp, f.ref as ref";
291 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
292 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
293 $sql .=
", pf.amount as pf_amount";
294 if (isModEnabled(
"bank")) {
295 $sql .=
", ba.ref as bankaccount";
297 $sql .=
", p.rowid as prowid";
298 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
299 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f,";
300 $sql .=
" ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf,";
301 if (isModEnabled(
"bank")) {
302 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
304 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
305 if (!$user->hasRight(
'societe',
'client',
'voir')) {
306 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
308 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facturefourn = f.rowid AND pf.fk_paiementfourn = p.rowid";
309 if (isModEnabled(
"bank")) {
310 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
312 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
313 $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)).
"'";
314 if (!$user->hasRight(
'societe',
'client',
'voir')) {
315 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
317 if (!empty($socid)) {
318 $sql .=
" AND s.rowid = ".((int) $socid);
322 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiementfourn ASC";
324 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiementfourn ASC";
329 dol_syslog(get_class($this).
"::write_file", LOG_DEBUG);
330 $result = $this->db->query($sql);
332 $num = $this->db->num_rows($result);
336 $objp = $this->db->fetch_object($result);
338 $lines[$i][0] = $objp->ref;
339 $lines[$i][1] =
dol_print_date($this->db->jdate($objp->dp),
"day",
false, $outputlangs,
true);
340 $lines[$i][2] = $langs->transnoentities(
"PaymentTypeShort".$objp->paiement_code);
341 $lines[$i][3] = $objp->num_payment;
342 $lines[$i][4] =
price($objp->paiement_amount);
343 $lines[$i][5] =
price($objp->facture_amount);
344 $lines[$i][6] =
price($objp->pf_amount);
345 $lines[$i][7] = $objp->prowid;
346 $lines[$i][8] = $objp->bankaccount;
347 $lines[$i][9] = $objp->paiement_amount;
354 $pages = intval(($num + $numpaiement) / $this->line_per_page);
356 if ((($num + $numpaiement) % $this->line_per_page) > 0) {
367 $pdf->SetDrawColor(128, 128, 128);
369 $pdf->SetTitle($outputlangs->transnoentities(
"Payments"));
370 $pdf->SetSubject($outputlangs->transnoentities(
"Payments"));
371 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
372 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
375 $pdf->SetCompression(
false);
379 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
380 $pdf->SetAutoPageBreak(1, 0);
385 $this->
_pagehead($pdf, $pagenb, 1, $outputlangs);
386 $pdf->SetFont(
'',
'', 9);
387 $pdf->MultiCell(0, 3,
'');
388 $pdf->SetTextColor(0, 0, 0);
391 $this->
Body($pdf, 1, $lines, $outputlangs);
393 if (method_exists($pdf,
'AliasNbPages')) {
394 $pdf->AliasNbPages();
399 $pdf->Output($file,
'F');
402 if (!is_object($hookmanager)) {
403 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
406 $hookmanager->initHooks(array(
'pdfgeneration'));
407 $parameters = array(
'file' => $file,
'object' => $this,
'outputlangs' => $outputlangs);
409 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
411 $this->error = $hookmanager->error;
412 $this->errors = $hookmanager->errors;
417 $this->result = array(
'fullpath' => $file);
432 protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
442 switch ($this->doc_type) {
444 $title .=
' - '.$outputlangs->transnoentities(
"ListOfCustomerPayments");
447 $title .=
' - '.$outputlangs->transnoentities(
"ListOfSupplierPayments");
450 $title .=
' - '.dol_print_date(
dol_mktime(0, 0, 0, $this->month, 1, $this->year),
"%B %Y",
false, $outputlangs,
true);
451 $pdf->SetFont(
'',
'B', $default_font_size + 1);
452 $pdf->SetXY($this->marge_gauche, 10);
453 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 2, $title, 0,
'C');
455 $pdf->SetFont(
'',
'', $default_font_size);
457 $pdf->SetXY($this->posxdate, 16);
458 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"DateBuild").
" : ".
dol_print_date(time(),
"day",
false, $outputlangs,
true), 0,
'L');
460 $pdf->SetXY($this->posxdate + 100, 16);
461 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"Page").
" : ".$page, 0,
'R');
465 $pdf->SetXY($this->posxdate, $this->tab_top + 2);
466 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate, 2,
'Date');
468 $pdf->line($this->posxpaymenttype - 1, $this->tab_top, $this->posxpaymenttype - 1, $this->tab_top + $this->tab_height + 10);
469 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 2);
470 $pdf->MultiCell($this->posxinvoice - $this->posxpaymenttype, 2, $outputlangs->transnoentities(
"PaymentMode"), 0,
'L');
472 $pdf->line($this->posxinvoice - 1, $this->tab_top, $this->posxinvoice - 1, $this->tab_top + $this->tab_height + 10);
473 $pdf->SetXY($this->posxinvoice, $this->tab_top + 2);
474 $pdf->MultiCell($this->posxbankaccount - $this->posxinvoice, 2, $outputlangs->transnoentities(
"Invoice"), 0,
'L');
476 $pdf->line($this->posxbankaccount - 1, $this->tab_top, $this->posxbankaccount - 1, $this->tab_top + $this->tab_height + 10);
477 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 2);
478 $pdf->MultiCell($this->posxinvoiceamount - $this->posxbankaccount, 2, $outputlangs->transnoentities(
"BankAccount"), 0,
'L');
481 $pdf->line($this->posxinvoiceamount - 1, $this->tab_top, $this->posxinvoiceamount - 1, $this->tab_top + $this->tab_height + 10);
482 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 2);
483 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, 2, $outputlangs->transnoentities(
"AmountInvoice"), 0,
'R');
485 $pdf->line($this->posxpaymentamount - 1, $this->tab_top, $this->posxpaymentamount - 1, $this->tab_top + $this->tab_height + 10);
486 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 2);
487 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount - 1, 2, $outputlangs->transnoentities(
"AmountPayment"), 0,
'R');
489 $pdf->line($this->marge_gauche, $this->tab_top + 10, $this->page_largeur - $this->marge_droite, $this->tab_top + 10);
491 $pdf->Rect($this->marge_gauche, $this->tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->tab_height + 10);
507 public function Body(&$pdf, $page, $lines, $outputlangs)
510 global $langs,
$conf;
513 $pdf->SetFont(
'',
'', $default_font_size - 1);
519 $pdf->SetFillColor(220, 220, 220);
521 $numlines = count($lines);
522 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
525 for ($j = 0; $j < $numlines; $j++) {
527 if ($yp > $this->tab_height - 5) {
530 $this->
_pagehead($pdf, $page, 0, $outputlangs);
531 $pdf->SetFont(
'',
'', $default_font_size - 1);
534 if ($oldprowid != $lines[$j][7]) {
535 if ($yp > $this->tab_height - 15) {
536 $pdf->SetFillColor(255, 255, 255);
537 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
538 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
539 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
540 $pdf->SetFont(
'',
'B', $default_font_size - 1);
541 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
542 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R', 1);
543 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
544 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R', 1);
545 $pdf->SetFont(
'',
'', $default_font_size - 1);
546 $pdf->SetFillColor(220, 220, 220);
549 $this->
_pagehead($pdf, $page, 0, $outputlangs);
550 $pdf->SetFont(
'',
'', $default_font_size - 1);
552 $total += $total_page;
556 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
557 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L', 1);
559 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
560 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L', 1);
562 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
563 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R', 1);
565 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
566 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R', 1);
568 $total_page += (float) $lines[$j][9];
569 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
570 $total_mod += (float) $lines[$j][9];
575 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
576 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L', 0);
579 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
580 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L', 0);
583 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
584 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R', 0);
587 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
588 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R', 0);
591 if ($oldprowid != $lines[$j][7]) {
592 $oldprowid = $lines[$j][7];
596 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])) {
597 $pdf->SetFillColor(245, 245, 245);
598 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
599 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
600 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
601 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
602 $pdf->SetFont(
'',
'I', $default_font_size - 1);
603 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R', 1);
604 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
605 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_mod), 0,
'R', 1);
606 $pdf->SetFont(
'',
'', $default_font_size - 1);
607 $mod = $lines[$j + 1][2];
610 if ($yp > $this->tab_height - 5) {
613 $this->
_pagehead($pdf, $page, 0, $outputlangs);
614 $pdf->SetFont(
'',
'', $default_font_size - 1);
617 $pdf->SetFillColor(220, 220, 220);
620 $total += $total_page;
621 $pdf->SetFillColor(255, 255, 255);
622 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
623 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
624 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
625 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
626 $pdf->SetFont(
'',
'B');
627 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R', 1);
628 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
629 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R', 1);
630 $pdf->SetFillColor(220, 220, 220);