Subversion Repositories SmartDukaan

Rev

Rev 36316 | 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
 
36408 amit 106
	// Date-range filter
107
	$(document).on('click', '#invoice-return-date-apply', function () {
108
		var fromDate = $('#invoice-return-from-date').val();
109
		var toDate = $('#invoice-return-to-date').val();
110
		if (!fromDate || !toDate) {
111
			alert("Please pick both From and To dates");
112
			return;
113
		}
114
		if (fromDate > toDate) {
115
			alert("From date must be on or before To date");
116
			return;
117
		}
118
		doAjaxRequestHandler(context + "/return/invoice?fromDate=" + encodeURIComponent(fromDate)
119
				+ "&toDate=" + encodeURIComponent(toDate), "GET", function (response) {
120
			$('#main-content').html(response);
121
		});
122
	});
123
 
35998 amit 124
	// Debit Note Details
125
	$(document).on('click', '.debit-note-details', function () {
126
		var debitNoteId = $(this).data("debitnote-id");
127
		doAjaxRequestHandler(context + "/return/debit-note/details/" + debitNoteId, "GET", function (response) {
128
			$('#main-content').html(response);
129
		});
130
	});
131
 
132
	// Receive Debit Note
133
	$(document).on('click', '.receive-debit-note', function () {
134
		var debitNoteId = $(this).data("debitnote-id");
135
		doAjaxRequestHandler(context + "/return/debit-note/receive/" + debitNoteId, "GET", function (response) {
136
			$('#main-content').html(response);
137
		});
138
	});
139
 
140
	// Show/hide DOA certificate section based on BAD selection on mobile items
141
	$(document).on('change', '.return-condition', function () {
142
		var hasMobileBad = false;
143
		$('#receive-debit-note-form tr[data-category-id]').each(function () {
144
			var categoryId = $(this).data('category-id');
145
			var condition = $(this).find('.return-condition').val();
146
			if (condition === 'BAD' && categoryId == 10006) {
147
				hasMobileBad = true;
148
			}
149
		});
150
		if (hasMobileBad) {
151
			$('#doa-certificate-section').show();
152
		} else {
153
			$('#doa-certificate-section').hide();
154
		}
155
	});
156
 
157
	// Submit receive debit note form
158
	$(document).on('submit', '#receive-debit-note-form', function (e) {
159
		e.preventDefault();
160
 
161
		// Validate remarks for BAD items
162
		var valid = true;
163
		$(this).find('tr[data-item-id]').each(function () {
164
			var condition = $(this).find('.return-condition').val();
165
			var remark = $(this).find('.remark-field').val();
166
			if (condition === 'BAD' && !remark) {
167
				alert("Remark is required for BAD/DOA returns");
168
				valid = false;
169
				return false;
170
			}
171
		});
172
		if (!valid) return;
173
 
174
		// Check DOA certificate if mobile BAD items exist
175
		var hasMobileBad = false;
176
		$(this).find('tr[data-category-id]').each(function () {
177
			if ($(this).data('category-id') == 10006 && $(this).find('.return-condition').val() === 'BAD') {
178
				hasMobileBad = true;
179
			}
180
		});
181
		if (hasMobileBad && !$('input[name="doaCertificateValid"]:checked').val()) {
182
			alert("Please select DOA certificate validity");
183
			return;
184
		}
185
 
186
		var debitNoteId = $(this).data('debitnote-id');
187
		if (confirm("Are you sure you want to confirm receipt for this debit note?")) {
188
			$.ajax({
189
				url: context + "/return/debit-note/receive/" + debitNoteId,
190
				type: "POST",
191
				data: $(this).serialize(),
192
				success: function (response) {
193
					if (response === 'true' || response.indexOf('true') >= 0) {
194
						alert("Debit note items received successfully");
195
						doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
196
							$('#main-content').html(resp);
197
						});
198
					} else {
199
						alert("Receipt failed: " + response);
200
					}
201
				},
202
				error: function (xhr) {
203
					alert("Error: " + xhr.responseText);
204
				}
205
			});
206
		}
207
	});
208
 
209
	// Refund Debit Note - opens refund view with receipt details
210
	$(document).on('click', '.refund-debit-note', function () {
211
		var debitNoteId = $(this).data("debitnote-id");
212
		doAjaxRequestHandler(context + "/return/debit-note/refund/" + debitNoteId, "GET", function (response) {
213
			$('#main-content').html(response);
214
		});
215
	});
216
 
217
	// Confirm refund with finance remark
218
	$(document).on('click', '.refund-debit-note-confirm', function () {
219
		var debitNoteId = $(this).data("debitnote-id");
220
		var financeRemark = $('#finance-remark').val();
221
		if (confirm("Are you sure you want to process refund for debit note " + debitNoteId + "?")) {
222
			doAjaxRequestHandler(context + "/return/debit-note/refund/" + debitNoteId + "?financeRemark=" + encodeURIComponent(financeRemark), "PUT", function (response) {
223
				if (response === 'true') {
224
					alert("Debit note refunded successfully");
225
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
226
						$('#main-content').html(resp);
227
					});
228
				} else {
229
					alert("Refund failed: " + response);
230
				}
231
			});
232
		}
233
	});
234
 
235
	// Reject debit note return
