source: trunk/Modules/FinanceBankAPI/ImportPS.php@ 550

Last change on this file since 550 was 550, checked in by chronos, 12 years ago
  • Upraveno: Přepracována třída pro import plateb přes Fio API. Nyní se načítají položky přes CSV formát.
  • Přidáno: Import z Fio do tabulky FinanceBankImport a odsud pak pokud je nalezen variabilní symbol tak do FinanceOperation.
File size: 3.4 KB
Line 
1<?php
2
3class ImportPS extends BankImport
4{
5 function ImportFile($Content, $Ext)
6 {
7 if($Ext == 'txt') $this->ImportTxt($Content);
8 else if($Ext == 'cvs') $this->ImportCVS($Content);
9 }
10
11 function ImportTxt($Content)
12 {
13 $Finance = &$this->System->Modules['Finance'];
14 $Data = explode("\n", $Content);
15 }
16
17 function ImportCVS($Content)
18 {
19 $Finance = &$this->System->Modules['Finance'];
20
21 $Data = explode("\n", $Content);
22 foreach($Data as $Key => $Value)
23 {
24 $Value = str_replace('\"', '"', $Value);
25 $Data[$Key] = str_getcsv($Value, ',', '"', "\\");
26 //print_r($Data[$Key]);
27 foreach($Data[$Key] as $Key2 => $Value2)
28 {
29 if(substr($Data[$Key][$Key2], 0, 2) == '\"')
30 $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2);
31 }
32 }
33 $Header = array(
34 0 => 'datum zaúčtování',
35 1 => 'částka',
36 2 => 'měna',
37 3 => 'zůstatek',
38 4 => 'konstantní symbol',
39 5 => 'variabilní symbol',
40 6 => 'specifický symbol',
41 7 => 'označení operace',
42 8 => 'název protiúčtu',
43 9 => 'protiúčet',
44 10 => 'poznámka',
45 11 => '',
46 );
47
48 if($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV';
49 else
50 {
51 array_shift($Data);
52 $Automatic = '';
53 $Manual = '';
54 $Output = '<form action="?Operation=insert" method="post">';
55 $I = 0;
56 foreach($Data as $Key => $Value)
57 {
58 if(count($Value) <= 1) continue;
59 if($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna
60 $Time = explode('.', $Value[0]);
61 $Time = $Time[2].'-'.$Time[1].'-'.$Time[0];
62 $Money = $Value[1];
63 if(is_numeric($Value[5]))
64 {
65 $Subject = $Value[5] * 1;
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).')';
68 } else
69 {
70 $Subject = '? ('.$Value[5].')';
71 }
72 if(!is_numeric($Subject))
73 {
74 $Mode = 'Ručně';
75 $Style = 'style="background-color: LightPink;" ';
76 } else
77 {
78 $Mode = 'Automaticky';
79 $Style = '';
80 }
81
82 if($Money < 0) $Text = 'Platba převodem';
83 else $Text = 'Přijatá platba';
84 $Automatic .= '<tr>'.
85 //'<td>'.$Mode.'</td>'.
86 '<td><input type="text" name="Date'.$I.'" value="'.$Time.'"/></td>'.
87 '<td><input type="text" '.$Style.'name="Subject'.$I.'" value="'.$Subject.'"/></td>'.
88 '<td>'.$Value[8].'</td>'.
89 '<td><input type="text" name="Money'.$I.'" value="'.$Money.'"/></td>'.
90 '<td><input type="text" name="Text'.$I.'" value="'.$Text.'"/></td>'.
91 '<td><input type="text" name="Taxable'.$I.'" value="1"/></td>'.
92 '<td><input type="text" name="Network'.$I.'" value="1"/></td>'.
93 '</tr><tr><td colspan="7">'.implode(', ', $Value).'</td></tr>';
94 $I++;
95 }
96 $Output .= '<table class="WideTable">'.
97 '<tr>'.
98 //'<th>Zpracování</th>'.
99 '<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>';
100 $Output .= $Automatic.'</table>';
101 $Output .= '<input type="hidden" name="ItemCount" value="'.$I.'"/>';
102 $Output .= '<input type="submit" value="Zpracovat"/></form>';
103 }
104 }
105}
Note: See TracBrowser for help on using the repository browser.