Skip to content

Commit

Permalink
storing data in audit table & ON DELETION also storing delete date an…
Browse files Browse the repository at this point in the history
…d email of user who deleted row
  • Loading branch information
kamranzafar4343 committed Nov 5, 2024
1 parent af86a2e commit 993f4d5
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 21 deletions.
17 changes: 15 additions & 2 deletions createAccessWO.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,27 @@
die("workorder already created against that barcode");
} else {
$sql = "INSERT INTO orders ( creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$creator', 'Access', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_code', '$barcodes', '$alt_codes', '$requestor_names', '$designations', '$req_dates', '$descriptions')";
VALUES ( '$creator', 'Access', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
}

if ($conn->query($sql) === TRUE) {

// Get the last inserted order_no from the orders table
$last_id = $conn->insert_id;

echo $sqlAudit = "INSERT INTO orders_audit (order_no, creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$last_id','$creator', 'Access', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
exit();
}

if ($conn->query($sqlAudit) === TRUE) {
header("Location: access.php");
exit();
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
echo "Error: " . $sqlAudit . "<br>" . $conn->error;
exit();
}
}

Expand Down
22 changes: 12 additions & 10 deletions createDeliveryWO.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,27 @@
die("workorder already created against that barcode");
} else {
$sql = "INSERT INTO orders ( creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$creator', 'Delivery', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_code', '$barcodes', '$alt_codes', '$requestor_names', '$designations', '$req_dates', '$descriptions')";
VALUES ( '$creator', 'Delivery', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
}

if($conn->query($sql) === TRUE){
$sqlAudit = "INSERT INTO orders_audit ( creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$creator', 'Delivery', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_code', '$barcodes', '$alt_codes', '$requestor_names', '$designations', '$req_dates', '$descriptions')";
}
else{
if ($conn->query($sql) === TRUE) {

// Get the last inserted order_no from the orders table
$last_id = $conn->insert_id;

echo $sqlAudit = "INSERT INTO orders_audit (order_no, creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$last_id', '$creator', 'Delivery', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
exit();
}

if ($conn->query($sqlAudit) === TRUE) {
header("Location: order.php");
exit();
} else {
echo "Error: " . $sqlAudit . "<br>" . $conn->error;
exit();
}
}

Expand Down Expand Up @@ -536,7 +541,7 @@
<div class="container d-flex justify-content-center">
<div class="card custom-card shadow-lg mt-3">
<div class="card-body mt-3">
<form class="row g-3 needs-validation" action="" method="POST">
<form class="row g-3 needs-validation" id="orderForm" action="" method="POST">

<hr style="color: white;">

Expand Down Expand Up @@ -842,9 +847,6 @@ function updateBarcodeInput() {
});
</script>




<script src="assets/js/main.js"></script>

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
Expand Down
18 changes: 15 additions & 3 deletions createDestroyWO.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,30 @@
die("workorder already created against that barcode");
} else {
$sql = "INSERT INTO orders ( creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$creator', 'Destroy', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_code', '$barcodes', '$alt_codes', '$requestor_names', '$designations', '$req_dates', '$descriptions')";
VALUES ( '$creator', 'Destroy', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
}

if ($conn->query($sql) === TRUE) {

// Get the last inserted order_no from the orders table
$last_id = $conn->insert_id;

echo $sqlAudit = "INSERT INTO orders_audit (order_no, creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$last_id','$creator', 'Destroy', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
exit();
}

if ($conn->query($sqlAudit) === TRUE) {
header("Location: destroy.php");
exit();
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
echo "Error: " . $sqlAudit . "<br>" . $conn->error;
exit();
}
}


?>


Expand Down
17 changes: 15 additions & 2 deletions createPermoutWO.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,27 @@
die("workorder already created against that barcode");
} else {
$sql = "INSERT INTO orders ( creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$creator', 'Permout', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_code', '$barcodes', '$alt_codes', '$requestor_names', '$designations', '$req_dates', '$descriptions')";
VALUES ( '$creator', 'Permout', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
}

if ($conn->query($sql) === TRUE) {

// Get the last inserted order_no from the orders table
$last_id = $conn->insert_id;

echo $sqlAudit = "INSERT INTO orders_audit (order_no, creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$last_id','$creator', 'Permout', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
exit();
}

if ($conn->query($sqlAudit) === TRUE) {
header("Location: permout.php");
exit();
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
echo "Error: " . $sqlAudit . "<br>" . $conn->error;
exit();
}
}

Expand Down
17 changes: 15 additions & 2 deletions createPickupWO.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,27 @@
die("workorder already created against that barcode");
} else {
$sql = "INSERT INTO orders ( creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$creator', 'Pickup', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_code', '$barcodes', '$alt_codes', '$requestor_names', '$designations', '$req_dates', '$descriptions')";
VALUES ( '$creator', 'Pickup', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
}

if ($conn->query($sql) === TRUE) {

// Get the last inserted order_no from the orders table
$last_id = $conn->insert_id;

echo $sqlAudit = "INSERT INTO orders_audit (order_no, creator, flag, comp_id_fk, branch_id_fk, dept_id_fk, priority, date, foc, foc_phone, pickup_address, object_code, barcode, alt, requestor, role, req_date, description)
VALUES ( '$last_id','$creator', 'Pickup', '$comp', '$branch', '$dept', '$priority', '$date', '$foc', '$foc_phone', '$pickup_address', '$object_codes', '$barcodes', '$alt_codes', '$requestor_names', '$designation', '$request_dates', '$descriptions')";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
exit();
}

if ($conn->query($sqlAudit) === TRUE) {
header("Location: pickup.php");
exit();
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
echo "Error: " . $sqlAudit . "<br>" . $conn->error;
exit();
}
}

Expand Down
7 changes: 5 additions & 2 deletions deleteOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
// Now, perform the delete operation
$delete_sql = "DELETE FROM `orders` WHERE `order_no` = $order_id";

if($conn->query($delete_sql) === TRUE) {
//insert delete time into order audit table
if ($conn->query($delete_sql) === TRUE) {
$updateDelTime = "UPDATE `orders_audit` SET `deleted_at` = NOW(), `deleted_by` = '".$_SESSION['email']."' WHERE `order_no` = $order_id";
}
if ($conn->query($updateDelTime) === TRUE) {
// Redirect to the referring page
if (isset($_SERVER['HTTP_REFERER'])) {
header("Location: " . $_SERVER['HTTP_REFERER']);
Expand All @@ -27,7 +31,6 @@
}
exit();
}

} else {
echo "Error: No company found for this branch.";
}
Expand Down

0 comments on commit 993f4d5

Please sign in to comment.