<?php
// DISPLAY ALL ERRORS
//error_reporting(E_ALL);
ini_set('display_errors', 0);
session_start();
// START & CONFIG
ob_start();
require 'setup/config.php';

$LANG =  'cn';
// 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 = '../Docs/data/Customer.json'; // DATA FILE NAME
$file2 = '../Docs/data/BlacklistCustomer.json'; 
// LOGIN CHECK

$login = check_current_user_login($ARR_USERS, $SALT);
$currentuser = $login['user'];
//var_dump($login);
if ($login['status'] == 200) {
    
} else {
    header('location: login.php');
    exit;
}
// DELETE ENTRY IF DEL LINK IS CLICKED
if (@$_GET['delete_id'] != '') {
    $data = json_decode(file_get_contents($file), true);
    
    foreach ( $data as $key => $r  ){
        if($r['id'] == @$_GET['delete_id']){
            unset($data[$key]);
        }
    }
    
    $convert_array_to_json = array_values($data);
    $write_json = json_encode($convert_array_to_json);
    file_put_contents($file, $write_json);
    header('location: customer.php?msg=' . $i18n['Entry successfully deleted.']);
    
}
if (@$_GET['delete_id1'] != '') {
    $data = json_decode(file_get_contents($file2), true);
    
    foreach ( $data as $key => $r  ){
        if($r['id'] == @$_GET['delete_id1']){
            unset($data[$key]);
        }
    }
    
    $convert_array_to_json = array_values($data);
    $write_json = json_encode($convert_array_to_json);
    file_put_contents($file2, $write_json);
    header('location: customer.php?msg=' . $i18n['Entry successfully deleted.']);
    
}
// READ DATA
$user = json_decode(file_get_contents('data/User.json'));
$data = json_decode(file_get_contents($file), true);
$data2 = json_decode(file_get_contents($file2), true);
$currency = json_decode(file_get_contents('data/Currency.json'), true);

$stt = 1;
foreach ($data as $r){
	if( $_POST['location'] == $r['location']  ){
		$stt++;
	}
}
$stt =  $_POST['location'].str_pad( $stt , 5, '0', STR_PAD_LEFT); 

if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['name'] != ''  && $_POST['acronym'] != '' && $_POST['blacklist'] == '1'  ) {
	$id = time();
	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] , '../Docs/uploads/'.$filename_text );
			 }
			
	}
		
	if($_POST['id'] == ''){	
   	
        $formdata = array(
        'id' => $id
		, 'customerid' => $stt 
        , 'name' => $_POST['name']
        , 'acronym' => $_POST['acronym']
        , 'liabilities' => $_POST['liabilities']
        , 'currency' => $_POST['currency']
		, 'account' => $_POST['account']
		, 'remark' => $_POST['remark']
		, 'createdby' => $currentuser->name
		, 'createddate' => $id
		, 'modifieddate' => '' 				
		, 'filename' => $filename
		, 'filetype' => $filetype
		, 'filesize' => $filesize
		, 'filetimeupload' => $filetimeupload
		, 'filecreatebyid' => $filecreatebyid
		, 'filecreatebyname' => $filecreatebyname
		, 'filepath' => $filepath
		);
		$arr_data = array();
    	if (file_exists($file2)) {
        	$jsondata = file_get_contents($file2);
        	$arr_data = json_decode($jsondata, true);
    	}
		$arr_data[] = $formdata;

	}else{
		$arr_data = array();
    		if (file_exists($file2)) {
        		$jsondata = file_get_contents($file2);
        		$arr_data = json_decode($jsondata, true);
    		}
		foreach ($arr_data as $key => $r){
			if($r['id'] == $_POST['id']){
				// write logs
				foreach ($arr_data[$key] as $keylog => $logs ){
					if($keylog == 'name' || $keylog == 'acronym' || $keylog == 'currency' || $keylog == 'account' || $keylog == 'remark' 
					|| $keylog == 'contracttermsstart' || $keylog == 'contracttermsend' ){
						if(is_array($_POST[$keylog])){
							$_POST[$keylog] = implode(', ',$_POST[$keylog]);
							$logs = implode(', ',$logs);
						}
						if( $_POST[$keylog] != $logs){
								
								if($_POST[$keylog] == ''){ 
									$textlog = date('Y-m-d H:i:s').' - '.$currentuser->name.': changed '.$keylog.' from '.$logs.' to empty'  ;
								}else{
									$textlog = date('Y-m-d H:i:s').' - '.$currentuser->name.': changed '.$keylog.' from '.$logs.' to '.$_POST[$keylog]  ;
								}
								file_put_contents('logs/'.$_POST['id'],file_get_contents('logs/'.$_POST['id']).$textlog.PHP_EOL);
						}
					
					}
				}
				$arr_data[$key]['name'] = $_POST['name'];
				$arr_data[$key]['acronym'] = $_POST['acronym'];
				$arr_data[$key]['currency'] = $_POST['currency'];
				$arr_data[$key]['account'] = $_POST['account'];
				$arr_data[$key]['remark'] = $_POST['remark'];
				$arr_data[$key]['modifieddate'] = $id;
				$arr_data[$key]['modifiedby'] = $currentuser->name;
				$arr_data[$key]['contracttermsstart'] = $_POST['contracttermsstart'];
				$arr_data[$key]['contracttermsend'] = $_POST['contracttermsend'];
				if(count((array)$filename) > 0){
					$arr_data[$key]['filename'] = $filename;
					$arr_data[$key]['filetype'] = $filetype;
					$arr_data[$key]['filesize'] = $filesize;
					$arr_data[$key]['filetimeupload'] = $filetimeupload;
					$arr_data[$key]['filecreatebyid'] = $filecreatebyid;
					$arr_data[$key]['filecreatebyname'] = $filecreatebyname;
					$arr_data[$key]['filepath'] = $filepath;
				}
			}
		}
	}
  
    $jsondata = json_encode($arr_data);

    if (file_put_contents($file2, $jsondata)) {
        $msg = $i18n['Data successfully saved!'];
    } else {
        $msg = $i18n['ERROR &mdash; Data not saved!'];
    }
    header('location: customer.php?msg=' . $msg);
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $_GET['msg'] = $i18n['All fields are required!'];
}

