Subversion Repositories SmartDukaan

Rev

Rev 32349 | Rev 32354 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32349 Rev 32352
Line 1... Line 1...
1
$(function() {
1
$(function () {
2
	$(document).on('click', ".warehouse-create-purchase-order", function() {
2
    $(document).on('click', ".warehouse-create-purchase-order", function () {
3
		loadCreatePurchase("main-content");
3
        loadCreatePurchase("main-content");
4
	});
4
    });
5
 
5
 
6
	$(document).on('click', ".warehouse-receive-new-invoice", function() {
6
    $(document).on('click', ".warehouse-receive-new-invoice", function () {
7
		loadNewReceiveInvoice("main-content");
7
        loadNewReceiveInvoice("main-content");
8
	});
8
    });
9
 
9
 
10
 
10
 
11
	$(document).on('click', ".warehouse-grn-request", function() {
11
    $(document).on('click', ".warehouse-grn-request", function () {
12
		loadGrnRequest("main-content");
12
        loadGrnRequest("main-content");
13
	});
13
    });
14
 
14
 
15
 
15
 
16
	$(document).on('click', ".warehouse-debit-note", function() {
16
    $(document).on('click', ".warehouse-debit-note", function () {
17
		loadDebitNote("main-content");
17
        loadDebitNote("main-content");
18
	});
18
    });
19
 
19
 
20
 
20
 
-
 
21
    $(document).on('click', ".warehouse-invoices", function () {
-
 
22
        loadWarehouseInvoices("main-content");
-
 
23
    });
21
 
24
 
22
	$(document).on('click', ".warehouse-invoices", function() {
-
 
23
		loadWarehouseInvoices("main-content");
-
 
24
	});
-
 
25
 
25
 
-
 
26
    $(document).on('click', '.dateWiseInvoices', function () {
26
 
27
 
-
 
28
        var startDate = getDatesFromPicker('input[name="invoice-duration"]').startDate;
27
	$(document).on('click', '.dateWiseInvoices', function() {
29
        var endDate = getDatesFromPicker('input[name="invoice-duration"]').endDate
28
 
30
 
29
		var startDate = getDatesFromPicker('input[name="invoice-duration"]').startDate;
-
 
30
		var endDate = getDatesFromPicker('input[name="invoice-duration"]').endDate
31
        var vendorId = $('#vendorId').val();
31
 
32
 
-
 
33
        doGetAjaxRequestHandler(context + "/getWarehouseInvoicesByVendor?vendorId=" + vendorId + "&startDate=" + startDate + "&endDate=" + endDate, function (response) {
32
		var vendorId = $('#vendorId').val();
34
            $('.invoicesviewcontainer').html(response);
33
 
35
 
34
		doGetAjaxRequestHandler(context + "/getWarehouseInvoicesByVendor?vendorId=" + vendorId + "&startDate=" + startDate + "&endDate=" + endDate, function(response) {
-
 
35
			$('.invoicesviewcontainer').html(response);
36
        });
36
 
37
 
37
		});
-
 
38
 
38
 
-
 
39
    });
39
 
40
 
40
	});
-
 
41
 
41
 
-
 
42
    $(document)
-
 
43
        .on(
-
 
44
            'input',
-
 
45
            '#invoice',
-
 
46
            function () {
-
 
47
                if (confirm('Document has been selected, Do you want to upload ?')) {
-
 
48
                    var fileSelector = $('#invoice')[0];
-
 
49
                    if (fileSelector != undefined
-
 
50
                        && fileSelector.files[0] != undefined) {
-
 
51
                        var url = context + '/document-upload';
42
 
52
 
43
	$(document)
53
                        console.log(url);
-
 
54
                        var file = this.files[0];
-
 
55
                        doAjaxUploadRequestHandler(
44
		.on(
56
                            url,
45
			'input',
57
                            'POST',
46
			'#invoice',
58
                            file,
47
			function() {
59
                            function (response) {
-
 
60
                                console.log(response);
48
				if (confirm('Document has been selected, Do you want to upload ?')) {
61
                                var documentId = response.response.document_id;
49
					var fileSelector = $('#invoice')[0];
62
                                console.log("documentId : "
50
					if (fileSelector != undefined
63
                                    + documentId);
51
						&& fileSelector.files[0] != undefined) {
64
                                localStorage.setItem("invoiceDocument",
52
						var url = context + '/document-upload';
65
                                    documentId);
53
 
66
 
54
						console.log(url);
-
 
55
						var file = this.files[0];
-
 
56
						doAjaxUploadRequestHandler(
-
 
57
							url,
-
 
58
							'POST',
-
 
59
							file,
-
 
60
							function(response) {
-
 
61
								console.log(response);
-
 
62
								var documentId = response.response.document_id;
-
 
63
								console.log("documentId : "
-
 
64
									+ documentId);
-
 
65
								localStorage.setItem("invoiceDocument",
-
 
66
									documentId);
-
 
67
 
67
 
-
 
68
                            });
68
 
69
 
-
 
70
                    }
-
 
71
                } else {
-
 
72
                    // Do nothing!
-
 
73
                }
69
							});
74
            });
70
 
75
 
71
					}
-
 
72
				} else {
-
 
73
					// Do nothing!
76
    $(document).on('click', ".createReceiveInvoice", function () {
74
				}
-
 
75
			});
-
 
76
 
77
 
77
	$(document).on('click', ".createReceiveInvoice", function() {
78
        var invoiceDate = $('#actualDate').val();
78
 
79
 
79
		var invoiceDate = $('#actualDate').val();
80
        var warehouseId = $('#warehouseMap').val();
80
 
81
 
81
		var warehouseId = $('#warehouseMap').val();
82
        var numItems = $('#numberofItems').val();
82
 
83
 
83
		var numItems = $('#numberofItems').val();
84
        var supplierId = $('#vendorId').val();
84
 
85
 
85
		var supplierId = $('#vendorId').val();
86
        var totalValue = $('#totalValue').val();
86
 
87
 
87
		var totalValue = $('#totalValue').val();
88
        var invoiceNumber = $('#invoiceNumber').val();
88
 
89
 
89
		var invoiceNumber = $('#invoiceNumber').val();
-
 
90
 
90
 
-
 
91
        var invoiceDoc = localStorage
-
 
92
            .getItem("invoiceDocument");
91
 
93
 
92
		var invoiceDoc = localStorage
-
 
93
			.getItem("invoiceDocument");
-
 
94
 
94
 
-
 
95
        console.log(invoiceDoc)
95
 
96
 
96
		console.log(invoiceDoc)
-
 
97
 
97
 
-
 
98
        if (invoiceDate === "" && warehouseId === "" && numItems === "" && supplierId === "" && totalValue === "" && invoiceNumber === "" && invoiceDoc === "") {
-
 
99
            alert("Field can't be empty");
-
 
100
            return false;
-
 
101
        }
98
 
102
 
99
		if (invoiceDate === "" && warehouseId === "" && numItems === "" && supplierId === "" && totalValue === "" && invoiceNumber === "" && invoiceDoc === "") {
-
 
100
			alert("Field can't be empty");
-
 
101
			return false;
-
 
102
		}
-
 
103
 
103
 
-
 
104
        if (invoiceDate === "") {
-
 
105
            alert("please select date");
-
 
106
            return false;
-
 
107
        }
-
 
108
        if (warehouseId === "") {
-
 
109
            alert("please choose warehouse");
-
 
110
            return false;
-
 
111
        }
104
 
112
 
105
		if (invoiceDate === "") {
-
 
106
			alert("please select date");
-
 
107
			return false;
-
 
108
		}
-
 
109
		if (warehouseId === "") {
113
        if (numItems === "") {
110
			alert("please choose warehouse");
114
            alert("please fill number of items.");
111
			return false;
115
            return false;
112
		}
116
        }
113
 
117
 
114
		if (numItems === "") {
-
 
115
			alert("please fill number of items.");
-
 
116
			return false;
-
 
117
		}
-
 
118
 
118
 
-
 
119
        if (supplierId === "") {
-
 
120
            alert("please choose supplier");
-
 
121
            return false;
-
 
122
        }
119
 
123
 
120
		if (supplierId === "") {
-
 
121
			alert("please choose supplier");
-
 
122
			return false;
-
 
123
		}
-
 
124
 
124
 
-
 
125
        if (totalValue === "") {
-
 
126
            alert("please fill Total Value.");
-
 
127
            return false;
-
 
128
        }
125
 
129
 
-
 
130
        if (invoiceNumber === "") {
-
 
131
            alert("please fill Invoice Number.");
-
 
132
            return false;
-
 
133
        }
126
 
134
 
127
		if (totalValue === "") {
-
 
128
			alert("please fill Total Value.");
-
 
129
			return false;
-
 
130
		}
-
 
131
 
135
 
132
		if (invoiceNumber === "") {
136
        if (invoiceDoc === "") {
133
			alert("please fill Invoice Number.");
137
            alert("please upload invoice.");
134
			return false;
138
            return false;
135
		}
139
        }
-
 
140
        var newReceiveInvoice = {};
136
 
141
 
-
 
142
        newReceiveInvoice['invoiceDate'] = invoiceDate;
-
 
143
        newReceiveInvoice['warehouseId'] = warehouseId
-
 
144
        newReceiveInvoice['numItems'] = numItems
-
 
145
        newReceiveInvoice['supplierId'] = supplierId
-
 
146
        newReceiveInvoice['totalValue'] = totalValue
-
 
147
        newReceiveInvoice['invoiceNumber'] = invoiceNumber
-
 
148
        newReceiveInvoice['invoiceDoc'] = invoiceDoc
137
 
149
 
138
		if (invoiceDoc === "") {
150
        console.log()
139
			alert("please upload invoice.");
-
 
140
			return false;
-
 
141
		}
-
 
142
		var newReceiveInvoice = {};
-
 
143
 
151
 
144
		newReceiveInvoice['invoiceDate'] = invoiceDate;
152
        if (confirm("Are you sure you want to add new Invoice") == true) {
145
		newReceiveInvoice['warehouseId'] = warehouseId
-
 
146
		newReceiveInvoice['numItems'] = numItems
-
 
147
		newReceiveInvoice['supplierId'] = supplierId
-
 
148
		newReceiveInvoice['totalValue'] = totalValue
-
 
149
		newReceiveInvoice['invoiceNumber'] = invoiceNumber
-
 
150
		newReceiveInvoice['invoiceDoc'] = invoiceDoc
-
 
151
 
153
 
-
 
154
            doPostAjaxRequestWithJsonHandler(context
-
 
155
                + "/newReceiveInvoice", JSON
-
 
156
                .stringify(newReceiveInvoice), function (response) {
-
 
157
                if (response == 'true') {
-
 
158
                    alert("successfully added");
-
 
159
                    localStorage.removeItem("invoiceDocument");
-
 
160
                    loadNewReceiveInvoice("main-content");
-
 
161
                }
152
		console.log()
162
            });
-
 
163
        }
153
 
164
 
154
		if (confirm("Are you sure you want to add new Invoice") == true) {
-
 
155
 
165
 
156
			doPostAjaxRequestWithJsonHandler(context
-
 
157
				+ "/newReceiveInvoice", JSON
-
 
158
					.stringify(newReceiveInvoice), function(response) {
-
 
159
						if (response == 'true') {
-
 
160
							alert("successfully added");
-
 
161
							localStorage.removeItem("invoiceDocument");
-
 
162
							loadNewReceiveInvoice("main-content");
-
 
163
						}
-
 
164
					});
166
    });
165
		}
-
 
166
 
167
 
167
 
168
 
-
 
169
    var purchaseItemIds;
-
 
170
    $(document).on('click', ".purchaseorderitemview", function () {
-
 
171
        purchaseItemIds = [];
-
 
172
        var vendorId = $('#vendorId').val();
-
 
173
        var warehouseId = $('#warehouseMap').val();
168
 
174
 
-
 
175
        console.log(warehouseId);
169
 
176
 
-
 
177
        if (warehouseId === null && vendorId === "") {
-
 
178
            alert("Field can't be empty");
-
 
179
            return;
-
 
180
        }
170
 
181
 
171
	});
-
 
172
 
182
 
-
 
183
        if (warehouseId === null) {
-
 
184
            alert("please select warehouse");
-
 
185
            return;
-
 
186
        }
-
 
187
        if (vendorId === "") {
-
 
188
            alert("please select vendor");
-
 
189
            return;
-
 
190
        }
-
 
191
        doGetAjaxRequestHandler(context + "/addPurchaseItemView?warehouseId=" + warehouseId + "&vendorId=" + vendorId, function (response) {
-
 
192
            $(".createpurchaseordercontainer").html(response);
-
 
193
        });
-
 
194
    });
173
 
195
 
174
	var purchaseItemIds;
-
 
175
	$(document).on('click', ".purchaseorderitemview", function() {
-
 
176
		purchaseItemIds = [];
-
 
177
		var vendorId = $('#vendorId').val();
-
 
178
		var warehouseId = $('#warehouseMap').val();
-
 
179
 
196
 
-
 
197
    $(document).on('click', ".addRowInPurchaseOrder", function () {
180
		console.log(warehouseId)
198
        var totalQty = 0;
181
 
199
 
182
		if (warehouseId == null && vendorId === "") {
200
        /*$("table > tbody > tr").each(function () {
183
			alert("Field can't be empty");
201
            var itemId = $(this).find(".transferPrice").data('itemid');
184
			return;
202
            var qty = $(this).find(".qty").val();
185
		}
-
 
186
 
203
 
-
 
204
            console.log(qty);
187
 
205
 
188
		if (warehouseId == null) {
206
            if (qty !== undefined) {
189
			alert("please select warehouse");
207
                totalQty += parseInt(qty);
190
			return;
-
 
191
		}
-
 
192
		if (vendorId === "") {
-
 
193
			alert("please select vendor");
-
 
194
			return;
208
            }
195
		}
-
 
196
		doGetAjaxRequestHandler(context + "/addPurchaseItemView?warehouseId=" + warehouseId + "&vendorId=" + vendorId, function(response) {
-
 
197
			$(".createpurchaseordercontainer").html(response);
-
 
198
		});
-
 
199
	});
-
 
200
 
209
 
-
 
210
            console.log(totalQty);
201
 
211
 
202
	$(document).on('click', ".addRowInPurchaseOrder", function() {
-
 
203
		var totalQty = 0
-
 
204
 
212
 
205
		$("table > tbody > tr").each(function() {
213
            if (itemId !== undefined) {
206
			var itemId = $(this).find(".transferPrice").data('itemid');
214
                purchaseItemIds.push(itemId);
-
 
215
            }
207
			var qty = $(this).find(".qty").val();
216
        });*/
208
 
217
 
209
			console.log(qty)
218
        var $html = $('<tr>  <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td> <td>  <input type="number" class="form-control qty"  name = "qty" placeholder="Quantity"/> </td><td>  <input type="number" class="form-control transferPrice"  disable placeholder="Transfer Price"/> </td>	<td>  <input type="number" class="form-control totalValue"  disable placeholder="Total Value"/> </td> <td> <input class="form-control btn btn-primary removeInPurchaseOrder" type="button" value="Remove"></td>  </tr> ');
210
 
219
 
211
			if (qty != undefined) {
-
 
212
				totalQty += parseInt(qty)
220
        var vendorId = $('#vendorId').val();
213
			}
-
 
214
 
221
 
-
 
222
        $('tbody').append($html);
-
 
223
        getVendorItemAheadOptions($html.find('.typeaheaditem'), vendorId, function (
215
			console.log(totalQty)
224
            selectedItem) {
-
 
225
            var itemId = selectedItem.itemId;
216
 
226
 
-
 
227
            if (purchaseItemIds.indexOf(itemId) > -1) {
-
 
228
                alert("item already added");
-
 
229
                $html.find('.typeaheaditem').val("");
217
 
230
 
218
			if (itemId != undefined) {
231
                return false;
219
				purchaseItemIds.push(itemId)
-
 
220
			}
232
            }
221
		});
-
 
222
 
233
 
223
		var $html = $('<tr>  <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td> <td>  <input type="number" class="form-control qty"  name = "qty" placeholder="Quantity"/> </td><td>  <input type="number" class="form-control transferPrice"  disable placeholder="Transfer Price"/> </td>	<td>  <input type="number" class="form-control totalValue"  disable placeholder="Total Value"/> </td> <td> <input class="form-control btn btn-primary removeInPurchaseOrder" type="button" value="Remove"></td>  </tr> ');
234
            addItem(itemId);
224
 
235
 
225
		var vendorId = $('#vendorId').val();
-
 
226
 
236
 
-
 
237
            doGetAjaxRequestHandler(context + "/getPricing?vendorId=" + vendorId + "&itemId=" + itemId, function (response) {
227
		$('tbody').append($html);
238
                if (response !== "null") {
-
 
239
                    var jsonObj = JSON.parse(response);
228
		getVendorItemAheadOptions($html.find('.typeaheaditem'), vendorId, function(
240
                    $html.find('.transferPrice').val(jsonObj.transferPrice);
-
 
241
                    $html.find('input.qty').focus();
229
			selectedItem) {
242
                } else {
230
			var itemId = selectedItem.itemId;
243
                    $html.find('.typeaheaditem').val("");
-
 
244
                }
-
 
245
            });
231
 
246
 
232
			if (purchaseItemIds.indexOf(itemId) > -1) {
-
 
233
				alert("item already selected");
247
        });
234
				$html.find('.typeaheaditem').val("")
-
 
235
 
248
 
236
				return false;
-
 
237
			}
249
    });
238
 
250
 
-
 
251
    function addItem(itemId) {
-
 
252
        oldItem = $html.find('.transferPrice').data(itemId);
-
 
253
        if (typeof (oldItem) === "undefined" || oldItem !== itemId) {
239
			purchaseItemIds.push(itemId);
254
            purchaseItemIds.push(itemId);
-
 
255
            $html.find('.transferPrice').data('itemId', itemId);
-
 
256
        } else {
-
 
257
            let oldIndex = purchaseItemIds.indexOf(oldItem);
-
 
258
            if (oldIndex > -1) {
-
 
259
                purchaseItemIds.splice(oldIndex, 1);
-
 
260
            }
-
 
261
        }
-
 
262
    }
240
 
263
 
-
 
264
    $(document).on('click', '.createSendPurchaseOrder', function () {
241
 
265
 
-
 
266
        createPurchase(true);
242
 
267
 
243
			doGetAjaxRequestHandler(context + "/getPricing?vendorId=" + vendorId + "&itemId=" + itemId, function(response) {
-
 
244
				console.log(response)
-
 
245
				if (response != "null") {
268
    });
246
					var jsonObj = JSON.parse(response);
-
 
247
 
269
 
248
					console.log(jsonObj)
-
 
249
					$html.find('.transferPrice').val(jsonObj.transferPrice)
-
 
250
 
270
 
251
					$html.find('.transferPrice').data('itemid', itemId)
271
    $(document).on('click', '.createPurchaseOrder', function () {
252
				} else {
-
 
253
 
272
 
254
					console.log(response)
-
 
255
					$html.find('.typeaheaditem').val("")
-
 
256
 
273
 
257
				}
274
        createPurchase(false);
258
			});
275
    });
259
 
276
 
260
		});
-
 
261
 
277
 
262
	});
-
 
-
 
278
    $(document).on('change', '.qty', function () {
263
 
279
 
264
	$(document).on('click', '.createSendPurchaseOrder', function() {
-
 
265
 
280
 
266
		createPurchase(true);
281
        var row = $(this).closest("tr");
-
 
282
        var qty = $(row).find(".qty").val();
-
 
283
        var transferPrice = $(row).find(".transferPrice").val();
267
 
284
 
268
	});
-
 
-
 
285
        var totalVal = transferPrice * qty;
269
 
286
 
-
 
287
        var totalValue = $(row).find(".totalValue").val(totalVal);
270
 
288
 
271
	$(document).on('click', '.createPurchaseOrder', function() {
289
        var purchaseOrderValue = 0;
272
 
290
 
-
 
291
        $("table > tbody > tr").each(function () {
273
 
292
 
-
 
293
            var totalValue = $(this).find(".totalValue").val();
274
		createPurchase(false);
294
            purchaseOrderValue += totalValue
275
	});
-
 
276
 
295
 
-
 
296
        });
277
 
297
 
278
	$(document).on('change', '.qty', function() {
298
    });
279
 
299
 
280
 
300
 
281
		var row = $(this).closest("tr");
301
    $(document).on('click', '.warehouse-open-purchase-order', function () {
282
		var qty = $(row).find(".qty").val();
302
        loadOpenPurchase("main-content");
283
		var transferPrice = $(row).find(".transferPrice").val();
303
    });
284
 
304
 
285
		var totalVal = transferPrice * qty;
-
 
286
 
305
 
-
 
306
    $(document).on('click', '.editViewPurchaseOrder', function () {
-
 
307
        var purchaseOrderId = $(this).data('poid');
-
 
308
        doGetAjaxRequestHandler(context + "/getEditPOByPurchaseId?purchaseId=" + purchaseOrderId, function (response) {
287
		var totalValue = $(row).find(".totalValue").val(totalVal);
309
            $('#warehouseEditPurchaseContainer .modal-content').html(response);
-
 
310
        });
288
 
311
 
289
		var purchaseOrderValue = 0;
312
    });
290
 
313
 
291
		$("table > tbody > tr").each(function() {
314
    $(document).on('click', '.editPurchaseOrder', function () {
-
 
315
        var purchaseOrderId = $(this).data('poid');
292
 
316
 
293
			var totalValue = $(this).find(".totalValue").val();
317
        editPurchase(false, purchaseOrderId);
294
			purchaseOrderValue += totalValue
-
 
295
 
318
 
296
		});
319
    });
297
 
320
 
298
	});
-
 
299
 
321
 
-
 
322
    $(document).on('click', '.editSendPurchaseOrder', function () {
-
 
323
        var purchaseOrderId = $(this).data('poid');
300
 
324
 
301
 
325
 
-
 
326
        editPurchase(true, purchaseOrderId);
-
 
327
    });
302
 
328
 
303
	$(document).on('click', '.warehouse-open-purchase-order', function() {
329
    $(document).on('click', '.closePurchaseOrder', function () {
304
		loadOpenPurchase("main-content");
330
        var purchaseOrderId = $(this).data('poid');
305
	});
-
 
-
 
331
        if (confirm("Are you sure you want to close the PO") == true) {
-
 
332
            doPostAjaxRequestHandler(context + "/closePuchaseOrder?purchaseId=" + purchaseOrderId,
-
 
333
                function (response) {
306
 
334
 
-
 
335
                    console.log(response);
-
 
336
                    if (response == 'true') {
-
 
337
                        alert("successfully closed");
-
 
338
                        loadOpenPurchase("main-content")
-
 
339
                    }
-
 
340
                });
-
 
341
        }
-
 
342
    });
307
 
343
 
308
 
344
 
309
	$(document).on('click', '.editViewPurchaseOrder', function() {
345
    $(document).on('click', '.warehouse-view-purchase-order', function () {
310
		var purchaseOrderId = $(this).data('poid');
-
 
311
		doGetAjaxRequestHandler(context + "/getEditPOByPurchaseId?purchaseId=" + purchaseOrderId, function(response) {
346
        doGetAjaxRequestHandler(context + "/viewPurchaseOrder", function (response) {
312
			$('#warehouseEditPurchaseContainer .modal-content').html(response);
347
            $('#' + 'main-content').html(response);
-
 
348
        });
313
		});
349
    });
314
 
350
 
315
	});
-
 
316
 
351
 
317
	$(document).on('click', '.editPurchaseOrder', function() {
352
    $(document).on('click', '.dateWisePo', function () {
318
		var purchaseOrderId = $(this).data('poid');
-
 
319
 
353
 
-
 
354
        var startDate = getDatesFromPicker('input[name="duration"]').startDate;
320
		editPurchase(false, purchaseOrderId);
355
        var endDate = getDatesFromPicker('input[name="duration"]').endDate
321
 
356
 
322
	});
-
 
323
 
357
 
-
 
358
        doGetAjaxRequestHandler(context + "/getPurchaseOrders?startDate=" + startDate + "&endDate=" + endDate, function (response) {
-
 
359
            $('.purchaseorderviewcontainer').html(response);
324
 
360
 
325
	$(document).on('click', '.editSendPurchaseOrder', function() {
-
 
326
		var purchaseOrderId = $(this).data('poid');
361
        });
327
 
362
 
328
 
363
 
329
		editPurchase(true, purchaseOrderId);
-
 
330
	});
364
    });
331
 
365
 
332
	$(document).on('click', '.closePurchaseOrder', function() {
-
 
333
		var purchaseOrderId = $(this).data('poid');
-
 
334
		if (confirm("Are you sure you want to close the PO") == true) {
-
 
335
			doPostAjaxRequestHandler(context + "/closePuchaseOrder?purchaseId=" + purchaseOrderId,
-
 
336
				function(response) {
-
 
337
 
366
 
338
					console.log(response);
-
 
339
					if (response == 'true') {
-
 
340
						alert("successfully closed");
367
    $(document).on('click', '.viewPurchaseOrderlineItem', function () {
341
						loadOpenPurchase("main-content")
368
        var purchaseOrderId = $(this).data('poid');
342
					}
-
 
343
				});
-
 
344
		}
-
 
345
	});
-
 
346
 
369
 
-
 
370
        doGetAjaxRequestHandler(context + "/getWarehouseLineItemByPurchaseId?purchaseId=" + purchaseOrderId, function (response) {
-
 
371
            $('#warehouseLineItem .modal-content').html(response);
347
 
372
 
348
	$(document).on('click', '.warehouse-view-purchase-order', function() {
-
 
349
		doGetAjaxRequestHandler(context + "/viewPurchaseOrder", function(response) {
-
 
350
			$('#' + 'main-content').html(response);
-
 
351
		});
373
        });
352
	});
374
    });
353
 
375
 
354
 
376
 
-
 
377
    $(document).on("click", '.removeInPurchaseOrder', function () {
355
 
378
 
-
 
379
        var row = $(this).closest("tr");
-
 
380
        let itemIndex = purchaseItemIds.indexOf();
-
 
381
        if (itemIndex > -1) { // only splice array when item is found
-
 
382
            purchaseItemIds.splice(itemIndex, 1); // 2nd parameter means remove one item only
-
 
383
        }
-
 
384
        row.remove();
-
 
385
    });
356
 
386
 
357
 
387
 
358
	$(document).on('click', '.dateWisePo', function() {
388
    $(document).on('click', ".addRowForInvoiceItem", function () {
359
 
389
 
360
		var startDate = getDatesFromPicker('input[name="duration"]').startDate;
390
        var numitems = $(this).data("numitems");
361
		var endDate = getDatesFromPicker('input[name="duration"]').endDate
391
        var invoiceId = $(this).data("invoiceid");
-
 
392
        var invoiceItemIds = [];
-
 
393
        var totalQty = 0
362
 
394
 
-
 
395
        $("#invoice-order-table > tbody > tr").each(function () {
-
 
396
            var itemId = $(this).find(".rate").data('itemid');
-
 
397
            var qty = $(this).find(".qty").val();
363
 
398
 
364
		doGetAjaxRequestHandler(context + "/getPurchaseOrders?startDate=" + startDate + "&endDate=" + endDate, function(response) {
399
            if (qty != undefined) {
365
			$('.purchaseorderviewcontainer').html(response);
400
                totalQty += qty
-
 
401
            }
366
 
402
 
-
 
403
            if (itemId != undefined) {
-
 
404
                invoiceItemIds.push(itemId)
-
 
405
            }
367
		});
406
        });
368
 
407
 
-
 
408
        var $html = $('<tr>  <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td>' +
-
 
409
            '<td>  <input type="number" class="form-control qty"  name = "qty" placeholder="Quantity"/> </td>' +
-
 
410
            '<td>  <input type="number" class="form-control rate"  disable placeholder="Rate"/> </td>' +
-
 
411
            '<td> <input class="form-control btn btn-primary removeInInvoiceItem" type="button" value="Remove"></td>  </tr> ');
369
 
412
 
370
	});
-
 
371
 
413
 
-
 
414
        getItemAheadOptions($html.find('.typeaheaditem'), true, function (
-
 
415
            selectedItem) {
-
 
416
            var itemId = selectedItem.itemId;
372
 
417
 
373
 
418
 
374
	$(document).on('click', '.viewPurchaseOrderlineItem', function() {
-
 
375
		var purchaseOrderId = $(this).data('poid');
419
            console.log(invoiceItemIds)
376
 
420
 
377
		doGetAjaxRequestHandler(context + "/getWarehouseLineItemByPurchaseId?purchaseId=" + purchaseOrderId, function(response) {
421
            if (invoiceItemIds.indexOf(itemId) > -1) {
-
 
422
                alert("Item already added");
378
			$('#warehouseLineItem .modal-content').html(response);
423
                $html.find('.typeaheaditem').val("")
379
 
424
 
380
		});
425
                return false;
381
	});
426
            }
-
 
427
            $html.find('.rate').data('itemid', itemId)
382
 
428
 
-
 
429
            $html.find('.removeInInvoiceItem').data('invoiceid', invoiceId)
-
 
430
            $html.find('.removeInInvoiceItem').data('itemid', itemId)
383
 
431
 
-
 
432
        });
384
 
433
 
385
 
434
 
386
	$(document).on("click", '.removeInPurchaseOrder', function() {
435
        if (totalQty < numitems) {
387
 
436
 
388
		var row = $(this).closest("tr");
-
 
389
		let itemIndex = purchaseItemIds.indexOf();
437
            $('#invoice-order-table tbody').append($html);
390
		if (itemIndex > -1) { // only splice array when item is found
-
 
391
			purchaseItemIds.splice(itemIndex, 1); // 2nd parameter means remove one item only
-
 
392
		}
438
        }
393
		row.remove();
-
 
394
	});
-
 
395
 
439
 
-
 
440
    });
396
 
441
 
397
	$(document).on('click', ".addRowForInvoiceItem", function() {
-
 
398
 
442
 
399
		var numitems = $(this).data("numitems");
-
 
400
		var invoiceId = $(this).data("invoiceid");
443
    $(document).on('click', '.saveInvoiceDetail', function () {
401
		var invoiceItemIds = [];
-
 
402
		var totalQty = 0
-
 
403
 
444
 
404
		$("#invoice-order-table > tbody > tr").each(function() {
445
        var numItems = $(this).data("numitems");
405
			var itemId = $(this).find(".rate").data('itemid');
446
        var invoiceId = $(this).data("invoiceid");
-
 
447
        var warehouseId = $(this).data("warehouseid");
406
			var qty = $(this).find(".qty").val();
448
        var supplierId = $(this).data("supplierid");
-
 
449
        getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, false);
407
 
450
 
408
			if (qty != undefined) {
-
 
409
				totalQty += qty
-
 
410
			}
451
    });
411
 
452
 
412
			if (itemId != undefined) {
-
 
413
				invoiceItemIds.push(itemId)
-
 
414
			}
-
 
415
		});
-
 
416
 
453
 
417
		var $html = $('<tr>  <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td>' +
454
    $(document).on('click', '.validateInvoiceDetail', function () {
-
 
455
        var numItems = $(this).data("numitems");
418
			'<td>  <input type="number" class="form-control qty"  name = "qty" placeholder="Quantity"/> </td>' +
456
        var invoiceId = $(this).data("invoiceid");
419
			'<td>  <input type="number" class="form-control rate"  disable placeholder="Rate"/> </td>' +
457
        var warehouseId = $(this).data("warehouseid");
420
			'<td> <input class="form-control btn btn-primary removeInInvoiceItem" type="button" value="Remove"></td>  </tr> ');
458
        var supplierId = $(this).data("supplierid");
421
 
459
 
-
 
460
        getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, true);
422
 
461
 
423
		getItemAheadOptions($html.find('.typeaheaditem'), true, function(
-
 
424
			selectedItem) {
462
    });
425
			var itemId = selectedItem.itemId;
-
 
426
 
463
 
427
 
464
 
428
			console.log(invoiceItemIds)
465
    $(document).on("click", '.removeInInvoiceItem', function () {
429
 
466
 
-
 
467
        var row = $(this).closest("tr");
-
 
468
        var invoiceId = $(this).data("invoiceid");
-
 
469
        var itemId = $(this).data("itemid");
430
			if (invoiceItemIds.indexOf(itemId) > -1) {
470
        if (invoiceId != undefined && itemId != undefined) {
-
 
471
            doDeleteAjaxRequestHandler(context + "/removeInvoiceItem?invoiceId="
-
 
472
                + invoiceId + "&itemId=" + itemId, function (response) {
431
				alert("Item already added");
473
                if (response == "true") {
432
				$html.find('.typeaheaditem').val("")
474
                    alert("Item removed successfully");
433
 
475
 
-
 
476
                }
434
				return false;
477
            });
435
			}
478
        }
436
			$html.find('.rate').data('itemid', itemId)
-
 
437
 
479
 
438
			$html.find('.removeInInvoiceItem').data('invoiceid', invoiceId)
-
 
439
			$html.find('.removeInInvoiceItem').data('itemid', itemId)
480
        row.remove();
440
 
481
 
441
		});
482
    });
442
 
483
 
443
 
484
 
444
		if (totalQty < numitems) {
485
    $(document).on('click', '.purchaseGrn', function () {
445
 
486
 
446
			$('#invoice-order-table tbody').append($html);
487
        var grnItemArray = [];
447
		}
-
 
448
 
488
 
449
	});
-
 
-
 
489
        var invoiceId = $(this).data("invoiceid");
450
 
490
 
451
 
491
 
-
 
492
        $("#invoice-purchase-validate > tbody > tr").each(function () {
-
 
493
            var grnItemJson = {};
452
 
494
 
-
 
495
            var itemId = $(this).find(".itemId").text();
-
 
496
            var qty = $(this).find(".qty").text();
-
 
497
            var poId = $(this).find(".purchaseId").text();
-
 
498
            var excessQty = $(this).find(".excessQty").text();
-
 
499
            var itemType = $(this).find(".itemType").text();
453
 
500
 
-
 
501
            console.log(itemType);
454
 
502
 
-
 
503
            if (itemType == "Serialized") {
-
 
504
                var serialNumbers = $(this).find(".imeis-to-grn").tagsinput('items');
455
	$(document).on('click', '.saveInvoiceDetail', function() {
505
                grnItemJson['serialNumbers'] = serialNumbers
456
 
506
 
-
 
507
                if (excessQty > 0) {
-
 
508
                    var returnSerialNumbers = $(this).find(".imeis-to-grn-return").tagsinput('items');
-
 
509
                    grnItemJson['returnSerialNumbers'] = returnSerialNumbers
-
 
510
                }
-
 
511
            }
457
		var numItems = $(this).data("numitems");
512
            console.log(serialNumbers)
458
		var invoiceId = $(this).data("invoiceid");
513
            grnItemJson['itemId'] = itemId;
459
		var warehouseId = $(this).data("warehouseid");
514
            grnItemJson['serialNumbers'] = serialNumbers
-
 
515
            grnItemJson['qty'] = qty
460
		var supplierId = $(this).data("supplierid");
516
            grnItemJson['poId'] = poId
461
		getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, false);
517
            grnItemJson['invoiceId'] = invoiceId
-
 
518
            grnItemJson['itemType'] = itemType
-
 
519
            grnItemJson['excessQty'] = excessQty
462
 
520
 
463
	});
-
 
-
 
521
            grnItemJson['returnSerialNumbers'] = returnSerialNumbers
464
 
522
 
-
 
523
            grnItemArray.push(grnItemJson)
465
 
524
 
-
 
525
            console.log(grnItemArray)
466
 
526
 
467
	$(document).on('click', '.validateInvoiceDetail', function() {
-
 
468
		var numItems = $(this).data("numitems");
527
        });
469
		var invoiceId = $(this).data("invoiceid");
-
 
470
		var warehouseId = $(this).data("warehouseid");
-
 
471
		var supplierId = $(this).data("supplierid");
-
 
472
 
528
 
473
		getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, true);
529
        for (var i = 0; i < grnItemArray.length; i++) {
474
 
530
 
475
	});
-
 
-
 
531
            var serialNumbers = grnItemArray[i].serialNumbers.length
476
 
532
 
-
 
533
            var itemType = grnItemArray[i].itemType
477
 
534
 
478
	$(document).on("click", '.removeInInvoiceItem', function() {
-
 
479
 
535
 
480
		var row = $(this).closest("tr");
-
 
481
		var invoiceId = $(this).data("invoiceid");
-
 
482
		var itemId = $(this).data("itemid");
536
            if (itemType == "Serialized") {
483
		if (invoiceId != undefined && itemId != undefined) {
537
                var excessQty = grnItemArray[i].excessQty
484
			doDeleteAjaxRequestHandler(context + "/removeInvoiceItem?invoiceId="
-
 
485
				+ invoiceId + "&itemId=" + itemId, function(response) {
-
 
486
					if (response == "true") {
-
 
487
						alert("Item removed successfully");
-
 
488
 
538
 
489
					}
-
 
490
				});
-
 
491
		}
-
 
492
 
539
 
-
 
540
                var serialNumbers = grnItemArray[i].serialNumbers.length
493
		row.remove();
541
                var qty = grnItemArray[i].qty
494
 
542
 
-
 
543
                if (serialNumbers != qty) {
-
 
544
                    alert("serial number is not matched with qty")
-
 
545
                    return false;
495
	});
546
                }
496
 
547
 
-
 
548
                if (excessQty > 0) {
497
 
549
 
498
	$(document).on('click', '.purchaseGrn', function() {
550
                    var returnSerialNumbers = grnItemArray[i].returnSerialNumbers.length
499
 
551
 
-
 
552
                    if (returnSerialNumbers != excessQty) {
-
 
553
                        alert("Return serial number is not matched with excess qty")
-
 
554
                        return false;
500
		var grnItemArray = [];
555
                    }
501
 
556
 
502
		var invoiceId = $(this).data("invoiceid");
557
                }
-
 
558
            }
503
 
559
 
-
 
560
        }
504
 
561
 
505
		$("#invoice-purchase-validate > tbody > tr").each(function() {
-
 
506
			var grnItemJson = {};
-
 
507
 
562
 
508
			var itemId = $(this).find(".itemId").text();
563
        console.log(JSON.stringify(grnItemArray))
509
			var qty = $(this).find(".qty").text();
-
 
510
			var poId = $(this).find(".purchaseId").text();
564
        if (confirm("Are you sure you want to grn purchase order") == true) {
511
			var excessQty = $(this).find(".excessQty").text();
-
 
512
			var itemType = $(this).find(".itemType").text();
-
 
513
 
565
 
-
 
566
            doPostAjaxRequestWithJsonHandler(context
-
 
567
                + "/createGrn", JSON
-
 
568
                .stringify(grnItemArray), function (response) {
-
 
569
                if (response == 'true') {
-
 
570
                    alert("successfully done");
-
 
571
                    loadNewReceiveInvoice("main-content");
-
 
572
                }
514
			console.log(itemType);
573
            });
-
 
574
        }
515
 
575
 
516
			if (itemType == "Serialized") {
-
 
517
				var serialNumbers = $(this).find(".imeis-to-grn").tagsinput('items');
-
 
518
				grnItemJson['serialNumbers'] = serialNumbers
-
 
519
 
576
 
520
				if (excessQty > 0) {
-
 
521
					var returnSerialNumbers = $(this).find(".imeis-to-grn-return").tagsinput('items');
-
 
522
					grnItemJson['returnSerialNumbers'] = returnSerialNumbers
-
 
523
				}
577
    });
524
			}
-
 
525
			console.log(serialNumbers)
-
 
526
			grnItemJson['itemId'] = itemId;
-
 
527
			grnItemJson['serialNumbers'] = serialNumbers
-
 
528
			grnItemJson['qty'] = qty
-
 
529
			grnItemJson['poId'] = poId
-
 
530
			grnItemJson['invoiceId'] = invoiceId
-
 
531
			grnItemJson['itemType'] = itemType
-
 
532
			grnItemJson['excessQty'] = excessQty
-
 
533
 
578
 
534
			grnItemJson['returnSerialNumbers'] = returnSerialNumbers
-
 
535
 
579
 
536
			grnItemArray.push(grnItemJson)
580
    $(document).on('click', '.grnRequest', function () {
537
 
581
 
-
 
582
        var grnRequestJson = {};
538
			console.log(grnItemArray)
583
        var grnRequestItemArray = [];
539
 
584
 
540
		});
-
 
-
 
585
        var invoiceId = $(this).data("invoiceid");
541
 
586
 
542
		for (var i = 0; i < grnItemArray.length; i++) {
-
 
543
 
587
 
544
			var serialNumbers = grnItemArray[i].serialNumbers.length
588
        $("#invoice-purchase-validate > tbody > tr").each(function () {
-
 
589
            var grnItemJson = {};
545
 
590
 
546
			var itemType = grnItemArray[i].itemType
591
            var itemId = $.trim($(this).find(".itemId").text());
-
 
592
            var poId = $.trim($(this).find(".purchaseId").text());
547
 
593
 
-
 
594
            var qty = parseInt($(this).find(".qty").text());
548
 
595
 
549
			if (itemType == "Serialized") {
-
 
550
				var excessQty = grnItemArray[i].excessQty
596
            var excessQty = parseInt($(this).find(".excessQty").text());
551
 
597
 
-
 
598
            var priceMismatch = $.trim($(this).find(".priceMismatch").text());
-
 
599
            console.log(priceMismatch)
552
 
600
 
553
 
601
 
-
 
602
            if (priceMismatch != null || excessQty > 0) {
-
 
603
                console.log(typeof priceMismatch)
-
 
604
                console.log(excessQty)
554
				var serialNumbers = grnItemArray[i].serialNumbers.length
605
                grnItemJson['itemId'] = itemId;
555
				var qty = grnItemArray[i].qty
606
                grnItemJson['qty'] = qty;
-
 
607
                grnItemJson['excessQty'] = excessQty
-
 
608
                grnItemJson['mismatch'] = priceMismatch
-
 
609
                grnItemJson['poId'] = poId
556
 
610
 
557
				if (serialNumbers != qty) {
-
 
558
					alert("serial number is not matched with qty")
611
                grnRequestItemArray.push(grnItemJson)
559
					return false;
612
            }
560
				}
613
        });
561
 
614
 
562
				if (excessQty > 0) {
615
        console.log(grnRequestItemArray)
563
 
616
 
564
					var returnSerialNumbers = grnItemArray[i].returnSerialNumbers.length
-
 
565
 
617
 
566
					if (returnSerialNumbers != excessQty) {
618
        grnRequestJson['invoiceId'] = invoiceId;
567
						alert("Return serial number is not matched with excess qty")
619
        grnRequestJson['warehousePurchaseModel'] = grnRequestItemArray
568
						return false;
-
 
569
					}
-
 
570
 
620
 
571
				}
-
 
572
			}
-
 
-
 
621
        if (confirm("Are you sure you want to raise grn request") == true) {
573
 
622
 
-
 
623
            doPostAjaxRequestWithJsonHandler(context
-
 
624
                + "/grnRequest", JSON
-
 
625
                .stringify(grnRequestJson), function (response) {
-
 
626
                if (response == 'true') {
-
 
627
                    alert("successfully done");
-
 
628
                    loadNewReceiveInvoice("main-content");
-
 
629
                }
-
 
630
            });
574
		}
631
        }
575
 
632
 
576
 
633
 
577
		console.log(JSON.stringify(grnItemArray))
634
    });
578
		if (confirm("Are you sure you want to grn purchase order") == true) {
-
 
579
 
635
 
580
			doPostAjaxRequestWithJsonHandler(context
-
 
581
				+ "/createGrn", JSON
-
 
582
					.stringify(grnItemArray), function(response) {
-
 
583
						if (response == 'true') {
-
 
584
							alert("successfully done");
-
 
585
							loadNewReceiveInvoice("main-content");
-
 
586
						}
-
 
587
					});
-
 
588
		}
-
 
589
 
636
 
-
 
637
    $(document).on('click', '.resolvedPriceMismatchRequest', function () {
-
 
638
        var id = $(this).data("id");
590
 
639
 
-
 
640
        var invoiceId = $(this).data("invoiceid");
591
 
641
 
592
	});
-
 
-
 
642
        var requestId = $(this).data("requestid");
593
 
643
 
-
 
644
        var mismatch = $(this).data("mismatch");
594
 
645
 
-
 
646
        if (mismatch == "InvoiceMismatch") {
-
 
647
            if (confirm("Are you sure you want to resolve invoice mismatch") == true) {
595
 
648
 
-
 
649
                doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id, function (response) {
-
 
650
                    if (response == 'true') {
596
	$(document).on('click', '.grnRequest', function() {
651
                        getGrnRequestItems(requestId, invoiceId)
-
 
652
                    }
-
 
653
                });
597
 
654
 
598
		var grnRequestJson = {};
655
            }
599
		var grnRequestItemArray = [];
656
        } else if (mismatch == "PoMismatch") {
-
 
657
            if (confirm("Are you sure you want to resolve Po Mismatch. Discard the current PoLineItem new Po will generate on the invoice date.") == true) {
600
 
658
 
-
 
659
                doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id, function (response) {
601
		var invoiceId = $(this).data("invoiceid");
660
                    if (response == 'true') {
-
 
661
                        getGrnRequestItems(requestId, invoiceId)
-
 
662
                    }
-
 
663
                });
602
 
664
 
-
 
665
            }
-
 
666
        }
603
 
667
 
604
		$("#invoice-purchase-validate > tbody > tr").each(function() {
-
 
605
			var grnItemJson = {};
668
    });
606
 
669
 
607
			var itemId = $.trim($(this).find(".itemId").text());
-
 
608
			var poId = $.trim($(this).find(".purchaseId").text());
-
 
609
 
670
 
-
 
671
    $(document).on('click', '.resolvedQtyMismatchRequest', function () {
610
			var qty = parseInt($(this).find(".qty").text());
672
        var id = $(this).data("id");
611
 
673
 
612
			var excessQty = parseInt($(this).find(".excessQty").text());
674
        var invoiceId = $(this).data("invoiceid");
613
 
675
 
614
			var priceMismatch = $.trim($(this).find(".priceMismatch").text());
676
        var requestId = $(this).data("requestid");
615
			console.log(priceMismatch)
677
        var requestId = $(this).data("requestid");
616
 
678
 
617
 
679
 
618
			if (priceMismatch != null || excessQty > 0) {
-
 
619
				console.log(typeof priceMismatch)
-
 
620
				console.log(excessQty)
-
 
621
				grnItemJson['itemId'] = itemId;
-
 
622
				grnItemJson['qty'] = qty;
-
 
623
				grnItemJson['excessQty'] = excessQty
-
 
624
				grnItemJson['mismatch'] = priceMismatch
680
        var mismatch = $(this).data("mismatch");
625
				grnItemJson['poId'] = poId
-
 
626
 
681
 
-
 
682
        var $row = $(this).closest("tr");
627
				grnRequestItemArray.push(grnItemJson)
683
        var requiredQty = $row.find(".requiredQty").val();
628
			}
-
 
629
		});
-
 
630
 
684
 
631
		console.log(grnRequestItemArray)
685
        console.log(requiredQty);
632
 
686
 
-
 
687
        if (mismatch == "QtyMismatch") {
-
 
688
            if (confirm("Are you sure you want to resolve qty mismatch") == true) {
633
 
689
 
-
 
690
                doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id + "&requiredQty=" + requiredQty, function (response) {
-
 
691
                    if (response == 'true') {
-
 
692
                        getGrnRequestItems(requestId, invoiceId)
-
 
693
                    }
-
 
694
                });
634
 
695
 
635
		grnRequestJson['invoiceId'] = invoiceId;
-
 
636
		grnRequestJson['warehousePurchaseModel'] = grnRequestItemArray
-
 
637
 
-
 
638
		if (confirm("Are you sure you want to raise grn request") == true) {
-
 
639
 
-
 
640
			doPostAjaxRequestWithJsonHandler(context
-
 
641
				+ "/grnRequest", JSON
-
 
642
					.stringify(grnRequestJson), function(response) {
-
 
643
						if (response == 'true') {
-
 
644
							alert("successfully done");
-
 
645
							loadNewReceiveInvoice("main-content");
-
 
646
						}
696
            }
647
					});
-
 
648
		}
-
 
649
 
-
 
650
 
-
 
651
 
-
 
652
	});
