ESH/save_app_indent_vendor_rate.php
2024-10-23 18:28:06 +05:30

84 lines
3.1 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
$indent_id = $_POST['indent_id'];
$status = $_POST['ven_status'];
$remarks = $_POST['app_remarks'];
$app_date = $_POST['approval_date'];
$rolecode = $_SESSION['RoleCode'];
$item_list = $_POST['item_list'];
$items=explode(",", $item_list);
error_log('itemlist'.count($item_list));
begin();
for($i=0;$i<count($items);$i++){
$indent_item_id=$items[$i];
$vendor_rate = $_POST['vendor_rate_'.$indent_item_id];
$sql_item="update indent_items set status='".$status."' , vendor_rate='".$vendor_rate."' , mrp='".$_POST['mrp'.$indent_item_id]."' , gst='".$_POST['gst'.$indent_item_id]."' , discount='".$_POST['discount'.$indent_item_id]."' , unit='".$_POST['unit'.$indent_item_id]."' where item_id='".$indent_item_id."' and indent_id='".$indent_id."' ";
error_log($sql_item);
if (!$result_item = @mysqli_query($conn, $sql_item)) {
error_log ("Exception saving save_app_indent_vendor_rate:".mysqli_error($conn)." failing query:".$sql_item);
rollback();
exit(mysqli_error($conn));
}
}
//update remarks
$sql_remarks = "update indent_master set remarks='".$remarks."' where indent_id='" . $indent_id . "'";
error_log("sql_remarks " . $sql_remarks);
if (!$result = @mysqli_query($conn, $sql_remarks)) {
error_log ("Exception saving save_app_indent_vendor_rate:".mysqli_error($conn)." failing query:".$sql_remarks);
rollback();
exit(mysqli_error($conn));
}
$user_id=$_SESSION['user_id'];
error_log('xxxxxxxxx'.$user_id);
$contractor_id=getTableFieldValue('tbl_users','vendor_id','user_id',$user_id);
$approved=0;
$sql_approved="select count(*) as items from indent_items where indent_id='".$indent_id."' and (status='') ";
error_log('approved'.$sql_approved);
if (!$result_approved = @mysqli_query($conn, $sql_approved)) {
error_log ("Exception saving save_app_indent_vendor_rate:".mysqli_error($conn)." failing query:".$sql_approved);
rollback();
exit(mysqli_error($conn));
}
$row_approved = mysqli_fetch_array($result_approved);
$unapproved=$row_approved['items'];
if($unapproved==0){
$sql = "update indent_master set status='" . $status . "',remarks='".$remarks."' where indent_id='" . $indent_id . "'";
error_log("sql " . $sql);
if (!$result = @mysqli_query($conn, $sql)) {
error_log ("Exception saving save_app_indent_vendor_rate:".mysqli_error($conn)." failing query:".$sql);
rollback();
exit(mysqli_error($conn));
} else {
$data = "success";
}
}
// if ($rolecode == 'DOC') {
// $sql = "update indent_master set status='" . $status . "',approval_date2=STR_TO_DATE('" . $app_date . "','%d/%m/%Y'),approving_doc_id2='" . $_SESSION['user_id'] . "',approval_remarks2='" . $remarks . "' where indent_id='" . $indent_id . "'";
// } else {
// $sql = "update indent_master set status='" . $status . "' where indent_id='" . $indent_id . "'";
// }
// error_log("sql " . $sql);
// if (!$result = @mysqli_query($conn, $sql)) {
// exit(mysqli_error($conn));
// } else {
// $data = "success";
// }
commit();
echo json_encode($data);