@extends('adminlte::page')

@section('content')
@include('administrator.agency-close-sale.form-add-agency-close-sale')
<?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 Condition Commission Company</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>Condition Commission Company</h3>
                    </div>
                    {{--<span class="button_success btn-circle pull-right btn-add-agency-close-sale" style="cursor: pointer;"><i class="fa fa-plus"></i> Create New</span>--}}
                </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>Company Amount (%)</th>
                    <th>Condition</th>
                    <th>Percentage</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            @foreach($data as $key => $value)
                <tr>
                    <td>{{$value->id}}</td>
                    <td>{{$value->agency_company_amount_get.' %'}} </td>
                    <td>{{$value->agency_company_condition}}</td>
                    <td>{{$value->agency_company_percentage}}</td>
                    <td>
                        @can('Commission-Set-Edit')
                            <a href="{{route("admin-commission.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-close-sale', function() {
            $('#add-agency-close-sale ').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


