Subversion Repositories SmartDukaan

Rev

Rev 32012 | 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) {
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
 
155
$(document).on('click', 'button.mk_download_pricing', function () {
156
    doAjaxGetDownload(context + "/tagListing/download/4", "pricing.xlsx")
157
});
158
 
159
$(document).on('click', '.mk_auto_process', function () {
160
    var trElement = $(this).closest('tr');
161
    var payout = trElement.find('input.partner-payout').val();
162
    if (isNaN(parseInt(payout)) || parseInt(payout) <= 0) {
163
        alert("Invalid payout amount");
164
    }
165
    if (confirm("Are you sure you want to Process Payout?")) {
166
        clickedPriceDrop = $(this);
167
        var priceDropId = trElement.data('pricedropid');
168
        autoProcess({priceDropId: priceDropId, partnerPayout: payout, activatedOnly: $(this).data('activatedonly')})
169
    }
170
});
171
 
172
function priceDropImeis(priceDropId) {
173
 
174
 
175
    doAjaxRequestWithJsonHandler(context + "/priceDropImeis/" + priceDropId, 'GET', null, function (response) {
176
        response = JSON.parse(response);
177
        holdArr = [];
178
        response.holdImeis.forEach(function (val, index) {
179
            holdArr.push('<option>' + val + '</option>')
180
        });
181
        $('select.mk_hold').html(holdArr.join('')).find('option');
182
        $('span.mk_hold_count').html(holdArr.length);
183
 
184
 
185
        pendingArr = [];
186
        response.pendingImeis.forEach(function (val, index) {
187
            pendingArr.push('<option>' + val + '</option>')
188
        });
189
        $('select.mk_pending').html(pendingArr.join('')).find('option');
190
        $('span.mk_pending_count').html(pendingArr.length);
191
 
192
        approvedArr = [];
193
        response.approvedImeis.forEach(function (val, index) {
194
            approvedArr.push('<option>' + val + '</option>')
195
        });
196
        $('select.mk_approved').html(approvedArr.join(''));
197
        $('span.mk_approved_count').html(approvedArr.length);
198
 
199
        rejectedArr = [];
200
        response.rejectedImeis.forEach(function (val, index) {
201
            rejectedArr.push('<option>' + val + '</option>')
202
        });
203
        $('span.mk_rejected_count').html(rejectedArr.length);
204
        $('select.mk_rejected').html(rejectedArr.join(''));
205
        // if(rejected) {}
206
    });
207
 
24083 amit.gupta 208
}
24406 amit.gupta 209
 
32012 amit.gupta 210
$(document).on('click', '.mk_view_imeis', function () {
211
    clickedPriceDrop = $(this);
212
    var trElement = $(this).closest('tr');
213
    var priceDropId = trElement.data('pricedropid');
214
    priceDropImeis(priceDropId);
215
 
216
});
217
 
218
$(document).on('click', '.mk_add_payout', function () {
219
    if (confirm("Are you sure you want to add price Drop?")) {
220
        var trElement = $(this).closest('tr');
221
        var priceDropId = trElement.data('pricedropid');
222
        var partnerPayout = trElement.find('.partner-payout').val();
223
        var priceDropIn = trElement.find('.price-drop-in').val();
224
 
225
        if (isNaN(partnerPayout) || partnerPayout == 0) {
226
            alert("Partner Payout can't be 0");
227
            return false;
228
        } else if (isNaN(priceDropIn) || priceDropIn == 0) {
229
            alert("Price Drop can't be 0");
230
            return false;
231
        } else {
232
            let priceDropObj = {
233
                priceDropIn: parseFloat(priceDropIn),
234
                partnerPayout: parseFloat(partnerPayout),
235
                priceDropId: parseInt(priceDropId)
236
            };
237
            addPayout(priceDropObj);
238
        }
239
    } else {
240
        return false;
241
    }
242
});
243
 
244
function addPayout(priceDropProcessObj) {
245
    doPostAjaxRequestWithJsonHandler(context + "/price-drop/addPayout", JSON.stringify(priceDropProcessObj), function (response) {
246
        if (response == 'true') {
247
            alert("Payout added");
248
            loadPriceDrop("main-content");
249
        } else {
250
            alert("Some error occurred while adding payout.");
251
        }
252
    });
23966 amit.gupta 253
}
23819 govind 254
 
32012 amit.gupta 255
function autoProcess(priceDropObj) {
256
    doPostAjaxRequestWithJsonHandler(context + "/processPriceDrop", JSON.stringify(priceDropObj), function (response) {
257
        if (response == 'true') {
258
            alert("PriceDrop sends successfully");
259
            loadPriceDrop("main-content");
260
        } else {
261
            alert("No IMEI is Eligible for PriceDrop");
262
            loadPriceDrop("main-content");
263
        }
264
    });
265
}
28568 amit.gupta 266
 
267
 
32012 amit.gupta 268
function updatePriceDropImeis(status) {
269
    var imeisInText = [];
270
    $('input.mk_imeis_text').val().trim().split(',').forEach(function (imei, i) {
271
        if (imei.trim() !== '') {
272
            imeisInText.push(imei.trim());
273
        }
274
    });
26348 amit.gupta 275
 
32012 amit.gupta 276
    var pendingArr = new Array();
277
    $('select.mk_pending option').each(function () {
278
        pendingArr.push($(this).val());
279
    });
280
    var rejectedArr = new Array();
281
    $('select.mk_rejected option').each(function () {
282
        rejectedArr.push($(this).val());
283
    });
284
    var approvedArr = new Array();
285
    $('select.mk_approved option').each(function () {
286
        approvedArr.push($(this).val());
287
    });
288
    var allImeisToUpdate;
28568 amit.gupta 289
 
32012 amit.gupta 290
    if (status === 'rejected') {
291
        if ($("#statusForm .mk_rejection_reason").val().trim() === "") {
292
            alert("Please enter rejection reason");
293
            return;
294
        }
295
        allImeisToUpdate = $('select.mk_pending').val();
296
        for (const imeiInText of imeisInText) {
297
            if (pendingArr.includes(imeiInText)) {
298
                allImeisToUpdate.push(imeiInText);
299
            } else {
300
                alert("All IMEIs Should be present in pending Status");
301
                return;
302
            }
303
        }
304
    } else if (status === 'approved') {
305
        allImeisToUpdate = $('select.mk_pending').val();
306
        for (const imeiInText of imeisInText) {
307
            if (pendingArr.includes(imeiInText)) {
308
                allImeisToUpdate.push(imeiInText);
309
            } else {
310
                alert("All IMEIs Should be present in pending Status");
311
                return;
312
            }
313
        }
314
    } else {
315
        allImeisToUpdate = $('select.mk_rejected').val();
316
        for (const imeiInText of imeisInText) {
317
            if (rejectedArr.includes(imeiInText)) {
318
                allImeisToUpdate.push(imeiInText);
319
            } else {
320
                alert("All IMEIs Should be present in Rejected Status");
321
                return;
322
            }
323
        }
324
    }
24176 amit.gupta 325
 
32012 amit.gupta 326
    if (allImeisToUpdate.length === 0) {
327
        alert('Please choose imeis');
328
        return;
329
    }
330
 
331
    if (!confirm("Move selected imeis to " + status + "?")) {
332
        return;
333
    }
334
    var trElement = clickedPriceDrop.closest('tr');
335
    var priceDropId = trElement.data('pricedropid');
336
 
337
    priceDropImeisObj = {
338
        priceDropId: priceDropId,
339
        updatedStatus: status,
340
        updatedImeis: allImeisToUpdate
341
    };
342
    doPostAjaxRequestWithJsonHandler(context + "/updatePriceDropImeis", JSON.stringify(priceDropImeisObj), function (response) {
343
        if (response == 'true') {
344
            alert('Imeis updated and processed successfully');
345
            priceDropImeis(priceDropId);
346
        } else {
347
            alert("Error occurred while updating.");
348
        }
349
    });
350
 
351
 
24410 amit.gupta 352
}