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

Last change on this file since 724 was 724, checked in by chronos, 10 years ago
  • Removed: Do not need preload tariffs anymore. They were replaced by more generalized services.
File size: 27.6 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Bill.php');
4include_once(dirname(__FILE__).'/Manage.php');
5include_once(dirname(__FILE__).'/UserState.php');
6include_once(dirname(__FILE__).'/Import.php');
7include_once(dirname(__FILE__).'/Zivnost.php');
8
9// TODO: Move constants to Finance module configuration
10define('TARIFF_FREE', 7);
11define('INVOICE_DUE_DAYS', 15);
12define('DOC_LINE_TREASURY_IN', 1);
13define('DOC_LINE_TREASURY_OUT', 2);
14define('DOC_LINE_ACCOUNT_IN', 3);
15define('DOC_LINE_ACCOUNT_OUT', 4);
16define('DOC_LINE_INVOICE_IN', 5);
17define('DOC_LINE_INVOICE_OUT', 6);
18define('VAT_TYPE_BASE', 2);
19
20
21class Finance extends Model
22{
23 var $kWh;
24 var $Internet;
25 var $Sprava;
26 var $DatumOdecteni;
27 var $InternetUsers;
28 var $SpravaUsers;
29 var $MaxSpeed;
30 var $RealMaxSpeed;
31 var $SpeedReserve;
32 var $BaseSpeedElement;
33 var $BaseTariffPrice;
34 var $TopTariffPrice;
35 var $TotalPaid;
36 var $TotalInternetPaid;
37 var $MainSubject;
38 var $BillingPeriods;
39 var $DirectoryId;
40
41 function LoadMonthParameters($Period = 1) // 0 - now, 1 - next month
42 {
43 $DbResult = $this->Database->query('SELECT * FROM `FinanceBillingPeriod`');
44 while($BillingPeriod = $DbResult->fetch_assoc())
45 $this->BillingPeriods[$BillingPeriod['Id']] = $BillingPeriod;
46
47 // Period parameter is not used as it have to be determined from item replacement
48 $DbResult = $this->Database->query('SELECT * FROM `FinanceCharge` WHERE `ReplaceId` IS NULL LIMIT 1');
49 $Row = $DbResult->fetch_array();
50 $this->kWh = $Row['kWh'];
51 $this->Internet = $Row['Internet'];
52 $this->Sprava = $Row['AdministrationPerUser'];
53 $this->RealMaxSpeed = $Row['InternetSpeed'];
54 $this->SpeedReserve = $Row['InternetSpeedReserve'];
55 $this->BaseSpeedElement = $Row['BaseSpeedElement'];
56 $this->MaxSpeed = $this->RealMaxSpeed - $this->SpeedReserve;
57 $this->TopTariffPrice = $Row['TopTariffPrice'];
58 $this->BaseTariffPrice = $Row['BaseTariffPrice'];
59
60 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member`');
61 $Row = $DbResult->fetch_row();
62 $this->InternetUsers = $Row[0];
63 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member` WHERE (`Blocked`=0) AND (`BillingPeriod` > 1)');
64 $Row = $DbResult->fetch_row();
65 $this->PayingUsers = $Row[0];
66
67 $this->SpravaUsers = $this->PayingUsers;
68
69 $DbResult = $this->Database->query('SELECT SUM(`MemberPayment`.`MonthlyInternet`) AS `MonthlyInternet`, '.
70 'SUM(`MemberPayment`.`MonthlyTotal`) AS `MonthlyTotal` '.
71 'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` WHERE `Member`.`Blocked`=0');
72 $Row = $DbResult->fetch_assoc();
73 $this->TotalInternetPaid = $Row['MonthlyInternet'];
74 $this->TotalPaid = $Row['MonthlyTotal'];
75 }
76
77 function W2Kc($Spotreba)
78 {
79 return(round($Spotreba * 0.72 * $this->kWh));
80 }
81
82 function GetNextDocumentLineNumber($Id, $FinanceYear = 0)
83 {
84 if($FinanceYear == 0)
85 {
86 // Get latest year
87 $DbResult = $this->Database->select('FinanceYear', '*', '1 ORDER BY `Year` DESC LIMIT 1');
88 } else $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$FinanceYear);
89 if($DbResult->num_rows == 0) throw new Exception('Rok '.$FinanceYear.' nenalezen');
90 $FinanceYear = $DbResult->fetch_assoc();
91 if($FinanceYear['Closed'] == 1) throw new Exception('Rok '.$FinanceYear['Year'].' je již uzavřen. Nelze do něj přidávat položky.');
92
93 $DbResult = $this->Database->query('SELECT `Shortcut`, `Id` FROM `DocumentLine` WHERE `Id`='.$Id);
94 $DocumentLine = $DbResult->fetch_assoc();
95
96 $DbResult = $this->Database->query('SELECT * FROM `DocumentLineSequence` WHERE '.
97 '`DocumentLine`='.$Id.' AND `FinanceYear`='.$FinanceYear['Id']);
98 $Sequence = $DbResult->fetch_assoc();
99
100 if($Sequence['YearPrefix'] == 1)
101 {
102 $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'].'/'.$FinanceYear['Year'];
103 } else $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'];
104
105 $this->Database->query('UPDATE `DocumentLineSequence` SET `NextNumber` = `NextNumber` + 1 '.
106 'WHERE (`DocumentLine`='.$Id.') AND (`FinanceYear`='.$FinanceYear['Id'].')');
107 return($Result);
108 }
109
110 function RecalculateMemberPayment()
111 {
112 $Output = 'Aktualizuji finance členů...<br />';
113 $this->Database->query('TRUNCATE TABLE `MemberPayment`');
114 $DbResult = $this->Database->query('SELECT * FROM `Member`');
115 while($Member = $DbResult->fetch_assoc())
116 {
117 $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(-SUM(Value*Direction), 0) FROM FinanceOperation '.
118 'WHERE Subject='.$Member['Subject'].') + (SELECT COALESCE(-SUM(Value*Direction), 0) FROM FinanceInvoice '.
119 'WHERE Subject='.$Member['Subject'].')) AS Cash');
120 $Cash = $DbResult2->fetch_row();
121 $Cash = $Cash[0];
122
123 $DbResult2 = $this->Database->query('SELECT SUM(`Product`.`Consumption`) * `StockSerialNumber`.`Amount` '.
124 'FROM `StockSerialNumber` JOIN `Product` ON `Product`.`Id` = `StockSerialNumber`.`Product` '.
125 'WHERE (`StockSerialNumber`.`Location` = '.$Member['Id'].') AND (`StockSerialNumber`.`TimeElimination` IS NULL)');
126 $ConsumptionPlus = $DbResult2->fetch_row();
127 $ConsumptionPlus = $ConsumptionPlus[0];
128
129 $DbResult2 = $this->Database->query('SELECT SUM(`Service`.`Price`) AS `Price` '.
130 'FROM `ServiceCustomerRel` LEFT JOIN '.
131 '`Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` WHERE `ServiceCustomerRel`.`Customer`='.
132 $Member['Id'].' AND `ServiceCustomerRel`.`Action` IS NULL');
133 $DbRow = $DbResult2->fetch_assoc();
134 $Monthly = 0;
135 if($DbRow['Price'] != '') $MonthlyInet = $DbRow['Price'];
136 else $MonthlyInet = 0;
137
138 $Monthly += $MonthlyInet;
139 $Monthly -= $this->W2Kc($ConsumptionPlus);
140 $Monthly = round($Monthly);
141
142 if($Member['BillingPeriodNext'] == 1)
143 {
144 // Inactive payer
145 $MonthlyInet = 0;
146 $Monthly = 0;
147 $ConsumptionPlus = 0;
148 $Consumption = 0;
149 }
150 $this->Database->insert('MemberPayment', array('Member' => $Member['Id'],
151 'NetworkDevice' => $NetworkDevice, 'MonthlyInternet' => $MonthlyInet,
152 'MonthlyTotal' => $Monthly, 'MonthlyConsumption' => $this->W2Kc($Consumption),
153 'Cash' => $Cash, 'MonthlyPlus' => $this->W2Kc($ConsumptionPlus)));
154 }
155 $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'RecalculateMemberPayment');
156 return($Output);
157 }
158
159 function GetVATByType($TypeId)
160 {
161 $Time = time();
162 $DbResult = $this->Database->select('FinanceVAT', 'Value', '(Type='.$TypeId.
163 ') AND (ValidFrom <= "'.TimeToMysqlDate($Time).'") AND ((ValidTo >= "'.
164 TimeToMysqlDate($Time).'") OR (ValidTo IS NULL)) LIMIT 1');
165 $Row = $DbResult->fetch_array();
166 return($Row[0]);
167 }
168}
169
170class ModuleFinance extends AppModule
171{
172 function __construct($System)
173 {
174 parent::__construct($System);
175 $this->Name = 'Finance';
176 $this->Version = '1.0';
177 $this->Creator = 'Chronos';
178 $this->License = 'GNU/GPLv3';
179 $this->Description = 'Base module for finance management';
180 $this->Dependencies = array('File', 'EmailQueue');
181 }
182
183 function DoInstall()
184 {
185 }
186
187 function DoUninstall()
188 {
189 }
190
191 function DoStart()
192 {
193 global $Config;
194
195 $this->System->RegisterPage(array('finance', 'sprava'), 'PageFinanceManage');
196 $this->System->RegisterPage(array('finance', 'platby'), 'PageFinanceUserState');
197 $this->System->RegisterPage(array('finance', 'import'), 'PageFinanceImportPayment');
198 $this->System->RegisterPage(array('finance', 'zivnost'), 'PageFinanceTaxFiling');
199
200 $this->System->FormManager->RegisterClass('FinanceOperation', array(
201 'Title' => 'Finanční operace',
202 'Table' => 'FinanceOperation',
203 'DefaultSortColumn' => 'Time',
204 'DefaultSortOrder' => 1,
205 'Items' => array(
206 'Direction' => array('Type' => 'TFinanceOperationDirection', 'Caption' => 'Směr', 'Default' => '1'),
207 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
208 'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
209 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
210 'Time' => array('Type' => 'Date', 'Caption' => 'Čas realizace', 'Default' => ''),
211 'Cash' => array('Type' => 'Boolean', 'Caption' => 'Hotově', 'Default' => ''),
212 'Taxable' => array('Type' => 'Boolean', 'Caption' => 'Zdanitelné', 'Default' => ''),
213 'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
214 'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
215 'Text' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
216 'Network' => array('Type' => 'Boolean', 'Caption' => 'Týkající sítě', 'Default' => ''),
217 'BankAccount' => array('Type' => 'TFinanceBankAccount', 'Caption' => 'Účet', 'Default' => '', 'Null' => true),
218 'Treasury' => array('Type' => 'TFinanceTreasury', 'Caption' => 'Pokladna', 'Default' => '', 'Null' => true),
219 'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
220 'InvoiceRel' => array('Type' => 'TFinanceInvoiceOperationRelListOperation', 'Caption' => 'Zaplacené faktury', 'Default' => ''),
221 ),
222 'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
223 ));
224
225 $this->System->FormManager->RegisterClass('FinanceTreasuryIn', $this->System->FormManager->Classes['FinanceOperation']);
226 $this->System->FormManager->Classes['FinanceTreasuryIn']['Title'] = 'Pokladní příjmy';
227 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Default'] = 1;
228 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Hidden'] = true;
229 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Direction']['Filter'] = true;
230 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Default'] = DOC_LINE_TREASURY_IN;
231 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Hidden'] = true;
232 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['DocumentLine']['Filter'] = true;
233 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['BankAccount']['Hidden'] = true;
234
235 $this->System->FormManager->RegisterClass('FinanceTreasuryOut', $this->System->FormManager->Classes['FinanceOperation']);
236 $this->System->FormManager->Classes['FinanceTreasuryOut']['Title'] = 'Pokladní výdeje';
237 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Default'] = -1;
238 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Hidden'] = true;
239 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Direction']['Filter'] = true;
240 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Default'] = DOC_LINE_TREASURY_OUT;
241 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Hidden'] = true;
242 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['DocumentLine']['Filter'] = true;
243 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['BankAccount']['Hidden'] = true;
244
245 $this->System->FormManager->RegisterClass('FinanceAccountIn', $this->System->FormManager->Classes['FinanceOperation']);
246 $this->System->FormManager->Classes['FinanceAccountIn']['Title'] = 'Příjmy na účet';
247 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Default'] = 1;
248 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Hidden'] = true;
249 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Direction']['Filter'] = true;
250 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Default'] = DOC_LINE_ACCOUNT_IN;
251 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Hidden'] = true;
252 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['DocumentLine']['Filter'] = true;
253 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Treasury']['Hidden'] = true;
254
255
256 $this->System->FormManager->RegisterClass('FinanceAccountOut', $this->System->FormManager->Classes['FinanceOperation']);
257 $this->System->FormManager->Classes['FinanceAccountOut']['Title'] = 'Výdeje z účtu';
258 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Default'] = -1;
259 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Hidden'] = true;
260 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Direction']['Filter'] = true;
261 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Default'] = DOC_LINE_ACCOUNT_OUT;
262 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Hidden'] = true;
263 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['DocumentLine']['Filter'] = true;
264 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Treasury']['Hidden'] = true;
265
266 $this->System->FormManager->RegisterFormType('TFinanceOperationDirection', array(
267 'Type' => 'Enumeration',
268 'States' => array(-1 => 'Výdej', 1 => 'Příjem'),
269 ));
270 $this->System->FormManager->RegisterClass('FinanceInvoice', array(
271 'Title' => 'Faktury',
272 'Table' => 'FinanceInvoice',
273 'DefaultSortColumn' => 'Time',
274 'DefaultSortOrder' => 1,
275 'Items' => array(
276 'Direction' => array('Type' => 'TFinanceInvoiceDirection', 'Caption' => 'Směr', 'Default' => '1'),
277 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
278 'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
279 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
280 'Time' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
281 'TimeDue' => array('Type' => 'Date', 'Caption' => 'Čas splatnosti', 'Default' => ''),
282 'TimePayment' => array('Type' => 'Date', 'Caption' => 'Čas zaplacení', 'Default' => '', 'Null' => true),
283 'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
284 'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
285 'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
286 'PeriodFrom' => array('Type' => 'Date', 'Caption' => 'Období od', 'Default' => '', 'Null' => true),
287 'PeriodTo' => array('Type' => 'Date', 'Caption' => 'Období do', 'Default' => '', 'Null' => true),
288 'Cash' => array('Type' => 'Boolean', 'Caption' => 'Platit hotově', 'Default' => ''),
289 'Items' => array('Type' => 'TFinanceInvoiceItemListInvoice', 'Caption' => 'Položky', 'Default' => ''),
290 'OperationRel' => array('Type' => 'TFinanceInvoiceOperationRelListInvoice', 'Caption' => 'Platba', 'Default' => ''),
291 'OperationRelCount' => array('Type' => 'Integer', 'Caption' => 'Plateb',
292 'ReadOnly' => true, 'SQL' => '(SELECT COUNT(`FinanceInvoiceOperationRel`.`Id`) FROM `FinanceInvoiceOperationRel` '.
293 'WHERE `FinanceInvoiceOperationRel`.`Invoice`=#Id)'),
294 ),
295 'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
296 ));
297 $this->System->FormManager->RegisterClass('FinanceInvoiceIn', $this->System->FormManager->Classes['FinanceInvoice']);
298 $this->System->FormManager->Classes['FinanceInvoiceIn']['Title'] = 'Přijaté faktury';
299 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Default'] = -1;
300 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Hidden'] = true;
301 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Filter'] = true;
302 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Default'] = DOC_LINE_INVOICE_IN;
303 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Hidden'] = true;
304 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Filter'] = true;
305
306 $this->System->FormManager->RegisterClass('FinanceInvoiceOut', $this->System->FormManager->Classes['FinanceInvoice']);
307 $this->System->FormManager->Classes['FinanceInvoiceOut']['Title'] = 'Vydané faktury';
308 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Default'] = 1;
309 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Hidden'] = true;
310 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Filter'] = true;
311 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Default'] = DOC_LINE_INVOICE_OUT;
312 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Hidden'] = true;
313 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Filter'] = true;
314
315 $this->System->FormManager->RegisterFormType('TFinanceInvoiceDirection', array(
316 'Type' => 'Enumeration',
317 'States' => array(-1 => 'Příjem', 1 => 'Výdej'),
318 ));
319
320 $this->System->FormManager->RegisterClass('Company', array(
321 'Title' => 'Firma',
322 'Table' => 'Company',
323 'Items' => array(
324 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
325 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => '0'),
326 ),
327 ));
328 $this->System->FormManager->RegisterClass('FinanceInvoiceItem', array(
329 'Title' => 'Položka faktury',
330 'Table' => 'FinanceInvoiceItem',
331 'Items' => array(
332 'FinanceInvoice' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Faktura', 'Default' => '0'),
333 'Description' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => 'Položka'),
334 'Price' => array('Type' => 'Float', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
335 'Quantity' => array('Type' => 'Integer', 'Caption' => 'Množství', 'Default' => '1'),
336 'VAT' => array('Type' => 'Integer', 'Caption' => 'Daň', 'Default' => '21', 'Suffix' => '%'),
337 'Total' => array('Type' => 'Integer', 'Caption' => 'Celkem', 'Default' => '', 'Suffix' => 'Kč',
338 'ReadOnly' => true, 'SQL' => 'CEIL(`Price` * `Quantity`)'),
339 ),
340 ));
341 $this->System->FormManager->RegisterClass('FinanceTreasury', array(
342 'Title' => 'Pokladny',
343 'Table' => 'FinanceTreasury',
344 'DefaultSortColumn' => 'Name',
345 'Items' => array(
346 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
347 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
348 'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
349 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '.
350 'WHERE `FinanceOperation`.`Treasury`=#Id)'),
351 'Operations' => array('Type' => 'TFinanceOperationListTreasury', 'Caption' => 'Operace', 'Default' => ''),
352 ),
353 ));
354 $this->System->FormManager->RegisterFormType('TFinanceTreasury', array(
355 'Type' => 'Reference',
356 'Table' => 'FinanceTreasury',
357 'Id' => 'Id',
358 'Name' => 'Name',
359 'Filter' => '1',
360 ));
361 $this->System->FormManager->RegisterClass('FinanceBankAccount', array(
362 'Title' => 'Účty',
363 'Table' => 'FinanceBankAccount',
364 'DefaultSortColumn' => 'Comment',
365 'Items' => array(
366 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Vlastník', 'Default' => ''),
367 'Comment' => array('Type' => 'String', 'Caption' => 'Komentář', 'Default' => ''),
368 'Number' => array('Type' => 'String', 'Caption' => 'Číslo', 'Default' => ''),
369 'Bank' => array('Type' => 'TFinanceBank', 'Caption' => 'Banka', 'Default' => ''),
370 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
371 'TimeEnd' => array('Type' => 'Date', 'Caption' => 'Čas zrušení', 'Default' => '', 'Null' => true),
372 'Currency' => array('Type' => 'TCurrency', 'Caption' => 'Měna', 'Default' => ''),
373 'LoginName' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno / token', 'Default' => ''),
374 'LoginPassword' => array('Type' => 'String', 'Caption' => 'Přihlašovací heslo', 'Default' => ''),
375 'Operations' => array('Type' => 'TFinanceOperationListAccount', 'Caption' => 'Operace', 'Default' => ''),
376 'LastImportDate' => array('Type' => 'Date', 'Caption' => 'Datum posledního importu', 'Default' => ''),
377 'LastImportId' => array('Type' => 'String', 'Caption' => 'Id posledního importu', 'Default' => ''),
378 'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
379 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '.
380 'WHERE `FinanceOperation`.`BankAccount`=#Id)'),
381 ),
382 'ItemActions' => array(
383 array('Caption' => 'Import plateb z banky', 'URL' => '/finance/import-api/?i=#RowId'),
384 array('Caption' => 'Import plateb ze souboru', 'URL' => '/finance/import-soubor/?i=#RowId'),
385 ),
386 ));
387 $this->System->FormManager->RegisterFormType('TFinanceBankAccount', array(
388 'Type' => 'Reference',
389 'Table' => 'FinanceBankAccount',
390 'Id' => 'Id',
391 'Name' => 'Comment',
392 'Filter' => '1',
393 ));
394 $this->System->FormManager->RegisterClass('FinanceBank', array(
395 'Title' => 'Banky',
396 'Table' => 'FinanceBank',
397 'Items' => array(
398 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
399 'Code' => array('Type' => 'String', 'Caption' => 'Český kód', 'Default' => ''),
400 'BIC' => array('Type' => 'String', 'Caption' => 'Kód BIC', 'Default' => ''),
401 'Country' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => ''),
402 ),
403 ));
404 $this->System->FormManager->RegisterFormType('TFinanceBank', array(
405 'Type' => 'Reference',
406 'Table' => 'FinanceBank',
407 'Id' => 'Id',
408 'Name' => 'CONCAT(Name, " (", Code, ")")',
409 'Filter' => '1',
410 ));
411 $this->System->FormManager->RegisterClass('Currency', array(
412 'Title' => 'Měny',
413 'Table' => 'Currency',
414 'Items' => array(
415 'Code' => array('Type' => 'String', 'Caption' => 'Kód', 'Default' => ''),
416 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
417 'Symbol' => array('Type' => 'String', 'Caption' => 'Symbol', 'Default' => ''),
418 ),
419 ));
420 $this->System->FormManager->RegisterClass('FinanceCharge', array(
421 'Title' => 'Parametry účtování',
422 'Table' => 'FinanceCharge',
423 'Items' => array(
424 'Internet' => array('Type' => 'Integer', 'Caption' => 'Platba Internetu', 'Default' => '0', 'Suffix' => 'Kč'),
425 'InternetSpeed' => array('Type' => 'Integer', 'Caption' => 'Rychlost Internetu', 'Default' => '0', 'Suffix' => 'Mbit/s'),
426 'InternetSpeedReserve' => array('Type' => 'Integer', 'Caption' => 'Rezerva rychlosti', 'Default' => '0', 'Suffix' => 'Mbit/s'),
427 'AdministrationPerUser' => array('Type' => 'Integer', 'Caption' => 'Správa za uživatele', 'Default' => '0', 'Suffix' => 'Kč'),
428 'kWh' => array('Type' => 'Integer', 'Caption' => 'Cena kWh', 'Default' => '0', 'Suffix' => 'Kč'),
429 'BaseSpeedElement' => array('Type' => 'Integer', 'Caption' => 'Základní díl rychlosti', 'Default' => '0', 'Suffix' => 'Mbit/s'),
430 'BaseTariffPrice' => array('Type' => 'Integer', 'Caption' => 'Základní cena tarifu', 'Default' => '0', 'Suffix' => 'Kč'),
431 'TopTariffPrice' => array('Type' => 'Integer', 'Caption' => 'Nejvyšší cena tarifu', 'Default' => '0', 'Suffix' => 'Kč'),
432 'Action' => array('Type' => 'TActionEnum', 'Caption' => 'Změna období', 'Default' => '', 'Null' => true),
433 'ReplaceId' => array('Type' => 'TFinanceCharge', 'Caption' => 'Cílová položka', 'Default' => '0', 'Null' => true),
434 ),
435 ));
436 $this->System->FormManager->RegisterClass('FinanceVAT', array(
437 'Title' => 'Sazby DPH',
438 'Table' => 'FinanceVAT',
439 'Items' => array(
440 'Type' => array('Type' => 'TFinanceVATType', 'Caption' => 'Typ', 'Default' => ''),
441 'ValidFrom' => array('Type' => 'Date', 'Caption' => 'Platnost od', 'Default' => ''),
442 'ValidTo' => array('Type' => 'Date', 'Caption' => 'Platnost do', 'Default' => '', 'Null' => true),
443 'Value' => array('Type' => 'Integer', 'Caption' => 'Hodnota', 'Default' => '', 'Suffix' => '%'),
444 ),
445 ));
446 $this->System->FormManager->RegisterClass('FinanceVATType', array(
447 'Title' => 'Sazby DPH',
448 'Table' => 'FinanceVATType',
449 'Items' => array(
450 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
451 ),
452 ));
453 $this->System->FormManager->RegisterClass('Contract', array(
454 'Title' => 'Smlouvy',
455 'Table' => 'Contract',
456 'Items' => array(
457 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
458 'BillCode' => array('Type' => 'String', 'Caption' => 'Kód', 'Default' => ''),
459 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
460 'ValidFrom' => array('Type' => 'Date', 'Caption' => 'Platnost od', 'Default' => ''),
461 'ValidTo' => array('Type' => 'Date', 'Caption' => 'Platnost do', 'Default' => '', 'Null' => true),
462 'File' => array('Type' => 'TFile', 'Caption' => 'Soubor', 'Default' => '', 'Null' => true),
463 ),
464 'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
465 ));
466 $this->System->FormManager->RegisterFormType('TContract', array(
467 'Type' => 'Reference',
468 'Table' => 'Contract',
469 'Id' => 'Id',
470 'Name' => 'BillCode',
471 'Filter' => '1',
472 ));
473 $this->System->FormManager->RegisterFormType('TFinanceVAT', array(
474 'Type' => 'Reference',
475 'Table' => 'FinanceVAT',
476 'Id' => 'Id',
477 'Name' => 'Name',
478 'Filter' => '1',
479 ));
480 $this->System->FormManager->RegisterFormType('TFinanceVATType', array(
481 'Type' => 'Reference',
482 'Table' => 'FinanceVATType',
483 'Id' => 'Id',
484 'Name' => 'Name',
485 'Filter' => '1',
486 ));
487 $this->System->FormManager->RegisterFormType('TBankAccount', array(
488 'Type' => 'Reference',
489 'Table' => 'FinanceBankAccount',
490 'Id' => 'Id',
491 'Name' => 'CONCAT(`Comment`, " (", `Number`, "/", '.
492 '(SELECT `FinanceBank`.`Code` FROM `FinanceBank` WHERE `FinanceBank`.`Id`=`FinanceBankAccount`.`Bank`), ")")',
493 'Filter' => '1',
494 ));
495
496 $this->System->AddModule(new Bill($this->System));
497 $this->System->AddModule(new Finance($this->System));
498 $this->System->Modules['Finance']->MainSubject = $Config['Finance']['MainSubjectId'];
499 $this->System->Modules['Finance']->DirectoryId = $Config['Finance']['DirectoryId'];
500 }
501
502 function DoStop()
503 {
504 }
505
506 function BeforeInsertFinanceOperation($Form)
507 {
508 if(array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
509 else $Year = date("Y", $Form->Values['ValidFrom']);
510 $DocumentLine = $Form->Values['DocumentLine'];
511 $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
512 return($Form->Values);
513 }
514}
Note: See TracBrowser for help on using the repository browser.