Changeset 502


Ignore:
Timestamp:
Mar 12, 2013, 10:58:10 PM (12 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.
Location:
trunk
Files:
2 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Form/Form.php

    r501 r502  
    8383    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
    8484    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
    85     ($$this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     85    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    8686    {
    8787      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
  • trunk/Common/Form/Types/File.php

    r501 r502  
    11<?php
     2
     3class DbFile
     4{
     5  var $Id;
     6  var $FileName;
     7  var $Size;
     8  var $Directory;
     9  var $DirectoryId;
     10  var $TempName;
     11 
     12  function DetectMimeType()
     13  {
     14    // For proper mime-type detection php-pecl-Fileinfo package should be installed on *nix systems
     15    $FileInfo = new finfo(FILEINFO_MIME, '/usr/share/misc/magic');
     16    $Result = $FileInfo->file($FileName);
     17    //$FileInfo->close();
     18    return($Result);
     19  }
     20 
     21  function GetSize($Item)
     22  {
     23    $FileName = $this->GetFullName($Item);
     24    if(file_exists($FileName)) $Result = filesize($FileName);
     25      else $Result = 0;
     26    return($Result);
     27  }
     28 
     29  function GetFullName()
     30  {
     31    $ParentId = $this->Directory;
     32    while($ParenId != null)
     33    {
     34      $DbResult = $this->Database->select('FileDirectory', '*', 'Id='.$ParentId);
     35      $DbRow = $DbResult->fetch_assoc();
     36      $Path .= $DbRow['Name'].'/';
     37      $ParentId = $DbRow['Parent'];
     38    }     
     39    $Result = $this->UploadFileFolder.'/'.$Path.$File->Name;
     40    return($Result);
     41  }
     42 
     43  function GetExt()
     44  {
     45    return(substr($this->Name, 0, strpos($this->Name, '.') - 1));
     46  }
     47 
     48  function Delete()
     49  {
     50    if(file_exists($this->GetFullName())) unlink($this->GetFullName());
     51  }
     52 
     53  function GetContent()
     54  {
     55    if($this->TempName != '') $Content = file_get_contents($this->TempName);
     56      else $Content = file_get_contents($this->GetFullName());
     57    return($Content);
     58  }
     59}
    260
    361class TypeFile extends TypeBase
     
    765  var $DirectoryId;
    866 
    9   function __construct()
     67  function __construct($FormManager)
    1068  {
     69    parent::__construct($FormManager);
    1170    $this->FileDownloadURL = 'File.php';
    1271    $this->DirectoryId = null;
     
    1574  function OnView($Item)
    1675  {
    17     global $Database;
    18 
    19     $DbResult = $Database->query('SELECT `Name`, `Size` FROM `SystemFile` WHERE `Id`='.$Item['Value']);
    20     if($DbResult->num_rows > 0)
    21     {
    22       $DbRow = $DbResult->fetch_assoc();
    23       return('<a href="'.$this->FileDownloadURL.'?Id='.$Item['Value'].'">'.$DbRow['Name'].'</a> ('.HumanSize($DbRow['Size']).')');
    24     } else return('');
     76    $File = &$Item['Value'];
     77    return('<a href="'.$this->FileDownloadURL.'?Id='.$File->Id.'">'.
     78      $File.'</a> ('.HumanSize($File->Size).')');
    2579  }
    2680
     
    3084    // ini_set("upload_max_filesize", "100M");
    3185    // <input type="hidden" name="MAX_FILE_SIZE" value="10000000">
    32     $Output = '<input type="file" name="'.$Item['Name'].'" value="">';
     86    $File = &$Item['Value'];
     87    $Output = '<input type="file" name="'.$Item['Name'].'" value="'.$File->Name.'">';
    3388    return($Output);
    3489  }
     
    3691  function OnLoad($Item)
    3792  {
    38     global $Database, $Config;
    39 
    40     $Result = 0;
    41     print_r($_FILES);
    42     print_r($_POST);
     93    if(!is_object($Item['Value'])) $Item['Value'] = new DbFile();
     94    $File = &$Item['Value'];
    4395    if(array_key_exists($Item['Name'], $_FILES) and ($_FILES[$Item['Name']]['name'] != ''))
    4496    {
    45       if(file_exists($_FILES[$Item['Name']]['tmp_name']))
     97      $UploadFile = $_FILES[$Item['Name']];
     98      if(file_exists($UploadFile['tmp_name']))
    4699      {
    47         $FileName = substr($_FILES[$Item['Name']]['name'], strrpos($_FILES[$Item['Name']]['name'], '/'));
    48         $Database->insert('File', array('Name' => $FileName, 'Size' => filesize($_FILES[$Item['Name']]['tmp_name']),
    49            'Directory' => $this->DirectoryId));
    50         $Result = $Database->insert_id;
    51         if(!move_uploaded_file($_FILES[$Item['Name']]['tmp_name'], $this->UploadFileFolder.'/'.$Result))
    52           SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!');
     100        $File->Name = $UploadFile['name'];
     101        $File->Size = $UploadFile['size'];
     102        $File->TempName = $UploadFile['tmp_name'];
    53103      }
    54104    }
    55     return($Result);
     105    return($File);
    56106  }
     107 
     108  function OnLoadDb($Item)
     109  {
     110    if(!is_object($Item['Value'])) $Item['Value'] = new DbFile();
     111    $File = &$Item['Value'];
     112    $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id);
     113    if($DbResult->num_rows() > 0)
     114    {
     115      $DbRow = $DbResult->fetch_assoc();
     116      $File->Name = $DbRow['Name'];
     117      $File->Size = $DbRow['Size'];
     118      $File->Directory = $DbRow['Directory'];
     119    }
     120    return($File);
     121  }
     122 
     123  function OnSaveDb($Item)
     124  {
     125    if(!is_object($Item['Value'])) $Item['Value'] = new DbFile();
     126    $File = &$Item['Value'];
     127    $Properties = array('Name' => $File->Name,
     128      'Size' => $File->GetSize(), 'Directory' => $File->Directory);
     129    $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id);
     130    if($DbResult->num_rows() > 0)
     131    {
     132      $DbRow = $DbResult->fetch_assoc();
     133      if($File->TempName != '')
     134      {
     135        $FileName = $File->GetFullName();
     136        unlink($FileName);
     137      }
     138      $this->Database->update('File', 'Id='.$File->Id, $Properties);
     139    } else
     140    {
     141      $this->Database->insert('File', $Properties);
     142      $File->Id = $this->Database->insert_id;
     143    }
     144    if(!move_uploaded_file($File->TempName, $FileName))
     145      SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!');
     146  }
     147 
    57148}
    58149
  • trunk/Common/Form/Types/File/FileDownload.php

    r428 r502  
    11<?php
    22
    3 // For proper mime-type detection php-pecl-Fileinfo package should be installed on *nix systems
    4 function DetectMimeType($FileName)
    5 {
    6   $FileInfo = new finfo(FILEINFO_MIME, '/usr/share/misc/magic');
    7   $Result = $FileInfo->file($FileName);
    8   //$FileInfo->close();
    9   return($Result);
    10 }
    113
    124chdir('../..');
  • trunk/Common/Form/Types/OneToMany.php

    r501 r502  
    77  function OnView($Item)
    88  {
    9     $Type = $this->System->Type->TypeDefinitionList[$Item['Type']];
     9    $Type = $this->FormManager->Type->TypeDefinitionList[$Item['Type']];
    1010    if($Item['Value'] != '')
    1111    {
    1212      if(array_key_exists('View', $Type['Parameters'])) $Table = $Type['Parameters']['View'];
    1313        else $Table = $Type['Parameters']['Table'];
    14       $DbResult = $this->System->Database->query('SELECT '.$Type['Parameters']['Name'].
     14      $DbResult = $this->Database->query('SELECT '.$Type['Parameters']['Name'].
    1515        ' AS `Name` FROM '.$Table.' WHERE `'.
    1616        $Type['Parameters']['Id'].'`='.$Item['Value']);
  • trunk/Common/Form/Types/Type.php

    r501 r502  
    1717include(dirname(__FILE__).'/Hidden.php');
    1818include(dirname(__FILE__).'/File.php');
    19 include(dirname(__FILE__).'/FileContent.php');
    2019include(dirname(__FILE__).'/GPS.php');
    2120include(dirname(__FILE__).'/IPv4Address.php');
     
    5352      'Color' => array('Name' => 'Color', 'Class' => 'Color', 'ParentType' => '', 'Parameters' => array()),
    5453      'RandomHash' => array('Name' => 'RandomHash', 'Class' => 'RandomHash', 'ParentType' => '', 'Parameters' => array()),
    55       'FileContent' => array('Name' => 'FileContent', 'Class' => 'FileContent', 'ParentType' => '', 'Parameters' => array()),
    5654    );
    5755  }
  • trunk/Common/Version.php

    r501 r502  
    11<?php
    22
    3 $Revision = 501; // Subversion revision
    4 $DatabaseRevision = 501;
     3$Revision = 502; // Subversion revision
     4$DatabaseRevision = 502;
    55$ReleaseTime = '2013-03-10';
    66
  • 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  }
  • trunk/Modules/FinanceBankAPI/FinanceBankAPI.php

    r501 r502  
    22
    33include_once(dirname(__FILE__).'/FileImport.php');
     4include_once(dirname(__FILE__).'/ImportPS.php');
     5include_once(dirname(__FILE__).'/ImportFio.php');
    46
    57class ModuleFinanceBankAPI extends AppModule
     
    2729  {
    2830    parent::Start();
    29     $this->System->RegisterPage('finance', array('import' => 'PageFileImport'));
     31    $FormClass = array(
     32      'Title' => 'Import souborů s platbami',
     33      'Table' => 'FinanceBank',
     34      'SubmitText' => 'Načíst',
     35      'Items' => array(
     36        'BankAccount' => array('Type' => 'TBankAccount', 'Caption' => 'Bankovní účet', 'Default' => ''),
     37        'File' => array('Type' => 'File', 'Caption' => 'Soubor', 'Default' => ''),
     38      ),
     39    );
     40    $this->System->FormManager->RegisterClass('ImportBankFile', $FormClass);
     41    $this->System->RegisterPage('finance', array('import-api' => 'PageImportAPI',
     42      'import-soubor' => 'PageImportFile'));
    3043  } 
    3144 
  • trunk/Modules/IS/IS.php

    r501 r502  
    167167   
    168168    foreach($FormClass['Items'] as $ItemIndex => $FormItem)
    169     if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type) or
     169    if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
    170170      (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
    171171      ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
     172    {
    172173      $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
     174    }   
    173175    $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
    174176    if(!array_key_exists('DefaultSortColumn', $FormClass))
  • trunk/admin/Updates.php

    r500 r502  
    142142}
    143143
     144function UpdateTo502($Manager)
     145{
     146  $Manager->Execute("ALTER TABLE `FinanceBankAccount` ADD `LoginName` VARCHAR( 255 ) NOT NULL ");
     147  $Manager->Execute("ALTER TABLE `FinanceBankAccount` ADD `LoginPassword` VARCHAR( 255 ) NOT NULL");
     148  $Manager->Execute("ALTER TABLE `FinanceBankAccount` ADD `Currency` INT NOT NULL AFTER `Use` ,".
     149    "ADD INDEX ( `Currency` ) ");
     150  $Manager->Execute("INSERT INTO `ISMenuItem` (`Id` ,`Name` ,`Parent` ,`Table` ,`IconName`) ".
     151    "VALUES (NULL , 'Banka', '2', '', '');");
     152  $Manager->Execute("UPDATE `ISMenuItem` SET `Parent` = '51' WHERE `ISMenuItem`.`Id` =10; ".
     153    "UPDATE `ISMenuItem` SET `Parent` = '51' WHERE `ISMenuItem`.`Id` =48;".
     154    "UPDATE `ISMenuItem` SET `Parent` = '51' WHERE `ISMenuItem`.`Id` =50;");
     155}
     156
    144157$Updates = array(
    145158        491 => array('Revision' => 493, 'Function' => 'UpdateTo493'),
     
    150163  498 => array('Revision' => 499, 'Function' => 'UpdateTo499'),
    151164  499 => array('Revision' => 500, 'Function' => 'UpdateTo500'),
     165  500 => array('Revision' => 502, 'Function' => 'UpdateTo502'),
    152166);
    153167
  • trunk/form_classes.php

    r501 r502  
    1919{
    2020  $FormManager->Classes = array(
    21   'ImportBankFile' => array(
    22     'Title' => 'Import souborů s platbami',
    23     'Table' => 'FinanceBank',
    24     'SubmitText' => 'Načíst',
    25     'Items' => array(
    26       'BankAccount' => array('Type' => 'TBankAccount', 'Caption' => 'Bankovní účet', 'Default' => ''),
    27       'File' => array('Type' => 'File', 'Caption' => 'Soubor', 'Default' => ''),
    28     )
    29    ),       
    3021  'FinanceBank' => array(
    3122    'Title' => 'Banky',
     
    493484      'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''),
    494485      'TimeEnd' => array('Type' => 'Date', 'Caption' => 'Čas zrušení', 'Default' => ''),
     486      'Currency' => array('Type' => 'TCurrency', 'Caption' => 'Měna', 'Default' => ''),
     487      'LoginName' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno / token', 'Default' => ''),
     488      'LoginPassword' => array('Type' => 'String', 'Caption' => 'Přihlašovací heslo', 'Default' => ''),
    495489      'Operations' => array('Type' => 'TFinanceOperationListAccount', 'Caption' => 'Operace', 'Default' => ''),
     490    ),
     491    'ItemActions' => array(
     492      array('Caption' => 'Import plateb z banky', 'URL' => '/finance/import-api/?'),
     493      array('Caption' => 'Import plateb ze souboru', 'URL' => '/finance/import-soubor/?'),
    496494    ),
    497495  ),
     
    931929    'Table' => 'FinanceBankAccount',
    932930    'Id' => 'Id',
    933     'Name' => 'CONCAT(Comment, " (", Number, ")")',
     931    'Name' => 'CONCAT(`Comment`, " (", `Number`, "/", '.
     932      '(SELECT `FinanceBank`.`Code` FROM `FinanceBank` WHERE `FinanceBank`.`Id`=`FinanceBankAccount`.`Bank`), ")")',
    934933    'Filter' => '1',
    935934  ),
Note: See TracChangeset for help on using the changeset viewer.