Ignore:
Timestamp:
Jan 1, 2017, 10:21:42 PM (8 years ago)
Author:
chronos
Message:
  • Added: Autocreate new finance year if necessary for new document line items.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Finance/Finance.php

    r812 r844  
    8282    return(round($Spotreba * 0.72 * $this->kWh));
    8383  }
    84 
    85   function GetNextDocumentLineNumber($Id, $FinanceYear = 0)
    86   {
    87     if($FinanceYear == 0)
     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)
    88105    {
    89106      // Get latest year
    90107      $DbResult = $this->Database->select('FinanceYear', '*', '1 ORDER BY `Year` DESC LIMIT 1');
    91     } else $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$FinanceYear);
    92     if($DbResult->num_rows == 0) throw new Exception('Rok '.$FinanceYear.' nenalezen');
     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        }
    93116    $FinanceYear = $DbResult->fetch_assoc();
    94     if($FinanceYear['Closed'] == 1) throw new Exception('Rok '.$FinanceYear['Year'].' je již uzavřen. Nelze do něj přidávat položky.');
     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);
    95125
    96126    $DbResult = $this->Database->query('SELECT `Shortcut`, `Id` FROM `DocumentLine` WHERE `Id`='.$Id);
Note: See TracChangeset for help on using the changeset viewer.