Subversion Repositories SmartDukaan

Rev

Rev 33981 | Blame | Compare with Previous | Last modification | View Log | RSS feed

var customerId;
var orderId;
$(document).on('click', ".upsale-calling", function () {
    upsalingDAshboard();
});

$(document).on('click', "#fetch-calling-data", function () {
    doAjaxRequestHandler(context + "/fetchMobileNumberForUpSale", "GET",
        function (response) {
            $('#main-content').html(response);
        });
});

$(document).on('click', ".generatePlanModel", function () {
    const data = {
        orderId: $(this).data("orderid"),
        orderItemId: $(this).data("orderitemid"),
        planName: $(this).data("planname"),
        planId: $(this).data("planid"),
        productDescription: $(this).data("description"),
        amount: $(this).data("premium"),
        mobile: $(this).data('mobile'),
        customerName: $(this).data('customername'), // Fixed typo: 'cutsomername' to 'customername'
        customerEmail: $(this).data('customeremail'), // Fixed typo: 'cutsomeremail' to 'customeremail'
        serialNumber: $(this).data('serialnumber'),
    };

    geneartePlanDetail(data);
});

$(document).on('click', ".payment-link-mk", function () {
    // Prompt the user for confirmation
    const userConfirmed = confirm("Are you sure you want to generate and send the payment link?");

    if (userConfirmed) {
        $(".create-insurance-mk").show();
        const data = {
            orderId: $('.order-id').val(),
            orderItemId: $('.order-item-id').val(),
            planName: $('.insurance-plan-name').val(),
            planId: $('.insurance-id').val(),
            productDescription: $('.insurance-description').val(),
            amount: $('.insurance-amount').val(),
            mobile: $('.customer-mobile-number').val(),
            customerName: $('.customer-first-name').val(),
            customerEmail: $('.customer-email-id').val(),
            serialNumber: $('.customer-serial-number').val(),
        };

        doPostAjaxRequestWithJsonHandler(
            `${context}/generatePaymentLink`,
            JSON.stringify(data),
            function (response) {
                if (response.response) {
                    alert('Payment link generated and sent successfully');
                } else {
                    alert("Something went wrong");
                }
            }
        );
    } else {
        alert("Payment link generation cancelled.");
    }
});


function geneartePlanDetail(data) {
    doPostAjaxRequestWithJsonHandler(`${context}/generatePlanDetail`, JSON.stringify(data), function (response) {
        //handle response here
        $("#generatePlanModel").modal('show'); // Show the modal
        $('#generatePlanModel #generatePlanBody').html(response);
        $(".serial-number-input").val(data.serialNumber);
    });
}

function upsalingDAshboard() {
    doAjaxRequestHandler(context + "/upsaleProductslist", "GET",
        function (response) {
            $('#main-content').html(response);
            $(".disposition-button-mk").hide();
        });
}


