Subversion Repositories SmartDukaan

Rev

Rev 33220 | Rev 33508 | 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
 
33220 amit.gupta 491
function getStartOfFinancialYear(momentObj) {
492
    recentQuarter = momentObj.startOf('quarter').set('quarter', 2);
493
    return momentObj.quarter >= 2 ? recentQuarter : recentQuarter.subtract('year', 1);
494
}
30599 amit.gupta 495
 
33220 amit.gupta 496
function getStatementRanges() {
497
    return {
498
        ranges: {
499
            'This Month': [moment().startOf('month'), moment().startOf('day')],
500
            'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1,'month').endOf('month')],
501
            'Last 3 Months': [moment().subtract(3, 'month').startOf('month'), moment().subtract(1,'month').endOf('month')],
502
            'Last 6 Months': [moment().subtract(6, 'month').startOf('month'), moment().subtract(1,'month').endOf('month')],
503
            'Current Financial Year': [getStartOfFinancialYear(moment()), getStartOfFinancialYear(moment()).add('year', 1).subtract(1, 'day')],
504
            'Last Financial Year': [getStartOfFinancialYear(moment()).subtract('year', 1), getStartOfFinancialYear(moment()).subtract(1, 'day')]
505
        },
506
        alwaysShowCalendars: false,
507
        showCustomRangeLabel: false,
508
        showDropdowns: true,
509
        locale: {
510
            format: 'DD/MM/YYYY'
511
        }
512
    }
513
}
514
 
30599 amit.gupta 515
function getRangedDatePicker(showRanges, startMoment, endMoment) {
32301 amit.gupta 516
    if (typeof showRanges == "undefined") {
517
        showRanges = false;
518
    }
519
    var rangedDatePicker = {
520
        "todayHighlight": true,
33220 amit.gupta 521
        "showDropdowns": true,
32301 amit.gupta 522
        "opens": "right",
523
        "startDate": startMoment || moment().startOf('day'),
524
        "endDate": endMoment || moment().endOf('day'),
525
        "autoclose": true,
526
        "alwaysShowCalendars": false,
527
        "autoUpdateInput": true,
528
        "locale": {
529
            'format': 'DD/MM/YYYY'
530
        }
531
    };
532
    if (showRanges) {
533
        rangedDatePicker['ranges'] = {
534
            'Today': [moment(), moment()],
535
            'Yesterday': [moment().subtract(1, 'days'),
536
                moment().subtract(1, 'days')],
537
            'Last 7 Days': [moment().subtract(6, 'days'), moment()],
538
            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
539
            'This Month': [moment().startOf('month'), moment().endOf('month')],
540
            'Last Month': [moment().subtract(1, 'month').startOf('month'),
541
                moment()],
542
            'Last 3 Months': [moment().subtract(3, 'month').startOf('month'),
543
                moment()],
544
            'Last 6 Months': [moment().subtract(6, 'month').startOf('month'),
545
                moment()]
546
        }
547
    }
548
    return rangedDatePicker;
23892 amit.gupta 549
}
30017 amit.gupta 550
 
23946 amit.gupta 551
function showPosition(position) {
32301 amit.gupta 552
    if (typeof latitude == "undefined") {
553
        var coords = {
554
            latitude: position.coords.latitude,
555
            longitude: position.coords.longitude
556
        }
557
        doAjaxRequestWithJsonHandler('partner/location', 'PUT', JSON
558
            .stringify(coords), function () {
559
            latitude = position.coords.latitude;
560
            longitude = position.coords.longitude;
561
        });
562
    }
563
    // distance = getDistance(latitude, longitude, position.coords.latitude,
564
    // position.coords.longitude);
24168 amit.gupta 565
}
566
 
24595 tejbeer 567
function getAuthorisedWarehouses(callback) {
32301 amit.gupta 568
    bootBoxObj = {
569
        size: "small",
570
        title: "Choose Warehouse",
571
        callback: callback,
572
        inputType: 'select',
573
        inputOptions: typeof inputOptions == "undefined" ? undefined
574
            : inputOptions
575
    }
576
    if (typeof inputOptions == "undefined") {
577
        doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
578
            response) {
579
            response = JSON.parse(response);
580
            inputOptions = [];
581
            response.forEach(function (warehouse) {
582
                inputOptions.push({
583
                    text: warehouse.name,
584
                    value: warehouse.id,
585
                });
586
            });
587
            bootBoxObj['inputOptions'] = inputOptions;
588
            bootbox.prompt(bootBoxObj);
589
        });
