<script src="js/ajax.js" type="text/javascript"></script>
<div class="page-content-wrapper">
                <div class="page-content">
                    <div class="page-bar">
                        <div class="page-title-breadcrumb">
                            <div class=" pull-left">
                                <div class="page-title"><?php echo 'Add Advance Salary'; ?></div>
                            </div>
                            <ol class="breadcrumb page-breadcrumb pull-right">
                                <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item" href="index.php?page=home">Home</a>&nbsp;<i class="fa fa-angle-right"></i>
                                </li>
                                <li><a class="parent-item" href="index.php?page=view_staff&id=<?php echo $staffId; ?>">Staff</a>&nbsp;<i class="fa fa-angle-right"></i></li><li class="active">Add Advance Salary</li>
                            </ol>
                        </div>
                    </div>
<div class="row">
                        <div class="col-md-12 col-sm-12">
                            <div class="card card-box">
                                <div class="card-head">
                                    <header><?php echo 'Add Advance Salary'; ?></header>                                    
                                </div>
                                <div class="card-body" id="bar-parent1">
                                	<?php if(isset($error) && $error!='') { ?> 
                                	<div class="alert alert-danger"><?php echo $error; ?></div>
                                	<?php } else if(isset($success) && $success!=''){ ?>                                		
                                		<div class="alert alert-success"><?php echo $success; ?></div>
                                	<?php } else if(isset($_REQUEST['success'])){ ?>                                		
                                		<div class="alert alert-success"><?php echo urldecode($_REQUEST['success']); ?></div>
                                	<?php } ?>
                                    <form action="" id="form_staff_add" class="form-horizontal" method="post">
                                        <div class="form-body">                                            
                                            <div class="form-group row">
                                                <label class="control-label col-md-3">Select Staff<span class="required"> * </span></label>
                                                <div class="col-md-4">                                                    
                                                    <select class="form-control" name="staff" id="staff" >
                                                        <option value="">Select Staff</option>
                                                        <?php if(mysqli_num_rows($staffListRs)>0){
                                                        	while($staffRec = mysqli_fetch_array($staffListRs)){ ?>   
                                                        	<option value="<?php echo $staffRec['id']; ?>" <?php if(isset($_POST['staff']) && $_POST['staff']==$staffRec['id']){ echo 'selected="selected"';} else if(isset($staffId) && $staffId==$staffRec['id']){ echo 'selected="selected"';}?> ><?php echo getStaffName($staffRec['id']); ?></option>
                                                        <?php } } ?>                                                     
                                                    </select>
                                                </div>                                                  
                                            </div> 
                                            <!--<div class="form-group row">
                                                <label class="control-label col-md-3">Salary</label>
                                                <div class="col-md-4">                                                    
                                                    <input readonly="readonly" name="salary" type="text" id="salary" data-required="1" class="form-control" value="<?php if(isset($basicSalary) && $basicSalary!=''){ echo $basicSalary;} ?>"/>
                                                </div>
                                            </div> -->                                           
                                            <div class="form-group row">
                                                <label class="control-label col-md-3">Advance Amount<span class="required"> * </span></label>
                                                <div class="col-md-4">                                                    
                                                    <input name="advance_amount" type="text" id="advance_amount" data-required="1" class="form-control" value="<?php if(isset($_POST['advance_amount']) && $_POST['advance_amount']!=''){ echo $_POST['advance_amount'];} else if($advanceAmount>0){ echo $advanceAmount; } else { echo '0';}  ?>"/>
                                                </div>
                                            </div>      
                                            <div class="form-group row">
                                                <label class="control-label col-md-3">Description</label>
                                                <div class="col-md-4">                                                    
                                                    <textarea name="description" id="description"><?php if(isset($_POST['description']) && $_POST['description']!=''){ echo $_POST['description'];}   ?></textarea>
                                                </div>
                                            </div>                             
                                            
                                        </div>
                                      <div class="form-group">
                                            <div class="offset-md-3 col-md-9">                                            	
                                            		<button type="submit" name="add" class="btn btn-info">Add</button>                                            	
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        
                        
                        <div class="col-md-12">
                            <div class="card card-topline-red">
                                <div class="card-head">
                                    <header>Advance Report</header>
                                    <div class="tools">
                                        <!--<a class="fa fa-repeat btn-color box-refresh" href="javascript:;"></a>-->
	                                    <a class="t-collapse btn-color fa fa-chevron-down" href="javascript:;"></a>
	                                    <a class="t-close btn-color fa fa-times" href="javascript:;"></a>
                                    </div>
                                </div>
                                <div class="card-body ">
                                    <div class="row p-b-20">                                        
                                        
                                    </div>  
                                    <?php if(isset($execDetails) && mysqli_num_rows($execDetails)>0) { ?>                                  
                                    <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%" id="example4">
                                        <thead>
                                            <tr>                                                                                                
                                                <!--<th> Staff Name </th>-->
                                                <th> Date </th>
                                                <th> Amount </th>
                                                <th> Advance / Return </th>
                                                <th> Description </th>                                                
                                                <th> Actions </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        	<?php                                        	
												while($resDetails = mysqli_fetch_array($execDetails)) {	
													if($resDetails['deducted']=='yes' && $resDetails['advance_return']>0){
														$type = 'Return';
														$amount = $resDetails['advance_return'];
													} else {
														$type = 'Advance';
														$amount = $resDetails['amount'];
													}
													
													?>
                                            <tr class="odd gradeX">                                                
                                                <!--<td><?php echo getStaffName($resDetails['staff_id']); ?></td>-->
                                                <td><?php echo getFormattedDate($resDetails['date']); ?></td>
                                                <td><?php echo $amount; ?></td> 
                                                <td><?php echo $type; ?></td>     
                                                <td><?php echo $resDetails['description']; ?></td>                                                                                              
                                                <td class="valigntop">
                                                    <div class="btn-group">
                                                        <button class="btn btn-xs deepPink-bgcolor dropdown-toggle no-margin" type="button" data-toggle="dropdown" aria-expanded="false"> Actions
                                                            <i class="fa fa-angle-down"></i>
                                                        </button>
                                                        <ul class="dropdown-menu pull-left" role="menu">
                                                            <!--<li>
                                                                <a href="index.php?page=add_salary&staff_id=<?php echo $resDetails['id']; ?>">
                                                                    <i class="icon-docs"></i> Edit Salary </a>
                                                            </li>-->                                                            
                                                        </ul>
                                                    </div>
                                                </td>
                                            </tr>
                                            <?php } ?>                                            
                                        </tbody>
                                    </table>
                                    <div style="float: left; width: 25%;"> <?php echo $pageNums; ?> </div>
                                    <?php } else { ?>
                                    	<div class="alert alert-danger">Sorry! No Results Found.</div>					        		
					        		<?php }	?> 
                                </div>
                            </div>               
                        
                        
                        
                    </div>
	</div>
</div>
