Subversion Repositories SmartDukaan

Rev

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