$(document).on('click', '.create-insurance-mk', function () {
    // Gather input values
    const customerEmail = $('.customerEmail').val();
    const serialNumber = $('.serial-number').val();
    const fofoOrderId = $('.order-id').val();
    const fofoOrderItemId = $('.order-item-id').val();
    const insuranceId = $('.insurance-id').val();
    const insdp = $('.insurance-dp').val();
    const premium = $('.insurance-premium').val();
    const insuranceAmount = $('.insurance-amount').val();
    const memory = $('.memory').val();
    const ram = $('.ram').val();
    const wmfgDate = $('.wmfgDate').val();
    const gender = $('.gender').val();
    const dob = $('.dob').val();

    // Validate required fields
    let missingFields = [];

    if (!customerEmail) missingFields.push('Customer Email');
    if (!serialNumber) missingFields.push('Serial Number');
    if (!memory) missingFields.push('Memory');
    if (!ram) missingFields.push('Ram');
    if (!wmfgDate) missingFields.push('MFG Date');
    if (!gender) missingFields.push('Gender');
    if (!dob) missingFields.push('DOB');

    if (missingFields.length > 0) {
        alert('The following fields are required: ' + missingFields.join(', '));
        return;
    }


    // List of payment options
    const paymentOptions = [
        {paymentOptionId: 29, paymentOption: "BENOW"},
        {paymentOptionId: 28, paymentOption: "AMAZON PAY"},
        {paymentOptionId: 27, paymentOption: "MOBIKWIK"},
        {paymentOptionId: 26, paymentOption: "CLEVERPE"},
        {paymentOptionId: 25, paymentOption: "PAYTAIL"},
        {paymentOptionId: 24, paymentOption: "TVS"},
        {paymentOptionId: 23, paymentOption: "ONLINE"},
        {paymentOptionId: 22, paymentOption: "SAMSUNG SURE"},
        {paymentOptionId: 20, paymentOption: "ACCOUNT TRANSFER"},
        {paymentOptionId: 19, paymentOption: "UPI PAYMENT"},
        {paymentOptionId: 18, paymentOption: "MOBILE PLANET"},
        {paymentOptionId: 17, paymentOption: "HDFC PAPER FINANCE"},
        {paymentOptionId: 16, paymentOption: "HDB"},
        {paymentOptionId: 15, paymentOption: "IDFC (CF)"},
        {paymentOptionId: 14, paymentOption: "ZEST MONEY"},
        {paymentOptionId: 13, paymentOption: "HOME CREDIT"},
        {paymentOptionId: 10, paymentOption: "BAJAJ FINSERV"},
        {paymentOptionId: 7, paymentOption: "PAYTM"},
        {paymentOptionId: 4, paymentOption: "PINELABS"},
        {paymentOptionId: 1, paymentOption: "CASH"}
    ];

    // Set amounts for payment options
    paymentOptions.forEach(option => {
        option.amount = option.paymentOption === "ONLINE" ? insuranceAmount : 0;
    });

    // Create the object
    const data = {
        customerEmail: customerEmail,
        serialNumber: serialNumber,
        fofoOrderId: fofoOrderId,
        fofoOrderItemId: fofoOrderItemId,
        insuranceId: insuranceId,
        insdp: insdp,
        premium: premium,
        insuranceAmount: insuranceAmount,
        memory: memory,
        ram: ram,
        wmfgDate: wmfgDate,
        gender: gender,
        dob: dob,
        paymentOptions: paymentOptions
    };

    doPostAjaxRequestWithJsonHandler(
        `${context}/create-insurance`, JSON.stringify(data), function (response) {
            if (response.responseStatus == 'SUCCESS') {
                alert("Insurance created successfully");
                $('#generatePlanModel').modal('hide');

                // Remove the backdrop
                $('.modal-backdrop').remove();
                // upsalingDAshboard();
            }

        });
});

$(document).on('click', 'button.btn-add-new-address', function () {
    // Gather input values
    const firstName = $('#addFirstName').val();
    const lastName = $('#addLastName').val();
    const alternatePhone = $('#addAlternatePhone').val();
    const line1 = $('#addLine1').val();
    const line2 = $('#addLine2').val();
    const landmark = $('#addLandmark').val();
    const pinCode = $('#addPinCode').val();
    const city = $('#addCity').val();
    const state = $('select[name=state] option:selected').val();

    // Validate required fields
    let missingFields = [];

    if (!firstName) missingFields.push('First Name');
    if (!line1) missingFields.push('Address Line 1');
    if (!state) missingFields.push('State');
    if (!city) missingFields.push('City');
    if (!pinCode) missingFields.push('Pin Code');
    if (!alternatePhone) missingFields.push('Mobile Number');

    if (missingFields.length > 0) {
        alert('The following fields are required: ' + missingFields.join(', '));
        return;
    }

    // Create the customerAddress object
    const customerAddress = {
        name: firstName,
        lastName: lastName,
        line1: line1,
        line2: line2,
        landmark: landmark,
        city: city,
        state: state,
        pinCode: pinCode,
        phoneNumber: alternatePhone,
        country: "India"
    };

    // Send the AJAX request
    doPostAjaxRequestWithJsonHandler(`${context}/customer/address?customerId=${customerId}`, JSON.stringify(customerAddress), function (response) {
        console.log('responsee', response);
        if (response.responseStatus == "SUCCESS") {
            $('#addNewaddressModal').modal('hide');
            // Prepend the new address to the table
            alert('Address added successfully');
            const newAddress = response.response; // Adjust according to your response structure
            const newRow = `
                <tr>
                    <td>${newAddress.name}</td>
                    <td>${newAddress.line1} ${newAddress.line2}</td>
                    <td>${newAddress.city}</td>
                    <td>${newAddress.state}</td>
                    <td>${newAddress.pinCode}</td>
                    <td>${newAddress.phoneNumber}</td>
                    <td><a href="javascript:void(0)" class="select-customer-address" data-addressid="${newAddress.id}" data-orderid="${orderId}">Select Address</a></td>
                </tr>
            `;
            $('.address-table tbody').prepend(newRow);
        }

    });
});