-
 
653
 
-
 
654
 
-
 
655
	$(document).on('click', '.resolvedPriceMismatchRequest', function() {
-
 
656
		var id = $(this).data("id");
-
 
657
 
-
 
658
		var invoiceId = $(this).data("invoiceid");
-
 
659
 
-
 
660
		var requestId = $(this).data("requestid");
-
 
661
 
-
 
662
		var mismatch = $(this).data("mismatch");
-
 
663
 
-
 
664
		if (mismatch == "InvoiceMismatch") {
-
 
665
			if (confirm("Are you sure you want to resolve invoice mismatch") == true) {
-
 
666
 
-
 
667
				doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id, function(response) {
-
 
668
					if (response == 'true') {
-
 
669
						getGrnRequestItems(requestId, invoiceId)
-
 
670
					}
-
 
671
				});
-
 
672
 
-
 
673
			}
-
 
674
		} else if (mismatch == "PoMismatch") {
-
 
675
			if (confirm("Are you sure you want to resolve Po Mismatch. Discard the current PoLineItem new Po will generate on the invoice date.") == true) {
-
 
676
 
-
 
677
				doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id, function(response) {
-
 
678
					if (response == 'true') {
-
 
679
						getGrnRequestItems(requestId, invoiceId)
-
 
680
					}
-
 
681
				});
-
 
682
 
-
 
683
			}
-
 
684
		}
