Subversion Repositories SmartDukaan

Rev

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