| Line 135... |
Line 135... |
| 135 |
doAjaxRequestHandler(context + "/return/debit-note/receive/" + debitNoteId, "GET", function (response) {
|
135 |
doAjaxRequestHandler(context + "/return/debit-note/receive/" + debitNoteId, "GET", function (response) {
|
| 136 |
$('#main-content').html(response);
|
136 |
$('#main-content').html(response);
|
| 137 |
});
|
137 |
});
|
| 138 |
});
|
138 |
});
|
| 139 |
|
139 |
|
| - |
|
140 |
// A row whose selected condition differs from what the partner declared is a disagreement,
|
| - |
|
141 |
// not a correction — the server rejects the whole debit note for it.
|
| - |
|
142 |
function hasConditionMismatch() {
|
| - |
|
143 |
var mismatch = false;
|
| - |
|
144 |
$('#receive-debit-note-form tr[data-item-id]').each(function () {
|
| - |
|
145 |
var select = $(this).find('.return-condition');
|
| - |
|
146 |
if (select.val() !== select.data('declared')) {
|
| - |
|
147 |
mismatch = true;
|
| - |
|
148 |
}
|
| - |
|
149 |
});
|
| - |
|
150 |
return mismatch;
|
| - |
|
151 |
}
|
| - |
|
152 |
|
| 140 |
// Show/hide DOA certificate section based on BAD selection on mobile items
|
153 |
// Show/hide DOA certificate section based on BAD selection on mobile items
|
| 141 |
$(document).on('change', '.return-condition', function () {
|
154 |
$(document).on('change', '.return-condition', function () {
|
| - |
|
155 |
var mismatch = hasConditionMismatch();
|
| - |
|
156 |
|
| - |
|
157 |
// On a mismatch the receipt never happens, so the DOA certificate is not collected.
|
| - |
|
158 |
if (mismatch) {
|
| - |
|
159 |
$('#condition-mismatch-section').show();
|
| - |
|
160 |
$('#doa-certificate-section').hide();
|
| - |
|
161 |
$('#submit-receive').removeClass('btn-primary').addClass('btn-danger').text('Reject Return');
|
| - |
|
162 |
return;
|
| - |
|
163 |
}
|
| - |
|
164 |
$('#condition-mismatch-section').hide();
|
| - |
|
165 |
$('#submit-receive').removeClass('btn-danger').addClass('btn-primary').text('Confirm Receipt');
|
| - |
|
166 |
|
| 142 |
var hasMobileBad = false;
|
167 |
var hasMobileBad = false;
|
| 143 |
$('#receive-debit-note-form tr[data-category-id]').each(function () {
|
168 |
$('#receive-debit-note-form tr[data-category-id]').each(function () {
|
| 144 |
var categoryId = $(this).data('category-id');
|
169 |
var categoryId = $(this).data('category-id');
|
| 145 |
var condition = $(this).find('.return-condition').val();
|
170 |
var condition = $(this).find('.return-condition').val();
|
| 146 |
if (condition === 'BAD' && categoryId == 10006) {
|
171 |
if (condition === 'BAD' && categoryId == 10006) {
|
| Line 156... |
Line 181... |
| 156 |
|
181 |
|
| 157 |
// Submit receive debit note form
|
182 |
// Submit receive debit note form
|
| 158 |
$(document).on('submit', '#receive-debit-note-form', function (e) {
|
183 |
$(document).on('submit', '#receive-debit-note-form', function (e) {
|
| 159 |
e.preventDefault();
|
184 |
e.preventDefault();
|
| 160 |
|
185 |
|
| 161 |
// Validate remarks for BAD items
|
186 |
var mismatch = hasConditionMismatch();
|
| - |
|
187 |
|
| - |
|
188 |
// Validate remarks: mandatory for BAD rows, and for any row whose condition was changed —
|
| - |
|
189 |
// the remark is what the partner and the escalation chain see as the reason for rejection.
|
| 162 |
var valid = true;
|
190 |
var valid = true;
|
| 163 |
$(this).find('tr[data-item-id]').each(function () {
|
191 |
$(this).find('tr[data-item-id]').each(function () {
|
| 164 |
var condition = $(this).find('.return-condition').val();
|
192 |
var select = $(this).find('.return-condition');
|
| - |
|
193 |
var condition = select.val();
|
| 165 |
var remark = $(this).find('.remark-field').val();
|
194 |
var remark = $(this).find('.remark-field').val();
|
| - |
|
195 |
if (condition !== select.data('declared') && !remark) {
|
| - |
|
196 |
alert("Remark is required when you change the condition — it is sent to the partner as the rejection reason");
|
| - |
|
197 |
valid = false;
|
| - |
|
198 |
return false;
|
| - |
|
199 |
}
|
| 166 |
if (condition === 'BAD' && !remark) {
|
200 |
if (condition === 'BAD' && !remark) {
|
| 167 |
alert("Remark is required for BAD/DOA returns");
|
201 |
alert("Remark is required for BAD/DOA returns");
|
| 168 |
valid = false;
|
202 |
valid = false;
|
| 169 |
return false;
|
203 |
return false;
|
| 170 |
}
|
204 |
}
|
| 171 |
});
|
205 |
});
|
| 172 |
if (!valid) return;
|
206 |
if (!valid) return;
|
| 173 |
|
207 |
|
| 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');
|
208 |
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(),
|
209 |
var form = $(this);
|
| - |
|
210 |
|
| 192 |
success: function (response) {
|
211 |
if (mismatch) {
|
| 193 |
if (response === 'true' || response.indexOf('true') >= 0) {
|
212 |
if (!confirm("The condition you selected does not match what the partner declared.\n\n"
|
| 194 |
alert("Debit note items received successfully");
|
213 |
+ "This will REJECT the entire debit note and notify the partner, Logistics, RBM and Sales. "
|
| 195 |
doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
|
214 |
+ "No refund will be raised.\n\nProceed?")) {
|
| 196 |
$('#main-content').html(resp);
|
215 |
return;
|
| 197 |
});
|
216 |
}
|
| 198 |
} else {
|
217 |
} else {
|
| 199 |
alert("Receipt failed: " + response);
|
218 |
// Check DOA certificate if mobile BAD items exist
|
| 200 |
}
|
- |
|
| 201 |
},
|
219 |
var hasMobileBad = false;
|
| 202 |
error: function (xhr) {
|
220 |
$(this).find('tr[data-category-id]').each(function () {
|
| - |
|
221 |
if ($(this).data('category-id') == 10006 && $(this).find('.return-condition').val() === 'BAD') {
|
| 203 |
alert("Error: " + xhr.responseText);
|
222 |
hasMobileBad = true;
|
| 204 |
}
|
223 |
}
|
| 205 |
});
|
224 |
});
|
| - |
|
225 |
if (hasMobileBad && !$('input[name="doaCertificateValid"]:checked').val()) {
|
| - |
|
226 |
alert("Please select DOA certificate validity");
|
| - |
|
227 |
return;
|
| - |
|
228 |
}
|
| - |
|
229 |
if (!confirm("Are you sure you want to confirm receipt for this debit note?")) {
|
| - |
|
230 |
return;
|
| - |
|
231 |
}
|
| 206 |
}
|
232 |
}
|
| - |
|
233 |
|
| - |
|
234 |
$.ajax({
|
| - |
|
235 |
url: context + "/return/debit-note/receive/" + debitNoteId,
|
| - |
|
236 |
type: "POST",
|
| - |
|
237 |
data: form.serialize(),
|
| - |
|
238 |
success: function (response) {
|
| - |
|
239 |
if (response === 'true' || response.indexOf('true') >= 0) {
|
| - |
|
240 |
alert(mismatch
|
| - |
|
241 |
? "Debit note rejected due to condition mismatch. Partner and escalation chain notified."
|
| - |
|
242 |
: "Debit note items received successfully");
|
| - |
|
243 |
doAjaxRequestHandler(context + "/return/invoice", "GET", function (resp) {
|
| - |
|
244 |
$('#main-content').html(resp);
|
| - |
|
245 |
});
|
| - |
|
246 |
} else {
|
| - |
|
247 |
alert((mismatch ? "Rejection failed: " : "Receipt failed: ") + response);
|
| - |
|
248 |
}
|
| - |
|
249 |
},
|
| - |
|
250 |
error: function (xhr) {
|
| - |
|
251 |
alert("Error: " + xhr.responseText);
|
| - |
|
252 |
}
|
| - |
|
253 |
});
|
| 207 |
});
|
254 |
});
|
| 208 |
|
255 |
|
| 209 |
// Refund Debit Note - opens refund view with receipt details
|
256 |
// Refund Debit Note - opens refund view with receipt details
|
| 210 |
$(document).on('click', '.refund-debit-note', function () {
|
257 |
$(document).on('click', '.refund-debit-note', function () {
|
| 211 |
var debitNoteId = $(this).data("debitnote-id");
|
258 |
var debitNoteId = $(this).data("debitnote-id");
|