Subversion Repositories SmartDukaan

Rev

Rev 33720 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
33715 ranu 1
var customerId;
2
var orderId;
3
$(document).on('click', ".upsale-calling", function () {
4
    upsalingDAshboard();
5
});
6
 
7
$(document).on('click', "#fetch-calling-data", function () {
8
    doAjaxRequestHandler(context + "/fetchMobileNumberForUpSale", "GET",
9
        function (response) {
10
            $('#main-content').html(response);
11
        });
12
});
13
 
14
$(document).on('click', ".generatePlanModel", function () {
15
    const data = {
16
        orderId: $(this).data("orderid"),
17
        orderItemId: $(this).data("orderitemid"),
18
        planName: $(this).data("planname"),
19
        planId: $(this).data("planid"),
20
        productDescription: $(this).data("description"),
21
        amount: $(this).data("premium"),
22
        mobile: $(this).data('mobile'),
23
        customerName: $(this).data('customername'), // Fixed typo: 'cutsomername' to 'customername'
24
        customerEmail: $(this).data('customeremail'), // Fixed typo: 'cutsomeremail' to 'customeremail'
25
        serialNumber: $(this).data('serialnumber'),
26
    };
27
 
28
    geneartePlanDetail(data);
29
});
30
 
31
$(document).on('click', ".payment-link-mk", function () {
32
    // Prompt the user for confirmation
33
    const userConfirmed = confirm("Are you sure you want to generate and send the payment link?");
34
 
35
    if (userConfirmed) {
36
        const data = {
37
            orderId: $('.order-id').val(),
38
            orderItemId: $('.order-item-id').val(),
39
            planName: $('.insurance-plan-name').val(),
40
            planId: $('.insurance-id').val(),
41
            productDescription: $('.insurance-description').val(),
42
            amount: $('.insurance-amount').val(),
43
            mobile: $('.customer-mobile-number').val(),
44
            customerName: $('.customer-first-name').val(),
45
            customerEmail: $('.customer-email-id').val(),
46
            serialNumber: $('.customer-serial-number').val(),
47
        };
48
 
49
        doPostAjaxRequestWithJsonHandler(
50
            `${context}/generatePaymentLink`,
51
            JSON.stringify(data),
52
            function (response) {
53
                if (response.response) {
54
                    alert('Payment link generated and sent successfully');
55
                } else {
56
                    alert("Something went wrong");
57
                }
58
            }
59
        );
60
    } else {
61
        alert("Payment link generation cancelled.");
62
    }
63
});
64
 
65
 
66
function geneartePlanDetail(data) {
67
    doPostAjaxRequestWithJsonHandler(`${context}/generatePlanDetail`, JSON.stringify(data), function (response) {
68
        //handle response here
69
        $("#generatePlanModel").modal('show'); // Show the modal
70
        $('#generatePlanModel #generatePlanBody').html(response);
71
        $(".serial-number-input").val(data.serialNumber);
72
    });
73
}
74
 
75
function upsalingDAshboard() {
76
    doAjaxRequestHandler(context + "/upsaleProductslist", "GET",
77
        function (response) {
78
            $('#main-content').html(response);
79
            $(".disposition-button-mk").hide();
80
        });
81
}
82
 
83
 
