Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
33247 ranu 1
$(function () {
2
    $(document).on('click', ".warehouse-management", function () {
3
        getAuthorisedWarehousesList(function (warehouseId) {
4
            loadAllTransaction(warehouseId, "main-content");
5
        });
6
 
7
    });
8
 
9
    $(document).on('click', ".order_by_transaction", function () {
10
        var transactionId = $(this).data("transaction");
11
        var warehouseId = $("#selectedWarehouse").val();
12
        loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
13
    });
14
 
33257 ranu 15
    $(document).on('click', ".change-warehouse-save-mk", function () {
16
        var selectedFromBillingWarehouse = $("#selectedFromBillingWarehouse").val();
17
        var orderId = $("#selectedFromBillingWarehouse").data('orderid');
18
        doPostAjaxRequestHandler(context + `/om/changeBillingWarehouse/?billingFromWarehouseId=${selectedFromBillingWarehouse}&orderId=${orderId}`, function (response) {
19
            if (response.response === true) {
20
                var warehouseId = $("#selectedWarehouse").val();
21
                loadAllTransaction(warehouseId, "main-content");
22
            } else {
23
                alert('Something went wrong');
24
            }
25
 
26
        });
27
    });
28
 
29
    $(document).on('click', ".changeWarehouse-mk", function () {
30
        var itemId = $(this).data("itemid");
31
        var warehouseId = $(this).data("warehouseid");
32
        var orderId = $(this).data("orderid");
33
        console.log('warehouse', warehouseId);
34
        console.log('itemId', itemId);
35
        doGetAjaxRequestHandler(`${context}/om/formWarehouseByItemId/?warehouseId=${warehouseId}&itemId=${itemId}`, function (response) {
36
            console.log(response);
37
            if (response && response.response && Array.isArray(response.response)) {
38
                console.log("response warehouse", response.response);
39
                var selectOptions = '';
40
                response.response.forEach(function (warehouse) {
41
                    selectOptions += `<option value="${warehouse.warehouseFrom}">${warehouse.warehouseFromName}</option>`;
42
                });
43
                // Populate the modal with the select dropdown
44
                $('#changeWarehouseModal .modal-body').html(`<select id="selectedFromBillingWarehouse" data-orderid="${orderId}" class="form-control">${selectOptions}</select>`);
45
            } else {
46
                console.log('error: invalid response structure');
47
            }
48
        });
49
    });
50
 
51
 
52
 
53
 
33247 ranu 54
    $(document).on('click', ".order_accepted", function () {
55
        var transactionId = $("#selectedTransactionId").text();
56
        var warehouseId = $("#selectedWarehouseId").val();
57
        var orderBillingModels = []; // Array to store OrderBillingModel objects
58
        $("#wareHouseTransactionTable > tbody > tr").each(function (rowIndex) {
59
            if ($(this).hasClass('main-tr')) {
60
                var orderId = parseInt($(this).find(".orderId").text().trim());
61
                var fillQuantityInput = $(this).find(".filledQty");
62
                var fillQuantity = fillQuantityInput.length ? parseInt(fillQuantityInput.val().trim()) : 0; // Get fill quantity from input field if it exists
63
                var serialNumbers = [];
64
 
65
                var imeiInputAvailability = $(this).find(".imeis-to-grn");
66
                if (imeiInputAvailability.length) {
67
                    var imeiInput = ($(this).find(".imeis-to-grn")).tagsinput('items'); // Get selected serial numbers
68
                    if (imeiInput.length) {
69
                        imeiInput.forEach((imei) => {
70
                            serialNumbers.push(imei);
71
                        });
72
                    }
73
                }
74
 
75
                // Determine the quantity to bill based on serial numbers and fill quantity
76
                var quantityToBill;
77
                if (serialNumbers.length) {
78
                    quantityToBill = serialNumbers.length;
79
                } else {
80
                    quantityToBill = fillQuantity;
81
                }
82
 
83
                // Create OrderBillingModel object
84
                var orderBillingModel = {
85
                    orderId: orderId,
86
                    serialNumbersToBill: serialNumbers,
87
                    quantityToBill: quantityToBill
88
                };
89
 
90
                // Add OrderBillingModel object to the array
91
                orderBillingModels.push(orderBillingModel);
92
            }
93
        });
94
 
95
        // Convert orderBillingModels array to JSON string
96
        var requestBody = JSON.stringify(orderBillingModels);
97
 
98
        // Perform further actions with the requestBody, such as sending it in an AJAX request
99
        console.log('Request Body:', requestBody);
100
 
101
        doPostAjaxRequestWithJsonHandler(`${context}/om/addBillingDetailsForGrouppedOrders/?warehouseId=${warehouseId}&transactionId=${transactionId}`, requestBody, function (response) {
102
            if (response) {
103
                alert("bill generated successfully");
104
            } else {
105
                alert("something went wrong");
106
            }
107
        });
108
 
109
    });
110
 
111
 
112
});
113
 
114
 
115
function loadAllTransaction(warehouseId, domId) {
116
    doGetAjaxRequestHandler(context + "/om/transactions/?warehouseId=" + warehouseId + "&orderStatus=SUBMITTED_FOR_PROCESSING", function (response) {
117
        $('#' + domId).html(response);
118
        var transactionId = $("#firstTxnId").val();
119
        $("#selectedWarehouse").val(warehouseId);
120
        console.log("Transaction ID:", transactionId);
121
        loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
122
    });
123
}
124
 
125
function loadTransactionDetail(transactionId, warehouseId, detailContainer) {
126
    var url = context + "/om/orderByTransaction/?transactionId=" + transactionId + "&warehouseId=" + warehouseId;
127
    doGetAjaxRequestHandler(url, function (response) {
128
        $('#' + detailContainer).html(response);
129
        $("#selectedTransactionId").text(transactionId);
130
        $("#selectedWarehouseId").val(warehouseId);
131
    });
132
}
133
 
134
 
135
function getAuthorisedWarehousesList(callback) {
136
    bootBoxObj = {
137
        size: "small",
138
        title: "Choose Warehouse",
139
        callback: callback,
140
        inputType: 'select',
141
        inputOptions: typeof inputOptions == "undefined" ? undefined
142
            : inputOptions
143
    }
144
    if (typeof inputOptions == "undefined") {
145
        doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
146
            response) {
147
            console.log("response warehouse", response);
148
            response = JSON.parse(response);
149
            inputOptions = [];
150
            response.forEach(function (warehouse) {
151
                inputOptions.push({
152
                    text: warehouse.name,
153
                    value: warehouse.id,
154
                });
155
            });
156
            bootBoxObj['inputOptions'] = inputOptions;
157
            bootbox.prompt(bootBoxObj);
158
        });
159
    } else if (inputOptions.length == 1) {
160
        callback(inputOptions[0].warehouse.id);
161
    } else {
162
        bootbox.prompt(bootBoxObj);
163
    }
164
 
165
}