| Line 297... |
Line 297... |
| 297 |
var financeRemark = $('#finance-remark').val();
|
297 |
var financeRemark = $('#finance-remark').val();
|
| 298 |
if (confirm("Are you sure you want to process refund for debit note " + debitNoteId + "?")) {
|
298 |
if (confirm("Are you sure you want to process refund for debit note " + debitNoteId + "?")) {
|
| 299 |
doAjaxRequestHandler(context + "/return/debit-note/refund/" + debitNoteId + "?financeRemark=" + encodeURIComponent(financeRemark), "PUT", function (response) {
|
299 |
doAjaxRequestHandler(context + "/return/debit-note/refund/" + debitNoteId + "?financeRemark=" + encodeURIComponent(financeRemark), "PUT", function (response) {
|
| 300 |
if (response === 'true') {
|
300 |
if (response === 'true') {
|
| 301 |
alert("Debit note refunded successfully");
|
301 |
alert("Debit note refunded successfully");
|
| 302 |
doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
|
- |
|
| 303 |
$('#main-content').html(resp);
|
302 |
reloadReturnQueue();
|
| 304 |
});
|
- |
|
| 305 |
} else {
|
303 |
} else {
|
| 306 |
alert("Refund failed: " + response);
|
304 |
alert("Refund failed: " + response);
|
| 307 |
}
|
305 |
}
|
| 308 |
});
|
306 |
}, approvalFailed);
|
| 309 |
}
|
307 |
}
|
| 310 |
});
|
308 |
});
|
| 311 |
|
309 |
|
| 312 |
// Reject debit note return
|
310 |
// Reject debit note return
|
| 313 |
$(document).on('click', '.reject-debit-note-confirm', function () {
|
311 |
$(document).on('click', '.reject-debit-note-confirm', function () {
|
| Line 336... |
Line 334... |
| 336 |
var proId = $(this).data("pro-id");
|
334 |
var proId = $(this).data("pro-id");
|
| 337 |
if (confirm("Are you sure you want to approve and refund this invoice return?")) {
|
335 |
if (confirm("Are you sure you want to approve and refund this invoice return?")) {
|
| 338 |
doAjaxRequestHandler(context + "/return/invoice/approve/" + proId, "PUT", function (response) {
|
336 |
doAjaxRequestHandler(context + "/return/invoice/approve/" + proId, "PUT", function (response) {
|
| 339 |
if (response === 'true') {
|
337 |
if (response === 'true') {
|
| 340 |
alert("Invoice return approved and refunded successfully");
|
338 |
alert("Invoice return approved and refunded successfully");
|
| 341 |
doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
|
- |
|
| 342 |
$('#main-content').html(resp);
|
339 |
reloadReturnQueue();
|
| 343 |
});
|
- |
|
| 344 |
} else {
|
340 |
} else {
|
| 345 |
alert("Approval failed: " + response);
|
341 |
alert("Approval failed: " + response);
|
| 346 |
}
|
342 |
}
|
| 347 |
});
|
343 |
}, approvalFailed);
|
| 348 |
}
|
344 |
}
|
| 349 |
});
|
345 |
});
|
| 350 |
|
346 |
|
| - |
|
347 |
// ── Refund as B2C (Finance, same day as a NIC refusal for the buyer's GSTIN) ──
|
| - |
|
348 |
|
| - |
|
349 |
$(document).on('click', '.b2c-refund', function () {
|
| - |
|
350 |
var proId = $(this).data("pro-id");
|
| - |
|
351 |
doAjaxRequestHandler(context + "/return/b2c-refund/" + proId, "GET", function (response) {
|
| - |
|
352 |
$('#main-content').html(response);
|
| - |
|
353 |
});
|
| - |
|
354 |
});
|
| - |
|
355 |
|
| - |
|
356 |
// Enable the button only when the typed amount equals the refund amount exactly, a remark is
|
| - |
|
357 |
// entered and consent is ticked. The server repeats every one of these checks.
|
| - |
|
358 |
$(document).on('input change', '#b2c-amount, #b2c-remark, #b2c-consent', function () {
|
| - |
|
359 |
var $amount = $('#b2c-amount');
|
| - |
|
360 |
var typed = $.trim($amount.val()).replace(/,/g, '');
|
| - |
|
361 |
var expected = String($amount.data('expected'));
|
| - |
|
362 |
var matches = typed !== '' && /^\d+$/.test(typed) && typed === expected;
|
| - |
|
363 |
$('#b2c-amount-error').toggle(typed !== '' && !matches);
|
| - |
|
364 |
var ready = matches && $.trim($('#b2c-remark').val()) !== '' && $('#b2c-consent').is(':checked');
|
| - |
|
365 |
$('#b2c-refund-confirm').prop('disabled', !ready);
|
| - |
|
366 |
});
|
| - |
|
367 |
|
| - |
|
368 |
$(document).on('click', '.b2c-refund-confirm', function () {
|
| - |
|
369 |
var $btn = $(this);
|
| - |
|
370 |
var proId = $btn.data("pro-id");
|
| - |
|
371 |
var amount = $.trim($('#b2c-amount').val()).replace(/,/g, '');
|
| - |
|
372 |
var remark = $.trim($('#b2c-remark').val());
|
| - |
|
373 |
if (!confirm("Refund Rs. " + $btn.data("amount-label") + " to " + $btn.data("partner") + " as B2C?\n"
|
| - |
|
374 |
+ "Stock comes back to the warehouse and a local credit note is issued.\nThis cannot be undone.")) {
|
| - |
|
375 |
return;
|
| - |
|
376 |
}
|
| - |
|
377 |
$btn.prop('disabled', true);
|
| - |
|
378 |
doAjaxRequestHandler(context + "/return/b2c-refund/" + proId + "?amount=" + encodeURIComponent(amount)
|
| - |
|
379 |
+ "&remark=" + encodeURIComponent(remark) + "&consent=true", "PUT", function (response) {
|
| - |
|
380 |
var cnNumber = response;
|
| - |
|
381 |
try { cnNumber = JSON.parse(response); } catch (e) { /* already a plain string */ }
|
| - |
|
382 |
alert("Refunded Rs. " + $btn.data("amount-label") + ". Credit note " + cnNumber + " issued (B2C, no IRN).");
|
| - |
|
383 |
reloadReturnQueue();
|
| - |
|
384 |
}, function (xhr, msg) {
|
| - |
|
385 |
alert("B2C refund failed: " + errorText(msg));
|
| - |
|
386 |
$btn.prop('disabled', false);
|
| - |
|
387 |
});
|
| - |
|
388 |
});
|
| - |
|
389 |
|
| - |
|
390 |
$(document).on('click', '.b2c-refund-cancel', function () {
|
| - |
|
391 |
reloadReturnQueue();
|
| - |
|
392 |
});
|
| - |
|
393 |
|
| 351 |
// Reject Invoice Return — sale stands, no inventory/wallet/GST action
|
394 |
// Reject Invoice Return — sale stands, no inventory/wallet/GST action
|
| 352 |
$(document).on('click', '.reject-invoice-return', function () {
|
395 |
$(document).on('click', '.reject-invoice-return', function () {
|
| 353 |
var proId = $(this).data("pro-id");
|
396 |
var proId = $(this).data("pro-id");
|
| 354 |
var rejectRemark = prompt("Reason for rejecting this invoice return? (sale will stand, no refund will be issued)");
|
397 |
var rejectRemark = prompt("Reason for rejecting this invoice return? (sale will stand, no refund will be issued)");
|
| 355 |
if (!rejectRemark) {
|
398 |
if (!rejectRemark) {
|
| Line 472... |
Line 515... |
| 472 |
function getDebitNote(debitNotedId) {
|
515 |
function getDebitNote(debitNotedId) {
|
| 473 |
doAjaxRequestHandler(context+"/return/debit-note/" + debitNotedId, "GET", function(response){
|
516 |
doAjaxRequestHandler(context+"/return/debit-note/" + debitNotedId, "GET", function(response){
|
| 474 |
|
517 |
|
| 475 |
});
|
518 |
});
|
| 476 |
}
|
519 |
}
|
| - |
|
520 |
|
| - |
|
521 |
function reloadReturnQueue() {
|
| - |
|
522 |
doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
|
| - |
|
523 |
$('#main-content').html(resp);
|
| - |
|
524 |
});
|
| - |
|
525 |
}
|
| - |
|
526 |
|
| - |
|
527 |
// Pull the human-readable message out of an error body; fall back to the raw text.
|
| - |
|
528 |
function errorText(msg) {
|
| - |
|
529 |
try {
|
| - |
|
530 |
var body = JSON.parse(msg);
|
| - |
|
531 |
var r = body.response || body;
|
| - |
|
532 |
return r.message || r.code || body.message || body.code || msg;
|
| - |
|
533 |
} catch (e) {
|
| - |
|
534 |
return msg;
|
| - |
|
535 |
}
|
| - |
|
536 |
}
|
| - |
|
537 |
|
| - |
|
538 |
// A refused approval may have just opened the B2C option, so show the reason and reload the
|
| - |
|
539 |
// queue - the row then carries the "Refund as B2C" button without a manual refresh.
|
| - |
|
540 |
function approvalFailed(xhr, msg) {
|
| - |
|
541 |
alert("Approval failed: " + errorText(msg));
|
| - |
|
542 |
reloadReturnQueue();
|
| - |
|
543 |
}
|