-
Notifications
You must be signed in to change notification settings - Fork 47
/
delete.php
74 lines (67 loc) · 2.87 KB
/
delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
include_once "init.php";
// Use session variable on this page. This function must put on the top of page.
if(!isset($_SESSION['username']) || $_SESSION['usertype'] !='admin'){ // if session variable "username" does not exist.
header("location:index.php?msg=Please%20login%20to%20access%20admin%20area%20!"); // Re-direct to index.php
}
else
{
error_reporting (E_ALL ^ E_NOTICE);
if(isset($_GET['id']) && isset($_GET['table']))
{
$id=$_GET['id'];
$tablename=$_GET['table'];
$return=$_GET['return'];
if($tablename=="stock_entries")
{
$difference=$db->queryUniqueValue("SELECT quantity FROM stock_entries WHERE id=$id");
$name=$db->queryUniqueValue("SELECT stock_name FROM stock_entries WHERE id=$id");
$result=$db->query("SELECT * FROM stock_entries where id > $id");
while ($line2 = $db->fetchNextObject($result)) {
$osd=$line2->opening_stock - $difference;
$csd=$line2->closing_stock - $difference;
$cid=$line2->id;
$db->execute("UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
}
$total = $db->queryUniqueValue("SELECT quantity FROM stock_avail WHERE name='$name'");
$total = $total - $difference;
$db->execute("UPDATE stock_avail SET quantity=$total WHERE name='$name'");
}
if($tablename=="stock_sales")
{ $difference=$db->queryUniqueValue("SELECT quantity FROM stock_sales WHERE id=$id");
$sid=$db->queryUniqueValue("SELECT transactionid FROM stock_sales WHERE id=$id");
$id=$db->queryUniqueValue("SELECT id FROM stock_entries WHERE salesid='$sid'");
$name=$db->queryUniqueValue("SELECT stock_name FROM stock_entries WHERE id=$id");
$result=$db->query("SELECT * FROM stock_entries where id > $id");
while ($line2 = $db->fetchNextObject($result)) {
$osd=$line2->opening_stock + $difference;
$csd=$line2->closing_stock + $difference;
$cid=$line2->id;
$db->execute("UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
}
echo "sale $name";
$total = $db->queryUniqueValue("SELECT quantity FROM stock_avail WHERE name='$name'");
$total = $total + $difference;
$db->execute("UPDATE stock_avail SET quantity=$total WHERE name='$name'");
$db->execute("DELETE FROM $tablename WHERE id=$id");
}
$id=$_GET['id'];
$db->execute("DELETE FROM $tablename WHERE id=$id");
header("location:$return?msg=Record Deleted Successfully!&id=$id");
}
if(isset($_POST['table']) && isset($_POST['checklist']))
{
$data=$_REQUEST['checklist'];
$tablename=$_POST['table'];
$return =$_REQUEST['return'];
for($i=0;$i<count($data);$i++){
$db->execute("DELETE FROM $tablename WHERE id=$data[$i]");
}
header("location:$return?msg=Record Deleted Successfully!");
}
echo $_POST['return'];
if(isset($_POST['return'])){
header("location:$return");
}
}
?>