This topic is locked

Calculation Page

4/12/2020 7:23:26 PM
PHPRunner General questions
Spider Webster author

Hello <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=27288&image=1&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />

I have 3 tables but require an extra results page with calculations from the tables.
(1.) Table Expenses [list of all expenses individually like Advertising, Bank charges, Electricity, etc ] <<<< sum total on this is say £205,943

(2.) Table Machine List [list of all machines and their sizes like 125Tonne 200Tonne 80Tonne 50Tonne etc] <<<sum total of this is say 480Tonnes

(3.) Table Utilisation 365 days minus holidays 28 minus weekends 104 = 233 x weekly expected hours of 50hrs = 2423

These three tables are defined by the user with different values.
From the tables above I need a page where I can calculate the machine hourly charges based on total expenses (1.) divided by total machine sizes (2.) Divided by running hours (3.)
4th page requires:-

Table expense Sum £205,943 divided Table machine tonnage Sum 480 = 429 x machine size divided 2423

Then from Table (2.)

Table machine tonnage:-

125 x 429 = 53625 divided 2423 = £22.13

125 x 429 = 53625 divided 2423 = £22.13

90 x 429 = 38610 divided 2423 = £15.93

80 x 429 = 34320 divided 2423 = £14.16

35 x 429 = 15015 divided 2423 = £6.19

25 x 429 = 10725 divided 2423 = £4.42
I think I just need pointing in the right direction as to how to go about this, if not then would need someone who can crunsh it up for me?
Thank you
Spider Webster,.,.,

Sergey Kornilov admin 4/13/2020

Not really sure if I understand the exact question but it looks like you need to perform all these calculations in the code.
I guess this can be, for instance, an additional View page of one of those three tables. You can just remove everything you don't need, insert a code snippet and run your calculations there.

Spider Webster author 4/17/2020



Not really sure if I understand the exact question but it looks like you need to perform all these calculations in the code.
I guess this can be, for instance, an additional View page of one of those three tables. You can just remove everything you don't need, insert a code snippet and run your calculations there.


Thanks Sergey.
I have tried first using code snippets from the manual to get something that works. The examples don't seem to be quite right for what I'm after but have added some simple ones to my toolbox like current time and build number.

Im sure what I need would be fairly simple ☺
I need in this additional view a sum(Amount) from a table, the sum of Machine Tonnage.




Any help from anyone would be welcome ☺☺☺

need2sleepDevClub member 4/18/2020

On the Field's Page, click 'Properties' and then click 'Field Events' change 'Event' from "click" to "change".
Now click 'Add Event'
Put your calculations here using javascript and it will save it to the database.
Here is some documentation:
https://xlinesoft.com/phprunner/docs/field_events.htm

Spider Webster author 4/19/2020



On the Field's Page, click 'Properties' and then click 'Field Events' change 'Event' from "click" to "change".
Now click 'Add Event'
Put your calculations here using javascript and it will save it to the database.
Here is some documentation:
https://xlinesoft.com/phprunner/docs/field_events.htm


Thanks Need2sleep, I have looked at the documentation for that and not sure that its the right solution forward for me.

I have tables set up for users to input data (small not very big tables) I have then created a custom view with the intention of adding code snippets to collect information from the different tables, as Sergey suggests.
The custom view is a copy of one of the tables and I have summed one of the sums I require with SQL.
SELECT

SUM(Amount) AS Expense_Total,

Amount,

ownerid

FROM Expenses
But I require this with a code snippet as I also require a sum showing from another table and then further calculations. ☺

Sergey Kornilov admin 4/19/2020

It really hard to understand what kind of help you looking for. Right now it says "I have to perform a bunch of calculations and I don't know where to start" and it is not clear what kind of answer you looking for. I will help you split your question into a several smaller parts and make each part of the question more specific.

Spider Webster author 4/20/2020



It really hard to understand what kind of help you looking for. Right now it says "I have to perform a bunch of calculations and I don't know where to start" and it is not clear what kind of answer you looking for. I will help you split your question into a several smaller parts and make each part of the question more specific.


Thanks Sergey

I have followed your suggestion I have created a custom view page and deleted everything I don't need and added a code snippet.

First of all I am looking to show a sum from one of my tables "expenses" of the column "Amount". I have used the following:-
$sql = "select sum(Amount) as Stotal from Expenses ";

$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

echo "Expense Total: " . $data["Stotal"];
This has given me a result but it seems to be exactly twice the amount that it should be ie 417406 instead of the correct amount 208703?

Sergey Kornilov admin 4/20/2020

Though is not really a PHPRunner question it is a great example of the question that can be understood and helped with.
As a first step, run the following query manually against your database using the software like phpMyAdmin

select sum(Amount) as Stotal from Expenses


Once it returns correct results use the same query in your code snippet and it will do exactly the same thing.

Spider Webster author 4/20/2020



Though is not really a PHPRunner question it is a great example of the question that can be understood and helped with.
As a first step, run the following query manually against your database using the software like phpMyAdmin

select sum(Amount) as Stotal from Expenses


Once it returns correct results use the same query in your code snippet and it will do exactly the same thing.


Thanks Sergey, this highlighted what my problem was when I looked I realised that it was user group permissions etc that was causing double results. I had created two accounts and populated with dummy data of the same. The sql query was returning full results instead of results by ownerid. Will have to check out user group permissions.

Thanks for pointing me in right direction.

Spider Webster author 4/22/2020



Though is not really a PHPRunner question it is a great example of the question that can be understood and helped with.
As a first step, run the following query manually against your database using the software like phpMyAdmin

select sum(Amount) as Stotal from Expenses


Once it returns correct results use the same query in your code snippet and it will do exactly the same thing.


Code snippet seems to be working correctly but not adhering to ownerid security settings. I have checked all the security settings and users can see and edit their own data only.

The code snippet sums all user data, is there something I need to add to it to get it to sum just the current user data?

Sergey Kornilov admin 4/22/2020

Code snippet is just the code and it doesn't know anything at all about your project settings. You will have to write your code the way it only returns data for the current user.