Changeset 740 for trunk/Modules/Finance/Finance.php
- Timestamp:
- Jul 3, 2015, 11:36:07 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Finance.php
r738 r740 10 10 define('TARIFF_FREE', 7); 11 11 define('INVOICE_DUE_DAYS', 15); 12 define(' DOC_LINE_TREASURY_IN', 1);13 define(' DOC_LINE_TREASURY_OUT', 2);14 define(' DOC_LINE_ACCOUNT_IN', 3);15 define(' DOC_LINE_ACCOUNT_OUT', 4);16 define(' DOC_LINE_INVOICE_IN', 5);17 define(' DOC_LINE_INVOICE_OUT', 6);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 18 define('VAT_TYPE_BASE', 2); 19 19 … … 108 108 } 109 109 110 function GetFinanceGroupById($Id, $Table) 111 { 112 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `Id`= '.$Id); 113 if($DbResult->num_rows == 1) { 114 $Group = $DbResult->fetch_assoc(); 115 return($Group); 116 } else die('Finance group not found'); 117 } 118 110 119 function RecalculateMemberPayment() 111 120 { … … 115 124 while($Member = $DbResult->fetch_assoc()) 116 125 { 117 $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM( Value*Direction), 0) FROM FinanceOperation'.118 'WHERE Subject='.$Member['Subject'].') - (SELECT COALESCE(SUM(Value*Direction), 0) FROM FinanceInvoice'.119 'WHERE Subject='.$Member['Subject'].')) AS Cash');126 $DbResult2 = $this->Database->query('SELECT ((SELECT COALESCE(SUM(`Value` * `ValueSign`), 0) FROM `FinanceOperation` '. 127 'WHERE `Subject`='.$Member['Subject'].') - (SELECT COALESCE(SUM(`Value` * `ValueSign`), 0) FROM `FinanceInvoice` '. 128 'WHERE `Subject`='.$Member['Subject'].')) AS `Cash`'); 120 129 $Cash = $DbResult2->fetch_row(); 121 130 $Cash = $Cash[0]; … … 204 213 'DefaultSortOrder' => 1, 205 214 'Items' => array( 206 'Direction' => array('Type' => 'TFinanceOperationDirection', 'Caption' => 'Směr', 'Default' => '1'), 207 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''), 208 'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''), 215 'Group' => array('Type' => 'TFinanceOperationGroup', 'Caption' => 'Skupina', 'Default' => ''), 216 'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true), 209 217 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''), 210 218 'Time' => array('Type' => 'Date', 'Caption' => 'Čas realizace', 'Default' => ''), 211 219 'Cash' => array('Type' => 'Boolean', 'Caption' => 'Hotově', 'Default' => ''), 212 220 'Taxable' => array('Type' => 'Boolean', 'Caption' => 'Zdanitelné', 'Default' => ''), 221 'ValueSign' => array('Type' => 'TFinanceOperationValueSign', 'Caption' => 'Znaménko', 'Default' => '1'), 213 222 'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'), 214 223 'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true), … … 225 234 $this->System->FormManager->RegisterClass('FinanceTreasuryIn', $this->System->FormManager->Classes['FinanceOperation']); 226 235 $this->System->FormManager->Classes['FinanceTreasuryIn']['Title'] = 'Pokladní příjmy'; 227 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items'][' Direction']['Default'] = 1;228 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items'][' Direction']['Hidden'] = true;229 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items'][' Direction']['Filter'] = true;230 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items'][' DocumentLine']['Default'] = DOC_LINE_TREASURY_IN;231 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items'][' DocumentLine']['Hidden'] = true;232 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items'][' DocumentLine']['Filter'] = true;236 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Default'] = OPERATION_GROUP_TREASURY_IN; 237 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Hidden'] = true; 238 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Group']['Filter'] = true; 239 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 1; 240 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true; 241 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false; 233 242 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['BankAccount']['Hidden'] = true; 234 243 235 244 $this->System->FormManager->RegisterClass('FinanceTreasuryOut', $this->System->FormManager->Classes['FinanceOperation']); 236 245 $this->System->FormManager->Classes['FinanceTreasuryOut']['Title'] = 'Pokladní výdeje'; 237 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items'][' Direction']['Default'] = -1;238 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items'][' Direction']['Hidden'] = true;239 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items'][' Direction']['Filter'] = true;240 $this->System->FormManager->Classes['FinanceTreasury Out']['Items']['DocumentLine']['Default'] = DOC_LINE_TREASURY_OUT;241 $this->System->FormManager->Classes['FinanceTreasury Out']['Items']['DocumentLine']['Hidden'] = true;242 $this->System->FormManager->Classes['FinanceTreasury Out']['Items']['DocumentLine']['Filter'] = true;246 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Default'] = OPERATION_GROUP_TREASURY_OUT; 247 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Hidden'] = true; 248 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['Group']['Filter'] = true; 249 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 1; 250 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true; 251 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false; 243 252 $this->System->FormManager->Classes['FinanceTreasuryOut']['Items']['BankAccount']['Hidden'] = true; 244 253 245 254 $this->System->FormManager->RegisterClass('FinanceAccountIn', $this->System->FormManager->Classes['FinanceOperation']); 246 255 $this->System->FormManager->Classes['FinanceAccountIn']['Title'] = 'Příjmy na účet'; 247 $this->System->FormManager->Classes['FinanceAccountIn']['Items'][' Direction']['Default'] = 1;248 $this->System->FormManager->Classes['FinanceAccountIn']['Items'][' Direction']['Hidden'] = true;249 $this->System->FormManager->Classes['FinanceAccountIn']['Items'][' Direction']['Filter'] = true;250 $this->System->FormManager->Classes['Finance AccountIn']['Items']['DocumentLine']['Default'] = DOC_LINE_ACCOUNT_IN;251 $this->System->FormManager->Classes['Finance AccountIn']['Items']['DocumentLine']['Hidden'] = true;252 $this->System->FormManager->Classes['Finance AccountIn']['Items']['DocumentLine']['Filter'] = true;256 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Default'] = OPERATION_GROUP_ACCOUNT_IN; 257 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Hidden'] = true; 258 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Group']['Filter'] = true; 259 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 0; 260 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true; 261 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false; 253 262 $this->System->FormManager->Classes['FinanceAccountIn']['Items']['Treasury']['Hidden'] = true; 254 255 263 256 264 $this->System->FormManager->RegisterClass('FinanceAccountOut', $this->System->FormManager->Classes['FinanceOperation']); 257 265 $this->System->FormManager->Classes['FinanceAccountOut']['Title'] = 'Výdeje z účtu'; 258 $this->System->FormManager->Classes['FinanceAccountOut']['Items'][' Direction']['Default'] = -1;259 $this->System->FormManager->Classes['FinanceAccountOut']['Items'][' Direction']['Hidden'] = true;260 $this->System->FormManager->Classes['FinanceAccountOut']['Items'][' Direction']['Filter'] = true;261 $this->System->FormManager->Classes['Finance AccountOut']['Items']['DocumentLine']['Default'] = DOC_LINE_ACCOUNT_OUT;262 $this->System->FormManager->Classes['Finance AccountOut']['Items']['DocumentLine']['Hidden'] = true;263 $this->System->FormManager->Classes['Finance AccountOut']['Items']['DocumentLine']['Filter'] = true;266 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Default'] = OPERATION_GROUP_ACCOUNT_OUT; 267 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Hidden'] = true; 268 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Group']['Filter'] = true; 269 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Default'] = 0; 270 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Hidden'] = true; 271 $this->System->FormManager->Classes['FinanceTreasuryIn']['Items']['Cash']['Filter'] = false; 264 272 $this->System->FormManager->Classes['FinanceAccountOut']['Items']['Treasury']['Hidden'] = true; 265 273 266 $this->System->FormManager->RegisterFormType('TFinanceOperationDirection', array( 274 $this->System->FormManager->RegisterClass('FinanceOperationGroup', array( 275 'Title' => 'Skupina finančních operací', 276 'Table' => 'FinanceOperationGroup', 277 'Items' => array( 278 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'), 279 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'), 280 'ValueSign' => array('Type' => 'TFinanceInvoiceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'), 281 ), 282 )); 283 $this->System->FormManager->RegisterFormType('TFinanceOperationGroup', array( 284 'Type' => 'Reference', 285 'Table' => 'FinanceOperationGroup', 286 'Id' => 'Id', 287 'Name' => 'Name', 288 'Filter' => '1', 289 )); 290 $this->System->FormManager->RegisterFormType('TFinanceOperationValueSign', array( 267 291 'Type' => 'Enumeration', 268 'States' => array(-1 => ' Výdej', 1 => 'Příjem'),292 'States' => array(-1 => 'Mínus', 1 => 'Plus'), 269 293 )); 270 294 $this->System->FormManager->RegisterClass('FinanceInvoice', array( … … 274 298 'DefaultSortOrder' => 1, 275 299 'Items' => array( 276 'Direction' => array('Type' => 'TFinanceInvoiceDirection', 'Caption' => 'Směr', 'Default' => '1'), 277 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''), 278 'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''), 300 'Group' => array('Type' => 'TFinanceInvoiceGroup', 'Caption' => 'Skupina', 'Default' => ''), 301 'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true), 279 302 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''), 280 303 'Time' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''), 281 304 'TimeDue' => array('Type' => 'Date', 'Caption' => 'Čas splatnosti', 'Default' => ''), 282 305 'TimePayment' => array('Type' => 'Date', 'Caption' => 'Čas zaplacení', 'Default' => '', 'Null' => true), 306 'ValueSign' => array('Type' => 'TFinanceInvoiceValueSign', 'Caption' => 'Znaménko', 'Default' => '1'), 283 307 'Value' => array('Type' => 'Integer', 'Caption' => 'Částka', 'Default' => '0', 'Suffix' => 'Kč'), 284 308 'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true), … … 297 321 $this->System->FormManager->RegisterClass('FinanceInvoiceIn', $this->System->FormManager->Classes['FinanceInvoice']); 298 322 $this->System->FormManager->Classes['FinanceInvoiceIn']['Title'] = 'Přijaté faktury'; 299 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Default'] = -1; 300 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Hidden'] = true; 301 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Direction']['Filter'] = true; 302 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Default'] = DOC_LINE_INVOICE_IN; 303 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Hidden'] = true; 304 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['DocumentLine']['Filter'] = true; 323 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Default'] = INVOICE_GROUP_IN; 324 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Hidden'] = true; 325 $this->System->FormManager->Classes['FinanceInvoiceIn']['Items']['Group']['Filter'] = true; 305 326 306 327 $this->System->FormManager->RegisterClass('FinanceInvoiceOut', $this->System->FormManager->Classes['FinanceInvoice']); 307 328 $this->System->FormManager->Classes['FinanceInvoiceOut']['Title'] = 'Vydané faktury'; 308 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Default'] = 1; 309 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Hidden'] = true; 310 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Direction']['Filter'] = true; 311 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Default'] = DOC_LINE_INVOICE_OUT; 312 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Hidden'] = true; 313 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['DocumentLine']['Filter'] = true; 314 315 $this->System->FormManager->RegisterFormType('TFinanceInvoiceDirection', array( 329 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Default'] = INVOICE_GROUP_OUT; 330 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Hidden'] = true; 331 $this->System->FormManager->Classes['FinanceInvoiceOut']['Items']['Group']['Filter'] = true; 332 333 $this->System->FormManager->RegisterFormType('TFinanceInvoiceValueSign', array( 316 334 'Type' => 'Enumeration', 317 'States' => array(-1 => 'Příjem', 1 => 'Výdej'), 335 'States' => array(-1 => 'Mínus', 1 => 'Plus'), 336 )); 337 338 $this->System->FormManager->RegisterClass('FinanceInvoiceGroup', array( 339 'Title' => 'Skupina faktur', 340 'Table' => 'FinanceInvoiceGroup', 341 'Items' => array( 342 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'), 343 'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'), 344 'ValueSign' => array('Type' => 'TFinanceInvoiceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'), 345 ), 346 )); 347 $this->System->FormManager->RegisterFormType('TFinanceInvoiceGroup', array( 348 'Type' => 'Reference', 349 'Table' => 'FinanceInvoiceGroup', 350 'Id' => 'Id', 351 'Name' => 'Name', 352 'Filter' => '1', 318 353 )); 319 354 … … 347 382 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''), 348 383 'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '', 349 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.` Direction`) FROM `FinanceOperation` '.384 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`) FROM `FinanceOperation` '. 350 385 'WHERE `FinanceOperation`.`Treasury`=#Id)'), 351 386 'Operations' => array('Type' => 'TFinanceOperationListTreasury', 'Caption' => 'Operace', 'Default' => ''), … … 378 413 'LastImportId' => array('Type' => 'String', 'Caption' => 'Id posledního importu', 'Default' => ''), 379 414 'State' => array('Type' => 'Float', 'Caption' => 'Stav', 'Default' => '', 380 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.` Direction`) FROM `FinanceOperation` '.415 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`ValueSign`) FROM `FinanceOperation` '. 381 416 'WHERE `FinanceOperation`.`BankAccount`=#Id)'), 382 417 'AutoImport' => array('Type' => 'Boolean', 'Caption' => 'Automaticky stahovat z banky', 'Default' => ''), … … 511 546 if(array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']); 512 547 else $Year = date("Y", $Form->Values['ValidFrom']); 513 $ DocumentLine = $Form->Values['DocumentLine'];514 $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumber($ DocumentLine, $Year);548 $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup'); 549 $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumber($FinanceGroup['DocumentLine'], $Year); 515 550 return($Form->Values); 516 551 }
Note:
See TracChangeset
for help on using the changeset viewer.