Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //create connection with db
- $servername = "localhost";
- $username = "usertally";
- $password = "tally1234;";
- $database = "teller_manager";
- $con = mysqli_connect($servername, $username, $password, $database);
- //Select query
- $sql = "SELECT * FROM payment_details";
- //execute query
- $records = mysqli_query($con, $sql);
- require "pdf/fpdf.php";
- class myPDF extends FPDF
- {
- function header()
- {
- $this->SetFont('Arial', 'B', 14);
- $this->Cell(275, 6, 'TRIPS REPORT', 0, 0, 'C');
- $this->Ln();
- $this->SetFont('Times', '', 12);
- $this->Cell(275, 10, 'VEHICLES ON TRANSIT', 0, 0, 'C');
- $this->Ln(20);
- }
- function footer()
- {
- $this->SetY(-15);
- $this->SetFont('Arial', '', '8');
- $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
- }
- function headerTable()
- {
- $this->SetFont('Times', 'B', 10);
- $this->Cell(70, 12, 'Numberplate', 1, 0, 'C');
- $this->Cell(49, 12, 'Rate', 1, 0, 'C');
- $this->Cell(49,12, 'Amount', 1,0, 'C');
- $this->Cell(49,12, 'PassengerNo', 1,0, 'C');
- $this->Cell(70, 12, 'Destination', 1, 0, 'C');
- $this->Cell(49, 12, 'Origin', 1, 0, 'C');
- $this->Ln();
- }
- public function viewTable($number_plate,$rate,$amount,$passenger_no,$destination,$origin)
- {
- $servername = "localhost";
- $username = "usertally";
- $password = "tally1234;";
- $database = "teller_manager";
- $con = mysqli_connect($servername, $username, $password, $database);
- $sql2 = mysqli_query($con, "SELECT * FROM `payment_details` GROUP BY number_plate");
- $ress = mysqli_query($con,$sql);
- $response["sales"] = array();
- while( $row = mysqli_fetch_assoc($sql2)){
- $payments = array();
- $payments ["id"] = $row["id"];
- $payments ["number_plate"] = $row["number_plate"];
- $payments ["rate"] = $row["rate"];
- $payments ["destination"] = $row["destination"];
- $payments ["origin"] = $row["origin"];
- $sql3 = "SELECT SUM(amount) as amount,COUNT(*) as passenger_no FROM fare WHERE number_plate = '".$payments["number_plate"]."'";
- $ress = mysqli_query($con, $sql3);
- if($rowfare = mysqli_fetch_array($ress))
- {
- $payments ["amount"] = $rowfare["amount"];
- $payments ["passenger_no"] = $rowfare["passenger_no"];
- }
- }
- $this->SetFont('Times', '', 10);
- $this->Cell(70, 8, $number_plate, 1, 0, 'C');
- $this->Cell(49, 8, $rate, 1, 0, 'C');
- $this->Cell(49, 8, $amount, 1, 0, 'C');
- $this->Cell(49, 8, $passenger_no, 1, 0, 'C');
- $this->Cell(55, 8, $destination, 1, 0, 'C');
- $this->Cell(55, 8, $origin, 1, 0, 'C');
- $this->Ln();
- }
- }
- $pdf = new myPDF();
- $pdf->AliasNbPages();
- $pdf->AddPage('L', 'A4', 0);
- $pdf->headerTable();
- $pdf->viewTable($number_plate,$rate,$amount,$passenger_no,$destination,$origin);
- $attachment=$pdf->Output($filename,'F');
- // $name = "Name goes here";
- // $email = "someome@anadress.com";
- $to = "Emperor <mwaurawamichwe@gmail.com>";
- $from = "Teller Admin <Mouraa@zamzam45.com> ";
- $subject = "Teller Manager Report";
- $mainMessage = "Hello. Please find attached the report you requested.";
- $fileatt = "/home/qcuizarl75rs/public_html/tally_driver_copy/doc.pdf";
- $fileatttype = "application/pdf";
- $fileattname = "attachment1.pdf";
- $headers = "From: $from";
- // File
- $file = fopen($fileatt, 'rb');
- $data = fread($file, filesize($fileatt));
- fclose($file);
- // This attaches the file
- $semi_rand = md5(time());
- $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
- $headers .= "\nMIME-Version: 1.0\n" .
- "Content-Type: multipart/mixed;\n" .
- " boundary=\"{$mime_boundary}\"";
- $message = "This is a multi-part message in MIME format.\n\n" .
- "-{$mime_boundary}\n" .
- "Content-Type: text/plain; charset=\"iso-8859-1\n" .
- "Content-Transfer-Encoding: 7bit\n\n" .
- $mainMessage . "\n\n";
- $data = chunk_split(base64_encode($data));
- $message .= "--{$mime_boundary}\n" .
- "Content-Type: {$fileatttype};\n" .
- " name=\"{$fileattname}\"\n" .
- "Content-Disposition: attachment;\n" .
- " filename=\"{$fileattname}\"\n" .
- "Content-Transfer-Encoding: base64\n\n" .
- $data . "\n\n" .
- "-{$mime_boundary}-\n";
- // Send the email
- if(mail($to, $subject, $message, $headers)) {
- echo "The email was sent.";
- }
- else {
- echo "There was an error sending the mail.";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement