{{ header }}{{ column_left }}
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
            <div class="pull-right">
                <div class="{{ easy_visibility }} pull-right easy-mode ">
                    <img src="view/image/entegrasyon/logo.png"/>
                </div>

            </div>
            <ul class="breadcrumb">
                {% for breadcrumb in breadcrumbs %}
                    <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
                {% endfor %}
            </ul>
        </div>
    </div>
    <div class="container-fluid">{% if error_warning %}
            <div class="alert alert-danger alert-dismissible"><i
                        class="fa fa-exclamation-circle"></i> {{ error_warning }}
                <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
        {% endif %}
        {% if success %}
            <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
                <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
        {% endif %}

        <div class="row well" style="border-top: 2px solid #27ad5e;">


            <div class="col-sm-1">
                <img class="img-responsive" src="view/image/entegrasyon/bilgi.png"/>
            </div>
            <div class="col-sm-11">
                <h3 style="color:#27ad5e;font-weight: bolder ">Bilgilendirme</h3>
                <p class="" style="font-size: larger">Son 24 saat içerisinde pazaryerlerinden aldığınız siparişlerinizi
                    <strong>Siparişleri Güncelle</strong> butonuna tıklayarak mağazanıza aktarabilisiniz. Siparişleriniz
                    aktarıldığı anda sipariş verilen ürün/ürünler mağazanızda da mevcutsa, ilgili ürün/ürünler'in stoğu
                    önce mağazanızda sonra tüm pazaryerlerinde otomatik olarak güncellenir. <span class="hidden"> Dilerseniz hosting panelinizden zamanlanmış bir Cron/Job görevi oluşturarak bu işlemi belli zaman aralıklarında otomatik olarak yapabilirsiniz. Cron Job linkinize <strong>Ayarlar</strong> sayfasından ulaşabilisiniz.</span>
                </p>

            </div>
        </div>

        <div id="filter-order" class="col-md-12 col-sm-12 hidden-sm hidden-xs">
            <div class="panel panel-default" style="border-top: 2px solid #27ad5e;">
                <div class="panel-heading">
                    <h2 class="panel-title"><i class="fa fa-filter"></i> {{ text_filter }}</h2>

                </div>
                <div class="panel-body">
                    <div class="form-group col-md-4">
                        <label class="control-label" for="input-order-id">Sipariş No</label>
                        <input type="text" name="filter_order_id" value="{{ filter_order_id }}"
                               placeholder="{{ entry_order_id }}" id="input-order-id" class="form-control"/>
                    </div>
                    <div class="form-group col-md-4">
                        <label class="control-label" for="input-customer">Müşteri</label>
                        <input type="text" name="filter_customer" value="{{ filter_customer }}"
                               placeholder="{{ entry_customer }}" id="input-customer" class="form-control"/>
                    </div>
                    <div class="form-group col-md-4 ">
                        <label class="control-label" for="input-order-status">Sipariş Durumu</label>
                        <select name="filter_order_status_id" id="input-order-status" class="form-control">
                            <option value="*">Tümü</option>


                            {% for order_status in order_statuses %}
                                {% if order_status.order_status_id == filter_order_status_id %}

                                    <option value="{{ order_status.order_status_id }}"
                                            selected="selected">{{ order_status.name }}</option>

                                {% else %}

                                    <option value="{{ order_status.order_status_id }}">{{ order_status.name }}</option>

                                {% endif %}
                            {% endfor %}

                        </select>
                    </div>

                    <div class="form-group col-md-4">
                        <label class="control-label" for="input-model">Sadece Seçilen Mağazanın Siparişleri</label>

                        <select name="filter_marketplace" class="form-control">
                            <option value="*">Tümü</option>
                            {% for marketplace in marketplaces %}
                                
                                    {% if filter_marketplace==marketplace.code %}
                                        <option selected value="{{ marketplace.code }}">{{ marketplace.name }}</option>
                                    {% else %}
                                        <option value="{{ marketplace.code }}">{{ marketplace.name }}</option>

                                    {% endif %}



                            {% endfor %}


                        </select>
                    </div>
                    <div class="form-group col-md-4">
                        <label class="control-label" for="input-model">Sadece Seçilen Satıcının Siparişleri</label>

                        <select name="filter_seller" class="form-control">
                            <option value="*">Tümü</option>
                            {% for seller in sellers %}

                                {% if seller.status %}

                                    {% if filter_seller==seller.user_id %}
                                        <option selected value="{{ seller.user_id }}">{{ seller.customer }}</option>
                                    {% else %}
                                        <option value="{{ seller.user_id }}">{{ seller.customer }}</option>

                                    {% endif %}

                                {% endif %}

                            {% endfor %}


                        </select>
                    </div>

                    <div class="form-group col-md-4 {% if not efatura_status %} hidden {% endif %}  ">
                        <label class="control-label" for="input-model">Fatura durumu</label>

                        <select name="filter_invoice_status" id="input-status" class="form-control">
                            <option value="">Tümü</option>

                            {% if filter_invoice_status == '1' %}

                                <option value="1" selected="selected">Faturalandı</option>

                            {% else %}

                                <option value="1">Faturalandı</option>

                            {% endif %}
                            {% if filter_invoice_status == '2' %}

                                <option value="2" selected="selected">Faturalanmadı</option>

                            {% else %}

                                <option value="2">Faturalanmadı</option>

                            {% endif %}

                            {% if filter_invoice_status == '3' %}

                                <option value="3" selected="selected">İmzalandı</option>

                            {% else %}

                                <option value="3">İmzalandı</option>

                            {% endif %}

                            {% if filter_invoice_status == '4' %}

                                <option value="4" selected="selected">İmzalanmadı</option>

                            {% else %}

                                <option value="4">İmzalanmadı</option>

                            {% endif %}
                            {% if filter_invoice_status == '5' %}

                                <option value="5" selected="selected">Mail Gönderildi</option>

                            {% else %}

                                <option value="5">Mail Gönderildi</option>

                            {% endif %}
                            {% if filter_invoice_status == '6' %}

                                <option value="6" selected="selected">Mail Gönderilmedi</option>

                            {% else %}

                                <option value="6">Mail Gönderilmedi</option>

                            {% endif %}

                        </select>
                    </div>


                    <div class="form-group col-md-4">
                        <label class="control-label" for="input-date-added">Başlangıç Tarihi</label>
                        <div class="input-group date">
                            <input type="text" name="filter_date_added" value="{{ filter_date_added }}"
                                   placeholder="{{ entry_date_added }}" data-date-format="YYYY-MM-DD"
                                   id="input-date-added" class="form-control"/>
                            <span class="input-group-btn">
              <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
              </span></div>
                    </div>
                    <div class="form-group col-md-4">
                        <label class="control-label" for="input-date-modified">Bitiş Tarihi</label>
                        <div class="input-group date">
                            <input type="text" name="filter_date_modified" value="{{ filter_date_modified }}"
                                   placeholder="{{ entry_date_modified }}" data-date-format="YYYY-MM-DD"
                                   id="input-date-modified" class="form-control"/>
                            <span class="input-group-btn">
              <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
              </span></div>
                    </div>
                    <div class="form-group text-right">
                        <button type="button" id="button-filter" class="btn btn-default"><i
                                    class="fa fa-filter"></i> {{ button_filter }}</button>
                    </div>
                </div>
            </div>
        </div>

        <h2 class="panel-title  hidden"><i class="fa fa-list"></i> {{ text_list }}</h2>

        <div class="col-md-12 col-sm-12">
            <div class="panel panel-default" style="border-top: 2px solid #27ad5e;">

                <div class="panel-heading" style="height: 40px">


                    <div class="pull-left {% if not efatura_status %} hidden {% endif %}" style="margin-top: -9px;">


                        <div class="pull-right">
                            <div class="btn-group">
                                <button class="btn btn-default">
                                    Fatura İşlemleri
                                </button>
                                <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu pull-right">
                                    <li>
                                        <a id="btnFatura"> <i class="fa fa-file-image-o" aria-hidden="true"></i>
                                            Seçilenleri Faturala</a>
                                    </li>
                                    <li>
                                        <a id="btnFaturaSil"><i class="fa fa-trash-o" aria-hidden="true"></i>
                                            Seçilenleri Sil</a>
                                    </li>
                                    <li>
                                        <a id="btnInvoiceSync"><i class="fa fa-refresh " aria-hidden="true"></i>
                                            Senkronize Et</a>
                                    </li>    <li>
                                        <a id="btnInvoiceMail"><i class="fa fa-refresh " aria-hidden="true"></i>
                                            Mail gönder</a>
                                    </li>


                                    <li>
                                        <a id="btnFaturaLogout"><i class="fa fa-power-off" aria-hidden="true"></i>
                                            Eportaldan Çıkış Yap</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <div class="btn-group pull-right" style="margin-top: -38px;">
                    <button id="btnCheckOrder" data-toggle="tooltip" title="Yeni siparişleri kontrol et"
                            data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> " class="btn btn-primary"><i
                                class="fa fa-refresh"></i> <span class="hidden-xs"></span></button>
                    <button id="btnShipping" data-toggle="tooltip" title="KARGO ETİKETİ YAZDIR"
                            data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> " class="btn "><i
                                class="fa fa-truck"></i> <span class="hidden-xs"></span></button>
                    <!--<button id="btnBulkInfo"  style="margin-right: 10px" data-toggle="tooltip" title="Toplu Sipariş Etiketi" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Etiketler Oluşuyor" class="btn btn-info"><i class="fa fa-tags"></i> <span class="hidden-xs">Toplu Sipariş Etiketi</span></button> -->
                    <button type="button" data-toggle="tooltip" title="Seçilen Siparişleri Sil"
                            data-loading-text="<i class='fa fa-spinner fa-spin'></i> "
                            class="btnBulkDel btn btn-danger pull-right">
                        <i class="fa fa-trash-o"></i> <span class="hidden-xs"></span>
                    </button>
                </div>
            </div>
            <div class="panel-body">
                <form method="post" action="" enctype="multipart/form-data" id="form-order">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <td style="width: 1px;" class="text-center"><input type="checkbox"
                                                                                   onclick="$('input[name*=\'selected\']').prop('checked', this.checked);"/>
                                </td>
                                <td class="text-right">
                                    Sipariş No</td>
                                <td class="text-center">Mağaza</td>
                                <td class="text-center">Satıcı</td>

                                <td class="text-left">{% if sort == 'customer' %} <a href="{{ sort_customer }}"
                                                                                     class="{{ order|lower }}">{{ column_customer }}</a> {% else %}
                                        <a href="{{ sort_customer }}">Müşteri</a> {% endif %}</td>
                                <td class="col-sm-2 hidden">Şehir</td>

                                <td class="text-center">

                                    <table class="table">
                                        <tr><td>Ürün adı</td><td>Barkod</td><td>Adet</td></tr>
                                    </table>



                                </td>

                                <td class="text-right">{% if sort == 'o.total' %} <a href="{{ sort_total }}"
                                                                                     class="{{ order|lower }}">{{ column_total }}</a> {% else %}
                                        <a href="{{ sort_total }}">Toplam Fiyat</a> {% endif %}</td>
                                <td class="text-left">{% if sort == 'o.date_added' %} <a href="{{ sort_date_added }}"
                                                                                         class="{{ order|lower }}">{{ column_date_added }}</a> {% else %}
                                        <a href="{{ sort_date_added }}">Tarih</a> {% endif %}</td>
                                <td class="text-left ">{% if sort == 'order_status' %} <a href="{{ sort_status }}"
                                                                                          class="{{ order|lower }}">{{ column_status }}</a> {% else %}
                                        <a href="{{ sort_status }}">Durum</a> {% endif %}</td>

                                <td class="{% if not efatura_status %} hidden {% endif %}">Fatura</td>
                                <td class="text-right">Eylem</td>
                            </tr>
                            </thead>
                            <tbody>

                            {% if orders %}
                                {% for order in orders %}
                                    <tr id="tr{{ order.order_id }}" class="{% if order.buy and (order.order_status_id==2 or order.order_status_id==1 ) %}bg-success{% elseif order.buy==0 and (order.order_status_id==2 or order.order_status_id==1)%} bg-danger {% endif %}">
                                        <td class="text-center"> {% if order.order_id in selected %}
                                                <input type="checkbox" class="select" name="selected[]"
                                                       value="{{ order.order_id }}" checked="checked"/>
                                            {% else %}
                                                <input type="checkbox" class="select" name="selected[]"
                                                       value="{{ order.order_id }}"/>
                                            {% endif %}
                                            <input type="hidden" name="shipping_code[]"
                                                   value="{{ order.shipping_code }}"/></td>
                                        <td class="text-left">{{ order.market_order_id }}</td>
                                        <td class="text-left"><img src="{{ order.logo }}"/></td>
                                        <td class="text-left">{{ order.seller }}<br>
                                        <td class="text-left">{{ order.customer }}<br>
                                            <div class="text-small"> {% if order.payment_info.vd %} VD:{{ order.payment_info.vd }}
                                                    <br> {% endif %} {% if order.payment_info.vkn %} VKN: {{ order.payment_info.vkn }}{% endif %}{% if order.payment_info.company %}
                                                    <br></br>Firma:{{ order.payment_info.company }}{% endif %}
                                                <br>{% if order.invoice_link %}Fatura link:<a class="colorbox"
                                                                                              href="{{ order.invoice_link }}">
                                                    <i class="fa fa-external-link-square" aria-hidden="true"></i>
                                                </a>{% endif %}</div>
                                        </td>
                                        <td class="hidden">{{ order.city }}/{{ order.town }}</td>

                                        <td class="text-left">
                                            <table class="table">

                                                {% for id,product in order.ordered_products %}


                                                    <tr>
                                                        <td>{{ product.name }} <a target="_blank" class="colorbox"
                                                                                  href="{{ product.market_url }}">
                                                                <i class="fa fa-external-link-square" aria-hidden="true"></i></a></td> <td>{{ product.barcode }}<a target="_blank" class="colorbox"
                                                                                                                                                                   href="{{ product.buy_url }}">
                                                                <i class="fa fa-external-link-square" aria-hidden="true"></i></a></td> <td><label class="label label-success"> {{ product.quantity }}</label></td>
                                                    </tr>




                                                {% endfor %}
                                            </table>
                                        </td>
                                        <td class="text-right">{{ order.total }}</td>
                                        <td class="text-left">{{ order.date_added }}</td>
                                        <td class="text-left ">{{ order.order_status }}
                                            {% if order.tracking_url %}<a title="Kargo Takip" class="btn btn-info btn-block btn-sm" href="{{ order.tracking_url }}" target="_blank"><i class="fa fa-link"></i> </a> {% endif %}

                                        </td>
                                        <td class="{% if not efatura_status %} hidden {% endif %}"
                                            style="background: #fff"
                                            id="fatura_{{ order.order_id }}">{% if order.invoice_id %}<label
                                                    class="label label-success">Faturalandı</label> <br>
                                                <span> İmza: <i
                                                            class="fa {% if order.is_signed %} fa-check text-success {% else %} fa-close text-danger {% endif %}>"> </i></span>
                                                <br>
                                                <span> Mail: <i
                                                            class="fa {% if order.email_send %} fa-check text-success {% else %} fa-close text-danger {% endif %}>"> </i></span>
                                                <br>
                                                {% if order.invoice_data %}  <a target=""
                                                                                class="btn btn-primary btn-block btn-sm"
                                                                                target="_blank"
                                                                                href="index.php?route=entegrasyon/all_order/show_invoice&order_id={{ order.order_id }}&{{ token_link }}">
                                                        <i class="fa fa-download"></i></a>{% endif %}

                                            {% else %}<label class="label label-danger">Faturalanmadı</label><br>
                                            {% endif %}</td>

                                        <td class="text-right">
                                            {% if order.order_status_id==1 or order.order_status_id==2 %}
                                            <div style="min-width: 140px;">
                                                <div class="btn-group">
                                                 {% if order.buy==0 %}   <a class="btn btn-primary btnBuy" order_id="{{ order.order_id }}"><i
                                                                class="fa fa-pencil"></i> Satın Aldım</a> {% else %}


                                                     <hr>
                                        <a class="btn  btnEtiket {% if order.label_printed==0 %} btn-danger {% else %} btn-success  {% endif %} " order_id="{{ order.order_id }}"><i
                                                                 class="fa fa-truck"></i></a>

                                                     {% endif %}

                                                </div>
                                            </div>
                                            {% endif %}
                                        </td>
                                    </tr>
                                {% endfor %}
                            {% else %}
                                <tr>
                                    <td class="text-center" colspan="8">{{ text_no_results }}</td>
                                </tr>
                            {% endif %}
                            </tbody>

                        </table>
                    </div>
                </form>
                <div class="row">
                    <div class="col-sm-6 text-left">{{ pagination }}</div>
                    <div class="col-sm-6 text-right">{{ results }}</div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    $(document).on('click', '.btnBuy', function () {


        var order_id=$(this).attr('order_id');

        $.post('index.php?route=entegrasyon/all_order/buy&order_id=' + order_id + '&{{ token_link }}', {}, function (json) {


            if(json['status']){


                $('#tr'+order_id).removeClass("bg-danger");
                $('#tr'+order_id).addClass("bg-success");
                const Toast = Swal.mixin({
                    toast: true,
                    position: 'top-end',
                    showConfirmButton: false,
                    timer: 3000,
                    timerProgressBar: true,
                    didOpen: (toast) => {
                        toast.addEventListener('mouseenter', Swal.stopTimer)
                        toast.addEventListener('mouseleave', Swal.resumeTimer)
                    }
                })

                Toast.fire({
                    icon: 'success',
                    title: 'Ürün satın alındı olarak güncellendi!'
                })

            }

        },'JSON');




        })

    $(document).on('click', '.btnBulkDel', function () {
        var order_list = [];
        $('.btnBulkDel').button('loading');
        $(".table .select:checked").each(function () {
            var order_id = $(this).val();
            order_list.push(order_id);


        });
        if (order_list.length != 0) {

            deleteOrders(order_list[0], order_list);


        } else {
            $('.btnBulkDel').button('reset');
            Swal.fire('Ürün Seçmediniz');
        }


        function deleteOrders(item, pList) {


            var first_element = $("input[type='checkbox'][name='selected[]']:checked").first();
            var reference = first_element.val();


            var data = {};
            data.list = pList;

            if ($("#firstrow:checked").val()) {
                data.reference = reference;
            } else {
                data.reference = 0;
            }

            $.post('index.php?route=entegrasyon/all_order/delete_bulk&order_id=' + item + '&{{ token_link }}', data, function (json) {


                if (json['next']) {

                    deleteOrders(json['item'], json['list']);


                    const Toast = Swal.mixin({
                        toast: true,
                        position: 'top-end',
                        showConfirmButton: false,
                        timer: 3000,
                        timerProgressBar: true,
                        didOpen: (toast) => {
                            toast.addEventListener('mouseenter', Swal.stopTimer)
                            toast.addEventListener('mouseleave', Swal.resumeTimer)
                        }
                    })

                    Toast.fire({
                        icon: 'success',
                        title: 'Silindi'
                    })


                } else {
                    $('.btnBulkDel').button('reset');
                    const Toast = Swal.mixin({
                        toast: true,
                        position: 'top-end',
                        showConfirmButton: false,
                        timer: 3000,
                        timerProgressBar: true,
                        didOpen: (toast) => {
                            toast.addEventListener('mouseenter', Swal.stopTimer)
                            toast.addEventListener('mouseleave', Swal.resumeTimer)
                        }
                    })

                    Toast.fire({
                        icon: 'success',
                        title: 'Silindi'
                    })
                    Swal.fire({
                        title: 'Başarılı',
                        text: 'Seçilen Siparişler Silindi',
                        icon: 'success',
                        confirmButtonText: 'Tamam'
                    }).then((result) => {
                        if (result.value) {

                            window.location.href = 'index.php?route=entegrasyon/all_order&{{ token_link }}';

                        }
                    })

                }


            }, 'JSON');


        }


    });


