2024-10-16 19:18:52 +05:30
< ? php
include ( 'includes/config/config.php' );
error_reporting ( E_ERROR | E_PARSE );
$appointment_id ;
$data = array ();
$appointment_date = $_POST [ 'appointment_date' ];
$ailments = $_POST [ 'ailment' ];
$ailmentSystems = $_POST [ 'ailment_system' ];
$injuryTypes = $_POST [ 'injury_type' ];
$injuryClasses = $_POST [ 'injury_class' ];
$injuryParts = $_POST [ 'injury_part' ];
$injuryTypes = implode ( ',' , $injuryTypes );
$injuryClasses = implode ( ',' , $injuryClasses );
$injuryParts = implode ( ',' , $injuryParts );
$ailment_ids = implode ( ',' , $ailments );
$ailment_system_ids = implode ( ',' , $ailmentSystems );
$health_advice_names = $_POST [ 'health_advice_name' ];
$health_advice_names = implode ( ',' , $health_advice_names );
$health_risk_names = $_POST [ 'health_risk_name' ];
$health_risk_names = implode ( ',' , $health_risk_names );
$medicine_disbursement = $_POST [ 'medicine_disbursement' ];
$tests = $_POST [ 'recommended_test' ];
$tests = implode ( ',' , $tests );
//echo "shibhamid".$_REQUEST['appointment_id'];
//insert update to main table
if ( ! empty ( $_REQUEST [ 'appointment_id' ])){
$query = " update guest_appointment SET guest_id=' " . addslashes ( $_REQUEST [ 'guest_id' ]) . " ', appointment_type=' " . addslashes ( $_REQUEST [ 'appointment_type' ]) . " ',ailment_ids=' " . $ailment_ids . " ',ailment_system_ids=' " . $ailment_system_ids . " ',IsEmergency= " . addslashes ( $_REQUEST [ 'isEmergency' ]) . " ,complaints=' " . $_REQUEST [ 'complaints' ] . " ',examination_remarks=' " . addslashes ( $_REQUEST [ 'examination_remarks' ]) . " ',bp_sbp =' " . $_REQUEST [ 'sbp' ] . " ',bp_dbp =' " . $_REQUEST [ 'dbp' ] . " ',heart_rate=' " . $_POST [ 'heart_rate' ] . " ',blood_sugar_fbs =' " . $_REQUEST [ 'fbs' ] . " ',blood_sugar_rbs =' " . $_REQUEST [ 'rbs' ] . " ',blood_sugar_ppbs =' " . $_REQUEST [ 'ppbs' ] . " ',referral =' " . $_REQUEST [ 'referral' ] . " ',followup =' " . $_REQUEST [ 'followup' ] . " ',remarks =' " . $_REQUEST [ 'pro_remarks' ] . " ',appointment_date =STR_TO_DATE(' " . $_POST [ 'appointment_date' ] . " ', '%d/%m/%Y %h:%i %p'),injury_time =STR_TO_DATE(' " . $_POST [ 'injury_time' ] . " ', '%d/%m/%Y %h:%i %p'), modified_by=' " . $_SESSION [ 'user_id' ] . " ' ,
injury_types = '".$injuryTypes."' , doctor_attended_flag = '$doctor_attended_flag' , medi_disbursement = '$medicine_disbursement' , ticket_no = '$ticket_no' , total_amount = '".$_POST[' order_level_total ']."' , injury_classes = '".$injuryClasses."' , injury_parts = '".$injuryParts."' , injury_form = '".$_REQUEST[' injury_form ']."' , absence_start = STR_TO_DATE ( '".$_POST[' absence_start ']."' , '%d/%m/%Y' ), absence_end = STR_TO_DATE ( '".$_POST[' absence_end ']."' , '%d/%m/%Y' ), injury_firm = '".$_REQUEST[' injury_firm ']."' , injury_sbu = '".$_REQUEST[' injury_sbu ']."' , injury_section = '".$_REQUEST[' injury_section ']."' , injury_sub_section = '".$_REQUEST[' injury_sub_section ']."' , tests = '".$tests."' , hospital_treatment = '".$_REQUEST[' hospital_treatment ']."' , health_advices = '".$health_advice_names."' where appointment_id = '".$_REQUEST[' appointment_id ']."' " ;
//echo $query;
}
else {
$query = " insert into guest_appointment SET guest_id=' " . addslashes ( $_REQUEST [ 'guest_id' ]) . " ',medi_disbursement=' $medicine_disbursement ',doctor_attended_flag=' $doctor_attended_flag ',ticket_no=' $ticket_no ',appointment_type=' " . addslashes ( $_REQUEST [ 'appointment_type' ]) . " ',ailment_ids=' " . $ailment_ids . " ',ailment_system_ids=' " . $ailment_system_ids . " ',IsEmergency= " . addslashes ( $_REQUEST [ 'isEmergency' ]) . " ,complaints=' " . $_REQUEST [ 'complaints' ] . " ',
examination_remarks = '".addslashes($_REQUEST[' examination_remarks '])."' , bp_sbp = '".$_REQUEST[' sbp ']."' , heart_rate = '".$_POST[' heart_rate ']."' ,
bp_dbp = '".$_REQUEST[' dbp ']."' , blood_sugar_fbs = '".$_REQUEST[' fbs ']."' , blood_sugar_rbs = '".$_REQUEST[' rbs ']."' , blood_sugar_ppbs = '".$_REQUEST[' ppbs ']."' ,
referral = '".$_REQUEST[' referral ']."' , followup = '".$_REQUEST[' followup ']."' , remarks = '$pro_remarks' , appointment_date = STR_TO_DATE ( '".$_POST[' appointment_date ']."' ,
'%d/%m/%Y %h:%i %p' ), injury_time = STR_TO_DATE ( '".$_POST[' injury_time ']."' , '%d/%m/%Y %h:%i %p' ), modified_by = '".$_SESSION[' user_id ']."' , injury_types = '".$injuryTypes."' , injury_classes = '".$injuryClasses."' ,
injury_parts = '".$injuryParts."' , injury_form = '".$_REQUEST[' injury_form ']."' , absence_start = STR_TO_DATE ( '".$_POST[' absence_start ']."' , '%d/%m/%Y' ),
absence_end = STR_TO_DATE ( '".$_POST[' absence_end ']."' , '%d/%m/%Y' ), injury_firm = '".$_REQUEST[' injury_firm ']."' , injury_sbu = '".$_REQUEST[' injury_sbu ']."' , injury_section = '".$_REQUEST[' injury_section ']."' ,
injury_sub_section = '".$_REQUEST[' injury_sub_section ']."' , tests = '".$tests."' , hospital_treatment = '".$_REQUEST[' hospital_treatment ']."' , health_advices = '".$health_advice_names."' , total_amount = '".$_POST[' order_level_total ']."' " ;
//echo $query;
}
//echo "shu".$query;
if ( ! $result = @ mysqli_query ( $conn , $query )) {
//main insert fails
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
} else {
if ( empty ( $_REQUEST [ 'appointment_id' ])){
$query = " select max(appointment_id) appointment_id from guest_appointment where guest_id = ' " . addslashes ( $_REQUEST [ 'guest_id' ]) . " ' " ;
//echo $query;
if ( ! $result = @ mysqli_query ( $conn , $query )) {
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
}
if ( mysqli_num_rows ( $result ) > 0 ) {
while ( $row = mysqli_fetch_assoc ( $result )) {
$data [ 0 ] = $row ;
$appointment_id = $row [ 'appointment_id' ];
}
}
} else {
$data [ 0 ][ 'appointment_id' ] = $_REQUEST [ 'appointment_id' ];
}
/* if ( ! empty ( $_REQUEST [ 'appointment_id' ])){
$appointment_id = $_REQUEST [ 'appointment_id' ];
// echo $appointment_id;
// echo "shubha".$_REQUEST['count_treatment_item'];
for ( $i = 0 ; $i < $_REQUEST [ 'count_treatment_item' ]; $i ++ ){
if ( ! empty ( $_REQUEST [ 'treatment_id' . $appointment_id . $i ])){
$treatment_id = $_REQUEST [ 'treatment_id' . $appointment_id . $i ];
echo " shubham " . $treatment_id ;
$query_treatment = " update treatment SET item_id=' " . addslashes ( $ { " treatment_item $appointment_id $i " }) . " ',item_qty=' " . addslashes ( $ { " treatment_item_total $appointment_id $i " }) . " ',issued_qty=' " . addslashes ( $ { " treatment_item_qtygvn $appointment_id $i " }) . " ',dosage=' " . addslashes ( $ { " dosage $appointment_id $i " }) . " ',for_days=' " . addslashes ( $ { " treatment_item_days $appointment_id $i " }) . " ', frequency_id=' " . $ { " treatment_item_dosage $appointment_id $i " } . " ',price=' " . addslashes ( $ { " treatment_item_total_amount $appointment_id $i " }) . " ', modified_by=' " . $_SESSION [ 'user_id' ] . " ' where treatment_id=' " . $treatment_id . " ' " ;
//echo $query_treatment;
$result_treatment = @ mysqli_query ( $conn , $query_treatment );
} else {
echo " shubham " ;
$query_treatment = " insert into treatment SET appointment_id=' " . $appointment_id . " ', item_id=' " . addslashes ( $ { " treatment_item $appointment_id $i " }) . " ',item_qty=' " . addslashes ( $ { " treatment_item_total $appointment_id $i " }) . " ',issued_qty=' " . addslashes ( $ { " treatment_item_qtygvn $appointment_id $i " }) . " ',dosage=' " . addslashes ( $ { " dosage $appointment_id $i " }) . " ',for_days=' " . addslashes ( $ { " treatment_item_days $appointment_id $i " }) . " ', frequency_id=' " . $ { " treatment_item_dosage $appointment_id $i " } . " ',price=' " . addslashes ( $ { " treatment_item_total_amount $appointment_id $i " }) . " ', modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
$result_treatment = @ mysqli_query ( $conn , $query_treatment );
}
}
}
else { */
$treatment_id_array = array ();
for ( $i = 0 ; $i < $_REQUEST [ 'count_treatment_item' ]; $i ++ ){
//$appointment_id=$_REQUEST['appointment_id'];
if ( $ { " treatment_item $i " }){
//echo $_REQUEST['count_treatment_item'];
// echo "shubham";
$query_treatment = " insert into guest_treatment SET appointment_id=' " . $appointment_id . " ', item_id=' " . addslashes ( $ { " treatment_item $i " }) . " ',item_qty=' " . addslashes ( $ { " treatment_item_total $i " }) . " ',issued_qty=' " . addslashes ( $ { " treatment_item_qtygvn $i " }) . " ',dosage=' " . addslashes ( $ { " dosage $i " }) . " ',for_days=' " . addslashes ( $ { " treatment_item_days $i " }) . " ', frequency_id=' " . $ { " treatment_item_dosage $i " } . " ',price=' " . addslashes ( $ { " treatment_item_total_amount $i " }) . " ', modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
//echo $query_treatment;
$result_treatment = @ mysqli_query ( $conn , $query_treatment );
$treatment_id = @ mysqli_insert_id ();
$treatment_id_array [ $i ] = $treatment_id ;
$data [ 1 ] = $treatment_id_array ;
//echo $treatment_id;
$query_stock_history = " insert into guest_appointment_stock_history set appointment_id=' " . $appointment_id . " ', treatment_id=' " . $treatment_id . " ', current_stock=' " . addslashes ( $ { " current_stock $i " }) . " ', price=' " . addslashes ( $ { " treatment_item_total_amount $i " }) . " ',item_qty=' " . addslashes ( $ { " treatment_item_total $i " }) . " ', item_id=' " . addslashes ( $ { " treatment_item $i " }) . " ',issued_qty=' " . addslashes ( $ { " treatment_item_qtygvn $i " }) . " ' " ;
//echo $query_stock_history;
$result_treatment1 = @ mysqli_query ( $conn , $query_stock_history );
}
}
//echo "shubham".$_REQUEST['count_treatment_item'];
/* foreach ( $_POST as $key => $value ){
echo $key . " : " . $value . " <br /> \r \n " ;
} */
for ( $i = 0 ; $i < $_REQUEST [ 'count_treatment_item' ]; $i ++ ){
//echo "shubham".${"treatment_item$i"};
if ( $ { " treatment_item $i " }){
$issued_qty = addslashes ( $ { " treatment_item_qtygvn $i " });
$stock_level_qty = addslashes ( $ { " current_stock $i " });
//echo "shubham".$stock_level_qty;
$item_id = addslashes ( $ { " treatment_item $i " });
//echo "shubham".$item_id;
if ( ! empty ( $_REQUEST [ 'treatment_id' . $i ])){
//echo "shubham";
// echo "shubham".$_REQUEST['treatment_id'.$i];
$treatment_id = $_REQUEST [ 'treatment_id' . $i ];
$query_stock_history = " select issued_qty from guest_appointment_stock_history where treatment_id=' " . $treatment_id . " ' " ;
//echo $query_stock_history;
$result_stock_history = @ mysqli_query ( $conn , $query_stock_history );
while ( $row_stock_history = mysqli_fetch_assoc ( $result_stock_history )) {
$old_qty = $row_stock_history [ 'issued_qty' ];
}
// echo "old_qty=".$old_qty;
$final_qty = $old_qty - $issued_qty ;
// echo "final_qty=".$final_qty;
$current_stock_qty = $stock_level_qty + $final_qty ;
$query_stock = " update tbl_items SET current_stock_level=' " . $current_stock_qty . " ' where item_id=' " . $item_id . " ' " ;
$result_stock = @ mysqli_query ( $conn , $query_stock );
// echo $query_stock;
$query_del = " delete from guest_treatment where treatment_id = ' " . $treatment_id . " ' " ;
//echo $query_del;
$result_del = @ mysqli_query ( $conn , $query_del );
$query_stock_history_delete = " delete from guest_appointment_stock_history where treatment_id=' " . $treatment_id . " ' " ;
//echo $query_stock_history_delete;
@ mysqli_query ( $conn , $query_stock_history_delete );
} else {
//echo "shubhamelse";
$current_stock_qty = $stock_level_qty - $issued_qty ;
$query_stock = " update tbl_items SET current_stock_level=' " . $current_stock_qty . " ' where item_id=' " . $item_id . " ' " ;
//echo $query_stock;
$result_stock = @ mysqli_query ( $conn , $query_stock );
}
}
}
//}//
}
echo json_encode ( $data );
?>