if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['name'] != ''  && $_POST['acronym'] != '' && $_POST['blacklist'] == '0'  ) {
	$id = time();
	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] , '../Docs/uploads/'.$filename_text );
			 }
			
	}
	for($i = 0; $i < 5 ; $i++){
		if($_POST['cusfrom'][$i] == 'addnew'){ 
			$Setting = json_decode(file_get_contents('../Docs/data/Setting.json'));
			$newline = PHP_EOL.$_POST['departurefrom'][$i].'|'.$_POST['departuretext'][$i].'|'.$_POST['departuretext'][$i];
			$Setting->Departure .= $newline;		
			file_put_contents('../Docs/data/Setting.json',json_encode($Setting));
			$_POST['cusfrom'][$i] = $_POST['departuretext'][$i];
		}
		if($_POST['custo'][$i] == 'addnew'){
			$Setting = json_decode(file_get_contents('../Docs/data/Setting.json'));
			$newline = PHP_EOL.$_POST['arrivalfrom'][$i].'|'.$_POST['arrivaltext'][$i].'|'.$_POST['arrivaltext'][$i];
			$Setting->Arrival .= $newline;
			file_put_contents('../Docs/data/Setting.json',json_encode($Setting));
			$_POST['custo'][$i] = $_POST['arrivaltext'][$i];
		}
	}
	if($_POST['id'] == ''){	
   	
        $formdata = array(
        'id' => $id
		, 'customerid' => $stt 
        , 'name' => $_POST['name']
        , 'acronym' => $_POST['acronym']
        , 'invoicetype' => $_POST['invoicetype']
        , 'location' => $_POST['location']
		, 'agent' => $_POST['Agent']
		, 'createdby' => $currentuser->name
		, 'createddate' => $id
		, 'modifieddate' => '' 
		, 'dayofmonth' => $_POST['dayofmonth']
		, 'contracttermsstart' => $_POST['contracttermsstart']
		, 'contracttermsend' =>  $_POST['contracttermsend']
		, 'type' =>  $_POST['type']		
		, 'paymentpath' =>  $_POST['paymentpath']	
		, 'remark' => $_POST['remark']
		, 'cusfrom' => $_POST['cusfrom']		
		, 'custo' => $_POST['custo']		
		, 'cusprice' => $_POST['cusprice']		
		, 'cuscurrency' => $_POST['cuscurrency']				
		, 'filename' => $filename
		, 'filetype' => $filetype
		, 'filesize' => $filesize
		, 'filetimeupload' => $filetimeupload
		, 'filecreatebyid' => $filecreatebyid
		, 'filecreatebyname' => $filecreatebyname
		, 'filepath' => $filepath
		);
  	$arr_data = array();
    	if (file_exists($file)) {
        	$jsondata = file_get_contents($file);
        	$arr_data = json_decode($jsondata, true);
    	}
   	$arr_data[] = $formdata;

	}else{
		$arr_data = array();
    		if (file_exists($file)) {
        		$jsondata = file_get_contents($file);
        		$arr_data = json_decode($jsondata, true);
    		}
		foreach ($arr_data as $key => $r){
			if($r['id'] == $_POST['id']){
				
				foreach ($arr_data[$key] as $keylog => $logs ){
					if($keylog == 'name' || $keylog == 'acronym' || $keylog == 'invoicetype' || $keylog == 'location' || $keylog == 'agent' 
					|| $keylog == 'contracttermsstart' || $keylog == 'contracttermsend'|| $keylog == 'paymentpath' || $keylog == 'remark' 
					|| $keylog == 'dayofmonth' 	|| $keylog == 'type' 	|| $keylog == 'cusfrom' || $keylog == 'custo' 	|| $keylog == 'cusprice' 
					|| $keylog == 'cuscurrency' ){
						$textdata = $_POST[$keylog];
						if(is_array($_POST[$keylog])){
							$textdata = implode(', ',$_POST[$keylog]);
							$logs = implode(', ',$logs);
						}
						if( $textdata != $logs){
								
								if($_POST[$keylog] == ''){ 
									$textlog = date('Y-m-d H:i:s').' - '.$currentuser->name.': changed '.$keylog.' from '.$logs.' to empty'  ;
								}else{
									$textlog = date('Y-m-d H:i:s').' - '.$currentuser->name.': changed '.$keylog.' from '.$logs.' to '.$textdata  ;
								}
								file_put_contents('logs/'.$_POST['id'],file_get_contents('logs/'.$_POST['id']).$textlog.PHP_EOL);
						}
					
					}
				}
				
				$arr_data[$key]['name'] = $_POST['name'];
				$arr_data[$key]['acronym'] = $_POST['acronym'];
				$arr_data[$key]['invoicetype'] = $_POST['invoicetype'];
				$arr_data[$key]['location'] = $_POST['location'];
				$arr_data[$key]['agent'] = $_POST['Agent'];
				$arr_data[$key]['paymentpath'] = $_POST['paymentpath'];
				$arr_data[$key]['modifieddate'] = $id;
				$arr_data[$key]['modifiedby'] = $currentuser->name;
				$arr_data[$key]['dayofmonth'] = $_POST['dayofmonth'];
				$arr_data[$key]['contracttermsstart'] = $_POST['contracttermsstart'];
				$arr_data[$key]['contracttermsend'] = $_POST['contracttermsend'];
				$arr_data[$key]['remark'] = $_POST['remark'];
				$arr_data[$key]['type'] = $_POST['type'];
				$arr_data[$key]['cusfrom'] = $_POST['cusfrom'];
				$arr_data[$key]['custo'] = $_POST['custo'];
				$arr_data[$key]['cusprice'] = $_POST['cusprice'];
				$arr_data[$key]['cuscurrency'] = $_POST['cuscurrency'];
				if(count((array)$filename) > 0){
					$arr_data[$key]['filename'] = $filename;
					$arr_data[$key]['filetype'] = $filetype;
					$arr_data[$key]['filesize'] = $filesize;
					$arr_data[$key]['filetimeupload'] = $filetimeupload;
					$arr_data[$key]['filecreatebyid'] = $filecreatebyid;
					$arr_data[$key]['filecreatebyname'] = $filecreatebyname;
					$arr_data[$key]['filepath'] = $filepath;
				}
			}
		}
	}
  
    $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: customer.php?msg=' . $msg);
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $_GET['msg'] = $i18n['All fields are required!'];
}

// CREATE DATA FILE IF NOT EXISTS
if (!is_file($file)) {
    file_put_contents($file, '');
}

