-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
125 lines (112 loc) · 4.95 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
require_once 'includes/initialize.php';
$id = filter_input(INPUT_GET, "id", FILTER_DEFAULT);
$type = filter_input(INPUT_GET, "type", FILTER_DEFAULT);
switch ($type) {
case "user":
$user = User::find_by_id(base64_decode($id));
if($user && $user->delete()){
$session->message("User info removed successfully.");
}else {
$session->message("An error occured.");
}
redirect_to("settings-users.php");
break;
case "stock":
$stock = Stock::find_by_id(base64_decode($id));
if($stock && $stock->delete()){
$session->message("Stock info removed successfully.");
}else {
$session->message("An error occured.");
}
redirect_to("settings-stock.php");
break;
case "package":
$package = Package::find_by_id(base64_decode($id));
if($package && $package->delete()){
$session->message("Package removed successfully.");
}else {
$session->message("An error occured.");
}
redirect_to("settings-packages.php");
break;
case "category":
$category = Category::find_by_id(base64_decode($id));
if($category && $category->delete()){
$session->message("Category removed successfully.");
}else {
$session->message("An error occured.");
}
redirect_to("settings-categories.php");
break;
case "sale":
$stockhh = Stockhistory::find_by_id(base64_decode($id));
if($stockhh && $stockhh->delete()){
$stockk = Stock::find_by_id($stockhh->stock);
$stockh = new Stockhistory();
$stockh->stock = $stockk->id;
$stockh->type = "add";
$stockh->prev = $stockk->qty;
$stockh->qty = $stockhh->qty;
$stockh->new = $stockk->qty + $stockhh->qty;
$stockh->remarks = "Deleted Sale";
$stockh->created = strftime("%Y-%m-%d %H:%M:%S", time());
$stockh->createdby = $session->id;
$stockk->qty = $stockh->new;
$stockh->save();
$stockk->save();
$session->message("Sale removed successfully.");
}else {
$session->message("An error occured.");
}
redirect_to("sales-add.php");
break;
case "subscription":
$sub = Subscription::find_by_id(base64_decode($id));
if($sub && $sub->delete()){
//remove customer information
$customer = Customer::find_by_id($sub->customer);
$customer->delete();
//delete and reverse stock inputs
$stockhs = Stockhistory::find_for_subscription($sub->id);
if($stockhs && $stockhs->delete()){
foreach ($stockhs as $stockhh):
if($stockhh{
//update stock data
$stockk = Stock::find_by_id($stockhh->stock);
$stockh = new Stockhistory();
$stockh->stock = $stockk->id;
$stockh->type = "add";
$stockh->prev = $stockk->qty;
$stockh->qty = $stockhh->qty;
$stockh->new = $stockk->qty + $stockhh->qty;
$stockh->remarks = "Deleted Subscription";
$stockh->created = strftime("%Y-%m-%d %H:%M:%S", time());
$stockh->createdby = $session->id;
$stockk->qty = $stockh->new;
$stockh->save();
$stockk->save();
}
endforeach;
}
//delete payment record
$payment = Payment::find_by_sub($sub->id);
$payment->delete();
$session->message("Subscription removed successfully.");
}else {
$session->message("An error occured.");
}
redirect_to("subscriptions-add.php");
break;
case "payment":
$payment = Payment::find_by_id(base64_decode($id));
if($payment && $payment->delete()){
$session->message("Payment record removed successfully.");
}else {
$session->message("An error occured.");
}
redirect_to("subscriptions-details.php?id=". base64_encode($payment->sub));
break;
default:
break;
}