Subversion Repositories SmartDukaan

Rev

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