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

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