2024-10-16 19:18:52 +05:30
< ? php
error_reporting ( E_ERROR | E_PARSE );
include ( 'includes/config/config.php' );
include ( 'includes/functions.php' );
include ( 'log_entry.php' );
error_log ( " Start Printing Request Attributes " );
$requestStr = " " ;
foreach ( $_REQUEST as $key => $value ) {
$requestStr .= $key . " : " . $value . " \n " ;
error_log ( $key . " : " . $value . " <br /> \r \n " );
}
error_log ( " End Printing Request Attributes " );
save_log ( $requestStr , 'Manage Item' , 'SAVE' , 'save_item.php' );
$data = array ();
$cat_id = $_POST [ 'cat_id' ];
$medicine_form = $_POST [ 'medicine_form' ];
// $medicine_usage_cat = $_POST['medicine_usage_cat'];
$item_code = $_POST [ 'item_code' ];
$item_name = $_POST [ 'item_name' ];
$item_id = $_POST [ 'item_id' ];
$ailmentSystems = $_POST [ 'ailment_system' ];
$ailmentSystems = implode ( ',' , $ailmentSystems );
$medicine_usage_cat = $_POST [ 'medicine_usage_cat' ];
// $medicine_usage_cat = implode(',', $medicine_usage_cat);
// SUB CLASSIFICATION TO SIDE EFFECTS
$sub_classification = $_POST [ 'sub_classification' ];
$sub_classification = implode ( ',' , $sub_classification );
$composition = $_POST [ 'composition' ];
$composition = implode ( ',' , $composition );
$indication = $_POST [ 'indication' ];
$indication = implode ( ',' , $indication );
$contra_indication = $_POST [ 'contra_indication' ];
$contra_indication = implode ( ',' , $contra_indication );
$side_effect = $_POST [ 'side_effect' ];
$side_effect = implode ( ',' , $side_effect );
//END SUB CLASSIFICATION TO SIDE EFFECTS
$interaction = $_POST [ 'interaction' ];
$item_precaution = $_POST [ 'item_precaution' ];
$item_alternate = $_POST [ 'alternate_medicine' ];
$item_alternate = implode ( ',' , $item_alternate );
$reorder_stock_level = $_POST [ 'reorder_stock_level' ];
$is_prescription = $_POST [ 'is_prescription' ];
$remarks = $_POST [ 'remarks' ];
$status = $_POST [ 'status' ];
$unit_id = $_POST [ 'unit' ];
$salt_ids = $_POST [ 'salt' ];
$salt_ids = implode ( ',' , $salt_ids );
$initial_query = " " ;
$end_query = " " ;
if ( empty ( $item_id ) && ! empty ( $medicine_form ) && ! empty ( $item_name )) {
error_log ( " checking duplicate " );
$row_existing = runSqlGenericSingleRow ( " select item_id from tbl_items where item_name=' $item_name ' and item_form_id=' $medicine_form ' " );
if ( $row_existing != null ) {
error_log ( " checking duplicate success " );
$item_id = $row_existing [ 'item_id' ];
}
}
if ( ! empty ( $item_id )) {
$initial_query = " update tbl_items " ;
$end_query = " where item_id = ' " . $item_id . " ' " ;
} else {
$initial_query = " insert into tbl_items " ;
$end_query = " " ;
}
$query = $initial_query . " set ohc_type_id =' " . $_SESSION [ 'current_ohcttype' ] . " ', cat =' $cat_id ',unit_id=' $unit_id ',item_code=' $item_code ',item_form_id=' $medicine_form ',ailments=' $ailmentSystems ',`sub_classification`=' $sub_classification ',`composition`=' $composition ',`indication`=' $indication ',`contra_indication`=' $contra_indication ',`side_effects`=' $side_effect ',interaction=' $interaction ',item_precaution=' $item_precaution ',item_alternate=' $item_alternate ' ,item_name=' $item_name ', medicine_usage_cat_id=' $medicine_usage_cat ',is_prescription=' $is_prescription ',remarks =' $remarks ',status=' $status ',reorder_store_level=' " . $_POST [ 'reorder_store_level' ] . " ',indent_percent_reorderlevel=' " . $_POST [ 'indent_percent_reorderlevel' ] . " ',reorder_dispensary_level=' " . $_POST [ 'reorder_dispensary_level' ] . " ',min_store_level=' " . $_POST [ 'min_store_level' ] . " ',min_store_level_mis=' " . $_POST [ 'min_store_level_ambulance' ] . " ',reorder_store_level_mis=' " . $_POST [ 'reorder_store_level_ambulance' ] . " ',max_indent_level=' " . $_POST [ 'max_indent_level' ] . " ',min_indent_level=' " . $_POST [ 'min_indent_level' ] . " ',min_dispensary_level=' " . $_POST [ 'min_dispensary_level' ] . " ',modified_by = ' " . $_SESSION [ 'user_id' ] . " ' " . $end_query ;
error_log ( $query . " add item " );
// echo $query;
//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
} else {
$data [ 'status' ] = 200 ;
$data [ " message " ] = " success " ;
}
$salt = $_POST [ 'salt' ];
$item_c = mysqli_insert_id ( $conn );
if ( ! empty ( $item_id )) {
$delete_Salt = " DELETE FROM `item_salt` WHERE item_id =' $item_id ' " ;
$sqlt_delete_result = mysqli_query ( $conn , $delete_Salt );
foreach ( $salt as $salts ) {
$sql_salt = " INSERT INTO item_salt SET `salt_id`=' $salts ' , `item_id`=' $item_id ',modified_by = ' " . $_SESSION [ 'user_id' ] . " ' " ;
$sqlt_result = mysqli_query ( $conn , $sql_salt );
error_log ( $sql_salt . " get salt " );
}
} else {
foreach ( $salt as $salts ) {
$sql_salt = " INSERT INTO item_salt SET `salt_id`=' $salts ' , `item_id`=' $item_c ',modified_by = ' " . $_SESSION [ 'user_id' ] . " ' " ;
$sqlt_result = mysqli_query ( $conn , $sql_salt );
error_log ( $sql_salt . " get salt " );
}
}
/* $query_del = " delete from item_ingredient where item_id = ' " . $item_id . " ' " ;
$result_del = @ mysqli_query ( $conn , $query_del );
$ingredients = explode ( ',' , $ingredients );
//echo $ingredients;
2024-11-02 18:03:13 +05:30
//echo count($ingredients);
for ( $i = 0 ; $i < count ( $ingredients ); $i ++ ){
2024-10-16 19:18:52 +05:30
$query_item_ing = " insert into item_ingredient SET item_id=' " . $item_id . " ',ingredient_id=' " . $ingredients [ $i ] . " ', modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
$result_item_ing = @ mysqli_query ( $conn , $query_item_ing );
} */
/* $query_del = " delete from item_ailment_system where item_id = ' " . $item_id . " ' " ;
$result_del = @ mysqli_query ( $conn , $query_del );
$ailmentSystems = explode ( ',' , $ailmentSystems );
//echo $ingredients;
2024-11-02 18:03:13 +05:30
//echo count($ingredients);
for ( $i = 0 ; $i < count ( $ailmentSystems ); $i ++ ){
2024-10-16 19:18:52 +05:30
$query_item_ing = " insert into item_ailment_system SET item_id=' " . $item_id . " ',ailment_sys_id=' " . $ailmentSystems [ $i ] . " ', modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
$result_item_ing = @ mysqli_query ( $conn , $query_item_ing );
} */