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/printers_db.inc");
17 include_once($path_to_root . "/config.php");
18 class FrontReport extends Cpdf
48 var $companyLogoEnable; // select whether to use a company logo graphic in some header templates
50 var $footerEnable; // select whether to print a page footer or not
51 var $footerText; // store user-generated footer text
52 var $headerFunc; // store the name of the currently selected header function
54 function FrontReport($title, $filename, $size = 'A4', $fontsize = 9, $orientation = 'P', $margins = NULL, $excelColWidthFactor = NULL)
56 global $page_security;
57 if (!$_SESSION["wa_current_user"]->can_access_page($page_security))
59 display_error(_("The security settings on your account do not permit you to print this report"));
63 // Page margins - if user-specified, use those. Otherwise, use defaults below.
66 $this->topMargin = $margins['top'];
67 $this->bottomMargin = $margins['bottom'];
68 $this->leftMargin = $margins['left'];
69 $this->rightMargin = $margins['right'];
71 // Page orientation - P: portrait, L: landscape
72 $orientation = strtoupper($orientation);
74 switch (strtoupper($size))
79 if ($orientation == 'P')
82 $this->pageHeight=842;
86 $this->bottomMargin=30;
88 $this->rightMargin=30;
95 $this->pageHeight=595;
99 $this->bottomMargin=30;
100 $this->leftMargin=40;
101 $this->rightMargin=30;
107 if ($orientation == 'P')
109 $this->pageWidth=842;
110 $this->pageHeight=1190;
111 if (!isset($margins))
114 $this->bottomMargin=50;
115 $this->leftMargin=50;
116 $this->rightMargin=40;
122 $this->pageWidth=1190;
123 $this->pageHeight=842;
124 if (!isset($margins))
127 $this->bottomMargin=50;
128 $this->leftMargin=50;
129 $this->rightMargin=40;
135 if ($orientation == 'P')
137 $this->pageWidth=612;
138 $this->pageHeight=792;
139 if (!isset($margins))
142 $this->bottomMargin=30;
143 $this->leftMargin=30;
144 $this->rightMargin=25;
150 $this->pageWidth=792;
151 $this->pageHeight=612;
152 if (!isset($margins))
155 $this->bottomMargin=30;
156 $this->leftMargin=30;
157 $this->rightMargin=25;
163 if ($orientation == 'P')
165 $this->pageWidth=612;
166 $this->pageHeight=1008;
167 if (!isset($margins))
170 $this->bottomMargin=40;
171 $this->leftMargin=30;
172 $this->rightMargin=25;
178 $this->pageWidth=1008;
179 $this->pageHeight=612;
180 if (!isset($margins))
183 $this->bottomMargin=40;
184 $this->leftMargin=30;
185 $this->rightMargin=25;
190 $this->size = array(0, 0, $this->pageWidth, $this->pageHeight);
191 $this->title = $title;
192 $this->filename = $filename.".pdf";
193 $this->pageNumber = 0;
194 $this->endLine = $this->pageWidth - $this->rightMargin;
195 $this->lineHeight = 12;
196 $this->fontSize = $fontsize;
197 $this->oldFontSize = 0;
198 $this->row = $this->pageHeight - $this->topMargin;
199 $this->currency = '';
200 $this->scaleLogoWidth = false; // if Logo, scale on width (else height).
201 $this->headerFunc = 'Header'; // default to the original header template
202 $rtl = ($_SESSION['language']->dir === 'rtl' ? 'rtl' : 'ltr');
203 $code = $_SESSION['language']->code;
204 $enc = strtoupper($_SESSION['language']->encoding);
205 // for the language array in class.pdf.inc
206 $l = array('a_meta_charset' => $enc, 'a_meta_dir' => $rtl, 'a_meta_language' => $code, 'w_page' => 'page');
207 $this->Cpdf($size, $l, $orientation);
211 * Select the font and style to use for following output until
212 * it's changed again.
215 * * a special case string (for backwards compatible with older code):
218 * * or a case-insensitive string where each char represents a style choice
219 * and you can use more than one or none at all. Possible choices:
220 * * empty string: regular
224 * * D: line trough (aka "strike through")
225 * $fontname should be a standard PDF font (like 'times', 'helvetica' or 'courier')
226 * or one that's been installed on your system (see TCPDF docs for details).
227 * An empty string can also be used which will retain the font currently in use if
228 * you just want to change the style.
230 function Font($style = '', $fontname = '')
232 $this->selectFont($fontname, $style);
235 function Info($params, $cols, $headers, $aligns,
236 $cols2 = null, $headers2 = null, $aligns2 = null,
237 $companylogoenable = false, $footerenable = false, $footertext = '')
239 global $app_title, $version, $power_by, $power_url;
241 $this->addinfo('Title', $this->title);
242 $this->addinfo('Subject', $this->title);
243 $this->addinfo('Author', $app_title . ' ' . $version);
244 $this->addinfo('Creator',$power_by . ' - ' . $power_url);
245 $year = get_current_fiscalyear();
246 if ($year['closed'] == 0)
250 $this->fiscal_year = sql2date($year['begin']) . " - " . sql2date($year['end']) . " " . "(" . $how . ")";
251 $this->company = get_company_prefs();
252 $this->user = $_SESSION["wa_current_user"]->name;
253 $this->host = $_SERVER['SERVER_NAME'];
254 $this->params = $params;
256 for ($i = 0; $i < count($this->cols); $i++)
257 $this->cols[$i] += $this->leftMargin;
258 $this->headers = $headers;
259 $this->aligns = $aligns;
260 $this->cols2 = $cols2;
261 if ($this->cols2 != null)
263 for ($i = 0; $i < count($this->cols2); $i++)
264 $this->cols2[$i] += $this->leftMargin;
266 $this->headers2 = $headers2;
267 $this->aligns2 = $aligns2;
269 // Set whether to display company logo in some header templates
270 $this->companyLogoEnable = $companylogoenable;
272 // Store footer settings
273 $this->footerEnable = $footerenable;
274 $this->footerText = $footertext;
279 $companyCol = $this->endLine - 150;
280 $titleCol = $this->leftMargin + 100;
283 if ($this->pageNumber > 1)
285 $this->row = $this->pageHeight - $this->topMargin;
287 $this->SetDrawColor(128, 128, 128);
288 $this->Line($this->row + 5, 1);
292 $this->fontSize += 4;
294 $this->Text($this->leftMargin, $this->title, $companyCol);
296 $this->fontSize -= 4;
297 $this->Text($companyCol, $this->company['coy_name']);
298 $this->row -= ($this->lineHeight + 4);
300 $str = _("Print Out Date") . ':';
301 $this->Text($this->leftMargin, $str, $titleCol);
302 $str = Today() . ' ' . Now();
303 if ($this->company['time_zone'])
304 $str .= ' ' . date('O') . ' GMT';
305 $this->Text($titleCol, $str, $companyCol);
306 $this->Text($companyCol, $this->host);
309 $str = _("Fiscal Year") . ':';
310 $this->Text($this->leftMargin, $str, $titleCol);
311 $str = $this->fiscal_year;
312 $this->Text($titleCol, $str, $companyCol);
313 $this->Text($companyCol, $this->user);
314 for ($i = 1; $i < count($this->params); $i++)
316 if ($this->params[$i]['from'] != '')
319 $str = $this->params[$i]['text'] . ':';
320 $this->Text($this->leftMargin, $str, $titleCol);
321 $str = $this->params[$i]['from'];
322 if ($this->params[$i]['to'] != '')
323 $str .= " - " . $this->params[$i]['to'];
324 $this->Text($titleCol, $str, $companyCol);
327 if ($this->params[0] != '') // Comments
330 $str = _("Comments") . ':';
331 $this->Text($this->leftMargin, $str, $titleCol);
333 $this->Text($titleCol, $this->params[0], $this->endLine - 35);
336 $str = _("Page") . ' ' . $this->pageNumber;
337 $this->Text($this->endLine - 38, $str);
338 $this->Line($this->row - 5, 1);
340 $this->row -= ($this->lineHeight + 6);
341 $this->Font('italic');
342 if ($this->headers2 != null)
344 $count = count($this->headers2);
345 for ($i = 0; $i < $count; $i++)
346 $this->TextCol2($i, $i + 1, $this->headers2[$i]);
349 $count = count($this->headers);
350 for ($i = 0; $i < $count; $i++)
351 $this->TextCol($i, $i + 1, $this->headers[$i]);
353 $this->Line($this->row - 5, 1);
358 function Header2($myrow, $branch, $sales_order, $bankaccount, $doctype)
360 global $comp_path, $path_to_root, $print_as_quote, $print_invoice_no, $packing_slip;
363 if ($this->pageNumber > 1)
366 if (isset($myrow['curr_code']) && $this->currency != $myrow['curr_code'])
368 include($path_to_root . "/reporting/includes/doctext2.inc");
372 include($path_to_root . "/reporting/includes/doctext.inc");
375 include($path_to_root . "/reporting/includes/header2.inc");
380 // Alternate header style which also supports a simple footer
385 // Make this header the default for the current report ( used by NewLine() )
386 $this->headerFunc = 'Header3';
388 // Turn off cell padding for the main report header, restoring the current setting later
389 $oldcMargin = $this->cMargin;
390 $this->SetCellPadding(0);
392 // Set some constants which control header item layout
393 // only set them once or the PHP interpreter gets angry
394 if ($this->pageNumber == 0)
396 define('COMPANY_WIDTH', 150);
397 define('LOGO_HEIGHT', 50);
398 define('LOGO_Y_POS_ADJ_FACTOR', 0.74);
399 define('LABEL_WIDTH', 80);
400 define('PAGE_NUM_WIDTH', 60);
401 define('TITLE_FONT_SIZE', 14);
402 define('HEADER1_FONT_SIZE', 10);
403 define('HEADER2_FONT_SIZE', 9);
404 define('FOOTER_FONT_SIZE', 10);
405 define('FOOTER_MARGIN', 4);
407 // Set some variables which control header item layout
408 $companyCol = $this->endLine - COMPANY_WIDTH;
409 $headerFieldCol = $this->leftMargin + LABEL_WIDTH;
410 $pageNumCol = $this->endLine - PAGE_NUM_WIDTH;
411 $footerCol = $this->leftMargin + PAGE_NUM_WIDTH;
412 $footerRow = $this->bottomMargin - FOOTER_MARGIN;
414 // Calling this function generates a new PDF page after the first instance
416 if ($this->pageNumber > 1)
418 // // TODO: experimenting with line drawing to highlight current period
419 // $this->SetLineWidth(1);
420 // $this->LineTo($this->cols[3], 33, $this->cols[3], 534);
421 // $this->LineTo($this->cols[4], 33, $this->cols[4], 534);
422 // $this->SetLineWidth(0.1);
426 $this->row = $this->pageHeight - $this->topMargin;
428 // Set the color of dividing lines we'll draw
429 $oldDrawColor = $this->GetDrawColor();
430 $this->SetDrawColor(128, 128, 128);
432 // Tell TCPDF that we want to use its alias system to track the total number of pages
433 $this->AliasNbPages();
436 if ($this->footerEnable)
438 $this->Line($footerRow, 1);
439 $prevFontSize = $this->fontSize;
440 $this->fontSize = FOOTER_FONT_SIZE;
441 $this->TextWrap($footerCol, $footerRow - ($this->fontSize + 1),
442 $pageNumCol - $footerCol, $this->footerText, $align = 'center',
443 $border = 0, $fill = 0, $link = NULL, $stretch = 1);
444 $this->TextWrap($pageNumCol, $footerRow - ($this->fontSize + 1),
445 PAGE_NUM_WIDTH, _("Page") . ' ' . $this->pageNumber . '/' . $this->getAliasNbPages(),
446 $align = 'right', $border = 0, $fill = 0, $link = NULL, $stretch = 1);
447 $this->fontSize = $prevFontSize;
454 // Print gray line across the page
455 $this->Line($this->row + 8, 1);
459 // Print the report title nice and big
460 $oldFontSize = $this->fontSize;
461 $this->fontSize = TITLE_FONT_SIZE;
463 $this->Text($this->leftMargin, $this->title, $companyCol);
464 $this->fontSize = HEADER1_FONT_SIZE;
466 // Print company logo if present and requested, or else just print company name
467 if ($this->companyLogoEnable && ($this->company['coy_logo'] != ''))
469 // Build a string specifying the location of the company logo file
470 $logo = $comp_path .'/'. user_company() . "/images/" . $this->company['coy_logo'];
472 // Width being zero means that the image will be scaled to the specified height
473 // keeping its aspect ratio intact.
474 if ($this->scaleLogoWidth)
475 $this->AddImage($logo, $companyCol, $this->row, COMPANY_WIDTH, 0);
477 $this->AddImage($logo, $companyCol, $this->row - (LOGO_HEIGHT * LOGO_Y_POS_ADJ_FACTOR), 0, LOGO_HEIGHT);
480 $this->Text($companyCol, $this->company['coy_name']);
482 // Dimension 1 - optional
483 // - only print if available and not blank
484 if (count($this->params) > 3)
485 if ($this->params[3]['from'] != '')
487 $this->NewLine(1, 0, $this->fontSize + 2);
488 $str = $this->params[3]['text'] . ':';
489 $this->Text($this->leftMargin, $str, $headerFieldCol);
490 $str = $this->params[3]['from'];
491 $this->Text($headerFieldCol, $str, $companyCol);
494 // Dimension 2 - optional
495 // - only print if available and not blank
496 if (count($this->params) > 4)
497 if ($this->params[4]['from'] != '')
499 $this->NewLine(1, 0, $this->fontSize + 2);
500 $str = $this->params[4]['text'] . ':';
501 $this->Text($this->leftMargin, $str, $headerFieldCol);
502 $str = $this->params[4]['from'];
503 $this->Text($headerFieldCol, $str, $companyCol);
507 // if present, it's an array of tag names
508 if (count($this->params) > 5)
509 if ($this->params[5]['from'] != '')
511 $this->NewLine(1, 0, $this->fontSize + 2);
512 $str = $this->params[5]['text'] . ':';
513 $this->Text($this->leftMargin, $str, $headerFieldCol);
515 for ($i = 0; $i < count($this->params[5]['from']); $i++)
519 $str .= $this->params[5]['from'][$i];
521 $this->Text($headerFieldCol, $str, $companyCol);
524 // Report Date - time period covered
525 // - can specify a range, or just the end date (and the report contents
526 // should make it obvious what the beginning date is)
527 $this->NewLine(1, 0, $this->fontSize + 2);
528 $str = _("Report Period") . ':';
529 $this->Text($this->leftMargin, $str, $headerFieldCol);
531 if (isset($this->params[1]['from']) && $this->params[1]['from'] != '')
532 $str = $this->params[1]['from'] . ' - ';
533 $str .= $this->params[1]['to'];
534 $this->Text($headerFieldCol, $str, $companyCol);
539 $this->NewLine(1, 0, $this->fontSize + 1);
541 // Make the remaining report headings a little less important
542 $this->fontSize = HEADER2_FONT_SIZE;
544 // Timestamp of when this copy of the report was generated
545 $str = _("Generated At") . ':';
546 $this->Text($this->leftMargin, $str, $headerFieldCol);
547 $str = Today() . ' ' . Now();
548 if ($this->company['time_zone'])
549 $str .= ' ' . date('O') . ' GMT';
550 $this->Text($headerFieldCol, $str, $companyCol);
552 // Name of the user that generated this copy of the report
553 $this->NewLine(1, 0, $this->fontSize + 1);
554 $str = _("Generated By") . ':';
555 $this->Text($this->leftMargin, $str, $headerFieldCol);
557 $this->Text($headerFieldCol, $str, $companyCol);
559 // Display any user-generated comments for this copy of the report
560 if ($this->params[0] != '') // Comments
562 $this->NewLine(1, 0, $this->fontSize + 1);
563 $str = _("Comments") . ':';
564 $this->Text($this->leftMargin, $str, $headerFieldCol);
566 $this->Text($headerFieldCol, $this->params[0], $companyCol, 0, 0, 'left', 0, 0, $link=NULL, 1);
570 // Add page numbering to header if footer is turned off
571 if (!$this->footerEnable)
573 $str = _("Page") . ' ' . $this->pageNumber . '/' . $this->getAliasNbPages();
574 $this->Text($pageNumCol, $str, 0, 0, 0, 'right', 0, 0, NULL, 1);
577 // Print gray line across the page
578 $this->Line($this->row - 5, 1);
580 // Restore font size to user-defined size
581 $this->fontSize = $oldFontSize;
583 // restore user-specified cell padding for column headers
584 $this->SetCellPadding($oldcMargin);
586 // scoot down the page a bit
587 $oldLineHeight = $this->lineHeight;
588 $this->lineHeight = $this->fontSize + 1;
589 $this->row -= ($this->lineHeight + 6);
590 $this->lineHeight = $oldLineHeight;
592 // Print the column headers!
594 if ($this->headers2 != null)
596 $count = count($this->headers2);
597 for ($i = 0; $i < $count; $i++)
598 $this->TextCol2($i, $i + 1, $this->headers2[$i], $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1);
601 $count = count($this->headers);
602 for ($i = 0; $i < $count; $i++)
603 $this->TextCol($i, $i + 1, $this->headers[$i], $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1);
608 // restore user-specified draw color
609 $this->SetDrawColor($oldDrawColor[0], $oldDrawColor[1], $oldDrawColor[2]);
613 * Format a numeric string date into something nicer looking.
615 * @param string $date Date string to be formatted.
616 * @param int $input_format Format of the input string. Possible values are:<ul><li>0: user's default (default)</li></ul>
617 * @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>
620 function DatePrettyPrint($date, $input_format = 0, $output_format = 0)
624 $date = date2sql($date);
625 $year = (int) (substr($date, 0, 4));
626 $month = (int) (substr($date, 5, 2));
627 $day = (int) (substr($date, 8, 2));
628 if ($output_format == 0)
629 return(date('F j, Y', mktime(12, 0, 0, $month, $day, $year)));
630 elseif ($output_format == 1)
631 return(date('F Y', mktime(12, 0, 0, $month, $day, $year)));
632 elseif ($output_format == 2)
633 return(date('M Y', mktime(12, 0, 0, $month, $day, $year)));
639 function AddImage($logo, $x, $y, $w, $h)
641 if (strpos($logo, ".png") || strpos($logo, ".PNG"))
642 $this->addPngFromFile($logo, $x, $y, $w, $h);
644 $this->addJpegFromFile($logo, $x, $y, $w, $h);
647 // Get current draw color setting from TCPDF object; returns array of RGB numbers
648 function GetDrawColor()
650 // Convert the TCPDF stored DrawColor string into an array of strings
651 $colorFields = explode(' ', $this->DrawColor);
653 // Test last value: G == grayscale, single number; RG == RGB, 3 numbers
654 if ($colorFields[count($colorFields) - 1] == 'G')
655 // Convert a grayscale string value to the equivalent RGB value
656 $drawColor = array((float) $colorFields[0], (float) $colorFields[0], (float) $colorFields[0]);
658 // Convert RGB string values to the a numeric array
659 $drawColor = array((float) $colorFields[0], (float) $colorFields[1], (float) $colorFields[2]);
664 function SetDrawColor($r, $g, $b)
666 parent::SetDrawColor($r, $g, $b);
669 function SetTextColor($r, $g, $b)
671 parent::SetTextColor($r, $g, $b);
675 * Set the fill color for table cells.
676 * @see reporting/includes/TCPDF#SetFillColor($col1, $col2, $col3, $col4)
678 function SetFillColor($r, $g, $b)
680 parent::SetFillColor($r, $g, $b);
683 // Get current cell padding setting from TCPDF object
684 function GetCellPadding()
686 return $this->cMargin;
689 // Set desired cell padding (aka "cell margin")
690 // Seems to be just left and right margins...
691 function SetCellPadding($pad)
693 parent::SetCellPadding($pad);
696 function Text($c, $txt, $n=0, $corr=0, $r=0, $align='left', $border=0, $fill=0, $link=NULL, $stretch=1)
699 $n = $this->pageWidth - $this->rightMargin;
701 return $this->TextWrap($c, $this->row - $r, $n - $c + $corr, $txt, $align, $border, $fill, $link, $stretch);
704 function TextWrap($xpos, $ypos, $len, $str, $align = 'left', $border = 0, $fill = 0, $link = NULL, $stretch = 1)
706 if ($this->fontSize != $this->oldFontSize)
708 $this->SetFontSize($this->fontSize);
709 $this->oldFontSize = $this->fontSize;
711 return $this->addTextWrap($xpos, $ypos, $len, $this->fontSize, $str, $align, $border, $fill, $link, $stretch);
714 function TextCol($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
716 return $this->TextWrap($this->cols[$c], $this->row - $r, $this->cols[$n] - $this->cols[$c] + $corr, $txt, $this->aligns[$c], $border, $fill, $link, $stretch);
719 function AmountCol($c, $n, $txt, $dec=0, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1, $color_red=false)
721 if ($color_red && $txt < 0)
722 $this->SetTextColor(255, 0, 0);
723 $ret = $this->TextCol($c, $n, number_format2($txt, $dec), $corr, $r, $border, $fill, $link, $stretch);
724 if ($color_red && $txt < 0)
725 $this->SetTextColor(0, 0, 0);
729 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')
731 setlocale(LC_MONETARY, $amount_locale);
732 if ($color_red && $txt < 0)
733 $this->SetTextColor(255, 0, 0);
734 $ret = $this->TextCol($c, $n, money_format($amount_format, $txt), $corr, $r, $border, $fill, $link, $stretch);
735 if ($color_red && $txt < 0)
736 $this->SetTextColor(0, 0, 0);
740 function DateCol($c, $n, $txt, $conv=false, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
743 $txt = sql2date($txt);
744 return $this->TextCol($c, $n, $txt, $corr, $r, $border, $fill, $link, $stretch);
747 function TextCol2($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
749 return $this->TextWrap($this->cols2[$c], $this->row - $r, $this->cols2[$n] - $this->cols2[$c] + $corr, $txt, $this->aligns2[$c], $border, $fill, $link, $stretch);
752 function TextColLines($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
755 $this->TextWrapLines($this->cols[$c], $this->cols[$n] - $this->cols[$c] + $corr, $txt, $this->aligns[$c], $border, $fill, $link, $stretch);
758 function TextWrapLines($c, $width, $txt, $align='left', $border=0, $fill=0, $link=NULL, $stretch=1)
760 $str = Explode("\n", $txt);
761 for ($i = 0; $i < count($str); $i++)
766 $l = $this->TextWrap($c, $this->row , $width, $l, $align, $border, $fill, $link, $stretch);
767 $this->row -= $this->lineHeight;
774 * Expose the underlying calcTextWrap() function in this API.
776 function TextWrapCalc($txt, $width, $spacebreak=false)
778 return $this->calcTextWrap($txt, $width, $spacebreak);
782 * Sets the line drawing style.
784 * Takes an associative array as arg so you don't need to specify all values.
787 * width (float) - the thickness of the line in user units
788 * cap (string) - the type of cap to put on the line, values can be 'butt','round','square'
789 * where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
791 * join (string) - can be 'miter', 'round', 'bevel'
792 * dash (mixed) - Dash pattern. Is 0 (without dash) or string with series of length values, which are the
793 * lengths of the on and off dashes. For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...;
794 * "2,1" is 2 on, 1 off, 2 on, 1 off, ...
795 * phase (integer) - a modifier on the dash pattern which is used to shift the point at which the pattern starts.
796 * color (array) - draw color. Format: array(GREY), or array(R,G,B) or array(C,M,Y,K).
798 function SetLineStyle($style)
800 parent::SetLineStyle($style);
804 * Sets the line drawing width.
806 function SetLineWidth($width)
808 parent::SetLineWidth($width);
811 function LineTo($from, $row, $to, $row2)
813 parent::line($from, $row, $to, $row2);
816 function Line($row, $height = 0)
818 $oldLineWidth = $this->GetLineWidth();
819 $this->SetLineWidth($height + 1);
820 parent::line($this->pageWidth - $this->rightMargin, $row ,$this->leftMargin, $row);
821 $this->SetLineWidth($oldLineWidth);
825 * Underlines the contents of a cell, but not the cell padding area.
826 * Primarily useful for the last line before a "totals" line.
827 * @param int $c Column number to underline.
828 * @param int $r Print the underline(s) this number of rows below the current position. Can be negative in order to go up.
829 * @param int $type Type of underlining to draw. Possible values are:<ul><li>1: single underline (default)</li><li>2: double underline</li></ul>
830 * @param int $linewidth Thickness of the line to draw. Default value of zero will use the current line width defined for this document.
831 * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
833 * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
835 function UnderlineCell($c, $r = 0, $type = 1, $linewidth = 0, $style = array())
837 // If line width was specified, save current setting so we can reset it
840 $oldLineWidth = $this->GetLineWidth();
841 $this->SetLineWidth($linewidth);
844 // Figure out how far down to move the line based on current font size
845 // Calculate this because printing underline directly at $this->row goes on top
846 // of the parts of characters that "hang down", like the bottom of commas &
847 // lowercase letter 'g', etc.
848 if ($this->fontSize < 10)
852 parent::line($this->cols[$c] + $this->cMargin, $this->row - $r - $y_adj, $this->cols[$c + 1] - $this->cMargin, $this->row - $r - $y_adj, $style);
854 // Double underline, far enough below the first underline so as not to overlap
855 // the first underline (depends on current line thickness (aka "line width")
857 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);
859 // If line width was specified, reset it back to the original setting
861 $this->SetLineWidth($oldLineWidth);
864 function NewLine($l=1, $np=0, $h = NULL)
866 // If the line height wasn't specified, use the current setting
868 $h = $this->lineHeight;
870 // Move one line down the page
871 $this->row -= ($l * $h);
872 // Reset the "current line height" for the new line
873 $this->curLineHeight = $this->fontSize;
874 // Check to see if we're at the bottom and should insert a page break
875 if ($this->row < $this->bottomMargin + ($np * $h))
876 $this->{$this->headerFunc}(); // call header template chosen by current report
879 function End($email=0, $subject=null, $myrow=null, $doctype = 0)
881 global $pdf_debug, $path_to_root, $comp_path;
885 $pdfcode = $this->Output('','S');
886 $pdfcode = str_replace("\n", "\n<br>", htmlspecialchars($pdfcode));
889 echo '</body></html>';
890 //header("Content-Length: $len");
891 //header("Content-Disposition: inline; filename=" . $this->filename);
892 //header('Expires: 0');
893 //header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
894 //header('Pragma: public');
896 //$this->pdf->stream();
901 $dir = $comp_path.'/'.user_company(). '/pdf_files';
903 if (!file_exists($dir))
907 // do not use standard filenames or your sensitive company data
908 // are world readable
910 $fname = $dir.'/'.$this->filename;
912 $fname = $dir.'/'.uniqid('').'.pdf';
913 $this->Output($fname, 'F');
917 if ($this->currency != $myrow['curr_code'])
919 include("doctext2.inc");
923 include("doctext.inc");
925 require_once($path_to_root . "/reporting/includes/class.mail.inc");
926 $mail = new email($this->company['coy_name'], $this->company['email']);
927 if (!isset($myrow['email']) || $myrow['email'] == '')
928 $myrow['email'] = isset($myrow['contact_email']) ? $myrow['contact_email'] : '';
929 $to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">";
930 $msg = $doc_Dear_Sirs . " " . $myrow['DebtorName'] . ",\n\n" . $doc_AttachedFile . " " . $subject .
932 if (isset($myrow['dimension_id']) && $myrow['dimension_id'] > 0 && $doctype == ST_SALESINVOICE) // helper for payment links
934 if ($myrow['dimension_id'] == 1)
936 $amt = number_format($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"], user_price_dec());
937 $txt = $doc_Payment_Link . " PayPal: ";
938 $nn = urlencode($this->title . " " . $myrow['reference']);
939 $url = "https://www.paypal.com/xclick/business=" . $this->company['email'] . "&item_name=" .
940 $nn . "&amount=" . $amt . "¤cy_code=" . $myrow['curr_code'];
941 $msg .= $txt . $url . "\n\n";
944 $msg .= $doc_Kindest_regards . "\n\n";
945 $sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone'];
947 $mail->subject($subject);
948 $mail->text($msg . $sender);
949 $mail->attachment($fname);
950 $ret = $mail->send();
952 display_error(_("Sending document by email failed"));
954 display_notification($this->title . " " . $myrow['reference'] . " "
955 . _("has been sent by email."));
960 $printer = get_report_printer(user_print_profile(), $_POST['REP_ID']);
961 if ($printer == false) {
965 if (user_rep_popup())
966 $Ajax->popup($fname); // when embeded pdf viewer used
968 $Ajax->redirect($fname); // otherwise use faster method
972 // <SCRIPT LANGUAGE="JavaScript"><!--
973 // function go_now () { window.location.href = "'.$fname.'"; }
976 // <body onLoad="go_now()"; >
977 // <a href="'.$fname.'">click here</a> if you are not re-directed.
980 header('Content-type: application/pdf');
981 header("Content-Disposition: inline; filename=$this->filename");
982 header('Expires: 0');
983 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
984 header('Pragma: public');
988 } else { // send report to network printer
989 $prn = new remote_printer($printer['queue'],$printer['host'],
990 $printer['port'], $printer['timeout']);
991 $error = $prn->print_file($fname);
993 display_error($error);
995 display_notification(_('Report has been sent to network printer ').$printer['name']);
998 // first have a look through the directory,
999 // and remove old temporary pdfs
1000 if ($d = @opendir($dir)) {
1001 while (($file = readdir($d)) !== false) {
1002 if (!is_file($dir.'/'.$file) || $file == 'index.php') continue;
1003 // then check to see if this one is too old
1004 $ftime = filemtime($dir.'/'.$file);
1005 // seems 3 min is enough for any report download, isn't it?
1006 if (time()-$ftime > 180){
1007 unlink($dir.'/'.$file);