<?php
// DISPLAY ALL ERRORS
//error_reporting(E_ALL);
ini_set('display_errors', 0);

// FOR DEBUG ONLY
if (isset($_GET['php']) and $_GET['php'] == 'info') {
    die(phpinfo());
}
// SEARCH HELPER FUNCTION
function contains(array $array, $string) {
    $count = 0;
    foreach ($array as $value) {
        if (false !== stripos($string, $value)) {
            ++$count;
        }
    }
    return $count == count((array)$array);
}

// START & CONFIG
ob_start();
require 'setup/config.php';

// SET LANGUAGE
$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 = 'data/receiver_payer.json'; // DATA FILE NAME
// LOGIN CHECK
session_start();
$login = check_current_user_login($ARR_USERS, $SALT);
$currentuser = $login['user'];
//var_dump($login);
if ($login['status'] == 200) {
    //var_dump($login);
} else {
    header('location: login.php');
    exit;
}
// DELETE ENTRY IF DEL LINK IS CLICKED
if($_GET['merge'] == '1'){
$listchange = array( "伏开朗0530" => "私卡0530",
"伏开朗0530卡" => "私卡0530",
"伏0530" => "私卡0530",
"伏开朗0174" => "私卡0174",
"农行0174" => "私卡0174",
"农行0175" => "私卡0174",
"农行 伏 0174" => "私卡0174",
"私账0174" => "私卡0174",
"私户0174" => "私卡0174",
"0174卡" => "私卡0174",
"私卡0174卡" => "私卡0174",
"伏-农行0174" => "私卡0174",
"伏0174卡" => "私卡0174",
"伏0174" => "私卡0174",
"星展8272" => "公账8272",
"星展8273" => "公账8272",
"星展8254" => "公账8272",
"星展FUBO 8272" => "公账8272",
"星展FUBO8272" => "公账8272",
"星展FUBO827" => "公账8272",
"星展" => "公账8272",
"伏波星展" => "公账8272",
"Fubo Industry Co.,Ltd (HONG KONG)" => "公账8272",
"Fubo Industry Co.,Ltd" => "公账8272",
"越南公账1876" => "公账1876",
"私户4004" => "私卡4004",
"私4004" => "私卡4004",
"VND4004" => "私卡4004",
"账户4004" => "私卡4004",
"私户2457" => "私卡2457",
"私2457" => "私卡2457",
"个卡2457" => "私卡2457",
"账户2457" => "私卡2457",
"伏8376" => "私卡8376",
"8376伏" => "私卡8376",
"农行8376" => "私卡8376",
"伏丽8376" => "私卡8376",
"伏丽 8376" => "私卡8376",
"伏丽837" => "私卡8376",
"私户8376" => "私卡8376",
"8376卡" => "私卡8376",
"越南8376" => "私卡8376",
"8376卡， 杰诚威" => "私卡8376",
"阿玲给现金" => "现金",
"现金-VND" => "现金",
"VND现金" => "现金",
"现金存入" => "现金",
"韦山余取现" => "现金",
"泰现金" => "现金",
"工行3438" => "公账3438",
"银行3438" => "公账3438",
"3438卡" => "公账3438",
"公账工行3438" => "公账3438",
"徐大文4343" => "私卡4343",
"工行4343" => "私卡4343",
"徐大文工行4343" => "私卡4343",
"私户4343" => "私卡4343",
"4343卡" => "私卡4343",
"建行0372" => "私卡0372",
"伏丽0372" => "私卡0372",
"伏开朗0372" => "私卡0372",
"私户0372" => "私卡0372",
"私账0372" => "私卡0372",
"0372卡" => "私卡0372",
"泰私5543" => "私卡5543",
"5543卡" => "私卡5543",
"私户5543" => "私卡5543",
"From Acc.5543" => "私卡5543",
"泰国公账1995" => "公账1995",
"公1995" => "公账1995",
"Bangkok Bank.Acc1995" => "公账1995" );
$data = json_decode(file_get_contents('data/Documents.json'), true);


$data1 = json_decode(file_get_contents($file), true);

foreach ($data1 as $r){
	$receiver_payer_name[$r['name']] = $r['id'];
	$receiver_payer_id[$r['id']] = $r['id'];
}
foreach ($listchange as $key =>  $r){
	$listchangeid[$receiver_payer_name[$key]] =  $receiver_payer_name[$r];
}
foreach ($data as $key => $r){
	if($listchangeid[$r['payer']] != ''){
		$data[$key]['payer'] = $listchangeid[$r['payer']];
	}
	if($listchange[$r['payer']] != ''){
		$data[$key]['payer'] = $receiver_payer_name[$listchange[$r['payer']]]; 
	}
}
$data =  array_values($data);
$write_json = json_encode($data);
file_put_contents('data/Documents1.json', $write_json);

foreach ($data1 as  $key => $r){
	if( $listchange[$r['name']] != '' ){
		unset($data1[$key]);
	}
}

$data1 =  array_values($data1);
$write_json = json_encode($data1);
file_put_contents('data/receiver_payer1.json', $write_json);

echo 'done';
die;
}
if (@$_GET['sync'] == '1') {
	$data = json_decode(file_get_contents('data/Documents.json'), true);
	$data1 = json_decode(file_get_contents($file), true);
	foreach ($data as $r){
		if(!is_array($r['payer'])){
			$r['payer'] =  array($r['payer']);
		}
		foreach ($r['payer'] as $j){
			$checkdata[$j] = 1;
		}		
	}
	
	//echo '<pre>';
	foreach ($data1 as $key =>  $r){
		if($checkdata[$r['id']] != 1 && $checkdata[$r['name']] != 1){
			unset($data1[$key]);
			$k++;
		}
	}
	$convert_array_to_json = array_values($data1);
    $write_json = json_encode($convert_array_to_json);
    file_put_contents($file, $write_json);
	echo 'done '.$k.' delete';
	die;
}

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: receiver_payer.php?msg=' . $i18n['Entry successfully deleted.']);
    
}



