Changeset 901 for trunk/Modules/Finance/FinanceModels.php
- Timestamp:
- Feb 17, 2021, 9:27:32 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/FinanceModels.php
r899 r901 77 77 } 78 78 79 function CreateFinanceYear(int $Year) 80 { 81 $StartTime = mktime(0, 0, 0, 1, 1, $Year); 82 $EndTime = mktime(0, 0, 0, 12, 31, $Year); 83 $this->Database->insert('FinanceYear', array('Year' => $Year, 84 'DateStart' => TimeToMysqlDate($StartTime), 'DateEnd' => TimeToMysqlDate($EndTime), 'Closed' => 0)); 85 $YearId = $this->Database->insert_id; 86 87 // Create DocumentLineSequence from previous 88 $DbResult = $this->Database->select('DocumentLine', 'Id', '`Yearly` = 1'); 89 while ($DbRow = $DbResult->fetch_assoc()) 79 function GetFinanceGroupById(string $Id, string $Table): ?array 80 { 81 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `Id`= '.$Id); 82 if ($DbResult->num_rows == 1) 90 83 { 91 $this->Database->insert('DocumentLineSequence', array('FinanceYear' => $YearId,92 'NextNumber' => 1, 'YearPrefix' => 1, 'DocumentLine' => $DbRow['Id']));93 }94 }95 96 function GetFinanceYear(int $Year): array97 {98 if ($Year == 0)99 {100 // Get latest year101 $DbResult = $this->Database->select('FinanceYear', '*', '1 ORDER BY `Year` DESC LIMIT 1');102 } else $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year);103 if ($DbResult->num_rows == 0)104 {105 if ($Year == date('Y'))106 {107 $this->CreateFinanceYear($Year);108 $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year);109 } else throw new Exception('Rok '.$Year.' nenalezen');110 }111 $FinanceYear = $DbResult->fetch_assoc();112 if ($FinanceYear['Closed'] == 1)113 throw new Exception('Rok '.$FinanceYear['Year'].' je již uzavřen. Nelze do něj přidávat položky.');114 return $FinanceYear;115 }116 117 function GetNextDocumentLineNumber(string $Id, int $FinanceYear = 0): string118 {119 $FinanceYear = $this->GetFinanceYear($FinanceYear);120 121 $DbResult = $this->Database->query('SELECT `Shortcut`, `Id` FROM `DocumentLine` WHERE `Id`='.$Id);122 $DocumentLine = $DbResult->fetch_assoc();123 124 $DbResult = $this->Database->query('SELECT * FROM `DocumentLineSequence` WHERE '.125 '`DocumentLine`='.$Id.' AND `FinanceYear`='.$FinanceYear['Id']);126 $Sequence = $DbResult->fetch_assoc();127 128 if ($Sequence['YearPrefix'] == 1)129 {130 $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'].'/'.$FinanceYear['Year'];131 } else $Result = $DocumentLine['Shortcut'].$Sequence['NextNumber'];132 133 $this->Database->query('UPDATE `DocumentLineSequence` SET `NextNumber` = `NextNumber` + 1 '.134 'WHERE (`DocumentLine`='.$Id.') AND (`FinanceYear`='.$FinanceYear['Id'].')');135 return $Result;136 }137 138 function GetNextDocumentLineNumberId(string $Id, int $FinanceYear = 0): int139 {140 $Code = $this->GetNextDocumentLineNumber($Id, $FinanceYear);141 $this->Database->insert('DocumentLineCode', array('DocumentLine' => $Id, 'Name' => $Code));142 return $this->Database->insert_id;143 }144 145 function GetFinanceGroupById(string $Id, string $Table): ?array146 {147 $DbResult = $this->Database->query('SELECT * FROM `'.$Table.'` WHERE `Id`= '.$Id);148 if ($DbResult->num_rows == 1) {149 84 $Group = $DbResult->fetch_assoc(); 150 85 return $Group; … … 443 378 } 444 379 445 class Contract extends Model446 {447 static function GetModelDesc(): ModelDesc448 {449 $Desc = new ModelDesc(self::GetClassName());450 $Desc->AddReference('DocumentLine', DocumentLine::GetClassName());451 $Desc->AddReference('BillCode', DocumentLineCode::GetClassName());452 $Desc->AddReference('Subject', Subject::GetClassName());453 $Desc->AddDate('ValidFrom');454 $Desc->AddDate('ValidTo');455 $Desc->AddReference('File', File::GetClassName());456 return $Desc;457 }458 }459 460 380 class FinanceBillingPeriod extends Model 461 381 {
Note:
See TracChangeset
for help on using the changeset viewer.