<?php

ob_start();
require 'setup/config.php';
session_start();
$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
$file = 'data/Reminder.json'; // DATA FILE NAME
// LOGIN CHECK
session_start();
$login = check_current_user_login($ARR_USERS, $SALT);
$currentuser = $login['user'];
$currency = json_decode(file_get_contents('data/Currency.json'), true);
foreach ($currency as $r){
	$currency[$r['id']] = $r['exchangerate'];
}
//var_dump($login);
if($login['status'] == 200){
    if($currentuser->gm != '1' && $currentuser->reminder != '1' ){        
        header('location: index.php');
        exit;
    }
    //var_dump($login);
}else{
    header('location: login.php');
    exit;
}


if (@$_GET['delete_id'] != '' && $currentuser->gm  == '1' ) {
    $data = json_decode(file_get_contents($file), true);
    foreach ( $data as $key => $r  ){
        if($r['id'] == @$_GET['delete_id']){
			if ($currentuser->role == 'Manager' || ( $currentuser->role == 'Operator' && $r['status'] == '' ) ) {
				unset($data[$key]);
			}
        }
    }
	
    $convert_array_to_json = array_values($data);
    $write_json = json_encode($convert_array_to_json);
    file_put_contents($file, $write_json);
	header('location: reminder.php?msg=' . $i18n['Entry successfully deleted.']);
}

