So bascially I’ve been creating a site for a my dad friend who own a garage so he can go in and create his own invoices. I’ve done all of the forms and the background PHP to save to the server however I also want the function to print the invoice or send the invoice by email to the customer.
So my question is whats the best way to go about it? I have tried normal HTML emails but with the lack of possible styling I doubt I will be able to get what I want to achieve. I was messing around with FPDF but same again I would like to create the PDF invoice from a master template then send the customers copy via e-mail. This is pretty new I’ve been playing around with the PHP creating login systems for the site as well as a page that keeps track of tasks in the garage but I have absolutely no idea on where to even start. I already have an invoice I just use to type into on excel so I have a template of what I want it to look like!
Below is the code I have the inputs into the database, preferable would like the functions to be in there so it’s all under one roof. Any help would be greatly appreciated!
<?php
if(isset($_POST['createemail'])){
// get main stuff
$conn = mysqli_connect('localhost', 'root', 'Ju5tM@tt3x', 'cheshirewest');
$vrm = mysqli_real_escape_string($conn, $_POST['vrm']);
$make = mysqli_real_escape_string($conn, $_POST['make']);
$model = mysqli_real_escape_string($conn, $_POST['model']);
$mileage = mysqli_real_escape_string($conn, $_POST['mileage']);
$date = mysqli_real_escape_string($conn, $_POST['date']);
$firstname = mysqli_real_escape_string($conn, $_POST['firstname']);
$lastname = mysqli_real_escape_string($conn, $_POST['lastname']);
$housenumber = mysqli_real_escape_string($conn, $_POST['housenumber']);
$postcode = mysqli_real_escape_string($conn, $_POST['postcode']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$contactnumber = mysqli_real_escape_string($conn, $_POST['contactnumber']);
$work1 = mysqli_real_escape_string($conn, $_POST['work1']);
$work2 = mysqli_real_escape_string($conn, $_POST['work2']);
$work3 = mysqli_real_escape_string($conn, $_POST['work3']);
$amount1 = mysqli_real_escape_string($conn, $_POST['amount1']);
$amount2 = mysqli_real_escape_string($conn, $_POST['amount2']);
$amount3 = mysqli_real_escape_string($conn, $_POST['amount3']);
$hours = mysqli_real_escape_string($conn, $_POST['hours']);
$charged = mysqli_real_escape_string($conn, $_POST['charged']);
$gtotal = mysqli_real_escape_string($conn, $_POST['gtotal']);
$other = mysqli_real_escape_string($conn, $_POST['other']);
$sqlinsert = "INSERT INTO invoices (VRM, make, model, mileage, invoicedate, firstname, lastname, housenumber, postcode, email, contactnumber,work1, amount1, work2, amount2, work3, ammount3, labour, rate, total, other) VALUES ('$vrm','$make','$model','$mileage','$date','$firstname','$lastname','$housenumber','$postcode','$email','$contactnumber','$work1','$amount1','$work2','$amount2','$work3','$amount3','$hours','$charged','$gtotal','$other')";
mysqli_query($conn, $sqlinsert);
header("Location: ../createinvoice.php?create=success");
exit();
//echo $sqlinsert;
} elseif(isset($_POST['createprint'])){
//POST Values
$vrm = mysqli_real_escape_string($conn, $_POST['vrm']);
$make = mysqli_real_escape_string($conn, $_POST['make']);
$model = mysqli_real_escape_string($conn, $_POST['model']);
$mileage = mysqli_real_escape_string($conn, $_POST['mileage']);
$date = mysqli_real_escape_string($conn, $_POST['date']);
$firstname = mysqli_real_escape_string($conn, $_POST['firstname']);
$lastname = mysqli_real_escape_string($conn, $_POST['lastname']);
$housenumber = mysqli_real_escape_string($conn, $_POST['housenumber']);
$postcode = mysqli_real_escape_string($conn, $_POST['postcode']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$contactnumber = mysqli_real_escape_string($conn, $_POST['contactnumber']);
$work1 = mysqli_real_escape_string($conn, $_POST['work1']);
$work2 = mysqli_real_escape_string($conn, $_POST['work2']);
$work3 = mysqli_real_escape_string($conn, $_POST['work3']);
$amount1 = mysqli_real_escape_string($conn, $_POST['amount1']);
$amount2 = mysqli_real_escape_string($conn, $_POST['amount2']);
$amount3 = mysqli_real_escape_string($conn, $_POST['amount3']);
$hours = mysqli_real_escape_string($conn, $_POST['hours']);
$charged = mysqli_real_escape_string($conn, $_POST['charged']);
$gtotal = mysqli_real_escape_string($conn, $_POST['gtotal']);
$other = mysqli_real_escape_string($conn, $_POST['other']);
//SQL Save
$sqlinsert = "INSERT INTO invoices(VRM, make, model, mileage, date, firstname, lastname, housenumber, postcode, email, contactnumber, work1, amount1, work2, amount2, work3, ammount3, labour, rate, total, other) VALUES('$vrm','$make','$model','$mileage','$date','$firstname','$lastname','$housenumber','$postcode','$email','$contactnumber','$work1','$amount1','$work2','$amount2','$work3','$amount3','$hours','$charged','$gtotal','$other');";
mysqli_query($conn, $sqlinsert);
header("Location: ../createinvoice.php?create=success&emailsent");
exit();
} else {
header("Location: ../createinvoice.php?erroroccurred");
exit();
};