@extends('adminlte::page')

@section('content')
@include('administrator.agency-type.form-add-agency-type')
<?php Fun::lang()?>
<div class="title-add">
    <div class="page-bar"> 
        <ul class="page-breadcrumb"> 
            <li> <a class="ng-binding" href="#"><i class="fa fa-dashboard"></i> Dashboard</a> </li>
            <li><a href="#">Manage Agency Type</a></li>
        </ul> 
    </div>
</div>
<div class="page">
    <div class="top-content">
        <div class="row">
            <div class="col-sm-12 col-xs-12">
                <div class="title-add">
                    <div class="pull-left">
                      <h3>Agency Type</h3>
                    </div>
                    @can('Agency-Type-Create')
                    <span class="button_success btn-circle pull-right btn-add-agency-type" style="cursor: pointer;"><i class="fa fa-plus"></i> Create New</span>
                    @endcan
                </div>

            </div>
        </div>
    </div>
    <div class="box-body table-responsive">
        <table id="datatable" class="table  table-bordered table-hover nowrap">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Agency Type</th>
                    <th>Agency Type Amount (%)</th>
                    <th>Condition Type</th>
                    <th>Percentage Type</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            @foreach($data as $key => $value)
                <tr>
                    <td>{{$value->id}}</td>
                    <td>{{$value->agency_type_name}}</td>
                    <td>{{!empty($value->agency_type_amount_get)?$value->agency_type_amount_get.' %' : ''}} </td>
                    <td>{{$value->agency_type_condition}}</td>
                    <td>{{$value->agency_type_percentage}}</td>
                    <td>
                        @can('Agency-Type-Edit')
                            <a href="{{route("agency-type.edit", $value->id)}}"><span class="button_success fa fa-edit"></span></a>
                        @endcan
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
@endsection
@section('js')
    <script type="text/javascript">
        $(document).on('click', '.btn-add-agency-type', function() {
            $('#add-agency-type').modal('show');
        });
        $(document).on('change', '#condition_com_option', function() {
            var id = $(this).find(':selected').val();
            $(".conditions").empty();
            $.ajax({
                type: 'post',
                url: "{{route('get_commission_network_condition')}}",
                dataType: 'json',
                data: {
                    "_token": "{{ csrf_token() }}",
                    "id": id,
                },
                success: function(data) {
                    $(".conditions").empty();
                    var opt = '<option>please select</option>';

                    $.each(data, function(index, value) {
                        opt = '<option value="' + value.commission + '">' + value.commission + '</option>';
                        $('.agent_condition').val(value.condition);
                    });
                    $('.conditions').append(opt);

                }
            });

        });
    </script>
@endsection


