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