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(
"banque")) {
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(
"banque")) {
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') && !$socid) {
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(
"banque")) {
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') && !$socid) {
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(
"banque")) {
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(
"banque")) {
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') && !$socid) {
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(
"banque")) {
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') && !$socid) {
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);
340 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
341 $pdf->SetAutoPageBreak(1, 0);
346 $this->
_pagehead($pdf, $pagenb, 1, $outputlangs);
347 $pdf->SetFont(
'',
'', 9);
348 $pdf->MultiCell(0, 3,
'');
349 $pdf->SetTextColor(0, 0, 0);
352 $this->
Body($pdf, 1, $lines, $outputlangs);
354 if (method_exists($pdf,
'AliasNbPages')) {
355 $pdf->AliasNbPages();
360 $pdf->Output($file,
'F');
363 if (!is_object($hookmanager)) {
364 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
367 $hookmanager->initHooks(array(
'pdfgeneration'));
368 $parameters = array(
'file'=>$file,
'object'=>$this,
'outputlangs'=>$outputlangs);
370 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
372 $this->error = $hookmanager->error;
373 $this->errors = $hookmanager->errors;
378 $this->result = array(
'fullpath'=>$file);
393 protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
396 global $langs, $conf;
403 $title = $conf->global->MAIN_INFO_SOCIETE_NOM;
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(
"Account"), 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);
467 public function Body(&$pdf, $page, $lines, $outputlangs)
470 global $langs, $conf;
473 $pdf->SetFont(
'',
'', $default_font_size - 1);
477 $pdf->SetFillColor(220, 220, 220);
479 $numlines = count($lines);
480 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
484 for ($j = 0; $j < $numlines; $j++) {
486 if ($yp > $this->tab_height - 5) {
489 $this->
_pagehead($pdf, $page, 0, $outputlangs);
490 $pdf->SetFont(
'',
'', $default_font_size - 1);
493 if ($oldprowid != $lines[$j][7]) {
494 if ($yp > $this->tab_height - 15) {
495 $pdf->SetFillColor(255, 255, 255);
496 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
497 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
498 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
499 $pdf->SetFont(
'',
'B', $default_font_size - 1);
500 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
501 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R', 1);
502 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
503 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R', 1);
504 $pdf->SetFont(
'',
'', $default_font_size - 1);
505 $pdf->SetFillColor(220, 220, 220);
508 $this->
_pagehead($pdf, $page, 0, $outputlangs);
509 $pdf->SetFont(
'',
'', $default_font_size - 1);
511 $total += $total_page;
515 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
516 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L', 1);
518 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
519 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L', 1);
521 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
522 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R', 1);
524 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
525 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R', 1);
527 $total_page += $lines[$j][9];
528 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
529 $total_mod += $lines[$j][9];
534 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
535 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L', 0);
538 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
539 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L', 0);
542 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
543 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R', 0);
546 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
547 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R', 0);
550 if ($oldprowid != $lines[$j][7]) {
551 $oldprowid = $lines[$j][7];
555 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])) {
556 $pdf->SetFillColor(245, 245, 245);
557 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
558 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
559 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
560 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
561 $pdf->SetFont(
'',
'I', $default_font_size - 1);
562 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R', 1);
563 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
564 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_mod), 0,
'R', 1);
565 $pdf->SetFont(
'',
'', $default_font_size - 1);
566 $mod = $lines[$j + 1][2];
569 if ($yp > $this->tab_height - 5) {
572 $this->
_pagehead($pdf, $page, 0, $outputlangs);
573 $pdf->SetFont(
'',
'', $default_font_size - 1);
576 $pdf->SetFillColor(220, 220, 220);
579 $total += $total_page;
580 $pdf->SetFillColor(255, 255, 255);
581 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
582 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
583 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
584 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
585 $pdf->SetFont(
'',
'B');
586 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R', 1);
587 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
588 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R', 1);
589 $pdf->SetFillColor(220, 220, 220);