Subversion Repositories SmartDukaan

Rev

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