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

export in dec_time or std_time in export_pdf2 #810

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
107 changes: 78 additions & 29 deletions extensions/ki_export/export_pdf2.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public function getHtmlStringLines($string, $line_width) {
public function Footer() {
global $kga, $customerData, $projectData;

// Position at 1.5 cm from bottom
// Position at 1.5 cm from bottom
$this->SetY(-15);

// customer data
/*$this->SetFont('freesans', '', 8); // Set font
$this->Cell(80, 10, $customerData['customerName'].' ('.$projectData['pct_name'].')', 0, 0, 'L');*/

// Page number
// Page number
$this->SetFont('freesans', 'I', 8); // Set font
$this->Cell(30, 10, $kga['lang']['export_extension']['page'] . ' ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 0, 0, 'C');

Expand Down Expand Up @@ -102,7 +102,16 @@ public function printRows($data, $widths) {
else {
$this->printTimeRow($widths, $row);
$this->moneySum += $row['wage'];
$this->timeSum += $row['decimalDuration'] == -1 ? 0 : $row['decimalDuration'];
if ($_REQUEST['time_type'] == "dec_time") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks as if there are race-conditions where timeSum will not be generated.
I would prefer creating a default timeSum (leaving the previous line) and then overwriting its value in case $_REQUEST['time_type'] != 'dec_time' && isset($this->columns['time'])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on line 105 if $_REQUEST['time_type'] != 'dec_time then it goes to line 109 } else {
and there, if isset($this->columns['time'] TimeSum is updated
I don't understand your race-condition

if (isset($this->columns['dec_time'])) {
$this->timeSum += $row['decimalDuration'] == - 1 ? 0 : $row['decimalDuration'];
}
} else {
if (isset($this->columns['time'])) {
$this->timeSum = $this->SumStdTime($row['formattedDuration'] == - 1 ? 0 : $row['formattedDuration'], $this->timeSum);
}
}

}
}
}
Expand Down Expand Up @@ -143,20 +152,31 @@ function printExpenseRow($w, $row) {

// check if page break is nessessary
if ($this->getPageHeight() - $this->pagedim[$this->page]['bm'] - ($this->getY() + ($field_rows + $probable_comment_lines + 4) * 6) < 0) {
if (isset($this->columns['wage']) && isset($this->columns['dec_time'])) {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1] + $w[2], 6, $this->getX(), $this->getY(), $this->timespan($this->timeSum), '', 0, 0, true, 'R');
if (isset($this->columns['wage']) && (isset($this->columns['dec_time']) || isset($this->columns['time']))) {
if ($_REQUEST['time_type'] == "dec_time") {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1] + $w[2], 6, $this->getX(), $this->getY(), $this->timespan($this->timeSum), '', 0, 0, true, 'R');
} else {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1] + $w[2], 6, $this->getX(), $this->getY(), $this->time_unit($this->timeSum), '', 0, 0, true, 'R');
}
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1], 6, $this->getX(), $this->getY(), $kga['lang']['export_extension']['subtotal'] . ':', '', 0, 0, true, 'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(), $this->getY(), $this->money($this->moneySum), '', 0, 0, true, 'R');
} elseif (isset($this->columns['wage'])) {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1], 6, $this->getX(), $this->getY(), $kga['lang']['export_extension']['subtotal'] . ':', '', 0, 0, true, 'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(), $this->getY(), $this->money($this->moneySum), '', 0, 0, true, 'R');
} elseif (isset($this->columns['dec_time'])) {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1], 6, $this->getX(), $this->getY(), $kga['lang']['export_extension']['subtotal'] . ':', '', 0, 0, true, 'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(), $this->getY(), $this->timespan($this->timeSum), '', 0, 0, true, 'R');
} else {
if($_REQUEST['time_type']=="dec_time") {
$this->ln();
$this->WriteHtmlCell($w[0]+$w[1], 6, $this->getX(),$this->getY(),$kga['lang']['export_extension']['subtotal'].':', '',0,0,true,'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(),$this->getY(),$this->timespan($this->timeSum),'',0,0,true,'R');
} else {
$this->ln();
$this->WriteHtmlCell($w[0]+$w[1], 6, $this->getX(),$this->getY(),$kga['lang']['export_extension']['subtotal'].':', '',0,0,true,'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(),$this->getY(),$this->time_unit($this->timeSum),'',0,0,true,'R');
}
}
$this->AddPage();
}
Expand Down Expand Up @@ -269,10 +289,17 @@ function printTimeRow($w, $row) {
else
$comment_string = '';

if (isset($this->columns['time']) && !empty($row['formattedDuration']))
$time_string = $kga['lang']['export_extension']['duration'] . ': <i>' . $row['formattedDuration'] . ' ' . $kga['lang']['export_extension']['duration_unit'] . '</i>';
else
$time_string = '';
if ($_REQUEST['time_type'] == "dec_time") {
if (isset($this->columns['dec_time']) && ! empty($row['decimalDuration']))
$time_string = $kga['lang']['export_extension']['duration'] . ': <i>' . $row['decimalDuration'] . ' ' . $kga['lang']['export_extension']['duration_unit'] . '</i>';
else
$time_string = '';
} else {
if (isset($this->columns['time']) && ! empty($row['formattedDuration']))
$time_string = $kga['lang']['export_extension']['duration'] . ': <i>' . $row['formattedDuration'] . ' ' . $kga['lang']['export_extension']['duration_unit'] . '</i>';
else
$time_string = '';
}

if (isset($this->columns['rate']) && !empty($row['rate']))
$rate_string = $kga['lang']['rate'] . ': <i>' . $row['rate'] . '</i>';
Expand Down Expand Up @@ -307,20 +334,31 @@ function printTimeRow($w, $row) {

// check if page break is nessessary
if ($this->getPageHeight() - $this->pagedim[$this->page]['bm'] - ($this->getY() + ($field_rows + $probable_comment_lines + 4) * 6) < 0) {
if (isset($this->columns['wage']) && isset($this->columns['dec_time'])) {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1] + $w[2], 6, $this->getX(), $this->getY(), $this->timespan($this->timeSum), '', 0, 0, true, 'R');
if (isset($this->columns['wage']) && (isset($this->columns['dec_time']) || isset($this->columns['time']))) {
if ($_REQUEST['time_type'] == "dec_time") {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1] + $w[2], 6, $this->getX(), $this->getY(), $this->timespan($this->timeSum), '', 0, 0, true, 'R');
} else {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1] + $w[2], 6, $this->getX(), $this->getY(), $this->time_unit($this->timeSum), '', 0, 0, true, 'R');
}
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1], 6, $this->getX(), $this->getY(), $kga['lang']['export_extension']['subtotal'] . ':', '', 0, 0, true, 'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(), $this->getY(), $this->money($this->moneySum), '', 0, 0, true, 'R');
} elseif (isset($this->columns['wage'])) {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1], 6, $this->getX(), $this->getY(), $kga['lang']['export_extension']['subtotal'] . ':', '', 0, 0, true, 'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(), $this->getY(), $this->money($this->moneySum), '', 0, 0, true, 'R');
} elseif (isset($this->columns['dec_time'])) {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1], 6, $this->getX(), $this->getY(), $kga['lang']['export_extension']['subtotal'] . ':', '', 0, 0, true, 'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(), $this->getY(), $this->timespan($this->timeSum), '', 0, 0, true, 'R');
} else {
if ($_REQUEST['time_type'] == "dec_time") {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1], 6, $this->getX(), $this->getY(), $kga['lang']['export_extension']['subtotal'] . ':', '', 0, 0, true, 'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(), $this->getY(), $this->timespan($this->timeSum), '', 0, 0, true, 'R');
} else {
$this->ln();
$this->WriteHtmlCell($w[0] + $w[1], 6, $this->getX(), $this->getY(), $kga['lang']['export_extension']['subtotal'] . ':', '', 0, 0, true, 'R');
$this->WriteHtmlCell($w[2], 6, $this->getX(), $this->getY(), $this->time_unit($this->timeSum), '', 0, 0, true, 'R');
}
}
$this->AddPage();
}
Expand Down Expand Up @@ -559,21 +597,32 @@ function printTimeRow($w, $row) {
$widths = $pdf->columnWidths($max_time_width, $max_money_width);

$pdf->printRows($customer[$project_id], $widths);

if (isset($columns['wage']) && isset($columns['dec_time'])) {
$pdf->ln();
$pdf->WriteHtmlCell($widths[0] + $widths[1] + $widths[2], 6, $pdf->getX(), $pdf->getY(), $pdf->timespan($pdf->timeSum), '', 0, 0, true, 'R');

if (isset($columns['wage']) && (isset($columns['dec_time']) || isset($this->columns['time']))) {
if ($_REQUEST['time_type'] == "dec_time") {
$pdf->ln();
$pdf->WriteHtmlCell($widths[0] + $widths[1] + $widths[2], 6, $pdf->getX(), $pdf->getY(), $pdf->timespan($pdf->timeSum), '', 0, 0, true, 'R');
} else {
$pdf->ln();
$pdf->WriteHtmlCell($widths[0] + $widths[1] + $widths[2], 6, $pdf->getX(), $pdf->getY(), $pdf->time_unit($pdf->timeSum), '', 0, 0, true, 'R');
}
$pdf->ln();
$pdf->WriteHtmlCell($widths[0] + $widths[1], 6, $pdf->getX(), $pdf->getY(), $kga['lang']['export_extension']['finalamount'] . ':', '', 0, 0, true, 'R');
$pdf->WriteHtmlCell($widths[2], 6, $pdf->getX(), $pdf->getY(), $pdf->money($pdf->moneySum), '', 0, 0, true, 'R');
} elseif (isset($columns['wage'])) {
$pdf->ln();
$pdf->WriteHtmlCell($widths[0] + $widths[1], 6, $pdf->getX(), $pdf->getY(), $kga['lang']['export_extension']['finalamount'] . ':', '', 0, 0, true, 'R');
$pdf->WriteHtmlCell($widths[2], 6, $pdf->getX(), $pdf->getY(), $pdf->money($pdf->moneySum), '', 0, 0, true, 'R');
} elseif (isset($columns['dec_time'])) {
$pdf->ln();
$pdf->WriteHtmlCell($widths[0] + $widths[1], 6, $pdf->getX(), $pdf->getY(), $kga['lang']['export_extension']['finalamount'] . ':', '', 0, 0, true, 'R');
$pdf->WriteHtmlCell($widths[2], 6, $pdf->getX(), $pdf->getY(), $pdf->timespan($pdf->timeSum), '', 0, 0, true, 'R');
} else {
if ($_REQUEST['time_type'] == "dec_time") {
$pdf->ln();
$pdf->WriteHtmlCell($widths[0] + $widths[1], 6, $pdf->getX(), $pdf->getY(), $kga['lang']['export_extension']['finalamount'] . ':', '', 0, 0, true, 'R');
$pdf->WriteHtmlCell($widths[2], 6, $pdf->getX(), $pdf->getY(), $pdf->timespan($pdf->timeSum), '', 0, 0, true, 'R');
} else {
$pdf->ln();
$pdf->WriteHtmlCell($widths[0] + $widths[1], 6, $pdf->getX(), $pdf->getY(), $kga['lang']['export_extension']['finalamount'] . ':', '', 0, 0, true, 'R');
$pdf->WriteHtmlCell($widths[2], 6, $pdf->getX(), $pdf->getY(), $pdf->time_unit($pdf->timeSum), '', 0, 0, true, 'R');
}
}
}
}
Expand Down