if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['content'] != '' 
    && $_POST['amount'] != '' && ($currentuser->gm  == '1' || $currentuser->reminder  == '1' ) ) {
		
	if(count((array)$_FILES['fileupload']['name']) > 0){
			 foreach ($_FILES['fileupload']['name'] as $filekey => $fileu){
				if($_FILES['fileupload']['error'][$filekey] != 0 || strpos($_FILES['fileupload']['filetype'][$filekey],'application/octet-stream') !== false || strpos($fileu,'.php') !== false || strpos($fileu,'.html') !== false ){ continue; }
				
				 $filename_text = time().'_'.$fileu;
				 $filename[] = $fileu;
				 $filetype[] = $_FILES['fileupload']['type'][$filekey];
				 $filesize[] =  $_FILES['fileupload']['size'][$filekey];
				 $filetimeupload[] = time();
				 $filecreatebyid[] = $currentuser->id;
				 $filecreatebyname[] = $currentuser->name;
				 $filepath[] = $filename_text;
				 copy( $_FILES['fileupload']['tmp_name'][$filekey] , __DIR__.'/uploads/'.$filename_text );
			 }
			
	}	
	
	if($_POST['id'] == ''){		
		$receivable = $amount = 0;
        $formdata = array(
        'id' => time()
        , 'content' => $_POST['content']
        , 'start' => $_POST['start']
        , 'end' => $_POST['end']
		, 'type' => $_POST['type']
		, 'currency' => $_POST['currency']
		, 'dayofmonth' => $_POST['dayofmonth']
		, 'amount' => $_POST['amount']	
		, 'deposit' => 	$_POST['deposit']	
		, 'location' => $_POST['location'] 
		, 'method'	 => $_POST['method']
		, 'remark'	 => $_POST['remark'] 		
		, 'createby' => $currentuser->name
		, 'filename' => $filename
		, 'filetype' => $filetype
		, 'filesize' => $filesize
		, 'filetimeupload' => $filetimeupload
		, 'filecreatebyid' => $filecreatebyid
		, 'filecreatebyname' => $filecreatebyname
		, 'filepath' => $filepath
		);
		$arr_data = array();
		if (file_exists($file)) {
			$jsondata = file_get_contents($file);
			$arr_data = json_decode($jsondata, true);
		}
		$arr_data[] = $formdata;
	}else{
		$arr_data = array();
			if (file_exists($file)) {
        		$jsondata = file_get_contents($file);
        		$arr_data = json_decode($jsondata, true);
    		}
		foreach ($arr_data as $key => $r){
			if($r['id'] == $_POST['id']){ 
				if(file_exists('logs/'.$_POST['id'])){
					$textlog = '----------------------'.date('Y-m-d H:i:s').' - '.$currentuser->name.'----------------------'.PHP_EOL.$_POST['content'];
				}else{
					$textlog = $arr_data[$key]['Content'].PHP_EOL.'----------------------'.date('Y-m-d H:i:s').' - '.$currentuser->name.'----------------------'.PHP_EOL.$_POST['content'];
				}
				$arr_data[$key]['currency'] = $_POST['currency'];
				$arr_data[$key]['content'] = $_POST['content'];
				$arr_data[$key]['start'] = $_POST['start'];
				$arr_data[$key]['end'] = $_POST['end'];
				$arr_data[$key]['location'] = $_POST['location'];	
				$arr_data[$key]['type'] = $_POST['type'];
				$arr_data[$key]['dayofmonth'] = $_POST['dayofmonth'];					
				$arr_data[$key]['amount'] = $_POST['amount'];
				$arr_data[$key]['deposit'] = $_POST['deposit'];
				$arr_data[$key]['method'] = $_POST['method'];
				$arr_data[$key]['remark'] = $_POST['remark'];
				$arr_data[$key]['modifiedname'] = $currentuser->name;
				$arr_data[$key]['modifiedtime'] = time();
				$arr_data[$key]['method'] = $_POST['method'];
				$arr_data[$key]['filename'] = $_POST['filename'];
				if(count((array)$filename) > 0){
					if(is_array($arr_data[$key]['filename'])){
						$arr_data[$key]['filename'] = array_merge($filename,$arr_data[$key]['filename']);
					}else{
						$arr_data[$key]['filename'] = $filename;
					}
					
					if(is_array($arr_data[$key]['filepath'])){
						$arr_data[$key]['filepath'] = array_merge($filepath,$arr_data[$key]['filepath']);
					}else{
						$arr_data[$key]['filepath'] = $filepath;
					}
					
					
					if(is_array($arr_data[$key]['filetype'])){
						$arr_data[$key]['filetype'] = array_merge($filetype,$arr_data[$key]['filetype']);
					}else{
						$arr_data[$key]['filetype'] = $filetype;
					}
					
					//$arr_data[$key]['filetype'] = array_merge($filetype,$arr_data[$key]['filetype']);
					$arr_data[$key]['filesize'] = array_merge($filesize,$arr_data[$key]['filesize']);
					$arr_data[$key]['filetimeupload'] = array_merge($filetimeupload,$arr_data[$key]['filetimeupload']);
					$arr_data[$key]['filecreatebyid'] = array_merge($filecreatebyid,$arr_data[$key]['filecreatebyid']);
					$arr_data[$key]['filecreatebyname'] = array_merge($filecreatebyname,$arr_data[$key]['filecreatebyname']);
					//$arr_data[$key]['filepath'] = array_merge($filepath,$arr_data[$key]['filepath']);
				}
				file_put_contents('logs/'.$_POST['id'],file_get_contents('logs/'.$_POST['id']).$textlog.PHP_EOL);
			}			
		}
		
	}
    
	$arr_data = array_values($arr_data);
    $jsondata = json_encode($arr_data);
    if (file_put_contents($file, $jsondata)) {
        $msg = $i18n['Data successfully saved!'];
    } else {
        $msg = $i18n['ERROR &mdash; Data not saved!'];
    }
    header('location: reminder.php?msg=' . $msg);
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $_GET['msg'] = $i18n['All fields are required!'];
}


// READ DATA
$jsonString = file_get_contents($file);
$data = json_decode($jsonString, true);
$tabs = json_decode(file_get_contents('data/Tabs.json'));
// GENERATE LIST FOR DATA-LIST IN NAME INPUT FIELD


// SAVE NEW ENTRY IF FORM POSTED
// HEADER
ob_end_flush();
include 'tpl/header.php';

