Page 1 of 1

Generate PDF Invoice from Master/Detail

Posted: Mon Feb 05, 2018 6:19 pm
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.


Re: Generate Invoice from Master/Detail

Posted: Tue Feb 06, 2018 10:09 am
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.


Re: Generate Invoice from Master/Detail

Posted: Tue Feb 06, 2018 4:31 pm
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.


Re: Generate Invoice from Master/Detail

Posted: Wed Feb 07, 2018 12:18 pm
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".


Re: Generate Invoice from Master/Detail

Posted: Wed Feb 07, 2018 7:10 pm
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.


Re: Generate Invoice from Master/Detail

Posted: Thu Feb 08, 2018 10:56 am
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.


Re: Generate Invoice from Master/Detail

Posted: Thu Feb 08, 2018 10:12 pm
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.


Re: Generate Invoice from Master/Detail

Posted: Sat Feb 10, 2018 6:11 pm
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

}


Re: Generate Invoice from Master/Detail

Posted: Tue Feb 13, 2018 9:36 pm
by Fakiro82

I resolve it.

Thank you so much,
Andrea.


Re: Generate PDF Invoice from Master/Detail

Posted: Tue Mar 20, 2018 9:14 pm
by dh1340

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