Changeset 887 for trunk/Modules/Finance/Finance.php
- Timestamp:
- Nov 20, 2020, 12:08:12 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Finance.php
r877 r887 41 41 var $Rounding; 42 42 43 function LoadMonthParameters( $Period = 1) // 0 - now, 1 - next month43 function LoadMonthParameters(int $Period = 1) // 0 - now, 1 - next month 44 44 { 45 45 $DbResult = $this->Database->query('SELECT * FROM `FinanceBillingPeriod`'); … … 78 78 } 79 79 80 function W2Kc($Spotreba) 80 function W2Kc($Spotreba): string 81 81 { 82 82 return round($Spotreba * 0.72 * $this->kWh); … … 88 88 $EndTime = mktime(0, 0, 0, 12, 31, $Year); 89 89 $this->Database->insert('FinanceYear', array('Year' => $Year, 90 'DateStart' => TimeToMysqlDate($StartTime), 'DateEnd' => TimeToMysqlDate($EndTime), 'Closed' => 0));91 $YearId = $this->Database->insert_id;90 'DateStart' => TimeToMysqlDate($StartTime), 'DateEnd' => TimeToMysqlDate($EndTime), 'Closed' => 0)); 91 $YearId = $this->Database->insert_id; 92 92 93 93 // Create DocumentLineSequence from previous … … 95 95 while ($DbRow = $DbResult->fetch_assoc()) 96 96 { 97 $this->Database->insert('DocumentLineSequence', array('FinanceYear' => $YearId,98 'NextNumber' => 1, 'YearPrefix' => 1, 'DocumentLine' => $DbRow['Id']));99 }100 } 101 102 function GetFinanceYear( $Year)97 $this->Database->insert('DocumentLineSequence', array('FinanceYear' => $YearId, 98 'NextNumber' => 1, 'YearPrefix' => 1, 'DocumentLine' => $DbRow['Id'])); 99 } 100 } 101 102 function GetFinanceYear(int $Year) 103 103 { 104 104 if ($Year == 0) … … 107 107 $DbResult = $this->Database->select('FinanceYear', '*', '1 ORDER BY `Year` DESC LIMIT 1'); 108 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); 109 if ($DbResult->num_rows == 0) 110 { 111 if ($Year == date('Y')) 112 { 113 $this->CreateFinanceYear($Year); 113 114 $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year); 114 } else throw new Exception('Rok '.$Year.' nenalezen');115 }115 } else throw new Exception('Rok '.$Year.' nenalezen'); 116 } 116 117 $FinanceYear = $DbResult->fetch_assoc(); 117 118 if ($FinanceYear['Closed'] == 1) … … 120 121 } 121 122 122 function GetNextDocumentLineNumber( $Id,$FinanceYear = 0)123 { 124 $FinanceYear = $this->GetFinanceYear($FinanceYear);123 function GetNextDocumentLineNumber(string $Id, int $FinanceYear = 0) 124 { 125 $FinanceYear = $this->GetFinanceYear($FinanceYear); 125 126 126 127 $DbResult = $this->Database->query('SELECT `Shortcut`, `Id` FROM `DocumentLine` WHERE `Id`='.$Id); … … 141 142 } 142 143 143 function GetNextDocumentLineNumberId( $Id, $FinanceYear = 0)144 function GetNextDocumentLineNumberId(string $Id, int $FinanceYear = 0): int 144 145 { 145 146 $Code = $this->GetNextDocumentLineNumber($Id, $FinanceYear); … … 148 149 } 149 150 150 function GetFinanceGroupById( $Id, $Table)151 function GetFinanceGroupById(string $Id, string $Table): ?array 151 152 { 152 153 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `Id`= '.$Id); … … 154 155 $Group = $DbResult->fetch_assoc(); 155 156 return $Group; 156 } else die('Finance group id '.$Id.' not found in table '.$Table); 157 } 158 159 function RecalculateMemberPayment() 157 } 158 echo('Finance group id '.$Id.' not found in table '.$Table); 159 return null; 160 } 161 162 function RecalculateMemberPayment(): string 160 163 { 161 164 $Output = 'Aktualizuji finance členů...<br />'; … … 199 202 $Consumption = 0; 200 203 $this->Database->insert('MemberPayment', array('Member' => $Member['Id'], 201 202 203 204 'MonthlyInternet' => $MonthlyInet, 205 'MonthlyTotal' => $Monthly, 'MonthlyConsumption' => $this->W2Kc($Consumption), 206 'Cash' => $Cash, 'MonthlyPlus' => $this->W2Kc($ConsumptionPlus))); 204 207 } 205 $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'RecalculateMemberPayment');208 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('Finance', 'RecalculateMemberPayment'); 206 209 return $Output; 207 210 } 208 211 209 function GetVATByType( $TypeId)212 function GetVATByType(string $TypeId): string 210 213 { 211 214 $Time = time(); … … 220 223 class ModuleFinance extends AppModule 221 224 { 222 function __construct($System) 225 public Finance $Finance; 226 public Bill $Bill; 227 228 function __construct(System $System) 223 229 { 224 230 parent::__construct($System); … … 229 235 $this->Description = 'Base module for finance management'; 230 236 $this->Dependencies = array('File', 'EmailQueue'); 231 } 232 233 function DoInstall() 234 { 235 } 236 237 function DoUninstall() 238 { 239 } 240 241 function DoStart() 237 238 $this->Bill = new Bill($this->System); 239 $this->Finance = new Finance($this->System); 240 } 241 242 function DoInstall(): void 243 { 244 } 245 246 function DoUninstall(): void 247 { 248 } 249 250 function DoStart(): void 242 251 { 243 252 global $Config; 244 253 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');254 $this->System->RegisterPage(['finance', 'sprava'], 'PageFinanceManage'); 255 $this->System->RegisterPage(['finance', 'platby'], 'PageFinanceUserState'); 256 $this->System->RegisterPage(['finance', 'import'], 'PageFinanceImportPayment'); 257 $this->System->RegisterPage(['finance', 'zivnost'], 'PageFinanceTaxFiling'); 249 258 250 259 $this->System->FormManager->RegisterClass('FinanceOperation', array( … … 644 653 )); 645 654 646 647 $this->System->AddModule(new Bill($this->System)); 648 $this->System->AddModule(new Finance($this->System)); 649 $this->System->Modules['Finance']->MainSubject = $Config['Finance']['MainSubjectId']; 650 $this->System->Modules['Finance']->DirectoryId = $Config['Finance']['DirectoryId']; 651 652 $this->System->ModuleManager->Modules['IS']->RegisterDashboardItem('Finance', 653 array('ModuleFinance', 'ShowDashboardItem')); 654 } 655 656 function ShowDashboardItem() 655 $this->Finance->MainSubject = $Config['Finance']['MainSubjectId']; 656 $this->Finance->DirectoryId = $Config['Finance']['DirectoryId']; 657 658 ModuleIS::Cast($this->System->GetModule('IS'))->RegisterDashboardItem('Finance', array($this, 'ShowDashboardItem')); 659 } 660 661 function ShowDashboardItem(): string 657 662 { 658 663 $DbResult = $this->Database->select('FinanceOperation', 'ROUND(SUM(`Value`))', '1'); … … 662 667 } 663 668 664 function DoStop() 665 { 666 } 667 668 function BeforeInsertFinanceOperation( $Form)669 function DoStop(): void 670 { 671 } 672 673 function BeforeInsertFinanceOperation(Form $Form): array 669 674 { 670 675 if (array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']); 671 676 else $Year = date("Y", $Form->Values['ValidFrom']); 672 $FinanceGroup = $this-> System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');673 $Form->Values['BillCode'] = $this-> System->Modules['Finance']->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);674 return $Form->Values; 675 } 676 677 function AfterInsertFinanceOperation( $Form, $Id)678 { 679 $FinanceGroup = $this-> System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');677 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup'); 678 $Form->Values['BillCode'] = $this->Finance->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year); 679 return $Form->Values; 680 } 681 682 function AfterInsertFinanceOperation(Form $Form, string $Id): array 683 { 684 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup'); 680 685 $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '. 681 686 ($Form->Values['ValueUser'] * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id); … … 683 688 } 684 689 685 function BeforeModifyFinanceOperation( $Form, $Id)686 { 687 $FinanceGroup = $this-> System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup');690 function BeforeModifyFinanceOperation(Form $Form, string $Id): array 691 { 692 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceOperationGroup'); 688 693 $this->Database->query('UPDATE `'.$Form->Definition['Table'].'` SET `Value`= '. 689 694 ($Form->Values['ValueUser'] * $FinanceGroup['ValueSign']).' WHERE `Id`='.$Id); … … 691 696 } 692 697 693 function BeforeInsertFinanceInvoice( $Form)698 function BeforeInsertFinanceInvoice(Form $Form): array 694 699 { 695 700 // Get new DocumentLineCode by selected invoice Group 696 701 if (array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']); 697 702 else $Year = date("Y", $Form->Values['ValidFrom']); 698 $Group = $this-> System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');699 $Form->Values['BillCode'] = $this-> System->Modules['Finance']->GetNextDocumentLineNumberId($Group['DocumentLine'], $Year);700 return $Form->Values; 701 } 702 703 function AfterInsertFinanceInvoice( $Form, $Id)704 { 705 $FinanceGroup = $this-> System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');703 $Group = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup'); 704 $Form->Values['BillCode'] = $this->Finance->GetNextDocumentLineNumberId($Group['DocumentLine'], $Year); 705 return $Form->Values; 706 } 707 708 function AfterInsertFinanceInvoice(Form $Form, string $Id): array 709 { 710 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup'); 706 711 $DbResult = $this->Database->query(str_replace('#Id', $Id, $Form->Definition['Items']['ValueUser']['SQL'])); 707 712 $DbRow = $DbResult->fetch_row(); … … 713 718 } 714 719 715 function BeforeModifyFinanceInvoice( $Form, $Id)716 { 717 $FinanceGroup = $this-> System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');720 function BeforeModifyFinanceInvoice(Form $Form, string $Id): array 721 { 722 $FinanceGroup = $this->Finance->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup'); 718 723 $DbResult = $this->Database->query(str_replace('#Id', $Id, $Form->Definition['Items']['ValueUser']['SQL'])); 719 724 $DbRow = $DbResult->fetch_row(); … … 724 729 } 725 730 726 function AfterInsertFinanceInvoiceItem( $Form, $Id)731 function AfterInsertFinanceInvoiceItem(Form $Form, string $Id): array 727 732 { 728 733 $ParentForm = new Form($this->System->FormManager); … … 733 738 } 734 739 735 function AfterModifyFinanceInvoiceItem( $Form, $Id)740 function AfterModifyFinanceInvoiceItem(Form $Form, string $Id): array 736 741 { 737 742 $ParentForm = new Form($this->System->FormManager); … … 742 747 } 743 748 744 function BeforeInsertContract( $Form)749 function BeforeInsertContract(Form $Form): array 745 750 { 746 751 if (array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']); 747 752 else $Year = date("Y", $Form->Values['ValidFrom']); 748 $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($Form->Values['DocumentLine'], $Year); 749 return $Form->Values; 753 $Form->Values['BillCode'] = $this->Finance->GetNextDocumentLineNumberId($Form->Values['DocumentLine'], $Year); 754 return $Form->Values; 755 } 756 757 static function Cast(AppModule $AppModule): ModuleFinance 758 { 759 if ($AppModule instanceof ModuleFinance) 760 { 761 return $AppModule; 762 } 763 throw new Exception('Expected ModuleFinance type but '.gettype($AppModule)); 750 764 } 751 765 }
Note:
See TracChangeset
for help on using the changeset viewer.