</script>


<script type="text/javascript"><!--
    $('#button-filter').on('click', function () {
        url = '';

        var filter_order_id = $('input[name=\'filter_order_id\']').val();

        if (filter_order_id) {
            url += '&filter_order_id=' + encodeURIComponent(filter_order_id);
        }

        var filter_customer = $('input[name=\'filter_customer\']').val();

        if (filter_customer) {
            url += '&filter_customer=' + encodeURIComponent(filter_customer);
        }

        var filter_order_status_id = $('select[name=\'filter_order_status_id\']').val();

        if (filter_order_status_id !== '') {
            url += '&filter_order_status_id=' + encodeURIComponent(filter_order_status_id);
        }
        var filter_seller = $('select[name=\'filter_seller\']').val();

        if (filter_seller !== '') {
            url += '&filter_seller=' + encodeURIComponent(filter_seller);
        }

        var filter_marketplace = $('select[name=\'filter_marketplace\']').val();

        if (filter_marketplace) {
            url += '&filter_marketplace=' + encodeURIComponent(filter_marketplace);
        }

        var filter_invoice_status = $('select[name=\'filter_invoice_status\']').val();

        if (filter_invoice_status) {
            url += '&filter_invoice_status=' + encodeURIComponent(filter_invoice_status);
        }

        var filter_date_added = $('input[name=\'filter_date_added\']').val();

        if (filter_date_added) {
            url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
        }

        var filter_date_modified = $('input[name=\'filter_date_modified\']').val();

        if (filter_date_modified) {
            url += '&filter_date_modified=' + encodeURIComponent(filter_date_modified);
        }

        location = 'index.php?route=entegrasyon/all_order&{{ token_link }}' + url;
    });
    //--></script>