84
$(document).on('click', '.create-insurance-mk', function () {
85
    // Gather input values
86
    const customerEmail = $('.customerEmail').val();
87
    const serialNumber = $('.serial-number').val();
88
    const fofoOrderId = $('.order-id').val();
89
    const fofoOrderItemId = $('.order-item-id').val();
90
    const insuranceId = $('.insurance-id').val();
91
    const insdp = $('.insurance-dp').val();
92
    const premium = $('.insurance-premium').val();
93
    const insuranceAmount = $('.insurance-amount').val();
94
    const memory = $('.memory').val();
95
    const ram = $('.ram').val();
96
    const wmfgDate = $('.wmfgDate').val();
97
    const gender = $('.gender').val();
98
    const dob = $('.dob').val();
99
 
100
    // Validate required fields
101
    let missingFields = [];
102
 
103
    if (!customerEmail) missingFields.push('Customer Email');
104
    if (!serialNumber) missingFields.push('Serial Number');
105
    if (!memory) missingFields.push('Memory');
106
    if (!ram) missingFields.push('Ram');
107
    if (!wmfgDate) missingFields.push('MFG Date');
108
    if (!gender) missingFields.push('Gender');
109
    if (!dob) missingFields.push('DOB');
110
 
111
    if (missingFields.length > 0) {
112
        alert('The following fields are required: ' + missingFields.join(', '));
113
        return;
114
    }
115
 
116
 
117
    // List of payment options
118
    const paymentOptions = [
119
        {paymentOptionId: 29, paymentOption: "BENOW"},
120
        {paymentOptionId: 28, paymentOption: "AMAZON PAY"},
121
        {paymentOptionId: 27, paymentOption: "MOBIKWIK"},
122
        {paymentOptionId: 26, paymentOption: "CLEVERPE"},
123
        {paymentOptionId: 25, paymentOption: "PAYTAIL"},
124
        {paymentOptionId: 24, paymentOption: "TVS"},
125
        {paymentOptionId: 23, paymentOption: "ONLINE"},
126
        {paymentOptionId: 22, paymentOption: "SAMSUNG SURE"},
127
        {paymentOptionId: 20, paymentOption: "ACCOUNT TRANSFER"},
128
        {paymentOptionId: 19, paymentOption: "UPI PAYMENT"},
129
        {paymentOptionId: 18, paymentOption: "MOBILE PLANET"},
130
        {paymentOptionId: 17, paymentOption: "HDFC PAPER FINANCE"},
131
        {paymentOptionId: 16, paymentOption: "HDB"},
132
        {paymentOptionId: 15, paymentOption: "IDFC (CF)"},
133
        {paymentOptionId: 14, paymentOption: "ZEST MONEY"},
134
        {paymentOptionId: 13, paymentOption: "HOME CREDIT"},
135
        {paymentOptionId: 10, paymentOption: "BAJAJ FINSERV"},
136
        {paymentOptionId: 7, paymentOption: "PAYTM"},
137
        {paymentOptionId: 4, paymentOption: "PINELABS"},
138
        {paymentOptionId: 1, paymentOption: "CASH"}
139
    ];
140
 
141
    // Set amounts for payment options
142
    paymentOptions.forEach(option => {
143
        option.amount = option.paymentOption === "ONLINE" ? insuranceAmount : 0;
144
    });
145
 
146
    // Create the object
147
    const data = {
148
        customerEmail: customerEmail,
149
        serialNumber: serialNumber,
150
        fofoOrderId: fofoOrderId,
151
        fofoOrderItemId: fofoOrderItemId,
152
        insuranceId: insuranceId,
153
        insdp: insdp,
154
        premium: premium,
155
        insuranceAmount: insuranceAmount,
156
        memory: memory,
157
        ram: ram,
158
        wmfgDate: wmfgDate,
159
        gender: gender,
160
        dob: dob,
161
        paymentOptions: paymentOptions
162
    };
163
 
164
    doPostAjaxRequestWithJsonHandler(
165
        `${context}/create-insurance`, JSON.stringify(data), function (response) {
166
            if (response.responseStatus == 'SUCCESS') {
167
                alert("Insurance created successfully");
168
                $('#generatePlanModel').modal('hide');
169
 
170
                // Remove the backdrop
171
                $('.modal-backdrop').remove();
172
                // upsalingDAshboard();
173
            }
174
 
175
        });
176
});
177
 
178
$(document).on('click', 'button.btn-add-new-address', function () {
179
    // Gather input values
180
    const firstName = $('#addFirstName').val();
181
    const lastName = $('#addLastName').val();
182
    const alternatePhone = $('#addAlternatePhone').val();
183
    const line1 = $('#addLine1').val();
184
    const line2 = $('#addLine2').val();
185
    const landmark = $('#addLandmark').val();
186
    const pinCode = $('#addPinCode').val();
187
    const city = $('#addCity').val();
188
    const state = $('select[name=state] option:selected').val();
189
 
190
    // Validate required fields
191
    let missingFields = [];
192
 
193
    if (!firstName) missingFields.push('First Name');
194
    if (!line1) missingFields.push('Address Line 1');
195
    if (!state) missingFields.push('State');
196
    if (!city) missingFields.push('City');
197
    if (!pinCode) missingFields.push('Pin Code');
198
    if (!alternatePhone) missingFields.push('Mobile Number');
199
 
200
    if (missingFields.length > 0) {
201
        alert('The following fields are required: ' + missingFields.join(', '));
202
        return;
203
    }
204
 
205
    // Create the customerAddress object
206
    const customerAddress = {
207
        name: firstName,
208
        lastName: lastName,
209
        line1: line1,
210
        line2: line2,
211
        landmark: landmark,
212
        city: city,
213
        state: state,
214
        pinCode: pinCode,
215
        phoneNumber: alternatePhone,
216
        country: "India"
217
    };
218
 
219
    // Send the AJAX request
220
    doPostAjaxRequestWithJsonHandler(`${context}/customer/address?customerId=${customerId}`, JSON.stringify(customerAddress), function (response) {
221
        console.log('responsee', response);
222
        if (response.responseStatus == "SUCCESS") {
223
            $('#addNewaddressModal').modal('hide');
224
            // Prepend the new address to the table
225
            alert('Address added successfully');
226
            const newAddress = response.response; // Adjust according to your response structure
227
            const newRow = `
228
                <tr>
229
                    <td>${newAddress.name}</td>
230
                    <td>${newAddress.line1} ${newAddress.line2}</td>
231
                    <td>${newAddress.city}</td>
232
                    <td>${newAddress.state}</td>
233
                    <td>${newAddress.pinCode}</td>
234
                    <td>${newAddress.phoneNumber}</td>
235
                    <td><a href="javascript:void(0)" class="select-customer-address" data-addressid="${newAddress.id}" data-orderid="${orderId}">Select Address</a></td>
236
                </tr>
237
            `;
238
            $('.address-table tbody').prepend(newRow);
239
        }
240
 
241
    });
242
});
243
 
