1 | <?php
|
---|
2 |
|
---|
3 | include_once('../Common/Global.php');
|
---|
4 |
|
---|
5 | class FinanceTaxFilingPage extends Page
|
---|
6 | {
|
---|
7 | var $FullTitle = 'Daňová evidence';
|
---|
8 | var $ShortTitle = 'Daňová evidence';
|
---|
9 | var $ExternalSubject = 96;
|
---|
10 | var $MainSubject = 71;
|
---|
11 | var $StartEvidence = 0;
|
---|
12 |
|
---|
13 | /*function TransformFinance()
|
---|
14 | {
|
---|
15 | //$Database->Query('SELECT user as Subject, date as TimeCreation, date as TimeDue, date as TimePayment, -money as Value, bill_id as Bill, comment as Text FROM `finance_operations` WHERE Comment LIKE "Poplatek za měsíc%" AND date >= "2007-12-01"');
|
---|
16 | //'TRUNCATE TABLE FinanceCashFlow; INSERT INTO FinanceCashFlow (SELECT '' as Id, user as Subject, comment as Text, date as Time, 1 as Taxable, 0 as Cash, money as Value, bill_id as Bill FROM `finance_operations` WHERE comment NOT LIKE "Poplatek za měsíc%" AND date >= "2007-12-01")'
|
---|
17 | // 'UPDATE finance_operations SET date="2007-11-24" WHERE comment="Jednorázový poplatek za společné zařízení"'
|
---|
18 |
|
---|
19 | $DbResult = $this->Database->query('SELECT * FROM users WHERE role=2');
|
---|
20 | while($User = $DbResult->fetch_array())
|
---|
21 | {
|
---|
22 | $DbResult2 = $this->Database->query('SELECT SUM(money) FROM finance_operations WHERE user='.$User['id'].' AND date < "2007-12-01"');
|
---|
23 | $Row = $DbResult2->fetch_array();
|
---|
24 | echo($User['second_name'].' '.$User['first_name'].' '.$Row[0].'<br />');
|
---|
25 | // if($Row[0] > 0) $Database->insert('FinanceCashFlow', array('Text' => 'Přijatá záloha (z období před účetnictvím)', 'Subject' => $User['id'], 'Time' => '2007-01-01', 'Taxable' => 1, 'Cash' => 0, 'Value' => $Row[0], 'Bill' => 0));
|
---|
26 | if($Row[0] < 0)
|
---|
27 | {
|
---|
28 | $this->Database->insert('FinanceClaimsLiabilities', array('Text' => 'Připojení k síti (z období před účetnictvím)', 'Subject' => $User['id'], 'TimeCreation' => '2007-12-01', 'TimeDue' => '2007-12-14', 'TimePayment' => '', 'Value' => (-$Row[0]), 'Bill' => 0));
|
---|
29 | //echo($Database->LastQuery.'<br />');
|
---|
30 | }
|
---|
31 | }
|
---|
32 | }*/
|
---|
33 | function GetTimePeriodBalance($StartTime, $EndTime)
|
---|
34 | {
|
---|
35 | $Balance = array();
|
---|
36 | $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Value > 0)');
|
---|
37 | $Row = $DbResult->fetch_array();
|
---|
38 | $Balance['Income']['Start'] = $Row[0] + 0;
|
---|
39 | $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Value > 0)');
|
---|
40 | //echo('SELECT SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value > 0 AND Taxable = 1'.'<br />');
|
---|
41 | $Row = $DbResult->fetch_array();
|
---|
42 | $Balance['Income']['End'] = $Row[0] + 0;
|
---|
43 |
|
---|
44 | $DbResult = $this->Database->query('SELECT SUM(-Value) FROM FinanceOperation WHERE (Time < "'.TimeToMysqlDateTime($StartTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Value < 0)');
|
---|
45 | $Row = $DbResult->fetch_array();
|
---|
46 | $Balance['Spend']['Start'] = $Row[0] + 0;
|
---|
47 | $DbResult = $this->Database->query('SELECT SUM(-Value) FROM FinanceOperation WHERE (Time <= "'.TimeToMysqlDateTime($EndTime).'") AND (Time >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Taxable = 1) AND (Value < 0)');
|
---|
48 | //echo('SELECT -SUM(Value) FROM FinanceCashFlow WHERE Time <= "'.TimeToMysqlDateTime($EndTime).'" AND Value < 0 AND Taxable = 1'.'<br />');
|
---|
49 | $Row = $DbResult->fetch_array();
|
---|
50 | $Balance['Spend']['End'] = $Row[0] + 0;
|
---|
51 |
|
---|
52 | $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceClaimsLiabilities WHERE (TimeCreation < "'.TimeToMysqlDateTime($StartTime).'") AND (TimeCreation >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Value > 0)');
|
---|
53 | $Row = $DbResult->fetch_array();
|
---|
54 | $Balance['Claims']['Start'] = $Row[0] + 0;
|
---|
55 | $DbResult = $this->Database->query('SELECT SUM(Value) FROM FinanceClaimsLiabilities WHERE (TimeCreation <= "'.TimeToMysqlDateTime($EndTime).'") AND (TimeCreation >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Value > 0)');
|
---|
56 | $Row = $DbResult->fetch_array();
|
---|
57 | $Balance['Claims']['End'] = $Row[0] + 0;
|
---|
58 |
|
---|
59 | $DbResult = $this->Database->query('SELECT SUM(-Value) FROM FinanceClaimsLiabilities WHERE (TimeCreation < "'.TimeToMysqlDateTime($StartTime).'") AND (TimeCreation >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Value < 0)');
|
---|
60 | $Row = $DbResult->fetch_array();
|
---|
61 | $Balance['Liabilities']['Start'] = $Row[0] + 0;
|
---|
62 | $DbResult = $this->Database->query('SELECT SUM(-Value) FROM FinanceClaimsLiabilities WHERE (TimeCreation <= "'.TimeToMysqlDateTime($EndTime).'") AND (TimeCreation >= "'.TimeToMysqlDateTime($this->StartEvidence).'") AND (Value < 0)');
|
---|
63 | $Row = $DbResult->fetch_array();
|
---|
64 | $Balance['Liabilities']['End'] = $Row[0] + 0;
|
---|
65 |
|
---|
66 | // SmallAssets
|
---|
67 | $DbResult = $this->Database->query('SELECT SUM(SellPrice) FROM StockItem WHERE (TimeEnlistment < "'.TimeToMysqlDateTime($StartTime).'") AND (TimeEnlistment != 0) AND ((TimeElimination > "'.TimeToMysqlDateTime($StartTime).'") OR (TimeElimination IS NULL))');
|
---|
68 | //$Output .= $Database->error;
|
---|
69 | $Row = $DbResult->fetch_array();
|
---|
70 | $Balance['SmallAssets']['Start'] = $Row[0] + 0;
|
---|
71 | $DbResult = $this->Database->query('SELECT SUM(SellPrice) FROM StockItem WHERE (TimeEnlistment < "'.TimeToMysqlDateTime($EndTime).'") AND (TimeEnlistment != 0) AND ((TimeElimination > "'.TimeToMysqlDateTime($EndTime).'") OR (TimeElimination IS NULL))');
|
---|
72 | $Row = $DbResult->fetch_array();
|
---|
73 | $Balance['SmallAssets']['End'] = $Row[0] + 0;
|
---|
74 | return($Balance);
|
---|
75 | }
|
---|
76 |
|
---|
77 | function Show()
|
---|
78 | {
|
---|
79 | if(!$this->System->Modules['User']->CheckPermission('Finance', 'TradingStatus')) return('Nemáte oprávnění');
|
---|
80 | $this->System->Modules['Finance']->LoadTariffs(1);
|
---|
81 | //TransformFinance();
|
---|
82 |
|
---|
83 | $Output = '';
|
---|
84 | if(!array_key_exists('table', $_GET)) $_GET['table'] = '';
|
---|
85 | switch($_GET['table'])
|
---|
86 | {
|
---|
87 | case 'AnnualBalance':
|
---|
88 | $Output = '<table style="font-size: smaller;" class="WideTable">';
|
---|
89 | $Output .= '<tr><th colspan="3">Účetní období</th><th colspan="5">Na konci</th><th colspan="6">Během</th></tr>'.
|
---|
90 | '<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>';
|
---|
91 |
|
---|
92 | $this->StartEvidence = mktime(0, 0, 0, 12, 1, 2007);
|
---|
93 | $StartYear = date('Y', $this->StartEvidence);
|
---|
94 | $EndYear = date('Y', time());
|
---|
95 | for($Year = $StartYear; $Year <= $EndYear; $Year++)
|
---|
96 | {
|
---|
97 | $EndTime = mktime(0, 0, 0, 12, 31, $Year);
|
---|
98 | //$Year = date('Y', $EndTime);
|
---|
99 | $StartTime = mktime(0, 0, 0, 1, 1, $Year);
|
---|
100 | if($StartTime < $this->StartEvidence) $StartTime = $this->StartEvidence;
|
---|
101 |
|
---|
102 | $Balance = $this->GetTimePeriodBalance($StartTime, $EndTime);
|
---|
103 |
|
---|
104 | $Output .= '<tr><td>'.$Year.'</td><td>'.date(HumanDate(TimeToMysqlDateTime($StartTime))).'</td><td>'.date(HumanDate(TimeToMysqlDateTime($EndTime))).'</td>';
|
---|
105 | $Output .= '<td>'.round($Balance['Income']['End']).'</td>';
|
---|
106 | $Output .= '<td>'.round($Balance['Spend']['End']).'</td>';
|
---|
107 | $Output .= '<td>'.round($Balance['Claims']['End']).'</td>';
|
---|
108 | $Output .= '<td>'.round($Balance['Liabilities']['End']).'</td>';
|
---|
109 | $Output .= '<td>'.round($Balance['SmallAssets']['End']).'</td>';
|
---|
110 |
|
---|
111 | $Output .= '<td>'.round($Balance['Income']['End'] - $Balance['Income']['Start']).'</td>';
|
---|
112 | $Output .= '<td>'.round($Balance['Spend']['End'] - $Balance['Spend']['Start']).'</td>';
|
---|
113 | $Output .= '<td>'.round($Balance['Claims']['End'] - $Balance['Claims']['Start']).'</td>';
|
---|
114 | $Output .= '<td>'.round($Balance['Liabilities']['End'] - $Balance['Liabilities']['Start']).'</td>';
|
---|
115 | $Output .= '<td>'.round($Balance['SmallAssets']['End'] - $Balance['SmallAssets']['Start']).'</td>';
|
---|
116 | $Output .= '<td>'.round(($Balance['Income']['End'] - $Balance['Income']['Start']) - ($Balance['Spend']['End'] - $Balance['Spend']['Start'])).'</td></tr>';
|
---|
117 | }
|
---|
118 | $Output .= '</table>';
|
---|
119 | break;
|
---|
120 | case 'MonthlyBalance':
|
---|
121 | $Output = '<table class="WideTable" style="font-size: smaller;">';
|
---|
122 | $Output .= '<tr><th colspan="4">Účetní období</th><th colspan="5">Na konci</th><th colspan="6">Během</th></tr>'.
|
---|
123 | '<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>';
|
---|
124 |
|
---|
125 | $this->StartEvidence = mktime(0, 0, 0, 12, 1, 2007);
|
---|
126 | $StartYear = date('Y', $this->StartEvidence);
|
---|
127 | $EndYear = date('Y', time());
|
---|
128 | for($Year = $StartYear; $Year <= $EndYear; $Year++)
|
---|
129 | {
|
---|
130 | for($Month = 1; $Month <= 12; $Month++)
|
---|
131 | {
|
---|
132 | $EndTime = mktime(0, 0, 0, $Month, 31, $Year);
|
---|
133 | //$Year = date('Y', $EndTime);
|
---|
134 | $StartTime = mktime(0, 0, 0, $Month, 1, $Year);
|
---|
135 | if(($StartTime < time()) and ($EndTime > $this->StartEvidence))
|
---|
136 | {
|
---|
137 | if($StartTime < $this->StartEvidence) $StartTime = $this->StartEvidence;
|
---|
138 |
|
---|
139 | $Balance = $this->GetTimePeriodBalance($StartTime, $EndTime);
|
---|
140 |
|
---|
141 | $Output .= '<tr><td>'.$Year.'</td><td>'.$Month.'</td><td>'.date(HumanDate(TimeToMysqlDateTime($StartTime))).'</td><td>'.date(HumanDate(TimeToMysqlDateTime($EndTime))).'</td>';
|
---|
142 | $Output .= '<td>'.round($Balance['Income']['End']).'</td>';
|
---|
143 | $Output .= '<td>'.round($Balance['Spend']['End']).'</td>';
|
---|
144 | $Output .= '<td>'.round($Balance['Claims']['End']).'</td>';
|
---|
145 | $Output .= '<td>'.round($Balance['Liabilities']['End']).'</td>';
|
---|
146 | $Output .= '<td>'.round($Balance['SmallAssets']['End']).'</td>';
|
---|
147 |
|
---|
148 | $Output .= '<td>'.round($Balance['Income']['End'] - $Balance['Income']['Start']).'</td>';
|
---|
149 | $Output .= '<td>'.round($Balance['Spend']['End'] - $Balance['Spend']['Start']).'</td>';
|
---|
150 | $Output .= '<td>'.round($Balance['Claims']['End'] - $Balance['Claims']['Start']).'</td>';
|
---|
151 | $Output .= '<td>'.round($Balance['Liabilities']['End'] - $Balance['Liabilities']['Start']).'</td>';
|
---|
152 | $Output .= '<td>'.round($Balance['SmallAssets']['End'] - $Balance['SmallAssets']['Start']).'</td>';
|
---|
153 | $Output .= '<td>'.round(($Balance['Income']['End'] - $Balance['Income']['Start']) - ($Balance['Spend']['End'] - $Balance['Spend']['Start'])).'</td></tr>';
|
---|
154 | }
|
---|
155 | }
|
---|
156 | }
|
---|
157 | $Output .= '</table>';
|
---|
158 | break;
|
---|
159 | case 'Incomes':
|
---|
160 | $Table = array('Ne', 'Ano');
|
---|
161 | $DbResult = $this->Database->select('FinanceYear', '*', 'Id='.$_GET['year']);
|
---|
162 | $Year = $DbResult->fetch_assoc();
|
---|
163 |
|
---|
164 | $Total = 0;
|
---|
165 | $TotalTax = array(0, 0);
|
---|
166 | $TotalCash = array(0, 0);
|
---|
167 | $Output .= '<strong>Příjmy za rok '.$Year['Year'].'</strong>';
|
---|
168 | $Output .= '<table style="font-size: smaller;" class="WideTable">';
|
---|
169 | $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>';
|
---|
170 | $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
|
---|
171 | 'WHERE (Value > 0) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
|
---|
172 | while($Row = $DbResult->fetch_array())
|
---|
173 | {
|
---|
174 | $Row['Time'] = explode(' ', $Row['Time']);
|
---|
175 | $Row['Time'] = $Row['Time'][0];
|
---|
176 | $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>';
|
---|
177 | $Total += $Row['Value'];
|
---|
178 | $TotalTax[$Row['Taxable']] += $Row['Value'];
|
---|
179 | $TotalCash[$Row['Cash']] += $Row['Value'];
|
---|
180 | }
|
---|
181 | $Output .= '</table><br/>';
|
---|
182 | $Output .= '<strong>Souhrn</strong><br/>';
|
---|
183 | $Output .= 'Celkem: '.$Total.' Kč<br/>';
|
---|
184 | $Output .= ' Daňové: '.$TotalTax[1].' Kč<br/>';
|
---|
185 | $Output .= ' Nedaňové: '.$TotalTax[0].' Kč<br/>';
|
---|
186 | $Output .= ' Hotovostní: '.$TotalCash[1].' Kč<br/>';
|
---|
187 | $Output .= ' Bezhotovostní: '.$TotalCash[0].' Kč<br/>';
|
---|
188 | break;
|
---|
189 | case 'Expenses':
|
---|
190 | $Table = array('Ne', 'Ano');
|
---|
191 | $DbResult = $this->Database->select('FinanceYear', '*', 'Id='.$_GET['year']);
|
---|
192 | $Year = $DbResult->fetch_assoc();
|
---|
193 |
|
---|
194 | $Total = 0;
|
---|
195 | $TotalTax = array(0, 0);
|
---|
196 | $TotalCash = array(0, 0);
|
---|
197 | $Output .= '<strong>Výdaje za rok '.$Year['Year'].'</strong>';
|
---|
198 | $Output .= '<table style="font-size: smaller;" class="WideTable">';
|
---|
199 | $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>';
|
---|
200 | $DbResult = $this->Database->query('SELECT * FROM FinanceOperation LEFT JOIN Subject ON Subject.Id = FinanceOperation.Subject '.
|
---|
201 | 'WHERE (Value < 0) AND (FinanceOperation.Time >= "'.$Year['DateStart'].'") AND (FinanceOperation.Time <= "'.$Year['DateEnd'].'") ORDER BY Time');
|
---|
202 | while($Row = $DbResult->fetch_array())
|
---|
203 | {
|
---|
204 | $Row['Time'] = explode(' ', $Row['Time']);
|
---|
205 | $Row['Time'] = $Row['Time'][0];
|
---|
206 | $Row['Value'] = $Row['Value'] * -1;
|
---|
207 | $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>';
|
---|
208 | $Total += $Row['Value'];
|
---|
209 | $TotalTax[$Row['Taxable']] += $Row['Value'];
|
---|
210 | $TotalCash[$Row['Cash']] += $Row['Value'];
|
---|
211 | }
|
---|
212 | $Output .= '</table><br/>';
|
---|
213 | $Output .= '<strong>Souhrn</strong><br/>';
|
---|
214 | $Output .= 'Celkem: '.$Total.' Kč<br/>';
|
---|
215 | $Output .= ' Daňové: '.$TotalTax[1].' Kč<br/>';
|
---|
216 | $Output .= ' Nedaňové: '.$TotalTax[0].' Kč<br/>';
|
---|
217 | $Output .= ' Hotovostní: '.$TotalCash[1].' Kč<br/>';
|
---|
218 | $Output .= ' Bezhotovostní: '.$TotalCash[0].' Kč<br/>';
|
---|
219 | break;
|
---|
220 | case 'Claims':
|
---|
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>Pohledávky 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 * FROM FinanceClaimsLiabilities JOIN Subject ON Subject.Id = FinanceClaimsLiabilities.Subject '.
|
---|
230 | 'WHERE (Value > 0) AND (FinanceClaimsLiabilities.TimeCreation >= "'.$Year['DateStart'].'") AND (FinanceClaimsLiabilities.TimeCreation <= "'.$Year['DateEnd'].'") ORDER BY TimeCreation');
|
---|
231 | while($Row = $DbResult->fetch_array())
|
---|
232 | {
|
---|
233 | if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = ' ';
|
---|
234 | $Output .= '<tr><td>'.HumanDate($Row['TimeCreation']).'</td><td>'.$Row['BillCode'].'</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td></tr>';
|
---|
235 | $Total += $Row['Value'];
|
---|
236 | }
|
---|
237 | $Output .= '</table><br/>';
|
---|
238 | $Output .= 'Celkem: '.$Total.' Kč<br/>';
|
---|
239 | break;
|
---|
240 | case 'Liabilities':
|
---|
241 | $Table = array('Ne', 'Ano');
|
---|
242 | $DbResult = $this->Database->select('FinanceYear', '*', 'Id='.$_GET['year']);
|
---|
243 | $Year = $DbResult->fetch_assoc();
|
---|
244 |
|
---|
245 | $Total = 0;
|
---|
246 | $Output .= '<strong>Závazky za rok '.$Year['Year'].'</strong>';
|
---|
247 | $Output .= '<table style="font-size: smaller;" class="WideTable">';
|
---|
248 | $Output .= '<tr><th>Čas vystavení</th><th>Kód</th><th>Subjekt</th><th>Text</th><th>Hodnota [Kč]</th></tr>';
|
---|
249 | $DbResult = $this->Database->query('SELECT * FROM FinanceClaimsLiabilities JOIN Subject ON Subject.Id = FinanceClaimsLiabilities.Subject '.
|
---|
250 | 'WHERE (Value < 0) AND (FinanceClaimsLiabilities.TimeCreation >= "'.$Year['DateStart'].'") AND (FinanceClaimsLiabilities.TimeCreation <= "'.$Year['DateEnd'].'") ORDER BY TimeCreation');
|
---|
251 | while($Row = $DbResult->fetch_array())
|
---|
252 | {
|
---|
253 | if($Row['TimePayment'] == '0000-00-00 00:00:00') $Row['TimePayment'] = ' ';
|
---|
254 | $Row['Value'] = $Row['Value'] * -1;
|
---|
255 | $Output .= '<tr><td>'.HumanDate($Row['TimeCreation']).'</td><td>'.$Row['BillCode'].'</td><td>'.$Row['Name'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td></tr>';
|
---|
256 | $Total += $Row['Value'];
|
---|
257 | }
|
---|
258 | $Output .= '</table><br/>';
|
---|
259 | $Output .= 'Celkem: '.$Total.' Kč<br/>';
|
---|
260 | break;
|
---|
261 | case 'SubjectList':
|
---|
262 | $Output .= '<strong>Seznam subjektů</strong>';
|
---|
263 | $Output .= '<table style="font-size: smaller;" class="WideTable">';
|
---|
264 | $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>';
|
---|
265 | $DbResult = $this->Database->query('SELECT Id, Name, 0 AS Cash, '.
|
---|
266 | '(SELECT SUM(T1.Value) FROM FinanceClaimsLiabilities AS T1 WHERE (T1.Subject = Subject.Id) AND (T1.Value > 0)) as Claims, '.
|
---|
267 | '(SELECT SUM(T2.Value) FROM FinanceClaimsLiabilities AS T2 WHERE (T2.Subject = Subject.Id) AND (T2.Value > 0) AND (TimePayment IS NULL)) as OpenedClaims, '.
|
---|
268 | '(SELECT -SUM(T3.Value) FROM FinanceClaimsLiabilities AS T3 WHERE (T3.Subject = Subject.Id) AND (T3.Value < 0)) as Liabilities, '.
|
---|
269 | '(SELECT -SUM(T4.Value) FROM FinanceClaimsLiabilities AS T4 WHERE (T4.Subject = Subject.Id) AND (T4.Value < 0) AND (TimePayment IS NULL)) AS OpenedLiabilities, '.
|
---|
270 | '(SELECT SUM(T5.Value) FROM FinanceOperation AS T5 WHERE (T5.Subject = Subject.Id) AND (T5.Value > 0)) AS Gains, '.
|
---|
271 | '(SELECT -SUM(T6.Value) FROM FinanceOperation AS T6 WHERE (T6.Subject = Subject.Id) AND (T6.Value < 0)) AS Spends '.
|
---|
272 | 'FROM Subject ORDER BY Name');
|
---|
273 | while($Row = $DbResult->fetch_assoc())
|
---|
274 | {
|
---|
275 | $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>';
|
---|
276 | }
|
---|
277 | $Output .= '</table>';
|
---|
278 | break;
|
---|
279 | case 'SmallAssets':
|
---|
280 | $Output .= '<strong>Drobný majetek</strong>';
|
---|
281 | $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
|
---|
282 | $Output .= '<tr><th>Název</th><th>Hodnota [Kč]</th><th>Datum zakoupení</th><th>Datum vyřezení</th></tr>';
|
---|
283 | $DbResult = $this->Database->query('SELECT Product.Name AS Name, StockItem.SellPrice AS Price, StockItem.TimeEnlistment AS TimeEnlistment, StockItem.TimeElimination AS TimeElimination '.
|
---|
284 | 'FROM StockItem JOIN Product ON Product.Id = StockItem.Product '.
|
---|
285 | 'WHERE (TimeElimination IS NOT NULL)');
|
---|
286 | while($Row = $DbResult->fetch_array())
|
---|
287 | {
|
---|
288 | $Output .= '<tr><td>'.$Row['Name'].'</td><td>'.$Row['Price'].'</td><td>'.$Row['TimeEnlistment'].'</td><td>'.$Row['TimeElimination'].'</td></tr>';
|
---|
289 | }
|
---|
290 | $Output .= '</table>';
|
---|
291 | break;
|
---|
292 | case 'SubjectAccount':
|
---|
293 | $Output .= '<strong>Výpis příjmů/výdajů</strong>';
|
---|
294 | $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
|
---|
295 | $Output .= '<tr><th>Datum</th><th>Název</th><th>Hodnota [Kč]</th></tr>';
|
---|
296 | $DbResult = $this->Database->select('FinanceCashFlow', '*', 'Subject='.$_GET['Id']);
|
---|
297 | while($Row = $DbResult->fetch_array())
|
---|
298 | {
|
---|
299 | $Output .= '<tr><td>'.$Row['Time'].'</td><td>'.$Row['Text'].'</td><td>'.$Row['Value'].'</td><td>'.$Row['Bill'].'</td></tr>';
|
---|
300 | }
|
---|
301 | $Output .= '</table><br />';
|
---|
302 |
|
---|
303 | $Output .= '<strong>Výpis závazků/pohledávek</strong>';
|
---|
304 | $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
|
---|
305 | $Output .= '<tr><th>Datum vytvoření</th><th>Datum zaplacení</th><th>Název</th><th>Hodnota [Kč]</th></tr>';
|
---|
306 | $DbResult = $this->Database->select('FinanceClaimsLiabilities', '*', 'Subject='.$_GET['Id']);
|
---|
307 | while($Row = $DbResult->fetch_array())
|
---|
308 | {
|
---|
309 | $Output .= '<tr><td>'.$Row['TimeCreation'].'</td><td>'.$Row['TimePayment'].'</td><td>'.$Row['Text'].'</td><td>'.(-$Row['Value']).'</td><td>'.$Row['Bill'].'</td></tr>';
|
---|
310 | }
|
---|
311 | $Output .= '</table><br />';
|
---|
312 |
|
---|
313 | $Output .= '<strong>Výpis záloh</strong>';
|
---|
314 | $Output .= '<table style="font-size: smaller;" border="1" cellspacing="0" cellpadding="3">';
|
---|
315 | $Output .= '<tr><th>Datum vytvoření</th><th>Datum zaplacení</th><th>Název</th><th>Hodnota [Kč]</th></tr>';
|
---|
316 | $DbResult = $this->Database->select('FinanceAdvances', '*', 'Subject='.$_GET['Id']);
|
---|
317 | while($Row = $DbResult->fetch_array())
|
---|
318 | {
|
---|
319 | $Output .= '<tr><td>'.$Row['TimeCreation'].'</td><td>'.$Row['TimePass'].'</td><td>'.$Row['Direction'].'</td><td>'.($Row['Value']).'</td><td>'.$Row['CashFlowId'].'</td></tr>';
|
---|
320 | }
|
---|
321 | $Output .= '</table>';
|
---|
322 |
|
---|
323 | $DbResult = $this->Database->query('SELECT Id, 0 AS Cash, (SELECT SUM(FinanceClaimsLiabilities.Value) FROM FinanceClaimsLiabilities WHERE FinanceClaimsLiabilities.Subject = Subject.Id AND FinanceClaimsLiabilities.Value > 0) as Claims, (SELECT SUM(FinanceClaimsLiabilities.Value) FROM FinanceClaimsLiabilities WHERE FinanceClaimsLiabilities.Subject = Subject.Id AND FinanceClaimsLiabilities.Value > 0 AND TimePayment IS NULL) as OpenedClaims, (SELECT SUM(FinanceClaimsLiabilities.Value) FROM FinanceClaimsLiabilities WHERE FinanceClaimsLiabilities.Subject = Subject.Id AND FinanceClaimsLiabilities.Value < 0) as Liabilities, (SELECT SUM(FinanceClaimsLiabilities.Value) FROM FinanceClaimsLiabilities WHERE FinanceClaimsLiabilities.Subject = Subject.Id AND FinanceClaimsLiabilities.Value < 0 AND TimePayment IS NULL) as OpenedLiabilities, (SELECT SUM(FinanceCashFlow.Value) FROM FinanceCashFlow WHERE FinanceCashFlow.Subject = Subject.Id AND FinanceCashFlow.Value > 0) as Gains, (SELECT SUM(FinanceCashFlow.Value) FROM FinanceCashFlow WHERE FinanceCashFlow.Subject = Subject.Id AND FinanceCashFlow.Value < 0) as Spends, (SELECT SUM(FinanceAdvances.Value) FROM FinanceAdvances WHERE FinanceAdvances.Subject = Subject.Id AND FinanceAdvances.Direction="In") as AdvancesIn, (SELECT SUM(FinanceAdvances.Value) FROM FinanceAdvances WHERE FinanceAdvances.Subject = Subject.Id AND FinanceAdvances.Direction="Out") as AdvancesOut FROM Subject WHERE Id='.$_GET['Id']);
|
---|
324 | $Row = $DbResult->fetch_array();
|
---|
325 | $Output .= 'Stav placení: '.($Row['AdvancesIn'] - $Row['AdvancesOut'] - $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&year='.$Year.'">Příjmy</a><br />';
|
---|
347 | $Output .= '<a href="?table=Expenses&year='.$Year.'">Výdaje</a><br />';
|
---|
348 | $Output .= '<a href="?table=Claims&year='.$Year.'">Pohledávky</a><br />';
|
---|
349 | $Output .= '<a href="?table=Liabilities&year='.$Year.'">Závazky</a><br />';
|
---|
350 | $Output .= '<a href="?table=Advantages&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 | }
|
---|
378 |
|
---|
379 | $System->AddModule(new FinanceTaxFilingPage());
|
---|
380 | $System->Modules['FinanceTaxFilingPage']->GetOutput();
|
---|
381 |
|
---|
382 | ?>
|
---|