409 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • India
Dhruv says

Hello,

I am writing a invoice script, but don’t know how to go about this.

I have two tables i..e “invoice” and “invoice_items”

Here’s the table structure for invoice_items with demo content

id | invoiceid | title | qty | amount

1 | 1 | this is a new invoice item | 2 | 299

2 | 1 | this is another item | 1 | 399

3 | 1 | this is another item for invoice 1 | 1 | 600

4 | 2 | invoice 2 item | 1 | 600

What i want to do is

1. display all the invoice items related to invoiceid 1 – DONE

2. display total price for each invoice item (qty * amount) – DONE

3. Display grand total : i don’t know how to do this…(ran our of ideas)

So, can anyone help me out and guide me in the right direction??

181 posts
  • Bought between 100 and 499 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
Artillegence says

I suggest you to first learn php and MySql , you can find good tutorials of nettuts :)

409 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • India
Dhruv says

Well, i know both php and mysql, i just don’t know how to go about this..,

I mean first i have to loop through all invoice_items table, after that i have to select invoice_items with invoiceid 1, after doing this i have to multiply amount with qty and then display all these data

At the end, i have to add all the amount i..e total price (in this case 3) and display it as grand total.

BTW , I know i can / will find goood tutorials at nettuts :D

409 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • India
Dhruv says

@5thSenseLabs

I see you are releasing an Invoice Management Application by next week,

Even i am planning to launch my Application by next week (max 2 weeks), so you can be sure of some competition :) (atleast a little.)

181 posts
  • Bought between 100 and 499 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
Artillegence says

I hav been working on my application for 3 weeks now, should be releasing this weekend.. :P .. as far as the table is concerned, I think you are confused about how to work with invoice items in the table, for that just create a column invoice_item add the items separated by example comma, use php explode function to work with them… no need for 2 tables

409 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • India
Dhruv says

This is exactly(sort of) what i was looking for earlier.., but i will use it now.

Can you post some screenshots or demo of your app??? :D

181 posts
  • Bought between 100 and 499 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
Artillegence says

sure here it is … http://twitpic.com/25utz5 , it has invoice, client, project, estimate and events management 8-)

409 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • India
Dhruv says

Looks Great. Have you made use of jquery/ajax or not?

499 posts
  • Canada
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Has been a member for 5-6 years
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
TutelageSystems says
I hav been working on my application for 3 weeks now, should be releasing this weekend.. :P .. as far as the table is concerned, I think you are confused about how to work with invoice items in the table, for that just create a column invoice_item add the items separated by example comma, use php explode function to work with them… no need for 2 tables

Or instead of explode you could also use serialize / unserialize.

Not to take over the thread or anything have either of you checked out Invoice Bubble?

Back on track, so you say you have two tables. You could do this in php or MySQL.

PHP

I haven’t tested this, and it isn’t fully completed or anything but just helping along the tracks.
// grab invoice
$invoice = $Invoices->get(1);  // Invoice Class returns Invoice Information for Invoice 1
$invoice_items = $Invoices->getItems(1); // Same as above
// Both of these return an Array
$grand_total = 0;

foreach($invoice_items as $item)
{
  $grand_total += ($item['qty'] * $item['amount'];)
}
The other way you can do this is using SQL to create a column
select title, qty, amount, (qty * amount) as total from invoice_items where invoiceid = 1
181 posts
  • Bought between 100 and 499 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
Artillegence says

@dhruv yup jQuery interface ... and @TutelageSystems serialize is also a good solution nice one buddy ;) , not much of use in my app so didnt mentioned it :P

by
by
by
by
by
by