-
 
685
 
-
 
686
	});
-
 
687
 
-
 
688
 
-
 
689
 
-
 
690
	$(document).on('click', '.resolvedQtyMismatchRequest', function() {
-
 
691
		var id = $(this).data("id");
-
 
692
 
-
 
693
		var invoiceId = $(this).data("invoiceid");
-
 
694
 
-
 
695
		var requestId = $(this).data("requestid");
-
 
696
		var requestId = $(this).data("requestid");
-
 
697
 
-
 
698
 
-
 
699
		var mismatch = $(this).data("mismatch");
-
 
700
 
-
 
701
		var $row = $(this).closest("tr");
-
 
702
		var requiredQty = $row.find(".requiredQty").val();
-
 
703
 
-
 
704
		console.log(requiredQty);
-
 
705
 
-
 
706
		if (mismatch == "QtyMismatch") {
-
 
707
			if (confirm("Are you sure you want to resolve qty mismatch") == true) {
-
 
708
 
-
 
709
				doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id + "&requiredQty=" + requiredQty, function(response) {
-
 
710
					if (response == 'true') {
-
 
711
						getGrnRequestItems(requestId, invoiceId)
-
 
712
					}
697
        }
713
				});
-
 
714
 
-
 
715
			}
-
 
716
		}
-
 
717
 
-
 
718
	});
-
 
719
 
-
 
720
 
-
 
721
 
698
 
-
 
699
    });
722
 
700
 
723
 
701
 
724
});
702
});
725
 
703
 
726
function loadCreatePurchase(domId) {
704
function loadCreatePurchase(domId) {
727
	doGetAjaxRequestHandler(context + "/warehousePurchaseOrder", function(response) {
705
    doGetAjaxRequestHandler(context + "/warehousePurchaseOrder", function (response) {
728
		$('#' + domId).html(response);
706
        $('#' + domId).html(response);
729
	});
707
    });
730
}
708
}
731
 
709
 
732
 
710
 
733
 
-
 
734
function loadOpenPurchase(domId) {
711
function loadOpenPurchase(domId) {
735
 
712
 
736
	doGetAjaxRequestHandler(context + "/getOpenPurchaseOrder", function(response) {
713
    doGetAjaxRequestHandler(context + "/getOpenPurchaseOrder", function (response) {
737
		$('#' + domId).html(response);
714
        $('#' + domId).html(response);
738
	});
715
    });
739
}
716
}
740
 
717
 
741
function loadNewReceiveInvoice(domId) {
718
function loadNewReceiveInvoice(domId) {
742
	doGetAjaxRequestHandler(context + "/newReceiveInvoice", function(response) {
719
    doGetAjaxRequestHandler(context + "/newReceiveInvoice", function (response) {
743
		$('#' + domId).html(response);
720
        $('#' + domId).html(response);
744
	});
721
    });
745
}
722
}
746
 