236
	$(document).on('click', '.reject-debit-note-confirm', function () {
237
		var debitNoteId = $(this).data("debitnote-id");
238
		var rejectRemark = $('#reject-remark').val();
239
		if (!rejectRemark) {
240
			alert("Please enter a reject remark");
241
			return;
242
		}
243
		if (confirm("Are you sure you want to reject return for debit note " + debitNoteId + "? This will reverse all scans and quantities.")) {
244
			doAjaxRequestHandler(context + "/return/debit-note/reject/" + debitNoteId + "?rejectRemark=" + encodeURIComponent(rejectRemark), "PUT", function (response) {
245
				if (response === 'true') {
246
					alert("Return rejected successfully");
247
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
248
						$('#main-content').html(resp);
249
					});
250
				} else {
251
					alert("Rejection failed: " + response);
252
				}
253
			});
254
		}
255
	});
36022 amit 256
 
36027 amit 257
	// Approve Invoice Return (finance approval for shipped invoices)
258
	$(document).on('click', '.approve-invoice-return', function () {
259
		var proId = $(this).data("pro-id");
260
		if (confirm("Are you sure you want to approve and refund this invoice return?")) {
261
			doAjaxRequestHandler(context + "/return/invoice/approve/" + proId, "PUT", function (response) {
262
				if (response === 'true') {
263
					alert("Invoice return approved and refunded successfully");
264
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
265
						$('#main-content').html(resp);
266
					});
267
				} else {
268
					alert("Approval failed: " + response);
269
				}
270
			});
271
		}
272
	});
273
 
36408 amit 274
	// Reject Invoice Return — sale stands, no inventory/wallet/GST action
275
	$(document).on('click', '.reject-invoice-return', function () {
276
		var proId = $(this).data("pro-id");
277
		var rejectRemark = prompt("Reason for rejecting this invoice return? (sale will stand, no refund will be issued)");
278
		if (!rejectRemark) {
279
			return;
280
		}
281
		if (confirm("Reject invoice return and let the sale stand? This cannot be undone.")) {
282
			doAjaxRequestHandler(context + "/return/invoice/reject/" + proId + "?rejectRemark=" + encodeURIComponent(rejectRemark), "PUT", function (response) {
283
				if (response === 'true') {
284
					alert("Invoice return rejected");
285
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
286
						$('#main-content').html(resp);
287
					});
288
				} else {
289
					alert("Rejection failed: " + response);
290
				}
291
			});
292
		}
293
	});
294
 
36022 amit 295
	// Process Invoice Return (non-GRN'd)
296
	$(document).on('click', '.process-invoice-return', function () {
297
		var invoiceNumber = $(this).data("invoice");
298
		var remark = $('#invoice-return-remark').val();
299
		if (confirm("Are you sure you want to process return for invoice " + invoiceNumber + "?")) {
300
			doAjaxRequestHandler(context + "/return/invoice/process?invoiceNumber=" + encodeURIComponent(invoiceNumber) + "&remark=" + encodeURIComponent(remark), "PUT", function (response) {
301
				if (response === 'true') {
302
					alert("Invoice return processed successfully");
303
					doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
304
						$('#main-content').html(resp);
305
					});
306
				} else {
307
					alert("Return failed: " + response);
308
				}
309
			});
310
		}
311
	});
23506 amit.gupta 312
});
313
 
23638 amit.gupta 314
function viewReturnStores(domId){
315
	doAjaxRequestHandler(context+"/return/stores", "GET", function(response){
23506 amit.gupta 316
		$('#' + domId).html(response);
317
	});
318
}
319
 
320
function viewPendingReturns(domId){
321
	doAjaxRequestHandler(context+"/return/pending", "GET", function(response){
322
		$('#' + domId).html(response);
323
	});
324
}
325
 
326
function viewApprovedReturns(domId){
327
	doAjaxRequestHandler(context+"/return/approved", "GET", function(response){
328
		$('#' + domId).html(response);
329
		$("#approved-returns").find('a:first').click();
330
	});
331
}
332
 
23539 amit.gupta 333
function viewDebitNotes(domId){
334
	doAjaxRequestHandler(context+"/return/debit-note-created", "GET", function(response){
335
		$('#' + domId).html(response);
336
		$("#debit-notes").find('a:first').click();
337
	});
338
}
339
 
23506 amit.gupta 340
function createReturnRequest(inventoryItemId, container){
341
	doAjaxRequestHandler(context+"/return/inventory/" + inventoryItemId, "PUT", function(response){
342
		if(response=='true') {
343
			container.closest('td').html('Return requested');
344
		}
345
	});
346
}
347
 
348
function approveReturnRequest(inventoryItemId, container){
349
	doAjaxRequestHandler(context+"/return/inventory/approve/" + inventoryItemId, "PUT", function(response){
350
		if(response=='true') {
351
			container.closest('td').html('Return Approved');
352
		}
353
	});
354
}
355
 
356
function denyReturnRequest(inventoryItemId, container){
357
	doAjaxRequestHandler(context+"/return/inventory/deny/" + inventoryItemId, "PUT", function(response){
358
		if(response=='true') {
359
			container.closest('td').html('Return denied');
360
		}
361
	});
362
}
363
 
364
function viewDebitNote(warehouseId){
365
	doAjaxRequestHandler(context+"/return/debit-note/view/" + warehouseId, "GET", function(response){
366
		//Download PDF code
367
	});
368
}
369
 
370
function generateDebitNote(warehouseId){
371
	doAjaxRequestHandler(context+"/return/debit-note/generate/" + warehouseId, "PUT", function(response){
372
		if(response=='true') {
35998 amit 373
			//Download the pdf
23506 amit.gupta 374
		}
35998 amit 375
	});
23506 amit.gupta 376
}
377
 
378
function getDebitNote(debitNotedId) {
379
	doAjaxRequestHandler(context+"/return/debit-note/" + debitNotedId, "GET", function(response){
35998 amit 380
 
23506 amit.gupta 381
	});
382
}