<!-- Form -->
<div class="content-animation animated">
    <div class="row clearfix fBTitrBold ">
        <!-- Advanced Form Example With Validation -->
        <div class="row clearfix">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="card">
                    <div class="header text-center">
                        <h2 class="content-title">ثبت پذیرنده جدید</h2>
                    </div>
                    <div class="body">
                        <div class="row rtl" dir="rtl">
                            <div class="col-md-12">
                                <div class="col-md-6"></div>
                                <div class="col-md-6">

                                    <div class="dropdown">
                                        <button class="dropbtn btn btn-default btn-block">
                                            پروفایل
                                            کاربری
                                        </button>
                                        <div id="myDropdown" class="dropdown-content">
                                            <input type="text" placeholder="Search.." id="select-search-input"/>
                                            <?php
                                            $query = "SELECT ID, concat(fName,' ',lName) as name FROM `app_acceptor_profile` WHERE concat(fName,' ',lName) like '%$object%'";

                                            $array[] = array("ID" => -1, "name" => 'بدون مشخصات');
                                            $select = $DAL->Select($query);
                                            if ($select) foreach ($select as $item) $array[] = $item;
                                            foreach ($array as $record) echo '<button data-id="' . $record['ID'] . '"  class="btn btn-block btn-default waves-effect">' . $record['name'] . '</button><br>';
                                            ?>

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


                            <div class="col-md-12">
                                <div class="btn btn-lg btn-info full_width " id="google-map"
                                     style="height: 350px"></div>
                            </div>
                            <div class="col-md-12">
                                <div class="col-md-3">
                                    <input id="sName" class="effect-7 fBTitrBold" type="text" placeholder="نام محل">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-3">
                                    <select id="category" class="form-control full_width full_height"
                                            title="دسته بندی"></select>
                                </div>
                                <div class="col-md-3">
                                    <input id="placeNumber" class="effect-7 fBTitrBold" type="text"
                                           placeholder="شماره محل">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-3">
                                    <input id="sPhoto" class="effect-7 fBTitrBold" type="text"
                                           placeholder="آدرس تصویر محل">
                                    <span class="focus-border"><i></i></span>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="col-md-4">
                                    <textarea id="sAP" class="effect-7 fBTitrBold form-control full_width" type="text"
                                              placeholder="درباره محل"></textarea>
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-4">
                                    <input style="font-size: 10px" id="sLocation" class="effect-7 fBTitrBold"
                                           type="text"
                                           placeholder="موقعیت">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-4">
                                    <input id="sAddress" class="effect-7 fBTitrBold" type="text" placeholder="آدرس">
                                    <span class="focus-border"><i></i></span>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="col-md-2">
                                    <select id="province_id" class="form-control full_width full_height"
                                            title="استان"></select>
                                </div>
                                <div class="col-md-2">
                                    <select id="county_id" class="form-control full_width full_height"
                                            title="شهر"></select>
                                </div>

                                <div class="col-md-2 text-center">
                                    <button type="button" data-toggle="tooltip" data-placement="bottom"
                                            title="شروع قرار داد"
                                            class="btn btn-warning btn-lg waves-effect sStart"
                                            id="sStart"
                                            name="sStart">
                                        <i class="material-icons">perm_contact_calendar</i>
                                        <span>شروع قرار داد</span>
                                    </button>
                                </div>
                                <div class="col-md-2 text-center">
                                    <button type="button" data-toggle="tooltip" data-placement="bottom"
                                            title="پایان قرارداد"
                                            class="btn btn-warning btn-lg waves-effect sEnd"
                                            id="sEnd"
                                            name="sEnd">
                                        <i class="material-icons">perm_contact_calendar</i>
                                        <span>پایان قرارداد</span>
                                    </button>
                                </div>
                                <div class="col-md-2">
                                    <input id="sInstallments" class="effect-7 fBTitrBold full_width" type="number"
                                           min="0"
                                           value="0"
                                           placeholder="اقساط">
                                    <span class="focus-border">اقساط<i></i></span>

                                </div>
                                <div class="col-md-2">
                                    <input id="sDiscount" class="effect-7 fBTitrBold full_width" type="number" min="0"
                                           max="100"
                                           value="0"
                                           placeholder="درصد تخفیف">
                                    <span class="focus-border">درصد تخفیف<i></i></span>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="col-md-3">
                                    <input id="sSite" class="effect-7 fBTitrBold" type="text" placeholder="سایت">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-3">
                                    <input id="sInstagram" class="effect-7 fBTitrBold" type="text"
                                           placeholder="اینستاگرام">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-3">
                                    <input id="sFacebook" class="effect-7 fBTitrBold" type="text" placeholder="فیسبوک">
                                    <span class="focus-border"><i></i></span>
                                </div>
                                <div class="col-md-3">
                                    <input id="sTelegram" class="effect-7 fBTitrBold" type="text" placeholder="تلگرام">
                                    <span class="focus-border"><i></i></span>
                                </div>
                            </div>
                            <div class="col-md-12 text-center ">
                                <button class="btn btn-success action-db waves-effect">ثبت داده</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Exportable Table -->
        <div class="row clearfix text-center">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                <div class="card ">
                    <div class="header">
                        <h2>جستوجو پذیرنده</h2>
                    </div>
                    <div class="body ">
                        <div class="row">
                            <div class="col-md-12 ">
                                <div class="table-responsive text-center p-t-20 align-center no-overflow-y no-overflow-x">
                                    <table class="table table-bordered table-striped table-hover dataTable js-exportable text-center full_width"
                                           style="overflow-y: hidden">
                                        <thead>
                                        <tr>
                                            <td class="text-center">تنظیمات</td>
                                            <td class="text-center">کد پذیرنده</td>
                                            <td class="text-center">نام محل</td>
                                            <td class="text-center">نام - نام خانوادگی</td>
                                            <td class="text-center">آیدی پذیرنده</td>
                                            <td class="text-center">شماره</td>
                                        </tr>
                                        </thead>
                                        <tbody class="bordered">


                                        </tbody>
                                        <tfoot>
                                        <tr>
                                            <td class=" text-center">تنظیمات</td>
                                            <td class="text-center">کد پذیرنده</td>
                                            <td class="text-center">نام محل</td>
                                            <td class="text-center">نام - نام خانوادگی</td>
                                            <td class="text-center">آیدی پذیرنده</td>
                                            <td class="text-center">شماره</td>
                                        </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- #END# Exportable Table -->
        <!-- #END# Advanced Form Example With Validation -->
    </div>
