Subversion Repositories SmartDukaan

Rev

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

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