// HEADER
ob_end_flush();
include 'tpl/header.php';
// FORM FOR NEW ENTRY
if(@$_GET['q'] == ''){
?>

<script>

$(document).ready(function(){
    $('select').formSelect();
	
});
function editb(id) {
	var obj = jQuery.parseJSON(id);
	$('#idbad').val(obj.id);
	$('#badname,#badacronym,#liabilities,#remark').next().addClass('active');
	$('#badname').val(obj.name);
	$('#badacronym').val(obj.acronym);
	$('#liabilities').val(obj.liabilities);
	$('#remark').val(obj.remark);
	$('#currency').val(obj.currency);
	$('select').formSelect();
}
function editc(id) {

var obj = jQuery.parseJSON(id);
$('#name').next().addClass('active');
$('#acronym').next().addClass('active');
$('#contracttermsstart').next().addClass('active');
$('#contracttermsend').next().addClass('active');
$('#id').val(obj.id);

$('#contracttermsstart').val(obj.contracttermsstart);
$('#contracttermsend').val(obj.contracttermsend);

$('#name').val(obj.name);
$('#acronym').val(obj.acronym);
$('#invoicetype').val(obj.invoicetype);
$("#location").val(obj.location).change();
$("#agent").val(obj.agent).change();
$("#remarkdsa").val(obj.remark);
for (var i = 0; i < 5; i++){
	if( obj.cusfrom[i] != '' ){
		if(i > 0){
			$(".addmore").trigger('click');
		}
		$('#cusfrom'+i).val(obj.cusfrom[i]);
		$('#custo'+i).val(obj.custo[i]);
		$('#cusprice'+i).val(obj.cusprice[i]);
		$('#cuscurrency'+i).val(obj.cuscurrency[i]);
		$('.isblock'+i+' label').addClass('active');
	}
}
//$("#remarkdsa").val(obj.remark);

$('input:radio[name="type"][value='+obj.type+']').prop('checked', true);


$("#dayofmonth").val(obj.dayofmonth).change();
$('select').formSelect();
}        
</script> 
<div class="row">
<div class="s12">
    <ul style="    border-bottom: 2px solid #e2e2e2;display:flex;background:#eeeeee;align-items:center;height:unset;<?php if($_GET['none']) ?>" class="tabs">
        <li data-tab="tab-0" class="tab-link  current "><?php echo $i18n['Current']; ?></li>
        <li data-tab="tab-1" class="tab-link  " style="background: #fcff77;" ><?php echo $i18n['Blacklist']; ?></li>
		<li data-tab="tab-2" class="tab-link  " style="background: #ffcaca;color: #000;" ><?php echo $i18n['Dangerous']; ?></li>
		<li data-tab="tab-3" class="tab-link  " style="background: #cfffca;color: #000;" ><?php echo $i18n['Controversial']; ?></li>
    </ul>
</div>	
<div class="tab-content current col s12" id="tab-0" style="    padding: 0;" >
<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
        <div class="badge grey lighten-3 create-user" style="padding: 0px 15px;padding-top: 22px;">
            <form action="" method="POST"  enctype="multipart/form-data"  >
					<input value=""  id="id" name="id" type="hidden"  />
					<input value="0"  id="blacklist" name="blacklist" type="hidden"  />
                <div class="row">
                    <div class="input-field col s2">
                        <input 
                            value="<?php echo @$_POST['name']; ?>" 
                            id="name" 
                            name="name" 
                            type="text" 
                            class="validate" 
                          
                            required="required"  autocomplete="off"  />
                        <label for="name"><?php echo $i18n['cusname']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                         
                        </span>
                    </div> 			
					<div class="input-field col s2">
                        <input 
                            value="<?php echo @$_POST['acronym']; ?>" 
                            id="acronym" 
                            name="acronym" 
                            type="text" 
                            class="validate" 
                         
                            required="required"  autocomplete="off"  />
                        <label for="acronym"><?php echo $i18n['cusacronym']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                            
                        </span>
                    </div>  
                    <div class="input-field col s1">					
						<select name="location" id="location">
							<option value="">-----------</</option> 
							<option value="VN">VietNam</option>  
							<option value="HCM">Ho Chi Minh</option>
							<option value="HPG" >Hai Phong</option>
							<option value="TAL" >ThaiLand</option>
							<option value="China" >China</option>
						</select>							
                        <label for="location"><?php echo $i18n['cuslocation']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                            
                        </span>
                    </div>
					<div class="input-field col s1">					
						<select name="paymentlocation" id="paymentlocation">
							<option value="">-----------</</option> 
							<option value="VN">VietNam</option>  
							<option value="HCM">Ho Chi Minh</option>
							<option value="HPG" >Hai Phong</option>
							<option value="TAL" >ThaiLand</option>
							<option value="China" >China</option>
						</select>							
                        <label for="paymentlocation"><?php echo $i18n['paymentLocation']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                            
                        </span>
                    </div>
					<div class="input-field col s2">					
					<select name="invoicetype" id="invoicetype" onchange=" if($(this).val()=='月结客户及账期 - Per Month'){ $('.dnsadn').show(); }else{ $('.dnsadn').hide(); } " >
						<option value="" >-----------</option>
						<option value="票结客户 - Per Diem" >票结客户 - Per Diem</option>
						<option value="月结客户及账期 - Per Month" >月结客户及账期 - Per Month</option>
						<option value="以柜压柜客户 - Per Container" >以柜压柜客户 - Per Container</option>					
                    </select>				
                    </select>				
                        <label for="invoicetype"><?php echo $i18n['cusType']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">                          
                        </span>
                    </div>
					<div class="input-field col s1 "  >
						<input 
                            value="" 
                            id="paymentpath" 
                            name="paymentpath" 
                            type="text" 
                            class="" 
                           
                            autocomplete="off"  />
                        <label for="dayofmonth"><?php echo $i18n['paymentpath']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                          
                        </span>
					</div>
					<div class="input-field col s1 dnsadn" style="display:none;" >
						<input 
                            value="" 
                            id="dayofmonth" 
                            name="dayofmonth" 
                            type="text" 
                            class="" 
                          
                              autocomplete="off"  />
                        <label for="dayofmonth"><?php echo $i18n['paymentpath']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                         
                        </span>
					</div>
					<div class="input-field col s1">
                        <input 
                            value="<?php echo @$_POST['contracttermsstart']; ?>" 
                            id="contracttermsstart" 
                            name="contracttermsstart" 
                            type="text" 
                            class="datepicker" 
                           
                             autocomplete="off"  />
                        <label for="contracttermsstart"><?php echo $i18n['contractstart']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                         
                        </span>
                    </div> 
					<div class="input-field col s1">
                        <input 
                            value="<?php echo @$_POST['contracttermsend']; ?>" 
                            id="contracttermsend" 
                            name="contracttermsend" 
                            type="text" 
                            class="datepicker" 
                          
                             autocomplete="off"  />
                        <label for="contracttermsend"><?php echo $i18n['contractend']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                         
                        </span>
                    </div> 
                    <div class="input-field col s1" style="    text-align: right;">
                        <button class="colortoptran btn waves-effect waves-light" type="submit" name="action">
                            <?php echo $i18n['Save New Issue']; ?>
                        </button>
                    </div>
                    <div class="input-field col s1 ">
                        <a style="    background: #4e4e4e;" class="btn  btn-default waves-effect waves-light" href="./index.php">
                            <?php echo $i18n['Go Back']; ?>
                        </a>
                    </div>
					<div class="input-field col s5">
						<input 
                            value="<?php echo @$_POST['remark']; ?>" 
                            id="remarkdsa" 
                            name="remark" 
                            type="text" 
                            class="validate" 
                        
                           autocomplete="off"  />
                        <label for="remarkdsa"><?php echo $i18n["Remarks"]; ?></label>                     
					</div> 
					<div class="input-field col s2  dhkasbdbas"  >
						<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 class="input-field col s2 "  >
						<label>
							<input class="with-gap" name="type" value="0" type="radio" checked />
							<span><?php echo $i18n['default']; ?></span>
						  </label>
					</div>	  
					<div class="input-field col s2 "  >
						  <label>
							<input class="with-gap" name="type" value="1" type="radio" />
							<span><?php echo $i18n['dangerous']; ?></span>
						  </label>
					</div>	
					<div class="input-field col s2 "  >
						   <label>
							<input class="with-gap" value="2" name="type" type="radio"  />
							<span><?php echo $i18n['Controversial']; ?></span>
						  </label>
					</div>	
					<?php for($i = 0; $i < 5 ; $i++){ ?>
					<div class="input-field col s12 isblock<?php echo $i; ?>" <?php if($i != 0){ echo 'style="display:none;"';} ?> >	
							<?php $Setting = json_decode(file_get_contents('../Docs/data/Setting.json')); ?>
						
							<div class="input-field col s3">
							   <select class="departure" name="cusfrom[]" id="cusfrom<?php echo $i; ?>"  >
								<option value="" >------------</option>
								<option value="addnew" >---Add new / 添新---</option>
										<?php 
											$departures_op = $Setting->Departure;
											$departures_op = explode(PHP_EOL,$departures_op );
											
											
											foreach($departures_op as $departure_op ){
												$departure_op = explode('|',$departure_op )
												?> 
													<option value="<?php echo $departure_op[1]; ?>"><?php echo $departure_op[0].' - '.$departure_op[2]; ?></option>
												<?php
											}
										?>
								</select>
							<label  style="top: 0px;    left: -7px;    width: 30px;    font-size: 15px;"  for="departure"><?php echo $i18n['From']; ?></label>
							
							<div class="cblockadd" style="display:none;"  >
										<div class="col s4">
											<select name="departurefrom[]" id="iddeparturefrom" style="width: 70%;float: left;" >
												<option value="vn">VN</option>
												<option value="th">TH</option>
												<option value="cn">CN</option>
												<option value="usa">Usa</option>
												<option value="ja">Japan</option>
												<option value="eu">Europe</option>
												<option value="order">Orders</option>
											</select>
											<script>
												$("#iddeparturefrom").change(function(){
													if($(this).val() == 'order' ){
														$(this).parents().eq(0).find('input').remove();
														$('<input type="text" name="departurefrom[]" style="width: 90%;float: left;"  />').insertAfter(this);
														$(this).remove();
													}
												});
											</script>
										</div>
										<div class="col s1" style="    padding-top: 20px;    margin-left: -7px;">-</div>
										<div class="col s7">
											<input 
												value="" 
												id="departuretext" 
												name="departuretext[]" 
												type="text" 
												class="validate"
												placeholder="Add Departure"										
												maxlength="32" 
												data-length="32" 
											/>				
										</div>
								</div>
						</div>
						<div class="input-field col s3" >
							   <select class="arrival" name="custo[]" id="custo<?php echo $i; ?>" >
								 <option value="" >------------</option>
								 <option value="addnew" >---Add new / 添新---</option>
										<?php 
											$arrivals_op = $Setting->Arrival;
											$arrivals_op = explode(PHP_EOL,$arrivals_op );
											foreach($arrivals_op as $arrival_op ){
												$arrival_op = explode('|',$arrival_op )
												?> 
													<option value="<?php echo $arrival_op[1]; ?>"><?php echo $arrival_op[0].' - '.$arrival_op[2]; ?></option>
												<?php
											}
										?>
								</select>	
							<label for="arrival" style="top: 0px;    left: -7px;    width: 30px;    font-size: 15px;" ><?php echo $i18n['To']; ?></a></label>
							
							<div class="cblockadd" style="display:none;"  >
										<div class="col s4">
											<select name="arrivalfrom[]" id="idarrivalfrom" style="width: 70%;float: left;" >
												<option value="vn">VN</option>
												<option value="th">TH</option>
												<option value="cn">CN</option>
												<option value="usa">Usa</option>
												<option value="ja">Japan</option>
												<option value="eu">Europe</option>
												<option value="order">Orders</option>
											</select>
										</div>
										<div class="col s1" style="    padding-top: 20px;    margin-left: -7px;">-</div>
										<div class="col s7">
											<input 
												value="" 
												id="idarrivaltext" 
												name="arrivaltext[]" 
												type="text" 
												class="validate" 
												placeholder="Add Arrival"	
												maxlength="32" 
												data-length="32" 
											/>				
										</div>
								</div>
						</div>    
				
				
							<div class="input-field col s2">
								<input 
									value="<?php echo @$_POST['liabilities']; ?>" 
									id="cusprice<?php echo $i; ?>" 
									name="cusprice[]" 
									data-type='currency'
									type="text" 
									class="cusprice validate" 
									maxlength="32" 
									data-length="32" 
									  autocomplete="off"  />
								<label for="cusprice<?php echo $i; ?>"><?php echo $i18n["price"]; ?></label>
								
							</div> 
							<div class="input-field col s1">
								 <select name="cuscurrency[]" id="cuscurrency<?php echo $i; ?>"  tabindex="-1">                           
										<?php foreach($currency as $r){	?>
											<option value="<?php echo $r['id']; ?>" <?php echo $sel; ?> ><?php echo $r['currency']; ?></option>
										<?php } ?>	
								</select>
							</div> 
							<?php if($i == 0){ ?>
							<div class="input-field col s1">
								<button class="addmore btn waves-effect waves-light" type="button" name="action"><i class="material-icons right" style="line-height:1.5;    margin-left: 0px;
    margin-right: 0px;">add_circle_outline</i></button>
							</div>	
							<?php }else{ ?>
							<div class="input-field col s1">
								<i class="removecusprice material-icons " style=" color: red; padding-top: 0px; cursor: pointer;">indeterminate_check_box</i>
							</div>	
							<?php } ?>	
					</div>	
					<?php } ?>
                </div>
            </form>
        </div>
	<?php }} ?>
	   <div class="row" style="    margin-top: -20px;    margin-bottom: 40px;">
		<div class="input-field col s2 right "  >
						<label>
							<input onclick="$('.sdjvb').show();" class="with-gap" name="qg" value="0" type="radio" checked />
							<span>All/所有</span>
						  </label>
					</div>	
		<div class="input-field col s2 right"  >
						<label>
							<input onclick="$('.sdjvb').hide();$('.VN').show();" class="with-gap" name="qg" value="1" type="radio" />
							<span>VietNam/越南</span>
						  </label>
					</div>	  
					<div class="input-field col s2 right"  >
						  <label>
							<input onclick="$('.sdjvb').hide();$('.China').show();" class="with-gap" name="qg" value="2" type="radio" />
							<span>China/中国</span>
						  </label>
					</div>	
					<div class="input-field col s2 right"  >
						   <label>
							<input onclick="$('.sdjvb').hide();$('.TAL').show();" class="with-gap" value="3" name="qg" type="radio"  />
							<span>ThaiLand/泰国</span>
						  </label>
					</div>		  
   </div>
        <table class="striped responsive-table  tablesorter "  >
            <thead>
                <tr>
					<th>ID</th>
                    <th style="display:none;" >Customer ID</th>
					<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                    <th style="width:90px;" ><?php echo $i18n['cusname']; ?></th>
					<?php } ?>
                    <th style="width:90px;" ><?php echo $i18n['cusacronym']; ?></th>
                    <th style="width:200px;" ><?php echo $i18n['cusType']; ?></th>
					<th><?php echo $i18n['paymentpath']; ?></th>
					<th><?php echo $i18n['cuslocation']; ?></th>
					<th><?php echo $i18n['paymentLocation']; ?></th>
                  
					<th><?php echo $i18n['price']; ?></th>
					<th><?php echo $i18n['文件']; ?> </th>
					<th><?php echo $i18n['contractstart']; ?></th>
					<th><?php echo $i18n['contractend']; ?></th>
					<th style="width:250px;"><?php echo $i18n["Remarks"]; ?></th>	
					<th style="width:60px;"><?php echo $i18n['Created']; ?></th>					
					<th style="width:60px;"><?php echo $i18n['Modified']; ?></th>
					<th style="width:104px;"></th>
                </tr>
            </thead>
        <tbody>
   <?php 
	 foreach ($data as $key => $values) {   
		$data_ex[$values['acronym']] = $values;
	 }
	 ksort($data_ex);
	 $data = array_values($data_ex);	
	 
     $total_receivable = $total_amount = $total_profit = 0;
     $countNo = 0; $i = 0;
        foreach ($data as $key => $values) {   
		     $toast = 'M.toast({html: "<span>' . $values['name'] . '</span>' .
                    '<a href=\"?delete_id=' . $values['id'] . '\" class=\"toast-action\">' .
                    $i18n['DELETE'] . '</a> &nbsp; &nbsp;"});';
					$file = '';
					foreach ($values['filename'] as $keyfile => $dataf ){
										$fnjf++;
										if ( strpos($values['filetype'][$keyfile] , 'pdf')  !== false ) {												
												
												if( $currentuser->location == '中国' ){
													$file .=  '<a ref="https://htlservice.net/Docs/uploads/'.rawurlencode($values['filepath'][$keyfile]).'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}else{
													$file .=  '<a ref="https://drive.google.com/viewerng/viewer?url=https://htlservice.net/Docs/uploads/'.urlencode($values['filepath'][$keyfile]).'?pid=explorer&efh=false&a=v&chrome=false&embedded=true" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}
										} elseif ( strpos($values['filetype'][$keyfile] , 'sheet')  !== false || strpos($values['filepath'][$keyfile] , '.xls')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/excel.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'zip')  !== false ) { 
												$file .=  '<a download href="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/zip.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'doc')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'"  href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/word.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'image')  !== false ) { 
												$file .=  '<a ref="https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));"  ><img src="https://htlservice.net/Docs/tpl/img/png.png" style="width:24px;height:auto;" /></a>';
										} else{
												$file .=  '<a download href="https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/file.png" style="width:24px;height:auto;" /></a>';
										}
					}	
					if($values['type'] == 1){
						$Dangerous[] = $values;
					}
					if($values['type'] == 2){
						$Controversial[] = $values;
					}
					if ($currentuser->gm == '1' && file_exists("logs/".$values['id'])) {
						$logs = file_get_contents("logs/".$values['id']);
						$logs = str_replace(PHP_EOL,'<br>',$logs);
						$logsmode = '<a  href="#" data-target="modal6" class="modal-trigger cllogcontent" ><span style="display:none;" >'. $logs .'</span><i class="grey-text small material-icons">content_paste</i></a>';
					}else{
						$logsmode = '';
					}
	            ?>    
                <tr class="sdjvb <?= $values['location']?>" style="<?php if($values['type'] == 1){ echo 'background:#ffcaca;'; }elseif($values['type'] == 2){ echo 'background:#cfffca;'; } ?>" >
					<td  style="padding-left:6px"><?= ++$i; ?> </td>
                    <td  style="display:none;" style="padding-left:6px"><?= $values['customerid'] ?> </td>
					<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                    <td style="padding-left:6px"><?= $values['name']?></td>
					<?php } ?>
                    <td style="padding-left:6px"><?= $values['acronym']?></td>
                    <td style="padding-left:6px"><?= $values['invoicetype']?><?php if($values['dayofmonth'] != '' && $values['invoicetype'] == '月结客户及账期 - Per Month'){ echo '<br><b>Day:</b>'.$values['dayofmonth']; } ?></td>
					<td style="padding-left:6px"><?= $values['paymentpath']?></td>
					<td style="padding-left:6px;"><?= $values['location']?></td>
					<td style="padding-left:6px;"><?= $values['paymentlocation']?></td>
					
					<td style="padding-left:6px"><div class="nofulltext" ><?php foreach( $values['cusfrom'] as $ke => $r ){ 
							if($values['cusfrom'][$ke]==''){continue;}
									foreach($currency as $r1){ 
										if($values['cuscurrency'][$ke] == $r1['id']){
											$currencyname = $r1['currency'];
											$exchangerate =  $r1['exchangerate'];
										}
									 }
							?><p><b><?php echo $values['cusfrom'][$ke].' - '.$values['custo'][$ke]; ?></b>: <?php echo $values['cusprice'][$ke].' '.$currencyname; ?></p><?php } ?></div><i class="fas fa-sort-down" style="color: #000;    font-size: 17px;"></i>					
					</td>
					
					<td style="padding-left:6px"><?php echo $file;  ?></td>
					<td style="padding-left:6px"><?= $values['contracttermsstart']; ?></td>
					<td style="padding-left:6px"><?= $values['contracttermsend']; ?></td>
					<td style="padding-left:6px"><?= $values['remark']; ?></td>
					<td style="padding-left:6px"><a href="#" title="<?= date('d/m/y h:i',$values['createddate']); ?>" ><?= $values['createdby']?></a></td>
					<td style="padding-left:6px"><a <?= date('d/m/y h:i',$values['modifieddate']); ?>><?php echo $values['modifiedby']; ?><a></td>
					<td style="padding-left:6px">
						<?php if( $currentuser->gm == 1){  ?>
                        <a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['Click alert link for delete!']?>" href="#" onclick='<?php echo $toast; ?>' >
                            <i class="red-text text-darken-4 small material-icons">delete_forever</i>
                        </a>
						<?php } ?>
						<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                        <a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['EDIT'] ?>" href="#" onclick='editc("<?php echo addslashes(json_encode($values)); ?>")'>
                            <i class="grey-text small material-icons">mode_edit</i>
                        </a>
						<?php echo $logsmode; } ?>
                    </td>
                </tr>
            <?php  }  ?>
        </tbody>
        </table>
