Subversion Repositories SmartDukaan

Rev

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

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