590
    } else if (inputOptions.length == 1) {
591
        callback(inputOptions[0].warehouse.id);
592
    } else {
593
        bootbox.prompt(bootBoxObj);
594
    }
24595 tejbeer 595
 
24176 amit.gupta 596
}
30017 amit.gupta 597
 
24410 amit.gupta 598
function getColorsForItems(catalogId, itemId, description, callback) {
32301 amit.gupta 599
    colorCheckboxHandler(catalogId, itemId, description, callback);
30017 amit.gupta 600
}
601
 
602
function colorNumberHandler(catalogId, itemId, title, actionText, callback) {
32301 amit.gupta 603
    doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
604
        + catalogId + "&itemId=" + itemId, function (response) {
605
        let coloredItems = JSON.parse(response);
606
        let modalBody = [];
607
        coloredItems.forEach(function (item) {
608
            modalBody.push(`
30017 amit.gupta 609
                <div class="row">
610
                    <div class="col-sm-2">
611
                        ${item.color}
612
                    </div>
613
                    <div class="col-sm-2">
614
                            <input data-itemid="${item.id}" type="text" class="form-control" />
615
                    </div>
616
                </div>
617
            `);
32301 amit.gupta 618
        });
619
        let dialogBoxHtml = `<div class="modal modal" tabindex="-1" role="dialog">
30017 amit.gupta 620
                              <div class="modal-dialog" >
621
                                <div class="modal-content">
622
                                  <div class="modal-header">
623
                                    <h5 class="modal-title">${title}</h5>
624
                                  </div>
625
                                  <div class="modal-body">
626
                                        ${modalBody.join('')}
627
                                  </div>
628
                                  <div class="modal-footer">
629
                                    <button type="button" class="btn btn-primary number_dialog">${actionText}</button>
630
                                  </div>
631
                                </div>
632
                              </div>
633
                            </div>`;
32301 amit.gupta 634
        let $dialog = $(dialogBoxHtml);
635
        let modalObj = $dialog.modal('show');
636
        modalObj.on('hidden.bs.modal', function (e) {
637
            $dialog.remove();
638
        });
639
        $('button.number_dialog').on('click', function () {
640
            let itemQty = [];
641
            let anySelected = false;
642
            $(modalObj).find('.modal-body').find('input').each(function () {
643
                $input = $(this);
644
                if ($input.val() > 0) {
645
                    itemQty.push({
646
                        itemId: $input.data("itemid"),
647
                        quantity: $input.val()
648
                    });
649
                    anySelected = true;
650
                }
651
            });
652
            if (anySelected && confirm("Are you sure want to notify?")) {
653
                $that = $(this);
654
                callback(itemQty, function () {
655
                    $that.off('click');
656
                    modalObj.hide();
657
                });
658
            } else {
659
                alert("Pls mention quantity");
660
            }
661
        });
662
    });
30017 amit.gupta 663
}
664
 
665
 
30021 amit.gupta 666
function colorCheckboxHandler(catalogId, itemId, description, callback) {
32301 amit.gupta 667
    let bootBoxObj = {
668
        size: "small",
669
        className: "item-wrapper",
670
        title: description,
671
        callback: callback,
672
        inputType: 'checkbox',
673
    }
674
    doGetAjaxRequestHandler(context + "/itemsByCatalogId?catalogId="
675
        + catalogId + "&itemId=" + itemId, function (response) {
676
        coloredItems = JSON.parse(response);
677
        inputOptions = [{
678
            text: "All",
679
            value: "0",
680
            onclick: "toggleAll('itemIds')"
681
        }];
682
        coloredItems.forEach(function (item) {
683
            inputOptions.push({
684
                text: item.color,
685
                value: item.id,
686
                selected: item.active
687
            });
688
        });
689
        bootBoxObj['inputOptions'] = inputOptions;
690
        promptObj = bootbox.prompt(bootBoxObj);
691
        promptObj.modal('show')
692
        $('.item-wrapper').find("input[type='checkbox']").slice(1).each(
693
            function (index, checkbox) {
694
                checkbox.checked = coloredItems[index].active;
695
            });
696
    });
24406 amit.gupta 697
}
28055 tejbeer 698
 
