Generate PDF Invoice from Master/Detail

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Fakiro82
User
Posts: 108

Generate PDF Invoice from Master/Detail

Post by Fakiro82 »

Hi,
I try to generate invoice from Master/Detail Tables.
I know how to generate data from Master Table, but I don't know how to generate record from Detail Table.
Have someone any example? Or Can someone help me?

Thank you,
Andrea.


arbei
User
Posts: 9292

Post by arbei »

You can create a custom file with your layout and write the content to pdf.

So you can use ew_Execute or ew_ExecuteScalar to load the corresponding data from the database.

Read help file topic: "Server Events and Client Scripts" -> "Some Global Functions" for more information.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

I have a custom file.

My problem is to create a loop to insert record from Details Table. I need to read all record in Details Table and insert like Item in Invoice.

Can you help me?

Thank you.

Andrea.


arbei
User
Posts: 9292

Post by arbei »

In add item part, use Conn()->Execute() to retrieve records and loop it.

For example:
$rs = Conn()->Execute("SELECT * FROM <Detail TAble> WHERE <Condition>");
while (!$rs->EOF) {
// add the detail record to your PDF
$rs->MoveNext();
}

Read help file topic: "Server Events and Client Scripts" -> "Some Global Functions".


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi arbei,
I insert this code like your suggest:

/* Adding Items in table */


$rs = Conn()->Execute("SELECT * OrdersMaster INNER JOIN OrdersDetail ON OrdersMaster.OrderId = OrdersDetail.OrderId");
while (!$rs->EOF) {
//$invoice->addItem($GET["ItemCode"],$GET["Description"],$GET["Quantity"],$GET["Price"]$GET["Quantity"]22/100,$GET["Price"],0,$_GET["NetTotal"]);
$rs->MoveNext();
}

But I received the error : "Uncaught Error: Call to a member function Execute() on boolean. Stack Trace: #0 (main).
I use sql server like database.
Can you help me please?

Thank you so much,
Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

Fakiro82 wrote:
But I received the error : "Uncaught Error: Call to a member function Execute() on boolean. Stack Trace: #0 (main).

Make sure you have already enabled "Include common files" from your Custom File setup. Please read "Custom Files" topic from PHPMaker Help menu for more info and example.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

now I include common files and it work.

Now, when I generate Invoice.pdf, all fields ($GET["ItemCode"],$GET["Description"],etc...) in my code:

$invoice->addItem($GET["ItemCode"],$GET["Description"],$GET["Quantity"],$GET["Price"]$GET["Quantity"]22/100,$GET["Price"],0,$_GET["NetTotal"]);

are blank.

But if I substitute $GET["ItemCode"] with "TEST" it's ok. I think that the problem is in $GET["ItemCode"] or query. Can you help me please?

Thank you so much.

Andrea.


mobhar
User
Posts: 11660

Post by mobhar »

Make sure you have already included your if condition check by using PHP isset() function for your GET variable, for example:

if (isset($_GET["ItemCode"])) { // make sure the GET variable is already set and is not NULL
// ... your code goes below this line

}


Fakiro82
User
Posts: 108

Post by Fakiro82 »

I resolve it.

Thank you so much,
Andrea.


dh1340
User
Posts: 58

Post by dh1340 »

Hi Andrea, do you mind posting a detailed description for your solution ?
THX
david


Post Reply