![]() |
fhumanes 1/15/2022 |
Hello, I think it can be inspired by the example I did: https://fhumanes.com/blog/guias-desarrollo/guia-7-phprunner-sincronizar-actualizacion-entre-maestro-y-detalle/ If you do not get to solve it, you write me to my email and you tell me what version of Phprunner you use and I make an example (FREE) set to the information you have facilitated. Greetings, fernandohumanes@gmail.com |
T
|
thamestrader 1/15/2022 |
I have done something very similar in my applications.I tend to use the Before record added to do any processing to obtain data from other tables and to produce calcuated fields. I have found that, and this may have changed with later versions, that calculated fields need to be defined on the page i.e. calc_field as " ". Looking at how I use JSONLOAD Event - that tends to be for altering Whether/ How / Format of a field on the page, rather than affecting the actual contents of the field, the PHP code has to be in the Before Display Event and the Javascript code in the JSONLOAD Event. I have found with the various code or application generators I have used that the key to success is understanding the products 'in built' processing cycle and then designing my solutions to match that cycle, whenever I'm finding something is difficult or generating a lot of code (defeating the object) its useally because my design is not in sync with the inbuilt cycle. My understanding of PHPRunner is that with Master Detail relationship designs the inbuilt cycle is to search for something, produce a List page for the results, select a record and then include functionality to add a detail, find all the details, update the record selected etc. In the event that the search doesn't find a record then provide the option to add a new master record. This is prodably a rather simplistic definition - other users will no doubt be able to improve on this. You might find that a slight redesign of the application may make this simpler to code. Using the inbuilt Master/Detail functionality. Create a list page for the Names table, use the basic search to display all the names that 'match', with a large file of names this will be quicker that paging through a dropdown list, and opens up a range of search features with zero coding. Once the list page displays the names that match, include a button to add a Detail record, using custom view that will automatically lookup fields, use the Before Display Event to perform the data editting before its displayed and the Before record added to perform any data editing required based on data keyed in. Something else to consider is to have a unique (auto-increment) numeric record ID field on each table, and use this to link master and detail, rather than by Name given there could be many records for Smith, Brown, Jones etc You might also find one of the templates for Invoicing provides a solution for as the underlying concept seems similar. I've never used any templates as I've found it easier to go my own way. Good luck its a great product. UPDATE: I tend to think of the PHPRunner generated applications as 'Client-Server' because the application contains PHP and SQL code that runs on the Server; which in turn outputs HTML and Javascript code that is transmitted to the Clients web browser to be processed. I found it useful to determine which functionality was server and which was client as it helped in deciding which PHPRunner event should be used. |
T
|
thamestrader 1/16/2022 |
Further to my earlier post, I had an odd hour to spare so I made a working solution that does what you require, using out of the box functionality, and 13 lines of code to do the lookups and calculation required. Those 13 lines also include the code to check for a charge of duration on an edit, that requires a lookup for the charge rate (it might have changed) and the recalculation of the fee. I can't attach an export of the project to this post or a PDF of the PHPRunner screen prints showing the set up. The lookups are in the ADD Page // Get Name and Rate from Master The Fee calculation is in the Before record Added Event $values["Fee"] = $values["J_ChargeRate"] * $values["Duration"]; To satisfy your requirement thats all the code needed, I included the following code to for completeness. The EDIT Page has the follwoing code in the Before Record Updated Event if ($oldvalues["Duration"] <> $values["Duration"]) { Hope this helps - I'm happy to send you the PDF screen prints or project export if theres a way to do it. |