</div>
<div class="tab-content col s12" id="tab-1" style="    padding: 0;">	
<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
		<div class="badge grey lighten-3 create-user" style="padding: 0px 15px;float: left;    width: 100%;padding-top: 22px;">
			<form action="" method="POST"  enctype="multipart/form-data"  >
				<input value=""  id="idbad" name="id" type="hidden"  />
				<input value="1"  id="blacklist" name="blacklist" type="hidden"  />
				<div class="input-field col s2">
                        <input 
                            value="<?php echo @$_POST['name']; ?>" 
                            id="badname" 
                            name="name" 
                            type="text" 
                            class="validate" 
                           
                            data-length="32" 
                            required="required"  autocomplete="off"  />
                        <label for="badname"><?php echo $i18n['cusname']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                          
                        </span>
                    </div> 			
					<div class="input-field col s2">
                        <input 
                            value="<?php echo @$_POST['acronym']; ?>" 
                            id="badacronym" 
                            name="acronym" 
                            type="text" 
                            class="validate" 
                            
                            required="required"  autocomplete="off"  />
                        <label for="badacronym"><?php echo $i18n['cusacronym']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div> 
					<div class="input-field col s2">
                        <input 
                            value="<?php echo @$_POST['liabilities']; ?>" 
                            id="liabilities" 
                            name="liabilities" 
							data-type='currency'
                            type="text" 
                            class="validate" 
                           
                              autocomplete="off"  />
                        <label for="liabilities"><?php echo $i18n['Liabilities']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div> 
					<div class="input-field col s1">
					 <select name="currency" id="currency"  tabindex="-1">                           
                       		<?php foreach($currency as $r){	?>
								<option value="<?php echo $r['id']; ?>" <?php echo $sel; ?> ><?php echo $r['currency']; ?></option>
							<?php } ?>	
					</select>
					</div> 
					
					<div class="input-field col s3">
						<input 
                            value="<?php echo @$_POST['remark']; ?>" 
                            id="remark" 
                            name="remark" 
                            type="text" 
                            class="validate" 
                          
                           autocomplete="off"  />
                        <label for="remark"><?php echo $i18n["Remarks"]; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                            
                        </span>
					</div> 
					<div class="input-field col s2  dhkasbdbas"  >
						<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 class="input-field col s1" style="    text-align: right;">
                        <button class="colortoptran btn waves-effect waves-light" type="submit" name="action">
                            <?php echo $i18n['Save New Issue']; ?>
                        </button>
                    </div>
                    <div class="input-field col s1 ">
                        <a style="    background: #4e4e4e;" class="btn  btn-default waves-effect waves-light" href="./index.php">
                            <?php echo $i18n['Go Back']; ?>
                        </a>
                    </div>
			</form>
		</div>
