-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_sale.php
108 lines (101 loc) · 3.69 KB
/
edit_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
$page_title = 'Edit sale';
require_once('includes/load.php');
// Checkin What level user has permission to view this page
page_require_level(3);
?>
<?php
$sale = find_by_id('sales',(int)$_GET['id']);
if(!$sale){
$session->msg("d","Missing product id.");
redirect('sales.php');
}
?>
<?php $product = find_by_id('products',$sale['product_id']); ?>
<?php
if(isset($_POST['update_sale'])){
$req_fields = array('title','quantity','price','total', 'date' );
validate_fields($req_fields);
if(empty($errors)){
$p_id = $db->escape((int)$product['id']);
$s_qty = $db->escape((int)$_POST['quantity']);
$s_total = $db->escape($_POST['total']);
$date = $db->escape($_POST['date']);
$s_date = date("Y-m-d", strtotime($date));
$sql = "UPDATE sales SET";
$sql .= " product_id= '{$p_id}',qty={$s_qty},price='{$s_total}',date='{$s_date}'";
$sql .= " WHERE id ='{$sale['id']}'";
$result = $db->query($sql);
if( $result && $db->affected_rows() === 1){
update_product_qty($s_qty,$p_id);
$session->msg('s',"Sale updated.");
redirect('edit_sale.php?id='.$sale['id'], false);
} else {
$session->msg('d',' Sorry failed to updated!');
redirect('sales.php', false);
}
} else {
$session->msg("d", $errors);
redirect('edit_sale.php?id='.(int)$sale['id'],false);
}
}
?>
<?php include_once('layouts/header.php'); ?>
<div class="row">
<div class="col-md-6">
<?php echo display_msg($msg); ?>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel">
<div class="panel-heading clearfix">
<strong>
<span class="glyphicon glyphicon-th"></span>
<span>All Sales</span>
</strong>
<div class="pull-right">
<a href="sales.php" class="btn btn-primary">Show all sales</a>
</div>
</div>
<div class="panel-body">
<table class="table table-bordered">
<thead>
<th> Product title </th>
<th> Qty </th>
<th> Price </th>
<th> Total </th>
<th> Date</th>
<th> Action</th>
</thead>
<tbody id="product_info">
<tr>
<form method="post" action="edit_sale.php?id=<?php echo (int)$sale['id']; ?>">
<td id="s_name">
<input type="text" class="form-control" id="sug_input" name="title" value="<?php echo remove_junk($product['name']); ?>">
<div id="result" class="list-group"></div>
</td>
<td id="s_qty">
<input type="text" class="form-control" name="quantity" value="<?php echo (int)$sale['qty']; ?>">
</td>
<td id="s_price">
<input type="text" class="form-control" name="price" value="<?php echo remove_junk($product['sale_price']); ?>" >
</td>
<td>
<input type="text" class="form-control" name="total" value="<?php echo remove_junk($sale['price']); ?>">
</td>
<td id="s_date">
<input type="date" class="form-control datepicker" name="date" data-date-format="" value="<?php echo remove_junk($sale['date']); ?>">
</td>
<td>
<button type="submit" name="update_sale" class="btn btn-primary">Update sale</button>
</td>
</form>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php include_once('layouts/footer.php'); ?>