

<?php $__env->startSection('pageTitle', 'Vega Soft'); ?>
<?php $__env->startSection('page-content'); ?>

 <input type="hidden" id="table_settings_field" branch_id="" branch_name=""  column_heading="<?= $rows->column_heading;?>" column_width="<?= $rows->column_width;?>" column_alighn="<?= $rows->column_alighn;?>"  column_conversion="<?= $rows->column_conversion;?>" settings_row_id="<?= $id;?>" sp_date_picker="<?= $rows->sp_date_picker;?>"  header_from_date="<?=date('d-m-Y', strtotime('-7 days')); ?>"   header_till_date="<?=date('d-m-Y'); ?>"  sp_sort="<?= $rows->menu_id; ?>"  active_mn="<?= $rows->root;?>"  active_mnt="<?= $rows->menu_type;?>">

<style>
#dynamic_ajax_table_length ,.dt-buttons ,#dynamic_ajax_table_filter{
    //float: left;
}
.custom-design-modal{
max-width:70%;
}
.dt-buttons{
    height: 34px;
}

.form-group {
  margin-bottom: 1rem;
}
#emp_info tr td{
  padding:0px;
}

#adv_tbl thead tr th{
  padding:2px;
}
#adv_tbl tbody tr td{
  padding:2px;
}
#adv_tbl tfoot tr td{
  padding:2px;
}

#adv_tbl thead {
  background:#4d3b39;
  color:white;
}
#adv_tbl tfoot {
  background:#4d5b39;
  color:white;
}

#emp_table tr:hover{

  cursor:pointer;
  background:#60603f;
  color:white;
}

.td_rt{
  text-align:right;
}

</style>


<div class="page-header">
<div class="row align-items-center">
<div class="col">
<h3 class="page-title"><?= $rows->menu_name;?></h3>
</div>
<div class="col-auto float-end ms-auto">

</div>
</div>
</div>


<div class="row ">
  <div class="content row">

<div class="col-lg-4">

<div class="row">



<div class="form-group row">
<label class="col-form-label col-lg-3">Date</label>
<div class="col-lg-6">
<input class="form-control form-control-sm focusable date_cls" readonly type="text" id="entry_date" > 

</div>
</div>    
<div class="form-group row">
<label class="col-form-label col-lg-3">Employee </label>
<div class="col-lg-6">
<input class="form-control form-control-sm focusable "  type="text" id="emp_name"> 

</div>
<div class="col-lg-3">
<button type="button" class="btn-btn-sm btn-outline-danger " onclick="load_emp();"><i class="las la-search"></i></button>
</div>
</div>    
<div class="form-group row">
<label class="col-form-label col-lg-3">Amount </label>
<div class="col-lg-6">
<input class="form-control form-control-sm focusable "  type="text" id="amt" onkeypress="return isNumber(event, this.value);"> 

</div>

</div>    
<div class="form-group row">
<label class="col-form-label col-lg-3">Description </label>
<div class="col-lg-7">
<input class="form-control form-control-sm focusable "  type="text" id="desc"> 

</div>


</div>    
<div class="submit-section" style="margin-top:0px !important;">

<button type="button" id="add_btn" class="btn btn-info btn-sm" onclick="submit_form();">Save</button>
<button type="button" id="edit_btn" class="btn btn-success btn-sm" onclick="submit_form();">Edit</button>
<button type="button" class="btn btn-danger btn-sm">Reset</button>
</div>



</div>



</div>



<div class="col-lg-8 col-md-8 col-sm-8">
  <table class="table table-sm table-bordered" id="adv_tbl">
<thead>
  <tr>
<th style="width:4%;">Sl no</th>
<th>T date</th>
<th>Narration</th>
<th>Amount</th>
<th>Adjusted</th>
<th style="width:10%;">&nbsp;</th>
<th style="width:10%;">&nbsp;</th>

  </tr>

</thead>

<tbody>


</tbody>



<tfoot></tfoot>
  </table>


</div>




  </div>

</div>


</div>


<input type="hidden" id="emp_id">
<input type="hidden" id="hidden_status" value="0">
<input type="hidden" id="row_id" value="0">


<div id="emp_modal" class="modal custom-modal fade add_main_modal" role="dialog">
<div class="modal-dialog modal-dialog-centered modal-md " role="document">
<div class="modal-content">
<div class="modal-header">

<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" >
<div class="container-fluid">
<div class="col-lg-4">
  <input type="text" class="form-control form-control-sm" placeholder="Search Employee.." id="serch_tbl">
</div>

<div class="col-lg-12">

<table class="table" id="emp_table">



</table>


</div>


</div>

</div>
</div>


</div>
</div>



<?php $__env->stopSection(); ?>




<?php $__env->startSection('page-script'); ?>
<script src="<?php echo e(asset('project-js\vega-front-scripts.js')); ?>"></script>
<script type="text/javascript">
set_mn();

$("#adv_tbl").hide();


function submit_form(){
  status=0;

  if($("#emp_id").val()==""||$("#emp_id").val()==0){
    alert("No Employe Selected");
    status=1;
    return;
  }

if(status==0){
  save_form();
}

}


