System->User->CheckPermission('Finance', 'SubjectList')) return('Nemáte oprávnění'); if(array_key_exists('Operation', $_GET)) { if($_GET['Operation'] == 'prepare') return($this->Prepare()); else if($_GET['Operation'] == 'insert') return($this->Insert()); else echo('Neplatná akce'); } else { $Output = 'Vložte CSV data z SYLK exportu Poštovní spořitelny'; $Output .= '
'; return($Output); } } function Prepare() { $Finance = $this->System->Modules['Finance']; $Finance->LoadMonthParameters(0); $Data = explode("\n", $_POST['Source']); foreach($Data as $Key => $Value) { $Value = str_replace('\"', '"', $Value); $Data[$Key] = str_getcsv($Value, ',', '"', "\\"); //print_r($Data[$Key]); foreach($Data[$Key] as $Key2 => $Value2) { if(substr($Data[$Key][$Key2], 0, 2) == '\"') $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2); } } $Header = array( 0 => 'datum zaúčtování', 1 => 'částka', 2 => 'měna', 3 => 'zůstatek', 4 => 'konstantní symbol', 5 => 'variabilní symbol', 6 => 'specifický symbol', 7 => 'označení operace', 8 => 'název protiúčtu', 9 => 'protiúčet', 10 => 'poznámka', 11 => '', ); //print_r($Header); //print_r($Data[0]); //print_r($_POST['Source']); //print_r($Data); if($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV'; else { array_shift($Data); $Automatic = ''; $Manual = ''; $Output = ''; } return($Output); } function InsertMoney($Subject, $Value, $Cash, $Taxable, $Time, $Text, $DocumentLine) { $BillCode = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine); $this->Database->insert('FinanceOperation', array('Text' => $Text, 'Subject' => $Subject, 'Cash' => $Cash, 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time), 'Taxable' => $Taxable, 'BillCode' => $BillCode)); } function Insert() { $Finance = $this->System->Modules['Finance']; $Finance->LoadMonthParameters(0); $Output = ''; for($I = $_POST['ItemCount'] - 1; $I >= 0 ; $I--) { if($_POST['Money'.$I] < 0) $DocumentLine = 4; else $DocumentLine = 3; $Date = explode('-', $_POST['Date'.$I]); $Date = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]); $this->InsertMoney($_POST['Subject'.$I], $_POST['Money'.$I], 0, $_POST['Taxable'.$I], $Date, $_POST['Text'.$I], $DocumentLine); $Output .= $I.', '; $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'NewPaymentInserted'); } return($Output); } } ?>