forked from hewagekasunthilina/Pharmacy-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cashier_mail.php
195 lines (161 loc) · 7.32 KB
/
Cashier_mail.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
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
$mysqli = new mysqli('localhost', 'root', '', 'nimedco') or die(mysqli_error($mysqli));
$inID = $mysqli->query("SELECT id FROM cashierinvoice ORDER BY id DESC LIMIT 1") or die($mysqli->error);
$rowinID = $inID->fetch_array();
$email = $_POST['email'];
try {
//Server settings
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'nimedco.pharmacy@gmail.com'; // SMTP username
$mail->Password = 'nimedco@123'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('nimedco.pharmacy@gmail.com', 'Nimedco Pharmacy');
$mail->addAddress($email); // Add a recipient
// Name is optional
//$mail->addReplyTo($email);
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
// Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Invoice id : '.$rowinID['id'];
$id = $rowinID['id'];
$result = $mysqli->query("SELECT * FROM cashierinvoiceitem WHERE invoiceID='$id'") or die($mysqli->error);
//$mail->Body = 'a';
$mail->Body .='<font size="6" color="#2B65EC">Nimedco Pharmacy</font><br>';
$mail->Body .='No:33, Gampaha Road, Meerigama, Sri Lanka.<br><a href="www.nimedco.lk">www.nimedco.lk</a><br>+94 770 828 319<br>';
$mail->Body .='<font size="5" color="#571B7E">Invoice id : '.$rowinID['id'].'</font>';
$mail->Body .='<table border="0" width="70%">';
$mail->Body .='<tr bgcolor="#ffb3b3" align="center">';
$mail->Body .= '<td>#</td><td colspan="4">PRODUCT</td><td>QTY</td><td>PRICE</td><td>AMOUNT</td>';
$mail->Body .='</tr>';
//$mail->Body .= "First Name: <br>" ;
$c = 1;
while($row = $result->fetch_assoc()){
$mail->Body .='<tr bgcolor="yellow" align="center">';
//$ItemID = $row['ItemID'] ;
//$mail->Body .= $c.'.';
//$mail->Body .= ' ';
//$mail->Body .= $row['ItemID'];
//$mail->Body .= ' ';
//$mail->Body .= '<b>'.$item['ItemName'].'</b>';
//$mail->Body .= ' ';
//$mail->Body .= $item['Description'];
//$mail->Body .= ' ';
//$mail->Body .= $item['Category'];
//$mail->Body .= ' ';
//$mail->Body .= '(  '.$row['ItemQuantity'].'   x  '.$item['Price'].'  )';
//$mail->Body .= '  ';
//$mail->Body .= $row['Total'];
$mail->Body .= '<td>';
$mail->Body .= $c;
$mail->Body .= '</td>';
$mail->Body .= '<td>';
$mail->Body .= $row['ItemID'];
$mail->Body .= '</td>';
$ItemID=$row['ItemID'];
$itemd = $mysqli->query("SELECT * FROM stockitem WHERE ItemID='$ItemID'") or die($mysqli->error);
$item = $itemd->fetch_array();
$mail->Body .= '<td>';
$mail->Body .= '<b>'.$item['ItemName'].'</b>';
$mail->Body .= '</td>';
$mail->Body .= '<td>';
$mail->Body .= $item['Description'];
$mail->Body .= '</td>';
$mail->Body .= '<td>';
$mail->Body .= $item['Category'];
$mail->Body .= '</td>';
$mail->Body .= '<td>';
$mail->Body .= '<b>'.$row['ItemQuantity'].'</b>';
$mail->Body .= '</td>';
$mail->Body .= '<td>';
$mail->Body .= $item['Price'];
$mail->Body .= '</td>';
$mail->Body .= '<td align="right">';
$mail->Body .= '<b>'.$row['Total'].'</b>';
$mail->Body .= '</td>';
$mail->Body .='</tr>';
//$mail->Body .= '<br>';
$c++;
}
$subTot = $mysqli->query("SELECT * FROM cashierinvoice WHERE id='$id'") or die($mysqli->error);
$subTota = $subTot->fetch_array();
$mail->Body .='<tr bgcolor="#00ffbf">';
$mail->Body .='<td colspan="7" align="right">';
$mail->Body .='<font size="4">Sub Total:</font>';
$mail->Body .='</td>';
$mail->Body .='<td align="right">';
$mail->Body .='<font size="4">'.$subTota['subTotal'].'</font>';
$mail->Body .='</td>';
$mail->Body .='</tr>';
$mail->Body .='<tr bgcolor="#7FFFD4">';
$mail->Body .='<td colspan="7" align="right">';
$mail->Body .='<font size="3">Discount:</font>';
$mail->Body .='</td>';
$mail->Body .='<td align="right">';
$mail->Body .='<font size="3">'.$subTota['discount'].' %'.'</font>';
$mail->Body .='</td>';
$mail->Body .='</tr>';
$mail->Body .='<tr bgcolor="#ADFF2F">';
$mail->Body .='<td colspan="7" align="right">';
$mail->Body .='<font size="6">Net Total:</font>';
$mail->Body .='</td>';
$mail->Body .='<td align="right">';
$mail->Body .='<font size="6">'.$subTota['netTotal'].'</font>';
$mail->Body .='</td>';
$mail->Body .='</tr>';
$mail->Body .='<tr bgcolor="#7FFFD4">';
$mail->Body .='<td colspan="7" align="right">';
$mail->Body .='<font size="2">Cash:</font>';
$mail->Body .='</td>';
$mail->Body .='<td align="right">';
$mail->Body .='<font size="2">'.$subTota['CashAmt'].'</font>';
$mail->Body .='</td>';
$mail->Body .='</tr>';
$mail->Body .='<tr bgcolor="#7FFFD4">';
$mail->Body .='<td colspan="7" align="right">';
$mail->Body .='<font size="2">Balance:</font>';
$mail->Body .='</td>';
$mail->Body .='<td align="right">';
$mail->Body .='<font size="2">'.$subTota['ChangeAmt'].'</font>';
$mail->Body .='</td>';
$mail->Body .='</tr>';
$mail->Body .='<tr bgcolor="#7FFFD4">';
$mail->Body .='<td colspan="7" align="right">';
$mail->Body .='<font size="3">No of Items:</font>';
$mail->Body .='</td>';
$mail->Body .='<td align="right">';
$qt = $c-1;
$mail->Body .='<font size="3">'.$qt.'</font>';
$mail->Body .='</td>';
$mail->Body .='</tr>';
$mail->Body .='</table>';
$mail->Body .='<font size="4" color="red">Thank you !</font>';
//$mail->msgHTML("
//<html>
//<body>
//</body>
//</html>");
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
//header("location: CashierInvoice.php");
?>