<script type="text/javascript"><!--
    $('input[name=\'filter_customer\']').autocomplete({
        'source': function (request, response) {
            $.ajax({
                url: 'index.php?route=entegrasyon/all_order/autocomplete&{{ token_link }}&filter_name=' + encodeURIComponent(request),
                dataType: 'json',
                success: function (json) {
                    response($.map(json, function (item) {
                        return {
                            label: item['name'],
                            value: item['customer_id']
                        }
                    }));
                }
            });
        },
        'select': function (item) {
            $('input[name=\'filter_customer\']').val(item['label']);
        }
    });
    //--></script>

<script src="view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<link href="view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet"
      media="screen"/>
<script type="text/javascript"><!--
    $('.date').datetimepicker({
        language: '{{ datepicker }}',
        pickTime: false
    });
    //--></script>


<script>
    $('#btnCheckOrder').on('click', function (event) {

        var $btn = $(this);
        $btn.button('loading');

        $.post('{{ catalog_url }}index.php?route=entegrasyon/update/orders', {}, function (data) {

            $btn.button('reset');
            if (data['total'] > 0) {

                Swal.fire({
                    title: 'Sipariş Kontrol',
                    text: 'Toplam' + data['total'] + ' Yeni Siparişiniz Var. Siparişler Sayfasını Yenilecenektir.',
                    icon: 'info',
                    showCancelButton: false,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Sayfayı Yenile!'
                }).then((result) => {
                    if (result.value) {

                        window.location.href = 'index.php?route=entegrasyon/all_order&{{ token_link }}';

                    }
                })

            } else {

                if (data['message']) {

                    Swal.fire({
                        title: 'Sipariş Kontrol',
                        icon: 'warning',
                        text: data['message'],
                        confirmButtonColor: '#3085d6',
                        icon: 'warning',
                        confirmButtonText: 'Tamam'
                    })

                } else {

                    Swal.fire({
                        title: 'Sipariş Kontrol',
                        icon: 'info',
                        text: 'Hiç Yeni Sipariş Yok!.',
                        confirmButtonColor: '#3085d6',
                        icon: 'success',
                        confirmButtonText: 'Sağlık Olsun!'
                    })
                }

            }


        }, 'JSON');

    })
    $('#btnInvoiceSync').on('click', function (event) {

        var $btn = $(this);
        $btn.button('loading');

        $.post('{{ catalog_url }}index.php?route=entegrasyon/efatura/sync_invoice', {}, function (data) {

            $btn.button('reset');

            if (data['status']) {

                Swal.fire({
                    title: 'Fatura Senkronizasyonu',
                    text: 'Eklenen:' + data['added'] + ' - Silinen:'+data['deleted'] + ' - Güncellenen:' + data['updated'],
                    icon: 'info',
                    showCancelButton: false,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Sayfayı Yenile!'
                }).then((result) => {
                    if (result.value) {

                        location.reload();
                        // window.location.href = 'index.php?route=entegrasyon/all_order&{{ token_link }}';

                    }
                })

            } else {


                Swal.fire({
                    title: 'Fatura Kontrol',
                    icon: 'warning',
                    text: data['message'],
                    confirmButtonColor: '#3085d6',
                    icon: 'warning',
                    confirmButtonText: 'Tamam'
                })


            }


        }, 'JSON');

    })

    $('#btnInvoiceMail').on('click', function (event) {

        var $btn = $(this);
        $btn.button('loading');

        $.post('{{ catalog_url }}index.php?route=entegrasyon/efatura/create_pdf', {}, function (data) {

            $btn.button('reset');



            Swal.fire({
                title: 'Mail Gönderimi',
                text: 'Başarılı:' + data['success'] + ' - Başarısız:'+data['fail'],
                icon: 'info',
                showCancelButton: false,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Sayfayı Yenile!'
            }).then((result) => {
                if (result.value) {

                    //location.reload();
                    // window.location.href = 'index.php?route=entegrasyon/all_order&{{ token_link }}';

                }
            })



        }, 'JSON');

    })


    $('#btnInvoiceSync').on('click', function (event) {

        var $btn = $(this);
        $btn.button('loading');

        $.post('{{ catalog_url }}index.php?route=entegrasyon/efatura/sync_invoice', {}, function (data) {

            $btn.button('reset');

            if (data['status']) {

                Swal.fire({
                    title: 'Fatura Senkronizasyonu',
                    text: 'Eklenen:' + data['added'] + ' - Silinen:'+data['deleted'] + ' - Güncellenen:' + data['updated'],
                    icon: 'info',
                    showCancelButton: false,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Sayfayı Yenile!'
                }).then((result) => {
                    if (result.value) {

                        location.reload();
                        // window.location.href = 'index.php?route=entegrasyon/all_order&{{ token_link }}';

                    }
                })

            } else {


                Swal.fire({
                    title: 'Fatura Kontrol',
                    icon: 'warning',
                    text: data['message'],
                    confirmButtonColor: '#3085d6',
                    icon: 'warning',
                    confirmButtonText: 'Tamam'
                })


            }


        }, 'JSON');

    })

