<?php
date_default_timezone_set('Asia/Bangkok');
error_reporting(E_ALL);
ini_set('display_errors',0);
session_start();

// START & CONFIG
ob_start();
require 'setup/config.php';
$LANG =  'en';
// SET LANGUAGE
if (isset($_GET['lang'])){	
	$_SESSION['HTTP_ACCEPT_LANGUAGE'] = $_GET['lang'];
}
if (isset($_SESSION['HTTP_ACCEPT_LANGUAGE']) and file_exists('lang/' . $_SESSION['HTTP_ACCEPT_LANGUAGE'] . '.php')) {	
	if((@include 'lang/' . $_SESSION['HTTP_ACCEPT_LANGUAGE'] . '.php') === false){
		echo 'Caught exception: Translate file is wrong';
	}else{
		@include_once('lang/' . $_SESSION['HTTP_ACCEPT_LANGUAGE'] . '.php');
	}
} else {
	if((@include 'lang/' . $LANG . '.php') === false){
		echo 'Caught exception: Translate file is wrong';
	}else{
		@include_once('lang/' . $LANG . '.php');
	}
}
// INI VARs
$found = 0;                     	// MARKER HOW MANY HITS FOUND A SEARCH
$done = 0;                     		// MARKER HOW MANY ENTRYs ARE DONE
$msg = '';                    		// TOAST MESSAGE
$file = 'data/' . $TYPE . '.json';  // DATA FILE NAME

// LOGIN CHECK
$login = check_current_user_login($ARR_USERS, $SALT);
$currentuser = $login['user'];

$currencydate = date('Ymd');
if($_GET['currencydate'] != ''){
	$currencydate = $_GET['currencydate'];
}
$currency = json_decode(file_get_contents('data/Currency.json'), true);



if ($_GET['import'] != ''){
	$_SESSION['import'] = $_GET['import'];
}
if ($currencyUser == ''){
	$currencyUser = '1560829223';
}
if ($_GET['currency'] != ''){
	$currencyUser = $_GET['currency'];
	
	foreach ($currency as $r){
		if($currencyUser == $r['id']){
			$_SESSION['currencyUser'] = $r;
		}
	}
}
if($_SESSION['currencyUser'] == ''){
	foreach ($currency as $r){
		if($currencyUser == $r['id']){
			$_SESSION['currencyUser'] = $r;
		}
	}
}

//var_dump($login);
if ($login['status'] == 200) {
   
} else {
    header('location: login.php');
    exit;
}

$ip = getenv('HTTP_CLIENT_IP')?:
	getenv('HTTP_X_FORWARDED_FOR')?:
	getenv('HTTP_X_FORWARDED')?:
	getenv('HTTP_FORWARDED_FOR')?:
	getenv('HTTP_FORWARDED')?:
	getenv('REMOTE_ADDR'); 

file_put_contents('ipdata',$ip);


$tabs = json_decode(file_get_contents('data/Tabs.json'));
$user = json_decode(file_get_contents('data/User.json'));
$tabdocfull = $tabdoc = json_decode(file_get_contents('data/TabDoc.json'));
$tabfull = $tabs;
$Setting = json_decode(file_get_contents('data/Setting.json'));

if($currentuser->role == 'Operator' ){	
	if($currentuser->location == '总公司' && !in_array( $ip , explode(',',$Setting->ipmain)) && $Setting->ipmain != ''  ){
		header('location: login.php');exit;
	}
	if($currentuser->location == '越南' && !in_array( $ip , explode(',',$Setting->ipvn)) && $Setting->ipvn != '' ){
		header('location: login.php');exit;
	}	
	if($currentuser->location == '中国' && !in_array( $ip , explode(',',$Setting->ipcn)) && $Setting->ipcn != '' ){
		header('location: login.php');exit;
	}		
	if($currentuser->location == '泰国'  && !in_array( $ip , explode(',',$Setting->iptha)) && $Setting->iptha != '' ){
		header('location: login.php');exit;
	}		
}



if ($_SERVER['REQUEST_METHOD'] == 'POST' and $_POST['payment'] != '' and $_POST['classification'] != '' ) {
	 
	 if(count((array)$_FILES['fileupload']['name']) > 0){
		 foreach ($_FILES['fileupload']['name'] as $filekey => $fileu){
			if($_FILES['fileupload']['error'][$filekey] != 0 || strpos($_FILES['fileupload']['filetype'][$filekey],'application/octet-stream') !== false || strpos($fileu,'.php') !== false || strpos($fileu,'.html') !== false ){ continue; }
			
			 $filename_text = time().'_'.$fileu;
			 $filename[] = $fileu;
			 $filetype[] = $_FILES['fileupload']['type'][$filekey];
			 $filesize[] =  $_FILES['fileupload']['size'][$filekey];
			 $filetimeupload[] = time();
			 $filecreatebyid[] = $currentuser->id;
			 $filecreatebyname[] = $currentuser->name;
			 $filepath[] = $filename_text;
			 copy( $_FILES['fileupload']['tmp_name'][$filekey] , __DIR__.'/uploads/'.$filename_text );
		 }
		// print_r($_FILES['fileupload']);;die;
	 }
	if($_SESSION['import'] == 1 && $_POST['date'] != '' ){
		//
	}else{
		//$id = time();
	}
	if($currentuser->gm == 1){
		$id = strtotime(str_replace('.','-',$_POST['date']).' '.date('H:i:s'));
	}else{
		$id = strtotime(str_replace('.','-',$_POST['date']).' '.date('H:i:s'));
		if( $id < strtotime('-6 day') ){
			$id = strtotime('-5 day');
		}
	}
	$id = $id + $_POST['adf'];
    $formdata = array(
        'id' => $id
		//, 'date' => $_POST['date']
        , 'payment' => $_POST['payment']
        //, 'account' => $_POST['account']
        , 'department' => $_POST['department']
        , 'classification' => $_POST['classification']
        , 'charge' => $_POST['charge']
        , 'summary' => $_POST['summary']
		, 'amountincome' => str_replace(',','',$_POST['amountincome'])
		, 'amountpayout' => str_replace(',','',$_POST['amountpayout'])
		, 'payer' => $_POST['payer']
		, 'requestnumber' => $_POST['requestnumber']
		, 'documentnumber' => $_POST['documentnumber']
		, 'jobnumber' => $_POST['jobnumber']
		//, 'fee' => $_POST['fee']
		, 'billno' => $_POST['billno']
		, 'billto' => $_POST['billto']
		, 'vat' => $_POST['vat']
		, 'wht' => $_POST['wht']
		
		, 'remarks' => $_POST['remarks']
		, 'writtenoff' => $_POST['writtenoff']
		, 'location' => $_POST['location']
		, 'createbyname' => $currentuser->name
		, 'createbyid' => $currentuser->id		
		, 'filename' => $filename
		, 'filetype' => $filetype
		, 'filesize' => $filesize
		, 'filetimeupload' => $filetimeupload
		, 'filecreatebyid' => $filecreatebyid
		, 'filecreatebyname' => $filecreatebyname
		, 'filepath' => $filepath
    );
	$tabdocfull =  (array)$tabdocfull; 
	$tabdocfull[] = array(
		'iddoc' => $id,      
		'idtab' => $_POST['tabs'],
	);    
	$tabdocfull = array_values($tabdocfull);
	file_put_contents('data/TabDoc.json', json_encode($tabdocfull));
    $arr_data = array();
    if (file_exists($file)) {
        $jsondata = file_get_contents($file);
        $arr_data = json_decode($jsondata, true);
    }
    $arr_data[] = $formdata;
    $jsondata = json_encode($arr_data);
    if (file_put_contents($file, $jsondata)) {
        $msg = $i18n['Data successfully saved!'];
    } else {
        $msg = $i18n['ERROR &mdash; Data not saved!'];
    }
    header('location: index.php?msg=' . $msg);
	exit();
}
// CREATE DATA FILE IF NOT EXISTS
if (!is_file($file)) {
    file_put_contents($file, '');
}
// READ DATA
$newdata = array();
$data = json_decode(file_get_contents($file), true);
// HEADER
ob_end_flush();
include 'tpl/header.php';
?>

