2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 //include_once($path_to_root . "reporting/includes/class.pdf.inc");
13 include_once(dirname(__FILE__)."/class.pdf.inc");
14 include_once(dirname(__FILE__)."/printer_class.inc");
15 include_once($path_to_root . "/admin/db/company_db.inc");
16 include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
17 include_once($path_to_root . "/admin/db/printers_db.inc");
18 include_once($path_to_root . "/config.php");
19 class FrontReport extends Cpdf
50 var $companyLogoEnable; // select whether to use a company logo graphic in some header templates
52 var $footerEnable; // select whether to print a page footer or not
53 var $footerText; // store user-generated footer text
54 var $headerFunc; // store the name of the currently selected header function
56 function FrontReport($title, $filename, $size = 'A4', $fontsize = 9, $orientation = 'P', $margins = NULL, $excelColWidthFactor = NULL)
58 global $page_security;
59 if (!$_SESSION["wa_current_user"]->can_access_page($page_security))
61 display_error(_("The security settings on your account do not permit you to print this report"));
65 // Page margins - if user-specified, use those. Otherwise, use defaults below.
68 $this->topMargin = $margins['top'];
69 $this->bottomMargin = $margins['bottom'];
70 $this->leftMargin = $margins['left'];
71 $this->rightMargin = $margins['right'];
73 // Page orientation - P: portrait, L: landscape
74 $orientation = strtoupper($orientation);
76 switch (strtoupper($size))
81 if ($orientation == 'P')
84 $this->pageHeight=842;
88 $this->bottomMargin=30;
90 $this->rightMargin=30;
97 $this->pageHeight=595;
101 $this->bottomMargin=30;
102 $this->leftMargin=40;
103 $this->rightMargin=30;
109 if ($orientation == 'P')
111 $this->pageWidth=842;
112 $this->pageHeight=1190;
113 if (!isset($margins))
116 $this->bottomMargin=50;
117 $this->leftMargin=50;
118 $this->rightMargin=40;
124 $this->pageWidth=1190;
125 $this->pageHeight=842;
126 if (!isset($margins))
129 $this->bottomMargin=50;
130 $this->leftMargin=50;
131 $this->rightMargin=40;
137 if ($orientation == 'P')
139 $this->pageWidth=612;
140 $this->pageHeight=792;
141 if (!isset($margins))
144 $this->bottomMargin=30;
145 $this->leftMargin=30;
146 $this->rightMargin=25;
152 $this->pageWidth=792;
153 $this->pageHeight=612;
154 if (!isset($margins))
157 $this->bottomMargin=30;
158 $this->leftMargin=30;
159 $this->rightMargin=25;
165 if ($orientation == 'P')
167 $this->pageWidth=612;
168 $this->pageHeight=1008;
169 if (!isset($margins))
172 $this->bottomMargin=40;
173 $this->leftMargin=30;
174 $this->rightMargin=25;
180 $this->pageWidth=1008;
181 $this->pageHeight=612;
182 if (!isset($margins))
185 $this->bottomMargin=40;
186 $this->leftMargin=30;
187 $this->rightMargin=25;
192 $this->size = array(0, 0, $this->pageWidth, $this->pageHeight);
193 $this->title = $title;
194 $this->filename = $filename.".pdf";
195 $this->pageNumber = 0;
196 $this->endLine = $this->pageWidth - $this->rightMargin;
197 $this->lineHeight = 12;
198 $this->fontSize = $fontsize;
199 $this->oldFontSize = 0;
200 $this->row = $this->pageHeight - $this->topMargin;
201 $this->currency = '';
202 $this->scaleLogoWidth = false; // if Logo, scale on width (else height).
203 $this->headerFunc = 'Header'; // default to the original header template
205 $rtl = ($_SESSION['language']->dir === 'rtl' ? 'rtl' : 'ltr');
206 $code = $_SESSION['language']->code;
207 $enc = strtoupper($_SESSION['language']->encoding);
208 // for the language array in class.pdf.inc
209 $l = array('a_meta_charset' => $enc, 'a_meta_dir' => $rtl, 'a_meta_language' => $code, 'w_page' => 'page');
210 $this->Cpdf($size, $l, $orientation);
214 * Select the font and style to use for following output until
215 * it's changed again.
218 * * a special case string (for backwards compatible with older code):
221 * * or a case-insensitive string where each char represents a style choice
222 * and you can use more than one or none at all. Possible choices:
223 * * empty string: regular
227 * * D: line trough (aka "strike through")
228 * $fontname should be a standard PDF font (like 'times', 'helvetica' or 'courier')
229 * or one that's been installed on your system (see TCPDF docs for details).
230 * An empty string can also be used which will retain the font currently in use if
231 * you just want to change the style.
233 function Font($style = '', $fontname = '')
235 $this->selectFont($fontname, $style);
238 function Info($params, $cols, $headers, $aligns,
239 $cols2 = null, $headers2 = null, $aligns2 = null,
240 $companylogoenable = false, $footerenable = false, $footertext = '')
242 global $app_title, $version, $power_by, $power_url;
244 $this->addinfo('Title', $this->title);
245 $this->addinfo('Subject', $this->title);
246 $this->addinfo('Author', $app_title . ' ' . $version);
247 $this->addinfo('Creator',$power_by . ' - ' . $power_url);
248 $year = get_current_fiscalyear();
249 if ($year['closed'] == 0)
253 $this->fiscal_year = sql2date($year['begin']) . " - " . sql2date($year['end']) . " " . "(" . $how . ")";
254 $this->company = get_company_prefs();
255 $this->user = $_SESSION["wa_current_user"]->name;
256 $this->host = $_SERVER['SERVER_NAME'];
257 $this->params = $params;
259 for ($i = 0; $i < count($this->cols); $i++)
260 $this->cols[$i] += $this->leftMargin;
261 $this->headers = $headers;
262 $this->aligns = $aligns;
263 $this->cols2 = $cols2;
264 if ($this->cols2 != null)
266 for ($i = 0; $i < count($this->cols2); $i++)
267 $this->cols2[$i] += $this->leftMargin;
269 $this->headers2 = $headers2;
270 $this->aligns2 = $aligns2;
272 // Set whether to display company logo in some header templates
273 $this->companyLogoEnable = $companylogoenable;
275 // Store footer settings
276 $this->footerEnable = $footerenable;
277 $this->footerText = $footertext;
282 $companyCol = $this->endLine - 150;
283 $titleCol = $this->leftMargin + 100;
286 if ($this->pageNumber > 1)
289 $this->row = $this->pageHeight - $this->topMargin;
291 $this->SetDrawColor(128, 128, 128);
292 $this->Line($this->row + 5, 1);
296 $this->fontSize += 4;
298 $this->Text($this->leftMargin, $this->title, $companyCol);
300 $this->fontSize -= 4;
301 $this->Text($companyCol, $this->company['coy_name']);
302 $this->row -= ($this->lineHeight + 4);
304 $str = _("Print Out Date") . ':';
305 $this->Text($this->leftMargin, $str, $titleCol);
306 $str = Today() . ' ' . Now();
307 if ($this->company['time_zone'])
308 $str .= ' ' . date('O') . ' GMT';
309 $this->Text($titleCol, $str, $companyCol);
310 $this->Text($companyCol, $this->host);
313 $str = _("Fiscal Year") . ':';
314 $this->Text($this->leftMargin, $str, $titleCol);
315 $str = $this->fiscal_year;
316 $this->Text($titleCol, $str, $companyCol);
317 $this->Text($companyCol, $this->user);
318 for ($i = 1; $i < count($this->params); $i++)
320 if ($this->params[$i]['from'] != '')
323 $str = $this->params[$i]['text'] . ':';
324 $this->Text($this->leftMargin, $str, $titleCol);
325 $str = $this->params[$i]['from'];
326 if ($this->params[$i]['to'] != '')
327 $str .= " - " . $this->params[$i]['to'];
328 $this->Text($titleCol, $str, $companyCol);
331 if ($this->params[0] != '') // Comments
334 $str = _("Comments") . ':';
335 $this->Text($this->leftMargin, $str, $titleCol);
337 $this->Text($titleCol, $this->params[0], $this->endLine - 35);
340 $str = _("Page") . ' ' . $this->pageNumber;
341 $this->Text($this->endLine - 38, $str);
342 $this->Line($this->row - 5, 1);
344 $this->row -= ($this->lineHeight + 6);
345 $this->Font('italic');
346 if ($this->headers2 != null)
348 $count = count($this->headers2);
349 for ($i = 0; $i < $count; $i++)
350 $this->TextCol2($i, $i + 1, $this->headers2[$i]);
353 $count = count($this->headers);
354 for ($i = 0; $i < $count; $i++)
355 $this->TextCol($i, $i + 1, $this->headers[$i]);
357 $this->Line($this->row - 5, 1);
362 function Header2($myrow, $branch, $sales_order, $bankaccount, $doctype)
364 global $comp_path, $path_to_root, $print_as_quote, $print_invoice_no, $packing_slip;
367 if ($this->pageNumber > 1)
371 // leave layout files names without path to enable including
372 // modified versions from comapny/x/reporting directory
373 if (isset($myrow['curr_code']) && $this->currency != $myrow['curr_code'])
375 include("includes/doctext2.inc");
379 include("includes/doctext.inc");
382 include("includes/header2.inc");
387 // Alternate header style which also supports a simple footer
392 // Make this header the default for the current report ( used by NewLine() )
393 $this->headerFunc = 'Header3';
395 // Turn off cell padding for the main report header, restoring the current setting later
396 $oldcMargin = $this->cMargin;
397 $this->SetCellPadding(0);
399 // Set some constants which control header item layout
400 // only set them once or the PHP interpreter gets angry
401 if ($this->pageNumber == 0)
403 define('COMPANY_WIDTH', 150);
404 define('LOGO_HEIGHT', 50);
405 define('LOGO_Y_POS_ADJ_FACTOR', 0.74);
406 define('LABEL_WIDTH', 80);
407 define('PAGE_NUM_WIDTH', 60);
408 define('TITLE_FONT_SIZE', 14);
409 define('HEADER1_FONT_SIZE', 10);
410 define('HEADER2_FONT_SIZE', 9);
411 define('FOOTER_FONT_SIZE', 10);
412 define('FOOTER_MARGIN', 4);
414 // Set some variables which control header item layout
415 $companyCol = $this->endLine - COMPANY_WIDTH;
416 $headerFieldCol = $this->leftMargin + LABEL_WIDTH;
417 $pageNumCol = $this->endLine - PAGE_NUM_WIDTH;
418 $footerCol = $this->leftMargin + PAGE_NUM_WIDTH;
419 $footerRow = $this->bottomMargin - FOOTER_MARGIN;
421 // Calling this function generates a new PDF page after the first instance
423 if ($this->pageNumber > 1)
425 // // TODO: experimenting with line drawing to highlight current period
426 // $this->SetLineWidth(1);
427 // $this->LineTo($this->cols[3], 33, $this->cols[3], 534);
428 // $this->LineTo($this->cols[4], 33, $this->cols[4], 534);
429 // $this->SetLineWidth(0.1);
433 $this->row = $this->pageHeight - $this->topMargin;
435 // Set the color of dividing lines we'll draw
436 $oldDrawColor = $this->GetDrawColor();
437 $this->SetDrawColor(128, 128, 128);
439 // Tell TCPDF that we want to use its alias system to track the total number of pages
440 $this->AliasNbPages();
443 if ($this->footerEnable)
445 $this->Line($footerRow, 1);
446 $prevFontSize = $this->fontSize;
447 $this->fontSize = FOOTER_FONT_SIZE;
448 $this->TextWrap($footerCol, $footerRow - ($this->fontSize + 1),
449 $pageNumCol - $footerCol, $this->footerText, $align = 'center',
450 $border = 0, $fill = 0, $link = NULL, $stretch = 1);
451 $this->TextWrap($pageNumCol, $footerRow - ($this->fontSize + 1),
452 PAGE_NUM_WIDTH, _("Page") . ' ' . $this->pageNumber . '/' . $this->getAliasNbPages(),
453 $align = 'right', $border = 0, $fill = 0, $link = NULL, $stretch = 1);
454 $this->fontSize = $prevFontSize;
461 // Print gray line across the page
462 $this->Line($this->row + 8, 1);
466 // Print the report title nice and big
467 $oldFontSize = $this->fontSize;
468 $this->fontSize = TITLE_FONT_SIZE;
470 $this->Text($this->leftMargin, $this->title, $companyCol);
471 $this->fontSize = HEADER1_FONT_SIZE;
473 // Print company logo if present and requested, or else just print company name
474 if ($this->companyLogoEnable && ($this->company['coy_logo'] != ''))
476 // Build a string specifying the location of the company logo file
477 $logo = $comp_path .'/'. user_company() . "/images/" . $this->company['coy_logo'];
479 // Width being zero means that the image will be scaled to the specified height
480 // keeping its aspect ratio intact.
481 if ($this->scaleLogoWidth)
482 $this->AddImage($logo, $companyCol, $this->row, COMPANY_WIDTH, 0);
484 $this->AddImage($logo, $companyCol, $this->row - (LOGO_HEIGHT * LOGO_Y_POS_ADJ_FACTOR), 0, LOGO_HEIGHT);
487 $this->Text($companyCol, $this->company['coy_name']);
489 // Dimension 1 - optional
490 // - only print if available and not blank
491 if (count($this->params) > 3)
492 if ($this->params[3]['from'] != '')
494 $this->NewLine(1, 0, $this->fontSize + 2);
495 $str = $this->params[3]['text'] . ':';
496 $this->Text($this->leftMargin, $str, $headerFieldCol);
497 $str = $this->params[3]['from'];
498 $this->Text($headerFieldCol, $str, $companyCol);
501 // Dimension 2 - optional
502 // - only print if available and not blank
503 if (count($this->params) > 4)
504 if ($this->params[4]['from'] != '')
506 $this->NewLine(1, 0, $this->fontSize + 2);
507 $str = $this->params[4]['text'] . ':';
508 $this->Text($this->leftMargin, $str, $headerFieldCol);
509 $str = $this->params[4]['from'];
510 $this->Text($headerFieldCol, $str, $companyCol);
514 // if present, it's an array of tag names
515 if (count($this->params) > 5)
516 if ($this->params[5]['from'] != '')
518 $this->NewLine(1, 0, $this->fontSize + 2);
519 $str = $this->params[5]['text'] . ':';
520 $this->Text($this->leftMargin, $str, $headerFieldCol);
522 for ($i = 0; $i < count($this->params[5]['from']); $i++)
526 $str .= $this->params[5]['from'][$i];
528 $this->Text($headerFieldCol, $str, $companyCol);
531 // Report Date - time period covered
532 // - can specify a range, or just the end date (and the report contents
533 // should make it obvious what the beginning date is)
534 $this->NewLine(1, 0, $this->fontSize + 2);
535 $str = _("Report Period") . ':';
536 $this->Text($this->leftMargin, $str, $headerFieldCol);
538 if (isset($this->params[1]['from']) && $this->params[1]['from'] != '')
539 $str = $this->params[1]['from'] . ' - ';
540 $str .= $this->params[1]['to'];
541 $this->Text($headerFieldCol, $str, $companyCol);
546 $this->NewLine(1, 0, $this->fontSize + 1);
548 // Make the remaining report headings a little less important
549 $this->fontSize = HEADER2_FONT_SIZE;
551 // Timestamp of when this copy of the report was generated
552 $str = _("Generated At") . ':';
553 $this->Text($this->leftMargin, $str, $headerFieldCol);
554 $str = Today() . ' ' . Now();
555 if ($this->company['time_zone'])
556 $str .= ' ' . date('O') . ' GMT';
557 $this->Text($headerFieldCol, $str, $companyCol);
559 // Name of the user that generated this copy of the report
560 $this->NewLine(1, 0, $this->fontSize + 1);
561 $str = _("Generated By") . ':';
562 $this->Text($this->leftMargin, $str, $headerFieldCol);
564 $this->Text($headerFieldCol, $str, $companyCol);
566 // Display any user-generated comments for this copy of the report
567 if ($this->params[0] != '') // Comments
569 $this->NewLine(1, 0, $this->fontSize + 1);
570 $str = _("Comments") . ':';
571 $this->Text($this->leftMargin, $str, $headerFieldCol);
573 $this->Text($headerFieldCol, $this->params[0], $companyCol, 0, 0, 'left', 0, 0, $link=NULL, 1);
577 // Add page numbering to header if footer is turned off
578 if (!$this->footerEnable)
580 $str = _("Page") . ' ' . $this->pageNumber . '/' . $this->getAliasNbPages();
581 $this->Text($pageNumCol, $str, 0, 0, 0, 'right', 0, 0, NULL, 1);
584 // Print gray line across the page
585 $this->Line($this->row - 5, 1);
587 // Restore font size to user-defined size
588 $this->fontSize = $oldFontSize;
590 // restore user-specified cell padding for column headers
591 $this->SetCellPadding($oldcMargin);
593 // scoot down the page a bit
594 $oldLineHeight = $this->lineHeight;
595 $this->lineHeight = $this->fontSize + 1;
596 $this->row -= ($this->lineHeight + 6);
597 $this->lineHeight = $oldLineHeight;
599 // Print the column headers!
601 if ($this->headers2 != null)
603 $count = count($this->headers2);
604 for ($i = 0; $i < $count; $i++)
605 $this->TextCol2($i, $i + 1, $this->headers2[$i], $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1);
608 $count = count($this->headers);
609 for ($i = 0; $i < $count; $i++)
610 $this->TextCol($i, $i + 1, $this->headers[$i], $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1);
615 // restore user-specified draw color
616 $this->SetDrawColor($oldDrawColor[0], $oldDrawColor[1], $oldDrawColor[2]);
620 * Format a numeric string date into something nicer looking.
622 * @param string $date Date string to be formatted.
623 * @param int $input_format Format of the input string. Possible values are:<ul><li>0: user's default (default)</li></ul>
624 * @param int $output_format Format of the output string. Possible values are:<ul><li>0: Month (word) Day (numeric), 4-digit Year - Example: January 1, 2000 (default)</li><li>1: Month 4-digit Year - Example: January 2000</li><li>2: Month Abbreviation 4-digit Year - Example: Jan 2000</li></ul>
627 function DatePrettyPrint($date, $input_format = 0, $output_format = 0)
631 $date = date2sql($date);
632 $year = (int) (substr($date, 0, 4));
633 $month = (int) (substr($date, 5, 2));
634 $day = (int) (substr($date, 8, 2));
635 if ($output_format == 0)
636 return(date('F j, Y', mktime(12, 0, 0, $month, $day, $year)));
637 elseif ($output_format == 1)
638 return(date('F Y', mktime(12, 0, 0, $month, $day, $year)));
639 elseif ($output_format == 2)
640 return(date('M Y', mktime(12, 0, 0, $month, $day, $year)));
646 function AddImage($logo, $x, $y, $w, $h)
648 if (strpos($logo, ".png") || strpos($logo, ".PNG"))
649 $this->addPngFromFile($logo, $x, $y, $w, $h);
651 $this->addJpegFromFile($logo, $x, $y, $w, $h);
654 // Get current draw color setting from TCPDF object; returns array of RGB numbers
655 function GetDrawColor()
657 // Convert the TCPDF stored DrawColor string into an array of strings
658 $colorFields = explode(' ', $this->DrawColor);
660 // Test last value: G == grayscale, single number; RG == RGB, 3 numbers
661 if ($colorFields[count($colorFields) - 1] == 'G')
662 // Convert a grayscale string value to the equivalent RGB value
663 $drawColor = array((float) $colorFields[0], (float) $colorFields[0], (float) $colorFields[0]);
665 // Convert RGB string values to the a numeric array
666 $drawColor = array((float) $colorFields[0], (float) $colorFields[1], (float) $colorFields[2]);
671 function SetDrawColor($r, $g, $b)
673 parent::SetDrawColor($r, $g, $b);
676 function SetTextColor($r, $g, $b)
678 parent::SetTextColor($r, $g, $b);
682 * Set the fill color for table cells.
683 * @see reporting/includes/TCPDF#SetFillColor($col1, $col2, $col3, $col4)
685 function SetFillColor($r, $g, $b)
687 parent::SetFillColor($r, $g, $b);
690 // Get current cell padding setting from TCPDF object
691 function GetCellPadding()
693 return $this->cMargin;
696 // Set desired cell padding (aka "cell margin")
697 // Seems to be just left and right margins...
698 function SetCellPadding($pad)
700 parent::SetCellPadding($pad);
703 function Text($c, $txt, $n=0, $corr=0, $r=0, $align='left', $border=0, $fill=0, $link=NULL, $stretch=1)
706 $n = $this->pageWidth - $this->rightMargin;
708 return $this->TextWrap($c, $this->row - $r, $n - $c + $corr, $txt, $align, $border, $fill, $link, $stretch);
711 function TextWrap($xpos, $ypos, $len, $str, $align = 'left', $border = 0, $fill = 0, $link = NULL, $stretch = 1)
713 if ($this->fontSize != $this->oldFontSize)
715 $this->SetFontSize($this->fontSize);
716 $this->oldFontSize = $this->fontSize;
718 return $this->addTextWrap($xpos, $ypos, $len, $this->fontSize, $str, $align, $border, $fill, $link, $stretch);
721 function TextCol($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
723 return $this->TextWrap($this->cols[$c], $this->row - $r, $this->cols[$n] - $this->cols[$c] + $corr, $txt, $this->aligns[$c], $border, $fill, $link, $stretch);
726 function AmountCol($c, $n, $txt, $dec=0, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1, $color_red=false)
728 if ($color_red && $txt < 0)
729 $this->SetTextColor(255, 0, 0);
730 $ret = $this->TextCol($c, $n, number_format2($txt, $dec), $corr, $r, $border, $fill, $link, $stretch);
731 if ($color_red && $txt < 0)
732 $this->SetTextColor(0, 0, 0);
736 function AmountCol2($c, $n, $txt, $dec=0, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1, $color_red=false, $amount_locale = 'en_US.UTF-8', $amount_format = '%(!.2n')
738 setlocale(LC_MONETARY, $amount_locale);
739 if ($color_red && $txt < 0)
740 $this->SetTextColor(255, 0, 0);
741 $ret = $this->TextCol($c, $n, money_format($amount_format, $txt), $corr, $r, $border, $fill, $link, $stretch);
742 if ($color_red && $txt < 0)
743 $this->SetTextColor(0, 0, 0);
747 function DateCol($c, $n, $txt, $conv=false, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
750 $txt = sql2date($txt);
751 return $this->TextCol($c, $n, $txt, $corr, $r, $border, $fill, $link, $stretch);
754 function TextCol2($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
756 return $this->TextWrap($this->cols2[$c], $this->row - $r, $this->cols2[$n] - $this->cols2[$c] + $corr, $txt, $this->aligns2[$c], $border, $fill, $link, $stretch);
759 function TextColLines($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
762 $this->TextWrapLines($this->cols[$c], $this->cols[$n] - $this->cols[$c] + $corr, $txt, $this->aligns[$c], $border, $fill, $link, $stretch);
765 function TextWrapLines($c, $width, $txt, $align='left', $border=0, $fill=0, $link=NULL, $stretch=1)
767 $str = Explode("\n", $txt);
768 for ($i = 0; $i < count($str); $i++)
773 $l = $this->TextWrap($c, $this->row , $width, $l, $align, $border, $fill, $link, $stretch);
774 $this->row -= $this->lineHeight;
781 * Expose the underlying calcTextWrap() function in this API.
783 function TextWrapCalc($txt, $width, $spacebreak=false)
785 return $this->calcTextWrap($txt, $width, $spacebreak);
789 * Sets the line drawing style.
791 * Takes an associative array as arg so you don't need to specify all values.
794 * width (float) - the thickness of the line in user units
795 * cap (string) - the type of cap to put on the line, values can be 'butt','round','square'
796 * where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
798 * join (string) - can be 'miter', 'round', 'bevel'
799 * dash (mixed) - Dash pattern. Is 0 (without dash) or string with series of length values, which are the
800 * lengths of the on and off dashes. For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...;
801 * "2,1" is 2 on, 1 off, 2 on, 1 off, ...
802 * phase (integer) - a modifier on the dash pattern which is used to shift the point at which the pattern starts.
803 * color (array) - draw color. Format: array(GREY), or array(R,G,B) or array(C,M,Y,K).
805 function SetLineStyle($style)
807 parent::SetLineStyle($style);
811 * Sets the line drawing width.
813 function SetLineWidth($width)
815 parent::SetLineWidth($width);
818 function LineTo($from, $row, $to, $row2)
820 parent::line($from, $row, $to, $row2);
823 function Line($row, $height = 0)
825 $oldLineWidth = $this->GetLineWidth();
826 $this->SetLineWidth($height + 1);
827 parent::line($this->pageWidth - $this->rightMargin, $row ,$this->leftMargin, $row);
828 $this->SetLineWidth($oldLineWidth);
832 * Underlines the contents of a cell, but not the cell padding area.
833 * Primarily useful for the last line before a "totals" line.
834 * @param int $c Column number to underline.
835 * @param int $r Print the underline(s) this number of rows below the current position. Can be negative in order to go up.
836 * @param int $type Type of underlining to draw. Possible values are:<ul><li>1: single underline (default)</li><li>2: double underline</li></ul>
837 * @param int $linewidth Thickness of the line to draw. Default value of zero will use the current line width defined for this document.
838 * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
840 * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
842 function UnderlineCell($c, $r = 0, $type = 1, $linewidth = 0, $style = array())
844 // If line width was specified, save current setting so we can reset it
847 $oldLineWidth = $this->GetLineWidth();
848 $this->SetLineWidth($linewidth);
851 // Figure out how far down to move the line based on current font size
852 // Calculate this because printing underline directly at $this->row goes on top
853 // of the parts of characters that "hang down", like the bottom of commas &
854 // lowercase letter 'g', etc.
855 if ($this->fontSize < 10)
859 parent::line($this->cols[$c] + $this->cMargin, $this->row - $r - $y_adj, $this->cols[$c + 1] - $this->cMargin, $this->row - $r - $y_adj, $style);
861 // Double underline, far enough below the first underline so as not to overlap
862 // the first underline (depends on current line thickness (aka "line width")
864 parent::line($this->cols[$c] + $this->cMargin, $this->row - $r - $y_adj - ($this->GetLineWidth() + 2), $this->cols[$c + 1] - $this->cMargin, $this->row - $r - $y_adj - ($this->GetLineWidth() + 2), $style);
866 // If line width was specified, reset it back to the original setting
868 $this->SetLineWidth($oldLineWidth);
871 function NewLine($l=1, $np=0, $h = NULL)
873 // If the line height wasn't specified, use the current setting
875 $h = $this->lineHeight;
877 // Move one line down the page
878 $this->row -= ($l * $h);
880 // Check to see if we're at the bottom and should insert a page break
881 if ($this->row < $this->bottomMargin + ($np * $h))
882 $this->{$this->headerFunc}(); // call header template chosen by current report
885 function End($email=0, $subject=null, $myrow=null, $doctype = 0)
887 global $pdf_debug, $path_to_root, $comp_path;
891 $pdfcode = $this->Output('','S');
892 $pdfcode = str_replace("\n", "\n<br>", htmlspecialchars($pdfcode));
895 echo '</body></html>';
896 //header("Content-Length: $len");
897 //header("Content-Disposition: inline; filename=" . $this->filename);
898 //header('Expires: 0');
899 //header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
900 //header('Pragma: public');
902 //$this->pdf->stream();
907 $dir = $comp_path.'/'.user_company(). '/pdf_files';
909 if (!file_exists($dir))
913 // do not use standard filenames or your sensitive company data
914 // are world readable
916 $fname = $dir.'/'.$this->filename;
918 $fname = $dir.'/'.uniqid('').'.pdf';
919 $this->Output($fname, 'F');
923 if ($this->currency != $myrow['curr_code'])
925 include("includes/doctext2.inc");
929 include("includes/doctext.inc");
931 require_once($path_to_root . "/reporting/includes/class.mail.inc");
932 $mail = new email($this->company['coy_name'], $this->company['email']);
933 if (!isset($myrow['email']) || $myrow['email'] == '')
934 $myrow['email'] = isset($myrow['contact_email']) ? $myrow['contact_email'] : '';
935 $to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">";
936 $msg = $doc_Dear_Sirs . " " . $myrow['DebtorName'] . ",\n\n" . $doc_AttachedFile . " " . $subject .
938 if (isset($myrow['dimension_id']) && $myrow['dimension_id'] > 0 && $doctype == ST_SALESINVOICE) // helper for payment links
940 if ($myrow['dimension_id'] == 1)
942 $amt = number_format($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"], user_price_dec());
943 $txt = $doc_Payment_Link . " PayPal: ";
944 $nn = urlencode($this->title . " " . $myrow['reference']);
945 $url = "https://www.paypal.com/xclick/business=" . $this->company['email'] . "&item_name=" .
946 $nn . "&amount=" . $amt . "¤cy_code=" . $myrow['curr_code'];
947 $msg .= $txt . $url . "\n\n";
950 $msg .= $doc_Kindest_regards . "\n\n";
951 $sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone'];
953 $mail->subject($subject);
954 $mail->text($msg . $sender);
955 $mail->attachment($fname);
956 $ret = $mail->send();
958 display_error(_("Sending document by email failed"));
960 display_notification($this->title . " " . $myrow['reference'] . " "
961 . _("has been sent by email."));
966 $printer = get_report_printer(user_print_profile(), $_POST['REP_ID']);
967 if ($printer == false) {
971 if (user_rep_popup())
972 $Ajax->popup($fname); // when embeded pdf viewer used
974 $Ajax->redirect($fname); // otherwise use faster method
978 // <SCRIPT LANGUAGE="JavaScript"><!--
979 // function go_now () { window.location.href = "'.$fname.'"; }
982 // <body onLoad="go_now()"; >
983 // <a href="'.$fname.'">click here</a> if you are not re-directed.
986 header('Content-type: application/pdf');
987 header("Content-Disposition: inline; filename=$this->filename");
988 header('Expires: 0');
989 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
990 header('Pragma: public');
994 } else { // send report to network printer
995 $prn = new remote_printer($printer['queue'],$printer['host'],
996 $printer['port'], $printer['timeout']);
997 $error = $prn->print_file($fname);
999 display_error($error);
1001 display_notification(_('Report has been sent to network printer ').$printer['name']);
1004 // first have a look through the directory,
1005 // and remove old temporary pdfs
1006 if ($d = @opendir($dir)) {
1007 while (($file = readdir($d)) !== false) {
1008 if (!is_file($dir.'/'.$file) || $file == 'index.php') continue;
1009 // then check to see if this one is too old
1010 $ftime = filemtime($dir.'/'.$file);
1011 // seems 3 min is enough for any report download, isn't it?
1012 if (time()-$ftime > 180){
1013 unlink($dir.'/'.$file);