Subversion Repositories SmartDukaan

Rev

Rev 36027 | Rev 36408 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23506 amit.gupta 1
$(function() {
27754 amit.gupta 2
	$(document).on('click', "a.view-returns", function() {
23638 amit.gupta 3
		viewReturnStores("main-content");
23506 amit.gupta 4
	});
27754 amit.gupta 5
	$(document).on('click', "a.pending-returns", function() {
23506 amit.gupta 6
		viewPendingReturns("main-content");
7
	});
27754 amit.gupta 8
	$(document).on('click', "a.approved-returns", function() {
23506 amit.gupta 9
		viewApprovedReturns("main-content");
10
	});
11
 
27754 amit.gupta 12
	$(document).on('click', "a.view-debit-note", function() {
23539 amit.gupta 13
		viewDebitNotes("main-content");
14
	});
15
 
36316 aman 16
	$(document).on('click', "a.unsettled-purchase-returns", function () {
17
		doAjaxRequestHandler(context + "/return/unsettled", "GET", function (response) {
18
			$('#main-content').html(response);
19
		});
20
	});
21
 
22
	$(document).on('click', "a.create-purchase-return", function () {
23
		doAjaxRequestHandler(context + "/return/unsettled/new", "GET", function (response) {
24
			$('#main-content').html(response);
25
		});
26
	});
27
 
27754 amit.gupta 28
	$(document).on('click', "a.wh-display-name", function() {
23506 amit.gupta 29
		var whId = $(this).closest('tr').data('id');
30
		$("#approved-returns-container").find("tr.filter").hide().filter('[data-id="' + whId + '"]').show();
23540 amit.gupta 31
		$(this).closest('table').find('tr').removeClass('warning');
23506 amit.gupta 32
		$(this).closest('tr').addClass('warning');
33
	});
23539 amit.gupta 34
 
27754 amit.gupta 35
	$(document).on('click', "a.debit-note", function() {
23539 amit.gupta 36
		var debitNoteId = $(this).closest('tr').data('id');
37
		$("#debit-note-items").find("tr.filter").hide().filter('[data-id="' + debitNoteId + '"]').show();
29937 amit.gupta 38
		$(this).closest('table').find('tr').removeClass('alert-warning');
39
		$(this).closest('tr').addClass('alert-warning');
23539 amit.gupta 40
	});
35998 amit 41
 
42
 
27754 amit.gupta 43
	$(document).on('click', "a.request-return", function() {
23506 amit.gupta 44
		if(confirm("Are you sure?")) {
45
			createReturnRequest($(this).data("inventoryitemid"), $(this));
46
		}
47
	});
27754 amit.gupta 48
	$(document).on('click', "a.approve-return", function() {
23506 amit.gupta 49
		if(confirm("Are you sure to Approve?")) {
23638 amit.gupta 50
			approveReturnRequest($(this).closest('td').data("returnid"), $(this).closest('td'));
23506 amit.gupta 51
		}
52
	});
27754 amit.gupta 53
	$(document).on('click', "a.deny-return", function() {
23506 amit.gupta 54
		if(confirm("Are you sure to Deny?")) {
23644 amit.gupta 55
			denyReturnRequest($(this).closest('td').data("returnid"), $(this).closest('td'));
23506 amit.gupta 56
		}
57
	});
35998 amit 58
 
27763 tejbeer 59
	$(document).on('click', '#inventory-container a', function (){
23638 amit.gupta 60
		itemId=$(this).data('id');
34142 tejus.loha 61
		if(!fofoId){
62
			fofoId =$('select[name="fofo-users"]').val();
63
			console.log("fofo Id -"+fofoId);
64
		}
23638 amit.gupta 65
		doAjaxRequestHandler(context+"/return/inventory/" + fofoId + "/" + itemId, "GET", function(response){
66
			returnsTable.rows().remove().rows.add($(response)).draw(false);
67
		});
68
	});
35998 amit 69
 
70
	$(document).on('click', '.vendor_return', function () {
71
		doAjaxRequestHandler(context + "/return/to/vendor", "GET", function (response) {
72
			$('#main-content').html(response);
73
		});
74
	});
75
 
76
	// Invoice Return
77
	$(document).on('click', 'a.invoice-return', function () {
78
		doAjaxRequestHandler(context + "/return/invoice", "GET", function (response) {
79
			$('#main-content').html(response);
80
		});
81
	});
82
 
83
	// Search by Debit Note Number
84
	$(document).on('click', '#search-debit-note-btn', function () {
85
		var debitNoteNumber = $('#debit-note-number-input').val();
86
		if (!debitNoteNumber) {
87
			alert("Please enter a debit note number");
88
			return;
89
		}
90
		doAjaxRequestHandler(context + "/return/search/debit-note?debitNoteNumber=" + encodeURIComponent(debitNoteNumber), "GET", function (response) {
91
			$('#invoice-return-results').html(response);
92
		});
93
	});
94
 
95
	$(document).on('click', '#return-invoice-button', function () {
96
		var invoiceNumber = $('#invoice-number-input').val();
97
		if (!invoiceNumber) {
98
			alert("Please enter an invoice number");
99
			return;
100
		}
101
		doAjaxRequestHandler(context + "/return/invoice/search?invoiceNumber=" + encodeURIComponent(invoiceNumber), "GET", function (response) {
102
			$('#invoice-return-results').html(response);
103
		});
104
	});
105
 
106
	// Debit Note Details
107
	$(document).on('click', '.debit-note-details', function () {
108
		var debitNoteId = $(this).data("debitnote-id");
109
		doAjaxRequestHandler(context + "/return/debit-note/details/" + debitNoteId, "GET", function (response) {
110
			$('#main-content').html(response);
111
		});
112
	});
113
 
114
	// Receive Debit Note
115
	$(document).on('click', '.receive-debit-note', function () {
116
		var debitNoteId = $(this).data("debitnote-id");
117
		doAjaxRequestHandler(context + "/return/debit-note/receive/" + debitNoteId, "GET", function (response) {
118
			$('#main-content').html(response);
119
		});
120
	});
121
 
122
	// Show/hide DOA certificate section based on BAD selection on mobile items
123
	$(document).on('change', '.return-condition', function () {
124
		var hasMobileBad = false;
125
		$('#receive-debit-note-form tr[data-category-id]').each(function () {
126
			var categoryId = $(this).data('category-id');
127
			var condition = $(this).find('.return-condition').val();
128
			if (condition === 'BAD' && categoryId == 10006) {
129
				hasMobileBad = true;
130
			}
131
		});
132
		if (hasMobileBad) {
133
			$('#doa-certificate-section').show();
134
		} else {
135
			$('#doa-certificate-section').hide();
136
		}
137
	});
138
 
139
	// Submit receive debit note form
140
	$(document).on('submit', '#receive-debit-note-form', function (e) {
141
		e.preventDefault();
142
 
143
		// Validate remarks for BAD items
144
		var valid = true;
145
		$(this).find('tr[data-item-id]').each(function () {
146
			var condition = $(this).find('.return-condition').val();
147
			var remark = $(this).find('.remark-field').val();
148
			if (condition === 'BAD' && !remark) {
149
				alert("Remark is required for BAD/DOA returns");
150
				valid = false;
151
				return false;
152
			}
153
		});
154
		if (!valid) return;
155
 
156
		// Check DOA certificate if mobile BAD items exist
157
		var hasMobileBad = false;
158
		$(this).find('tr[data-category-id]').each(function () {
159
			if ($(this).data('category-id') == 10006 && $(this).find('.return-condition').val() === 'BAD') {
160
				hasMobileBad = true;
161
			}
162
		});
163
		if (hasMobileBad && !$('input[name="doaCertificateValid"]:checked').val()) {
164
			alert("Please select DOA certificate validity");
165
			return;
166
		}
167
 
168
		var debitNoteId = $(this).data('debitnote-id');
169
		if (confirm("Are you sure you want to confirm receipt for this debit note?")) {
170
			$.ajax({
171
				url: context + "/return/debit-note/receive/" + debitNoteId,
172
				type: "POST",
173
				data: $(this).serialize(),
174
				success: function (response) {
175
					if (response === 'true' || response.indexOf('true') >= 0) {
176
						alert("Debit note items received successfully");
177
						doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
178
							$('#main-content').html(resp);
179
						});
180
					} else {
181
						alert("Receipt failed: " + response);
182
					}
183
				},
184
				error: function (xhr) {
185
					alert("Error: " + xhr.responseText);
186
				}
187
			});
188
		}
189
	});
