forked from mgherghi/inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.php
171 lines (166 loc) · 5.75 KB
/
home.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
<?php
$page_title = 'Home Page';
require_once('includes/load.php');
//if (!$session->isUserLoggedIn(true)) { redirect('index.php', false);}
$products_sold = find_higest_saleing_product('10');
$recent_products = find_recent_product_added('5');
$recent_sales = find_recent_sale_added('5');
$order_id = last_id('checkout');
$new_order_id = $order_id[id] + 1;
?>
<?php
if(isset($_POST['add_order'])){
$req_fields = array( 'line','machine','reason','employee');
validate_fields($req_fields);
$item = remove_junk($db->escape($_POST['item']));
$line = remove_junk($db->escape($_POST['line']));
$machine = remove_junk($db->escape($_POST['machine']));
$reason = remove_junk($db->escape($_POST['reason']));
$employee = remove_junk($db->escape($_POST['employee']));
$q_taken = remove_junk($db->escape($_POST['q_taken']));
$quans = $_POST['quan'];
$gpc_nums = $_POST['gpc_num'];
$current_date = make_date();
if(empty($errors)){
for ($x=0; $x < count($quans); $x++){
$sql = "INSERT INTO checkout (item,line,machine,reason,date,employee,q_taken)";
$sql .= " VALUES ('{$gpc_nums[$x]}','{$line}','{$machine}','{$reason}','{$current_date}','{$employee}','{$quans[$x]}')";
if($db->query($sql))
{
$session->msg("s", "Successfully Signed out item");
$product = find_by_gpcnum("products", $gpc_nums[$x]);
$q_before = $product[quantity];
$q_result = $q_before - $q_taken;
$sql = "UPDATE products SET";
$sql .= " quantity='{$q_result}',date='{$current_date}'";
$sql .= " WHERE id='{$product['id']}'";
$result = $db->query($sql);
if ( $product['id'] == 0 )
{
$session->msg('d',' Sorry failed to added!');
}
$comments = $line;
$comments .= '-';
$comments .= $machine;
$comments .= '-';
$comments .= $reason;
$sql2 = "INSERT INTO stock (product_id,quantity,comments,date)";
$sql2 .= " VALUES ('{$product['id']}','{$quans[$x]}','{$comments}','{$current_date}')";
$result2 = $db->query($sql2);
if( $result2 && $db->affected_rows() === 1)
{
$session->msg('s',"Product added ");
}
} else {
$session->msg("d", "Sorry Failed to insert.");
}
}
redirect( 'add_order.php' , false);
} else {
$session->msg("d", $errors);
}
}
?>
<?php include_once('layouts/header.php'); ?>
<?php echo display_msg($msg); ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function closePanel()
{
var x = document.getElementById("myDIV");
if (x.style.display === "none")
{
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
<script>
$(document).ready(function() {
var max_fields = 20;
var wrapper = $(".container1");
var add_button = $(".add_form_field");
var x = 1;
$(add_button).click(function(e) {
e.preventDefault();
if (x < max_fields) {
x++;
$(wrapper).append('<div><input style="width:60px" type="number" name="quan[]" placeholder="quantity taken"/><input style="width:120px" type="number" name="gpc_num[]" placeholder="GPC item number" id="gpc' + x + '"/><a href="#" class="delete">Delete</a></div>'); //add input box
$("#gpc" + x).focus();
$("#add_field").prop("disabled", true);
setTimeout(function(){
$("#add_field").prop("disabled", false);}, 100);
} else {
alert('You Reached the limit')
}
});
$(wrapper).on("click", ".delete", function(e) {
e.preventDefault();
$(this).parent('div').remove();
x--;
})
});
$(document).keypress(function(e){
if (e.which == 13){
$("#add_field").click();
}
});
</script>
<div class="row" id="myDIV">
<div class="col-md-12">
<div class="panel">
<div class="pull-right">
<a href="#" onclick="closePanel();" class="btn btn-xs btn-danger" data-toggle="tooltip" title="Close"><i class="glyphicon glyphicon-remove"></i></a>
</div>
<div class="jumbotron text-center">
<h3>Welcome!</h3>Contact support for additional assistance.
</div>
</div>
</div>
</div>
<div class="row">
<div class="login-page">
<div class="text-center">
<h2>Check Out Item</h3>
<h3>#<?php echo $new_order_id;?></h3>
<h4 style=color:red>All fields required</h4>
</div>
<form method="post" action="" class="clearfix">
<div class="form-group">
<label for="name" class="control-label">Employee Number</label>
<input type="text" class="form-control" name="employee" placeholder="Employee Number" required>
</div>
<div class="form-group">
<label for="name" class="control-label">Reason</label>
<select class="form-control" name="reason" required>
<option value="">Select Reason</option>
<option value="Down">Down</option>
<option value="PM">PM</option>
<option value="Misc">Misc</option>
</select>
</div>
<div class="form-group">
<label for="name" class="control-label">Line</label>
<input type="text" class="form-control" name="line" placeholder="line" required>
</div>
<div class="form-group">
<label for="name" class="control-label">Machine</label>
<input type="text" class="form-control" name="machine" placeholder="machine" required>
</div>
<div class="form-group">
<div class="container1">
<button class="add_form_field" id="add_field">+</button>
<div><input style="width:60px" type="number" name="quan[]" placeholder="quantity taken" required><input style="width:120px" type="number" name="gpc_num[]" placeholder="GPC item number" required></div>
</div>
</div>
<div class="form-group">
<div class="pull-left">
<button type="submit" name="add_order" class="btn btn-info">submit Item taken</button>
</div>
</div>
</form>
</div>
</div>
<?php include_once('layouts/footer.php'); ?>