<?php $__env->startSection('content'); ?>
                

<script>
function addrow(id)
{
  
  var table=document.getElementById(id);
  var rowcount=table.rows.length;
  var row=table.insertRow(rowcount);
  var colcount=table.rows[1].cells.length;
  //alert(colcount);
     for(var i=0;i<colcount;i++)
     {
       var newcell=row.insertCell(i);
       newcell.innerHTML=table.rows[1].cells[i].innerHTML;
     }
  
  
}


function delete_row(tid){


  var table=document.getElementById(tid);
  var rowcount=table.rows.length;
  //alert(rowcount);
   for(var i=1;i<=rowcount;i++){
     
     var chkbox=table.rows[i].cells[0].childNodes[0];
     if(chkbox!=null && chkbox.checked==true)
     {
       if(rowcount <=2)
       {
         alert("can't delete all row");
         break;
       }
       table.deleteRow(i);
       rowcount--;
       i--;
     }
  }
}


$(document).ready(function(){

  $(document.body).on('change', '.category' ,function(){ // you have not need to apply to delegate for dynamic content form 
    var catnm=($(this).children("option:selected").text()).toLowerCase();
 
 if(catnm=='other')
    {
  var selectele=($(this).closest('tr').find('.subcategory')).css("display","none");
  var type1=($(this).closest('tr').find('.type')).css("display","none");
   
   }else{
  var selectele=($(this).closest('tr').find('.subcategory')).css("display","block");
  var type1=($(this).closest('tr').find('.type')).css("display","block");

   }


   var catid=$(this).val();
    var selectele=$(this).closest('tr').find('.subcategory');

      selectele.find('option').not(':first').remove();

         $.ajax({
           url: 'getSubcategory/'+catid,
           type: 'get',
           dataType: 'json',
           success: function(response){

             var len = 0;
             if(response['data'] != null){
               len = response['data'].length;
             }

             if(len > 0){
               // Read data and create <option >
               for(var i=0; i<len; i++){

                 var id = response['data'][i].id;
                 var name = response['data'][i].subcategorynm;

                 var option = "<option value='"+id+"'>"+name+"</option>"; 

               selectele.append(option); 
               }
             }

           }
        });
 });


});

</script>

 <h3 class="text-center"><b>Add Expenses</b></h3> 

                  
<?php $__currentLoopData = ["success","error"]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<?php if(Session::has($status)): ?>
<div class="alert alert-<?php echo e($status); ?> alert-dismissible">
  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
  <strong><?php echo e($status); ?>!</strong> <?php echo e(Session::get($status)); ?> action.
</div>
<?php endif; ?>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

<form  name="chngpwd" method="post" action="<?php echo e(route('saveexpenses')); ?>" enctype="multipart/form-data">
                                  <?php echo csrf_field(); ?>
                                  <div class="col-sm-12 table-responsive" >
  <?php 
$category=App\Category::all()->pluck('id','categorynm');
//dd($category);
 ?>   

<input type="button" value="add row" onclick="addrow('tid')" class="btn btn-sm btn-success" />
<input type="button" value="delete row" onclick="delete_row('tid')" class="btn btn-sm btn-danger" /><br/><br/>
<div class="table-responsive">
<table class="table table-bordered table-striped" id="tid" >
<tr>
  <th>&nbsp;</th>
<th>Category</th>
<th>Subcategory</th>
<th>type</th>
<th>expenses Name</th>
<th>expenses Amount</th>
<th>Description</th>
<th>Attachment File</th>
</tr>

<tr>

<td><input type="checkbox" /></td>

<td>

<select  name='category[]' class="form-control category" >
<option> --Select-- </option>  
<?php $__currentLoopData = $category; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<option value="<?php echo e($value); ?>"><?php echo e($key); ?></option>

<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</select>

</td>


<td>

<select  name='subcategory[]' class="subcategory form-control subcategory" >
<option> --Select-- </option>  
 
</select>

</td>
<td>
 <select  name='type[]' class="type form-control"  >
<option> --Select-- </option>  
<option value="self"> self  </option>
<option value="rent">  rent </option>
</select> 

</td>

<td><input type='text' class="form-control" name="expenses[]" /></td>


<td><input type='text' class="form-control" name="amount[]" /></td>

<td><input type='text' class="form-control" name="description[]" /></td>
<td><input type='file' class="form-control" name="attachment[]" /></td>

</tr>

</table>
</div>
 </div>
 <div class="col-sm-4 text-center">
<button type="submit" name="change" class="btn btn-primary" >Create</button>

</div>

 </form>
                             
    <?php $__env->stopSection(); ?>
             
<?php echo $__env->make('layout/master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\sangya\resources\views/expensive.blade.php ENDPATH**/ ?>