118 lines
4.1 KiB
PHP
118 lines
4.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($items));
|
||
|
|
||
|
begin();
|
||
|
for($i=0;$i<count($items);$i++){
|
||
|
$indent_item_id=$items[$i];
|
||
|
$batch=$_POST['batch'.$indent_item_id];
|
||
|
$expiry=$_POST['expiry'.$indent_item_id];
|
||
|
|
||
|
if($status=='DRAFT_DISPATCH'){
|
||
|
$dispatxh_qty =getTableFieldValue('indent_items','dispatch_qty','item_id' ,$indent_item_id , 'indent_id',$indent_id);
|
||
|
}else{
|
||
|
$dispatxh_qty=$_POST['dispatch_qty'.$indent_item_id]+getTableFieldValue('indent_items','dispatch_qty','item_id' ,$indent_item_id , 'indent_id',$indent_id);
|
||
|
}
|
||
|
|
||
|
$in_qty=getTableFieldValue('indent_items','indent_qty','item_id' ,$indent_item_id , 'indent_id',$indent_id);
|
||
|
|
||
|
$curr_item_status=getTableFieldValue('indent_items','status','indent_id',$indent_id,'item_id',$indent_item_id, );
|
||
|
|
||
|
if($curr_item_status!='GRN_APPROVED'){
|
||
|
$new_dispatxh_qty=$_POST['dispatch_qty'.$indent_item_id]+getTableFieldValue('indent_items','new_dispatch_qty','item_id' ,$indent_item_id , 'indent_id',$indent_id); ;
|
||
|
}
|
||
|
else{
|
||
|
$new_dispatxh_qty=$_POST['dispatch_qty'.$indent_item_id];
|
||
|
}
|
||
|
|
||
|
if($in_qty==$dispatxh_qty){
|
||
|
$item_status=$status;
|
||
|
}else{
|
||
|
$item_status='PENDING_DISPATCH';
|
||
|
}
|
||
|
|
||
|
|
||
|
$sql_item="update indent_items set status='".$item_status."',batch='".$batch."',expiry='".$expiry."',dispatch_qty='".$dispatxh_qty."',new_dispatch_qty='".$new_dispatxh_qty."' 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:".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:".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 vendor_id='$contractor_id' and ( status='APPROVED' or status='REJECTED' or status='PENDING_DISPATCH') ";
|
||
|
error_log('approved'.$sql_approved);
|
||
|
if (!$result_approved = @mysqli_query($conn, $sql_approved)) {
|
||
|
error_log ("Exception saving save_app_indent_vendor:".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:".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);
|