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 ***********************************************************************/
14 . add StartReport/EndReport handlers for better bulk report support, with
15 . email/printer destination option should be selected on class creation instead
17 . add/use setter function for Header2 parameters (currently passed globally)
18 . in report files pass already prepared options to SetCommonData() to avoid need for
19 selection inside FrontReport generic class.
21 include_once(dirname(__FILE__)."/class.pdf.inc");
22 include_once(dirname(__FILE__)."/printer_class.inc");
23 include_once($path_to_root . "/admin/db/company_db.inc");
24 include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
25 include_once($path_to_root . "/admin/db/printers_db.inc");
26 include_once($path_to_root . "/config.php");
28 class FrontReport extends Cpdf
59 var $companyLogoEnable; // select whether to use a company logo graphic in some header templates
61 var $footerEnable; // select whether to print a page footer or not
62 var $footerText; // store user-generated footer text
63 var $headerTmpl; // store the name of the currently selected header template
64 var $tmplSize; // pdf header template size in pages
67 var $formData; // common data used for printing headers footers etc.
69 var $dest; // destination: email or printer
71 function FrontReport($title, $filename, $size = 'A4', $fontsize = 9, $orientation = 'P', $margins = NULL, $excelColWidthFactor = NULL)
73 global $page_security;
75 $this->rep_id = $_POST['REP_ID']; // FIXME
77 if (!$_SESSION["wa_current_user"]->can_access_page($page_security))
79 display_error(_("The security settings on your account do not permit you to print this report"));
83 // Page margins - if user-specified, use those. Otherwise, use defaults below.
86 $this->topMargin = $margins['top'];
87 $this->bottomMargin = $margins['bottom'];
88 $this->leftMargin = $margins['left'];
89 $this->rightMargin = $margins['right'];
91 // Page orientation - P: portrait, L: landscape
92 $orientation = strtoupper($orientation);
94 switch (strtoupper($size))
99 if ($orientation == 'P')
101 $this->pageWidth=595;
102 $this->pageHeight=842;
103 if (!isset($margins))
106 $this->bottomMargin=30;
107 $this->leftMargin=40;
108 $this->rightMargin=30;
114 $this->pageWidth=842;
115 $this->pageHeight=595;
116 if (!isset($margins))
119 $this->bottomMargin=30;
120 $this->leftMargin=40;
121 $this->rightMargin=30;
127 if ($orientation == 'P')
129 $this->pageWidth=842;
130 $this->pageHeight=1190;
131 if (!isset($margins))
134 $this->bottomMargin=50;
135 $this->leftMargin=50;
136 $this->rightMargin=40;
142 $this->pageWidth=1190;
143 $this->pageHeight=842;
144 if (!isset($margins))
147 $this->bottomMargin=50;
148 $this->leftMargin=50;
149 $this->rightMargin=40;
155 if ($orientation == 'P')
157 $this->pageWidth=612;
158 $this->pageHeight=792;
159 if (!isset($margins))
162 $this->bottomMargin=30;
163 $this->leftMargin=30;
164 $this->rightMargin=25;
170 $this->pageWidth=792;
171 $this->pageHeight=612;
172 if (!isset($margins))
175 $this->bottomMargin=30;
176 $this->leftMargin=30;
177 $this->rightMargin=25;
183 if ($orientation == 'P')
185 $this->pageWidth=612;
186 $this->pageHeight=1008;
187 if (!isset($margins))
190 $this->bottomMargin=40;
191 $this->leftMargin=30;
192 $this->rightMargin=25;
198 $this->pageWidth=1008;
199 $this->pageHeight=612;
200 if (!isset($margins))
203 $this->bottomMargin=40;
204 $this->leftMargin=30;
205 $this->rightMargin=25;
210 $this->size = array(0, 0, $this->pageWidth, $this->pageHeight);
211 $this->title = $title;
212 $this->filename = $filename.".pdf";
213 $this->pageNumber = 0;
214 $this->endLine = $this->pageWidth - $this->rightMargin;
215 $this->lineHeight = 12;
216 $this->fontSize = $fontsize;
217 $this->oldFontSize = 0;
218 $this->row = $this->pageHeight - $this->topMargin;
219 $this->currency = '';
220 $this->scaleLogoWidth = false; // if Logo, scale on width (else height).
221 $this->SetHeaderType('Header'); // default
223 $this->Cpdf($size, $_SESSION['language']->code, $orientation);
227 * Select the font and style to use for following output until
228 * it's changed again.
231 * * a special case string (for backwards compatible with older code):
234 * * or a case-insensitive string where each char represents a style choice
235 * and you can use more than one or none at all. Possible choices:
236 * * empty string: regular
240 * * D: line trough (aka "strike through")
241 * $fontname should be a standard PDF font (like 'times', 'helvetica' or 'courier')
242 * or one that's been installed on your system (see TCPDF docs for details).
243 * An empty string can also be used which will retain the font currently in use if
244 * you just want to change the style.
246 function Font($style = '', $fontname = '')
248 $this->selectFont($fontname, $style);
251 function Info($params, $cols, $headers, $aligns,
252 $cols2 = null, $headers2 = null, $aligns2 = null,
253 $companylogoenable = false, $footerenable = false, $footertext = '')
255 global $app_title, $version, $power_by, $power_url;
257 $this->addinfo('Title', $this->title);
258 $this->addinfo('Subject', $this->title);
259 $this->addinfo('Author', $app_title . ' ' . $version);
260 $this->addinfo('Creator',$power_by . ' - ' . $power_url);
261 $year = get_current_fiscalyear();
262 if ($year['closed'] == 0)
266 $this->fiscal_year = sql2date($year['begin']) . " - " . sql2date($year['end']) . " " . "(" . $how . ")";
267 $this->company = get_company_prefs();
268 $this->user = $_SESSION["wa_current_user"]->name;
269 $this->host = $_SERVER['SERVER_NAME'];
270 $this->params = $params;
272 for ($i = 0; $i < count($this->cols); $i++)
273 $this->cols[$i] += $this->leftMargin;
274 $this->headers = $headers;
275 $this->aligns = $aligns;
276 $this->cols2 = $cols2;
277 if ($this->cols2 != null)
279 for ($i = 0; $i < count($this->cols2); $i++)
280 $this->cols2[$i] += $this->leftMargin;
282 $this->headers2 = $headers2;
283 $this->aligns2 = $aligns2;
285 // Set whether to display company logo in some header templates
286 $this->companyLogoEnable = $companylogoenable;
288 // Store footer settings
289 $this->footerEnable = $footerenable;
290 $this->footerText = $footertext;
293 // Header for listings
297 $companyCol = $this->endLine - 150;
298 $titleCol = $this->leftMargin + 100;
300 $this->row = $this->pageHeight - $this->topMargin;
302 $this->SetDrawColor(128, 128, 128);
303 $this->Line($this->row + 5, 1);
307 $this->fontSize += 4;
309 $this->Text($this->leftMargin, $this->title, $companyCol);
311 $this->fontSize -= 4;
312 $this->Text($companyCol, $this->company['coy_name']);
313 $this->row -= ($this->lineHeight + 4);
315 $str = _("Print Out Date") . ':';
316 $this->Text($this->leftMargin, $str, $titleCol);
317 $str = Today() . ' ' . Now();
318 if ($this->company['time_zone'])
319 $str .= ' ' . date('O') . ' GMT';
320 $this->Text($titleCol, $str, $companyCol);
321 $this->Text($companyCol, $this->host);
324 $str = _("Fiscal Year") . ':';
325 $this->Text($this->leftMargin, $str, $titleCol);
326 $str = $this->fiscal_year;
327 $this->Text($titleCol, $str, $companyCol);
328 $this->Text($companyCol, $this->user);
329 for ($i = 1; $i < count($this->params); $i++)
331 if ($this->params[$i]['from'] != '')
334 $str = $this->params[$i]['text'] . ':';
335 $this->Text($this->leftMargin, $str, $titleCol);
336 $str = $this->params[$i]['from'];
337 if ($this->params[$i]['to'] != '')
338 $str .= " - " . $this->params[$i]['to'];
339 $this->Text($titleCol, $str, $companyCol);
342 if ($this->params[0] != '') // Comments
345 $str = _("Comments") . ':';
346 $this->Text($this->leftMargin, $str, $titleCol);
348 $this->Text($titleCol, $this->params[0], $this->endLine - 35);
351 $str = _("Page") . ' ' . $this->pageNumber;
352 $this->Text($this->endLine - 38, $str);
353 $this->Line($this->row - 5, 1);
355 $this->row -= ($this->lineHeight + 6);
356 $this->Font('italic');
357 if ($this->headers2 != null)
359 $count = count($this->headers2);
360 for ($i = 0; $i < $count; $i++)
361 $this->TextCol2($i, $i + 1, $this->headers2[$i]);
364 $count = count($this->headers);
365 for ($i = 0; $i < $count; $i++)
366 $this->TextCol($i, $i + 1, $this->headers[$i]);
368 $this->Line($this->row - 5, 1);
375 function SetCommonData($myrow, $branch, $sales_order, $bankaccount, $doctype)
377 // $this->formData = array_merge($myrow, $branch, $sales_order,
378 // $bank_account, array('doctype' => $doctype));
380 $this->formData = array();
382 'myrow' => array('ord_date', 'date_', 'tran_date',
383 'order_no','reference', 'id', 'trans_no', 'name', 'location_name',
384 'delivery_address', 'supp_name', 'address',
385 'DebtorName', 'supp_account_no', 'wo_ref', 'debtor_ref','type', 'trans_no',
386 'StockItemName', 'tax_id', 'order_', 'delivery_date', 'units_issued',
387 'due_date', 'required_by', 'payment_terms', 'curr_code',
388 'ov_freight', 'ov_gst', 'ov_amount', 'rep_lang'),
389 'branch' => array('br_address', 'br_name', 'salesman', 'disable_branch', 'rep_lang'),
390 'sales_order' => array('deliver_to', 'delivery_address', 'customer_ref'),
391 'bankaccount' => array('bank_name', 'bank_account_number')
394 foreach($datnames as $var => $fields) {
396 foreach($fields as $locname) {
397 if (isset(${$var}[$locname]) && (${$var}[$locname]!==null)) {
398 $this->formData[$locname] = ${$var}[$locname];
403 $this->formData['doctype'] = $doctype;
404 error_log('cust:'.var_export($myrow, true));
405 error_log('branch:'.var_export($branch, true));
410 function SetHeaderType($name) {
411 $this->headerTmpl = $name;
414 Header for sales/purchase documents
418 global $path_to_root, $print_as_quote,
419 $print_invoice_no, $packing_slip, $dflt_lang; // FIXME should be passed as params
421 $doctype = $this->formData['doctype'];
424 $this->SetLang(@$this->formData['rep_lang'] ? $this->formData['rep_lang'] : $dflt_lang);
426 // leave layout files names without path to enable including
427 // modified versions from company/x/reporting directory
428 include("includes/doctext.inc");
429 include("includes/header2.inc");
434 // Alternate header style which also supports a simple footer
437 // Turn off cell padding for the main report header, restoring the current setting later
438 $oldcMargin = $this->cMargin;
439 $this->SetCellPadding(0);
441 // Set some constants which control header item layout
442 // only set them once or the PHP interpreter gets angry
443 if ($this->pageNumber == 1)
445 define('COMPANY_WIDTH', 150);
446 define('LOGO_HEIGHT', 50);
447 define('LOGO_Y_POS_ADJ_FACTOR', 0.74);
448 define('LABEL_WIDTH', 80);
449 define('PAGE_NUM_WIDTH', 60);
450 define('TITLE_FONT_SIZE', 14);
451 define('HEADER1_FONT_SIZE', 10);
452 define('HEADER2_FONT_SIZE', 9);
453 define('FOOTER_FONT_SIZE', 10);
454 define('FOOTER_MARGIN', 4);
456 // Set some variables which control header item layout
457 $companyCol = $this->endLine - COMPANY_WIDTH;
458 $headerFieldCol = $this->leftMargin + LABEL_WIDTH;
459 $pageNumCol = $this->endLine - PAGE_NUM_WIDTH;
460 $footerCol = $this->leftMargin + PAGE_NUM_WIDTH;
461 $footerRow = $this->bottomMargin - FOOTER_MARGIN;
463 // Calling this function generates a new PDF page after the first instance
465 // // TODO: experimenting with line drawing to highlight current period
466 // $this->SetLineWidth(1);
467 // $this->LineTo($this->cols[3], 33, $this->cols[3], 534);
468 // $this->LineTo($this->cols[4], 33, $this->cols[4], 534);
469 // $this->SetLineWidth(0.1);
473 $this->row = $this->pageHeight - $this->topMargin;
475 // Set the color of dividing lines we'll draw
476 $oldDrawColor = $this->GetDrawColor();
477 $this->SetDrawColor(128, 128, 128);
479 // Tell TCPDF that we want to use its alias system to track the total number of pages
480 $this->AliasNbPages();
483 if ($this->footerEnable)
485 $this->Line($footerRow, 1);
486 $prevFontSize = $this->fontSize;
487 $this->fontSize = FOOTER_FONT_SIZE;
488 $this->TextWrap($footerCol, $footerRow - ($this->fontSize + 1),
489 $pageNumCol - $footerCol, $this->footerText, $align = 'center',
490 $border = 0, $fill = 0, $link = NULL, $stretch = 1);
491 $this->TextWrap($pageNumCol, $footerRow - ($this->fontSize + 1),
492 PAGE_NUM_WIDTH, _("Page") . ' ' . $this->pageNumber . '/' . $this->getAliasNbPages(),
493 $align = 'right', $border = 0, $fill = 0, $link = NULL, $stretch = 1);
494 $this->fontSize = $prevFontSize;
501 // Print gray line across the page
502 $this->Line($this->row + 8, 1);
506 // Print the report title nice and big
507 $oldFontSize = $this->fontSize;
508 $this->fontSize = TITLE_FONT_SIZE;
510 $this->Text($this->leftMargin, $this->title, $companyCol);
511 $this->fontSize = HEADER1_FONT_SIZE;
513 // Print company logo if present and requested, or else just print company name
514 if ($this->companyLogoEnable && ($this->company['coy_logo'] != ''))
516 // Build a string specifying the location of the company logo file
517 $logo = company_path() . "/images/" . $this->company['coy_logo'];
519 // Width being zero means that the image will be scaled to the specified height
520 // keeping its aspect ratio intact.
521 if ($this->scaleLogoWidth)
522 $this->AddImage($logo, $companyCol, $this->row, COMPANY_WIDTH, 0);
524 $this->AddImage($logo, $companyCol, $this->row - (LOGO_HEIGHT * LOGO_Y_POS_ADJ_FACTOR), 0, LOGO_HEIGHT);
527 $this->Text($companyCol, $this->company['coy_name']);
529 // Dimension 1 - optional
530 // - only print if available and not blank
531 if (count($this->params) > 3)
532 if ($this->params[3]['from'] != '')
534 $this->NewLine(1, 0, $this->fontSize + 2);
535 $str = $this->params[3]['text'] . ':';
536 $this->Text($this->leftMargin, $str, $headerFieldCol);
537 $str = $this->params[3]['from'];
538 $this->Text($headerFieldCol, $str, $companyCol);
541 // Dimension 2 - optional
542 // - only print if available and not blank
543 if (count($this->params) > 4)
544 if ($this->params[4]['from'] != '')
546 $this->NewLine(1, 0, $this->fontSize + 2);
547 $str = $this->params[4]['text'] . ':';
548 $this->Text($this->leftMargin, $str, $headerFieldCol);
549 $str = $this->params[4]['from'];
550 $this->Text($headerFieldCol, $str, $companyCol);
554 // if present, it's an array of tag names
555 if (count($this->params) > 5)
556 if ($this->params[5]['from'] != '')
558 $this->NewLine(1, 0, $this->fontSize + 2);
559 $str = $this->params[5]['text'] . ':';
560 $this->Text($this->leftMargin, $str, $headerFieldCol);
562 for ($i = 0; $i < count($this->params[5]['from']); $i++)
566 $str .= $this->params[5]['from'][$i];
568 $this->Text($headerFieldCol, $str, $companyCol);
571 // Report Date - time period covered
572 // - can specify a range, or just the end date (and the report contents
573 // should make it obvious what the beginning date is)
574 $this->NewLine(1, 0, $this->fontSize + 2);
575 $str = _("Report Period") . ':';
576 $this->Text($this->leftMargin, $str, $headerFieldCol);
578 if (isset($this->params[1]['from']) && $this->params[1]['from'] != '')
579 $str = $this->params[1]['from'] . ' - ';
580 $str .= $this->params[1]['to'];
581 $this->Text($headerFieldCol, $str, $companyCol);
586 $this->NewLine(1, 0, $this->fontSize + 1);
588 // Make the remaining report headings a little less important
589 $this->fontSize = HEADER2_FONT_SIZE;
591 // Timestamp of when this copy of the report was generated
592 $str = _("Generated At") . ':';
593 $this->Text($this->leftMargin, $str, $headerFieldCol);
594 $str = Today() . ' ' . Now();
595 if ($this->company['time_zone'])
596 $str .= ' ' . date('O') . ' GMT';
597 $this->Text($headerFieldCol, $str, $companyCol);
599 // Name of the user that generated this copy of the report
600 $this->NewLine(1, 0, $this->fontSize + 1);
601 $str = _("Generated By") . ':';
602 $this->Text($this->leftMargin, $str, $headerFieldCol);
604 $this->Text($headerFieldCol, $str, $companyCol);
606 // Display any user-generated comments for this copy of the report
607 if ($this->params[0] != '') // Comments
609 $this->NewLine(1, 0, $this->fontSize + 1);
610 $str = _("Comments") . ':';
611 $this->Text($this->leftMargin, $str, $headerFieldCol);
613 $this->Text($headerFieldCol, $this->params[0], $companyCol, 0, 0, 'left', 0, 0, $link=NULL, 1);
617 // Add page numbering to header if footer is turned off
618 if (!$this->footerEnable)
620 $str = _("Page") . ' ' . $this->pageNumber . '/' . $this->getAliasNbPages();
621 $this->Text($pageNumCol, $str, 0, 0, 0, 'right', 0, 0, NULL, 1);
624 // Print gray line across the page
625 $this->Line($this->row - 5, 1);
627 // Restore font size to user-defined size
628 $this->fontSize = $oldFontSize;
630 // restore user-specified cell padding for column headers
631 $this->SetCellPadding($oldcMargin);
633 // scoot down the page a bit
634 $oldLineHeight = $this->lineHeight;
635 $this->lineHeight = $this->fontSize + 1;
636 $this->row -= ($this->lineHeight + 6);
637 $this->lineHeight = $oldLineHeight;
639 // Print the column headers!
641 if ($this->headers2 != null)
643 $count = count($this->headers2);
644 for ($i = 0; $i < $count; $i++)
645 $this->TextCol2($i, $i + 1, $this->headers2[$i], $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1);
648 $count = count($this->headers);
649 for ($i = 0; $i < $count; $i++)
650 $this->TextCol($i, $i + 1, $this->headers[$i], $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1);
655 // restore user-specified draw color
656 $this->SetDrawColor($oldDrawColor[0], $oldDrawColor[1], $oldDrawColor[2]);
660 * Format a numeric string date into something nicer looking.
662 * @param string $date Date string to be formatted.
663 * @param int $input_format Format of the input string. Possible values are:<ul><li>0: user's default (default)</li></ul>
664 * @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>
667 function DatePrettyPrint($date, $input_format = 0, $output_format = 0)
671 $date = date2sql($date);
672 $year = (int) (substr($date, 0, 4));
673 $month = (int) (substr($date, 5, 2));
674 $day = (int) (substr($date, 8, 2));
675 if ($output_format == 0)
676 return(date('F j, Y', mktime(12, 0, 0, $month, $day, $year)));
677 elseif ($output_format == 1)
678 return(date('F Y', mktime(12, 0, 0, $month, $day, $year)));
679 elseif ($output_format == 2)
680 return(date('M Y', mktime(12, 0, 0, $month, $day, $year)));
686 function AddImage($logo, $x, $y, $w, $h)
688 if (strpos($logo, ".png") || strpos($logo, ".PNG"))
689 $this->addPngFromFile($logo, $x, $y, $w, $h);
691 $this->addJpegFromFile($logo, $x, $y, $w, $h);
694 // Get current draw color setting from TCPDF object; returns array of RGB numbers
695 function GetDrawColor()
697 // Convert the TCPDF stored DrawColor string into an array of strings
698 $colorFields = explode(' ', $this->DrawColor);
700 // Test last value: G == grayscale, single number; RG == RGB, 3 numbers
701 if ($colorFields[count($colorFields) - 1] == 'G')
702 // Convert a grayscale string value to the equivalent RGB value
703 $drawColor = array((float) $colorFields[0], (float) $colorFields[0], (float) $colorFields[0]);
705 // Convert RGB string values to the a numeric array
706 $drawColor = array((float) $colorFields[0], (float) $colorFields[1], (float) $colorFields[2]);
711 function SetDrawColor($r, $g, $b)
713 parent::SetDrawColor($r, $g, $b);
716 function SetTextColor($r, $g, $b)
718 parent::SetTextColor($r, $g, $b);
722 * Set the fill color for table cells.
723 * @see reporting/includes/TCPDF#SetFillColor($col1, $col2, $col3, $col4)
725 function SetFillColor($r, $g, $b)
727 parent::SetFillColor($r, $g, $b);
730 // Get current cell padding setting from TCPDF object
731 function GetCellPadding()
733 return $this->cMargin;
736 // Set desired cell padding (aka "cell margin")
737 // Seems to be just left and right margins...
738 function SetCellPadding($pad)
740 parent::SetCellPadding($pad);
743 function Text($c, $txt, $n=0, $corr=0, $r=0, $align='left', $border=0, $fill=0, $link=NULL, $stretch=1)
746 $n = $this->pageWidth - $this->rightMargin;
748 return $this->TextWrap($c, $this->row - $r, $n - $c + $corr, $txt, $align, $border, $fill, $link, $stretch);
751 function TextWrap($xpos, $ypos, $len, $str, $align = 'left', $border = 0, $fill = 0, $link = NULL, $stretch = 1)
753 if ($this->fontSize != $this->oldFontSize)
755 $this->SetFontSize($this->fontSize);
756 $this->oldFontSize = $this->fontSize;
758 return $this->addTextWrap($xpos, $ypos, $len, $this->fontSize, $str, $align, $border, $fill, $link, $stretch);
761 function TextCol($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
763 return $this->TextWrap($this->cols[$c], $this->row - $r, $this->cols[$n] - $this->cols[$c] + $corr, $txt, $this->aligns[$c], $border, $fill, $link, $stretch);
766 function AmountCol($c, $n, $txt, $dec=0, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1, $color_red=false)
768 if ($color_red && $txt < 0)
769 $this->SetTextColor(255, 0, 0);
770 $ret = $this->TextCol($c, $n, number_format2($txt, $dec), $corr, $r, $border, $fill, $link, $stretch);
771 if ($color_red && $txt < 0)
772 $this->SetTextColor(0, 0, 0);
776 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')
778 setlocale(LC_MONETARY, $amount_locale);
779 if ($color_red && $txt < 0)
780 $this->SetTextColor(255, 0, 0);
781 $ret = $this->TextCol($c, $n, money_format($amount_format, $txt), $corr, $r, $border, $fill, $link, $stretch);
782 if ($color_red && $txt < 0)
783 $this->SetTextColor(0, 0, 0);
787 function DateCol($c, $n, $txt, $conv=false, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
790 $txt = sql2date($txt);
791 return $this->TextCol($c, $n, $txt, $corr, $r, $border, $fill, $link, $stretch);
794 function TextCol2($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
796 return $this->TextWrap($this->cols2[$c], $this->row - $r, $this->cols2[$n] - $this->cols2[$c] + $corr, $txt, $this->aligns2[$c], $border, $fill, $link, $stretch);
799 function TextColLines($c, $n, $txt, $corr=0, $r=0, $border=0, $fill=0, $link=NULL, $stretch=1)
802 $this->TextWrapLines($this->cols[$c], $this->cols[$n] - $this->cols[$c] + $corr, $txt, $this->aligns[$c], $border, $fill, $link, $stretch);
805 function TextWrapLines($c, $width, $txt, $align='left', $border=0, $fill=0, $link=NULL, $stretch=1)
807 $str = Explode("\n", $txt);
808 for ($i = 0; $i < count($str); $i++)
813 $l = $this->TextWrap($c, $this->row , $width, $l, $align, $border, $fill, $link, $stretch);
814 $this->row -= $this->lineHeight;
821 * Expose the underlying calcTextWrap() function in this API.
823 function TextWrapCalc($txt, $width, $spacebreak=false)
825 return $this->calcTextWrap($txt, $width, $spacebreak);
829 * Sets the line drawing style.
831 * Takes an associative array as arg so you don't need to specify all values.
834 * width (float) - the thickness of the line in user units
835 * cap (string) - the type of cap to put on the line, values can be 'butt','round','square'
836 * where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
838 * join (string) - can be 'miter', 'round', 'bevel'
839 * dash (mixed) - Dash pattern. Is 0 (without dash) or string with series of length values, which are the
840 * lengths of the on and off dashes. For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...;
841 * "2,1" is 2 on, 1 off, 2 on, 1 off, ...
842 * phase (integer) - a modifier on the dash pattern which is used to shift the point at which the pattern starts.
843 * color (array) - draw color. Format: array(GREY), or array(R,G,B) or array(C,M,Y,K).
845 function SetLineStyle($style)
847 parent::SetLineStyle($style);
851 * Sets the line drawing width.
853 function SetLineWidth($width)
855 parent::SetLineWidth($width);
858 function LineTo($from, $row, $to, $row2)
860 parent::line($from, $row, $to, $row2);
863 function Line($row, $height = 0)
865 $oldLineWidth = $this->GetLineWidth();
866 $this->SetLineWidth($height + 1);
867 parent::line($this->pageWidth - $this->rightMargin, $row ,$this->leftMargin, $row);
868 $this->SetLineWidth($oldLineWidth);
872 * Underlines the contents of a cell, but not the cell padding area.
873 * Primarily useful for the last line before a "totals" line.
874 * @param int $c Column number to underline.
875 * @param int $r Print the underline(s) this number of rows below the current position. Can be negative in order to go up.
876 * @param int $type Type of underlining to draw. Possible values are:<ul><li>1: single underline (default)</li><li>2: double underline</li></ul>
877 * @param int $linewidth Thickness of the line to draw. Default value of zero will use the current line width defined for this document.
878 * @param array $style Line style. Array like for {@link SetLineStyle SetLineStyle}. Default value: default line style (empty array).
880 * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
882 function UnderlineCell($c, $r = 0, $type = 1, $linewidth = 0, $style = array())
884 // If line width was specified, save current setting so we can reset it
887 $oldLineWidth = $this->GetLineWidth();
888 $this->SetLineWidth($linewidth);
891 // Figure out how far down to move the line based on current font size
892 // Calculate this because printing underline directly at $this->row goes on top
893 // of the parts of characters that "hang down", like the bottom of commas &
894 // lowercase letter 'g', etc.
895 if ($this->fontSize < 10)
899 parent::line($this->cols[$c] + $this->cMargin, $this->row - $r - $y_adj, $this->cols[$c + 1] - $this->cMargin, $this->row - $r - $y_adj, $style);
901 // Double underline, far enough below the first underline so as not to overlap
902 // the first underline (depends on current line thickness (aka "line width")
904 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);
906 // If line width was specified, reset it back to the original setting
908 $this->SetLineWidth($oldLineWidth);
911 function NewLine($l=1, $np=0, $h = NULL)
913 // If the line height wasn't specified, use the current setting
915 $h = $this->lineHeight;
917 // Move one line down the page
918 $this->row -= ($l * $h);
920 // Check to see if we're at the bottom and should insert a page break
921 if ($this->row < $this->bottomMargin + ($np * $h))
927 if ($this->pageNumber==0)
929 // check if there is pdf header template for this report
930 // and set if it is found
931 $tmpl_pdf = find_custom_file("/reporting/forms/".$this->headerTmpl.".pdf");
933 $this->tmplSize = $this->setSourceFile($tmpl_pdf);
940 if ($this->tmplSize) {
941 $this->row = $this->pageHeight - $this->topMargin; // reset row
942 $id = $this->importPage(min($this->pageNumber, $this->tmplSize));
943 $this->useTemplate($id);
946 // include related php file if any
947 $tmpl_php = find_custom_file("/reporting/forms/".$this->headerTmpl.".php");
952 if (method_exists($this, $this->headerTmpl)) // draw predefined page layout if any
953 $this->{$this->headerTmpl}();
956 function End($email=0, $subject=null, $myrow=null, $doctype = 0)
958 global $pdf_debug, $path_to_root;
962 $pdfcode = $this->Output('','S');
963 $pdfcode = str_replace("\n", "\n<br>", htmlspecialchars($pdfcode));
966 echo '</body></html>';
971 $dir = company_path(). '/pdf_files';
973 if (!file_exists($dir))
977 // do not use standard filenames or your sensitive company data
978 // are world readable
980 $fname = $dir.'/'.$this->filename;
982 $fname = $dir.'/'.uniqid('').'.pdf';
983 $this->Output($fname, 'F');
988 $this->SetLang($this->formData['rep_lang']);
989 include("includes/doctext.inc");
991 require_once($path_to_root . "/reporting/includes/class.mail.inc");
992 $mail = new email(str_replace(",", "", $this->company['coy_name']), $this->company['email']);
993 if (!isset($myrow['email']) || $myrow['email'] == '')
994 $myrow['email'] = isset($myrow['contact_email']) ? $myrow['contact_email'] : '';
995 $to = str_replace(",", "", $myrow['DebtorName']) . " <" . $myrow['email'] . ">";
996 $msg = $doc_Dear_Sirs . " " . $myrow['DebtorName'] . ",\n\n" . $doc_AttachedFile . " " . $subject .
998 if (isset($myrow['dimension_id']) && $myrow['dimension_id'] > 0 && $doctype == ST_SALESINVOICE) // helper for payment links
1000 if ($myrow['dimension_id'] == 1)
1002 $amt = number_format($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"], user_price_dec());
1003 $txt = $doc_Payment_Link . " PayPal: ";
1004 $nn = urlencode($this->title . " " . $myrow['reference']);
1005 $url = "https://www.paypal.com/xclick/business=" . $this->company['email'] . "&item_name=" .
1006 $nn . "&amount=" . $amt . "¤cy_code=" . $myrow['curr_code'];
1007 $msg .= $txt . $url . "\n\n";
1010 $msg .= $doc_Kindest_regards . "\n\n";
1011 $sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone'];
1013 $mail->subject($subject);
1014 $mail->text($msg . $sender);
1015 $mail->attachment($fname);
1016 $ret = $mail->send();
1018 display_error(_("Sending document by email failed"));
1020 display_notification($this->title . " " . $myrow['reference'] . " "
1021 . _("has been sent by email."));
1026 $printer = get_report_printer(user_print_profile(), $this->rep_id);
1027 if ($printer == false) {
1031 if (user_rep_popup())
1032 $Ajax->popup($fname); // when embeded pdf viewer used
1034 $Ajax->redirect($fname); // otherwise use faster method
1036 header('Content-type: application/pdf');
1037 header('Content-Disposition: inline; filename='.$this->filename);
1038 header('Expires: 0');
1039 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1040 header('Pragma: public');
1041 // $this->Stream(basename($fname));
1042 $this->Stream($this->filename);
1044 } else { // send report to network printer
1045 $prn = new remote_printer($printer['queue'],$printer['host'],
1046 $printer['port'], $printer['timeout']);
1047 $error = $prn->print_file($fname);
1049 display_error($error);
1051 display_notification(_('Report has been sent to network printer ').$printer['name']);
1054 // first have a look through the directory,
1055 // and remove old temporary pdfs
1056 if ($d = @opendir($dir)) {
1057 while (($file = readdir($d)) !== false) {
1058 if (!is_file($dir.'/'.$file) || $file == 'index.php') continue;
1059 // then check to see if this one is too old
1060 $ftime = filemtime($dir.'/'.$file);
1061 // seems 3 min is enough for any report download, isn't it?
1062 if (time()-$ftime > 180){
1063 unlink($dir.'/'.$file);