Changeset 844


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.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/FormClasses.php

    r817 r844  
    2929      'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
    3030      'Shortcut' => array('Type' => 'String', 'Caption' => 'Kód', 'Default' => ''),
     31      'Yearly' => array('Type' => 'Boolean', 'Caption' => 'Ročně', 'Default' => 0),
    3132      'Sequence' => array('Type' => 'TDocumentLineSequenceListLine', 'Caption' => 'Čísleníky', 'Default' => ''),
    3233      'Codes' => array('Type' => 'TDocumentLineCodeList', 'Caption' => 'Kódy', 'Default' => ''),
  • trunk/Application/UpdateTrace.php

    r839 r844  
    20362036{
    20372037  $Manager->Execute('ALTER TABLE `News` CHANGE `Date` `Date` DATETIME NULL, CHANGE `TargetDate` `TargetDate` DATETIME NULL;');
     2038}
     2039
     2040function UpdateTo844($Manager)
     2041{
     2042  $Manager->Execute('ALTER TABLE `DocumentLine` ADD `Yearly` BOOLEAN NOT NULL DEFAULT FALSE AFTER `Shortcut`;');
    20382043}
    20392044
     
    21322137      824 => array('Revision' => 831, 'Function' => 'UpdateTo831'),
    21332138      831 => array('Revision' => 838, 'Function' => 'UpdateTo838'),
     2139      838 => array('Revision' => 844, 'Function' => 'UpdateTo844'),
    21342140    ));
    21352141  }
  • trunk/Application/Version.php

    r843 r844  
    22
    33$Revision = 844; // Subversion revision
    4 $DatabaseRevision = 838; // SQL structure revision
     4$DatabaseRevision = 844; // SQL structure revision
    55$ReleaseTime = strtotime('2017-01-01');
  • 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.