4

I am using a pre defined php inventory manager. So in sales my data is getting stored this way:

[{"product_id":"8","total_number":"70","selling_price":"110"}]

enter image description here

To display these values in table I use the following code

$sub_total          =   0;
$invoice_entries    =   json_decode($row['invoice_entries']);
foreach ($invoice_entries as $row2):
    $sub_total  +=  ($row2->total_number * $row2->selling_price);                                       
endforeach;

$sub_total      =   $sub_total - ( $sub_total * ($row['discount_percentage'] / 100) );
$grand_total    =   $sub_total + ( $sub_total * ($row['vat_percentage'] / 100) );
echo $grand_total;

I get the desired output here which is the total value of the sale.

enter image description here

Now, I am trying to give a report feature which will show all the invoices with the client name, sale value. I want to calculate the total of all the invoices and show in a table row i.e. Total of $grand_total.

I am unable to understand how do I get that. Any java script could do it? I don't understand js well. So I have no clue if its possible with it or not.

Thanks in advance

4
  • Use a different inventory manager Commented May 15, 2015 at 5:59
  • @Strawberry : Good advice but not applicable right now as Client has already started to use it :) Commented May 15, 2015 at 6:11
  • create an variable simply name as $final_total, initial to 0 when reload page, $final_total += $grand_total on every row you get $grand_total value, then display it Commented May 15, 2015 at 6:38
  • @YuYenkan : Can you show how do I code it ? It will really be helpful Commented May 15, 2015 at 6:50

1 Answer 1

3

since you storing data in database, you can use another query to sum up all the grand_total from all the record you want to retrieve.

select sum(grand_total) from yourTable where yourFilter

if grand_total is sum up from another query, you can use nested select statement to do it.

http://www.mysqltutorial.org/mysql-subquery/

this link have some example on nested select.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.