foreach ($data as $key => $values) {
	if(  	$currentuser->gm  == '1' 
			|| $values['location'] == 'All' 
			|| $values['location'] == $currentuser->locationreminder 
			|| $currentuser->location == "总公司"   
		){
			
			$l[$values['type']][] = $values;
	}
}
$data = $l;

// FORM FOR EDIT ENTRY
?>

    <div class="badge grey lighten-3 hoverable create-user">
            <form action="" method="POST" enctype="multipart/form-data" >
				<input value=""  id="id" name="id" type="hidden"  />
                <div class="row">                    
					<div class="input-field col s1">
						<select name="type" id="type" >
							<option value="" >-------</option>
							<option value="1.工资" >1.工资</option>
							<option value="2.社保" >2.社保</option>
							<option value="3.奖金" >3.奖金</option>
							<option value="4.员工年终奖" >4.员工年终奖</option>
							<option value="5.房租车租类" >5.房租车租类</option>
							<option value="6.水电网话物类" >6.水电网话物类</option>
							<option value="7.差旅费" >7.差旅费</option>
							<option value="8.办公费" >8.办公费</option>
							<option value="9.快递费" >9.快递费</option>
							<option value="10.福利费" >10.福利费</option>
							<option value="11.服务费-GM" >11.服务费-GM</option>
							<option value="12.业务招待费" >12.业务招待费</option>
							<option value="13.坏账损失" >13.坏账损失</option>
							<option value="14.利息" >14.利息</option>
						</select>
						<label for="name"><?php echo $i18n['费用归类']; ?></label>
                        <span class="helper-text" data-error="Error" data-success="OK">                          
                        </span>
					</div>
					<div class="input-field col s2" style="width: 20%;" >
                        <input 
                            value="<?php echo $data['content']; ?>" 
                            id="content" 
                            name="content" 
                            type="text" 
                            class="validate"                           
                            required="required" 
							autocomplete="off" />
                        <label for="content">Content/内容</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
					
					<div class="input-field col s2 shi ">
						<select name="dayofmonth[]" id="dayofmonth" multiple >
							<?php for($i = 1 ; $i <= 31 ; $i++ ){ ?>
								<option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
							<?php } ?>
						</select>
						<label for="name">Date of month/付款时间</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
					</div>
					<div class="input-field col s1">
						<select name="method" id="method"  >
							<option value="现金" >现金</option>
							<option value="公司卡" >公司卡</option>
							<option value="个卡" >个卡</option>												
						</select>
						<label for="name">Payment/付款形式</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
					</div>
					
					<div class="input-field col s1">
                        <input 
                            value="" 
							data-type='currency'
                            id="amount" 
                            name="amount" 
                            type="text" 
                            class="validate" 
                            maxlength="32" 
                            data-length="32" 
                            required="required" autocomplete="off" />
                        <label for="amount">Amount/金额</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
					<div class="input-field col s1">
                        <input 
                            value="" 
							data-type='currency'
                            id="deposit" 
                            name="deposit" 
                            type="text" 
                            class="validate" 
                            maxlength="32" 
                            data-length="32" 
                            autocomplete="off" />
                        <label for="deposit">押金 - Deposit</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
					
					<div class="input-field col s1" style="    width: 85px;">
                        <select name="currency" id="currency" tabindex="-1">                           
                       		<option value="RMB">RMB</option>
							<option value="USD">USD</option>
							<option value="VND" selected="">VND</option>
							<option value="Baht">Baht</option>								
						</select>
                        <label for="amount"></label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
					
					<div class="input-field col s1"  >
                        <select name="location" id="location">
                            <option value="All">All/所有</option>
                           	<option value="总公司">总公司</option>
                            <option value="越南">越南</option>
                            <option value="中国">中国</option>
							<option value="泰国">泰国</option>
                        </select>
                        <label for="location">地点/Location</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                            
                        </span>
                    </div>
					
					
					 <div class="input-field col s1">
                       <input
                         value="<?php echo date($DATE);?>"
                         id="start"
                         name="start"
                         type="text"
                         class="datepicker"
                         maxlength="<?php strlen($PICK); ?>"
                         data-length="<?php strlen($PICK); ?>" />
                        <label for="date">Start/开始</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
					
                    <div class="input-field col s1">
                       <input
                         value="<?php echo date($DATE);?>"
                         id="end"
                         name="end"
                         type="text"
                         class="datepicker"
                         maxlength="<?php strlen($PICK); ?>"
                         data-length="<?php strlen($PICK); ?>" />
                        <label for="date">End/结束</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
					
					<div class="input-field col s1" style="    text-align: right;    width: auto;    padding: 0;">
                        <button class="colortoptran btn waves-effect waves-light" type="submit" name="action">
                          Save
                        </button>
                    </div>
                    <div class="input-field col s1 " style="    width: auto;" >
                        <a style="    background: #4e4e4e;" class="btn  btn-default waves-effect waves-light" href="./index.php">
                            <?php echo $i18n['Go Back']; ?>
                        </a>
                    </div>
					
					<div class="input-field col s4  dhkasbdbas"  >
						<div class="file-field">
							<div class="btn btn-primary btn-sm float-left" style="padding: 3px;" >
								  <span><?php echo $i18n['Choose file']; ?></span>
								  <input type="file"  name="fileupload[]"  id="fileupload"  multiple="multiple" style="z-index: 1000;" >
							</div>
							<div class="file-path-wrapper">
							
							<div class="chips chips-initial input-field" style="    margin: 0;" >
								<input class="file-path validate" type="text" style="border-bottom: 0;" placeholder="<?php echo $i18n['Upload your file']; ?>">
							</div>
								 
							</div>
						</div>
					</div>
					<div class="input-field col s3">
                        <textarea 
                            id="remark" 
                            name="remark" 
                            type="text" 
                            class="validate" 
                            autocomplete="off" style="   background: #fff; margin-top: 10px;height:40px;" ><?php echo @$_POST['Content']; ?></textarea>
                        <label for="name">Remark/备注</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
                </div> 
            </form>
        </div>
