Subversion Repositories SmartDukaan

Rev

Rev 32979 | Rev 33167 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27711 amit.gupta 1
const MAIN_CONTAINER = "#main-content";
24440 amit.gupta 2
var logosmapping = {
32301 amit.gupta 3
    mobile_insurance_providers: {
4
        "0": context + '/resources/images/icons/provider-logos/iffco.png',
5
        "1": context + '/resources/images/icons/provider-logos/icici.jpg',
6
        "2": context + '/resources/images/icons/provider-logos/tataaig.png',
7
        "3": context + '/resources/images/icons/provider-logos/bharti.jpg',
8
        "4": context + '/resources/images/icons/provider-logos/bharti.jpg',
9
        "5": context + '/resources/images/icons/provider-logos/oneassist.jpeg'
10
    }
24440 amit.gupta 11
}
30414 amit.gupta 12
 
24595 tejbeer 13
function badRequestAlert(response) {
32301 amit.gupta 14
    console.log(response.responseText);
15
    var errorObject = JSON.parse(response.responseText);
16
    errorObject = errorObject.response;
17
    bootbox.alert('Bad Request\n' + 'rejectedType : '
18
        + errorObject.rejectedType + '\n' + 'rejectedValue : '
19
        + errorObject.rejectedValue + '\n' + 'message : '
20
        + errorObject.message);
22956 ashik.ali 21
}
24595 tejbeer 22
 
23
function internalServerErrorAlert(response) {
32301 amit.gupta 24
    console.log(response.responseText);
25
    var errorObject = JSON.parse(response.responseText);
26
    errorObject = errorObject.response;
27
    bootbox.alert('Internal Server Error\n' + 'rejectedType : '
28
        + errorObject.rejectedType + '\n' + 'rejectedValue : '
29
        + errorObject.rejectedValue + '\n' + 'message : '
30
        + errorObject.message);
22956 ashik.ali 31
}
32
 
32301 amit.gupta 33
$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
34
    if (typeof loaderDialogObj != "undefined") {
35
        loaderDialogObj.modal('hide');
36
        // $('div.modal-backdrop.fade').remove();
37
    }
38
    if (jqxhr.status == 400) {
39
        // $('#error-prompt-model').modal();
40
        badRequestAlert(jqxhr);
41
    } else {
42
        internalServerErrorAlert(jqxhr);
43
    }
22956 ashik.ali 44
});
45
 
32301 amit.gupta 46
$(document).ajaxComplete(function () {
47
    if (typeof loaderDialogObj != "undefined") {
48
        loaderDialogObj.modal('hide');
49
        // $('div.modal-backdrop.fade').remove();
50
    }
23946 amit.gupta 51
});
30017 amit.gupta 52
 
24992 tejbeer 53
function ajaxStartHandler() {
32301 amit.gupta 54
    if (typeof loaderDialogObj != "undefined")
55
        loaderDialogObj.modal('show');
24976 amit.gupta 56
}
30017 amit.gupta 57
 
24976 amit.gupta 58
$(document).ajaxStart(ajaxStartHandler);
24595 tejbeer 59
 
60
function doAjaxRequestWithParamsHandler(urlString, httpType, params,
32301 amit.gupta 61
                                        callback_function) {
62
    $.ajax({
63
        url: urlString,
64
        async: true,
65
        cache: false,
66
        data: params,
67
        // dataType:'json',
68
        type: httpType,
69
        success: function (response) {
70
            callback_function(response);
32308 amit.gupta 71
            formatCurrency();
32301 amit.gupta 72
        }
73
    });
23193 ashik.ali 74
}
75
 
24595 tejbeer 76
function doGetAjaxRequestWithParamsHandler(urlString, params, callback_function) {
32301 amit.gupta 77
    doAjaxRequestWithParamsHandler(urlString, "GET", params, callback_function);
23500 ashik.ali 78
}
79
 
24595 tejbeer 80
function doPostAjaxRequestWithParamsHandler(urlString, params,
32301 amit.gupta 81
                                            callback_function) {
82
    doAjaxRequestWithParamsHandler(urlString, "POST", params, callback_function);
23500 ashik.ali 83
}
84
 
32308 amit.gupta 85
function formatCurrency() {
86
    $('.rcurrency').each(function (index, ele) {
87
        if (!isNaN(parseInt($(ele).html()))) {
88
            $(ele).html(numberToComma($(ele).html(), true));
89
        }
90
    });
91
    $('.currency').each(function (index, ele) {
92
        if (!isNaN(parseInt($(ele).html()))) {
93
            $(ele).html(numberToComma($(ele).html()));
94
        }
95
    });
96
 
97
}
98
 
24595 tejbeer 99
function doAjaxRequestWithJsonHandler(urlString, httpType, json,
32301 amit.gupta 100
                                      callback_function) {
101
    $.ajax({
102
        url: urlString,
103
        async: true,
104
        cache: false,
105
        processData: false,
106
        data: json,
107
        contentType: 'application/json',
108
        type: httpType,
109
        success: function (response) {
110
            // console.log("response"+JSON.stringify(data));
111
            callback_function(response);
32308 amit.gupta 112
            formatCurrency();
32301 amit.gupta 113
        }
114
    });
23032 ashik.ali 115
}
116
 
24595 tejbeer 117
function doPostAjaxRequestWithJsonHandler(urlString, json, callback_function) {
32301 amit.gupta 118
    doAjaxRequestWithJsonHandler(urlString, "POST", json, callback_function);
23500 ashik.ali 119
}
23032 ashik.ali 120
 
