128 public function write_file($_dir, $month, $year, $outputlangs)
131 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
133 global $conf, $hookmanager, $langs, $user;
137 $socid = $user->socid;
140 if (!is_object($outputlangs)) {
141 $outputlangs = $langs;
145 $outputlangs->charset_output =
'ISO-8859-1';
148 $this->month = $month;
150 $dir = $_dir.
'/'.$year;
155 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
160 $month = sprintf(
"%02d", $month);
161 $year = sprintf(
"%04d", $year);
163 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
164 switch ($this->doc_type) {
166 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
169 $file = $dir.
"/supplier_payments-".$year.
"-".$month.
".pdf";
175 if (!is_object($hookmanager)) {
176 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
179 $hookmanager->initHooks(array(
'pdfgeneration'));
180 $parameters = array(
'file' => $file,
'object' => $this,
'outputlangs' => $outputlangs);
182 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $this, $action);
187 if (class_exists(
'TCPDF')) {
188 $pdf->setPrintHeader(
false);
189 $pdf->setPrintFooter(
false);
197 $sql =
"SELECT p.rowid as prowid";
198 switch ($this->doc_type) {
200 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
203 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
206 $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)).
"'";
207 $sql .=
" AND p.entity = ".$conf->entity;
208 $result = $this->db->query($sql);
210 $numpaiement = $this->db->num_rows($result);
214 switch ($this->doc_type) {
216 $sql =
"SELECT p.datep as dp, f.ref";
217 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
218 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
219 $sql .=
", pf.amount as pf_amount";
220 if (isModEnabled(
"bank")) {
221 $sql .=
", ba.ref as bankaccount";
223 $sql .=
", p.rowid as prowid";
224 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
225 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f,";
226 $sql .=
" ".MAIN_DB_PREFIX.
"paiement_facture as pf,";
227 if (isModEnabled(
"bank")) {
228 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
230 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
231 if (!$user->hasRight(
'societe',
'client',
'voir')) {
232 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
234 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
235 if (isModEnabled(
"bank")) {
236 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
238 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
239 $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)).
"'";
240 if (!$user->hasRight(
'societe',
'client',
'voir')) {
241 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
243 if (!empty($socid)) {
244 $sql .=
" AND s.rowid = ".((int) $socid);
248 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiement ASC";
250 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiement ASC";
254 $sql =
"SELECT p.datep as dp, f.ref as ref";
255 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
256 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
257 $sql .=
", pf.amount as pf_amount";
258 if (isModEnabled(
"bank")) {
259 $sql .=
", ba.ref as bankaccount";
261 $sql .=
", p.rowid as prowid";
262 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
263 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f,";
264 $sql .=
" ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf,";
265 if (isModEnabled(
"bank")) {
266 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
268 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
269 if (!$user->hasRight(
'societe',
'client',
'voir')) {
270 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
272 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facturefourn = f.rowid AND pf.fk_paiementfourn = p.rowid";
273 if (isModEnabled(
"bank")) {
274 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
276 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
277 $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)).
"'";
278 if (!$user->hasRight(
'societe',
'client',
'voir')) {
279 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
281 if (!empty($socid)) {
282 $sql .=
" AND s.rowid = ".((int) $socid);
286 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiementfourn ASC";
288 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiementfourn ASC";
293 dol_syslog(get_class($this).
"::write_file", LOG_DEBUG);
294 $result = $this->db->query($sql);
296 $num = $this->db->num_rows($result);
300 $objp = $this->db->fetch_object($result);
302 $lines[$i][0] = $objp->ref;
303 $lines[$i][1] =
dol_print_date($this->db->jdate($objp->dp),
"day",
false, $outputlangs,
true);
304 $lines[$i][2] = $langs->transnoentities(
"PaymentTypeShort".$objp->paiement_code);
305 $lines[$i][3] = $objp->num_payment;
306 $lines[$i][4] =
price($objp->paiement_amount);
307 $lines[$i][5] =
price($objp->facture_amount);
308 $lines[$i][6] =
price($objp->pf_amount);
309 $lines[$i][7] = $objp->prowid;
310 $lines[$i][8] = $objp->bankaccount;
311 $lines[$i][9] = $objp->paiement_amount;
318 $pages = intval(($num + $numpaiement) / $this->line_per_page);
320 if ((($num + $numpaiement) % $this->line_per_page) > 0) {
331 $pdf->SetDrawColor(128, 128, 128);
333 $pdf->SetTitle($outputlangs->transnoentities(
"Payments"));
334 $pdf->SetSubject($outputlangs->transnoentities(
"Payments"));
335 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
336 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
339 $pdf->SetCompression(
false);
343 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
344 $pdf->SetAutoPageBreak(1, 0);
349 $this->
_pagehead($pdf, $pagenb, 1, $outputlangs);
350 $pdf->SetFont(
'',
'', 9);
351 $pdf->MultiCell(0, 3,
'');
352 $pdf->SetTextColor(0, 0, 0);
355 $this->
Body($pdf, 1, $lines, $outputlangs);
357 if (method_exists($pdf,
'AliasNbPages')) {
358 $pdf->AliasNbPages();
363 $pdf->Output($file,
'F');
366 if (!is_object($hookmanager)) {
367 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
370 $hookmanager->initHooks(array(
'pdfgeneration'));
371 $parameters = array(
'file' => $file,
'object' => $this,
'outputlangs' => $outputlangs);
373 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
375 $this->error = $hookmanager->error;
376 $this->errors = $hookmanager->errors;
381 $this->result = array(
'fullpath' => $file);
396 protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
406 switch ($this->doc_type) {
408 $title .=
' - '.$outputlangs->transnoentities(
"ListOfCustomerPayments");
411 $title .=
' - '.$outputlangs->transnoentities(
"ListOfSupplierPayments");
414 $title .=
' - '.dol_print_date(
dol_mktime(0, 0, 0, $this->month, 1, $this->year),
"%B %Y",
false, $outputlangs,
true);
415 $pdf->SetFont(
'',
'B', $default_font_size + 1);
416 $pdf->SetXY($this->marge_gauche, 10);
417 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 2, $title, 0,
'C');
419 $pdf->SetFont(
'',
'', $default_font_size);
421 $pdf->SetXY($this->posxdate, 16);
422 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"DateBuild").
" : ".
dol_print_date(time(),
"day",
false, $outputlangs,
true), 0,
'L');
424 $pdf->SetXY($this->posxdate + 100, 16);
425 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"Page").
" : ".$page, 0,
'R');
429 $pdf->SetXY($this->posxdate, $this->tab_top + 2);
430 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate, 2,
'Date');
432 $pdf->line($this->posxpaymenttype - 1, $this->tab_top, $this->posxpaymenttype - 1, $this->tab_top + $this->tab_height + 10);
433 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 2);
434 $pdf->MultiCell($this->posxinvoice - $this->posxpaymenttype, 2, $outputlangs->transnoentities(
"PaymentMode"), 0,
'L');
436 $pdf->line($this->posxinvoice - 1, $this->tab_top, $this->posxinvoice - 1, $this->tab_top + $this->tab_height + 10);
437 $pdf->SetXY($this->posxinvoice, $this->tab_top + 2);
438 $pdf->MultiCell($this->posxbankaccount - $this->posxinvoice, 2, $outputlangs->transnoentities(
"Invoice"), 0,
'L');
440 $pdf->line($this->posxbankaccount - 1, $this->tab_top, $this->posxbankaccount - 1, $this->tab_top + $this->tab_height + 10);
441 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 2);
442 $pdf->MultiCell($this->posxinvoiceamount - $this->posxbankaccount, 2, $outputlangs->transnoentities(
"BankAccount"), 0,
'L');
445 $pdf->line($this->posxinvoiceamount - 1, $this->tab_top, $this->posxinvoiceamount - 1, $this->tab_top + $this->tab_height + 10);
446 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 2);
447 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, 2, $outputlangs->transnoentities(
"AmountInvoice"), 0,
'R');
449 $pdf->line($this->posxpaymentamount - 1, $this->tab_top, $this->posxpaymentamount - 1, $this->tab_top + $this->tab_height + 10);
450 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 2);
451 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount - 1, 2, $outputlangs->transnoentities(
"AmountPayment"), 0,
'R');
453 $pdf->line($this->marge_gauche, $this->tab_top + 10, $this->page_largeur - $this->marge_droite, $this->tab_top + 10);
455 $pdf->Rect($this->marge_gauche, $this->tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->tab_height + 10);
471 public function Body(&$pdf, $page, $lines, $outputlangs)
474 global $langs, $conf;
477 $pdf->SetFont(
'',
'', $default_font_size - 1);
481 $pdf->SetFillColor(220, 220, 220);
483 $numlines = count($lines);
484 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
488 for ($j = 0; $j < $numlines; $j++) {
490 if ($yp > $this->tab_height - 5) {
493 $this->
_pagehead($pdf, $page, 0, $outputlangs);
494 $pdf->SetFont(
'',
'', $default_font_size - 1);
497 if ($oldprowid != $lines[$j][7]) {
498 if ($yp > $this->tab_height - 15) {
499 $pdf->SetFillColor(255, 255, 255);
500 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
501 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
502 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
503 $pdf->SetFont(
'',
'B', $default_font_size - 1);
504 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
505 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R', 1);
506 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
507 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R', 1);
508 $pdf->SetFont(
'',
'', $default_font_size - 1);
509 $pdf->SetFillColor(220, 220, 220);
512 $this->
_pagehead($pdf, $page, 0, $outputlangs);
513 $pdf->SetFont(
'',
'', $default_font_size - 1);
515 $total += $total_page;
519 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
520 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L', 1);
522 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
523 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L', 1);
525 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
526 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R', 1);
528 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
529 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R', 1);
531 $total_page += $lines[$j][9];
532 if (($this->doc_type ==
'client' &&
getDolGlobalString(
'PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type ==
'fourn' &&
getDolGlobalString(
'PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
533 $total_mod += $lines[$j][9];
538 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
539 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L', 0);
542 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
543 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L', 0);
546 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
547 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R', 0);
550 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
551 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R', 0);
554 if ($oldprowid != $lines[$j][7]) {
555 $oldprowid = $lines[$j][7];
559 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])) {
560 $pdf->SetFillColor(245, 245, 245);
561 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
562 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
563 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
564 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
565 $pdf->SetFont(
'',
'I', $default_font_size - 1);
566 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R', 1);
567 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
568 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_mod), 0,
'R', 1);
569 $pdf->SetFont(
'',
'', $default_font_size - 1);
570 $mod = $lines[$j + 1][2];
573 if ($yp > $this->tab_height - 5) {
576 $this->
_pagehead($pdf, $page, 0, $outputlangs);
577 $pdf->SetFont(
'',
'', $default_font_size - 1);
580 $pdf->SetFillColor(220, 220, 220);
583 $total += $total_page;
584 $pdf->SetFillColor(255, 255, 255);
585 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
586 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash' => 1));
587 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
588 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
589 $pdf->SetFont(
'',
'B');
590 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R', 1);
591 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
592 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R', 1);
593 $pdf->SetFillColor(220, 220, 220);