
@extends('layouts.admin')
@section('pageTitle', 'Vega Soft')
@section('page-content')



<style>
#dynamic_ajax_table_length ,.dt-buttons ,#dynamic_ajax_table_filter{
    //float: left;
}
.custom-design-modal{
max-width:70%;
}
.dt-buttons{
    height: 34px;
}
</style>
   <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;?>">
    @if ($rows->sedp != "")
  @foreach(explode(',', $rows->sedp) as  $z=>$info) 
     @if ($info == "1" && $z==1)
       <input type="hidden" class="additional_btns" btn_icon="fa fa-pencil" btn_text="Edit" btn_click_function="call_edit_modal" btn_class="btn btn-success btn-sm btn-dtbl" col_width="30" >
     @endif 
     @if ($info == "1" && $z==2)
        <input type="hidden" class="additional_btns" btn_icon="fa fa-trash-o " btn_text="Remove" btn_click_function="call_remove_modal" btn_class="btn btn-danger btn-sm btn-dtbl" col_width="40"  >
     @endif 
     @if ($info == "1" && $z==3)
          <input type="hidden" class="additional_btns" btn_icon="fa fa-print" btn_text="Print" btn_click_function="call_print_function2" btn_class="btn btn-info btn-sm btn-dtbl" col_width="40"  >
     @endif
  @endforeach
@endif


<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">
<a href="#" class="btn add-btn" data-bs-toggle="modal" data-bs-target="#add_employee"><i class="fa fa-plus"></i>Add State</a>

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


<div class="row filter-row">




</div>

<div class="row">
<div class="col-md-12">
<div class="table-responsive" id="table_result">
    
</div>
</div>
</div>
<input type="hidden" id="hidden_status" value="0">
<input type="hidden" id="row_id" value="0">




<div id="add_employee" class="modal custom-modal fade add_main_modal" role="dialog">
<div class="modal-dialog modal-dialog-centered modal-lg custom-design-modal" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?= $rows->menu_name;?></h5>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="row">
<div class="col-sm-6">

<div class="form-group">
<label class="col-form-label">Country<span class="text-danger">*</span></label>


<select   class="form-control form-select" id="country" >
    <option value="0" selected>-Select-</option>
          @foreach($country as $cn)
  <option value="{{$cn->country_id}}">{{$cn->country_name}}</option>
  @endforeach
</select>

</div>


</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">State Name<span class="text-danger">*</span></label>
<input class="form-control focusable" autocomplete="off" type="text" id="state_name">

</div>
</div>

<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">State Code<span class="text-danger">*</span></label>
<input class="form-control focusable" autocomplete="off" type="text" id="state_code">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-form-label">State Code No<span class="text-danger">*</span></label>
<input class="form-control focusable" autocomplete="off" type="number" id="state_code_number">
</div>
</div>



<div class="submit-section">

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




@section('page-script')
<script src="{{ asset('project-js\vega-front-scripts.js')}}"></script>
<script type="text/javascript">
  /*var table = $('#dynamic_ajax_table').DataTable({
    dom: 'lBfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'colvis'
        ],
    "bLengthChange": true,
    "bSort" : true,
     "lengthMenu": [[ 20, 50,75,100, -1], [ 20, 50,75,100, "All"]],
     "pagingType": "full_numbers",
        columnDefs: [ {
            visible: false
        } ]
    
        
    });



    


$("#dynamic_ajax_table_wrapper").addClass("row");
$('#dynamic_ajax_table_length').addClass("col-lg-2 col-sm-2 col-md-2 col-2");
    $('#dynamic_ajax_table_length').after('<div id="space" class="col-lg-6 col-sm-6 col-md-6 col-6"> <div class="row filter-row"><div class="col-sm-4 col-md-4 col-lg-4  col-4">   <div class="form-group form-focus focused"><div class="cal-icon"><input class="form-control floating datetimepicker fr_date" type="text"></div><label class="focus-label">From</label></div></div><div class="col-sm-4 col-md-4 col-lg-4  col-4">   <div class="form-group form-focus focused"><div class="cal-icon"><input class="form-control floating datetimepicker to_date" type="text"></div><label class="focus-label">To</label></div></div><div class="col-sm-4 col-md-4 col-lg-4  col-4"><a href="#" class="btn btn-success btn-sm "> Load </a></div></div></div>');
$(".dt-buttons").addClass("col-lg-4 col-sm-4 col-md-4 col-4");*/