<?php } ?>		
  		<table class="striped responsive-table  tablesorter" >
            <thead>
                <tr>
					<th >ID</th>
                    <th style="display:none;" >Customer ID</th>
					<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                    <th><?php echo $i18n['cusname']; ?></th>
					<?php } ?>
                    <th><?php echo $i18n['cusacronym']; ?></th>
                    <th><?php echo $i18n['Liabilities']; ?></th>					
					<th><?php echo $i18n['文件']; ?> </th>
					<th><?php echo $i18n["Remarks"]; ?></th>			
                    <th><?php echo $i18n["Created"]; ?></th>
					<th><?php echo $i18n["Modified"]; ?></th>
				
				<th>
				</th>
                </tr>
            </thead>
        <tbody>
   <?php 
     $total_receivable = $total_amount = $total_profit = 0;
     $countNo = 0; $i = 0;
	 
	 foreach ($data2 as $key => $values) {   
		$data_ex[$values['acronym']] = $values;
	 }
	 ksort($data_ex);
	 $data = array_values($data_ex);
	 
        foreach ($data2 as $key => $values) {   
		     $toast = 'M.toast({html: "<span>' . $values['name'] . '</span>' .
                    '<a href=\"?delete_id1=' . $values['id'] . '\" class=\"toast-action\">' .
                    $i18n['DELETE'] . '</a> &nbsp; &nbsp;"});';
					$file = '';
					foreach ($values['filename'] as $keyfile => $dataf ){
										$fnjf++;
										if ( strpos($values['filetype'][$keyfile] , 'pdf')  !== false ) {												
												
												if( $currentuser->location == '中国' ){
													$file .=  '<a ref="https://htlservice.net/Docs/uploads/'.rawurlencode($values['filepath'][$keyfile]).'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}else{
													$file .=  '<a ref="https://drive.google.com/viewerng/viewer?url=https://htlservice.net/Docs/uploads/'.urlencode($values['filepath'][$keyfile]).'?pid=explorer&efh=false&a=v&chrome=false&embedded=true" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}
										} elseif ( strpos($values['filetype'][$keyfile] , 'sheet')  !== false || strpos($values['filepath'][$keyfile] , '.xls')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/excel.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'zip')  !== false ) { 
												$file .=  '<a download href="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/zip.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'doc')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'"  href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/word.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'image')  !== false ) { 
												$file .=  '<a ref="https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));"  ><img src="https://htlservice.net/Docs/tpl/img/png.png" style="width:24px;height:auto;" /></a>';
										} else{
												$file .=  '<a download href="https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/file.png" style="width:24px;height:auto;" /></a>';
										}
					}
					 foreach($currency as $r){ 
						if($values['currency'] == $r['id']){
							$currencyname = $r['currency'];
							$exchangerate =  $r['exchangerate'];
						}
					 }
					
					$total += str_replace(',','',$values['liabilities'])*$exchangerate;
					if ($currentuser->gm == '1' && file_exists("logs/".$values['id'])) {
						$logs = file_get_contents("logs/".$values['id']);
						$logs = str_replace(PHP_EOL,'<br>',$logs);
						$logsmode = '<a  href="#" data-target="modal6" class="modal-trigger cllogcontent" ><span style="display:none;" >'. $logs .'</span><i class="grey-text small material-icons">content_paste</i></a>';
					}else{
						$logsmode = '';
					}
	            ?>    
                <tr>
					<td  style="padding-left:6px"><?= ++$i; ?> </td>
                    <td  style="display:none;" style="padding-left:6px"><?= $values['customerid'] ?> </td>
					<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                    <td style="padding-left:6px"><?= $values['name']?></td>
					<?php } ?>
                    <td style="padding-left:6px"><?= $values['acronym']?></td>
					<td style="padding-left:6px"><?= $values['liabilities'];?> <?= $currencyname; ?></td>
					<td style="padding-left:6px"><?php echo $file;  ?></td>
					<td style="padding-left:6px"><?= $values['remark']?></td>
                    <td style="padding-left:6px"><a title="<?= date('d/m/y h:i',$values['createddate']); ?>" ><?= $values['createdby']?></a></td>
					<td style="padding-left:6px"><a title="<?= date('d/m/y h:i',$values['modifieddate']); ?>"><?= $values['modifiedby']?></a></td>
					
                    <td style="padding-left:6px">
						<?php if( $currentuser->gm == 1){  ?>
                        <a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['Click alert link for delete!']?>" href="#" onclick='<?php echo $toast; ?>' >
                            <i class="red-text text-darken-4 small material-icons">delete_forever</i>
                        </a>
						<?php } ?>
						<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                        <a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['EDIT'] ?>" href="#" onclick='editb("<?php echo addslashes(json_encode($values)); ?>")'>
                            <i class="grey-text small material-icons">mode_edit</i>
                        </a>
						<?php echo $logsmode; } ?>
                    </td>
                </tr>
            <?php  }  ?>
        </tbody>
		<tfoot>
			<tr>
				<td></td>
				<td></td>
				<td><b style="float:right;" >Total/总:</b></td>
				<td style="padding-left:6px;font-weight:bold;"><?php echo number_format((float)$total,2).' RMB'; ?></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
		</tfoot>
        </table>
