<?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 tc.cid asc");
                                        $query_inq_tc = mysqli_query($_conn_db,"select * from tbl_courier as tc  where tc.doc_no='$quotation_number' and tc.action='1' order by tc.cid asc limit 1");
                                        if(mysqli_num_rows($query_inq)>0){ ?>

                                            <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>
                                                    <a href='<?php echo "$http://$host$uri/track-order?inq=";?><?php echo show_jsnj_data($quotation_number);?>' class='btn btn-success' data-container='body'><i class='demo-pli-receipt-4 btn-label'></i>Update Status</a>
                                                    <hr>
                                                    <div class="card-content">
                                                        <div class="card-body">
                                                        <div class="table-responsive">
                                                            <table class="table table-bordered">
                                 <?php while($data_inq_tc = mysqli_fetch_array($query_inq_tc)){ ?>
                                                                <tr>
                                                                    <th>Company Name</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['company_name']);?></td>
                                                                </tr>
                                     <tr>
                                         <th>Courier Type</th>
                                         <td><?php echo show_jsnj_data($data_inq_tc['type']);?></td>
                                     </tr>
                                     <tr>
                                         <th>Weight</th>
                                         <td><?php echo show_jsnj_data($data_inq_tc['weight']);?></td>
                                     </tr>
                                     <tr>
                                         <th>Invoice No</th>
                                         <td><?php echo show_jsnj_data($data_inq_tc['invice_no']);?></td>
                                     </tr>
                                     <tr>
                                         <th>Quantity</th>
                                         <td><?php echo show_jsnj_data($data_inq_tc['qty']);?></td>
                                     </tr>
                                     <tr>
                                         <th>Freight</th>
                                         <td><?php echo show_jsnj_data($data_inq_tc['freight']);?></td>
                                     </tr>
                                     <tr>
                                         <th>Pick Date</th>
                                         <td><?php echo jsnj_date_dmy($data_inq_tc['pick_date']);?></td>
                                     </tr>
                                     <tr>
                                         <th>Pick Time</th>
                                         <td><?php echo show_jsnj_data($data_inq_tc['pick_time']);?></td>
                                     </tr>
                                     <tr>
                                         <th>Book Date</th>
                                         <td><?php echo jsnj_date_dmy($data_inq_tc['book_date']);?></td>
                                     </tr>
                                                                <tr>
                                                                    <th>Ship From Name</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['ship_name']);?></td>
                                                                </tr>
                                                                <tr>
                                                                    <th>Ship From phone</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['phone']);?></td>
                                                                </tr>
                                                                <tr>
                                                                    <th>Ship From Address</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['s_add']);?></td>
                                                                </tr>
                                                                <tr>
                                                                    <th>Ship From Country/State/City/Pincode</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['s_country']);?>/<?php echo show_jsnj_data($data_inq_tc['s_state']);?>/<?php echo show_jsnj_data($data_inq_tc['s_city']);?>/<?php echo show_jsnj_data($data_inq_tc['s_pincode']);?></td>
                                                                </tr>
                                                                <tr>
                                                                    <th>Ship To Name</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['rev_name']);?></td>
                                                                </tr>
                                                                <tr>
                                                                    <th>Ship To phone</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['r_phone']);?></td>
                                                                </tr>
                                                                <tr>
                                                                    <th>Ship To Address</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['r_add']);?></td>
                                                                </tr>
                                                                <tr>
                                                                    <th>Ship From Country/State/City/Pincode</th>
                                                                    <td><?php echo show_jsnj_data($data_inq_tc['r_country']);?>/<?php echo show_jsnj_data($data_inq_tc['r_state']);?>/<?php echo show_jsnj_data($data_inq_tc['r_city']);?>/<?php echo show_jsnj_data($data_inq_tc['r_pincode']);?></td>
                                                                </tr>

                                 <?php };?>
                                                            </table>
                                                        </div>
                                                        </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)){
                                                $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;?>
                                                    <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);
                }
            });
        };
    });

    function calculation_amount(){
        var gst_percent = parseInt($('#gst_percent').val());
        var freight_charge = parseInt($('#freight_charge').val());
        var fuel_charge = parseInt($('#fuel_charge').val());
        var other_charges = parseInt($('#other_charges').val());
        var insurance_charges = parseInt($('#insurance_charges').val());
        var total = 0;
        var total_amount = 0;
        if(!freight_charge){freight_charge = 0}
        if(!fuel_charge){fuel_charge = 0}
        if(!other_charges){other_charges = 0}
        if(!insurance_charges){insurance_charges = 0}
        if(!total_amount){total_amount = 0}
        if(gst_percent !== 0){total = ((freight_charge + fuel_charge)*gst_percent)/100;}
        if(!total_amount){total_amount = freight_charge + fuel_charge + total + other_charges + insurance_charges}
        $('#gst_amount').val(total.toFixed(2));
        $('#total_amount').val(total_amount.toFixed(2));
    };
    $('.calculation_amount').keyup(function(){
        calculation_amount();
    });
    $('.calculation_amount').change(function(){
        calculation_amount();
    });
</script>
<!-- END: Body-->
</html>