Subversion Repositories SmartDukaan

Rev

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

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