This commit is contained in:
Ravi Gulhane 2026-10-12 16:00:38 +05:30
parent 7a9ab54e73
commit 18106b4977
3 changed files with 56 additions and 5 deletions

View File

@ -121,13 +121,17 @@ class FormController extends Controller
if ($invoice !== '' && !$hasInvoice) {
return ['__error' => 'Upload an invoice as a JPG, JPEG, PNG, or PDF file.'];
}
if (!$isExisting) {
$post['submission_status'] = 'Order Taken';
$supplyYes = ($post['supply_status'] ?? '') === 'Yes';
if (!$supplyYes) {
if (!$isExisting) {
$post['submission_status'] = 'Order Taken';
} else {
unset($post['submission_status']);
}
return $post;
}
if (!$hasInvoice) {
unset($post['submission_status']);
return $post;
return ['__error' => 'Upload an invoice as a JPG, JPEG, PNG, or PDF file.'];
}
$actualUnits = 0;
$actualValue = 0;

View File

@ -116,6 +116,7 @@ $(function () {
dateInput.min = '2026-09-01';
dateInput.max = today.getFullYear() + '-' + month + '-' + day;
var surveyContacts = [];
var submittedIdentities = [];
var contactsReady = false;
// Dev only: open every section. Set to false to lock later sections until the previous step is complete.
var unlockAllSections = true;
@ -622,6 +623,39 @@ $(function () {
return true;
}
return existingPin === String(pincode || '').trim();
}) || submittedIdentities.some(function (item) {
if (item.type !== type) {
return false;
}
if (normalizedName(item.name) !== wantedName || contactPhone({ phone: item.phone }) !== wantedPhone) {
return false;
}
if (type !== 'ebt_chemist') {
return true;
}
var savedPin = String(item.pincode || '').trim();
if (!savedPin) {
return true;
}
return savedPin === String(pincode || '').trim();
});
}
function rememberSubmission(type) {
if (type === 'doctor') {
submittedIdentities.push({
type: 'ebt_doctor',
name: $('#field-doctor_name').val(),
phone: $('#field-mobile_number').val(),
pincode: ''
});
return;
}
submittedIdentities.push({
type: 'ebt_chemist',
name: $('#field-chemist_name').val(),
phone: $('#field-chemist_mobile').val(),
pincode: $('#field-chemist_pincode').val()
});
}
@ -794,6 +828,7 @@ $(function () {
emptyFiles.prop('disabled', false);
$('#pageloader').fadeOut();
if (data.status == 'success') {
rememberSubmission(type);
Swal.fire({ title: 'Great!', text: 'Your data is successfully submitted!', icon: 'success' });
$('#report-form .saved-file').remove();
$('#report-form .photo-chosen').text('');

View File

@ -408,7 +408,7 @@
$('#report-form [name="actual_' + name + '"]').val(mode === 'upload' ? (actual || data[name] || 0) : (actual || 0));
});
recalc('.pob-units', '.pob-value', '#field-total_pob_units', '#field-total_pob_value');
setActualVisible(mode === 'upload');
setActualVisible($('#field-supply_status').val() === 'Yes');
openContactId = data.contact_id || '';
}
@ -510,6 +510,7 @@
return;
}
openContactId = $('#field-contact_id').val() || openContactId;
$('#report-form [name="submission_status"]').val($('#field-supply_status').val() === 'Yes' ? 'Invoice Uploaded' : 'Order Taken');
$('#pageloader').css('display', 'flex').hide().fadeIn();
$.ajax({
type: 'POST',
@ -541,6 +542,17 @@
$('#report-form').on('input', '.pob-units', function () {
recalc('.pob-units', '.pob-value', '#field-total_pob_units', '#field-total_pob_value');
});
$('#field-supply_status').on('change', function () {
if (this.value === 'Yes') {
unitFields.forEach(function (name) {
var actual = $('#report-form [name="actual_' + name + '"]');
if (!actual.val() || actual.val() === '0') {
actual.val($('#report-form [name="' + name + '"]').val() || 0);
}
});
}
setActualVisible(this.value === 'Yes');
});
$('#report-form').on('input', '.actual-units', function () {
recalc('.actual-units', '.actual-value', '#field-total_actual_pob_units', '#field-total_actual_pob_value');
});