function load_emp(){

  $.ajax({
            type: 'POST',
             async: false,
              url: '/get_data',
              data: {
                   '_token': "<?php echo e(csrf_token()); ?>",
                  'cid':"<?php echo e(Session::get('cid')); ?>",
                   row_id: 1,
                   CID: "<?php echo e(Session::get('CID')); ?>",
            url1:'prl_load_emp.php'
              },
              error: function (request, error) {
                  alert("Please Wait, Loading...");
              },
              success: function (response) {
data=response;

$("#emp_modal").modal("show");
tr='';

$(data).each(function(key,val){
  emp_id="'"+val['emp_id']+"'";
  emp_name="'"+val['emp_name']+"'";

tr+='<tr emp_id='+emp_id+'   emp_name='+emp_name+' onclick="load_emp_adv(this)">';
tr+='<td>'+val['emp_name']+'</td>';

tr+='</tr>';




});
$("#emp_table").html(tr);
       
   
          
      
      }
        
   });

}


$(document).ready(function(){
  $("#serch_tbl").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#emp_table tr").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});





function load_emp_adv(elm){

emp_name=$(elm).attr('emp_name');
emp_id=$(elm).attr('emp_id');

$("#emp_name").val(emp_name);
$("#emp_id").val(emp_id);

$("#emp_modal").modal('hide');


load_emp_adv_detail();




}



$("#entry_date").on('change',function(){
  load_emp_adv_detail();
});





function load_emp_adv_detail(){

  $.ajax({
            type: 'POST',
             async: false,
              url: '/get_data_shdl',
              data: {
                   '_token': "<?php echo e(csrf_token()); ?>",
                  'cid':"<?php echo e(Session::get('cid')); ?>",
                   row_id: $.trim($("#entry_date").val()),
                   emp_id:$("#emp_id").val(),
                   CID: "<?php echo e(Session::get('CID')); ?>",
            url1:'prl_load_emp_advc.php'
              },
              error: function (request, error) {
                  alert("Please Wait, Loading...");
              },
              success: function (response) {
data=response;
$("#adv_tbl").fadeIn(100);

tr='';
amt=0;
adjusted=0;
total=0;
m_total=0;
$(data).each(function(key,val){
  

 
  total+=parseFloat(val['total']);
  m_total=parseFloat(val['total']);
tr+='<tr class="adv_tr_cls" flag="'+val['flag']+'">';
tr+='<td>'+val['adv_id']+'</td>';
tr+='<td class="tdate">'+val['t_date']+'</td>';
tr+='<td class="narration">'+val['narration']+'</td>';
tr+='<td class="amt td_rt">'+val['amount']+'</td>';

if(val['flag']==1){
  adjusted+=parseFloat(val['amount']);
  tr+='<td class="adjusted td_rt">'+val['amount']+'</td>';

}
else{
  amt+=parseFloat(val['amount']);
  tr+='<td class="adjusted td_rt">'+val['adjusted']+'</td>';
}


tr+='<td class="total td_rt">'+val['total']+'</td>';




tr+='<td><button class="btn btn-md btn-danger del_btn"  adv_id='+val['adv_id']+'  onclick="delete_row('+val['adv_id']+')"><i class="las la-trash"></i></button></td>';

tr+='</tr>';




});



$("#adv_tbl tbody").html(tr);
tr1='<tr><td colspan="3" style="text-align: center;">Totals</td>';

tr1+='<td class="td_rt">'+amt+'</td>';
tr1+='<td class="td_rt">'+adjusted+'</td>';
tr1+='<td class="td_rt">'+m_total+'</td>';
tr1+='<td>&nbsp;</td>';


$("#adv_tbl tfoot").html(tr1);
       
   


$(".adv_tr_cls").each(function(key,val){
if($(this).attr('flag')==1){
  $(".del_btn").hide();
}


});
          
      
      }
        
   });

}




function edit_row(elm){
  adv_id=$(elm).attr('adv_id');
  $(elm).closest('tr').remove();

$("#row_id").val(adv_id);
$('#hidden_status').val(1)

$("#entry_date").val($(elm).closest('tr').find('.tdate').text());
$("#amt").val($(elm).closest('tr').find('.amt').text());
$("#desc").val($(elm).closest('tr').find('.narration').text());



}




function delete_row(adv_id){

if(confirm('Are you sure to delete..')){
  $('#hidden_status').val('2');
  $('#row_id').val(adv_id);


  save_form();


}




}




function save_form(){



  arr={
              'cid':"<?php echo e(Session::get('cid')); ?>",
              'hidden_status':$.trim($('#hidden_status').val()),
              'row_id':$.trim($('#row_id').val()),

              'entry_date':$.trim($('#entry_date').val()),
              'amt':$.trim($('#amt').val()),
              'emp_id':$.trim($('#emp_id').val()),
              'desc':$.trim($('#desc').val()),

   
              'branch_id': "<?php echo e(Session::get('b_id')); ?>",
              'added_by':"<?php echo e(Session::get('user_id')); ?>",
              'CID':"<?php echo e(Session::get('CID')); ?>",
};




  $.ajax({
          url: "/store_data",
          type: "POST",
          data:{
             '_token': "<?php echo e(csrf_token()); ?>",
              json_data: JSON.stringify(arr),
              url1:'prl_adv_clct_save.php'
             
          },
          success:function(response){
            
            console.log(response);
            if (response) {
              alert(response['msg']);
            $("#emp_name").val('');
            $("#emp_id").val(0);
            $("#adv_tbl tbody,#adv_tbl tfoot").html('');
            $("#amt").val('');
            $("#desc").val('');
             
            }else{

            }
          },
          error: function(response) {
          }
         });

}



</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\payroll\resources\views/adv_collection.blade.php ENDPATH**/ ?>