24595 tejbeer 121
function doPutAjaxRequestWithJsonHandler(urlString, json, callback_function) {
32301 amit.gupta 122
    doAjaxRequestWithJsonHandler(urlString, "PUT", json, callback_function);
23500 ashik.ali 123
}
124
 
24595 tejbeer 125
function doAjaxRequestHandler(urlString, httpType, callback_function) {
32301 amit.gupta 126
    $.ajax({
127
        url: urlString,
128
        async: true,
129
        cache: false,
130
        type: httpType,
131
        success: function (response) {
132
            callback_function(response);
32308 amit.gupta 133
            formatCurrency();
32301 amit.gupta 134
        }
135
    });
22982 ashik.ali 136
}
137
 
24595 tejbeer 138
function doGetAjaxRequestHandler(urlString, callback_function) {
32301 amit.gupta 139
    doAjaxRequestHandler(urlString, "GET", callback_function);
23500 ashik.ali 140
}
141
 
24595 tejbeer 142
function doPutAjaxRequestHandler(urlString, callback_function) {
32301 amit.gupta 143
    doAjaxRequestHandler(urlString, "PUT", callback_function);
23500 ashik.ali 144
}
145
 
24595 tejbeer 146
function doPostAjaxRequestHandler(urlString, callback_function) {
32301 amit.gupta 147
    doAjaxRequestHandler(urlString, "POST", callback_function);
23629 ashik.ali 148
}
149
 
24595 tejbeer 150
function doDeleteAjaxRequestHandler(urlString, callback_function) {
32301 amit.gupta 151
    doAjaxRequestHandler(urlString, "DELETE", callback_function);
23783 ashik.ali 152
}
153
 
24595 tejbeer 154
function doAjaxUploadRequest(urlString, httpType, file) {
32301 amit.gupta 155
    var response;
156
    doAjaxUploadRequestHandler(urlString, httpType, file,
157
        function (ajaxResponse) {
158
            response = ajaxResponse;
159
        });
160
    return response;
23347 ashik.ali 161
}
162
 
24595 tejbeer 163
function doAjaxUploadRequestHandler(urlString, httpType, file,
32301 amit.gupta 164
                                    callback_function) {
165
    var formData = new FormData();
166
    formData.append("file", file);
167
    $.ajax({
168
        url: urlString,
169
        type: httpType,
170
        data: formData,
171
        dataType: 'json',
172
        async: true,
173
        cache: false,
174
        contentType: false,
175
        enctype: 'multipart/form-data',
176
        processData: false,
177
        success: function (response) {
178
            // console.log("response"+JSON.stringify(data));
179
            callback_function(response);
180
        }
181
    });
22982 ashik.ali 182
}
30017 amit.gupta 183
 
24595 tejbeer 184
function doAjaxUploadRequestJsonHandler(urlString, httpType, file, json,
32301 amit.gupta 185
                                        callback_function) {
186
    var formData = new FormData();
187
    formData.append("file", file);
188
    formData.append('json', new Blob([json]));
189
    $.ajax({
190
        url: urlString,
191
        type: httpType,
192
        data: formData,
193
        enctype: 'multipart/form-data',
194
        contentType: false,
195
        processData: false,
196
        success: function (response) {
197
            // console.log("response"+JSON.stringify(data));
198
            callback_function(response);
199
        }
200
    });
24171 govind 201
}
22982 ashik.ali 202
 
24595 tejbeer 203
function uploadDocument(file) {
32301 amit.gupta 204
    var url = context + '/document-upload';
205
    doAjaxUploadRequestHandler(url, 'POST', file, function (response) {
206
        var documentId = response.response.document_id;
207
        console.log("documentId : " + documentId);
208
        return documentId;
209
    });
23347 ashik.ali 210
}
211
 
24595 tejbeer 212
function doAjaxGetDownload(urlString, fileName) {
32301 amit.gupta 213
    console.log("fileName : " + fileName);
214
    doAjaxDownload(urlString, "GET", null, fileName);
22982 ashik.ali 215
}
216
 
31702 amit.gupta 217
function doAjaxPostDownload(urlString, data, fileName, callback) {
32301 amit.gupta 218
    doAjaxDownload(urlString, "POST", data, fileName, callback);
21627 kshitij.so 219
}
220
 
31702 amit.gupta 221
function doAjaxDownload(urlString, httpType, data, fileName, callback) {
32301 amit.gupta 222
    xhttp = new XMLHttpRequest();
223
    if (typeof loaderDialogObj != "undefined")
224
        loaderDialogObj.modal('show');
225
    xhttp.onreadystatechange = function () {
226
        var a;
227
        if (xhttp.readyState === 2) {
228
            if (xhttp.status == 200) {
229
                xhttp.responseType = "blob";
230
            } else {
231
                xhttp.responseType = "text";
232
            }
233
        } else if (xhttp.readyState === 4 && xhttp.status === 200) {
234
            // Trick for making downloadable link
235
            if (typeof loaderDialogObj != "undefined") {
236
                loaderDialogObj.modal('hide');
237
                // $('div.modal-backdrop.fade').remove();
238
            }
27355 tejbeer 239
 
32301 amit.gupta 240
            a = document.createElement('a');
241
            a.href = window.URL.createObjectURL(xhttp.response);
242
            // Give filename you wish to download
243
            a.download = fileName;
244
            a.style.display = 'none';
245
            document.body.appendChild(a);
246
            a.click();
247
        } else if (xhttp.readyState == 4 && xhttp.status === 400) {
248
            if (typeof loaderDialogObj != "undefined") {
249
                loaderDialogObj.modal('hide');
250
                // $('div.modal-backdrop.fade').remove();
251
            }
252
            badRequestAlert(xhttp);
253
        } else if (xhttp.readyState == 4 && xhttp.status === 500) {
254
            if (typeof loaderDialogObj != "undefined") {
255
                loaderDialogObj.modal('hide');
256
                // $('div.modal-backdrop.fade').remove();
257
            }
258
            internalServerErrorAlert(xhttp);
259
        }
260
    };
261
    // Post data to URL which handles post request
262
    xhttp.open(httpType, urlString);
263
    if (httpType == "POST") {
264
        xhttp.setRequestHeader("Content-Type", "application/json");
265
    }
266
    // You should set responseType as blob for binary responses
267
    // xhttp.responseType = 'blob';
268
    xhttp.send(data);
23405 amit.gupta 269
}
30017 amit.gupta 270
 
