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

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

$LANG =  '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/' . $TYPE . '.json'; // DATA FILE NAME
// LOGIN CHECK
$login = check_current_user_login($ARR_USERS, $SALT);
$currentuser = $login['user'];
$currency = json_decode(file_get_contents('data/Currency.json'), true);
$_SESSION['currencyUser'] = '';
if ($currencyUser == ''){
	$currencyUser = '1560828928';
}
if ($_GET['currency'] != ''){
	$currencyUser = $_GET['currency'];
	
	foreach ($currency as $r){
		if($currencyUser == $r['id']){
			$_SESSION['currencyUser'] = $r;
		}
	}
}
if($_SESSION['currencyUser'] == ''){
	foreach ($currency as $r){
		if($currencyUser == $r['id']){
			$_SESSION['currencyUser'] = $r;
		}
	}
}

if ($login['status'] == 200) {    
    if($currentuser->gm  != '1' && $currentuser->role != 'Finance' && $currentuser->total != '1' && $currentuser->totalconsignee != '1' && $currentuser->totalmonth != '1'  && $currentuser->mod4 != '1' ){ //  && $currentuser->location != '总公司'
		header('location: index.php');
        exit;
	}
} else {
    header('location: login.php');
    exit;
}



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

if ($_SERVER['REQUEST_METHOD'] == 'POST' and isset($_POST['summarytable']) ) {
	$jsondata = json_decode( file_get_contents("data/Setting2.json"),true );
	foreach ($_POST as $key => $r){
		$jsondata[$key] = $r;
	}
	if (file_put_contents("data/Setting2.json", json_encode($jsondata))) {
        $msg = $i18n['Data successfully saved!'];
    } else {
        $msg = $i18n['ERROR &mdash; Data not saved!'];
    }
	header('location: total.php');
}


if ($_SERVER['REQUEST_METHOD'] == 'POST' and $_POST['password'] != '' ) {
	
	$jsondata = json_decode( file_get_contents("data/User.json"),true );
	foreach ($jsondata as $key => $r){
		if( $r['id'] == $currentuser->id ){
			$jsondata[$key]['password'] = $_POST['password'];
		}
	}
	if (file_put_contents("data/User.json", json_encode($jsondata))) {
        $msg = $i18n['Data successfully saved!'];
    } else {
        $msg = $i18n['ERROR &mdash; Data not saved!'];
    }
    header('location: index.php?msg=' . $msg);
}

if ($_SERVER['REQUEST_METHOD'] == 'POST' and $_POST['updateremak'] == 1 ) {
	//print_r($_POST);die;
	$jsondata = json_decode( file_get_contents("data/TotalRemark.json"),true );
	foreach ($_POST as $key => $r){
                $jsondata[$key.'_last'] = $jsondata[$key];
                $jsondata[$key.'_who'] = $currentuser->name;
                $jsondata[$key.'_time'] = time();
                $jsondata[$key] = $r;
	}
	if (file_put_contents("data/TotalRemark.json", json_encode($jsondata))) {
        $msg = $i18n['Data successfully saved!'];
    } else {
        $msg = $i18n['ERROR &mdash; Data not saved!'];
    }
	header('location: total.php?msg=' . $msg);
}


// READ DATA
$newdata = array();
$data = json_decode(file_get_contents($file), true);

