This repository has been archived by the owner on Apr 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoice.php
executable file
·163 lines (145 loc) · 5.29 KB
/
invoice.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
<?php
session_start();
require_once("essentials/config.php");
if (!$_SESSION['id']) {
echo '<script>
location.href="login.php"
</script>';
}
if (!$_GET['id']) {
echo '<script>
location.href="error.php"
</script>';
}
$order_id = $_GET['id'];
$customer_id = $_SESSION['id'];
require('fpdf/fpdf.php');
class PDF extends FPDF
{
function Header()
{
$this->Image('img/logo.png',80,0,45);
$this->Ln(20);
}
function populate_table($customer_id,$order_id,$connect){
$x=$this->GetX();
$y=$this->GetY();
$this->setXY($x,$y);
$this->Cell(20,7,'S.No.',1,2,'L');
$this->setXY($x+20,$y);
$this->Cell(50,7,'Product name',1,2,'L');
$this->setXY($x+70,$y);
$this->Cell(30,7,'Variant',1,2,'L');
$this->setXY($x+100,$y);
$this->Cell(20,7,'Qty',1,2,'L');
$this->setXY($x+120,$y);
$this->Cell(30,7,'Unit Price',1,2,'L');
$this->setXY($x+150,$y);
$this->Cell(30,7,'Total Price',1,2,'L');
$i=1;
$total=0;
$sql = "SELECT * FROM order_detail WHERE order_id = '$order_id' and customer_id = '$customer_id' ";
$result = mysqli_query($connect, $sql);
while($d = mysqli_fetch_assoc($result))
{
$vid = $d["variant_id"];
$result_2 = mysqli_query($connect, "SELECT color,size FROM variant where variant_id='$vid'");
$attr_prop = mysqli_fetch_assoc($result_2);
$color_id = $attr_prop['color'];
$size_id = $attr_prop['size'];
$result_3 = mysqli_query($connect, "SELECT value FROM attribute where attr_id='$color_id'");
$variant_prop = mysqli_fetch_assoc($result_3);
$color = $variant_prop['value'];
$result_4 = mysqli_query($connect, "SELECT value FROM attribute where attr_id='$size_id'");
$variant_prop = mysqli_fetch_assoc($result_4);
$size = $variant_prop['value'];
$price = $d["price"]*$d["units"];
$this->Ln(0);
$x=$this->GetX();
$y=$this->GetY();
$this->setXY($x,$y);
$this->Cell(20,7,$i,1,2,'L');
$this->setXY($x+20,$y);
$this->Cell(50,7,$d["product_name"],1,2,'L');
$this->setXY($x+70,$y);
$this->Cell(30,7,$color.", " .$size,1,2,'L');
$this->setXY($x+100,$y);
$this->Cell(20,7,$d["units"],1,2,'L');
$this->setXY($x+120,$y);
$this->Cell(30,7,$d["price"],1,2,'L');
$this->setXY($x+150,$y);
$this->Cell(30,7,$price,1,2,'L');
$total += $price;
$i++;
}
$this->Ln(0);
$x=$this->GetX();
$y=$this->GetY();
$this->setXY($x+120,$y);
$this->Cell(30,7,'Grand Total',1,2,'C');
$this->setXY($x+150,$y);
$this->Cell(30,7,round($total,2),1,2,'L');
}
function Footer()
{
$this->SetFont('Arial','',8);
$this->SetY(-21);
$date = date('Y/d/M h:i:s:A', time());
$this->Cell(0,10,'This invoice is electronically genrated on '.$date.' No signature needed',0,0,'C');
$this->SetY(-14);
$this->Cell(0,10,'MIT Licensed @ahampriyanshu',0,0,'C');
$this->SetY(-7);
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Courier','B',12);
$pdf->Cell(0,8,'Aanav Pvt Ltd',0,1,'C');
$pdf->Cell(0,8,'ahampriyanshu@gmail.com',0,1,'C');
$pdf->Cell(0,20,'',0,1,'C');
$pdf->SetFont('Arial','',12);
$sql = "SELECT * FROM orders WHERE order_id = '$order_id' ";
$result = mysqli_query($connect, $sql);
while($row = mysqli_fetch_assoc($result))
{
$pdf->Cell(0,8,'Name : '.$row['full_name'],0,1,'L');
$pdf->Cell(0,8,'Email : '.$row['email'],0,1,'L');
$pdf->Cell(0,8,'Phone : '.$row['phone'],0,1,'L');
if ($row['store_id'] != 0 )
{
$store_sql = "SELECT * FROM store WHERE store_id =" . $row['store_id'];
$store_query = mysqli_query($connect, $store_sql);
$store_row = mysqli_fetch_array($store_query);
$pdf->Cell(0,8,'Store Name : '.$store_row['store_name'],0,1,'L');
$pdf->Cell(0,8,'Store Address : '. $store_row['address'],0,1,'L');
$pdf->Cell(0,8,' '.$store_row['email'],0,1,'L');
$pdf->Cell(0,8,' '.$store_row['phone'],0,1,'L');
}
else
{
$pdf->Cell(0,8,'Address : '.$row['street_address'],0,1,'L');
$pdf->Cell(0,8,'City : '.$row['city'],0,1,'L');
$pdf->Cell(0,8,'State : '.$row['state'],0,1,'L');
$pdf->Cell(0,8,'Pincode : '.$row['pincode'],0,1,'L');
}
$pdf->Cell(0,10,'',0,1,'C');
$pdf->populate_table($customer_id,$order_id,$connect);
$pdf->Cell(0,10,'',0,1,'C');
$pdf->Cell(0,8,'Payment Type : '.$row['payment_type'],0,1,'L');
if ($row['status'] < 2 )
{
$pdf->Cell(0,8,'Payment Status :Not Received',0,1,'L');
}
else if ($row['status'] >=2 && $row['status'] <=5)
{
$pdf->Cell(0,8,'Payment Status :Received',0,1,'L');
}
else if ($row['status'] == 6 )
{
$pdf->Cell(0,8,'Payment Status : Refunded',0,1,'L');
}
$pdf->Cell(0,8,'Order Placed On :'.$row['created_date'],0,1,'L');
}
$pdf->Output();