Subversion Repositories SmartDukaan

Rev

Rev 37365 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37365 Rev 37543
Line 132... Line 132...
132
	// Receive Debit Note
132
	// Receive Debit Note
133
	$(document).on('click', '.receive-debit-note', function () {
133
	$(document).on('click', '.receive-debit-note', function () {
134
		var debitNoteId = $(this).data("debitnote-id");
134
		var debitNoteId = $(this).data("debitnote-id");
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
			applyDeclaredConditions();
137
		});
138
		});
138
	});
139
	});
139
 
140
 
-
 
141
	// Seed every condition dropdown from what the partner declared, then settle the dependent
-
 
142
	// sections. Doing both here keeps one source of truth - the row's data-declared attribute - and
-
 
143
	// guarantees the DOA radios are resolved on load, which a preselected BAD never triggers on its
-
 
144
	// own because no change event fires for it.
-
 
145
	//
-
 
146
	// The markup still renders `selected` server-side as the fallback. If this script fails to load,
-
 
147
	// a declared BAD must not quietly present as GOOD: the server reads any difference from
-
 
148
	// data-declared as the warehouse DISAGREEING with the partner and rejects the whole debit note.
-
 
149
	function applyDeclaredConditions() {
-
 
150
		$('#receive-debit-note-form .return-condition').each(function () {
-
 
151
			var declared = $(this).data('declared');
-
 
152
			if (declared) {
-
 
153
				$(this).val(declared);
-
 
154
			}
-
 
155
		});
-
 
156
		syncReceiveConditionState();
-
 
157
	}
-
 
158
 
140
	// A row whose selected condition differs from what the partner declared is a disagreement,
159
	// 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.
160
	// not a correction — the server rejects the whole debit note for it.
142
	function hasConditionMismatch() {
161
	function hasConditionMismatch() {
143
		var mismatch = false;
162
		var mismatch = false;
144
		$('#receive-debit-note-form tr[data-item-id]').each(function () {
163
		$('#receive-debit-note-form tr[data-item-id]').each(function () {
Line 148... Line 167...
148
			}
167
			}
149
		});
168
		});
150
		return mismatch;
169
		return mismatch;
151
	}
170
	}
152
 
171
 
153
	// Show/hide DOA certificate section based on BAD selection on mobile items
172
	// Show/hide the DOA certificate section based on BAD selection on mobile items.
-
 
173
	//
-
 
174
	// Driven by the CURRENT state of the form, never by what the operator just touched, because the
154
	$(document).on('change', '.return-condition', function () {
175
	// form arrives with the partner's declared condition already selected. A partner declaring a
-
 
176
	// mobile as BAD - the ordinary DOA case - renders BAD preselected, so no change event ever
-
 
177
	// fires; leaving this logic in the change handler alone hid the DOA radios on exactly the rows
-
 
178
	// that need them, and the server then refused the receipt for a missing certificate the operator
-
 
179
	// was never shown.
155
		var mismatch = hasConditionMismatch();
180
	function syncReceiveConditionState() {
-
 
181
		if (!$('#receive-debit-note-form').length) {
-
 
182
			return;
-
 
183
		}
156
 
184
 
157
		// On a mismatch the receipt never happens, so the DOA certificate is not collected.
185
		// On a mismatch the receipt never happens, so the DOA certificate is not collected.
158
		if (mismatch) {
186
		if (hasConditionMismatch()) {
159
			$('#condition-mismatch-section').show();
187
			$('#condition-mismatch-section').show();
160
			$('#doa-certificate-section').hide();
188
			$('#doa-certificate-section').hide();
161
			$('#submit-receive').removeClass('btn-primary').addClass('btn-danger').text('Reject Return');
189
			$('#submit-receive').removeClass('btn-primary').addClass('btn-danger').text('Reject Return');
162
			return;
190
			return;
163
		}
191
		}
Line 175... Line 203...
175
		if (hasMobileBad) {
203
		if (hasMobileBad) {
176
			$('#doa-certificate-section').show();
204
			$('#doa-certificate-section').show();
177
		} else {
205
		} else {
178
			$('#doa-certificate-section').hide();
206
			$('#doa-certificate-section').hide();
179
		}
207
		}
180
	});
208
	}
-
 
209
 
-
 
210
	$(document).on('change', '.return-condition', syncReceiveConditionState);
181
 
211
 
182
	// Submit receive debit note form
212
	// Submit receive debit note form
183
	$(document).on('submit', '#receive-debit-note-form', function (e) {
213
	$(document).on('submit', '#receive-debit-note-form', function (e) {
184
		e.preventDefault();
214
		e.preventDefault();
185
 
215