-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquotation.php
427 lines (359 loc) · 15.3 KB
/
quotation.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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<?php
require_once 'conf/smarty-conf.php';
include 'functions/inventory_functions.php';
include 'functions/quotation_functions.php';
include 'functions/user_functions.php';
include 'functions/navigation_functions.php';
$module_no = 23;
if ($_SESSION['login'] == 1) {
if (check_access($module_no, $_SESSION['user_id']) == 1) {
if ($_REQUEST['job']=='barcode'){
$selected_item=$_POST['barcode'];
if (!isset($_SESSION['quotation_no'])) {
$_SESSION['quotation_no']=$quotation_no=get_quotation_no();
}
else{
}
$quotation_no=$_SESSION['quotation_no'];
$quotation_info=get_quotation_info_by_quotation_no($quotation_no);
$info=get_item_info_by_name($selected_item);
$product_name=$info['product_name'];
$product_id=$info['product_id'];
//$stock=get_total_stock($info['product_id']);
$quantity=get_quantity($product_id, $_SESSION['quotation_no'])+1;
if(check_added_items($product_id, $_SESSION['quotation_no'])==1){
$info_for_quotation_has_items=get_product_info_from_quotation_has_items($product_id, $quotation_no);
$selling_price=$info_for_quotation_has_items['selling_price'];
$discount=$info_for_quotation_has_items['discount'];
$quantity=$quantity+1;
$item_total=($quantity*$selling_price/100)*(100-$discount);
if($_SESSION['edit']==1 && $info_for_quotation_has_items['saved']==1){
reupdate_inventory($product_id, $info_for_quotation_has_items['quantity'], $stock);
}
else{
}
update_quotation_item_for_repeative_adding($product_id, $quantity, $item_total);
}
else{
$discount=$info['discount'];
$selling_price=$info['selling_price'];
add_quotation_item($selected_item, $product_name, $stock, $selling_price, $discount, $_SESSION['quotation_no']);
//$total_to_ledger=($selling_price/100)*(100-$discount);
//add_quotation_items_ledger($_SESSION['quotation_no'], $product_id, $total_to_ledger);
}
$smarty->assign('customer_name',"$quotation_info[customer_name]");
$smarty->assign('date',"$quotation_info[date]");
$smarty->assign('remarks',"$quotation_info[remarks]");
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
if($_SESSION['edit']==1){
$smarty->assign('edit_mode',"on");
$smarty->assign('prepared_by',"$quotation_info[prepared_by]");
$smarty->assign('updated_by',"$_SESSION[user_name]");
}
else{
$smarty->assign('prepared_by',"$_SESSION[user_name]");
}
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('total',get_total_quotation($_SESSION['quotation_no']));
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
}
elseif($_REQUEST['job']=='update_item'){
$product_id=$_REQUEST['product_id'];
$quantity=$_POST['quantity'];
$selling_price=$_POST['selling_price'];
$discount=$_POST['discount'];
$user_name=$_SESSION['user_name'];
$item_total=($quantity*$selling_price/100)*(100-$discount);
//$stock=get_total_stock($_REQUEST['product_id']);
//$stock = get_branch_stock($product_id);
$quotation_no=$_SESSION['quotation_no'];
$quotation_info=get_quotation_info_by_quotation_no($quotation_no);
$item_info=get_product_info_from_quotation_has_items($product_id, $quotation_no);
if($_SESSION['edit']==1 && $item_info['saved']==1){
reupdate_inventory($product_id, $item_info['quantity'], $stock);
}
else{
}
update_quotation_item($product_id, $quantity, $item_total, $selling_price, $discount, $quotation_no, $stock);
//update_quotation_item_ledger($product_id ,$quotation_no);
$smarty->assign('customer_name',"$quotation_info[customer_name]");
$smarty->assign('date',"$quotation_info[date]");
$smarty->assign('remarks',"$quotation_info[remarks]");
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
if($_SESSION['edit']==1){
$smarty->assign('edit_mode',"on");
$smarty->assign('prepared_by',"$quotation_info[prepared_by]");
$smarty->assign('updated_by',"$_SESSION[user_name]");
}
else{
$smarty->assign('prepared_by',"$_SESSION[user_name]");
}
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
$smarty->assign('prepared_by',"$_SESSION[user_name]");
$smarty->assign('total',get_total_quotation($_SESSION['quotation_no']));
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
}
elseif ($_REQUEST['job']=='search'){
$_SESSION['quotation_no_search']=$_POST['quotation_no_search'];
$_SESSION['customer_search']=$_POST['customer_search'];
$smarty->assign('search_mode',"on");
unset($_SESSION['quotation_no']);
$smarty->assign('quotation_no_search',"$_SESSION[quotation_no_search]");
$smarty->assign('customer_search',"$_SESSION[customer_search]");
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('total',"$total");
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
}
elseif ($_REQUEST['job']=='edit'){
$_SESSION['edit']=1;
$_SESSION['id']=$id=$_REQUEST['id'];
$info=get_quotation_info($id);
$_SESSION['quotation_no']=$info['quotation_no'];
$supplier_name=$info['supplier_name'];
$remarks=$info['remarks'];
$prepared_by=$info['prepared_by'];
$date=$info['date'];
$smarty->assign('edit_mode',"on");
$smarty->assign('updated_by',"$_SESSION[user_name]");
$smarty->assign('total',get_total_quotation($_SESSION['quotation_no']));
$smarty->assign('parent_catagorys',list_parent_catagory());
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
$smarty->assign('customer_name',"$info[customer_name]");
$smarty->assign('date',"$info[date]");
$smarty->assign('remarks',"$info[remarks]");
$smarty->assign('supplier_search',"$_SESSION[supplier_search]");
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
$smarty->assign('prepared_by',"$info[prepared_by]");
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
}
elseif ($_REQUEST['job']=='delete_item'){
$id=$_REQUEST['id'];
$info=get_product_info_from_quotation_has_items_by_id($id);
$item_info=get_product_info_from_quotation_has_items($info['product_id'], $_SESSION['quotation_no']);
$stock=get_total_stock($info['product_id']);
if($_SESSION['edit']==1 && $item_info['saved']==1){
reupdate_inventory($info['product_id'], $item_info['quantity'], $stock);
}
else{
}
cancel_item($id);
//delete_quotation_items_ledger($id);
$quotation_no=$_SESSION['quotation_no'];
$quotation_info=get_quotation_info_by_quotation_no($quotation_no);
$smarty->assign('customer_name',"$quotation_info[customer_name]");
$smarty->assign('date',"$quotation_info[date]");
$smarty->assign('remarks',"$quotation_info[remarks]");
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
if($_SESSION['edit']==1){
$smarty->assign('edit_mode',"on");
$smarty->assign('prepared_by',"$quotation_info[prepared_by]");
$smarty->assign('updated_by',"$_SESSION[user_name]");
}
else{
$smarty->assign('prepared_by',"$_SESSION[user_name]");
}
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
$smarty->assign('total',get_total_quotation($_SESSION['quotation_no']));
$smarty->assign('prepared_by',"$_SESSION[user_name]");
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
}
elseif($_REQUEST['job']=='quotation'){
if($_REQUEST['ok']=='Finish the Bill & Print'){
$date=$_POST['date'];
$remarks=$_POST['remarks'];
$discount=$_POST['discount'];
$customer_name=$_POST['customer_name'];
$customer_amount=$_POST['customer_amount'];
$prepared_by=$_POST['prepared_by'];
$quotation_no=$_POST['quotation_no'];
$total=get_total_quotation($_SESSION['quotation_no']);
$total_after_discount= $total-$discount;
$balance=$customer_amount-$total_after_discount;
save_quotation($quotation_no, $date, $customer_name, $prepared_by, $remarks,$discount,$customer_amount, $total_after_discount, $total,$balance);
//add_quotation_ledger($quotation_no);
}
else {
$id=$_SESSION['id'];
$date=$_POST['date'];
$remarks=$_POST['remarks'];
$discount=$_POST['discount'];
$customer_name=$_POST['customer_name'];
$prepared_by=$_POST['prepared_by'];
$updated_by=$_POST['updated_by'];
$quotation_no=$_POST['quotation_no'];
$total=get_total_quotation($_SESSION['quotation_no']);
update_quotation($id, $quotation_no, $date, $customer_name, $prepared_by, $remarks,$discount, $total, $updated_by);
//update_quotation_ledger($quotation_no);
unset($_SESSION['edit']);
}
$customer_name=$_POST['customer_name'];
$customer_address=$_POST['customer_address'];
$customer_tel=$_POST['customer_tel'];
$smarty->assign('customer_name',"$customer_name");
$smarty->assign('customer_address',"$customer_address");
$smarty->assign('customer_tel',"$customer_tel");
$_SESSION['print_no']=$_SESSION['quotation_no'];
unset($_SESSION['quotation_no']);
$date = date("Y-m-d");
$smarty->assign('parent_catagorys',list_parent_catagory());
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('date',"$date");
$smarty->assign('quotation',"$_SESSION[print_no]");
$smarty->assign('total',get_total_quotation($_SESSION['quotation_no']));
$smarty->assign('page',"quotation");
$smarty->display('quotation/print.tpl');
}
elseif ($_REQUEST['job']=='must_new'){
unset($_SESSION['edit']);
unset($_SESSION['quotation_no']);
unset($_SESSION['remarks']);
unset($_SESSION['prepared_by']);
unset($_SESSION['updated_by']);
unset($_SESSION['supplier_name']);
unset($_SESSION['updated_by']);
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('parent_catagorys',list_parent_catagory());
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
}
elseif($_REQUEST['job']=='quotation_page'){
$smarty->assign('page',"Notifications");
$smarty->display('quotation/quotation.tpl');
}
elseif ($_REQUEST['job']=='select'){
$selected_item=$_POST['selected_item'];
if (!isset($_SESSION['quotation_no'])) {
$_SESSION['quotation_no']=$quotation_no=get_quotation_no();
}
else{
}
$quotation_no=$_SESSION['quotation_no'];
$quotation_info=get_quotation_info_by_quotation_no($quotation_no);
$info=get_item_info_by_name($selected_item);
$product_name=$info['product_name'];
$product_id=$info['product_id'];
//$stock=get_total_stock($info['product_id']);
$quantity=get_quantity($product_id, $_SESSION['quotation_no'])+1;
if(check_added_items($product_id, $_SESSION['quotation_no'])==1){
$info_for_quotation_has_items=get_product_info_from_quotation_has_items($product_id, $quotation_no);
$selling_price=$info_for_quotation_has_items['selling_price'];
$discount=$info_for_quotation_has_items['discount'];
$quantity=$quantity+1;
$item_total=($quantity*$selling_price/100)*(100-$discount);
if($_SESSION['edit']==1 && $info_for_quotation_has_items['saved']==1){
reupdate_inventory($product_id, $info_for_quotation_has_items['quantity'], $stock);
}
else{
}
update_quotation_item_for_repeative_adding($product_id, $quantity, $item_total);
}
else{
$discount=$info['discount'];
$selling_price=$info['selling_price'];
add_quotation_item($selected_item, $product_name, $stock, $selling_price, $discount, $_SESSION['quotation_no']);
//$total_to_ledger=($selling_price/100)*(100-$discount);
//add_quotation_items_ledger($_SESSION['quotation_no'], $product_id, $total_to_ledger);
}
$smarty->assign('customer_name',"$quotation_info[customer_name]");
$smarty->assign('date',"$quotation_info[date]");
$smarty->assign('remarks',"$quotation_info[remarks]");
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
if($_SESSION['edit']==1){
$smarty->assign('edit_mode',"on");
$smarty->assign('prepared_by',"$quotation_info[prepared_by]");
$smarty->assign('updated_by',"$_SESSION[user_name]");
}
else{
$smarty->assign('prepared_by',"$_SESSION[user_name]");
}
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('total',get_total_quotation($_SESSION['quotation_no']));
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
}
elseif ($_REQUEST['job']=='delete'){
$module_no = 103;
if (check_access($module_no, $_SESSION['user_id']) == 1) {
$id=$_REQUEST['id'];
$info=get_quotation_info($id);
$quotation_no_for_delete=$info['quotation_no'];
calncel_items_for_quotation_no($quotation_no_for_delete);
cancel_quotation($id);
//delete_quotation_ledger($quotation_no_for_delete);
//delete_all_quotation_items_ledger($quotation_no_for_delete);
$smarty->assign('search_mode',"on");
unset($_SESSION['quotation_no']);
$smarty->assign('quotation_no_search',"$_SESSION[quotation_no_search]");
$smarty->assign('customer_search',"$_SESSION[customer_search]");
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
} else {
$user_name = $_SESSION['user_name'];
$smarty->assign('org_name', "$_SESSION[org_name]");
$smarty->assign('error_report', "on");
$smarty->assign('error_message', "Dear $user_name, you don't have permission to DELETE a quotation.");
$smarty->assign('page', "Access Error");
$smarty->display('user_home/access_error.tpl');
}
}
else {
unset($_SESSION['edit']);
unset($_SESSION['quotation_no']);
unset($_SESSION['remarks']);
unset($_SESSION['prepared_by']);
unset($_SESSION['updated_by']);
unset($_SESSION['supplier_name']);
unset($_SESSION['updated_by']);
if(check_non_saved_quotation_order($_SESSION['user_name'])==1){
$_SESSION['quotation_no']=non_save_quotation_info($_SESSION['user_name']);
$info=get_quotation_info_by_quotation_no($_SESSION['quotation_no']);
$customer_name=$info['customer_name'];
$remarks=$info['remarks'];
$prepared_by=$info['prepared_by'];
$date=$info['date'];
$_SESSION['edit']=1;
if ($customer_name){
$smarty->assign('new',"Skip Editing and <a href='quotation.php?job=must_new' style='color: orange; font-size: 20px;'> Create New Perchase Order.</a>");
$smarty->assign('edit_mode',"on");
$smarty->assign('updated_by',"$_SESSION[user_name]");
$smarty->assign('customer_name',"$info[customer_name]");
$smarty->assign('date',"$info[date]");
$smarty->assign('remarks',"$info[remarks]");
$smarty->assign('prepared_by',"$info[prepared_by]");
}
else {
$smarty->assign('prepared_by',"$_SESSION[user_name]");
}
}
else{
}
$total=get_total_quotation($_SESSION['quotation_no']);
$smarty->assign('org_name',"$_SESSION[org_name]");
$smarty->assign('parent_catagorys',list_parent_catagory());
$smarty->assign('quotation_no',"$_SESSION[quotation_no]");
$smarty->assign('total',"$total");
$smarty->assign('page',"quotation");
$smarty->display('quotation/quotation.tpl');
}
} else {
$user_name = $_SESSION['user_name'];
$smarty->assign('org_name', "$_SESSION[org_name]");
$smarty->assign('error_report', "on");
$smarty->assign('error_message', "Dear $user_name, you don't have permission to access quotation.");
$smarty->assign('page', "Access Error");
$smarty->display('user_home/access_error.tpl');
}
}
else{
$smarty->assign('page',"Home");
$smarty->display('index.tpl');
}