-
Notifications
You must be signed in to change notification settings - Fork 0
/
receipt_gen.php
70 lines (68 loc) · 2.12 KB
/
receipt_gen.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
<?php
// Inialize session
session_start();
// Check, if user is already login, then jump to secured page
if (!isset($_SESSION['username'])) {
header('Location: studentlogin.php');
}
require ('includes/fpdf/fpdf.php');
require ('includes/Database.php');
$id = $_SESSION['username'];
$pdf = new FPDF('p','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(190,10,"T.U.M Hostel Receipt",1,1,'C');
$pdf->SetFont('Arial','B',12);
$sql1 = "SELECT mpesa_id FROM tumhostel.payments WHERE username = $id";
$db2 = new Database($sql1);
$resp = $db2->execute_query();
$rec = "";
while ($row=mysql_fetch_row($resp)){
$rec = $row;
echo $rec;
}
$sql3 = "SELECT fname,lname,email FROM student WHERE studentid = (SELECT distinct studentid FROM payments WHERE username = $id)";
$fullname = "";
$email = "";
$db3 = new Database($sql3);
$resp3 = $db3->execute_query();
while ($row=mysql_fetch_row($resp3)){
$fullname = "$row[1] $row[2]";
$email = $row[6];
}
$pdf->Cell(190,10,"Sales Receipt",0,1,'C');
$pdf->Cell(190,10,"Receipt Number: ".$rec,0,1,'R');
$pdf->Cell(190,10,"Date: ".date('d-m-Y'),0,1,'R');
$pdf->SetFillColor(0,255,0);
$header = array('PAID BY','StudentID','Mpesa_ID','Total Amount');
$pdf->Cell(195,7,"Particulars",1,1,'C',true);
foreach ($header as $col){
$pdf->Cell(39,7,$col,1,0,'C',true);
}
$sql = "select payments.username,payments.studentid,payments.mpesa_id,payments.amount,payments.paymentdate from payments where payments.username = $id";
$db = new Database($sql);
$sum = 0;
$resp = $db->execute_query();
while ($row = mysql_fetch_row($resp)){
$pdf->Ln();
$sum += $row[4];
$pdf->Cell(39,7,$row[0],1,0,'C');
$pdf->Cell(39,7,$row[1],1,0,'C');
$pdf->Cell(39,7,$row[3],1,0,'C');
$pdf->Cell(39,7,$row[2],1,0,'C');
$pdf->Cell(39,7,$row[4],1,0,'C');
}
$pdf->Ln();
$pdf->Cell(156,7,"Total",1,0,'C',true);
$pdf->Cell(39,7,$sum,1,0,'C',true);
$pdf->Ln();
$pdf->Cell(195,7,"Receipt For : ".$fullname,1,0,'C');
$pdf->Ln();
$pdf->Cell(156,7,"Customer Signature",0,0,'C');
$pdf->Cell(39,7,"",1,0,'C');
$pdf->Ln();
$pdf->Cell(156,7,"Customer Signature",0,0,'C');
$pdf->Cell(39,7,"",1,0,'C');
$pdf->Output("test.pdf");
echo $email;
?>