723
 
747
 
724
 
748
 
-
 
749
function loadGrnRequest(domId) {
725
function loadGrnRequest(domId) {
750
	doGetAjaxRequestHandler(context + "/grnRequest", function(response) {
726
    doGetAjaxRequestHandler(context + "/grnRequest", function (response) {
751
		$('#' + domId).html(response);
727
        $('#' + domId).html(response);
752
	});
728
    });
753
}
729
}
754
 
730
 
755
function loadDebitNote(domId) {
731
function loadDebitNote(domId) {
756
	doGetAjaxRequestHandler(context + "/getDebitNote", function(response) {
732
    doGetAjaxRequestHandler(context + "/getDebitNote", function (response) {
757
		$('#' + domId).html(response);
733
        $('#' + domId).html(response);
758
	});
734
    });
759
}
735
}
760
 
736
 
761
function loadWarehouseInvoices(domId) {
737
function loadWarehouseInvoices(domId) {
762
	doGetAjaxRequestHandler(context + "/getWarehouseInvoices", function(response) {
738
    doGetAjaxRequestHandler(context + "/getWarehouseInvoices", function (response) {
763
		$('#' + domId).html(response);
739
        $('#' + domId).html(response);
764
	});
740
    });
765
}
741
}
766
 
742
 
767
function createPurchase(sendPo) {
743
function createPurchase(sendPo) {
768
	var purchaseOrder = {};
744
    var purchaseOrder = {};
769
 
-
 
770
	var vendorId = $('#vendorId').val();
-
 
771
 
745
 
772
	var warehouseId = $('#warehouseMap').val();
746
    var vendorId = $('#vendorId').val();
773
 
747
 
-
 
748
    var warehouseId = $('#warehouseMap').val();
774
 
749
 
775
	var items = []
-
 
776
	$("table > tbody > tr").each(function() {
-
 
777
		var purchaseOrderJson = {};
-
 
778
 
750
 
779
		var itemId = $(this).find(".transferPrice").data('itemid');
-
 
780
		var qty = $(this).find(".qty").val();
751
    var items = []
781
		var transferPrice = $(this).find(".transferPrice").val();
752
    $("table > tbody > tr").each(function () {
782
		var totalValue = $(this).find(".totalValue").val();
753
        var purchaseOrderJson = {};
783
 
754
 
-
 
755
        var itemId = $(this).find(".transferPrice").data('itemid');
-
 
756
        var qty = $(this).find(".qty").val();
-
 
757
        var transferPrice = $(this).find(".transferPrice").val();
-
 
758
        var totalValue = $(this).find(".totalValue").val();
784
 
759
 
785
		purchaseOrderJson['itemId'] = itemId;
-
 
786
		purchaseOrderJson['amendedQty'] = qty
-
 
787
		purchaseOrderJson['totalValue'] = totalValue
-
 
788
		purchaseOrderJson['transferPrice'] = transferPrice
-
 
789
 
760
 
790
		items.push(purchaseOrderJson)
761
        purchaseOrderJson['itemId'] = itemId;
791
	});
-
 
-
 
762
        purchaseOrderJson['amendedQty'] = qty
-
 
763
        purchaseOrderJson['totalValue'] = totalValue
-
 
764
        purchaseOrderJson['transferPrice'] = transferPrice
792
 
765
 
-
 
766
        items.push(purchaseOrderJson)
-
 
767
    });
793
 
768
 
794
	for (var i = 0; i < items.length; i++) {
-
 
795
		console.log(items[i])
-
 
796
 
769
 
797
		var itemId = items[i].itemId
-
 
798
		var qty = items[i].amendedQty
-
 
799
		var transferPrice = items[i].transferPrice
770
    for (var i = 0; i < items.length; i++) {
800
		var totalValue = items[i].totalValue
771
        console.log(items[i])
801
 
772
 
802
		if (itemId === "" && qty === "" && transferPrice === "" && totalValue === "") {
773
        var itemId = items[i].itemId
803
			alert("Field can't be empty");
774
        var qty = items[i].amendedQty
-
 
775
        var transferPrice = items[i].transferPrice
804
			return false;
776
        var totalValue = items[i].totalValue
805
		}
-
 
806
 
777
 
-
 
778
        if (itemId === "" && qty === "" && transferPrice === "" && totalValue === "") {
-
 
779
            alert("Field can't be empty");
-
 
780
            return false;
-
 
781
        }
807
 
782
 
808
		if (itemId === "") {
-
 
809
			alert("please select item");
-
 
810
			return false;
-
 
811
		}
-
 
812
		if (qty === "") {
-
 
813
			alert("please choose qty");
-
 
814
			return false;
-
 
815
		}
-
 
816
 
783
 
817
		if (transferPrice === "") {
784
        if (itemId === "") {
818
			alert("Transfer Price can't be empty");
785
            alert("please select item");
819
			return false;
786
            return false;
820
		}
787
        }
821
		if (totalValue === "") {
788
        if (qty === "") {
822
			alert("Total value can't be empty");
789
            alert("please choose qty");
823
			return false;
790
            return false;
824
		}
791
        }
825
 
792
 
-
 
793
        if (transferPrice === "") {
-
 
794
            alert("Transfer Price can't be empty");
-
 
795
            return false;
-
 
796
        }
826
		if (qty <= 0) {
797
        if (totalValue === "") {
827
			alert("Please fill Qty");
798
            alert("Total value can't be empty");
828
			return false;
799
            return false;
829
		}
800
        }
830
 
801
 
-
 
802
        if (qty <= 0) {
-
 
803
            alert("Please fill Qty");
-
 
804
            return false;
-
 
805
        }
831
 
806
 
832
 
807
 
833
	}
808
    }
834
 
809
 
835
	purchaseOrder['vendorId'] = vendorId;
810
    purchaseOrder['vendorId'] = vendorId;
836
	purchaseOrder['warehouseId'] = warehouseId
811
    purchaseOrder['warehouseId'] = warehouseId
837
	purchaseOrder['sendPo'] = sendPo
812
    purchaseOrder['sendPo'] = sendPo
838
 
813
 
839
	purchaseOrder['items'] = items
814
    purchaseOrder['items'] = items
840
 
815
 
841
	console.log(purchaseOrder)
816
    console.log(purchaseOrder)
842
 
817
 
843
 
818
 
-
 
819
    if (confirm("Are you sure you want to create purchase order") == true) {
844
 
820
 
845
	if (confirm("Are you sure you want to create purchase order") == true) {
-
 
846
 
-
 
847
		doPostAjaxRequestWithJsonHandler(context
821
        doPostAjaxRequestWithJsonHandler(context
848
			+ "/createPurchaseOrder", JSON
822
            + "/createPurchaseOrder", JSON
849
				.stringify(purchaseOrder), function(response) {
823
            .stringify(purchaseOrder), function (response) {
850
					if (response == 'true') {
824
            if (response == 'true') {
851
						alert("successfully created");
825
                alert("successfully created");
852
						loadCreatePurchase("main-content");
826
                loadCreatePurchase("main-content");
853
					}
827
            }
854
				});
828
        });
855
	}
829
    }
856
 
830
 
857
}
831
}
858
 