</div>
<div class="modal fade fBTitrBold" id="defaultModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row clearfix ">
                    <div class="card">
                        <div class="header">
                            <div class="row clearfix rtl">
                                <div class="col-sm-4">
                                    <div class="form-group text-center">
                                        <button data-id="-1" type="button"
                                                class="btn add-slide-child btn-success waves-effect">اضافه
                                            کردن
                                        </button>
                                    </div>
                                </div>
                                <div class="col-sm-8">
                                    <div class="form-group">
                                        <div class="form-line">
                                            <input type="text" id="acceptor-terminal-code" class="form-control"
                                                   placeholder="کد پذیرنده"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="body">
                            <div class="col-md-12" id="preloader">
                                <div class="text-center">
                                    <div class="preloader pl-size-xl">
                                        <div class="spinner-layer center pl-deep-orange">
                                            <div class="circle-clipper left">
                                                <div class="circle"></div>
                                            </div>
                                            <div class="circle-clipper right">
                                                <div class="circle"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div id="aniimated-thumbnials" class="list-unstyled row clearfix">


                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-link waves-effect" data-dismiss="modal">بستن</button>
            </div>
        </div>
    </div>
</div>
<!-- #END# Form -->
<script type="text/javascript">

    let Province = [];
    <?php
    $select = $DAL->Select("SELECT name,id FROM province_db");

    foreach ($select as $record) {
        echo ' Province.push({id:' . $record['id'] . ', name:"' . $record['name'] . '", county:[]});' . "\n";
        $county = $DAL->Select("SELECT name,id FROM county_db WHERE province_id='{$record['id']}'");
        if ($county AND count($county) > 0) {
            foreach ($county as $count)
                echo 'Province[Province.length-1].county.push({Pid:' . $record['id'] . ',id:' . $count['id'] . ', name:"' . $count['name'] . '", city:[]});' . "\n";
        }
    }
    ?>




    let profileKey = -1, selectFunctionReset = {};
    (function ($) {

        let LoadProvince = function (province_id = -1, county_id = -1) {
            try {
                province_id = parseInt(province_id);
                county_id = parseInt(county_id);
            } catch (e) {
                province_id = -1;
                county_id = -1;
            }
            let $province = $('#province_id');

            $province.append().empty();
            for (let i = 0; i < Province.length; i += 1) {
                $province.append("<option data-index='" + i + "' value='" + Province[i].id + "' " + ((province_id === Province[i].id && province_id > 0) ? 'selected' : '') + ">" + Province[i].name + "</option>")
                if ((i === 0 && province_id === -1) || (province_id === Province[i].id && province_id > 0)) {
                    LoadCounty({id: Province[i].id, index: i}, county_id);
                }
            }

            $province.change(function () {
                let option = {id: $(this).val(), index: $(this).find('option:selected').attr("data-index")};
                LoadCounty(option);
            })

        };

        let LoadCounty = function (option, county_id = -1) {
            let $county = $('#county_id');
            if (typeof Province[option.index].county == "object" && Province[option.index].county.length > 0) {
                $county.append().empty();
                let county = Province[option.index].county;
                for (let c = 0; c < county.length; c += 1) {
                    $county.append("<option data-province='" + county[c].Pid + "' value='" + county[c].id + "' " + ((county_id > 0 && county_id === county[c].id) ? 'selected' : '') + ">" + county[c].name + "</option>")
                }
            }

        };


        let getSelectedLocation = function () {
            let $county = $('#county_id');
            let $province = $('#province_id');
            return {province: $province.find("option:selected").val(), county: $county.find("option:selected").val()};
        };

        // LoadProvince(4, 65);
        // console.log(getSelectedLocation());

        let btnprofile = {};
        let div = $('#myDropdown');
        $('.dropbtn').unbind().bind('click, tap', function (e) {
            btnprofile = $(this);
            div.toggle("show");
            div.find('button').unbind().bind('click, tap', function () {
                profileKey = $(this).attr('data-id');
                btnprofile.text($(this).text());
                div.toggle("hide");
            });
        });
        div.toggle("show");

        $('#select-search-input').unbind().bind('keyup', function () {
            let input, filter, ul, li, a, i;
            input = document.getElementById("select-search-input");
            filter = input.value.toUpperCase();
            let div = document.getElementById("myDropdown");
            a = div.getElementsByTagName("button");
            for (i = 0; i < a.length; i++) {
                txtValue = a[i].textContent || a[i].innerText;
                if (txtValue.toUpperCase().indexOf(filter) > -1) {
                    a[i].style.display = "";
                } else {
                    a[i].style.display = "none";
                }
            }
        });
        selectFunctionReset = function (key = '') {
            let label = $('.dropbtn');
            if (key === '') label.text('پروفایل کاربری');
            else {

                let buttons = $('#myDropdown').find('button'), find = false;
                buttons.each(function (e) {
                    let btn = $(this);
                    if (key === btn.attr('data-id')) {
                        label.text(btn.text());
                        profileKey = btn.attr('data-id');
                        find = true;
                    }
                });
                if (!find) {
                    profileKey = -1;
                    label.text("یافت نشد");
                }
            }
        };


        selectFunctionReset();

        /*acceptor Section*/
        let i = {
            sName: $("#sName"),
            sGuild: $("#category"),
            sNumber: $("#placeNumber"),
            sPhoto: $("#sPhoto"),
            /**********/
            sAP: $("#sAP"),
            sLocation: $("#sLocation"),
            sAddress: $("#sAddress"),
            /**********/
            sStart: $("#sStart"),
            sEnd: $("#sEnd"),
            sInstallments: $("#sInstallments"),
            sDiscount: $("#sDiscount"),
            /**********/
            sTelegram: $("#sTelegram"),
            sSite: $("#sSite"),
            sInstagram: $("#sInstagram"),
            sFacebook: $("#sFacebook")
        };

        let init = function (element = {}, object = {}, flag = true) {
            $.AdminBSB.input.activate();
            btnInsert = $('.action-db');

            element.sStart.persianDatepicker({
                element: element.sStart
            });

            element.sEnd.persianDatepicker({
                element: element.sEnd
            });

            if (!flag && object !== {}) {
                element.sName.val(object['sName']);
                element.sGuild.val(object['sGuild']);
                element.sNumber.val(object['sNumber']);
                element.sPhoto.val(object['sPhoto']);
                element.sAP.val(object['sAP']);
                element.sLocation.val(object['sLocation']);
                element.sAddress.val(object['sAddress']);
                element.sStart.find('span').text(object['sStart']);
                element.sEnd.find('span').text(object['sEnd']);
                element.sInstallments.val(object['sInstallments']);
                element.sDiscount.val(object['sDiscount']);
                element.sTelegram.val(object['sTelegram']);
                element.sSite.val(object['sSite']);
                element.sInstagram.val(object['sInstagram']);
                element.sFacebook.val(object['sFacebook']);
                btnInsert.text('ویرایش');
                LoadProvince(object['province'], object['county']);
                initGoogleMap(element.sLocation.val());
                selectFunctionReset(object['profile_id']);
                LoadGuild(object['sGuild']);
            } else {
                btnInsert.text('ثبت داده');
                LoadGuild(-1);
                LoadProvince();
            }
            btnInsert.unbind()//, click"
                .bind("tap ", function () {
                    let btn = $(this);
                    if (flag && object === {}) {
                        //insert
                        InsertDB(element);
                    } else {
                        //update
                        InsertDB(element, object.ID);
                    }
                });
        };


        /*google map*/
        let initGoogleMap = function (location = null) {
            if (Map == null) {
                Map = new google.maps.Map($('#google-map')[0], {
                    center: new google.maps.LatLng(33, 55),
                    zoom: 5
                });
                google.maps.event.addListener(Map, 'click', function (event) {
                    addMarker(event.latLng);
                });
            }

            try {
                if (location == null) {
                    moveToLocation(33, 55, 5);
                } else {
                    let loc = location.split(',');
                    if (loc.length === 2) moveToLocation(loc[0].replace("(", ''), loc[1].replace(")", ''), 5);
                }
            } catch (e) {
                console.log(e);
            }
        };

        let singleMarker, Map = null;
        let addMarker = function (latLng) {
            //if marker exists, erase marker
            if (singleMarker) {
                singleMarker.setMap(null);
            }
            $('#sLocation').val(latLng);
            singleMarker = new google.maps.Marker({
                position: latLng, //mouse click position
                map: Map,
                draggable: true,
                icon: "http://www.google.com/mapfiles/marker_green.png"
            });
        };
        let moveToLocation = function (lat, lng, zoom) {
            let center = new google.maps.LatLng(lat, lng);
            // // using global variable:
            Map.setZoom(zoom);
            Map.panTo(center);
            addMarker(center);
        };
        /*google map*/

        /*guild list*/
        let LoadGuild = function (id = -1) {
            let cat = $("#category");
            cat.append().empty();
            LoadData({
                    request: 'proxy',
                    action: 'load-category',
                    object: 'load'
                },
                null, true, function (data) {
                    for (let i = 0; i < data.length; i += 1) {
                        let item = data[i];
                        item.id = parseInt(item.id);
                        id = parseInt(id);
                        cat.append("<option value='" + item.id + "' " + (item.id === id ? "selected" : "") + " >" + item.name + "</option>")
                    }
                });
        };

        /*guild list*/
        let model = $('#defaultModal');


        //Allowed memory size of 33554432 bytes exhausted (tried to allocate 4194743 bytes
        /*public func*/
        let table = null;
        let LoadDB = function () {
            LoadData({
                    request: 'proxy',
                    action: 'acceptorController',
                    'header-type': 'load-acceptor'
                },
                null, true, function (data) {
                    ListItem = data;
                    if (table !== null)
                        table.destroy();
                    table = $('.js-exportable').DataTable({
                        "data": data,
                        "fnInfoCallback": function (oSettings, iStart, iEnd, iMax, iTotal, sPre) {
                            // FieldCounter.p4.c2.
                            $('.dataTable').find('button').unbind()//, click"
                                .bind("tap ", function () {
                                    let btn = $(this);
                                    let tr = btn.parents('tr');
                                    switch (btn.attr('data-action')) {
                                        case 'edit-item':
                                            OnEditItem(btn.attr('data-id'), btn.attr('data-index'));
                                            break;
                                        case 'delete-item':
                                            DeleteItem(btn.attr('data-id'), tr);
                                            break;
                                        case 'show-item':
                                            ActiveItem(btn, btn.attr('data-id'), btn.attr('data-value'));
                                            break;
                                        case 'acceptor-terminal':
                                            AddTerminalCode(btn.attr('data-id'));
                                            break;
                                        default:
                                            break;
                                    }
                                });
                        },
                        "columns": [
                            {"data": "button-edit"},
                            {"data": "terminal"},
                            {"data": "sName"},
                            {"data": "full-name"},
                            {"data": "acceptor-code"},
                            {"data": "counter"},
                        ],
                        responsive: true,
                        "language": {
                            "lengthMenu": "Display _MENU_ records per page",
                            "zeroRecords": " چیزی یافت نشد",
                            "info": "نمایش از _START_ تا _END_ در _TOTAL_ رکورد",
                            "infoEmpty": "<center>رکوردی پیدا نشد</center>",
                            "infoFiltered": "(filtered from _MAX_ total records)",
                            "paginate": {
                                "next": "بعدی",
                                "previous": "قبلی"
                            }
                        }
                    });
                }
            );
        };

        let LoadPreData = function (id, d) {
            LoadData({
                request: 'proxy',
                id: id,
                action: "acceptor-terminal",
                'header-type': 'load-acceptor-code'
            }, null, true, function (e) {
                $("#preloader").addClass("hidden");
                if (e.length > 0) {
                    for (let i = 0; i < e.length; i += 1) {
                        LoadItem(id, e[i].code, e[i].terminal, d);
                    }
                }
            });
        };

        let eventTerminal = function () {
            $('button.add-terminal-code').unbind().bind("tap", function (e) {
                let btn = $(this);
                let panel = $('#' + btn.attr('panel-id'));
                let terminal = prompt("ترمینال را وارد کنید");
                if (terminal.length > 0) {
                    LoadData({
                        request: 'proxy',
                        id: btn.attr('ac-id'),
                        ac: btn.attr("ac-code"),
                        at: terminal,
                        action: "acceptor-terminal",
                        'header-type': 'add-acceptor-terminal'
                    }, null, true, function (e) {
                        if (e.state === '1') {
                            panel.append(inline(e.item_id, e.terminal));
                            terminalRemoveEvent();
                            swal("ثبت شد.", "این مورد ثبت شد.", "success");
                        } else {
                            swal("خطا", "این درخواست انجام نشد", "error");
                        }
                    })
                }
            });
            $('button.remove-acceptor-code').unbind().bind('tap', function (e) {
                let btn = $(this);
                swal({
                    title: "آیا این مورد حذف شود؟",
                    text: "شما قادر به بازگردانی این مورد و ترمینال های آن نخواهید بود",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "بله حذف شود",
                    cancelButtonText: "نه حذف نشود",
                    closeOnConfirm: true,
                    closeOnCancel: true
                }, function (isConfirm) {
                    if (isConfirm) {
                        LoadData({
                            request: 'proxy',
                            id: btn.attr('ac-id'),
                            code: btn.attr('ac-code'),
                            action: "acceptor-terminal",
                            'header-type': 'remove-acceptor-code'
                        }, null, true, function (e) {
                            if (e.state === '1') {
                                $('#panel-' + btn.attr('ac-code')).fadeOut("slow", function () {
                                    swal("حذف شد", "این مورد حذف شد", "success");
                                });
                            } else {
                                swal("خطا", "این درخواست انجام نشد", "error");
                            }
                        });
                    }
                });
            });
            terminalRemoveEvent();
        };

        let AddTerminalCode = function (id) {
            model.modal('show');

            let btn = $('.add-slide-child'), input = $("#acceptor-terminal-code"), data = $("#aniimated-thumbnials");
            data.append().empty();
            btn.attr("data-id", id);
            input.val("");
            LoadPreData(id, data);
            btn.unbind().bind("tap", function (e) {
                LoadData({
                    request: 'proxy',
                    id: id,
                    ac: input.val(),
                    action: "acceptor-terminal",
                    'header-type': 'add-acceptor-code'
                }, null, true, function (e) {
                    if (e.state === '1') {
                        LoadItem(e.id, e.code, null, data);
                        swal("ثبت شد.", "این مورد ثبت شد.", "success");
                    } else {
                        swal("خطا", "این درخواست انجام نشد", "error");
                    }
                })
            });
        };

        let LoadItem = function (id, code, terminal, data) {
            let html = "";
            html += '<div class="col-sm-4" id="panel-' + code + '" dir="rtl">';
            html += '<button type="button" ac-code="' + code + '" ac-id="' + id + '" class="remove-acceptor-code btn bg-pink waves-effect col-sm-4 waves-light">X</button>';
            html += '<button class="btn bg-cyan waves-effect m-b-15 col-sm-8" type="button" data-toggle="collapse" data-target="#cd-' + code + '" aria-expanded="false" aria-controls="collapseExample">';
            html += '<span>';
            html += 'کد ' + code;
            html += '</span>';
            html += '</button>';

            html += '<div class="collapse" id="cd-' + code + '">';
            html += '<div class="well">';
            html += '<button type="button" ac-code="' + code + '" ac-id="' + id + '" class="add-terminal-code btn bg-pink waves-effect btn-block" panel-id="panel-cd-' + code + '">اضافه کردن</button>';
            html += '<div class="row m-t-10">';
            html += '<div class="list-group" id="panel-cd-' + code + '">';

            if (terminal != null)
                if (terminal.length > 0) {
                    for (let i = 0; i < terminal.length; i += 1) {
                        let t = terminal[i];
                        html += inline(t.ID, t.acceptor_terminal);
                    }
                }
            html += '</div>';
            html += '</div>';
            html += '</div>';
            html += '</div>';
            data.append(html);
            eventTerminal();
        };

        let inline = function (ID, terminal) {
            let html = '';
            html += '<div class="btn list-group-item btn-block p-b-40" id="id-' + ID + '">';
            html += '<button type="button" data-id="' + ID + '" class="btn-remove btn btn-default waves-effect pull-left">X</button>';
            html += '<p class="text-right pull-right">کد ' + terminal + '</p>';
            html += '</div>';
            return html;
        };

        let terminalRemoveEvent = function () {
            $('button.btn-remove').unbind().bind('tap', function (e) {
                let btn = $(this);
                swal({
                    title: "آیا این مورد حذف شود؟",
                    text: "شما قادر به بازگردانی ترمینال نخواهید بود",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "بله حذف شود",
                    cancelButtonText: "نه حذف نشود",
                    closeOnConfirm: true,
                    closeOnCancel: true
                }, function (isConfirm) {
                    if (isConfirm) {
                        LoadData({
                            request: 'proxy',
                            id: btn.attr('data-id'),
                            action: "acceptor-terminal",
                            'header-type': 'remove-terminal'
                        }, null, true, function (e) {
                            if (e.state === '1') {
                                $('#id-' + btn.attr('data-id')).fadeOut("slow", function () {
                                    swal("حذف شد", "این مورد حذف شد", "success");
                                });
                            } else {
                                swal("خطا", "این درخواست انجام نشد", "error");
                            }
                        });
                    }
                });
            });
        };


        let DeleteItem = function (id, tr) {
            swal({
                title: "آیا این مورد حذف شود؟",
                text: "شما قادر به بازگردانی این مورد نخواهید بود",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "بله حذف شود",
                cancelButtonText: "نه حذف نشود",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function (isConfirm) {
                if (isConfirm) {
                    LoadData({
                        request: 'proxy',
                        object: {id: id},
                        action: 'acceptorController',
                        'header-type': 'delete-acceptor'
                    }, null, false, function (data) {
                        if (data === '1') {
                            tr.fadeOut(function (e) {
                                table.row(tr)
                                    .remove()
                                    .draw();
                            });
                            swal("حذف شد", "این مورد حذف شد", "success");
                        } else {
                            swal("خطا", "این درخواست انجام نشد", "error");
                        }
                    });
                } else {
                    swal("لغو شد", "این درخواست لغو شد", "error");
                }
            });
        };
        let ActiveItem = function (btn, id, show) {
            LoadData({
                request: 'proxy',
                object: {
                    id: id,
                    show: show
                },
                action: 'acceptorController',
                'header-type': 'active-acceptor'
            }, null, false, function (data) {
                if (data === '1') {
                    btn.attr('data-value', (show === '1') ? 0 : 1);
                    btn.removeClass((show === '1') ? 'btn-warning' : 'btn-info');
                    btn.addClass((show === '0') ? 'btn-warning' : 'btn-info');
                    btn.find('i').empty().append((show === '0') ? 'visibility_off' : 'visibility');
                }
            });
        };
        let OnEditItem = function (id, index) {
            if (ListItem[index].ID === id) {
                let object = ListItem[index];
                init(i, object, false);
            } else {
                swal("خطا", "این درخواست انجام نشد", "error");
            }
        };
        let InsertDB = function (e, id = 0) {
            let mode = (id === 0 ? 'add-acceptor' : 'edit-acceptor');
            LoadData({
                    request: 'proxy',
                    object: {
                        mode: 'direct',
                        profileKey: profileKey,
                        /**********/
                        sName: e.sName.val(),
                        sGuild: e.sGuild.val(),
                        sNumber: e.sNumber.val(),
                        sPhoto: e.sPhoto.val(),
                        /********/
                        sAP: e.sAP.val(),
                        sLocation: e.sLocation.val(),
                        sAddress: e.sAddress.val(),
                        /**********/
                        sStart: e.sStart.find('span').text(),
                        sEnd: e.sEnd.find('span').text(),
                        sInstallments: e.sInstallments.val(),
                        sDiscount: e.sDiscount.val(),
                        /**********/
                        sTelegram: e.sTelegram.val(),
                        sSite: e.sSite.val(),
                        sInstagram: e.sInstagram.val(),
                        sFacebook: e.sFacebook.val(),
                        /*city system*/
                        // LoadProvince(object['province'], object['county']);
                        province: getSelectedLocation().province,
                        county: getSelectedLocation().county,
                        id: id
                    },
                    action: 'acceptorController',
                    'header-type': mode
                },
                null, false, function (data) {
                    if (data === '1') {
                        LoadDB();
                        btnInsert.text('ثبت داده');
                        swal("ثبت شد.", "این مورد ثبت شد.", "success");
                        selectFunctionReset();
                        LoadProvince();
                    } else {
                        swal("خطا", "این درخواست انجام نشد", "error");
                    }
                }
            );
        };
        /*public func*/
        init(i);
        initGoogleMap();
        LoadDB();
        /*acceptor Section*/
    }(jQuery))
</script>