source: trunk/Modules/Finance/Import.php@ 523

Last change on this file since 523 was 523, checked in by chronos, 12 years ago
  • Upraveno: Záznam akcí Log předělán na aplikační modul.
  • Přidáno: Modul System a zobrazení seznamu dostupných modulů.
File size: 5.2 KB
Line 
1<?php
2
3class PageFinanceImportPayment extends Page
4{
5 var $FullTitle = 'Import plateb';
6 var $ShortTitle = 'Import plateb';
7 var $ParentClass = 'PageFinance';
8
9 function Show()
10 {
11 if(!$this->System->Modules['User']->CheckPermission('Finance', 'SubjectList')) return('Nemáte oprávnění');
12 if(array_key_exists('Operation', $_GET))
13 {
14 if($_GET['Operation'] == 'prepare') return($this->Prepare());
15 else if($_GET['Operation'] == 'insert') return($this->Insert());
16 else echo('Neplatná akce');
17 } else
18 {
19 $Output = 'Vložte CSV data z SYLK exportu Poštovní spořitelny';
20 $Output .= '<form action="?Operation=prepare" method="post">';
21 $Output .= '<textarea name="Source" cols="80" rows="20"></textarea><br/>';
22 $Output .= '<input type="submit" value="Analyzovat"/>';
23 $Output .= '</form>';
24 return($Output);
25 }
26 }
27
28 function Prepare()
29 {
30 $Finance = $this->System->Modules['Finance'];
31 $Data = explode("\n", $_POST['Source']);
32 foreach($Data as $Key => $Value)
33 {
34 $Value = str_replace('\"', '"', $Value);
35 $Data[$Key] = str_getcsv($Value, ',', '"', "\\");
36 //print_r($Data[$Key]);
37 foreach($Data[$Key] as $Key2 => $Value2)
38 {
39 if(substr($Data[$Key][$Key2], 0, 2) == '\"')
40 $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2);
41 }
42 }
43 $Header = array(
44 0 => 'datum zaúčtování',
45 1 => 'částka',
46 2 => 'měna',
47 3 => 'zůstatek',
48 4 => 'konstantní symbol',
49 5 => 'variabilní symbol',
50 6 => 'specifický symbol',
51 7 => 'označení operace',
52 8 => 'název protiúčtu',
53 9 => 'protiúčet',
54 10 => 'poznámka',
55 11 => '',
56 );
57 //print_r($Header);
58 //print_r($Data[0]);
59 //print_r($_POST['Source']);
60 //print_r($Data);
61
62 if($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV';
63 else
64 {
65 array_shift($Data);
66 $Automatic = '';
67 $Manual = '';
68 $Output = '<form action="?Operation=insert" method="post">';
69 $I = 0;
70 foreach($Data as $Key => $Value)
71 {
72 if(count($Value) <= 1) continue;
73 if($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna
74 $Time = explode('.', $Value[0]);
75 $Time = $Time[2].'-'.$Time[1].'-'.$Time[0];
76 $Money = $Value[1];
77 if(is_numeric($Value[5]))
78 {
79 $Subject = $Value[5] * 1;
80 $DbResult = $this->Database->query('SELECT Id FROM Subject WHERE Id='.$this->Database->real_escape_string($Subject));
81 if($DbResult->num_rows == 0) $Subject = '? ('.($Value[5] * 1).')';
82 } else
83 {
84 $Subject = '? ('.$Value[5].')';
85 }
86 if(!is_numeric($Subject))
87 {
88 $Mode = 'Ručně';
89 $Style = 'style="background-color: LightPink;" ';
90 } else
91 {
92 $Mode = 'Automaticky';
93 $Style = '';
94 }
95
96 if($Money < 0) $Text = 'Platba převodem';
97 else $Text = 'Přijatá platba';
98 $Automatic .= '<tr>'.
99 //'<td>'.$Mode.'</td>'.
100 '<td><input type="text" name="Date'.$I.'" value="'.$Time.'"/></td>'.
101 '<td><input type="text" '.$Style.'name="Subject'.$I.'" value="'.$Subject.'"/></td>'.
102 '<td>'.$Value[8].'</td>'.
103 '<td><input type="text" name="Money'.$I.'" value="'.$Money.'"/></td>'.
104 '<td><input type="text" name="Text'.$I.'" value="'.$Text.'"/></td>'.
105 '<td><input type="text" name="Taxable'.$I.'" value="1"/></td>'.
106 '<td><input type="text" name="Network'.$I.'" value="1"/></td>'.
107 '</tr><tr><td colspan="7">'.implode(', ', $Value).'</td></tr>';
108 $I++;
109 }
110 $Output .= '<table class="WideTable">'.
111 '<tr>'.
112 //'<th>Zpracování</th>'.
113 '<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>';
114 $Output .= $Automatic.'</table>';
115 $Output .= '<input type="hidden" name="ItemCount" value="'.$I.'"/>';
116 $Output .= '<input type="submit" value="Zpracovat"/></form>';
117 }
118 return($Output);
119 }
120
121 function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $DocumentLine)
122 {
123
124 $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
125 $this->Database->insert('FinanceOperation', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
126 }
127
128 function Insert()
129 {
130 $Finance = $this->System->Modules['Finance'];
131 $Output = '';
132
133 for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
134 {
135 if($_POST['Money'.$I] < 0) $DocumentLine = 4;
136 else $DocumentLine = 3;
137 $Date = explode('-', $_POST['Date'.$I]);
138 $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
139 $this->InsertMoney($_POST['Subject'.$I], $_POST['Money'.$I], 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
140 $Output .= $I.', ';
141 $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
142 }
143 return($Output);
144 }
145}
146
147?>
Note: See TracBrowser for help on using the repository browser.