</script>

<script>
    $(document).on('click', '#btnBulkInfo', function () {

        var order_list = [];
        $(".table .select:checked").each(function () {
            var order_id = $(this).val();
            order_list.push(order_id);


        });

        if (order_list.length != 0) {

            bulkInfo(order_list[0], order_list);


        } else {
            alert('Sipariş Seçmediniz');
        }

        function bulkInfo(item, pList) {

            var first_element = $("input[type='checkbox'][name='selected[]']:checked").first();
            var reference = first_element.val();


            var data = {};
            data.list = pList;

            if ($("#firstrow:checked").val()) {
                data.reference = reference;
            } else {
                data.reference = 0;
            }


            BootstrapDialog.show({
                title: 'Kargo Detayları',
                closable: true,
                size: BootstrapDialog.SIZE_WIDE,

                message: function (dialog) {
                    var $message = $('<div></div>');
                    var pageToLoad = dialog.getData('pageToLoad');
                    $message.load(pageToLoad);
                    return $message;
                },
                data: {
                    'pageToLoad': 'index.php?route=entegrasyon/all_order/bulkinfo&{{ token_link }}&data=' + pList + ''
                }
            });


        }


    });
</script>
<script>


    $('.btnEtiket ').on('click',function (event) {

        var order_list = [];

        var order_id=$(this).attr('order_id')

        order_list.push(order_id);
        printLabel('index.php?route=entegrasyon/all_order/create_barcode&{{ token_link }}&data=' + order_list + '')


    })

    $(document).on('click', '#btnShipping', function () {


        var order_list = [];
        $(".table .select:checked").each(function () {
            var order_id = $(this).val();
            order_list.push(order_id);


        });
        if (order_list.length != 0) {

            shipping(order_list[0], order_list);


        } else {
            alert('Sipariş Seçmediniz');
        }

        function shipping(item, pList) {

            var first_element = $("input[type='checkbox'][name='selected[]']:checked").first();
            var reference = first_element.val();


            var data = {};
            data.list = pList;

            if ($("#firstrow:checked").val()) {
                data.reference = reference;
            } else {
                data.reference = 0;
            }

            //   window.open('index.php?route=entegrasyon/all_order/create_barcode&{{ token_link }}&data='+pList);


            BootstrapDialog.show({
                title: 'Kargo Detayları',
                closable: true,
                size: BootstrapDialog.SIZE_WIDE,

                message: function (dialog) {
                    var $message = $('<div></div>');
                    var pageToLoad = dialog.getData('pageToLoad');
                    $message.load(pageToLoad);
                    return $message;
                },buttons: [{
                    label: 'Yazdır',
                    action: function(dialog) {
                        // dialog.getModalBody().css('background-color', '#0088cc');
                        printLabel('index.php?route=entegrasyon/all_order/create_barcode&{{ token_link }}&data=' + pList + '')
                    }
                }, {
                    label: 'Kapat',
                    action: function(dialog) {
                        dialog.close();
                    }
                }],
                data: {
                    'pageToLoad': 'index.php?route=entegrasyon/all_order/create_barcode&{{ token_link }}&data=' + pList + ''
                }
            });


        }

    })


    function printLabel(url){



        // Yeni bir iframe oluşturun
        var iframe = document.createElement("iframe");
        iframe.style.display = "none"; // Görünmez iframe

        // iframe'e harici URL'yi yükleyin
        iframe.src = url;

        // İframe sayfa yüklendiğinde yapılacak işlem
        iframe.onload = function () {
            var printWindow = iframe.contentWindow;

            // iframe içeriğini yazdırma penceresine kopyala ve yazdır
            printWindow.focus();
            printWindow.print();
        };

        // İframe'i sayfaya ekleyin
        document.body.appendChild(iframe);

        // Harici URL'den HTML içeriğini al


    }
    $(document).on('click', '#btnPrint', function () {
        var order_list = [];
        $(".table .select:checked").each(function () {
            var order_id = $(this).val();
            order_list.push(order_id);


        });
        shipping(order_list[0], order_list);

        function shipping(item, pList) {

            var first_element = $("input[type='checkbox'][name='selected[]']:checked").first();
            var reference = first_element.val();


            var data = {};
            data.list = pList;

            if ($("#firstrow:checked").val()) {
                data.reference = reference;
            } else {
                data.reference = 0;
            }

            window.open('index.php?route=entegrasyon/all_order/create_barcode&print=true&{{ token_link }}&data=' + pList);


        }
    })

