Subversion Repositories SmartDukaan

Rev

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