// HEADER
ob_end_flush();
include 'tpl/header.php';
//var_dump($currentuser);
$showtotalaccount = 0;
$showmod20 = 0;
$showtotalconsignee = 0;
$showtotalmonth = 0;
$showtotalal = 0;
if($currentuser->gm  != '1'){
	if(isset($currentuser->total)){
		if($currentuser->total == '1'){
			$showtotalaccount = 1;
		}
	}
	if(isset($currentuser->totalconsignee)){
		if($currentuser->totalconsignee == '1'){
			$showtotalconsignee = 1;
		}
	}
	if(isset($currentuser->totalmonth)){
		if($currentuser->totalmonth == '1'){
			$showtotalmonth = 1;
		}
	}
        if(isset($currentuser->mod4)){
		if($currentuser->mod4 == '1'){
			$showtotalal = 1;
		}
	}
        
        if(isset($currentuser->mod20)){
		if($currentuser->mod20 == '1'){
			$showmod20 = 1;
		}
	}
}else{
	$showtotalaccount = 1;
	$showtotalconsignee = 1;
	$showtotalmonth = 1;
        $showtotalal = 1;
        $showmod20 = 1;
}
echo '<div style="display:none;">showtotalaccount='.$showtotalaccount.'|showtotalconsignee='.$showtotalconsignee.'|showtotalmonth='.$showtotalmonth.'</div>';
?>
<form class="formupload" method="POST">
<input type="hidden" name="updateremak"  value="1" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<?php if($showtotalaccount == 1){
	?>
	<h2 style="text-align:center;font-size: 28px; margin-top: 190px;" >MOD1余额汇总</h2>
	<table style="width: 100%!important;position: relative;margin-top: 10px;" class="striped responsive-table  tablesorter  "  >
	  <thead>
			<tr>
			<th style="width:100px;    background-color: #ccc;" ><div style="    text-align: right;" >类别</div>
			<select class="asdnasndasjkl" onchange="if($(this).val() == 0){ $('.fullaccount').show();  $('.fullttaccount').hide(); $('.全部').show();   }else{  $('.fullttaccount').hide(); $('.fullaccount').hide(); $('.'+$(this).val()).show(); }" >
				<option value="0" >全部</option>
				<option value="公司账户" >公司账户</option>
				<option value="供应商账户" >供应商账户</option>
				<option value="停用账户" >停用账户</option>
				<option value="已注销账户" >已注销账户</option>
			</select>
			
			</th>
			<th style="width:200px;" ><div style="    text-align: right;" >币种</div>
			<div style="
					border: 1px solid;
					transform: rotateZ(24deg);
					width: 113%;
					margin-left: -6%;
				"></div>
			<div>账户</div></th>
			<th style="width:70px;display:none;" >Currency</th>
			<th>USD</th>		
			<th>RMB</th>
			<th>VND</th>
			<th>THB</th>
                        <th>HKD</th>
                        <th>IDR</th>
                        <th>MYR</th>
			<th><?php echo $_SESSION['currencyUser']['currency']; ?> Exchange</th>
			<th style="width:50%;" >备注</th>
			</tr>
	  </thead>
	  <tbody>
	<?php   
	
	if(isset($_POST['datestart'])){
				$datestart = $_POST['datestart'];
	}else{
				$datestart = date('Y.m.d',strtotime("-365 day"));
	}		
	if(isset($_POST['dateto'])){
				$dateto = $_POST['dateto'];
	}else{
				$dateto = date('Y.m.d');
	}
	/*
	foreach ($data as $key => $values) {       
		$data2[$values['id']] = $values;
	}
	ksort($data2);
	$data = array_values($data2);
	*/
        $data11 = $data;
	foreach($tabs as $tab){
		if($tab->name == '阿黄（HK）8979卡' || $tab->name == '阿达车队9006卡' || $tab->name == '新港车队0007卡' || $tab->name == '国内-伏开朗0174注销'  ){continue;}
                if($currentuser->role != 'Controller' && $currentuser->gm  != '1'){
                    if(!in_array($tab->id, $currentuser->account)){
                        continue;
                    }
                }
                
		// LOOP EACH ENTRY
		$total_receivable = $total_amount = $total_profit = 0;
		$countNo = 0;
		$amountincome = 0;
		$amountpayout = 0;
		$balanceJun = $balance = 0;
		
		foreach($currency as $rcurrency){
				if($rcurrency['id'] == $tab->currency ){
					$exchangerate =  $rcurrency['exchangerate'];
					$currencyname =  $rcurrency['currency'];
				} 	
		}
                
		if($currencyname == "HKD"){
                    foreach($currency as $rcurrency){
				if($rcurrency['currency'] == 'HKDRMB' ){
					$exchangerate =  $rcurrency['exchangerate'];
				} 	
                    }	
		}	
                
		$tygia = json_decode(file_get_contents('currency/'.date('Ymd'))); 
		for($i = 9; $i >= 0; $i--){			
					//$tygia = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));				
					if($currencyname == "USD"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (floatval($tab->balance)*$tygia->USD);
					}elseif($currencyname == "VND"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (floatval($tab->balance)*$tygia->VND);
					}elseif($currencyname == "RMB"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (floatval($tab->balance));
					}elseif($currencyname == "Baht"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (floatval($tab->balance)*$tygia->THB);
					}elseif($currencyname == "HKD"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (floatval($tab->balance)*$tygia->HKDRMB);
					}elseif($currencyname == "MYR"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (floatval($tab->balance)*$tygia->MYR);
					}elseif($currencyname == "IDR"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (floatval($tab->balance)*$tygia->IDR);
					}
		}
		
		foreach ($data as $key => $values) {       
			$appprove = 0; 
			if( $values['tabs'] == '' ){
				foreach ($tabdocfull as $keytab => $r){
					if ( $values['id'] == $r->iddoc && $tab->id == $r->idtab ) {
						$appprove = 1; 
						$rt = $r->idtab;		
						unset($tabdocfull[$keytab]);	break;
					}
				}
				if ($appprove == 0){
				 continue;
				}
			}else{
				if ($values['tabs'] != $tab->id ){
					 continue;
				}
				$rt = $values['tabs'];
			}
			
			
		
			if($tab->special3 == 1){
				
				if($values['exchangeusdtovnd'] > 0){
					$balance += (((float)$values['exchangeusdtovnd']*(float)$values['amountpayoutusd']) - ((float)$values['amountpayout'])) ;
				}else{
					$balance += (((float)$values['amountincome']) - ((float)$values['amountpayout'])) ;
				}
			}else{
				$balance += (abs((float)$values['amountincome']) - abs((float)$values['amountpayout'])) ;
			}
			
			$balancespecial3 += (((float)$values['amountincomeusd']) - ((float)$values['amountpayoutusd']));
			if(stripos($tab->name,'2457') !== false || stripos($tab->name,'8272') !== false || stripos($tab->name,'6414') !== false ) {
				if( stripos($values['charge'],'王军') !== false && $values['id'] >= strtotime(str_replace('.','-',$Setting['summarytable']))){
					$balanceJun += (((float)$values['amountincome']) - ((float)$values['amountpayout'])) ;
					$lineup[$tab->name][] = date('Y.m.d H:i:s',$values['id']).':'.(((float)$values['amountincome']) - ((float)$values['amountpayout'])).' | '.($balanceJun+(float)str_replace(',','',$Setting['account'][$tab->name]));
				}
			}
			
			for($i = 9; $i >= 0; $i--){
				if(date('Ymd',strtotime("-".$i." day")) >= date('Ymd',$values['id']) ){
					//$tygia = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));
					if($currencyname == "USD"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$tygia->USD;
						$sumbydate['a'.date('Y-m-d',strtotime("-".$i." day"))][] = $values['amountincome'].' - '.$values['amountpayout'].' - '.$sumbydate[date('Y-m-d',strtotime("-".$i." day"))].' - '.$tygia->USD;
					}elseif($currencyname == "VND"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$tygia->VND;
					}elseif($currencyname == "RMB"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']));
					}elseif($currencyname == "Baht"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$tygia->THB;
					}elseif($currencyname == "HKD"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$tygia->HKDRMB;
					}elseif($currencyname == "MYR"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$tygia->MYR;
					}elseif($currencyname == "IDR"){
						$sumbydate[date('Y-m-d',strtotime("-".$i." day"))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$tygia->IDR;
					}
				}	
			}
				
			if( date('Y.m.d',$values['id']) >=  $datestart && date('Y.m.d',$values['id']) <=  $dateto ){
				$chart[$tab->location][$values['classification'].' '] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate/$_SESSION['currencyUser']['exchangerate'];
			}else{
				$chart[$tab->location][$values['classification'].' '] += 0;
			}
			unset($data[$key]);
	   }
           
         
                
		if(stripos($tab->name,'4400') !== false){
                    $balance  = $balance - 5945;
                }
					
		$remark = '';$remarkwho = '';$remarktime = '';$remarklast = '';
		foreach ($TotalRemark as $key => $r){
			if($key == 'remark_'.$tab->id ){
				$remark = $r;                       
			}
					if($key == 'remark_'.$tab->id.'_who' ){			
							$remarkwho = $r;
			}
					if($key == 'remark_'.$tab->id.'_time' ){			
							$remarktime = date('Y-m-d H:i',$r);
			}
					if($key == 'remark_'.$tab->id.'_last' ){			
							$remarklast = $r;
			}
		}
		$balanceusd = $balancermb = $balancevnd = $balancethb = $balancemyd = $balanceidr = $balancehkd = 0;
		
		if($currencyname == "USD" || $tab->special3 == 1 ){
			if($tab->special3 == 1){
				$balanceusd = $balancespecial3;
				$balancevnd = $balance+floatval($tab->balance);
				$balance = $balance+($balancespecial3*$tygia->USDVND);
			}else{
				$balanceusd = $balance+floatval($tab->balance);
			}	
		}elseif($currencyname == "VND"){
			$balancevnd = $balance+floatval($tab->balance);
		}elseif($currencyname == "RMB"){
			$balancermb = $balance+floatval($tab->balance);
		}elseif($currencyname == "Baht"){
			$balancethb = $balance+floatval($tab->balance);
		}elseif($currencyname == "HKD"){
			$balancehkd = $balance+floatval($tab->balance);
		}elseif($currencyname == "MYR"){
			$balancemyd = $balance+floatval($tab->balance);
		}elseif($currencyname == "IDR"){
			$balanceidr = $balance+floatval($tab->balance);
		}
               
		if(stripos($tab->name,'2457') !== false || stripos($tab->name,'8272') !== false || stripos($tab->name,'6414') !== false ) {
			if($currencyname == "USD"  ){
				$tab_ex[$tab->name]['balanceusd'] = $balanceJun+(float)str_replace(',','',$Setting['account'][$tab->name]);
				$balanceJun+=(float)str_replace(',','',$Setting['account'][$tab->name]);
			}elseif($currencyname == "VND"){
				$tab_ex[$tab->name]['balancevnd'] = $balanceJun+(float)str_replace(',','',$Setting['account'][$tab->name]);
				$balanceJun+=(float)str_replace(',','',$Setting['account'][$tab->name]);			
			}elseif($currencyname == "RMB"){
				$tab_ex[$tab->name]['balancermb'] = $balanceJun+(float)str_replace(',','',$Setting['account'][$tab->name]);
				$balanceJun+=(float)str_replace(',','',$Setting['account'][$tab->name]);
			}elseif($currencyname == "Baht"){
				$tab_ex[$tab->name]['balancethb'] = $balanceJun+(float)str_replace(',','',$Setting['account'][$tab->name]);	
				$balanceJun+=(float)str_replace(',','',$Setting['account'][$tab->name]);
			}elseif($currencyname == "HKD"){
				$tab_ex[$tab->name]['balancehkd'] = $balanceJun+(float)str_replace(',','',$Setting['account'][$tab->name]);	
				$balanceJun+=(float)str_replace(',','',$Setting['account'][$tab->name]);
			}elseif($currencyname == "MYR"){
				$tab_ex[$tab->name]['balancemyr'] = $balanceJun+(float)str_replace(',','',$Setting['account'][$tab->name]);	
				$balanceJun+=(float)str_replace(',','',$Setting['account'][$tab->name]);
			}elseif($currencyname == "IDR"){
				$tab_ex[$tab->name]['balanceidr'] = $balanceJun+(float)str_replace(',','',$Setting['account'][$tab->name]);	
				$balanceJun+=(float)str_replace(',','',$Setting['account'][$tab->name]);
			}
			$tab_ex[$tab->name]['balance'] = (float)($balanceJun)*(float)$exchangerate/(float)$_SESSION['currencyUser']['exchangerate'];
			$tab_ex[$tab->name]['currencyname'] = $currencyname;
		}
		
               
                
		$total += (float)($balance+floatval($tab->balance))*(float)$exchangerate/(float)$_SESSION['currencyUser']['exchangerate'];
		
		$totalx[$tab->tabsg] += (float)($balance+floatval($tab->balance))*(float)$exchangerate/(float)$_SESSION['currencyUser']['exchangerate'];
		$sumbydate[date('Y-m-d')] = $total;
		
			
	?>
	
	<tr class="fullaccount <?php echo $tab->tabsg; ?>" >
			<td><b><?php echo $tab->tabsg; ?></b></td>
			<td style="width:180px;padding-left:10px!important;" ><?php echo $tab->name; ?></td>
			<td style="text-align:center;display:none;" ><?php echo $currencyname; ?></td>
			<td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><?php echo number_format((float)$balanceusd,2); ?></td>
			<td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><?php echo number_format((float)$balancermb,2); ?></td>
			<td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><?php echo number_format((float)$balancevnd); ?></td>
			<td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><?php echo number_format((float)$balancethb,2); ?></td>
                        <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><?php echo number_format((float)$balancehkd,2); ?></td>
			<td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><?php echo number_format((float)$balanceidr,0); ?></td>
                        <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><?php echo number_format((float)$balancemyd,0); ?></td>
                        <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><?php echo number_format(($balance+floatval($tab->balance))*$exchangerate/$_SESSION['currencyUser']['exchangerate'],2); ?></td>
					<td style="padding-left:10px!important;" ><input  <?php  $remarklast_array = explode(' ',$remarklast);
					//$remark_array = explode(' ',$remark);
					$asd = array();$havechange = 0;
					foreach($remarklast_array as $key => $r){
						if(stripos($remark,$r) !== false){
							$asd[] = $r;
						}else{
							$havechange = 1;
							$asd[] = '<span class=\'tored\' >'.$r.'</span>';
						}
					}
					if($havechange){
					?> data-tooltip="修改人: <?php echo $remarkwho; ?> (<?php echo $remarktime; ?>) | Log: <?php echo implode(' ',$asd); ?>" type="text"  <?php } ?> class="remark totip" style="width: 90%;float: left;" name="remark_<?php echo $tab->id; ?>" value="<?php echo $remark ?>" />
                                            <button type="button" style="cursor:pointer;    margin-left: 6px;    display: block;    background: #1b278a;    border: none;    padding: 5px 10px;    color: #fff;   border-radius: 3px;width: 70px;float: right;" >保存</button></td>
	</tr>
	
	
	<?php
         if(stripos($tab->name,'国内-伏开朗0174注销') !== false){
                    //echo $balance;
                  //  echo $currencyname;
                    //echo $balancevnd;
                  //  echo ($balance+floatval($tab->balance))*$exchangerate/$_SESSION['currencyUser']['exchangerate'];
                   // die;
                }
	}
	?>
	</tbody>
	<tfoot>
	<tr>
		<td></td><td style="display:none;" ><td></td></td><td></td><td></td><td></td><td></td><td></td><td></td><td  style="text-align:right;font-weight:bold;font-size:18px;" ><b>
		
		<span class="fullttaccount 全部" >全部</span>
		<span class="fullttaccount 公司账户" style="display:none;" >公司账户</span>
		<span class="fullttaccount 供应商账户" style="display:none;" >供应商账户</span>
		<span class="fullttaccount 停用账户" style="display:none;" >停用账户</span>
		<span class="fullttaccount 已注销账户" style="display:none;" >已注销账户</span>
	
		Total:</b></td><td style="text-align:right;font-weight:bold;font-size:18px;" >
		<span class="fullttaccount 全部" ><?php echo number_format((float)$total,2); ?></span>
		<span class="fullttaccount 公司账户" style="display:none;" ><?php echo number_format((float)$totalx['公司账户'],2); ?></span>
		<span class="fullttaccount 供应商账户" style="display:none;" ><?php echo number_format((float)$totalx['供应商账户'],2); ?></span>
		<span class="fullttaccount 停用账户" style="display:none;" ><?php echo number_format((float)$totalx['停用账户'],2); ?></span>
		<span class="fullttaccount 已注销账户" style="display:none;" ><?php echo number_format((float)$totalx['已注销账户'],2); ?></span>
		
		</td><td></td>
	</tr>
	</tfoot>
	</table>
	</form>
<script>
	jQuery("document").ready(function(){
		
                $('.asdnasndasjkl').val('公司账户').change();
	});
</script>   
<?php } ?>
<?php if($showmod20 == 1){ 
   
       if($_POST['datemod20']){
            $datemod20 = date('Ymd',strtotime($_POST['datemod20']));
            $datestart = date('Y-m-d',strtotime(str_replace('.','-',$_POST['datestart'])));
            $dateto = date('Y-m-d',strtotime(str_replace('.','-',$_POST['dateto'])));
            $setdatemod20 = date('Y-m-d',strtotime($_POST['datemod20']));
        }else{
            $datemod20 = date('Ymd');//, strtotime("-1 days")
            $datestart = $dateto = $setdatemod20 = date('Y-m-d');
        }
       
        ?>

<script>
	jQuery("document").ready(function(){
		$( "body" ).delegate( '.dfjaksku' , "click", function() {	
			$('.toast.rounded').hide();
		});
                $('.jksahjkb').val('公司账户').change();
	});
</script>   
<style>    
    .dfjaksku {
	position: absolute;
	top:-26px;
	right:0px;
	color:red;
	font-weight:bold;
	font-size:30px;    cursor: pointer;
}
table.tblinfo{} table.tblinfo td{border-spacing:collapse;border:1px solid #555; min-width:50px;}
.toast.rounded {
    
    margin-top: 200px;
}
</style>
<h2 style="text-align:center;font-size: 28px; margin-top: 190px;" >MOD20收支汇总/日</h2>
<form class="formupload1" method="POST">
    
    <?php /*
    <input value="<?php echo $datestart; ?>" id="datestart" name="datestart" type="hidden" />
    <input value="<?php echo $dateto; ?>" id="dateto" name="dateto" type="hidden" />
    
    <div class="reportrange" style="      padding: 10px;   cursor: pointer;   float:left;">
<i class="material-icons " style="float:right;" >date_range</i> 
<?php echo $datestart.' to '.$dateto; ?>
     
     */
    
   
?>
    <input type="date" name="datemod20" style="    width: 113px;    float: left;" value="<?php echo $setdatemod20; ?>" />
	</div>
    
    <div style="width: 95px;float: left;margin-top: 13px;padding-left: 10px;" >  </div>
<button onclick="jQuery('table').remove();" style="width: 80px; cursor:pointer;    right: 6px;    display: block;    background: #1b278a;    border: none;    padding: 5px 10px;    margin-top: 13px;color: #fff;  float: left;   border-radius: 3px;">Go</button>
	
	<table style="    clear: both;width: 55%!important;position: relative;margin-top: 10px;" class="striped responsive-table  tablesorter  "  >
	  <thead>
			<tr>
                            <th rowspan="2" style="width:160px;    background-color: #ccc;" ><div style="    text-align: right;" >类别</div>
			<select class="jksahjkb" onchange="if($(this).val() == 0){ $('.fullaccount1').show();  $('.fullttaccount1').hide(); $('.全部1').show();   }else{  $('.fullttaccount1').hide(); $('.fullaccount1').hide(); $('.'+$(this).val()+'1').show(); }" >
				<option value="0" >全部</option>
                                <option value="公司账户" selected="" >公司账户</option>
				<option value="供应商账户" >供应商账户</option>
				<option value="停用账户" >停用账户</option>
				<option value="已注销账户" >已注销账户</option>
			</select>
			
			</th>
			<th rowspan="2" style="width:200px;" ><div style="    text-align: right;" >币种</div>
			<div style="
					border: 1px solid;
					transform: rotateZ(24deg);
					width: 113%;
					margin-left: -6%;
				"></div>
			<div>账户</div></th>
			
                        <th colspan="2" style="text-align: center;" >USD</th>		
			<th colspan="2" style="text-align: center;">RMB</th>
			<th colspan="2" style="text-align: center;">VND</th>
                        <th colspan="2" style="text-align: center;">HKD</th>
			</tr>
                        <tr>
                            <th style="width: 9%;" >收</th>
                            <th style="width: 9%;" >付</th>
                            <th style="width: 9%;" >收</th>
                            <th style="width: 9%;" >付</th>
                            <th style="width: 9%;">收</th>
                            <th style="width: 9%;" >付</th>
                            <th style="width: 9%;">收</th>
                            <th style="width: 9%;" >付</th>
                        </tr>
	  </thead>
	  <tbody>
	<?php   
	
     
	foreach($tabs as $tab){
		if($tab->name == '阿黄（HK）8979卡' || $tab->name == '阿达车队9006卡' || $tab->name == '新港车队0007卡' || $tab->name == '国内-伏开朗0174注销'  ){continue;}
		
               
		$balancein = $balanceout = 0;
                
                foreach($currency as $rcurrency){
				if($rcurrency['id'] == $tab->currency ){
					$exchangerate =  $rcurrency['exchangerate'];
					$currencyname =  $rcurrency['currency'];
				} 	
		}
                if($currencyname == "HKD"){
                    foreach($currency as $rcurrency){
				if($rcurrency['currency'] == 'HKDRMB' ){
					$exchangerate =  $rcurrency['exchangerate'];
				} 	
                    }	
		}	
                
		$salarymonthout = $salarymonthin = '';
		foreach ($data11 as $key => $values) {       
			$appprove = 0; 
			if( $values['tabs'] == '' ){
				foreach ($tabdocfull as $keytab => $r){
					if ( $values['id'] == $r->iddoc && $tab->id == $r->idtab ) {
						$appprove = 1; 
						$rt = $r->idtab;		
						unset($tabdocfull[$keytab]);	break;
					}
				}
				if ($appprove == 0){
				 continue;
				}
			}else{
				if ($values['tabs'] != $tab->id ){
					 continue;
				}
				$rt = $values['tabs'];
			}
                         if(date('Ymd',$values['id']) != $datemod20 ){
                             continue;
                            //echo date('Ymd',strtotime($datestart)).'-'.date('Ymd',strtotime($dateto)).'|';
                         }
//                        if(date('Ymd',$values['id']) < date('Ymd',strtotime($datestart)) || date('Ymd',$values['id']) > date('Ymd',strtotime($dateto))  ){
//                           continue;
//                        }
                        $values['datecte'] = date('Y-m-d h:i:s',$values['id']);
                        
                        
                        foreach ($values['corresponding'] as $rcorresponding){
                                if($strfullname != '') { $strfullname .='; '; }
                                $strfullname .= $corresponding_id[$rcorresponding]->fullname;
                        }

                        if((float)$values['amountincome'] > 0){
                            $salarymonthin .= '<tr datestart='.
                            date('Y.m.d',$values['id']-592000).' 				dateto='.
                            date('Y.m.d',$values['id']+592000).'				rowclick=row'.
                            $tab->id.$values['id'].'				tabclick='.
                            $tab->id.'			style=\\\'cursor:pointer;color:#039be5;\\\' ><td>'.$tab->name
                            .'</td><td>'.date('d.m.Y',$values['id'])
                            .'</td><td>'. $values['summary']
                            .'</td><td>'.$strfullname.'</td><td>'.number_format((float)$values['amountincome'],$decimal).' '.$currencyname  
                            .'</td><td>'.number_format((float)$values['amountpayout'],$decimal).' '.$currencyname 
                            .'</td><td>'.$payer_row
                            .'</td><td>'.$values['requestnumber']
                            .'</td><td>'.$values['documentnumber']						
                            .'</td></tr>';
                        }else{
                            $salarymonthout .= '<tr datestart='.
                            date('Y.m.d',$values['id']-592000).' 				dateto='.
                            date('Y.m.d',$values['id']+592000).'				rowclick=row'.
                            $tab->id.$values['id'].'				tabclick='.
                            $tab->id.'			style=\\\'cursor:pointer;color:#039be5;\\\' ><td>'.$tab->name
                            .'</td><td>'.date('d.m.Y',$values['id'])
                            .'</td><td>'. $values['summary']
                            .'</td><td>'.$strfullname.'</td><td>'.number_format((float)$values['amountincome'],$decimal).' '.$currencyname  
                            .'</td><td>'.number_format((float)$values['amountpayout'],$decimal).' '.$currencyname 
                            .'</td><td>'.$payer_row
                            .'</td><td>'.$values['requestnumber']
                            .'</td><td>'.$values['documentnumber']						
                            .'</td></tr>';
                        }
			if($tab->special3 == 1){
				
				if($values['exchangeusdtovnd'] > 0){
                                    $balancein += ($values['exchangeusdtovnd']*$values['amountpayoutusd']) ;
                                    $balanceout += abs((float)$values['amountpayout']);	
				}else{
                                   $balancein += abs((float)$values['amountincome']) ;
                                   $balanceout += abs((float)$values['amountpayout']);
				}
			}else{
				$balancein += abs((float)$values['amountincome']) ;
                                $balanceout += abs((float)$values['amountpayout']);
			}
			
			
			unset($data11[$key]);
	   }
               $ttbalancein[$tab->tabsg][$currencyname] += (float)$balancein;
               $ttbalanceout[$tab->tabsg][$currencyname] += (float)$balanceout;
               
               $ttbalancein['all'][$currencyname] += (float)$balancein;
               $ttbalanceout['all'][$currencyname] += (float)$balanceout;
              // print_r($datemod20aa);
		
			
	?>
	
	<tr class="fullaccount1 <?php echo $tab->tabsg.'1'; ?>" >
			<td><b><?php echo $tab->tabsg; ?></b></td>
			<td style="width:180px;padding-left:10px!important;" ><?php echo $tab->name; ?></td>
                        
                        <td  class=""  onclick=" jQuery('.toast.rounded').hide(); M.toast({html:'<a class=\'dfjaksku\'>X</a><div  ><table class=\'tblinfo\'><tr><td>账户</td><td>日期</td><td>摘要</td><td>往来单位</td><td>币别</td><td>金额</td><td>收/付款人</td><td>要求</td><td>凭证号</td></tr><?php if($currencyname == 'USD'){ echo str_replace('"','',$salarymonthin); } ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); "  style="padding-right:5px!important;text-align:right;    color: #039be5;font-size:16px;" >
                            <?php if($currencyname == 'USD'){
                                echo number_format((float)$balancein,2);
                            } ?>
                        </td>
                        <td  class=""  onclick=" jQuery('.toast.rounded').hide(); M.toast({html:'<a class=\'dfjaksku\'>X</a><div  ><table class=\'tblinfo\'><tr><td>账户</td><td>日期</td><td>摘要</td><td>往来单位</td><td>币别</td><td>金额</td><td>收/付款人</td><td>要求</td><td>凭证号</td></tr><?php if($currencyname == 'USD'){ echo str_replace('"','',$salarymonthout);} ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); "  style="padding-right:5px!important;text-align:right; color: #039be5;font-size:16px;" >
                            <?php if($currencyname == 'USD'){
                                echo number_format((float)$balanceout,2);
                            } ?>
                        </td>
                        <td  class=""  onclick=" jQuery('.toast.rounded').hide(); M.toast({html:'<a class=\'dfjaksku\'>X</a><div  ><table class=\'tblinfo\'><tr><td>账户</td><td>日期</td><td>摘要</td><td>往来单位</td><td>币别</td><td>金额</td><td>收/付款人</td><td>要求</td><td>凭证号</td></tr><?php if($currencyname == 'RMB'){ echo str_replace('"','',$salarymonthin); } ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); "  style="padding-right:5px!important;text-align:right; color: #039be5;font-size:16px;" >
                            <?php if($currencyname == 'RMB'){
                                echo number_format((float)$balancein,2);
                            } ?>
                        </td>
                        <td  class=""  onclick=" jQuery('.toast.rounded').hide(); M.toast({html:'<a class=\'dfjaksku\'>X</a><div  ><table class=\'tblinfo\'><tr><td>账户</td><td>日期</td><td>摘要</td><td>往来单位</td><td>币别</td><td>金额</td><td>收/付款人</td><td>要求</td><td>凭证号</td></tr><?php if($currencyname == 'RMB'){ echo str_replace('"','',$salarymonthout); } ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); "  style="padding-right:5px!important;text-align:right; color: #039be5;font-size:16px;" >
                            <?php if($currencyname == 'RMB'){
                                echo number_format((float)$balanceout,2);
                            } ?>
                        </td>
                        <td  class=""  onclick=" jQuery('.toast.rounded').hide(); M.toast({html:'<a class=\'dfjaksku\'>X</a><div  ><table class=\'tblinfo\'><tr><td>账户</td><td>日期</td><td>摘要</td><td>往来单位</td><td>币别</td><td>金额</td><td>收/付款人</td><td>要求</td><td>凭证号</td></tr><?php if($currencyname == 'VND'){ echo str_replace('"','',$salarymonthin); } ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); "  style="padding-right:5px!important;text-align:right; color: #039be5;font-size:16px;" >
                            <?php if($currencyname == 'VND'){
                                echo number_format((float)$balancein);
                            } ?>
                        </td>
                        <td  class=""  onclick=" jQuery('.toast.rounded').hide(); M.toast({html:'<a class=\'dfjaksku\'>X</a><div  ><table class=\'tblinfo\'><tr><td>账户</td><td>日期</td><td>摘要</td><td>往来单位</td><td>币别</td><td>金额</td><td>收/付款人</td><td>要求</td><td>凭证号</td></tr><?php if($currencyname == 'VND'){ echo str_replace('"','',$salarymonthout); } ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); "  style="padding-right:5px!important;text-align:right; color: #039be5;font-size:16px;" >
                            <?php if($currencyname == 'VND'){
                                echo number_format((float)$balanceout);
                            } ?>
                        </td>
                        <td  class=""  onclick=" jQuery('.toast.rounded').hide(); M.toast({html:'<a class=\'dfjaksku\'>X</a><div  ><table class=\'tblinfo\'><tr><td>账户</td><td>日期</td><td>摘要</td><td>往来单位</td><td>币别</td><td>金额</td><td>收/付款人</td><td>要求</td><td>凭证号</td></tr><?php if($currencyname == 'VND'){ echo str_replace('"','',$salarymonthin); } ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); "  style="padding-right:5px!important;text-align:right; color: #039be5;font-size:16px;" >
                            <?php if($currencyname == 'HKD'){
                                echo number_format((float)$balancein);
                            } ?>
                        </td>
                        <td  class=""  onclick=" jQuery('.toast.rounded').hide(); M.toast({html:'<a class=\'dfjaksku\'>X</a><div  ><table class=\'tblinfo\'><tr><td>账户</td><td>日期</td><td>摘要</td><td>往来单位</td><td>币别</td><td>金额</td><td>收/付款人</td><td>要求</td><td>凭证号</td></tr><?php if($currencyname == 'VND'){ echo str_replace('"','',$salarymonthout); } ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); "  style="padding-right:5px!important;text-align:right; color: #039be5;font-size:16px;" >
                            <?php if($currencyname == 'HKD'){
                                echo number_format((float)$balanceout);
                            } ?>
                        </td>
		
	</tr>
        <?php } ?>
        <tr>
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                 <b>Total:</b>
             </td>
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ></td>
             
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                <span class="fullttaccount1 全部1" ><?php echo number_format((float)$ttbalancein['all']['USD'],2); ?></span>
		<span class="fullttaccount1 公司账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['公司账户']['USD'],2); ?></span>
		<span class="fullttaccount1 供应商账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['供应商账户']['USD'],2); ?></span>
		<span class="fullttaccount1 停用账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['停用账户']['USD'],2); ?></span>
		<span class="fullttaccount1 已注销账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['已注销账户']['USD'],2); ?></span>
             </td>
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                <span class="fullttaccount1 全部1" ><?php echo number_format((float)$ttbalanceout['all']['USD'],2); ?></span>
		<span class="fullttaccount1 公司账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['公司账户']['USD'],2); ?></span>
		<span class="fullttaccount1 供应商账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['供应商账户']['USD'],2); ?></span>
		<span class="fullttaccount1 停用账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['停用账户']['USD'],2); ?></span>
		<span class="fullttaccount1 已注销账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['已注销账户']['USD'],2); ?></span>
                 
                </td>
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                  <span class="fullttaccount1 全部1" ><?php echo number_format((float)$ttbalancein['all']['RMB'],2); ?></span>
		<span class="fullttaccount1 公司账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['公司账户']['RMB'],2); ?></span>
		<span class="fullttaccount1 供应商账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['供应商账户']['RMB'],2); ?></span>
		<span class="fullttaccount1 停用账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['停用账户']['RMB'],2); ?></span>
		<span class="fullttaccount1 已注销账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['已注销账户']['RMB'],2); ?></span>
                
                 </td>
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                 
                    <span class="fullttaccount1 全部1" ><?php echo number_format((float)$ttbalanceout['all']['RMB'],2); ?></span>
		<span class="fullttaccount1 公司账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['公司账户']['RMB'],2); ?></span>
		<span class="fullttaccount1 供应商账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['供应商账户']['RMB'],2); ?></span>
		<span class="fullttaccount1 停用账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['停用账户']['RMB'],2); ?></span>
		<span class="fullttaccount1 已注销账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['已注销账户']['RMB'],2); ?></span>
                 
                </td>
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                   <span class="fullttaccount1 全部1" ><?php echo number_format((float)$ttbalancein['all']['VND'],0); ?></span>
		<span class="fullttaccount1 公司账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['公司账户']['VND'],0); ?></span>
		<span class="fullttaccount1 供应商账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['供应商账户']['VND'],0); ?></span>
		<span class="fullttaccount1 停用账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['停用账户']['VND'],0); ?></span>
		<span class="fullttaccount1 已注销账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['已注销账户']['VND'],0); ?></span>
                 
                 <?php echo number_format((float)$ttbalancein['VND']); ?></td>
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                   <span class="fullttaccount1 全部1" ><?php echo number_format((float)$ttbalanceout['all']['VND'],2); ?></span>
		<span class="fullttaccount1 公司账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['公司账户']['VND'],0); ?></span>
		<span class="fullttaccount1 供应商账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['供应商账户']['VND'],0); ?></span>
		<span class="fullttaccount1 停用账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['停用账户']['VND'],0); ?></span>
		<span class="fullttaccount1 已注销账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['已注销账户']['VND'],0); ?></span>
                 
                 </td>
                 
                 <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                   <span class="fullttaccount1 全部1" ><?php echo number_format((float)$ttbalancein['all']['HKD'],0); ?></span>
		<span class="fullttaccount1 公司账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['公司账户']['HKD'],0); ?></span>
		<span class="fullttaccount1 供应商账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['供应商账户']['HKD'],0); ?></span>
		<span class="fullttaccount1 停用账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['停用账户']['HKD'],0); ?></span>
		<span class="fullttaccount1 已注销账户1" style="display:none;" ><?php echo number_format((float)$ttbalancein['已注销账户']['HKD'],0); ?></span>
                 
                 <?php echo number_format((float)$ttbalancein['HKD']); ?></td>
             <td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" >
                   <span class="fullttaccount1 全部1" ><?php echo number_format((float)$ttbalanceout['all']['HKD'],2); ?></span>
		<span class="fullttaccount1 公司账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['公司账户']['HKD'],0); ?></span>
		<span class="fullttaccount1 供应商账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['供应商账户']['HKD'],0); ?></span>
		<span class="fullttaccount1 停用账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['停用账户']['HKD'],0); ?></span>
		<span class="fullttaccount1 已注销账户1" style="display:none;" ><?php echo number_format((float)$ttbalanceout['已注销账户']['HKD'],0); ?></span>
                 
                 </td>
        </tr>
	
	</tbody>
	
	</table>
	</form>

<?php } ?>
<?php 
if($showtotalal == 1){
	
$consignee = json_decode(file_get_contents('../Docs/data/Consignee_none.json'), true);

$head = json_decode(file_get_contents('../Docs/data/2head.json'), true);
$receiver = json_decode(file_get_contents('../Docs/data/Receiver.json'), true);
$head[] = array('name' => 'None', 'id' => 'none' );
foreach ($receiver as $r){
	$receiver[$r['id']] =  $r['receiverid'];
}
foreach ($head as $r){
	$head[$r['id']] =  $r['name'];
}
foreach ($consignee as $r3){
			if( $r3['type_sub'] == '3'){
				$kq[$r3['id_consignee']][$r3['id_head']] += ((float)str_replace(',','',$r3['none_revenue'])-(float)str_replace(',','',$r3['none_expenditure']));
			}
}

foreach ($kq as $key => $r1){
	foreach ($kq[$key] as $key2 => $r2){
		if( $r2 < 1 && $r2 > -1  ){
			unset($kq[$key][$key2]);
		}
	}
}
	?>
	<h2 style="text-align:center;font-size: 28px; margin-top: 190px;" >MOD4</h2>
	<table style="width: 450px!important;position: relative;margin-top: 10px;" class="striped responsive-table  tablesorter  "  >
	  <thead>
			<tr>
			<th style="width:100px;" ><div style="    text-align: right;" >类别</div>
			<th style="width:350px;" ><div style="    text-align: right;" >币种</div>
			<div style="
					border: 1px solid;
					transform: rotateZ(13deg);
					width: 113%;
					margin-left: -6%;
				"></div>
			<div>账户</div></th>		
			<th>RMB</th>
			</tr>
	  </thead>
	  <tbody>
		<?php foreach ($kq as $key => $r1){
		foreach ($kq[$key] as $key2 => $r2){
			$tt += (float)$r2;
			?>
			<tr>
				<td><b></b></td>
				<td><b><?php echo $receiver[$key].' -> '.$head[str_replace('h','',$key2)]; ?></b></td>
				<td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:16px;" ><b><?php echo number_format((float)$r2,2); ?></b></td>
			</tr>
			<?php
				}
			} ?>
	  </tbody>
	  <tfoot>
	  <tr>
				<td style="text-align:right;" ><b>Total</b></td>
				<td style="padding-right:5px!important;text-align:right;font-weight:bold;font-size:17px;" ><b><?php echo number_format((float)$tt,2); ?></b></td>
			</tr>
	  </tfoot>
	</table>  
	<table style="width: 100%!important;position: relative;    position: absolute;    top: 70px;" class="striped responsive-table  tablesorter  "  >
	  <thead>
			<tr>
				<?php for($i = 9; $i >= 0; $i--){ ?>
						<th style="text-align:center;" ><?php echo date('Y-m-d',strtotime("-".$i." day") ) ?></th>
				<?php } ?>
			</tr>
	  </thead>
	  <tbody>
			<tr>
				<?php for($i = 9; $i >= 0; $i--){
						$data = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));
				?>
						<td style="text-align:center;" >1 USD = <?php echo round($data->USD,4); ?> RMB</td>
				<?php } ?>
			</tr>
			<tr>
				<?php for($i = 9; $i >= 0; $i--){
						$data = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));
                                                if($data->VND <= 0 ){
                                                    continue;
                                                }
					?>
						<td style="text-align:center;" >1 RMB = <?php echo number_format(1/$data->VND); ?> VND</td>
				<?php } ?>
			</tr>
			<tr>
				<?php for($i = 9; $i >= 0; $i--){
						$data = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));
                                                if($data->THB <= 0 ){
                                                    continue;
                                                }
					?>
						<td style="text-align:center;" >1 RMB = <?php echo round(1/$data->THB,3); ?> Bath</td>
				<?php } ?>
			</tr>
			<tr>
				<?php for($i = 9; $i >= 0; $i--){
						$data = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));
					?>
						<td style="text-align:center;" >1 USD = <?php echo number_format((float)$data->USDVND); ?> VND</td>
				<?php } ?>
			</tr>
			
			<tr>
				<?php for($i = 9; $i >= 0; $i--){
						$data = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));
                                                if($data->VND <= 0 ){
                                                    continue;
                                                }
					?>
						<td style="text-align:center;" >USD*RMB = <?php echo number_format((1/$data->VND)*$data->USD,0); ?> VND</td>
				<?php } ?>
			</tr>
                        <tr>
				<?php for($i = 9; $i >= 0; $i--){
						$data = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));
					?>
						<td style="text-align:center;" >1 HKD = <?php echo $data->HKDRMB; ?> RMB</td>
				<?php } ?>
			</tr>
			<tr style='display:none;' >
				<?php for($i = 9; $i >= 0; $i--){ 
						$data = json_decode(file_get_contents('currency/'.date('Ymd',strtotime("-".$i." day"))));
				?>
						<td style="text-align:center;" ><?php echo number_format((float)$sumbydate[date('Y-m-d',strtotime("-".$i." day"))],2); ?> RMB</td>
				<?php } ?>
			</tr>
	  </tbody>
	</table>
	<?php
} ?>  
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script>
	jQuery("document").ready(function(){
		$('.remark').change(function(){
			$(".formupload").submit();
		});
		
		$('.dkasndlkas2').change(function(){
			$(".formajax").submit();
		});
              
		
	});
	
	
