Subversion Repositories SmartDukaan

Rev

Rev 32267 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
32012 amit.gupta 1
$(document).on('change', "#selectPriceDropStatus", function () {
2
    var status = this.value;
3
    if (status == 'rejected') {
4
        $('.mk_rejection_reason').val('').show();
5
    } else {
6
        $('.mk_rejection_reason').val('').hide();
7
    }
8
});
9
$(document).on('click', "#processPDButton", function () {
10
    var status = $("#selectPriceDropStatus").val();
11
    updatePriceDropImeis(status);
12
});
24406 amit.gupta 13
 
32012 amit.gupta 14
$(document).on('click', "button.processPayout", function () {
15
    if ($(".mk_pending")) {
24019 amit.gupta 16
 
32012 amit.gupta 17
    }
18
});
24409 amit.gupta 19
 
32012 amit.gupta 20
$(document).on('click', "button.add-pricing", function () {
21
    if ($("#typeaheaditem1").val().trim().length == 0) {
32267 jai.hind 22
        alert("Please choose Item ");
32012 amit.gupta 23
        return;
24
    }
25
    var mop = $("#mop").val();
26
    var dp = $("#dp").val();
27
    var mrp = $("#mrp").val();
28
    var tp = $("#tp").val();
29
    if (isNaN(dp) || isNaN(mop) || isNaN(mrp)) {
30
        alert("DP/MOP/MRP should be a number");
31
        return;
32
    }
32267 jai.hind 33
        mop = parseFloat(mop),
34
        tp = parseFloat(tp),
32012 amit.gupta 35
        dp = parseFloat(dp),
36
        mrp = parseFloat(mrp)
32267 jai.hind 37
         if  (dp < tp || mop < tp) {
38
           if(!confirm("DP/MOP  is less than TP, Do you want to continue?")){
39
            return;
40
           }
41
         }
42
           if( mop < dp ){
43
            if(!confirm("MOP  is less than DP, Do you want to continue?")){
44
            return;
45
           }
46
         }
47
    if (mrp != 0 && (mrp < mop || mrp < dp || mrp < tp )) {
32012 amit.gupta 48
        bootbox.alert("DP/MOP/TP should be lower than MRP");
49
        return;
50
    }
32267 jai.hind 51
 
32012 amit.gupta 52
    getColorsForItems(0, currentItem.itemId, "Update prices for " + currentItem.itemDescription, function (itemIds) {
53
        console.log(itemIds);
23884 amit.gupta 54
 
32012 amit.gupta 55
        if (itemIds != null) {
56
            dataList = [];
57
            coloredItems.forEach(function (item) {
58
                console.log(item);
59
                console.log(itemIds.indexOf(String(item.id)));
60
                if (itemIds.indexOf(String(item.id)) >= 0) {
61
                    dataList.push(
62
                        {
63
                            id: item.id,
64
                            mop: mop,
65
                            dp: dp,
66
                            mrp: mrp,
67
                            tp: tp
68
                        });
69
                }
70
            });
71
            bootbox.confirm("Confirm Update " + currentItem.itemDescription + "?", function (result) {
72
                if (result) {
73
                    doPostAjaxRequestWithJsonHandler(
74
                        context + "/add-pricing", JSON.stringify(dataList),
75
                        function (response) {
76
                            if (response == 'true') {
77
                                bootbox.alert("Prices Successfully Updated");
78
                            } else {
79
                                bootbox.alert("Something went wrong pls try after sometime");
80
                            }
81
                        }
82
                    );
83
                }
84
            });
85
        }
86
    });
28568 amit.gupta 87
 
32012 amit.gupta 88
});
89
$(document).on('click', "button.addPriceDrop", function () {
90
    if ($("#typeaheaditem").val().trim().length == 0) {
91
        alert("Please choose Item");
92
        return;
93
    }
94
    var newDp = $("#newDp").val();
95
    var newTp = $("#newTp").val();
96
    var newMop = $("#newMop").val();
97
    var affectedOn = $("#affectedDate").val();
98
    var allColors = $("#allColors").prop('checked');
24083 amit.gupta 99
 
32012 amit.gupta 100
    if (newDp.length == 0 || parseFloat(newDp) == 0) {
101
        alert("New Tp should not be empty");
102
        return;
103
    }
104
    if (newTp.length == 0 || parseFloat(newTp) == 0) {
105
        alert("New Tp should not be empty");
106
        return;
107
    }
108
    if (newMop.length == 0 || parseFloat(newMop) == 0) {
109
        alert("New Mop should not be empty");
110
        return;
111
    }
112
 
113
    if (affectedOn.length == 0) {
114
        alert("Affected Date Should not be empty");
115
        return;
116
    }
117
    // as of now allColors is set to true. This means that all colors are
118
    // eligible for price drop
119
    if (confirm("Are you sure?")) {
120
        var obj = {
121
            itemId: currentItem.itemId,
122
            dp: parseFloat(newDp),
123
            tp: parseFloat(newTp),
124
            mop: parseFloat(newMop),
125
            allColors: true,
126
            affectedDate: getDatesFromPicker($('#affectedDate')).startDate
127
        }
128
        doPostAjaxRequestWithJsonHandler(
129
            context + "/priceDrop", JSON.stringify(obj),
130
            function (response) {
131
                if (response == 'true') {
132
                    $('#newPriceDropModal').find('button.close').trigger('click');
133
                    setTimeout(() => {
134
                        alert("PriceDrop added successfully from " + $("#typeaheaditem").val());
135
                        loadPriceDrop("main-content");
136
                    }, 500);
137
                } else {
138
                    alert("Invalid values provided could not update");
139
                }
140
            }
141
        );
142
    }
143
});
144
$(document).on('click', 'input.downloadtotalIMEI', function () {
145
    var priceDropId = $(this).closest('tr').data('pricedropid');
146
    doAjaxGetDownload(context + "/downloadtotalPriceDropIMEI/" + priceDropId,
147
        "totalPriceDropIMEI" + priceDropId + ".csv");
148
});
149
 
