-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_sale.php
87 lines (80 loc) · 2.62 KB
/
add_sale.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
<?php
$page_title = 'Add Sale';
require_once('includes/load.php');
// Checkin What level user has permission to view this page
page_require_level(3);
?>
<?php
if(isset($_POST['add_sale'])){
$req_fields = array('s_id','quantity','price','total', 'date' );
validate_fields($req_fields);
if(empty($errors)){
$p_id = $db->escape((int)$_POST['s_id']);
$s_qty = $db->escape((int)$_POST['quantity']);
$s_total = $db->escape($_POST['total']);
$date = $db->escape($_POST['date']);
$s_date = make_date();
$sql = "INSERT INTO sales (";
$sql .= " product_id,qty,price,date";
$sql .= ") VALUES (";
$sql .= "'{$p_id}','{$s_qty}','{$s_total}','{$s_date}'";
$sql .= ")";
if($db->query($sql)){
update_product_qty($s_qty,$p_id);
$session->msg('s',"Sale added. ");
redirect('add_sale.php', false);
} else {
$session->msg('d',' Sorry failed to add!');
redirect('add_sale.php', false);
}
} else {
$session->msg("d", $errors);
redirect('add_sale.php',false);
}
}
?>
<?php include_once('layouts/header.php'); ?>
<div class="row">
<div class="col-md-6">
<?php echo display_msg($msg); ?>
<form method="post" action="ajax.php" autocomplete="off" id="sug-form">
<div class="form-group">
<div class="input-group">
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">Find It</button>
</span>
<input type="text" id="sug_input" class="form-control" name="title" placeholder="Search for product name">
</div>
<div id="result" class="list-group"></div>
</div>
</form>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<strong>
<span class="glyphicon glyphicon-th"></span>
<span>Sale Eidt</span>
</strong>
</div>
<div class="panel-body">
<form method="post" action="add_sale.php">
<table class="table table-bordered">
<thead>
<th> Item </th>
<th> Price </th>
<th> Qty </th>
<th> Total </th>
<th> Date</th>
<th> Action</th>
</thead>
<tbody id="product_info"> </tbody>
</table>
</form>
</div>
</div>
</div>
</div>
<?php include_once('layouts/footer.php'); ?>