</script>

<script>

    $('.view_order').on('click', function () {


        var thisBtn = $(this);

        var order_id = thisBtn.attr('order_id');

        BootstrapDialog.show({
            title: 'Sipariş Etiketi',
            closable: true,
            size: BootstrapDialog.SIZE_WIDE,

            message: function (dialog) {
                var $message = $('<div></div>');
                var pageToLoad = dialog.getData('pageToLoad');
                $message.load(pageToLoad);
                return $message;
            },
            data: {
                'pageToLoad': 'index.php?route=entegrasyon/all_order/info&{{ token_link }}&order_id=' + order_id + ''
            }
        });

    })

</script>


<script>
    $('#btnFatura').on('click', function (event) {
        var $this = $(this);
        $this.button('loading');

        var order_list = [];
        $(".table .select:checked").each(function () {
            var order_id = $(this).val();
            order_list.push(order_id);

        });


        $.post('index.php?route=entegrasyon/efatura/invoice&{{ token_link }}', {order_list: order_list}, function (json) {
            console.log(json);
            if (json['status']) {

                $.each(json['result'], function (i, item) {
                    console.log(item)
                    if (item['status']) {
                        $.toast({
                            heading: 'Başarılı',
                            text: 'Fatura bilgileri başarıyla gönderildi!',
                            position: 'top-right',
                            loader: true,
                            allowToastClose: false,
                            showHideTransition: 'slide',
                            icon: 'success'
                        });

                        $('#fatura_' + i).empty();
                        $('#fatura_' + i).html('<span class="text-success">Faturalandı</span>');

                    } else {

                        $.toast({
                            heading: 'Başarısız işlem',
                            text: item['message'],
                            position: 'top-right',
                            loader: true,
                            allowToastClose: false,
                            showHideTransition: 'slide',
                            icon: 'error'
                        });

                        // Swal.fire('Hata', json['message'], 'error');
                    }
                });

                $this.button('reset');

            } else {

                Swal.fire(
                    'Ne yazıkki birşeyler ters gitti!',
                    json['message'],
                    'warning'
                )
                $this.button('reset');


            }


        }, 'JSON');
//GEL
    });

</script>


<script>

    $('.btnBy').on('click', function (event) {

        var order_id =$(this).attr('order_id');

        $.post('index.php?route=entegrasyon/all_order/buy&{{ token_link }}', {order_id: order_id}, function (json) {

        },'JSON');

        });


</script>

<script>
    $('#btnFaturaSil').on('click', function (event) {
        var $this = $(this);
        $this.button('loading');

        var order_list = [];
        $(".table .select:checked").each(function () {
            var order_id = $(this).val();
            order_list.push(order_id);

        });


        $.post('index.php?route=entegrasyon/efatura/delete_invoice&{{ token_link }}', {order_list: order_list}, function (json) {

            if (!json['status']) {

                Swal.fire(
                    'Ne yazıkki birşeyler ters gitti!',
                    json['message'],
                    'warning'
                )
                $this.button('reset');

                return;
            }

            $.each(json['result'], function (i, item) {
                console.log(item)
                if (item['status']) {
                    $.toast({
                        heading: 'Başarılı',
                        text: item['message'],
                        position: 'top-right',
                        loader: true,
                        allowToastClose: false,
                        showHideTransition: 'slide',
                        icon: 'success'
                    });

                    $('#fatura_' + i).empty();
                    $('#fatura_' + i).html('');

                } else {

                    $.toast({
                        heading: 'Başarısız işlem',
                        text: item['message'],
                        position: 'top-right',
                        loader: true,
                        allowToastClose: false,
                        showHideTransition: 'slide',
                        icon: 'error'
                    });

                    // Swal.fire('Hata', json['message'], 'error');
                }
            });

            $this.button('reset');

        }, 'JSON');
//GEL
    });

</script>
<script>
    $('#btnFaturaLogout').on('click', function (event) {
        var $this = $(this);
        $this.button('loading');

        $.post('index.php?route=entegrasyon/efatura/logout&{{ token_link }}', {}, function (json) {

            console.log(json);
            if (json['status']) {
                $.toast({
                    heading: 'Başarılı',
                    text: 'Başarıyla Çıkış Yapıldı',
                    position: 'top-right',
                    loader: true,
                    allowToastClose: false,
                    showHideTransition: 'slide',
                    icon: 'success'
                });


            } else {

                Swal.fire('Hata', json['message'], 'error');
            }
            $this.button('reset');
        })

    });
</script>


<script>

    $('.btnEmail').on('click', function (event) {

        var order_id = $(this).attr('id');

        $.post('index.php?route=entegrasyon/efatura/send_invoice_mail&{{ token_link }}', {order_id: order_id}, function (json) {


        }, 'JSON');

    })

</script>

</div>
