Subversion Repositories SmartDukaan

Rev

Rev 33269 | Rev 33271 | 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) {
33270 amit.gupta 121
            if (invoiceNumber) {
122
                window.open(`${context}/om/downloadInvoice/${invoiceNumber}`, "_blank");
33247 ranu 123
                alert("bill generated successfully");
33263 ranu 124
                loadAllTransaction(warehouseId, "main-content");
33247 ranu 125
            } else {
126
                alert("something went wrong");
127
            }
128
        });
129
 
130
    });
131
 
132
 
133
});
134
 
135
 
136
function loadAllTransaction(warehouseId, domId) {
137
    doGetAjaxRequestHandler(context + "/om/transactions/?warehouseId=" + warehouseId + "&orderStatus=SUBMITTED_FOR_PROCESSING", function (response) {
138
        $('#' + domId).html(response);
139
        var transactionId = $("#firstTxnId").val();
140
        $("#selectedWarehouse").val(warehouseId);
141
        console.log("Transaction ID:", transactionId);
33261 ranu 142
 
143
        var selectOptions = '';
144
        authorisedWarehouses.forEach(function (warehouse) {
145
            var selected = (warehouse.id == warehouseId) ? 'selected' : '';
146
 
147
            selectOptions += `<option value="${warehouse.id}" ${selected}>${warehouse.name}</option>`;
148
        });
149
        $('#authWarehousesList').html(`<select class="form-control" id="selectedWarehouse">${selectOptions}</select>`);
150
 
33247 ranu 151
        loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
152
    });
153
}
154
 
155
function loadTransactionDetail(transactionId, warehouseId, detailContainer) {
156
    var url = context + "/om/orderByTransaction/?transactionId=" + transactionId + "&warehouseId=" + warehouseId;
157
    doGetAjaxRequestHandler(url, function (response) {
158
        $('#' + detailContainer).html(response);
159
        $("#selectedTransactionId").text(transactionId);
160
        $("#selectedWarehouseId").val(warehouseId);
161
    });
162
}
163
 
164
 
33261 ranu 165
function getAuthorisedWarehouseList(callback) {
33247 ranu 166
    bootBoxObj = {
167
        size: "small",
168
        title: "Choose Warehouse",
169
        callback: callback,
170
        inputType: 'select',
171
        inputOptions: typeof inputOptions == "undefined" ? undefined
172
            : inputOptions
173
    }
174
    if (typeof inputOptions == "undefined") {
33261 ranu 175
        doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (response) {
176
            console.log("responseeee warehouse", response);
177
            authorisedWarehouses = JSON.parse(response);
178
 
33247 ranu 179
            inputOptions = [];
33261 ranu 180
            authorisedWarehouses.forEach(function (warehouse) {
33247 ranu 181
                inputOptions.push({
182
                    text: warehouse.name,
183
                    value: warehouse.id,
184
                });
185
            });
186
            bootBoxObj['inputOptions'] = inputOptions;
187
            bootbox.prompt(bootBoxObj);
188
        });
189
    } else if (inputOptions.length == 1) {
190
        callback(inputOptions[0].warehouse.id);
191
    } else {
192
        bootbox.prompt(bootBoxObj);
193
    }
33261 ranu 194
}
33247 ranu 195
 
33261 ranu 196
 
197