source: trunk/Modules/FinanceBankAPI/FileImport.php@ 502

Last change on this file since 502 was 502, checked in by chronos, 12 years ago
  • 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.
File size: 4.2 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Common/Global.php');
4
5class FileImport
6{
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';
54
55 function Show()
56 {
57 $Output = '';
58 if(!$this->System->Modules['User']->CheckPermission('Finance', 'SubjectList')) return('Nemáte oprávnění');
59 if(array_key_exists('Operation', $_GET))
60 {
61 if($_GET['Operation'] == 'prepare') $Output .= $this->Prepare();
62 else if($_GET['Operation'] == 'insert') $Output .= $this->Insert();
63 else $Output .= 'Neplatná akce';
64 } else $Output .= $this->ShowForm();
65 return($Output);
66 }
67
68 function ShowForm()
69 {
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();
75 return($Output);
76 }
77
78 function Prepare()
79 {
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();
89
90 $DbResult = $this->Database->select('FinanceBank', '*', 'Id='.$BankAccount['Bank']);
91 $Bank = $DbResult->fetch_assoc();
92 $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')';
93
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
100 return($Output);
101 }
102
103 function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $DocumentLine)
104 {
105
106 $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine);
107 $this->Database->insert('FinanceOperation', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode));
108 }
109
110 function Insert()
111 {
112 $Finance = $this->System->Modules['Finance'];
113 $Output = '';
114
115 for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--)
116 {
117 if($_POST['Money'.$I] < 0) $DocumentLine = 4;
118 else $DocumentLine = 3;
119 $Date = explode('-', $_POST['Date'.$I]);
120 $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
121 $this->InsertMoney($_POST['Subject'.$I], $_POST['Money'.$I], 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine);
122 $Output .= $I.', ';
123 $this->System->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted');
124 }
125 return($Output);
126 }
127}
128
129?>
Note: See TracBrowser for help on using the repository browser.