</script>   
<style>    
    
    .tored {
        color:red;
    }    
.tablesorter input[type=text]:not(.browser-default){
    height: 22px;
	    margin-bottom: 3px;
}	
table.tablesorter tbody td, table.tablesorter thead tr th {
    border: 1px solid #ccc;
}  
table.tablesorter thead tr th {
    background-color: #1b278a;
    color: #fff;
}  
table.striped tr {
    cursor: pointer;
}
.navbar-fixed nav {
	padding: 0 30px;
}
table.tablesorter tbody td {
    vertical-align: middle;
}
table.tablesorter tbody td {
    padding: 0px;
}
.helper-text {
	display:none!important;
}
.input-field {
    position: relative;
    margin-top: 5px;
    margin-bottom: 5px;
}
#modal5 {   
    min-width: 1150px;
}
.ui-resizable-e , .ui-resizable-se {
	display:none!important;
}
.ui-resizable-s {    
    height: 10px;    
    bottom: -5px;
}
li.disabled{
	display:none;
}
#tabnameSave {
    position: relative;
    margin-right: 24px;
    transform: none;
}
.modal-fixed {
    width: 600px !important;
}
.nofulltext {
	display:block!important;
    /*height: 19px;*/
    overflow: hidden;
	width: 90%;
    float: left;
}
.fa-sort-down {
	width: 10%;
    float: right;
}
body {
	overflow-x: hidden;
}
.datepicker-day-button {
    color: #000;
}
</style>
<script src="https://htlservice.net/Docs/tpl/js/colResizable-1.6.min.js"></script>
<script src="tpl/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />

