Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Transaction Patterns » Calculated fields
Calculated fields [message #4282] Mon, 23 June 2014 09:20 Go to next message
htManager is currently offline  htManager
Messages: 415
Registered: May 2014
Senior Member
Hi Tony,

can I automatically calculate a field with a method of the radicore framework?

I have three fields, amount_netto, amount_tax and amount_brutto.
I want that the field amount_brutto is calculated automatically after filling out the fields amount_netto and amount_tax.

I used to develop desktop applications in ObjectPAL, a language called Object orientet Paradox Apllication Language for the desktop database Paradox for Windows. In this language I would have put the code in an event of the amount_tax field. But in a web environment with Radicore and PHP I don't know how to do this.

Thanks in advance, best regards,

Juergen
Re: Calculated fields [message #4284 is a reply to message #4282] Tue, 24 June 2014 04:08 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
No, the framework cannot do such things for you automatically, you have to write the code yourself.

When reading from the database you can build the calculation into the SQL statement such as:
SELECT product_id, unit_price, quantity, SUM(unit_price * quantity) AS extended_price ...


Re: Calculated fields [message #4286 is a reply to message #4284] Tue, 24 June 2014 10:24 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 415
Registered: May 2014
Senior Member
Isn't there a possibility to change $fieldarray with a custom method (like i.e. _cm_getExtraData) when jumping with the Tabulator from field to field?
Re: Calculated fields [message #4288 is a reply to message #4286] Tue, 24 June 2014 11:53 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
No. Nothing is sent from the client browser to the application on the server until you press a SUBMIT button. That is how HTML works.

Re: Calculated fields [message #4291 is a reply to message #4288] Wed, 25 June 2014 11:04 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 415
Registered: May 2014
Senior Member
I changed my database schema by inserting a column with type boolean where you can decide if the field will be calculated or not.

You said that nothing is sent until the submit button is pressed. That's ok for me because I now want to calculate the values after having pressed the submit button.

I tried to put my code for changing the values in $fieldarray in the custom method _cm_preInsertorUpdate($rows) in the class file. I tried to change the values of $rows with $rows['column_name'] = 'foobar'. But I didn't succeed. Is this a possible way or not?

Or do I have to use another custom method?
Re: Calculated fields [message #4292 is a reply to message #4291] Wed, 25 June 2014 12:08 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
You need to look at http://www.tonymarston.net/php-mysql/functions-and-variables .html#sequence.of.events to see which custom methods are called, and in what sequence, for each transaction pattern. You will notice there that the _cm_pre_insertOrUpdate () method is *NOT* called when the pattern starts with insertRecord ($rowdata).

Re: Calculated fields [message #4312 is a reply to message #4292] Sat, 28 June 2014 09:15 Go to previous message
htManager is currently offline  htManager
Messages: 415
Registered: May 2014
Senior Member
Thank you very much. It works perfectly.
Previous Topic: eMail sent automatically
Next Topic: Dropdown list
Goto Forum:
  


Current Time: Thu Mar 28 11:23:16 EDT 2024

Total time taken to generate the page: 0.01100 seconds