1 | <?php
|
---|
2 |
|
---|
3 | class Bill extends Pdf
|
---|
4 | {
|
---|
5 | public int $SpecificSymbol = 1; // computer network number
|
---|
6 | }
|
---|
7 |
|
---|
8 | class BillInvoice extends Bill
|
---|
9 | {
|
---|
10 | public string $InvoiceId;
|
---|
11 |
|
---|
12 | function ShowSubjectInfo(array $Subject): string
|
---|
13 | {
|
---|
14 | $BooleanText = array('Ne', 'Ano');
|
---|
15 | $Output = $Subject['Name'].'<br>'.
|
---|
16 | $Subject['AddressStreet'].'<br>'.
|
---|
17 | $Subject['AddressPSC'].' '.$Subject['AddressTown'].'<br>';
|
---|
18 | if (($Subject['IC'] != '') and ($Subject['IC'] != 0)) $Output .= 'IČ: '.$Subject['IC'].'<br>';
|
---|
19 | if ($Subject['DIC'] != '') $Output .= 'DIČ: '.$Subject['DIC'].'<br>';
|
---|
20 | if ($Subject['Account'] != '') $Output .= 'Účet: '.$Subject['Account'].'<br>';
|
---|
21 | if ($Subject['PayVAT'] != '') $Output .= 'Plátce DPH: '.$BooleanText[$Subject['PayVAT']].'<br>';
|
---|
22 | return $Output;
|
---|
23 | }
|
---|
24 |
|
---|
25 | function GenerateHTML(): string
|
---|
26 | {
|
---|
27 | $Finance = &ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance;
|
---|
28 | $Finance->LoadMonthParameters(0);
|
---|
29 |
|
---|
30 | $DbResult = $this->Database->query('SELECT `FinanceInvoice`.*, `FinanceInvoiceGroup`.`Direction`, `DocumentLineCode`.`Name` AS `BillName` FROM `FinanceInvoice` '.
|
---|
31 | 'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
|
---|
32 | 'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id`=`FinanceInvoice`.`BillCode` '.
|
---|
33 | 'WHERE `FinanceInvoice`.`Id`='.$this->InvoiceId);
|
---|
34 | $Invoice = $DbResult->fetch_assoc();
|
---|
35 |
|
---|
36 | $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Invoice['Subject']);
|
---|
37 | $SubjectTo = $DbResult->fetch_assoc();
|
---|
38 | $SubjectTo['Account'] = '';
|
---|
39 | $SubjectTo['PayVAT'] = '';
|
---|
40 | $VarSym = $SubjectTo['Id'];
|
---|
41 |
|
---|
42 | $DbResult = $this->Database->select('Subject', '*', '`Id`='.$this->System->Config['Finance']['MainSubjectId']);
|
---|
43 | $SubjectFrom = $DbResult->fetch_assoc();
|
---|
44 |
|
---|
45 | $DbResult = $this->Database->query('SELECT FinanceBankAccount.*, CONCAT(FinanceBankAccount.Number, "/", FinanceBank.Code) AS NumberFull FROM FinanceBankAccount '.
|
---|
46 | 'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '.
|
---|
47 | 'WHERE (FinanceBankAccount.`Subject`='.$this->System->Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
|
---|
48 | $SubjectFromAccount = $DbResult->fetch_assoc();
|
---|
49 | $SubjectFrom['Account'] = $SubjectFromAccount['NumberFull'];
|
---|
50 |
|
---|
51 | $InvoiceItems = array();
|
---|
52 | $DbResult = $this->Database->select('FinanceInvoiceItem', '*, ROUND(`Price` * `Quantity`, '.$Finance->Rounding.') AS `Total`', '`FinanceInvoice`='.$this->InvoiceId);
|
---|
53 | while ($Item = $DbResult->fetch_assoc())
|
---|
54 | {
|
---|
55 | $InvoiceItems[$Item['Id']] = $Item;
|
---|
56 | }
|
---|
57 |
|
---|
58 | // If direction is in => switch sides
|
---|
59 | if ($Invoice['Direction'] == FINANCE_DIRECTION_OUT)
|
---|
60 | {
|
---|
61 | }
|
---|
62 | else if ($Invoice['Direction'] == FINANCE_DIRECTION_IN)
|
---|
63 | {
|
---|
64 | $Subject = $SubjectTo;
|
---|
65 | $SubjectTo = $SubjectFrom;
|
---|
66 | $SubjectFrom = $Subject;
|
---|
67 | }
|
---|
68 | else throw new Exception('Wrong finance direction');
|
---|
69 |
|
---|
70 | $PaymentType = array('převodem', 'hotově');
|
---|
71 | $BooleanText = array('Ne', 'Ano');
|
---|
72 |
|
---|
73 | $Output = '<table width="100%"><tr><td colspan="2">'.
|
---|
74 | '<font size="6"><div align="center">Faktura - daňový doklad</font></div>'.
|
---|
75 | '<hr></td></tr>'.
|
---|
76 | '<tr><td valign="top" width="50%"><strong>Dodavatel:</strong><br>'.
|
---|
77 | $this->ShowSubjectInfo($SubjectFrom).
|
---|
78 | '</td><td valign="top">'.
|
---|
79 | '<strong>Odběratel:</strong><br>'.
|
---|
80 | $this->ShowSubjectInfo($SubjectTo);
|
---|
81 | $Output .=
|
---|
82 | '</td></tr>'.
|
---|
83 | '<tr><td colspan="2"><hr></td></tr>'.
|
---|
84 | '<tr><td width="50%" valign="top">'.
|
---|
85 | '<strong>Platební podmínky:</strong><br>'.
|
---|
86 | 'Číslo dokladu: '.$Invoice['BillName'].'<br>'.
|
---|
87 | 'Variabilní symbol: '.$VarSym.'<br>'.
|
---|
88 | 'Specifický symbol: '.$this->SpecificSymbol.'<br>'.
|
---|
89 | 'Konstantní symbol:<br>'.
|
---|
90 | 'Způsob úhrady: '.$PaymentType[$Invoice['Cash']].
|
---|
91 | '</td><td valign="top">'.
|
---|
92 | '<br>'.
|
---|
93 | 'Datum vystavení: '.HumanDate($Invoice['Time']).'<br>'.
|
---|
94 | 'Datum zdanitel. plnění: '.HumanDate($Invoice['Time']).'<br>'.
|
---|
95 | 'Datum splatnosti: '.HumanDate($Invoice['TimeDue']).'<br>';
|
---|
96 | if (($Invoice['PeriodFrom'] != '') and ($Invoice['PeriodTo'] != ''))
|
---|
97 | $Output .= 'Fakturované období: '.HumanDate($Invoice['PeriodFrom']).' - '.
|
---|
98 | HumanDate($Invoice['PeriodTo']).'<br>';
|
---|
99 | $Output .= '</td></tr>'.
|
---|
100 | '<tr><td colspan="2">'.
|
---|
101 | '<hr>'.
|
---|
102 | '<br>'.
|
---|
103 | '<table border="0" width="100%">'.
|
---|
104 | '<tr><th align="left">Dodávka</th><th align="right">Množství</th><th align="right">Cena/MJ</th><th align="right">Celkem</th></tr>'.
|
---|
105 | '<tr><td colspan="4"><hr></td></tr>';
|
---|
106 |
|
---|
107 | $Total = 0;
|
---|
108 | foreach ($InvoiceItems as $Item)
|
---|
109 | {
|
---|
110 | $Output .= '<tr><td>'.$Item['Description'].'</td><td align="right">'.
|
---|
111 | $Item['Quantity'].'</td><td align="right">'.$Item['Price'].
|
---|
112 | ' Kč</td><td align="right">'.$Item['Total'].' Kč</td></tr>';
|
---|
113 | $Total += $Item['Total'];
|
---|
114 | }
|
---|
115 | $Output .= '<tr><th colspan="3" align="left">Celkem</th><th align="right">'.$Total.' Kč</th></tr>';
|
---|
116 | $Output .= '</table>'.
|
---|
117 | '</td></tr>'.
|
---|
118 | '<tr><td colspan="2"><hr></td></tr>'.
|
---|
119 | '</table>';
|
---|
120 |
|
---|
121 | return $Output;
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | class BillOperation extends Bill
|
---|
126 | {
|
---|
127 | public string $OperationId;
|
---|
128 |
|
---|
129 | function GenerateHTML(): string
|
---|
130 | {
|
---|
131 | $DbResult = $this->Database->query('SELECT `FinanceOperation`.*, `FinanceOperationGroup`.`Direction`, `DocumentLineCode`.`Name` AS `BillName` FROM `FinanceOperation` '.
|
---|
132 | 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
|
---|
133 | 'LEFT JOIN `DocumentLineCode` ON `DocumentLineCode`.`Id`=`FinanceOperation`.`BillCode` '.
|
---|
134 | 'WHERE `FinanceOperation`.`Id`='.$this->OperationId);
|
---|
135 | $Operation = $DbResult->fetch_assoc();
|
---|
136 |
|
---|
137 | $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Operation['Subject']);
|
---|
138 | $Subject = $DbResult->fetch_assoc();
|
---|
139 |
|
---|
140 | $DbResult = $this->Database->select('Subject', '*', '`Id`='.$this->System->Config['Finance']['MainSubjectId']);
|
---|
141 | $MainSubject = $DbResult->fetch_assoc();
|
---|
142 |
|
---|
143 | $DbResult = $this->Database->query('SELECT FinanceBankAccount.*, CONCAT(FinanceBankAccount.Number, "/", FinanceBank.Code) AS NumberFull FROM FinanceBankAccount '.
|
---|
144 | 'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '.
|
---|
145 | 'WHERE (FinanceBankAccount.`Subject`='.$this->System->Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
|
---|
146 | $MainSubjectAccount = $DbResult->fetch_assoc();
|
---|
147 |
|
---|
148 | $BooleanText = array('Ne', 'Ano');
|
---|
149 | if ($Operation['Direction'] == FINANCE_DIRECTION_OUT)
|
---|
150 | $Desc = array(
|
---|
151 | 'Type' => 'VÝDAJOVÝ',
|
---|
152 | 'Signature' => 'Vydal',
|
---|
153 | 'Target' => 'Vydáno komu',
|
---|
154 | );
|
---|
155 | else if ($Operation['Direction'] == FINANCE_DIRECTION_IN)
|
---|
156 | $Desc = array(
|
---|
157 | 'Type' => 'PŘÍJMOVÝ',
|
---|
158 | 'Signature' => 'Přijal',
|
---|
159 | 'Target' => 'Přijato od',
|
---|
160 | );
|
---|
161 | else throw new Exception('Wrong finance direction');
|
---|
162 |
|
---|
163 | $Output = '<table width="100%" border="1" cellspacing="0" cellpadding="3"><tr><td width="50%">'.
|
---|
164 | '<strong>Firma:</strong><br>'.
|
---|
165 | $MainSubject['Name'].'<br>'.
|
---|
166 | $MainSubject['AddressStreet'].'<br>'.
|
---|
167 | $MainSubject['AddressPSC'].' '.$MainSubject['AddressTown'].'<br>'.
|
---|
168 | 'IČ: '.$MainSubject['IC'].'<br>'.
|
---|
169 | 'DIČ: '.$MainSubject['DIC'].'<br>'.
|
---|
170 | 'Účet: '.$MainSubjectAccount['NumberFull'].'<br>'.
|
---|
171 | 'Plátce DPH: '.$BooleanText[$MainSubject['PayVAT']].
|
---|
172 | '</td><td width="50%" valign="top">'.
|
---|
173 | '<font size="5"><strong>'.$Desc['Type'].' POKLADNÍ DOKLAD</strong></font><br><br>'.
|
---|
174 | 'Číslo dokladu: '.$Operation['BillName'].'<br>'.
|
---|
175 | 'Datum vystavení: '.HumanDate($Operation['Time']).'<br>'.
|
---|
176 | '</td></tr>'.
|
---|
177 | '<tr><td colspan="2"><strong>'.$Desc['Target'].':</strong><br>'.
|
---|
178 | $Subject['Name'].'<br>'.
|
---|
179 | $Subject['AddressStreet'].'<br>'.
|
---|
180 | $Subject['AddressPSC'].' '.$Subject['AddressTown'].'<br>';
|
---|
181 | if ($Subject['IC'] != 0) $Output .= 'IČ: '.$Subject['IC'].'<br>';
|
---|
182 | if ($Subject['DIC'] != '') $Output .= 'DIČ: '.$Subject['DIC'].'<br>';
|
---|
183 | $Description = $Operation['Text'];
|
---|
184 | $Output .= '</td></tr>'.
|
---|
185 | '<tr><td colspan="2"><strong>Částka:</strong> '.$Operation['Value'].' Kč<br><br>'.
|
---|
186 | '</td></tr>'.
|
---|
187 | '<tr><td colspan="2"><strong>Účel platby:</strong><br>'.$Description.'</td></tr>'.
|
---|
188 | '<tr><td> </td><td><br><br>'.$Desc['Signature'].':</td></tr>';
|
---|
189 | $Output .= '</table>';
|
---|
190 | return $Output;
|
---|
191 | }
|
---|
192 | }
|
---|