-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathedit_stock.php
130 lines (114 loc) · 3.68 KB
/
edit_stock.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
<?php
$page_title = 'Edit category';
require_once('includes/load.php');
// Checkin What level user has permission to view this page
page_require_level(1);
?>
<?php
//Display all catgories.
$stock = find_by_id('stock',(int)$_GET['id']);
$product = find_by_id('products',(int)$stock['product_id']);
if(!$stock){
$session->msg("d","Missing order id.");
redirect('stock.php');
}
?>
<?php
if(isset($_POST['edit_stock'])){
$req_field = array('product_id','quantity');
validate_fields($req_field);
$product_id = remove_junk($db->escape($_POST['product_id']));
$quantity = remove_junk($db->escape($_POST['quantity']));
// check if the quantity has changed
$s_qty_diff = 0;
if ( $quantity != $stock['quantity'] )
{
// there has been an increase in quantity
if ( $quantity > $stock['quantity'] )
{
// difference between previous quantity and new value
$s_qty_diff = $quantity - $stock['quantity'];
$decrease_quantity_flag = false;
}
// there has been a decrease in quantity
else if ( $quantity < $stock['quantity'] )
{
// difference between previous quantity and new value
$s_qty_diff = $stock['quantity'] - $quantity;
$decrease_quantity_flag = true;
}
}
$comments = remove_junk($db->escape($_POST['comments']));
$date = remove_junk($db->escape($_POST['date']));
$current_date = make_date();
if(empty($errors))
{
$sql = "UPDATE stock SET";
$sql .= " product_id='{$product_id}', quantity='{$quantity}', comments='{$comments}', date='{$current_date}'";
$sql .= " WHERE id='{$stock['id']}'";
$result = $db->query($sql);
if($result && $db->affected_rows() === 1)
{
if ( $s_qty_diff > 0 )
{
if ( $decrease_quantity_flag )
{
decrease_product_qty($s_qty_diff,$product_id);
} else {
increase_product_qty($s_qty_diff,$product_id);
}
}
$session->msg("s", "Successfully updated");
redirect('stock.php',false);
} else {
$session->msg("d", "Sorry! Failed");
redirect('edit_stock.php',false);
}
} else {
$session->msg("d", $errors);
redirect('edit_stock.php',false);
}
}
?>
<?php include_once('layouts/header.php'); ?>
<div class="row">
<div class="col-md-12">
<?php echo display_msg($msg); ?>
</div>
<div class="col-md-5">
<div class="panel panel-default">
<div class="panel-heading">
<strong>
<span class="glyphicon glyphicon-th"></span>
<span>Editing <?php echo remove_junk(ucfirst($stock['product_id']));?></span>
</strong>
</div>
<div class="panel-body">
<form method="post" action="">
<div class="form-group">
<label for="name" class="control-label"><?php echo $product['name'];?></label>
<input type="hidden" class="form-control" name="product_id" value="<?php echo $stock['product_id'] ;?>">
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-shopping-cart"></i>
</span>
<input type="number" class="form-control" name="quantity" value="<?php echo $stock['quantity'] ;?>" placeholder="Product Quantity">
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="comments" value="<?php echo remove_junk(ucfirst($stock['comments']));?>" placeholder="Notes">
</div>
<button type="submit" name="edit_stock" class="btn btn-primary">Update Inventory</button>
</form>
</div>
</div>
<?php
print "<pre>";
print_r($stock);
print "</pre>\n";
?>
</div>
</div>
<?php include_once('layouts/footer.php'); ?>