//$('#dynamic_ajax_table_length').after('<div id="space" class="col-lg-6 col-sm-6 col-md-6 col-6"> <div class="row filter-row"><div class="col-sm-4 col-md-4 col-lg-4  col-4">   <div class="form-group form-focus focused"><div class="cal-icon"><input class="form-control floating datetimepicker fr_date" type="text"></div><label class="focus-label">From</label></div></div><div class="col-sm-4 col-md-4 col-lg-4  col-4">   <div class="form-group form-focus focused"><div class="cal-icon"><input class="form-control floating datetimepicker to_date" type="text"></div><label class="focus-label">To</label></div></div><div class="col-sm-4 col-md-4 col-lg-4  col-4"><a href="#" class="btn btn-success btn-sm "> Load </a></div></div></div>');


set_mn();

fetch_view_table();


function submit_form() {
 status=0;
 if($.trim($('#country').val())==0){
    alert('Select Country');
    $('#country').focus();
    status==1;
    return;
 }
 if($.trim($('#state_name').val())==""){
    alert('Enter State Name');
    $('#state_name').focus();
    status==1;
    return;
 }
 if($.trim($('#state_code').val())==0){
    alert('Enter State Code');
    $('#state_code').focus();
    status==1;
    return;
 }
 if($.trim($('#state_code_number').val())==0){
    alert('Enter State Code No');
    $('#state_code_number').focus();
    status==1;
    return;
 }



 if (status==0) {
Save_form();
 }
}
//http://192.168.18.128/prl_api/ij/prl_branch_edit.php

function call_edit_modal(row_id) {
$('#add_btn').hide();
$('#edit_btn').show();

    $('#row_id').val(row_id);
    $('#hidden_status').val(1);
        $.ajax({
              type: 'POST',
               async: false,
                url: '/get_data',
                data: {
                     '_token': "{{ csrf_token() }}",
                    'cid':"{{ Session::get('cid')}}",
                     row_id: row_id,
              url1:'prl_state_edit.php'
                },
                error: function (request, error) {
                    alert("Please Wait, Loading...");
                },
                success: function (response) {
 datas=response.edit;

          
              $('.add_main_modal').modal('show');
            $('#country').val(datas[0]['country']); 
            $('#state_name').val(datas[0]['state_name']); 
            $('#state_code').val(datas[0]['state_code']); 
            $('#state_code_number').val(datas[0]['state_code_number']); 
   
            
       // start_focus();   
        }
          
     });  
}

  function Save_form() {
  arr={
              'cid':"{{ Session::get('cid')}}",
              'hidden_status':$.trim($('#hidden_status').val()),
              'row_id':$.trim($('#row_id').val()),

              'country':$.trim($('#country').val()),
              'state_name':$.trim($('#state_name').val()),
              'state_code':$.trim($('#state_code').val()),
              'state_code_number':$.trim($('#state_code_number').val()),
              
              'added_by':"{{ Session::get('user_id')}}",
};
           $.ajax({
          url: "/store_data",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
              json_data: JSON.stringify(arr),
              url1:'prl_state_save.php'
             
          },
          success:function(response){
            
            console.log(response);
            if (response) {
              alert(response['msg']);
            
               $('.add_main_modal').modal('hide');
               fetch_view_table();
            }else{

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

  $( ".add_main_modal" ).on('hidden.bs.modal', function(){ $('#add_btn').show();
$('#edit_btn').hide();
 $('#hidden_status').val(0);
 $('.add_main_modal .form-control').val('');
});

</script>
@endsection