Pushing calculated data to database on change

Pushing calculated data to database on change

marcusa007marcusa007 Posts: 26Questions: 4Answers: 0

I have the following code running:

{ data: null,
"render": function(data, type, row){
var invoice_amt = (data.vendor_billing['billable_hours'] * data.vendor_billing['rate']);
return invoice_amt;
}
}

Billable hours and the rate calculates the invoice amount field automatically and displays it correctly.
I would like to push the calculated value to the database to be stored anytime it changes. I have tried naming the data field vendor_billing.hours_invoiced amount but that breaks the calculation and with null it does not update the database.
How would I go about doing this?

Replies

  • allanallan Posts: 62,109Questions: 1Answers: 10,183 Site admin

    How are you currently submitting information to the server? Are you using Editor and its PHP or .NET libraries, or something else?

    Thanks,
    Allan

  • marcusa007marcusa007 Posts: 26Questions: 4Answers: 0

    I am using Editor and it's the PHP library. I also have inline editing on the fields.

  • allanallan Posts: 62,109Questions: 1Answers: 10,183 Site admin

    The columns.render function is client-side only, so what I would suggest here is that you use a server-side event to calculate the value when creating or editing an entry and have that use $editor->field(...)->setValue(...);.

    What I don't get though is why you want to store a number you are just going to calculate anyway?

    Allan

  • marcusa007marcusa007 Posts: 26Questions: 4Answers: 0

    Thanks, Allan. My thought is to store the calculated value in the database so if the rate ever changes the previously stored sums will not change. They have to always stay as they have originally been calculated and paid.

This discussion has been closed.