Subversion Repositories SmartDukaan

Rev

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