699
function getHotdealsForItems(catalogId, itemId, description, callback) {
32301 amit.gupta 700
    bootBoxObj = {
701
        size: "small",
702
        className: "item-wrapper",
703
        title: description,
704
        callback: callback,
705
        inputType: 'checkbox',
706
    }
707
    doGetAjaxRequestHandler(context + "/hotdealsitemsByCatalogId?catalogId="
708
        + catalogId + "&itemId=" + itemId, function (response) {
709
        coloredItems = JSON.parse(response);
710
        inputOptions = [{
711
            text: "All",
712
            value: "0",
713
            onclick: "toggleAll('itemIds')"
714
        }];
715
        coloredItems.forEach(function (item) {
716
            inputOptions.push({
717
                text: item.color,
718
                value: item.id,
719
                selected: item.hotDeals
720
            });
721
        });
722
        bootBoxObj['inputOptions'] = inputOptions;
723
        promptObj = bootbox.prompt(bootBoxObj);
724
        promptObj.modal('show')
725
        $('.item-wrapper').find("input[type='checkbox']").slice(1).each(
726
            function (index, checkbox) {
727
                checkbox.checked = coloredItems[index].hotDeals;
728
            });
729
    });
28055 tejbeer 730
}
30017 amit.gupta 731
 
27763 tejbeer 732
$(document).on('change', ".item-wrapper input[type='checkbox']:first",
32301 amit.gupta 733
    function () {
734
        if (this.value == "0") {
735
            $(this).closest('.item-wrapper').find("input[type='checkbox']")
736
                .slice(1).prop('checked', $(this).prop('checked'));
737
        }
738
    });
30017 amit.gupta 739
 
27618 tejbeer 740
function getItemAheadOptions(jqElement, anyColor, callback) {
32301 amit.gupta 741
    console.log(anyColor)
742
    jqElement.typeahead('destroy').typeahead({
743
        source: function (q, process) {
744
            if (q.length >= 3) {
745
                return $.ajax(context + "/item?anyColor=" + anyColor, {
746
                    global: false,
747
                    data: {
748
                        query: q
749
                    },
750
                    success: function (data) {
751
                        queryData = JSON.parse(data);
752
                        process(queryData);
753
                    },
754
                });
755
            }
756
        },
757
        delay: 300,
758
        items: 20,
759
        displayText: function (item) {
760
            return item.itemDescription;
761
        },
762
        autoSelect: true,
763
        afterSelect: callback
764
    });
24176 amit.gupta 765
}
28795 tejbeer 766
 
767
 
32195 tejbeer 768
function getVendorItemAheadOptions(jqElement, vendorId, callback) {
32301 amit.gupta 769
    jqElement.typeahead('destroy').typeahead({
770
        source: function (q, process) {
771
            if (q.length >= 3) {
772
                return $.ajax(context + "/vendorItem?vendorId=" + vendorId, {
773
                    global: false,
774
                    data: {
775
                        query: q
776
                    },
777
                    success: function (data) {
778
                        queryData = JSON.parse(data);
779
                        process(queryData);
780
                    },
781
                });
782
            }
783
        },
784
        delay: 300,
785
        items: 20,
786
        displayText: function (item) {
787
            return item.itemDescription;
788
        },
789
        autoSelect: true,
790
        afterSelect: callback
791
    });
32195 tejbeer 792
}
793
 
28795 tejbeer 794
function getImeiAheadOptions(jqElement, fofoId, callback) {
32301 amit.gupta 795
    jqElement.typeahead('destroy').typeahead({
796
            source: function (q, process) {
797
                if (q.length >= 3) {
798
                    return $.ajax(context + "/imei?fofoId=" + fofoId, {
799
                        global: false,
800
                        data: {
801
                            query: q
802
                        },
803
                        success: function (data) {
804
                            queryData = JSON.parse(data);
805
                            process(queryData);
806
                        },
807
                    });
808
                }
809
            },
810
            delay: 300,
811
            items: 20,
812
            displayText: function (imei) {
813
                return imei;
814
            },
815
            autoSelect: true,
816
            afterSelect: callback
817
        }
818
    );
31762 tejbeer 819
}
820
 
821
 