</div>	
<div class="tab-content col s12" id="tab-2" style="    padding: 0;">	

   <table class="striped responsive-table  tablesorter "  >
            <thead>
                <tr>
					<th>ID</th>
                    <th style="display:none;" >Customer ID</th>
					<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                    <th><?php echo $i18n["cusname"]; ?></th>
					<?php } ?>
                    <th><?php echo $i18n["cusacronym"]; ?></th>
                    <th><?php echo $i18n["cusType"]; ?></th>
					<th><?php echo $i18n["paymentpath"]; ?></th>
					<th style="display:none;"  >Location</th>			
                    <th><?php echo $i18n["Created"]; ?></th>					
					<th><?php echo $i18n["Modified"]; ?></th>
					<th>File </th>
					<th><?php echo $i18n["contractstart"]; ?></th>
					<th><?php echo $i18n["contractend"]; ?></th>
					<th><?php echo $i18n["Remarks"]; ?></th>	
					
                </tr>
            </thead>
        <tbody>
   <?php 
	
     $total_receivable = $total_amount = $total_profit = 0;
     $countNo = 0;$i = 0;
        foreach ($Dangerous as $key => $values) {   
		     $toast = 'M.toast({html: "<span>' . $values['name'] . '</span>' .
                    '<a href=\"?delete_id=' . $values['id'] . '\" class=\"toast-action\">' .
                    $i18n['DELETE'] . '</a> &nbsp; &nbsp;"});';
					$file = '';
					foreach ($values['filename'] as $keyfile => $dataf ){
										$fnjf++;
										if ( strpos($values['filetype'][$keyfile] , 'pdf')  !== false ) {												
												
												if( $currentuser->location == '中国' ){
													$file .=  '<a ref="https://htlservice.net/Docs/uploads/'.rawurlencode($values['filepath'][$keyfile]).'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}else{
													$file .=  '<a ref="https://drive.google.com/viewerng/viewer?url=https://htlservice.net/Docs/uploads/'.urlencode($values['filepath'][$keyfile]).'?pid=explorer&efh=false&a=v&chrome=false&embedded=true" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}
										} elseif ( strpos($values['filetype'][$keyfile] , 'sheet')  !== false || strpos($values['filepath'][$keyfile] , '.xls')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/excel.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'zip')  !== false ) { 
												$file .=  '<a download href="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/zip.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'doc')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'"  href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/word.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'image')  !== false ) { 
												$file .=  '<a ref="https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));"  ><img src="https://htlservice.net/Docs/tpl/img/png.png" style="width:24px;height:auto;" /></a>';
										} else{
												$file .=  '<a download href="https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/file.png" style="width:24px;height:auto;" /></a>';
										}
					}	
					if($values['type'] == 1){
						$Dangerous[] = $values;
					}
					if($values['type'] == 2){
						$Controversial[] = $values;
					}
	            ?>    
                <tr>
					<td  style="padding-left:6px"><?= ++$i; ?> </td>
                    <td  style="display:none;" style="padding-left:6px"><?= $values['customerid'] ?> </td>
					<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                    <td style="padding-left:6px"><?= $values['name']?></td>
					<?php } ?>
                    <td style="padding-left:6px"><?= $values['acronym']?></td>
                    <td style="padding-left:6px"><?= $values['invoicetype']?><?php if($values['dayofmonth'] != '' && $values['invoicetype'] == '月结客户及账期 - Per Month'){ echo '<br><b>Day:</b>'.$values['dayofmonth']; } ?></td>
					<td style="padding-left:6px"><?= $values['paymentpath']?></td>
					<td style="padding-left:6px;display:none;"><?= $values['location']?></td>
					
					<td style="padding-left:6px"><a href="#" title="<?= date('d/m/y h:i',$values['createddate']); ?>" ><?= $values['createdby']?></a></td>
					<td style="padding-left:6px"><?= date('d/m/y h:i',$values['modifieddate']); ?></td>
					<td style="padding-left:6px"><?php echo $file;  ?></td>
					<td style="padding-left:6px"><?= $values['contracttermsstart']; ?></td>
					<td style="padding-left:6px"><?= $values['contracttermsend']; ?></td>
					<td style="padding-left:6px"><?= $values['remark']; ?></td>
		
                    
                </tr>
            <?php  }  ?>
        </tbody>
        </table>
		
