Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
1,849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. <?php
  2.  
  3. //create connection with db
  4.  
  5. $servername = "localhost";
  6. $username = "usertally";
  7. $password = "tally1234;";
  8. $database = "teller_manager";
  9. $con = mysqli_connect($servername, $username, $password, $database);
  10.  
  11.  
  12.  
  13. //Select query
  14. $sql = "SELECT * FROM payment_details";
  15.  
  16. //execute query
  17. $records = mysqli_query($con, $sql);
  18.  
  19. require "pdf/fpdf.php";
  20. class myPDF extends FPDF
  21. {
  22. function header()
  23. {
  24. $this->SetFont('Arial', 'B', 14);
  25. $this->Cell(275, 6, 'TRIPS REPORT', 0, 0, 'C');
  26. $this->Ln();
  27. $this->SetFont('Times', '', 12);
  28. $this->Cell(275, 10, 'VEHICLES ON TRANSIT', 0, 0, 'C');
  29. $this->Ln(20);
  30. }
  31.  
  32. function footer()
  33. {
  34. $this->SetY(-15);
  35. $this->SetFont('Arial', '', '8');
  36. $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
  37. }
  38.  
  39. function headerTable()
  40. {
  41.  
  42. $this->SetFont('Times', 'B', 10);
  43. $this->Cell(70, 12, 'Numberplate', 1, 0, 'C');
  44. $this->Cell(49, 12, 'Rate', 1, 0, 'C');
  45. $this->Cell(49,12, 'Amount', 1,0, 'C');
  46. $this->Cell(49,12, 'PassengerNo', 1,0, 'C');
  47. $this->Cell(70, 12, 'Destination', 1, 0, 'C');
  48. $this->Cell(49, 12, 'Origin', 1, 0, 'C');
  49. $this->Ln();
  50. }
  51.  
  52. public function viewTable($number_plate,$rate,$amount,$passenger_no,$destination,$origin)
  53. {
  54. $servername = "localhost";
  55. $username = "usertally";
  56. $password = "tally1234;";
  57. $database = "teller_manager";
  58. $con = mysqli_connect($servername, $username, $password, $database);
  59.  
  60.  
  61. $sql2 = mysqli_query($con, "SELECT * FROM `payment_details` GROUP BY number_plate");
  62.  
  63. $ress = mysqli_query($con,$sql);
  64. $response["sales"] = array();
  65.  
  66. while( $row = mysqli_fetch_assoc($sql2)){
  67. $payments = array();
  68.  
  69. $payments ["id"] = $row["id"];
  70. $payments ["number_plate"] = $row["number_plate"];
  71. $payments ["rate"] = $row["rate"];
  72. $payments ["destination"] = $row["destination"];
  73. $payments ["origin"] = $row["origin"];
  74.  
  75. $sql3 = "SELECT SUM(amount) as amount,COUNT(*) as passenger_no FROM fare WHERE number_plate = '".$payments["number_plate"]."'";
  76.  
  77. $ress = mysqli_query($con, $sql3);
  78. if($rowfare = mysqli_fetch_array($ress))
  79. {
  80. $payments ["amount"] = $rowfare["amount"];
  81. $payments ["passenger_no"] = $rowfare["passenger_no"];
  82. }
  83.  
  84. }
  85. $this->SetFont('Times', '', 10);
  86. $this->Cell(70, 8, $number_plate, 1, 0, 'C');
  87. $this->Cell(49, 8, $rate, 1, 0, 'C');
  88. $this->Cell(49, 8, $amount, 1, 0, 'C');
  89. $this->Cell(49, 8, $passenger_no, 1, 0, 'C');
  90. $this->Cell(55, 8, $destination, 1, 0, 'C');
  91. $this->Cell(55, 8, $origin, 1, 0, 'C');
  92. $this->Ln();
  93.  
  94. }
  95. }
  96.  
  97. $pdf = new myPDF();
  98. $pdf->AliasNbPages();
  99. $pdf->AddPage('L', 'A4', 0);
  100. $pdf->headerTable();
  101. $pdf->viewTable($number_plate,$rate,$amount,$passenger_no,$destination,$origin);
  102. $attachment=$pdf->Output($filename,'F');
  103.  
  104. // $name = "Name goes here";
  105. // $email = "someome@anadress.com";
  106. $to = "Emperor <mwaurawamichwe@gmail.com>";
  107. $from = "Teller Admin <Mouraa@zamzam45.com> ";
  108. $subject = "Teller Manager Report";
  109. $mainMessage = "Hello. Please find attached the report you requested.";
  110. $fileatt = "/home/qcuizarl75rs/public_html/tally_driver_copy/doc.pdf";
  111. $fileatttype = "application/pdf";
  112. $fileattname = "attachment1.pdf";
  113. $headers = "From: $from";
  114.  
  115. // File
  116. $file = fopen($fileatt, 'rb');
  117. $data = fread($file, filesize($fileatt));
  118. fclose($file);
  119.  
  120. // This attaches the file
  121. $semi_rand = md5(time());
  122. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  123. $headers .= "\nMIME-Version: 1.0\n" .
  124. "Content-Type: multipart/mixed;\n" .
  125. " boundary=\"{$mime_boundary}\"";
  126. $message = "This is a multi-part message in MIME format.\n\n" .
  127. "-{$mime_boundary}\n" .
  128. "Content-Type: text/plain; charset=\"iso-8859-1\n" .
  129. "Content-Transfer-Encoding: 7bit\n\n" .
  130. $mainMessage . "\n\n";
  131.  
  132. $data = chunk_split(base64_encode($data));
  133. $message .= "--{$mime_boundary}\n" .
  134. "Content-Type: {$fileatttype};\n" .
  135. " name=\"{$fileattname}\"\n" .
  136. "Content-Disposition: attachment;\n" .
  137. " filename=\"{$fileattname}\"\n" .
  138. "Content-Transfer-Encoding: base64\n\n" .
  139. $data . "\n\n" .
  140. "-{$mime_boundary}-\n";
  141.  
  142. // Send the email
  143. if(mail($to, $subject, $message, $headers)) {
  144.  
  145. echo "The email was sent.";
  146.  
  147. }
  148. else {
  149.  
  150. echo "There was an error sending the mail.";
  151.  
  152. }
  153.  
  154. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement