This topic is locked

I need help to make a calculation from 2 database fields

3/2/2009 12:19:16 PM
PHPRunner General questions
cyberjas2001 author

Look my problem is a complex way to calculate how many days a container has been staying on our yard and its payment, I have the following formula:
TO CALCULATE DAYS IN YARD

DaysInYard field (save this on the DB) = DateIn field (from database) (TIMESTAMP) - DateOut field (TIMESTAMP);
TO CALCULATE AMOUNT

if ContainerSize (from Database) <= 40

then

Amount (Driver has to pay) = DaysInYard 12;

else

Amount (Driver has to pay) = DaysInYard
15;
All this has to be done inside the EDIT FORM on PHPRunner.

I'll apreciate any feedback on this problem, thanks

J
Jane 3/3/2009

Hi,
useBefore record updated event on the Events tab for this purpose.

Here is a sample:

//TO CALCULATE DAYS IN YARD

$values["DaysInYard"] = (strtotime($values["DateIn"])-strtotime($values["DateOut"]))/(606024);
//TO CALCULATE AMOUNT


if ($values["ContainerSize"]<= 40)

$values["Amount"] = $values["DaysInYard"] 12;

else

$values["Amount"] = $values["DaysInYard"]
15;

cyberjas2001 author 3/3/2009

Thank you so much Jane!!!!, that help me a lot believe me.
Now I have this question, I have in my ADD FORM for TABLE COMPANY a field called ACCOUNT, is a checkbox, now if any Company has an account with us in the ADD FORM for TABLE CONTAINER the field called PAYMENT has to be locked to ACCOUNT and when he wants to take out a container should not pay anything.
And also i want to create a RECEIPT BUTTON in the EDIT FORM for CONTAINER, i was able to create the button and called and external page named RECEIPT.PHP but i'm trying to capture the ID number so I can grab the information from that record from the DATABASE.
Again, Thanks a lot...
I hope you can help me again....

J
Jane 3/4/2009

Hi,
please see my answers below:

  1. to hide PAYMENT field on the add page use Add page: Before display event on the Events tab.

    Select and check ACCOUNT field from TABLE COMPANY and then hide PAYMENT field if needed.

    Here is just a sample:
    $xt->assign("PAYMENT_fieldblock",false);


2. to add new button edit HTML code directly on the Visual Editor tab (in HTML mode).

cyberjas2001 author 3/4/2009

Ok i see but,

  1. I want to place this is inside a condition, here's my formula:
    if account = 0 then

    $xt->assign("PAYMENT_fieldblock",false);


Am I right? Remember that I'm taking ACCOUNT field from the COMPANY TABLE, and I'm adding a New Item on ADD PAGE for the CONTAINER TABLE.
2. I know how to add a button, i have this:

<INPUT class=button onclick="window.location.href='receipt.php';" type=button value=Receipt>


I want to open this on a New Window and the only question that I have is I want to capture the ID number from the EDIT PAGE so I can use it on my Receipt to grab the missing information from the database.
Any ideas? thanks again for the feedback

J
Jane 3/5/2009

Hi,
you need to select account values from company table manually before.

Here is just a sample:

global $conn, $strTableName;

$rs = CustomQuery("select account from company where ...");

$data = db_fetch_array($rs);

$account = $data["account"];

if ($account==0)

...


Regarding the second question.

Here is a sample:

<INPUT class=button onclick="window.location.href='receipt.php?id={$show_key1}';" type=button value=Receipt>