
 
<?php 

 
?>
@extends('layout/master2')

@section('contentchild')
    <style>

.help-block{
  color:red;
}
.is-invalid{border:1px solid red !important;}
      </style>   

<script type="text/javascript">
  
function printData()
{
  //alert("ram");
   var divToPrint=document.getElementById("dataTable");
    divToPrint.border = 1;
        divToPrint.cellSpacing = 0;
        divToPrint.cellPadding = 2;
        divToPrint.style.borderCollapse = 'collapse';
   newWin= window.open("");

 
    newWin.document.write("<h4 align='center'>SANGYA CONSTRUCTION MANAGEMENT SYSTEM </h4>");
     newWin.document.write("<h5 align='center'>Expenses List </h5>");
      $('tr').children().eq(8).hide();
      $('table tr').find('td:eq(8)').hide();
   newWin.document.write(divToPrint.outerHTML);
   newWin.print();
    $('tr').children().eq(8).show();
    $('table tr').find('td:eq(8)').show();
   newWin.close();
}



$(document).ready(function() {
   
$(".approve").click(function(){ 
var rate=$(this).closest('tr').find(".price");
if(rate.val()!='')
{
var distance=parseInt($(this).closest('tr').find(".distance").text());
 
var id=$(this).attr("id");

$.ajax({
           url: 'approvework',
           type: 'post',
           data:{'id':id,'rate':rate.val(),'distance':distance,"_token":"{{csrf_token()}}"},
           dataType: 'json',
           success: function(response){
             reload.location();
              

           },error:function(error){

           }

  });

}else{
  alert("Enter the amount");
  $(this).closest('tr').find(".price").css("border","1px solid red");
}


});
 });




</script>

<?php
$data=App\Project::all()->pluck('id','projectnm');

?>

<div class="col-sm-12">
 
<form action="{{url('worklist')}}" method="post">
  @csrf
  <div class="card-body">
<div class="row" style="border:1px solid">

  <div class="col-sm-3" >
    <label>date</label>
   <input type="text" name="date" class="datepicker-here form-control" data-language="en"/><br/>
 </div>

 <div class="col-sm-3" >
    <label>project</label>
<select name='project_id' class="form-control">
    <option value=''>-- Select--</option>
@foreach($data as $key=>$value)
 <option value="{{ $value }}">{{ $key }}</option>
@endforeach
</select>
</div>

 
<div class="col-sm-3" >
    <label>Status</label>
<select name='is_approved' class="form-control">
    <option value=''>-- Select--</option>
    <option value="0">Pending</option>
    <option value="1">Approved</option>
    <option value="2">Disapproved</option>

</select>
</div>


<div class="col-sm-3" >
     <label>&nbsp;</label><br/> 
<input type="submit" value="Find" class="btn btn-success" />
</div>
  </div>

 </form>
</div>
 
<div class="row"><br/>
<div class="col-sm-6 text-left">
<a href="{{url('addwork')}}"  >Add work+ </a>
</div>
<div class="col-sm-6  text-right">
<button onclick="printData()" class="btn btn-primary">Print </button>
</div>
</div><br/>

 @foreach(["success","error"] as $status)
@if(Session::has($status))
<div class="alert alert-{{$status}} alert-dismissible">
  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
  <strong>{{$status}}!</strong> {{Session::get($status)}} action.
</div>
@endif
@endforeach
  <?php 
//dd($Explist);




//dd($amountlist);

  ?>     


  <div class="card mb-4">
<div class="card-header">
<i class="fas fa-table mr-1"></i>
     Amount List
</div>  
 <div class="card-body">  
<div class="table-responsive">
<table  class="table table-bordered" id="dataTable" width="100%" cellspacing="0" >
<thead>
<tr>
  
  <th>Sr No.</th> <th>Project</th> <th>Person</th> <th>Category Name</th> <th>Subcategory Name</th> <th>type</th> <th>Work</th> <th>distance</th>  <th>unit</th>   <th>Date</th><th>Amount/rate</th> <th>Action</th>
</tr>
</thead>
<tbody>
<?php $i=0; ?>
@foreach($worklist as $exp)

<tr>
  <td>{{ ++$i }}</td>

<td>{{  $exp->projectnm}}</td>
  <td>{{  $exp->name }}</td>

  <td>{{  $exp->categorynm }}</td>
  <td>{{ $exp->subcategorynm }}</td>
  <td>{{$exp->type}}</td>
  <td>{{$exp->work}}</td>
  <td class='distance'>{{$exp->distance}}</td>
  <td class='distance'>{{$exp->unit}}</td>
  <td>{{ $exp->date    }}</td>
  <td>
@if($exp->is_approved=='0')
    <input type="text" placeholder="Amount/meter" class="price" /> 
@else
   @if($exp->is_approved=='1')
{{$exp->total_amount}} / {{$exp->rate}}
@else
   <span style="color:red;">rejected</span>
  @endif
@endif
  </td>

  <td> 
  @if($exp->is_approved==0)  
   <input type="button" value="Approve" id="{{$exp->id}}" class="approve btn btn-primary btn-sm"/>  
   <a href="{{url('disapproved',['id'=>$exp->id,'work'])}}" class="btn btn-danger btn-sm">Disapprove </a>
   

   @else
   {{ ($exp->is_approved==1)?"Approved":(($exp->is_approved==2)?"Rejected":"Pending")}}
   @endif
    
  </td>

</tr>
@endforeach
</tbody>

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


     @endsection
             