Database = &$System->Database; $this->System = &$System; } function Import(): string { return ''; } function ImportFile($Content, $Ext) { } function PairOperations(): void { $Finance = &ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance; $DbResult = $this->Database->select('FinanceBankImport', '*', 'FinanceOperation IS NULL'); while ($DbRow = $DbResult->fetch_assoc()) { if (is_numeric($DbRow['VariableSymbol'])) { $DbResult2 = $this->Database->select('Subject', 'Id', 'Id='.$DbRow['VariableSymbol']); if ($DbResult2->num_rows == 1) { $DbRow2 = $DbResult2->fetch_assoc(); if ($DbRow['Value'] >= 0) { $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup'); } else { $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup'); } $Year = date('Y', MysqlDateToTime($DbRow['Time'])); $BillCode = ModuleDocument::Cast($this->System->GetModule('Document'))->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year); $this->Database->insert('FinanceOperation', array('Subject' => $DbRow2['Id'], 'Cash' => 0, 'ValueUser' => Abs($DbRow['Value']), 'Value' => 0, 'Taxable' => 1, 'BankAccount' => $DbRow['BankAccount'], 'Network' => 1, 'Time' => $DbRow['Time'], 'Text' => $DbRow['Description'], 'BillCode' => $BillCode, 'Group' => $FinanceGroup['Id'])); $Id = $this->Database->insert_id; $this->Database->update('FinanceBankImport', 'Id='.$DbRow['Id'], array('FinanceOperation' => $Id)); // Execute after insert event $Form = new Form($this->System->FormManager); $Form->SetClass('FinanceOperation'); $Form->LoadValuesFromDatabase($Id); if (array_key_exists('AfterInsert', $Form->Definition)) { $Class = $Form->Definition['AfterInsert'][0]; $Method = $Form->Definition['AfterInsert'][1]; $Form->Values = $Class->$Method($Form, $Id); } } } } } } class PageImportAPI extends Page { function __construct(System $System) { parent::__construct($System); $this->Title = 'Import plateb přes API'; $this->ParentClass = 'PageFinance'; } function Import(int $Id): string { $Output = ''; $DbResult = $this->Database->select('FinanceBankAccount', '*', 'Id='.$Id); $BankAccount = $DbResult->fetch_assoc(); $DbResult = $this->Database->select('FinanceBank', '*', 'Id='.$BankAccount['Bank']); $Bank = $DbResult->fetch_assoc(); $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')'."\n"; if ($Bank['Code'] == '2010') $Import = new ImportFio($this->System); else if ($Bank['Code'] == '0300') $Import = new ImportPS($this->System); else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován'); if (isset($Import)) { $Import->BankAccount = $BankAccount; $Output .= $Import->Import(); $Import->PairOperations(); } return $Output; } function Show(): string { if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Finance', 'SubjectList')) return 'Nemáte oprávnění'; $Output = $this->Import($_GET['i']); return $Output; } } class PageImportFile extends Page { function __construct(System $System) { parent::__construct($System); $this->Title = 'Import plateb ze souboru'; $this->ParentClass = 'PageFinance'; } function Show(): string { $Output = ''; if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('Finance', 'SubjectList')) return 'Nemáte oprávnění'; if (array_key_exists('Operation', $_GET)) { if ($_GET['Operation'] == 'prepare') $Output .= $this->Prepare(); else if ($_GET['Operation'] == 'insert') $Output .= $this->Insert(); else $Output .= 'Neplatná akce'; } else $Output .= $this->ShowForm(); return $Output; } function ShowForm(): string { $Form = new Form($this->System->FormManager); $Form->SetClass('ImportBankFile'); $Form->OnSubmit = '?Operation=prepare'; $Form->Values['BankAccount'] = $_GET['id']; $Output = $Form->ShowEditForm(); return $Output; } function Prepare() { $Form = new Form($this->System->FormManager); $Form->SetClass('ImportBankFile'); $Form->LoadValuesFromForm(); $File = $Form->Values['File']; $Output = $File->Name.'
'; $Output .= $File->GetFullName().'
'; $DbResult = $this->Database->select('FinanceBankAccount', '*', 'Id='.$Form->Values['BankAccount']); $BankAccount = $DbResult->fetch_assoc(); $DbResult = $this->Database->select('FinanceBank', '*', 'Id='.$BankAccount['Bank']); $Bank = $DbResult->fetch_assoc(); $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')'; if ($Bank['Code'] == '2010') $Import = new ImportFio($this->System); else if ($Bank['Code'] == '0300') $Import = new ImportPS($this->System); else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován'); $Import->BankAccount = $BankAccount; $Output .= $Import->ImportFile($File->GetContent(), $File->GetExt()); return $Output; } function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $Group): void { $Year = date('Y', $Time); $BillCode = ModuleDocument::Cast($this->System->GetModule('Document'))->GetNextDocumentLineNumberId( $Group['DocumentLine'], $Year); $this->Database->insert('FinanceOperation', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'ValueUser' => $Value, 'Value' => $Value * $Group['ValueSign'], 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode)); } function Insert(): string { $Finance = ModuleFinance::Cast($this->System->GetModule('Finance'))->Finance; $Output = ''; for ($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--) { if ($_POST['Money'.$I] >= 0) { $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_IN, 'FinanceOperationGroup'); } else { $FinanceGroup = $Finance->GetFinanceGroupById(OPERATION_GROUP_ACCOUNT_OUT, 'FinanceOperationGroup'); } $Date = explode('-', $_POST['Date'.$I]); $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]); $this->InsertMoney($_POST['Subject'.$I], Abs($_POST['Money'.$I]), 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $FinanceGroup); $Output .= $I.', '; ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('Finance', 'NewPaymentInserted'); } return $Output; } }