Subversion Repositories SmartDukaan

Rev

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