150
$(document).on('click', 'button.download-imeis', function () {
151
    let affectedDate = getDatesFromPicker('#affectedDate').startDate;
152
    doAjaxGetDownload(context + "/price-drop/imes/download/?affectedDate=" + affectedDate + "&itemId=" + currentItem.itemId, "pricedrop.csv")
153
});
154
 
34651 aman.kumar 155
$(document).on('click', '.download-price-drop-statement-report', function () {
156
    var startDate = getDatesFromPicker('input[name="priceDropStatementPeriod"]').startDate;
157
    var endDate = getDatesFromPicker('input[name="priceDropStatementPeriod"]').endDate;
158
    let endPoint = `${context}/pricedropByDate/download?startDate=${startDate}&endDate=${endDate}`;
159
    window.location.href = endPoint;
160
});
161
 
162
$(document).on('click', '.fetch-price-drop-statement-report', function () {
163
 
164
    var startDate = getDatesFromPicker('input[name="priceDropStatementPeriod"]').startDate;
165
    var endDate = getDatesFromPicker('input[name="priceDropStatementPeriod"]').endDate;
166
 
167
    if (startDate == "" || startDate == undefined) {
168
        alert("start date is not be empty!!");
169
        return;
170
    }
171
    if (endDate == "" || endDate == undefined) {
172
 
173
        alert("end date is not be empty!!");
174
        return;
175
    }
176
 
177
    doGetAjaxRequestHandler(context + "/getPricedropByDate?startDate=" + startDate + "&endDate=" + endDate,
178
        function (response) {
179
            $('#table-container').html(response);
180
        });
181
 
182
});
183
 
32012 amit.gupta 184
$(document).on('click', 'button.mk_download_pricing', function () {
185
    doAjaxGetDownload(context + "/tagListing/download/4", "pricing.xlsx")
186
});
187
 