<?php  
		$now = strtotime(date('Y-m-d 00:00:00')); // or your date as well
		//echo $datestart.'-'.$dateto;
		$your_date = strtotime(str_replace('.','-',$datestart).' 00:00:00'); 
		$datediff = round(($now - $your_date)/84600);
		if($datediff <= 0){
			$numdatstart = $datediff;
		}else{
			$numdatstart = $datediff-1;
		}
		
		$your_date = strtotime(str_replace('.','-',$dateto).' 00:00:00');
		$datediff = round(($now - $your_date)/84600); 
		if($datediff <= 0){
			$numdatto = $datediff;
		}else{
			$numdatto = $datediff-1;
		}
		
		$monthchinatext = array('一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月');
		
?>

<script>
$(document).ready(function () {
	$( '.totip' ).tooltip();
	var start = moment().subtract(<?php echo $numdatstart; ?>, 'days');
    var end = moment().subtract(<?php echo $numdatto; ?>, 'days');
	
	function cb(start, end , sub) {		
		$('.reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
   
		jQuery('#datestart').val(start.format('YYYY.MM.DD')); 
		jQuery('#dateto').val(end.format('YYYY.MM.DD')); 
		if(sub != 1){
			jQuery("#formfilter").submit();
		}
    }
	
	
        
        
        $('.reportrange').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
           '今天': [moment(), moment()],
           '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           //'七天内': [moment().subtract(6, 'days'), moment()],
           //'十五天内': [moment().subtract(14, 'days'), moment()],
           //'三十天内': [moment().subtract(29, 'days'), moment()]
         
        }
        }, cb);
	cb(start, end , 1);
	
	$(".sandjnas").change(function(){
		if($( ".sandjnas option:selected" ).hasClass('isspeci')){
			$(".isdepartmentform").show();
		}else{
			$(".isdepartmentform").hide();
		}
	});
	
	setTimeout(function(){ 
		$("#classification option").each(function(){
			if($(this).attr('color') != ''){
				var adf = $(this).val();var color = $(this).attr('color');
				$(this).parents().eq(1).find('li').each(function(){
					if($(this).find('span').text() == adf){
						$(this).find('span').css('color',color);$(this).find('span').css('font-weight','bold');
					}
				});
			}
		});
	}, 3000);
	
	<?php if ($currentuser->role == "Manager"  ){ ?>
		$('.tab-link').on('click',function(){
          //  $('.tabs button:not(.sdastr),.tabs a').hide();
		});
        $('.tab-link').on('dblclick',function(){
            var tab_id = $(this).attr('data-tab');
            $('.' + tab_id).css({"display":"block"});
           // $(this).css({"display":"none"});
        });
    <?php } ?>

	$(".tabnameSave").click(function(){
		
		$(".sdastr").trigger("click");
		$("#addNewTab #currency").val($(this).prev().attr('currency'));
		$('#addNewTab #currency').formSelect();
		$("#addNewTab #id_tabname").val($(this).prev().attr('data-id'));
		$("#addNewTab #tab").val($(this).prev().attr('name'));
		$("#addNewTab #tabinfo").val($(this).prev().attr('info'));
		if($(this).prev().attr('special') == 1){
			$("#addNewTab #special").prop('checked',true);
		}else{
			$("#addNewTab #special").prop('checked',false);
		}

	});
	$("#classification").change(function(){
		$('#charge').val('');
		if($(this).val() != ''){
			$('#charge').prop('disabled',false);
			$('#charge option').prop('disabled',true);
			if( $('.'+$(this).val()).length ){
				$('.'+$(this).val()).prop('disabled',false);
			}else{
				$('.novalue').prop('disabled',false);
				$('.novalue').attr('value',$(this).val());
				$('.novalue').text($(this).val());
			}
		}else{
			$('#charge').prop('disabled',true);
		}
		$('#charge').formSelect();
	});
	//$(".responsive-table").colResizable({resizeMode:'overflow'});
	//$('.responsive-table td').resizable();
});
                            
                          jQuery(document).ready(function ($) {
							  
							
							$("input[data-type='currency']").each(function(){
								 formatCurrency($(this)); 
							});
							  
                           
							
                            $("input[data-type='currency']").on({
                                keyup: function() {
                                  formatCurrency($(this));
                                },
                                blur: function() { 
                                  formatCurrency($(this), "blur");
                                }
                            });
                            
                            
                          

                            function formatNumber(n) {
                              return n.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",")
                            }


                            function formatCurrency(input, blur) {
                             
                              var input_val = input.val(); 
                              if (input_val === "" || input_val == "0.00") { return; }
                              var original_len = input_val.length;
                              var caret_pos = input.prop("selectionStart");
                              if (input_val.indexOf(".") >= 0) {
                                var decimal_pos = input_val.indexOf(".");
                                var left_side = input_val.substring(0, decimal_pos);
                                var right_side = input_val.substring(decimal_pos);
                                left_side = formatNumber(left_side);

                                right_side = formatNumber(right_side);
                                if (blur === "blur") {
                                 // right_side += "00";
                                }

                                right_side = right_side.substring(0, 2);

                                input_val =  left_side + "." + right_side;

                              } else {
                              
                                input_val = formatNumber(input_val);
                                input_val =  input_val;

                                // final formatting
                                if (blur === "blur") {
                                  //input_val += ".00";
                                }
                              }

                              input.val(input_val);

                              var updated_len = input_val.length;
                              caret_pos = updated_len - original_len + caret_pos;
                              input[0].setSelectionRange(caret_pos, caret_pos);
                            }
                           });
                           
                        </script>
			
			
<!-- Styles -->
<?php 
if($showtotalconsignee == 1){ ?>
	<h2 style="text-align:center;font-size: 28px; margin-top: 10px;" >MOD2财务报表</h2>
	<iframe src="total_profit.php" width="100%" height="820" frameBorder="0">Browser not compatible.</iframe>
	<?php } ?>
<?php if($showtotalmonth == 1){
    
	?>
        <h2 style="text-align:center;font-size: 28px; margin-top: 10px;" >MOD3账户收支</h2>
        <iframe src="total_in_out.php" width="100%" height="1500" frameBorder="0" style="" >Browser not compatible.</iframe><?php
} ?> 
<?php    
// FOOTER
include 'tpl/footer.php';