832
 
859
 
833
 
860
function editPurchase(sendPo, poid) {
834
function editPurchase(sendPo, poid) {
861
	var editpurchaseOrder = {}
835
    var editpurchaseOrder = {}
862
	var items = []
836
    var items = []
863
	$("#purchase-edit-lineitem > tbody > tr").each(function() {
837
    $("#purchase-edit-lineitem > tbody > tr").each(function () {
864
		var purchaseOrderJson = {};
838
        var purchaseOrderJson = {};
865
		var itemId = $(this).find("td:eq(0)").text();
839
        var itemId = $(this).find("td:eq(0)").text();
866
 
840
 
867
		var qty = $(this).find("td:eq(2)").text();
841
        var qty = $(this).find("td:eq(2)").text();
868
 
842
 
869
		var amendedQty = $(this).find(".editqty").val();
843
        var amendedQty = $(this).find(".editqty").val();
870
 
844
 
871
		var transferPrice = $.trim($(this).find(".transferPrice").html());
845
        var transferPrice = $.trim($(this).find(".transferPrice").html());
872
 
846
 
873
 
847
 
874
		purchaseOrderJson['itemId'] = itemId;
848
        purchaseOrderJson['itemId'] = itemId;
875
		purchaseOrderJson['amendedQty'] = parseInt(amendedQty)
849
        purchaseOrderJson['amendedQty'] = parseInt(amendedQty)
876
		purchaseOrderJson['qty'] = parseInt(qty)
850
        purchaseOrderJson['qty'] = parseInt(qty)
877
		purchaseOrderJson['transferPrice'] = transferPrice
851
        purchaseOrderJson['transferPrice'] = transferPrice
878
 
852
 
879
		items.push(purchaseOrderJson)
853
        items.push(purchaseOrderJson)
880
	});
854
    });
881
 
855
 
882
 
856
 
883
	for (var i = 0; i < items.length; i++) {
857
    for (var i = 0; i < items.length; i++) {
884
		console.log(items[i])
858
        console.log(items[i])
885
 
859
 
886
		var amendedQty = items[i].amendedQty
860
        var amendedQty = items[i].amendedQty
887
		var qty = items[i].qty
861
        var qty = items[i].qty
888
 
862
 
889
 
863
 
890
		if (amendedQty === "") {
864
        if (amendedQty === "") {
891
			alert("please choose qty");
865
            alert("please choose qty");
892
			return false;
866
            return false;
893
		}
867
        }
894
 
868
 
895
		if (amendedQty < qty) {
869
        if (amendedQty < qty) {
896
			alert("Quantity should be greater than existing qty");
870
            alert("Quantity should be greater than existing qty");
897
			return false;
871
            return false;
898
		}
872
        }
899
 
873
 
900
 
874
 
901
	}
875
    }
902
 
876
 
903
	editpurchaseOrder['purchaseOrderId'] = poid;
877
    editpurchaseOrder['purchaseOrderId'] = poid;
904
	editpurchaseOrder['sendPo'] = sendPo
878
    editpurchaseOrder['sendPo'] = sendPo
905
	editpurchaseOrder['items'] = items
879
    editpurchaseOrder['items'] = items
906
 
880
 
907
 
881
 
908
	if (confirm("Are you sure you want to edit purchase order") == true) {
882
    if (confirm("Are you sure you want to edit purchase order") == true) {
909
 
883
 
910
		doPostAjaxRequestWithJsonHandler(context
884
        doPostAjaxRequestWithJsonHandler(context
911
			+ "/editPurchaseOrder", JSON
885
            + "/editPurchaseOrder", JSON
912
				.stringify(editpurchaseOrder), function(response) {
886
            .stringify(editpurchaseOrder), function (response) {
913
					if (response == 'true') {
887
            if (response == 'true') {
914
						alert("successfully created");
888
                alert("successfully created");
915
						$('#warehouseEditPurchaseContainer').modal('hide');
889
                $('#warehouseEditPurchaseContainer').modal('hide');
916
						$('.modal-backdrop').remove();
890
                $('.modal-backdrop').remove();
917
 
891
 
918
						loadOpenPurchase("main-content")
892
                loadOpenPurchase("main-content")
919
					}
893
            }
920
				});
894
        });
921
	}
895
    }
922
 
896
 
923
}
897
}
924
 
