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