Subversion Repositories SmartDukaan

Rev

Rev 34580 | Rev 36022 | 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
	});
23506 amit.gupta 226
});
227
 
23638 amit.gupta 228
function viewReturnStores(domId){
229
	doAjaxRequestHandler(context+"/return/stores", "GET", function(response){
23506 amit.gupta 230
		$('#' + domId).html(response);
231
	});
232
}
233
 
234
function viewPendingReturns(domId){
235
	doAjaxRequestHandler(context+"/return/pending", "GET", function(response){
236
		$('#' + domId).html(response);
237
	});
238
}
239
 
240
function viewApprovedReturns(domId){
241
	doAjaxRequestHandler(context+"/return/approved", "GET", function(response){
242
		$('#' + domId).html(response);
243
		$("#approved-returns").find('a:first').click();
244
	});
245
}
246
 
23539 amit.gupta 247
function viewDebitNotes(domId){
248
	doAjaxRequestHandler(context+"/return/debit-note-created", "GET", function(response){
249
		$('#' + domId).html(response);
250
		$("#debit-notes").find('a:first').click();
251
	});
252
}
253
 
23506 amit.gupta 254
function createReturnRequest(inventoryItemId, container){
255
	doAjaxRequestHandler(context+"/return/inventory/" + inventoryItemId, "PUT", function(response){
256
		if(response=='true') {
257
			container.closest('td').html('Return requested');
258
		}
259
	});
260
}
261
 
262
function approveReturnRequest(inventoryItemId, container){
263
	doAjaxRequestHandler(context+"/return/inventory/approve/" + inventoryItemId, "PUT", function(response){
264
		if(response=='true') {
265
			container.closest('td').html('Return Approved');
266
		}
267
	});
268
}
269
 
270
function denyReturnRequest(inventoryItemId, container){
271
	doAjaxRequestHandler(context+"/return/inventory/deny/" + inventoryItemId, "PUT", function(response){
272
		if(response=='true') {
273
			container.closest('td').html('Return denied');
274
		}
275
	});
276
}
277
 
278
function viewDebitNote(warehouseId){
279
	doAjaxRequestHandler(context+"/return/debit-note/view/" + warehouseId, "GET", function(response){
280
		//Download PDF code
281
	});
282
}
283
 
284
function generateDebitNote(warehouseId){
285
	doAjaxRequestHandler(context+"/return/debit-note/generate/" + warehouseId, "PUT", function(response){
286
		if(response=='true') {
35998 amit 287
			//Download the pdf
23506 amit.gupta 288
		}
35998 amit 289
	});
23506 amit.gupta 290
}
291
 
292
function getDebitNote(debitNotedId) {
293
	doAjaxRequestHandler(context+"/return/debit-note/" + debitNotedId, "GET", function(response){
35998 amit 294
 
23506 amit.gupta 295
	});
296
}