117 public function write_file($_dir, $month, $year, $outputlangs)
120 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
122 global $conf, $hookmanager, $langs, $user;
126 $socid = $user->socid;
129 if (!is_object($outputlangs)) {
130 $outputlangs = $langs;
133 if (!empty($conf->global->MAIN_USE_FPDF)) {
134 $outputlangs->charset_output =
'ISO-8859-1';
137 $this->month = $month;
139 $dir = $_dir.
'/'.$year;
144 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
149 $month = sprintf(
"%02d", $month);
150 $year = sprintf(
"%04d", $year);
152 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
153 switch ($this->doc_type) {
155 $file = $dir.
"/payments-".$year.
"-".$month.
".pdf";
158 $file = $dir.
"/supplier_payments-".$year.
"-".$month.
".pdf";
164 if (!is_object($hookmanager)) {
165 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
168 $hookmanager->initHooks(array(
'pdfgeneration'));
169 $parameters = array(
'file'=>$file,
'outputlangs'=>$outputlangs);
171 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
176 if (class_exists(
'TCPDF')) {
177 $pdf->setPrintHeader(
false);
178 $pdf->setPrintFooter(
false);
186 $sql =
"SELECT p.rowid as prowid";
187 switch ($this->doc_type) {
189 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
192 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
196 $sql .=
" AND p.entity = ".$conf->entity;
197 $result = $this->db->query($sql);
199 $numpaiement = $this->db->num_rows($result);
203 switch ($this->doc_type) {
205 $sql =
"SELECT p.datep as dp, f.ref";
206 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
207 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
208 $sql .=
", pf.amount as pf_amount";
209 if (isModEnabled(
"banque")) {
210 $sql .=
", ba.ref as bankaccount";
212 $sql .=
", p.rowid as prowid";
213 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
214 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f,";
215 $sql .=
" ".MAIN_DB_PREFIX.
"paiement_facture as pf,";
216 if (isModEnabled(
"banque")) {
217 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
219 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
220 if (empty($user->rights->societe->client->voir) && !$socid) {
221 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
223 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid";
224 if (isModEnabled(
"banque")) {
225 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
227 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
229 if (empty($user->rights->societe->client->voir) && !$socid) {
230 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
232 if (!empty($socid)) {
233 $sql .=
" AND s.rowid = ".((int) $socid);
236 if (!empty($conf->global->PAYMENTS_REPORT_GROUP_BY_MOD)) {
237 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiement ASC";
239 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiement ASC";
243 $sql =
"SELECT p.datep as dp, f.ref as ref";
244 $sql .=
", c.code as paiement_code, p.num_paiement as num_payment";
245 $sql .=
", p.amount as paiement_amount, f.total_ttc as facture_amount";
246 $sql .=
", pf.amount as pf_amount";
247 if (isModEnabled(
"banque")) {
248 $sql .=
", ba.ref as bankaccount";
250 $sql .=
", p.rowid as prowid";
251 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_paiement = c.id";
252 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f,";
253 $sql .=
" ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf,";
254 if (isModEnabled(
"banque")) {
255 $sql .=
" ".MAIN_DB_PREFIX.
"bank as b, ".MAIN_DB_PREFIX.
"bank_account as ba,";
257 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s";
258 if (empty($user->rights->societe->client->voir) && !$socid) {
259 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
261 $sql .=
" WHERE f.fk_soc = s.rowid AND pf.fk_facturefourn = f.rowid AND pf.fk_paiementfourn = p.rowid";
262 if (isModEnabled(
"banque")) {
263 $sql .=
" AND p.fk_bank = b.rowid AND b.fk_account = ba.rowid ";
265 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
267 if (empty($user->rights->societe->client->voir) && !$socid) {
268 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
270 if (!empty($socid)) {
271 $sql .=
" AND s.rowid = ".((int) $socid);
274 if (!empty($conf->global->PAYMENTS_FOURN_REPORT_GROUP_BY_MOD)) {
275 $sql .=
" ORDER BY paiement_code ASC, p.datep ASC, pf.fk_paiementfourn ASC";
277 $sql .=
" ORDER BY p.datep ASC, pf.fk_paiementfourn ASC";
282 dol_syslog(get_class($this).
"::write_file", LOG_DEBUG);
283 $result = $this->db->query($sql);
285 $num = $this->db->num_rows($result);
289 $objp = $this->db->fetch_object($result);
291 $lines[$i][0] = $objp->ref;
292 $lines[$i][1] =
dol_print_date($this->db->jdate($objp->dp),
"day",
false, $outputlangs,
true);
293 $lines[$i][2] = $langs->transnoentities(
"PaymentTypeShort".$objp->paiement_code);
294 $lines[$i][3] = $objp->num_payment;
295 $lines[$i][4] =
price($objp->paiement_amount);
296 $lines[$i][5] =
price($objp->facture_amount);
297 $lines[$i][6] =
price($objp->pf_amount);
298 $lines[$i][7] = $objp->prowid;
299 $lines[$i][8] = $objp->bankaccount;
300 $lines[$i][9] = $objp->paiement_amount;
307 $pages = intval(($num + $numpaiement) / $this->line_per_page);
309 if ((($num + $numpaiement) % $this->line_per_page) > 0) {
320 $pdf->SetDrawColor(128, 128, 128);
322 $pdf->SetTitle($outputlangs->transnoentities(
"Payments"));
323 $pdf->SetSubject($outputlangs->transnoentities(
"Payments"));
324 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
325 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
328 $pdf->SetCompression(
false);
331 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
332 $pdf->SetAutoPageBreak(1, 0);
337 $this->
_pagehead($pdf, $pagenb, 1, $outputlangs);
338 $pdf->SetFont(
'',
'', 9);
339 $pdf->MultiCell(0, 3,
'');
340 $pdf->SetTextColor(0, 0, 0);
343 $this->
Body($pdf, 1, $lines, $outputlangs);
345 if (method_exists($pdf,
'AliasNbPages')) {
346 $pdf->AliasNbPages();
351 $pdf->Output($file,
'F');
354 if (!is_object($hookmanager)) {
355 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
358 $hookmanager->initHooks(array(
'pdfgeneration'));
359 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
361 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
363 $this->error = $hookmanager->error;
364 $this->errors = $hookmanager->errors;
369 $this->result = array(
'fullpath'=>$file);
384 protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
387 global $langs, $conf;
394 $title = $conf->global->MAIN_INFO_SOCIETE_NOM;
395 switch ($this->doc_type) {
397 $title .=
' - '.$outputlangs->transnoentities(
"ListOfCustomerPayments");
400 $title .=
' - '.$outputlangs->transnoentities(
"ListOfSupplierPayments");
403 $title .=
' - '.dol_print_date(
dol_mktime(0, 0, 0, $this->month, 1, $this->year),
"%B %Y",
false, $outputlangs,
true);
404 $pdf->SetFont(
'',
'B', $default_font_size + 1);
405 $pdf->SetXY($this->marge_gauche, 10);
406 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->marge_gauche, 2, $title, 0,
'C');
408 $pdf->SetFont(
'',
'', $default_font_size);
410 $pdf->SetXY($this->posxdate, 16);
411 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"DateBuild").
" : ".
dol_print_date(time(),
"day",
false, $outputlangs,
true), 0,
'L');
413 $pdf->SetXY($this->posxdate + 100, 16);
414 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"Page").
" : ".$page, 0,
'R');
418 $pdf->SetXY($this->posxdate, $this->tab_top + 2);
419 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate, 2,
'Date');
421 $pdf->line($this->posxpaymenttype - 1, $this->tab_top, $this->posxpaymenttype - 1, $this->tab_top + $this->tab_height + 10);
422 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 2);
423 $pdf->MultiCell($this->posxinvoice - $this->posxpaymenttype, 2, $outputlangs->transnoentities(
"PaymentMode"), 0,
'L');
425 $pdf->line($this->posxinvoice - 1, $this->tab_top, $this->posxinvoice - 1, $this->tab_top + $this->tab_height + 10);
426 $pdf->SetXY($this->posxinvoice, $this->tab_top + 2);
427 $pdf->MultiCell($this->posxbankaccount - $this->posxinvoice, 2, $outputlangs->transnoentities(
"Invoice"), 0,
'L');
429 $pdf->line($this->posxbankaccount - 1, $this->tab_top, $this->posxbankaccount - 1, $this->tab_top + $this->tab_height + 10);
430 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 2);
431 $pdf->MultiCell($this->posxinvoiceamount - $this->posxbankaccount, 2, $outputlangs->transnoentities(
"Account"), 0,
'L');
434 $pdf->line($this->posxinvoiceamount - 1, $this->tab_top, $this->posxinvoiceamount - 1, $this->tab_top + $this->tab_height + 10);
435 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 2);
436 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, 2, $outputlangs->transnoentities(
"AmountInvoice"), 0,
'R');
438 $pdf->line($this->posxpaymentamount - 1, $this->tab_top, $this->posxpaymentamount - 1, $this->tab_top + $this->tab_height + 10);
439 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 2);
440 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount - 1, 2, $outputlangs->transnoentities(
"AmountPayment"), 0,
'R');
442 $pdf->line($this->marge_gauche, $this->tab_top + 10, $this->page_largeur - $this->marge_droite, $this->tab_top + 10);
444 $pdf->Rect($this->marge_gauche, $this->tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->tab_height + 10);
458 public function Body(&$pdf, $page, $lines, $outputlangs)
461 global $langs, $conf;
464 $pdf->SetFont(
'',
'', $default_font_size - 1);
468 $pdf->SetFillColor(220, 220, 220);
470 $numlines = count($lines);
471 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))) {
475 for ($j = 0; $j < $numlines; $j++) {
477 if ($yp > $this->tab_height - 5) {
480 $this->
_pagehead($pdf, $page, 0, $outputlangs);
481 $pdf->SetFont(
'',
'', $default_font_size - 1);
484 if ($oldprowid <> $lines[$j][7]) {
485 if ($yp > $this->tab_height - 15) {
486 $pdf->SetFillColor(255, 255, 255);
487 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
488 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
489 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
490 $pdf->SetFont(
'',
'B', $default_font_size - 1);
491 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
492 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'SubTotal').
" : ", 0,
'R', 1);
493 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
494 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_page), 0,
'R', 1);
495 $pdf->SetFont(
'',
'', $default_font_size - 1);
496 $pdf->SetFillColor(220, 220, 220);
499 $this->
_pagehead($pdf, $page, 0, $outputlangs);
500 $pdf->SetFont(
'',
'', $default_font_size - 1);
502 $total += $total_page;
506 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
507 $pdf->MultiCell($this->posxpaymenttype - $this->posxdate + 1, $this->line_height, $lines[$j][1], 0,
'L', 1);
509 $pdf->SetXY($this->posxpaymenttype, $this->tab_top + 10 + $yp);
510 $pdf->MultiCell($this->posxinvoiceamount - $this->posxpaymenttype, $this->line_height, $lines[$j][2].
' '.$lines[$j][3], 0,
'L', 1);
512 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
513 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount, $this->line_height,
'', 0,
'R', 1);
515 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
516 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0,
'R', 1);
518 $total_page += $lines[$j][9];
519 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))) {
520 $total_mod += $lines[$j][9];
525 $pdf->SetXY($this->posxinvoice, $this->tab_top + 10 + $yp);
526 $pdf->MultiCell($this->posxinvoice - $this->posxbankaccount, $this->line_height, $lines[$j][0], 0,
'L', 0);
529 $pdf->SetXY($this->posxbankaccount, $this->tab_top + 10 + $yp);
530 $pdf->MultiCell($this->posxbankaccount - $this->posxdate, $this->line_height, $lines[$j][8], 0,
'L', 0);
533 $pdf->SetXY($this->posxinvoiceamount, $this->tab_top + 10 + $yp);
534 $pdf->MultiCell($this->posxpaymentamount - $this->posxinvoiceamount - 1, $this->line_height, $lines[$j][5], 0,
'R', 0);
537 $pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
538 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][6], 0,
'R', 0);
541 if ($oldprowid <> $lines[$j][7]) {
542 $oldprowid = $lines[$j][7];
546 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])) {
547 $pdf->SetFillColor(245, 245, 245);
548 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
549 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
550 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
551 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
552 $pdf->SetFont(
'',
'I', $default_font_size - 1);
553 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
' '.$mod.
" : ", 0,
'R', 1);
554 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
555 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total_mod), 0,
'R', 1);
556 $pdf->SetFont(
'',
'', $default_font_size - 1);
557 $mod = $lines[$j + 1][2];
560 if ($yp > $this->tab_height - 5) {
563 $this->
_pagehead($pdf, $page, 0, $outputlangs);
564 $pdf->SetFont(
'',
'', $default_font_size - 1);
567 $pdf->SetFillColor(220, 220, 220);
570 $total += $total_page;
571 $pdf->SetFillColor(255, 255, 255);
572 $pdf->Rect($this->marge_gauche + 1, $this->tab_top + 10 + $yp, $this->posxpaymentamount - $this->marge_droite - 3, $this->line_height,
'F', array(), array());
573 $pdf->line($this->marge_gauche, $this->tab_top + 10 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 10 + $yp, array(
'dash'=>1));
574 $pdf->line($this->marge_gauche, $this->tab_top + 15 + $yp, $this->page_largeur - $this->marge_droite, $this->tab_top + 15 + $yp);
575 $pdf->SetXY($this->posxdate - 1, $this->tab_top + 10 + $yp);
576 $pdf->SetFont(
'',
'B');
577 $pdf->MultiCell($this->posxpaymentamount - 2 - $this->marge_droite, $this->line_height, $langs->transnoentities(
'Total').
" : ", 0,
'R', 1);
578 $pdf->SetXY($this->posxpaymentamount - 1, $this->tab_top + 10 + $yp);
579 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount + 1, $this->line_height,
price($total), 0,
'R', 1);
580 $pdf->SetFillColor(220, 220, 220);