This topic is locked

Check sum of detail records

11/23/2006 6:46:55 AM
PHPRunner General questions
D
daniel author

Can anyone give me a solution to the following situation?
I've got a master table ("fct_kontrolle_kopf") holding the quantity of items produced ("menge_kontrolliert") and the quantity of good items ("menge_io").

On the detail page ("fct_kontrolle_posten") a user adds several records that store the quantities of bad items ("menge_fehler") in several records (every record corresponds to a different reason).

Example:
Master: 100 items produced, 80 of them OK

Detail: 10 have wrong color, 7 are broken, 3 are too small
When a user types in a detail record, there should be a check, if all bad items on the detail page have been added: is ("fct_kontrolle_kopf.menge_kontrolliert" - "fct_kontrolle_kopf.menge_io") > sum("fct_kontrolle_posten.menge_fehler")? As long as the result is "true", a message should be displayed, saying "Please enter the the remaining records.".
What is the appropriate way to do this? Thanks again for your help, my project is getting better every day <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=3942&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
Daniel

J
Jane 11/23/2006

Daniel,
you can do it using events.

Proceed to the Events tab, select After record updated event and add your code in it.

Here is a sample code:

function AfterAdd()

{

global $conn, $strTableName;

$str1 = "select sum(menge_fehler) from fct_kontrolle_posten where FieldName1=".$_SESSION[$strTableName."_masterkey1"];

$rs1 = db_query($str1,$conn);

$data1=db_fetch_numarray($rs1);
$str2 = "select menge_kontrolliert,menge_io from fct_kontrolle_kopf where FieldName2=".$_SESSION[$strTableName."_masterkey1"];

$rs2 = db_query($str2,$conn);

$data2=db_fetch_array($rs2);
if ($data1 && $data2)

{

if ($data2["menge_kontrolliert"]-$data["menge_io"]>$data[0])

echo "Please enter the the remaining records.";

}

}



where FieldName1 is a foreign key in the fct_kontrolle_posten table, FieldNames is a primary key in the fct_kontrolle_kopf table.

D
daniel author 11/24/2006

Perfect, thank you very much <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=13169&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />

Right now the message is located just on top of the page - how can i relocate the message? I tried to insert

{doevent name="AfterAdd"}{$message}

in my php-file, but then I get the same message several times...

J
Jane 11/24/2006

Daniel,
you can do the following:

  • replace this line in the AfterAdd event:

    echo "Please enter the the remaining records.";

    with this one:

    $_SESSION["mess"] = "Please enter the the remaining records.";
  • add AddOnLoad event with this code:
    function AddOnLoad()

    {

    echo $_SESSION["mess"];

    $_SESSION["mess"] = "";

    }


  • drag and drop AddOnLoad event to the end of the ADD page on the Visual Editor tab.

D
daniel author 11/24/2006

Jane,
thanks a lot. Everything is just as I wanted it to be. PHPrunner and your help made me establish a complete front-end without learning php, that's great.
Thanks again

Daniel