822
function getAllImeiAheadOptions(jqElement, callback) {
32301 amit.gupta 823
    jqElement.typeahead('destroy').typeahead({
824
        source: function (q, process) {
825
            if (q.length >= 3) {
826
                return $.ajax(context + "/allimei", {
827
                    global: false,
828
                    data: {
829
                        query: q
830
                    },
831
                    success: function (data) {
832
                        queryData = JSON.parse(data);
833
                        process(queryData);
834
                    },
835
                });
836
            }
837
        },
838
        delay: 300,
839
        items: 20,
840
        displayText: function (imei) {
841
            return imei;
842
        },
843
        autoSelect: true,
844
        afterSelect: callback
845
    });
28795 tejbeer 846
}
847
 
848
 
25394 amit.gupta 849
function getEntityAheadOptions(jqElement, callback) {
32301 amit.gupta 850
    jqElement.typeahead('destroy').typeahead({
851
        source: function (q, process) {
852
            if (q.length >= 3) {
853
                return $.ajax(context + "/entity", {
854
                    global: false,
855
                    data: {
856
                        query: q
857
                    },
858
                    success: function (data) {
859
                        queryData = JSON.parse(data);
860
                        process(queryData);
861
                    },
862
                });
863
            }
864
        },
865
        delay: 300,
866
        items: 30,
867
        displayText: function (entity) {
868
            return entity.title_s + "(" + entity.catalogId_i + ")";
869
        },
870
        autoSelect: true,
871
        afterSelect: callback
872
    });
25394 amit.gupta 873
}
30017 amit.gupta 874
 
24349 amit.gupta 875
function getPartnerAheadOptions(jqElement, callback) {
32301 amit.gupta 876
    jqElement.typeahead('destroy').typeahead({
877
        source: function (q, process) {
878
            if (q.length >= 3) {
879
                return $.ajax(context + "/partners", {
880
                    global: false,
881
                    data: {
882
                        query: q
883
                    },
884
                    success: function (data) {
885
                        queryData = JSON.parse(data);
886
                        process(queryData);
887
                    },
888
                });
889
            }
890
        },
891
        delay: 300,
892
        items: 20,
893
        displayText: function (partner) {
894
            return partner.displayName;
895
        },
896
        autoSelect: true,
897
        afterSelect: callback
898
    });
24349 amit.gupta 899
}
24406 amit.gupta 900
 
32074 tejbeer 901
function getVendorAheadOptions(jqElement, callback) {
32301 amit.gupta 902
    jqElement.typeahead('destroy').typeahead({
903
        source: function (q, process) {
904
            if (q.length >= 3) {
905
                return $.ajax(context + "/vendors", {
906
                    global: false,
907
                    data: {
908
                        query: q
909
                    },
910
                    success: function (data) {
911
                        queryData = JSON.parse(data);
912
                        process(queryData);
913
                    },
914
                });
915
            }
916
        },
917
        delay: 300,
918
        items: 20,
919
        displayText: function (vendor) {
920
            return vendor.name;
921
        },
922
        autoSelect: true,
923
        afterSelect: callback
924
    });
32074 tejbeer 925
}
926
 
24595 tejbeer 927
function loadPriceDrop(domId) {
32301 amit.gupta 928
    doGetAjaxRequestHandler(context + "/getItemDescription",
929
        function (response) {
930
            $('#' + domId).html(response);
931
        });
24406 amit.gupta 932
}
30017 amit.gupta 933
 
32301 amit.gupta 934
$(document).on('click', ".price_drop", function () {
935
    loadPriceDrop("main-content");
24595 tejbeer 936
});
25649 tejbeer 937
 
27618 tejbeer 938
 
32301 amit.gupta 939
$(document).on('click', ".closed_pricedrop", function () {
940
    loadClosedPriceDrop("main-content");
28569 amit.gupta 941
});
942
 
943
function loadClosedPriceDrop(domId) {
32301 amit.gupta 944
    doGetAjaxRequestHandler(context + "/getClosedPricedropItemDescription",
945
        function (response) {
946
            $('#' + domId).html(response);
947
        });
28569 amit.gupta 948
}
949
 
