Zenova(Sitazit & Glipiq Tracker)
This commit is contained in:
parent
77145718ab
commit
d5ddb7debe
|
|
@ -241,105 +241,144 @@
|
||||||
$('#field-msl_code').val($('option:selected', this).attr('msl_code'))
|
$('#field-msl_code').val($('option:selected', this).attr('msl_code'))
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
$('#field-contact_id').change(function() {
|
||||||
$('#field-sankalp_lead_received_penvial').val($('option:selected', this).attr('lead_recieved'))
|
$('#field-sankalp_lead_received_penvial').val($('option:selected', this).attr('lead_recieved'))
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
$('#field-contact_id').change(function() {
|
||||||
$('#field-sankalp_lead_enrolled_penvial').val($('option:selected', this).attr('lead_enrolled'))
|
$('#field-sankalp_lead_enrolled_penvial').val($('option:selected', this).attr('lead_enrolled'))
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
$('#field-contact_id').change(function() {
|
||||||
$('#field-pmos_dr').val($('option:selected', this).attr('pmos_dr'))
|
$('#field-pmos_dr').val($('option:selected', this).attr('pmos_dr'))
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
$('#field-contact_id').change(function() {
|
||||||
$('#field-qbs_dr').val($('option:selected', this).attr('qbs_dr'))
|
$('#field-qbs_dr').val($('option:selected', this).attr('qbs_dr'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
$('#field-contact_id').change(function() {
|
||||||
$('#field-adboard_dr').val($('option:selected', this).attr('adboard_dr'))
|
$('#field-adboard_dr').val($('option:selected', this).attr('adboard_dr'))
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
$('#field-contact_id').change(function() {
|
||||||
$('#field-fb_live_dr').val($('option:selected', this).attr('fb_live_dr'))
|
$('#field-fb_live_dr').val($('option:selected', this).attr('fb_live_dr'))
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
$('#field-contact_id').change(function() {
|
||||||
$('#field-ecme_dr').val($('option:selected', this).attr('ecme_dr'))
|
$('#field-ecme_dr').val($('option:selected', this).attr('ecme_dr'))
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
$('#field-contact_id').change(function() {
|
||||||
$('#field-rtm_dr').val($('option:selected', this).attr('rtm_dr'))
|
$('#field-rtm_dr').val($('option:selected', this).attr('rtm_dr'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('#field-msl_code,#field-speciality').attr('readonly',true);
|
$('#field-msl_code,#field-speciality').attr('readonly',true);
|
||||||
|
|
||||||
/* $('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units,#field-sankalp_lead_received_penvial,#field-pmos_dr,#field-qbs_dr,#field-adboard_dr,#field-fb_live_dr,#field-ecme_dr,#field-rtm_dr,#field-sankalp_lead_enrolled_penvial').parent().hide();
|
|
||||||
$('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units,#field-sankalp_lead_received_penvial,#field-pmos_dr,#field-qbs_dr,#field-adboard_dr,#field-fb_live_dr,#field-ecme_dr,#field-rtm_dr,#field-sankalp_lead_enrolled_penvial').prop({"required":false});
|
const glipiFields = [
|
||||||
$('#field-rx_count,#field-pob_units,#field-brand_sku').parent().hide();
|
'#field-pen_rx_count','#field-vial_rx_count','#field-pen_pob_units',
|
||||||
$('#field-rx_count,#field-pob_units,#field-brand_sku').prop({"required":false});
|
'#field-vial_pob_units','#field-sankalp_lead_received_penvial',
|
||||||
|
'#field-pmos_dr','#field-qbs_dr','#field-adboard_dr',
|
||||||
|
'#field-fb_live_dr','#field-ecme_dr','#field-rtm_dr',
|
||||||
|
'#field-sankalp_lead_enrolled_penvial','#field-upload_glipiq_rxn'
|
||||||
|
].join(',');
|
||||||
|
|
||||||
$('#field-select_brand').on('change',function(){
|
const sitazitFields = [
|
||||||
let dropDown=$('#field-select_brand').val();
|
'#field-rx_count','#field-pob_units','#field-brand_sku', '#field-upload_sitazit_rxn'
|
||||||
if(dropDown==='GlipiQ'){
|
].join(',');
|
||||||
$('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units,#field-sankalp_lead_received_penvial,#field-pmos_dr,#field-qbs_dr,#field-adboard_dr,#field-fb_live_dr,#field-ecme_dr,#field-rtm_dr,#field-sankalp_lead_enrolled_penvial').parent().show();
|
|
||||||
$('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units,#field-sankalp_lead_received_penvial,#field-pmos_dr,#field-qbs_dr,#field-adboard_dr,#field-fb_live_dr,#field-ecme_dr,#field-rtm_dr,#field-sankalp_lead_enrolled_penvial').prop({"required":true});
|
function toggleFields(selector, show) {
|
||||||
$('#field-rx_count,#field-pob_units,#field-brand_sku').parent().hide();
|
$(selector).parent().toggle(show);
|
||||||
$('#field-rx_count,#field-pob_units,#field-brand_sku').prop({"required":false});
|
$(selector).prop('required', show);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial hide
|
||||||
|
toggleFields(glipiFields, false);
|
||||||
|
toggleFields(sitazitFields, false);
|
||||||
|
|
||||||
|
$('#field-select_brand').on('change', function () {
|
||||||
|
const brand = $(this).val();
|
||||||
|
console.log("Brand is :",brand);
|
||||||
|
toggleFields(glipiFields, brand === 'Glipiq');
|
||||||
|
toggleFields(sitazitFields, brand === 'Sitazit');
|
||||||
|
|
||||||
|
if(brand==='Glipiq'){
|
||||||
|
$('#report-form').append('<input type="hidden" name="glipiq_rx_total">');
|
||||||
|
$('#report-form').append('<input type="hidden" name="glipiq_pob_total">');
|
||||||
|
$('#report-form').append('<input type="hidden" name="glipiq_new_conversion">');
|
||||||
|
$('#report-form').append('<input type="hidden" name="glipiq_existing_conversion">');
|
||||||
|
|
||||||
|
$('#field-conversion_status').on('change',function(){
|
||||||
|
let value=$(this).val();
|
||||||
|
if(value==='New Conversion'){
|
||||||
|
$('#report-form input[name="glipiq_new_conversion"]').val(1);
|
||||||
|
}
|
||||||
|
else if(value==='Existing Prescriber'){
|
||||||
|
$('#report-form input[name="glipiq_existing_conversion"]').val(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(dropDown==='Sitazit'){
|
else if(brand==='Sitazit'){
|
||||||
$('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units,#field-sankalp_lead_received_penvial,#field-pmos_dr,#field-qbs_dr,#field-adboard_dr,#field-fb_live_dr,#field-ecme_dr,#field-rtm_dr,#field-sankalp_lead_enrolled_penvial').parent().hide();
|
$('#report-form').append('<input type="hidden" name="sitazit_new_conversion">');
|
||||||
$('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units,#field-sankalp_lead_received_penvial,#field-pmos_dr,#field-qbs_dr,#field-adboard_dr,#field-fb_live_dr,#field-ecme_dr,#field-rtm_dr,#field-sankalp_lead_enrolled_penvial').prop({"required":false});
|
$('#report-form').append('<input type="hidden" name="sitazit_existing_conversion">');
|
||||||
$('#field-rx_count,#field-pob_units,#field-brand_sku').parent().show();
|
|
||||||
$('#field-rx_count,#field-pob_units,#field-brand_sku').prop({"required":true});
|
$('#field-conversion_status').on('change',function(){
|
||||||
}else{
|
let value=$(this).val();
|
||||||
$('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units,#field-sankalp_lead_received_penvial,#field-pmos_dr,#field-qbs_dr,#field-adboard_dr,#field-fb_live_dr,#field-ecme_dr,#field-rtm_dr,#field-sankalp_lead_enrolled_penvial').parent().hide();
|
if(value==='New Conversion'){
|
||||||
$('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units,#field-sankalp_lead_received_penvial,#field-pmos_dr,#field-qbs_dr,#field-adboard_dr,#field-fb_live_dr,#field-ecme_dr,#field-rtm_dr,#field-sankalp_lead_enrolled_penvial').prop({"required":false});
|
$('#report-form input[name="sitazit_new_conversion"]').val(1);
|
||||||
$('#field-rx_count,#field-pob_units,#field-brand_sku').parent().hide();
|
}
|
||||||
$('#field-rx_count,#field-pob_units,#field-brand_sku').prop({"required":false});
|
else if(value==='Existing Prescriber'){
|
||||||
|
$('#report-form input[name="sitazit_existing_conversion"]').val(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$('#report-form input[name="glipiq_new_conversion"]').val(0);
|
||||||
|
$('#report-form input[name="glipiq_existing_conversion"]').val(0);
|
||||||
|
$('#report-form input[name="sitazit_new_conversion"]').val(0);
|
||||||
|
$('#report-form input[name="sitazit_existing_conversion"]').val(0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}) */
|
|
||||||
|
|
||||||
const glipiFields = [
|
|
||||||
'#field-pen_rx_count','#field-vial_rx_count','#field-pen_pob_units',
|
|
||||||
'#field-vial_pob_units','#field-sankalp_lead_received_penvial',
|
|
||||||
'#field-pmos_dr','#field-qbs_dr','#field-adboard_dr',
|
|
||||||
'#field-fb_live_dr','#field-ecme_dr','#field-rtm_dr',
|
|
||||||
'#field-sankalp_lead_enrolled_penvial','#field-upload_glipiq_rxn'
|
|
||||||
].join(',');
|
|
||||||
|
|
||||||
const sitazitFields = [
|
|
||||||
'#field-rx_count','#field-pob_units','#field-brand_sku', '#field-upload_sitazit_rxn'
|
|
||||||
].join(',');
|
|
||||||
|
|
||||||
function toggleFields(selector, show) {
|
|
||||||
$(selector).parent().toggle(show);
|
|
||||||
$(selector).prop('required', show);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initial hide
|
|
||||||
toggleFields(glipiFields, false);
|
|
||||||
toggleFields(sitazitFields, false);
|
|
||||||
|
|
||||||
$('#field-select_brand').on('change', function () {
|
|
||||||
const brand = $(this).val();
|
|
||||||
|
|
||||||
toggleFields(glipiFields, brand === 'Glipiq');
|
|
||||||
toggleFields(sitazitFields, brand === 'Sitazit');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// $('#field-contact_id').append('<option value="others">Others</option>');
|
$('#field-pen_rx_count,#field-vial_rx_count,#field-pen_pob_units,#field-vial_pob_units').on('change',function(){
|
||||||
|
let pen_rx=parseInt($('#field-pen_rx_count').val())||0;
|
||||||
|
let viral_rx=parseInt($('#field-vial_rx_count').val())||0;
|
||||||
|
let pen_pob=parseInt($('#field-pen_pob_units').val())||0;
|
||||||
|
let viral_pob=parseInt($('#field-vial_pob_units').val())||0;
|
||||||
|
|
||||||
|
console.log("pen & viral :",pen_rx,viral_rx);
|
||||||
|
console.log("pen & viral :",pen_pob,viral_pob);
|
||||||
|
|
||||||
|
let total_rx=pen_rx+viral_rx;
|
||||||
|
let total_pob=pen_pob+viral_pob;
|
||||||
|
|
||||||
|
$('#report-form input[name="glipiq_rx_total"]').val(total_rx);
|
||||||
|
|
||||||
|
$('#report-form input[name="glipiq_pob_total"]').val(total_pob);
|
||||||
|
|
||||||
|
console.log("Total RX :", total_rx);
|
||||||
|
console.log("Total POB :", total_pob);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('#field-file_upload, #field-upload_sitazit_rxn, #field-upload_glipiq_rxn').on('change', function () {
|
$('#field-file_upload, #field-upload_sitazit_rxn, #field-upload_glipiq_rxn').on('change', function () {
|
||||||
|
|
@ -382,338 +421,226 @@ $('#field-select_brand').on('change', function () {
|
||||||
{sku_code:'sitazit_d', brand:'SITAZIT', sku:'Sitazit D', material_code:'421112413'},
|
{sku_code:'sitazit_d', brand:'SITAZIT', sku:'Sitazit D', material_code:'421112413'},
|
||||||
{sku_code:'sitazit_m', brand:'SITAZIT', sku:'Sitazit M', material_code:'421112413'},
|
{sku_code:'sitazit_m', brand:'SITAZIT', sku:'Sitazit M', material_code:'421112413'},
|
||||||
{sku_code:'sitazit_trio', brand:'SITAZIT', sku:'Sitazit Trio', material_code:'421112413'},
|
{sku_code:'sitazit_trio', brand:'SITAZIT', sku:'Sitazit Trio', material_code:'421112413'},
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#field-select_brand').trigger('change');
|
$('#field-select_brand').trigger('change');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*$('#field-sankalp_lead_received_penvial').on('change', function () {
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
// Pehle existing hidden input hata do
|
|
||||||
$('input[name="sankalp_recieved"]').remove();
|
|
||||||
|
|
||||||
// Sirf Yes pe value bhejo
|
|
||||||
if (value === 'Yes') {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="sankalp_recieved" value="1">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#field-sankalp_lead_enrolled_penvial').on('change', function () {
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
// Pehle existing hidden input hata do
|
|
||||||
$('input[name="sankalp_enrolled"]').remove();
|
|
||||||
|
|
||||||
// Sirf Yes pe value bhejo
|
|
||||||
if (value === 'Yes') {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="sankalp_enrolled" value="1">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$('#field-pmos_dr').on('change', function () {
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
// Pehle existing hidden input hata do
|
|
||||||
$('input[name="pmos_dr"]').remove();
|
|
||||||
|
|
||||||
// Sirf Yes pe value bhejo
|
|
||||||
if (value === 'Yes') {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="pmos_dr" value="1">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#field-qbs_dr').on('change', function () {
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
// Pehle existing hidden input hata do
|
|
||||||
$('input[name="qbs_dr"]').remove();
|
|
||||||
|
|
||||||
// Sirf Yes pe value bhejo
|
|
||||||
if (value === 'Yes') {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="qbs_dr" value="1">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#field-adboard_dr').on('change', function () {
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
// Pehle existing hidden input hata do
|
|
||||||
$('input[name="adboard_dr"]').remove();
|
|
||||||
|
|
||||||
// Sirf Yes pe value bhejo
|
|
||||||
if (value === 'Yes') {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="adboard_dr" value="1">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#field-fb_live_dr').on('change', function () {
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
// Pehle existing hidden input hata do
|
|
||||||
$('input[name="fb_live_dr"]').remove();
|
|
||||||
|
|
||||||
// Sirf Yes pe value bhejo
|
|
||||||
if (value === 'Yes') {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="fb_live_dr" value="1">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#field-ecme_dr').on('change', function () {
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
// Pehle existing hidden input hata do
|
|
||||||
$('input[name="ecme_dr"]').remove();
|
|
||||||
|
|
||||||
// Sirf Yes pe value bhejo
|
|
||||||
if (value === 'Yes') {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="ecme_dr" value="1">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$('#field-rtm_dr').on('change', function () {
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
// Pehle existing hidden input hata do
|
|
||||||
$('input[name="rtm_dr"]').remove();
|
|
||||||
|
|
||||||
// Sirf Yes pe value bhejo
|
|
||||||
if (value === 'Yes') {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="rtm_dr" value="1">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// FETCH PREVIOUS SUBMISSION FOR SELECTED DOCTOR
|
// FETCH PREVIOUS SUBMISSION FOR SELECTED DOCTOR
|
||||||
// ONLY FOR THIS FORM
|
// ONLY FOR THIS FORM
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
const targetFormId = '1788239728-6f7f3c27-c5dc-4e6e-a042-aefd5681af3a';
|
const targetFormId = '1788239728-6f7f3c27-c5dc-4e6e-a042-aefd5681af3a';
|
||||||
|
|
||||||
$('#field-contact_id').on('change.previousData', function () {
|
$('#field-contact_id').on('change.previousData', function () {
|
||||||
|
|
||||||
const currentFormId = $('input[name="form_id"]').val();
|
const currentFormId = $('input[name="form_id"]').val();
|
||||||
|
|
||||||
// Run only for this form
|
// Run only for this form
|
||||||
if (currentFormId !== targetFormId) {
|
if (currentFormId !== targetFormId) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const doctorId = $(this).val();
|
|
||||||
|
|
||||||
if (!doctorId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const userId = $('#field-user_id').val();
|
|
||||||
const partition = '{{ $form->partition }}';
|
|
||||||
|
|
||||||
if (!userId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#pageloader").fadeIn();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "/form/getformfielddata",
|
|
||||||
|
|
||||||
data: {
|
|
||||||
_token: $('input[name="_token"]').val(),
|
|
||||||
form_id: targetFormId,
|
|
||||||
user_id: userId,
|
|
||||||
partition: partition,
|
|
||||||
|
|
||||||
// We are NOT looking for a particular date.
|
|
||||||
// We want all previous submissions.
|
|
||||||
record_date: ''
|
|
||||||
},
|
|
||||||
|
|
||||||
success: function (response) {
|
|
||||||
|
|
||||||
$("#pageloader").fadeOut();
|
|
||||||
|
|
||||||
if (
|
|
||||||
!response.submissions ||
|
|
||||||
!Array.isArray(response.submissions)
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
const doctorId = $(this).val();
|
||||||
// FIND PREVIOUS SUBMISSIONS FOR THIS DOCTOR
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
const doctorSubmissions = response.submissions.filter(function (submission) {
|
if (!doctorId) {
|
||||||
|
|
||||||
if (!submission.formdata) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return String(submission.formdata.contact_id || '') === String(doctorId);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (doctorSubmissions.length === 0) {
|
|
||||||
|
|
||||||
// No previous data for this doctor
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
const userId = $('#field-user_id').val();
|
||||||
// GET LATEST SUBMISSION
|
const partition = '{{ $form->partition }}';
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
doctorSubmissions.sort(function (a, b) {
|
if (!userId) {
|
||||||
|
return;
|
||||||
const dateA = new Date(
|
|
||||||
a.updatedAt || a.createdAt || 0
|
|
||||||
);
|
|
||||||
|
|
||||||
const dateB = new Date(
|
|
||||||
b.updatedAt || b.createdAt || 0
|
|
||||||
);
|
|
||||||
|
|
||||||
return dateB - dateA;
|
|
||||||
});
|
|
||||||
|
|
||||||
const previousData = doctorSubmissions[0].formdata;
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// AUTO POPULATE ALL PREVIOUS FIELDS
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
Object.keys(previousData).forEach(function (fieldCode) {
|
|
||||||
|
|
||||||
const field = $('#field-' + fieldCode);
|
|
||||||
|
|
||||||
if (!field.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't change the selected doctor
|
|
||||||
if (fieldCode === 'contact_id') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't populate file inputs
|
|
||||||
if (field.attr('type') === 'file') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const value = previousData[fieldCode];
|
|
||||||
|
|
||||||
if (value === null || value === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
field.val(value);
|
|
||||||
|
|
||||||
// Important for dropdowns such as Select Brand
|
|
||||||
field.trigger('change');
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
error: function (xhr) {
|
|
||||||
|
|
||||||
$("#pageloader").fadeOut();
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
"Failed to fetch previous submission:",
|
|
||||||
xhr.responseText
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#report-form').on('submit', function(event){
|
|
||||||
event.preventDefault();
|
|
||||||
const formData = new FormData($('#report-form')[0]);
|
|
||||||
// Log form data to console
|
|
||||||
for (let [key, value] of formData.entries()) {
|
|
||||||
console.log(key, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#pageloader").fadeIn();
|
$("#pageloader").fadeIn();
|
||||||
|
|
||||||
if ($('#field-select_brand').val() === 'Sitazit') {
|
|
||||||
|
|
||||||
$('#report-form').append(
|
$.ajax({
|
||||||
'<input type="hidden" name="' + $('#field-brand_sku').val() + '_rx_count" value="' + $('#field-rx_count').val() + '">'
|
type: "POST",
|
||||||
);
|
url: "/form/getformfielddata",
|
||||||
|
|
||||||
$('#report-form').append(
|
data: {
|
||||||
'<input type="hidden" name="' + $('#field-brand_sku').val() + '_pob_units" value="' + $('#field-pob_units').val() + '">'
|
_token: $('input[name="_token"]').val(),
|
||||||
);
|
form_id: targetFormId,
|
||||||
|
user_id: userId,
|
||||||
|
partition: partition,
|
||||||
|
|
||||||
let sku_brand_map = sku_brand_maps.find(
|
// We are NOT looking for a particular date.
|
||||||
sb => sb.sku_code === $('#field-brand_sku').val()
|
// We want all previous submissions.
|
||||||
);
|
record_date: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (response) {
|
||||||
|
|
||||||
|
$("#pageloader").fadeOut();
|
||||||
|
|
||||||
|
if (
|
||||||
|
!response.submissions ||
|
||||||
|
!Array.isArray(response.submissions)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// FIND PREVIOUS SUBMISSIONS FOR THIS DOCTOR
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
const doctorSubmissions = response.submissions.filter(function (submission) {
|
||||||
|
|
||||||
|
if (!submission.formdata) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(submission.formdata.contact_id || '') === String(doctorId);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (doctorSubmissions.length === 0) {
|
||||||
|
|
||||||
|
// No previous data for this doctor
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// GET LATEST SUBMISSION
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
doctorSubmissions.sort(function (a, b) {
|
||||||
|
|
||||||
|
const dateA = new Date(
|
||||||
|
a.updatedAt || a.createdAt || 0
|
||||||
|
);
|
||||||
|
|
||||||
|
const dateB = new Date(
|
||||||
|
b.updatedAt || b.createdAt || 0
|
||||||
|
);
|
||||||
|
|
||||||
|
return dateB - dateA;
|
||||||
|
});
|
||||||
|
|
||||||
|
const previousData = doctorSubmissions[0].formdata;
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// AUTO POPULATE ALL PREVIOUS FIELDS
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
Object.keys(previousData).forEach(function (fieldCode) {
|
||||||
|
|
||||||
|
const field = $('#field-' + fieldCode);
|
||||||
|
|
||||||
|
if (!field.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't change the selected doctor
|
||||||
|
if (fieldCode === 'contact_id') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't populate file inputs
|
||||||
|
if (field.attr('type') === 'file') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = previousData[fieldCode];
|
||||||
|
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
field.val(value);
|
||||||
|
|
||||||
|
// Important for dropdowns such as Select Brand
|
||||||
|
field.trigger('change');
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr) {
|
||||||
|
|
||||||
|
$("#pageloader").fadeOut();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"Failed to fetch previous submission:",
|
||||||
|
xhr.responseText
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (sku_brand_map) {
|
|
||||||
$('#report-form').append(
|
|
||||||
'<input type="hidden" name="sku_name" value="' + sku_brand_map.sku + '">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: '/form/ajaxsubmit',
|
|
||||||
data: new FormData($('#report-form')[0]),
|
|
||||||
processData: false,
|
|
||||||
contentType: false,
|
|
||||||
success: function( data ) {
|
|
||||||
$("#pageloader").fadeOut();
|
|
||||||
if(data.status == 'success') {
|
|
||||||
Swal.fire({
|
|
||||||
title: 'Great!',
|
|
||||||
text: 'Your data is successfully submitted!',
|
|
||||||
icon: 'success'
|
|
||||||
}).then(() => {
|
|
||||||
location.reload(); // 🔥 page refresh here
|
|
||||||
});
|
|
||||||
$('#report-form').trigger("reset");
|
|
||||||
} else {
|
|
||||||
Swal.fire({
|
|
||||||
icon: 'error',
|
|
||||||
title: 'Data not submitted',
|
|
||||||
text: 'Something went wrong, please try again after some time!'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#report-form').on('submit', function(event){
|
||||||
|
event.preventDefault();
|
||||||
|
const formData = new FormData($('#report-form')[0]);
|
||||||
|
// Log form data to console
|
||||||
|
for (let [key, value] of formData.entries()) {
|
||||||
|
console.log(key, value);
|
||||||
|
}
|
||||||
|
$("#pageloader").fadeIn();
|
||||||
|
|
||||||
|
if ($('#field-select_brand').val() === 'Sitazit') {
|
||||||
|
|
||||||
|
$('#report-form').append(
|
||||||
|
'<input type="hidden" name="' + $('#field-brand_sku').val() + '_rx_count" value="' + $('#field-rx_count').val() + '">'
|
||||||
|
);
|
||||||
|
|
||||||
|
$('#report-form').append(
|
||||||
|
'<input type="hidden" name="' + $('#field-brand_sku').val() + '_pob_units" value="' + $('#field-pob_units').val() + '">'
|
||||||
|
);
|
||||||
|
|
||||||
|
let sku_brand_map = sku_brand_maps.find(
|
||||||
|
sb => sb.sku_code === $('#field-brand_sku').val()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (sku_brand_map) {
|
||||||
|
$('#report-form').append(
|
||||||
|
'<input type="hidden" name="sku_name" value="' + sku_brand_map.sku + '">'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: '/form/ajaxsubmit',
|
||||||
|
data: new FormData($('#report-form')[0]),
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
success: function( data ) {
|
||||||
|
$("#pageloader").fadeOut();
|
||||||
|
if(data.status == 'success') {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Great!',
|
||||||
|
text: 'Your data is successfully submitted!',
|
||||||
|
icon: 'success'
|
||||||
|
}).then(() => {
|
||||||
|
location.reload(); // 🔥 page refresh here
|
||||||
|
});
|
||||||
|
$('#report-form').trigger("reset");
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Data not submitted',
|
||||||
|
text: 'Something went wrong, please try again after some time!'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var today = new Date();
|
||||||
|
var dd = String(today.getDate()).padStart(2, '0');
|
||||||
|
var mm = String(today.getMonth() + 1).padStart(2, '0');
|
||||||
|
var yyyy = today.getFullYear();
|
||||||
|
today = yyyy + '-' + mm + '-' + dd;
|
||||||
|
|
||||||
|
var plandateField = document.getElementById('field-record_date');
|
||||||
|
|
||||||
|
plandateField.setAttribute('max', today);
|
||||||
});
|
});
|
||||||
|
|
||||||
var today = new Date();
|
|
||||||
var dd = String(today.getDate()).padStart(2, '0');
|
|
||||||
var mm = String(today.getMonth() + 1).padStart(2, '0');
|
|
||||||
var yyyy = today.getFullYear();
|
|
||||||
today = yyyy + '-' + mm + '-' + dd;
|
|
||||||
|
|
||||||
var plandateField = document.getElementById('field-record_date');
|
|
||||||
|
|
||||||
plandateField.setAttribute('max', today);
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue