    const dataUrl='http://uat.quickq-innovation.com/qq-delivery-backend';


    $(function (){
        const urlParams = new URLSearchParams(window.location.search);
        actionParam = urlParams.get('wayId');

        $.ajax({
            type: "GET",
            url: dataUrl+'/v1/delivery/detail/' + actionParam,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            crossDomain: true,
            success: function(data){
              if( data.success){
                var accessToken= data.data;
                document.title="Invoice No." + accessToken.trackingId;
                document.getElementById("lblWayID").innerHTML = "WayID: " + accessToken.trackingId;
                document.getElementById("lblInvDate").innerHTML = "Inv Date: " + moment(new Date()).format('DD/MM/YY');
                document.getElementById("lblOrderDate").innerHTML = "Order: " + moment(accessToken.createdOn).format('DD/MM/YY');
                if( accessToken.doneOn)
                    document.getElementById("lblDeliveryDate").innerHTML = "Delivery: " + moment(accessToken.doneOn).format('DD/MM/YY hh:mm a');
                else
                    document.getElementById("lblDeliveryDate").innerHTML = "Delivery:......./" + moment(new Date()).format('MM') +"/"+ moment(new Date()).format('YY');

                var pickupPerson;
                var dropOffPerson;
                var pickupAgent;
                var dropOffAgent;
                var item;
                accessToken.contacts.map( item =>{
                    if( item.contactType==="Pickup")
                        pickupPerson = item;
                    else if( item.contactType==="Drop-off")
                        dropOffPerson = item;
                    else if( item.contactType==="Drop-off Employee")
                        dropOffAgent = item;
                    else if( item.contactType==="Pickup Employee")
                        pickupAgent = item;
                });
                item = accessToken.items[0];

                document.getElementById("lblPickupCustomerName").innerHTML = "အမည်။ " + pickupPerson.name;
                document.getElementById("lblDropOffCustomerName").innerHTML = "အမည်။ " + dropOffPerson.name;
                document.getElementById("lblPickupCustomerAddress").innerHTML = "လိပ်စာ။ " + pickupPerson.address+"၊ "+ pickupPerson.street+"၊ "+ pickupPerson.township;
                document.getElementById("lblDropOffCustomerAddress").innerHTML = "လိပ်စာ။ " + dropOffPerson.address+"၊ "+ dropOffPerson.street+"၊ "+ dropOffPerson.township;
                document.getElementById("lblPickupCustomerPhone").innerHTML = "ဖုန်းနံပါတ်။ " + pickupPerson.primaryPhone;
                document.getElementById("lblDropOffCustomerPhone").innerHTML = "ဖုန်းနံပါတ်။ " + dropOffPerson.primaryPhone;
                document.getElementById("lblDeliCharges").innerHTML = item.charges.toLocaleString()+" ကျပ်";
                document.getElementById("lblSubTotal").innerHTML = item.charges.toLocaleString()+" ကျပ်";
                document.getElementById("lblPromotion").innerHTML = accessToken.promotion.toLocaleString()+" ကျပ်";
                //document.getElementById("lblPromotion").innerHTML = accessToken.promotion+" ကျပ်";
                document.getElementById("lblTotal").innerHTML = ( item.charges - accessToken.promotion ).toLocaleString() + " ကျပ်";
                document.getElementById("lblCashToCollect").innerHTML = accessToken.totalCharges.toLocaleString()+" ကျပ်";

                var refundAmount;
                if( accessToken ){
                  var itemPrice = 0;
                  var deliCharge = 0;
                  var deliChargeForShow = 0;
                  var promo = 0;
                  if( item.priceOption == 'Unpaid')
                    itemPrice = item.price? item.price : 0;

                  if( item.chargeOption == 'Paid') {
                    deliCharge = item.charges? item.charges : 0;
                  }
                  deliChargeForShow = item.forShowCharges? item.forShowCharges : 0;
                  var chargeDiff = deliChargeForShow - (item.charges? item.charges : 0);

                  promo = accessToken.promotion? accessToken.promotion : 0;
                  refundAmount = (itemPrice + promo + chargeDiff) - deliCharge;
                }

                document.getElementById("lblCashToRefund").innerHTML = refundAmount.toLocaleString()+" ကျပ်";
                if( accessToken.refundDate )
                    document.getElementById("lblRefundDate").innerHTML = moment(accessToken.refundDate).format('DD/MM/YY hh:mm a');

                if( pickupAgent ){
                    document.getElementById("lblPickupAgentName").innerHTML = pickupAgent.name+"";
                    document.getElementById("lblPickupAgentPrimaryPhone").innerHTML = pickupAgent.primaryPhone+"";
                }
                if( dropOffAgent ){
                    document.getElementById("lblDropOffAgentName").innerHTML = dropOffAgent.name+"";
                    document.getElementById("lblDropOffAgentPrimaryPhone").innerHTML = dropOffAgent.primaryPhone+"";

                }
              }
            },
            failure: function(errMsg) {
                alert(errMsg);
            }
        });
    });