244
$(document).on('click', 'button.add-new-address-btn', function () {
245
    customerId = $(this).data('customerid');
246
    orderId = $(this).data('orderid');
247
    $('#addNewaddressModal').modal({show: true});
248
});
249
 
250
$(document).on('click', '.select-customer-address', function () {
251
    var addressId = $(this).data('addressid');
252
    var orderId = $(this).data('orderid');
253
    console.log('orderid', orderId);
254
    doPostAjaxRequestHandler(`${context}/update-fofoOrder-addressId?addressId=${addressId}&&orderId=${orderId}`, function (response) {
255
        if (response.responseStatus == "SUCCESS") {
256
            console.log('address updated successfully');
257
        }
258
    });
259
 
260
});
261
 
262
 
263
$(document).on('change', ".disposition-options-mk",
264
    function () {
265
        var disposition = $(this).val();
266
        if (disposition == 'RESCHEDULED') {
267
            $(".schedule-time").css("display", "block");
268
        } else {
269
            $(".schedule-time").css("display", "none");
270
        }
271
 
272
    });
273
$(document).on('click', ".click-to-call-mk", function () {
274
    var customerMobile = $(this).data("customermobile");
275
    var upsellCallId = $(this).data("upsalecallid");
276
 
277
    doPostAjaxRequestHandler(
278
        `${context}/upsell/clickToCall/${customerMobile}/${upsellCallId}`,
279
        function (response) {
280
            if (response.responseStatus === "SUCCESS") {
281
                $(".disposition-button-mk").show(); // Shows the button
282
                showToast("Call initiated!");
283
            }
284
        }
285
    );
286
});
287
 
288
 
289
$(document).on('click', ".fill-disposition-mk", function () {
290
    var callId = $(this).data("upsalecallid");
291
    var disposition = $(".disposition-options-mk").val();
292
    var scheduleTime = $(".scheduleTime-select-mk").val();
293
 
294
    if (disposition == 'RESCHEDULED' && scheduleTime == '') {
295
        alert('please enter call scheduled time');
296
        return false;
297
    }
298
 
299
    // Convert scheduleTime to LocalDateTime format if it's not empty
300
    var formattedScheduleTime = scheduleTime ? new Date(scheduleTime).toISOString() : '';
301
 
302
    doPostAjaxRequestHandler(
303
        `${context}/upsell/disposition/${callId}?disposition=${disposition}&scheduleTime=${formattedScheduleTime}`,
304
        function (response) {
305
            if (response) {
306
                $("#dispositionModel").modal('hide');
307
                alert("Disposition, Disposition submitted successfully!");
308
 
309
            }
310
        }
311
    );
312
});
313
 
314
$(document).on('click', ".order-payment-status", function () {
315
    var orderId = $(this).data("orderid");
316
 
317
    doGetAjaxRequestHandler(
318
        `${context}/razorpapPaymentStatus?orderId=${orderId}`,
319
        function (response) {
320
            if (response) {
321
                $("#checkPaymentStatusModel").modal('show'); // Show the modal
322
                $('#checkPaymentStatusModel #checkPaymentStatusBody').html(response);
323
 
324
            }
325
        }
326
    );
327
});
328
 
329
 
330
 
331
 
332
 
333