93 lines
4.1 KiB
PHP
93 lines
4.1 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
$indent_id = $_POST['indent_id'];
|
|
$status = $_POST['status'];
|
|
$remarks = $_POST['app_remarks'];
|
|
$app_date = $_POST['approval_date'];
|
|
$rolecode = $_SESSION['RoleCode'];
|
|
|
|
$items = $_POST['delivery_item_count'];
|
|
begin();
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
|
|
$po_id =$_REQUEST['po_id'];
|
|
if ($po_id != '' && $po_id != null) {
|
|
|
|
$initial_query = "update po_master set ";
|
|
$end_query = "where po_id='" . $po_id . "' ";
|
|
} else {
|
|
|
|
$initial_query = "insert into po_master set po_no='" . $_REQUEST['po_no'] . "',generated_by='" . $_SESSION['user_id'] . "', po_date=STR_TO_DATE('" . $_POST['po_date'] . "','%d/%m/%Y'),";
|
|
$end_query = "";
|
|
}
|
|
$app_str='';
|
|
if($status =='APPROVED'){
|
|
$app_str=" ,approver='".$_SESSION['user_id']."',approver_date=STR_TO_DATE('" . $_POST['po_date'] . "','%d/%m/%Y')";
|
|
}
|
|
$final_query = $initial_query . "vendor_id='".$_REQUEST['vendor_id']."',quotation_no='".$_REQUEST['qt_id'] ."',indent_id='".$_REQUEST['indent_id'] ."', status='" . $status . "',remarks='" . $remarks . "' $app_str " . $end_query;
|
|
|
|
error_log("po_master:: " . $final_query);
|
|
if (! $result_query = @mysqli_query($conn, $final_query)) {
|
|
error_log("Error saving indent:" . mysqli_error($conn) . ": Query Failing: " . $final_query);
|
|
rollback();
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
|
|
if ($po_id == '' || $po_id == null) {
|
|
$po_id = getTableFieldValue('po_master', 'max(po_id)', '', '');
|
|
}
|
|
|
|
|
|
for ($i = 0; $i < $items; $i++) {
|
|
|
|
$item_id = $_POST['item_id' . $i];
|
|
$delivery_location = $_POST['delivery_location' . $i];
|
|
$delivery_qty = $_POST['delivery_qty' . $i];
|
|
$delivery_date = $_POST['delivery_date' . $i];
|
|
$remarks= $_POST['remarks' . $i];
|
|
$tolerance=$_POST['tolerance' . $i];
|
|
|
|
$vendor_id = $_REQUEST['vendor_id'];
|
|
|
|
$po_item_id = $_POST['po_item_id' . $i];
|
|
error_log('po_item_id '.$po_item_id);
|
|
if ($po_item_id == '' || $po_item_id == null) {
|
|
|
|
$sql_item = "insert into po_items set status='" . $status . "' ,po_id='" . $po_id . "' , vendor_id='" . $vendor_id . "', item_id='" . $item_id . "' , quotation_no='" . $_REQUEST['qt_id'] . "' ,delivery_location='" . $delivery_location . "',delivery_qty='" . $delivery_qty . "',delivery_date=STR_TO_DATE('" . $delivery_date . "','%d/%m/%Y'),tolerance='".$tolerance."',remarks='".$remarks."' ";
|
|
error_log('po_items' . $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();
|
|
$data['message'] = "insert";
|
|
exit(mysqli_error($conn));
|
|
} else {
|
|
$sql_qt_item = "update quotation_list set scheduled_qty=scheduled_qty+'".$delivery_qty."' where quotation_no='" . $_REQUEST['qt_id'] . "' and item_id= '$item_id' and vendor_id='$vendor_id' ";
|
|
error_log('update quotation_list' . $sql_qt_item);
|
|
if (!$result_qt_item = @mysqli_query($conn, $sql_qt_item)) {
|
|
error_log("Exception saving save_app_indent_vendor_rate:" . mysqli_error($conn) . " failing query:" . $sql_qt_item);
|
|
rollback();
|
|
|
|
exit(mysqli_error($conn));
|
|
}
|
|
}
|
|
}else{
|
|
$sql_item = "update po_items set status='" . $status . "' ,po_id='" . $po_id . "' , vendor_id='" . $vendor_id . "', item_id='" . $item_id . "' , quotation_no='" . $_REQUEST['qt_id'] . "' ,delivery_location='" . $delivery_location . "',delivery_qty='" . $delivery_qty . "',tolerance='".$tolerance."',remarks='".$remarks."' where po_item_id='$po_item_id'";
|
|
error_log('po_items' . $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();
|
|
$data['message'] = "update";
|
|
exit(mysqli_error($conn));
|
|
}
|
|
}
|
|
}
|
|
|
|
commit();
|
|
$data['po_id'] = $po_id;
|
|
|
|
// error_log(print_r($data, true));
|
|
echo json_encode($data);
|