source: trunk/Modules/Finance/Zivnost.php@ 724

Last change on this file since 724 was 724, checked in by chronos, 10 years ago
  • Removed: Do not need preload tariffs anymore. They were replaced by more generalized services.
File size: 23.8 KB
Line 
1<?php
2
3class PageFinanceTaxFiling extends Page
4{
5 var $FullTitle = 'Daňová evidence';
6 var $ShortTitle = 'Daňová evidence';
7 var $ParentClass = 'PageFinance';
8 var $StartEvidence = 0;
9
10 function GetTimePeriodBalance($StartTime, $EndTime)
11 {
12 $Balance = array();
13 $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Direction = 1)');
14 $Row = $DbResult->fetch_array();
15 $Balance['Income']['Start'] = $Row[0] + 0;
16 $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Direction = 1)');
17 //echo('SELECT SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value > 0 AND Taxable = 1'.'<br />');
18 $Row = $DbResult->fetch_array();
19 $Balance['Income']['End'] = $Row[0] + 0;
20
21 $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Direction = -1)');
22 $Row = $DbResult->fetch_array();
23 $Balance['Spend']['Start'] = $Row[0] + 0;
24 $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Direction = -1)');
25 //echo('SELECT -SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value < 0 AND Taxable = 1'.'<br />');
26 $Row = $DbResult->fetch_array();
27 $Balance['Spend']['End'] = $Row[0] + 0;
28
29 $DbResult = $this->Database->query('SELECT SUM(Value*Direction) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = 1)');
30 $Row = $DbResult->fetch_array();
31 $Balance['Claims']['Start'] = $Row[0] + 0;
32 $DbResult = $this->Database->query('SELECT SUM(Value*Direction) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = 1)');
33 $Row = $DbResult->fetch_array();
34 $Balance['Claims']['End'] = $Row[0] + 0;
35
36 $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceInvoice WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = -1)');
37 $Row = $DbResult->fetch_array();
38 $Balance['Liabilities']['Start'] = $Row[0] + 0;
39 $DbResult = $this->Database->query('SELECT -SUM(Value*Direction) FROM FinanceInvoice WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Direction = -1)');
40 $Row = $DbResult->fetch_array();
41 $Balance['Liabilities']['End'] = $Row[0] + 0;
42
43 // SmallAssets
44 $DbResult = $this->Database->query('SELECT SUM(SellPrice) FROM StockSerialNumber WHERE (TimeEnlistment < "'.TimeToMysqlDateTime($StartTime).'") AND (TimeEnlistment != 0) AND ((TimeElimination > "'.TimeToMysqlDateTime($StartTime).'") OR (TimeElimination IS NULL))');
45 //$Output .= $Database->error;
46 $Row = $DbResult->fetch_array();
47 $Balance['SmallAssets']['Start'] = $Row[0] + 0;
48 $DbResult = $this->Database->query('SELECT SUM(SellPrice) FROM StockSerialNumber WHERE (TimeEnlistment < "'.TimeToMysqlDateTime($EndTime).'") AND (TimeEnlistment != 0) AND ((TimeElimination > "'.TimeToMysqlDateTime($EndTime).'") OR (TimeElimination IS NULL))');
49 $Row = $DbResult->fetch_array();
50 $Balance['SmallAssets']['End'] = $Row[0] + 0;
51 return($Balance);
52 }
53
54 function Show()
55 {
56 if(!$this->System->User->CheckPermission('Finance', 'TradingStatus')) return('Nemáte oprávnění');
57
58 $Output = '';
59 if(!array_key_exists('table', $_GET)) $_GET['table'] = '';
60 switch($_GET['table'])
61 {
62 case 'AnnualBalance':
63 $Output = '<table style="font-size: smaller;" class="WideTable">';
64 $Output .= '<tr><th colspan="3">Účetní období</th><th colspan="5">Na konci</th><th colspan="6">Během</th></tr>'.
65 '<tr><th>Rok</th><th>Od</th><th>Do</th><th>Příjmy</th><th>Výdaje</th><th>Pohledávky</th><th>Závazky</th><th>Drobný majetek</th><th>Příjmy</th><th>Výdaje</th><th>Pohledávky</th><th>Závazky</th><th>Drobný majetek</th><th>Základ daně</th></tr>';
66
67 $this->StartEvidence = mktime(0, 0, 0, 12, 1, 2007);
68 $StartYear = date('Y', $this->StartEvidence);
69 $EndYear = date('Y', time());
70 for($Year = $StartYear; $Year <= $EndYear; $Year++)
71 {
72 $EndTime = mktime(0, 0, 0, 12, 31, $Year);
73 //$Year = date('Y', $EndTime);
74 $StartTime = mktime(0, 0, 0, 1, 1, $Year);
75 if($StartTime < $this->StartEvidence) $StartTime = $this->StartEvidence;
76
77 $Balance = $this->GetTimePeriodBalance($StartTime, $EndTime);
78
79 $Output .= '<tr><td>'.$Year.'</td><td>'.date(HumanDate(TimeToMysqlDateTime($StartTime))).'</td><td>'.date(HumanDate(TimeToMysqlDateTime($EndTime))).'</td>';
80 $Output .= '<td>'.round($Balance['Income']['End']).'</td>';
81 $Output .= '<td>'.round($Balance['Spend']['End']).'</td>';
82 $Output .= '<td>'.round($Balance['Claims']['End']).'</td>';
83 $Output .= '<td>'.round($Balance['Liabilities']['End']).'</td>';
84 $Output .= '<td>'.round($Balance['SmallAssets']['End']).'</td>';
85
86 $Output .= '<td>'.round($Balance['Income']['End'] - $Balance['Income']['Start']).'</td>';
87 $Output .= '<td>'.round($Balance['Spend']['End'] - $Balance['Spend']['Start']).'</td>';
88 $Output .= '<td>'.round($Balance['Claims']['End'] - $Balance['Claims']['Start']).'</td>';
89 $Output .= '<td>'.round($Balance['Liabilities']['End'] - $Balance['Liabilities']['Start']).'</td>';
90 $Output .= '<td>'.round($Balance['SmallAssets']['End'] - $Balance['SmallAssets']['Start']).'</td>';
91 $Output .= '<td>'.round(($Balance['Income']['End'] - $Balance['Income']['Start']) - ($Balance['Spend']['End'] - $Balance['Spend']['Start'])).'</td></tr>';
92 }
93 $Output .= '</table>';
94 break;
95 case 'MonthlyBalance':
96 $Output = '<table class="WideTable" style="font-size: smaller;">';
97 $Output .= '<tr><th colspan="4">Účetní období</th><th colspan="5">Na konci</th><th colspan="6">Během</th></tr>'.
98 '<tr><th>Rok</th><th>Měsíc</th></th><th>Od</th><th>Do</th><th>Příjmy</th><th>Výdaje</th><th>Pohledávky</th><th>Závazky</th><th>Drobný majetek</th><th>Příjmy</th><th>Výdaje</th><th>Pohledávky</th><th>Závazky</th><th>Drobný majetek</th><th>Základ daně</th></tr>';
99
100 $this->StartEvidence = mktime(0, 0, 0, 12, 1, 2007);
101 $StartYear = date('Y', $this->StartEvidence);
102 $EndYear = date('Y', time());
103 for($Year = $StartYear; $Year <= $EndYear; $Year++)
104 {
105 for($Month = 1; $Month <= 12; $Month++)
106 {
107 $EndTime = mktime(0, 0, 0, $Month, 31, $Year);
108 //$Year = date('Y', $EndTime);
109 $StartTime = mktime(0, 0, 0, $Month, 1, $Year);
110 if(($StartTime < time()) and ($EndTime > $this->StartEvidence))
111 {
112 if($StartTime < $this->StartEvidence) $StartTime = $this->StartEvidence;
113
114 $Balance = $this->GetTimePeriodBalance($StartTime, $EndTime);
115
116 $Output .= '<tr><td>'.$Year.'</td><td>'.$Month.'</td><td>'.date(HumanDate(TimeToMysqlDateTime($StartTime))).'</td><td>'.date(HumanDate(TimeToMysqlDateTime($EndTime))).'</td>';
117 $Output .= '<td>'.round($Balance['Income']['End']).'</td>';
118 $Output .= '<td>'.round($Balance['Spend']['End']).'</td>';
119 $Output .= '<td>'.round($Balance['Claims']['End']).'</td>';
120 $Output .= '<td>'.round($Balance['Liabilities']['End']).'</td>';
121 $Output .= '<td>'.round($Balance['SmallAssets']['End']).'</td>';
122
123 $Output .= '<td>'.round($Balance['Income']['End'] - $Balance['Income']['Start']).'</td>';
124 $Output .= '<td>'.round($Balance['Spend']['End'] - $Balance['Spend']['Start']).'</td>';
125 $Output .= '<td>'.round($Balance['Claims']['End'] - $Balance['Claims']['Start']).'</td>';
126 $Output .= '<td>'.round($Balance['Liabilities']['End'] - $Balance['Liabilities']['Start']).'</td>';
127 $Output .= '<td>'.round($Balance['SmallAssets']['End'] - $Balance['SmallAssets']['Start']).'</td>';
128 $Output .= '<td>'.round(($Balance['Income']['End'] - $Balance['Income']['Start']) - ($Balance['Spend']['End'] - $Balance['Spend']['Start'])).'</td></tr>';
129 }
130 }
131 }
132 $Output .= '</table>';
133 break;
134 case 'Incomes':
135 $Table = array('Ne', 'Ano');
136 $DbResult = $this->Database->select('FinanceYear', '*', 'Id='.$_GET['year']);
137 $Year = $DbResult->fetch_assoc();
138
139 $Total = 0;
140 $TotalTax = array(0, 0);
141 $TotalCash = array(0, 0);
142 $Output .= '<strong>Příjmy za rok '.$Year['Year'].'</strong>';
143 $Output .= '<table style="font-size: smaller;" class="WideTable">';
144 $Output .= '<tr><th>Čas</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th><th>Daňový</th><th>Hotovost</th></tr>';
145 $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
146 'WHERE (Direction = 1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
147 while($Row = $DbResult->fetch_array())
148 {
149 $Row['Time'] = explode(' ', $Row['Time']);
150 $Row['Time'] = $Row['Time'][0];
151 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].'</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td><td>'.$Table[$Row['Taxable']].'</td><td>'.$Table[$Row['Cash']].'</td></tr>';
152 $Total += $Row['Value'];
153 $TotalTax[$Row['Taxable']] += $Row['Value'];
154 $TotalCash[$Row['Cash']] += $Row['Value'];
155 }
156 $Output .= '</table><br/>';
157 $Output .= '<strong>Souhrn</strong><br/>';
158 $Output .= 'Celkem: '.$Total.' Kč<br/>';
159 $Output .= ' Daňové: '.$TotalTax[1].' Kč<br/>';
160 $Output .= ' Nedaňové: '.$TotalTax[0].' Kč<br/>';
161 $Output .= ' Hotovostní: '.$TotalCash[1].' Kč<br/>';
162 $Output .= ' Bezhotovostní: '.$TotalCash[0].' Kč<br/>';
163 break;
164 case 'Expenses':
165 $Table = array('Ne', 'Ano');
166 $DbResult = $this->Database->select('FinanceYear', '*', 'Id='.$_GET['year']);
167 $Year = $DbResult->fetch_assoc();
168
169 $Total = 0;
170 $TotalTax = array(0, 0);
171 $TotalCash = array(0, 0);
172 $Output .= '<strong>Výdaje za rok '.$Year['Year'].'</strong>';
173 $Output .= '<table style="font-size: smaller;" class="WideTable">';
174 $Output .= '<tr><th>Čas</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th><th>Daňový</th><th>Hotovost</th></tr>';
175 $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
176 'WHERE (Direction = -1) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
177 while($Row = $DbResult->fetch_array())
178 {
179 $Row['Time'] = explode(' ', $Row['Time']);
180 $Row['Time'] = $Row['Time'][0];
181 $Row['Value'] = $Row['Value'];
182 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].'</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td><td>'.$Table[$Row['Taxable']].'</td><td>'.$Table[$Row['Cash']].'</td></tr>';
183 $Total += $Row['Value'];
184 $TotalTax[$Row['Taxable']] += $Row['Value'];
185 $TotalCash[$Row['Cash']] += $Row['Value'];
186 }
187 $Output .= '</table><br/>';
188 $Output .= '<strong>Souhrn</strong><br/>';
189 $Output .= 'Celkem: '.$Total.' Kč<br/>';
190 $Output .= ' Daňové: '.$TotalTax[1].' Kč<br/>';
191 $Output .= ' Nedaňové: '.$TotalTax[0].' Kč<br/>';
192 $Output .= ' Hotovostní: '.$TotalCash[1].' Kč<br/>';
193 $Output .= ' Bezhotovostní: '.$TotalCash[0].' Kč<br/>';
194 break;
195 case 'Claims':
196 $Table = array('Ne', 'Ano');
197 $DbResult = $this->Database->select('FinanceYear', '*', 'Id='.$_GET['year']);
198 $Year = $DbResult->fetch_assoc();
199
200 $Total = 0;
201 $Output .= '<strong>Pohledávky za rok '.$Year['Year'].'</strong>';
202 $Output .= '<table style="font-size: smaller;" class="WideTable">';
203 $Output .= '<tr><th>Čas vystavení</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th></tr>';
204 $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text '.
205 'FROM FinanceInvoice JOIN Subject ON Subject.Id = FinanceInvoice.Subject '.
206 'WHERE (Direction = 1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
207 '") AND (FinanceInvoice.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
208 while($Row = $DbResult->fetch_array())
209 {
210 if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = '&nbsp;';
211 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].
212 '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['Direction']).'</td></tr>';
213 $Total += $Row['Value'];
214 }
215 $Output .= '</table><br/>';
216 $Output .= 'Celkem: '.$Total.' Kč<br/>';
217 break;
218 case 'Liabilities':
219 $Table = array('Ne', 'Ano');
220 $DbResult = $this->Database->select('FinanceYear', '*', 'Id='.$_GET['year']);
221 $Year = $DbResult->fetch_assoc();
222
223 $Total = 0;
224 $Output .= '<strong>Závazky za rok '.$Year['Year'].'</strong>';
225 $Output .= '<table style="font-size: smaller;" class="WideTable">';
226 $Output .= '<tr><th>Čas vystavení</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th></tr>';
227 $DbResult = $this->Database->query('SELECT *, (SELECT GROUP_CONCAT(Description SEPARATOR ",") FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text '.
228 'FROM FinanceInvoice JOIN Subject ON Subject.Id = FinanceInvoice.Subject '.
229 'WHERE (Direction = -1) AND (FinanceInvoice.Time >= "'.$Year['DateStart'].
230 '") AND (FinanceInvoice.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
231 while($Row = $DbResult->fetch_array())
232 {
233 if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = '&nbsp;';
234 $Row['Value'] = $Row['Value'] * -1;
235 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['BillCode'].
236 '</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.($Row['Value'] * $Row['Direction']).'</td></tr>';
237 $Total += $Row['Value'];
238 }
239 $Output .= '</table><br/>';
240 $Output .= 'Celkem: '.$Total.' Kč<br/>';
241 break;
242 case 'SubjectList':
243 $Output .= '<strong>Seznam subjektů</strong>';
244 $Output .= '<table style="font-size: smaller;" class="WideTable">';
245 $Output .= '<tr><th>Jméno</th><th>Závazky [Kč]</th><th>Pohledávky [Kč]</th><th>Příjmy [Kč]</th><th>Výdaje [Kč]</th><th>Stav účtu</th><th>Starý systém</th></tr>';
246 $DbResult = $this->Database->query('SELECT Id, Name, 0 AS Cash, '.
247 '(SELECT SUM(T1.Value*T1.Direction) FROM FinanceInvoice AS T1 WHERE (T1.Subject = Subject.Id) AND (T1.Direction = 1)) as Claims, '.
248 '(SELECT SUM(T2.Value*T2.Direction) FROM FinanceInvoice AS T2 WHERE (T2.Subject = Subject.Id) AND (T2.Direction = 1) AND (TimePayment IS NULL)) as OpenedClaims, '.
249 '(SELECT -SUM(T3.Value*T3.Direction) FROM FinanceInvoice AS T3 WHERE (T3.Subject = Subject.Id) AND (T3.Direction = -1)) as Liabilities, '.
250 '(SELECT -SUM(T4.Value*T4.Direction) FROM FinanceInvoice AS T4 WHERE (T4.Subject = Subject.Id) AND (T4.Direction = -1) AND (TimePayment IS NULL)) AS OpenedLiabilities, '.
251 '(SELECT SUM(T5.Value*T5.Direction) FROM FinanceOperation AS T5 WHERE (T5.Subject = Subject.Id) AND (T5.Direction = 1)) AS Gains, '.
252 '(SELECT SUM(T6.Value*T6.Direction) FROM FinanceOperation AS T6 WHERE (T6.Subject = Subject.Id) AND (T6.Direction = -1)) AS Spends '.
253 'FROM Subject ORDER BY Name');
254 while($Row = $DbResult->fetch_assoc())
255 {
256 $Output .= '<tr><td style="text-align: left;"><a href="?table=SubjectAccount&Id='.$Row['Id'].'">'.$Row['Name'].'</a></td><td>'.$Row['Liabilities'].' / '.$Row['OpenedLiabilities'].'</td><td>'.$Row['Claims'].' / '.$Row['OpenedClaims'].'</td><td>'.$Row['Gains'].'</td><td>'.$Row['Spends'].'</td><td>'.($Row['Gains'] - $Row['Spends'] - $Row['Claims'] + $Row['Liabilities']).'</td><td>'.$Row['Cash'].'</td></tr>';
257 }
258 $Output .= '</table>';
259 break;
260 case 'SmallAssets':
261 $Output .= '<strong>Drobný majetek</strong>';
262 $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
263 $Output .= '<tr><th>Název</th><th>Hodnota [Kč]</th><th>Datum zakoupení</th><th>Datum vyřezení</th></tr>';
264 $DbResult = $this->Database->query('SELECT Product.Name AS Name, StockSerialNumber.SellPrice AS Price, StockSerialNumber.TimeEnlistment AS TimeEnlistment, StockSerialNumber.TimeElimination AS TimeElimination '.
265 'FROM StockSerialNumber JOIN Product ON Product.Id = StockSerialNumber.Product '.
266 'WHERE (TimeElimination IS NOT NULL)');
267 while($Row = $DbResult->fetch_array())
268 {
269 $Output .= '<tr><td>'.$Row['Name'].'</td><td>'.$Row['Price'].'</td><td>'.$Row['TimeEnlistment'].'</td><td>'.$Row['TimeElimination'].'</td></tr>';
270 }
271 $Output .= '</table>';
272 break;
273 case 'SubjectAccount':
274 $Output .= '<table style="width: 100%"><tr><td style="vertical-align: top;">';
275 $Output .= '<strong>Výpis příjmů/výdajů</strong>';
276 $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
277 $Output .= '<tr><th>Datum</th><th>Název</th><th>Hodnota [Kč]</th><th>Doklad</th></tr>';
278 $DbResult = $this->Database->select('FinanceOperation', '*', 'Subject='.$_GET['Id'].' ORDER BY Time');
279 while($Row = $DbResult->fetch_array())
280 {
281 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.$Row['Text'].
282 '</td><td>'.($Row['Value']*$Row['Direction']).'</td><td>'.$Row['BillCode'].'</td></tr>';
283 }
284 $Output .= '</table></td><td style="vertical-align: top;">';
285
286 $Output .= '<strong>Výpis závazků/pohledávek</strong>';
287 $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
288 $Output .= '<tr><th>Datum vytvoření</th><th>Datum zaplacení</th><th>Název</th><th>Hodnota [Kč]</th><th>Doklad</th></tr>';
289 $DbResult = $this->Database->select('FinanceInvoice', '*, (SELECT GROUP_CONCAT(Description SEPARATOR ",") '.
290 'FROM FinanceInvoiceItem WHERE FinanceInvoiceItem.FinanceInvoice = FinanceInvoice.Id) AS Text',
291 'Subject='.$_GET['Id'].' ORDER BY Time');
292 while($Row = $DbResult->fetch_array())
293 {
294 $Output .= '<tr><td>'.HumanDate($Row['Time']).'</td><td>'.HumanDate($Row['TimePayment']).
295 '</td><td>'.$Row['Text'].'</td><td>'.ceil($Row['Value'] * $Row['Direction']).'</td><td>'.$Row['BillCode'].'</td></tr>';
296 }
297 $Output .= '</table></td></tr></table>';
298
299 /*$Output .= '<strong>Výpis záloh</strong>';
300 $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
301 $Output .= '<tr><th>Datum vytvoření</th><th>Datum zaplacení</th><th>Název</th><th>Hodnota [Kč]</th></tr>';
302 $DbResult = $this->Database->select('FinanceAdvances', '*', 'Subject='.$_GET['Id']);
303 while($Row = $DbResult->fetch_array())
304 {
305 $Output .= '<tr><td>'.$Row['Time'].'</td><td>'.$Row['TimePass'].'</td><td>'.$Row['Direction'].'</td><td>'.($Row['Value']).'</td><td>'.$Row['CashFlowId'].'</td></tr>';
306 }
307 $Output .= '</table>';*/
308
309 $DbResult = $this->Database->query('SELECT Id, 0 AS Cash, (SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) '.
310 'FROM FinanceInvoice WHERE (FinanceInvoice.Subject = Subject.Id) AND '.
311 '(FinanceInvoice.Direction = 1)) as Claims, (SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) '.
312 'FROM FinanceInvoice WHERE (FinanceInvoice.Subject = Subject.Id) AND ('.
313 'FinanceInvoice.Direction = 1) AND (TimePayment IS NULL)) as OpenedClaims, '.
314 '(SELECT SUM(FinanceInvoice.Value * FinanceInvoice.Direction) FROM FinanceInvoice '.
315 'WHERE (FinanceInvoice.Subject = Subject.Id) AND (FinanceInvoice.Direction = -1)) AS '.
316 'Liabilities, (SELECT SUM(FinanceInvoice.Value) FROM FinanceInvoice '.
317 'WHERE (FinanceInvoice.Subject = Subject.Id) AND (FinanceInvoice.Direction = -1) '.
318 'AND (TimePayment IS NULL)) AS OpenedLiabilities, '.
319 '(SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) '.
320 'FROM FinanceOperation WHERE FinanceOperation.Subject = Subject.Id AND FinanceOperation.Direction = 1) '.
321 'AS Gains, (SELECT SUM(FinanceOperation.Value*FinanceOperation.Direction) FROM FinanceOperation WHERE '.
322 'FinanceOperation.Subject = Subject.Id AND FinanceOperation.Direction = -1) as Spends '.
323 'FROM Subject WHERE Id='.$_GET['Id']);
324 $Row = $DbResult->fetch_array();
325 $Output .= 'Stav placení: '.(-$Row['OpenedClaims'] + Abs($Row['OpenedLiabilities']));
326 break;
327 case 'PrintMonthOperations':
328 $Output .= '<table><tr><th>Datum</th><th>Subjekt</th><td></td></tr></table>';
329 break;
330 case 'PrintMonthOperations':
331 $Output .= 'Výpis operací od '.$_GET['TimeFrom'].' do '.$_GET['TimeTo'];
332 $Output .= '<table><tr><th>Datum</th><th>Subjekt</th><th>Suma [Kč]</th><td></td></tr></table>';
333 break;
334 default:
335 $Output .= '<strong>Celkové přehledy</strong><br/>';
336 $Output .= '<a href="?table=AnnualBalance">Účetní závěrka</a><br />';
337 $Output .= '<a href="?table=MonthlyBalance">Měsíční přehledy</a><br />';
338 $Output .= '<a href="?table=SubjectList">Seznam subjektů</a><br />';
339 $Output .= '<a href="?table=SmallAssets">Drobný majetek</a><br />';
340 $Output .= '<br/>';
341 $Output .= '<strong>Roční přehledy</strong><br/>';
342 $Output .= $this->ShowFinanceYears();
343 if(array_key_exists('year', $_GET))
344 {
345 $Year = $_GET['year'] * 1;
346 $Output .= '<a href="?table=Incomes&amp;year='.$Year.'">Příjmy</a><br />';
347 $Output .= '<a href="?table=Expenses&amp;year='.$Year.'">Výdaje</a><br />';
348 $Output .= '<a href="?table=Claims&amp;year='.$Year.'">Pohledávky</a><br />';
349 $Output .= '<a href="?table=Liabilities&amp;year='.$Year.'">Závazky</a><br />';
350 $Output .= '<a href="?table=Advantages&amp;year='.$Year.'">Zálohy</a><br />';
351 }
352 }
353 return($Output);
354 }
355
356 function ShowFinanceYears()
357 {
358 $Output = 'Roky: ';
359 $DbRows = $this->Database->select('FinanceYear', '*');
360 while($DbRow = $DbRows->fetch_assoc())
361 $Output .= '<a href="?year='.$DbRow['Id'].'">'.$DbRow['Year'].'</a> ';
362 $Output .= '<br/>';
363 return($Output);
364 }
365
366 function AddMoney($Subject, $Value, $Text, $Time)
367 {
368 $TimeDue = $Time + 15 * 24 * 3600; // 15 dnů
369
370 }
371
372 function AddInvoice($Subject, $Value, $Text, $Time)
373 {
374 $TimeDue = $Time + 15 * 24 * 3600; // 15 dnů
375
376 }
377}
Note: See TracBrowser for help on using the repository browser.