<?php if( $currentuser->gm == '1' ){  ?><?php } ?>		
<table class="striped responsive-table  tablesorter" id="tab-table" style="border: 1px solid #000;" >
            <thead>
                <tr>
					<th style="border-left: 1px solid #1b278a;" >No.</th>
					<th >Type<br>管理费用</th>
                    <th style="width: 15%" >Content<br>内容</th>
					<th >Location<br>地点</th>
                    <th >Date of month<br>付款时间</th>
                    <th >Payment<br>付款形式</th>
					<th >Amount<br>金额</th>	
					<th >Deposit<br>押金</th>
					<th >Start<br>开始</th>
					<th >End<br>结束</th>
					<th >File<br>档案文件</th>		
					<th >Remark<br>备注</th>							
					<th  style="border-right: 1px solid #1b278a;" ><?php echo $i18n['Action']; ?></th>
					
            </thead>
        <tbody>
			<?php foreach ($data as $key1 => $value) {
						
					foreach ($value as $key2 => $values) { 
						if($re == 0){ $n = " border-top:1px solid #999!important;";  }else{ $n = "";  } 
						
						$file = ''; 
								
								
						foreach ($values['filename'] as $keyfile => $dataf ){
										$fnjf++;
										if ( strpos($values['filetype'][$keyfile] , 'pdf')  !== false ) {
												if( $currentuser->location == '中国' ){
													$file .=  '<a ref="https://htlservice.net/expense/uploads/'.rawurlencode($values['filepath'][$keyfile]).'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}else{
													$file .=  '<a ref="https://drive.google.com/viewerng/viewer?url=https://htlservice.net/expense/uploads/'.urlencode($values['filepath'][$keyfile]).'?pid=explorer&efh=false&a=v&chrome=false&embedded=true" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}
										} elseif ( strpos($values['filetype'][$keyfile] , 'sheet')  !== false || strpos($values['filepath'][$keyfile] , '.xls')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/expense/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/excel.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'zip')  !== false ) { 
												$file .=  '<a download href="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/zip.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'doc')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/expense/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'"  href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/word.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'image')  !== false ) { 
												$file .=  '<a ref="uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));"  ><img src="https://htlservice.net/Docs/tpl/img/png.png" style="width:24px;height:auto;" /></a>';
										} else{
												$file .=  '<a download href="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/file.png" style="width:24px;height:auto;" /></a>';
										}
						}
						$amount[$values['currency']] +=	str_replace(',','',$values['amount']);	
						
						$Deposit[$values['currency']] += 	str_replace(',','',$values['deposit']);
				?>
				<tr>
					<td style="text-align:center;<?php echo $n; ?>" ><?php echo ++$j; ?></td>
					<td style="<?php echo $n; ?>" ><?php if($re == 0) { echo $key1; $re = 1;} ?></td>					
					<td style="<?php echo $n; ?>" ><?php echo $values['content']; ?></td>
					<td style="<?php echo $n; ?>" ><?php echo $values['location']; ?></td>					
					<td style="<?php echo $n; ?>" ><?php echo implode(', ',$values['dayofmonth']); ?></td>
					<td style="<?php echo $n; ?>" ><?php echo $values['method']; ?></td>
					<td style="<?php echo $n; ?>" ><?php echo $values['amount'].' '.$values['currency']; ?></td>
					<td style="<?php echo $n; ?>" ><?php if($values['deposit'])echo $values['deposit'].' '.$values['currency']; ?></td>
					<td style="<?php echo $n; ?>" ><?php echo $values['start']; ?></td>
					<td style="<?php echo $n; ?>" ><?php echo $values['end']; ?></td>
					<td style="<?php echo $n; ?>" ><?php echo $file; ?></td>
					<td style="<?php echo $n; ?>" ><?php echo $values['remark']; ?></td>
					<td style="<?php echo $n; ?>" >
					
						<?php if( $currentuser->gm  == '1' || ( $currentuser->role == 'Finance' && $currentuser->reminder  == '1' ) ){ ?>
						<a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['EDIT'] ?>" href="#" onclick='editc("<?php echo addslashes(json_encode($values)); ?>")'>
								<i class="grey-text small material-icons">mode_edit</i>
						</a>
						<?php }	?>					
						<?php if( $currentuser->gm  == '1'){ ?>	
						<a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['Click alert link for delete!']?>" href="reminder.php?delete_id=<?php echo $values['id']; ?>" >
								<i class="red-text text-darken-4 small material-icons">delete_forever</i>
						</a>
						<?php } ?>
					</td>
				</tr>
			<?php }
				$re = 0;
			} ?>
		</tbody>
		<tfoot>
			<tr>
			<td ></td>
			<td ></td>
			<td ></td>
			
			
			<td ><b>Total/总</b></td>
			<td colspan="2" >
			<?php if($amount['VND']){echo number_format((float)$amount['VND']).' VND<br>';} ?>
			<?php if($amount['USD']){echo number_format((float)$amount['USD']).' USD<br>';} ?>
			<?php if($amount['Baht']){echo number_format((float)$amount['Baht']).' Baht<br>';} ?>
			<?php if($amount['RMB']){echo number_format((float)$amount['RMB']).' RMB';} ?>
			<td >总: <?php echo number_format((float)$amount['RMB']+$amount['VND']*$currency['1560829223']+$amount['Baht']*$currency['1560911884'] ); ?>(RMB)</td>
			</td>
			<td style="border-left: 1px solid #999999;" ><b>押金 - Deposit</b></td>
			
			<td colspan="2" >
			<?php if($Deposit['VND']){echo number_format((float)$Deposit['VND']).' VND<br>';} ?>
			<?php if($Deposit['USD']){echo number_format((float)$Deposit['USD']).' USD<br>';} ?>
			<?php if($Deposit['Baht']){echo number_format((float)$Deposit['Baht']).' Baht<br>';} ?>
			<?php if($Deposit['RMB']){echo number_format((float)$Deposit['RMB']).' RMB';} ?>
			</td>
			<td >总: <?php echo number_format((float)$Deposit['RMB']+$Deposit['VND']*$currency['1560829223']+$Deposit['Baht']*$currency['1560911884'] ); ?>(RMB)</td>
			<td ></td>
			<td ></td>
			</tr>
		</tfoot>