</div>	
<div class="tab-content col s12" id="tab-3" style="    padding: 0;">	

	
   <table class="striped responsive-table  tablesorter "  >
            <thead>
                <tr>
					<th>ID</th>
                    <th style="display:none;" >Customer ID</th>
					<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                    <th><?php echo $i18n["cusname"]; ?></th>
					<?php } ?>
                    <th><?php echo $i18n["cusacronym"]; ?></th>
                    <th><?php echo $i18n["cusType"]; ?></th>
					<th><?php echo $i18n["paymentpath"]; ?></th>
					<th style="display:none;"  >Location</th>			
                    <th><?php echo $i18n["Created"]; ?></th>					
					<th><?php echo $i18n["Modified"]; ?></th>
					<th>File </th>
					<th><?php echo $i18n["contractstart"]; ?></th>
					<th><?php echo $i18n["contractend"]; ?></th>
					<th><?php echo $i18n["Remarks"]; ?></th>	
					
                </tr>
            </thead>
        <tbody>
   <?php 
	
     $total_receivable = $total_amount = $total_profit = 0;
     $countNo = 0;$i = 0;
        foreach ($Controversial as $key => $values) {   
		     $toast = 'M.toast({html: "<span>' . $values['name'] . '</span>' .
                    '<a href=\"?delete_id=' . $values['id'] . '\" class=\"toast-action\">' .
                    $i18n['DELETE'] . '</a> &nbsp; &nbsp;"});';
					$file = '';
					foreach ($values['filename'] as $keyfile => $dataf ){
										$fnjf++;
										if ( strpos($values['filetype'][$keyfile] , 'pdf')  !== false ) {												
												
												if( $currentuser->location == '中国' ){
													$file .=  '<a ref="https://htlservice.net/Docs/uploads/'.rawurlencode($values['filepath'][$keyfile]).'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}else{
													$file .=  '<a ref="https://drive.google.com/viewerng/viewer?url=https://htlservice.net/Docs/uploads/'.urlencode($values['filepath'][$keyfile]).'?pid=explorer&efh=false&a=v&chrome=false&embedded=true" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}
										} elseif ( strpos($values['filetype'][$keyfile] , 'sheet')  !== false || strpos($values['filepath'][$keyfile] , '.xls')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/excel.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'zip')  !== false ) { 
												$file .=  '<a download href="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/zip.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'doc')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'"  href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/word.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'image')  !== false ) { 
												$file .=  '<a ref="https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));"  ><img src="https://htlservice.net/Docs/tpl/img/png.png" style="width:24px;height:auto;" /></a>';
										} else{
												$file .=  '<a download href="https://htlservice.net/Docs/uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/file.png" style="width:24px;height:auto;" /></a>';
										}
					}	
					if($values['type'] == 1){
						$Dangerous[] = $values;
					}
					if($values['type'] == 2){
						$Controversial[] = $values;
					}
	            ?>    
                <tr>
					<td  style="padding-left:6px"><?= ++$i; ?> </td>
                    <td  style="display:none;" style="padding-left:6px"><?= $values['customerid'] ?> </td>
					<?php if( $currentuser->customer  == '1' || $currentuser->gm == 1 ){ ?>
                    <td style="padding-left:6px"><?= $values['name']?></td>
					<?php } ?>
                    <td style="padding-left:6px"><?= $values['acronym']?></td>
                    <td style="padding-left:6px"><?= $values['invoicetype']?><?php if($values['dayofmonth'] != '' && $values['invoicetype'] == '月结客户及账期 - Per Month'){ echo '<br><b>Day:</b>'.$values['dayofmonth']; } ?></td>
					<td style="padding-left:6px"><?= $values['paymentpath']?></td>
					<td style="padding-left:6px;display:none;"><?= $values['location']?></td>
					
					<td style="padding-left:6px"><a href="#" title="<?= date('d/m/y h:i',$values['createddate']); ?>" ><?= $values['createdby']?></a></td>
					<td style="padding-left:6px"><?= date('d/m/y h:i',$values['modifieddate']); ?></td>
					<td style="padding-left:6px"><?php echo $file;  ?></td>
					<td style="padding-left:6px"><?= $values['contracttermsstart']; ?></td>
					<td style="padding-left:6px"><?= $values['contracttermsend']; ?></td>
					<td style="padding-left:6px"><?= $values['remark']; ?></td>
		
                    
                </tr>
            <?php  }  ?>
        </tbody>
        </table>
		
