You can directly generate invoice/ order/ quotes etc from database table using xInvoice. You can use this feature to integrate your application to generate the invoice pdf directly from your database. xInvoices comes with widely famous database abstraction script "PDOModel" (to know more about PDOModel click here) that allows you get data from database tables very easily and you can set this data to generate various parts of pdf as well as complete pdf. For example you can get company related data i.e. invoice from data from table and set it using setInvoiceFrom function. or you can write query to get complete pdf data.
Please note that if you are using the config file's data and also set data from database using the xInvoice functions then it replaces the same key data. Basically it merge the data from database and config file's data in this case. If you are not using any config file data or you don't want to replace data, then you can set any key (column name) as you want.
Below are two examples of how you can get the data from database and use it to generate
In first example, we are getting data from joining four different tables (customer, clients, ordertable and orderItem table) by using PDOModel executeQuery function. We need our db column names to have same name as of the our array of data in data file in order to replace the values, so we have modified the names of columns using the alias. We are using double underscore in the alias in order to break the column name for example order.invoice__no will be exploded in to "invoice" and "no" and it will replace the value of $data["invoice"]["no"]. You can set double underscore or any other character seperator in the config settings file.
In the second example, we are setting only a specific data for example form data. We are using pdocrud function to get the from data from the company table and setting it directly using the setInvoiceFromData();
$xinvoice = new Xinvoice(); //get pdo model object $pdomodelObj = $xinvoice->getPDOModelObj(); // Creating sql query with column names same as the array key names // we are using alias to create the same column names with double underscore // as database field seperator. Our system will use this to break it in column // name. You can change double underscore to different character seperator in config file. $data = $pdomodelObj->executeQuery("SELECT ot.order_number as invoice__no, ot.order_date as invoice__date, ot.order_due_date as invoice__due_date, ot.shipping as total__shipping, ot.tax as total__tax, ot.discount as total__discount, ot.order_total as total_grandtotal, ot.payment_method as payment__method1, co.company_name as from__name, co.address1 as from__address1, co.address2 as from_address2, co.city as from__city, co.country as from__country, co.state as from__state, co.email as from__email, cl.client_name as to__name, cl.address1 as to__address1, cl.address2 as to__address2, cl.city as to__city, cl.state as to__state, cl.country as to_country, cl.email as to__email, oi.item_name as item__name, oi.item_desc as item__desc, oi.item_qty as item__qty, oi.item_qty as item__qty, oi.item_rate as item__rate, oi.item_total as item__total FROM ordertable as ot INNER JOIN order_items as oi on ot.order_id = oi.order_id INNER JOIN company as co on ot.company_id = co.company_id INNER JOIN clients as cl on ot.client_id = cl.client_id"); //set complete data $xinvoice->setInvoiceCompleteData($data); // Other option is change/set specific data for example replace 'from' data // $pdomodelObj->columns = array("company_name as name","address1","address2","email"); // $dataFrom = $pdomodelObj->select("company"); // $xinvoice->setInvoiceData($dataFrom,"from"); // $pdomodelObj->columns = array("company_name as name","address1","address2","email"); // $dataFrom = $pdomodelObj->select("company"); // $xinvoice->setInvoiceData($dataFrom,"from"); echo $xinvoice->render();