source: trunk/Modules/Finance/Finance.php@ 960

Last change on this file since 960 was 960, checked in by chronos, 15 months ago
File size: 43.9 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/FinanceModels.php');
4include_once(dirname(__FILE__).'/Bill.php');
5include_once(dirname(__FILE__).'/Manage.php');
6include_once(dirname(__FILE__).'/UserState.php');
7include_once(dirname(__FILE__).'/Import.php');
8include_once(dirname(__FILE__).'/Trade.php');
9
10class ModuleFinance extends Module
11{
12 public Finance $Finance;
13 public Bill $Bill;
14
15 function __construct(System $System)
16 {
17 parent::__construct($System);
18 $this->Name = 'Finance';
19 $this->Version = '1.0';
20 $this->Creator = 'Chronos';
21 $this->License = 'GNU/GPLv3';
22 $this->Description = 'Base module for finance management';
23 $this->Dependencies = array(ModuleFile::GetName(), ModuleEmailQueue::GetName(), ModuleSubject::GetName(),
24 ModuleDocument::GetName());
25 $this->Models = array(FinanceBillingPeriod::GetClassName(), FinanceVatType::GetClassName(), FinanceVat::GetClassName(),
26 FinanceGroup::GetClassName(), FinanceOperationGroup::GetClassName(), FinanceOperation::GetClassName(),
27 FinanceInvoiceGroup::GetClassName(), FinanceInvoice::GetClassName(), FinanceInvoiceItem::GetClassName(),
28 Company::GetClassName(), FinanceTreasury::GetClassName(), FinanceTreasuryCheck::GetClassName(),
29 Currency::GetClassName(), FinanceBank::GetClassName(), FinanceBankAccount::GetClassName(), FinanceCharge::GetClassName(),
30 FinanceInvoiceOperationRel::GetClassName());
31
32 $this->Bill = new Bill($this->System);
33 $this->Finance = new Finance($this->System);
34 }
35
36 function DoStart(): void
37 {
38 $this->Finance->MainSubject = $this->System->Config['Finance']['MainSubjectId'];
39 $this->Finance->DirectoryId = $this->System->Config['Finance']['DirectoryId'];
40
41 $this->System->RegisterPage(['finance', 'sprava'], 'PageFinanceManage');
42 $this->System->RegisterPage(['finance', 'platby'], 'PageFinanceUserState');
43 $this->System->RegisterPage(['finance', 'import'], 'PageFinanceImportPayment');
44 $this->System->RegisterPage(['finance', 'zivnost'], 'PageFinanceTaxFiling');
45
46 $this->System->FormManager->RegisterClass('FinanceOperation', array(
47 'Title' => 'Finanční operace',
48 'Table' => 'FinanceOperation',
49 'DefaultSortColumn' => 'Time',
50 'DefaultSortOrder' => 1,
51 'Items' => array(
52 'Group' => array('Type' => 'TFinanceOperationGroup', 'Caption' => 'Skupina', 'Default' => ''),
53 'BillCode' => array('Type' => 'TDocumentLineCode', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true),
54 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
55 'Time' => array('Type' => 'Date', 'Caption' => 'Čas realizace', 'Default' => ''),
56 'Cash' => array('Type' => 'Boolean', 'Caption' => 'Hotově', 'Default' => ''),
57 'Taxable' => array('Type' => 'Boolean', 'Caption' => 'Zdanitelné', 'Default' => ''),
58 'Value' => array('Type' => 'Integer', 'Caption' => 'Částka absolutní', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true),
59 'ValueUser' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
60 'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
61 'Text' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
62 'Network' => array('Type' => 'Boolean', 'Caption' => 'Týkající sítě', 'Default' => ''),
63 'BankAccount' => array('Type' => 'TFinanceBankAccount', 'Caption' => 'Účet', 'Default' => '', 'Null' => true),
64 'Treasury' => array('Type' => 'TFinanceTreasury', 'Caption' => 'Pokladna', 'Default' => '', 'Null' => true),
65 'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
66 'Balance' => array('Type' => 'Integer', 'Caption' => 'Zůstatek', 'Default' => '',
67 'ReadOnly' => true, 'SQL' => '(SELECT SUM(`FinanceOperation2`.`Value`) FROM `FinanceOperation` AS `FinanceOperation2` WHERE `FinanceOperation2`.`Time`<`Time`)'),
68 'InvoiceRel' => array('Type' => 'TFinanceInvoiceOperationRelListOperation', 'Caption' => 'Zaplacené faktury', 'Default' => ''),
69 'InvoiceRelCount' => array('Type' => 'Integer', 'Caption' => 'Faktur',
70 'ReadOnly' => true, 'SQL' => '(SELECT COUNT(`FinanceInvoiceOperationRel`.`Id`) FROM `FinanceInvoiceOperationRel` '.
71 'WHERE `FinanceInvoiceOperationRel`.`Operation`=#Id)'),
72 ),
73 'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
74 'AfterInsert' => array($this, 'AfterInsertFinanceOperation'),
75 'BeforeModify' => array($this, 'BeforeModifyFinanceOperation'),
76 'AfterModify' => array($this, 'BeforeModifyFinanceOperation'),
77 'ItemActions' => array(
78 array('Caption' => 'Přegenerovat doklad', 'URL' => '/finance/sprava/?Operation=RegenerateOperation&i=#RowId'),
79 ),
80 ));
81
82 $this->System->FormManager->RegisterClass('FinanceTreasuryIn', $this->System->FormManager->Classes['FinanceOperation']);
83 $this->System->FormManager->Classes['FinanceTreasuryIn']['Title'] = 'Pokladní příjmy';
84 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Default'] = OPERATION_GROUP_TREASURY_IN;
85 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Hidden'] = true;
86 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Filter'] = true;
87 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 1;
88 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
89 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
90 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['BankAccount']['Hidden'] = true;
91 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Value']['Hidden'] = true;
92
93 $this->System->FormManager->RegisterClass('FinanceTreasuryOut', $this->System->FormManager->Classes['FinanceOperation']);
94 $this->System->FormManager->Classes['FinanceTreasuryOut']['Title'] = 'Pokladní výdeje';
95 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Default'] = OPERATION_GROUP_TREASURY_OUT;
96 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Hidden'] = true;
97 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Filter'] = true;
98 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 1;
99 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
100 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
101 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['BankAccount']['Hidden'] = true;
102 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Value']['Hidden'] = true;
103
104 $this->System->FormManager->RegisterClass('FinanceAccountIn', $this->System->FormManager->Classes['FinanceOperation']);
105 $this->System->FormManager->Classes['FinanceAccountIn']['Title'] = 'Příjmy na účet';
106 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Default'] = OPERATION_GROUP_ACCOUNT_IN;
107 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Hidden'] = true;
108 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Filter'] = true;
109 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 0;
110 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
111 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
112 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Treasury']['Hidden'] = true;
113 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Value']['Hidden'] = true;
114
115 $this->System->FormManager->RegisterClass('FinanceAccountOut', $this->System->FormManager->Classes['FinanceOperation']);
116 $this->System->FormManager->Classes['FinanceAccountOut']['Title'] = 'Výdeje z účtu';
117 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Default'] = OPERATION_GROUP_ACCOUNT_OUT;
118 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Hidden'] = true;
119 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Filter'] = true;
120 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 0;
121 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
122 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
123 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Treasury']['Hidden'] = true;
124 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Value']['Hidden'] = true;
125
126 $this->System->FormManager->RegisterClass('FinanceOperationGroup', array(
127 'Title' => 'Skupina finančních operací',
128 'Table' => 'FinanceOperationGroup',
129 'Items' => array(
130 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
131 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
132 'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
133 'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
134 'Items' => array('Type' => 'TFinanceOperationListGroup', 'Caption' => 'Operace', 'Default' => ''),
135 ),
136 ));
137 $this->System->FormManager->RegisterClass('FinanceBillingPeriod', array(
138 'Title' => 'Platební období',
139 'Table' => 'FinanceBillingPeriod',
140 'Items' => array(
141 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
142 'MonthCount' => array('Type' => 'Integer', 'Caption' => 'Počet měsíců', 'Default' => '0'),
143 'Customers' => array('Type' => 'TCustomerBillingPeriod', 'Caption' => 'Zákazníci')
144 ),
145 ));
146 $this->System->FormManager->RegisterFormType('TFinanceOperationGroup', array(
147 'Type' => 'Reference',
148 'Table' => 'FinanceOperationGroup',
149 'Id' => 'Id',
150 'Name' => 'Name',
151 'Filter' => '1',
152 ));
153 $this->System->FormManager->RegisterFormType('TFinanceValueSign', array(
154 'Type' => 'Enumeration',
155 'States' => array(-1 => 'Mínus', 1 => 'Plus'),
156 ));
157 $this->System->FormManager->RegisterFormType('TFinanceDirection', array(
158 'Type' => 'Enumeration',
159 'States' => array(0 => 'Příjem', 1 => 'Výdej'),
160 ));
161 $this->System->FormManager->RegisterClass('FinanceInvoice', array(
162 'Title' => 'Faktury',
163 'Table' => 'FinanceInvoice',
164 'DefaultSortColumn' => 'Time',
165 'DefaultSortOrder' => 1,
166 'Items' => array(
167 'Group' => array('Type' => 'TFinanceInvoiceGroup', 'Caption' => 'Skupina', 'Default' => ''),
168 'BillCode' => array('Type' => 'TDocumentLineCode', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true),
169 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
170 'Time' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
171 'TimeDue' => array('Type' => 'Date', 'Caption' => 'Čas splatnosti', 'Default' => ''),
172 'TimePayment' => array('Type' => 'Date', 'Caption' => 'Čas zaplacení', 'Default' => '', 'Null' => true),
173 'Value' => array('Type' => 'Integer', 'Caption' => 'Částka absolutní', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true),
174 'ValueUser' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
175 'SQL' => 'SELECT ROUND(SUM(`Price`*`Quantity`), '.$this->System->Config['Finance']['Rounding'].') FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice`=#Id'),
176 'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
177 'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
178 'PeriodFrom' => array('Type' => 'Date', 'Caption' => 'Období od', 'Default' => '', 'Null' => true),
179 'PeriodTo' => array('Type' => 'Date', 'Caption' => 'Období do', 'Default' => '', 'Null' => true),
180 'Cash' => array('Type' => 'Boolean', 'Caption' => 'Platit hotově', 'Default' => ''),
181 'VisibleToUser' => array('Type' => 'Boolean', 'Caption' => 'Viditelné uživatelům', 'Default' => '1'),
182 'Items' => array('Type' => 'TFinanceInvoiceItemListInvoice', 'Caption' => 'Položky', 'Default' => ''),
183 'StornoBy' => array('Type' => 'TFinanceInvoiceStornoListBy', 'Caption' => 'Původní doklady', 'Default' => ''),
184 'StornoOf' => array('Type' => 'TFinanceInvoiceStornoListOf', 'Caption' => 'Storno doklady', 'Default' => ''),
185 'OperationRel' => array('Type' => 'TFinanceInvoiceOperationRelListInvoice', 'Caption' => 'Platba', 'Default' => ''),
186 'OperationRelCount' => array('Type' => 'Integer', 'Caption' => 'Plateb',
187 'ReadOnly' => true, 'SQL' => '(SELECT COUNT(`FinanceInvoiceOperationRel`.`Id`) FROM `FinanceInvoiceOperationRel` '.
188 'WHERE `FinanceInvoiceOperationRel`.`Invoice`=#Id)'),
189 ),
190 'BeforeInsert' => array($this, 'BeforeInsertFinanceInvoice'),
191 'AfterInsert' => array($this, 'AfterInsertFinanceInvoice'),
192 'BeforeModify' => array($this, 'BeforeModifyFinanceInvoice'),
193 'AfterModify' => array($this, 'BeforeModifyFinanceInvoice'),
194 'ItemActions' => array(
195 array('Caption' => 'Přegenerovat doklad', 'URL' => '/finance/sprava/?Operation=RegenerateInvoice&i=#RowId'),
196 ),
197 ));
198 $this->System->FormManager->RegisterClass('FinanceInvoiceIn', $this->System->FormManager->Classes['FinanceInvoice']);
199 $this->System->FormManager->Classes['FinanceInvoiceIn']['Title'] = 'Přijaté faktury';
200 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Default'] = INVOICE_GROUP_IN;
201 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Hidden'] = true;
202 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Filter'] = true;
203 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Value']['Hidden'] = true;
204
205 $this->System->FormManager->RegisterClass('FinanceInvoiceOut', $this->System->FormManager->Classes['FinanceInvoice']);
206 $this->System->FormManager->Classes['FinanceInvoiceOut']['Title'] = 'Vydané faktury';
207 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Default'] = INVOICE_GROUP_OUT;
208 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Hidden'] = true;
209 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Filter'] = true;
210 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Value']['Hidden'] = true;
211
212 $this->System->FormManager->RegisterClass('FinanceInvoiceGroup', array(
213 'Title' => 'Skupina faktur',
214 'Table' => 'FinanceInvoiceGroup',
215 'Items' => array(
216 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
217 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
218 'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
219 'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
220 'Items' => array('Type' => 'TFinanceInvoiceListGroup', 'Caption' => 'Faktury', 'Default' => ''),
221 ),
222 ));
223
224 $this->System->FormManager->RegisterClass('FinanceInvoiceStorno', array(
225 'Title' => 'Storno faktur',
226 'Table' => 'FinanceInvoiceStorno',
227 'Items' => array(
228 'StornoBy' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Storno doklad', 'Default' => ''),
229 'StornoOf' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Původní doklad', 'Default' => ''),
230 ),
231 ));
232 $this->System->FormManager->RegisterFormType('TFinanceInvoiceGroup', array(
233 'Type' => 'Reference',
234 'Table' => 'FinanceInvoiceGroup',
235 'Id' => 'Id',
236 'Name' => 'Name',
237 'Filter' => '1',
238 ));
239
240 $this->System->FormManager->RegisterClass('Company', array(
241 'Title' => 'Firma',
242 'Table' => 'Company',
243 'Items' => array(
244 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
245 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => '0'),
246 ),
247 ));
248 $this->System->FormManager->RegisterClass('FinanceInvoiceItem', array(
249 'Title' => 'Položka faktury',
250 'Table' => 'FinanceInvoiceItem',
251 'Items' => array(
252 'FinanceInvoice' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Faktura', 'Default' => '0'),
253 'Description' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => 'Položka'),
254 'Price' => array('Type' => 'Float', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
255 'Quantity' => array('Type' => 'Float', 'Caption' => 'Množství', 'Default' => '1'),
256 'VAT' => array('Type' => 'Integer', 'Caption' => 'Daň', 'Default' => '21', 'Suffix' => '%'),
257 'Total' => array('Type' => 'Integer', 'Caption' => 'Celkem', 'Default' => '', 'Suffix' => 'Kč',
258 'ReadOnly' => true, 'SQL' => 'ROUND(`Price` * `Quantity`, '.$this->System->Config['Finance']['Rounding'].')'),
259 ),
260 'AfterInsert' => array($this, 'AfterInsertFinanceInvoiceItem'),
261 'AfterModify' => array($this, 'AfterModifyFinanceInvoiceItem'),
262 'AfterDelete' => array($this, 'AfterModifyFinanceInvoiceItem'),
263 ));
264 $this->System->FormManager->RegisterClass('FinanceTreasury', array(
265 'Title' => 'Pokladny',
266 'Table' => 'FinanceTreasury',
267 'DefaultSortColumn' => 'Name',
268 'Items' => array(
269 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
270 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
271 'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
272 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'IFNULL(ROUND((SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
273 'WHERE `FinanceOperation`.`Treasury`=#Id), '.$this->System->Config['Finance']['Rounding'].'), 0)'),
274 'Operations' => array('Type' => 'TFinanceOperationListTreasury', 'Caption' => 'Operace', 'Default' => ''),
275 'Check' => array('Type' => 'TFinanceTreasuryCheckListTreasury', 'Caption' => 'Kontrola', 'Default' => ''),
276 ),
277 ));
278 $this->System->FormManager->RegisterClass('FinanceTreasuryCheck', array(
279 'Title' => 'Kontrola pokladen',
280 'Table' => 'FinanceTreasuryCheck',
281 'DefaultSortColumn' => 'Time',
282 'DefaultSortOrder' => 1,
283 'Items' => array(
284 'Treasury' => array('Type' => 'TFinanceTreasury', 'Caption' => 'Pokladna', 'Default' => ''),
285 'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''),
286 'Value1' => array('Type' => 'Integer', 'Caption' => 'Hodnota 1', 'Default' => '0', 'Suffix' => 'ks'),
287 'Value2' => array('Type' => 'Integer', 'Caption' => 'Hodnota 2', 'Default' => '0', 'Suffix' => 'ks'),
288 'Value5' => array('Type' => 'Integer', 'Caption' => 'Hodnota 5', 'Default' => '0', 'Suffix' => 'ks'),
289 'Value10' => array('Type' => 'Integer', 'Caption' => 'Hodnota 10', 'Default' => '0', 'Suffix' => 'ks'),
290 'Value20' => array('Type' => 'Integer', 'Caption' => 'Hodnota 20', 'Default' => '0', 'Suffix' => 'ks'),
291 'Value50' => array('Type' => 'Integer', 'Caption' => 'Hodnota 50', 'Default' => '0', 'Suffix' => 'ks'),
292 'Value100' => array('Type' => 'Integer', 'Caption' => 'Hodnota 100', 'Default' => '0', 'Suffix' => 'ks'),
293 'Value200' => array('Type' => 'Integer', 'Caption' => 'Hodnota 200', 'Default' => '0', 'Suffix' => 'ks'),
294 'Value500' => array('Type' => 'Integer', 'Caption' => 'Hodnota 500', 'Default' => '0', 'Suffix' => 'ks'),
295 'Value1000' => array('Type' => 'Integer', 'Caption' => 'Hodnota 1000', 'Default' => '0', 'Suffix' => 'ks'),
296 'Value2000' => array('Type' => 'Integer', 'Caption' => 'Hodnota 2000', 'Default' => '0', 'Suffix' => 'ks'),
297 'Value5000' => array('Type' => 'Integer', 'Caption' => 'Hodnota 5000', 'Default' => '0', 'Suffix' => 'ks'),
298 'Sum' => array('Type' => 'Integer', 'Caption' => 'Součet', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
299 'SQL' => '(`Value1` * 1 + `Value2` * 2 + `Value5` * 5 + `Value10` * 10 + '.
300 '`Value20` * 20 + `Value50` * 50 + `Value100` * 100 + `Value200` * 200 + '.
301 '`Value500` * 500 + `Value1000` * 1000 + `Value2000` * 2000 + `Value5000` * 5000)'),
302 ),
303 ));
304 $this->System->FormManager->RegisterFormType('TCustomerBillingPeriod', array(
305 'Type' => 'ManyToOne',
306 'Table' => 'Member',
307 'Id' => 'Id',
308 'Ref' => 'BillingPeriod',
309 'Filter' => '1',
310 ));
311 $this->System->FormManager->RegisterFormType('TFinanceTreasuryCheckListTreasury', array(
312 'Type' => 'ManyToOne',
313 'Table' => 'FinanceTreasuryCheck',
314 'Id' => 'Id',
315 'Ref' => 'Treasury',
316 'Filter' => '1',
317 ));
318 $this->System->FormManager->RegisterFormType('TFinanceTreasury', array(
319 'Type' => 'Reference',
320 'Table' => 'FinanceTreasury',
321 'Id' => 'Id',
322 'Name' => 'Name',
323 'Filter' => '1',
324 ));
325 $this->System->FormManager->RegisterClass('FinanceBankAccount', array(
326 'Title' => 'Účty',
327 'Table' => 'FinanceBankAccount',
328 'DefaultSortColumn' => 'Comment',
329 'Items' => array(
330 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Vlastník', 'Default' => ''),
331 'Comment' => array('Type' => 'String', 'Caption' => 'Komentář', 'Default' => ''),
332 'Number' => array('Type' => 'String', 'Caption' => 'Číslo', 'Default' => ''),
333 'Bank' => array('Type' => 'TFinanceBank', 'Caption' => 'Banka', 'Default' => ''),
334 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
335 'TimeEnd' => array('Type' => 'Date', 'Caption' => 'Čas zrušení', 'Default' => '', 'Null' => true),
336 'Currency' => array('Type' => 'TCurrency', 'Caption' => 'Měna', 'Default' => ''),
337 'LoginName' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno / token', 'Default' => '', 'NotInList' => true),
338 'LoginPassword' => array('Type' => 'String', 'Caption' => 'Přihlašovací heslo', 'Default' => '', 'NotInList' => true),
339 'Operations' => array('Type' => 'TFinanceOperationListAccount', 'Caption' => 'Operace', 'Default' => ''),
340 'Use' => array('Type' => 'Boolean', 'Caption' => 'Používat', 'Default' => '0'),
341 'LastImportDate' => array('Type' => 'Date', 'Caption' => 'Datum posledního importu', 'Default' => ''),
342 'LastImportId' => array('Type' => 'String', 'Caption' => 'Id posledního importu', 'Default' => ''),
343 'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
344 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
345 'WHERE `FinanceOperation`.`BankAccount`=#Id)'),
346 'AutoImport' => array('Type' => 'Boolean', 'Caption' => 'Automaticky stahovat z banky', 'Default' => ''),
347 ),
348 'ItemActions' => array(
349 array('Caption' => 'Import plateb z banky', 'URL' => '/finance/import-api/?i=#RowId'),
350 array('Caption' => 'Import plateb ze souboru', 'URL' => '/finance/import-soubor/?i=#RowId'),
351 ),
352 ));
353 $this->System->FormManager->RegisterClass('FinanceBankAccountReport', array(
354 'Title' => 'Roční výkaz operací',
355 'Table' => 'FinanceBankAccountReport',
356 'SQL' => 'SELECT Id, DateEnd, DateStart FROM FinanceYear',
357 'DefaultSortColumn' => 'Id',
358 'Items' => array(
359 'Id' => array('Type' => 'TFinanceYear', 'Caption' => 'Rok', 'Default' => '',
360 'ReadOnly' => true),
361 //'Account' => array('Type' => 'TFinanceBankAccount', 'Caption' => 'Bankovní účet', 'Default' => '',
362 // 'ReadOnly' => true),
363 'StartBalance' => array('Type' => 'Integer', 'Caption' => 'Starý zůstatek', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
364 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
365 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
366 'WHERE (`FinanceOperation`.`Time` <= `DateStart`) AND (`FinanceOperation`.`BankAccount` = 2))'),
367 'EndBalance' => array('Type' => 'Integer', 'Caption' => 'Nový zůstatek', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
368 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
369 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
370 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) AND (`FinanceOperation`.`BankAccount` = 2))'),
371 'Change' => array('Type' => 'Integer', 'Caption' => 'Změna', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
372 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
373 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
374 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
375 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`BankAccount` = 2))'),
376 ),
377 //'AfterInsert' => array($this, 'AfterInsertFinanceYear'),
378 ));
379 $this->System->FormManager->RegisterFormType('TFinanceBankAccount', array(
380 'Type' => 'Reference',
381 'Table' => 'FinanceBankAccount',
382 'Id' => 'Id',
383 'Name' => 'Comment',
384 'Filter' => '1',
385 ));
386 $this->System->FormManager->RegisterClass('FinanceBank', array(
387 'Title' => 'Banky',
388 'Table' => 'FinanceBank',
389 'Items' => array(
390 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
391 'Code' => array('Type' => 'String', 'Caption' => 'Český kód', 'Default' => ''),
392 'BIC' => array('Type' => 'String', 'Caption' => 'Kód BIC', 'Default' => ''),
393 'Country' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => ''),
394 ),
395 ));
396 $this->System->FormManager->RegisterFormType('TFinanceBank', array(
397 'Type' => 'Reference',
398 'Table' => 'FinanceBank',
399 'Id' => 'Id',
400 'Name' => 'CONCAT(Name, " (", Code, ")")',
401 'Filter' => '1',
402 ));
403 $this->System->FormManager->RegisterClass('Currency', array(
404 'Title' => 'Měny',
405 'Table' => 'Currency',
406 'Items' => array(
407 'Code' => array('Type' => 'String', 'Caption' => 'Kód', 'Default' => ''),
408 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
409 'Symbol' => array('Type' => 'String', 'Caption' => 'Symbol', 'Default' => ''),
410 ),
411 ));
412 $this->System->FormManager->RegisterClass('FinanceCharge', array(
413 'Title' => 'Parametry účtování',
414 'Table' => 'FinanceCharge',
415 'Items' => array(
416 'Internet' => array('Type' => 'Integer', 'Caption' => 'Platba Internetu', 'Default' => '0', 'Suffix' => 'Kč'),
417 'InternetSpeed' => array('Type' => 'Integer', 'Caption' => 'Rychlost Internetu', 'Default' => '0', 'Suffix' => 'Mbit/s'),
418 'InternetSpeedReserve' => array('Type' => 'Integer', 'Caption' => 'Rezerva rychlosti', 'Default' => '0', 'Suffix' => 'Mbit/s'),
419 'AdministrationPerUser' => array('Type' => 'Integer', 'Caption' => 'Správa za uživatele', 'Default' => '0', 'Suffix' => 'Kč'),
420 'kWh' => array('Type' => 'Integer', 'Caption' => 'Cena kWh', 'Default' => '0', 'Suffix' => 'Kč'),
421 'BaseSpeedElement' => array('Type' => 'Integer', 'Caption' => 'Základní díl rychlosti', 'Default' => '0', 'Suffix' => 'Mbit/s'),
422 'BaseTariffPrice' => array('Type' => 'Integer', 'Caption' => 'Základní cena tarifu', 'Default' => '0', 'Suffix' => 'Kč'),
423 'TopTariffPrice' => array('Type' => 'Integer', 'Caption' => 'Nejvyšší cena tarifu', 'Default' => '0', 'Suffix' => 'Kč'),
424 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true, 'NotInList' => true),
425 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true),
426 'ChangeReplaceId' => array('Type' => 'TFinanceCharge', 'Caption' => 'Změna - položka', 'Default' => '0', 'Null' => true, 'NotInList' => true),
427 ),
428 ));
429 $this->System->FormManager->RegisterClass('FinanceVAT', array(
430 'Title' => 'Sazby DPH',
431 'Table' => 'FinanceVAT',
432 'Items' => array(
433 'Type' => array('Type' => 'TFinanceVATType', 'Caption' => 'Typ', 'Default' => ''),
434 'ValidFrom' => array('Type' => 'Date', 'Caption' => 'Platnost od', 'Default' => ''),
435 'ValidTo' => array('Type' => 'Date', 'Caption' => 'Platnost do', 'Default' => '', 'Null' => true),
436 'Value' => array('Type' => 'Integer', 'Caption' => 'Hodnota', 'Default' => '', 'Suffix' => '%'),
437 ),
438 ));
439 $this->System->FormManager->RegisterClass('FinanceVATType', array(
440 'Title' => 'Sazby DPH',
441 'Table' => 'FinanceVATType',
442 'Items' => array(
443 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
444 ),
445 ));
446 $this->System->FormManager->RegisterFormType('TFinanceVAT', array(
447 'Type' => 'Reference',
448 'Table' => 'FinanceVAT',
449 'Id' => 'Id',
450 'Name' => 'Name',
451 'Filter' => '1',
452 ));
453 $this->System->FormManager->RegisterFormType('TFinanceVATType', array(
454 'Type' => 'Reference',
455 'Table' => 'FinanceVATType',
456 'Id' => 'Id',
457 'Name' => 'Name',
458 'Filter' => '1',
459 ));
460 $this->System->FormManager->RegisterFormType('TBankAccount', array(
461 'Type' => 'Reference',
462 'Table' => 'FinanceBankAccount',
463 'Id' => 'Id',
464 'Name' => 'CONCAT(`Comment`, " (", `Number`, "/", '.
465 '(SELECT `FinanceBank`.`Code` FROM `FinanceBank` WHERE `FinanceBank`.`Id`=`FinanceBankAccount`.`Bank`), ")")',
466 'Filter' => '1',
467 ));
468 $this->System->FormManager->RegisterClass('FinanceYearReport', array(
469 'Title' => 'Roční výkaz',
470 'Table' => 'FinanceYearReport',
471 'SQL' => 'SELECT Id, DateEnd, DateStart FROM FinanceYear',
472 'DefaultSortColumn' => 'Id',
473 'DefaultSortOrder' => 1,
474 'Items' => array(
475 'Id' => array('Type' => 'TFinanceYear', 'Caption' => 'Rok', 'Default' => '',
476 'ReadOnly' => true),
477 'Income' => array('Type' => 'Integer', 'Caption' => 'Evidenční příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
478 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
479 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
480 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
481 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
482 'Spending' => array('Type' => 'Integer', 'Caption' => 'Evidenční výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
483 'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
484 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
485 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
486 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
487 'OperationBalance' => array('Type' => 'Integer', 'Caption' => 'Evidenční zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
488 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
489 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
490 'AND (`FinanceOperation`.`Time` >= `DateStart`))'),
491 'RealIncome' => array('Type' => 'Integer', 'Caption' => 'Skutečné příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
492 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
493 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
494 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) AND (`FinanceOperation`.`Subject` != '.$this->Finance->MainSubject.')'.
495 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
496 'RealSpending' => array('Type' => 'Integer', 'Caption' => 'Skutečné výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
497 'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
498 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
499 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) AND (`FinanceOperation`.`Subject` != '.$this->Finance->MainSubject.')'.
500 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
501 'RealOperationBalance' => array('Type' => 'Integer', 'Caption' => 'Skutečný zisk', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
502 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
503 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) AND (`FinanceOperation`.`Subject` != '.$this->Finance->MainSubject.')'.
504 'AND (`FinanceOperation`.`Time` >= `DateStart`))'),
505 'TaxIncome' => array('Type' => 'Integer', 'Caption' => 'Daňové příjmy', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
506 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
507 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
508 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
509 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperationGroup`.`ValueSign` = 1))'),
510 'TaxSpending' => array('Type' => 'Integer', 'Caption' => 'Daňové výdaje', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
511 'SQL' => '(SELECT -ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
512 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '.
513 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
514 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1) AND (`FinanceOperationGroup`.`ValueSign` = -1))'),
515 'TaxBase' => array('Type' => 'Integer', 'Caption' => 'Základ daně', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
516 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '.
517 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '.
518 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`Taxable` = 1))'),
519 'Claims' => array('Type' => 'Integer', 'Caption' => 'Pohledávky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
520 'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` '.
521 'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
522 'WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
523 'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoiceGroup`.`ValueSign` = 1))'),
524 'Liabilities' => array('Type' => 'Integer', 'Caption' => 'Závazky', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
525 'SQL' => '(SELECT -ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` '.
526 'LEFT JOIN `FinanceInvoiceGroup` ON `FinanceInvoiceGroup`.`Id`=`FinanceInvoice`.`Group` '.
527 'WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
528 'AND (`FinanceInvoice`.`Time` >= `DateStart`) AND (`FinanceInvoiceGroup`.`ValueSign` = -1))'),
529 'InvoiceBalance' => array('Type' => 'Integer', 'Caption' => 'Fakturační rozdíl', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
530 'SQL' => '(SELECT ROUND(SUM(`FinanceInvoice`.`Value`)) FROM `FinanceInvoice` WHERE (`FinanceInvoice`.`Time` <= `DateEnd`) '.
531 'AND (`FinanceInvoice`.`Time` >= `DateStart`))'),
532 'IncomeList' => array('Type' => 'TIncomeList', 'Caption' => 'Příjmy', 'Default' => '0'),
533 'SpendingList' => array('Type' => 'TSpendingList', 'Caption' => 'Výdaje', 'Default' => '0'),
534 'TaxIncomeList' => array('Type' => 'TTaxIncomeList', 'Caption' => 'Daňové příjmy', 'Default' => '0'),
535 'TaxSpendingList' => array('Type' => 'TTaxSpendingList', 'Caption' => 'Daňové výdaje', 'Default' => '0'),
536 'ClaimsList' => array('Type' => 'TClaimsList', 'Caption' => 'Pohledávky', 'Default' => '0'),
537 'LiabilitiesList' => array('Type' => 'TLiabilitiesList', 'Caption' => 'Závazky', 'Default' => '0'),
538 ),
539 //'AfterInsert' => array($this, 'AfterInsertFinanceYear'),
540 ));
541 $this->System->FormManager->RegisterFormType('TClaimsList', array(
542 'Type' => 'ManyToOne',
543 'Table' => 'FinanceInvoice',
544 'Id' => 'Id',
545 'Ref' => '',
546 'Filter' => '(`TX`.`Time` <= (SELECT `FinanceYear`.`DateEnd` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
547 'AND (`TX`.`Time` >= (SELECT `FinanceYear`.`DateStart` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
548 'AND (SIGN(`TX`.`Value`) > 0)',
549 ));
550 $this->System->FormManager->RegisterFormType('TLiabilitiesList', array(
551 'Type' => 'ManyToOne',
552 'Table' => 'FinanceInvoice',
553 'Id' => 'Id',
554 'Ref' => '',
555 'Filter' => '(`TX`.`Time` <= (SELECT `FinanceYear`.`DateEnd` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
556 'AND (`TX`.`Time` >= (SELECT `FinanceYear`.`DateStart` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
557 'AND (SIGN(`TX`.`Value`) < 0)',
558 ));
559 $this->System->FormManager->RegisterFormType('TSpendingList', array(
560 'Type' => 'ManyToOne',
561 'Table' => 'FinanceOperation',
562 'Id' => 'Id',
563 'Ref' => '',
564 'Filter' => '(`TX`.`Time` <= (SELECT `FinanceYear`.`DateEnd` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
565 'AND (`TX`.`Time` >= (SELECT `FinanceYear`.`DateStart` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
566 'AND (SIGN(`TX`.`Value`) < 0)',
567 ));
568 $this->System->FormManager->RegisterFormType('TIncomeList', array(
569 'Type' => 'ManyToOne',
570 'Table' => 'FinanceOperation',
571 'Id' => 'Id',
572 'Ref' => '',
573 'Filter' => '(`TX`.`Time` <= (SELECT `FinanceYear`.`DateEnd` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
574 'AND (`TX`.`Time` >= (SELECT `FinanceYear`.`DateStart` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
575 'AND (SIGN(`TX`.`Value`) > 0)',
576 ));
577 $this->System->FormManager->RegisterFormType('TTaxSpendingList', array(
578 'Type' => 'ManyToOne',
579 'Table' => 'FinanceOperation',
580 'Id' => 'Id',
581 'Ref' => '',
582 'Filter' => '(`TX`.`Time` <= (SELECT `FinanceYear`.`DateEnd` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
583 'AND (`TX`.`Time` >= (SELECT `FinanceYear`.`DateStart` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
584 'AND (SIGN(`TX`.`Value`) < 0) AND (`TX`.`Taxable` = 1)',
585 ));
586 $this->System->FormManager->RegisterFormType('TTaxIncomeList', array(
587 'Type' => 'ManyToOne',
588 'Table' => 'FinanceOperation',
589 'Id' => 'Id',
590 'Ref' => '',
591 'Filter' => '(`TX`.`Time` <= (SELECT `FinanceYear`.`DateEnd` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
592 'AND (`TX`.`Time` >= (SELECT `FinanceYear`.`DateStart` FROM `FinanceYear` WHERE `FinanceYear`.`Id`=#Id)) '.
593 'AND (SIGN(`TX`.`Value`) > 0) AND (`TX`.`Taxable` = 1)',
594 ));
595 $this->System->FormManager->RegisterClass('FinanceInvoiceOperationRel', array(
596 'Title' => 'Zaplacení faktůr',
597 'Table' => 'FinanceInvoiceOperationRel',
598 'Items' => array(
599 'Invoice' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Faktura', 'Default' => ''),
600 'Operation' => array('Type' => 'TFinanceOperation', 'Caption' => 'Platba', 'Default' => ''),
601 ),
602 ));
603
604 ModuleIS::Cast($this->System->GetModule('IS'))->RegisterDashboardItem('Finance', array($this, 'ShowDashboardItem'));
605 }
606
607 function ShowDashboardItem(): string
608 {
609 $DbResult = $this->Database->select('FinanceOperation', 'ROUND(SUM(`Value`))', '1');
610 $DbRow = $DbResult->fetch_row();
611 $Output = 'Stav placení: '.$DbRow['0'].' Kč<br/>';
612 return $Output;
613 }
614
615 function BeforeInsertFinanceOperation(Form $Form): array
616 {
617 if (array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
618 else $Year = date("Y", $Form->Values['ValidFrom']);
619 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
620 $Form->Values['BillCode'] = ModuleDocument::Cast($this->System->GetModule('Document'))->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);
621 return $Form->Values;
622 }
623
624 function AfterInsertFinanceOperation(Form $Form, string $Id): array
625 {
626 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
627 $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
628 ($Form->Values['ValueUser'] * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
629 return $Form->Values;
630 }
631
632 function BeforeModifyFinanceOperation(Form $Form, string $Id): array
633 {
634 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
635 $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
636 ($Form->Values['ValueUser'] * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
637 return $Form->Values;
638 }
639
640 function BeforeInsertFinanceInvoice(Form $Form): array
641 {
642 // Get new DocumentLineCode by selected invoice Group
643 if (array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
644 else $Year = date("Y", $Form->Values['ValidFrom']);
645 $Group = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
646 $Form->Values['BillCode'] = ModuleDocument::Cast($this->System->GetModule('Document'))->GetNextDocumentLineNumberId($Group['DocumentLine'], $Year);
647 return $Form->Values;
648 }
649
650 function AfterInsertFinanceInvoice(Form $Form, string $Id): array
651 {
652 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
653 $DbResult = $this->Database->query(str_replace('#Id', $Id, $Form->Definition['Items']['ValueUser']['SQL']));
654 $DbRow = $DbResult->fetch_row();
655 $Sum = $DbRow[0];
656
657 $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
658 ($Sum * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
659 return $Form->Values;
660 }
661
662 function BeforeModifyFinanceInvoice(Form $Form, string $Id): array
663 {
664 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
665 $DbResult = $this->Database->query(str_replace('#Id', $Id, $Form->Definition['Items']['ValueUser']['SQL']));
666 $DbRow = $DbResult->fetch_row();
667 $Sum = $DbRow[0];
668 $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
669 ($Sum * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
670 return $Form->Values;
671 }
672
673 function AfterInsertFinanceInvoiceItem(Form $Form, string $Id): array
674 {
675 $ParentForm = new Form($this->System->FormManager);
676 $ParentForm->SetClass('FinanceInvoice');
677 $ParentForm->LoadValuesFromDatabase($Form->Values['FinanceInvoice']);
678 $this->AfterInsertFinanceInvoice($ParentForm, $Form->Values['FinanceInvoice']);
679 return $Form->Values;
680 }
681
682 function AfterModifyFinanceInvoiceItem(Form $Form, string $Id): array
683 {
684 $ParentForm = new Form($this->System->FormManager);
685 $ParentForm->SetClass('FinanceInvoice');
686 $ParentForm->LoadValuesFromDatabase($Form->Values['FinanceInvoice']);
687 $this->BeforeModifyFinanceInvoice($ParentForm, $Form->Values['FinanceInvoice']);
688 return $Form->Values;
689 }
690
691 static function Cast(Module $Module): ModuleFinance
692 {
693 if ($Module instanceof ModuleFinance)
694 {
695 return $Module;
696 }
697 throw new Exception('Expected ModuleFinance type but '.gettype($Module));
698 }
699}
Note: See TracBrowser for help on using the repository browser.