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

Last change on this file since 537 was 537, checked in by chronos, 12 years ago
  • Upraveno: Neinicializovat finance při generování jakékoliv stránky, ale jen těch, které používají modul Finance.
  • Upraveno: Soubor finance.php byl odstraněn a obsah přesunut do Finance.php. Na systémech bez rozlišování velikosti písmen jména soubor nelze mít dva soubory o stejném jméně.
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->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 $Finance->LoadMonthParameters(0);
32 $Data = explode("\n", $_POST['Source']);
33 foreach($Data as $Key => $Value)
34 {
35 $Value = str_replace('\"', '"', $Value);
36 $Data[$Key] = str_getcsv($Value, ',', '"', "\\");
37 //print_r($Data[$Key]);
38 foreach($Data[$Key] as $Key2 => $Value2)
39 {
40 if(substr($Data[$Key][$Key2], 0, 2) == '\"')
41 $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2);
42 }
43 }
44 $Header = array(
45 0 => 'datum zaúčtování',
46 1 => 'částka',
47 2 => 'měna',
48 3 => 'zůstatek',
49 4 => 'konstantní symbol',
50 5 => 'variabilní symbol',
51 6 => 'specifický symbol',
52 7 => 'označení operace',
53 8 => 'název protiúčtu',
54 9 => 'protiúčet',
55 10 => 'poznámka',
56 11 => '',
57 );
58 //print_r($Header);
59 //print_r($Data[0]);
60 //print_r($_POST['Source']);
61 //print_r($Data);
62
63 if($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV';
64 else
65 {
66 array_shift($Data);
67 $Automatic = '';
68 $Manual = '';
69 $Output = '<form action="?Operation=insert" method="post">';
70 $I = 0;
71 foreach($Data as $Key => $Value)
72 {
73 if(count($Value) <= 1) continue;
74 if($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna
75 $Time = explode('.', $Value[0]);
76 $Time = $Time[2].'-'.$Time[1].'-'.$Time[0];
77 $Money = $Value[1];
78 if(is_numeric($Value[5]))
79 {
80 $Subject = $Value[5] * 1;
81 $DbResult = $this->Database->query('SELECT Id FROM Subject WHERE Id='.$this->Database->real_escape_string($Subject));
82 if($DbResult->num_rows == 0) $Subject = '? ('.($Value[5] * 1).')';
83 } else
84 {
85 $Subject = '? ('.$Value[5].')';
86 }
87 if(!is_numeric($Subject))
88 {
89 $Mode = 'Ručně';
90 $Style = 'style="background-color: LightPink;" ';
91 } else
92 {
93 $Mode = 'Automaticky';
94 $Style = '';
95 }
96
97 if($Money < 0) $Text = 'Platba převodem';
98 else $Text = 'Přijatá platba';
99 $Automatic .= '<tr>'.
100 //'<td>'.$Mode.'</td>'.
101 '<td><input type="text" name="Date'.$I.'" value="'.$Time.'"/></td>'.
102 '<td><input type="text" '.$Style.'name="Subject'.$I.'" value="'.$Subject.'"/></td>'.
103 '<td>'.$Value[8].'</td>'.
104 '<td><input type="text" name="Money'.$I.'" value="'.$Money.'"/></td>'.
105 '<td><input type="text" name="Text'.$I.'" value="'.$Text.'"/></td>'.
106 '<td><input type="text" name="Taxable'.$I.'" value="1"/></td>'.
107 '<td><input type="text" name="Network'.$I.'" value="1"/></td>'.
108 '</tr><tr><td colspan="7">'.implode(', ', $Value).'</td></tr>';
109 $I++;
110 }
111 $Output .= '<table class="WideTable">'.
112 '<tr>'.
113 //'<th>Zpracování</th>'.
114 '<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>';
115 $Output .= $Automatic.'</table>';
116 $Output .= '<input type="hidden" name="ItemCount" value="'.$I.'"/>';
117 $Output .= '<input type="submit" value="Zpracovat"/></form>';
118 }
119 return($Output);
120 }
121
122 function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $DocumentLine)
123 {
124
125 $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
126 $this->Database->insert('FinanceOperation', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
127 }
128
129 function Insert()
130 {
131 $Finance = $this->System->Modules['Finance'];
132 $Finance->LoadMonthParameters(0);
133 $Output = '';
134
135 for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
136 {
137 if($_POST['Money'.$I] < 0) $DocumentLine = 4;
138 else $DocumentLine = 3;
139 $Date = explode('-', $_POST['Date'.$I]);
140 $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
141 $this->InsertMoney($_POST['Subject'.$I], $_POST['Money'.$I], 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
142 $Output .= $I.', ';
143 $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
144 }
145 return($Output);
146 }
147}
148
149?>
Note: See TracBrowser for help on using the repository browser.