CalcBuilder Forum

Can matrix values used for any calculation you want

Usuario adk 2018-11-03 10:29:48

I want to make use of matrix values for different calculations.

We have created price calculations for similar products:
Price calculation product 1
Price calculation product 2

These price calculation make use of the same prices per kilogram for different materials. So we want to make a matrix $prices with the data:
material1=price1
material2=price2

Is it possible to use the values of the matrix $prices in both price calculations?

Or with other words : is it possible to create a "central" matrix which values can be recovered in any calculation you want?

Moonsoft support 2018-11-05 11:03:30

Hi,
very interesting question, you have one way to share information among different calculators, using a query to the general database at your code section. If you have one matrix created called 'prices', and you want to use it in another calculator, you can try to include this code below


$db =JFactory::getDBO();
$db->setQuery("select value from #__calcbuilder_matrix where var='prices'");
eval("$prices=".$db->loadResult().";");

/*
At this point you can use
$prices
matrix same as you were working with the calculator this matrix belongs to
*/


Hope this helps

Usuario adk 2018-11-05 17:47:27

I am not sure if I have understood it correctly because it does not work yet.

I have created a calculator with the name: general
In this calculator I have created a matrix with the name : prices.
The colomn name of this matrix : price
And row names are : material1, material2,... and so on.

I have created another calculator with the name: pricecalulator product 1
In this calculator I want to calculate the price of a aluminium profile by multiplying the weight of the profile with the price per kilogram of the profile.

Question 1. Do I have to paste the next code into the code section of the calculator with the name : general ? Or in the pricecalculator product 1?
$db =JFactory::getDBO();
$db->setQuery("select value from #__calcbuilder_matrix where var='prices'");
eval("$prices=".$db->loadResult().";");

Question 2. Is the next PHP code correct when I want to recover the price of material1 to calculate the $profileprice based on the $profileweight in the calculator with the name : pricecalulator product 1
$profileprice=$prices*$profileweight;

Regards,
AdK

Moonsoft support 2018-11-06 09:56:23

Hi,
1. the code should be placed at the code section of the calculator 'product1' (just at the beginning). Please copy it again, the forum content sometimes strips out some special chars, here the right lines:


$db =JFactory::getDBO();
$db->setQuery("select value from #__calcbuilder_matrix where var='prices'");
eval("\$prices=".$db->loadResult().";");


2. below these lines you can start to use the matrix 'prices', so this is correct:

$profileprice=$prices*$profileweight;

Please double check your matrix has the 'variable' set to 'prices' (and not only the name). If you can't get it working, please place a ticket at the helpdesk, where code can be shared without restrictions.

Thanks, regards

Usuario adk 2018-11-06 13:09:31

You forgot to put the backslash (\) in the last line of the code in your first reply on november 5th. With the blackslash it works perfect.

We are very happy we can share matrices between calculations.

Thank you very much for your help.

The code looks for me impressive, I could never wrote this code by myself.

Best regards
AdK

Moonsoft support 2018-11-07 09:53:18

Hi,
yes, the front-parser 'ate' the backslash, at the last entry we forced to show right. Great it worked, its a little bit tricky because of the format used to store, but you can use the same code in any other calculator now.

Regards