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__).'/Trade.php');
|
---|
8 |
|
---|
9 | // TODO: Move constants to Finance module configuration
|
---|
10 | define('TARIFF_FREE', 7);
|
---|
11 | define('INVOICE_DUE_DAYS', 15);
|
---|
12 | define('OPERATION_GROUP_TREASURY_IN', 1);
|
---|
13 | define('OPERATION_GROUP_TREASURY_OUT', 2);
|
---|
14 | define('OPERATION_GROUP_ACCOUNT_IN', 3);
|
---|
15 | define('OPERATION_GROUP_ACCOUNT_OUT', 4);
|
---|
16 | define('INVOICE_GROUP_IN', 1);
|
---|
17 | define('INVOICE_GROUP_OUT', 2);
|
---|
18 | define('VAT_TYPE_BASE', 2);
|
---|
19 | define('FINANCE_DIRECTION_OUT', 1);
|
---|
20 | define('FINANCE_DIRECTION_IN', 0);
|
---|
21 |
|
---|
22 | class 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 | var $Rounding;
|
---|
42 |
|
---|
43 | function LoadMonthParameters($Period = 1) // 0 - now, 1 - next month
|
---|
44 | {
|
---|
45 | $DbResult = $this->Database->query('SELECT * FROM `FinanceBillingPeriod`');
|
---|
46 | while ($BillingPeriod = $DbResult->fetch_assoc())
|
---|
47 | $this->BillingPeriods[$BillingPeriod['Id']] = $BillingPeriod;
|
---|
48 |
|
---|
49 | // Period parameter is not used as it have to be determined from item replacement
|
---|
50 | $DbResult = $this->Database->query('SELECT * FROM `FinanceCharge` WHERE (`ChangeAction` IS NULL) LIMIT 1');
|
---|
51 | $Row = $DbResult->fetch_array();
|
---|
52 | $this->kWh = $Row['kWh'];
|
---|
53 | $this->Internet = $Row['Internet'];
|
---|
54 | $this->Sprava = $Row['AdministrationPerUser'];
|
---|
55 | $this->RealMaxSpeed = $Row['InternetSpeed'];
|
---|
56 | $this->SpeedReserve = $Row['InternetSpeedReserve'];
|
---|
57 | $this->BaseSpeedElement = $Row['BaseSpeedElement'];
|
---|
58 | $this->MaxSpeed = $this->RealMaxSpeed - $this->SpeedReserve;
|
---|
59 | $this->TopTariffPrice = $Row['TopTariffPrice'];
|
---|
60 | $this->BaseTariffPrice = $Row['BaseTariffPrice'];
|
---|
61 |
|
---|
62 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member`');
|
---|
63 | $Row = $DbResult->fetch_row();
|
---|
64 | $this->InternetUsers = $Row[0];
|
---|
65 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Member` WHERE (`Blocked`=0) AND (`BillingPeriod` > 1)');
|
---|
66 | $Row = $DbResult->fetch_row();
|
---|
67 | $this->PayingUsers = $Row[0];
|
---|
68 |
|
---|
69 | $this->SpravaUsers = $this->PayingUsers;
|
---|
70 |
|
---|
71 | $DbResult = $this->Database->query('SELECT SUM(`MemberPayment`.`MonthlyInternet`) AS `MonthlyInternet`, '.
|
---|
72 | 'SUM(`MemberPayment`.`MonthlyTotal`) AS `MonthlyTotal` '.
|
---|
73 | 'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` WHERE `Member`.`Blocked`=0');
|
---|
74 | $Row = $DbResult->fetch_assoc();
|
---|
75 | $this->TotalInternetPaid = $Row['MonthlyInternet'];
|
---|
76 | $this->TotalPaid = $Row['MonthlyTotal'];
|
---|
77 | $this->Rounding = $this->System->Config['Finance']['Rounding'];
|
---|
78 | }
|
---|
79 |
|
---|
80 | function W2Kc($Spotreba)
|
---|
81 | {
|
---|
82 | return (round($Spotreba * 0.72 * $this->kWh));
|
---|
83 | }
|
---|
84 |
|
---|
85 | function CreateFinanceYear($Year)
|
---|
86 | {
|
---|
87 | $StartTime = mktime(0, 0, 0, 1, 1, $Year);
|
---|
88 | $EndTime = mktime(0, 0, 0, 12, 31, $Year);
|
---|
89 | $this->Database->insert('FinanceYear', array('Year' => $Year,
|
---|
90 | 'DateStart' => TimeToMysqlDate($StartTime), 'DateEnd' => TimeToMysqlDate($EndTime), 'Closed' => 0));
|
---|
91 | $YearId = $this->Database->insert_id;
|
---|
92 |
|
---|
93 | // Create DocumentLineSequence from previous
|
---|
94 | $DbResult = $this->Database->select('DocumentLine', 'Id', '`Yearly` = 1');
|
---|
95 | while ($DbRow = $DbResult->fetch_assoc())
|
---|
96 | {
|
---|
97 | $this->Database->insert('DocumentLineSequence', array('FinanceYear' => $YearId,
|
---|
98 | 'NextNumber' => 1, 'YearPrefix' => 1, 'DocumentLine' => $DbRow['Id']));
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | function GetFinanceYear($Year)
|
---|
103 | {
|
---|
104 | if ($Year == 0)
|
---|
105 | {
|
---|
106 | // Get latest year
|
---|
107 | $DbResult = $this->Database->select('FinanceYear', '*', '1 ORDER BY `Year` DESC LIMIT 1');
|
---|
108 | } else $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year);
|
---|
109 | if ($DbResult->num_rows == 0) {
|
---|
110 | if ($Year == date('Y'))
|
---|
111 | {
|
---|
112 | $this->CreateFinanceYear($Year);
|
---|
113 | $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year);
|
---|
114 | } else throw new Exception('Rok '.$Year.' nenalezen');
|
---|
115 | }
|
---|
116 | $FinanceYear = $DbResult->fetch_assoc();
|
---|
117 | if ($FinanceYear['Closed'] == 1)
|
---|
118 | throw new Exception('Rok '.$FinanceYear['Year'].' je již uzavřen. Nelze do něj přidávat položky.');
|
---|
119 | return $FinanceYear;
|
---|
120 | }
|
---|
121 |
|
---|
122 | function GetNextDocumentLineNumber($Id, $FinanceYear = 0)
|
---|
123 | {
|
---|
124 | $FinanceYear = $this->GetFinanceYear($FinanceYear);
|
---|
125 |
|
---|
126 | $DbResult = $this->Database->query('SELECT `Shortcut`, `Id` FROM `DocumentLine` WHERE `Id`='.$Id);
|
---|
127 | $DocumentLine = $DbResult->fetch_assoc();
|
---|
128 |
|
---|
129 | $DbResult = $this->Database->query('SELECT * FROM `DocumentLineSequence` WHERE '.
|
---|
130 | '`DocumentLine`='.$Id.' AND `FinanceYear`='.$FinanceYear['Id']);
|
---|
131 | $Sequence = $DbResult->fetch_assoc();
|
---|
132 |
|
---|
133 | if ($Sequence['YearPrefix'] == 1)
|
---|
134 | {
|
---|
135 | $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'].'/'.$FinanceYear['Year'];
|
---|
136 | } else $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'];
|
---|
137 |
|
---|
138 | $this->Database->query('UPDATE `DocumentLineSequence` SET `NextNumber` = `NextNumber` + 1 '.
|
---|
139 | 'WHERE (`DocumentLine`='.$Id.') AND (`FinanceYear`='.$FinanceYear['Id'].')');
|
---|
140 | return ($Result);
|
---|
141 | }
|
---|
142 |
|
---|
143 | function GetNextDocumentLineNumberId($Id, $FinanceYear = 0)
|
---|
144 | {
|
---|
145 | $Code = $this->GetNextDocumentLineNumber($Id, $FinanceYear);
|
---|
146 | $this->Database->insert('DocumentLineCode', array('DocumentLine' => $Id, 'Name' => $Code));
|
---|
147 | return $this->Database->insert_id;
|
---|
148 | }
|
---|
149 |
|
---|
150 | function GetFinanceGroupById($Id, $Table)
|
---|
151 | {
|
---|
152 | $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `Id`= '.$Id);
|
---|
153 | if ($DbResult->num_rows == 1) {
|
---|
154 | $Group = $DbResult->fetch_assoc();
|
---|
155 | return ($Group);
|
---|
156 | } else die('Finance group id '.$Id.' not found in table '.$Table);
|
---|
157 | }
|
---|
158 |
|
---|
159 | function RecalculateMemberPayment()
|
---|
160 | {
|
---|
161 | $Output = 'Aktualizuji finance členů...<br />';
|
---|
162 | $this->Database->query('TRUNCATE TABLE `MemberPayment`');
|
---|
163 | $DbResult = $this->Database->query('SELECT * FROM `Member`');
|
---|
164 | while ($Member = $DbResult->fetch_assoc())
|
---|
165 | {
|
---|
166 | $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(`Value`), 0) FROM `FinanceOperation` '.
|
---|
167 | 'WHERE `Subject`='.$Member['Subject'].') - (SELECT COALESCE(SUM(`Value`), 0) FROM `FinanceInvoice` '.
|
---|
168 | 'WHERE `Subject`='.$Member['Subject'].')) AS `Cash`');
|
---|
169 | $Cash = $DbResult2->fetch_row();
|
---|
170 | $Cash = $Cash[0];
|
---|
171 |
|
---|
172 | $DbResult2 = $this->Database->query('SELECT SUM(`Product`.`Consumption`) * `StockSerialNumber`.`Amount` '.
|
---|
173 | 'FROM `StockSerialNumber` JOIN `Product` ON `Product`.`Id` = `StockSerialNumber`.`Product` '.
|
---|
174 | 'WHERE (`StockSerialNumber`.`Location` = '.$Member['Id'].') AND (`StockSerialNumber`.`TimeElimination` IS NULL)');
|
---|
175 | $ConsumptionPlus = $DbResult2->fetch_row();
|
---|
176 | $ConsumptionPlus = $ConsumptionPlus[0];
|
---|
177 |
|
---|
178 | $DbResult2 = $this->Database->query('SELECT SUM(`Service`.`Price`) AS `Price` '.
|
---|
179 | 'FROM `ServiceCustomerRel` LEFT JOIN '.
|
---|
180 | '`Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service` WHERE (`ServiceCustomerRel`.`Customer`='.
|
---|
181 | $Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL)');
|
---|
182 | $DbRow = $DbResult2->fetch_assoc();
|
---|
183 | $Monthly = 0;
|
---|
184 | if ($DbRow['Price'] != '') $MonthlyInet = $DbRow['Price'];
|
---|
185 | else $MonthlyInet = 0;
|
---|
186 |
|
---|
187 | $Monthly += $MonthlyInet;
|
---|
188 | //$Monthly -= $this->W2Kc($ConsumptionPlus);
|
---|
189 | $Monthly = round($Monthly);
|
---|
190 |
|
---|
191 | if ($Member['BillingPeriod'] == 1)
|
---|
192 | {
|
---|
193 | // Inactive payer
|
---|
194 | $MonthlyInet = 0;
|
---|
195 | $Monthly = 0;
|
---|
196 | $ConsumptionPlus = 0;
|
---|
197 | $Consumption = 0;
|
---|
198 | }
|
---|
199 | $Consumption = 0;
|
---|
200 | $this->Database->insert('MemberPayment', array('Member' => $Member['Id'],
|
---|
201 | 'MonthlyInternet' => $MonthlyInet,
|
---|
202 | 'MonthlyTotal' => $Monthly, 'MonthlyConsumption' => $this->W2Kc($Consumption),
|
---|
203 | 'Cash' => $Cash, 'MonthlyPlus' => $this->W2Kc($ConsumptionPlus)));
|
---|
204 | }
|
---|
205 | $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'RecalculateMemberPayment');
|
---|
206 | return ($Output);
|
---|
207 | }
|
---|
208 |
|
---|
209 | function GetVATByType($TypeId)
|
---|
210 | {
|
---|
211 | $Time = time();
|
---|
212 | $DbResult = $this->Database->select('FinanceVAT', 'Value', '(Type='.$TypeId.
|
---|
213 | ') AND (ValidFrom <= "'.TimeToMysqlDate($Time).'") AND ((ValidTo >= "'.
|
---|
214 | TimeToMysqlDate($Time).'") OR (ValidTo IS NULL)) LIMIT 1');
|
---|
215 | $Row = $DbResult->fetch_array();
|
---|
216 | return ($Row[0]);
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | class ModuleFinance extends AppModule
|
---|
221 | {
|
---|
222 | function __construct($System)
|
---|
223 | {
|
---|
224 | parent::__construct($System);
|
---|
225 | $this->Name = 'Finance';
|
---|
226 | $this->Version = '1.0';
|
---|
227 | $this->Creator = 'Chronos';
|
---|
228 | $this->License = 'GNU/GPLv3';
|
---|
229 | $this->Description = 'Base module for finance management';
|
---|
230 | $this->Dependencies = array('File', 'EmailQueue');
|
---|
231 | }
|
---|
232 |
|
---|
233 | function DoInstall()
|
---|
234 | {
|
---|
235 | }
|
---|
236 |
|
---|
237 | function DoUninstall()
|
---|
238 | {
|
---|
239 | }
|
---|
240 |
|
---|
241 | function DoStart()
|
---|
242 | {
|
---|
243 | global $Config;
|
---|
244 |
|
---|
245 | $this->System->RegisterPage(array('finance', 'sprava'), 'PageFinanceManage');
|
---|
246 | $this->System->RegisterPage(array('finance', 'platby'), 'PageFinanceUserState');
|
---|
247 | $this->System->RegisterPage(array('finance', 'import'), 'PageFinanceImportPayment');
|
---|
248 | $this->System->RegisterPage(array('finance', 'zivnost'), 'PageFinanceTaxFiling');
|
---|
249 |
|
---|
250 | $this->System->FormManager->RegisterClass('FinanceOperation', array(
|
---|
251 | 'Title' => 'Finanční operace',
|
---|
252 | 'Table' => 'FinanceOperation',
|
---|
253 | 'DefaultSortColumn' => 'Time',
|
---|
254 | 'DefaultSortOrder' => 1,
|
---|
255 | 'Items' => array(
|
---|
256 | 'Group' => array('Type' => 'TFinanceOperationGroup', 'Caption' => 'Skupina', 'Default' => ''),
|
---|
257 | 'BillCode' => array('Type' => 'TDocumentLineCode', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true),
|
---|
258 | 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
|
---|
259 | 'Time' => array('Type' => 'Date', 'Caption' => 'Čas realizace', 'Default' => ''),
|
---|
260 | 'Cash' => array('Type' => 'Boolean', 'Caption' => 'Hotově', 'Default' => ''),
|
---|
261 | 'Taxable' => array('Type' => 'Boolean', 'Caption' => 'Zdanitelné', 'Default' => ''),
|
---|
262 | 'Value' => array('Type' => 'Integer', 'Caption' => 'Částka absolutní', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true),
|
---|
263 | 'ValueUser' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
|
---|
264 | 'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
|
---|
265 | 'Text' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => ''),
|
---|
266 | 'Network' => array('Type' => 'Boolean', 'Caption' => 'Týkající sítě', 'Default' => ''),
|
---|
267 | 'BankAccount' => array('Type' => 'TFinanceBankAccount', 'Caption' => 'Účet', 'Default' => '', 'Null' => true),
|
---|
268 | 'Treasury' => array('Type' => 'TFinanceTreasury', 'Caption' => 'Pokladna', 'Default' => '', 'Null' => true),
|
---|
269 | 'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
|
---|
270 | 'InvoiceRel' => array('Type' => 'TFinanceInvoiceOperationRelListOperation', 'Caption' => 'Zaplacené faktury', 'Default' => ''),
|
---|
271 | ),
|
---|
272 | 'BeforeInsert' => array($this, 'BeforeInsertFinanceOperation'),
|
---|
273 | 'AfterInsert' => array($this, 'AfterInsertFinanceOperation'),
|
---|
274 | 'BeforeModify' => array($this, 'BeforeModifyFinanceOperation'),
|
---|
275 | 'ItemActions' => array(
|
---|
276 | array('Caption' => 'Přegenerovat doklad', 'URL' => '/finance/sprava/?Operation=RegenerateOperation&i=#RowId'),
|
---|
277 | ),
|
---|
278 | ));
|
---|
279 |
|
---|
280 | $this->System->FormManager->RegisterClass('FinanceTreasuryIn', $this->System->FormManager->Classes['FinanceOperation']);
|
---|
281 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Title'] = 'Pokladní příjmy';
|
---|
282 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Default'] = OPERATION_GROUP_TREASURY_IN;
|
---|
283 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Hidden'] = true;
|
---|
284 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Filter'] = true;
|
---|
285 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 1;
|
---|
286 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
|
---|
287 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
|
---|
288 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['BankAccount']['Hidden'] = true;
|
---|
289 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Value']['Hidden'] = true;
|
---|
290 |
|
---|
291 | $this->System->FormManager->RegisterClass('FinanceTreasuryOut', $this->System->FormManager->Classes['FinanceOperation']);
|
---|
292 | $this->System->FormManager->Classes['FinanceTreasuryOut']['Title'] = 'Pokladní výdeje';
|
---|
293 | $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Default'] = OPERATION_GROUP_TREASURY_OUT;
|
---|
294 | $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Hidden'] = true;
|
---|
295 | $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Filter'] = true;
|
---|
296 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 1;
|
---|
297 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
|
---|
298 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
|
---|
299 | $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['BankAccount']['Hidden'] = true;
|
---|
300 | $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Value']['Hidden'] = true;
|
---|
301 |
|
---|
302 | $this->System->FormManager->RegisterClass('FinanceAccountIn', $this->System->FormManager->Classes['FinanceOperation']);
|
---|
303 | $this->System->FormManager->Classes['FinanceAccountIn']['Title'] = 'Příjmy na účet';
|
---|
304 | $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Default'] = OPERATION_GROUP_ACCOUNT_IN;
|
---|
305 | $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Hidden'] = true;
|
---|
306 | $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Filter'] = true;
|
---|
307 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 0;
|
---|
308 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
|
---|
309 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
|
---|
310 | $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Treasury']['Hidden'] = true;
|
---|
311 | $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Value']['Hidden'] = true;
|
---|
312 |
|
---|
313 | $this->System->FormManager->RegisterClass('FinanceAccountOut', $this->System->FormManager->Classes['FinanceOperation']);
|
---|
314 | $this->System->FormManager->Classes['FinanceAccountOut']['Title'] = 'Výdeje z účtu';
|
---|
315 | $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Default'] = OPERATION_GROUP_ACCOUNT_OUT;
|
---|
316 | $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Hidden'] = true;
|
---|
317 | $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Filter'] = true;
|
---|
318 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 0;
|
---|
319 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true;
|
---|
320 | $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false;
|
---|
321 | $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Treasury']['Hidden'] = true;
|
---|
322 | $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Value']['Hidden'] = true;
|
---|
323 |
|
---|
324 | $this->System->FormManager->RegisterClass('FinanceOperationGroup', array(
|
---|
325 | 'Title' => 'Skupina finančních operací',
|
---|
326 | 'Table' => 'FinanceOperationGroup',
|
---|
327 | 'Items' => array(
|
---|
328 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
|
---|
329 | 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
|
---|
330 | 'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
|
---|
331 | 'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
|
---|
332 | 'Items' => array('Type' => 'TFinanceOperationListGroup', 'Caption' => 'Operace', 'Default' => ''),
|
---|
333 | ),
|
---|
334 | ));
|
---|
335 | $this->System->FormManager->RegisterFormType('TFinanceOperationGroup', array(
|
---|
336 | 'Type' => 'Reference',
|
---|
337 | 'Table' => 'FinanceOperationGroup',
|
---|
338 | 'Id' => 'Id',
|
---|
339 | 'Name' => 'Name',
|
---|
340 | 'Filter' => '1',
|
---|
341 | ));
|
---|
342 | $this->System->FormManager->RegisterFormType('TFinanceValueSign', array(
|
---|
343 | 'Type' => 'Enumeration',
|
---|
344 | 'States' => array(-1 => 'Mínus', 1 => 'Plus'),
|
---|
345 | ));
|
---|
346 | $this->System->FormManager->RegisterFormType('TFinanceDirection', array(
|
---|
347 | 'Type' => 'Enumeration',
|
---|
348 | 'States' => array(0 => 'Příjem', 1 => 'Výdej'),
|
---|
349 | ));
|
---|
350 | $this->System->FormManager->RegisterClass('FinanceInvoice', array(
|
---|
351 | 'Title' => 'Faktury',
|
---|
352 | 'Table' => 'FinanceInvoice',
|
---|
353 | 'DefaultSortColumn' => 'Time',
|
---|
354 | 'DefaultSortOrder' => 1,
|
---|
355 | 'Items' => array(
|
---|
356 | 'Group' => array('Type' => 'TFinanceInvoiceGroup', 'Caption' => 'Skupina', 'Default' => ''),
|
---|
357 | 'BillCode' => array('Type' => 'TDocumentLineCode', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true),
|
---|
358 | 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
|
---|
359 | 'Time' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
|
---|
360 | 'TimeDue' => array('Type' => 'Date', 'Caption' => 'Čas splatnosti', 'Default' => ''),
|
---|
361 | 'TimePayment' => array('Type' => 'Date', 'Caption' => 'Čas zaplacení', 'Default' => '', 'Null' => true),
|
---|
362 | 'Value' => array('Type' => 'Integer', 'Caption' => 'Částka absolutní', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true),
|
---|
363 | 'ValueUser' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
|
---|
364 | 'SQL' => 'SELECT ROUND(SUM(`Price`*`Quantity`), '.$Config['Finance']['Rounding'].') FROM `FinanceInvoiceItem` WHERE `FinanceInvoiceItem`.`FinanceInvoice`=#Id'),
|
---|
365 | 'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
|
---|
366 | 'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''),
|
---|
367 | 'PeriodFrom' => array('Type' => 'Date', 'Caption' => 'Období od', 'Default' => '', 'Null' => true),
|
---|
368 | 'PeriodTo' => array('Type' => 'Date', 'Caption' => 'Období do', 'Default' => '', 'Null' => true),
|
---|
369 | 'Cash' => array('Type' => 'Boolean', 'Caption' => 'Platit hotově', 'Default' => ''),
|
---|
370 | 'VisibleToUser' => array('Type' => 'Boolean', 'Caption' => 'Viditelné uživatelům', 'Default' => '1'),
|
---|
371 | 'Items' => array('Type' => 'TFinanceInvoiceItemListInvoice', 'Caption' => 'Položky', 'Default' => ''),
|
---|
372 | 'StornoBy' => array('Type' => 'TFinanceInvoiceStornoListBy', 'Caption' => 'Storno doklady', 'Default' => ''),
|
---|
373 | 'StornoOf' => array('Type' => 'TFinanceInvoiceStornoListOf', 'Caption' => 'Původní doklady', 'Default' => ''),
|
---|
374 | 'OperationRel' => array('Type' => 'TFinanceInvoiceOperationRelListInvoice', 'Caption' => 'Platba', 'Default' => ''),
|
---|
375 | 'OperationRelCount' => array('Type' => 'Integer', 'Caption' => 'Plateb',
|
---|
376 | 'ReadOnly' => true, 'SQL' => '(SELECT COUNT(`FinanceInvoiceOperationRel`.`Id`) FROM `FinanceInvoiceOperationRel` '.
|
---|
377 | 'WHERE `FinanceInvoiceOperationRel`.`Invoice`=#Id)'),
|
---|
378 | ),
|
---|
379 | 'BeforeInsert' => array($this, 'BeforeInsertFinanceInvoice'),
|
---|
380 | 'AfterInsert' => array($this, 'AfterInsertFinanceInvoice'),
|
---|
381 | 'BeforeModify' => array($this, 'BeforeModifyFinanceInvoice'),
|
---|
382 | 'ItemActions' => array(
|
---|
383 | array('Caption' => 'Přegenerovat doklad', 'URL' => '/finance/sprava/?Operation=RegenerateInvoice&i=#RowId'),
|
---|
384 | ),
|
---|
385 | ));
|
---|
386 | $this->System->FormManager->RegisterClass('FinanceInvoiceIn', $this->System->FormManager->Classes['FinanceInvoice']);
|
---|
387 | $this->System->FormManager->Classes['FinanceInvoiceIn']['Title'] = 'Přijaté faktury';
|
---|
388 | $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Default'] = INVOICE_GROUP_IN;
|
---|
389 | $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Hidden'] = true;
|
---|
390 | $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Filter'] = true;
|
---|
391 | $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Value']['Hidden'] = true;
|
---|
392 |
|
---|
393 | $this->System->FormManager->RegisterClass('FinanceInvoiceOut', $this->System->FormManager->Classes['FinanceInvoice']);
|
---|
394 | $this->System->FormManager->Classes['FinanceInvoiceOut']['Title'] = 'Vydané faktury';
|
---|
395 | $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Default'] = INVOICE_GROUP_OUT;
|
---|
396 | $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Hidden'] = true;
|
---|
397 | $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Filter'] = true;
|
---|
398 | $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Value']['Hidden'] = true;
|
---|
399 |
|
---|
400 | $this->System->FormManager->RegisterClass('FinanceInvoiceGroup', array(
|
---|
401 | 'Title' => 'Skupina faktur',
|
---|
402 | 'Table' => 'FinanceInvoiceGroup',
|
---|
403 | 'Items' => array(
|
---|
404 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
|
---|
405 | 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
|
---|
406 | 'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
|
---|
407 | 'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
|
---|
408 | 'Items' => array('Type' => 'TFinanceInvoiceListGroup', 'Caption' => 'Faktury', 'Default' => ''),
|
---|
409 | ),
|
---|
410 | ));
|
---|
411 |
|
---|
412 | $this->System->FormManager->RegisterClass('FinanceInvoiceStorno', array(
|
---|
413 | 'Title' => 'Storno faktur',
|
---|
414 | 'Table' => 'FinanceInvoiceStorno',
|
---|
415 | 'Items' => array(
|
---|
416 | 'StornoBy' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Storno doklad', 'Default' => ''),
|
---|
417 | 'StornoOf' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Původní doklad', 'Default' => ''),
|
---|
418 | ),
|
---|
419 | ));
|
---|
420 | $this->System->FormManager->RegisterFormType('TFinanceInvoiceGroup', array(
|
---|
421 | 'Type' => 'Reference',
|
---|
422 | 'Table' => 'FinanceInvoiceGroup',
|
---|
423 | 'Id' => 'Id',
|
---|
424 | 'Name' => 'Name',
|
---|
425 | 'Filter' => '1',
|
---|
426 | ));
|
---|
427 |
|
---|
428 | $this->System->FormManager->RegisterClass('Company', array(
|
---|
429 | 'Title' => 'Firma',
|
---|
430 | 'Table' => 'Company',
|
---|
431 | 'Items' => array(
|
---|
432 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
|
---|
433 | 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => '0'),
|
---|
434 | ),
|
---|
435 | ));
|
---|
436 | $this->System->FormManager->RegisterClass('FinanceInvoiceItem', array(
|
---|
437 | 'Title' => 'Položka faktury',
|
---|
438 | 'Table' => 'FinanceInvoiceItem',
|
---|
439 | 'Items' => array(
|
---|
440 | 'FinanceInvoice' => array('Type' => 'TFinanceInvoice', 'Caption' => 'Faktura', 'Default' => '0'),
|
---|
441 | 'Description' => array('Type' => 'String', 'Caption' => 'Popis', 'Default' => 'Položka'),
|
---|
442 | 'Price' => array('Type' => 'Float', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'),
|
---|
443 | 'Quantity' => array('Type' => 'Float', 'Caption' => 'Množství', 'Default' => '1'),
|
---|
444 | 'VAT' => array('Type' => 'Integer', 'Caption' => 'Daň', 'Default' => '21', 'Suffix' => '%'),
|
---|
445 | 'Total' => array('Type' => 'Integer', 'Caption' => 'Celkem', 'Default' => '', 'Suffix' => 'Kč',
|
---|
446 | 'ReadOnly' => true, 'SQL' => 'ROUND(`Price` * `Quantity`, '.$Config['Finance']['Rounding'].')'),
|
---|
447 | ),
|
---|
448 | 'AfterInsert' => array($this, 'AfterInsertFinanceInvoiceItem'),
|
---|
449 | 'AfterModify' => array($this, 'AfterModifyFinanceInvoiceItem'),
|
---|
450 | 'AfterDelete' => array($this, 'AfterModifyFinanceInvoiceItem'),
|
---|
451 | ));
|
---|
452 | $this->System->FormManager->RegisterClass('FinanceTreasury', array(
|
---|
453 | 'Title' => 'Pokladny',
|
---|
454 | 'Table' => 'FinanceTreasury',
|
---|
455 | 'DefaultSortColumn' => 'Name',
|
---|
456 | 'Items' => array(
|
---|
457 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
458 | 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
|
---|
459 | 'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
|
---|
460 | 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'IFNULL(ROUND((SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
|
---|
461 | 'WHERE `FinanceOperation`.`Treasury`=#Id), '.$Config['Finance']['Rounding'].'), 0)'),
|
---|
462 | 'Operations' => array('Type' => 'TFinanceOperationListTreasury', 'Caption' => 'Operace', 'Default' => ''),
|
---|
463 | 'Check' => array('Type' => 'TFinanceTreasuryCheckListTreasury', 'Caption' => 'Kontrola', 'Default' => ''),
|
---|
464 | ),
|
---|
465 | ));
|
---|
466 | $this->System->FormManager->RegisterClass('FinanceTreasuryCheck', array(
|
---|
467 | 'Title' => 'Kontrola pokladen',
|
---|
468 | 'Table' => 'FinanceTreasuryCheck',
|
---|
469 | 'DefaultSortColumn' => 'Time',
|
---|
470 | 'Items' => array(
|
---|
471 | 'Treasury' => array('Type' => 'TFinanceTreasury', 'Caption' => 'Pokladna', 'Default' => ''),
|
---|
472 | 'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''),
|
---|
473 | 'Value1' => array('Type' => 'Integer', 'Caption' => 'Hodnota 1', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
474 | 'Value2' => array('Type' => 'Integer', 'Caption' => 'Hodnota 2', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
475 | 'Value5' => array('Type' => 'Integer', 'Caption' => 'Hodnota 5', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
476 | 'Value10' => array('Type' => 'Integer', 'Caption' => 'Hodnota 10', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
477 | 'Value20' => array('Type' => 'Integer', 'Caption' => 'Hodnota 20', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
478 | 'Value50' => array('Type' => 'Integer', 'Caption' => 'Hodnota 50', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
479 | 'Value100' => array('Type' => 'Integer', 'Caption' => 'Hodnota 100', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
480 | 'Value200' => array('Type' => 'Integer', 'Caption' => 'Hodnota 200', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
481 | 'Value500' => array('Type' => 'Integer', 'Caption' => 'Hodnota 500', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
482 | 'Value1000' => array('Type' => 'Integer', 'Caption' => 'Hodnota 1000', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
483 | 'Value2000' => array('Type' => 'Integer', 'Caption' => 'Hodnota 2000', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
484 | 'Value5000' => array('Type' => 'Integer', 'Caption' => 'Hodnota 5000', 'Default' => '0', 'Suffix' => 'ks'),
|
---|
485 | 'Sum' => array('Type' => 'Integer', 'Caption' => 'Součet', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true,
|
---|
486 | 'SQL' => '(`Value1` * 1 + `Value2` * 2 + `Value5` * 5 + `Value10` * 10 + '.
|
---|
487 | '`Value20` * 20 + `Value50` * 50 + `Value100` * 100 + `Value200` * 200 + '.
|
---|
488 | '`Value500` * 500 + `Value1000` * 1000 + `Value2000` * 2000 + `Value5000` * 5000)'),
|
---|
489 | ),
|
---|
490 | ));
|
---|
491 | $this->System->FormManager->RegisterFormType('TFinanceTreasuryCheckListTreasury', array(
|
---|
492 | 'Type' => 'ManyToOne',
|
---|
493 | 'Table' => 'FinanceTreasuryCheck',
|
---|
494 | 'Id' => 'Id',
|
---|
495 | 'Ref' => 'Treasury',
|
---|
496 | 'Filter' => '1',
|
---|
497 | ));
|
---|
498 | $this->System->FormManager->RegisterFormType('TFinanceTreasury', array(
|
---|
499 | 'Type' => 'Reference',
|
---|
500 | 'Table' => 'FinanceTreasury',
|
---|
501 | 'Id' => 'Id',
|
---|
502 | 'Name' => 'Name',
|
---|
503 | 'Filter' => '1',
|
---|
504 | ));
|
---|
505 | $this->System->FormManager->RegisterClass('FinanceBankAccount', array(
|
---|
506 | 'Title' => 'Účty',
|
---|
507 | 'Table' => 'FinanceBankAccount',
|
---|
508 | 'DefaultSortColumn' => 'Comment',
|
---|
509 | 'Items' => array(
|
---|
510 | 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Vlastník', 'Default' => ''),
|
---|
511 | 'Comment' => array('Type' => 'String', 'Caption' => 'Komentář', 'Default' => ''),
|
---|
512 | 'Number' => array('Type' => 'String', 'Caption' => 'Číslo', 'Default' => ''),
|
---|
513 | 'Bank' => array('Type' => 'TFinanceBank', 'Caption' => 'Banka', 'Default' => ''),
|
---|
514 | 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
|
---|
515 | 'TimeEnd' => array('Type' => 'Date', 'Caption' => 'Čas zrušení', 'Default' => '', 'Null' => true),
|
---|
516 | 'Currency' => array('Type' => 'TCurrency', 'Caption' => 'Měna', 'Default' => ''),
|
---|
517 | 'LoginName' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno / token', 'Default' => '', 'NotInList' => true),
|
---|
518 | 'LoginPassword' => array('Type' => 'String', 'Caption' => 'Přihlašovací heslo', 'Default' => '', 'NotInList' => true),
|
---|
519 | 'Operations' => array('Type' => 'TFinanceOperationListAccount', 'Caption' => 'Operace', 'Default' => ''),
|
---|
520 | 'Use' => array('Type' => 'Boolean', 'Caption' => 'Používat', 'Default' => '0'),
|
---|
521 | 'LastImportDate' => array('Type' => 'Date', 'Caption' => 'Datum posledního importu', 'Default' => ''),
|
---|
522 | 'LastImportId' => array('Type' => 'String', 'Caption' => 'Id posledního importu', 'Default' => ''),
|
---|
523 | 'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '',
|
---|
524 | 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value`) FROM `FinanceOperation` '.
|
---|
525 | 'WHERE `FinanceOperation`.`BankAccount`=#Id)'),
|
---|
526 | 'AutoImport' => array('Type' => 'Boolean', 'Caption' => 'Automaticky stahovat z banky', 'Default' => ''),
|
---|
527 | ),
|
---|
528 | 'ItemActions' => array(
|
---|
529 | array('Caption' => 'Import plateb z banky', 'URL' => '/finance/import-api/?i=#RowId'),
|
---|
530 | array('Caption' => 'Import plateb ze souboru', 'URL' => '/finance/import-soubor/?i=#RowId'),
|
---|
531 | ),
|
---|
532 | ));
|
---|
533 | $this->System->FormManager->RegisterFormType('TFinanceBankAccount', array(
|
---|
534 | 'Type' => 'Reference',
|
---|
535 | 'Table' => 'FinanceBankAccount',
|
---|
536 | 'Id' => 'Id',
|
---|
537 | 'Name' => 'Comment',
|
---|
538 | 'Filter' => '1',
|
---|
539 | ));
|
---|
540 | $this->System->FormManager->RegisterClass('FinanceBank', array(
|
---|
541 | 'Title' => 'Banky',
|
---|
542 | 'Table' => 'FinanceBank',
|
---|
543 | 'Items' => array(
|
---|
544 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
545 | 'Code' => array('Type' => 'String', 'Caption' => 'Český kód', 'Default' => ''),
|
---|
546 | 'BIC' => array('Type' => 'String', 'Caption' => 'Kód BIC', 'Default' => ''),
|
---|
547 | 'Country' => array('Type' => 'TCountry', 'Caption' => 'Země', 'Default' => ''),
|
---|
548 | ),
|
---|
549 | ));
|
---|
550 | $this->System->FormManager->RegisterFormType('TFinanceBank', array(
|
---|
551 | 'Type' => 'Reference',
|
---|
552 | 'Table' => 'FinanceBank',
|
---|
553 | 'Id' => 'Id',
|
---|
554 | 'Name' => 'CONCAT(Name, " (", Code, ")")',
|
---|
555 | 'Filter' => '1',
|
---|
556 | ));
|
---|
557 | $this->System->FormManager->RegisterClass('Currency', array(
|
---|
558 | 'Title' => 'Měny',
|
---|
559 | 'Table' => 'Currency',
|
---|
560 | 'Items' => array(
|
---|
561 | 'Code' => array('Type' => 'String', 'Caption' => 'Kód', 'Default' => ''),
|
---|
562 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
563 | 'Symbol' => array('Type' => 'String', 'Caption' => 'Symbol', 'Default' => ''),
|
---|
564 | ),
|
---|
565 | ));
|
---|
566 | $this->System->FormManager->RegisterClass('FinanceCharge', array(
|
---|
567 | 'Title' => 'Parametry účtování',
|
---|
568 | 'Table' => 'FinanceCharge',
|
---|
569 | 'Items' => array(
|
---|
570 | 'Internet' => array('Type' => 'Integer', 'Caption' => 'Platba Internetu', 'Default' => '0', 'Suffix' => 'Kč'),
|
---|
571 | 'InternetSpeed' => array('Type' => 'Integer', 'Caption' => 'Rychlost Internetu', 'Default' => '0', 'Suffix' => 'Mbit/s'),
|
---|
572 | 'InternetSpeedReserve' => array('Type' => 'Integer', 'Caption' => 'Rezerva rychlosti', 'Default' => '0', 'Suffix' => 'Mbit/s'),
|
---|
573 | 'AdministrationPerUser' => array('Type' => 'Integer', 'Caption' => 'Správa za uživatele', 'Default' => '0', 'Suffix' => 'Kč'),
|
---|
574 | 'kWh' => array('Type' => 'Integer', 'Caption' => 'Cena kWh', 'Default' => '0', 'Suffix' => 'Kč'),
|
---|
575 | 'BaseSpeedElement' => array('Type' => 'Integer', 'Caption' => 'Základní díl rychlosti', 'Default' => '0', 'Suffix' => 'Mbit/s'),
|
---|
576 | 'BaseTariffPrice' => array('Type' => 'Integer', 'Caption' => 'Základní cena tarifu', 'Default' => '0', 'Suffix' => 'Kč'),
|
---|
577 | 'TopTariffPrice' => array('Type' => 'Integer', 'Caption' => 'Nejvyšší cena tarifu', 'Default' => '0', 'Suffix' => 'Kč'),
|
---|
578 | 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true),
|
---|
579 | 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true),
|
---|
580 | 'ChangeReplaceId' => array('Type' => 'TFinanceCharge', 'Caption' => 'Změna - položka', 'Default' => '0', 'Null' => true, 'NotInList' => true),
|
---|
581 | ),
|
---|
582 | ));
|
---|
583 | $this->System->FormManager->RegisterClass('FinanceVAT', array(
|
---|
584 | 'Title' => 'Sazby DPH',
|
---|
585 | 'Table' => 'FinanceVAT',
|
---|
586 | 'Items' => array(
|
---|
587 | 'Type' => array('Type' => 'TFinanceVATType', 'Caption' => 'Typ', 'Default' => ''),
|
---|
588 | 'ValidFrom' => array('Type' => 'Date', 'Caption' => 'Platnost od', 'Default' => ''),
|
---|
589 | 'ValidTo' => array('Type' => 'Date', 'Caption' => 'Platnost do', 'Default' => '', 'Null' => true),
|
---|
590 | 'Value' => array('Type' => 'Integer', 'Caption' => 'Hodnota', 'Default' => '', 'Suffix' => '%'),
|
---|
591 | ),
|
---|
592 | ));
|
---|
593 | $this->System->FormManager->RegisterClass('FinanceVATType', array(
|
---|
594 | 'Title' => 'Sazby DPH',
|
---|
595 | 'Table' => 'FinanceVATType',
|
---|
596 | 'Items' => array(
|
---|
597 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
598 | ),
|
---|
599 | ));
|
---|
600 | $this->System->FormManager->RegisterClass('Contract', array(
|
---|
601 | 'Title' => 'Smlouvy',
|
---|
602 | 'Table' => 'Contract',
|
---|
603 | 'Items' => array(
|
---|
604 | 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
|
---|
605 | 'BillCode' => array('Type' => 'TDocumentLineCode', 'Caption' => 'Kód', 'Default' => '', 'Null' => true),
|
---|
606 | 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''),
|
---|
607 | 'ValidFrom' => array('Type' => 'Date', 'Caption' => 'Platnost od', 'Default' => ''),
|
---|
608 | 'ValidTo' => array('Type' => 'Date', 'Caption' => 'Platnost do', 'Default' => '', 'Null' => true),
|
---|
609 | 'File' => array('Type' => 'TFile', 'Caption' => 'Soubor', 'Default' => '', 'Null' => true),
|
---|
610 | ),
|
---|
611 | 'BeforeInsert' => array($this, 'BeforeInsertContract'),
|
---|
612 | ));
|
---|
613 | $this->System->FormManager->RegisterFormType('TContract', array(
|
---|
614 | 'Type' => 'Reference',
|
---|
615 | 'Table' => 'Contract',
|
---|
616 | 'Id' => 'Id',
|
---|
617 | 'Name' => 'BillCode',
|
---|
618 | 'Filter' => '1',
|
---|
619 | ));
|
---|
620 | $this->System->FormManager->RegisterFormType('TFinanceVAT', array(
|
---|
621 | 'Type' => 'Reference',
|
---|
622 | 'Table' => 'FinanceVAT',
|
---|
623 | 'Id' => 'Id',
|
---|
624 | 'Name' => 'Name',
|
---|
625 | 'Filter' => '1',
|
---|
626 | ));
|
---|
627 | $this->System->FormManager->RegisterFormType('TFinanceVATType', array(
|
---|
628 | 'Type' => 'Reference',
|
---|
629 | 'Table' => 'FinanceVATType',
|
---|
630 | 'Id' => 'Id',
|
---|
631 | 'Name' => 'Name',
|
---|
632 | 'Filter' => '1',
|
---|
633 | ));
|
---|
634 | $this->System->FormManager->RegisterFormType('TBankAccount', array(
|
---|
635 | 'Type' => 'Reference',
|
---|
636 | 'Table' => 'FinanceBankAccount',
|
---|
637 | 'Id' => 'Id',
|
---|
638 | 'Name' => 'CONCAT(`Comment`, " (", `Number`, "/", '.
|
---|
639 | '(SELECT `FinanceBank`.`Code` FROM `FinanceBank` WHERE `FinanceBank`.`Id`=`FinanceBankAccount`.`Bank`), ")")',
|
---|
640 | 'Filter' => '1',
|
---|
641 | ));
|
---|
642 |
|
---|
643 |
|
---|
644 | $this->System->AddModule(new Bill($this->System));
|
---|
645 | $this->System->AddModule(new Finance($this->System));
|
---|
646 | $this->System->Modules['Finance']->MainSubject = $Config['Finance']['MainSubjectId'];
|
---|
647 | $this->System->Modules['Finance']->DirectoryId = $Config['Finance']['DirectoryId'];
|
---|
648 |
|
---|
649 | $this->System->ModuleManager->Modules['IS']->RegisterDashboardItem('Finance',
|
---|
650 | array('ModuleFinance', 'ShowDashboardItem'));
|
---|
651 | }
|
---|
652 |
|
---|
653 | function ShowDashboardItem()
|
---|
654 | {
|
---|
655 | $DbResult = $this->Database->select('FinanceOperation', 'ROUND(SUM(`Value`))', '1');
|
---|
656 | $DbRow = $DbResult->fetch_row();
|
---|
657 | $Output = 'Stav placení: '.$DbRow['0'].' Kč<br/>';
|
---|
658 | return $Output;
|
---|
659 | }
|
---|
660 |
|
---|
661 | function DoStop()
|
---|
662 | {
|
---|
663 | }
|
---|
664 |
|
---|
665 | function BeforeInsertFinanceOperation($Form)
|
---|
666 | {
|
---|
667 | if (array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
|
---|
668 | else $Year = date("Y", $Form->Values['ValidFrom']);
|
---|
669 | $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
|
---|
670 | $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);
|
---|
671 | return ($Form->Values);
|
---|
672 | }
|
---|
673 |
|
---|
674 | function AfterInsertFinanceOperation($Form, $Id)
|
---|
675 | {
|
---|
676 | $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
|
---|
677 | $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
|
---|
678 | ($Form->Values['ValueUser'] * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
|
---|
679 | return ($Form->Values);
|
---|
680 | }
|
---|
681 |
|
---|
682 | function BeforeModifyFinanceOperation($Form, $Id)
|
---|
683 | {
|
---|
684 | $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');
|
---|
685 | $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
|
---|
686 | ($Form->Values['ValueUser'] * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
|
---|
687 | return ($Form->Values);
|
---|
688 | }
|
---|
689 |
|
---|
690 | function BeforeInsertFinanceInvoice($Form)
|
---|
691 | {
|
---|
692 | // Get new DocumentLineCode by selected invoice Group
|
---|
693 | if (array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
|
---|
694 | else $Year = date("Y", $Form->Values['ValidFrom']);
|
---|
695 | $Group = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
|
---|
696 | $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($Group['DocumentLine'], $Year);
|
---|
697 | return ($Form->Values);
|
---|
698 | }
|
---|
699 |
|
---|
700 | function AfterInsertFinanceInvoice($Form, $Id)
|
---|
701 | {
|
---|
702 | $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
|
---|
703 | $DbResult = $this->Database->query(str_replace('#Id', $Id, $Form->Definition['Items']['ValueUser']['SQL']));
|
---|
704 | $DbRow = $DbResult->fetch_row();
|
---|
705 | $Sum = $DbRow[0];
|
---|
706 |
|
---|
707 | $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
|
---|
708 | ($Sum * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
|
---|
709 | return ($Form->Values);
|
---|
710 | }
|
---|
711 |
|
---|
712 | function BeforeModifyFinanceInvoice($Form, $Id)
|
---|
713 | {
|
---|
714 | $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
|
---|
715 | $DbResult = $this->Database->query(str_replace('#Id', $Id, $Form->Definition['Items']['ValueUser']['SQL']));
|
---|
716 | $DbRow = $DbResult->fetch_row();
|
---|
717 | $Sum = $DbRow[0];
|
---|
718 | $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '.
|
---|
719 | ($Sum * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id);
|
---|
720 | return ($Form->Values);
|
---|
721 | }
|
---|
722 |
|
---|
723 | function AfterInsertFinanceInvoiceItem($Form, $Id)
|
---|
724 | {
|
---|
725 | $ParentForm = new Form($this->System->FormManager);
|
---|
726 | $ParentForm->SetClass('FinanceInvoice');
|
---|
727 | $ParentForm->LoadValuesFromDatabase($Form->Values['FinanceInvoice']);
|
---|
728 | $this->AfterInsertFinanceInvoice($ParentForm, $Form->Values['FinanceInvoice']);
|
---|
729 | return ($Form->Values);
|
---|
730 | }
|
---|
731 |
|
---|
732 | function AfterModifyFinanceInvoiceItem($Form, $Id)
|
---|
733 | {
|
---|
734 | $ParentForm = new Form($this->System->FormManager);
|
---|
735 | $ParentForm->SetClass('FinanceInvoice');
|
---|
736 | $ParentForm->LoadValuesFromDatabase($Form->Values['FinanceInvoice']);
|
---|
737 | $this->BeforeModifyFinanceInvoice($ParentForm, $Form->Values['FinanceInvoice']);
|
---|
738 | return ($Form->Values);
|
---|
739 | }
|
---|
740 |
|
---|
741 | function BeforeInsertContract($Form)
|
---|
742 | {
|
---|
743 | if (array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
|
---|
744 | else $Year = date("Y", $Form->Values['ValidFrom']);
|
---|
745 | $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($Form->Values['DocumentLine'], $Year);
|
---|
746 | return ($Form->Values);
|
---|
747 | }
|
---|
748 | }
|
---|