Subversion Repositories SmartDukaan

Rev

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

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