Subversion Repositories SmartDukaan

Rev

Rev 33261 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33257 ranu 1
$(function () {
2
    $(document).on('click', ".billed-invoice", function () {
33261 ranu 3
        getAuthorisedWarehouseList(function (warehouseId) {
33257 ranu 4
            loadAllInvoice(warehouseId, "main-content");
5
        });
6
 
7
    });
8
 
33261 ranu 9
    $(document).on('change', "#WarehouseList", function () {
10
        var warehouseId = $(this).val();
11
        loadAllInvoice(warehouseId, "main-content");
12
    });
13
 
33257 ranu 14
    $(document).on('click', ".invoice-orders", function () {
15
        var invoiceNumber = $(this).data("invoice");
16
        loadInvoiceDetail(invoiceNumber, "invoice-detail-container");
17
    });
18
 
19
    $(document).on('click', ".invoice-download", function () {
20
        var invoiceNumber = $(this).data("invoice");
33270 amit.gupta 21
        window.open(`${context}/om/downloadInvoice/${invoiceNumber}`, "_blank");
33257 ranu 22
    });
23
});
24
 
25
 
26
function loadAllInvoice(warehouseId, domId) {
27
    doGetAjaxRequestHandler(context + "/om/billedInvoice/?warehouseId=" + warehouseId, function (response) {
28
        $('#' + domId).html(response);
29
        var invoiceNumber = $("#firstInvoiceNumber").val();
30
        $("#selectedWarehouse").val(warehouseId);
31
        console.log("invoiceNumber:", invoiceNumber);
33261 ranu 32
 
33
        var selectOptions = '';
34
        authorisedWarehouses.forEach(function (warehouse) {
35
            var selected = (warehouse.id == warehouseId) ? 'selected' : '';
36
 
37
            selectOptions += `<option value="${warehouse.id}" ${selected}>${warehouse.name}</option>`;
38
        });
39
        $('#authWarehousesList').html(`<select class="form-control" id="WarehouseList">${selectOptions}</select>`);
40
 
33257 ranu 41
        loadInvoiceDetail(invoiceNumber, "invoice-detail-container");
42
    });
43
}
44
 
45
function loadInvoiceDetail(invoiceNumber, detailContainer) {
46
    var url = context + "/om/billed-invoice-orders/?invoiceNumber=" + invoiceNumber;
47
    doGetAjaxRequestHandler(url, function (response) {
48
        $('#' + detailContainer).html(response);
49
        $("#selectedInvoiceNumber").text(invoiceNumber);
50
    });
51
}
52
 
53
 
54
function getAuthorisedWarehousesList(callback) {
55
    bootBoxObj = {
56
        size: "small",
57
        title: "Choose Warehouse",
58
        callback: callback,
59
        inputType: 'select',
60
        inputOptions: typeof inputOptions == "undefined" ? undefined
61
            : inputOptions
62
    }
63
    if (typeof inputOptions == "undefined") {
64
        doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
65
            response) {
66
            console.log("response warehouse", response);
67
            response = JSON.parse(response);
68
            inputOptions = [];
69
            response.forEach(function (warehouse) {
70
                inputOptions.push({
71
                    text: warehouse.name,
72
                    value: warehouse.id,
73
                });
74
            });
75
            bootBoxObj['inputOptions'] = inputOptions;
76
            bootbox.prompt(bootBoxObj);
77
        });
78
    } else if (inputOptions.length == 1) {
79
        callback(inputOptions[0].warehouse.id);
80
    } else {
81
        bootbox.prompt(bootBoxObj);
82
    }
83
 
84
}