-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_purchase.php
399 lines (310 loc) · 21.4 KB
/
update_purchase.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<?php
include_once("init.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PDV Web - Update Supplier</title>
<!-- Stylesheets -->
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="js/date_pic/date_input.css">
<link rel="stylesheet" href="lib/auto/css/jquery.autocomplete.css">
<!-- Optimize for mobile devices -->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<!-- jQuery & JS files -->
<?php include_once("tpl/common_js.php"); ?>
<script src="js/date_pic/jquery.date_input.js"></script>
<script src="lib/auto/js/jquery.autocomplete.js "></script>
<script src="js/script.js"></script>
<script src="js/update_purchase.js"></script>
</head>
<body>
<!-- TOP BAR -->
<?php include_once("tpl/top_bar.php"); ?>
<!-- end top-bar -->
<!-- HEADER -->
<div id="header-with-tabs">
<div class="page-full-width cf">
<ul id="tabs" class="fl">
<li><a href="dashboard.php" class="dashboard-tab">Dashboard</a></li>
<li><a href="view_sales.php" class="sales-tab">Sales</a></li>
<li><a href="view_customers.php" class=" customers-tab">Customers</a></li>
<li><a href="view_purchase.php" class="active-tab purchase-tab">Purchase</a></li>
<li><a href="view_supplier.php" class=" supplier-tab">Supplier</a></li>
<li><a href="view_product.php" class="stock-tab">Stocks / Products</a></li>
<li><a href="view_payments.php" class="payment-tab">Payments / Outstandings</a></li>
<li><a href="view_report.php" class="Relatórios-tab">Relatórioss</a></li>
</ul>
<!-- end tabs -->
<!-- Change this image to your own company's logo -->
<!-- The logo will automatically be resized to 30px height. -->
<a href="#" id="company-branding-small" class="fr"><img src="<?php if (isset($_SESSION['logo'])) {
echo "upload/" . $_SESSION['logo'];
} else {
echo "upload/posnic.png";
} ?>" alt="PDV Web"/></a>
</div>
<!-- end full-width -->
</div>
<!-- end header -->
<!-- MAIN CONTENT -->
<div id="content">
<div class="page-full-width cf">
<div class="side-menu fl">
<h3>Purchase Management</h3>
<ul>
<li><a href="add_purchase.php">Efetuar Compra</a></li>
<li><a href="view_purchase.php">Visualizar Compras </a></li>
</ul>
</div>
<!-- end side-menu -->
<div class="side-content fr">
<div class="content-module">
<div class="content-module-heading cf">
<h3 class="fl">Update Purchase</h3>
<span class="fr expand-collapse-text">CLIQUE PARA FECHAR</span>
<span class="fr expand-collapse-text initial-expand">CLIQUE PARA ABRIR</span>
</div>
<!-- end content-module-heading -->
<div class="content-module-main cf">
<?php
if (isset($_POST['supplier']) and isset($_POST['stock_name'])) {
//$billnumber = mysqli_real_escape_string($db->connection, $_POST['bill_no']);
$autoid = mysqli_real_escape_string($db->connection, $_POST['id']);
$supplier = mysqli_real_escape_string($db->connection, $_POST['supplier']);
//$payment = mysqli_real_escape_string($db->connection, $_POST['payment']);
//$balance = mysqli_real_escape_string($db->connection, $_POST['balance']);
$address = mysqli_real_escape_string($db->connection, $_POST['address']);
$contact = mysqli_real_escape_string($db->connection, $_POST['contact']);
$count = $db->countOf("supplier_details", "supplier_name='$supplier'");
if ($count == 0) {
$db->query("insert into supplier_details(supplier_name,supplier_address,supplier_contact1) values('$supplier','$address','$contact')");
}
$temp_balance = $db->queryUniqueValue("SELECT balance FROM supplier_details WHERE supplier_name='$supplier'");
//$temp_balance = (int)$temp_balance + (int)$balance;
$db->execute("UPDATE supplier_details SET balance='$temp_balance' WHERE supplier_name='$supplier'");
//$selected_date = $_POST['due'];
//$selected_date = strtotime($selected_date);
//$mysqldate = date('Y-m-d H:i:s', $selected_date);
//$due = $mysqldate;
$mode = mysqli_real_escape_string($db->connection, $_POST['mode']);
$description = mysqli_real_escape_string($db->connection, $_POST['description']);
$namet = $_POST['stock_name'];
$quantityt = isset($_POST['quanitity']) ? $_POST['quanitity'] : '';
$bratet = $_POST['cost'];
$sratet = $_POST['sell'];
$totalt = $_POST['total'];
$subtotal = mysqli_real_escape_string($db->connection, $_POST['subtotal']);
$username = $_SESSION['username'];
$i = 0;
$j = 1;
$selected_date = $_POST['date'];
$selected_date = strtotime($selected_date);
$mysqldate = date('Y-m-d H:i:s', $selected_date);
foreach ($namet as $name1) {
$quantity = $_POST['quantity'][$i];
$brate = $_POST['cost'][$i];
$srate = $_POST['sell'][$i];
$total = $_POST['total'][$i];
$sysid = $_POST['gu_id'][$i];
$count = $db->countOf("stock_avail", "name='$name1'");
$amount = $db->queryUniqueValue("SELECT quantity FROM stock_avail WHERE name='$name1'");
$oldquantity = $db->queryUniqueValue("SELECT quantity FROM stock_entries WHERE id='$sysid' ");
$amount1 = ($amount + $quantity) - $oldquantity;
$db->execute("UPDATE stock_avail SET quantity='$amount1' WHERE name='$name1'");
$db->query("UPDATE stock_entries SET stock_name='$name1', stock_supplier_name='$supplier', quantity='$quantity', company_price='$brate', selling_price='$srate', opening_stock='$amount', closing_stock='$amount1', date='$mysqldate', username='$username', type='entry', total='$total', mode='$mode', description='$description', subtotal='$subtotal' WHERE id='$sysid'");
//INSERT INTO `stock`.`stock_entries` (`id`, `stock_id`, `stock_name`, `stock_supplier_name`, `category`, `quantity`, `company_price`, `selling_price`, `opening_stock`, `closing_stock`, `date`, `username`, `type`, `salesid`, `total`, `payment`, `balance`, `mode`, `description`, `due`, `subtotal`, `count1`)
//VALUES (NULL, '$autoid1', '$name1', '$supplier', '', '$quantity', '$brate', '$srate', '$amount', '$amount1', '$mysqldate', 'sdd', 'entry', 'Sa45', '432.90', '2342.90', '24.34', 'cash', 'sdflj', '2010-03-25 12:32:02', '45645', '1');
$i++;
$j++;
}
echo "<br><font color=green size=+1 >Parchase order Updated successfully Ref: [" . $_POST['purchaseid'] . "] !</font>";
}
?>
<?php
if (isset($_GET['sid']))
$id = $_GET['sid'];
$line = $db->queryUniqueObject("SELECT * FROM stock_entries WHERE id='$id'");
?>
<form name="form1" method="post" id="form1" action="">
<input type="hidden" id="posnic_total">
<input type="hidden" name="id" value="<?php echo $id ?>">
<table class="form" border="0" cellspacing="0" cellpadding="0">
<tr>
<?php
$str = $db->maxOfAll("stock_id", "stock_entries");
$array = explode(' ', $str);
$autoid = ++$array[0];
?>
<td>Purchase ID:</td>
<td><input name="purchaseid" type="text" id="purchaseid" readonly="readonly" maxlength="200"
class="round default-width-input" style="width:130px "
value="<?php echo $line->stock_id; ?>"/></td>
<td>Date:</td>
<td><input name="date" id="test1" placeholder="" style="margin-left: 15px;" value="<?php echo $line->date; ?> "
type="text" id="name" maxlength="200" class="round default-width-input"/>
</td>
</tr>
<tr>
<td><span class="man">*</span>Supplier:</td>
<td><input name="supplier" placeholder="ENTER SUPPLIER" type="text" id="supplier"
value="<?php echo $line->stock_supplier_name; ?> " maxlength="200"
class="round default-width-input" style="width:130px "/></td>
<td>Address:</td>
<td><input name="address" placeholder="ENTER ADDRESS" type="text"
value="<?php $quantity = $db->queryUniqueValue("SELECT supplier_address FROM supplier_details WHERE supplier_name='" . $line->stock_supplier_name . "'");
echo $quantity; ?>" id="address" maxlength="200"
class="round default-width-input"/></td>
<td>contact:</td>
<td><input name="contact" placeholder="ENTER CONTACT" type="text"
value="<?php $quantity = $db->queryUniqueValue("SELECT supplier_contact1 FROM supplier_details WHERE supplier_name='" . $line->stock_supplier_name . "'");
echo $quantity; ?>" id="contact1" maxlength="200"
class="round default-width-input" onkeypress="return numbersonly(event)"
style="width:120px "/></td>
</tr>
</table>
<input type="hidden" id="guid">
<input type="hidden" id="edit_guid">
<table id="hideen_display">
<tr>
<td style="width: 174px">Item</td>
<td style="width: 20px">Quantity</td>
<td style="width: 87px">Cost</td>
<td style="width: 87px">Selling</td>
<td style="width: 97px">Available Stock</td>
<td style="width: 160x float: Left;">Total </td>
</tr>
</table>
<table class="form" id="display" style="display:none">
<tr>
<td><input name="" type="text" id="item" maxlength="200" class="round my_with "
style="width: 238px"
value="<?php echo isset($supplier) ? $supplier : ''; ?>"/></td>
<td><input name="" type="text" id="quty" maxlength="200" class="round my_with" style="width: 75px"
onKeyPress="quantity_chnage(event);return numbersonly(event)"
onkeyup="total_amount();unique_check()"
value="<?php echo isset($category) ? $category : ''; ?>"/></td>
<td><input name="" type="text" id="cost" readonly="readonly" maxlength="200" style="width: 133px"
class="round my_with"
value="<?php echo isset($category) ? $category : ''; ?>"/></td>
<td><input name="" type="text" id="sell" readonly="readonly" maxlength="200" style="width: 130px"
class="round my_with"
value="<?php echo isset($category) ? $category : ''; ?>"/></td>
<td><input name="" type="text" id="stock" readonly="readonly" maxlength="200" style="width: 143px"
class="round my_with"
value="<?php echo isset($category) ? $category : ''; ?>"/></td>
<td><input name="" type="text" id="total" maxlength="200"
class="round default-width-input " style="width:45px;"
value="<?php echo isset($category) ? $category : ''; ?>"/></td>
<td><input type="button" onclick="add_values()" onkeyup=" balance_amount();"
id="add_new_code"
style="width:30px;border:none;height:30px;background:url(images/Gravar.png)"
class="round">
</td>
<td><input type="button" value="" id="cancel" onclick="clear_data()"
style="width:30px;float: right; border:none;height:30px;background:url(images/close_new.png)">
</td>
</tr>
</table>
<input type="hidden" id="guid">
<input type="hidden" id="edit_guid">
<div style="overflow:auto ;max-height:300px; ">
<table class="form" id="item_copy_final">
<?php
$sid = $line->stock_id;
$max = $db->maxOf("count1", "stock_entries", "stock_id='$sid'");
for ($i = 1; $i <= $max; $i++) {
$line1 = $db->queryUniqueObject("SELECT * FROM stock_entries WHERE stock_id='$sid' and count1=$i");
$item = $db->queryUniqueValue("SELECT stock_id FROM stock_details WHERE stock_name='" . $line1->stock_name . "'");
?>
<tr>
<td><input name="stock_name[]" type="text" id="<?php echo $item . "st" ?>"
maxlength="30" style="width: 238px" readonly="readonly"
class="round "
value="<?php echo $line1->stock_name; ?>"/></td>
<td><input name="quantity[]" type="text" id="<?php echo $item . "q" ?>"
maxlength="20" style="width: 75px" class="round my_with"
value="<?php echo $line1->quantity; ?>" readonly="readonly"
onkeypress="return numbersonly(event)"/></td>
<td><input name="cost[]" type="text" id="<?php echo $item . "c" ?>"
maxlength="20" style="width: 133px" class="round my_with"
value="<?php echo $line1->company_price; ?>" readonly="readonly"
onkeypress="return numbersonly(event)"/></td>
<td><input name="sell[]" style="width: 130px" type="text" id="<?php echo $item . "s" ?>"
maxlength="20" readonly="readonly" class="round my_with"
value="<?php echo $line1->selling_price; ?>"
onkeypress="return numbersonly(event)"/></td>
<td><input name="stock[]" style="width: 143px" type="text" id="<?php echo $item . "p" ?>"
readonly="readonly" maxlength="200" class="round my_with"
value="<?php $quantity = $db->queryUniqueValue("SELECT quantity FROM stock_avail WHERE name='" . $line1->stock_name . "'");
echo $quantity; ?>"/></td>
<td>
<input name="total[]" type="text" id="<?php echo $item . "to" ?>"
readonly="readonly" maxlength="20"
style="width: 45px" class="round "
value="<?php echo $line1->total; ?>"/></td>
<input type="hidden" id="<?php echo $item . "my_tot" ?>" maxlength="20"
style="margin-left:20px;width: 120px" class="round "
value="<?php echo $line1->total; ?>"/>
<input type="hidden" id="<?php echo $item; ?>"><input type="hidden"
name="gu_id[]"
value="<?php echo $line1->id ?>">
<td><input type=button value="" id="<?php echo $item; ?>"
style="float: right;width:30px;border:none;height:30px;background:url(images/edit_new.png)"
class="round" onclick="edit_stock_details(this.id)"></td>
</tr>
<?php } ?>
</table>
</div>
<table>
<tr>
<td>Mode </td>
<td>
<select name="mode">
<option value="cheque">Cheque</option>
<option value="cheque">Cash</option>
<option value="cheque">Other</option>
</select>
</td>
<td>Description</td>
<td><textarea name="description"><?php echo $line->description; ?></textarea></td>
<td>Grand Total:<input type="hidden" readonly="readonly" id="grand_total"
value="<?php echo $line->subtotal; ?>" name="subtotal">
<input type="text" id="main_grand_total" class="round default-width-input"
value="<?php echo $line->subtotal; ?>" style="text-align:right;width: 120px">
</td>
<td> </td>
<td> </td>
</tr>
</table>
<table class="form">
<tr>
<td>
<input class="button round blue image-right ic-add text-upper" type="submit"
name="Submit" value="Add">
</td>
<td> (Control + S)
<input class="button round red text-upper" type="reset" name="Reset"
value="Reset"></td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</div>
<!-- end content-module-main -->
</div>
<!-- end content-module -->
</div>
<!-- end full-width -->
</div>
<!-- end content -->
<!-- FOOTER -->
<div id="footer">
<p>Nome da Empresa - www.nomedaempresa.com.br</a>.
</p>
</div>
<!-- end footer -->
</body>
</html>