<script src="tpl/js/jquery-ui.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

<style>  
.tab-content { min-width: 100%; } .section.no-pad-bot { padding-bottom: 0; padding-top: 0; } tfoot td { padding: 7px 0px; } table.tablesorter tbody td, table.tablesorter thead tr th { border: 1px solid #ccc; } table.tablesorter thead tr th { background-color: #1b278a; color: #fff; } table.striped tr { cursor: pointer; } .navbar-fixed nav { padding: 0 30px; } table.tablesorter tbody td { vertical-align: middle; } table.tablesorter tbody td { padding: 0px; } .helper-text { display:none!important; } .input-field { position: relative; margin-top: 5px; margin-bottom: 5px; } #modal5 { min-width: 1150px; } .ui-resizable-se { display:none!important; } .ui-resizable-s { height: 10px; bottom: -5px; } li.disabled{ display:none; } #tabnameSave { position: relative; margin-right: 24px; transform: none; } .modal-fixed { width: 600px !important; } .nofulltext { display:block!important; height: 19px; overflow: hidden; width: calc(100% - 20px); float: left; word-break: break-all; } .fa-sort-down { width: 17px; float: left; } i.fas.fa-sort-down.active { transform: rotateX(180deg); margin-top: 8px; } .responsive-table .btn { line-height: 26px; height: 26px; } .JCLRgrips { display:none!important; } #toast-container{ left: 10px; right: auto; position: fixed; z-index: 1000; } .filtervendor .select-wrapper { position: absolute; top: 0px; } .filtervendor input { border: none!important; opacity: 0; } .filtervendor svg{ color:#ffffff!important; fill: rgba(255, 255, 255, 0.87)!important; } .filtervendor ul{ min-width: 250px; max-height: 350px; overflow: auto; } } .bsdbk ul li:first-child input , .bsdbk ul li:last-child input , .filtervendor ul li:first-child input { display:none; } .bsdbk ul li:first-child span:before , .bsdbk ul li:last-child span:before , .filtervendor ul li:first-child span:before { display:none; } .bsdbk ul li:first-child ,.bsdbk ul li:last-child , .filtervendor ul li:first-child { text-decoration: none; background-color: #26a69a!important; text-align: center; letter-spacing: .5px; -webkit-transition: background-color .2s ease-out; transition: background-color .2s ease-out; cursor: pointer; } .bsdbk ul li:first-child:hover , .bsdbk ul li:last-child:hover ,.filtervendor ul li:first-child:hover { background-color: #117d73!important; } .bsdbk ul li:first-child [type="checkbox"]+span:not(.lever) , .bsdbk ul li:last-child [type="checkbox"]+span:not(.lever) , .filtervendor ul li:first-child [type="checkbox"]+span:not(.lever) { color: #fff!important;padding-left:0px; } textarea.nofulltext{ border: none; resize: none; line-height: 21px; } table.tablesorter tbody tr:hover td { background: #fffadc; } thead .tr_total td { padding-top:3px; padding-bottom:3px; } th .dropdown-content li>a, .dropdown-content li>span { padding: 4px 10px; } th .dropdown-content li { min-height: 34px; line-height: 16px; } th.filtervendor ul { min-width: 315px; top: 53px!important; } .bsdbk { position: relative; } .bsdbk .select-wrapper { position: absolute; left: -30px; top: 10px; z-index: 1000; } .bsdbk .caret { width: 36px; height: 36px; fill: rgb(38, 166, 154); box-shadow: 0px 0px 3px #545454a6; } .bsdbk .select-wrapper input.select-dropdown { width: 30px; border: none; color: transparent; } .bsdbk .dropdown-content { min-width:250px; top: 45px!important; } .bsdbk .dropdown-content li { min-height: 20px; } /*PRELOADING------------ */ #overlayer { width:100%; height:100%; position:fixed; z-index:10000; background:rgba(0, 0, 0, 0.97); left:0px; filter:blur(4px); -o-filter:blur(4px); -ms-filter:blur(4px); -moz-filter:blur(4px); -webkit-filter:blur(4px); } .loader { display: inline-block; width: 30px; height: 30px; position: fixed; z-index:30000; border: 4px solid #Fff; top: 50%; animation: loader 2s infinite ease; left: 50%; top: 50%; transform: translate(-50%, -50%); } .loader-inner { vertical-align: top; display: inline-block; width: 100%; background-color: #fff; animation: loader-inner 2s infinite ease-in; } @keyframes loader { 0% { transform: rotate(0deg); } 25% { transform: rotate(180deg); } 50% { transform: rotate(180deg); } 75% { transform: rotate(360deg); } 100% { transform: rotate(360deg); } } @keyframes loader-inner { 0% { height: 0%; } 25% { height: 0%; } 50% { height: 100%; } 75% { height: 100%; } 100% { height: 0%; } } .some-css-class { left: 50%!important; transform: translateX(-50%); } table { /* Not required only for visualizing */ border-collapse: collapse; width: 100%; } table thead tr:nth-child(1) th { /* Important background-color: red; */ position: sticky; z-index: 100; top: 0; } .makesimilarlabel .caret{ margin-top: -25px; } .isleft{ width: 50px; height: 50px; position: fixed; left: 15px; top: 45%; z-index: 1000000; font-size: 54px; opacity: 0.2;cursor: pointer; } .isright{ width: 50px; height: 50px; position: fixed; right: 15px; top: 45%; z-index: 1000000; font-size: 54px; opacity: 0.2;cursor: pointer; } .isleft:hover , .isright:hover{ opacity: 0.5; } .isleft i , .isright i { } #toast-container { top: 10px; max-width: 100%; } .toast.rounded { border-radius: 24px; height: 30px; } .collapsible-body{ background: rgb(218, 219, 219); position: absolute; padding: 0px 15px 0px 5px!important; min-width: 300px; margin-top: 6px; } .ui-autocomplete { top: 134px!important; margin-left: -6px!important; max-height:500px; overflow:auto; } .ui-autocomplete li { border-bottom: 1px solid; cursor:pointer; padding-left: 10px!important; } .ui-autocomplete li:nth-child(even) { background: #f0f0f0; } .ui-autocomplete li:nth-child(even) { background: #eee; } #project::placeholder { /* Firefox, Chrome, Opera */ color: #000; } #project:-ms-input-placeholder { /* Internet Explorer 10-11 */ color:#000; } #project::-ms-input-placeholder { /* Microsoft Edge */ color:#000; } .classdash1:after { content:'-1'; }
</style>

<style>  
	.navbar-fixed {
		display:none;
	}
	body{
		overflow: hidden;
		background: transparent;
	}
	html{
		background: transparent;
	}
	.row {   
		margin-bottom: 0px;
	}
</style>  

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<div >
     
			
		<form method="POST" enctype="multipart/form-data" id="bifdnino" >
            <div class="row" style="padding-top:15px;" >				
					<div class="input-field col s2">
						<select name="date" id="dkasndlkas" >						
							<option value="<?php echo date('Y.m.d'); ?>" selected ><?php echo date('Y.m.d'); ?></option>
							<option value="<?php echo date('Y.m.d',strtotime('-1 day')); ?>" ><?php echo date('Y.m.d',strtotime('-1 day')); ?></option>
							<option value="<?php echo date('Y.m.d',strtotime('-2 day')); ?>" ><?php echo date('Y.m.d',strtotime('-2 day')); ?></option>
							<option value="<?php echo date('Y.m.d',strtotime('-3 day')); ?>" ><?php echo date('Y.m.d',strtotime('-3 day')); ?></option>
							<option value="<?php echo date('Y.m.d',strtotime('-4 day')); ?>" ><?php echo date('Y.m.d',strtotime('-4 day')); ?></option>
							<option value="<?php echo date('Y.m.d',strtotime('-5 day')); ?>" ><?php echo date('Y.m.d',strtotime('-5 day')); ?></option>
							<option value="<?php echo date('Y.m.d',strtotime('-6 day')); ?>" ><?php echo date('Y.m.d',strtotime('-6 day')); ?></option>
							<option value="<?php echo date('Y.m.d',strtotime('-7 day')); ?>" ><?php echo date('Y.m.d',strtotime('-7 day')); ?></option>
						</select>
						<label for="dkasndlkas"><?php echo $i18n["Date"]; ?></label>
						<span class="helper-text" data-error="Error" data-success="OK">
							Enter Charge Details
						</span>
					</div>					
				<div class="input-field col s2">
                    <select name="tabs" id="tabs" class="sandjnas" required >						
                        <?php 
                            foreach($tabs as $tab){
								if( $currentuser->gm != 1 && $tab->iduser != $currentuser->id && !in_array($tab->id,$currentuser->account) ) { continue; } 
                                ?> 
                                    <option location="<?php echo $tab->location; ?>" class="<?php if($tab->special == 1){?> isspeci <?php } ?> <?php if($tab->special2 == 1){?> isspeci2 <?php } ?>" value="<?php echo $tab->id ?>"><?php echo $tab->name ?></option>
                                <?php
                            }
                        ?>
                    </select>
                    <label for="tab"><?php echo $i18n["Accounting"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Select Accounting
                    </span>
                </div>	
                <div class="input-field col s1">                  
					<select name="payment" id="idpayment"  tabindex="-1">         
							<option value="收"><?php if($i18n["收"] != ''){ echo $i18n["收"]; }else{ echo '收'; } ?></option>                  
                       		<option value="付"><?php if($i18n["付"] != ''){ echo $i18n["付"]; }else{ echo '付'; } ?></option>
					</select>
                    <label for="idpayment"><?php echo $i18n["收/付"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Enter Payment
                    </span>
                </div>
				<div class="input-field col s1 isdepartmentform" style="display:none;" >
					<select name="department" id="department"   >  
							<option value="">----------</option>       
							<option value="越南">越南</option>    
							<option value="中国">中国</option>  
							<option value="泰国">泰国</option>  							
					</select>	
                    <label for="charge"><?php echo $i18n["部门"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Enter department
                    </span>
                </div>
				<div class="input-field col s2">
                    <select name="classification" id="classification"  tabindex="-1"  >           
							<option value="">----------</option>                
                       		<?php 
									$containers_op = $Setting->Container;
									$containers_op = explode(PHP_EOL,$containers_op );
                                    foreach($containers_op as $container_op ){
										$container_op = explode('|',$container_op );
										$container_op[0] = str_replace(array("\n","\r\n","\r",PHP_EOL,' '), '',$container_op[0]);										
										$container_op[1] = str_replace(array("\n","\r\n","\r",PHP_EOL,' '), '',$container_op[1]);
										$container_op[2] = str_replace(array("\n","\r\n","\r",PHP_EOL,' '), '',$container_op[2]);
                                        ?> 
                                            <option value="<?php echo $container_op[0]; ?>" color="<?php echo $container_op[1]; ?>" freetext="<?php echo $container_op[2]; ?>" ><?php if($i18n[$container_op[0]] != ''){ echo $i18n[$container_op[0]]; }else{ echo $container_op[0]; } ?></option>
                                        <?php
                                    }
                            ?>

					</select>
                    <label for="classification"><?php echo $i18n["费用归类"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Enter Cost classification
                    </span>
                </div>
				<div class="input-field col s2 charge" >
					<select name="charge" id="charge"  tabindex="-1" disabled >           
							<option value="">----------</option>                
                       		<?php 
									$subContainer = $Setting->subContainer;
									$subContainers = explode(PHP_EOL,$subContainer );
                                    foreach($subContainers as $subContainer ){
										$subContainer = explode('|',$subContainer );
										$subContainer[1] = str_replace(array("\n","\r\n","\r",PHP_EOL,' '), '',$subContainer[1]);
										if($subContainer[0] != $fgni){
											$fgni = $subContainer[0];
											$dhere = 1;
										}else{
											$dhere++;
										}
										$erjkik[$subContainer[1]] =  $dhere.'. ';
                                        ?> 
                                            <option class="<?php echo $subContainer[0]; ?>" value="<?php echo $subContainer[1]; ?>"><?php echo $dhere; ?> <?php if($i18n[$subContainer[1]] != ''){ echo $i18n[$subContainer[1]]; }else{ echo $subContainer[1]; } ?></option>
                                        <?php
                                    }
                            ?>
							<option  class="novalue" value=""></option>                
					</select>	
                    <label for="charge"><?php echo $i18n["费用明细"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Enter Charge Details
                    </span>
                </div>
				
				<div class="input-field col s2 chargefreetext" style="display:none;" >
					 <input 
                        value="" 
                        id="chargefreetext" 
                        name="charge" 
                        type="text" 
                        class="validate"    
						disabled
                        />
                    <label for="chargefreetext"><?php echo $i18n["费用明细"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Enter Charge Details
                    </span>
                </div>
				
				<div class="input-field col s2 inputisspeci2 " style="display:none;" >
					 <input 
                        value="" 
                        id="BillNo" 
                        name="billno" 
                        type="text" 
                        class="validate"    
						
                        />
                    <label for="BillNo"><?php echo $i18n["Bill No."]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                    </span>
                </div>
				
				<div class="input-field col s2 inputisspeci2 " style="display:none;" >
					
					<select name="billto" id="Billto"   >  
							<option value="">----------</option>       
							<option value="Vantrans">Vantrans</option>    
							<option value="Fubo-AV6207001">Fubo-AV6207001</option>  							
					</select>	
					
                    <label for="Billto"><?php echo $i18n["Bill To"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                    </span>
                </div>
				
				<div class="input-field col s2 inputisspeci2 " style="display:none;" >
					 <input 
						data-type='currency'
                        value="" 
                        id="vat" 
                        name="vat" 
                        type="text" 
                        class="validate"    
						placeholder="0.00"
                        />
                    <label for="vat"><?php echo $i18n["增值税"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                    </span>
                </div>
				<div class="input-field col s2 inputisspeci2 " style="display:none;" >
					 <input 
						data-type='currency'
                        value="" 
                        id="wht" 
                        name="wht" 
                        type="text" 
                        class="validate"    
						placeholder="0.00"
                        />
                    <label for="wht"><?php echo $i18n["预扣税"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                    </span>
                </div>
				
				<div class="input-field col s2">
                    <input 
                        value="" 
                        id="summary" 
                        name="summary" 
                        type="text" 
                        class="validate"                        
                        />
                    <label for="summary"><?php echo $i18n["摘要"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Enter Summary
                    </span>
                </div>
                <div class="input-field col s2">
                    <input 
						data-type='currency'
                        value="" 
                        id="amountincome" 
                        name="amountincome" 
                        type="text" 
                        class="validate" 
                         placeholder="0.00"
                        />
                    <label for="amountincome"><?php echo $i18n["收入金额"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Amount of income
                    </span>
                </div>
                <div class="input-field col s2">
                    <input 
						data-type='currency'
                        value="" 
                        id="amountpayout" 
                        name="amountpayout" 
                        type="text" 
                        class="validate" 
                         placeholder="0.00"
                        />
                    <label for="amountpayout"><?php echo $i18n["支出金额"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Amount of payout
                    </span>
                </div>
				<div class="input-field col s2">
                    <input 
                        value="" 
                        id="payer" 
                        name="payer" 
                        type="text" 
                        class="validate"                       
                        />
                    <label for="payer"><?php echo $i18n["收付款人"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Enter Payer
                    </span>
                </div>
                <div class="input-field col s2" >
                    <input 
                        value="" 
                        id="requestnumber" 
                        name="requestnumber" 
                        type="text" 
                        class="validate" 
                        />
                    <label for="requestnumber"><?php echo $i18n["催/请款单号"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                       Request number
                    </span>
                </div>
				<?php if(0 == 1){ ?>
                <div class="input-field col s3">
                    <input 
                        value="" 
                        id="jobnumber" 
                        name="jobnumber" 
                        type="text" 
                        class="validate"                        
                        />
                    <label for="jobnumber"><?php echo $i18n["工作号"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                       Job number
                    </span>
                </div>
				<?php } ?>
				<div class="input-field col s1" style="min-width: 157px;">
                    <input 
                        value="" 
                        id="documentnumber" 
                        name="documentnumber" 
                        type="text" 
                        class="validate"     
						placeholder=" "				
                        />
                    <label for="documentnumber" class="makesimilarlabel" style="z-index: 1000!important;" ><span style="margin-right:2px;" ><?php echo $i18n["凭证号"]; ?></span> 
						<label class="pure-material-checkbox">
						  <input type="checkbox"  value="1"  id="iscontinue"    >
						  <span style="padding-left: 20px;    z-index: 100000;"><?php echo $i18n["继续?"]; ?></span>
						</label>
						<select class="makesimilar"  ></select> </label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                       Document number
                    </span>
					<style>
						.makesimilarlabel .dropdown-trigger {
							    border: none!important;
								position: absolute!important;
								width: 50px!important;
								color: transparent!important;
								top: -29px;
								height: 30px!important;
								left: 120px;
								background: rgba(0, 0, 0, 0.12)!important;
								opacity:0.4;
						}
						.makesimilarlabel .dropdown-content{
								min-width:190px;
								top: 10px!important;
								 
						}
					</style>
                </div>               
				<div class="input-field col s1"  >
					<select name="writtenoff" id="writtenoff"   >  
							<option value="">----------</option>       
							<option value="是"><?php if($i18n["是"] != ''){ echo $i18n["是"]; }else{ echo '是'; } ?></option>    
							<option value="没有"><?php if($i18n["没有"] != ''){ echo $i18n["没有"]; }else{ echo '没有'; } ?></option>  							
					</select>	
                    <label for="charge"><?php echo $i18n["是否核销"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                        Is it written off?
                    </span>
                </div>
                <div class="input-field col s3" style="    max-width: 20%;" >
                    <input 
                        value="" 
                        id="remarks" 
                        name="remarks" 
                        type="text" 
                        class="validate"                        
                        />
                    <label for="remarks"><?php echo $i18n["备注"]; ?></label>
                    <span class="helper-text" data-error="Error" data-success="OK">
                       Remarks
                    </span>
                </div>
                			
				
				<div class="input-field col s2  ">
					<div class="file-field">
						<div class="btn btn-primary btn-sm float-left" style="padding: 3px;" >
							  <span><?php echo $i18n['Choose file']; ?></span>
							  <input type="file"  name="fileupload[]"  id="fileupload"  multiple="multiple" >
						</div>
						<div class="file-path-wrapper">
							  <input class="file-path validate" type="text" placeholder="<?php echo $i18n['Upload your file']; ?>">
						</div>
					</div>
				</div>	
				
            </div>
			  <input value="<?php echo $_GET['adf']; ?>" name="adf" type="hidden" />
        </form>		
    </div>
	
    <ul style="display:none;" class="tabs">
        <?php if ( $currentuser->gm == 1 || $currentuser->role == 'Finance' ) {  ?>   
                <button data-target="addNewTab" onclick="$('#addNewTab #id_tabname,#addNewTab #tab,#addNewTab #tabinfo').val('')" class="btn modal-trigger sdastr" style="margin-left:10px;margin-right:10px;"><i class="material-icons right" style="line-height:1.5;font-size: 25px;margin: 0;padding: 0;">add_circle_outline</i></button>
        <?php } ?>     
            <?php
              foreach($tabs as $tab){
				  if( $currentuser->gm != 1 && $currentuser->role != 'Finance' && $tab->iduser != $currentuser->id && !in_array($tab->id,$currentuser->account) && !in_array($tab->id,$currentuser->accountreadonly) ) { continue; } 
				  foreach($currency as $rcurrency){
						if($rcurrency['id'] == $tab->currency){
							$currencyname =  $rcurrency['currency'];
						} 	
				  }
                  if ( $currentuser->gm != 1 && $currentuser->role != 'Finance' ){	
						if(in_array($tab->id,$currentuser->accountreadonly)){
							echo '<li data-tab="tab-'.$tab->id.'" data-id="'.$tab->id.'" style="color: #222;    border-top: 3px solid #eeeeee;" class="tab-link">'.$tab->name.'('.$currencyname.')</li>';
						}else{
							echo '<li data-tab="tab-'.$tab->id.'" data-id="'.$tab->id.'" class="tab-link">'.$tab->name.'('.$currencyname.')</li>';
						}
                  }else{
                        foreach ($user as $us){
                            if ($us->id == $tab->iduser) {
                                $name = $us->name;             
	                   	break;
                            }
                        }
						  if ( $kk++ == 0){
							  $current= 'current';
						  }else{
							  $current= '';
						  }  
                       echo '<li data-tab="tab-'.$tab->id.'" balance="'.$tab->balance.'" data-id="'.$tab->id.'" location="'.$tab->location.'" name="'.$tab->name.'" info="'.$tab->info.'" currency="'.$tab->currency.'"  special="'.$tab->special.'"   special2="'.$tab->special2.'" class="tab'.$tab->id.' tab-link '.$current.'">'.$tab->name.'('.$currencyname.')<span class="tabdescription" style="display:none;" >'.$tab->tabdescription.'</span></li>';
					   echo '<button class="tab-'.$tab->id.' tabnameSave" id="tabnameSave" > <i class="material-icons">edit</i></button>                      
							<a href="#" onclick="if (confirm(\'Are you sure delete this account ?\')) { window.location.replace(\'?delete_tab='.$tab->id.'\');}" class="material-icons close tab-'.$tab->id.'">close</a>' ;
				  }
                }   
        ?>
        </ul>
	
    <?php
//foreach ($data as $key => $values) {       
//	$data2[$values['id']] = $values;
//}
//ksort($data2);
//$data = array_values($data2);
	

	$nextvalue1['越南'] =  substr( $nextvalue1['越南']+1001 , 1 , 3 );
	$nextvalue1['中国'] =  substr( $nextvalue1['中国']+1001 , 1 , 3 );
	$nextvalue1['泰国'] =  substr( $nextvalue1['泰国']+1001 , 1 , 3 );
	
	$nextvalue2['越南'] =  substr( $nextvalue2['越南']+1001 , 1 , 3 );
	$nextvalue2['中国'] =  substr( $nextvalue2['中国']+1001 , 1 , 3 );
	$nextvalue2['泰国'] =  substr( $nextvalue2['泰国']+1001 , 1 , 3 );
	
	$nextvalue3['越南'] =  substr( $nextvalue3['越南']+1001 , 1 , 3 );
	$nextvalue3['中国'] =  substr( $nextvalue3['中国']+1001 , 1 , 3 );	
	$nextvalue3['泰国'] =  substr( $nextvalue3['泰国']+1001 , 1 , 3 );
	
	echo '
	
		<input type="hidden" class="nextvalue1越南" value="'.$nextvalue1['越南'].'" />
		<input type="hidden" class="nextvalue1中国" value="'.$nextvalue1['中国'].'" />
		<input type="hidden" class="nextvalue1泰国" value="'.$nextvalue1['泰国'].'" />
		
		<input type="hidden" class="nextvalue2越南" value="'.$nextvalue2['越南'].'" />
		<input type="hidden" class="nextvalue2中国" value="'.$nextvalue2['中国'].'" />
		<input type="hidden" class="nextvalue2泰国" value="'.$nextvalue2['泰国'].'" />
		
		<input type="hidden" class="nextvalue3越南" value="'.$nextvalue3['越南'].'" />
		<input type="hidden" class="nextvalue3中国" value="'.$nextvalue3['中国'].'" />
		<input type="hidden" class="nextvalue3泰国" value="'.$nextvalue3['泰国'].'" />'.'<table><tr>'.$phieubosung.'</tr></table>';
?>

		
		
		
     
       
	</div>

	
<script type="text/javascript">

$(window).load(function() {
 
$("#classification option").each(function(){
			if($(this).attr('color') != ''){
				var adf = $(this).val();var color = $(this).attr('color');
				$(this).parents().eq(1).find('li').each(function(){
					if($(this).find('span').text() == adf){
						$(this).find('span').css('color',color);$(this).find('span').css('font-weight','bold');
					}
				});
			}
});

	
});
</script>

<script type="text/javascript">
$(function() {  	
	jQuery('.editmode').click(function(){
		jQuery('.frameedit').attr( 'src',jQuery(this).attr('ref'));
	});	
});

function closeiframe(){
	$('.modal-overlay').trigger('click');
}
function closeiframereload(){
	$('.modal-overlay').trigger('click');
	location.reload();
}
function changewidthframe(){
	$('.frameedit').css('height','510px');
}

$(document).ready(function () {
	$(this).bind("contextmenu", function(e) {
		e.preventDefault();
	});
	$( "body" ).delegate( '.searchresult' , "click", function() {
		var row = $(this).attr('row');
		$('.tab'+$(this).attr('tab')).trigger('click');
		$($(this).attr('row')).css('background','#c5d9ff');
		$([document.documentElement, document.body]).animate({
			scrollTop: $($(this).attr('row')).offset().top - 100
		}, 2000);
		setTimeout(function(){
			$(row).removeAttr('style');
		}, 7000);
		
	});
	$('.collapsible').collapsible();
	$('.isleft').click(function(){
		if($('.isreadder'+$(this).attr('nextread')).prev().hasClass('modal-trigger')){
			$('.isreadder'+$(this).attr('nextread')).prev().trigger('click');
		}
	});
	$('.isright').click(function(){
		if($('.isreadder'+$(this).attr('nextread')).next().hasClass('modal-trigger')){
			$('.isreadder'+$(this).attr('nextread')).next().trigger('click');
		}
	});
	$('.ranges li:last-child').text('搜寻');
	
	$("#bifdnino").submit(function(e){		
		var issubmit = 1 ;
		$('#overlayer,.loader').show();
		$('.ismoreadd').each(function(index){
			if(jQuery(this).hasClass('act')){ 
				var self = this;
				setTimeout(function () {
					$(self).find("iframe").contents().find("#bifdnino").submit();
					$(self).hide();$(self).removeClass('act');
				}, index*1500);
				issubmit = 0;
			}
		});
		if(issubmit == 0){
			e.preventDefault();
			setTimeout(function () { $("#bifdnino").submit(); }, 7500);
		}
	});
	
	$("#dsjdbksa").submit(function(e){
		if( $("#tabexport").val() == null ) {
			$('.bsdbk .select-dropdown').trigger('click');
			e.preventDefault();
		}
	});
	
	$("#tabexport").change(function(){
		var string = $(this).val();
		if(string.indexOf("clicktosearch") !== -1 ){
			jQuery(".reportrange2").trigger('click');
			$(this).prop('selected',false);
			$(this).val('[]');
			$("#tabexport").formSelect();
			
		}
		if(string.indexOf("-1") !== -1 ){
			$("#dsjdbksa").submit();
			setTimeout(function(){
				$("#tabexport").val('[]');
				$("#tabexport").formSelect();
			}, 2000);
		}
	});
	
	$(".shkabkasb").change(function(){
		jQuery('#vendor').val($(this).val()); 
		var string = $(this).val();
		if(string.indexOf("clicktosearch") !== -1 ){
			jQuery("#formfilter").submit();
		}
	});

	$(".nofulltext").each(function(){
		if($(this).text().length < 9 && $(window).width() >= 1400){
			$(this).next().hide();
		}		
		if($(this).text().length < 9 && $(window).width() < 1400){
			$(this).next().hide();
		}
	});
	$('.fa-sort-down').click(function(){
		if($(this).hasClass('active')){
			$(this).parents().eq(1).find('.nofulltext').removeAttr('style');
			$(this).parents().eq(1).find('.fa-sort-down').removeClass('active');
		}else{
			$(this).parents().eq(1).find('.nofulltext').css('height','auto');
			$(this).parents().eq(1).find('.fa-sort-down').addClass('active');
		}
	});
	
	$(".sandjnas").change(function(){
		if($( ".sandjnas option:selected" ).hasClass('isspeci')){
			$(".isdepartmentform").show();
		}else{
			$(".isdepartmentform").hide();
		}
		
		if($( ".sandjnas option:selected" ).hasClass('isspeci2')){
			$(".inputisspeci2").show();
		}else{
			$(".inputisspeci2").hide();
		}
	});
	$(".sandjnas").change();

	
	$('.tab-link').on('click',function(){
 
		 $("#documentnumber").val('');$("#classification").val('');
         $(".sandjnas").val($(this).attr("data-id")).change();
		 $("#acctiveaccount").val($(this).attr("data-id"));
		 $(".sandjnas").formSelect();
		 $("#classification").formSelect();
		 
		
	});
	$('.treopit').on('click',function(){
		$(".snmnln").text($(this).find('.tabdescription').text());
	});
	
	$(".tabnameSave").click(function(){		
		$(".sdastr").trigger("click");
		$("#addNewTab #currency").val($(this).prev().attr('currency'));
		$('#addNewTab #currency').formSelect();
		$("#addNewTab #id_tabname").val($(this).prev().attr('data-id'));
		$("#addNewTab #tab").val($(this).prev().attr('name'));
		$("#addNewTab #Balance").val($(this).prev().attr('balance'));
		$("#addNewTab #tabinfo").val($(this).prev().attr('info'));
		$("#addNewTab #tabdescription").val($(this).prev().find('.tabdescription').text());
		$("#addNewTab #aclocation").val($(this).prev().attr('location'));		
		$('#aclocation').formSelect();
		if($(this).prev().attr('special') == 1){
			$("#addNewTab #special").prop('checked',true);
		}else{
			$("#addNewTab #special").prop('checked',false);
		}
		
		if($(this).prev().attr('special2') == 1){
			$("#addNewTab #special2").prop('checked',true);
		}else{
			$("#addNewTab #special2").prop('checked',false);
		}
	});
	function pad (str, max) {
	  str = str.toString();
	  return str.length < max ? pad("0" + str, max) : str;
	}
	$(".makesimilar").change(function(){
		var str = $(this).val();
	
		var res = str.split("-");
		for ( var i = 2; i <= 999; i++){			
			if(!$('.'+res[0]+'-'+i<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> ).length ){
					$("#documentnumber").val(res[0]+'-'+i);
					$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="'+res[0]+'-'+i+'" >'+res[0]+'-'+i+'</td> ' );
					break;
			}
		}
		$("#documentnumber").attr('readonly','');
	});
	
	function pad (str, max) {
	  str = str.toString();
	  return str.length < max ? pad("0" + str, max) : str;
	}


	$("#classification").change(function(){
		$('#charge').val('');$("#documentnumber").val('');
		jQuery('.makesimilar').empty();
		jQuery('.makesimilar').formSelect();
		jQuery('#iscontinue').prop('checked',false);
		$("#documentnumber").removeAttr('readonly');
		if($(this).val() != ''){
			$('#charge').prop('disabled',false);
			$('#charge option').prop('disabled',true);
			if( $("#classification option:selected").attr('freetext') == 'freetext' ){
				$('.charge').hide();
				$('#chargefreetext,.chargefreetext').show();
				$('#chargefreetext').val('');
				$('#chargefreetext').prop('disabled',false);
			}else{
				$('.charge').show();
				$('#chargefreetext,.chargefreetext').hide();
				$('#chargefreetext').val('');
				$('#chargefreetext').prop('disabled',true);
				if( $('.'+$(this).val()).length ){
					$('.'+$(this).val()).prop('disabled',false);
				}else{
					$('.novalue').prop('disabled',false);
					$('.novalue').attr('value',$(this).val());
					$('.novalue').text($(this).val());
				}
				
			}
		}else{
			$('#charge').prop('disabled',true);
		}
		$('#charge').formSelect();
		
		var location = $( ".sandjnas option:selected" ).attr('location');
		if( $( ".sandjnas option:selected" ).hasClass('isspeci') && $("#department").val() != '' ){
			location = $("#department").val();
		}
		var tabvalue = $( ".sandjnas" ).val();
		var date = "<?php echo date("ym"); ?>"+'';		
		
		if($(this).val() == "管理费用"){			
			if(location == '越南'){
				var num = $( ".nextvalue1越南" ).val();	
					num = parseInt(num);				
				for ( ; num <= 999; num++){
					if( !$('.'+'VNG'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> ).length ){
						break;
					}
				}				
				$("#documentnumber").val('VNG'+date+pad(num, 3));				
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="tddocumentnumber管理费用越南 '+'VNG'+date+pad(num, 3)+'" >'+'VNG'+date+pad(num, 3)+'</td> ' );
				
			}
			if(location == '中国'){
				var num = $( ".nextvalue1中国" ).val();
				num = parseInt(num);		
				for ( ; num <= 999; num++){
					if( !$('.'+'CNG'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>).length ){
						break;
					}
				}				
				$("#documentnumber").val('CNG'+date+pad(num, 3));
				
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="tddocumentnumber管理费用中国 '+'CNG'+date+pad(num, 3)+'" >'+'CNG'+date+pad(num, 3)+'</td> ' );
			}
			if(location == '泰国'){
				var num = $( ".nextvalue1泰国" ).val();
				num = parseInt(num);
				for ( ; num <= 999; num++){
					if( !$('.'+'THG'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>).length ){
						break;
					}
				}				
				$("#documentnumber").val('THG'+date+pad(num, 3));				
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>) ).append( '<td class="tddocumentnumber管理费用泰国 '+'THG'+date+pad(num, 3)+'" >'+'THG'+date+pad(num, 3)+'</td> ' );
			}
			$("#documentnumber").attr('readonly','');
		}
		if($(this).val() == "应收账款"){ 
			if(location == '越南'){
				var num = $( ".nextvalue2越南" ).val();
				num = parseInt(num);				
				for ( ; num <= 999; num++){
					if( !$('.'+'VNS'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> ).length ){
						break;
					}
				}				
				$("#documentnumber").val('VNS'+date+pad(num, 3));
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="tddocumentnumber应收账款越南 '+'VNS'+date+pad(num, 3)+'" >'+'VNS'+date+pad(num, 3)+'</td> ' );
				
			}
			if(location == '中国'){
				var num = $( ".nextvalue2中国" ).val();
				num = parseInt(num);				
				for ( ; num <= 999; num++){
					if( !$('.'+'CNS'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> ).length ){
						break;
					}
				}		
				$("#documentnumber").val('CNS'+date+pad(num, 3));
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="tddocumentnumber应收账款中国 '+'CNS'+date+pad(num, 3)+'" >'+'CNS'+date+pad(num, 3)+'</td> ' );
				
			}
			if(location == '泰国'){
				var num = $( ".nextvalue2泰国" ).val();
				num = parseInt(num);				
				for ( ; num <= 999; num++){
					if( !$('.'+'THS'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> ).length ){
						break;
					}
				}		
				$("#documentnumber").val('THS'+date+pad(num, 3));
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="tddocumentnumber应收账款泰国 '+'THS'+date+pad(num, 3)+'" >'+'THS'+date+pad(num, 3)+'</td> ' );
				
			}
			$("#documentnumber").attr('readonly','');
		}		
		if($(this).val() == "应付账款"){			
			
			if(location == '越南'){
				var num = $( ".nextvalue3越南" ).val();
				num = parseInt(num);				
				for ( ; num <= 999; num++){
					if( !$('.'+'VNF'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> ).length ){
						break;
					}
				}		
				$("#documentnumber").val('VNF'+date+pad(num, 3));
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="tddocumentnumber应付账款越南 '+'VNF'+date+pad(num, 3)+'" >'+'VNF'+date+pad(num, 3)+'</td> ' );
				
			}
			if(location == '中国'){
				var num = $( ".nextvalue3中国" ).val();
				num = parseInt(num);				
				for ( ; num <= 999; num++){
					if( !$('.'+'CNF'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> ).length ){
						break;
					}
				}		
				$("#documentnumber").val('CNF'+date+pad(num, 3));
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="tddocumentnumber应付账款中国 '+'CNF'+date+pad(num, 3)+'" >'+'CNF'+date+pad(num, 3)+'</td> ' );
				
			}
			if(location == '泰国'){
				var num = $( ".nextvalue3泰国" ).val();
				num = parseInt(num);				
				for ( ; num <= 999; num++){
					if( !$('.'+'THF'+date+pad(num, 3)<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> ).length ){
						break;
					}
				}	
				$("#documentnumber").val('THF'+date+pad(num, 3));
				$( $('.formchiem'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>)).append( '<td class="tddocumentnumber应付账款泰国 '+'THF'+date+pad(num, 3)+'" >'+'THF'+date+pad(num, 3)+'</td> ' );
				
			}
			$("#documentnumber").attr('readonly','');
		}		
	});	
	<?php 	if ($currentuser->role == 'Finance' || $currentuser->gm == 1 ) { ?>
		jQuery(".bskue").each(function(){
			if( jQuery(this).attr('status') != 'pending' ){		
				jQuery(this).hide();
			}	
		});
	<?php }elseif ($currentuser->role == 'Manager'){ ?>
		jQuery(".bskue").each(function(){
			jQuery(this).hide();	
		});
	<?php }elseif ($currentuser->role == 'Operator'){ ?>
		jQuery(".bskue").each(function(){
			if( jQuery(this).attr('status') != '' ){		
				jQuery(this).hide();
			}		
		});
	<?php }	?>
	jQuery(".bskue").click(function(){
		if(jQuery(this).is(':checked')){	
			<?php 	if ($currentuser->role == 'Finance' || $currentuser->gm == 1 ) { ?>
				M.Toast.dismissAll();
				if( jQuery(this).attr('status') == 'pending' ){					
					M.toast({displayLength: 12000,html: "<button style='margin-right: 10px;' class='btn waves-effect waves-light mapproval'>Yes</button><button class='btn red waves-effect waves-light mdeny'>No</button>" });
				}else{
					jQuery(this).prop('checked',false);
					jQuery(this).prop('disabled',true);
				}
			<?php }elseif ($currentuser->role == 'Operator'){ ?>
				M.Toast.dismissAll();
				if( jQuery(this).attr('status') == '' ){					
					M.toast({displayLength: 12000,html: "<button style='width:100%;' class='btn waves-effect waves-light msendtoaproval '>发送</button>" });
				}else{
					jQuery(this).prop('checked',false);
					jQuery(this).prop('disabled',true);
				}
			<?php }	?>
		}
	});
	<?php if ($currentuser->role == 'Manager' || $currentuser->role == 'Operator') { ?>      
	jQuery(".tablesorter tbody tr").dblclick(function() {
		$('.modal-overlay').trigger("click");
		if($(this).find('.editmode').length){
			$('.frameedit').css('height','auto');
			$(this).find('.editmode').trigger('click').click();
			$('#modal5').modal('open'); 
		}else{
			alert("This order can\'t edit.");
		}	
	});
	<?php } ?>
	<?php if ($currentuser->gm == "1"  ){ ?>	
	$(".cllogcontent").click(function(){
		$(".logcontent").html($(this).find('span').html());
	});	
	<?php } ?>
	$('.sendtoaproval').click(function(){ 
			//if (confirm('Are you sure send to approval, can\'t modify after approval  ?')) {
				$("#fromsendtoaproval .iddoc").val($(this).attr('id'));
				$("#fromsendtoaproval").submit();
			//}
	});
	<?php if ($currentuser->role == "Operator"  ){ ?>	
	
		
		$( "body" ).delegate( ".msendtoaproval", "click", function() {
			var mapproval = '';
			$(".bskue").each(function(){
				if(jQuery(this).is(':checked')){
					if(mapproval == ''){
					mapproval += jQuery(this).val();
					}else{	
					mapproval += ','+jQuery(this).val();
					}
				}	
			});
			$("#fromsendtoaproval .iddoc").val(mapproval);
			$("#fromsendtoaproval").submit();
		});		
	<?php } ?>
	<?php if ($currentuser->role == "Manager"  || $currentuser->role == "Finance"  ){ ?>
		$('.approval').click(function(){
			if (confirm('Are you sure set to approval ?')) {
				$("#fromapproval .type").val('approval');
				$("#fromapproval .iddoc").val($(this).attr('id'));
				$("#fromapproval").submit();
			}
		});	
		$('.deny').click(function(){
			var newnote = window.prompt("Are you sure set to deny ?", "Reason Why");
			if ( newnote != '' ) {
				$("#fromapproval .note").val(newnote);
				$("#fromapproval .type").val('notapproval');
				$("#fromapproval .iddoc").val($(this).attr('id'));
				$("#fromapproval").submit();
			}
		});
		$( "body" ).delegate( ".mapproval", "click", function() {
				$("#fromapproval .type").val('approval');
				var mapproval = '';
				$(".bskue").each(function(){
					if(jQuery(this).is(':checked')){
						if(mapproval == ''){
						mapproval += jQuery(this).val();	
						}else{
						mapproval += ','+jQuery(this).val();
						}
					}	
				});
				$("#fromapproval .iddoc").val(mapproval);
				$("#fromapproval").submit();
		});
		$( "body" ).delegate( ".mdeny", "click", function() {	
				$("#fromapproval .type").val('notapproval');
				var mapproval = '';
				$(".bskue").each(function(){
					if(jQuery(this).is(':checked')){
						if(mapproval == ''){
						mapproval += jQuery(this).val();
						}else{	
						mapproval += ','+jQuery(this).val();
						}
					}	
				});
				$("#fromapproval .iddoc").val(mapproval);
				$("#fromapproval").submit();
		});	
	<?php } ?>	
	 <?php if ( $currentuser->gm == 1 || $currentuser->role == 'Finance' ) {  ?>   
		$('.tab-link').on('click',function(){
          //  $('.tabs button:not(.sdastr),.tabs a').hide();
		});
        $('.tab-link').on('dblclick',function(){
            var tab_id = $(this).attr('data-tab');
            $('.' + tab_id).css({"display":"block"});
           // $(this).css({"display":"none"});
        });
    <?php } ?>
	var arrlist2 = [];
	$("#iscontinue").change(function(){
		if($("#classification").val() == ''){
			alert('select <?php echo $i18n['费用归类']; ?> first ');
			jQuery('.makesimilar').empty();
			jQuery('.makesimilar').formSelect();
			jQuery('#iscontinue').prop('checked',false);
			return;
		}
		if(jQuery(this).is(':checked')){
			var location = $( ".sandjnas option:selected" ).attr('location');
			if( $( ".sandjnas option:selected" ).hasClass('isspeci') && $("#department").val() != '' ){
				location = $("#department").val();
			}
			var classification = $("#classification").val();
			if( classification == "管理费用"){			
				if(location == '越南'){
					var arr =  $('.tddocumentnumber管理费用越南'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> );
				}
				if(location == '中国'){
					var arr =  $('.tddocumentnumber管理费用中国'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> );
				}
				if(location == '泰国'){
					var arr =  $('.tddocumentnumber管理费用泰国'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> );
				}
			}
			if( classification == "应收账款"){ 
				if(location == '越南'){
					var arr =  $('.tddocumentnumber应收账款越南'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> );
				}
				if(location == '中国'){
					var arr =  $('.tddocumentnumber应收账款中国'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> );
				}
				if(location == '泰国'){
					var arr =  $('.tddocumentnumber应收账款泰国'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> );
				}
			}		
			if( classification == "应付账款"){			
				
				if(location == '越南'){
					var arr =  $('.tddocumentnumber应付账款越南'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> );
				}
				if(location == '中国'){
					var arr =  $('.tddocumentnumber应付账款中国'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?> );
				}
				if(location == '泰国'){
					var arr =  $('.tddocumentnumber应付账款泰国'<?php if($_GET['onlyform'] == 1) { ?> , window.parent.document <?php } ?>);
				}
			}
			jQuery('.makesimilar').empty();
			$('.asbkdbsak').empty();
			var arrlist = [];			
			jQuery(arr).each(function( index ) {
				//if(jQuery(this).text() != '' && arrlist.indexOf(jQuery(this).text()) == -1 ){
				jQuery(this).text($.trim(jQuery(this).text()));	
				var str = jQuery(this).text();
				if(jQuery(this).text() != ''){
					arrlist2.push(jQuery(this).text());
				}
				if(jQuery(this).text() != '' && arrlist.indexOf(jQuery(this).text()) == -1 && str.indexOf('-') == -1 ){
					//var text = jQuery(this).parents().eq(0).html();
					//text = text.replace(/td/g,'div');
					//text = text.replace(/div>/g,'div>  ');
					//jQuery('.asbkdbsak').append('<div class="is'+jQuery(this).text()+'" ><div style="width:300px;" >'+jQuery(this).parents().eq(2).find('.treopit td').html()+'</div><br>'+text+'</div>');
					//var str = jQuery(this).text();
					
					var totalnum = 1;
					for ( var i = 2; i <= 999; i++){
						if( $('.'+jQuery(this).text()+'-'+i, window.parent.document).length ){
							totalnum++;
						}else{
							break;
						}
					}
					var str = '('+totalnum+')';
					if(str == '(1)'){
						str = '';
					}
					jQuery('.makesimilar').append("<option  value='"+jQuery(this).text()+"' >"+jQuery(this).text()+" "+str+"</option>");
					arrlist.push(jQuery(this).text());
				}
			});
			
			var options = $('.makesimilar option');
			var arr = options.map(function(_, o) { return { t: $(o).text(), v: o.value }; }).get();
			arr.sort(function(o1, o2) { return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0; });
			options.each(function(i, o) {
			  o.value = arr[i].v;
			  $(o).text(arr[i].t);
			});
			
			jQuery('.makesimilar').formSelect();
			
			jQuery('.asbkdbsak button , .asbkdbsak select , .asbkdbsak i  , .asbkdbsak input , .asbkdbsak .modal-trigger').remove();
			jQuery('.asbkdbsak .nofulltext').removeClass('nofulltext');
			
			jQuery('.asbkdbsak a').attr('onclick','');
			jQuery('.makesimilarlabel .dropdown-trigger').css('opacity',1); 
			
			
	
		}else{
			jQuery('.makesimilarlabel .dropdown-trigger').css('opacity',0.4);
			jQuery('.makesimilar').empty();
			jQuery('.makesimilar').formSelect();
		}
	});
	
	
	$( "body" ).delegate( '.makesimilarlabel .select-dropdown.dropdown-content li' , "mouseover", function() {	
				// $('.toast.rounded').hide();
				 //M.Toast.dismissAll();
				// var isclass =  $(this).text();
				// isclass = isclass.split(" ");
				// M.toast({html: jQuery('.is'+isclass[0]).html(),  classes: 'rounded' , displayLength: 6000 , inDuration: 50 , outDuration: 50 });
			});

	$( "body" ).delegate( '.makesimilarlabel .select-dropdown.dropdown-content li' , "mouseout", function() {
				 $('.toast.rounded').hide();
				 //M.Toast.dismissAll();
			});

	$('.tab-link').each(function(){
		
	});
							
		$("input[data-type='currency']").each(function(){
			formatCurrency($(this)); 
		});
		$("input[data-type='currency']").on({
            keyup: function() {
            formatCurrency($(this));
        },
			blur: function() { 
			formatCurrency($(this), "blur");
        }
        });
        function formatNumber(n) {
            return n.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",")
        }
		function formatCurrency(input, blur) {                             
			var input_val = input.val(); 
			if (input_val === "" || input_val == "0.00") { return; }
				var original_len = input_val.length;
				var caret_pos = input.prop("selectionStart");
			if (input_val.indexOf(".") >= 0) {
				var decimal_pos = input_val.indexOf(".");
				var left_side = input_val.substring(0, decimal_pos);
				var right_side = input_val.substring(decimal_pos);
				left_side = formatNumber(left_side);
				right_side = formatNumber(right_side);
				if (blur === "blur") {
					// right_side += "00";
				}
				right_side = right_side.substring(0, 2);
				input_val =  left_side + "." + right_side;
			} else {
				input_val = formatNumber(input_val);
				input_val =  input_val;
				// final formatting
				if (blur === "blur") {
				//input_val += ".00";
				}
			}
			input.val(input_val);
			var updated_len = input_val.length;
			caret_pos = updated_len - original_len + caret_pos;
			input[0].setSelectionRange(caret_pos, caret_pos);
			}
});
</script>
<div style="display:none" class="asbkdbsak" ></div>
<?php if($_GET['onlyform'] != 1) { ?>
<table style="display:none" ><tr class="formchiem" > <tr><table>
<br>
<?php } ?>
	
<?php    
// FOOTER
include 'tpl/footer.php'; ?>