Hi Guys,
Looking for a bit of coding help with a query I am building. I have two tables, one contains all of the billable items that have been used by the specific user and the charges for said items and the other will contain the userID and a generated invoiceID and the BillableLine.
What I want to do now is bill them for the items, so the script will loop through all the charges in the billable items table and populate a second table with the grouped charges so everything can then be fpdf'd over from the cron. The problem I am facing is that I need to create an invoice ID and then use this ID for the invoice lines to th at I will be able to report using the invoiceID for each user.
include("../includes/config.php");
// Get's the last ID from the dsn_invoice_id field (Not an auto increment)
$sql2 = "SELECT dsn_invoice_id FROM DSN_invoices ORDER BY chargeID DESC LIMIT 1";
$result2 = mysqli_query($db, $sql2);while($row2 = mysqli_fetch_assoc($result2)) { $dsn_invoice_id = $row2["dsn_invoice_id"];}
// Get the list of charges / billale items
$sql1 = "SELECT userID, chargeID FROM posted_charges WHERE charge_processed = '0'";
$result1 = mysqli_query($db, $sql1); while($row1 = mysqli_fetch_assoc($result1)) { $userID = $row1["userID"];$chargeID = $row1["chargeID"];
// Insert the item, with an increment of + 1.
$sqlIns = "INSERT INTO dsn_invoice_id (dsn_invoice_id, userID, ChargeID) VALUES ('". ($currentnumber + 1) ."','$userID','$chargeID')";
}
Thanks for taking the time to read this!
Kind regards,