</div>
</div>	
<script>
$(document).ready(function(){   
<?php if ($currentuser->gm == "1"  ){ ?>	
	$(".cllogcontent").click(function(){
		$(".logcontent").html($(this).find('span').html());
	});	
	<?php } ?>
	
jQuery( "body" ).delegate( ".departure , .arrival  ", "change", function() {	
	if($(this).val() == 'addnew' ){
		$(this).parents().eq(0).hide();
		$(this).parents().eq(1).find('.cblockadd').fadeIn();
	}
});



	var tt = 1;
	$(".addmore").click(function(){ 
		if(tt < 5){
			$(".isblock"+tt).show();
			tt++;
		}else{
			alert('Maximum/最大值');
		}
	});
	$(".removecusprice").click(function(){
		$(this).parents().eq(1).find('input').val('');
		$(this).parents().eq(1).hide();
		tt--;
	});
	$(".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');
		}
	});
	$('.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');
		}
	});
});
$("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>
<style>
table thead tr th {
    position: sticky;
    z-index: 100;
    top: 0;
}
.dropdown-content li>a, .dropdown-content li>span {   
    padding: 7px 16px;
}
.nofulltext { display:block!important; height: 19px; overflow: hidden; width: calc(100% - 20px); float: left; word-break: break-all; }
.nofulltext p {		padding: 0px;		margin: 0px;	}
.input-field {
    position: relative;
    margin-top: 0rem;
    margin-bottom: 0rem;
}
table.tablesorter thead tr th {
    background-color: #ddd;
}
.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 { } 
</style>           
<div id="readfile" class="modal" style="    width: 80%!important;" >
			<a onclick="$('.modal-overlay').trigger('click');" style="       background: transparent;    color: red;    font-weight: bold;    font-size: 35px;	    font-family: cursive;    width: 30px;    height: 30px;    top: 0px;    right: 20px;    position: absolute;    left: unset;    bottom: unset;    display: block;    cursor: pointer;" >x</a>
			<iframe class="iframereadfile" src="" width="100%" style="height:auto;    min-height: 550px;" ></iframe>
			<div class="isleft" ><i class="fas fa-chevron-left"></i></div>
			<div class="isright" ><i class="fas fa-chevron-right"></i></div>		
</div>	
<?php if ($currentuser->gm == "1"  ){ ?>	
<div id="modal6" class="modal">
  <div class="logcontent" style="padding: 15px;" ></div>
</div>
<?php } ?>	
<?php
// FOOTER
include 'tpl/footer.php';
?>