898
 
925
 
899
 
926
function getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, validate) {
900
function getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, validate) {
927
 
901
 
928
	var invoiceJson = {};
902
    var invoiceJson = {};
929
	console.log(numItems)
903
    console.log(numItems)
930
	var totalQty = 0;
904
    var totalQty = 0;
931
	var invoiceItems = []
905
    var invoiceItems = []
932
	$("#invoice-order-table > tbody > tr").each(function() {
906
    $("#invoice-order-table > tbody > tr").each(function () {
933
		var invoiceItemJson = {};
907
        var invoiceItemJson = {};
934
		var itemId = $(this).find(".rate").data('itemid');
908
        var itemId = $(this).find(".rate").data('itemid');
935
		var qty = $(this).find(".qty").val();
909
        var qty = $(this).find(".qty").val();
936
 
910
 
937
		if (qty != undefined) {
911
        if (qty != undefined) {
938
			totalQty += parseInt(qty)
912
            totalQty += parseInt(qty)
939
		}
913
        }
940
		var rate = $(this).find(".rate").val();
914
        var rate = $(this).find(".rate").val();
941
		invoiceItemJson['itemId'] = itemId;
915
        invoiceItemJson['itemId'] = itemId;
942
		invoiceItemJson['qty'] = qty
916
        invoiceItemJson['qty'] = qty
943
		invoiceItemJson['rate'] = rate
917
        invoiceItemJson['rate'] = rate
944
		invoiceItems.push(invoiceItemJson)
918
        invoiceItems.push(invoiceItemJson)
945
	});
919
    });
946
 
920
 
947
 
921
 
948
	for (var i = 0; i < invoiceItems.length; i++) {
922
    for (var i = 0; i < invoiceItems.length; i++) {
949
 
923
 
950
		var itemId = invoiceItems[i].itemId
924
        var itemId = invoiceItems[i].itemId
951
		var qty = invoiceItems[i].qty
925
        var qty = invoiceItems[i].qty
952
		var rate = invoiceItems[i].rate
926
        var rate = invoiceItems[i].rate
953
		if (itemId === "" && qty === "" && rate === "") {
927
        if (itemId === "" && qty === "" && rate === "") {
954
			alert("Field can't be empty");
928
            alert("Field can't be empty");
955
			return false;
929
            return false;
956
		}
930
        }
957
 
931
 
958
		if (itemId === "") {
932
        if (itemId === "") {
959
			alert("please select item");
933
            alert("please select item");
960
			return false;
934
            return false;
961
		}
935
        }
962
		if (qty === "") {
936
        if (qty === "") {
963
			alert("please choose qty");
937
            alert("please choose qty");
964
			return false;
938
            return false;
965
		}
939
        }
966
 
940
 
967
		if (rate === "") {
941
        if (rate === "") {
968
			alert("Rate can't be empty");
942
            alert("Rate can't be empty");
969
			return false;
943
            return false;
970
		}
944
        }
971
 
945
 
972
	}
946
    }
973
 
947
 
974
	console.log(totalQty)
948
    console.log(totalQty)
975
 
949
 
976
	if (totalQty > numItems) {
950
    if (totalQty > numItems) {
977
		alert("Qty Should not be more than  Invoice items");
951
        alert("Qty Should not be more than  Invoice items");
978
		return false;
952
        return false;
979
	}
953
    }
980
 
954
 
981
	if (validate) {
955
    if (validate) {
982
 
956
 
983
		if (totalQty != numItems) {
957
        if (totalQty != numItems) {
984
			alert("Qty Should not match with Invoice items");
958
            alert("Qty Should not match with Invoice items");
985
			return false;
959
            return false;
986
		}
960
        }
987
	}
961
    }
988
 
962
 
989
 
963
 
990
	invoiceJson['invoiceId'] = invoiceId;
964
    invoiceJson['invoiceId'] = invoiceId;
991
	invoiceJson['warehouseId'] = warehouseId;
965
    invoiceJson['warehouseId'] = warehouseId;
992
	invoiceJson['supplierId'] = supplierId;
966
    invoiceJson['supplierId'] = supplierId;
993
	invoiceJson['invoiceItems'] = invoiceItems
967
    invoiceJson['invoiceItems'] = invoiceItems
994
	if (validate) {
968
    if (validate) {
995
		validateInvoiceItems(invoiceJson);
969
        validateInvoiceItems(invoiceJson);
996
	} else {
970
    } else {
997
		saveInvoiceItems(invoiceJson)
971
        saveInvoiceItems(invoiceJson)
998
	}
972
    }
999
}
973
}
1000
 
