Subversion Repositories SmartDukaan

Rev

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