Subversion Repositories SmartDukaan

Rev

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

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