27618 tejbeer 271
function loadPaginatedCatalogNextItems(url, params, paginatedIdentifier,
32301 amit.gupta 272
                                       tableIdentifier, detailsContainerIdentifier) {
273
    var start = $("#" + paginatedIdentifier + " .start").text();
23405 amit.gupta 274
 
32301 amit.gupta 275
    var end = $("#" + paginatedIdentifier + " .end").text();
27618 tejbeer 276
 
32301 amit.gupta 277
    url = context + url + "?offset=" + end;
27618 tejbeer 278
 
32301 amit.gupta 279
    if (params != null) {
280
        for (var key in params) {
281
            if (params.hasOwnProperty(key)) {
282
                //console.log(key + " -> " + params[key]);
283
                url = url + "&" + key + "=" + params[key];
284
            }
285
        }
286
    }
27618 tejbeer 287
 
32301 amit.gupta 288
    doGetAjaxRequestHandler(url, function (response) {
289
        var size = $("#" + paginatedIdentifier + " .size").text();
290
        if ((parseInt(end) + 20) > parseInt(size)) {
291
            // console.log("(end + 10) > size == true");
292
            $("#" + paginatedIdentifier + " .end").text(size);
293
        } else {
294
            // console.log("(end + 10) > size == false");
295
            $("#" + paginatedIdentifier + " .end").text(+end + +20);
296
        }
297
        $("#" + paginatedIdentifier + " .start").text(+start + +20);
298
        var last = $("#" + paginatedIdentifier + " .end").text();
299
        var temp = $("#" + paginatedIdentifier + " .size").text();
300
        console.log("last" + last);
301
        if (parseInt(last) >= parseInt(temp)) {
302
            $("#" + paginatedIdentifier + " .next").prop('disabled', true);
303
            // $( "#good-inventory-paginated .end" ).text(temp);
304
        }
305
        $('#' + tableIdentifier).html(response);
306
        if (detailsContainerIdentifier != null) {
307
            $('#' + detailsContainerIdentifier).html('');
308
        }
309
        $("#" + paginatedIdentifier + " .previous").prop('disabled', false);
310
    });
27618 tejbeer 311
 
312
}
30017 amit.gupta 313
 
27618 tejbeer 314
function loadPaginatedCatalogPreviousItem(url, params, paginatedIdentifier,
32301 amit.gupta 315
                                          tableIdentifier, detailsContainerIdentifier) {
316
    var start = $("#" + paginatedIdentifier + " .start").text();
317
    console.log("start" + start);
318
    var end = $("#" + paginatedIdentifier + " .end").text();
319
    console.log("Startend" + end);
320
    var size = $("#" + paginatedIdentifier + " .size").text();
321
    console.log("size" + size);
322
    if (parseInt(end) == parseInt(size) && parseInt(end) % 20 != 0) {
323
        var mod = parseInt(end) % 20;
324
        end = parseInt(end) + (20 - mod);
325
    }
326
    var pre = end - 20;
327
    var lat = pre - 20;
328
    //console.log("preCatalog" +pre);
27618 tejbeer 329
 
32301 amit.gupta 330
    url = context + url + "?offset=" + pre;
27618 tejbeer 331
 
32301 amit.gupta 332
    if (params != null) {
333
        for (var key in params) {
334
            if (params.hasOwnProperty(key)) {
335
                url = url + "&" + key + "=" + params[key];
336
            }
337
        }
338
    }
27618 tejbeer 339
 
32301 amit.gupta 340
    doGetAjaxRequestHandler(url, function (response) {
341
        $("#" + paginatedIdentifier + " .end").text(+end - +20);
342
        $("#" + paginatedIdentifier + " .start").text(+start - +20);
343
        $('#' + tableIdentifier).html(response);
344
        if (detailsContainerIdentifier != null) {
345
            $('#' + detailsContainerIdentifier).html('');
346
        }
347
        $("#" + paginatedIdentifier + " .next").prop('disabled', false);
348
        if (parseInt(lat) == 0) {
349
            $("#" + paginatedIdentifier + " .previous").prop('disabled', true);
350
        }
351
    });
27618 tejbeer 352
 
353
}
354
 
