Subversion Repositories SmartDukaan

Rev

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