190
 
191
	// Refund Debit Note - opens refund view with receipt details
192
	$(document).on('click', '.refund-debit-note', function () {
193
		var debitNoteId = $(this).data("debitnote-id");
194
		doAjaxRequestHandler(context + "/return/debit-note/refund/" + debitNoteId, "GET", function (response) {
195
			$('#main-content').html(response);
196
		});
197
	});
198
 
199
	// Confirm refund with finance remark
200
	$(document).on('click', '.refund-debit-note-confirm', function () {
201
		var debitNoteId = $(this).data("debitnote-id");
202
		var financeRemark = $('#finance-remark').val();
203
		if (confirm("Are you sure you want to process refund for debit note " + debitNoteId + "?")) {
204
			doAjaxRequestHandler(context + "/return/debit-note/refund/" + debitNoteId + "?financeRemark=" + encodeURIComponent(financeRemark), "PUT", function (response) {
205
				if (response === 'true') {
206
					alert("Debit note refunded successfully");
207
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
208
						$('#main-content').html(resp);
209
					});
210
				} else {
211
					alert("Refund failed: " + response);
212
				}
213
			});
214
		}
215
	});
216
 
217
	// Reject debit note return
218
	$(document).on('click', '.reject-debit-note-confirm', function () {
219
		var debitNoteId = $(this).data("debitnote-id");
220
		var rejectRemark = $('#reject-remark').val();
221
		if (!rejectRemark) {
222
			alert("Please enter a reject remark");
223
			return;
224
		}
225
		if (confirm("Are you sure you want to reject return for debit note " + debitNoteId + "? This will reverse all scans and quantities.")) {
226
			doAjaxRequestHandler(context + "/return/debit-note/reject/" + debitNoteId + "?rejectRemark=" + encodeURIComponent(rejectRemark), "PUT", function (response) {
227
				if (response === 'true') {
228
					alert("Return rejected successfully");
229
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
230
						$('#main-content').html(resp);
231
					});
232
				} else {
233
					alert("Rejection failed: " + response);
234
				}
235
			});
236
		}
