|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Investform module for webcms2. |
|
5
|
|
|
* Copyright (c) @see LICENSE |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace WebCMS\InvestformModule\Common; |
|
9
|
|
|
|
|
10
|
|
|
require(APP_DIR . '/fpdm/fpdm.php'); |
|
11
|
|
|
|
|
12
|
|
|
use Nette\Templating\FileTemplate; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
class PdfPrinter |
|
18
|
|
|
{ |
|
19
|
|
|
private $investment; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct($investment) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->investment = $investment; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function printPdfForm($response = false) |
|
27
|
|
|
{ |
|
28
|
|
|
$fvoa = new FutureValueOfAnnuityCalculator($this->investment->getInvestment(), $this->investment->getRealInvestmentLength()); |
|
29
|
|
|
|
|
30
|
|
|
$templatePath = APP_DIR . '/../zajistenainvestice-kalkulace.pdf'; |
|
31
|
|
|
$length = $this->investment->getInvestmentLength(); |
|
32
|
|
|
|
|
33
|
|
|
$company = $this->investment->getCompany(); |
|
34
|
|
|
$name = $this->investment->getAddress()->getName() . ' ' . $this->investment->getAddress()->getLastname() . (!empty($company) ? ' / ' . $company : ''); |
|
35
|
|
|
$fieldData = array( |
|
36
|
|
|
'name' => $name, |
|
37
|
|
|
'investmentAmount' => number_format($this->investment->getInvestment(), 0, ",", ".") . ',- Kč', |
|
38
|
|
|
'investmentAmountGraph' => number_format($this->investment->getInvestment(), 0, ",", ".") . ',- Kč', |
|
39
|
|
|
'address' => $this->investment->getAddress()->getAddressString(), |
|
40
|
|
|
'bankAccountNumber' => $this->investment->getBankAccount(), |
|
41
|
|
|
'email' => $this->investment->getEmail(), |
|
42
|
|
|
'telephoneNumber' => $this->investment->getPhone(), |
|
43
|
|
|
'investmentLength' => ($length == '3' ? 'tříletý' : 'pětiletý'), // TODO move to settings |
|
44
|
|
|
'incomeAfterTaxes' => number_format($fvoa->getTotalProfit(), 0, ",", ".") . ',- Kč', |
|
45
|
|
|
'incomeBeforeTaxes' => number_format($fvoa->getTotalProfit(), 0, ",", ".") . ',- Kč' |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
return $this->processPdf($response, $templatePath, $fieldData, $this->investment, $this->investment->getHash()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function printPdfContract($response = false, $investmentDate = '') |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$fvoa = new FutureValueOfAnnuityCalculator($this->investment->getInvestment(), $this->investment->getRealInvestmentLength()); |
|
54
|
|
|
|
|
55
|
|
|
$oldcontract = ''; |
|
56
|
|
|
$paymentBankAccount = '2114010185/2700'; |
|
57
|
|
|
|
|
58
|
|
|
$templatePath = APP_DIR . "/../zajistenainvestice-smlouva_{$this->investment->getInvestmentLength()}lety-dluhopis{$oldcontract}.pdf"; |
|
59
|
|
|
$bNumber = $this->investment->getBirthdateNumber(); |
|
60
|
|
|
$postalAddress = ($this->investment->getPostalAddress() ? $this->investment->getPostalAddress()->getName() . ' ' . $this->investment->getPostalAddress()->getLastname() . ', ' . $this->investment->getPostalAddress()->getAddressString() : '-'); |
|
61
|
|
|
|
|
62
|
|
|
$company = $this->investment->getCompany(); |
|
63
|
|
|
$name = $this->investment->getAddress()->getName() . ' ' . $this->investment->getAddress()->getLastname() . (!empty($company) ? ' / ' . $company : ''); |
|
64
|
|
|
$id = (!empty($bNumber) ? str_replace('/', '', $bNumber) : $this->investment->getRegistrationNumber()); |
|
65
|
|
|
|
|
66
|
|
|
$businnesId = ($this->investment->getBusinessman() ? $this->investment->getBusinessman()->getBusinessId() : $this->investment->getPin()); |
|
67
|
|
|
|
|
68
|
|
|
$fieldData = array( |
|
69
|
|
|
'name' => $name, |
|
70
|
|
|
'identificationNumber' => $id, |
|
71
|
|
|
'address' => $this->investment->getAddress()->getAddressString(), |
|
72
|
|
|
'mailingAddress' => $postalAddress, |
|
73
|
|
|
'bankAccountNumber' => $this->investment->getBankAccount(), |
|
74
|
|
|
'email' => $this->investment->getEmail(), |
|
75
|
|
|
'paymentAmount' => number_format($fvoa->getPurchaseAmount(), 0, ',', '.') . ',- Kč', |
|
76
|
|
|
'paymentBankAccount' => $paymentBankAccount, // TODO move to settings |
|
77
|
|
|
'telephoneNumber' => $this->investment->getPhone(), |
|
78
|
|
|
'paymentVariableSymbol' => $id, |
|
79
|
|
|
'amountOfBonds' => $this->investment->getInvestment() / 100000, // TODO move to settings |
|
80
|
|
|
'pin' => $businnesId |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
return $this->processPdf($response, $templatePath, $fieldData, $this->investment, $this->investment->getContractHash()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function savePdfToZip($subfolder) |
|
87
|
|
|
{ |
|
88
|
|
|
//TODO refactor to one function |
|
89
|
|
|
$fvoa = new FutureValueOfAnnuityCalculator($this->investment->getInvestment(), $this->investment->getRealInvestmentLength()); |
|
90
|
|
|
|
|
91
|
|
|
$templatePath = APP_DIR . "/../zajistenainvestice-smlouva_{$this->investment->getInvestmentLength()}lety-dluhopis.pdf"; |
|
92
|
|
|
$bNumber = $this->investment->getBirthdateNumber(); |
|
93
|
|
|
$postalAddress = ($this->investment->getPostalAddress() ? $this->investment->getPostalAddress()->getName() . ' ' . $this->investment->getPostalAddress()->getLastname() . ', ' . $this->investment->getPostalAddress()->getAddressString() : '-'); |
|
94
|
|
|
|
|
95
|
|
|
$company = $this->investment->getCompany(); |
|
96
|
|
|
$name = $this->investment->getAddress()->getName() . ' ' . $this->investment->getAddress()->getLastname() . (!empty($company) ? ' / ' . $company : ''); |
|
97
|
|
|
$id = (!empty($bNumber) ? str_replace('/', '', $bNumber) : $this->investment->getRegistrationNumber()); |
|
98
|
|
|
$businnesId = ($this->investment->getBusinessman() ? $this->investment->getBusinessman()->getBusinessId() : $this->investment->getPin()); |
|
99
|
|
|
$fieldData = array( |
|
100
|
|
|
'name' => $name, |
|
101
|
|
|
'identificationNumber' => $id, |
|
102
|
|
|
'address' => $this->investment->getAddress()->getAddressString(), |
|
103
|
|
|
'mailingAddress' => $postalAddress, |
|
104
|
|
|
'bankAccountNumber' => $this->investment->getBankAccount(), |
|
105
|
|
|
'email' => $this->investment->getEmail(), |
|
106
|
|
|
'paymentAmount' => number_format($fvoa->getPurchaseAmount(), 0, ',', '.') . ',- Kč', |
|
107
|
|
|
'paymentBankAccount' => '2114010185/2700', // TODO move to settings |
|
108
|
|
|
'telephoneNumber' => $this->investment->getPhone(), |
|
109
|
|
|
'paymentVariableSymbol' => $id, |
|
110
|
|
|
'amountOfBonds' => $this->investment->getInvestment() / 100000, // TODO move to settings |
|
111
|
|
|
'pin' => $businnesId |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
$pdf = new \FPDM($templatePath); |
|
115
|
|
|
$pdf->Load($fieldData, true); // second parameter: false if field values are in ISO-8859-1, true if UTF-8 |
|
116
|
|
|
$pdf->Merge(); |
|
117
|
|
|
|
|
118
|
|
|
$contractPath = WWW_DIR . '/upload/contracts/' . $subfolder; |
|
119
|
|
|
if (!file_exists($contractPath)) { |
|
120
|
|
|
mkdir($contractPath); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$output = $this->getPdfContent($pdf); |
|
124
|
|
|
file_put_contents($contractPath . '/' . $this->investment->getContractHash() . '.pdf', $output); |
|
125
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
private function processPdf($response, $templatePath, $fieldData, $investment, $hash) |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
$pdf = new \FPDM($templatePath); |
|
131
|
|
|
$pdf->Load($fieldData, true); // second parameter: false if field values are in ISO-8859-1, true if UTF-8 |
|
132
|
|
|
$pdf->Merge(); |
|
133
|
|
|
|
|
134
|
|
|
$contractPath = WWW_DIR . '/upload/contracts'; |
|
135
|
|
|
if (!file_exists($contractPath)) { |
|
136
|
|
|
mkdir($contractPath); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
$output = $this->getPdfContent($pdf); |
|
140
|
|
|
file_put_contents($contractPath . '/' . $hash . '.pdf', $output); |
|
141
|
|
|
|
|
142
|
|
|
if ($response) { |
|
143
|
|
|
header('Content-type: application/pdf'); |
|
144
|
|
|
header('Content-Disposition: inline; filename="smlouva.pdf"'); |
|
145
|
|
|
header('Content-Transfer-Encoding: binary'); |
|
146
|
|
|
header('Content-Length: ' . filesize($contractPath . '/' . $hash . '.pdf')); |
|
147
|
|
|
header('Accept-Ranges: bytes'); |
|
148
|
|
|
|
|
149
|
|
|
echo $output; |
|
150
|
|
|
|
|
151
|
|
|
die(); |
|
152
|
|
|
} else { |
|
153
|
|
|
return $output; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
private function getPdfContent($pdf) |
|
158
|
|
|
{ |
|
159
|
|
|
ob_start(); |
|
160
|
|
|
|
|
161
|
|
|
$pdf->Output(); |
|
162
|
|
|
|
|
163
|
|
|
$pdf = ob_get_contents(); |
|
164
|
|
|
ob_clean(); |
|
165
|
|
|
|
|
166
|
|
|
return $pdf; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
} |
|
171
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.