</table>		
<style>
tfoot td {	
    background: #ffeace;
	border-top: 1px solid #999!important;
	font-weight:bold;
}
th {
    padding: 10px 5px;

}
.chip {
    z-index: 1001;
    position: relative;
	    max-width: 130px;
    overflow: hidden;
	    margin-bottom: -9px;
}
.chip i{
	    color: red;
}
.shi .dropdown-content li>span {  
    padding: 0px 12px;
}
.dropdown-content li>span {  
    padding: 0px 12px;
}
.shi .dropdown-content li {  
   width: 30%;
    float: left;
    text-align: left;
	    clear: none;
}
table.tablesorter thead tr th {
    background-color: #1b278a;
    color: #fff;
}
table.striped tr {
    border-bottom: none;
}
.input-field .helper-text {  
    display: none;
}
.chips .input.file-path {
    width: 100%!important;
}
.chips .input.file-path.isacctive {
    width: 120px!important;
}
.isleft{ width: 50px; height: 50px; position: fixed; left: 15px; top: 45%; z-index: 1000000; font-size: 54px; opacity: 0.2;cursor: pointer; } .isright{ width: 50px; height: 50px; position: fixed; right: 15px; top: 45%; z-index: 1000000; font-size: 54px; opacity: 0.2;cursor: pointer; } .isleft:hover , .isright:hover{ opacity: 0.5; } .isleft i , .isright i { } 
</style>           
<div id="readfile" class="modal" style="    width: 80%!important;" >
			<a onclick="$('.modal-overlay').trigger('click');" style="       background: transparent;    color: red;    font-weight: bold;    font-size: 35px;	    font-family: cursive;    width: 30px;    height: 30px;    top: 0px;    right: 20px;    position: absolute;    left: unset;    bottom: unset;    display: block;    cursor: pointer;" >x</a>
			<iframe class="iframereadfile" src="" width="100%" style="height:auto;    min-height: 550px;" ></iframe>
			<div class="isleft" ><i class="fas fa-chevron-left"></i></div>
			<div class="isright" ><i class="fas fa-chevron-right"></i></div>		
