-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbilling.php
137 lines (105 loc) · 4.82 KB
/
billing.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
<?php
require 'config.php';
require 'conversion.php';
// echo convertNumberToWordsForIndia(10); die;
$conn = connection();
// Generate the unique id for every bill
$date = date("F_j_Y_G_i_s");
$uid = uniqid($date);
// echo $uid; die;
// code to make entry in the bill table
$bill_name = $_REQUEST['bill_name'];
// echo $gst = $_REQUEST['gst_no'];
// echo $tchrg = $_REQUEST['trans_chg'];
// echo $tno = $_REQUEST['trans_no'];
$entrydt = date("Y-m-d H:i:s");
$total = $_REQUEST['total_amt'];
$type = $_REQUEST['bill_type'];
$record = "INSERT INTO `bill_records` (`bill_id`, `bill_uid`, `bill_name`, `bill_gst`, `bill_tchrg`, `bill_tno`, `bill_amt`, `bill_type`, `bill_entrydt`) VALUES (NULL, '$uid', '$bill_name', NULL, NULL, NULL, '$total', $type, '$entrydt');";
$conn->query($record);
// code to insert the product in billing product table
$count = $_REQUEST['count'];
for ($i=0; $i < $count; $i++) {
$firm = $_REQUEST['bill_f_'.$i];
$cat = $_REQUEST['bill_p_'.$i];
$size = $_REQUEST['bill_s_'.$i];
$qty = $_REQUEST['bill_q_'.$i];
// This query fetch the product id on the basis of cat and type
$sql = "SELECT pro_id, pro_price, pro_qty FROM product p INNER JOIN category c ON cat_id=pro_grpid INNER JOIN type t ON pro_typeid=ty_id WHERE pro_firmid = $firm AND pro_grpid = $cat AND pro_typeid = $size";
$pro_id = $conn->query($sql);
foreach ($pro_id as $key => $value) {
$pid = $value['pro_id']; //final product id
$price = $value['pro_price']; //product price
$sqty = $value['pro_qty']; //product quantity in stock
// Add the stock when bill type is 1 and Remove the stock when bill type is 2
if ($type == 1) {
$remain = $qty + $sqty;
}
else{
$remain = $sqty - $qty;
}
$update_stock = "UPDATE product SET pro_qty = $remain WHERE pro_id = $pid";
$conn->query($update_stock);
// query to insert all product of this perticular bill
$produts = "INSERT INTO bill_products (bp_uid, bp_pid, bp_qty, bp_price) VALUES ('$uid', $pid, $qty, $price)";
$conn->query($produts);
}
}
$query = "SELECT * FROM `bill_records` WHERE `bill_uid` = '$uid'";
$rec = $conn->query($query);
$pro = "SELECT f.firm_name,c.cat_name,t.ty_name,bp.bp_qty,bp.bp_price,p.pro_price FROM `bill_products` bp INNER JOIN product p ON p.pro_id = bp.bp_pid INNER JOIN category c ON c.cat_id=p.pro_grpid INNER JOIN type t ON t.ty_id=p.pro_typeid INNER JOIN firm f ON f.firm_id= p.pro_firmid WHERE bp.bp_uid = '$uid'";
$detail = $conn->query($pro);
?>
<?php
foreach ($rec as $key => $value) {
// echo $value['bill_id']; die;
}
?>
<link rel="stylesheet" type="text/css" href="assets/lib/perfect-scrollbar/css/perfect-scrollbar.min.css"/>
<link rel="stylesheet" type="text/css" href="assets/lib/material-design-icons/css/material-design-iconic-font.min.css"/>
<link rel="stylesheet" href="assets/css/style.css" type="text/css"/>
<table align="center" border="1px dotted black;" width="90%">
<tr>
<br>
<h1 style="text-decoration: underline; font-style: italic;
"><center><strong>ESTIMATE</strong></center></h1>
<br>
</tr>
<tr>
<td colspan="2"><strong> Bill No. : <?php echo $value['bill_id']; ?></strong> </td>
<td colspan="3"><strong> M/S : <?php echo ucwords($value['bill_name']); ?></strong></td>
<td colspan="2"><strong> Date : <?php echo $value['bill_entrydt'];?></strong></td>
</tr>
<tr>
<td colspan="7"> </td>
</tr>
<tr>
<th><strong><center>S. No.</center></strong></th>
<th><strong><center>FIRM</center></strong></th>
<th><strong><center>DESCRIPTION</center></strong></th>
<th><strong><center>SIZE</center></strong></th>
<th><strong><center>QUANTITY</center></strong></th>
<th><strong><center>RATE</center></strong></th>
<th><strong><center>AMOUNT</center></strong></th>
</tr>
<?php $s=0; foreach ($detail as $key => $row) { $s++; ?>
<tr>
<td><center><?php echo $s; ?></center></td>
<td> <?php echo ucwords($row['firm_name']); ?></td>
<td> <?php echo ucwords($row['cat_name']); ?></td>
<td><center><?php echo ucwords(strtoupper($row['ty_name'])); ?></center></td>
<td><center><?php echo $row['bp_qty']; ?></center></td>
<td><center><?php echo $row['bp_price']; ?></center></td>
<td><center><?php echo $row['bp_price'] * $row['bp_qty'];?></center></td>
</tr>
<?php } ?>
<tr>
<td colspan="5"><strong> Rupees In Words : </strong><?php echo convertNumberToWordsForIndia($value['bill_amt']); ?></td>
<td colspan="2"><strong> Total : <?php echo $value['bill_amt']." /-"; ?></strong></td>
</tr>
<tr>
<td colspan="2"><strong> GSTIN : <?php echo $value['bill_gst']; ?></strong></td>
<td colspan="3"><strong> Transport Charge : <?php echo $value['bill_tchrg']; ?></strong></td>
<td colspan="2"><strong> Transport no : <?php echo $value['bill_tno']; ?></strong></td>
</tr>
</table>