diff --git a/extensions/ki_adminpanel/init.php b/extensions/ki_adminpanel/init.php
index fb991a756..d57df80ec 100755
--- a/extensions/ki_adminpanel/init.php
+++ b/extensions/ki_adminpanel/init.php
@@ -121,6 +121,13 @@
$view->assign('roundSeconds', $kga['conf']['roundSeconds']);
}
+ if (!function_exists('exec')) {
+ // deactivate latex functionality
+ $view->assign('execAvailable', false);
+ } else {
+ $view->assign('execAvailable', true);
+ }
+
$view->assign('tab_advanced', $view->render("advanced.php"));
$view->assign('tab_database', $view->render("database.php"));
}
diff --git a/extensions/ki_adminpanel/processor.php b/extensions/ki_adminpanel/processor.php
index f184e0dd2..aa0b129ee 100755
--- a/extensions/ki_adminpanel/processor.php
+++ b/extensions/ki_adminpanel/processor.php
@@ -463,6 +463,7 @@
$config_data['decimalSeparator'] = $_REQUEST['decimalSeparator'];
$config_data['durationWithSeconds'] = getRequestBool('durationWithSeconds');
$config_data['exactSums'] = getRequestBool('exactSums');
+ $config_data['LaTeXExec'] = $_REQUEST['LaTeX_exec'];
$editLimit = false;
if (getRequestBool('editLimitEnabled')) {
$hours = (int)$_REQUEST['editLimitHours'];
diff --git a/extensions/ki_adminpanel/templates/scripts/advanced.php b/extensions/ki_adminpanel/templates/scripts/advanced.php
index ce14998e1..0a753eb58 100755
--- a/extensions/ki_adminpanel/templates/scripts/advanced.php
+++ b/extensions/ki_adminpanel/templates/scripts/advanced.php
@@ -96,6 +96,13 @@
roundTimesheetEntries): ?> disabled="disabled" > kga['lang']['minutes']?> kga['lang']['and']?>
roundTimesheetEntries): ?> disabled="disabled" > kga['lang']['seconds']?>
+
+ execAvailable): ?>
+ kga['lang']['LaTeXExecutable']?>
+
+ kga['lang']['cannotExecute']?>
+
+
diff --git a/extensions/ki_invoice/init.php b/extensions/ki_invoice/init.php
index f33d14fe0..a6a52fe95 100644
--- a/extensions/ki_invoice/init.php
+++ b/extensions/ki_invoice/init.php
@@ -53,15 +53,29 @@
// Extract all Invoice Templates in groups
$invoice_template_files = array();
$allInvoices = glob('invoices/*');
-foreach($allInvoices as $tplFile)
-{
- $extension = 'HTML';
+foreach ($allInvoices as $tplFile) {
+ $extension = '';
$tplInfo = pathinfo($tplFile);
if (!is_dir($tplFile)) {
$extension = strtoupper($tplInfo['extension']);
+ } else {
+ //Check if index.html or invoice.tex is there
+ if (file_exists($tplFile . '/index.html')) {
+ $extension = 'HTML';
+ } elseif (file_exists($tplFile . '/invoice.tex')) {
+ $extension = 'LaTeX';
+ //Test if we can execute pdflatex
+ if (!function_exists('exec') or !is_executable($kga['LaTeXExec'])) {
+ Kimai_Logger::logfile('Could not execute pdflatex. Check your installation!');
+ $extension = '';
+ }
+ }
}
$filename = str_replace('_', ' ', $tplInfo['filename']);
- $invoice_template_files[$extension][$tplInfo['basename']] = ucfirst($filename);
+ //Only add if the extension was detected.
+ if ($extension != '') {
+ $invoice_template_files[$extension][$tplInfo['basename']] = ucfirst($filename);
+ }
}
$view->assign('invoice_templates', $invoice_template_files);
diff --git a/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.cls b/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.cls
new file mode 100644
index 000000000..7b23ffe09
--- /dev/null
+++ b/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.cls
@@ -0,0 +1,182 @@
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesClass{invoice}[2016/12/07 v1.0 Invoice for kimai]
+
+%%
+% This file is part of
+% Kimai - Open Source Time Tracking // http://www.kimai.org
+% (c) Kimai-Development-Team since 2006
+%
+% Kimai is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; Version 3, 29 June 2007
+%
+% Kimai is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with Kimai; If not, see .
+%%
+
+%%
+% An example LaTeX class template for printing invoices.
+%
+% @author Gustav Johansson
+%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Load standard document type %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\LoadClass[10pt,a4paper]{article}
+\RequirePackage{fancyhdr}
+\RequirePackage{graphicx}
+\RequirePackage{longtable}
+\RequirePackage{lastpage}
+\RequirePackage{hhline}
+\RequirePackage{etoolbox}
+\RequirePackage{multirow}
+\RequirePackage{numprint}
+\RequirePackage[table]{xcolor}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Define template controls %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%These can be redefined in the template for different languages, etc.
+\def\textTitle{\textbf{\textsf{Invoice}}}
+\def\textPage{Page}
+\def\textDate{Date:}
+\def\textDueDate{Due Date:}
+\def\textTotal{Total:}
+\def\textID{Invoice ID:}
+\def\textPhone{Phone: }
+\def\textEmail{Email: }
+\def\textTotalExVAT{\textbf{Total (excl. VAT)}}
+\def\textVAT{\textbf{VAT \vatRate{}\%}}
+\def\textGTotal{\textbf{Total (incl. VAT)}}
+\def\rulerWidth{0.4pt}
+\def\headerOne{Product}
+\def\headerTwo{Price}
+\def\headerThree{Quantity}
+\def\headerFour{Total}
+\def\headerColor{gray!50}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Define commands %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%Define product command
+\newcommand*{\@products}{}
+\def\rowCol{gray!25}
+\newcounter{colCount}
+\setcounter{colCount}{0}
+\newcommand*{\productColor}[4]{%
+ \protected@edef\@products{\@products
+ \cellcolor{\rowCol}#1\unitOne & \cellcolor{\rowCol}#2\unitTwo &%
+ \cellcolor{\rowCol}%
+ \ifstrempty{#3}{}{\numprint{#3}\unitThree}%
+ & \cellcolor{\rowCol}\numprint{#4}\unitFour\\
+ }%
+}
+\newcommand*{\productNoColor}[4]{%
+ \protected@edef\@products{\@products
+ #1\unitOne & #2\unitTwo &%
+ \ifstrempty{#3}{}{\numprint{#3}\unitThree}%
+ & \numprint{#4}\unitFour\\
+ }%
+}
+\newcommand*{\product}[4]{%
+ \ifnumequal{\thecolCount}{1}{%
+ \productColor{#1}{#2}{#3}{#4}
+ \addtocounter{colCount}{-1}%
+ }{%
+ \productNoColor{#1}{#2}{#3}{#4}
+ \addtocounter{colCount}{1}%
+ }%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Define printing of commands %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%Print company info
+\newcommand{\makecompany}{%
+ \noindent
+ \companyName\\
+ \companyAddress\\
+ \textPhone\companyPhone\\
+ \textEmail\companyEmail\\
+ \par\noindent
+ \textID\space\invoiceID\\
+ \par\noindent
+}
+
+%Print products into a table
+\newcommand{\makeproducts}{%
+ \nprounddigits{2}
+ \begin{longtable}{@{}p{0.5\textwidth}rrr@{}}
+ \rowcolor{\headerColor}
+ \headerOne&\headerTwo&\headerThree&\headerFour\\
+ \@products%
+ \hhline{~~--}
+ &&\multicolumn{1}{l}{\textTotalExVAT}&\numprint{\total}\space\currency\\
+ &&\multicolumn{1}{l}{\textVAT}&\numprint{\vat}\space\currency\\
+ &&\multicolumn{1}{l}{\textGTotal}&\numprint{\gtotal}\space\currency
+ \end{longtable}
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Setup the headers and footers %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\pagestyle{fancy}
+\fancyhf{}%Clear all settings
+%Set the rulers
+\renewcommand{\headrulewidth}{\rulerWidth}
+\renewcommand{\footrulewidth}{\rulerWidth}
+%Setup header
+\fancyhead[L]{%
+ \hspace*{0.2cm}\includegraphics[width=4.0cm]{logo.png}%
+}
+\fancyhead[C]{%
+ \raisebox{1.7cm}{%
+ \large{\textTitle}%
+ }
+}
+\fancyhead[R]{%
+ \raisebox{0.5cm}{%
+ \textsf{%
+ \begin{tabular}{p{2.0cm}p{3.5cm}}%
+ \rowcolor{white}%
+ {\small\textDate} & {\small\today}\tabularnewline%
+ \rowcolor{white}%
+ {\small\textID} & {\small\invoiceID}\tabularnewline%
+ \rowcolor{white}%
+ \textbf{\small\textDueDate} & \textbf{\duedate}\tabularnewline%
+ \rowcolor{white}%
+ {\small\textTotal} & {\numprint{\gtotal}\space\currency}%
+ \end{tabular}%
+ }%
+ }%
+}
+%Setup footer
+\fancyfoot[L]{%
+ \textsf{%
+ \leftOne\\%
+ \leftTwo\\%
+ \leftThree%
+ }%
+}
+\fancyfoot[C]{%
+ \textsf{%
+ \centerOne\\%
+ \centerTwo\\%
+ \centerThree\\%
+ }%
+}
+\fancyfoot[R]{%
+ \textsf{%
+ \rightOne\\%
+ \rightTwo\\%
+ \rightThree\\%
+ \textPage\space\thepage(\pageref{LastPage})%
+ }%
+}
+\endinput
diff --git a/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.ini b/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.ini
new file mode 100644
index 000000000..6c11a9950
--- /dev/null
+++ b/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.ini
@@ -0,0 +1,60 @@
+;;
+; This file is part of
+; Kimai - Open Source Time Tracking // http://www.kimai.org
+; (c) Kimai-Development-Team since 2006
+;
+; Kimai is free software; you can redistribute it and/or modify
+; it under the terms of the GNU General Public License as published by
+; the Free Software Foundation; Version 3, 29 June 2007
+;
+; Kimai is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+; GNU General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with Kimai; If not, see .
+;;
+
+;;
+; An example LaTeX setting file for printing invoices.
+;
+; @author Gustav Johansson
+;;
+
+; This configuration file is used to define some settings
+; that defines how the template is rendered.
+
+; List all files that are needed for rendering except the
+; invoice.tex and the automatically generated data.tex and
+; info.tex. Typically classes and images.
+files[] = "invoice.cls"
+files[] = "logo.png"
+
+; The followin keys can be used in the table generation, i.e., for each row:
+; 'type'
+; 'desc'
+; 'start'
+; 'end'
+; 'hour'
+; 'fDuration'
+; 'duration'
+; 'timestamp'
+; 'amount'
+; 'description'
+; 'rate'
+; 'comment'
+; 'username'
+; 'useralias'
+; 'location'
+; 'trackingNr'
+; 'projectID'
+; 'projectName'
+; 'projectComment'
+; 'date'
+
+; List all fields that shall be used as columns in the generated table.
+table[] = "desc"
+table[] = "rate"
+table[] = "hour"
+table[] = "amount"
diff --git a/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.tex b/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.tex
new file mode 100644
index 000000000..259bcfdc0
--- /dev/null
+++ b/extensions/ki_invoice/invoices/my_company_LaTeX/invoice.tex
@@ -0,0 +1,84 @@
+\documentclass{invoice}
+
+%%
+% This file is part of
+% Kimai - Open Source Time Tracking // http://www.kimai.org
+% (c) Kimai-Development-Team since 2006
+%
+% Kimai is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; Version 3, 29 June 2007
+%
+% Kimai is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with Kimai; If not, see .
+%%
+
+%%
+% An example LaTeX template for printing invoices.
+%
+% @author Gustav Johansson
+%%
+
+%%%%%%%%%%%%%%%%%%%%%%
+% Setup other stuff %
+%%%%%%%%%%%%%%%%%%%%%%
+%Language
+\usepackage[utf8]{inputenc} %Needed since the data from PHP is in utf8. Don't use any other encoding!
+
+%%%%%%%%%%%%%%%%%%%%%%
+% Setup page %
+%%%%%%%%%%%%%%%%%%%%%%
+\setlength{\topmargin}{-2cm}
+\setlength{\textwidth}{16cm}
+\setlength{\textheight}{22cm}
+\setlength{\oddsidemargin}{5.5mm}
+\setlength{\intextsep}{24pt}
+\setlength{\headheight}{3cm}
+\setlength{\headwidth}{16cm}
+
+%%%%%%%%%%%%%%%%%%%%%%
+% Setup footer %
+%%%%%%%%%%%%%%%%%%%%%%
+\def\leftOne{Test company AB}
+\def\leftTwo{Fake address 33}
+\def\leftThree{SE-123 45 Gotham City}
+\def\centerOne{Telephone: +99 99 999 9999}
+\def\centerTwo{E-mail: contact@batman.robin}
+\def\centerThree{Web: www.batman.robin}
+\def\rightOne{Org. nr: 123456-7890}
+\def\rightTwo{Bankgiro: 123-1234}
+\def\rightThree{Approved for tax.}
+
+%%%%%%%%%%%%%%%%%%%%%%
+% Setup table units %
+%%%%%%%%%%%%%%%%%%%%%%
+\def\unitOne{}
+\def\unitTwo{}
+\def\unitThree{\space h}
+\def\unitFour{\space\currency}
+
+%%%%%%%%%%%%%%%%%%%%%%
+% Start document %
+%%%%%%%%%%%%%%%%%%%%%%
+\input{info.tex}
+\pagestyle{fancy}%
+\thispagestyle{fancy}%
+\begin{document}
+ \sffamily%
+ %Process company info
+ \makecompany
+ %Write any text you like before the table
+ The following invoice is for services performed from \startDate{} through
+\endDate{} under agreement 11111 between \leftOne{} and \companyName.
+ %Load data
+ \input{data.tex}
+ %Alternating colors in table
+% \rowcolors{2}{gray!25}{white}%
+ %Create the table
+ \makeproducts
+\end{document}
diff --git a/extensions/ki_invoice/invoices/my_company_LaTeX/logo.png b/extensions/ki_invoice/invoices/my_company_LaTeX/logo.png
new file mode 100644
index 000000000..ed241acc2
Binary files /dev/null and b/extensions/ki_invoice/invoices/my_company_LaTeX/logo.png differ
diff --git a/extensions/ki_invoice/print.php b/extensions/ki_invoice/print.php
index 02f43d368..3e0fecf94 100644
--- a/extensions/ki_invoice/print.php
+++ b/extensions/ki_invoice/print.php
@@ -168,7 +168,8 @@
$renderers = array(
'odt' => new Kimai_Invoice_OdtRenderer(),
'html' => new Kimai_Invoice_HtmlRenderer(),
- 'pdf' => new Kimai_Invoice_HtmlToPdfRenderer()
+ 'pdf' => new Kimai_Invoice_HtmlToPdfRenderer(),
+ 'LaTeX' => new Kimai_Invoice_LaTeXRenderer()
);
/* @var $renderer Kimai_Invoice_AbstractRenderer */
diff --git a/includes/version.php b/includes/version.php
index 41567d524..3c40ff11f 100644
--- a/includes/version.php
+++ b/includes/version.php
@@ -1,4 +1,4 @@
"Round new timesheet entries to",
"minutes" => "Minutes",
"seconds" => "Seconds",
+ "LaTeXExecutable" => "Full path to LaTeX executable, i.e., 'pdflatex'. For more information, see https://www.ctan.org/",
+ "cannotExecute" => "Your system does not allow execution of external files. LaTeX invoice generation will be disabled.",
"and" => "and",
"customerlogin" => "customer login",
"expense" => "Expense",
diff --git a/libraries/Kimai/Database/Mysql.php b/libraries/Kimai/Database/Mysql.php
index 6d9834b57..b85da5e94 100644
--- a/libraries/Kimai/Database/Mysql.php
+++ b/libraries/Kimai/Database/Mysql.php
@@ -2932,6 +2932,7 @@ public function initializeConfig(Kimai_Config $config)
// break is not here on purpose!
case 'adminmail':
+ case 'LaTeXExec':
case 'loginTries':
case 'loginBanTime':
case 'currency_name':
diff --git a/libraries/Kimai/Invoice/Checksum.php b/libraries/Kimai/Invoice/Checksum.php
new file mode 100644
index 000000000..50cf86558
--- /dev/null
+++ b/libraries/Kimai/Invoice/Checksum.php
@@ -0,0 +1,103 @@
+.
+ */
+
+/**
+ * Class for generating checksums for invoices.
+ * This file calculates a checksum for the invoice number.
+ * Feel free to add more checksum functions as needed in different countries.
+ *
+ * @author Gustav Johansson
+ */
+
+class Kimai_Invoice_Checksum
+{
+ /**
+ * @param $type
+ * @param $id
+ * @param $args
+ * @return string
+ */
+ public function generateChecksum($type, $id, $args)
+ {
+ switch ($type) {
+ case 'OCR':
+ return $this->OCR($id, $args);
+ break;
+ }
+ }
+
+ /**
+ * @param $id
+ * @param bool $addLength
+ * @return int|string
+ */
+ private function OCR($id, $addLength = true)
+ {
+ /**
+ * Calculates the checksum with length number according to the swedish OCR
+ * system. I.e., 123456 will have a length number added to it (including the
+ * length number itself and a checksum digit. The return invoice id will be
+ * a valid OCR-number: 12345682 where the next to last digit is the total
+ * length and the last digit is the checksum.
+ */
+ //Check length. Max is 25 including checksum and length no.
+ if ($addLength) {
+ $max = 23;
+ } else {
+ $max = 24;
+ }
+ if (strlen($id) > $max) {
+ return -1;
+ }
+
+ //Calculate the length number (only last digit)
+ $len = (strlen($id) + 2) % 10;
+ if ($addLength) {
+ $invoice = $id . $len;
+ } else {
+ $invoice = $id;
+ }
+
+ //Calculate checksum
+ $inReverse = array_reverse(str_split($invoice));
+ $sum = 0;
+ $even = true;
+ foreach ($inReverse as $num) {
+ if ($even) {
+ $even = false;
+ $tmp = $num * 2;
+ if ($tmp > 9) {
+ $tmp = $tmp - 9;
+ }
+ $sum = $sum + $tmp;
+ } else {
+ $even = true;
+ $sum = $sum + $num;
+ }
+ }
+ $check = 10 - ($sum % 10);
+ //Make sure we use 0 and not 10
+ if ($check == 10) {
+ $check = 0;
+ }
+ $checksum = $invoice . $check;
+
+ return $checksum;
+ }
+}
diff --git a/libraries/Kimai/Invoice/LaTeXRenderer.php b/libraries/Kimai/Invoice/LaTeXRenderer.php
new file mode 100644
index 000000000..344252503
--- /dev/null
+++ b/libraries/Kimai/Invoice/LaTeXRenderer.php
@@ -0,0 +1,156 @@
+.
+ */
+
+/**
+ * Class for rendering LaTeX invoices templates as PDF.
+ *
+ * @author Gustav Johansson
+ */
+class Kimai_Invoice_LaTeXRenderer extends Kimai_Invoice_AbstractRenderer
+{
+ const FILE_TEX = 'invoice.tex';
+
+ /**
+ * Render the invoice.
+ *
+ * @return mixed
+ */
+ public function render()
+ {
+ global $kga;
+
+ Kimai_Logger::logfile('Rendering LaTeX invoice!');
+ $tempDir = $this->getTemporaryDirectory();
+ $dateFormat = '%B %e, %Y';
+ $templateDir = $this->getTemplateDir() . $this->getTemplateFile();
+
+ //Load the ini file
+ $iniFile = $templateDir . '/invoice.ini';
+ $iniArray = parse_ini_file($iniFile, true);
+
+ // fetch variables from model to get values
+ $customer = $this->getModel()->getCustomer();
+ $projects = $this->getModel()->getProjects();
+ $entries = $this->getModel()->getEntries();
+ $data = $this->getModel()->toArray();
+
+ //Create invoiceId
+ $in = time();
+ $invoiceID = date('y', $in) . $customer['customerID'] . date('m', $in) . date('d', $in);
+ $checksum = new Kimai_Invoice_Checksum();
+ $invoiceID = $checksum->generateChecksum('OCR', $invoiceID, true);
+ Kimai_Logger::logfile('InvoiceID: ' . $invoiceID);
+ $this->getModel()->setInvoiceId($invoiceID);
+
+ $data = $this->getModel()->toArray();
+
+ //Write the header/footer data
+ $file = $tempDir . '/info.tex';
+ $handle = fopen($file, 'w');
+ $content = '';
+ $content .= "\\def\\duedate{" . strftime($dateFormat, $data['dueDate']) . "}%\n";
+ $content .= "\\def\\total{" . $data['amount'] . "}%\n";
+ $content .= "\\def\\invoiceID{" . $data['invoiceId'] . "}%\n";
+ $content .= "\\def\\currency{" . $data['currencySign'] . "}%\n";
+ $content .= "\\def\\companyName{" . $customer['company'] . "}%\n";
+ $content .= "\\def\\companyAddress{" . $customer['street'] . "\\\\" . $customer['zipcode'] . " " . $customer['city'] . "}%\n";
+ $content .= "\\def\\companyPhone{" . $customer['phone'] . "}%\n";
+ $content .= "\\def\\companyEmail{" . $customer['mail'] . "}%\n";
+ $content .= "\\def\\comment{" . $customer['comment'] . "}%\n";
+ $content .= "\\def\\startDate{" . strftime($dateFormat, $data['beginDate']) . "}%\n";
+ $content .= "\\def\\endDate{" . strftime($dateFormat, $data['endDate']) . "}%\n";
+ $content .= "\\def\\vatRate{" . $data['vatRate'] . "}%\n";
+ $content .= "\\def\\vat{" . $data['vat'] . "}%\n";
+ $content .= "\\def\\gtotal{" . $data['total'] . "}%\n";
+ $content .= "\\endinput";
+ fwrite($handle, $content);
+ fclose($handle);
+
+ //Write the table
+ $file = $tempDir . '/data.tex';
+ $handle = fopen($file, 'w');
+ $content = '';
+ foreach ($entries as $row) {
+ $table_row = "\\product";
+ foreach ($iniArray['table'] as $index) {
+ $table_row = $table_row . '{' . $row[$index] . '}';
+ }
+ $table_row = $table_row . "%\n";
+ $content .= $table_row;
+ }
+ $content .= "\\endinput";
+ fwrite($handle, $content);
+ fclose($handle);
+
+ //Copy all the neccessary files to the rendering directory
+ copy($templateDir . '/invoice.tex', $tempDir . '/' . $data['invoiceId'] . '.tex');
+ foreach ($iniArray['files'] as $file) {
+ copy($templateDir . '/' . $file, $tempDir . '/' . $file);
+ }
+
+ //Run pdflatex, throw error if not!
+ $output = exec('cd ' . $tempDir . ' && ' . $kga['LaTeXExec'] . ' ' . $data['invoiceId'] . '.tex');
+ if (strlen($output) == 0) {
+ Kimai_Logger::logfile('Could not execute pdflatex. Check your installation!');
+ return;
+ }
+ //Run pdflatex again, throw error if not!
+ $output = exec('cd ' . $tempDir . ' && ' . $kga['LaTeXExec'] . ' ' . $data['invoiceId'] . '.tex');
+
+ //Return the rendered file
+ $this->sendResponse($tempDir . '/' . $data['invoiceId'] . '.pdf');
+ }
+
+ /**
+ * @param string $fileName
+ */
+ public function sendResponse($fileName)
+ {
+ Kimai_Logger::logfile('File to send: ' . $fileName);
+ header('Content-Type: application/pdf');
+ header('Content-Disposition: attachment; filename="' . basename($fileName) . '"');
+ header('Content-Length: ' . filesize($fileName));
+ ob_clean();
+ flush();
+ readfile($fileName);
+ exit;
+ }
+
+ /**
+ * @return string
+ */
+ protected function getTemplateFilename()
+ {
+ return self::FILE_TEX;
+ }
+
+ /**
+ * Check if the file can be rendered.
+ *
+ * @return bool
+ */
+ public function canRender()
+ {
+ if (!is_dir($this->getTemplateDir() . $this->getTemplateFile())) {
+ return false;
+ }
+
+ return (is_file($this->getTemplateDir() . $this->getTemplateFile() . DIRECTORY_SEPARATOR . self::FILE_TEX));
+ }
+}
diff --git a/updater/updater.php b/updater/updater.php
index 91b41215b..57ce39722 100644
--- a/updater/updater.php
+++ b/updater/updater.php
@@ -1174,6 +1174,11 @@
exec_query("ALTER TABLE `${p}timeSheet` CHANGE `fixedRate` `fixedRate` DECIMAL(10,2) NULL");
}
+if ((int)$revisionDB < 1394) {
+ Kimai_Logger::logfile("-- update to r1394");
+ exec_query("INSERT INTO `${p}configuration` (`option`,`value`) VALUES('LaTeXExec', '')");
+}
+
// ================================================================================
// FINALIZATION: update DB version number
// ================================================================================