2024-10-16 19:18:52 +05:30
< ? php
include ( 'includes/config/config.php' );
include ( 'includes/functions.php' );
error_reporting ( E_ALL & ~ E_NOTICE & ~ E_DEPRECATED & ~ E_WARNING );
include ( 'log_entry.php' );
error_log ( " Start Printing Request Attributes " );
foreach ( $_REQUEST as $key => $value ) {
error_log ( $key . " : " . $value . " \r \n " );
}
error_log ( " End Printing Request Attributes " );
$issue_id = $_POST [ 'issue_log_id' ];
$issue_qty = $_REQUEST [ 'issue_qty' ];
$approval_comments = $_POST [ 'approval_comments' ];
$data = array ();
$query = " " ;
$query_initial = " " ;
$query_end = " " ;
begin ();
if ( ! empty ( $issue_id )) {
$data [ 'message' ] = " update " ;
$query_initial = " update direct_medicine_issue_log " ;
$query_end = " where issue_log_id=' " . $issue_id . " ' " ;
} else {
$query_initial = " insert into direct_medicine_issue_log " ;
$data [ 'message' ] = " save " ;
}
$code = getFieldFromTable ( 'code' , 'medicine_issue_point' , 'point_id' , $_POST [ 'point_id' ]);
$isAutoApprove = getConfigKey ( " AUTO_APPROVE_STORE_RETURN " );
if ( $isAutoApprove == " TRUE " ) {
$approval_status = " A " ;
} else {
$approval_status = $_POST [ 'approval_status' ];
}
error_log ( " key for auto approve store return: " . $isAutoApprove );
$query = " set date_of_issue= STR_TO_DATE(' " . $_POST [ 'issue_date' ] . " ', '%d/%m/%Y %h:%i %p') ,code=' " . $code . " ',issue_point_id=' " . $_POST [ 'point_id' ] . " ',comments = ' " . $_POST [ 'comment' ] . " ',ohc_location_id=' " . $_SESSION [ 'current_ohcttype' ] . " ',approval_status = ' $approval_status ',approval_comments=' $approval_comments ',modified_by=' " . $_SESSION [ 'user_id' ] . " ' " ;
$query = $query_initial . " " . $query . " " . $query_end ;
error_log ( " sndsj " . $query );
if ( ! $result = @ mysqli_query ( $conn , $query )) {
error_log ( " Exception while saving direct_medicine_issue_log: " . mysqli_error ( $conn ));
error_log ( " Failing Query: " . $query );
rollback ();
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
} else {
if ( empty ( $issue_id )) {
$issue_id = @ mysqli_insert_id ( $conn );
}
//if already data exists we need to reset the dispensary stock. So pull existing before update
//add back to the dispensary stock the existing qty
resetDirectMedicineDispensaryItemsStock ( $issue_id , $_SESSION [ 'current_ohcttype' ]);
//then delete the record
if ( !@ mysqli_query ( $conn , " delete from direct_medicine_issue_log_details where issue_log_id=' " . $issue_id . " ' " )) {
error_log ( " No records found for direct issue deletion: " . mysqli_error ( $conn ));
}
for ( $i = 0 ; $i < $_REQUEST [ 'count_items' ]; $i ++ ) {
error_log ( " row count:: " . $_REQUEST [ 'count_items' ]);
if ( isset ( $ { " item_id $i " }) && isset ( $ { " issue_qty $i " }) && $ { " issue_qty $i " } > 0 ) {
$query_issue = " insert into direct_medicine_issue_log_details SET issue_log_id=' " . $issue_id . " ',item_id=' " . addslashes ( $ { " item_id $i " }) . " ',item_batch_no = ' " . $ { " item_batch_no $i " } . " ',issue_qty=' " . $ { " issue_qty $i " } . " ',comments=' " . $ { " comments $i " } . " ' " ;
error_log ( " ssdcdfsj " . $query_issue );
if ( ! $result = @ mysqli_query ( $conn , $query_issue )) {
error_log ( " Error Saving direct_medicine_issue_log_details data: " . mysqli_error ( $conn ) . " Failed Query: " . $query_intake );
rollback ();
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
} else {
error_log ( " Done Saving direct_medicine_issue_log_details data: " . $query_issue );
updateItemStockAtDispensaryLevel ( $_SESSION [ 'current_ohcttype' ], addslashes ( $ { " item_id $i " }), $ { " issue_qty $i " });
}
}
//reduce the new stock qty from the dispensary stock
}
}
commit ();
$data [ 'issue_log_id' ] = $issue_id ;
echo json_encode ( $data );