27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
46 $langs->loadLangs(array(
"bills",
"compta",
"main"));
49 $this->
description = $langs->transnoentities(
"ListOfCustomerPayments");
54 $this->page_largeur = $formatarray[
'width'];
55 $this->page_hauteur = $formatarray[
'height'];
56 $this->format = array($this->page_largeur, $this->page_hauteur);
64 $this->line_height = 5;
65 $this->line_per_page = 40;
66 $this->tab_height = $this->page_hauteur - $this->marge_haute - $this->marge_basse - $this->tab_top - 5;
68 $this->posxdate = $this->marge_gauche + 2;
69 $this->posxpaymenttype = 42;
70 $this->posxinvoice = 82;
71 $this->posxbankaccount = 110;
72 $this->posxinvoiceamount = 132;
73 $this->posxpaymentamount = 162;
74 if ($this->page_largeur < 210) {
75 $this->line_per_page = 35;
76 $this->posxpaymenttype -= 10;
77 $this->posxinvoice -= 0;
78 $this->posxinvoiceamount -= 10;
79 $this->posxpaymentamount -= 20;
82 $this->doc_type =
"client";
96 public function write_file($_dir, $month, $year, $outputlangs)
99 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
101 global $conf, $hookmanager, $langs, $user;
105 $socid = $user->socid;
108 if (!is_object($outputlangs)) {
109 $outputlangs = $langs;
112 if (!empty($conf->global->MAIN_USE_FPDF)) {
113 $outputlangs->charset_output =
'ISO-8859-1';
116 $this->month = $month;
118 $dir = $_dir.
'/'.$year;
123 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
128 $month = sprintf(
"%02d", $month);
129 $year = sprintf(
"%04d", $year);
131 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
132 switch ($this->doc_type) {
134 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
137 $file = $dir.
"/supplier_payments-".$year.
"-".$month.
".pdf";
143 if (!is_object($hookmanager)) {
144 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
147 $hookmanager->initHooks(array(
'pdfgeneration'));
148 $parameters = array(
'file'=>$file,
'outputlangs'=>$outputlangs);
150 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
155 if (class_exists(
'TCPDF')) {
156 $pdf->setPrintHeader(
false);
157 $pdf->setPrintFooter(
false);
165 $sql =
"SELECT p.rowid as prowid";
166 switch ($this->doc_type) {
168 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
171 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
175 $sql .=
" AND p.entity = ".$conf->entity;
176 $result = $this->
db->query($sql);
178 $numpaiement = $this->
db->num_rows($result);
182 switch ($this->doc_type) {
184 $sql =
"SELECT p.datep as dp, f.ref";
185 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
186 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
187 $sql .=
", pf.amount as pf_amount";
189 $sql .=
", ba.ref as bankaccount";
191 $sql .=
", p.rowid as prowid";
192 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
193 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f,";
194 $sql .=
" ".MAIN_DB_PREFIX.
"paiement_facture as pf,";
196 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
198 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
199 if (empty($user->rights->societe->client->voir) && !$socid) {
200 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
202 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
204 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
206 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
208 if (empty($user->rights->societe->client->voir) && !$socid) {
209 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
211 if (!empty($socid)) {
212 $sql .=
" AND s.rowid = ".((int) $socid);
215 if (!empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) {
216 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiement ASC";
218 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiement ASC";
222 $sql =
"SELECT p.datep as dp, f.ref as ref";
223 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
224 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
225 $sql .=
", pf.amount as pf_amount";
227 $sql .=
", ba.ref as bankaccount";
229 $sql .=
", p.rowid as prowid";
230 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
231 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f,";
232 $sql .=
" ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf,";
234 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
236 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
237 if (empty($user->rights->societe->client->voir) && !$socid) {
238 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
240 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facturefourn = f.rowid AND pf.fk_paiementfourn = p.rowid";
242 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
244 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
246 if (empty($user->rights->societe->client->voir) && !$socid) {
247 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
249 if (!empty($socid)) {
250 $sql .=
" AND s.rowid = ".((int) $socid);
253 if (!empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD)) {
254 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiementfourn ASC";
256 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiementfourn ASC";
261 dol_syslog(get_class($this).
"::write_file", LOG_DEBUG);
262 $result = $this->
db->query($sql);
264 $num = $this->
db->num_rows($result);
268 $objp = $this->
db->fetch_object($result);
270 $lines[$i][0] = $objp->ref;
271 $lines[$i][1] =
dol_print_date($this->
db->jdate($objp->dp),
"day",
false, $outputlangs,
true);
272 $lines[$i][2] = $langs->transnoentities(
"PaymentTypeShort".$objp->paiement_code);
273 $lines[$i][3] = $objp->num_payment;
274 $lines[$i][4] =
price($objp->paiement_amount);
275 $lines[$i][5] =
price($objp->facture_amount);
276 $lines[$i][6] =
price($objp->pf_amount);
277 $lines[$i][7] = $objp->prowid;
278 $lines[$i][8] = $objp->bankaccount;
279 $lines[$i][9] = $objp->paiement_amount;
286 $pages = intval(($num + $numpaiement) / $this->line_per_page);
288 if ((($num + $numpaiement) % $this->line_per_page) > 0) {
299 $pdf->SetDrawColor(128, 128, 128);
301 $pdf->SetTitle($outputlangs->transnoentities(
"Payments"));
302 $pdf->SetSubject($outputlangs->transnoentities(
"Payments"));
303 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
304 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
307 $pdf->SetCompression(
false);
310 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
311 $pdf->SetAutoPageBreak(1, 0);
316 $this->
_pagehead($pdf, $pagenb, 1, $outputlangs);
317 $pdf->SetFont(
'',
'', 9);
318 $pdf->MultiCell(0, 3,
'');
319 $pdf->SetTextColor(0, 0, 0);
322 $this->
Body($pdf, 1, $lines, $outputlangs);
324 if (method_exists($pdf,
'AliasNbPages')) {
325 $pdf->AliasNbPages();
330 $pdf->Output($file,
'F');
333 if (!is_object($hookmanager)) {
334 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
337 $hookmanager->initHooks(array(
'pdfgeneration'));
338 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
340 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
342 $this->error = $hookmanager->error;
343 $this->errors = $hookmanager->errors;
346 if (!empty($conf->global->MAIN_UMASK)) {
347 @chmod($file, octdec($conf->global->MAIN_UMASK));
350 $this->result = array(
'fullpath'=>$file);
365 protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
368 global $langs, $conf;
375 $title = $conf->global->MAIN_INFO_SOCIETE_NOM;
376 switch ($this->doc_type) {
378 $title .=
' - '.$outputlangs->transnoentities(
"ListOfCustomerPayments");
381 $title .=
' - '.$outputlangs->transnoentities(
"ListOfSupplierPayments");
384 $title .=
' - '.dol_print_date(
dol_mktime(0, 0, 0, $this->month, 1, $this->year),
"%B %Y",
false, $outputlangs,
true);
385 $pdf->SetFont(
'',
'B', $default_font_size + 1);
386 $pdf->SetXY($this->marge_gauche, 10);
387 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 2, $title, 0,
'C');
389 $pdf->SetFont(
'',
'', $default_font_size);
391 $pdf->SetXY($this->posxdate, 16);
392 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"DateBuild").
" : ".
dol_print_date(time(),
"day",
false, $outputlangs,
true), 0,
'L');
394 $pdf->SetXY($this->posxdate + 100, 16);
395 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"Page").
" : ".$page, 0,
'R');
399 $pdf->SetXY($this->posxdate, $this->tab_top + 2);
400 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate, 2,
'Date');
402 $pdf->line($this->posxpaymenttype - 1, $this->tab_top, $this->posxpaymenttype - 1, $this->tab_top + $this->tab_height + 10);
403 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 2);
404 $pdf->MultiCell($this->posxinvoice - $this->posxpaymenttype, 2, $outputlangs->transnoentities(
"PaymentMode"), 0,
'L');
406 $pdf->line($this->posxinvoice - 1, $this->tab_top, $this->posxinvoice - 1, $this->tab_top + $this->tab_height + 10);
407 $pdf->SetXY($this->posxinvoice, $this->tab_top + 2);
408 $pdf->MultiCell($this->posxbankaccount - $this->posxinvoice, 2, $outputlangs->transnoentities(
"Invoice"), 0,
'L');
410 $pdf->line($this->posxbankaccount - 1, $this->tab_top, $this->posxbankaccount - 1, $this->tab_top + $this->tab_height + 10);
411 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 2);
412 $pdf->MultiCell($this->posxinvoiceamount - $this->posxbankaccount, 2, $outputlangs->transnoentities(
"Account"), 0,
'L');
415 $pdf->line($this->posxinvoiceamount - 1, $this->tab_top, $this->posxinvoiceamount - 1, $this->tab_top + $this->tab_height + 10);
416 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 2);
417 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, 2, $outputlangs->transnoentities(
"AmountInvoice"), 0,
'R');
419 $pdf->line($this->posxpaymentamount - 1, $this->tab_top, $this->posxpaymentamount - 1, $this->tab_top + $this->tab_height + 10);
420 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 2);
421 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount - 1, 2, $outputlangs->transnoentities(
"AmountPayment"), 0,
'R');
423 $pdf->line($this->marge_gauche, $this->tab_top + 10, $this->page_largeur - $this->marge_droite, $this->tab_top + 10);
425 $pdf->Rect($this->marge_gauche, $this->tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->tab_height + 10);
439 public function Body(&$pdf, $page, $lines, $outputlangs)
442 global $langs, $conf;
445 $pdf->SetFont(
'',
'', $default_font_size - 1);
449 $pdf->SetFillColor(220, 220, 220);
451 $numlines = count($lines);
452 if (($this->doc_type ==
'client' && !empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) || ($this->doc_type ==
'fourn' && !empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD))) {
456 for ($j = 0; $j < $numlines; $j++) {
458 if ($yp > $this->tab_height - 5) {
461 $this->
_pagehead($pdf, $page, 0, $outputlangs);
462 $pdf->SetFont(
'',
'', $default_font_size - 1);
465 if ($oldprowid <> $lines[$j][7]) {
466 if ($yp > $this->tab_height - 15) {
467 $pdf->SetFillColor(255, 255, 255);
468 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
469 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
470 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
471 $pdf->SetFont(
'',
'B', $default_font_size - 1);
472 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
473 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R', 1);
474 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
475 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R', 1);
476 $pdf->SetFont(
'',
'', $default_font_size - 1);
477 $pdf->SetFillColor(220, 220, 220);
480 $this->
_pagehead($pdf, $page, 0, $outputlangs);
481 $pdf->SetFont(
'',
'', $default_font_size - 1);
483 $total += $total_page;
487 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
488 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L', 1);
490 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
491 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L', 1);
493 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
494 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R', 1);
496 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
497 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R', 1);
499 $total_page += $lines[$j][9];
500 if (($this->doc_type ==
'client' && !empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) || ($this->doc_type ==
'fourn' && !empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD))) {
501 $total_mod += $lines[$j][9];
506 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
507 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L', 0);
510 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
511 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L', 0);
514 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
515 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R', 0);
518 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
519 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R', 0);
522 if ($oldprowid <> $lines[$j][7]) {
523 $oldprowid = $lines[$j][7];
527 if ((($this->doc_type ==
'client' && !empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) || ($this->doc_type ==
'fourn' && !empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD))) && ($mod != $lines[$j + 1][2])) {
528 $pdf->SetFillColor(245, 245, 245);
529 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
530 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
531 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
532 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
533 $pdf->SetFont(
'',
'I', $default_font_size - 1);
534 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R', 1);
535 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
536 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_mod), 0,
'R', 1);
537 $pdf->SetFont(
'',
'', $default_font_size - 1);
538 $mod = $lines[$j + 1][2];
541 if ($yp > $this->tab_height - 5) {
544 $this->
_pagehead($pdf, $page, 0, $outputlangs);
545 $pdf->SetFont(
'',
'', $default_font_size - 1);
548 $pdf->SetFillColor(220, 220, 220);
551 $total += $total_page;
552 $pdf->SetFillColor(255, 255, 255);
553 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
554 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
555 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
556 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
557 $pdf->SetFont(
'',
'B');
558 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R', 1);
559 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
560 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R', 1);
561 $pdf->SetFillColor(220, 220, 220);