source: trunk/Modules/FinanceBankAPI/ImportPS.php

Last change on this file was 929, checked in by chronos, 3 years ago
  • Modified: Removed commended out print_r and echo commands used only for debugging.
File size: 3.3 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 }
14
15 function ImportCVS($Content)
16 {
17 $Data = explode("\n", $Content);
18 foreach ($Data as $Key => $Value)
19 {
20 $Value = str_replace('\"', '"', $Value);
21 $Data[$Key] = str_getcsv($Value, ',', '"', "\\");
22
23 foreach ($Data[$Key] as $Key2 => $Value2)
24 {
25 if (substr($Data[$Key][$Key2], 0, 2) == '\"')
26 $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2);
27 }
28 }
29 $Header = array(
30 0 => 'datum zaúčtování',
31 1 => 'částka',
32 2 => 'měna',
33 3 => 'zůstatek',
34 4 => 'konstantní symbol',
35 5 => 'variabilní symbol',
36 6 => 'specifický symbol',
37 7 => 'označení operace',
38 8 => 'název protiúčtu',
39 9 => 'protiúčet',
40 10 => 'poznámka',
41 11 => '',
42 );
43
44 if ($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV';
45 else
46 {
47 array_shift($Data);
48 $Automatic = '';
49 $Manual = '';
50 $Output = '<form action="?Operation=insert" method="post">';
51 $I = 0;
52 foreach ($Data as $Key => $Value)
53 {
54 if (count($Value) <= 1) continue;
55 if ($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna
56 $Time = explode('.', $Value[0]);
57 $Time = $Time[2].'-'.$Time[1].'-'.$Time[0];
58 $Money = $Value[1];
59 if (is_numeric($Value[5]))
60 {
61 $Subject = $Value[5] * 1;
62 $DbResult = $this->Database->query('SELECT Id FROM Subject WHERE Id='.$this->Database->real_escape_string($Subject));
63 if ($DbResult->num_rows == 0) $Subject = '? ('.($Value[5] * 1).')';
64 } else
65 {
66 $Subject = '? ('.$Value[5].')';
67 }
68 if (!is_numeric($Subject))
69 {
70 $Mode = 'Ručně';
71 $Style = 'style="background-color: LightPink;" ';
72 } else
73 {
74 $Mode = 'Automaticky';
75 $Style = '';
76 }
77
78 if ($Money < 0) $Text = 'Platba převodem';
79 else $Text = 'Přijatá platba';
80 $Automatic .= '<tr>'.
81 //'<td>'.$Mode.'</td>'.
82 '<td><input type="text" name="Date'.$I.'" value="'.$Time.'"/></td>'.
83 '<td><input type="text" '.$Style.'name="Subject'.$I.'" value="'.$Subject.'"/></td>'.
84 '<td>'.$Value[8].'</td>'.
85 '<td><input type="text" name="Money'.$I.'" value="'.$Money.'"/></td>'.
86 '<td><input type="text" name="Text'.$I.'" value="'.$Text.'"/></td>'.
87 '<td><input type="text" name="Taxable'.$I.'" value="1"/></td>'.
88 '<td><input type="text" name="Network'.$I.'" value="1"/></td>'.
89 '</tr><tr><td colspan="7">'.implode(', ', $Value).'</td></tr>';
90 $I++;
91 }
92 $Output .= '<table class="WideTable">'.
93 '<tr>'.
94 //'<th>Zpracování</th>'.
95 '<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>';
96 $Output .= $Automatic.'</table>';
97 $Output .= '<input type="hidden" name="ItemCount" value="'.$I.'"/>';
98 $Output .= '<input type="submit" value="Zpracovat"/></form>';
99 }
100 }
101}
Note: See TracBrowser for help on using the repository browser.