-
Notifications
You must be signed in to change notification settings - Fork 1
/
invoice_test.php
217 lines (173 loc) · 5.17 KB
/
invoice_test.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
<?php
require_once 'core/init.php';
$user2=new user();
if(!$user2->isLoggedIn()){
Redirect::to('index.php');
}
$res=DB::getInstance()->get('reservation',array('user_id','=', $user2->data()->id));
if($res->count()){
foreach($res->results() as $row){
$re_id=$row->id;
}
// echo $row->id; reservTION id
}
?>
<html>
<head>
<title>Simple invoice in PHP</title>
<style type="text/css">
body {
font-family: Verdana;;
}
div.invoice {
border:1px solid #ccc;
padding:10px;
height:740pt;
width: 570pt;
}
div.company-address {
border:1px solid #ccc;
float:left;
width:200pt;
}
div.invoice-details {
border:1px solid #ccc;
float:right;
width:200pt;
}
div.customer-address {
border:1px solid #ccc;
float:right;
margin-bottom:50px;
margin-top:100px;
width:200pt;
}
div.clear-fix {
clear:both;
float:none;
}
table {
width:100%;
}
th {
text-align: left;
}
.text-left {
text-align:left;
}
.text-center {
text-align:center;
}
.text-right {
text-align:right;
}
</style>
</head>
<body>
<div class="invoice">
<div class="company-address">
Sayians CO.
<br />
12 park Street
<br />
Ain Shams, Cairo, Egypt
<br />
</div>
<div class="invoice-details">
Invoice : <?php
$num ='select id from invoice where cus_id ="' .$user2->data()->id. '" ';
$execute1=$link->query($num);
while($row=mysqli_fetch_assoc($execute1)){
echo $row["id"];
}
?>
<br />
Date :<?php echo date("Y-m-d")?>
</div>
<div class="customer-address">
To: <?php echo $user2->data()->name; ?>
<br />
Address: <?php echo $user2->data()->Address; ?>
<br />
Cairo Egypt
<br />
</div>
<div class="clear-fix"></div>
<table border='1'>
<tr>
<th width=400>Description</th>
<th width=300>Price</th>
</tr>
<?php
$sub_total = 0;
$reserv_price = 50;
$dat='';
$tim='';
$row='';
$ser='';
$link = mysqli_connect("localhost", "root", "toor", "new");
$sql = '
select s.name,s.price,res.user_id,res.start,res.date,resd.service_id from reservation_details as resd
inner join reservation as res
on resd.reservation_id = res.id
inner join service as s
on s.id = service_id
where res.id = "'.$re_id.'"
';
$result = $link->query($sql);
while($row=mysqli_fetch_assoc($result)){
$description = $row['name'];
$price = $row['price'];
$sub_total += $price;
$tim= $row['start'];
$dat= $row['date'];
$ser= $row['service_id'];
echo("<tr>");
echo("<td>$description</td>");
echo("<td class='text-right'>$price</td>");
echo("</tr>");
}
echo("<tr>");
echo("<td colspan='2' class='text-right'>Sub total</td>");
echo("<td class='text-right'>" . number_format($sub_total,2) . "</td>");
echo("</tr>");
echo("<tr>");
echo("<td colspan='2' class='text-right'>Reservation Price</td>");
echo("<td class='text-right'>" . number_format($reserv_price,2) . "</td>");
echo("</tr>");
echo("<tr>");
echo("<td colspan='2' class='text-right'><b>TOTAL</b></td>");
$total=(($sub_total+$reserv_price));
echo("<td class='text-right'><b>" . number_format($total,2) . "</b></td>");
echo("</tr>");
$user_id='select cus_id from invoice where cus_id ="' .$user2->data()->id. '" ';
$con = false;
$execu = $link->query($user_id);
while ($row = $execu->fetch_assoc())
{
if($row['cus_id'] == $user2->data()->id)
{$con= true;}
}
if(!$con){
$x="insert into invoice (cus_id,time,date,total_price) VALUES
('". $user2->data()->id ."', '". $tim ."', '". $dat ."','". $total ."')";
$exec = $link->query($x);
$inv_id='select id from invoice where cus_id ="' .$user2->data()->id. '" ';
$exe = $link->query($inv_id);
while ($row = $exe->fetch_assoc())
{
$result = $link->query($sql);
while($eee = $result->fetch_array())
{
$inv_det="insert into invoice_details (invoice_id, service_id) VALUES ('". $row['id'] ."','". $eee['service_id'] ."')";
$ex= $link->query($inv_det);
echo"test";
}
echo 'done';
}
}
?>
</table>
</div>
</body>
</html>