Best method to update another table

jo-ka

Member
Hello.
Please help me find the best way to do the following:

First, I have a table and form that stores member annual membership fees.

Table 1
id | member | value | in_debt | status (1, 2, 3)

For the status field, 1,2,3 are the values for unpaid, partially paid, fully paid.

So after I have a second table and form where all the movements are being stored

Table 2
id | member (dbjoin T1_member) | debt_value (calc from T1_value) (for info) | paid_value

So, as sometimes the paid value might be less than the debt_value, here's what I'm trying to achieve.

- If T2___paid_value = T1___in_debt then update T1___in_debt to 0 and T1___status to 3 (fully paid).

- If T2___paid_value < T1___in_debt then subtract (T1___in_debt - T2___paid_value) and update T1___in_debt with subtraction result, and, update T1___status to 2 (partially paid).

Is it possible to use the upsert plugin? If so, can you suggest some code for PHP?

Or the only option is to use the PHP form plugin?

Thank's in advance.
 
OK, some updates:

I'm trying to use the upsert form plugin bu it look's like the CONDITION field it's not working or, I can't figure out how to use it.

For the first situation I was trying to put this condition:

{T2___paid_value} === {T1___in_debt};

At first sight it looks like it was working but, after, i tried with a different condition:

{T2___paid_value} != {T1___in_debt};

And the values were updated also, when it should be failing as the condition returns false.

Also, for debugging I've tried something like:

{T2___paid_value} = 'aaa' and the values were updated also.

So, or there's something wrong with my condition, or the plugin have some bug. I've updated from github but the result was the same, so I assume that I'm doing something wrong with the condition.

Can you help please?

Thank's in advance.
 
The condition will only understand placeholders from the first table, as that's the one being submitted. As the condition runs before the plugin does, it has no knowledge of the table being updated, or what row you want from it.

You're better off rolling your own code in a PHP plugin.

-- hugh
 
Dear hugh, thanks for the update.

I hope i can find a way of doing it via PHP. I'm going to check out the forum for some PHP code examples.

Thank you.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top