@extends('layout/master2')

@section('contentchild')

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


<script>
  
$(document).ready(function(){

  $("#project_id").on('change',function(){ // you have not need to apply to delegate for dynamic content form 
   var project_id=$(this).val();
    //var selectele=$(this).closest('tr').find('.subcategory');
     //alert(project_id);


   $("#person").find('option').not(':first').remove();

         $.ajax({
           url: 'getpersonname/'+project_id,
           type: 'get',
           dataType: 'json',
           success: function(response){
//alert(response['data']);
             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].name;
                 var role = response['data'][i].role;

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

               $("#person").append(option); 
               }
             }

           }
        });
 



});


});



</script>



      <?php 
$projectlist=App\Project::all()->pluck('id','projectnm');
//dd($projectlist);
 ?>             
<div class="row justify-content-center">
   <div class="col-lg-5">
    <div class="card shadow-lg border-0 rounded-lg mt-5">
      <div class="col-sm-12">
                         <h4 class="text-center font-weight-light my-4">Create Account</h4>
                                    <form method="post" action="{{route('saveamount')}}">
@csrf
          @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

<div class="form-group">
  <label for="password">Choose Project</label>
<select class='@error('project_id') is-invalid @enderror form-control' id='project_id' name="project_id">
 <option value=''>-- Select--</option>

<?php 

//echo "<pre>";print_R($data);
foreach ($projectlist as $key=>$value) {
  echo "<option value='".$value."'>".$key."</option>"; 
}
?>

</select>
 @if ($errors->has('project_id'))
  <p class="help-block"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            {{ $errors->first('project_id') }}</p>
        @endif


     </div>

<div class="form-group">
  <label for="password">Choose Person</label>
<select class='@error('person') is-invalid @enderror form-control' name='person' id="person">
 <option value=''>-- Select--</option>

 
</select>
 @if ($errors->has('person'))
  <p class="help-block"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            {{ $errors->first('person') }}</p>
        @endif


     </div>


<div class="form-group">
  <label for="password">Amount</label>
 
<input type="text" name="amount" class='@error('amount') is-invalid @enderror form-control' />
 @if ($errors->has('amount'))
  <p class="help-block"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            {{ $errors->first('amount') }}</p>
        @endif

</div>


<div class="form-group">
  <label for="password">Date</label>
 
<input type="date" name="date" class='@error('cat_id') is-invalid @enderror form-control' />
 @if ($errors->has('date'))
  <p class="help-block"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            {{ $errors->first('date') }}</p>
        @endif

</div>


<div class="col-sm-12 text-center">
<button type="submit" name="change" class="btn btn-primary" >create</button>
</div>
</div>
 </form>
                             
        </div>
</div>
</div>


     @endsection
             