Subversion Repositories SmartDukaan

Rev

Rev 35289 | Rev 35459 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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