24595 tejbeer 355
function loadPaginatedNextItems(url, params, paginatedIdentifier,
32301 amit.gupta 356
                                tableIdentifier, detailsContainerIdentifier) {
357
    var start = $("#" + paginatedIdentifier + " .start").text();
358
    var end = $("#" + paginatedIdentifier + " .end").text();
359
    url = context + url + "?offset=" + end;
24595 tejbeer 360
 
32301 amit.gupta 361
    if (params != null) {
362
        for (var key in params) {
363
            if (params.hasOwnProperty(key)) {
364
                // console.log(key + " -> " + p[key]);
365
                url = url + "&" + key + "=" + params[key];
366
            }
367
        }
368
    }
24595 tejbeer 369
 
32301 amit.gupta 370
    doGetAjaxRequestHandler(url, function (response) {
371
        var size = $("#" + paginatedIdentifier + " .size").text();
372
        if ((parseInt(end) + 10) > parseInt(size)) {
373
            console.log("(end + 10) > size == true");
374
            $("#" + paginatedIdentifier + " .end").text(size);
375
        } else {
376
            console.log("(end + 10) > size == false");
377
            $("#" + paginatedIdentifier + " .end").text(+end + +10);
378
        }
379
        $("#" + paginatedIdentifier + " .start").text(+start + +10);
380
        var last = $("#" + paginatedIdentifier + " .end").text();
381
        var temp = $("#" + paginatedIdentifier + " .size").text();
382
        if (parseInt(last) >= parseInt(temp)) {
383
            $("#" + paginatedIdentifier + " .next").prop('disabled', true);
384
            // $( "#good-inventory-paginated .end" ).text(temp);
385
        }
386
        $('#' + tableIdentifier).html(response);
387
        if (detailsContainerIdentifier != null) {
388
            $('#' + detailsContainerIdentifier).html('');
389
        }
390
        $("#" + paginatedIdentifier + " .previous").prop('disabled', false);
391
    });
24595 tejbeer 392
 
23629 ashik.ali 393
}
23405 amit.gupta 394
 
24595 tejbeer 395
function loadPaginatedPreviousItems(url, params, paginatedIdentifier,
32301 amit.gupta 396
                                    tableIdentifier, detailsContainerIdentifier) {
397
    var start = $("#" + paginatedIdentifier + " .start").text();
398
    var end = $("#" + paginatedIdentifier + " .end").text();
399
    var size = $("#" + paginatedIdentifier + " .size").text();
400
    if (parseInt(end) == parseInt(size) && parseInt(end) % 10 != 0) {
401
        var mod = parseInt(end) % 10;
402
        end = parseInt(end) + (10 - mod);
403
    }
404
    var pre = end - 10;
24595 tejbeer 405
 
32301 amit.gupta 406
    url = context + url + "?offset=" + pre;
24595 tejbeer 407
 
32301 amit.gupta 408
    if (params != null) {
409
        for (var key in params) {
410
            if (params.hasOwnProperty(key)) {
411
                url = url + "&" + key + "=" + params[key];
412
            }
413
        }
414
    }
24595 tejbeer 415
 
32301 amit.gupta 416
    doGetAjaxRequestHandler(url, function (response) {
417
        $("#" + paginatedIdentifier + " .end").text(+end - +10);
418
        $("#" + paginatedIdentifier + " .start").text(+start - +10);
419
        $('#' + tableIdentifier).html(response);
420
        if (detailsContainerIdentifier != null) {
421
            $('#' + detailsContainerIdentifier).html('');
422
        }
423
        $("#" + paginatedIdentifier + " .next").prop('disabled', false);
424
        if (parseInt(pre) == 0) {
425
            $("#" + paginatedIdentifier + " .previous").prop('disabled', true);
426
        }
427
    });
24595 tejbeer 428
 
23629 ashik.ali 429
}
430
 
32308 amit.gupta 431
function numberToComma(x, rounded) {
32301 amit.gupta 432
    if (isNaN(x)) {
433
        x = x.replaceAll(",", '');
434
    }
435
    x = parseFloat(x);
32308 amit.gupta 436
    if (typeof rounded != "undefined" && rounded) {
437
        x = Math.round(x);
438
    } else {
439
        x = Math.round(x * 100) / 100;
440
    }
32301 amit.gupta 441
    x = x.toString();
442
    x = x.split('.');
443
    var x1 = x[0];
444
    var x2 = x.length > 1 && x[1] != '0' ? '.' + x[1] : '';
445
    var lastThree = x1.substring(x1.length - 3);
446
    var otherNumbers = x1.substring(0, x1.length - 3);
447
    if (x1.charAt(x1.length - 4) == ',' || x1.charAt(x1.length - 4) == '-') {
448
        console.log(lastThree)
449
    } else {
450
        if (otherNumbers != '')
451
            lastThree = ',' + lastThree;
452
    }
453
    return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + (lastThree)
454
        + x2;
24992 tejbeer 455
 
23786 amit.gupta 456
}
23870 amit.gupta 457
 
30599 amit.gupta 458
function getSingleDatePicker(startMoment) {
32301 amit.gupta 459
    var singleDatePicker = {
460
        "todayHighlight": true,
461
        "startDate": startMoment || moment(),
462
        "autoclose": true,
463
        "autoUpdateInput": true,
464
        "singleDatePicker": true,
465
        "locale": {
466
            'format': 'DD/MM/YYYY'
467
        }
468
    };
469
    return singleDatePicker;
23886 amit.gupta 470
}
471
 
30599 amit.gupta 472
function getDatesFromPicker(pickerElement) {
32301 amit.gupta 473
    return {
474
        startDate: $(pickerElement).data('daterangepicker').startDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS),
475
        endDate: $(pickerElement).data('daterangepicker').endDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS)
476
    }
30599 amit.gupta 477
}
478
 
479
function getReporticoDatesFromPicker(pickerElement) {
32301 amit.gupta 480
    let datePickerData = $(pickerElement).data('daterangepicker');
481
    let formattedEndDate = null;
482
    if (typeof datePickerData.endDate == "object") {
483
        formattedEndDate = datePickerData.endDate.format(moment.HTML5_FMT.DATE);
484
    }
485
    return {
486
        startDate: datePickerData.startDate.format(moment.HTML5_FMT.DATE),
487
        endDate: formattedEndDate
488
    };
30599 amit.gupta 489
}
490
 
491
 
