Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
Location:
trunk/Modules/FinanceBankAPI
Files:
8 edited

Legend:

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

    r765 r873  
    2626  {
    2727    $DbResult = $this->Database->select('FinanceBankImport', '*', 'FinanceOperation IS NULL');
    28     while($DbRow = $DbResult->fetch_assoc())
     28    while ($DbRow = $DbResult->fetch_assoc())
    2929    {
    30       if(is_numeric($DbRow['VariableSymbol']))
     30      if (is_numeric($DbRow['VariableSymbol']))
    3131      {
    3232        $DbResult2 = $this->Database->select('Subject', 'Id', 'Id='.$DbRow['VariableSymbol']);
    33         if($DbResult2->num_rows == 1)
     33        if ($DbResult2->num_rows == 1)
    3434        {
    3535          $DbRow2 = $DbResult2->fetch_assoc();
    36           if($DbRow['Value'] >= 0) {
     36          if ($DbRow['Value'] >= 0) {
    3737            $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup');
    3838          } else {
     
    5151          $Form->SetClass('FinanceOperation');
    5252          $Form->LoadValuesFromDatabase($Id);
    53           if(array_key_exists('AfterInsert', $Form->Definition))
     53          if (array_key_exists('AfterInsert', $Form->Definition))
    5454          {
    5555            $Class = $Form->Definition['AfterInsert'][0];
     
    8080    $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')'."\n";
    8181
    82     if($Bank['Code'] == '2010') $Import = new ImportFio($this->System);
    83       else if($Bank['Code'] == '0300') $Import = new ImportPS($this->System);
     82    if ($Bank['Code'] == '2010') $Import = new ImportFio($this->System);
     83      else if ($Bank['Code'] == '0300') $Import = new ImportPS($this->System);
    8484      else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován');
    85     if(isset($Import))
     85    if (isset($Import))
    8686    {
    8787      $Import->BankAccount = $BankAccount;
     
    8989      $Import->PairOperations();
    9090    }
    91     return($Output);
     91    return ($Output);
    9292  }
    9393
    9494  function Show()
    9595  {
    96     if(!$this->System->User->CheckPermission('Finance', 'SubjectList'))
    97       return('Nemáte oprávnění');
     96    if (!$this->System->User->CheckPermission('Finance', 'SubjectList'))
     97      return ('Nemáte oprávnění');
    9898
    9999    $Output = $this->Import($_GET['i']);
    100     return($Output);
     100    return ($Output);
    101101  }
    102102}
     
    111111  {
    112112    $Output = '';
    113     if(!$this->System->User->CheckPermission('Finance', 'SubjectList')) return('Nemáte oprávnění');
    114     if(array_key_exists('Operation', $_GET))
     113    if (!$this->System->User->CheckPermission('Finance', 'SubjectList')) return ('Nemáte oprávnění');
     114    if (array_key_exists('Operation', $_GET))
    115115    {
    116       if($_GET['Operation'] == 'prepare') $Output .= $this->Prepare();
    117       else if($_GET['Operation'] == 'insert') $Output .= $this->Insert();
     116      if ($_GET['Operation'] == 'prepare') $Output .= $this->Prepare();
     117      else if ($_GET['Operation'] == 'insert') $Output .= $this->Insert();
    118118      else $Output .= 'Neplatná akce';
    119119    } else $Output .= $this->ShowForm();
    120     return($Output);
     120    return ($Output);
    121121  }
    122122
     
    128128    $Form->Values['BankAccount'] = $_GET['id'];
    129129    $Output = $Form->ShowEditForm();
    130     return($Output);
     130    return ($Output);
    131131  }
    132132
     
    147147    $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')';
    148148
    149     if($Bank['Code'] == '2010') $Import = new ImportFio($this->System);
    150       else if($Bank['Code'] == '0300') $Import = new ImportPS($this->System);
     149    if ($Bank['Code'] == '2010') $Import = new ImportFio($this->System);
     150      else if ($Bank['Code'] == '0300') $Import = new ImportPS($this->System);
    151151      else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován');
    152152    $Import->BankAccount = $BankAccount;
    153153    $Output .= $Import->ImportFile($File->GetContent(), $File->GetExt());
    154154
    155     return($Output);
     155    return ($Output);
    156156  }
    157157
     
    171171    $Output = '';
    172172
    173     for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
     173    for ($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
    174174    {
    175       if($_POST['Money'.$I] >= 0) {
     175      if ($_POST['Money'.$I] >= 0) {
    176176        $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN,
    177177          'FinanceOperationGroup');
     
    187187      $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
    188188    }
    189     return($Output);
     189    return ($Output);
    190190  }
    191191}
  • trunk/Modules/FinanceBankAPI/FinanceBankAPI.php

    r799 r873  
    7676    $DbRow = $DbResult->fetch_row();
    7777    $Output = 'Nezpárovaných plateb: '.$DbRow['0'].'<br/>';
    78     return($Output);
     78    return ($Output);
    7979  }
    8080
     
    8282  {
    8383    $Preset = array();
    84     if($Item['Value'] < 0) $OperationGroupId = OPERATION_GROUP_ACCOUNT_OUT;
     84    if ($Item['Value'] < 0) $OperationGroupId = OPERATION_GROUP_ACCOUNT_OUT;
    8585       else $OperationGroupId = OPERATION_GROUP_ACCOUNT_IN;
    8686    $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($OperationGroupId, 'FinanceOperationGroup');
     
    9494      'presetBankAccount' => $Item['BankAccount'],
    9595      'presetGroup' => $FinanceGroup['Id']);
    96     return($Preset);
     96    return ($Preset);
    9797  }
    9898}
     
    106106      '(`AutoImport`=1) AND (`TimeCreate` < NOW()) AND '.
    107107      '((`TimeEnd` IS NULL) OR (`TimeEnd` > NOW()))');
    108     while($DbRow = $DbResult->fetch_assoc())
     108    while ($DbRow = $DbResult->fetch_assoc())
    109109    {
    110110      echo($DbRow['Comment']."\n");
     
    112112      $Output .= $Page->Import($DbRow['Id']);
    113113    }
    114     return($Output);
     114    return ($Output);
    115115  }
    116116}
  • trunk/Modules/FinanceBankAPI/Fio.php

    r738 r873  
    1111  function Import($TimeFrom, $TimeTo)
    1212  {
    13     if($this->UserName == '') throw new Exception('Missing value for UserName property.');
    14     if($this->Password == '') throw new Exception('Missing value for Password property.');
    15     if(!is_numeric($this->Account)) throw new Exception('Missing or not numeric value for Account property.');
     13    if ($this->UserName == '') throw new Exception('Missing value for UserName property.');
     14    if ($this->Password == '') throw new Exception('Missing value for Password property.');
     15    if (!is_numeric($this->Account)) throw new Exception('Missing or not numeric value for Account property.');
    1616
    1717    $fp = fsockopen('ssl://www.fio.cz', 443, $errno, $errstr, 30);
    18     if(!$fp)
     18    if (!$fp)
    1919    {
    2020      throw new Exception('Connection error: '.$errstr);
     
    3535      // Read response
    3636      $Response = array();
    37       while(!feof($fp))
     37      while (!feof($fp))
    3838      {
    3939        $Response[] = trim(fgets($fp, 1024));
     
    4242
    4343      // Strip HTTP header
    44       while($Response[0] != '') array_shift($Response);
     44      while ($Response[0] != '') array_shift($Response);
    4545      array_shift($Response); // Remove empty line
    4646      //echo(implode("\n", $Response));
     
    4949      $GPC = new GPC();
    5050      $Result = array();
    51       foreach($Response as $Index => $Line)
     51      foreach ($Response as $Index => $Line)
    5252      {
    53         if(($Index == 0) and (substr($Line, 0, strlen(GPC_TYPE_REPORT)) != GPC_TYPE_REPORT)) $this->NoValidDataError($Response);
     53        if (($Index == 0) and (substr($Line, 0, strlen(GPC_TYPE_REPORT)) != GPC_TYPE_REPORT)) $this->NoValidDataError($Response);
    5454        $GPCLine = $GPC->ParseLine($Line);
    55         if($GPCLine != NULL) $Result[] = $GPCLine;
     55        if ($GPCLine != NULL) $Result[] = $GPCLine;
    5656      }
    57       return($Result);
     57      return ($Result);
    5858    }
    5959  }
     
    6565  $Response = implode('', $Response);
    6666    $ErrorMessageStart = '<div id="oldform_warning">';
    67     if(strpos($Response, $ErrorMessageStart) !== false)
     67    if (strpos($Response, $ErrorMessageStart) !== false)
    6868  {
    6969    $Response = substr($Response, strpos($Response, $ErrorMessageStart) + strlen($ErrorMessageStart));
  • trunk/Modules/FinanceBankAPI/FioAPI.php

    r836 r873  
    77function RemoveComma($Text)
    88{
    9   if((mb_strlen($Text) >= 2) and ($Text[0] == '"') and (mb_substr($Text, -1, 1) == '"')) return(mb_substr($Text, 1, -1));
    10     else return($Text);
     9  if ((mb_strlen($Text) >= 2) and ($Text[0] == '"') and (mb_substr($Text, -1, 1) == '"')) return (mb_substr($Text, 1, -1));
     10    else return ($Text);
    1111}
    1212
     
    2525  function Import($TimeFrom, $TimeTo)
    2626  {
    27     if($this->Token == '') throw new Exception('Missing value for Token property.');
     27    if ($this->Token == '') throw new Exception('Missing value for Token property.');
    2828
    2929    // URL format: https://www.fio.cz/ib_api/rest/periods/{token}/{datum od}/{datum do}/transactions.{format}
     
    3333    $Response = '';
    3434    $Response = @file_get_contents('https://www.fio.cz'.$RequestURL);
    35     if($Response == FALSE)
     35    if ($Response == FALSE)
    3636    {
    3737      throw new Exception('Connection error');
    3838    } else
    3939    {
    40       if($this->Format == 'gpc') $Response = iconv('windows-1250', $this->Encoding, $Response);
     40      if ($this->Format == 'gpc') $Response = iconv('windows-1250', $this->Encoding, $Response);
    4141      $Response = explode("\n", $Response);
    4242
    43       if($this->Format == 'gpc')
     43      if ($this->Format == 'gpc')
    4444      {
    4545        // Parse all GPC lines
    4646        $GPC = new GPC();
    4747        $Result = array();
    48         foreach($Response as $Index => $Line)
     48        foreach ($Response as $Index => $Line)
    4949        {
    50           if(($Index == 0) and (substr($Line, 0, strlen(GPC_TYPE_REPORT)) != GPC_TYPE_REPORT)) $this->NoValidDataError($Response);
     50          if (($Index == 0) and (substr($Line, 0, strlen(GPC_TYPE_REPORT)) != GPC_TYPE_REPORT)) $this->NoValidDataError($Response);
    5151          $GPCLine = $GPC->ParseLine($Line);
    52           if($GPCLine != NULL) $Result[] = $GPCLine;
     52          if ($GPCLine != NULL) $Result[] = $GPCLine;
    5353        }
    5454      } else
    55       if($this->Format == 'csv')
     55      if ($this->Format == 'csv')
    5656      {
    5757        $Result = array(
     
    6060
    6161        // CVS header
    62         while((count($Response) > 0) and ($Response[0] != ''))
     62        while ((count($Response) > 0) and ($Response[0] != ''))
    6363        {
    6464          $Line = explode(';', $Response[0]);
    65           if($Line[0] == 'accountId') $Result['AccountNumber'] = $Line[0];
    66           else if($Line[0] == 'bankId') $Result['BankId'] = $Line[0];
    67           else if($Line[0] == 'currency') $Result['Currency'] = $Line[0];
    68           else if($Line[0] == 'iban') $Result['IBAN'] = $Line[0];
    69           else if($Line[0] == 'bic') $Result['BIC'] = $Line[0];
    70           else if($Line[0] == 'openingBalance') $Result['OpeningBalance'] = $Line[0];
    71           else if($Line[0] == 'closingBalance') $Result['ClosingBalance'] = $Line[0];
    72           else if($Line[0] == 'dateStart') $Result['DateStart'] = $Line[0];
    73           else if($Line[0] == 'dateEnd') $Result['DateEnd'] = $Line[0];
    74           else if($Line[0] == 'idFrom') $Result['IdFrom'] = $Line[0];
    75           else if($Line[0] == 'idTo') $Result['IdTo'] = $Line[0];
     65          if ($Line[0] == 'accountId') $Result['AccountNumber'] = $Line[0];
     66          else if ($Line[0] == 'bankId') $Result['BankId'] = $Line[0];
     67          else if ($Line[0] == 'currency') $Result['Currency'] = $Line[0];
     68          else if ($Line[0] == 'iban') $Result['IBAN'] = $Line[0];
     69          else if ($Line[0] == 'bic') $Result['BIC'] = $Line[0];
     70          else if ($Line[0] == 'openingBalance') $Result['OpeningBalance'] = $Line[0];
     71          else if ($Line[0] == 'closingBalance') $Result['ClosingBalance'] = $Line[0];
     72          else if ($Line[0] == 'dateStart') $Result['DateStart'] = $Line[0];
     73          else if ($Line[0] == 'dateEnd') $Result['DateEnd'] = $Line[0];
     74          else if ($Line[0] == 'idFrom') $Result['IdFrom'] = $Line[0];
     75          else if ($Line[0] == 'idTo') $Result['IdTo'] = $Line[0];
    7676          array_shift($Response);
    7777        }
    7878        array_shift($Response); // Remove empty line
    7979
    80         if((count($Response) == 0) or
     80        if ((count($Response) == 0) or
    8181          ($Response[0] != 'ID pohybu;Datum;Objem;Měna;Protiúčet;Název protiúčtu;Kód banky;Název banky;KS;VS;SS;Uživatelská identifikace;Zpráva pro příjemce;Typ;Provedl;Upřesnění;Komentář;BIC;ID pokynu')
    8282          ) throw new Exception('Unsupported CSV header');
    8383        array_shift($Response);
    8484        array_pop($Response);
    85         foreach($Response as $Index => $Line)
     85        foreach ($Response as $Index => $Line)
    8686        {
    8787          $Line = explode(';', $Line);
     
    9797        }
    9898      }
    99       return($Result);
     99      return ($Result);
    100100    }
    101101  }
     
    107107    $Response = implode('', $Response);
    108108    $ErrorMessageStart = '<div id="oldform_warning">';
    109     if(strpos($Response, $ErrorMessageStart) !== false)
     109    if (strpos($Response, $ErrorMessageStart) !== false)
    110110    {
    111111      $Response = substr($Response, strpos($Response, $ErrorMessageStart) + strlen($ErrorMessageStart));
  • trunk/Modules/FinanceBankAPI/FioDemo.php

    r738 r873  
    1111echo('<html><head><meta charset="utf-8"></head><body>');
    1212echo('<table border="1">');
    13 foreach($Records as $Record)
     13foreach ($Records as $Record)
    1414{
    1515  echo('<tr>');
    16   if($Record['Type'] == GPC_TYPE_REPORT)
     16  if ($Record['Type'] == GPC_TYPE_REPORT)
    1717  {
    1818    echo('<td>Jméno účtu: '.$Record['AccountName'].'</td>');
     
    3535    echo('<th>Uživatelská identifikace</th>');
    3636  } else
    37   if($Record['Type'] == GPC_TYPE_ITEM)
     37  if ($Record['Type'] == GPC_TYPE_ITEM)
    3838  {
    3939    echo('<td>'.date('j.n.Y', $Record['DueDate']).'</td>');
  • trunk/Modules/FinanceBankAPI/GPC.php

    r738 r873  
    1111    $Type = mb_substr($Line, 1, 3);
    1212
    13     if($Type == GPC_TYPE_REPORT)
     13    if ($Type == GPC_TYPE_REPORT)
    1414    {
    1515      $GPCLine = array
     
    2929      );
    3030    } else
    31     if($Type == GPC_TYPE_ITEM)
     31    if ($Type == GPC_TYPE_ITEM)
    3232    {
    3333      $GPCLine = array
     
    5353    $GPCLine = NULL;
    5454
    55     return($GPCLine);
     55    return ($GPCLine);
    5656  }
    5757}
  • trunk/Modules/FinanceBankAPI/ImportFio.php

    r765 r873  
    99    $Fio = new FioAPI();
    1010    $Fio->Token = $this->BankAccount['LoginName'];
    11     if($this->BankAccount['LastImportDate'] == '') $PeriodStart = time();
     11    if ($this->BankAccount['LastImportDate'] == '') $PeriodStart = time();
    1212      else $PeriodStart = MysqlDateToTime($this->BankAccount['LastImportDate']);
    1313    $PeriodEnd = time();
     
    2222        //$Output .= '<td>Suma výdajů: '.$Records['DebitValue'].' Kč</td>';
    2323      //$Output .= '</tr>';
    24     foreach($Records['Items'] as $Record)
     24    foreach ($Records['Items'] as $Record)
    2525    {
    2626      $DbResult = $this->Database->select('FinanceBankImport', 'ID', 'Identification='.$Record['ID']);
    27       if($DbResult->num_rows == 0)
     27      if ($DbResult->num_rows == 0)
    2828      {
    2929        $Output .= '<tr>';
     
    4444    $this->Database->update('FinanceBankAccount', 'Id='.$this->BankAccount['Id'],
    4545      array('LastImportDate' => TimeToMysqlDate($PeriodEnd)));
    46     return($Output);
     46    return ($Output);
    4747  }
    4848}
  • trunk/Modules/FinanceBankAPI/ImportPS.php

    r738 r873  
    55  function ImportFile($Content, $Ext)
    66  {
    7     if($Ext == 'txt') $this->ImportTxt($Content);
    8       else if($Ext == 'cvs') $this->ImportCVS($Content);
     7    if ($Ext == 'txt') $this->ImportTxt($Content);
     8      else if ($Ext == 'cvs') $this->ImportCVS($Content);
    99  }
    1010
     
    2020
    2121    $Data = explode("\n", $Content);
    22     foreach($Data as $Key => $Value)
     22    foreach ($Data as $Key => $Value)
    2323    {
    2424      $Value = str_replace('\"', '"', $Value);
    2525      $Data[$Key] = str_getcsv($Value, ',', '"', "\\");
    2626      //print_r($Data[$Key]);
    27       foreach($Data[$Key] as $Key2 => $Value2)
     27      foreach ($Data[$Key] as $Key2 => $Value2)
    2828      {
    29         if(substr($Data[$Key][$Key2], 0, 2) == '\"')
     29        if (substr($Data[$Key][$Key2], 0, 2) == '\"')
    3030          $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2);
    3131      }
     
    4646    );
    4747
    48     if($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV';
     48    if ($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV';
    4949    else
    5050    {
     
    5454      $Output = '<form action="?Operation=insert" method="post">';
    5555      $I = 0;
    56       foreach($Data as $Key => $Value)
     56      foreach ($Data as $Key => $Value)
    5757      {
    58         if(count($Value) <= 1) continue;
    59         if($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna
     58        if (count($Value) <= 1) continue;
     59        if ($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna
    6060        $Time = explode('.', $Value[0]);
    6161        $Time = $Time[2].'-'.$Time[1].'-'.$Time[0];
    6262        $Money = $Value[1];
    63         if(is_numeric($Value[5]))
     63        if (is_numeric($Value[5]))
    6464        {
    6565          $Subject = $Value[5] * 1;
    6666          $DbResult = $this->Database->query('SELECT Id FROM Subject WHERE Id='.$this->Database->real_escape_string($Subject));
    67           if($DbResult->num_rows == 0) $Subject = '? ('.($Value[5] * 1).')';
     67          if ($DbResult->num_rows == 0) $Subject = '? ('.($Value[5] * 1).')';
    6868        } else
    6969        {
    7070          $Subject = '? ('.$Value[5].')';
    7171        }
    72         if(!is_numeric($Subject))
     72        if (!is_numeric($Subject))
    7373        {
    7474          $Mode = 'Ručně';
     
    8080        }
    8181
    82         if($Money < 0) $Text = 'Platba převodem';
     82        if ($Money < 0) $Text = 'Platba převodem';
    8383        else $Text = 'Přijatá platba';
    8484        $Automatic .= '<tr>'.
Note: See TracChangeset for help on using the changeset viewer.