csrtechnew.ohctech.in/save_item.php

104 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2025-04-14 13:28:09 +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'];
2025-10-16 15:19:10 +05:30
$ailmentSystems = $_POST['ailment_system'];
$ailmentSystems = implodeSafe(',', $ailmentSystems);
2025-04-14 13:28:09 +05:30
2025-10-16 15:19:10 +05:30
$activity = $_POST['activity'];
$activity = implodeSafe(',', $activity);
2025-04-14 13:28:09 +05:30
2025-10-16 15:19:10 +05:30
$agency = $_POST['agency'];
$agency = implodeSafe(',', $agency);
2025-04-14 13:28:09 +05:30
$medicine_usage_cat = $_POST['medicine_usage_cat'];
2025-10-16 15:19:10 +05:30
// $medicine_usage_cat = implodeSafe(',', $medicine_usage_cat);
2025-04-14 13:28:09 +05:30
$reorder_stock_level = $_POST['reorder_stock_level'];
$is_prescription = $_POST['is_prescription'];
$remarks = $_POST['remarks'];
$status =$_POST['status'];
$batch_need =$_POST['batch_need'];
$unit_id=$_POST['unit'];
2025-10-16 15:19:10 +05:30
$specifications=$_POST['specifications'];
$make=$_POST['make'];
2025-04-14 13:28:09 +05:30
//echo $item_id;
$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' and ohc_type_id='".$_SESSION['current_ohcttype']."'" );
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="";
}
2025-10-16 15:19:10 +05:30
$query=$initial_query." set cat ='$cat_id',unit_id='$unit_id',item_code='$item_code',specifications='$specifications',make='$make',item_form_id='$medicine_form',ailments='$ailmentSystems',item_name='$item_name', medicine_usage_cat_id='$medicine_usage_cat',is_prescription='$is_prescription',remarks ='$remarks',status='$status',batch_need='$batch_need',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']."',max_indent_level='".$_POST['max_indent_level']."',min_indent_level='".$_POST['min_indent_level']."',min_dispensary_level='".$_POST['min_dispensary_level']."',agency='$agency',activity='$activity',modified_by = '".$_SESSION['user_id']."' ,ohc_type_id='".$_SESSION['current_ohcttype']."',RoleCode='" . $_SESSION['role_type'] . "' ".$end_query;
2025-04-14 13:28:09 +05:30
error_log("query".$query);
//echo $query;
if (!$result = @mysqli_query($conn,$query)) {
rollback();
exit(mysqli_error($conn));
}else{
$data ['status'] = 200;
$data["message"] = "success";
}
/*$query_del = " delete from item_ingredient where item_id = '".$item_id."' ";
$result_del = @mysqli_query($conn,$query_del);
$ingredients=explode(',',$ingredients);
//echo $ingredients;
//echo sizeOf($ingredients);
for($i=0;$i<sizeOf($ingredients);$i++){
$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;
//echo sizeOf($ingredients);
for($i=0;$i<sizeOf($ailmentSystems);$i++){
$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);
}*/
?>