492
function getRangedDatePicker(showRanges, startMoment, endMoment) {
32301 amit.gupta 493
    if (typeof showRanges == "undefined") {
494
        showRanges = false;
495
    }
496
    var rangedDatePicker = {
497
        "todayHighlight": true,
498
        "opens": "right",
499
        "startDate": startMoment || moment().startOf('day'),
500
        "endDate": endMoment || moment().endOf('day'),
501
        "autoclose": true,
502
        "alwaysShowCalendars": false,
503
        "autoUpdateInput": true,
504
        "locale": {
505
            'format': 'DD/MM/YYYY'
506
        }
507
    };
508
    if (showRanges) {
509
        rangedDatePicker['ranges'] = {
510
            'Today': [moment(), moment()],
511
            'Yesterday': [moment().subtract(1, 'days'),
512
                moment().subtract(1, 'days')],
513
            'Last 7 Days': [moment().subtract(6, 'days'), moment()],
514
            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
515
            'This Month': [moment().startOf('month'), moment().endOf('month')],
516
            'Last Month': [moment().subtract(1, 'month').startOf('month'),
517
                moment()],
518
            'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
519
                moment()],
520
            'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
521
                moment()]
522
        }
523
    }
524
    return rangedDatePicker;
23892 amit.gupta 525
}
30017 amit.gupta 526
 
23946 amit.gupta 527
function showPosition(position) {
32301 amit.gupta 528
    if (typeof latitude == "undefined") {
529
        var coords = {
530
            latitude: position.coords.latitude,
531
            longitude: position.coords.longitude
532
        }
533
        doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
534
            .stringify(coords), function () {
535
            latitude = position.coords.latitude;
536
            longitude = position.coords.longitude;
537
        });
538
    }
539
    // distance = getDistance(latitude, longitude, position.coords.latitude,
540
    // position.coords.longitude);
24168 amit.gupta 541
}
542
 
24595 tejbeer 543
function getAuthorisedWarehouses(callback) {
32301 amit.gupta 544
    bootBoxObj = {
545
        size: "small",
546
        title: "Choose Warehouse",
547
        callback: callback,
548
        inputType: 'select',
549
        inputOptions: typeof inputOptions == "undefined" ? undefined
550
            : inputOptions
551
    }
552
    if (typeof inputOptions == "undefined") {
553
        doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
554
            response) {
555
            response = JSON.parse(response);
556
            inputOptions = [];
557
            response.forEach(function (warehouse) {
558
                inputOptions.push({
559
                    text: warehouse.name,
560
                    value: warehouse.id,
561
                });
562
            });
563
            bootBoxObj['inputOptions'] = inputOptions;
564
            bootbox.prompt(bootBoxObj);
565
        });
566
    } else if (inputOptions.length == 1) {
567
        callback(inputOptions[0].warehouse.id);
568
    } else {
569
        bootbox.prompt(bootBoxObj);
570
    }
24595 tejbeer 571
 
24176 amit.gupta 572
}
30017 amit.gupta 573
 
24410 amit.gupta 574
function getColorsForItems(catalogId, itemId, description, callback) {
32301 amit.gupta 575
    colorCheckboxHandler(catalogId, itemId, description, callback);
30017 amit.gupta 576
}
577
 
578
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
32301 amit.gupta 579
    doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
580
        + catalogId + "&itemId=" + itemId, function (response) {
581
        let coloredItems = JSON.parse(response);
582
        let modalBody = [];
583
        coloredItems.forEach(function (item) {
584
            modalBody.push(`
30017 amit.gupta 585
                <div class="row">
586
                    <div class="col-sm-2">
587
                        ${item.color}
588
                    </div>
589
                    <div class="col-sm-2">
590
                            <input data-itemid="${item.id}" type="text" class="form-control" />
591
                    </div>
592
                </div>
593
            `);
32301 amit.gupta 594
        });
595
        let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
30017 amit.gupta 596
                              <div class="modal-dialog" >
597
                                <div class="modal-content">
598
                                  <div class="modal-header">
599
                                    <h5 class="modal-title">${title}</h5>
600
                                  </div>
601
                                  <div class="modal-body">
602
                                        ${modalBody.join('')}
603
                                  </div>
604
                                  <div class="modal-footer">
605
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
606
                                  </div>
607
                                </div>
608
                              </div>
609
                            </div>`;
32301 amit.gupta 610
        let $dialog = $(dialogBoxHtml);
611
        let modalObj = $dialog.modal('show');
612
        modalObj.on('hidden.bs.modal', function (e) {
613
            $dialog.remove();
614
        });
615
        $('button.number_dialog').on('click', function () {
616
            let itemQty = [];
617
            let anySelected = false;
618
            $(modalObj).find('.modal-body').find('input').each(function () {
619
                $input = $(this);
620
                if ($input.val() > 0) {
621
                    itemQty.push({
622
                        itemId: $input.data("itemid"),
623
                        quantity: $input.val()
624
                    });
625
                    anySelected = true;
626
                }
627
            });
628
            if (anySelected && confirm("Are you sure want to notify?")) {
629
                $that = $(this);
630
                callback(itemQty, function () {
631
                    $that.off('click');
632
                    modalObj.hide();
633
                });
634
            } else {
635
                alert("Pls mention quantity");
636
            }
637
        });
638
    });
30017 amit.gupta 639
}
640
 
641
 
30021 amit.gupta 642
function colorCheckboxHandler(catalogId, itemId, description, callback) {
32301 amit.gupta 643
    let bootBoxObj = {
644
        size: "small",
645
        className: "item-wrapper",
646
        title: description,
647
        callback: callback,
648
        inputType: 'checkbox',
649
    }
650
    doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
651
        + catalogId + "&itemId=" + itemId, function (response) {
652
        coloredItems = JSON.parse(response);
653
        inputOptions = [{
654
            text: "All",
655
            value: "0",
656
            onclick: "toggleAll('itemIds')"
657
        }];
658
        coloredItems.forEach(function (item) {
659
            inputOptions.push({
660
                text: item.color,
661
                value: item.id,
662
                selected: item.active
663
            });
664
        });
665
        bootBoxObj['inputOptions'] = inputOptions;
666
        promptObj = bootbox.prompt(bootBoxObj);
667
        promptObj.modal('show')
668
        $('.item-wrapper').find("input[type='checkbox']").slice(1).each(
669
            function (index, checkbox) {
670
                checkbox.checked = coloredItems[index].active;
671
            });
672
    });
24406 amit.gupta 673
}
28055 tejbeer 674
 
675
function getHotdealsForItems(catalogId, itemId, description, callback) {
32301 amit.gupta 676
    bootBoxObj = {
677
        size: "small",
678
        className: "item-wrapper",
679
        title: description,
680
        callback: callback,
681
        inputType: 'checkbox',
682
    }
683
    doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
684
        + catalogId + "&itemId=" + itemId, function (response) {
685
        coloredItems = JSON.parse(response);
686
        inputOptions = [{
687
            text: "All",
688
            value: "0",
689
            onclick: "toggleAll('itemIds')"
690
        }];
691
        coloredItems.forEach(function (item) {
692
            inputOptions.push({
693
                text: item.color,
694
                value: item.id,
695
                selected: item.hotDeals
696
            });
697
        });
698
        bootBoxObj['inputOptions'] = inputOptions;
699
        promptObj = bootbox.prompt(bootBoxObj);
700
        promptObj.modal('show')
701
        $('.item-wrapper').find("input[type='checkbox']").slice(1).each(
702
            function (index, checkbox) {
703
                checkbox.checked = coloredItems[index].hotDeals;
704
            });
705
    });
28055 tejbeer 706
}
30017 amit.gupta 707
 
27763 tejbeer 708
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
32301 amit.gupta 709
    function () {
710
        if (this.value == "0") {
711
            $(this).closest('.item-wrapper').find("input[type='checkbox']")
712
                .slice(1).prop('checked', $(this).prop('checked'));
713
        }
714
    });
30017 amit.gupta 715
 
27618 tejbeer 716
function getItemAheadOptions(jqElement, anyColor, callback) {
32301 amit.gupta 717
    console.log(anyColor)
718
    jqElement.typeahead('destroy').typeahead({
719
        source: function (q, process) {
720
            if (q.length >= 3) {
721
                return $.ajax(context + "/item?anyColor=" + anyColor, {
722
                    global: false,
723
                    data: {
724
                        query: q
725
                    },
726
                    success: function (data) {
727
                        queryData = JSON.parse(data);
728
                        process(queryData);
729
                    },
730
                });
731
            }
732
        },
733
        delay: 300,
734
        items: 20,
735
        displayText: function (item) {
736
            return item.itemDescription;
737
        },
738
        autoSelect: true,
739
        afterSelect: callback
740
    });
24176 amit.gupta 741
}
28795 tejbeer 742
 
743
 
32195 tejbeer 744
function getVendorItemAheadOptions(jqElement, vendorId, callback) {
32301 amit.gupta 745
    jqElement.typeahead('destroy').typeahead({
746
        source: function (q, process) {
747
            if (q.length >= 3) {
748
                return $.ajax(context + "/vendorItem?vendorId=" + vendorId, {
749
                    global: false,
750
                    data: {
751
                        query: q
752
                    },
753
                    success: function (data) {
754
                        queryData = JSON.parse(data);
755
                        process(queryData);
756
                    },
757
                });
758
            }
759
        },
760
        delay: 300,
761
        items: 20,
762
        displayText: function (item) {
763
            return item.itemDescription;
764
        },
765
        autoSelect: true,
766
        afterSelect: callback
767
    });
32195 tejbeer 768
}
769
 
28795 tejbeer 770
function getImeiAheadOptions(jqElement, fofoId, callback) {
32301 amit.gupta 771
    jqElement.typeahead('destroy').typeahead({
772
            source: function (q, process) {
773
                if (q.length >= 3) {
774
                    return $.ajax(context + "/imei?fofoId=" + fofoId, {
775
                        global: false,
776
                        data: {
777
                            query: q
778
                        },
779
                        success: function (data) {
780
                            queryData = JSON.parse(data);
781
                            process(queryData);
782
                        },
783
                    });
784
                }
785
            },
786
            delay: 300,
787
            items: 20,
788
            displayText: function (imei) {
789
                return imei;
790
            },
791
            autoSelect: true,
792
            afterSelect: callback
793
        }
794
    );
31762 tejbeer 795
}
796
 
797
 
798
function getAllImeiAheadOptions(jqElement, callback) {
32301 amit.gupta 799
    jqElement.typeahead('destroy').typeahead({
800
        source: function (q, process) {
801
            if (q.length >= 3) {
802
                return $.ajax(context + "/allimei", {
803
                    global: false,
804
                    data: {
805
                        query: q
806
                    },
807
                    success: function (data) {
808
                        queryData = JSON.parse(data);
809
                        process(queryData);
810
                    },
811
                });
812
            }
813
        },
814
        delay: 300,
815
        items: 20,
816
        displayText: function (imei) {
817
            return imei;
818
        },
819
        autoSelect: true,
820
        afterSelect: callback
821
    });
28795 tejbeer 822
}
823
 
824
 
25394 amit.gupta 825
function getEntityAheadOptions(jqElement, callback) {
32301 amit.gupta 826
    jqElement.typeahead('destroy').typeahead({
827
        source: function (q, process) {
828
            if (q.length >= 3) {
829
                return $.ajax(context + "/entity", {
830
                    global: false,
831
                    data: {
832
                        query: q
833
                    },
834
                    success: function (data) {
835
                        queryData = JSON.parse(data);
836
                        process(queryData);
837
                    },
838
                });
839
            }
840
        },
841
        delay: 300,
842
        items: 30,
843
        displayText: function (entity) {
844
            return entity.title_s + "(" + entity.catalogId_i + ")";
845
        },
846
        autoSelect: true,
847
        afterSelect: callback
848
    });
25394 amit.gupta 849
}
30017 amit.gupta 850
 
24349 amit.gupta 851
function getPartnerAheadOptions(jqElement, callback) {
32301 amit.gupta 852
    jqElement.typeahead('destroy').typeahead({
853
        source: function (q, process) {
854
            if (q.length >= 3) {
855
                return $.ajax(context + "/partners", {
856
                    global: false,
857
                    data: {
858
                        query: q
859
                    },
860
                    success: function (data) {
861
                        queryData = JSON.parse(data);
862
                        process(queryData);
863
                    },
864
                });
865
            }
866
        },
867
        delay: 300,
868
        items: 20,
869
        displayText: function (partner) {
870
            return partner.displayName;
871
        },
872
        autoSelect: true,
873
        afterSelect: callback
874
    });
24349 amit.gupta 875
}
24406 amit.gupta 876
 
32074 tejbeer 877
function getVendorAheadOptions(jqElement, callback) {
32301 amit.gupta 878
    jqElement.typeahead('destroy').typeahead({
879
        source: function (q, process) {
880
            if (q.length >= 3) {
881
                return $.ajax(context + "/vendors", {
882
                    global: false,
883
                    data: {
884
                        query: q
885
                    },
886
                    success: function (data) {
887
                        queryData = JSON.parse(data);
888
                        process(queryData);
889
                    },
890
                });
891
            }
892
        },
893
        delay: 300,
894
        items: 20,
895
        displayText: function (vendor) {
896
            return vendor.name;
897
        },
898
        autoSelect: true,
899
        afterSelect: callback
900
    });
32074 tejbeer 901
}
902
 
24595 tejbeer 903
function loadPriceDrop(domId) {
32301 amit.gupta 904
    doGetAjaxRequestHandler(context + "/getItemDescription",
905
        function (response) {
906
            $('#' + domId).html(response);
907
        });
24406 amit.gupta 908
}
30017 amit.gupta 909
 
32301 amit.gupta 910
$(document).on('click', ".price_drop", function () {
911
    loadPriceDrop("main-content");
24595 tejbeer 912
});
25649 tejbeer 913
 
27618 tejbeer 914
 
32301 amit.gupta 915
$(document).on('click', ".closed_pricedrop", function () {
916
    loadClosedPriceDrop("main-content");
28569 amit.gupta 917
});
918
 
919
function loadClosedPriceDrop(domId) {
32301 amit.gupta 920
    doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
921
        function (response) {
922
            $('#' + domId).html(response);
923
        });
28569 amit.gupta 924
}
925
 
27696 tejbeer 926
function notifyTypeChange(messageType, $container) {
32301 amit.gupta 927
    var messageQueryString = "?messageType=" + messageType;
928
    if (messageType == null) {
929
        messageQueryString = "";
930
    }
931
    doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function (response) {
932
        if ($container != null) {
933
            loaderDialogObj.one('hidden.bs.modal', function () {
934
                $container.popover({
935
                    container: $container,
936
                    template: '<div class="popover popover1" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popover2"></div></div>',
937
                    content: response,
938
                    html: true,
939
                    placement: "bottom",
940
                    trigger: "manual",
941
                    sanitize: false
942
                }).popover('show');
943
                setTimeout(function () {
944
                    $container.focus().one('blur', function () {
945
                        $container.popover('destroy');
946
                    });
947
                }, 100);
948
            });
949
        }
950
    });
25649 tejbeer 951
}
25651 tejbeer 952
 
25689 amit.gupta 953
function downloadNotifyDocument(documentId, cid, documentName) {
32301 amit.gupta 954
    doAjaxGetDownload(context + "/notifyDocument/download?cid=" + cid,
955
        documentName);
25651 tejbeer 956
}
28051 amit.gupta 957
 
958
 
959
/* Create an array with the values of all the input boxes in a column */
32301 amit.gupta 960
$.fn.dataTable.ext.order['dom-text'] = function (settings, col) {
961
    return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
962
        return $('input', td).val();
963
    });
28051 amit.gupta 964
}
28795 tejbeer 965
 
28063 amit.gupta 966
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
32301 amit.gupta 967
$.fn.dataTable.ext.order['dom-text-numeric'] = function (settings, col) {
968
    return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
969
        return $('input', td).val() * 1;
970
    });
28051 amit.gupta 971
}
28795 tejbeer 972
 
32301 amit.gupta 973
$.fn.dataTable.ext.order['dom-stock-numeric'] = function (settings, col) {
974
    return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
975
        return $(td).html().split("/")[0] * 1;
976
    });
28870 tejbeer 977
}
28051 amit.gupta 978
/* Create an array with the values of all the select options in a column */
32301 amit.gupta 979
$.fn.dataTable.ext.order['dom-select'] = function (settings, col) {
980
    return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
981
        return $('select', td).val();
982
    });
28051 amit.gupta 983
}
28795 tejbeer 984
 
28051 amit.gupta 985
/* Create an array with the values of all the checkboxes in a column */
32301 amit.gupta 986
$.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
987
    return this.api().column(col, {
988
        order: 'index'
989
    }).nodes().map(function (td, i) {
990
        return $('input', td).prop('checked') ? '1' : '0';
991
    });
30414 amit.gupta 992
}
993
 
32301 amit.gupta 994
$.fn.dataTable.Api.register('sum()', function () {
995
    return this.flatten().reduce(function (a, b) {
996
        if (typeof a === 'string') {
997
            a = a.replace(/[^\d.-]/g, '') * 1;
998
            a = isNaN(a) ? 0 : a;
999
        }
1000
        if (typeof b === 'string') {
1001
            b = b.replace(/[^\d.-]/g, '') * 1;
1002
            b = isNaN(b) ? 0 : b;
1003
        }
30414 amit.gupta 1004
 
32301 amit.gupta 1005
        return a + b;
1006
    }, 0);
30694 amit.gupta 1007
});
1008
 
1009
const debounce = (func, delay) => {
32301 amit.gupta 1010
    let debounceTimer
1011
    return function () {
1012
        const context = this
1013
        const args = arguments
1014
        clearTimeout(debounceTimer)
1015
        debounceTimer
1016
            = setTimeout(() => func.apply(context, args), delay)
1017
    }
30694 amit.gupta 1018
}
31687 amit.gupta 1019
 
32301 amit.gupta 1020
function parseDate(str) {
1021
    var m = str.match(/^(\d{1,2})[-/](\d{1,2})[-/](\d{4})$/);
1022
    return (m) ? new Date(m[3], m[2] - 1, m[1]) : null;
1023
}
31687 amit.gupta 1024
 
32130 amit.gupta 1025
function ExportToExcel(container, fn) {
32301 amit.gupta 1026
    let tableId = $(container).data('tableid');
1027
    var elt = document.getElementById(tableId);
32826 shampa 1028
    console.log('elt',elt);
32301 amit.gupta 1029
    if ($.fn.DataTable.isDataTable(`#${tableId}`)) {
32826 shampa 1030
       let dataTable = $(`#${tableId}`).DataTable();
1031
               dataTable.page.len(-1).draw();
1032
               elt = dataTable.table(0).container();
32301 amit.gupta 1033
    }
