/
transaction.php
294 lines (231 loc) · 11 KB
/
transaction.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
session_start();
include 'protected/config/db_config.php';
include 'protected/config/html_config.php';
include 'protected/library/validation_library.php';
include 'protected/controllers/index.php';
include 'protected/models/transaction-items-display.php';
$db = new db_config();
$formelem = new FormElem();
$transactionItemsModel = new TransactionItemsModel();
$connect = $db->connect();
$brand_name = $_SESSION['brand_name'];
if(isset($_POST['btn-finish'])){
$sales_transaction_id = "ST" . rand(0, 100) . date("ymds");
$subtotal = $_POST['subtotal'];
$sales_tax = $_POST['total_sales_tax'];
$total_amount = $_POST['total_amount'];
$amount_given = $_POST['amount_given'];
$change_amount = $_POST['change_amount'];
$transaction_date = date("Y-m-d H:i:s");
$brand_name_item = $_POST['brand_name'];
$item_code = $_POST['item_code'];
$item_description = $_POST['description'];
$price = $_POST['price'];
$sales_tax_amount = $_POST['sales_tax'];
$total_sales_price = $_POST['total'];
$transaction_date = date("Y-m-d H:i:s");
$sales_transaction_report_sql = "INSERT INTO tbl_sales_trans_report (sales_transaction_id, subtotal, sales_tax_total, total_amount, amount_given, change_amount, transaction_date) VALUES ('".$sales_transaction_id."', '".$subtotal."', '".$sales_tax."', '".$total_amount."', '".$amount_given."', '".$change_amount."', '".$transaction_date."')";
$sales_transaction_report_query = mysqli_query($connect, $sales_transaction_report_sql) or die(mysqli_error($connect));
//echo $sales_transaction_report_sql;
for ($i=0; $i<count($brand_name_item); $i++) {
$sales_transaction_item_id = "ST" . rand(0, 1000) . date("ymds");
$sales_transaction_item_sql = "INSERT INTO tbl_sales_trans (sales_transaction_item_id, sales_transaction_id, brand_name, item_code, item_description, transaction_date, price, sales_tax_amount, total_sales_price) VALUES ('".$sales_transaction_item_id."', '".$sales_transaction_id."', '".$brand_name_item[$i]."', '".$item_code[$i]."', '".$item_description[$i]."', '".$transaction_date."', '".$price[$i]."', '".$sales_tax_amount[$i]."', '".$total_sales_price[$i]."')";
$sales_transaction_item_query = mysqli_query($connect, $sales_transaction_item_sql) or die(mysqli_error($connect));
//echo $sales_transaction_item_sql;
}
for ($i=0; $i<count($sales_transaction_id); $i++) {
$count_item_sql = "SELECT sales_transaction_id, item_code, COUNT( * ) AS sold FROM tbl_sales_trans WHERE sales_transaction_id = '".$sales_transaction_id."' GROUP BY item_code";
$count_item_query = mysqli_query($connect, $count_item_sql) or die(mysqli_error($connect));
$data = '';
while ($row = mysqli_fetch_array($count_item_query)) {
//print_r($row);
$sales_transaction_id = $row['sales_transaction_id'];
$item_code = $row['item_code'];
$sold = $row['sold'];
$data .= $sales_transaction_id;
$data .= $item_code;
$data .= $sold;
$sql = "UPDATE tbl_deliveries SET quantity = (quantity - $sold) WHERE item_code = '".$item_code."'";
$query = mysqli_query($connect, $sql) or die(mysqli_error($connect));
}
}
header('location: /transaction.php?transaction_saved=true');
//echo $sales_transaction_report_sql;
//echo $sales_transaction_item_sql;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Transaction</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/main.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- Data Tables -->
<link href="css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!--header-->
<?php include("header.php"); ?>
<!--/header-->
<!-- Page Content -->
<div class="container">
<h1>Transaction</h1>
<hr>
<ol class="breadcrumb">
<li>
<i class="fa fa-home"></i>
<a href="index.php">Home</a>
</li>
<li class="active">
<i class="fa fa-shopping-cart fa-fw"></i>
Transaction
</li>
</ol>
<!-- Page Data Grid -->
<div class="form-group">
<label>Enter Product Code</label>
<input id="item-code" class="form-control auto-width">
<button class="btn btn-success btn-go-add" type="button">Go <i class="fa fa-arrow-right"></i></button>
</div>
<div class="panel panel-yellow">
<div class="panel-heading">
<h3 class="panel-title" style="width:500px">
<i class="fa fa-shopping-cart fa-fw"></i>
Transaction
</h3>
</div>
<div class="panel-body">
<div class="box-body table-responsive">
<table id="transactionTable" class="table table-bordered table-striped">
<tfoot>
<tr>
<th colspan="3" style="text-align:right">Total:</th>
<th class="price-col"></th>
<th class="tax-col"></th>
<th class="total-price-col"></th>
</tr>
</tfoot>
<thead>
<tr>
<th>Brand</th>
<th>Item Code</th>
<th>Details of Product</th>
<th>Price</th>
<th>Sales Tax 3%</th>
<th>Total</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<!-- <tr class="odd"><td class="">brand6</td><td class="">RXSHX</td><td class="">Rockshox Pike</td><td class="">6000.00</td><td class="">135.00</td><td class="">9135.00</td><td class=""><button class="btn btn-primary btn-remove-item" data-dismiss="modal" type="button">Remove</button></td></tr>
<tr class="odd"><td class="">brand6</td><td class="">RXSHX</td><td class="">Rockshox Pike</td><td class="">6000.00</td><td class="">135.00</td><td class="">9135.00</td><td class=""><button class="btn btn-primary btn-remove-item" data-dismiss="modal" type="button">Remove</button></td></tr>
<tr class="odd"><td class="">brand6</td><td class="">RXSHX</td><td class="">Rockshox Pike</td><td class="">6000.00</td><td class="">135.00</td><td class="">9135.00</td><td class=""><button class="btn btn-primary btn-remove-item" data-dismiss="modal" type="button">Remove</button></td></tr> -->
</tbody>
</table>
<div class="row">
<?php echo $formelem->create(array('method'=>'post','class'=>'', 'id'=>'saveSalesTransaction')); ?>
<div class="text-center">
<div class="panel panel-default">
<div class="panel-body" style="width:50%; margin:0 auto;">
<div class="form-group sub-total"><label>Sub Total:</label>
<?php echo $formelem->text(array('id'=>'subtotal','name'=>'subtotal','placeholder'=>'','class'=>'form-control', 'value'=>'')); ?>
</div>
<div class="form-group sales-tax"><label>Sales Tax:</label>
<?php echo $formelem->text(array('id'=>'total_sales_tax','name'=>'total_sales_tax','placeholder'=>'','class'=>'form-control', 'value'=>'')); ?>
</div>
<div class="form-group total-amount"><label>Total:</label>
<?php echo $formelem->text(array('id'=>'total_amount','name'=>'total_amount','placeholder'=>'','class'=>'form-control', 'value'=>'')); ?>
</div>
</div>
</div>
<div class="form-group">
<label>Amount Given</label>
<input id="amount_given" name="amount_given" class="form-control auto-width" minlength="1" required="">
</div>
<div class="form-group">
<label>Change</label>
<input id="change_amount" name="change_amount" class="form-control auto-width left45">
</div>
</div>
<div class="items-row">
<table></table>
</div>
<div class="pull-right">
<?php echo $formelem->button(array('id'=>'btn-finish','name'=>'btn-finish','class'=>'btn btn-primary big', 'value'=>'Finish', 'style'=>'margin-right: 5px')); ?>
<!-- <button id="btnFinish" class="btn btn-primary btn-finish big" data-dismiss="modal" type="button">Finish</button> -->
<button class="btn-print-report btn btn-success big" value="Print">Print</button>
<button class="btn btn-danger big cancel" data-dismiss="modal" type="button">Cancel</button>
</div>
<?php echo $formelem->close(); ?>
</div>
<div id="receipt" style="display:none;">
<div style="text-align:center; font-size:10px;">ZÁRIL lifestyle store</div>
<div style="text-align:center; font-size:8px; border-bottom:1px solid black">
97 Maginhawa st. Teacher's Village, Quezon City<br />
Tel NO.:947-51-55 <br />
TIN NO.:215-514-548-541
</div>
<div class="printableItems" style="font-size:8px; border-bottom:1px solid black; margin: 0 auto; width: 200px;">
<table>
</table>
</div>
<div class="printableTotals" style="font-size:8px; border-bottom:1px solid black">
<table>
<tr>
<td>Sub-total</td>
<td class="r_subtotal">------<span></span></td>
</tr>
<tr>
<td>Total</td>
<td class="r_total">------<span></span></td>
</tr>
</table>
<!-- Sub-total -------- 100.00 <br />
Total -------- 100.00 <br /> -->
</div>
<div style="font-size:8px; text-align:center;">
Thank you. Please come again<br />
Like us on Facebook:<br />
Zaril lifestyle store
</div>
</div>
</div><!-- /.box-body -->
</div>
</div>
<!-- /.row -->
<hr>
<!--footer-->
<?php include("footer.php"); ?>
<!--/footer-->
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<script src="js/jquery.validate.js"></script>
<script src="js/main.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- DATA TABES SCRIPT -->
<script src="js/jquery.dataTables.js" type="text/javascript"></script>
<script src="js/dataTables.bootstrap.js" type="text/javascript"></script>
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/transaction.js" type="text/javascript"></script>
</body>
</html>