<?php include_once('../function/__data_app_db.php');?>
<!DOCTYPE html>

<html class="loading" lang="en" data-textdirection="ltr">
<!-- BEGIN: Head-->
<?php include_once('head.php');?>
<!-- END: Head-->

<!-- BEGIN: Body-->
<body class="vertical-layout dark-layout 2-columns navbar-sticky footer-static pace-done menu-hide vertical-overlay-menu" data-open="click" data-menu="vertical-menu-modern" data-col="2-columns">

<!-- BEGIN: Header-->
<?php include_once('header.php');?>
<!-- END: Header-->

<!-- BEGIN: Main Menu-->
<?php include_once('sidemenu.php');?>
<!-- END: Main Menu-->

<!-- BEGIN: Content-->
<div class="app-content content">
    <div class="content-overlay"></div>
    <div class="content-wrapper">
        <div class="content-header row"></div>
        <div class="content-body">
            <section class="invoice-view-wrapper">
                <div class="row">
                    <!-- invoice view page -->
                                    <?php
                                    $quotation_number_err ='';
                                    if(isset($_GET['inq'])){
                                        $quotation_number_er = show_jsnj_data($_GET['inq']);
                                        $quotation_number_err = "<strong class='text-danger'>#$quotation_number_er</strong>";
                                    };
                                    $errorPage ='<div id="page-head">
                   <div class="text-center cls-content">
                       <h1 class="error-code text-info">Oops!</h1>
                   </div>
                </div>
                <div id="page-content">
					<!-- CONTENT -->
					<!--===================================================-->
					<div class="text-center cls-content">
					    <p class="h4 text-uppercase text-bold">Quotation '.$quotation_number_err.' Not Found!</p>
					    <div class="pad-btm">
					        Sorry, but the quotation '.$quotation_number_err.' you are looking for has not been found on our server.
					    </div>
					    <hr class="new-section-sm bord-no">
					    <div class="pad-top"><a class="btn btn-primary" href="quote-history">Return Quotation History</a></div>
					</div>
                </div>';
                                    if(isset($_GET['inq'])){
                                        $t_status = $lr_number='';
                                        $quotation_number = $inq_number = show_jsnj_data($_GET['inq']);
                                        $query_inq = mysqli_query($_conn_db,"select * from tbl_courier as tc inner join tbl_courier_track as tct on tc.doc_no = tct.doc_no where tc.doc_no='$quotation_number' and tc.action='1' order by tct.tracking_id asc");

                                        if(mysqli_num_rows($query_inq)>0){
                                            $query_inq_cid = mysqli_query($_conn_db,"select * from tbl_courier as tc inner join tbl_courier_track as tct on tc.doc_no = tct.doc_no where tc.doc_no='$quotation_number' and tc.action='1' order by tc.cid asc");
                                          $cid_q =  mysqli_fetch_array($query_inq_cid);
                                         $cid = show_jsnj_data($cid_q['cid']);
                                            ?>

                                            <div class="col-md-6">
                                                <div class="card pb-2">
                                                    <div class="card-header">
                                                        <h4 class="card-title">Tracking Details <strong class="text-success"># <?php echo $inq_number;?></strong> <br><small>Please fill all the details properly </small></h4>
                                                    </div>
                                                    <hr>
                                                    <div class="card-content">
                                                        <div class="card-body">
                                                            <form  id="data-form" action="function/insert/track-order">
                                                                <div class="row">
                                                                    <div class="col-md-6 col-xs-12 from_input">
                                                                        <div class="form-group">
                                                                            <label for="t_type">Type</label>
                                                                            <select class="form-control" name="t_type" id="t_type"><option value="Dispatch From">Dispatch From</option><option value="Arrived To">Arrived To</option><option value="Arrived At">Arrived At</option><option value="Delivered">Delivered</option></select>
                                                                        </div>
                                                                    </div>
                                                                    <div class="col-md-6 col-xs-12 from_input">
                                                                        <label for="dispatch_from"></label>
                                                                        <div class="form-group">
                                                                            <input type="text" name="dispatch_from" id="dispatch_from" class="form-control" placeholder="" required>
                                                                        </div>
                                                                    </div>
                                                                    <div class="col-md-6 col-xs-12 from_input">
                                                                        <label for="t_date">Date</label>
                                                                        <div class="form-group position-relative has-icon-left">
                                                                            <input type="text" name="t_date" id="t_date" class="form-control pickadate" placeholder="Select Date" value="<?php echo $showDatedmY;?>" required>
                                                                            <div class="form-control-position">
                                                                                <i class='bx bx-calendar'></i>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                    <div class="col-md-6 col-xs-12 from_input">
                                                                        <div class="form-group">
                                                                            <label for="status">Status</label>
                                                                            <select class="form-control calculation_amount" name="status" id="status"><option value="1">Pending</option><option value="2" selected>On The Way</option><option value="3">Dispatch</option><option value="4">Delivered</option><option value="5">Oops</option></select>
                                                                        </div>
                                                                    </div>
                                                                    <div class="col-md-12 col-xs-12 from_input">
                                                                        <label for="remark">Remark From</label>
                                                                        <div class="form-group">
                                                                            <textarea name="remark" id="remark" class="form-control"></textarea>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <input type="hidden" value="<?php echo $_SESSION['signup_token'];?>" name="tkn">
                                                                <input type="hidden" name="doc_no" value="<?php echo $quotation_number;?>">
                                                                <input type="hidden" name="c_id" value="<?php echo $cid;?>">
                                                                <hr class="mb-2">
                                                                <div class="row">
                                                                    <div class="col-md-6 offset-md-6">
                                                                        <button class="btn btn-success position-relative w-100 ladda-button submit-btn" data-style="zoom-in" type="submit" name="action"><span class="ladda-label">UPDATE TRACKING STATUS</span> <span class="ladda-spinner"></span> <i id="icon-arrow" class="bx bx-right-arrow-alt"></i></button>
                                                                    </div>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                    <div class="col-xl-6 col-md-6 col-12">
                        <div class="card">
                            <div class="card-content">
                                <div class="card-body pb-0 mx-25 p-1">
                                            <!-- header section -->
                                            <div class="row">
                                                <div class="col-xl-12 col-md-12">
                                                    <div class="row">
                                                        <div class="col-xl-4 col-md-4">
                                                            <img src="<?php echo "$http://$host$uri/../../app-assets/images/logo/avatar-s-1.png";?>" alt="invoice-logo">
                                                        </div>
                                                        <div class="col-xl-8 col-md-8 text-right pr-2">

                                                            <h3 class="text-uppercase text-thin mar-no text-primary mt-1"><small class="text-warning">Track Order</small> <a href="view-quote?inq=<?php echo $quotation_number;?>" class="text-success">#<?php echo $quotation_number;?></a></h3>
                                                            <p class="pull-right">
                                                                <strong class="text-main"><?php echo $company_name;?></strong>
                                                            </p>
                                                        </div>
                                                    </div>

                                                    <hr>
                                                </div>
                                            </div>
                                            <!-- logo and title -->

                                            <ul class="widget-timeline mb-0">
                                    <?php  while($data_inq = mysqli_fetch_array($query_inq)){
                                        $tracking_id = show_jsnj_data($data_inq['tracking_id']);
                                                $status_q = show_jsnj_data($data_inq['status']);
                                                if($status_q == 1){
                                                    $t_status = "<small class=\"timeline-time text-white badge badge-pill badge-warning\">Pending</small>";
                                                } elseif($status_q == 2){
                                                    $t_status = "<small class=\"timeline-time text-white badge badge-pill badge-info\">On The Way</small>";
                                                }elseif($status_q == 3){
                                                    $t_status = "<small class=\"timeline-time text-white badge badge-pill badge-glow\">Dispatch</small>";
                                                }elseif($status_q == 4){
                                                    $t_status = "<small class=\"timeline-time text-white badge badge-pill badge-success\">Delivered</small>";
                                                }elseif($status_q == 5){
                                                    $t_status = "<small class=\"timeline-time text-white badge badge-pill badge-danger\">Opps</small>";
                                                }
                                                $action = show_jsnj_data($data_inq['action']);
                                                $t_from = show_jsnj_data($data_inq['t_from']);
                                                $remark = show_jsnj_data($data_inq['remark']);
                                                $t_type = show_jsnj_data($data_inq['t_type']);
                                                if(!empty($remark)){
                                                    $remark = "<div class=\"timeline-content\">$remark</div>";
                                                } else {
                                                    $remark = "";
                                                }
                                                $time_t_date_time = jsnj_time_show($data_inq['t_date_time']);
                                                $t_date_time = jsnj_date_dmy($data_inq['t_date_time']);

                                            ?>
                                                <li class="timeline-items timeline-icon-primary active">
                                                    <?php echo $t_status;?> <button class="btn btn-danger waves-effect waves-light btn-sm delete" data-delete="<?php echo show_jsnj_data($tracking_id);?>">Delete</button>
                                                    <h6 class="timeline-title"><?php echo "$t_type $t_from";?></h6>
                                                    <div class="timeline-text"><?php echo $t_date_time;?></div>

                                                    <?php echo $remark;?>
                                                </li>
                                        <?php } ?></ul>
                                </div>
                            </div>
                        </div>
                    </div>
                                        <?php }else { echo $errorPage;} } else { echo $errorPage; }; ?>


                </div>
            </section>
        </div>
    </div>