27696 tejbeer 950
function notifyTypeChange(messageType, $container) {
32301 amit.gupta 951
    var messageQueryString = "?messageType=" + messageType;
952
    if (messageType == null) {
953
        messageQueryString = "";
954
    }
955
    doGetAjaxRequestHandler(context + "/notifications" + messageQueryString, function (response) {
956
        if ($container != null) {
957
            loaderDialogObj.one('hidden.bs.modal', function () {
958
                $container.popover({
959
                    container: $container,
960
                    template: '<div class="popover popover1" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popover2"></div></div>',
961
                    content: response,
962
                    html: true,
963
                    placement: "bottom",
964
                    trigger: "manual",
965
                    sanitize: false
966
                }).popover('show');
967
                setTimeout(function () {
968
                    $container.focus().one('blur', function () {
969
                        $container.popover('destroy');
970
                    });
971
                }, 100);
972
            });
973
        }
974
    });
25649 tejbeer 975
}
25651 tejbeer 976
 
25689 amit.gupta 977
function downloadNotifyDocument(documentId, cid, documentName) {
32301 amit.gupta 978
    doAjaxGetDownload(context + "/notifyDocument/download?cid=" + cid,
979
        documentName);
25651 tejbeer 980
}
28051 amit.gupta 981
 
982
 
983
/* Create an array with the values of all the input boxes in a column */
32301 amit.gupta 984
$.fn.dataTable.ext.order['dom-text'] = function (settings, col) {
985
    return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
986
        return $('input', td).val();
987
    });
28051 amit.gupta 988
}
28795 tejbeer 989
 
28063 amit.gupta 990
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
32301 amit.gupta 991
$.fn.dataTable.ext.order['dom-text-numeric'] = function (settings, col) {
992
    return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
993
        return $('input', td).val() * 1;
994
    });
28051 amit.gupta 995
}
28795 tejbeer 996
 
32301 amit.gupta 997
$.fn.dataTable.ext.order['dom-stock-numeric'] = function (settings, col) {
998
    return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
999
        return $(td).html().split("/")[0] * 1;
1000
    });
28870 tejbeer 1001
}
28051 amit.gupta 1002
/* Create an array with the values of all the select options in a column */
32301 amit.gupta 1003
$.fn.dataTable.ext.order['dom-select'] = function (settings, col) {
1004
    return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
1005
        return $('select', td).val();
1006
    });
28051 amit.gupta 1007
}
28795 tejbeer 1008
 
28051 amit.gupta 1009
/* Create an array with the values of all the checkboxes in a column */
32301 amit.gupta 1010
$.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
1011
    return this.api().column(col, {
1012
        order: 'index'
1013
    }).nodes().map(function (td, i) {
1014
        return $('input', td).prop('checked') ? '1' : '0';
1015
    });
30414 amit.gupta 1016
}
1017
 
32301 amit.gupta 1018
$.fn.dataTable.Api.register('sum()', function () {
1019
    return this.flatten().reduce(function (a, b) {
1020
        if (typeof a === 'string') {
1021
            a = a.replace(/[^\d.-]/g, '') * 1;
1022
            a = isNaN(a) ? 0 : a;
1023
        }
1024
        if (typeof b === 'string') {
1025
            b = b.replace(/[^\d.-]/g, '') * 1;
1026
            b = isNaN(b) ? 0 : b;
1027
        }
30414 amit.gupta 1028
 
32301 amit.gupta 1029
        return a + b;
1030
    }, 0);
30694 amit.gupta 1031
});
1032
 
1033
const debounce = (func, delay) => {
32301 amit.gupta 1034
    let debounceTimer
1035
    return function () {
1036
        const context = this
1037
        const args = arguments
1038
        clearTimeout(debounceTimer)
1039
        debounceTimer
1040
            = setTimeout(() => func.apply(context, args), delay)
1041
    }
30694 amit.gupta 1042
}
31687 amit.gupta 1043
 
32301 amit.gupta 1044
function parseDate(str) {
1045
    var m = str.match(/^(\d{1,2})[-/](\d{1,2})[-/](\d{4})$/);
1046
    return (m) ? new Date(m[3], m[2] - 1, m[1]) : null;
1047
}
31687 amit.gupta 1048
 
32130 amit.gupta 1049
function ExportToExcel(container, fn) {
32301 amit.gupta 1050
    let tableId = $(container).data('tableid');
1051
    var elt = document.getElementById(tableId);
33220 amit.gupta 1052
    console.log('elt', elt);
32301 amit.gupta 1053
    if ($.fn.DataTable.isDataTable(`#${tableId}`)) {
33220 amit.gupta 1054
        let dataTable = $(`#${tableId}`).DataTable();
1055
        dataTable.page.len(-1).draw();
1056
        elt = dataTable.table(0).container();
32301 amit.gupta 1057
    }
1058
    ExportTableToExcel(elt, fn);
31687 amit.gupta 1059
}
1060
 
