Changeset 873 for trunk/Modules/FinanceBankAPI
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- Location:
- trunk/Modules/FinanceBankAPI
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/FinanceBankAPI/FileImport.php
r765 r873 26 26 { 27 27 $DbResult = $this->Database->select('FinanceBankImport', '*', 'FinanceOperation IS NULL'); 28 while ($DbRow = $DbResult->fetch_assoc())28 while ($DbRow = $DbResult->fetch_assoc()) 29 29 { 30 if (is_numeric($DbRow['VariableSymbol']))30 if (is_numeric($DbRow['VariableSymbol'])) 31 31 { 32 32 $DbResult2 = $this->Database->select('Subject', 'Id', 'Id='.$DbRow['VariableSymbol']); 33 if ($DbResult2->num_rows == 1)33 if ($DbResult2->num_rows == 1) 34 34 { 35 35 $DbRow2 = $DbResult2->fetch_assoc(); 36 if ($DbRow['Value'] >= 0) {36 if ($DbRow['Value'] >= 0) { 37 37 $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup'); 38 38 } else { … … 51 51 $Form->SetClass('FinanceOperation'); 52 52 $Form->LoadValuesFromDatabase($Id); 53 if (array_key_exists('AfterInsert', $Form->Definition))53 if (array_key_exists('AfterInsert', $Form->Definition)) 54 54 { 55 55 $Class = $Form->Definition['AfterInsert'][0]; … … 80 80 $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')'."\n"; 81 81 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); 84 84 else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován'); 85 if (isset($Import))85 if (isset($Import)) 86 86 { 87 87 $Import->BankAccount = $BankAccount; … … 89 89 $Import->PairOperations(); 90 90 } 91 return ($Output);91 return ($Output); 92 92 } 93 93 94 94 function Show() 95 95 { 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í'); 98 98 99 99 $Output = $this->Import($_GET['i']); 100 return ($Output);100 return ($Output); 101 101 } 102 102 } … … 111 111 { 112 112 $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)) 115 115 { 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(); 118 118 else $Output .= 'Neplatná akce'; 119 119 } else $Output .= $this->ShowForm(); 120 return ($Output);120 return ($Output); 121 121 } 122 122 … … 128 128 $Form->Values['BankAccount'] = $_GET['id']; 129 129 $Output = $Form->ShowEditForm(); 130 return ($Output);130 return ($Output); 131 131 } 132 132 … … 147 147 $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')'; 148 148 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); 151 151 else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován'); 152 152 $Import->BankAccount = $BankAccount; 153 153 $Output .= $Import->ImportFile($File->GetContent(), $File->GetExt()); 154 154 155 return ($Output);155 return ($Output); 156 156 } 157 157 … … 171 171 $Output = ''; 172 172 173 for ($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)173 for ($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--) 174 174 { 175 if ($_POST['Money'.$I] >= 0) {175 if ($_POST['Money'.$I] >= 0) { 176 176 $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 177 177 'FinanceOperationGroup'); … … 187 187 $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted'); 188 188 } 189 return ($Output);189 return ($Output); 190 190 } 191 191 } -
trunk/Modules/FinanceBankAPI/FinanceBankAPI.php
r799 r873 76 76 $DbRow = $DbResult->fetch_row(); 77 77 $Output = 'Nezpárovaných plateb: '.$DbRow['0'].'<br/>'; 78 return ($Output);78 return ($Output); 79 79 } 80 80 … … 82 82 { 83 83 $Preset = array(); 84 if ($Item['Value'] < 0) $OperationGroupId = OPERATION_GROUP_ACCOUNT_OUT;84 if ($Item['Value'] < 0) $OperationGroupId = OPERATION_GROUP_ACCOUNT_OUT; 85 85 else $OperationGroupId = OPERATION_GROUP_ACCOUNT_IN; 86 86 $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($OperationGroupId, 'FinanceOperationGroup'); … … 94 94 'presetBankAccount' => $Item['BankAccount'], 95 95 'presetGroup' => $FinanceGroup['Id']); 96 return ($Preset);96 return ($Preset); 97 97 } 98 98 } … … 106 106 '(`AutoImport`=1) AND (`TimeCreate` < NOW()) AND '. 107 107 '((`TimeEnd` IS NULL) OR (`TimeEnd` > NOW()))'); 108 while ($DbRow = $DbResult->fetch_assoc())108 while ($DbRow = $DbResult->fetch_assoc()) 109 109 { 110 110 echo($DbRow['Comment']."\n"); … … 112 112 $Output .= $Page->Import($DbRow['Id']); 113 113 } 114 return ($Output);114 return ($Output); 115 115 } 116 116 } -
trunk/Modules/FinanceBankAPI/Fio.php
r738 r873 11 11 function Import($TimeFrom, $TimeTo) 12 12 { 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.'); 16 16 17 17 $fp = fsockopen('ssl://www.fio.cz', 443, $errno, $errstr, 30); 18 if (!$fp)18 if (!$fp) 19 19 { 20 20 throw new Exception('Connection error: '.$errstr); … … 35 35 // Read response 36 36 $Response = array(); 37 while (!feof($fp))37 while (!feof($fp)) 38 38 { 39 39 $Response[] = trim(fgets($fp, 1024)); … … 42 42 43 43 // Strip HTTP header 44 while ($Response[0] != '') array_shift($Response);44 while ($Response[0] != '') array_shift($Response); 45 45 array_shift($Response); // Remove empty line 46 46 //echo(implode("\n", $Response)); … … 49 49 $GPC = new GPC(); 50 50 $Result = array(); 51 foreach ($Response as $Index => $Line)51 foreach ($Response as $Index => $Line) 52 52 { 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); 54 54 $GPCLine = $GPC->ParseLine($Line); 55 if ($GPCLine != NULL) $Result[] = $GPCLine;55 if ($GPCLine != NULL) $Result[] = $GPCLine; 56 56 } 57 return ($Result);57 return ($Result); 58 58 } 59 59 } … … 65 65 $Response = implode('', $Response); 66 66 $ErrorMessageStart = '<div id="oldform_warning">'; 67 if (strpos($Response, $ErrorMessageStart) !== false)67 if (strpos($Response, $ErrorMessageStart) !== false) 68 68 { 69 69 $Response = substr($Response, strpos($Response, $ErrorMessageStart) + strlen($ErrorMessageStart)); -
trunk/Modules/FinanceBankAPI/FioAPI.php
r836 r873 7 7 function RemoveComma($Text) 8 8 { 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); 11 11 } 12 12 … … 25 25 function Import($TimeFrom, $TimeTo) 26 26 { 27 if ($this->Token == '') throw new Exception('Missing value for Token property.');27 if ($this->Token == '') throw new Exception('Missing value for Token property.'); 28 28 29 29 // URL format: https://www.fio.cz/ib_api/rest/periods/{token}/{datum od}/{datum do}/transactions.{format} … … 33 33 $Response = ''; 34 34 $Response = @file_get_contents('https://www.fio.cz'.$RequestURL); 35 if ($Response == FALSE)35 if ($Response == FALSE) 36 36 { 37 37 throw new Exception('Connection error'); 38 38 } else 39 39 { 40 if ($this->Format == 'gpc') $Response = iconv('windows-1250', $this->Encoding, $Response);40 if ($this->Format == 'gpc') $Response = iconv('windows-1250', $this->Encoding, $Response); 41 41 $Response = explode("\n", $Response); 42 42 43 if ($this->Format == 'gpc')43 if ($this->Format == 'gpc') 44 44 { 45 45 // Parse all GPC lines 46 46 $GPC = new GPC(); 47 47 $Result = array(); 48 foreach ($Response as $Index => $Line)48 foreach ($Response as $Index => $Line) 49 49 { 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); 51 51 $GPCLine = $GPC->ParseLine($Line); 52 if ($GPCLine != NULL) $Result[] = $GPCLine;52 if ($GPCLine != NULL) $Result[] = $GPCLine; 53 53 } 54 54 } else 55 if ($this->Format == 'csv')55 if ($this->Format == 'csv') 56 56 { 57 57 $Result = array( … … 60 60 61 61 // CVS header 62 while ((count($Response) > 0) and ($Response[0] != ''))62 while ((count($Response) > 0) and ($Response[0] != '')) 63 63 { 64 64 $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]; 76 76 array_shift($Response); 77 77 } 78 78 array_shift($Response); // Remove empty line 79 79 80 if ((count($Response) == 0) or80 if ((count($Response) == 0) or 81 81 ($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') 82 82 ) throw new Exception('Unsupported CSV header'); 83 83 array_shift($Response); 84 84 array_pop($Response); 85 foreach ($Response as $Index => $Line)85 foreach ($Response as $Index => $Line) 86 86 { 87 87 $Line = explode(';', $Line); … … 97 97 } 98 98 } 99 return ($Result);99 return ($Result); 100 100 } 101 101 } … … 107 107 $Response = implode('', $Response); 108 108 $ErrorMessageStart = '<div id="oldform_warning">'; 109 if (strpos($Response, $ErrorMessageStart) !== false)109 if (strpos($Response, $ErrorMessageStart) !== false) 110 110 { 111 111 $Response = substr($Response, strpos($Response, $ErrorMessageStart) + strlen($ErrorMessageStart)); -
trunk/Modules/FinanceBankAPI/FioDemo.php
r738 r873 11 11 echo('<html><head><meta charset="utf-8"></head><body>'); 12 12 echo('<table border="1">'); 13 foreach ($Records as $Record)13 foreach ($Records as $Record) 14 14 { 15 15 echo('<tr>'); 16 if ($Record['Type'] == GPC_TYPE_REPORT)16 if ($Record['Type'] == GPC_TYPE_REPORT) 17 17 { 18 18 echo('<td>Jméno účtu: '.$Record['AccountName'].'</td>'); … … 35 35 echo('<th>Uživatelská identifikace</th>'); 36 36 } else 37 if ($Record['Type'] == GPC_TYPE_ITEM)37 if ($Record['Type'] == GPC_TYPE_ITEM) 38 38 { 39 39 echo('<td>'.date('j.n.Y', $Record['DueDate']).'</td>'); -
trunk/Modules/FinanceBankAPI/GPC.php
r738 r873 11 11 $Type = mb_substr($Line, 1, 3); 12 12 13 if ($Type == GPC_TYPE_REPORT)13 if ($Type == GPC_TYPE_REPORT) 14 14 { 15 15 $GPCLine = array … … 29 29 ); 30 30 } else 31 if ($Type == GPC_TYPE_ITEM)31 if ($Type == GPC_TYPE_ITEM) 32 32 { 33 33 $GPCLine = array … … 53 53 $GPCLine = NULL; 54 54 55 return ($GPCLine);55 return ($GPCLine); 56 56 } 57 57 } -
trunk/Modules/FinanceBankAPI/ImportFio.php
r765 r873 9 9 $Fio = new FioAPI(); 10 10 $Fio->Token = $this->BankAccount['LoginName']; 11 if ($this->BankAccount['LastImportDate'] == '') $PeriodStart = time();11 if ($this->BankAccount['LastImportDate'] == '') $PeriodStart = time(); 12 12 else $PeriodStart = MysqlDateToTime($this->BankAccount['LastImportDate']); 13 13 $PeriodEnd = time(); … … 22 22 //$Output .= '<td>Suma výdajů: '.$Records['DebitValue'].' Kč</td>'; 23 23 //$Output .= '</tr>'; 24 foreach ($Records['Items'] as $Record)24 foreach ($Records['Items'] as $Record) 25 25 { 26 26 $DbResult = $this->Database->select('FinanceBankImport', 'ID', 'Identification='.$Record['ID']); 27 if ($DbResult->num_rows == 0)27 if ($DbResult->num_rows == 0) 28 28 { 29 29 $Output .= '<tr>'; … … 44 44 $this->Database->update('FinanceBankAccount', 'Id='.$this->BankAccount['Id'], 45 45 array('LastImportDate' => TimeToMysqlDate($PeriodEnd))); 46 return ($Output);46 return ($Output); 47 47 } 48 48 } -
trunk/Modules/FinanceBankAPI/ImportPS.php
r738 r873 5 5 function ImportFile($Content, $Ext) 6 6 { 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); 9 9 } 10 10 … … 20 20 21 21 $Data = explode("\n", $Content); 22 foreach ($Data as $Key => $Value)22 foreach ($Data as $Key => $Value) 23 23 { 24 24 $Value = str_replace('\"', '"', $Value); 25 25 $Data[$Key] = str_getcsv($Value, ',', '"', "\\"); 26 26 //print_r($Data[$Key]); 27 foreach ($Data[$Key] as $Key2 => $Value2)27 foreach ($Data[$Key] as $Key2 => $Value2) 28 28 { 29 if (substr($Data[$Key][$Key2], 0, 2) == '\"')29 if (substr($Data[$Key][$Key2], 0, 2) == '\"') 30 30 $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2); 31 31 } … … 46 46 ); 47 47 48 if ($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV';48 if ($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV'; 49 49 else 50 50 { … … 54 54 $Output = '<form action="?Operation=insert" method="post">'; 55 55 $I = 0; 56 foreach ($Data as $Key => $Value)56 foreach ($Data as $Key => $Value) 57 57 { 58 if (count($Value) <= 1) continue;59 if ($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna58 if (count($Value) <= 1) continue; 59 if ($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna 60 60 $Time = explode('.', $Value[0]); 61 61 $Time = $Time[2].'-'.$Time[1].'-'.$Time[0]; 62 62 $Money = $Value[1]; 63 if (is_numeric($Value[5]))63 if (is_numeric($Value[5])) 64 64 { 65 65 $Subject = $Value[5] * 1; 66 66 $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).')'; 68 68 } else 69 69 { 70 70 $Subject = '? ('.$Value[5].')'; 71 71 } 72 if (!is_numeric($Subject))72 if (!is_numeric($Subject)) 73 73 { 74 74 $Mode = 'Ručně'; … … 80 80 } 81 81 82 if ($Money < 0) $Text = 'Platba převodem';82 if ($Money < 0) $Text = 'Platba převodem'; 83 83 else $Text = 'Přijatá platba'; 84 84 $Automatic .= '<tr>'.
Note:
See TracChangeset
for help on using the changeset viewer.