Ignore:
Timestamp:
Nov 20, 2020, 12:08:12 AM (4 years ago)
Author:
chronos
Message:
  • Added: Static types added to almost all classes, methods and function. Supported by PHP 7.4.
  • Fixed: Various found code issues.
Location:
trunk/Modules/FinanceBankAPI
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/FinanceBankAPI/FileImport.php

    r884 r887  
    55class BankImport
    66{
    7   var $System;
    8   var $Database;
    9   var $BankAccount;
    10 
    11   function __construct($System)
     7  public System $System;
     8  public Database $Database;
     9  public int $BankAccount;
     10
     11  function __construct(System $System)
    1212  {
    1313    $this->Database = &$System->Database;
     
    1515  }
    1616
    17   function Import()
    18   {
     17  function Import(): string
     18  {
     19    return '';
    1920  }
    2021
     
    2324  }
    2425
    25   function PairOperations()
    26   {
     26  function PairOperations(): void
     27  {
     28    $Finance = &ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance;
    2729    $DbResult = $this->Database->select('FinanceBankImport', '*', 'FinanceOperation IS NULL');
    2830    while ($DbRow = $DbResult->fetch_assoc())
     
    3436        {
    3537          $DbRow2 = $DbResult2->fetch_assoc();
    36           if ($DbRow['Value'] >= 0) {
    37             $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup');
    38           } else {
    39             $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup');
     38          if ($DbRow['Value'] >= 0)
     39          {
     40            $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup');
     41          } else
     42          {
     43            $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup');
    4044          }
    4145          $Year = date('Y', MysqlDateToTime($DbRow['Time']));
    42           $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);
    43           $DbResult3 = $this->Database->insert('FinanceOperation', array('Subject' => $DbRow2['Id'], 'Cash' => 0,
     46          $BillCode = $Finance->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);
     47          $this->Database->insert('FinanceOperation', array('Subject' => $DbRow2['Id'], 'Cash' => 0,
    4448            'ValueUser' => Abs($DbRow['Value']), 'Value' => 0, 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1,
    4549            'Time' => $DbRow['Time'], 'Text' => $DbRow['Description'], 'BillCode' => $BillCode, 'Group' => $FinanceGroup['Id']));
     
    6569class PageImportAPI extends Page
    6670{
    67   var $FullTitle = 'Import plateb přes API';
    68   var $ShortTitle = 'Import plateb přes API';
    69   var $ParentClass = 'PageFinance';
    70 
    71   function Import($Id)
     71  function __construct(System $System)
     72  {
     73    parent::__construct($System);
     74    $this->FullTitle = 'Import plateb přes API';
     75    $this->ShortTitle = 'Import plateb přes API';
     76    $this->ParentClass = 'PageFinance';
     77  }
     78
     79  function Import(int $Id): string
    7280  {
    7381    $Output = '';
     
    92100  }
    93101
    94   function Show()
    95   {
    96     if (!$this->System->User->CheckPermission('Finance', 'SubjectList'))
     102  function Show(): string
     103  {
     104    if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Finance', 'SubjectList'))
    97105      return 'Nemáte oprávnění';
    98106
     
    104112class PageImportFile extends Page
    105113{
    106   var $FullTitle = 'Import plateb ze souboru';
    107   var $ShortTitle = 'Import plateb ze souboru';
    108   var $ParentClass = 'PageFinance';
    109 
    110   function Show()
     114  function __construct(System $System)
     115  {
     116    parent::__construct($System);
     117    $this->FullTitle = 'Import plateb ze souboru';
     118    $this->ShortTitle = 'Import plateb ze souboru';
     119    $this->ParentClass = 'PageFinance';
     120  }
     121
     122  function Show(): string
    111123  {
    112124    $Output = '';
    113     if (!$this->System->User->CheckPermission('Finance', 'SubjectList')) return 'Nemáte oprávnění';
     125    if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Finance', 'SubjectList')) return 'Nemáte oprávnění';
    114126    if (array_key_exists('Operation', $_GET))
    115127    {
     
    121133  }
    122134
    123   function ShowForm()
     135  function ShowForm(): string
    124136  {
    125137    $Form = new Form($this->System->FormManager);
     
    156168  }
    157169
    158   function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $Group)
     170  function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $Group): void
    159171  {
    160172    $Year = date('Y', $Time);
    161     $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumberId(
     173    $BillCode = ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance->GetNextDocumentLineNumberId(
    162174      $Group['DocumentLine'], $Year);
    163175    $this->Database->insert('FinanceOperation', array('Text' => $Text,
     
    166178  }
    167179
    168   function Insert()
    169   {
    170     $Finance = $this->System->Modules['Finance'];
     180  function Insert(): string
     181  {
     182    $Finance = $ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance;
    171183    $Output = '';
    172184
    173185    for ($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
    174186    {
    175       if ($_POST['Money'.$I] >= 0) {
     187      if ($_POST['Money'.$I] >= 0)
     188      {
    176189        $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN,
    177190          'FinanceOperationGroup');
    178       } else {
     191      } else
     192      {
    179193        $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT,
    180194          'FinanceOperationGroup');
     
    185199        0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $FinanceGroup);
    186200      $Output .= $I.', ';
    187       $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
     201      ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('Finance', 'NewPaymentInserted');
    188202    }
    189203    return $Output;
  • trunk/Modules/FinanceBankAPI/FinanceBankAPI.php

    r874 r887  
    88class ModuleFinanceBankAPI extends AppModule
    99{
    10   function __construct($System)
     10  function __construct(System $System)
    1111  {
    1212    parent::__construct($System);
     
    1616    $this->License = 'GNU/GPLv3';
    1717    $this->Description = 'Communication through API to various banks, manual file import';
    18     $this->Dependencies = array('Finance', 'Scheduler');
     18    $this->Dependencies = array('Finance', 'Scheduler', 'IS');
    1919  }
    2020
    21   function DoInstall()
     21  function DoInstall(): void
    2222  {
    2323  }
    2424
    25   function DoUninstall()
     25  function DoUninstall(): void
    2626  {
    2727  }
    2828
    29   function DoStart()
     29  function DoStart(): void
    3030  {
    3131    $this->System->FormManager->RegisterClass('ImportBankFile', array(
     
    6060    ));
    6161
    62     $this->System->RegisterPage(array('finance', 'import-api'), 'PageImportAPI');
    63     $this->System->RegisterPage(array('finance', 'import-soubor'), 'PageImportFile');
     62    $this->System->RegisterPage(['finance', 'import-api'], 'PageImportAPI');
     63    $this->System->RegisterPage(['finance', 'import-soubor'], 'PageImportFile');
    6464
    65     $this->System->ModuleManager->Modules['IS']->RegisterDashboardItem('FinanceBankAPI',
    66       array('ModuleFinanceBankAPI', 'ShowDashboardItem'));
     65    ModuleIS::Cast($this->System->GetModule('IS'))->RegisterDashboardItem('FinanceBankAPI',
     66      array($this, 'ShowDashboardItem'));
    6767  }
    6868
    69   function DoStop()
     69  function DoStop(): void
    7070  {
    7171  }
    7272
    73   function ShowDashboardItem()
     73  function ShowDashboardItem(): string
    7474  {
    7575    $DbResult = $this->Database->select('FinanceBankImport', 'COUNT(*)', '`FinanceOperation` IS NULL');
     
    7979  }
    8080
    81   function PresetItem($Item)
     81  function PresetItem(array $Item): array
    8282  {
    8383    $Preset = array();
    8484    if ($Item['Value'] < 0) $OperationGroupId = OPERATION_GROUP_ACCOUNT_OUT;
    8585       else $OperationGroupId = OPERATION_GROUP_ACCOUNT_IN;
    86     $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($OperationGroupId, 'FinanceOperationGroup');
     86    $FinanceGroup = ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance->GetFinanceGroupById($OperationGroupId, 'FinanceOperationGroup');
    8787
    8888    $Preset = array(
     
    100100class ScheduleBankImport extends SchedulerTask
    101101{
    102   function Execute()
     102  function Execute(): string
    103103  {
    104104    $Output = '';
  • trunk/Modules/FinanceBankAPI/Fio.php

    r874 r887  
    55class Fio
    66{
    7   var $UserName;
    8   var $Password;
    9   var $Account;
     7  public string $UserName;
     8  public string $Password;
     9  public int $Account;
    1010
    11   function Import($TimeFrom, $TimeTo)
     11  function Import(int $TimeFrom, int $TimeTo): array
    1212  {
    1313    if ($this->UserName == '') throw new Exception('Missing value for UserName property.');
     
    5959  }
    6060
    61   function NoValidDataError($Response)
     61  function NoValidDataError(array $Response): void
    6262  {
    6363    // Try to get error message
    64     // If something go wrong fio show HTML login page and display error message
    65   $Response = implode('', $Response);
     64    // If something go wrong fio shows HTML login page and display error message
     65    $Response = implode('', $Response);
    6666    $ErrorMessageStart = '<div id="oldform_warning">';
    6767    if (strpos($Response, $ErrorMessageStart) !== false)
    68   {
    69     $Response = substr($Response, strpos($Response, $ErrorMessageStart) + strlen($ErrorMessageStart));
    70     $ErrorMessage = trim(substr($Response, 0, strpos($Response, '</div>')));
    71   } else $ErrorMessage = '';
    72   throw new Exception('No valid GPC data: '.$ErrorMessage);
     68    {
     69      $Response = substr($Response, strpos($Response, $ErrorMessageStart) + strlen($ErrorMessageStart));
     70      $ErrorMessage = trim(substr($Response, 0, strpos($Response, '</div>')));
     71    } else $ErrorMessage = '';
     72    throw new Exception('No valid GPC data: '.$ErrorMessage);
    7373  }
    7474}
  • trunk/Modules/FinanceBankAPI/FioAPI.php

    r874 r887  
    2323  }
    2424
    25   function Import($TimeFrom, $TimeTo)
     25  function Import(int $TimeFrom, int $TimeTo): array
    2626  {
    2727    if ($this->Token == '') throw new Exception('Missing value for Token property.');
     
    101101  }
    102102
    103   function NoValidDataError($Response)
     103  function NoValidDataError(array $Response): void
    104104  {
    105105    // Try to get error message
  • trunk/Modules/FinanceBankAPI/GPC.php

    r874 r887  
    66class GPC
    77{
    8   function ParseLine($Line)
     8  function ParseLine(string $Line): array
    99  {
    1010    $Line = ' '.$Line;
  • trunk/Modules/FinanceBankAPI/ImportFio.php

    r884 r887  
    55class ImportFio extends BankImport
    66{
    7   function Import()
     7  function Import(): string
    88  {
    99    $Fio = new FioAPI();
  • trunk/Modules/FinanceBankAPI/ImportPS.php

    r873 r887  
    1111  function ImportTxt($Content)
    1212  {
    13     $Finance = &$this->System->Modules['Finance'];
    14     $Data = explode("\n", $Content);
    1513  }
    1614
    1715  function ImportCVS($Content)
    1816  {
    19     $Finance = &$this->System->Modules['Finance'];
    20 
    2117    $Data = explode("\n", $Content);
    2218    foreach ($Data as $Key => $Value)
Note: See TracChangeset for help on using the changeset viewer.