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