<?php
date_default_timezone_set('Asia/Bangkok');
error_reporting(E_ERROR);
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_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;
		}
	}
}

//var_dump($login);die;
if ($login['status'] == 200) {
   if($currentuser->gm != 1 && $currentuser->total != '1'  ){
		header('location: login.php');
		exit;
	}
} else {
    header('location: login.php');
    exit;
}
if ( $_GET['who'] != '' && $_GET['fileName'] != '' ) {
	$logdownload = file_get_contents("data/logdownload.json");
	$logdownload = json_decode($logdownload);
	$logdownload[] = $_GET['who'].': '.$_GET['fileName'];
	file_put_contents("data/logdownload.json", json_encode($logdownload));
	echo 'done';
	die;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' and $_POST['updateremak'] == 1 ) {
	$income = json_decode( file_get_contents("data/income.json"),true );
	$cost = json_decode( file_get_contents("data/cost.json"),true );
        $totalcustom = json_decode( file_get_contents("data/totalcustom.json"),true );
	foreach ($_POST as $key => $r){
		$r =  str_replace(',','',$r);
		if(strpos($key,'income_') !== false){
			if(strpos($key,'越南') !== false){
                            if($r  != $income['越南'][str_replace(array('越南_','income_'),'',$key)]){
                            $income['越南'][str_replace(array('越南_','income_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                            $income['越南'][str_replace(array('越南_','income_'),'',$key)] = $r;
                               
			}elseif(strpos($key,'中国') !== false){
                             if($r  != $income['中国'][str_replace(array('中国_','income_'),'',$key)]){
                             $income['中国'][str_replace(array('中国_','income_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                             $income['中国'][str_replace(array('中国_','income_'),'',$key)] = $r;
                                
			}elseif(strpos($key,'泰国') !== false){
                             if($r  != $income['泰国'][str_replace(array('泰国_','income_'),'',$key)]){
                             $income['泰国'][str_replace(array('泰国_','income_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                            $income['泰国'][str_replace(array('泰国_','income_'),'',$key)] = $r;
                               
			}elseif(strpos($key,'印尼') !== false){
                             if($r  != $income['印尼'][str_replace(array('印尼_','income_'),'',$key)]){
                             $income['印尼'][str_replace(array('印尼_','income_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                            $income['印尼'][str_replace(array('印尼_','income_'),'',$key)] = $r;
                               
			}elseif(strpos($key,'马来西亚') !== false){
                             if($r  != $income['马来西亚'][str_replace(array('马来西亚_','income_'),'',$key)]){
                             $income['马来西亚'][str_replace(array('马来西亚_','income_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                            $income['马来西亚'][str_replace(array('马来西亚_','income_'),'',$key)] = $r;
                               
			}
                        
                        
		}elseif(strpos($key,'cost_') !== false){
			if(strpos($key,'越南') !== false){
                             if($r  != $cost['越南'][str_replace(array('越南_','cost_'),'',$key)]){
                             $cost['越南'][str_replace(array('越南_','cost_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                            $cost['越南'][str_replace(array('越南_','cost_'),'',$key)] = $r;
                              
			}elseif(strpos($key,'中国') !== false){
                             if($r  != $cost['中国'][str_replace(array('中国_','cost_'),'',$key)]){
                             $cost['中国'][str_replace(array('中国_','cost_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                            $cost['中国'][str_replace(array('中国_','cost_'),'',$key)] = $r;
                                
			}elseif(strpos($key,'泰国') !== false){
                             if($r  != $cost['泰国'][str_replace(array('泰国_','cost_'),'',$key)]){
                             $cost['泰国'][str_replace(array('泰国_','cost_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                             $cost['泰国'][str_replace(array('泰国_','cost_'),'',$key)] = $r;
                             
			}elseif(strpos($key,'印尼') !== false){
                             if($r  != $cost['印尼'][str_replace(array('印尼_','cost_'),'',$key)]){
                             $cost['印尼'][str_replace(array('印尼_','cost_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                             $cost['印尼'][str_replace(array('印尼_','cost_'),'',$key)] = $r;
                             
			}elseif(strpos($key,'马来西亚') !== false){
                             if($r  != $cost['马来西亚'][str_replace(array('泰国_','cost_'),'',$key)]){
                             $cost['马来西亚'][str_replace(array('马来西亚_','cost_'),'',$key).'_log'] .= 'Who:'.$currentuser->name.'.Time:'.date('Y-m-d H:i').' - change:'.$r.'&#10;';}
                             $cost['马来西亚'][str_replace(array('马来西亚_','cost_'),'',$key)] = $r;
                             
			}			
                }else{
                    $totalcustom[$key] = $r;
                }
	}
        file_put_contents("data/totalcustom.json", json_encode($totalcustom));
	file_put_contents("data/income.json", json_encode($income));
	file_put_contents("data/cost.json", json_encode($cost));
        die;
	header('location: total_profit.php?msg=' . $msg);
}


$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/Setting.json'));

$income = json_decode(file_get_contents('data/income.json'),true);
$cost = json_decode(file_get_contents('data/cost.json'),true);
$totalcustom = json_decode(file_get_contents('data/totalcustom.json'),true);

$corresponding = json_decode(file_get_contents('data/Corresponding.json'));
foreach ($corresponding as $r){ 
	$corresponding_id[$r->id] = $r;
}

$receiver_payer = json_decode(file_get_contents('data/receiver_payer.json'));
foreach ($receiver_payer as $r){ if( $r->id == '' || $r->name == '' ) { continue; }
	$receiver_payer_name[$r->name] = $r;
	$receiver_payer_id[$r->id] = $r;
}

// READ DATA
$newdata = array();
$data = json_decode(file_get_contents('data/Documents.json'), true);

// HEADER
ob_end_flush();
include 'tpl/header.php';
$monthschedule = -14;
if($_GET['monthschedule'] != ''){
	$monthschedule = $_GET['monthschedule'];	
}
if($_GET['month'] != ''){
	$month = $_GET['month'];	
}else{
    $month = date('m');
}
if($_GET['year'] != ''){
	$year = $_GET['year'];	
}else{
    $year = date('Y');
}

if($_GET['month1'] != ''){
	$month1 = $_GET['month1'];	
}else{
    $month1 = date('m',strtotime('-14 months'));
}
if($_GET['year1'] != ''){
	$year1 = $_GET['year1'];	
}else{
     $year1 = date('Y',strtotime('-14 months'));
}
if($year && $month && $year1 && $month1){
    if(strtotime($year1.'-'.$month1.'-01') < strtotime($year.'-'.$month.'-01')){
        $d1 = new DateTime($year1.'-'.$month1.'-04 00:00:00');
        $d2 = new DateTime($year.'-'.$month.'-05 00:00:00');
        $dateInterval = $d1->diff($d2);
        $monthschedule = 12 * $dateInterval->y + $dateInterval->m;
        $monthschedule = $monthschedule*-1;
        //$monthschedule--;
    }else{
        $monthschedule = -14;
    }
  
    //$monthschedule = strtotime($year1.'-'.$month1.'-1') - strtotime($year.'-'.$month.'-1') ;
    //$monthschedule = round(($monthschedule/86400)/30);
}
if($monthschedule > 0){
    $monthschedule = -14;
}
//echo $year1.'-'.$month1.'-01|'.$year.'-'.$month.'-01|'.$monthschedule;
?>

<form id="dakb" method="get" style="    margin-bottom: 10px; width:700px;float:right;    margin-right: 85px;     position: relative;    z-index: 10000000;    margin-bottom: -44px;    background: #eeeeee;;   ">
    
    
    <label style="    width: 7%;    float: left;padding-top: 9px;">From<br>从日期</label>  
                    <label style="    width: 20%;    float: left;">
                   
                    <select name="month1" tabindex="8">
                        <option value="">Month</option>
                        <option value="1" <?php if($month1 == '1' ){ echo 'selected'; } ?> >Jan/一月</option>
                        <option value="2" <?php if($month1 == '2' ){ echo 'selected'; } ?>>Feb/二月</option>
                        <option value="3" <?php if($month1 == '3' ){ echo 'selected'; } ?>>Mar/三月</option>
                        <option value="4" <?php if($month1 == '4' ){ echo 'selected'; } ?>>Apr/四月</option>
                        <option value="5" <?php if($month1 == '5' ){ echo 'selected'; } ?>>May/五月</option>
                        <option value="6" <?php if($month1 == '6' ){ echo 'selected'; } ?>>Jun/六月</option>
                        <option value="7" <?php if($month1 == '7' ){ echo 'selected'; } ?>>Jul/七月</option>
                        <option value="8" <?php if($month1 == '8' ){ echo 'selected'; } ?>>Aug/八月</option>
                        <option value="9" <?php if($month1 == '9' ){ echo 'selected'; } ?>>Sep/九月</option>
                        <option value="10" <?php if($month1 == '10' ){ echo 'selected'; } ?>>Oct/十月</option>
                        <option value="11" <?php if($month1 == '11' ){ echo 'selected'; } ?>>Nov/十一月</option>
                        <option value="12" <?php if($month1 == '12' ){ echo 'selected'; } ?>>Dec/十二月</option>
                    </select>
                             </label>
                    <label style="    width: 20%;    float: left;">
                    <select name="year1" tabindex="9">
                        <option value="">Year</option>
                        <option value="2017" <?php if($year1 == '2017' ){ echo 'selected'; } ?> >2017</option>
                        <option value="2018" <?php if($year1 == '2018' ){ echo 'selected'; } ?>>2018</option>
                        <option value="2019" <?php if($year1 == '2019' ){ echo 'selected'; } ?>>2019</option>
                        <option value="2020" <?php if($year1 == '2020' ){ echo 'selected'; } ?>>2020</option>
                        <option value="2021" <?php if($year1 == '2021' ){ echo 'selected'; } ?>>2021</option>
                        <option value="2022" <?php if($year1 == '2022' ){ echo 'selected'; } ?>>2022</option>
                        <option value="2023" <?php if($year1 == '2023' ){ echo 'selected'; } ?>>2023</option>
                        <option value="2024" <?php if($year1 == '2024' ){ echo 'selected'; } ?>>2024</option>
                         <option value="2025" <?php if($year1 == '2025' ){ echo 'selected'; } ?>>2025</option>
                    </select>
                    </label>
                    <label style="    width: 7%;    float: left;padding-top: 9px;">Go To<br>去约会</label>  
                    <label style="    width: 20%;    float: left;">
                   
                    <select name="month" tabindex="8">
                        <option value="">Month</option>
                        <option value="1" <?php if($month == '1' ){ echo 'selected'; } ?> >Jan/一月</option>
                        <option value="2" <?php if($month == '2' ){ echo 'selected'; } ?>>Feb/二月</option>
                        <option value="3" <?php if($month == '3' ){ echo 'selected'; } ?>>Mar/三月</option>
                        <option value="4" <?php if($month == '4' ){ echo 'selected'; } ?>>Apr/四月</option>
                        <option value="5" <?php if($month == '5' ){ echo 'selected'; } ?>>May/五月</option>
                        <option value="6" <?php if($month == '6' ){ echo 'selected'; } ?>>Jun/六月</option>
                        <option value="7" <?php if($month == '7' ){ echo 'selected'; } ?>>Jul/七月</option>
                        <option value="8" <?php if($month == '8' ){ echo 'selected'; } ?>>Aug/八月</option>
                        <option value="9" <?php if($month == '9' ){ echo 'selected'; } ?>>Sep/九月</option>
                        <option value="10" <?php if($month == '10' ){ echo 'selected'; } ?>>Oct/十月</option>
                        <option value="11" <?php if($month == '11' ){ echo 'selected'; } ?>>Nov/十一月</option>
                        <option value="12" <?php if($month == '12' ){ echo 'selected'; } ?>>Dec/十二月</option>
                    </select>
                             </label>
                    <label style="    width: 20%;    float: left;">
                    <select name="year" tabindex="9">
                        <option value="">Year</option>
                        <option value="2017" <?php if($year == '2017' ){ echo 'selected'; } ?> >2017</option>
                        <option value="2018" <?php if($year == '2018' ){ echo 'selected'; } ?>>2018</option>
                        <option value="2019" <?php if($year == '2019' ){ echo 'selected'; } ?>>2019</option>
                        <option value="2020" <?php if($year == '2020' ){ echo 'selected'; } ?>>2020</option>
                        <option value="2021" <?php if($year == '2021' ){ echo 'selected'; } ?>>2021</option>
                        <option value="2022" <?php if($year == '2022' ){ echo 'selected'; } ?>>2022</option>
                        <option value="2023" <?php if($year == '2023' ){ echo 'selected'; } ?>>2023</option>
                        <option value="2024" <?php if($year == '2024' ){ echo 'selected'; } ?>>2024</option>
                        <option value="2024" <?php if($year == '2025' ){ echo 'selected'; } ?>>2025</option>
                    </select>
                    </label>
              
     
    <label style="    width: 6%;    float: left;padding-top: 15px;">
        <button onclick="jQuery('.asjdhb').css('background-size','auto'); jQuery('table').remove();" style="cursor:pointer;    right: 6px;    display: block;    background: #1b278a;    border: none;    padding: 5px 10px;    color: #fff;
    position: absolute;    border-radius: 3px;" >Go</button>
        </label>
		</form>
<?php 


 if( $currentuser->mod28 != '1' && $currentuser->gm  != '1' ){ ?>
       
<style>
.groupcate工资{
	display:none;
}
</style> 

<script>
$(document).ready(function () {
    $('.groupcate工资').remove();
});
</script>
 <?php    }

if($currentuser->gm  == '1' || $currentuser->location == '总公司' ){  ?>
<style>
.navbar-fixed{
	display:none;
}
</style>

<form class="formupload" method="POST"  >
<?php } ?>

<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   

$subContainer = $Setting->subContainer;
$subContainers = explode(PHP_EOL,$subContainer );
foreach($subContainers as $subContainer ){
$subContainer = explode('|',$subContainer );
$subContainer[1] = str_replace(array("\n","\r\n","\r",PHP_EOL,' '), '',$subContainer[1]);
$subContainer[0] = str_replace(array("\n","\r\n","\r",PHP_EOL,' '), '',$subContainer[0]);
if(count((array)$group[$subContainer[0]]) == 0){
	//$group[$subContainer[0]][] = '';
}
$group[$subContainer[0]][] = $subContainer[1];
}
$group['管理费用'][] = '';
$group['财务费用'][] = '';

$quocgia = array('越南','中国','泰国','印尼','马来西亚');

foreach ($data as $key => $values) {
	/*
	if(strpos($values['documentnumber'],'VN') !== false ){
		$data2['1'.$values['id']] = $values;
	}elseif(strpos($values['documentnumber'],'CN') !== false ){
		$data2['2'.$values['id']] = $values;
	}elseif(strpos($values['documentnumber'],'THG') !== false ){
		$data2['3'.$values['id']] = $values;
	}else{
		
	}
	*/
	if( strpos($values['documentnumber'],'VN') !== false || 
		strpos($values['documentnumber'],'CN') !== false ||
		strpos($values['documentnumber'],'THG') !== false){
		$ab = explode('-',$values['documentnumber']);
		if ($ab[1] < 10){
			$ab = '0'.$ab[1];
		}else{
			$ab = $ab[1];
		}
		
		
		
		if(strpos($values['documentnumber'],'-') !== false){
			$abdu = explode('-',$values['documentnumber']);
			if($abdu[1] < 10){
				$abdu[1] =  '0'.$abdu[1];
			}
			$abdu = $abdu[0].'-'.$abdu[1];
			$data2[preg_replace("/[^0-9.]/", "", str_replace('-','.',$abdu)).$values['id']] = $values;
		}else{
			$data2[preg_replace("/[^0-9.]/", "", $values['documentnumber'].'.00'.$values['id'])] = $values;
		}
		
	}else{
		$data2[$values['id']] = $values;
	}
}
ksort($data2);
$data = $data2;

if($month && $year){
        $as = strtotime(date('Y-m-01')) -  strtotime($year.'-'.$month.'-01');
        $adiff = round(($as/86400)/30);
        //$adiff--;
}

foreach($tabs as $tab){

    // LOOP EACH ENTRY
    $total_receivable = $total_amount = $total_profit = 0;
    $countNo = 0;
	$amountincome = 0;
	$amountpayout = 0;
	$balance = 0;
	
	foreach($currency as $rcurrency){
			if($rcurrency['id'] == $tab->currency ){
				$exchangerate =  $rcurrency['exchangerate'];
				$currencyname =  $rcurrency['currency'];
			} 	
	}
		

    
	
    foreach ($data as $key => $values) {     
        
        if($month && $year){
            if(date('Ym',$values['id']) < $year.$month ){
                //continue;
            }
        }
        
        $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(!is_array($values['payer'])){
				$values['payer'] = array($values['payer']);
		}
		$payer_row = '';
		foreach ($values['payer'] as $rpayer){
			if(isset($receiver_payer_id[$rpayer])){
				$payer_row .= $receiver_payer_id[$rpayer]->name;
			}elseif(isset($receiver_payer_name[$rpayer])){
				$payer_row .= $receiver_payer_name[$rpayer]->name;
			}else{
				$payer_row .= $rpayer;
			}
			if(count((array)$values['payer']) > 1){
				$payer_row .= ' | ';
			}
		}
		
		$decimal = 2;
		if($tab->currency == '1560829223'){
				$decimal = 0;
		}
		$values['department'] =  str_replace('国内','中国',$values['department']);
		if($values['department'] == ''){
			$values['department'] = $tab->location;//'越南';
		}
		if($values['department'] != ''){ // $tab->special == 1 && 
			$tab->location = $values['department'];
		}
		
		//if($values['charge'] == '员工年终奖'){
		//		$tablocation = '中国';
		//}else{
                    if($values['department'] != ''){
                        $tablocation = $values['department'];
                    }else{
                        $tablocation = $tab->location;
                    }
				
		//}
			
        for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
			
			if( date('mY',strtotime('first day of '.$i.' month')) == date('mY',$values['id']) && $values['classification'] == '管理费用'  ){
				if(!in_array($values['charge'],$group['管理费用'])){ $values['charge'] = ''; }
				$Managementcosts[$tablocation][date('m_Y',strtotime('first day of '.$i.' month'))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ; 
				$Managementcoststo[date('m_Y',strtotime('first day of '.$i.' month'))]  += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;
				$groupvalue[$values['charge']][$tablocation][date('m_Y',strtotime('first day of '.$i.' month'))]	+= (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;	
				$groupvalueto[$values['charge']][date('m_Y',strtotime('first day of '.$i.' month'))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;					
			}
			if( date('mY',strtotime('first day of '.$i.' month')) == date('mY',$values['id']) && $values['classification'] == '财务费用'  ){
				if(!in_array($values['charge'],$group['财务费用'])){ $values['charge'] = ''; }
				$Financialexpenses[$tablocation][date('m_Y',strtotime('first day of '.$i.' month'))] += ( ((float)$values['amountincome']) -  ((float)$values['amountpayout']))*$exchangerate ;
				$Financialexpensesto[date('m_Y',strtotime('first day of '.$i.' month'))] += ( ((float)$values['amountincome']) -  ((float)$values['amountpayout']))*$exchangerate ;
				$groupvalue2[$values['charge']][$tablocation][date('m_Y',strtotime('first day of '.$i.' month'))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;
				$groupvalue2to[$values['charge']][date('m_Y',strtotime('first day of '.$i.' month'))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;				
			}
                        
                        if( date('mY',strtotime('first day of '.$i.' month')) == date('mY',$values['id']) && $values['classification'] == '借款-支出'  ){
				if(!in_array($values['charge'],$group['财务费用'])){ $values['charge'] = ''; }
			
				$groupvalue3[$values['charge']][$tablocation][date('m_Y',strtotime('first day of '.$i.' month'))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;
				$groupvalue3to[$values['charge']][date('m_Y',strtotime('first day of '.$i.' month'))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;				
			}
                        
                        if( date('mY',strtotime('first day of '.$i.' month')) == date('mY',$values['id']) && $values['classification'] == '借款-收入'  ){
				if(!in_array($values['charge'],$group['财务费用'])){ $values['charge'] = ''; }
			
				$groupvalue4[$values['charge']][$tablocation][date('m_Y',strtotime('first day of '.$i.' month'))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;
				$groupvalue4to[$values['charge']][date('m_Y',strtotime('first day of '.$i.' month'))] += (((float)$values['amountincome']) - ((float)$values['amountpayout']))*$exchangerate ;				
			}
                        
                        
                        
                        
                        
                        
			if( date('mY',strtotime('first day of '.$i.' month')) == date('mY',$values['id'])  ){
					
$strfullname = '';
foreach ($values['corresponding'] as $rcorresponding){
	if($strfullname != '') { $strfullname .='; '; }
	$strfullname .= $corresponding_id[$rcorresponding]->fullname;
}
					$salarymonth[$tablocation][$values['charge']][date('m_Y',strtotime('first day of '.$i.' month'))] .= '<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>';
                                        
                                       $salarymonth2[$tablocation][$values['classification']][date('m_Y',strtotime('first day of '.$i.' month'))] .= '<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($values['charge'] == '工资'){
$strfullname = '';
foreach ($values['corresponding'] as $rcorresponding){
	if($strfullname != '') { $strfullname .='; '; }
	$strfullname .= $corresponding_id[$rcorresponding]->fullname;
}
				$salary[$tablocation][$values['charge']] .= '<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>';
		//}
		unset($data[$key]);
   }
  
}

?>

<script type="text/javascript" src="tpl/libs/js-xlsx/xlsx.core.min.js"></script>
<script type="text/javascript" src="tpl/libs/FileSaver/FileSaver.min.js"></script> 
<script type="text/javascript" src="tpl/libs/html2canvas/html2canvas.min.js"></script>
<script type="text/javascript" src="tpl/tableExport.js"></script>

<div class="s12">
	
    <ul style="display:flex;background:#eeeeee;align-items:center;height:unset;<?php if($_GET['none']) ?>" class="tabs">
		<?php if($currentuser->gm  == '1'  ||  $currentuser->location  == '越南' || $currentuser->location == '总公司'  ){ ?>
        <li data-tab="tab-0" class="tab-link  current ">越南公司财务报表 (RMB)</li>
		<?php } if($currentuser->gm  == '1' ||  $currentuser->location  == '中国' || $currentuser->location == '总公司' ){ ?>
        <li data-tab="tab-1" class="tab-link  ">中国公司财务报表 (RMB)</li>
		<?php } if($currentuser->gm  == '1' ||  $currentuser->location  == '泰国' || $currentuser->location == '总公司' ){ ?>
        <li data-tab="tab-2" class="tab-link  ">泰国公司财务报表 (RMB)</li>
        
       	<?php } if($currentuser->gm  == '1'  ||  $currentuser->location  == '印尼' || $currentuser->location == '总公司' ){ ?>
        <li data-tab="tab-3" class="tab-link  ">印尼公司财务报表 (RMB)</li> 
        <?php } if($currentuser->gm  == '1'  ||  $currentuser->location  == '马来西亚' || $currentuser->location == '总公司' ){ ?>
        <li data-tab="tab-4" class="tab-link  ">马来西亚公司财务报表 (RMB)</li> 
		<?php } if($currentuser->gm  == '1' || $currentuser->location == '总公司'  ){ ?>
		<li data-tab="tab-5" class="tab-link  ">公司财务报表 (RMB)</li>
                <li data-tab="tab-6" class="tab-link  "><button onclick="jQuery('.asjdhb').css('background-size','auto');jQuery('table').remove();jQuery('#tab-6').show(); setTimeout( function() { location.reload();    }, 1000);" style="cursor:pointer;        display: block;    background: #1b278a;    border: none;    padding: 5px 10px;    color: #fff;
    border-radius: 3px;">Save/节省</button></li>
		<?php } ?>
		
		
		<button type="botton" title="<?php $logdownload = file_get_contents("data/logdownload.json");	$logdownload = array_reverse(json_decode($logdownload)); echo implode('&#013;', $logdownload ); ?>" name="" class="btn-success" onclick="fnExcelReport('current');return false;" style="cursor:pointer;    right: 6px;    display: block;    background: #1b278a;    border: none;    padding: 5px 10px;    color: #fff;
    position: absolute;    border-radius: 3px;" >Export</button>
	
		<script>
			function fnExcelReport(tableid)
			{
				var dt = new Date();
				var time = dt.getDate() + "/"
                + (dt.getMonth()+1)  + "/" 
                + dt.getFullYear() + " @ "  
                + dt.getHours() + ":"  
                + dt.getMinutes() + ":" 
                + dt.getSeconds();
				jQuery('#tableexport').empty();
				jQuery('table.'+tableid+' tr').each(function(){
                                if(!jQuery(this).hasClass('tablesorter-filter-row')){
                                        jQuery(this).clone().appendTo("#tableexport");
                                }
                });
				$('#tableexport').tableExport({htmlContent: true,fileName: $('.tab-link.current').text()+'_'+time,type: 'xlsx'});
				jQuery('#tableexport').empty();
				$.get( "/expense/total_profit.php?who=<?php echo $currentuser->name; ?>&fileName="+$('.tab-link.current').text()+'_'+time, function( data ) {});
				
			}     
		</script>
      </ul>
</div>	
<div class='asjdhb' style="    width: 100%;    position: relative;     min-height: 500px;       background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/b1/Loading_icon.gif);
    background-repeat: no-repeat;    background-position: center center;     background-size: 0;">
<?php foreach ($quocgia as $keyquocgia => $ten){ 
  if($currentuser->gm  != '1' &&  $currentuser->role  != 'Finance' &&  $currentuser->location != $ten && $currentuser->location != '总公司' ){ 
	continue;
  }
  if ( $ml++ == 0){
      $current= 'current';
  }else{
      $current= '';
  }  
 
?>	
<?php if($ten == '中国'){ ?>
<table style="width: <?php echo $monthschedule*-100; ?>px!important;min-width:100%;position: relative;" class="striped responsive-table  tablesorter tab-content exclude <?php echo $current; ?>  " id="tab-<?php echo $keyquocgia; ?>"  >
		<thead>
			<tr>
			<th style="width: 10%;"></th>
			<?php for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ ?>
						<th><?php echo date('m/Y',strtotime('first day of '.$i.' month')); ?></th>
			<?php } ?>
			<th style="width:8%;" >总类型/Total</th>
			</tr>
		</thead>
		<tbody>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php  echo 'A.主营业务收入';  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
			$aa += (float)$income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td><input style="padding-left: 6px;font-size: 14px;width: calc(100% - 5px); font-weight: bold;" data-type="currency" type="text" placeholder="Income: 0.00" <?php if($currentuser->gm  != '1' && $currentuser->role != 'Controller'  &&  $currentuser->name != 'DANNA' &&  $currentuser->name != 'BILL' ){ echo 'disabled'; } ?> name="<?php echo $ten ?>_income_<?php echo date('m_Y',strtotime('first day of '.$i.' month')); ?>" class="remark totip" data-tooltip="Log: <?php echo str_replace('&#10;','<br>',str_replace(PHP_EOL,'&#10;',$income[$ten][date('m_Y',strtotime('first day of '.$i.' month')).'_log'])); ?>" type="text"  value="<?php echo number_format((float)$income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))],2); ?>" /></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php  echo 'B.主营业务支出';  ?></td>
		<?php $aa = 0 ;for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){
			$aa += (float)$cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td ><input style="padding-left: 6px;font-size: 14px;width: calc(100% - 5px); font-weight: bold;" data-type="currency" type="text" placeholder="Cost: 0.00" <?php if($currentuser->gm  != '1' && $currentuser->role != 'Controller' &&  $currentuser->name != 'DANNA' &&  $currentuser->name != 'BILL' ){ echo 'disabled'; } ?> name="<?php echo $ten ?>_cost_<?php echo date('m_Y',strtotime('first day of '.$i.' month')); ?>" class="remark totip " data-tooltip="Log: <?php echo str_replace('&#10;','<br>',str_replace(PHP_EOL,'&#10;',$cost[$ten][date('m_Y',strtotime('first day of '.$i.' month')).'_log'])); ?>" value="<?php echo number_format((float)$cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))],2); ?>" /></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >C.毛利润/Gross profit</td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){
				$aa += (float)$income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] - $cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format( ( $income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] - $cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))]) ,2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php  if($i18n['管理费用'] != ''){ echo 'D.'.$i18n['管理费用']; }else{ echo 'D.'.'管理费用'; }  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
			
		?>
                <td style="padding-left:6px!important; font-weight: bold;" >
                    <?php $d1 = 0;
                    foreach($totalcustom as $key => $p){
                        foreach ($group['管理费用'] as  $r) { 
                         if(stripos($key,'_'.date('m_Y',strtotime('first day of '.$i.' month'))) !== false && stripos($key,$r) !== false){
                             $d1 += (float)$p;
                             $aa += (float)$p;
                         }   
                        }         
                    }
                    $ad[date('m_Y',strtotime('first day of '.$i.' month'))] = $d1;
                    echo number_format((float)$d1,2); 
                    
                    ?>
                    
                    
                    
                </td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<?php $fn = 0 ;foreach ($group['管理费用'] as  $r) { 
    if( $currentuser->mod28 != '1' && $currentuser->gm  != '1' && $r == '工资'){
        //continue;
    }
    
    ?> 
<tr class="groupcate<?php echo $r; ?>">
		<td style="width:180px;padding-left:20px!important;" >
                    <?php echo ++$fn; ?>./ <?php if($r != ''){ if($i18n[$r] != ''){ echo $i18n[$r]; }else{ echo $r; } }else{ echo '未分类/none'; }; ?>
                </td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				  foreach($totalcustom as $key => $p){
                        
                                        if(stripos($key,'_'.date('m_Y',strtotime('first day of '.$i.' month'))) !== false && stripos($key,$r) !== false){
                                            $aa += (float)$p;
                                        }   

                                   }
		?>
				<td style="padding-left:6px!important;" >
                                    
                                    <input style="padding-left: 6px;font-size: 14px;width: calc(100% - 5px); font-weight: bold;" data-type="" type="text" placeholder="<?php echo $r; ?>: 0.00" <?php if($currentuser->gm  != '1' && $currentuser->role != 'Controller'  &&  $currentuser->name != 'DANNA' &&  $currentuser->name != 'BILL' ){ echo 'disabled'; } ?> name="<?php echo $ten ?>_<?php echo $r; ?>_<?php echo date('m_Y',strtotime('first day of '.$i.' month')); ?>" class="remark"  type="text"  value="<?php echo number_format( $totalcustom[$ten.'_'.$r.'_'.date('m_Y',strtotime('first day of '.$i.' month'))] ,2);  ?>" />
                                    
			
		</td>
		<?php } ?>
		<td style="padding-left:6px!important;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<?php } ?>		
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php   if($i18n['财务费用'] != ''){ echo 'E.'.$i18n['财务费用']; }else{ echo 'E.'.'财务费用'; }  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php 
                                
                                $d = 0;
                    foreach($totalcustom as $key => $p){
                        foreach ($group['财务费用'] as  $r) { 
                         if(stripos($key,'_'.date('m_Y',strtotime('first day of '.$i.' month'))) !== false && stripos($key,$r) !== false){
                             $d += (float)$p;
                              $aa += (float)$p;
                         }   
                        }         
                    }
                    $ad2[date('m_Y',strtotime('first day of '.$i.' month'))] = $d;
                    echo number_format((float)$d,2); 
                             
                                
                                
                                ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<?php  $fn = 0 ; foreach ($group['财务费用'] as $r){ ?> 
<tr>
		<td style="width:180px;padding-left:20px!important;" >
		
		<?php echo ++$fn; ?>./ <?php if($r != ''){ if($i18n[$r] != ''){ echo $i18n[$r]; }else{ echo $r; } }else{ echo '未分类/none'; }; ?>
		</td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
                    
                      foreach($totalcustom as $key => $p){
                        
                         if(stripos($key,'_'.date('m_Y',strtotime('first day of '.$i.' month'))) !== false && stripos($key,$r) !== false){
                             $aa += (float)$p;
                         }   
                                 
                    }
                    
                    
				
			?>
				<td style="padding-left:6px!important;" >	
                                       <input style="padding-left: 6px;font-size: 14px;width: calc(100% - 5px); font-weight: bold;" data-type="" type="text" placeholder="<?php echo $r; ?>: 0.00" <?php if($currentuser->gm  != '1' && $currentuser->role != 'Controller'  &&  $currentuser->name != 'DANNA' &&  $currentuser->name != 'BILL' ){ echo 'disabled'; } ?> name="<?php echo $ten ?>_<?php echo $r; ?>_<?php echo date('m_Y',strtotime('first day of '.$i.' month')); ?>" class="remark"  type="text"  value="<?php echo number_format( $totalcustom[$ten.'_'.$r.'_'.date('m_Y',strtotime('first day of '.$i.' month'))] ,2);  ?>" />
                                       
                                       
			
				</td>
		<?php } ?>
		<td style="padding-left:6px!important;" ><?php echo number_format((float)$aa,2); ?></td>
</tr>
<?php } ?>	

<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >G.纯利润/Net profit</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
                     if($income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] != 0){    
				$aa += (float)$b = $income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] - $cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] + $ad[date('m_Y',strtotime('first day of '.$i.' month'))] + $ad2[date('m_Y',strtotime('first day of '.$i.' month'))];
                     }
		?>
				<td style="padding-left:6px!important; font-weight: bold;" >
					<?php 
                                        if($income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] != 0){
                                            echo number_format($b,2);
                                        }else{
                                            echo '0.00';
                                        } 
                                        ?>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa,2); ?></td>
</tr>

<?php if( $currentuser->mod25 == '1' || $currentuser->gm  == '1'){ ?>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >F.借款收支</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
                    $abb = 0;
                    foreach($totalcustom as $key => $p){
                        
                         if(stripos($key,'_'.date('m_Y',strtotime('first day of '.$i.' month'))) !== false && stripos($key,'借款-支出') !== false){
                             $aa += (float)$p;
                             $abb += (float)$p;
                         }   
                           if(stripos($key,'_'.date('m_Y',strtotime('first day of '.$i.' month'))) !== false && stripos($key,'借款-收入') !== false){
                             $aa += (float)$p;
                             $abb += (float)$p;
                         }          
                    }
                    
			
		?>
				<td style="padding-left:6px!important; font-weight: bold;" >
					<?php echo number_format((float)$abb,2); ?>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa,2); ?></td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;   " >1.借款支出</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
                    
                      foreach($totalcustom as $key => $p){
                        
                         if(stripos($key,'_'.date('m_Y',strtotime('first day of '.$i.' month'))) !== false && stripos($key,'借款-支出') !== false){
                             $aa += (float)$p;
                         }   
                                 
                    }
                    
                    
			
		?>
				<td style="padding-left:6px!important; " >
                                    <input style="padding-left: 6px;font-size: 14px;width: calc(100% - 5px); font-weight: bold;" data-type="" type="text" placeholder="<?php echo '借款-支出'; ?>: 0.00" <?php if($currentuser->gm  != '1' && $currentuser->role != 'Controller'  &&  $currentuser->name != 'DANNA' &&  $currentuser->name != 'BILL' ){ echo 'disabled'; } ?> name="<?php echo $ten ?>_<?php echo '借款-支出'; ?>_<?php echo date('m_Y',strtotime('first day of '.$i.' month')); ?>" class="remark"  type="text"  value="<?php echo number_format( $totalcustom[$ten.'_'.'借款-支出'.'_'.date('m_Y',strtotime('first day of '.$i.' month'))] ,2);  ?>" />
                                    
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" >
                    <?php echo number_format((float)$aa,2); ?>  
                </td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;    " >2.借款收入</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
                    
                    
                      foreach($totalcustom as $key => $p){
                        
                         if(stripos($key,'_'.date('m_Y',strtotime('first day of '.$i.' month'))) !== false && stripos($key,'借款-收入') !== false){
                             $aa += (float)$p;
                         }   
                                 
                    }
                    
				
		?>
				<td style="padding-left:6px!important; " >
                                     <input style="padding-left: 6px;font-size: 14px;width: calc(100% - 5px); font-weight: bold;" data-type="" type="text" placeholder="<?php echo '借款-收入'; ?> : 0.00" <?php if($currentuser->gm  != '1' && $currentuser->role != 'Controller'  &&  $currentuser->name != 'DANNA' &&  $currentuser->name != 'BILL' ){ echo 'disabled'; } ?> name="<?php echo $ten ?>_<?php echo '借款-收入'; ?>_<?php echo date('m_Y',strtotime('first day of '.$i.' month')); ?>" class="remark"  type="text"  value="<?php echo number_format( $totalcustom[$ten.'_'.'借款-收入'.'_'.date('m_Y',strtotime('first day of '.$i.' month'))] ,2);  ?>" />
                                 
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" >
                   <?php echo number_format((float)$aa,2); ?> 
                </td>
</tr>

<?php } ?>



</tbody>
</table>    
<?php }else{ ?>    
<table style="width: <?php echo $monthschedule*-100; ?>px!important;min-width:100%;position: relative;" class="striped responsive-table  tablesorter tab-content exclude <?php echo $current; ?>  " id="tab-<?php echo $keyquocgia; ?>"  >
		<thead>
			<tr>
			<th style="width: 10%;"></th>
			<?php for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ ?>
						<th><?php echo date('m/Y',strtotime('first day of '.$i.' month')); ?></th>
			<?php } ?>
			<th style="width:8%;" >总类型/Total</th>
			</tr>
		</thead>
		<tbody>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php  echo 'A.主营业务收入';  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
			$aa += (float)$income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td><input style="padding-left: 6px;font-size: 14px;width: calc(100% - 5px); font-weight: bold;" data-type="currency" type="text" placeholder="Income: 0.00" <?php if($currentuser->gm  != '1' && $currentuser->role != 'Controller'  &&  $currentuser->name != 'DANNA' &&  $currentuser->name != 'BILL' ){ echo 'disabled'; } ?> name="<?php echo $ten ?>_income_<?php echo date('m_Y',strtotime('first day of '.$i.' month')); ?>" class="remark totip" data-tooltip="Log: <?php echo str_replace('&#10;','<br>',str_replace(PHP_EOL,'&#10;',$income[$ten][date('m_Y',strtotime('first day of '.$i.' month')).'_log'])); ?>" type="text"  value="<?php echo number_format((float)$income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))],2); ?>" /></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php  echo 'B.主营业务支出';  ?></td>
		<?php $aa = 0 ;for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){
			$aa += (float)$cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td ><input style="padding-left: 6px;font-size: 14px;width: calc(100% - 5px); font-weight: bold;" data-type="currency" type="text" placeholder="Cost: 0.00" <?php if($currentuser->gm  != '1' && $currentuser->role != 'Controller' &&  $currentuser->name != 'DANNA' &&  $currentuser->name != 'BILL'){ echo 'disabled'; } ?> name="<?php echo $ten ?>_cost_<?php echo date('m_Y',strtotime('first day of '.$i.' month')); ?>" class="remark totip " data-tooltip="Log: <?php echo str_replace('&#10;','<br>',str_replace(PHP_EOL,'&#10;',$cost[$ten][date('m_Y',strtotime('first day of '.$i.' month')).'_log'])); ?>" value="<?php echo number_format((float)$cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))],2); ?>" /></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >C.毛利润/Gross profit</td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){
				$aa += (float)$income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] - $cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format( ( $income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] - $cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))]) ,2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php  if($i18n['管理费用'] != ''){ echo 'D.'.$i18n['管理费用']; }else{ echo 'D.'.'管理费用'; }  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
			  $aa += (float)$Managementcosts[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format(  $Managementcosts[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] ,2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<?php $fn = 0 ;foreach ($group['管理费用'] as  $r) { 
    if( $currentuser->mod28 != '1' && $currentuser->gm  != '1' && $r == '工资'){
        //continue;
    }
    
    ?> 
<tr class="groupcate<?php echo $r; ?>">
		<td style="width:180px;padding-left:20px!important;" >
		<a href="#" class="tooltipped" data-position="top" data-tooltip="All month/整个月" 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 echo str_replace('"','',$salary[$ten][$r]); ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); " >
		<?php echo ++$fn; ?>./ <?php if($r != ''){ if($i18n[$r] != ''){ echo $i18n[$r]; }else{ echo $r; } }else{ echo '未分类/none'; }; ?>
		</a></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$groupvalue[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important;" >
				<a href="#" 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 echo str_replace(array('"',"'"),'',$salarymonth[$ten][$r][date('m_Y',strtotime('first day of '.$i.' month'))]); ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); " >
				<?php echo number_format((float)$groupvalue[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))],2);  ?>
				</a>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important;" ><?php echo number_format((float)$aa ,2); ?></td>
</tr>
<?php } ?>		
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php   if($i18n['财务费用'] != ''){ echo 'E.'.$i18n['财务费用']; }else{ echo 'E.'.'财务费用'; }  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$Financialexpenses[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format( $Financialexpenses[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] ,2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<?php  $fn = 0 ; foreach ($group['财务费用'] as $r){ ?> 
<tr>
		<td style="width:180px;padding-left:20px!important;" >
		
		<a href="#" class="tooltipped" data-position="top" data-tooltip="All month/整个月" 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 echo str_replace('"','',$salary[$ten][$r]); ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); " >
		<?php echo ++$fn; ?>./ <?php if($r != ''){ if($i18n[$r] != ''){ echo $i18n[$r]; }else{ echo $r; } }else{ echo '未分类/none'; }; ?>
		</a>
		</td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$groupvalue2[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
			?>
				<td style="padding-left:6px!important;" >				
				<a href="#" 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 echo str_replace('"','',$salarymonth[$ten][$r][date('m_Y',strtotime('first day of '.$i.' month'))]); ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); " >
				<?php echo number_format((float)$groupvalue2[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))],2);  ?>
				</a>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important;" ><?php echo number_format((float)$aa,2); ?></td>
</tr>
<?php } ?>	

<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >G.纯利润/Net profit</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
                     if($income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] != 0){    
				$aa += (float)$b = $income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] - $cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] + $Managementcosts[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] + $Financialexpenses[$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
                     }
		?>
				<td style="padding-left:6px!important; font-weight: bold;" >
				<?php 
                                        if($income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] != 0){
                                            echo number_format($b,2);
                                        }else{
                                            echo '0.00';
                                        } 
                                        ?>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa,2); ?></td>
</tr>

<?php if( $currentuser->mod25 == '1' || $currentuser->gm  == '1'){ ?>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >F.借款收支</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += ($groupvalue4[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))]+$groupvalue3[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))]);
		?>
				<td style="padding-left:6px!important; font-weight: bold;" >
					<?php echo number_format(($groupvalue4[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))]+$groupvalue3[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))]),2); ?>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa,2); ?></td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;   " >1.借款支出</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$groupvalue3[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; " >
                                    <a href="#" 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 echo str_replace(array('"',"'"),'',$salarymonth2[$ten]['借款-支出'][date('m_Y',strtotime('first day of '.$i.' month'))]); ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); " ><?php echo number_format((float)$groupvalue3[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))],2); ?></a>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" >
                    <?php echo number_format((float)$aa,2); ?>  
                </td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;    " >2.借款收入</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$groupvalue4[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; " >
                                    <a href="#" 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 echo str_replace(array('"',"'"),'',$salarymonth2[$ten]['借款-收入'][date('m_Y',strtotime('first day of '.$i.' month'))]); ?></table></div>',  classes: 'rounded' , displayLength: 20000 , inDuration: 50 , outDuration: 50 }); " ><?php echo number_format((float)$groupvalue4[$r][$ten][date('m_Y',strtotime('first day of '.$i.' month'))],2); ?></a>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" >
                   <?php echo number_format((float)$aa,2); ?> 
                </td>
</tr>

<?php } ?>



</tbody>
</table>
<?php } ?>    
<?php } ?>
<?php if($currentuser->gm  == '1' ||  $currentuser->role  == 'Finance'   ||  $currentuser->role  == 'Controller' ){ ?>
<table style="width: <?php echo $monthschedule*-100; ?>px!important;min-width:100%;position: relative;" class="striped responsive-table  tablesorter exclude tab-content" id="tab-5"  >
		<thead>
			<tr>
			<th style="width: 10%;"></th>
			<?php for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ ?>
						<th><?php echo date('m/Y',strtotime('first day of '.$i.' month')); ?></th>
			<?php } ?>
			<th style="width:8%;" >总类型/Total</th>
			</tr>
		</thead>
		<tbody>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php  echo 'A.主营业务收入';  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
			$aa += array_sum(array_column($income,date('m_Y',strtotime('first day of '.$i.' month')))); 
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format(array_sum(array_column($income,date('m_Y',strtotime('first day of '.$i.' month'))))  ,2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" ><?php  echo 'B.主营业务支出';  ?></td>
		<?php $aa = 0 ;for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){
			$aa +=  array_sum(array_column($cost,date('m_Y',strtotime('first day of '.$i.' month'))));  
		?>
				<td style="padding-left:6px!important; font-weight: bold;"  ><?php echo number_format(array_sum(array_column($cost,date('m_Y',strtotime('first day of '.$i.' month')))) ,2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >C.毛利润/Gross profit</td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){
				$aa += array_sum(array_column($income,date('m_Y',strtotime('first day of '.$i.' month')))) - array_sum(array_column($cost,date('m_Y',strtotime('first day of '.$i.' month'))));  
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format(array_sum(array_column($income,date('m_Y',strtotime('first day of '.$i.' month')))) - array_sum(array_column($cost,date('m_Y',strtotime('first day of '.$i.' month')))),2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >D.<?php  if($i18n['管理费用'] != ''){ echo $i18n['管理费用']; }else{ echo '管理费用'; }  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
			  $aa += (float)$Managementcoststo[date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format(  $Managementcoststo[date('m_Y',strtotime('first day of '.$i.' month'))] ,2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<?php $fn = 0 ;foreach ($group['管理费用'] as  $r) {
   
    
    
    ?> 
<tr class="groupcate<?php echo $r; ?>" >
		<td style="width:180px;padding-left:20px!important;" ><?php echo ++$fn; ?>./ <?php if($r != ''){ if($i18n[$r] != ''){ echo $i18n[$r]; }else{ echo $r; } }else{ echo '未分类/none'; }; ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$groupvalueto[$r][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important;" ><?php echo number_format((float)$groupvalueto[$r][date('m_Y',strtotime('first day of '.$i.' month'))],2);  ?></td>
		<?php } ?>
		<td style="padding-left:6px!important;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<?php } ?>		
<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >E.<?php   if($i18n['财务费用'] != ''){ echo $i18n['财务费用']; }else{ echo '财务费用'; }  ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$Financialexpensesto[date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format( $Financialexpensesto[date('m_Y',strtotime('first day of '.$i.' month'))] ,2); ?></td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa  ,2); ?></td>
</tr>
<?php  $fn = 0 ; foreach ($group['财务费用'] as $r){ ?> 
<tr>
		<td style="width:180px;padding-left:20px!important;" ><?php echo ++$fn; ?>./ <?php if($r != ''){ if($i18n[$r] != ''){ echo $i18n[$r]; }else{ echo $r; } }else{ echo '未分类/none'; }; ?></td>
		<?php $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$groupvalue2to[$r][date('m_Y',strtotime('first day of '.$i.' month'))];
			?>
				<td style="padding-left:6px!important;" ><?php echo number_format((float)$groupvalue2to[$r][date('m_Y',strtotime('first day of '.$i.' month'))],2);  ?></td>
		<?php } ?>
		<td style="padding-left:6px!important;" ><?php echo number_format(($aa)  ,2); ?></td>
</tr>
<?php } ?>	

<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >G.纯利润/Net profit</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$b = array_sum(array_column($income,date('m_Y',strtotime('first day of '.$i.' month'))))  - array_sum(array_column($cost,date('m_Y',strtotime('first day of '.$i.' month')))) + $Managementcoststo[date('m_Y',strtotime('first day of '.$i.' month'))] + $Financialexpensesto[date('m_Y',strtotime('first day of '.$i.' month'))];


// $income[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] - $cost[$ten][date('m_Y',strtotime('first day of '.$i.' month'))] + $Managementcoststo[date('m_Y',strtotime('first day of '.$i.' month'))] + $Financialexpensesto[date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; font-weight: bold;" >
					<?php echo number_format((float)$b,2); ?>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa,2); ?></td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;    font-weight: bold;" >F.借款收支</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += ($groupvalue3to[$r][date('m_Y',strtotime('first day of '.$i.' month'))]+$groupvalue4to[$r][date('m_Y',strtotime('first day of '.$i.' month'))]);
		?>
				<td style="padding-left:6px!important; font-weight: bold;" >
					<?php echo number_format(($groupvalue4to[$r][date('m_Y',strtotime('first day of '.$i.' month'))]+$groupvalue3to[$r][date('m_Y',strtotime('first day of '.$i.' month'))]),2); ?>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" ><?php echo number_format((float)$aa,2); ?></td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;   " >1.借款支出</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$groupvalue3to[$r][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; " >
                                   <?php echo number_format((float)$groupvalue3to[$r][date('m_Y',strtotime('first day of '.$i.' month'))],2); ?>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" >
                    <?php echo number_format((float)$aa,2); ?>  
                </td>
</tr>

<tr>
		<td style="width:180px;padding-left:6px!important;    " >2.借款收入</td>
		<?php  $aa = 0; for ($i = ($monthschedule-$adiff) ; $i < (1-$adiff) ; $i++){ 
				$aa += (float)$groupvalue4to[$r][date('m_Y',strtotime('first day of '.$i.' month'))];
		?>
				<td style="padding-left:6px!important; " >
                                   <?php echo number_format((float)$groupvalue4to[$r][date('m_Y',strtotime('first day of '.$i.' month'))],2); ?>
				</td>
		<?php } ?>
		<td style="padding-left:6px!important; font-weight: bold;" >
                   <?php echo number_format((float)$aa,2); ?> 
                </td>
</tr>



</tbody>
</table>
<div id="tab-6" style="display: none;" ><span style="color:red;">Loading..../加载中.....</span></div>
</div>
<?php } ?>


<?php if($currentuser->gm  == '1' || $currentuser->location == '总公司' ){  ?>
</form>
<?php } ?>

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script>
	jQuery("document").ready(function(){
                $( '.totip' ).tooltip();
		$('.remark').change(function(){
                        var form = $(".formupload");
                        var actionUrl = form.attr('action');

                        $.ajax({
                            type: "POST",
                            url: actionUrl,
                            data: form.serialize(), // serializes the form's elements.
                            success: function(data)
                            {
                             // alert(data); // show response from the php script.
                            }
                        });

			//$(".formupload").submit();
		});
	});
</script>   
<style>    
.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;
}
.toast.rounded div {
	height:300px;
	overflow:auto;
	width:100%;
}
td, th {
    padding: 5px 5px;
   
}
#toast-container {   
    top: 250px!important;
	min-width:850px;
}
.toast.rounded  {
	
}
.dfjaksku {
	position: absolute;
	top:-26px;
	right:0px;
	color:red;
	font-weight:bold;
	font-size:30px;    cursor: pointer;
}


</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 () {
		
		$( "body" ).delegate( '#toast-container tr' , "click", function() {
			$('#datestart').val($(this).attr('datestart'));
			$('#dateto').val($(this).attr('dateto'));
			$('#rowclick').val($(this).attr('rowclick'));
			$('#tabclick').val($(this).attr('tabclick'));			
			$('#formjump').submit();
		});
		$( "body" ).delegate( '.dfjaksku' , "click", function() {	
			$('.toast.rounded').hide();
		});
		$(".sandjnas").change(function(){
			if($( ".sandjnas option:selected" ).hasClass('isspeci')){
				$(".isdepartmentform").show();
			}else{
				$(".isdepartmentform").hide();
			}
		});
	
		$("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 -->
<form method="POST" id="formjump" action="index.php" target="_blank" >
	<input value="" id="datestart" name="datestart" type="hidden" />
	<input value="" id="dateto" name="dateto" type="hidden" />
	<input value="" id="rowclick" name="rowclick" type="hidden" />
	<input value="" id="tabclick" name="tabclick" type="hidden" />	
</form>
<table id="tableexport" ></table>	
<style>table.tblinfo{} table.tblinfo td{border-spacing:collapse;border:1px solid #555; min-width:50px;}

@media only screen and (max-width: 1466px) {
 
}


 ul.tabs li { 
    padding: 10px 5px!important;
  }
</style>					
<?php    
// FOOTER
include 'tpl/footer.php';