974
 
1001
 
975
 
1002
function saveInvoiceItems(invoiceJson) {
976
function saveInvoiceItems(invoiceJson) {
1003
 
977
 
1004
 
978
 
1005
	if (confirm("Are you sure you want to save invoice item") == true) {
979
    if (confirm("Are you sure you want to save invoice item") == true) {
1006
 
980
 
1007
		doPostAjaxRequestWithJsonHandler(context
981
        doPostAjaxRequestWithJsonHandler(context
1008
			+ "/invoiceItemDetail", JSON
982
            + "/invoiceItemDetail", JSON
1009
				.stringify(invoiceJson), function(response) {
983
            .stringify(invoiceJson), function (response) {
1010
					if (response == 'true') {
984
            if (response == 'true') {
1011
						getInvoiceItems(invoiceJson.invoiceId);
985
                getInvoiceItems(invoiceJson.invoiceId);
1012
					}
986
            }
1013
				});
987
        });
1014
	}
988
    }
1015
 
989
 
1016
}
990
}
1017
 
991
 
1018
 
992
 
1019
function validateInvoiceItems(invoiceJson) {
993
function validateInvoiceItems(invoiceJson) {
1020
 
994
 
1021
 
995
 
1022
	if (confirm("Are you sure you want to validate invoice item") == true) {
996
    if (confirm("Are you sure you want to validate invoice item") == true) {
1023
 
997
 
1024
		doPostAjaxRequestWithJsonHandler(context
998
        doPostAjaxRequestWithJsonHandler(context
1025
			+ "/validateInvoiceItemDetail", JSON
999
            + "/validateInvoiceItemDetail", JSON
1026
				.stringify(invoiceJson), function(response) {
1000
            .stringify(invoiceJson), function (response) {
1027
					$('.invoiceadditemcontainer').html(response);
1001
            $('.invoiceadditemcontainer').html(response);
1028
 
1002
 
1029
				});
1003
        });
1030
	}
1004
    }
1031
 
1005
 
1032
}
1006
}
1033
 
1007
 
1034
function getOpenPOFromWarehouse() {
1008
function getOpenPOFromWarehouse() {
1035
 
1009
 
1036
	var warehouseId = $('#warehouseMap').val();
1010
    var warehouseId = $('#warehouseMap').val();
1037
	doGetAjaxRequestHandler(context + "/getOpenPurchaseOrderByWarehouseId?warehouseId=" + warehouseId, function(response) {
1011
    doGetAjaxRequestHandler(context + "/getOpenPurchaseOrderByWarehouseId?warehouseId=" + warehouseId, function (response) {
1038
		$('#warehouseManagePuchaseContainer').html(response);
1012
        $('#warehouseManagePuchaseContainer').html(response);
1039
	});
1013
    });
1040
 
-
 
1041
 
1014
 
1042
 
1015
 
1043
}
1016
}
1044
 
1017
 
1045
function getPurchaseLineitem(poId) {
1018
function getPurchaseLineitem(poId) {
1046
 
1019
 
1047
 
1020
 
1048
	doGetAjaxRequestHandler(context + "/getPurchaseOrderItemByPoId?poId=" + poId, function(response) {
1021
    doGetAjaxRequestHandler(context + "/getPurchaseOrderItemByPoId?poId=" + poId, function (response) {
1049
		$('#warehouseManagePuchaseItemContainer').html(response);
1022
        $('#warehouseManagePuchaseItemContainer').html(response);
1050
		$('#warehousepurchaseitemgrn').hide()
1023
        $('#warehousepurchaseitemgrn').hide()
1051
	});
1024
    });
1052
 
1025
 
1053
 
1026
 
1054
}
1027
}
1055
 
1028
 
1056
 
1029
 
1057
function getInvoiceItems(invoiceId) {
1030
function getInvoiceItems(invoiceId) {
1058
 
1031
 
1059
	doGetAjaxRequestHandler(context + "/getInvoiceItems?invoiceId=" + invoiceId, function(response) {
1032
    doGetAjaxRequestHandler(context + "/getInvoiceItems?invoiceId=" + invoiceId, function (response) {
1060
		$('.invoiceadditemcontainer').html(response);
1033
        $('.invoiceadditemcontainer').html(response);
1061
 
1034
 
1062
	});
1035
    });
1063
}
1036
}
1064
 
1037
 
1065
 
1038
 
1066
function getGrnRequestItems(requestId, invoiceId) {
1039
function getGrnRequestItems(requestId, invoiceId) {
1067
 
1040
 
1068
	doGetAjaxRequestHandler(context + "/grnRequestItem?requestId=" + requestId + "&invoiceId=" + invoiceId, function(response) {
1041
    doGetAjaxRequestHandler(context + "/grnRequestItem?requestId=" + requestId + "&invoiceId=" + invoiceId, function (response) {
1069
		$('.grnRequestItemContainer').html(response);
1042
        $('.grnRequestItemContainer').html(response);
1070
 
1043
 
1071
	});
1044
    });
1072
}
1045
}
1073
 
1046
 
1074
 
1047