Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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));
Note: See TracChangeset for help on using the changeset viewer.