forked from hewagekasunthilina/Pharmacy-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cashier_process.php
176 lines (130 loc) · 6.2 KB
/
Cashier_process.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
session_start();
$id = 0;
$update = false;
$ItemID = '';
$ItemName ='';
$ItemQuantity ='';
$Total ='';
$new ='';
$mysqli = new mysqli('localhost', 'root', '', 'nimedco') or die(mysqli_error($mysqli));
if (isset($_POST['new'])){
$mysqli->query("INSERT INTO cashierinvoice(subTotal, discount, netTotal) VALUES(0,0,0)") or die($mysqli->error);
header("location: CashierInvoice.php");
}
if(isset($_POST['save'])){
$ItemID = $_POST['ItemID'];
$ItemQuantity = $_POST['ItemQuantity'];
$id = $_POST['id'];
$pQty = $mysqli->query("SELECT * FROM stockitem WHERE ItemID='$ItemID'") or die($mysqli->error);
$row = $pQty->fetch_array();
$new = $row['ItemQuantity'] - $ItemQuantity;
$total= $row['Price'] * $ItemQuantity;
if($row['ItemQuantity'] == 0){
$_SESSION['message'] = "Sorry Item is out of stock!";
$_SESSION['msg_type'] = "danger";
}
else if($row['ItemQuantity'] >= $ItemQuantity){
$mysqli->query("INSERT INTO cashierinvoiceitem(invoiceID, ItemID, ItemQuantity, Total) VALUES('$id','$ItemID', '$ItemQuantity', '$total')") or die($mysqli->error);
$mysqli->query("UPDATE stockitem SET ItemQuantity='$new' WHERE ItemID='$ItemID'") or die($mysqli->error);
$intot = $mysqli->query("SELECT subTotal FROM cashierinvoice WHERE id='$id'") or die($mysqli->error);
$tot = $intot->fetch_array();
$subtot=$tot['subTotal'];
$nsubtot=$subtot+$total;
$mysqli->query("UPDATE cashierinvoice SET subTotal='$nsubtot', netTotal='$nsubtot' WHERE id='$id'") or die($mysqli->error);
$_SESSION['message'] = "Item has been added!";
$_SESSION['msg_type'] = "success";
} else{
$_SESSION['message'] = "Sorry ".$row['ItemID']." only ".$row['ItemQuantity']." Items available in stock!";
$_SESSION['msg_type'] = "warning";
}
header("location: CashierInvoice.php");
}
if (isset($_GET['delete'])){
$id = $_GET['delete'];
$ItemID = $_GET['ItemID'];
$ItemQuantity = $_GET['ItemQuantity'];
$intot = $mysqli->query("SELECT * FROM cashierinvoiceitem WHERE invoiceID='$id' and ItemID='$ItemID' and ItemQuantity='$ItemQuantity'") or die($mysqli->error);
$tot = $intot->fetch_array();
$toti=$tot['Total'];
$iQt=$tot['ItemQuantity'];
$mysqli->query("DELETE FROM cashierinvoiceitem WHERE invoiceID='$id' and ItemID='$ItemID' and ItemQuantity='$ItemQuantity'") or die($mysql->error());
$pQty = $mysqli->query("SELECT * FROM stockitem WHERE ItemID='$ItemID'") or die($mysqli->error);
$row = $pQty->fetch_array();
$new = $row['ItemQuantity'] + $iQt;
//var_dump($new);
// die();
$mysqli->query("UPDATE stockitem SET ItemQuantity='$new' WHERE ItemID='$ItemID'") or die($mysqli->error);
$intot = $mysqli->query("SELECT * FROM cashierinvoice WHERE id='$id'") or die($mysqli->error);
$tot = $intot->fetch_array();
$subtot=$tot['subTotal'];
$nsubtot=$subtot-$toti;
$mysqli->query("UPDATE cashierinvoice SET subTotal='$nsubtot', netTotal='$nsubtot' WHERE id='$id'") or die($mysqli->error);
$_SESSION['message'] = "Record has been deleted!";
$_SESSION['msg_type'] = "danger";
header("location: CashierInvoice.php");
}
if (isset($_GET['edit'])){
$id = $_GET['edit'];
$ItemID = $_GET['ItemID'];
$update = true;
$resultin = $mysqli->query("SELECT * FROM cashierinvoiceitem WHERE invoiceID='$id' and ItemID='$ItemID'") or die($mysqli->error());
$rowin = $resultin->fetch_array();
$inID = $rowin['invoiceID'];
$ItemID = $rowin['ItemID'];
$ItemQuantity = $rowin['ItemQuantity'];
$Total = $rowin['Total'];
}
if(isset($_POST['update'])){
$ItemID = $_POST['ItemID'];
$ItemQuantity = $_POST['ItemQuantity'];
$id = $_POST['id'];
$itemValue = $mysqli->query("SELECT * FROM stockitem WHERE ItemID='$ItemID'") or die($mysqli->error);
$row = $itemValue->fetch_array();
$invoiceItemV = $mysqli->query("SELECT * FROM cashierinvoiceitem WHERE ItemID='$ItemID' and invoiceID='$id'") or die($mysqli->error);
$row1 = $invoiceItemV->fetch_array();
$firstitemV = $row1['ItemQuantity'];
$invoice = $mysqli->query("SELECT * FROM cashierinvoice WHERE id='$id'") or die($mysqli->error);
$in = $invoice->fetch_array();
$firsttot = $in['subTotal'];
$nowitem = $row['ItemQuantity'] + $firstitemV;
$lastitem = $nowitem - $ItemQuantity;
$ptot = $row1['Total'];
$ntot = $row['Price'] * $ItemQuantity;
$nsubtot = $firsttot - $ptot + $ntot;
if($nowitem >= $ItemQuantity){
$mysqli->query("UPDATE cashierinvoiceitem SET ItemQuantity='$ItemQuantity', Total='$ntot' WHERE invoiceID='$id' and ItemID='$ItemID'") or die($mysqli->error);
$mysqli->query("UPDATE stockitem SET ItemQuantity='$lastitem' WHERE ItemID='$ItemID'") or die($mysqli->error);
$mysqli->query("UPDATE cashierinvoice SET subTotal='$nsubtot', netTotal='$nsubtot' WHERE id='$id'") or die($mysqli->error);
$_SESSION['message'] = "Record has been updateed!";
$_SESSION['msg_type'] = "warning";
}
else{
$_SESSION['message'] = "Sorry ".$row['ItemID']." only ".$nowitem." Items available in stock!";
$_SESSION['msg_type'] = "warning";
}
header('location: CashierInvoice.php');
}
if (isset($_POST['discount'])){
//var_dump(12333);
$DiscountAm = $_POST['rate'];
$id = $_POST['id'];
$intot = $mysqli->query("SELECT * FROM cashierinvoice WHERE id='$id'") or die($mysqli->error);
$tot = $intot->fetch_array();
$subtot=$tot['subTotal'];
$mysqli->query("UPDATE cashierinvoice SET netTotal='$subtot' WHERE id='$id'") or die($mysqli->error);
$NnetTotal = $subtot - (($subtot*$DiscountAm)/100);
$mysqli->query("UPDATE cashierinvoice SET netTotal='$NnetTotal', discount='$DiscountAm' WHERE id='$id'") or die($mysqli->error);
header("location: CashierInvoice.php");
}
if(isset($_POST['Cash'])){
$Amount = $_POST['Amt'];
$id = $_POST['id'];
$intot = $mysqli->query("SELECT * FROM cashierinvoice WHERE id='$id'") or die($mysqli->error);
$tot = $intot->fetch_array();
$nettot=$tot['netTotal'];
$new = $Amount - $nettot;
$mysqli->query("UPDATE cashierinvoice SET CashAmt='$Amount',ChangeAmt='$new' WHERE id='$id'") or die($mysqli->error);
header("location: CashierInvoice.php");
}
?>