Help with a complex expression in a client side formatter

This is what I am trying to do

On the left we have list of extras, each has a price and a quantity. If the quantity is greater than 0 it adds it to the right hand side, if the quantity is more than 1 it multiplies the price by the quantity.

There is also a base price of the accommodation shown at the top right in this case 185

I now want to show the order total, and have it update as the user enters quantities on the left.

As you can see on the bottom right i have a total showing 185154.25 so basically my formatter has concatenated the 2 prices together instead of adding them to each other to give a total of 339.25

this is how the 185 part is calculated

sc_site_layout_checker_selected_room.data.query_selected_room.prices.where(`wvrsp_year`, sc_site_layout_checker.data.query_this_wedding.wvw_wedding_date.formatDate('yyyy'), '==').values('wvrsp_price')

As each year has a different price it needs to get the correct pricing based upon when the wedding is being held, which could easily be 2 years from now, this part works great.

The second part 154.25 also works perfectly with this

scf_room_booking_payment.repeat_room_detail_extras.items.where(`inp_wve_description.value`, 1, '>=').sum(`inp_wve_description_price.value*inp_wve_description.value`)

This calculates all xtra quantity prices where the quantity is greater than 0, and then sums the price multiplied by the quantity. As I mentioned this is calculating perfectly too.

This is when the problem comes in, adding the result of expression 1 with expression 2, i have tried. few ways, but none of them are working, however this one makes the most sense to me

((sc_site_layout_checker_selected_room.data.query_selected_room.prices.where(`wvrsp_year`, sc_site_layout_checker.data.query_this_wedding.wvw_wedding_date.formatDate('yyyy'), '==').values('wvrsp_price'))+(scf_room_booking_payment.repeat_room_detail_extras.items.where(`inp_wve_description.value`, 1, '>=').sum(`inp_wve_description_price.value*inp_wve_description.value`)))

However as you can see in the screenshot, that concatenates my 2 prices instead of adding them together. If I try fix it using the Wappler formatter i get the following error.

And I am getting no console log error.

Anyone got any ideas.

Have you tried converting to a number first?

1 Like

I did give it a try Ben, on one side and then the other and then on both but I get console log error of

parser.js:829 Formatter toNumber in expression [(((sc_site_layout_checker_selected_room.data.query_selected_room.prices.where(`wvrsp_year`, sc_site_layout_checker.data.query_this_wedding.wvw_wedding_date.formatDate('yyyy'), '==').values('wvrsp_price')).toNumber())+((scf_room_booking_payment.repeat_room_detail_extras.items.where(`inp_wve_description.value`, 1, '>=').sum(`inp_wve_description_price.value*inp_wve_description.value`)).toNumber()))] doesn't exist for type number

Figured it out @ben, i did not realise but one side of the equation was outputting an array with a single item inside it of my number, and the other side was outputting just the number on its own, I altered the first part to

sc_site_layout_checker_selected_room.data.query_selected_room.prices.where(`wvrsp_year`, sc_site_layout_checker.data.query_this_wedding.wvw_wedding_date.formatDate('yyyy'), '==').values('wvrsp_price').sum()

now it is working as expected, and I suppose it makes sense now that i think about it because i was giving it 3 dates and then using the where to get the single date i needed, however the where clause could have also matched more than one entry in other scenarios, so needs to output an array even though in my case it was an array with a single item.

clear as mud to me now. lol

1 Like