Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Added new functionality to allow LaTeX generation of invoices. #875

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions extensions/ki_adminpanel/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
1 change: 1 addition & 0 deletions extensions/ki_adminpanel/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
7 changes: 7 additions & 0 deletions extensions/ki_adminpanel/templates/scripts/advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
<input type="text" name="roundMinutes" size="3" class="formfield" value="<?php echo $this->roundMinutes?>" <?php if (!$this->roundTimesheetEntries): ?> disabled="disabled" <?php endif; ?>> <?php echo $this->kga['lang']['minutes']?> <?php echo $this->kga['lang']['and']?>
<input type="text" name="roundSeconds" size="3" class="formfield" value="<?php echo $this->roundSeconds?>" <?php if (!$this->roundTimesheetEntries): ?> disabled="disabled" <?php endif; ?>> <?php echo $this->kga['lang']['seconds']?>
</div>
<div>
<?php if ($this->execAvailable): ?>
<input type="text" name="LaTeX_exec" size="45" value="<?php echo $this->escape($this->kga['LaTeXExec']) ?>" class="formfield"> <?php echo $this->kga['lang']['LaTeXExecutable']?>
<?php else: ?>
<?php echo $this->kga['lang']['cannotExecute']?>
<?php endif; ?>
</div>
<div id="formbuttons">
<input id="adminPanel_extension_form_editadv_submit" class="btn_ok" type="submit" value="<?php echo $this->kga['lang']['save']?>" />
</div>
Expand Down
22 changes: 18 additions & 4 deletions extensions/ki_invoice/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
182 changes: 182 additions & 0 deletions extensions/ki_invoice/invoices/my_company_LaTeX/invoice.cls
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
%%

%%
% An example LaTeX class template for printing invoices.
%
% @author Gustav Johansson <[email protected]>
%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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
60 changes: 60 additions & 0 deletions extensions/ki_invoice/invoices/my_company_LaTeX/invoice.ini
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
;;

;;
; An example LaTeX setting file for printing invoices.
;
; @author Gustav Johansson <[email protected]>
;;

; 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"
84 changes: 84 additions & 0 deletions extensions/ki_invoice/invoices/my_company_LaTeX/invoice.tex
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
%%

%%
% An example LaTeX template for printing invoices.
%
% @author Gustav Johansson <[email protected]>
%%

%%%%%%%%%%%%%%%%%%%%%%
% 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: [email protected]}
\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}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading