<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
    <div class="container-fluid " style="padding: 0px;">
        
                <div class="col-sm-12">
     <div class="panel panel-default">
                <div class="panel-body" style="padding: 10px 0px;">
        <div class="col-md-6"> 
        <form id="inputOrderIDForm">
  <div class="form-group">
    <label for="inputOrderID">Sipariş Numarası ile Arama</label>
    <input type="text" class="form-control" id="inputOrderID"  placeholder="Sipariş No giriniz.">
  </div>

  <button type="submit" class="btn btn-primary">Bul</button>
</form>
    </div>
   </div>      
        
        </div>
 </div>



<script>

$(function() {

    $("#inputOrderIDForm").submit(function(e) {
 
        e.preventDefault();
        
        var inputOrderID =  $("#inputOrderID").val();
        
        if( inputOrderID.length != 0 ) {
         
         window.location = '/ps-panel//index.php?route=sale/order/info_detail&token=<?php echo $token; ?>&order_id='+inputOrderID+'';
            
        }
        
    });

});


$(document).on('keypress',function(e) {
    if(e.which == 13) {
       $("#inputOrderIDForm").submit(); 
    }
});

</script>

        <div class="col-sm-12" style="padding: 0;">
            <div class="panel panel-default">
                <div class="panel-body" style="padding: 0px 10px;">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <td class="text-left"><?php
                                    if ($column_image == 'column_image')
                                        echo 'Resim';
                                    else
                                        echo $column_image;
                                    ?> </td>
                                <td class="text-left"><?php echo $column_pattern_image; ?></td>
                                <td class="text-left"><?php echo $column_product; ?></td>
                                <td class="text-left"><?php echo $column_model; ?></td>
                               
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($products as $product) { ?>
                                <tr>
                                    <td class="text-center">
                                        <!--<a target="_blank" href="<?php echo $product['image']; ?>"><img src="<?php echo $product['image']; ?>" width="70"/></a>-->
                                        <a target="_blank" href="<?php echo (int)$product['product_type']==11?$product['p_11_pattern_img']:$product['image']; ?>"><img src="<?php echo (int)$product['product_type']==11?$product['p_11_pattern_img']:$product['image']; ?>" width="<?php echo (int)$product['product_type']==11?30:70;?>"/></a>
                                    </td>
                                    <td class="text-center">
                                        <?php if ($product['customcase_image'] != '') { ?>
                                        <?php if((int)$product['product_type'] != 11){ ?>
                                            <img width="50" height="80" src="<?php echo $product['case_image']; ?>" alt="Frame" style="position:absolute;">
                                        <?php }?>
                                            <!--<img width="49" height="80" src="<?php echo $product['customcase_image']; ?>" alt="">-->
                                        <img width="<?php echo (int)$product['product_type']==11?52:49;?>" height="<?php echo (int)$product['product_type']==11?60:80;?>" src="<?php echo $product['customcase_image']; ?>" alt="">
                                            <?php
                                        }elseif ($product['case_order_image'] != '') {
                                            ?>
                                            <a  download href="<?php echo $product['case_order_image']; ?>"><img src="<?php echo $product['case_order_image']; ?>" width="70"/></a>
                                            <?php
                                        } else {
                                            echo '-';
                                        }
                                        ?>

                                    </td>
                                    <td class="text-left">
                                    <?php if ($product['customcase_image'] != '') { ?>
                                            <a href="<?php echo HTTPS_CATALOG . '?route=' . $product['href']; ?>"><?php echo $product['name']; ?></a>
                                            <?php } else { ?>
                                            <a target="_blank" href="<?php echo HTTPS_CATALOG . '?route=' . $product['href']; ?>"><?php echo $product['name']; ?></a>
                                    <?php }  ?>


                                        <?php foreach ($product['option'] as $option) { ?>
                                            <br />
                                        <?php if ($option['type'] != 'file') { ?>
                                                &nbsp;<small> - <?php echo $option['name']; ?>: <?php echo $option['value']; ?></small>
                                            <?php } else { ?>
                                                &nbsp;<small> - <?php echo $option['name']; ?>: <a href="<?php echo $option['href']; ?>"><?php echo $option['value']; ?></a></small>
                                            <?php } ?>
                                        <?php } ?>

                                    </td>
                                    <td class="text-left"><?php echo $product['model']; ?> x <?php echo $product['quantity']; ?></td>
                               
                                </tr>
                                <?php } ?>
                             
                        </tbody>
                    </table>
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <td style="width: 50%;" class="text-left"><?php echo $text_payment_address; ?></td>
                                <?php if ($shipping_method) { ?>
                                    <td style="width: 50%;" class="text-left"><?php echo $text_shipping_address; ?></td>
                                <?php } ?>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td class="text-left"><?php echo $payment_address; ?></td>
                                <?php if ($shipping_method) { ?>
                                    <td class="text-left"><?php echo $shipping_address; ?></td>
                                <?php } ?>
                            </tr>
                        </tbody>
                    </table>

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




        
        
        
    </div>
    <script>
        // Return Check Box Chanhe #Bilal 10/11/2020
        function returnStatusCahange(order_product_id, product_id){

            var selected_value = $("." +order_product_id + "_ option:selected").val();


            $.ajax({
                url: 'index.php?route=sale/order/changeOrderReturnStatus&order_product_id='+ order_product_id +'&order_id=<?=$order_id;?>' +'&token=<?=$token?>&selected_value=' + selected_value + '&product_id=' + product_id,
                dataType: 'json',
                type: 'POST',
                data: {},
                success: function(json){

                    $('.alert').remove();

                    if (json['error']) {
                        $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                    }

                    if (json['success']) {
                        $('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                    }


                },beforeSend: function () {
                    //$('[data-value="'+ order_id +'"]').html("<b>İşlem Yapılıyor..</b>");
                   // $("." +order_product_id + "_").after("İşlem Yapılıyor..");
                }
            });
        }
        // Return Check Box Chanhe #Bilal 10/11/2020

        $('#button-shipping_second').click(function(e){

            var conf = confirm("Bu kargo barkodu iade ve değişim işlemleri için eklenmiştir. Emin misiniz? ");

            if(conf){
                var order_id = $(this).attr('data-kargovalue');
                var firma = 'YURTICI';
                $.ajax({
                    url: 'index.php?route=sale/order/kargola_second&firma='+ firma +'&order_id='+ order_id +'&token=<?=$token?>',
                    dataType: 'json',
                    type: 'POST',
                    data: {},
                    success: function(json){
                        if(json['status'] == 1){
                            location.reload();
                        }else{
                            $('body [data-kargovalue="'+ order_id +'"]').after("Başarısız");
                        }
                    },beforeSend: function () {
                        $('[data-kargovalue="'+ order_id +'"]').html("<b>İşlem Yapılıyor..</b>");
                    }
                });
            }


        });

        $('#button-shipping').click(function(e){
            var order_id = $(this).attr('data-value');
            var firma = 'YURTICI';
            $.ajax({
                url: 'index.php?route=sale/order/kargola&firma='+ firma +'&order_id='+ order_id +'&token=<?=$token?>',
                dataType: 'json',
                type: 'POST',
                data: {},
                success: function(json){
                    if(json['status'] == 1){
                        location.reload();
                    }else{
                        $('body [data-value="'+ order_id +'"]').after("Başarısız");
                    }
                },beforeSend: function () {
                    $('[data-value="'+ order_id +'"]').html("<b>İşlem Yapılıyor..</b>");
                }
            });
        });


        // ByExpress Cargo Send

        $('#button-shipping-byexpress').click(function(e){

            var conf = confirm("Emin misiniz!");
            if(conf){
                var order_id = $(this).attr('data-value');
                $.ajax({
                    url: 'index.php?route=sale/order/byexpress&order_id='+ order_id +'&token=<?=$token?>',
                    dataType: 'json',
                    type: 'POST',
                    data: {},
                    success: function(json){
                        if(json['status'] == 1){
                            location.reload();
                        }else{
                            $('body [data-value="'+ order_id +'"]').after("Başarısız");
                            alert(json['error']);
                        }
                    },beforeSend: function () {
                        $('[data-value="'+ order_id +'"]').html("<b>İşlem Yapılıyor..</b>");
                    }
                });
            }else{
                alert("Vazgeçtiniz!");
            }


        });

        // ByExpress Cargo Send

        function deleteGenerateImage(product_id) {

            if(confirm("Silmek istediğinizden Emin misiniz?")){
                $.ajax({
                    url: '<?php echo HTTPS_CATALOG ?>index.php?route=piyerSoft/cases/deleteGenerateImage',
                    type: 'post',
                    dataType: 'json',
                    data: {order_product_id: product_id},
                    success: function (json) {
                        if(json['success'])
                            location.reload();
                        else
                            alert(json['error']);
                    }
                });
            }


        }

        function GenerateImage(pattern_code, id, product_type, product_id, order_id) {
            //alert(product_type);
            var customer_pattern_data = $('#customer_pattern_data_' + id).val();

            if(product_type == 4){
                var url = '<?php echo HTTPS_CATALOG ?>index.php?route=piyerSoft/cases/GenerateDpiImageType4';
            }else{
                var url = '<?php echo HTTPS_CATALOG ?>index.php?route=piyerSoft/cases/GenerateDpiImage';
            }


            $("#btn_generate_" + id).hide();
            $("#loading_icon_" + id).show();
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: {order_product_id: id, pattern_code: pattern_code, customer_pattern_data: customer_pattern_data, product_id: product_id, order_id:order_id},

                success: function (res) {

                    if (res.responce == 'success') {
                        $("#loading_icon_" + id).hide();
                        $("#img_download_" + id).attr("href", '<?php echo HTTPS_CATALOG ?>image/' + res.pattern_img);
                        $("#img_download_" + id).show();
                        if(res.gradient_img!=''){
                        $("#gradient_img_download_" + id).attr("href", '<?php echo HTTPS_CATALOG ?>image/' + res.gradient_img);
                        $("#gradient_img_download_" + id).show();
                        }
                    } else {
                         alert(res.responce);
                        $("#btn_generate_" + id).show();
                        $("#loading_icon_" + id).hide();
                    }

                }
            });

        }
    </script>
        <script type="text/javascript"><!--

            $(document).delegate('#button-ip-add', 'click', function () {
                $.ajax({
                    url: 'index.php?route=user/api/addip&token=<?php echo $token; ?>&api_id=<?php echo $api_id; ?>',
                    type: 'post',
                    data: 'ip=<?php echo $api_ip; ?>',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#button-ip-add').button('loading');
                    },
                    complete: function () {
                        $('#button-ip-add').button('reset');
                    },
                    success: function (json) {
                        $('.alert').remove();

                        if (json['error']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                        }

                        if (json['success']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });

            $(document).delegate('#button-invoice', 'click', function () {
                $.ajax({
                    url: 'index.php?route=sale/order/createinvoiceno&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#button-invoice').button('loading');
                    },
                    complete: function () {
                        $('#button-invoice').button('reset');
                    },
                    success: function (json) {
                        $('.alert').remove();

                        if (json['error']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
                        }

                        if (json['invoice_no']) {
                            $('#invoice').html(json['invoice_no']);

                            $('#button-invoice').replaceWith('<button disabled="disabled" class="btn btn-success btn-xs"><i class="fa fa-cog"></i></button>');
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });

            $(document).delegate('#button-reward-add', 'click', function () {
                $.ajax({
                    url: 'index.php?route=sale/order/addreward&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
                    type: 'post',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#button-reward-add').button('loading');
                    },
                    complete: function () {
                        $('#button-reward-add').button('reset');
                    },
                    success: function (json) {
                        $('.alert').remove();

                        if (json['error']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
                        }

                        if (json['success']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');

                            $('#button-reward-add').replaceWith('<button id="button-reward-remove" data-toggle="tooltip" title="<?php echo $button_reward_remove; ?>" class="btn btn-danger btn-xs"><i class="fa fa-minus-circle"></i></button>');
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });

            $(document).delegate('#button-reward-remove', 'click', function () {
                $.ajax({
                    url: 'index.php?route=sale/order/removereward&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
                    type: 'post',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#button-reward-remove').button('loading');
                    },
                    complete: function () {
                        $('#button-reward-remove').button('reset');
                    },
                    success: function (json) {
                        $('.alert').remove();

                        if (json['error']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
                        }

                        if (json['success']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');

                            $('#button-reward-remove').replaceWith('<button id="button-reward-add" data-toggle="tooltip" title="<?php echo $button_reward_add; ?>" class="btn btn-success btn-xs"><i class="fa fa-plus-circle"></i></button>');
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });

            $(document).delegate('#button-commission-add', 'click', function () {
                $.ajax({
                    url: 'index.php?route=sale/order/addcommission&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
                    type: 'post',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#button-commission-add').button('loading');
                    },
                    complete: function () {
                        $('#button-commission-add').button('reset');
                    },
                    success: function (json) {
                        $('.alert').remove();

                        if (json['error']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
                        }

                        if (json['success']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');

                            $('#button-commission-add').replaceWith('<button id="button-commission-remove" data-toggle="tooltip" title="<?php echo $button_commission_remove; ?>" class="btn btn-danger btn-xs"><i class="fa fa-minus-circle"></i></button>');
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });

            $(document).delegate('#button-commission-remove', 'click', function () {
                $.ajax({
                    url: 'index.php?route=sale/order/removecommission&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
                    type: 'post',
                    dataType: 'json',
                    beforeSend: function () {
                        $('#button-commission-remove').button('loading');
                    },
                    complete: function () {
                        $('#button-commission-remove').button('reset');
                    },
                    success: function (json) {
                        $('.alert').remove();

                        if (json['error']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
                        }

                        if (json['success']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');

                            $('#button-commission-remove').replaceWith('<button id="button-commission-add" data-toggle="tooltip" title="<?php echo $button_commission_add; ?>" class="btn btn-success btn-xs"><i class="fa fa-plus-circle"></i></button>');
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });


            $('#tab-iyzico-refund').load('index.php?route=extension/payment/iyzico_checkout_form/order&token=<?= $token; ?>&order_id=<?= $order_id; ?>');

            $('#tab-coupon-create').load('index.php?route=sale/return/returnCoupon&token=<?= $token;?>&order_id=<?=$order_id;?>');


            var token = '';

            // Login to the API
            $.ajax({
                url: '<?php echo $catalog; ?>index.php?route=api/login',
                type: 'post',
                dataType: 'json',
                data: 'key=<?php echo $api_key; ?>',
                crossDomain: true,
                success: function (json) {
                    $('.alert').remove();

                    if (json['error']) {
                        if (json['error']['key']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error']['key'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                        }

                        if (json['error']['ip']) {
                            $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error']['ip'] + ' <button type="button" id="button-ip-add" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-danger btn-xs pull-right"><i class="fa fa-plus"></i> <?php echo $button_ip_add; ?></button></div>');
                        }
                    }

                    if (json['token']) {
                        token = json['token'];
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });

            $('#history').delegate('.pagination a', 'click', function (e) {
                e.preventDefault();

                $('#history').load(this.href);
            });



            $('#history').load('index.php?route=sale/order/history&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>');

            $('#button-history').on('click', function () {

                $.ajax({
                    url: '<?php echo $catalog; ?>index.php?route=api/order/history&token=' + token + '&store_id=<?php echo $store_id; ?>&order_id=<?php echo $order_id; ?>',
                    type: 'post',
                    dataType: 'json',
                    data: 'order_status_id=' + encodeURIComponent($('select[name=\'order_status_id\']').val()) + '&notify=' + ($('input[name=\'notify\']').prop('checked') ? 1 : 0) + '&override=' + ($('input[name=\'override\']').prop('checked') ? 1 : 0) + '&append=' + ($('input[name=\'append\']').prop('checked') ? 1 : 0) + '&comment=' + encodeURIComponent($('textarea[name=\'comment\']').val()),
                    beforeSend: function () {
                        $('#button-history').button('loading');
                    },
                    complete: function () {
                        $('#button-history').button('reset');
                    },
                    success: function (json) {
                        $('.alert').remove();

                        if (json['error']) {
                            $('#history').before('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                        }

                        if (json['success']) {
                            $('#history').load('index.php?route=sale/order/history&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>');

                            $('#history').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

                            $('textarea[name=\'comment\']').val('');
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });

            /*function changeStatus() {
                var status_id = $('select[name="order_status_id"]').val();

                $('#openbay-info').remove();

                $.ajax({
                    url: 'index.php?route=extension/openbay/getorderinfo&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&status_id=' + status_id,
                    dataType: 'html',
                    success: function (html) {
                        //$('#history').after(html);
                    }
                });
            }

            function addOrderInfo() {
                var status_id = $('select[name="order_status_id"]').val();

                $.ajax({
                    url: 'index.php?route=extension/openbay/addorderinfo&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&status_id=' + status_id,
                    type: 'post',
                    dataType: 'html',
                    data: $(".openbay-data").serialize()
                });
            }*/

            $(document).ready(function () {
                changeStatus();
            });

            $('select[name="order_status_id"]').change(function () {
                changeStatus();
            });
//--></script>
    </div>


    <?php echo $footer; ?>
