-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_sale.php
203 lines (183 loc) · 7.78 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
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
<?php
$page_title = 'Procesar Venta';
require_once('include/load.php');
// Checkin What level user has permission to view this page
page_require_level(3);
//$all_categories = find_all('categories');
//$all_photos = find_all('media');
?>
<?php
if (isset($_POST['add_sale'])) {
/* at least one, partNo, or productName is required */
if ( !validate_fields( array('partNo') ) && !validate_fields( array('product_name') ) ) {
$session->msg("d", $errors);
redirect(SITE_URL.'add_sale.php', false);
}
$req_fields = array( 'quantity','sale_price','total_sale','date' );
//if(empty($errors)){
if( validate_fields($req_fields) ){
if ( isset( $_POST['partNo'] ) && $_POST['partNo'] ) {
$product = find_product_by_partNo( $_POST['partNo'] );
if ( !$product || !sizeof($product) ) {
$session->msg("d", sprintf("No se encontró partNo='%s'", $_POST['partNo'] ) );
redirect(SITE_URL.'add_sale.php', false);
}
}
$p_id = $product['id'];
$s_qty = $db->escape((int)$_POST['quantity']);
$b_price = $product['buy_price'];
$s_price = $db->escape($_POST['sale_price']);
$s_total = $db->escape($_POST['total_sale']);
$s_profit = $s_total - $s_qty * $b_price;
if (isset( $_POST['destination'] ))
$s_dest = $db->escape($_POST['destination']);
else
$s_dest = "";
$date = $db->escape( $_POST['date'] );
$s_date = date( 'Y-m-d', strtotime( $date ) );
$sql = "INSERT INTO sales (";
$sql .= " product_id,qty,buy_price,sale_price,total_sale,profit,destination,date";
$sql .= ") VALUES (";
$sql .= "'${p_id}','${s_qty}','${b_price}','${s_price}','${s_total}','${s_profit}','${s_dest}','${s_date}'";
$sql .= ")";
if( $db->query($sql) ){
substract_product_qty($s_qty, $p_id);
$session->msg('s',"Listo!");
/* error */
redirect(SITE_URL.'add_sale.php', false);
} else {
$session->msg( 'd','Operación falló: '.$db->get_last_error() );
/* error */
redirect(SITE_URL.'add_sale.php', false);
}
} else {
$session->msg("d", $errors);
/* error */
redirect(SITE_URL.'add_sale.php',false);
}
}
?>
<?php include_once('layouts/header.php'); ?>
<div class="row">
<div class="col-md-9">
<?php echo display_msg($msg); ?>
</div>
</div>
<div class="row">
<div class="col-md-9">
<!--<div class="panel panel-default">-->
<div class="panel panel-default">
<div class="panel-heading clearfix">
<strong>
<i class="glyphicon glyphicon-plus"></i>
<span>Procesar Venta</span>
</strong>
</div>
<div class="panel-body">
<div class="col-md-12">
<form method="post" action="add_sale.php" class="clearfix">
<div class="form-group">
<div class="row">
<div class="col-md-6">
<!--<div class="input-group">
<span class="input-group-addon"></span>-->
<label for="" class="control-label">COD/Part No</label>
<input type="text" class="form-control form-control-lg form-control-primary rounded" id="partNo" name="partNo" placeholder="COD/Part No" autofocus>
<div id="lst_partNo" style="cursor: pointer;" class="list-group"></div>
</div>
<div class="col-md-6">
<label for="" class="control-label">Nombre producto</label>
<input type="text" class="form-control form-control-lg form-control-primary rounded" id="product_name" name="product_name" placeholder="Nombre producto">
<div id="lst_product_name" style="cursor: pointer;" class="list-group"></div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<img class="img-thumbnail" id="product_image" src="" style="height: 10em; display:none", alt="">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label for="" class="control-label">Categoría</label>
<span class="form-control rounded" id="category"></span>
</div>
<div class="col-md-6">
<label for="" class="control-label">Ubicación</label>
<span class="form-control rounded" id="location"></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-4">
<label for="" class="control-label">Fecha</label>
<div class="input-group">
<!--<input type="date" class="form-control datePicker" name="date" id="date" data-date data-date-format="yyyy-mm-dd" value="2021-03-15">-->
<input type="text" class="form-control rounded" name="date" id="date" data-date data-date-format="yyyy-mm-dd" placeholder="aaaa-mm-dd">
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
<div class="col-md-2">
<!-- column separator -->
</div>
<div class="col-md-6">
<label for="destination">Destino/Cliente</label>
<input type="text" class="form-control rounded" id="destination" name="destination" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label for="" class="control-label">Disponible</label>
<span class="form-control rounded" id="stock">0</span>
</div>
<div class="col-md-3">
<!-- column separator -->
</div>
<div class="col-md-3">
<label for="" class="control-label">Cantidad</label>
<input type="number" class="form-control input-number rounded" id="quantity" name="quantity" placeholder="0">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<!--<div class="col-md-3">
<label for="" class="control-label">Precio compra</label>
<span class="form-control rounded" id="buy_price">0.00</span>
</div>-->
<div class="col-md-3">
<label for="" class="control-label">Precio venta</label>
<input type="text" class="form-control rounded" id="sale_price" name="sale_price" placeholder="0.00">
</div>
<div class="col-md-3">
<!-- column separator -->
</div>
<div class="col-md-3">
<label for="" class="control-label">Total Venta</label>
<input type="text" class="form-control rounded" id="total_sale" name="total_sale" placeholder="0.00">
</div>
</div>
</div>
<div class="form-group">
<div class="row" style="margin-top: 2.5em;">
<div class="col-md-12">
<button type="submit" name="add_sale" id="btn_add_sale" class="btn btn-primary pull-left">Procesar Venta</button>
<button class="btn btn-warning pull-left" id="refresh">Limpiar</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- This is the jQuery background for this page -->
<script type="text/javascript" src="lib/js/add_sale.js"></script>
<?php include_once('layouts/footer.php'); ?>