32301 amit.gupta 1061
function ExportTableToExcel(tableElt, fn) {
1062
    $table = $(tableElt)
1063
    $table.find('td').each((index, value) => {
1064
        let $tdElement = $(value);
1065
        console.log($tdElement);
1066
        let parsedDate = parseDate($tdElement.html());
1067
        if (parsedDate != null) {
1068
            let days = Math.floor(parsedDate.getTime() / 86400 * 1000);
1069
            $tdElement.data('v', days);
1070
            $tdElement.data("t", "n");
1071
            $tdElement.data("z", "yyyy-mm-dd");
1072
        }
1073
    });
1074
    console.log($table.get(0))
1075
    var wb = XLSX.utils.table_to_book($table.get(0), {sheet: "sheet1"});
1076
    XLSX.writeFile(wb, fn + '.xlsx');
1077
}
31687 amit.gupta 1078
 
32301 amit.gupta 1079
 
1080
$(document).on('click', ".manage-pcm", function () {
1081
    managePCM();
31687 amit.gupta 1082
});
1083
 
1084
function managePCM() {
32301 amit.gupta 1085
    doGetAjaxRequestHandler(`${context}/brand-pcm`, function (response) {
1086
        $('#main-content').html(response);
1087
    });
31687 amit.gupta 1088
}
31786 tejbeer 1089
 
1090
 
32301 amit.gupta 1091
$(document).on('click', ".digify-retailer-login", function () {
31786 tejbeer 1092
 
32301 amit.gupta 1093
    doGetAjaxRequestHandler(context + "/digify/register", function (response) {
32074 tejbeer 1094
 
1095
 
32301 amit.gupta 1096
        $('#main-content').html(response);
32074 tejbeer 1097
 
32301 amit.gupta 1098
    });
1099
    //$('#main-content').html(`<iframe class="wrapper" src="${context}/digify/register" style="width:100%;height:100vh"> </iframe>`);
1100
    //$('#main-content').html(`<a class="wrapper" href="${context}/digify/register" target="_blank" style="width:100%;height:100vh"> </a>`);
32074 tejbeer 1101
 
31786 tejbeer 1102
});
31878 tejbeer 1103
 
32301 amit.gupta 1104
$(document).on('click', '.warehousewise_stock', function () {
1105
    doGetAjaxRequestHandler(`${context}/warehouse/stock-qty`, function (response) {
1106
        $('#main-content').html(response);
1107
    });
32130 amit.gupta 1108
});
31878 tejbeer 1109
 
32567 tejbeer 1110
function loadMainContent(htmlContent) {
1111
    $('#main-content').html(htmlContent);
1112
}
31878 tejbeer 1113
 
1114
 
32979 amit.gupta 1115
function jsonStartDate(dateInputString) {
33220 amit.gupta 1116
    if (dateInputString === '') return null;
33141 amit.gupta 1117
    return moment(dateInputString, "yyyy-MM-DD").format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
32979 amit.gupta 1118
}
33220 amit.gupta 1119
 
32979 amit.gupta 1120
function jsonEndDate(dateInputString) {
33220 amit.gupta 1121
    if (dateInputString === '') return null;
33141 amit.gupta 1122
    return moment(dateInputString, "yyyy-MM-DD").endOf('day').format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
32979 amit.gupta 1123
}
31878 tejbeer 1124
 
33167 amit.gupta 1125
function showToast(message) {
1126
    Toastify({
1127
        text: message,
1128
        duration: 3000, // 3 seconds
1129
        gravity: "top", // or "bottom"
1130
        position: "right", // "left", "center", "right"
1131
        backgroundColor: "green", // specify the background color
33400 ranu 1132
        offset: {
1133
            x: 20, // Horizontal margin from the right
1134
            y: 70 // Vertical margin from the top
1135
        }
33167 amit.gupta 1136
    }).showToast();
1137
}
31878 tejbeer 1138
 
32130 amit.gupta 1139
 
32567 tejbeer 1140
 
32979 amit.gupta 1141
 
33167 amit.gupta 1142