1034
    ExportTableToExcel(elt, fn);
31687 amit.gupta 1035
}
1036
 
32301 amit.gupta 1037
function ExportTableToExcel(tableElt, fn) {
1038
    $table = $(tableElt)
1039
    $table.find('td').each((index, value) => {
1040
        let $tdElement = $(value);
1041
        console.log($tdElement);
1042
        let parsedDate = parseDate($tdElement.html());
1043
        if (parsedDate != null) {
1044
            let days = Math.floor(parsedDate.getTime() / 86400 * 1000);
1045
            $tdElement.data('v', days);
1046
            $tdElement.data("t", "n");
1047
            $tdElement.data("z", "yyyy-mm-dd");
1048
        }
1049
    });
1050
    console.log($table.get(0))
1051
    var wb = XLSX.utils.table_to_book($table.get(0), {sheet: "sheet1"});
1052
    XLSX.writeFile(wb, fn + '.xlsx');
1053
}
31687 amit.gupta 1054
 
32301 amit.gupta 1055
 
1056
$(document).on('click', ".manage-pcm", function () {
1057
    managePCM();
31687 amit.gupta 1058
});
1059
 
1060
function managePCM() {
32301 amit.gupta 1061
    doGetAjaxRequestHandler(`${context}/brand-pcm`, function (response) {
1062
        $('#main-content').html(response);
1063
    });
31687 amit.gupta 1064
}
31786 tejbeer 1065
 
