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

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