// READ DATA
$user = json_decode(file_get_contents('data/User.json'));
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['dniijd_type']) && $_POST['id'] != ''  ) {
	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']){
			$arr_data[$key]['type'] = $_POST['dniijd_type'];
		}
	}
	
	$jsondata = json_encode($arr_data);

    if (file_put_contents($file, $jsondata)) {
        $msg = $i18n['Data successfully saved!'];
    } else {
        $msg = $i18n['ERROR &mdash; Data not saved!'];
    }
	
	echo 'done';
	die;
}

$data = json_decode(file_get_contents($file), true);




if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['name'] != ''  ) {
	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 );
			 }
			
	}	
	
	$id = time();
	if($_POST['id'] == ''){	
	
	
	$formdata = array(
        'id' => $id	
		, 'name' => $_POST['name']
		, 'abbreviation' => $_POST['abbreviation']
		, 'type' => $_POST['type']
		, 'group1' => $_POST['group1']
		, 'bank1' => $_POST['bank1']
		, 'namedetail1' => $_POST['namedetail1']
		, 'account1' => $_POST['account1']
		, 'bankaddress1' => $_POST['bankaddress1']
		, 'hotline' => $_POST['hotline']
		, 'companyname' => $_POST['companyname']
		, 'transactionname' => $_POST['transactionname']
		, 'companyaddress' => $_POST['companyaddress']
		, 'account2' => $_POST['account2']
		, 'bank2' => $_POST['bank2']
		, 'bankaddress2' => $_POST['bankaddress2']
		, 'swiftcode' => $_POST['swiftcode']
		, 'tel' => $_POST['tel']
		, 'email' => $_POST['email']
		
		
        , 'description' => $_POST['description']
		, 'createdby' => $currentuser->name
		, 'createddate' => $id
		
		, 'filename' => $filename
		, 'filetype' => $filetype
		, 'filesize' => $filesize
		, 'filetimeupload' => $filetimeupload
		, 'filecreatebyid' => $filecreatebyid
		, 'filecreatebyname' => $filecreatebyname
		, 'filepath' => $filepath
		
		
		, 'modifieddate' => ''  
  	);
  	$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 ($data[$key] as $keylog => $logs ){
					if($keylog == 'modifieddate' || $keylog == 'modifiedby' || $keylog == 'createdby' || $keylog == 'createddate' ){
						continue;
					} elseif ( $_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/'.$r['id'],file_get_contents('logs/'.$r['id']).$textlog.PHP_EOL);
					
					}
				}	
				
				$arr_data[$key]['abbreviation'] = $_POST['abbreviation'];
				$arr_data[$key]['name'] = $_POST['name'];
				$arr_data[$key]['type'] = $_POST['type'];
				$arr_data[$key]['description'] = $_POST['description'];		
				$arr_data[$key]['modifieddate'] = $id;
				$arr_data[$key]['modifiedby'] = $currentuser->name;
				
				$arr_data[$key]['group1'] = $_POST['group1'];
				$arr_data[$key]['bank1'] =  $_POST['bank1'];
				$arr_data[$key]['namedetail1'] =  $_POST['namedetail1'];
				$arr_data[$key]['account1'] =  $_POST['account1'];
				$arr_data[$key]['bankaddress1'] =  $_POST['bankaddress1'];
				$arr_data[$key]['hotline'] =  $_POST['hotline'];
				$arr_data[$key]['companyname'] =  $_POST['companyname'];
				$arr_data[$key]['transactionname'] =  $_POST['transactionname'];
				$arr_data[$key]['companyaddress'] =  $_POST['companyaddress'];
				$arr_data[$key]['account2'] =  $_POST['account2'];
				$arr_data[$key]['bank2'] =  $_POST['bank2'];
				$arr_data[$key]['bankaddress2'] =  $_POST['bankaddress2'];
				$arr_data[$key]['swiftcode'] =  $_POST['swiftcode'];
				$arr_data[$key]['tel'] =  $_POST['tel'];
				$arr_data[$key]['email'] =  $_POST['email'];
				
				$arr_data[$key]['filename'] = $_POST['filename'];
				if(count((array)$filename) > 0){
					if(is_array($arr_data[$key]['filename'])){
						$arr_data[$key]['filename'] = array_merge($filename,$arr_data[$key]['filename']);
					}else{
						$arr_data[$key]['filename'] = $filename;
					}
					
					if(is_array($arr_data[$key]['filepath'])){
						$arr_data[$key]['filepath'] = array_merge($filepath,$arr_data[$key]['filepath']);
					}else{
						$arr_data[$key]['filepath'] = $filepath;
					}
					
					
					if(is_array($arr_data[$key]['filetype'])){
						$arr_data[$key]['filetype'] = array_merge($filetype,$arr_data[$key]['filetype']);
					}else{
						$arr_data[$key]['filetype'] = $filetype;
					}
					
					//$arr_data[$key]['filetype'] = array_merge($filetype,$arr_data[$key]['filetype']);
					$arr_data[$key]['filesize'] = array_merge($filesize,$arr_data[$key]['filesize']);
					$arr_data[$key]['filetimeupload'] = array_merge($filetimeupload,$arr_data[$key]['filetimeupload']);
					$arr_data[$key]['filecreatebyid'] = array_merge($filecreatebyid,$arr_data[$key]['filecreatebyid']);
					$arr_data[$key]['filecreatebyname'] = array_merge($filecreatebyname,$arr_data[$key]['filecreatebyname']);
					//$arr_data[$key]['filepath'] = array_merge($filepath,$arr_data[$key]['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: receiver_payer.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';


if($_POST['receiver_payer_name_array'] != ''){
	$receiver_payer_name_array = json_decode(file_get_contents('data/receiver_payer_name.json'),true);
	$receiver_payer_name_array[$_POST['type']] = $_POST['receiver_payer_name_array'];
	file_put_contents('data/receiver_payer_name.json',json_encode($receiver_payer_name_array));
}
if($_GET['delete_tab'] != ''){
	$receiver_payer_name_array = json_decode(file_get_contents('data/receiver_payer_name.json'),true);
	unset($receiver_payer_name_array[$_GET['delete_tab']]);
	file_put_contents('data/receiver_payer_name.json',json_encode($receiver_payer_name_array));
	//header('location: receiver_payer.php');
	//exit;
}

$receiver_payer_name_array = json_decode(file_get_contents('data/receiver_payer_name.json'),true);


// FORM FOR NEW ENTRY
if(@$_GET['q'] == ''){
?>
<?php    
if($_GET['print_name'] == 1 ){
	foreach ($data as $r){
		$name[] = $r['name'];
	}
	sort($name);
	echo '<pre>';print_r($name);
	die;
}	   
if($_GET['nocontrol'] == 1 || $_GET['payer'] != '' ){	
?>
<style>
.navbar-fixed {
	display:none;
}
#myTable {
	min-width: 1960px!important;
}
</style>
<script>

</script>
<?php } ?>
<script>

$(document).ready(function(){
   // $('select').formSelect();
	$(".cllogcontent").click(function(){
		$(".logcontent").html($(this).find('span').html());
	});
	
	$(".tab-link").dblclick(function(){
		$(this).find("span").hide();
		$(this).find("form").show();
	});
	
	$(".receiver_payer_name_array").change(function(){
		$(this).parents().eq(0).submit();
	});
	
	$('.abuj').change(function(){
		if (this.value == '1') {
			$('.dnii1').addClass('open');
			$('.dnii2').removeClass('open');
		}
		else if (this.value == '2') {
			$('.dnii2').addClass('open');
			$('.dnii1').removeClass('open');
		}
	});
});

function editc(id) {
$('.create-user form input[type="text"]').val('');
var obj = jQuery.parseJSON(id);
$('#name,#acronym,#contracttermsstart,#contracttermsend,#productid,#description,#abbreviation').next().addClass('active');

$('#id').val(obj.id);
$('#name').val(obj.name);
$('#abbreviation').val(obj.abbreviation);
$('#description').val(obj.description);
$('#type').val(obj.type);
$('select').formSelect();

if (typeof obj.group1 != 'undefined'){
	if(obj.group1 == 1){
		$('#abuj1').prop('checked',true).change();
		$('#bank1,#namedetail1,#account1,#bankaddress1,#hotline').next().addClass('active');
	}
	if(obj.group1 == 2){
		$('#abuj2').prop('checked',true).change();
		$('#companyname,#transactionname,#companyaddress,#account2,#bank2,#bankaddress2,#swiftcode,#tel,#email').next().addClass('active');
	}
}
if (typeof obj.bank1 != 'undefined'){
	$('#bank1').val(obj.bank1);
}
if (typeof obj.namedetail1 != 'undefined'){
	$('#namedetail1').val(obj.namedetail1);
}
if (typeof obj.account1 != 'undefined'){
	$('#account1').val(obj.account1);
}
if (typeof obj.bankaddress1 != 'undefined'){
	$('#bankaddress1').val(obj.bankaddress1);
}
if (typeof obj.hotline != 'undefined'){
	$('#hotline').val(obj.hotline);
}
if (typeof obj.companyname != 'undefined'){
	$('#companyname').val(obj.companyname);
}
if (typeof obj.transactionname != 'undefined'){
	$('#transactionname').val(obj.transactionname);
}
if (typeof obj.companyaddress != 'undefined'){
	$('#companyaddress').val(obj.companyaddress);
}
if (typeof obj.account2 != 'undefined'){
	$('#account2').val(obj.account2);
}
if (typeof obj.bank2 != 'undefined'){
	$('#bank2').val(obj.bank2);
}
if (typeof obj.bankaddress2 != 'undefined'){
	$('#bankaddress2').val(obj.bankaddress2);
}
if (typeof obj.swiftcode != 'undefined'){
	$('#swiftcode').val(obj.swiftcode);
}
if (typeof obj.tel != 'undefined'){
	$('#tel').val(obj.tel);
}
if (typeof obj.email != 'undefined'){
	$('#email').val(obj.email);
}
$('.chip').remove();
$('.file-path').addClass('isacctive');

if (typeof obj.filename != 'undefined'){
$.each( obj.filename, function( key, value ) {
  $('.chips').prepend('<div class="chip" tabindex="0"><input type="hidden" name="filename[]" value="'+value+'" /><i style="cursor: pointer;" class="fas fa-times"></i> '+value+'</div>');
});
}



}
        
</script>     
<style>
.ishide:not(.open)::before {
    content: "";
    background: #000;
    opacity: 0.2;
    width: 92%;
    height: 80px;
    position: absolute;
    z-index: 100;
    right: 0;
    top: 0px;
} 
table.tablesorter thead tr th {
    background-color: #1c278a;
    color: #fff;
}
table.tablesorter tr td tr th {
   padding: 5px 5px;
}
table.tablesorter tbody td {
    vertical-align: top;
    border-bottom: 1px solid #ccc;
}
</style>       

        <div class="badge grey lighten-3 hoverable create-user">
			<?php if($_GET['payer'] == '' ){ ?>
            <form action="receiver_payer.php?nocontrol=<?php echo $_GET['nocontrol']; ?>" method="POST" enctype="multipart/form-data" >
				<input value=""  id="id" name="id" 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"  />
                        <label for="name">编号</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Numbering
                        </span>
                    </div> 	
					<div class="input-field col s2">
                        <input 
                            value="<?php echo @$_POST['abbreviation']; ?>" 
                            id="abbreviation" 
                            name="abbreviation" 
                            type="text" 
                            class="validate"   />
                        <label for="abbreviation">收付款人简称</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                          Abbreviation
                        </span>
                    </div>					
					<div class="input-field col s3">
                        <input 
                            value="<?php echo @$_POST['description']; ?>" 
                            id="description" 
                            name="description" 
                            type="text" 
                            class="validate" />
                        <label for="description">备注</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                          Details
                        </span>
                    </div>
					<div class="input-field col s3  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" style="z-index: 1000;" >
							</div>
							<div class="file-path-wrapper">
							
							<div class="chips chips-initial input-field" style="    margin: 0;" >
								<input class="file-path validate" type="text" style="border-bottom: 0;" placeholder="<?php echo $i18n['Upload your file']; ?>">
							</div>
								 
							</div>
						</div>
					</div>
					<div class="input-field col s1"  >
						<select name="type" id="type">
						<?php foreach ($receiver_payer_name_array as $key => $r){ if($kpf++ == 0){ $key = ''; } ?>
						<option value="<?php echo $key; ?>" ><?php echo $r; ?></option>
						<?php }?>
						</select>
						<label for="type">Type</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">Save</button>
                    </div>
					<div class="input-field col s12 ishide dnii1"  style="margin: 0;" >
					  <div class="input-field col s1">
						 <label>
							<input name="group1"  class="abuj"  id="abuj1" type="radio" value="1" />
							<span>私卡</span>
						 </label>
					  </div>
					  <div class="input-field col s2">
                        <input 
                            value="" 
                            id="bank1" 
                            name="bank1" 
                            type="text" 
                            class="validate"  />
                        <label for="bank1">开户行</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Bank
                        </span>
					  </div> 	
					  <div class="input-field col s2">
                        <input 
                            value="" 
                            id="namedetail1" 
                            name="namedetail1" 
                            type="text" 
                            class="validate"  />
                        <label for="namedetail1">户名</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Name
                        </span>
					  </div>
					  <div class="input-field col s2">
                        <input 
                            value="" 
                            id="account1" 
                            name="account1" 
                            type="text" 
                            class="validate"  />
                        <label for="account1">账号</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Account Number
                        </span>
					  </div>
					  <div class="input-field col s2">
                        <input 
                            value="" 
                            id="bankaddress1" 
                            name="bankaddress1" 
                            type="text" 
                            class="validate"  />
                        <label for="bankaddress1">银行地址</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Bank Address
                        </span>
					  </div>
					  <div class="input-field col s2">
                        <input 
                            value="" 
                            id="hotline" 
                            name="hotline" 
                            type="text" 
                            class="validate"  />
                        <label for="hotline">热线</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Hotline
                        </span>
					  </div>
					</div>
					<div class="input-field col s12 ishide dnii2" style="margin: 0;" >
					  <div class="input-field col s1">
						 <label>
							<input name="group1" class="abuj" id="abuj2" type="radio" value="2" />
							<span>公账</span>
						 </label>
					  </div> 
						 <div class="input-field col s2">
							<input 
								value="" 
								id="companyname" 
								name="companyname" 
								type="text" 
								class="validate"  />
							<label for="companyname">公司名</label>
							<span class="helper-text" data-error="Error" data-success="OK">
							   Company name
							</span>
						  </div> 
						  <div class="input-field col s1">
							<input 
								value="" 
								id="transactionname" 
								name="transactionname" 
								type="text" 
								class="validate"  />
							<label for="transactionname">英文名称</label>
							<span class="helper-text" data-error="Error" data-success="OK">
							  Transaction
							</span>
						  </div>	
						 <div class="input-field col s2">
							<input 
								value="" 
								id="companyaddress" 
								name="companyaddress" 
								type="text" 
								class="validate"  />
							<label for="companyaddress">地址</label>
							<span class="helper-text" data-error="Error" data-success="OK">
							  Company Address
							</span>
						  </div>
						<div class="input-field col s1">
                        <input 
                            value="" 
                            id="account2" 
                            name="account2" 
                            type="text" 
                            class="validate"  />
                        <label for="account2">账号</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Account
                        </span>
					  </div> 
						<div class="input-field col s2">
                        <input 
                            value="" 
                            id="bank2" 
                            name="bank2" 
                            type="text" 
                            class="validate"  />
                        <label for="bank2">开户行</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Bank
                        </span>
					  </div> 	
					   <div class="input-field col s2">
                        <input 
                            value="" 
                            id="bankaddress2" 
                            name="bankaddress2" 
                            type="text" 
                            class="validate"  />
                        <label for="bankaddress2">银行地址</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Bank Address
                        </span>
					  </div>
						<div class="input-field col s1">
                        <input 
                            value="" 
                            id="swiftcode"
                            name="swiftcode" 
                            type="text" 
                            class="validate"  />
                        <label for="swiftcode">SWIFT CODE:</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                        </span>
					  </div>
						<div class="input-field col s1">
                        <input 
                            value="" 
                            id="tel" 
                            name="tel" 
                            type="text" 
                            class="validate"  />
                        <label for="tel">联系电话</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           Tel
                        </span>
					  </div>
					  <div class="input-field col s1">
                        <input 
                            value="" 
                            id="email" 
                            name="email" 
                            type="text" 
                            class="validate"  />
                        <label for="email">邮箱 </label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           E-mail
                        </span>
					  </div>
					 
					</div>
                </div>
            </form>
			<?php } ?>
        </div>
    <?php
}
// DATA TABLE
if (!empty($data)) {
    // LOOP EACH ENTRY
    ?>
	<?php if($_GET['payer'] == ''){ ?>
	<ul style="display:flex;background:#eeeeee;align-items:center;height:unset;" class="tabs">
		<button data-target="addNewTab" onclick="$('.bkhkidh').show();" 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>
		<li data-tab="" class="tab-link bkhkidh" style="display:none;" >
			<form method="post" ><input style="height: 18px;"  name="receiver_payer_name_array" type="text" value="" class="receiver_payer_name_array" />
			<input name="type" type="hidden" value="Newcase<?php echo time(); ?>" />
			</form>
		</li>
			
		<?php $kpf = 0; foreach ($receiver_payer_name_array as $key => $r){ $kpf++; ?>
			<li data-tab="tab-<?php echo $kpf-1; ?>" class="tab-link classtab-<?php echo $kpf-1; ?> <?php if($kpf == 1){ echo 'current'; } ?>" <?php if($kpf != 1){ echo 'onclick="$(\'.typedefault\').hide();$(\'.'.$key.'\').show();"'; } ?>><span><?php echo $r; ?></span>
			<form method="post" style="display:none;" ><input style="height: 18px;    width: 120px;"  name="receiver_payer_name_array" type="text" value="<?php echo $r; ?>" class="receiver_payer_name_array" /><input name="type" type="hidden" value="<?php echo $key; ?>" />
			<a href="#" onclick="if (confirm('Are you sure delete this account ?')) { window.location.replace('receiver_payer.php?delete_tab=<?php echo $key; ?>');}" class="material-icons close tab-1563435423" style="display: block;float: right;margin-right: -28px;margin-left: 28px;" >close</a>
			</form></li>
		<?php }?>
		
		
		
	</ul>	
	<?php } ?>	
    <table class="striped responsive-table hoverable tablesorter" id="myTable" style="min-width:1360px;" >
            <thead>
                <tr>
					<th style="width: 33px;" ></th>
					<th><input type="text" id="myInput" onkeyup="myFunction()" placeholder="编号/Numbering" style="color:#fff;" ></th>
                    <th>收付款人简称</th>
					<th>备注</th>  
					<th>Info</th>   	
					<th style="width: 100px;" >档案文件</th>		
					<th>创造/改性</th>
					<th style="width: 85px;" >类型</th>
					<th style="width: 70px;" ></th>
                </tr>
            </thead>
        <tbody>
   <?php 
     $total_receivable = $total_amount = $total_profit = 0;
     $countNo = 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;"});';
						if($_GET['payer'] != '' && $_GET['payer'] !=  $values['name'] && $_GET['payer'] !=  $values['id'] ){
							continue;
						}
					
						$file = ''; 
								
								
						foreach ($values['filename'] as $keyfile => $dataf ){
										$fnjf++;
										if ( strpos($values['filetype'][$keyfile] , 'pdf')  !== false ) {
												if( $currentuser->location == '中国' ){
													$file .=  '<a ref="https://htlservice.net/expense/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/expense/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/expense/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/expense/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="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="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/file.png" style="width:24px;height:auto;" /></a>';
										}
						}
						
	            ?>    
                <tr class="typedefault <?php if($values['type'] != '' && isset($receiver_payer_name_array[$values['type']]) ){ echo $values['type']; }else{ echo 'nonetab'; } ?>" style="<?php if($values['type'] != '' && isset($receiver_payer_name_array[$values['type']]) && $_GET['payer'] == '' ){ echo 'display:none;'; } if($values['notapprove'] == 1){ ?> background:#ffcaca; <?php } ?>" >
					<td style="padding-left:6px"><?php echo ++$k['k_'.$values['type']]; ?></td>
					<td style="padding-left:6px"><a data-target="modal8" href="#" class="modal-trigger payerdetail" name="<?= $values['name']?>" id="<?= $values['id']?>"  ><?= $values['name']?></a></td>
					<td style="padding-left:6px"><?= $values['abbreviation']?></td>
                    <td style="padding-left:6px"><?= $values['description']?></td> 
					<td style="padding-left:6px">
						<?php
							if($values['group1'] == 1 ){
								?>
								  <table class="striped responsive-table hoverable tablesorter" id="tab-table1">
									<thead>
										<tr>
											<th>开户行（Bank)</th>
											<th>户名 (Name)</th>
											<th>账号 (Account Number)</th>  
											<th>银行地址(Bank Address)</th>   	
											<th>热线（Hotline）</th>											
										</tr>
									</thead>
									<tbody>
										<tr>
											<th><?php echo $values['bank1']; ?></th>
											<th><?php echo $values['namedetail1']; ?></th>
											<th><?php echo $values['account1']; ?></th>  
											<th><?php echo $values['bankaddress1']; ?></th>   	
											<th><?php echo $values['hotline']; ?></th>											
										</tr>
									</tbody>
								  </table>
								<?php
							}
							if($values['group1'] == 2 ){
								?>
								  <table class="striped responsive-table hoverable tablesorter" id="tab-table1">
									<thead>
										<tr>
											<th>公司名(Company name)</th>
											<th>英文名称 (Transaction name)</th>
											<th>地址 (Company Address)</th>  
											<th>账号（Account Number）</th>   	
											<th>开户行 （Bank）</th>
											<th>银行地址 (Bank Address)</th>
											<th>SWIFT CODE</th>
											<th>联系电话 (Tel)</th>
											<th>邮箱 (E-mail)</th>
										</tr>
									</thead>
									<tbody>
										<tr>
											<th><?php echo $values['companyname']; ?></th>
											<th><?php echo $values['transactionname']; ?></th>
											<th><?php echo $values['companyaddress']; ?></th>  
											<th><?php echo $values['account2']; ?></th>   	
											<th><?php echo $values['bank2']; ?></th>		
											<th><?php echo $values['bankaddress2']; ?></th>
											<th><?php echo $values['swiftcode']; ?></th>
											<th><?php echo $values['tel']; ?></th>  
											<th><?php echo $values['email']; ?></th> 											
										</tr>
									</tbody>
								  </table>
								<?php
							}
						?>
					</td> 	
					<td style="<?php echo $n; ?>" ><?php echo $file; ?></td>					
					<td style="padding-left:6px"><a href="#" title="<?= date('d/m/y h:i',$values['id']); ?>" ><?= $values['createdby']?><a><?php if($values['modifiedby']){ echo '<br><a title="'.date('d/m/y h:i',$values['modifieddate']).'" >'.$values['modifiedby'].'</a>'; } ?></td>
					<td style="padding-left:6px">
						<form class="dniijd" >
							<select name="dniijd_type" class="dniijd_type" >
								<?php $kpf = 0; foreach ($receiver_payer_name_array as $keyd => $rd){ if($kpf++ == 0){ $keyd = ''; } ?>
								<option value="<?php echo $keyd; ?>" <?php if($keyd == $values['type']){ echo 'selected=""';} ?> ><?php echo $rd; ?></option>
								<?php }?>
							</select>
							<input name="id" type="hidden" value="<?php echo $values['id']; ?>" />
						</form>
					</td>
                    <td style="">
						<?php if($_GET['payer'] == ''){ ?>
						<?php  if($currentuser->role == 'Manager' || $currentuser->role == 'Finance'  ) {  echo $logsmode ; ?>
                        <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 } ?>
                        <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 } ?>	
                    </td>
                </tr>
            <?php  }  ?>
        </tbody>
        </table>
		
		<?php $kpf = 0; foreach ($receiver_payer_name_array as $key => $r){ $kpf++; if($kpf == 1){ $key = ''; } ?>
		 <script>$('.classtab-<?php echo $kpf-1; ?> > span ').append(' (<?php echo $k['k_'.$key]; ?>)');</script>
		<?php } ?>
<div id="modal6" class="modal">
  <div class="logcontent" style="padding: 15px;" ></div>
</div>	
<div id="modal8" class="modal">
	<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="receiverpayer" src="" width="100%" style="height:auto;    min-height: 600px;" ></iframe>
</div>
<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
}
?>
<style>
#modal8 { min-width: 1280px; }
.mystyle {
	display:none!important;
}
</style>
<script>
jQuery('.payerdetail').click(function(){
		jQuery('.receiverpayer').attr( 'src','/expense/index_payer.php?name='+jQuery(this).attr('name')+'&id='+jQuery(this).attr('id'));
});	
	
$('.tab-link').click(function(){
	if($(this).attr('data-tab') == 'tab-0'){
		$('.typedefault').hide();
		$('.nonetab').show();
	}
});
$('.dniijd_type').change(function(){
	$(this).parents('form.dniijd').eq(0).submit();
			
});
$(".dniijd").submit(function(){
	$.ajax({ 
					type: 'POST', 
					url: '<?php echo $_SERVER[REQUEST_URI]; ?>', 
					enctype: 'multipart/form-data',
					processData: false,
					contentType: false,
					data: new FormData(this) ,
					success: function(data) {

					}
	});
	return false;
});
function myFunction() {
  // Declare variables
  var input, filter, table, tr, td, i, txtValue;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");

  // Loop through all table rows, and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[1];
	td2 = tr[i].getElementsByTagName("td")[2];
	td3 = tr[i].getElementsByTagName("td")[3];
    if (td) {
      txtValue = td.textContent+td2.textContent+td3.textContent; // || td.innerText;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].classList.remove("mystyle");
      } else {
        tr[i].classList.add("mystyle");
      }
    }
  }
}
</script>
<?php
include 'tpl/footer.php';
?>
