Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
Hi all,

Today i have a little bit complicated issue .

Now for example i have this invoice :

Item Code  | Qty | Unit Price | Discount | Total
book-1     | 1   |     5      | 2        | 3
book-2     | 2   |     5      | 2        | 8
Accessories| 1   |     2      | 1        | 1

I have the following sql tables
* "items" which contains item_Code as PK.
item_code |
book-1
book-2
Accessories
* "accounts" which contains account_id as PK .
account_id |
books sales account
books discount account
accessories sales account
accessories discount account


* "item_account_type" which contains the following :
1- type_id As PK.
2- type_name.
this table is filled as follows :
type_id  |  type_name
1        |  Sales account
2        |  discount account

* "item_account" which contain the following :
1- type_id As FK
2- item_code As FK
3- account_id As FK
For examples , this is the item_account for the same above invoice .
type_id | item_code | acount_id
1        | book-1      | books sales account
2        | book-1      | books discount account
1        | book-2      | books sales account
2        | book-2      | books discount account
1        | Accessories | accessories sales account
2        | Accessories | accessories discount account

Now, you may noticed that book-1 and book-2 had the same accounts .

the above invoice should be translated to the following form by checking each item account and if it's sales or discount and calculating the sums where account_id and type is the same . this is what i want to know ( how to make it like this ) :

the final form should be like this :
Account_id                   | total 
books sales account          | 15 
books discount account       | 4
accessories sales account    | 2
accessories discount account | 1


My tables are built correctly , but how do i reach to this point and save it in sql tables called " Entry" ..

I hope that my question is clear and please let me know if you have any questions ..

Thanks for trying to help me :) :)
Posted
Updated 20-May-13 9:30am
v2
Comments
hadi_753 18-May-13 16:59pm    
I Forgot to mention that im using datagridview in my invoices and entry
Sergey Alexandrovich Kryukov 18-May-13 22:12pm    
If some question is expected, this is your question. Where is it?
—SA
hadi_753 19-May-13 2:26am    
my question is what is the way to translated the invoice above to the following form based on database tables :

the final form should be like this :
Account_id | total
books sales account | 15
books discount account | 4
accessories sales account | 2
accessories discount account | 1
ZurdoDev 20-May-13 15:42pm    
You need to reply to a user's comments so that they are notified. Please do not add new comments to your own question. Use the improve question link instead.
hadi_753 19-May-13 2:30am    
i have one idea .. but i don't know how to make it ...

my idea is : to make something like local table and check for account no for each item then fill the table... then make sum by account no

1 solution

That would be dictated by your application requirements, not our opinions.

You DID write up a complete set of requirements before you started this, didn't you? You know, something that documents the exact business processes, step-by-step, that you're writing code against??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900