Ignore:
Timestamp:
Mar 12, 2013, 10:58:10 PM (11 years ago)
Author:
chronos
Message:
  • Přidáno: Akce pro import plateb přes API nebo ze souboru z tabulky "Bankovní účty" ze správy dat.
  • Přidáno: Prozatím zkoušení importu z Fio a Poštovní spořitelny.
File:
1 edited

Legend:

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

    r501 r502  
    33include_once(dirname(__FILE__).'/../../Common/Global.php');
    44
    5 class PageFileImport extends Page
     5class FileImport
    66{
    7   var $FullTitle = 'Import plateb';
    8   var $ShortTitle = 'Import plateb';
     7  var $Database;
     8  var $BankAccountId;
     9 
     10  function __construct($Database)
     11  {
     12    $this->Database = &$Database;
     13  }
     14     
     15  function Import()
     16  {
     17  }
     18 
     19  function ImportFile($Content, $Ext)
     20  {   
     21  }
     22}
     23
     24class PageImportAPI extends Page
     25{
     26  var $FullTitle = 'Import plateb přes API';
     27  var $ShortTitle = 'Import plateb přes API';
     28
     29  function Show()
     30  {   
     31    if(!$this->System->Modules['User']->CheckPermission('Finance', 'SubjectList')) return('Nemáte oprávnění');
     32   
     33    $DbResult = $this->Database->select('FinanceBankAccount', '*', 'Id='.$_GET['id']);
     34    $BankAccount = $DbResult->fetch_assoc();
     35   
     36    $DbResult = $this->Database->select('FinanceBank', '*', 'Id='.$BankAccount['Bank']);
     37    $Bank = $DbResult->fetch_assoc();
     38    $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')';
     39   
     40    if($Bank['Code'] == '2010') $Import = new ImportFio($this->Database);
     41      else if($Bank['Code'] == '0300') $Import = new ImportPS($this->Database);
     42      else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován');
     43    $Import->BankAccountId = $BankAccount['Id'];
     44    $Output .= $Import->Import();
     45   
     46    return($Output);
     47  }
     48}
     49 
     50class PageImportFile extends Page
     51{
     52  var $FullTitle = 'Import plateb ze souboru';
     53  var $ShortTitle = 'Import plateb ze souboru';
    954
    1055  function Show()
     
    2368  function ShowForm()
    2469  {
    25     $FormImport = new Form('ImportBankFile');
    26     $FormImport->OnSubmit = '?Operation=prepare';
    27     $Output = $FormImport->ShowEditForm();
     70    $Form = new Form($this->System->FormManager);
     71    $Form->SetClass('ImportBankFile');
     72    $Form->OnSubmit = '?Operation=prepare';
     73    $Form->Values['BankAccount'] = $_GET['id'];
     74    $Output = $Form->ShowEditForm();
    2875    return($Output);
    2976  }
     
    3178  function Prepare()
    3279  {   
    33     $FormImport = new Form('ImportBankFile');
    34     $FormImport->LoadValuesFromForm();
    35     $Output = $FormImport->ShowEditForm();
     80    $Form = new Form($this->System->FormManager);
     81    $Form->SetClass('ImportBankFile');
     82    $Form->LoadValuesFromForm();
     83    $File = $Form->Values['File'];
     84    $Output = $File->Name.'<br/>';
     85    $Output .= $File->GetFullName().'<br/>';
     86
     87    $DbResult = $this->Database->select('FinanceBankAccount', '*', 'Id='.$Form->Values['BankAccount']);
     88    $BankAccount = $DbResult->fetch_assoc();
    3689   
    37     $Finance = $this->System->Modules['Finance'];
    38     $Output = $FormImport->Values['File'];
    39     return($Output);
     90    $DbResult = $this->Database->select('FinanceBank', '*', 'Id='.$BankAccount['Bank']);
     91    $Bank = $DbResult->fetch_assoc();
     92    $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')';
    4093   
    41     $Data =  $FormImport->Values['File'];
    42     foreach($Data as $Key => $Value)
    43     {
    44       $Value = str_replace('\"', '"', $Value);
    45       $Data[$Key] = str_getcsv($Value, ',', '"', "\\");
    46       //print_r($Data[$Key]);
    47       foreach($Data[$Key] as $Key2 => $Value2)
    48       {
    49         if(substr($Data[$Key][$Key2], 0, 2) == '\"')
    50           $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2);
    51       }
    52     }
    53     $Header = array(
    54       0 => 'datum zaúčtování',         
    55       1 => 'částka',
    56       2 => 'měna',
    57       3 => 'zůstatek',
    58       4 => 'konstantní symbol',
    59       5 => 'variabilní symbol',
    60       6 => 'specifický symbol',
    61       7 => 'označení operace',
    62       8 => 'název protiúčtu',
    63       9 => 'protiúčet',
    64       10 => 'poznámka',
    65       11 => '',
    66     );
    67     //print_r($Header);
    68     //print_r($Data[0]);
    69     //print_r($_POST['Source']);
    70     //print_r($Data);
    71  
    72     if($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV';
    73     else
    74     {
    75       array_shift($Data);
    76       $Automatic = '';
    77       $Manual = '';
    78       $Output = '<form action="?Operation=insert" method="post">';
    79       $I = 0;
    80       foreach($Data as $Key => $Value)
    81       {
    82         if(count($Value) <= 1) continue;
    83         if($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna
    84         $Time = explode('.', $Value[0]);
    85         $Time = $Time[2].'-'.$Time[1].'-'.$Time[0];
    86         $Money = $Value[1];
    87         if(is_numeric($Value[5]))
    88         {
    89           $Subject = $Value[5] * 1;
    90           $DbResult = $this->Database->query('SELECT Id FROM Subject WHERE Id='.$this->Database->real_escape_string($Subject));
    91           if($DbResult->num_rows == 0) $Subject = '? ('.($Value[5] * 1).')';
    92         } else
    93         {
    94           $Subject = '? ('.$Value[5].')';
    95         }
    96         if(!is_numeric($Subject))
    97         {
    98           $Mode = 'Ručně';
    99           $Style = 'style="background-color: LightPink;" ';
    100         } else
    101         {
    102           $Mode = 'Automaticky';
    103           $Style = '';
    104         }
    105    
    106         if($Money < 0) $Text = 'Platba převodem';
    107           else $Text = 'Přijatá platba';
    108         $Automatic .= '<tr>'.
    109             //'<td>'.$Mode.'</td>'.
    110             '<td><input type="text" name="Date'.$I.'" value="'.$Time.'"/></td>'.
    111             '<td><input type="text" '.$Style.'name="Subject'.$I.'" value="'.$Subject.'"/></td>'.
    112             '<td>'.$Value[8].'</td>'.
    113             '<td><input type="text" name="Money'.$I.'" value="'.$Money.'"/></td>'.
    114             '<td><input type="text" name="Text'.$I.'" value="'.$Text.'"/></td>'.
    115             '<td><input type="text" name="Taxable'.$I.'" value="1"/></td>'.
    116             '<td><input type="text" name="Network'.$I.'" value="1"/></td>'.
    117             '</tr><tr><td colspan="7">'.implode(', ', $Value).'</td></tr>';
    118         $I++;
    119       }
    120       $Output .= '<table class="WideTable">'.
    121         '<tr>'.
    122         //'<th>Zpracování</th>'.
    123         '<th>Datum</th><th>Var. symbol</th><th>Protiúčet</th><th>Částka [Kč]</th><th>Text</th><th>Zdanitelné</th><th>Síť</th></tr>';
    124       $Output .= $Automatic.'</table>';
    125       $Output .= '<input type="hidden" name="ItemCount" value="'.$I.'"/>';
    126       $Output .= '<input type="submit" value="Zpracovat"/></form>';     
    127     }
     94    if($Bank['Code'] == '2010') $Import = new ImportFio($this->Database);
     95      else if($Bank['Code'] == '0300') $Import = new ImportPS($this->Database);
     96      else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován');
     97    $Import->BankAccountId = $BankAccount['Id'];
     98    $Output .= $Import->ImportFile($File->GetContent(), $File->GetExt());
     99   
    128100    return($Output);
    129101  }
Note: See TracChangeset for help on using the changeset viewer.