<?php require_once('../auth/auth.php');   
 $em_group_id=$_GET['em_group_id'];
?>
<section class="content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-4">
				<div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
					<div class="card-header" style="padding: 4px 8px;">
						<h3 class="card-title"> <?php echo language(170); ?>  </h3>
						<div class="card-tools">
							<button type="button" class="btn btn-tool" data-card-widget="remove">
							<i class="fas fa-times"></i>
							</button>
						</div>
					</div>
                    	<div class="card-body ">
					
							<div class="col-md-12" >
    						   <div class="info-box mt-1" style="background:#e9ecef;">
							<span class="info-box-icon bg-navyblue text-white"><i class="nav-icon fa fa-fw fa-user-secret"></i></span>
							<div class="info-box-content">
								<span class="info-box-number text-bold text-success ">
								   <span>Dr. <ss id="drtval"></ss> <?php echo $currency ?></span>
								   <hr style="background:black;">
							       <span class="text-danger">Cr. <ss id="crtval"></ss> <?php echo $currency ?></span> 
							    </span>
								
    							<small>
    							   <b> 
    								<span  style="float: left;"><?php echo language(244); ?> :  <?php 
									echo $branch_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT branch_name FROM branch WHERE  coid='$coid' AND brid='$brid' LIMIT 1 "))['branch_name'];?>  </span>
    								<span  style="float: right;"> <?php echo language(140); ?> : 
    								<?php	echo $count_row =mysqli_fetch_assoc(mysqli_query($conn,"SELECT  COUNT(*) as count_row FROM accounts 
    								WHERE coid='$coid' AND bid='$bid' AND gcatid='$em_group_id' AND active=1  "))['count_row'];  ?></span>
    							   </b>
    							</small>
							</div>
						</div>
						
								<div class="row">
									<div class="col-md-9">
										<div class="form-group">
											<input type="text" class="form-control form-control-sm inputselect" id="trsearch">
										</div>
									</div>
									<div class="col-md-3">
										<div class="card" style="margin:;">
											<button type="button" class="btn btn-success btn-xs" 
											onclick="pagecall('../hr_manage/employee_add.php?gcatid=<?php echo $em_group_id ?>'+'&ac_type=0','#employee_view')"> <i style="padding:px;" class="fa fa-plus"></i></button>
										</div>
									</div>
								</div>
							</div>
						</div>
				
					<div class="card-body table-responsive p-0 cscroll" style="max-height: 450px;">
						<table class="table table-sm table-head-fixed text-nowrap table-hover" style="overflow-x:auto;">
							<thead>
								<tr>
                                    <th class="text-center" style="width:2%;background:#e9ecef !important;"><?php echo language(15);?></th>
									<th style="width:70%;text-align:left;background:#e9ecef !important;"><?php echo language(215)?></th>
									<th style="width:28%;text-align:right;background:#e9ecef !important;"><?php echo language(233)?></th>
								</tr>
							</thead>
							<?php
								$accoung_query= mysqli_query($conn,"SELECT em_employee.em_id,em_employee.em_acid,em_employee.em_acname,em_employee.em_phone,em_employee.id_card,accounts.balance FROM em_employee INNER JOIN accounts ON  accounts.acid=em_employee.em_acid WHERE em_coid='$coid'  AND em_bid='$bid' AND em_brid='$brid'  AND active=1   ") or die (mysql_error());
						      	$data = [];
						      	while ($em_row= mysqli_fetch_assoc($accoung_query)){ $data[]=$em_row;}
							?>
						<tbody class="actived" id="employee_show"></tbody>
					</table>
				</div>
			</div>
		</div>
		<div class="col-md-8" id="employee_view"></div>
	</div>
</div>
</section>
<script type="text/javascript">
	$(document).ready(function(){
		let itdata = '';
		let i = 0;
		let drtval = 0;
		let crtval = 0;



     	$.each(<?php echo json_encode($data) ?>, function(key,value){
	    if(Number(value.balance)>=0) {
	      drtval  += Number(value.balance);
	    } else if(Number(value.balance)<0) {
	      crtval  += Number(-value.balance);  
	    }
		itdata += '<tr onclick="acprofile('+value.em_acid+' ,'+value.em_id+')">';
		itdata += '<td style="padding: ;text-align:center;">'+ ++i +'</td>';
		itdata += '<td style="padding: ;text-align:left;">'+ value.em_acname + ','+ value.id_card + ',' + value.em_phone +'</td>';
		itdata += '<td style="padding: ;text-align:right;">'+ bden.format(value.balance) +'</td>';
		itdata += '</tr>';
	});
		$("#employee_show").append(itdata);
		$("#drtval").text(bden.format(drtval));
		$("#crtval").text(bden.format(crtval));

	});

	function acprofile(em_acid,em_id){    
		pagecall('../accounts/ac_profile.php?acid='+em_acid+'&get_em_id='+em_id,'#employee_view');   
	}  
</script>
<script>
	$(document).ready(function(){
		$('#trsearch').on('keyup',function(){
			var searchTerm = $(this).val().toLowerCase();
			$('#employee_show tr').each(function(){
				var lineStr = $(this).text().toLowerCase();
				if(lineStr.indexOf(searchTerm) === -1){
					$(this).hide();
				}else{
					$(this).show();
				}
			});
		});
	});
</script>				
				