237
	});
36022 amit 238
 
36027 amit 239
	// Approve Invoice Return (finance approval for shipped invoices)
240
	$(document).on('click', '.approve-invoice-return', function () {
241
		var proId = $(this).data("pro-id");
242
		if (confirm("Are you sure you want to approve and refund this invoice return?")) {
243
			doAjaxRequestHandler(context + "/return/invoice/approve/" + proId, "PUT", function (response) {
244
				if (response === 'true') {
245
					alert("Invoice return approved and refunded successfully");
246
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
247
						$('#main-content').html(resp);
248
					});
249
				} else {
250
					alert("Approval failed: " + response);
251
				}
252
			});
253
		}
254
	});
255
 
36022 amit 256
	// Process Invoice Return (non-GRN'd)
257
	$(document).on('click', '.process-invoice-return', function () {
258
		var invoiceNumber = $(this).data("invoice");
259
		var remark = $('#invoice-return-remark').val();
260
		if (confirm("Are you sure you want to process return for invoice " + invoiceNumber + "?")) {
261
			doAjaxRequestHandler(context + "/return/invoice/process?invoiceNumber=" + encodeURIComponent(invoiceNumber) + "&remark=" + encodeURIComponent(remark), "PUT", function (response) {
262
				if (response === 'true') {
263
					alert("Invoice return processed successfully");
264
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
265
						$('#main-content').html(resp);
266
					});
267
				} else {
268
					alert("Return failed: " + response);
269
				}
270
			});
271
		}
272
	});
23506 amit.gupta 273
});
274
 
23638 amit.gupta 275
function viewReturnStores(domId){
276
	doAjaxRequestHandler(context+"/return/stores", "GET", function(response){
23506 amit.gupta 277
		$('#' + domId).html(response);
278
	});
279
}
280
 
281
function viewPendingReturns(domId){
282
	doAjaxRequestHandler(context+"/return/pending", "GET", function(response){
283
		$('#' + domId).html(response);
284
	});
285
}
286
 
287
function viewApprovedReturns(domId){
288
	doAjaxRequestHandler(context+"/return/approved", "GET", function(response){
289
		$('#' + domId).html(response);
290
		$("#approved-returns").find('a:first').click();
291
	});
292
}
293
 
23539 amit.gupta 294
function viewDebitNotes(domId){
295
	doAjaxRequestHandler(context+"/return/debit-note-created", "GET", function(response){
296
		$('#' + domId).html(response);
297
		$("#debit-notes").find('a:first').click();
298
	});
299
}
300
 
23506 amit.gupta 301
function createReturnRequest(inventoryItemId, container){
302
	doAjaxRequestHandler(context+"/return/inventory/" + inventoryItemId, "PUT", function(response){
303
		if(response=='true') {
304
			container.closest('td').html('Return requested');
305
		}
306
	});
307
}
308
 
309
function approveReturnRequest(inventoryItemId, container){
310
	doAjaxRequestHandler(context+"/return/inventory/approve/" + inventoryItemId, "PUT", function(response){
311
		if(response=='true') {
312
			container.closest('td').html('Return Approved');
313
		}
314
	});
315
}
316
 
317
function denyReturnRequest(inventoryItemId, container){
318
	doAjaxRequestHandler(context+"/return/inventory/deny/" + inventoryItemId, "PUT", function(response){
319
		if(response=='true') {
320
			container.closest('td').html('Return denied');
321
		}
322
	});
323
}
324
 
325
function viewDebitNote(warehouseId){
326
	doAjaxRequestHandler(context+"/return/debit-note/view/" + warehouseId, "GET", function(response){
327
		//Download PDF code
328
	});
329
}
330
 
331
function generateDebitNote(warehouseId){
332
	doAjaxRequestHandler(context+"/return/debit-note/generate/" + warehouseId, "PUT", function(response){
333
		if(response=='true') {
35998 amit 334
			//Download the pdf
23506 amit.gupta 335
		}
35998 amit 336
	});
23506 amit.gupta 337
}
338
 
339
function getDebitNote(debitNotedId) {
340
	doAjaxRequestHandler(context+"/return/debit-note/" + debitNotedId, "GET", function(response){
35998 amit 341
 
23506 amit.gupta 342
	});
343
}