188
$(document).on('click', '.mk_auto_process', function () {
189
    var trElement = $(this).closest('tr');
190
    var payout = trElement.find('input.partner-payout').val();
191
    if (isNaN(parseInt(payout)) || parseInt(payout) <= 0) {
192
        alert("Invalid payout amount");
193
    }
194
    if (confirm("Are you sure you want to Process Payout?")) {
195
        clickedPriceDrop = $(this);
196
        var priceDropId = trElement.data('pricedropid');
197
        autoProcess({priceDropId: priceDropId, partnerPayout: payout, activatedOnly: $(this).data('activatedonly')})
198
    }
199
});
200
 
201
function priceDropImeis(priceDropId) {
202
 
203
 
204
    doAjaxRequestWithJsonHandler(context + "/priceDropImeis/" + priceDropId, 'GET', null, function (response) {
205
        response = JSON.parse(response);
206
        holdArr = [];
207
        response.holdImeis.forEach(function (val, index) {
208
            holdArr.push('<option>' + val + '</option>')
209
        });
210
        $('select.mk_hold').html(holdArr.join('')).find('option');
211
        $('span.mk_hold_count').html(holdArr.length);
212
 
213
 
214
        pendingArr = [];
215
        response.pendingImeis.forEach(function (val, index) {
216
            pendingArr.push('<option>' + val + '</option>')
217
        });
218
        $('select.mk_pending').html(pendingArr.join('')).find('option');
219
        $('span.mk_pending_count').html(pendingArr.length);
220
 
221
        approvedArr = [];
222
        response.approvedImeis.forEach(function (val, index) {
223
            approvedArr.push('<option>' + val + '</option>')
224
        });
225
        $('select.mk_approved').html(approvedArr.join(''));
226
        $('span.mk_approved_count').html(approvedArr.length);
227
 
228
        rejectedArr = [];
229
        response.rejectedImeis.forEach(function (val, index) {
230
            rejectedArr.push('<option>' + val + '</option>')
231
        });
232
        $('span.mk_rejected_count').html(rejectedArr.length);
233
        $('select.mk_rejected').html(rejectedArr.join(''));
234
        // if(rejected) {}
235
    });
236
 
24083 amit.gupta 237
}
24406 amit.gupta 238
 
32012 amit.gupta 239
$(document).on('click', '.mk_view_imeis', function () {
240
    clickedPriceDrop = $(this);
241
    var trElement = $(this).closest('tr');
242
    var priceDropId = trElement.data('pricedropid');
243
    priceDropImeis(priceDropId);
244
 
245
});
246
 
247
$(document).on('click', '.mk_add_payout', function () {
248
    if (confirm("Are you sure you want to add price Drop?")) {
249
        var trElement = $(this).closest('tr');
250
        var priceDropId = trElement.data('pricedropid');
251
        var partnerPayout = trElement.find('.partner-payout').val();
252
        var priceDropIn = trElement.find('.price-drop-in').val();
253
 
254
        if (isNaN(partnerPayout) || partnerPayout == 0) {
255
            alert("Partner Payout can't be 0");
256
            return false;
257
        } else if (isNaN(priceDropIn) || priceDropIn == 0) {
258
            alert("Price Drop can't be 0");
259
            return false;
260
        } else {
261
            let priceDropObj = {
262
                priceDropIn: parseFloat(priceDropIn),
263
                partnerPayout: parseFloat(partnerPayout),
264
                priceDropId: parseInt(priceDropId)
265
            };
266
            addPayout(priceDropObj);
267
        }
268
    } else {
269
        return false;
270
    }
271
});
272
 
273
function addPayout(priceDropProcessObj) {
274
    doPostAjaxRequestWithJsonHandler(context + "/price-drop/addPayout", JSON.stringify(priceDropProcessObj), function (response) {
275
        if (response == 'true') {
276
            alert("Payout added");
277
            loadPriceDrop("main-content");
278
        } else {
279
            alert("Some error occurred while adding payout.");
280
        }
281
    });
23966 amit.gupta 282
}
23819 govind 283
 
