| 32352 |
amit.gupta |
1 |
$(function () {
|
|
|
2 |
$(document).on('click', ".warehouse-create-purchase-order", function () {
|
|
|
3 |
loadCreatePurchase("main-content");
|
|
|
4 |
});
|
| 32145 |
tejbeer |
5 |
|
| 32352 |
amit.gupta |
6 |
$(document).on('click', ".warehouse-receive-new-invoice", function () {
|
|
|
7 |
loadNewReceiveInvoice("main-content");
|
|
|
8 |
});
|
| 32145 |
tejbeer |
9 |
|
| 32192 |
tejbeer |
10 |
|
| 32352 |
amit.gupta |
11 |
$(document).on('click', ".warehouse-grn-request", function () {
|
|
|
12 |
loadGrnRequest("main-content");
|
|
|
13 |
});
|
| 32192 |
tejbeer |
14 |
|
| 32300 |
tejbeer |
15 |
|
| 32352 |
amit.gupta |
16 |
$(document).on('click', ".warehouse-debit-note", function () {
|
|
|
17 |
loadDebitNote("main-content");
|
|
|
18 |
});
|
| 32192 |
tejbeer |
19 |
|
|
|
20 |
|
| 32352 |
amit.gupta |
21 |
$(document).on('click', ".warehouse-invoices", function () {
|
|
|
22 |
loadWarehouseInvoices("main-content");
|
|
|
23 |
});
|
| 32256 |
tejbeer |
24 |
|
| 32300 |
tejbeer |
25 |
|
| 32352 |
amit.gupta |
26 |
$(document).on('click', '.dateWiseInvoices', function () {
|
| 32300 |
tejbeer |
27 |
|
| 32352 |
amit.gupta |
28 |
var startDate = getDatesFromPicker('input[name="invoice-duration"]').startDate;
|
|
|
29 |
var endDate = getDatesFromPicker('input[name="invoice-duration"]').endDate
|
| 32300 |
tejbeer |
30 |
|
| 32352 |
amit.gupta |
31 |
var vendorId = $('#vendorId').val();
|
| 32300 |
tejbeer |
32 |
|
| 34047 |
tejus.loha |
33 |
// doGetAjaxRequestHandler(context + "/getWarehouseInvoicesByVendor?vendorId=" + vendorId + "&startDate=" + startDate + "&endDate=" + endDate, function (response) {
|
|
|
34 |
// $('.invoicesviewcontainer').html(response);
|
|
|
35 |
doGetAjaxRequestHandler(context + "/getWarehouseInvoicesBydateWise?dateWiseInvoices=" + "&startDate=" + startDate + "&endDate=" + endDate, function (response) {
|
|
|
36 |
$('.invoicesviewcontainer').html(response);
|
|
|
37 |
});
|
| 32300 |
tejbeer |
38 |
|
| 33737 |
ranu |
39 |
});
|
| 32300 |
tejbeer |
40 |
|
| 33737 |
ranu |
41 |
$(document).on('click', '.generateInvoicesExcel', function () {
|
| 32300 |
tejbeer |
42 |
|
| 33737 |
ranu |
43 |
var startDate = getDatesFromPicker('input[name="invoice-duration"]').startDate;
|
|
|
44 |
var endDate = getDatesFromPicker('input[name="invoice-duration"]').endDate;
|
|
|
45 |
doAjaxGetDownload(context + "/generateDatewiseInvoiceExcel?startDate=" + startDate + "&endDate=" + endDate, "PurchaseInvoicesReport.xlsx");
|
| 32352 |
amit.gupta |
46 |
});
|
| 32300 |
tejbeer |
47 |
|
|
|
48 |
|
| 32352 |
amit.gupta |
49 |
$(document)
|
|
|
50 |
.on(
|
|
|
51 |
'input',
|
|
|
52 |
'#invoice',
|
|
|
53 |
function () {
|
|
|
54 |
if (confirm('Document has been selected, Do you want to upload ?')) {
|
|
|
55 |
var fileSelector = $('#invoice')[0];
|
|
|
56 |
if (fileSelector != undefined
|
|
|
57 |
&& fileSelector.files[0] != undefined) {
|
|
|
58 |
var url = context + '/document-upload';
|
| 32300 |
tejbeer |
59 |
|
| 32352 |
amit.gupta |
60 |
console.log(url);
|
|
|
61 |
var file = this.files[0];
|
|
|
62 |
doAjaxUploadRequestHandler(
|
|
|
63 |
url,
|
|
|
64 |
'POST',
|
|
|
65 |
file,
|
|
|
66 |
function (response) {
|
|
|
67 |
console.log(response);
|
|
|
68 |
var documentId = response.response.document_id;
|
|
|
69 |
console.log("documentId : "
|
|
|
70 |
+ documentId);
|
|
|
71 |
localStorage.setItem("invoiceDocument",
|
|
|
72 |
documentId);
|
| 32192 |
tejbeer |
73 |
|
| 32295 |
tejbeer |
74 |
|
| 32352 |
amit.gupta |
75 |
});
|
| 32300 |
tejbeer |
76 |
|
| 32352 |
amit.gupta |
77 |
}
|
|
|
78 |
} else {
|
|
|
79 |
// Do nothing!
|
|
|
80 |
}
|
|
|
81 |
});
|
| 32192 |
tejbeer |
82 |
|
| 32352 |
amit.gupta |
83 |
$(document).on('click', ".createReceiveInvoice", function () {
|
| 32192 |
tejbeer |
84 |
|
| 32352 |
amit.gupta |
85 |
var invoiceDate = $('#actualDate').val();
|
| 32192 |
tejbeer |
86 |
|
| 32352 |
amit.gupta |
87 |
var warehouseId = $('#warehouseMap').val();
|
| 32192 |
tejbeer |
88 |
|
| 32352 |
amit.gupta |
89 |
var numItems = $('#numberofItems').val();
|
| 32192 |
tejbeer |
90 |
|
| 32352 |
amit.gupta |
91 |
var supplierId = $('#vendorId').val();
|
| 32192 |
tejbeer |
92 |
|
| 32352 |
amit.gupta |
93 |
var totalValue = $('#totalValue').val();
|
| 32192 |
tejbeer |
94 |
|
| 32352 |
amit.gupta |
95 |
var invoiceNumber = $('#invoiceNumber').val();
|
| 32642 |
raveendra. |
96 |
//var invoiceDoc = $('#invoiceDoc').val();
|
| 32192 |
tejbeer |
97 |
|
| 34047 |
tejus.loha |
98 |
var invoice = $('#invoice').val();
|
| 32642 |
raveendra. |
99 |
var invoiceDoc = localStorage
|
|
|
100 |
.getItem("invoiceDocument");
|
| 34047 |
tejus.loha |
101 |
console.log(invoiceDoc)
|
| 32192 |
tejbeer |
102 |
|
| 32629 |
amit.gupta |
103 |
if (invoiceDate === "" && warehouseId === "" && numItems === "" && supplierId === "" && totalValue === "" && invoiceNumber === "" && invoiceDoc === "") {
|
| 32352 |
amit.gupta |
104 |
alert("Field can't be empty");
|
|
|
105 |
return false;
|
|
|
106 |
}
|
| 32192 |
tejbeer |
107 |
|
| 32629 |
amit.gupta |
108 |
if (invoiceDate === "") {
|
| 32638 |
raveendra. |
109 |
alert("Please select date");
|
| 32629 |
amit.gupta |
110 |
return false;
|
|
|
111 |
}
|
| 34047 |
tejus.loha |
112 |
if (supplierId === "") {
|
|
|
113 |
alert("Please choose supplier/Vendor");
|
|
|
114 |
return false;
|
|
|
115 |
}
|
| 32638 |
raveendra. |
116 |
|
|
|
117 |
if (invoiceNumber === "") {
|
|
|
118 |
alert("Please fill Invoice Number.");
|
|
|
119 |
return false;
|
|
|
120 |
}
|
| 32629 |
amit.gupta |
121 |
if (warehouseId === "") {
|
| 32638 |
raveendra. |
122 |
alert("Please choose warehouse");
|
| 32629 |
amit.gupta |
123 |
return false;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
if (numItems === "") {
|
| 32638 |
raveendra. |
127 |
alert("Please fill number of items.");
|
| 32629 |
amit.gupta |
128 |
return false;
|
|
|
129 |
}
|
|
|
130 |
if (totalValue === "") {
|
| 32638 |
raveendra. |
131 |
alert("Please fill Total Value.");
|
| 32629 |
amit.gupta |
132 |
return false;
|
|
|
133 |
}
|
| 32638 |
raveendra. |
134 |
console.log('invoice doc', invoiceDoc);
|
| 34047 |
tejus.loha |
135 |
if (invoiceDoc === "") {
|
| 32638 |
raveendra. |
136 |
alert("Please upload invoice.");
|
| 32629 |
amit.gupta |
137 |
return false;
|
|
|
138 |
}
|
| 32352 |
amit.gupta |
139 |
var newReceiveInvoice = {};
|
| 32192 |
tejbeer |
140 |
|
| 32352 |
amit.gupta |
141 |
newReceiveInvoice['invoiceDate'] = invoiceDate;
|
| 32629 |
amit.gupta |
142 |
newReceiveInvoice['warehouseId'] = warehouseId;
|
|
|
143 |
newReceiveInvoice['numItems'] = numItems;
|
|
|
144 |
newReceiveInvoice['supplierId'] = supplierId;
|
|
|
145 |
newReceiveInvoice['totalValue'] = totalValue;
|
|
|
146 |
newReceiveInvoice['invoiceNumber'] = invoiceNumber;
|
|
|
147 |
newReceiveInvoice['invoiceDoc'] = invoiceDoc;
|
| 32192 |
tejbeer |
148 |
|
| 32629 |
amit.gupta |
149 |
if (confirm("Are you sure you want to add new Invoice")) {
|
| 32192 |
tejbeer |
150 |
|
| 32390 |
amit.gupta |
151 |
doPostAjaxRequestWithJsonHandler(`${context}/newReceiveInvoice`, JSON
|
| 32352 |
amit.gupta |
152 |
.stringify(newReceiveInvoice), function (response) {
|
|
|
153 |
if (response == 'true') {
|
| 32638 |
raveendra. |
154 |
alert("Successfully added");
|
| 32352 |
amit.gupta |
155 |
localStorage.removeItem("invoiceDocument");
|
|
|
156 |
loadNewReceiveInvoice("main-content");
|
|
|
157 |
}
|
|
|
158 |
});
|
|
|
159 |
}
|
| 32295 |
tejbeer |
160 |
|
| 32192 |
tejbeer |
161 |
|
| 32352 |
amit.gupta |
162 |
});
|
| 32192 |
tejbeer |
163 |
|
|
|
164 |
|
| 32352 |
amit.gupta |
165 |
var purchaseItemIds;
|
|
|
166 |
$(document).on('click', ".purchaseorderitemview", function () {
|
|
|
167 |
purchaseItemIds = [];
|
|
|
168 |
var vendorId = $('#vendorId').val();
|
|
|
169 |
var warehouseId = $('#warehouseMap').val();
|
| 32390 |
amit.gupta |
170 |
var poDate = $('#poDate').val();
|
| 32192 |
tejbeer |
171 |
|
| 32352 |
amit.gupta |
172 |
console.log(warehouseId);
|
| 32192 |
tejbeer |
173 |
|
| 32352 |
amit.gupta |
174 |
if (warehouseId === null && vendorId === "") {
|
|
|
175 |
alert("Field can't be empty");
|
|
|
176 |
return;
|
|
|
177 |
}
|
| 32192 |
tejbeer |
178 |
|
| 32390 |
amit.gupta |
179 |
if (poDate === '') {
|
|
|
180 |
alert("PO Date is required");
|
|
|
181 |
return;
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
if (warehouseId === null && vendorId === "") {
|
|
|
185 |
alert("Field can't be empty");
|
|
|
186 |
return;
|
|
|
187 |
}
|
|
|
188 |
|
| 32352 |
amit.gupta |
189 |
if (warehouseId === null) {
|
|
|
190 |
alert("please select warehouse");
|
|
|
191 |
return;
|
|
|
192 |
}
|
|
|
193 |
if (vendorId === "") {
|
|
|
194 |
alert("please select vendor");
|
|
|
195 |
return;
|
|
|
196 |
}
|
|
|
197 |
doGetAjaxRequestHandler(context + "/addPurchaseItemView?warehouseId=" + warehouseId + "&vendorId=" + vendorId, function (response) {
|
|
|
198 |
$(".createpurchaseordercontainer").html(response);
|
|
|
199 |
});
|
|
|
200 |
});
|
| 32192 |
tejbeer |
201 |
|
| 32145 |
tejbeer |
202 |
|
| 36532 |
amit |
203 |
$(document).on('change', '#poItemsFile', function () {
|
|
|
204 |
var file = this.files[0];
|
|
|
205 |
if (!file) return;
|
|
|
206 |
|
|
|
207 |
var vendorId = $('#vendorId').val();
|
|
|
208 |
var poDate = $('#poDate').val();
|
|
|
209 |
|
|
|
210 |
var formData = new FormData();
|
|
|
211 |
formData.append("file", file);
|
|
|
212 |
|
|
|
213 |
$.ajax({
|
|
|
214 |
url: context + '/uploadPurchaseOrderItems?vendorId=' + vendorId + '&poDate=' + poDate,
|
|
|
215 |
type: 'POST',
|
|
|
216 |
data: formData,
|
|
|
217 |
dataType: 'json',
|
|
|
218 |
cache: false,
|
|
|
219 |
contentType: false,
|
|
|
220 |
processData: false,
|
|
|
221 |
success: function (items) {
|
|
|
222 |
// Clear existing rows
|
|
|
223 |
$('#purchase-order-table tbody').empty();
|
|
|
224 |
purchaseItemIds = [];
|
|
|
225 |
|
|
|
226 |
for (var i = 0; i < items.length; i++) {
|
|
|
227 |
var item = items[i];
|
|
|
228 |
var $row = $('<tr>' +
|
|
|
229 |
'<td><input type="text" class="form-control typeaheaditem" autocomplete="off" value="' + item.modelName + '" readonly/></td>' +
|
|
|
230 |
'<td><input type="number" class="form-control qty" name="qty" value="' + item.amendedQty + '"/></td>' +
|
|
|
231 |
'<td><input type="number" class="form-control transferPrice" readonly tabindex="-1" value="' + item.transferPrice + '" data-itemid="' + item.itemId + '"/></td>' +
|
|
|
232 |
'<td><input type="number" class="form-control totalValue" tabindex="-1" readonly value="' + item.totalValue + '"/></td>' +
|
|
|
233 |
'<td><input class="form-control btn btn-primary removeInPurchaseOrder" tabindex="-1" type="button" value="Remove"></td>' +
|
|
|
234 |
'</tr>');
|
|
|
235 |
$('#purchase-order-table tbody').append($row);
|
|
|
236 |
purchaseItemIds.push(item.itemId);
|
|
|
237 |
}
|
|
|
238 |
updateTotalValue();
|
|
|
239 |
alert("Uploaded " + items.length + " items successfully");
|
|
|
240 |
},
|
|
|
241 |
error: function (xhr) {
|
|
|
242 |
var msg = "Upload failed";
|
|
|
243 |
try {
|
|
|
244 |
var err = JSON.parse(xhr.responseText);
|
|
|
245 |
if (err.message) msg = err.message;
|
|
|
246 |
if (err.code) msg = err.code;
|
|
|
247 |
} catch (e) {}
|
|
|
248 |
alert(msg);
|
|
|
249 |
}
|
|
|
250 |
});
|
|
|
251 |
|
|
|
252 |
// Reset file input so same file can be re-uploaded
|
|
|
253 |
$(this).val('');
|
|
|
254 |
});
|
|
|
255 |
|
| 32352 |
amit.gupta |
256 |
$(document).on('click', ".addRowInPurchaseOrder", function () {
|
|
|
257 |
var totalQty = 0;
|
| 33727 |
ranu |
258 |
var totalValue = 0;
|
| 32145 |
tejbeer |
259 |
|
| 32358 |
amit.gupta |
260 |
$("table > tbody > tr").each(function () {
|
| 32352 |
amit.gupta |
261 |
var itemId = $(this).find(".transferPrice").data('itemid');
|
|
|
262 |
var qty = $(this).find(".qty").val();
|
| 33727 |
ranu |
263 |
var transferPrice = $(this).find(".transferPrice").val();
|
| 32145 |
tejbeer |
264 |
|
| 33727 |
ranu |
265 |
if (qty !== undefined && qty !== "") {
|
|
|
266 |
qty = parseInt(qty);
|
|
|
267 |
totalQty += qty;
|
|
|
268 |
if (transferPrice !== undefined && transferPrice !== "") {
|
|
|
269 |
transferPrice = parseFloat(transferPrice);
|
|
|
270 |
totalValue += qty * transferPrice;
|
|
|
271 |
}
|
| 32352 |
amit.gupta |
272 |
}
|
| 32358 |
amit.gupta |
273 |
});
|
| 32145 |
tejbeer |
274 |
|
| 32603 |
raveendra. |
275 |
var $html = $(`<tr>
|
| 33727 |
ranu |
276 |
<td><input type="text" class="form-control typeaheaditem" autocomplete="off" placeholder="Search Model"/></td>
|
| 37697 |
amit |
277 |
<td><div class="mv-qty-cell"><input type="number" class="form-control qty" name="qty" placeholder="Quantity"/><span class="mv-avail-icon" style="display:none;" tabindex="0">i</span></div><div class="mv-qty-warn" style="display:none;"></div></td>
|
| 33727 |
ranu |
278 |
<td><input type="number" class="form-control transferPrice" readonly tabindex="-1" placeholder="Transfer Price"/></td>
|
|
|
279 |
<td><input type="number" class="form-control totalValue" tabindex="-1" readonly placeholder="Total Value"/></td>
|
|
|
280 |
<td><input class="form-control btn btn-primary removeInPurchaseOrder" tabindex="-1" type="button" value="Remove"></td>
|
|
|
281 |
</tr>`);
|
| 32192 |
tejbeer |
282 |
|
| 32352 |
amit.gupta |
283 |
var vendorId = $('#vendorId').val();
|
| 32192 |
tejbeer |
284 |
|
| 32352 |
amit.gupta |
285 |
$('tbody').append($html);
|
| 33727 |
ranu |
286 |
getVendorItemAheadOptions($html.find('.typeaheaditem'), vendorId, function (selectedItem) {
|
| 32488 |
amit.gupta |
287 |
let poDate = $('#poDate').val();
|
| 32352 |
amit.gupta |
288 |
var itemId = selectedItem.itemId;
|
| 34047 |
tejus.loha |
289 |
var description = selectedItem.itemDescription;
|
|
|
290 |
if (itemId) {
|
| 32488 |
amit.gupta |
291 |
doGetAjaxRequestHandler(`${context}/getPricing?vendorId=${vendorId}&itemId=${itemId}&onDate=${poDate}`, function (response) {
|
| 32360 |
amit.gupta |
292 |
if (response !== "null") {
|
| 34047 |
tejus.loha |
293 |
if (response !== 'false') {
|
|
|
294 |
var jsonObj = JSON.parse(response);
|
|
|
295 |
$html.find('.transferPrice').val(jsonObj.transferPrice);
|
| 37697 |
amit |
296 |
renderMovementAvailability($html, jsonObj);
|
| 34047 |
tejus.loha |
297 |
$html.find('input.qty').focus();
|
| 33727 |
ranu |
298 |
|
| 34047 |
tejus.loha |
299 |
// Update the total value for this row
|
|
|
300 |
let qty = $html.find('.qty').val();
|
|
|
301 |
let transferPrice = jsonObj.transferPrice;
|
|
|
302 |
if (qty && transferPrice) {
|
|
|
303 |
let total = qty * transferPrice;
|
|
|
304 |
$html.find('.totalValue').val(total);
|
|
|
305 |
updateTotalValue();
|
|
|
306 |
}
|
|
|
307 |
addItem($html, itemId);
|
|
|
308 |
} else {
|
|
|
309 |
$html.find('.typeaheaditem').val('');
|
|
|
310 |
alert(`Category not Define(eg- HID, SLOW MOVING, FAST MOVING),First define the category of ${description} and Try again`);
|
| 33727 |
ranu |
311 |
}
|
| 34047 |
tejus.loha |
312 |
|
| 32360 |
amit.gupta |
313 |
} else {
|
| 34047 |
tejus.loha |
314 |
$html.find('.typeaheaditem').val('');
|
| 37072 |
amit |
315 |
alert(`No approved price for ${description} on ${poDate}. Get the vendor pricing approved first, then try again.`);
|
| 32360 |
amit.gupta |
316 |
}
|
|
|
317 |
});
|
|
|
318 |
} else {
|
| 32352 |
amit.gupta |
319 |
return false;
|
|
|
320 |
}
|
|
|
321 |
});
|
| 33727 |
ranu |
322 |
});
|
| 32145 |
tejbeer |
323 |
|
| 33727 |
ranu |
324 |
$(document).on('input', '.qty', function () {
|
|
|
325 |
var $row = $(this).closest('tr');
|
|
|
326 |
var qty = parseInt($(this).val());
|
| 37697 |
amit |
327 |
checkMovableQty($row, qty);
|
| 33727 |
ranu |
328 |
var transferPrice = parseFloat($row.find('.transferPrice').val());
|
|
|
329 |
if (!isNaN(qty) && !isNaN(transferPrice)) {
|
|
|
330 |
let total = qty * transferPrice;
|
|
|
331 |
$row.find('.totalValue').val(total);
|
|
|
332 |
}
|
|
|
333 |
updateTotalValue();
|
| 32352 |
amit.gupta |
334 |
});
|
| 32145 |
tejbeer |
335 |
|
| 33727 |
ranu |
336 |
function updateTotalValue() {
|
|
|
337 |
var grandTotal = 0;
|
| 36520 |
amit |
338 |
var totalQty = 0;
|
| 33727 |
ranu |
339 |
$('tbody > tr').each(function () {
|
|
|
340 |
var rowTotal = parseFloat($(this).find('.totalValue').val());
|
| 36520 |
amit |
341 |
var rowQty = parseInt($(this).find('.qty').val());
|
| 33727 |
ranu |
342 |
if (!isNaN(rowTotal)) {
|
|
|
343 |
grandTotal += rowTotal;
|
|
|
344 |
}
|
| 36520 |
amit |
345 |
if (!isNaN(rowQty)) {
|
|
|
346 |
totalQty += rowQty;
|
|
|
347 |
}
|
| 33727 |
ranu |
348 |
});
|
| 36520 |
amit |
349 |
$('#totalQuantity').text(totalQty);
|
| 33727 |
ranu |
350 |
$('#grandTotal').text(grandTotal.toFixed(2));
|
|
|
351 |
}
|
|
|
352 |
|
| 32355 |
amit.gupta |
353 |
function addItem(container, itemId) {
|
| 32361 |
amit.gupta |
354 |
oldItemId = container.find('.transferPrice').data('itemid');
|
| 32360 |
amit.gupta |
355 |
if (typeof (oldItemId) === "undefined") {
|
|
|
356 |
let itemIndex = purchaseItemIds.indexOf(itemId);
|
|
|
357 |
if (itemIndex >= 0) {
|
|
|
358 |
alert("Item already added");
|
| 32376 |
amit.gupta |
359 |
container.find('.typeaheaditem').val("");
|
| 32360 |
amit.gupta |
360 |
return false;
|
|
|
361 |
} else {
|
|
|
362 |
purchaseItemIds.push(itemId);
|
| 32361 |
amit.gupta |
363 |
container.find('.transferPrice').data('itemid', itemId);
|
| 32360 |
amit.gupta |
364 |
$('.addRowInPurchaseOrder').click();
|
|
|
365 |
}
|
| 32352 |
amit.gupta |
366 |
} else {
|
| 32360 |
amit.gupta |
367 |
if (oldItemId !== itemId) {
|
|
|
368 |
let oldIndex = purchaseItemIds.indexOf(oldItemId);
|
|
|
369 |
if (oldIndex > -1) {
|
|
|
370 |
purchaseItemIds.splice(oldIndex, 1);
|
|
|
371 |
}
|
|
|
372 |
purchaseItemIds.push(itemId);
|
| 32361 |
amit.gupta |
373 |
container.find('.transferPrice').data('itemid', itemId);
|
| 32358 |
amit.gupta |
374 |
} else {
|
| 32360 |
amit.gupta |
375 |
return false;
|
| 32352 |
amit.gupta |
376 |
}
|
|
|
377 |
}
|
| 32360 |
amit.gupta |
378 |
return true;
|
| 32352 |
amit.gupta |
379 |
}
|
| 32145 |
tejbeer |
380 |
|
| 33727 |
ranu |
381 |
|
| 32352 |
amit.gupta |
382 |
$(document).on('click', '.createSendPurchaseOrder', function () {
|
| 32145 |
tejbeer |
383 |
|
| 32390 |
amit.gupta |
384 |
createPO(true);
|
| 32145 |
tejbeer |
385 |
|
| 32352 |
amit.gupta |
386 |
});
|
| 32145 |
tejbeer |
387 |
|
|
|
388 |
|
| 32352 |
amit.gupta |
389 |
$(document).on('click', '.createPurchaseOrder', function () {
|
| 32145 |
tejbeer |
390 |
|
|
|
391 |
|
| 32390 |
amit.gupta |
392 |
createPO(false);
|
| 32352 |
amit.gupta |
393 |
});
|
| 32145 |
tejbeer |
394 |
|
|
|
395 |
|
| 32352 |
amit.gupta |
396 |
$(document).on('change', '.qty', function () {
|
| 32145 |
tejbeer |
397 |
|
|
|
398 |
|
| 32352 |
amit.gupta |
399 |
var row = $(this).closest("tr");
|
|
|
400 |
var qty = $(row).find(".qty").val();
|
|
|
401 |
var transferPrice = $(row).find(".transferPrice").val();
|
| 32145 |
tejbeer |
402 |
|
| 32352 |
amit.gupta |
403 |
var totalVal = transferPrice * qty;
|
| 32145 |
tejbeer |
404 |
|
| 32352 |
amit.gupta |
405 |
var totalValue = $(row).find(".totalValue").val(totalVal);
|
| 32145 |
tejbeer |
406 |
|
| 32352 |
amit.gupta |
407 |
var purchaseOrderValue = 0;
|
| 32145 |
tejbeer |
408 |
|
| 32352 |
amit.gupta |
409 |
$("table > tbody > tr").each(function () {
|
| 32145 |
tejbeer |
410 |
|
| 32352 |
amit.gupta |
411 |
var totalValue = $(this).find(".totalValue").val();
|
| 32358 |
amit.gupta |
412 |
purchaseOrderValue += totalValue;
|
| 32145 |
tejbeer |
413 |
|
| 32352 |
amit.gupta |
414 |
});
|
| 32145 |
tejbeer |
415 |
|
| 32352 |
amit.gupta |
416 |
});
|
| 32145 |
tejbeer |
417 |
|
|
|
418 |
|
| 32352 |
amit.gupta |
419 |
$(document).on('click', '.warehouse-open-purchase-order', function () {
|
|
|
420 |
loadOpenPurchase("main-content");
|
|
|
421 |
});
|
| 32145 |
tejbeer |
422 |
|
|
|
423 |
|
| 32352 |
amit.gupta |
424 |
$(document).on('click', '.editViewPurchaseOrder', function () {
|
|
|
425 |
var purchaseOrderId = $(this).data('poid');
|
|
|
426 |
doGetAjaxRequestHandler(context + "/getEditPOByPurchaseId?purchaseId=" + purchaseOrderId, function (response) {
|
|
|
427 |
$('#warehouseEditPurchaseContainer .modal-content').html(response);
|
|
|
428 |
});
|
| 32145 |
tejbeer |
429 |
|
| 32352 |
amit.gupta |
430 |
});
|
| 32145 |
tejbeer |
431 |
|
| 32352 |
amit.gupta |
432 |
$(document).on('click', '.editPurchaseOrder', function () {
|
|
|
433 |
var purchaseOrderId = $(this).data('poid');
|
| 32145 |
tejbeer |
434 |
|
| 32352 |
amit.gupta |
435 |
editPurchase(false, purchaseOrderId);
|
| 32145 |
tejbeer |
436 |
|
| 32352 |
amit.gupta |
437 |
});
|
| 32145 |
tejbeer |
438 |
|
|
|
439 |
|
| 32352 |
amit.gupta |
440 |
$(document).on('click', '.editSendPurchaseOrder', function () {
|
|
|
441 |
var purchaseOrderId = $(this).data('poid');
|
| 32145 |
tejbeer |
442 |
|
|
|
443 |
|
| 32352 |
amit.gupta |
444 |
editPurchase(true, purchaseOrderId);
|
|
|
445 |
});
|
| 32145 |
tejbeer |
446 |
|
| 32352 |
amit.gupta |
447 |
$(document).on('click', '.closePurchaseOrder', function () {
|
|
|
448 |
var purchaseOrderId = $(this).data('poid');
|
|
|
449 |
if (confirm("Are you sure you want to close the PO") == true) {
|
|
|
450 |
doPostAjaxRequestHandler(context + "/closePuchaseOrder?purchaseId=" + purchaseOrderId,
|
|
|
451 |
function (response) {
|
| 32145 |
tejbeer |
452 |
|
| 32352 |
amit.gupta |
453 |
console.log(response);
|
|
|
454 |
if (response == 'true') {
|
|
|
455 |
alert("successfully closed");
|
|
|
456 |
loadOpenPurchase("main-content")
|
|
|
457 |
}
|
|
|
458 |
});
|
|
|
459 |
}
|
|
|
460 |
});
|
| 32145 |
tejbeer |
461 |
|
|
|
462 |
|
| 32352 |
amit.gupta |
463 |
$(document).on('click', '.warehouse-view-purchase-order', function () {
|
|
|
464 |
doGetAjaxRequestHandler(context + "/viewPurchaseOrder", function (response) {
|
|
|
465 |
$('#' + 'main-content').html(response);
|
|
|
466 |
});
|
|
|
467 |
});
|
| 32145 |
tejbeer |
468 |
|
|
|
469 |
|
| 32352 |
amit.gupta |
470 |
$(document).on('click', '.dateWisePo', function () {
|
| 32145 |
tejbeer |
471 |
|
| 32352 |
amit.gupta |
472 |
var startDate = getDatesFromPicker('input[name="duration"]').startDate;
|
| 33729 |
ranu |
473 |
var endDate = getDatesFromPicker('input[name="duration"]').endDate;
|
| 32145 |
tejbeer |
474 |
|
|
|
475 |
|
| 32352 |
amit.gupta |
476 |
doGetAjaxRequestHandler(context + "/getPurchaseOrders?startDate=" + startDate + "&endDate=" + endDate, function (response) {
|
|
|
477 |
$('.purchaseorderviewcontainer').html(response);
|
| 32145 |
tejbeer |
478 |
|
| 32352 |
amit.gupta |
479 |
});
|
| 32145 |
tejbeer |
480 |
|
|
|
481 |
|
| 32352 |
amit.gupta |
482 |
});
|
| 32145 |
tejbeer |
483 |
|
|
|
484 |
|
| 32352 |
amit.gupta |
485 |
$(document).on('click', '.viewPurchaseOrderlineItem', function () {
|
|
|
486 |
var purchaseOrderId = $(this).data('poid');
|
| 32145 |
tejbeer |
487 |
|
| 32352 |
amit.gupta |
488 |
doGetAjaxRequestHandler(context + "/getWarehouseLineItemByPurchaseId?purchaseId=" + purchaseOrderId, function (response) {
|
|
|
489 |
$('#warehouseLineItem .modal-content').html(response);
|
| 32145 |
tejbeer |
490 |
|
| 32352 |
amit.gupta |
491 |
});
|
|
|
492 |
});
|
| 32145 |
tejbeer |
493 |
|
|
|
494 |
|
| 32352 |
amit.gupta |
495 |
$(document).on("click", '.removeInPurchaseOrder', function () {
|
|
|
496 |
var row = $(this).closest("tr");
|
| 32361 |
amit.gupta |
497 |
let itemId = row.find('.transferPrice').data('itemid');
|
| 32360 |
amit.gupta |
498 |
let itemIndex = purchaseItemIds.indexOf(itemId);
|
| 32352 |
amit.gupta |
499 |
if (itemIndex > -1) { // only splice array when item is found
|
|
|
500 |
purchaseItemIds.splice(itemIndex, 1); // 2nd parameter means remove one item only
|
|
|
501 |
}
|
|
|
502 |
row.remove();
|
|
|
503 |
});
|
| 32192 |
tejbeer |
504 |
|
|
|
505 |
|
| 32352 |
amit.gupta |
506 |
$(document).on('click', ".addRowForInvoiceItem", function () {
|
| 32145 |
tejbeer |
507 |
|
| 32352 |
amit.gupta |
508 |
var numitems = $(this).data("numitems");
|
|
|
509 |
var invoiceId = $(this).data("invoiceid");
|
|
|
510 |
var invoiceItemIds = [];
|
| 32360 |
amit.gupta |
511 |
var totalQty = 0;
|
| 32145 |
tejbeer |
512 |
|
| 32352 |
amit.gupta |
513 |
$("#invoice-order-table > tbody > tr").each(function () {
|
|
|
514 |
var itemId = $(this).find(".rate").data('itemid');
|
|
|
515 |
var qty = $(this).find(".qty").val();
|
| 32145 |
tejbeer |
516 |
|
| 32360 |
amit.gupta |
517 |
if (qty !== undefined) {
|
|
|
518 |
totalQty += qty;
|
| 32352 |
amit.gupta |
519 |
}
|
| 32145 |
tejbeer |
520 |
|
| 32360 |
amit.gupta |
521 |
if (itemId !== undefined) {
|
|
|
522 |
invoiceItemIds.push(itemId);
|
| 32352 |
amit.gupta |
523 |
}
|
|
|
524 |
});
|
| 32145 |
tejbeer |
525 |
|
| 32352 |
amit.gupta |
526 |
var $html = $('<tr> <td> <input type="text" class="form-control typeaheaditem" autocomplete="off" placeholder="Search Model"/> </td>' +
|
|
|
527 |
'<td> <input type="number" class="form-control qty" name = "qty" placeholder="Quantity"/> </td>' +
|
| 32364 |
amit.gupta |
528 |
'<td> <input type="number" class="form-control rate" placeholder="Rate"/> </td>' +
|
| 32352 |
amit.gupta |
529 |
'<td> <input class="form-control btn btn-primary removeInInvoiceItem" type="button" value="Remove"></td> </tr> ');
|
| 32145 |
tejbeer |
530 |
|
|
|
531 |
|
| 32352 |
amit.gupta |
532 |
getItemAheadOptions($html.find('.typeaheaditem'), true, function (
|
|
|
533 |
selectedItem) {
|
|
|
534 |
var itemId = selectedItem.itemId;
|
|
|
535 |
if (invoiceItemIds.indexOf(itemId) > -1) {
|
|
|
536 |
alert("Item already added");
|
|
|
537 |
$html.find('.typeaheaditem').val("")
|
| 32145 |
tejbeer |
538 |
|
| 32352 |
amit.gupta |
539 |
return false;
|
|
|
540 |
}
|
|
|
541 |
$html.find('.rate').data('itemid', itemId)
|
| 32145 |
tejbeer |
542 |
|
| 32352 |
amit.gupta |
543 |
$html.find('.removeInInvoiceItem').data('invoiceid', invoiceId)
|
|
|
544 |
$html.find('.removeInInvoiceItem').data('itemid', itemId)
|
| 32145 |
tejbeer |
545 |
|
| 37564 |
amit |
546 |
}, true);
|
| 32145 |
tejbeer |
547 |
|
| 32192 |
tejbeer |
548 |
|
| 32352 |
amit.gupta |
549 |
if (totalQty < numitems) {
|
| 32192 |
tejbeer |
550 |
|
| 32352 |
amit.gupta |
551 |
$('#invoice-order-table tbody').append($html);
|
|
|
552 |
}
|
| 32192 |
tejbeer |
553 |
|
| 32352 |
amit.gupta |
554 |
});
|
| 32256 |
tejbeer |
555 |
|
| 32192 |
tejbeer |
556 |
|
| 32352 |
amit.gupta |
557 |
$(document).on('click', '.saveInvoiceDetail', function () {
|
| 32192 |
tejbeer |
558 |
|
| 32352 |
amit.gupta |
559 |
var numItems = $(this).data("numitems");
|
|
|
560 |
var invoiceId = $(this).data("invoiceid");
|
|
|
561 |
var warehouseId = $(this).data("warehouseid");
|
|
|
562 |
var supplierId = $(this).data("supplierid");
|
|
|
563 |
getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, false);
|
| 32192 |
tejbeer |
564 |
|
| 32352 |
amit.gupta |
565 |
});
|
| 32192 |
tejbeer |
566 |
|
|
|
567 |
|
| 32352 |
amit.gupta |
568 |
$(document).on('click', '.validateInvoiceDetail', function () {
|
|
|
569 |
var numItems = $(this).data("numitems");
|
|
|
570 |
var invoiceId = $(this).data("invoiceid");
|
|
|
571 |
var warehouseId = $(this).data("warehouseid");
|
|
|
572 |
var supplierId = $(this).data("supplierid");
|
| 32192 |
tejbeer |
573 |
|
| 32352 |
amit.gupta |
574 |
getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, true);
|
| 32192 |
tejbeer |
575 |
|
| 32352 |
amit.gupta |
576 |
});
|
| 32192 |
tejbeer |
577 |
|
|
|
578 |
|
| 32352 |
amit.gupta |
579 |
$(document).on("click", '.removeInInvoiceItem', function () {
|
| 32192 |
tejbeer |
580 |
|
| 32352 |
amit.gupta |
581 |
var row = $(this).closest("tr");
|
|
|
582 |
var invoiceId = $(this).data("invoiceid");
|
|
|
583 |
var itemId = $(this).data("itemid");
|
|
|
584 |
if (invoiceId != undefined && itemId != undefined) {
|
|
|
585 |
doDeleteAjaxRequestHandler(context + "/removeInvoiceItem?invoiceId="
|
|
|
586 |
+ invoiceId + "&itemId=" + itemId, function (response) {
|
|
|
587 |
if (response == "true") {
|
|
|
588 |
alert("Item removed successfully");
|
| 32192 |
tejbeer |
589 |
|
| 32352 |
amit.gupta |
590 |
}
|
|
|
591 |
});
|
|
|
592 |
}
|
| 32192 |
tejbeer |
593 |
|
| 32352 |
amit.gupta |
594 |
row.remove();
|
| 32192 |
tejbeer |
595 |
|
| 32352 |
amit.gupta |
596 |
});
|
| 32192 |
tejbeer |
597 |
|
|
|
598 |
|
| 32352 |
amit.gupta |
599 |
$(document).on('click', '.purchaseGrn', function () {
|
| 32192 |
tejbeer |
600 |
|
| 32352 |
amit.gupta |
601 |
var grnItemArray = [];
|
| 32192 |
tejbeer |
602 |
|
| 32352 |
amit.gupta |
603 |
var invoiceId = $(this).data("invoiceid");
|
| 32192 |
tejbeer |
604 |
|
| 32352 |
amit.gupta |
605 |
$("#invoice-purchase-validate > tbody > tr").each(function () {
|
|
|
606 |
var grnItemJson = {};
|
| 32192 |
tejbeer |
607 |
|
| 32352 |
amit.gupta |
608 |
var itemId = $(this).find(".itemId").text();
|
|
|
609 |
var qty = $(this).find(".qty").text();
|
|
|
610 |
var poId = $(this).find(".purchaseId").text();
|
|
|
611 |
var excessQty = $(this).find(".excessQty").text();
|
|
|
612 |
var itemType = $(this).find(".itemType").text();
|
| 32192 |
tejbeer |
613 |
|
| 32352 |
amit.gupta |
614 |
console.log(itemType);
|
| 32192 |
tejbeer |
615 |
|
| 32352 |
amit.gupta |
616 |
if (itemType == "Serialized") {
|
|
|
617 |
var serialNumbers = $(this).find(".imeis-to-grn").tagsinput('items');
|
| 32366 |
amit.gupta |
618 |
grnItemJson['serialNumbers'] = serialNumbers;
|
| 32192 |
tejbeer |
619 |
|
| 32352 |
amit.gupta |
620 |
if (excessQty > 0) {
|
|
|
621 |
var returnSerialNumbers = $(this).find(".imeis-to-grn-return").tagsinput('items');
|
|
|
622 |
grnItemJson['returnSerialNumbers'] = returnSerialNumbers
|
|
|
623 |
}
|
|
|
624 |
}
|
| 32366 |
amit.gupta |
625 |
console.log(serialNumbers);
|
| 32352 |
amit.gupta |
626 |
grnItemJson['itemId'] = itemId;
|
|
|
627 |
grnItemJson['serialNumbers'] = serialNumbers
|
|
|
628 |
grnItemJson['qty'] = qty
|
|
|
629 |
grnItemJson['poId'] = poId
|
|
|
630 |
grnItemJson['invoiceId'] = invoiceId
|
|
|
631 |
grnItemJson['itemType'] = itemType
|
|
|
632 |
grnItemJson['excessQty'] = excessQty
|
| 32192 |
tejbeer |
633 |
|
| 32352 |
amit.gupta |
634 |
grnItemJson['returnSerialNumbers'] = returnSerialNumbers
|
| 32192 |
tejbeer |
635 |
|
| 32352 |
amit.gupta |
636 |
grnItemArray.push(grnItemJson)
|
| 32192 |
tejbeer |
637 |
|
| 32352 |
amit.gupta |
638 |
console.log(grnItemArray)
|
| 32192 |
tejbeer |
639 |
|
| 32352 |
amit.gupta |
640 |
});
|
| 32192 |
tejbeer |
641 |
|
| 32352 |
amit.gupta |
642 |
for (var i = 0; i < grnItemArray.length; i++) {
|
| 32366 |
amit.gupta |
643 |
var itemType = grnItemArray[i].itemType;
|
| 32192 |
tejbeer |
644 |
|
| 32352 |
amit.gupta |
645 |
if (itemType == "Serialized") {
|
|
|
646 |
var excessQty = grnItemArray[i].excessQty
|
| 32192 |
tejbeer |
647 |
|
|
|
648 |
|
| 32352 |
amit.gupta |
649 |
var serialNumbers = grnItemArray[i].serialNumbers.length
|
|
|
650 |
var qty = grnItemArray[i].qty
|
| 32192 |
tejbeer |
651 |
|
| 32352 |
amit.gupta |
652 |
if (serialNumbers != qty) {
|
|
|
653 |
alert("serial number is not matched with qty")
|
|
|
654 |
return false;
|
|
|
655 |
}
|
| 32192 |
tejbeer |
656 |
|
| 32352 |
amit.gupta |
657 |
if (excessQty > 0) {
|
| 32192 |
tejbeer |
658 |
|
| 32352 |
amit.gupta |
659 |
var returnSerialNumbers = grnItemArray[i].returnSerialNumbers.length
|
| 32192 |
tejbeer |
660 |
|
| 32352 |
amit.gupta |
661 |
if (returnSerialNumbers != excessQty) {
|
|
|
662 |
alert("Return serial number is not matched with excess qty")
|
|
|
663 |
return false;
|
|
|
664 |
}
|
| 32192 |
tejbeer |
665 |
|
| 32352 |
amit.gupta |
666 |
}
|
|
|
667 |
}
|
| 32192 |
tejbeer |
668 |
|
| 32352 |
amit.gupta |
669 |
}
|
| 32192 |
tejbeer |
670 |
|
|
|
671 |
|
| 32352 |
amit.gupta |
672 |
console.log(JSON.stringify(grnItemArray))
|
|
|
673 |
if (confirm("Are you sure you want to grn purchase order") == true) {
|
| 32192 |
tejbeer |
674 |
|
| 32352 |
amit.gupta |
675 |
doPostAjaxRequestWithJsonHandler(context
|
|
|
676 |
+ "/createGrn", JSON
|
|
|
677 |
.stringify(grnItemArray), function (response) {
|
|
|
678 |
if (response == 'true') {
|
|
|
679 |
alert("successfully done");
|
|
|
680 |
loadNewReceiveInvoice("main-content");
|
|
|
681 |
}
|
|
|
682 |
});
|
|
|
683 |
}
|
| 32192 |
tejbeer |
684 |
|
|
|
685 |
|
| 32352 |
amit.gupta |
686 |
});
|
| 32256 |
tejbeer |
687 |
|
|
|
688 |
|
| 32352 |
amit.gupta |
689 |
$(document).on('click', '.grnRequest', function () {
|
| 32192 |
tejbeer |
690 |
|
| 32352 |
amit.gupta |
691 |
var grnRequestJson = {};
|
|
|
692 |
var grnRequestItemArray = [];
|
| 32192 |
tejbeer |
693 |
|
| 32352 |
amit.gupta |
694 |
var invoiceId = $(this).data("invoiceid");
|
| 32192 |
tejbeer |
695 |
|
|
|
696 |
|
| 32352 |
amit.gupta |
697 |
$("#invoice-purchase-validate > tbody > tr").each(function () {
|
|
|
698 |
var grnItemJson = {};
|
| 32192 |
tejbeer |
699 |
|
| 32352 |
amit.gupta |
700 |
var itemId = $.trim($(this).find(".itemId").text());
|
|
|
701 |
var poId = $.trim($(this).find(".purchaseId").text());
|
| 32192 |
tejbeer |
702 |
|
| 32352 |
amit.gupta |
703 |
var qty = parseInt($(this).find(".qty").text());
|
| 32256 |
tejbeer |
704 |
|
| 32352 |
amit.gupta |
705 |
var excessQty = parseInt($(this).find(".excessQty").text());
|
| 32256 |
tejbeer |
706 |
|
| 32352 |
amit.gupta |
707 |
var priceMismatch = $.trim($(this).find(".priceMismatch").text());
|
|
|
708 |
console.log(priceMismatch)
|
| 32256 |
tejbeer |
709 |
|
|
|
710 |
|
| 32354 |
amit.gupta |
711 |
if (priceMismatch !== "" || excessQty > 0) {
|
| 32352 |
amit.gupta |
712 |
console.log(typeof priceMismatch)
|
|
|
713 |
console.log(excessQty)
|
|
|
714 |
grnItemJson['itemId'] = itemId;
|
|
|
715 |
grnItemJson['qty'] = qty;
|
|
|
716 |
grnItemJson['excessQty'] = excessQty
|
| 32376 |
amit.gupta |
717 |
if (priceMismatch === '') {
|
|
|
718 |
grnItemJson['mismatch'] = 'QtyMismatch';
|
|
|
719 |
} else {
|
|
|
720 |
grnItemJson['mismatch'] = priceMismatch
|
|
|
721 |
}
|
| 32352 |
amit.gupta |
722 |
grnItemJson['poId'] = poId
|
| 32192 |
tejbeer |
723 |
|
| 32352 |
amit.gupta |
724 |
grnRequestItemArray.push(grnItemJson)
|
|
|
725 |
}
|
|
|
726 |
});
|
| 32256 |
tejbeer |
727 |
|
| 32352 |
amit.gupta |
728 |
console.log(grnRequestItemArray)
|
| 32256 |
tejbeer |
729 |
|
|
|
730 |
|
| 32352 |
amit.gupta |
731 |
grnRequestJson['invoiceId'] = invoiceId;
|
|
|
732 |
grnRequestJson['warehousePurchaseModel'] = grnRequestItemArray
|
| 32256 |
tejbeer |
733 |
|
| 32366 |
amit.gupta |
734 |
if (confirm("Are you sure you want to raise grn request")) {
|
| 32192 |
tejbeer |
735 |
|
| 32352 |
amit.gupta |
736 |
doPostAjaxRequestWithJsonHandler(context
|
|
|
737 |
+ "/grnRequest", JSON
|
|
|
738 |
.stringify(grnRequestJson), function (response) {
|
|
|
739 |
if (response == 'true') {
|
|
|
740 |
alert("successfully done");
|
|
|
741 |
loadNewReceiveInvoice("main-content");
|
|
|
742 |
}
|
|
|
743 |
});
|
|
|
744 |
}
|
| 32192 |
tejbeer |
745 |
|
|
|
746 |
|
| 32352 |
amit.gupta |
747 |
});
|
| 32192 |
tejbeer |
748 |
|
| 32256 |
tejbeer |
749 |
|
| 32352 |
amit.gupta |
750 |
$(document).on('click', '.resolvedPriceMismatchRequest', function () {
|
|
|
751 |
var id = $(this).data("id");
|
| 32256 |
tejbeer |
752 |
|
| 32352 |
amit.gupta |
753 |
var invoiceId = $(this).data("invoiceid");
|
| 32256 |
tejbeer |
754 |
|
| 32352 |
amit.gupta |
755 |
var requestId = $(this).data("requestid");
|
| 32256 |
tejbeer |
756 |
|
| 32352 |
amit.gupta |
757 |
var mismatch = $(this).data("mismatch");
|
| 32256 |
tejbeer |
758 |
|
| 32352 |
amit.gupta |
759 |
if (mismatch == "InvoiceMismatch") {
|
| 32485 |
amit.gupta |
760 |
if (confirm("Are you sure you want to resolve invoice mismatch")) {
|
| 32352 |
amit.gupta |
761 |
doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id, function (response) {
|
|
|
762 |
if (response == 'true') {
|
|
|
763 |
getGrnRequestItems(requestId, invoiceId)
|
|
|
764 |
}
|
|
|
765 |
});
|
| 32256 |
tejbeer |
766 |
|
| 32352 |
amit.gupta |
767 |
}
|
|
|
768 |
} else if (mismatch == "PoMismatch") {
|
|
|
769 |
if (confirm("Are you sure you want to resolve Po Mismatch. Discard the current PoLineItem new Po will generate on the invoice date.") == true) {
|
| 32256 |
tejbeer |
770 |
|
| 32352 |
amit.gupta |
771 |
doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id, function (response) {
|
|
|
772 |
if (response == 'true') {
|
|
|
773 |
getGrnRequestItems(requestId, invoiceId)
|
|
|
774 |
}
|
|
|
775 |
});
|
| 32256 |
tejbeer |
776 |
|
| 32352 |
amit.gupta |
777 |
}
|
|
|
778 |
}
|
| 32256 |
tejbeer |
779 |
|
| 32352 |
amit.gupta |
780 |
});
|
| 32256 |
tejbeer |
781 |
|
|
|
782 |
|
| 32352 |
amit.gupta |
783 |
$(document).on('click', '.resolvedQtyMismatchRequest', function () {
|
|
|
784 |
var id = $(this).data("id");
|
|
|
785 |
var invoiceId = $(this).data("invoiceid");
|
|
|
786 |
var requestId = $(this).data("requestid");
|
| 32256 |
tejbeer |
787 |
|
|
|
788 |
|
| 32352 |
amit.gupta |
789 |
var mismatch = $(this).data("mismatch");
|
| 32256 |
tejbeer |
790 |
|
| 32352 |
amit.gupta |
791 |
var $row = $(this).closest("tr");
|
|
|
792 |
var requiredQty = $row.find(".requiredQty").val();
|
| 32256 |
tejbeer |
793 |
|
| 32352 |
amit.gupta |
794 |
console.log(requiredQty);
|
| 32256 |
tejbeer |
795 |
|
| 32352 |
amit.gupta |
796 |
if (mismatch == "QtyMismatch") {
|
|
|
797 |
if (confirm("Are you sure you want to resolve qty mismatch") == true) {
|
| 32256 |
tejbeer |
798 |
|
| 32352 |
amit.gupta |
799 |
doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id + "&requiredQty=" + requiredQty, function (response) {
|
|
|
800 |
if (response == 'true') {
|
|
|
801 |
getGrnRequestItems(requestId, invoiceId)
|
|
|
802 |
}
|
|
|
803 |
});
|
| 32256 |
tejbeer |
804 |
|
| 32352 |
amit.gupta |
805 |
}
|
|
|
806 |
}
|
| 32256 |
tejbeer |
807 |
|
| 32352 |
amit.gupta |
808 |
});
|
| 32256 |
tejbeer |
809 |
|
| 32192 |
tejbeer |
810 |
|
| 32145 |
tejbeer |
811 |
});
|
|
|
812 |
|
|
|
813 |
function loadCreatePurchase(domId) {
|
| 32352 |
amit.gupta |
814 |
doGetAjaxRequestHandler(context + "/warehousePurchaseOrder", function (response) {
|
|
|
815 |
$('#' + domId).html(response);
|
|
|
816 |
});
|
| 32145 |
tejbeer |
817 |
}
|
|
|
818 |
|
| 32192 |
tejbeer |
819 |
|
| 32145 |
tejbeer |
820 |
function loadOpenPurchase(domId) {
|
|
|
821 |
|
| 32352 |
amit.gupta |
822 |
doGetAjaxRequestHandler(context + "/getOpenPurchaseOrder", function (response) {
|
|
|
823 |
$('#' + domId).html(response);
|
|
|
824 |
});
|
| 32145 |
tejbeer |
825 |
}
|
|
|
826 |
|
| 32192 |
tejbeer |
827 |
function loadNewReceiveInvoice(domId) {
|
| 32352 |
amit.gupta |
828 |
doGetAjaxRequestHandler(context + "/newReceiveInvoice", function (response) {
|
|
|
829 |
$('#' + domId).html(response);
|
|
|
830 |
});
|
| 32192 |
tejbeer |
831 |
}
|
|
|
832 |
|
| 32256 |
tejbeer |
833 |
|
|
|
834 |
function loadGrnRequest(domId) {
|
| 32352 |
amit.gupta |
835 |
doGetAjaxRequestHandler(context + "/grnRequest", function (response) {
|
|
|
836 |
$('#' + domId).html(response);
|
|
|
837 |
});
|
| 32256 |
tejbeer |
838 |
}
|
|
|
839 |
|
|
|
840 |
function loadDebitNote(domId) {
|
| 32352 |
amit.gupta |
841 |
doGetAjaxRequestHandler(context + "/getDebitNote", function (response) {
|
|
|
842 |
$('#' + domId).html(response);
|
|
|
843 |
});
|
| 32256 |
tejbeer |
844 |
}
|
|
|
845 |
|
| 33729 |
ranu |
846 |
$(document).on('click', '.dateWiseDebitNote', function () {
|
|
|
847 |
|
|
|
848 |
var startDate = getDatesFromPicker('input[name="date-duration"]').startDate;
|
|
|
849 |
var endDate = getDatesFromPicker('input[name="date-duration"]').endDate;
|
|
|
850 |
|
|
|
851 |
|
|
|
852 |
doGetAjaxRequestHandler(context + "/getDateWiseDebitNote?startDate=" + startDate + "&endDate=" + endDate, function (response) {
|
|
|
853 |
$('#warehouse-datewise-debitnote-container').html(response);
|
|
|
854 |
|
|
|
855 |
});
|
|
|
856 |
});
|
|
|
857 |
|
|
|
858 |
$(document).on('click', '.generateVendorDebitNoteExcel', function () {
|
|
|
859 |
var startDate = getDatesFromPicker('input[name="date-duration"]').startDate;
|
|
|
860 |
var endDate = getDatesFromPicker('input[name="date-duration"]').endDate;
|
| 33809 |
ranu |
861 |
doAjaxGetDownload(context + "/generateVendorDebitNoteExcel?startDate=" + startDate + "&endDate=" + endDate, "VendorDebitNoteReport.csv");
|
| 33729 |
ranu |
862 |
});
|
|
|
863 |
|
| 32300 |
tejbeer |
864 |
function loadWarehouseInvoices(domId) {
|
| 32352 |
amit.gupta |
865 |
doGetAjaxRequestHandler(context + "/getWarehouseInvoices", function (response) {
|
|
|
866 |
$('#' + domId).html(response);
|
|
|
867 |
});
|
| 32300 |
tejbeer |
868 |
}
|
|
|
869 |
|
| 32390 |
amit.gupta |
870 |
function createPO(sendPo) {
|
| 32352 |
amit.gupta |
871 |
var purchaseOrder = {};
|
| 32145 |
tejbeer |
872 |
|
| 32352 |
amit.gupta |
873 |
var vendorId = $('#vendorId').val();
|
| 32145 |
tejbeer |
874 |
|
| 32352 |
amit.gupta |
875 |
var warehouseId = $('#warehouseMap').val();
|
| 32145 |
tejbeer |
876 |
|
| 32390 |
amit.gupta |
877 |
var poDate = $('#poDate').val();
|
| 32145 |
tejbeer |
878 |
|
| 32390 |
amit.gupta |
879 |
|
| 32352 |
amit.gupta |
880 |
var items = []
|
|
|
881 |
$("table > tbody > tr").each(function () {
|
|
|
882 |
var purchaseOrderJson = {};
|
| 32145 |
tejbeer |
883 |
|
| 32352 |
amit.gupta |
884 |
var itemId = $(this).find(".transferPrice").data('itemid');
|
|
|
885 |
var qty = $(this).find(".qty").val();
|
|
|
886 |
var transferPrice = $(this).find(".transferPrice").val();
|
|
|
887 |
var totalValue = $(this).find(".totalValue").val();
|
| 32145 |
tejbeer |
888 |
|
|
|
889 |
|
| 32352 |
amit.gupta |
890 |
purchaseOrderJson['itemId'] = itemId;
|
|
|
891 |
purchaseOrderJson['amendedQty'] = qty
|
|
|
892 |
purchaseOrderJson['totalValue'] = totalValue
|
|
|
893 |
purchaseOrderJson['transferPrice'] = transferPrice
|
| 32145 |
tejbeer |
894 |
|
| 32352 |
amit.gupta |
895 |
items.push(purchaseOrderJson)
|
|
|
896 |
});
|
| 32145 |
tejbeer |
897 |
|
|
|
898 |
|
| 32352 |
amit.gupta |
899 |
for (var i = 0; i < items.length; i++) {
|
|
|
900 |
console.log(items[i])
|
| 32145 |
tejbeer |
901 |
|
| 32352 |
amit.gupta |
902 |
var itemId = items[i].itemId
|
|
|
903 |
var qty = items[i].amendedQty
|
|
|
904 |
var transferPrice = items[i].transferPrice
|
|
|
905 |
var totalValue = items[i].totalValue
|
| 32145 |
tejbeer |
906 |
|
| 32352 |
amit.gupta |
907 |
if (itemId === "" && qty === "" && transferPrice === "" && totalValue === "") {
|
|
|
908 |
alert("Field can't be empty");
|
|
|
909 |
return false;
|
|
|
910 |
}
|
| 32145 |
tejbeer |
911 |
|
|
|
912 |
|
| 32352 |
amit.gupta |
913 |
if (itemId === "") {
|
|
|
914 |
alert("please select item");
|
|
|
915 |
return false;
|
|
|
916 |
}
|
|
|
917 |
if (qty === "") {
|
|
|
918 |
alert("please choose qty");
|
|
|
919 |
return false;
|
|
|
920 |
}
|
| 32145 |
tejbeer |
921 |
|
| 32352 |
amit.gupta |
922 |
if (transferPrice === "") {
|
|
|
923 |
alert("Transfer Price can't be empty");
|
|
|
924 |
return false;
|
|
|
925 |
}
|
|
|
926 |
if (totalValue === "") {
|
|
|
927 |
alert("Total value can't be empty");
|
|
|
928 |
return false;
|
|
|
929 |
}
|
| 32145 |
tejbeer |
930 |
|
| 32352 |
amit.gupta |
931 |
if (qty <= 0) {
|
|
|
932 |
alert("Please fill Qty");
|
|
|
933 |
return false;
|
|
|
934 |
}
|
| 32145 |
tejbeer |
935 |
|
|
|
936 |
|
| 32352 |
amit.gupta |
937 |
}
|
| 32261 |
tejbeer |
938 |
|
| 32352 |
amit.gupta |
939 |
purchaseOrder['vendorId'] = vendorId;
|
|
|
940 |
purchaseOrder['warehouseId'] = warehouseId
|
|
|
941 |
purchaseOrder['sendPo'] = sendPo
|
| 32390 |
amit.gupta |
942 |
purchaseOrder['poDate'] = poDate;
|
| 32352 |
amit.gupta |
943 |
purchaseOrder['items'] = items
|
| 32145 |
tejbeer |
944 |
|
| 32352 |
amit.gupta |
945 |
console.log(purchaseOrder)
|
| 32145 |
tejbeer |
946 |
|
|
|
947 |
|
| 32352 |
amit.gupta |
948 |
if (confirm("Are you sure you want to create purchase order") == true) {
|
| 32145 |
tejbeer |
949 |
|
| 32352 |
amit.gupta |
950 |
doPostAjaxRequestWithJsonHandler(context
|
|
|
951 |
+ "/createPurchaseOrder", JSON
|
|
|
952 |
.stringify(purchaseOrder), function (response) {
|
|
|
953 |
if (response == 'true') {
|
|
|
954 |
alert("successfully created");
|
|
|
955 |
loadCreatePurchase("main-content");
|
|
|
956 |
}
|
|
|
957 |
});
|
|
|
958 |
}
|
| 32145 |
tejbeer |
959 |
|
|
|
960 |
}
|
|
|
961 |
|
|
|
962 |
|
|
|
963 |
function editPurchase(sendPo, poid) {
|
| 32352 |
amit.gupta |
964 |
var editpurchaseOrder = {}
|
|
|
965 |
var items = []
|
|
|
966 |
$("#purchase-edit-lineitem > tbody > tr").each(function () {
|
|
|
967 |
var purchaseOrderJson = {};
|
|
|
968 |
var itemId = $(this).find("td:eq(0)").text();
|
| 32145 |
tejbeer |
969 |
|
| 32352 |
amit.gupta |
970 |
var qty = $(this).find("td:eq(2)").text();
|
| 32145 |
tejbeer |
971 |
|
| 32352 |
amit.gupta |
972 |
var amendedQty = $(this).find(".editqty").val();
|
| 32256 |
tejbeer |
973 |
|
| 32352 |
amit.gupta |
974 |
var transferPrice = $.trim($(this).find(".transferPrice").html());
|
| 32256 |
tejbeer |
975 |
|
|
|
976 |
|
| 32352 |
amit.gupta |
977 |
purchaseOrderJson['itemId'] = itemId;
|
|
|
978 |
purchaseOrderJson['amendedQty'] = parseInt(amendedQty)
|
|
|
979 |
purchaseOrderJson['qty'] = parseInt(qty)
|
|
|
980 |
purchaseOrderJson['transferPrice'] = transferPrice
|
| 32145 |
tejbeer |
981 |
|
| 32352 |
amit.gupta |
982 |
items.push(purchaseOrderJson)
|
|
|
983 |
});
|
| 32145 |
tejbeer |
984 |
|
|
|
985 |
|
| 32352 |
amit.gupta |
986 |
for (var i = 0; i < items.length; i++) {
|
|
|
987 |
console.log(items[i])
|
| 32145 |
tejbeer |
988 |
|
| 32352 |
amit.gupta |
989 |
var amendedQty = items[i].amendedQty
|
|
|
990 |
var qty = items[i].qty
|
| 32145 |
tejbeer |
991 |
|
| 32256 |
tejbeer |
992 |
|
| 32352 |
amit.gupta |
993 |
if (amendedQty === "") {
|
|
|
994 |
alert("please choose qty");
|
|
|
995 |
return false;
|
|
|
996 |
}
|
| 32145 |
tejbeer |
997 |
|
| 32352 |
amit.gupta |
998 |
if (amendedQty < qty) {
|
|
|
999 |
alert("Quantity should be greater than existing qty");
|
|
|
1000 |
return false;
|
|
|
1001 |
}
|
| 32145 |
tejbeer |
1002 |
|
|
|
1003 |
|
| 32352 |
amit.gupta |
1004 |
}
|
| 32145 |
tejbeer |
1005 |
|
| 32352 |
amit.gupta |
1006 |
editpurchaseOrder['purchaseOrderId'] = poid;
|
|
|
1007 |
editpurchaseOrder['sendPo'] = sendPo
|
|
|
1008 |
editpurchaseOrder['items'] = items
|
| 32145 |
tejbeer |
1009 |
|
|
|
1010 |
|
| 32352 |
amit.gupta |
1011 |
if (confirm("Are you sure you want to edit purchase order") == true) {
|
| 32145 |
tejbeer |
1012 |
|
| 32352 |
amit.gupta |
1013 |
doPostAjaxRequestWithJsonHandler(context
|
|
|
1014 |
+ "/editPurchaseOrder", JSON
|
|
|
1015 |
.stringify(editpurchaseOrder), function (response) {
|
|
|
1016 |
if (response == 'true') {
|
|
|
1017 |
alert("successfully created");
|
|
|
1018 |
$('#warehouseEditPurchaseContainer').modal('hide');
|
|
|
1019 |
$('.modal-backdrop').remove();
|
| 32295 |
tejbeer |
1020 |
|
| 32352 |
amit.gupta |
1021 |
loadOpenPurchase("main-content")
|
|
|
1022 |
}
|
|
|
1023 |
});
|
|
|
1024 |
}
|
| 32145 |
tejbeer |
1025 |
|
|
|
1026 |
}
|
|
|
1027 |
|
|
|
1028 |
|
| 32192 |
tejbeer |
1029 |
function getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, validate) {
|
|
|
1030 |
|
| 32352 |
amit.gupta |
1031 |
var invoiceJson = {};
|
|
|
1032 |
console.log(numItems)
|
|
|
1033 |
var totalQty = 0;
|
|
|
1034 |
var invoiceItems = []
|
|
|
1035 |
$("#invoice-order-table > tbody > tr").each(function () {
|
|
|
1036 |
var invoiceItemJson = {};
|
|
|
1037 |
var itemId = $(this).find(".rate").data('itemid');
|
|
|
1038 |
var qty = $(this).find(".qty").val();
|
| 32192 |
tejbeer |
1039 |
|
| 32352 |
amit.gupta |
1040 |
if (qty != undefined) {
|
|
|
1041 |
totalQty += parseInt(qty)
|
|
|
1042 |
}
|
|
|
1043 |
var rate = $(this).find(".rate").val();
|
|
|
1044 |
invoiceItemJson['itemId'] = itemId;
|
|
|
1045 |
invoiceItemJson['qty'] = qty
|
|
|
1046 |
invoiceItemJson['rate'] = rate
|
|
|
1047 |
invoiceItems.push(invoiceItemJson)
|
|
|
1048 |
});
|
| 32192 |
tejbeer |
1049 |
|
|
|
1050 |
|
| 32352 |
amit.gupta |
1051 |
for (var i = 0; i < invoiceItems.length; i++) {
|
| 32192 |
tejbeer |
1052 |
|
| 32352 |
amit.gupta |
1053 |
var itemId = invoiceItems[i].itemId
|
|
|
1054 |
var qty = invoiceItems[i].qty
|
|
|
1055 |
var rate = invoiceItems[i].rate
|
|
|
1056 |
if (itemId === "" && qty === "" && rate === "") {
|
|
|
1057 |
alert("Field can't be empty");
|
|
|
1058 |
return false;
|
|
|
1059 |
}
|
| 32192 |
tejbeer |
1060 |
|
| 32352 |
amit.gupta |
1061 |
if (itemId === "") {
|
|
|
1062 |
alert("please select item");
|
|
|
1063 |
return false;
|
|
|
1064 |
}
|
|
|
1065 |
if (qty === "") {
|
|
|
1066 |
alert("please choose qty");
|
|
|
1067 |
return false;
|
|
|
1068 |
}
|
| 32192 |
tejbeer |
1069 |
|
| 32352 |
amit.gupta |
1070 |
if (rate === "") {
|
|
|
1071 |
alert("Rate can't be empty");
|
|
|
1072 |
return false;
|
|
|
1073 |
}
|
| 32192 |
tejbeer |
1074 |
|
| 32352 |
amit.gupta |
1075 |
}
|
| 32192 |
tejbeer |
1076 |
|
| 32352 |
amit.gupta |
1077 |
console.log(totalQty)
|
| 32192 |
tejbeer |
1078 |
|
| 32352 |
amit.gupta |
1079 |
if (totalQty > numItems) {
|
|
|
1080 |
alert("Qty Should not be more than Invoice items");
|
|
|
1081 |
return false;
|
|
|
1082 |
}
|
| 32192 |
tejbeer |
1083 |
|
| 32352 |
amit.gupta |
1084 |
if (validate) {
|
| 32192 |
tejbeer |
1085 |
|
| 32352 |
amit.gupta |
1086 |
if (totalQty != numItems) {
|
|
|
1087 |
alert("Qty Should not match with Invoice items");
|
|
|
1088 |
return false;
|
|
|
1089 |
}
|
|
|
1090 |
}
|
| 32192 |
tejbeer |
1091 |
|
|
|
1092 |
|
| 32352 |
amit.gupta |
1093 |
invoiceJson['invoiceId'] = invoiceId;
|
|
|
1094 |
invoiceJson['warehouseId'] = warehouseId;
|
|
|
1095 |
invoiceJson['supplierId'] = supplierId;
|
|
|
1096 |
invoiceJson['invoiceItems'] = invoiceItems
|
|
|
1097 |
if (validate) {
|
|
|
1098 |
validateInvoiceItems(invoiceJson);
|
|
|
1099 |
} else {
|
|
|
1100 |
saveInvoiceItems(invoiceJson)
|
|
|
1101 |
}
|
| 32192 |
tejbeer |
1102 |
}
|
|
|
1103 |
|
|
|
1104 |
|
|
|
1105 |
function saveInvoiceItems(invoiceJson) {
|
|
|
1106 |
|
|
|
1107 |
|
| 32352 |
amit.gupta |
1108 |
if (confirm("Are you sure you want to save invoice item") == true) {
|
| 32192 |
tejbeer |
1109 |
|
| 32352 |
amit.gupta |
1110 |
doPostAjaxRequestWithJsonHandler(context
|
|
|
1111 |
+ "/invoiceItemDetail", JSON
|
|
|
1112 |
.stringify(invoiceJson), function (response) {
|
|
|
1113 |
if (response == 'true') {
|
|
|
1114 |
getInvoiceItems(invoiceJson.invoiceId);
|
|
|
1115 |
}
|
|
|
1116 |
});
|
|
|
1117 |
}
|
| 32192 |
tejbeer |
1118 |
|
|
|
1119 |
}
|
|
|
1120 |
|
|
|
1121 |
|
|
|
1122 |
function validateInvoiceItems(invoiceJson) {
|
|
|
1123 |
|
|
|
1124 |
|
| 32352 |
amit.gupta |
1125 |
if (confirm("Are you sure you want to validate invoice item") == true) {
|
| 32192 |
tejbeer |
1126 |
|
| 32352 |
amit.gupta |
1127 |
doPostAjaxRequestWithJsonHandler(context
|
|
|
1128 |
+ "/validateInvoiceItemDetail", JSON
|
|
|
1129 |
.stringify(invoiceJson), function (response) {
|
|
|
1130 |
$('.invoiceadditemcontainer').html(response);
|
| 32192 |
tejbeer |
1131 |
|
| 32352 |
amit.gupta |
1132 |
});
|
|
|
1133 |
}
|
| 32192 |
tejbeer |
1134 |
|
|
|
1135 |
}
|
|
|
1136 |
|
|
|
1137 |
function getOpenPOFromWarehouse() {
|
|
|
1138 |
|
| 32352 |
amit.gupta |
1139 |
var warehouseId = $('#warehouseMap').val();
|
|
|
1140 |
doGetAjaxRequestHandler(context + "/getOpenPurchaseOrderByWarehouseId?warehouseId=" + warehouseId, function (response) {
|
|
|
1141 |
$('#warehouseManagePuchaseContainer').html(response);
|
|
|
1142 |
});
|
| 32192 |
tejbeer |
1143 |
|
|
|
1144 |
|
|
|
1145 |
}
|
|
|
1146 |
|
|
|
1147 |
function getPurchaseLineitem(poId) {
|
|
|
1148 |
|
|
|
1149 |
|
| 32352 |
amit.gupta |
1150 |
doGetAjaxRequestHandler(context + "/getPurchaseOrderItemByPoId?poId=" + poId, function (response) {
|
|
|
1151 |
$('#warehouseManagePuchaseItemContainer').html(response);
|
|
|
1152 |
$('#warehousepurchaseitemgrn').hide()
|
|
|
1153 |
});
|
| 32192 |
tejbeer |
1154 |
|
|
|
1155 |
|
|
|
1156 |
}
|
|
|
1157 |
|
|
|
1158 |
|
|
|
1159 |
function getInvoiceItems(invoiceId) {
|
|
|
1160 |
|
| 32352 |
amit.gupta |
1161 |
doGetAjaxRequestHandler(context + "/getInvoiceItems?invoiceId=" + invoiceId, function (response) {
|
|
|
1162 |
$('.invoiceadditemcontainer').html(response);
|
| 32192 |
tejbeer |
1163 |
|
| 32352 |
amit.gupta |
1164 |
});
|
| 32192 |
tejbeer |
1165 |
}
|
|
|
1166 |
|
|
|
1167 |
|
| 32256 |
tejbeer |
1168 |
function getGrnRequestItems(requestId, invoiceId) {
|
| 32352 |
amit.gupta |
1169 |
doGetAjaxRequestHandler(context + "/grnRequestItem?requestId=" + requestId + "&invoiceId=" + invoiceId, function (response) {
|
|
|
1170 |
$('.grnRequestItemContainer').html(response);
|
| 32256 |
tejbeer |
1171 |
|
| 32352 |
amit.gupta |
1172 |
});
|
| 32256 |
tejbeer |
1173 |
}
|
|
|
1174 |
|
| 32912 |
amit.gupta |
1175 |
function removeInvoice(invoiceId) {
|
| 34047 |
tejus.loha |
1176 |
if (confirm(`Are your sure want to delete invoiceId ${invoiceId}`)) {
|
| 32912 |
amit.gupta |
1177 |
doGetAjaxRequestHandler(`${context}/removeInvoice?invoiceId=${invoiceId}`, function (response) {
|
| 34047 |
tejus.loha |
1178 |
$('#open-invoices').DataTable().row("#" + invoiceId).remove().draw();
|
| 32912 |
amit.gupta |
1179 |
alert("Invoice Removed");
|
|
|
1180 |
});
|
|
|
1181 |
}
|
|
|
1182 |
}
|
| 32256 |
tejbeer |
1183 |
|
| 32912 |
amit.gupta |
1184 |
function removeGrnRequest(invoiceId) {
|
| 34047 |
tejus.loha |
1185 |
if (confirm(`Are your sure want to remove grn request for invoiceId ${invoiceId}`)) {
|
| 32912 |
amit.gupta |
1186 |
doGetAjaxRequestHandler(`${context}/removeGrnRequest?invoiceId=${invoiceId}`, function (response) {
|
|
|
1187 |
$('#' + domId).html(response);
|
|
|
1188 |
alert("Grn Request Removed");
|
|
|
1189 |
});
|
|
|
1190 |
}
|
|
|
1191 |
}
|
|
|
1192 |
|
|
|
1193 |
|
| 35806 |
amit |
1194 |
// ============ GRN Correction ============
|
|
|
1195 |
|
|
|
1196 |
$(document).on('click', '.warehouse-grn-correction', function () {
|
|
|
1197 |
loadGrnCorrection("main-content");
|
|
|
1198 |
});
|
|
|
1199 |
|
|
|
1200 |
$(document).on('click', '.warehouse-grn-correction-approval', function () {
|
|
|
1201 |
loadGrnCorrectionApproval("main-content");
|
|
|
1202 |
});
|
|
|
1203 |
|
|
|
1204 |
$(document).on('click', '.searchCorrectionInvoices', function () {
|
|
|
1205 |
var startDate = getDatesFromPicker('input[name="correction-duration"]').startDate;
|
|
|
1206 |
var endDate = getDatesFromPicker('input[name="correction-duration"]').endDate;
|
|
|
1207 |
doGetAjaxRequestHandler(context + "/grnCorrection?startDate=" + startDate + "&endDate=" + endDate, function (response) {
|
|
|
1208 |
$('#main-content').html(response);
|
|
|
1209 |
});
|
|
|
1210 |
});
|
|
|
1211 |
|
|
|
1212 |
$(document).on('click', '.submitGrnCorrection', function () {
|
|
|
1213 |
var invoiceId = $(this).data('invoiceid');
|
|
|
1214 |
var remarks = $('#correctionRemarks').val();
|
|
|
1215 |
|
|
|
1216 |
if (!remarks || remarks.trim() === '') {
|
|
|
1217 |
alert("Please enter remarks explaining the reason for correction");
|
|
|
1218 |
return false;
|
|
|
1219 |
}
|
|
|
1220 |
|
|
|
1221 |
// Collect serial number corrections (old → new)
|
|
|
1222 |
var corrections = [];
|
|
|
1223 |
$('#serial-corrections-table > tbody > tr').each(function () {
|
|
|
1224 |
var oldSerial = $(this).find('.old-serial').val();
|
|
|
1225 |
var newSerial = $(this).find('.new-serial').val();
|
|
|
1226 |
|
|
|
1227 |
if (oldSerial && newSerial && oldSerial.trim() !== '' && newSerial.trim() !== '') {
|
|
|
1228 |
corrections.push({
|
|
|
1229 |
oldSerialNumber: oldSerial.trim(),
|
|
|
1230 |
newSerialNumber: newSerial.trim()
|
|
|
1231 |
});
|
|
|
1232 |
}
|
|
|
1233 |
});
|
|
|
1234 |
|
| 35884 |
amit |
1235 |
// Collect item corrections (serialized or non-serialized)
|
| 35806 |
amit |
1236 |
var qtyCorrections = [];
|
| 36206 |
amit |
1237 |
var imeiCountError = false;
|
| 35806 |
amit |
1238 |
$('#qty-corrections-table > tbody > tr').each(function () {
|
|
|
1239 |
var oldItemId = $(this).find('.qty-old-itemid').val();
|
|
|
1240 |
var newItemId = $(this).find('.qty-new-itemid').val();
|
| 35884 |
amit |
1241 |
var serial = $(this).find('.qty-serial').val();
|
| 35806 |
amit |
1242 |
var qty = parseInt($(this).find('.qty-correction-val').val());
|
|
|
1243 |
|
| 35884 |
amit |
1244 |
if (oldItemId && newItemId && serial && serial.trim() !== '') {
|
| 36206 |
amit |
1245 |
// Split IMEIs by space, comma, or newline
|
|
|
1246 |
var imeis = serial.trim().split(/[\s,]+/).filter(function(s) { return s.length > 0; });
|
|
|
1247 |
var imeiCount = imeis.length;
|
|
|
1248 |
|
|
|
1249 |
// Auto-set qty from IMEI count, validate if qty was manually entered
|
|
|
1250 |
if (qty > 0 && qty !== imeiCount) {
|
|
|
1251 |
alert("Row error: Qty (" + qty + ") does not match IMEI count (" + imeiCount + ").\nIMEIs: " + imeis.join(", "));
|
|
|
1252 |
imeiCountError = true;
|
|
|
1253 |
return false;
|
|
|
1254 |
}
|
|
|
1255 |
|
|
|
1256 |
// Create one entry per IMEI (each with qty=1)
|
|
|
1257 |
for (var i = 0; i < imeis.length; i++) {
|
|
|
1258 |
qtyCorrections.push({
|
|
|
1259 |
oldItemId: parseInt(oldItemId),
|
|
|
1260 |
newItemId: parseInt(newItemId),
|
|
|
1261 |
qty: 1,
|
|
|
1262 |
serialNumber: imeis[i].trim()
|
|
|
1263 |
});
|
|
|
1264 |
}
|
| 35884 |
amit |
1265 |
} else if (oldItemId && newItemId && qty > 0) {
|
|
|
1266 |
qtyCorrections.push({
|
|
|
1267 |
oldItemId: parseInt(oldItemId),
|
|
|
1268 |
newItemId: parseInt(newItemId),
|
| 35806 |
amit |
1269 |
qty: qty
|
|
|
1270 |
});
|
|
|
1271 |
}
|
|
|
1272 |
});
|
|
|
1273 |
|
| 36206 |
amit |
1274 |
if (imeiCountError) return false;
|
|
|
1275 |
|
| 35806 |
amit |
1276 |
if (corrections.length === 0 && qtyCorrections.length === 0) {
|
|
|
1277 |
alert("No corrections specified. Please enter serial number or quantity corrections.");
|
|
|
1278 |
return false;
|
|
|
1279 |
}
|
|
|
1280 |
|
|
|
1281 |
var requestModel = {
|
|
|
1282 |
invoiceId: invoiceId,
|
|
|
1283 |
remarks: remarks,
|
|
|
1284 |
corrections: corrections,
|
|
|
1285 |
qtyCorrections: qtyCorrections
|
|
|
1286 |
};
|
|
|
1287 |
|
|
|
1288 |
if (confirm("Are you sure you want to raise this GRN correction request?")) {
|
|
|
1289 |
doPostAjaxRequestWithJsonHandler(context + "/raiseGrnCorrection",
|
|
|
1290 |
JSON.stringify(requestModel), function (response) {
|
| 36299 |
amit |
1291 |
var parsed;
|
|
|
1292 |
try { parsed = typeof response === 'string' ? JSON.parse(response) : response; }
|
|
|
1293 |
catch (e) { parsed = null; }
|
|
|
1294 |
if (parsed && parsed.status === true) {
|
|
|
1295 |
if (parsed.autoApproved) {
|
|
|
1296 |
alert("Correction applied successfully (auto-approved: no model/qty change)");
|
|
|
1297 |
} else {
|
|
|
1298 |
alert("Correction request raised for approval");
|
|
|
1299 |
}
|
| 35806 |
amit |
1300 |
loadGrnCorrection("main-content");
|
|
|
1301 |
}
|
|
|
1302 |
});
|
|
|
1303 |
}
|
|
|
1304 |
});
|
|
|
1305 |
|
|
|
1306 |
$(document).on('click', '.approveGrnCorrectionBtn', function () {
|
|
|
1307 |
var requestId = $(this).data('requestid');
|
|
|
1308 |
var remarks = $('#approvalRemarks').val();
|
|
|
1309 |
|
|
|
1310 |
if (confirm("Are you sure you want to APPROVE this correction request? This will apply the IMEI/qty changes.")) {
|
|
|
1311 |
doPostAjaxRequestHandler(context + "/approveGrnCorrection?requestId=" + requestId + "&remarks=" + encodeURIComponent(remarks),
|
|
|
1312 |
function (response) {
|
|
|
1313 |
if (response == 'true') {
|
|
|
1314 |
alert("Correction approved and applied successfully");
|
|
|
1315 |
loadGrnCorrectionApproval("main-content");
|
|
|
1316 |
}
|
|
|
1317 |
});
|
|
|
1318 |
}
|
|
|
1319 |
});
|
|
|
1320 |
|
|
|
1321 |
$(document).on('click', '.rejectGrnCorrectionBtn', function () {
|
|
|
1322 |
var requestId = $(this).data('requestid');
|
|
|
1323 |
var remarks = $('#approvalRemarks').val();
|
|
|
1324 |
|
|
|
1325 |
if (!remarks || remarks.trim() === '') {
|
|
|
1326 |
alert("Please enter remarks explaining the reason for rejection");
|
|
|
1327 |
return false;
|
|
|
1328 |
}
|
|
|
1329 |
|
|
|
1330 |
if (confirm("Are you sure you want to REJECT this correction request?")) {
|
|
|
1331 |
doPostAjaxRequestHandler(context + "/rejectGrnCorrection?requestId=" + requestId + "&remarks=" + encodeURIComponent(remarks),
|
|
|
1332 |
function (response) {
|
|
|
1333 |
if (response == 'true') {
|
|
|
1334 |
alert("Correction request rejected");
|
|
|
1335 |
loadGrnCorrectionApproval("main-content");
|
|
|
1336 |
}
|
|
|
1337 |
});
|
|
|
1338 |
}
|
|
|
1339 |
});
|
|
|
1340 |
|
|
|
1341 |
function loadGrnCorrection(domId) {
|
|
|
1342 |
doGetAjaxRequestHandler(context + "/grnCorrection", function (response) {
|
|
|
1343 |
$('#' + domId).html(response);
|
|
|
1344 |
});
|
|
|
1345 |
}
|
|
|
1346 |
|
|
|
1347 |
function loadGrnCorrectionApproval(domId) {
|
|
|
1348 |
doGetAjaxRequestHandler(context + "/grnCorrectionApproval", function (response) {
|
|
|
1349 |
$('#' + domId).html(response);
|
|
|
1350 |
});
|
|
|
1351 |
}
|
|
|
1352 |
|
|
|
1353 |
function loadGrnCorrectionDetail(invoiceId) {
|
|
|
1354 |
doGetAjaxRequestHandler(context + "/grnCorrectionDetail?invoiceId=" + invoiceId, function (response) {
|
|
|
1355 |
$('.grnCorrectionDetailContainer').html(response);
|
|
|
1356 |
});
|
|
|
1357 |
}
|
|
|
1358 |
|
|
|
1359 |
function loadGrnCorrectionRequestDetail(requestId) {
|
|
|
1360 |
doGetAjaxRequestHandler(context + "/grnCorrectionRequestDetail?requestId=" + requestId, function (response) {
|
|
|
1361 |
$('.grnCorrectionRequestDetailContainer').html(response);
|
|
|
1362 |
});
|
|
|
1363 |
}
|
|
|
1364 |
|
|
|
1365 |
|
| 37697 |
amit |
1366 |
|
|
|
1367 |
/**
|
|
|
1368 |
* Shows what the sending warehouse can actually release of an item, on the row where a quantity is being typed.
|
|
|
1369 |
*
|
|
|
1370 |
* Only our own warehouses answer with this; an outside vendor's pricing response carries no availability, and its row
|
|
|
1371 |
* is left exactly as it was. Stock that is entirely promised is shown as zero with the orders holding it named, which
|
|
|
1372 |
* is what lets someone chase those orders instead of only seeing a smaller number.
|
|
|
1373 |
*/
|
|
|
1374 |
function renderMovementAvailability($row, pricing) {
|
|
|
1375 |
var $icon = $row.find('.mv-avail-icon');
|
|
|
1376 |
if (!pricing || typeof pricing.movableOnThisPo === 'undefined') {
|
|
|
1377 |
$icon.hide();
|
|
|
1378 |
$row.removeData('movableOnThisPo');
|
|
|
1379 |
return;
|
|
|
1380 |
}
|
|
|
1381 |
|
|
|
1382 |
var cap = pricing.movableOnThisPo;
|
|
|
1383 |
$row.data('movableOnThisPo', cap);
|
|
|
1384 |
|
|
|
1385 |
var rows = mvAvailLine('In stock', pricing.inStock);
|
|
|
1386 |
if (pricing.promisedTotal > 0) {
|
|
|
1387 |
rows += mvAvailLine('Promised on open orders', pricing.promisedTotal);
|
|
|
1388 |
$.each(pricing.promised || [], function (i, po) {
|
|
|
1389 |
rows += '<tr class="mv-po"><td>' + mvEscape(po.poNumber) + ' · ' + mvEscape(po.poDate)
|
|
|
1390 |
+ (po.destination ? ' → ' + mvEscape(po.destination) : '')
|
|
|
1391 |
+ '</td><td>' + po.qty + '</td></tr>';
|
|
|
1392 |
});
|
|
|
1393 |
}
|
|
|
1394 |
if (pricing.inbound > 0) {
|
|
|
1395 |
rows += mvAvailLine('On the way in (not yet received)', pricing.inbound);
|
|
|
1396 |
}
|
|
|
1397 |
rows += '<tr class="mv-total"><td>Can move on this PO</td><td>' + cap + '</td></tr>';
|
|
|
1398 |
|
|
|
1399 |
var note = '';
|
|
|
1400 |
if (pricing.costSplit) {
|
|
|
1401 |
note += '<div class="mv-note">' + (pricing.movableAltogether - cap)
|
|
|
1402 |
+ ' more came in at a different cost — raise a separate PO for those.</div>';
|
|
|
1403 |
}
|
|
|
1404 |
if (cap === 0) {
|
|
|
1405 |
note += '<div class="mv-note">Nothing can move until one of the orders above is completed or closed.</div>';
|
|
|
1406 |
}
|
|
|
1407 |
|
|
|
1408 |
$icon.attr('data-mv-content', '<table class="mv-avail">' + rows + '</table>' + note);
|
|
|
1409 |
$icon.removeClass('mv-none mv-part');
|
|
|
1410 |
if (cap === 0) {
|
|
|
1411 |
$icon.addClass('mv-none');
|
|
|
1412 |
} else if (pricing.promisedTotal > 0) {
|
|
|
1413 |
$icon.addClass('mv-part');
|
|
|
1414 |
}
|
|
|
1415 |
$icon.show();
|
|
|
1416 |
|
|
|
1417 |
$icon.popover('destroy');
|
|
|
1418 |
$icon.popover({
|
|
|
1419 |
html: true,
|
|
|
1420 |
container: 'body',
|
|
|
1421 |
placement: 'left',
|
|
|
1422 |
trigger: 'hover focus',
|
|
|
1423 |
title: 'Stock at ' + mvEscape(pricing.sourceName),
|
|
|
1424 |
content: function () {
|
|
|
1425 |
return $(this).attr('data-mv-content');
|
|
|
1426 |
}
|
|
|
1427 |
});
|
|
|
1428 |
|
|
|
1429 |
checkMovableQty($row, parseInt($row.find('.qty').val()));
|
|
|
1430 |
}
|
|
|
1431 |
|
|
|
1432 |
/** Flags a quantity that the order cannot take, while it is being typed rather than on submit. */
|
|
|
1433 |
function checkMovableQty($row, qty) {
|
|
|
1434 |
var cap = $row.data('movableOnThisPo');
|
|
|
1435 |
var $qty = $row.find('.qty');
|
|
|
1436 |
var $warn = $row.find('.mv-qty-warn');
|
|
|
1437 |
|
|
|
1438 |
if (typeof cap === 'undefined' || isNaN(qty)) {
|
|
|
1439 |
$qty.removeClass('mv-over');
|
|
|
1440 |
$warn.hide().empty();
|
|
|
1441 |
return;
|
|
|
1442 |
}
|
|
|
1443 |
|
|
|
1444 |
if (qty > cap) {
|
|
|
1445 |
$qty.addClass('mv-over');
|
|
|
1446 |
$warn.text(cap === 0 ? 'None can move right now' : 'Only ' + cap + ' can move on this PO').show();
|
|
|
1447 |
} else {
|
|
|
1448 |
$qty.removeClass('mv-over');
|
|
|
1449 |
$warn.hide().empty();
|
|
|
1450 |
}
|
|
|
1451 |
}
|
|
|
1452 |
|
|
|
1453 |
function mvAvailLine(label, value) {
|
|
|
1454 |
return '<tr><td>' + label + '</td><td>' + value + '</td></tr>';
|
|
|
1455 |
}
|
|
|
1456 |
|
|
|
1457 |
/** Values here are warehouse and order names out of the database, so they are escaped before going into the popover. */
|
|
|
1458 |
function mvEscape(value) {
|
|
|
1459 |
return $('<div/>').text(value === null || typeof value === 'undefined' ? '' : value).html();
|
|
|
1460 |
}
|