@extends('backend.header')
@section('index-content')
<?php
function convertToUnicodeNumber($input) {

    $standard_numsets = array("0","1","2","3","4","5","6","7","8","9");
    $devanagari_numsets = array("०","१","२","३","४","५","६","७","८","९");
    
    return str_replace($standard_numsets, $devanagari_numsets, $input);
}
?>


<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" ></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css"  />
    <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
    <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script> -->

<section role="main" class="content-body">
    <header class="page-header">
      <h2>Allot User Form</h2>
    </header>   
    <!-- allot user code here -->
    <div class="row" id="userallotform">
        <div class="col-md-12">
            <div class="py-2" style="font-size: 20px;">
                <label>Username :</label><span id="usernameid"> &nbsp;&nbsp;&nbsp;{{$user[0]->name}}</span>
            </div>
            <form action="{{url('gramallotuser')}}" method="post" class="form-horizontal">
            @csrf
                <section class="panel">
                    <header class="panel-heading mb-3">
                        <h4 class="my-0">Subvendor allot Details</h4>
                        <div class="back-btn-div">
                            <button class="btn btn-primary back-btn" onclick="window.history.back()">Back</button>
                        </div>
                    </header>
                    <div class="row px-5">
                        <input type="hidden" class="userid" name="userid" value="{{$user[0]->id}}">
                        <div class="col-sm-3 px-2">
                            <h4>District</h4>
                            <select class="w-100 h40" id="jilla_id">
                                <option value="">District Name</option>
                                @foreach($jilladata as $j)
                                <option value="{{$j->id}}">{{$j->area_name}}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-sm-3 px-2">
                            <h4>Mandal</h4>
                            <select class="w-100 h40" id="taluka">
                             <option value="">Mandal</option>   
                            </select>
                        </div>   
                        <div class="col-sm-3 px-2">
                            <h4>Add</h4>
                            <button type="button" class="btn btn-primary mt-1" id="addallotvendor"><i class="fa fa-plus" aria-hidden="true"></i></button>
                        </div>
                    </div>
                    <div class="row px-5">
                        <div class="col-12 px-2">
                            <table border="1" id="rowallot">
                                <tr><th>S.NO</th><th>District Name</th><th>Mandal Name</th><th>Status</th><th>Delete</th></tr>
                                <?php
                                $i=0;
                                $jk=1;
                                $count=0;
                                ?>
                                @foreach($allotuser as $jkl)
                                <?php $count++; ?>
                                
                                <tr>


                                       <td>{{$count}}</td>
                                        <td class="jilla<?php echo $jk;?>"><?php echo $jillaarr[$i];?><input type="hidden" name="jilla<?php echo $jk;?>" value="{{$jkl->jilla}}"></td>
                                        <td class="taluka<?php echo $jk;?>"><?php echo $talukaarr[$i];?><input type="hidden" name="taluka<?php echo $jk;?>" value="{{$jkl->taluka}}"></td>
                          

											<?php 
                                            //dd($jkl);
											$s=$jkl->status;
											if($s=='0')
											{
											?>
											<td><a  on class="btn btn-warning statuschk" id="statuschk" data-id="{{$jkl->id}}" data-mandal_id="{{$jkl->taluka}}">inactive</a></td>
											<?php
											}else{
											?>
											<td><a  class="btn btn-success statuschk" id="statuschk" data-id="{{$jkl->id}}" data-mandal_id="{{$jkl->taluka}}">active</a></td>
											<?php
											}
											?>
                       
                                       <td>

 
                                        <button type='button' onclick="return confirm('Are you sure you want to delete');" class='btn btn-danger gramallotdelete' value="{{$jkl->id}}">x</button>

                                    </td>
                                </tr>
                                <?php
                                $i++;
                                $jk++;
                                ?>
                                @endforeach
                            </table>
                        </div>
                    </div>
                    <div class="row px-5 pb-3">
                        <div class="col-12">
                            <div>
                                <input type="hidden" id="rowcount" name="rowcount" value="<?php echo $i;?>">
                                <div class="text-right">
                                    <button type="submit" class="btn btn-success">Submit</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            </form>
        </div>
    </div>

    <!-- allot code end here-->
    <!-- end: page -->
    <!-- start: page -->
  <!--   <section class="panel">
       <header class="panel-heading">
        <h4 class="my-0">User Details</h4>
        <div class="panel-actions">
         <a href="#" class="fa fa-caret-down"></a>
         <a href="#" class="fa fa-times"></a>
     </div>
      </header>
	</section> -->
</section>


				<script type="text/javascript">
					
            $(function() {
    

    $("body").on("click",".statuschk",function(){
                         var id=$(this).data('id');
						 var mandal_id=$(this).data('mandal_id');
						 var path=$(this);
						  //alert(id); 
						$.ajax({
							url:'{{url("subvendorChangeStatus")}}/'+id+'?mandal_id='+mandal_id,
							method:'get',
							 dataType:"json",
							success:function(data)
							{
                                if(data.status=="failed"){
                                    alert('This user already exist in another mandal');
                                }else{
                                   path.text(data.status);
                                   path.attr('class',data.class_name);
                               }
								//alert(data.status);
							},	
							error:function(data)
							{
								 alert(data);
							}
						});
					});
					
				
  })
  
  
				</script>
			@stop

    