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

[FEATURE] tinyDoc-->openTBS; support for .docx templates #1132

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"tecnickcom/tcpdf": "^6.2.12",
"zendframework/zendframework1": "^1.12",
"phpoffice/phpexcel": "1.8.*",
"tinybutstrong/tinybutstrong": "^3.10"
"tinybutstrong/tinybutstrong": "^3.10",
"tinybutstrong/opentbs": ">=1.9.11"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
Expand Down
49 changes: 48 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified extensions/ki_invoice/invoices/2016.odt
Binary file not shown.
Binary file added extensions/ki_invoice/invoices/2018.docx
Binary file not shown.
Binary file modified extensions/ki_invoice/invoices/long.odt
Binary file not shown.
Binary file modified extensions/ki_invoice/invoices/short.odt
Binary file not shown.
Binary file modified extensions/ki_invoice/invoices/spreadsheet.ods
Binary file not shown.
Binary file modified extensions/ki_invoice/invoices/vat.odt
100755 → 100644
Binary file not shown.
19 changes: 15 additions & 4 deletions extensions/ki_invoice/print.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* This file is part of
* Kimai - Open Source Time Tracking // https://www.kimai.org
* Kimai - Open Source Time Tracking // http://www.kimai.org
* (c) 2006-2009 Kimai-Development-Team
*
* Kimai is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -65,8 +65,8 @@
$customerName = html_entity_decode($customer['name']);
$beginDate = $in;
$endDate = $out;
$invoiceID = $customer['name'] . "-" . date("y", $in) . "-" . date("m", $in);
$today = time();
$invoiceID = date("Y", $today) . "." . date("m", $today). date("d", $today) . "-" . ($today % 86400);
$dueDate = mktime(0, 0, 0, date("m") + 1, date("d"), date("Y"));

$round = 0;
Expand Down Expand Up @@ -123,6 +123,13 @@
}
}

// generate invoice position numbers
$i = 1;
foreach ($invoiceArray as $k => $v) {
$invoiceArray[$k]['position'] = $i;
$i++;
}

$vat_rate = $customer['vat'];
if (!is_numeric($vat_rate)) {
$vat_rate = $kga->getDefaultVat();
Expand Down Expand Up @@ -163,14 +170,18 @@
$model->setCurrencySign($kga->getCurrencySign());
$model->setCurrencyName($kga->getCurrencyName());
$model->setDueDate(mktime(0, 0, 0, date("m") + 1, date("d"), date("Y")));
$model->setFttltime($fttltime);

// ---------------------------------------------------------------------------

$renderers = array(
'odt' => new Kimai_Invoice_OdtRenderer(),
// 'odt' => new Kimai_Invoice_OdtRenderer(),
'html' => new Kimai_Invoice_HtmlRenderer(),
'pdf' => new Kimai_Invoice_HtmlToPdfRenderer()
'pdf' => new Kimai_Invoice_HtmlToPdfRenderer(),
'doc-odt' => new Kimai_Invoice_DocxOdtRenderer()
);


/* @var $renderer Kimai_Invoice_AbstractRenderer */
foreach ($renderers as $rendererType => $renderer) {
$renderer->setTemplateDir($baseFolder);
Expand Down
81 changes: 81 additions & 0 deletions libraries/Kimai/Invoice/DocxOdtRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* This file is part of
* Kimai - Open Source Time Tracking // http://www.kimai.org
* (c) Kimai-Development-Team
*
* 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/>.
*/

/**
* Class for rendering DOC and DOCX invoices.
*
* @author Kevin Papst
*/


include_once('../../libraries/tinybutstrong/opentbs/tbs_plugin_opentbs.php');


class Kimai_Invoice_DocxOdtRenderer extends Kimai_Invoice_AbstractRenderer
{



/**
* Render the invoice.
*
* @return mixed
*/
public function render()
{
$doc = new clsTinyButStrong;
$doc->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);


$templateForm = $this->getTemplateDir() . $this->getTemplateFile();

$doc->LoadTemplate($templateForm, OPENTBS_ALREADY_UTF8);


$customer = $this->getModel()->getCustomer();

$allCustomer = $this->prepareCustomerArray($customer);

$invoiceData = array_merge($allCustomer, $this->getModel()->toArray());

$doc->MergeField('kimai', $invoiceData);

$doc->MergeBlock('pos', $invoiceData['entries']);

$invoiceFilename = $invoiceData['invoiceId'] . '-Invoice.' . substr(strrchr($this->getTemplateFile(), "."), 1);

$doc->Show(OPENTBS_DOWNLOAD, $invoiceFilename);
$doc->LoadTemplate(false);
}

/**
* Returns if the file can be rendered.
*
* @return bool
*/
public function canRender()
{
return (
(stripos($this->getTemplateFile(), '.docx') !== false || stripos($this->getTemplateFile(), '.doc') !== false ||
stripos($this->getTemplateFile(), '.odt') !== false || stripos($this->getTemplateFile(), '.ods') !== false
) &&
is_file($this->getTemplateDir() . $this->getTemplateFile())
);
}
}
105 changes: 0 additions & 105 deletions libraries/Kimai/Invoice/OdtRenderer.php

This file was deleted.

23 changes: 22 additions & 1 deletion libraries/Kimai/Invoice/PrintModel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* This file is part of
* Kimai - Open Source Time Tracking // https://www.kimai.org
* Kimai - Open Source Time Tracking // http://www.kimai.org
* (c) Kimai-Development-Team
*
* Kimai is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -49,6 +49,10 @@ class Kimai_Invoice_PrintModel
* @var int
*/
private $total = 0;
/**
* @var string
*/
private $fttltime = "";
/**
* @var array
*/
Expand Down Expand Up @@ -100,6 +104,7 @@ public function toArray()
'vat' => $this->getVat(),
'vatRate' => $this->getVatRate(),
'total' => $this->getTotal(),
'fttltime' => $this->getfttltime(),
'projects' => $this->getProjects(), // array
'invoiceId' => $this->getInvoiceId(),
'beginDate' => $this->getBeginDate(),
Expand Down Expand Up @@ -336,6 +341,22 @@ public function getTotal()
return $this->total;
}

/**
* @param int $total
*/
public function setFttltime($fttl)
{
$this->fttltime = $fttl;
}

/**
* @return int
*/
public function getFttltime()
{
return $this->fttltime;
}

/**
* @param array $projects
*/
Expand Down