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 .= '
'; $Output .= '
'; $Output .= ''; $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 = '
'; $I = 0; foreach($Data as $Key => $Value) { if(count($Value) <= 1) continue; if($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna $Time = explode('.', $Value[0]); $Time = $Time[2].'-'.$Time[1].'-'.$Time[0]; $Money = $Value[1]; if(is_numeric($Value[5])) { $Subject = $Value[5] * 1; $DbResult = $this->Database->query('SELECT Id FROM Subject WHERE Id='.$this->Database->real_escape_string($Subject)); if($DbResult->num_rows == 0) $Subject = '? ('.($Value[5] * 1).')'; } else { $Subject = '? ('.$Value[5].')'; } if(!is_numeric($Subject)) { $Mode = 'Ručně'; $Style = 'style="background-color: LightPink;" '; } else { $Mode = 'Automaticky'; $Style = ''; } if($Money < 0) $Text = 'Platba převodem'; else $Text = 'Přijatá platba'; $Automatic .= ''. //''.$Mode.''. ''. ''. ''.$Value[8].''. ''. ''. ''. ''. ''.implode(', ', $Value).''; $I++; } $Output .= ''. ''. //''. ''; $Output .= $Automatic.'
ZpracováníDatumVar. symbolProtiúčetČástka [Kč]TextZdanitelnéSíť
'; $Output .= ''; $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); } } ?>