$(document).on('click', 'button.add-new-address-btn', function () {
    customerId = $(this).data('customerid');
    orderId = $(this).data('orderid');
    $('#addNewaddressModal').modal({show: true});
});

$(document).on('click', '.select-customer-address', function () {
    var addressId = $(this).data('addressid');
    var orderId = $(this).data('orderid');
    console.log('orderid', orderId);
    doPostAjaxRequestHandler(`${context}/update-fofoOrder-addressId?addressId=${addressId}&&orderId=${orderId}`, function (response) {
        if (response.responseStatus == "SUCCESS") {
            console.log('address updated successfully');
        }
    });

});


$(document).on('change', ".disposition-options-mk",
    function () {
        var disposition = $(this).val();
        if (disposition == 'RESCHEDULED') {
            $(".schedule-time").css("display", "block");
        } else {
            $(".schedule-time").css("display", "none");
        }

    });
$(document).on('click', ".click-to-call-mk", function () {
    var customerMobile = $(this).data("customermobile");
    var upsellCallId = $(this).data("upsalecallid");

    doPostAjaxRequestHandler(
        `${context}/upsell/clickToCall/${customerMobile}/${upsellCallId}`,
        function (response) {
            if (response.responseStatus === "SUCCESS") {
                $(".disposition-button-mk").show(); // Shows the button
                showToast("Call has been initiated!");
            }
        }
    );
});


$(document).on('click', ".fill-disposition-mk", function () {
    var callId = $(this).data("upsalecallid");
    var disposition = $(".disposition-options-mk").val();
    var scheduleTime = $(".scheduleTime-select-mk").val();

    if (disposition == 'RESCHEDULED' && scheduleTime == '') {
        alert('please enter call scheduled time');
        return false;
    }

    // Convert scheduleTime to LocalDateTime format if it's not empty
    var formattedScheduleTime = scheduleTime ? new Date(scheduleTime).toISOString() : '';

    doPostAjaxRequestHandler(
        `${context}/upsell/disposition/${callId}?disposition=${disposition}&scheduleTime=${formattedScheduleTime}`,
        function (response) {
            if (response) {
                $("#dispositionModel").modal('hide');
                alert("Disposition, Disposition submitted successfully!");

            }
        }
    );
});

$(document).on('click', ".order-payment-status", function () {
    var orderId = $(this).data("orderid");

    doGetAjaxRequestHandler(
        `${context}/razorpapPaymentStatus?orderId=${orderId}`,
        function (response) {
            if (response) {
                $("#checkPaymentStatusModel").modal('show'); // Show the modal
                $('#checkPaymentStatusModel #checkPaymentStatusBody').html(response);

            }
        }
    );
});

$(document).on('click', ".upselling-report", function () {
    doAjaxRequestHandler(context + "/upsellingCallingList", "GET",
        function (response) {
            $('#main-content').html(response);
        });
});

$(document).on('click', '.download-upselling-report', function () {
    var startDate = getDatesFromPicker('input[name="upsellingPeriod"]').startDate;
    var endDate = getDatesFromPicker('input[name="upsellingPeriod"]').endDate;

    if (startDate == "" || startDate == undefined) {
        alert("start date is not be empty!!");
        return;
    }
    if (endDate == "" || endDate == undefined) {

        alert("end date is not be empty!!");
        return;
    }
    let endPoint = `${context}/downloadUpsellingReport?startDate=${startDate}&endDate=${endDate}`;
    window.location.href = endPoint;
});


$(document).on('click', '.fetch-upselling-report', function () {

    var startDate = getDatesFromPicker('input[name="upsellingPeriod"]').startDate;
    var endDate = getDatesFromPicker('input[name="upsellingPeriod"]').endDate;

    if (startDate == "" || startDate == undefined) {
        alert("start date is not be empty!!");
        return;
    }
    if (endDate == "" || endDate == undefined) {

        alert("end date is not be empty!!");
        return;
    }

    doGetAjaxRequestHandler(context + "/getUpsellingReport?startDate=" + startDate + "&endDate=" + endDate,
        function (response) {
            $('#upselling-report-list').html(response);
        });

});