diff --git a/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php b/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php
index f5c61c03..60031aa9 100644
--- a/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php
+++ b/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php
@@ -326,122 +326,111 @@
applySelect2ToDoctorDropdowns();
$("#pageloader").fadeOut();
});
- @endif
- for (let i = 1; i <= 10; i++) {
- $(`#field-mobile_number_${i}`).on('input', function () {
+ // 1. Blade मधील आधीचे submissions JavaScript मध्ये घ्या
+var existingSubmissions = @json($submissions ?? []);
- // Remove non-numeric characters
- this.value = this.value.replace(/\D/g, '');
+// 2. Month change event
+$('#field-month').on('change', function () {
+ var selectedMonth = $(this).val();
- // Limit to 10 digits
- if (this.value.length > 10) {
- this.value = this.value.slice(0, 10);
- }
- });
- }
+ if (!selectedMonth) {
+ return;
+ }
- for (let i = 1; i <= 10; i++) {
+ // निवडलेल्या महिन्यासाठी आधीचे submission शोधा
+ var prevSubmission = existingSubmissions.find(function (sub) {
+ // Backend key नुसार sub.month किंवा sub.data.month तपासा
+ return (sub.month === selectedMonth) || (sub.data && sub.data.month === selectedMonth);
+ });
- $(`#field-email_id_${i}`).on('input', function () {
-
- // Remove spaces
- this.value = this.value.replace(/\s/g, '');
- });
-
- $(`#field-email_id_${i}`).on('blur', function () {
-
- let email = $(this).val().trim();
-
- let emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
-
- if (email !== '' && !emailPattern.test(email)) {
- alert('Please enter a valid email address');
- $(this).focus();
- }
- });
+ if (prevSubmission) {
+ var values = prevSubmission.data || prevSubmission;
+ // Form submission update करण्यासाठी hidden 'id' सेट करा
+ if (prevSubmission.id) {
+ if ($('input[name="id"]').length) {
+ $('input[name="id"]').val(prevSubmission.id);
+ } else {
+ $('#report-form').append('');
+ }
}
- // Loop through hierarcies and fetch contacts for each hierarchy, store in contacts variable
+ // सर्व fields मध्ये जुना डेटा भरा
+ $.each(values, function (fieldKey, val) {
+ if (fieldKey === 'month') return; // महिना परत ओव्हरराईट करू नये
+
+ var field = $('[name="' + fieldKey + '"]');
+ if (!field.length) {
+ field = $('[name="' + fieldKey + '[]"]'); // checkboxes
+ }
+
+ if (field.length) {
+ if (field.is(':checkbox')) {
+ field.prop('checked', false);
+ if (Array.isArray(val)) {
+ val.forEach(function (v) {
+ field.filter('[value="' + v + '"]').prop('checked', true);
+ });
+ }
+ } else if (field.is('select')) {
+ field.val(val);
+
+ // Dropdown ला msl_code / speciality सेट करण्यासाठी change trigger करा
+ field.trigger('change');
+
+ // Select2 UI sync करा
+ if (field.data('select2')) {
+ field.trigger('change.select2');
+ }
+ } else {
+ field.val(val);
+ }
+ }
+ });
+
+ // Unique doctor validation पुन्हा लागू करा
+ if (typeof enforceUniqueDoctorSelections === "function") {
+ enforceUniqueDoctorSelections();
+ }
+
+ $('#submit-btn').text('Update');
+
+ Swal.fire({
+ icon: 'info',
+ title: 'Data Found',
+ text: selectedMonth + ' चा आधीचा डेटा फॉर्ममध्ये भरला गेला आहे.',
+ timer: 2000,
+ showConfirmButton: false
+ });
+
+ } else {
+ // जर या महिन्यासाठी आधी डेटा भरलेला नसेल, तर फॉर्म नवीन submission साठी तयार ठेवा
+ $('input[name="id"]').remove();
+ $('#submit-btn').text('Submit');
+
+ // डॉक्टर ड्रॉपडाउन्स आणि टेक्स्ट बॉक्सेस क्लिअर करा
+ $("[id^='field-contact_id']").each(function () {
+ $(this).val('').trigger('change');
+ if ($(this).data('select2')) {
+ $(this).trigger('change.select2');
+ }
+ });
+ }
+});
+
+
+
+
+ @endif
+
- // $('#field-user_id').change(function(){
- // let hierarchy = $('option:selected', this).attr('hierarchy');
- // $('#field-hierarchy_id').val(hierarchy)
- // event.preventDefault();
- // $("#pageloader").fadeIn();
- // $.ajax({
- // type: "GET",
- // url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy='+hierarchy,
- // processData: false,
- // contentType: false,
- // success: function( data ) {
- // $("#pageloader").fadeOut();
- // for (let i = 1; i <= 10; i++) {
-
- // let contactField = $('#field-contact_id_' + i);
-
- // // Skip if field does not exist
- // if (!contactField.length) continue;
-
- // contactField.html('');
- // contactField.append(
- // $("")
- // .attr("value", '')
- // .text('-- Select --')
- // );
-
- // for (let itm of data) {
- // contactField.append(
- // $("")
- // .attr("value", itm.value)
- // .text(itm.display)
- // .attr("msl_code", itm.contact.msl_code)
- // .attr("speciality", itm.contact.speciality)
-
- // );
- // }
-
-
-
- // // Remove old change events before binding again
-
-
- // contactField.off('change').on('change', function () {
-
- // let selected = $(this).find(':selected');
-
- // $('#field-msl_code_' + i).val(selected.attr('msl_code') || '');
-
- // $('#field-speciality_' + i).val(selected.attr('speciality') || '');
-
- // console.log(selected.text()); // selected doctor name
- // });
-
- // contactField.select2({
- // placeholder: "-- Select --",
- // allowClear: true,
- // width: '100%'
- // });
-
-
-
- // }
-
-
-
-
- // },
- // });
-
- // console.log(hierarchy)
- // })
-
- // for (let i = 1; i <= 10; i++) {
- // $('#field-msl_code_' + i).attr('readonly',true);
- // $('#field-speciality_' + i).attr('readonly',true);
- // }
+
+
+
+
+
$('#report-form').on('submit', function(event){
event.preventDefault();
@@ -485,9 +474,7 @@
var yyyy = today.getFullYear();
today = yyyy + '-' + mm + '-' + dd;
- var plandateField = document.getElementById('field-record_date');
-
- plandateField.setAttribute('max', today);
+
});