</div>
<!-- END: Content-->

<!-- BEGIN: Footer-->
<?php include_once('footer.php');?>
<!-- END: Footer-->

<?php include_once('foot.php');?>

<script type="text/javascript">

    $('form').parsley();
    $('form#data-form').submit(function (e) {
        e.preventDefault();
        var action = $(this).attr('action');
        var m_form_data = new FormData(this);
        if($(this).parsley().isValid()){
            var l = Ladda.create(document.querySelector('.submit-btn'));
            l.start();
            $.ajax({
                type: "POST",
                url: action,
                data: m_form_data,
                cache: false,
                dataType:"json",
                enctype: 'multipart/form-data',
                processData: false,  // tell jQuery not to process the data
                contentType: false,   // tell jQuery not to set contentType
                success: function(data){
                   //alert(data);
                    l.stop();
                    var goTo =data.goTo;
                    var notify_type = data.notif_type;
                    var notify_title = data.notif_title;
                    var notify_desc = data.notif_desc;

                    if(data.res === 'true'){
                        $.notify({
                            // options
                            title: notify_title,
                            message: notify_desc
                        },{
                            // settings
                            type: notify_type,
                            animate: {
                                enter: 'animated bounceInDown',
                                exit: 'animated bounceOutUp'
                            },
                        });
                        location.reload();
                    } else {
                        $.notify({
                            // options
                            title: notify_title,
                            message: notify_desc
                        },{
                            // settings
                            type: notify_type,
                            animate: {
                                enter: 'animated bounceInDown',
                                exit: 'animated bounceOutUp'
                            },
                        });
                    }
                },
                error: function (jqXHR, exception) {
                    var msg = '';
                    if (jqXHR.status === 0) {
                        msg = "oops error";
                    } else if (jqXHR.status === 404) {
                        msg = "404 error";
                    } else if (jqXHR.status === 500) {
                        msg = "505 error";
                    } else if (exception === 'parsererror') {
                        msg = "error";
                    } else if (exception === 'timeout') {
                        msg = "timeout";
                    } else if (exception === 'abort') {
                        msg = "abort";
                    } else {
                        msg = "oops something want wrong"
                    }
                    l.stop();
                    alert(msg);
                }
            });
        };
    });

    $('.delete').click(function () {
        var deleteData = $(this).data('delete');
            Swal.fire({
                    title: 'Are you sure?', text: "You want to delete selected data.", type: "warning", showCancelButton: !0, confirmButtonColor: "#f44336", cancelButtonColor: "#5e5e5e", confirmButtonText: "Delete", cancelButtonText: 'Cancel', confirmButtonClass: "btn btn-danger", cancelButtonClass: "btn btn-dark ml-1", buttonsStyling: !1, allowOutsideClick: function () {
                        Swal.isLoading()
                    }
                }
            ).then(function (t) {
                    if(t.value){
                        $.ajax({
                            url: "function/deleteData",
                            method: "POST",
                            dataType: "json",
                            cache: false,
                            data: {deleteData: deleteData, for: 'track_details'},
                            success: function (res) {
                                if (res.res === 'true') {
                                    Swal.fire(res.notif_title, res.notif_disc, res.notif_type).then(function (t) { if(t.value){ location.reload(); } });
                                }else {
                                    Swal.fire('Oops', 'Something want wrong', 'warning');
                                }
                            }
                        });
                    }
                }
            );
        });
</script>
<!-- END: Body-->
</html>