1066
 
32301 amit.gupta 1067
$(document).on('click', ".digify-retailer-login", function () {
31786 tejbeer 1068
 
32301 amit.gupta 1069
    doGetAjaxRequestHandler(context + "/digify/register", function (response) {
32074 tejbeer 1070
 
1071
 
32301 amit.gupta 1072
        $('#main-content').html(response);
32074 tejbeer 1073
 
32301 amit.gupta 1074
    });
1075
    //$('#main-content').html(`<iframe class="wrapper" src="${context}/digify/register" style="width:100%;height:100vh"> </iframe>`);
1076
    //$('#main-content').html(`<a class="wrapper" href="${context}/digify/register" target="_blank" style="width:100%;height:100vh"> </a>`);
32074 tejbeer 1077
 
31786 tejbeer 1078
});
31878 tejbeer 1079
 
32301 amit.gupta 1080
$(document).on('click', '.warehousewise_stock', function () {
1081
    doGetAjaxRequestHandler(`${context}/warehouse/stock-qty`, function (response) {
1082
        $('#main-content').html(response);
1083
    });
32130 amit.gupta 1084
});
31878 tejbeer 1085
 
32567 tejbeer 1086
function loadMainContent(htmlContent) {
1087
    $('#main-content').html(htmlContent);
1088
}
31878 tejbeer 1089
 
1090
 
32979 amit.gupta 1091
function jsonStartDate(dateInputString) {
1092
    if(dateInputString === '') return null;
33141 amit.gupta 1093
    return moment(dateInputString, "yyyy-MM-DD").format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
32979 amit.gupta 1094
}
1095
function jsonEndDate(dateInputString) {
1096
    if(dateInputString === '') return null;
33141 amit.gupta 1097
    return moment(dateInputString, "yyyy-MM-DD").endOf('day').format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
32979 amit.gupta 1098
}
31878 tejbeer 1099
 
1100
 
32130 amit.gupta 1101
 
32567 tejbeer 1102
 
32979 amit.gupta 1103