</div>		
<script>
$(document).ready(function(){
	 $('.chips').chips();
	$('.isleft').click(function(){
		if($('.isreadder'+$(this).attr('nextread')).prev().hasClass('modal-trigger')){
			$('.isreadder'+$(this).attr('nextread')).prev().trigger('click');
		}
	});
	$('.isright').click(function(){
		if($('.isreadder'+$(this).attr('nextread')).next().hasClass('modal-trigger')){
			$('.isreadder'+$(this).attr('nextread')).next().trigger('click');
		}
	});	
	$( "body" ).delegate( ".chip i", "click", function() {
		$(this).parent().remove();
	});
});	
function editc(id) {

var obj = jQuery.parseJSON(id);
$('#content, #amount, #remark').next().addClass('active');
$('#id').val(obj.id);
$('#content').val(obj.content);
$('#start').val(obj.start);
$('#end').val(obj.end);
$('#location').val(obj.location);
$('#dayofmonth').val(obj.dayofmonth);
$('#method').val(obj.method);
$('#amount').val(obj.amount);


$('#currency').val(obj.currency);
$('#type').val(obj.type);
$('#remark').val(obj.remark);
$('#deposit').val(obj.deposit);
$('select:not(.exclude):not(#status)').formSelect();
$('.chip').remove();
$('.file-path').addClass('isacctive');

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


								
								
}
   
jQuery(document).ready(function ($) {
							  
								$(".cllogcontent").click(function(){
		$(".logcontent").html($(this).find('span').html());
	});	
							$("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>	
<?php
// FOOTER
include 'tpl/footer.php';