32012 amit.gupta 284
function autoProcess(priceDropObj) {
285
    doPostAjaxRequestWithJsonHandler(context + "/processPriceDrop", JSON.stringify(priceDropObj), function (response) {
286
        if (response == 'true') {
287
            alert("PriceDrop sends successfully");
288
            loadPriceDrop("main-content");
289
        } else {
290
            alert("No IMEI is Eligible for PriceDrop");
291
            loadPriceDrop("main-content");
292
        }
293
    });
294
}
28568 amit.gupta 295
 
296
 
32012 amit.gupta 297
function updatePriceDropImeis(status) {
298
    var imeisInText = [];
299
    $('input.mk_imeis_text').val().trim().split(',').forEach(function (imei, i) {
300
        if (imei.trim() !== '') {
301
            imeisInText.push(imei.trim());
302
        }
303
    });
26348 amit.gupta 304
 
32012 amit.gupta 305
    var pendingArr = new Array();
306
    $('select.mk_pending option').each(function () {
307
        pendingArr.push($(this).val());
308
    });
309
    var rejectedArr = new Array();
310
    $('select.mk_rejected option').each(function () {
311
        rejectedArr.push($(this).val());
312
    });
313
    var approvedArr = new Array();
314
    $('select.mk_approved option').each(function () {
315
        approvedArr.push($(this).val());
316
    });
317
    var allImeisToUpdate;
28568 amit.gupta 318
 
32012 amit.gupta 319
    if (status === 'rejected') {
320
        if ($("#statusForm .mk_rejection_reason").val().trim() === "") {
321
            alert("Please enter rejection reason");
322
            return;
323
        }
324
        allImeisToUpdate = $('select.mk_pending').val();
325
        for (const imeiInText of imeisInText) {
326
            if (pendingArr.includes(imeiInText)) {
327
                allImeisToUpdate.push(imeiInText);
328
            } else {
329
                alert("All IMEIs Should be present in pending Status");
330
                return;
331
            }
332
        }
333
    } else if (status === 'approved') {
334
        allImeisToUpdate = $('select.mk_pending').val();
335
        for (const imeiInText of imeisInText) {
336
            if (pendingArr.includes(imeiInText)) {
337
                allImeisToUpdate.push(imeiInText);
338
            } else {
339
                alert("All IMEIs Should be present in pending Status");
340
                return;
341
            }
342
        }
343
    } else {
344
        allImeisToUpdate = $('select.mk_rejected').val();
345
        for (const imeiInText of imeisInText) {
346
            if (rejectedArr.includes(imeiInText)) {
347
                allImeisToUpdate.push(imeiInText);
348
            } else {
349
                alert("All IMEIs Should be present in Rejected Status");
350
                return;
351
            }
352
        }
353
    }
24176 amit.gupta 354
 
32012 amit.gupta 355
    if (allImeisToUpdate.length === 0) {
356
        alert('Please choose imeis');
357
        return;
358
    }
359
 
360
    if (!confirm("Move selected imeis to " + status + "?")) {
361
        return;
362
    }
363
    var trElement = clickedPriceDrop.closest('tr');
364
    var priceDropId = trElement.data('pricedropid');
365
 
366
    priceDropImeisObj = {
367
        priceDropId: priceDropId,
368
        updatedStatus: status,
369
        updatedImeis: allImeisToUpdate
370
    };
371
    doPostAjaxRequestWithJsonHandler(context + "/updatePriceDropImeis", JSON.stringify(priceDropImeisObj), function (response) {
372
        if (response == 'true') {
373
            alert('Imeis updated and processed successfully');
374
            priceDropImeis(priceDropId);
375
        } else {
376
            alert("Error occurred while updating.");
377
        }
378
    });
379
 
380
 
24410 amit.gupta 381
}