Design Database schema for billing system - database-schema

I want to design a database for billing system. In one bill a customer might have purchased multiple different items ,for example fot bill Id 1 customer purchased 2 apples 3 bananas and 1 watermelon. i want to know how i can normalize this database.

This is a pretty standard, basic normalization exercise with a pretty standard solution. The usual approach is to have an orders table containing order ID, customer ID, order date &c., and an order_items table with a record for each line item on the order.

Related

Is there a better way to design an E-commerce products database when the products can have multiple price lines?

I'm trying to develop a new products database for a client and I am having a hard time finding a solution to handle the many different prices a product can have.
Variables that can affect the price of a product:
region (where the customer lives).
customer type (whether they're a new customer or a registered customer).
order type (whether you want to purchase the item once or subscribe monthly).
store type (there were many store types, but now they're transitioning to one, but I don't know if they will add more in the future again so I want this to be flexible
Product Table
id
product_name
sku
description
1
Vanilla Protein Powder
1111
This is a description...
Attributes Table
id
associate_type
region
store
currency_code
order_type
1
2
1
11
usd
1
2
2
1
11
usd
2
Product Attributes Table
id
price
product_id
attribute_id
1
49.95
1
1
2
29.95
1
2
I was initially thinking this would be a good route to go, but the issue that arises is on the product page I want to display the price of the product if you want to purchase it once and the price if you wanted to subscribe. The same issue would happen if I also wanted to show a list of product cards on a product category page displaying both prices.
The issue I run into
When I write a query to get the correct products with the correct price lines, I would filter all the products by the variables mentioned above, but I will always want the subscription price and the one-time price, so in the query, I would have to include WHERE order_type = 1 AND order_type = 2 but doing this would return duplicate records of the product/ products because of the different prices for a one-time purchase and a subscription purchase.
Is there a better way to set up the tables I have so that the query would not return duplicate records of the product/ products? Or is there a way to write the query to handle this for me? Or do I even need to switch up my database design altogether?

How to Display the Sales and Other Department Sales Seperatly on Tally

hope you all are good .I new to tally and I have a new situation ,I have provided the details below
1.we Own a supermarket and which contains some other departments as well
2.only one counter is available for this supermarket section
3.so the sales of other departments also get mixed with the total sale
Task :- when I enter this data into tally I have to show the other departments sales seperatly on balance sheet, how to achieve this
The Profit & Loss statement in Tally shows you the sales data of every Sales ledger separately. So, to have data on separate sales for separate departments, you will have to make different sales ledgers for different departments and make the entries accordingly.
If you are using combined single ledger for all sales, then you should make three ledgers now for sales of each of the three departments. If you are using sales ledger item wise or tax slab wise, then you need to create similar ledgers for every department and take care of choosing the right ledger when creating the voucher.

Dimension Table Usage when we have a loaded fact table

i am new to data warehouse and i want to ask that on copying all the foreign key data and to the fact table then why we still use dimension as all the data is present in Fact table , can some please guide me.
Short answer: a typical dimension has additional attributes than only a key. Your fact table has a foreign key to a dimension where additional info is available and even grouping is possible.
Recommended reading: "The Data Warehouse Toolkit" by Ralph Kimball
A fact table should only store 1) the business metric that it models (e.g. a sales order/transaction, or some other business transaction that you are measuring); 2) foreign keys to the related dimensions.
A dimension table should only store the context/qualitative data that is necessary to understand your business transactions (your facts).
Let's say, for example, that you are modelling sales on retail stores; a very simplified dimensional model for this would be something like:
Store Dimension: name, street address, city, county, etc
Product Dimension: name, brand, description, sku, etc
Date Dimension: year, month, day, etc
Sales Fact table: fkStore, fkProduct, fkDate, unitsSold, salesAmmount
So, the fact table only holds the metrics/measures and foreign keys, but business users need to use the information stored in dimensions to be able to explore the facts. That's how you enable them to explore unitsSold or salesAmmount according to a specific product, or on a specific store/location, or on a specific date.
The fact table by itself only provides quantitative data ("ammount sold") while the dimensions provide the context that a business user needs to interpret that metric ("ammount of product X sold in store Y in 2017").
The decision on what falls into dimension or fact data is not clear cut in many cases. Typically data that is re-usable ( is meaningful in relation to other fact data) can be considered dimension data.
A lot of times fact data is the most changeable over time. Fact tables contain the history of these records changing over time
Like daily Sales numbers, nightly EndOfDay results, etc.
These are often of numeric type i.e. quantitative measures. Datawarehouse analysis then consists of bucketing ( summing / Grouping ) these numerics so they carry the narrative of a trend over time at varying levels of granularity
Where dimension data is of more of 'static' nature like Trade , Customer , Product details.
I recommend reading:
https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/

How to link tables as one-many in crystal report

I am using
OS - Windows 7,
technology - progess 4gl.
I have two tables customer and order. I am displaying customer details along with their orders. Each customer may have more then one order. The report should be as below
CUSTOMER:-
CUMTOMER NAME ADDRESS
CUSTOMER1 XYZ
ORDER1 OF CUSTOMER1:-
ORDER NO. ORDER DETAILS
1 ASD
2 ASDFGGH
3 FGHJFG /* IT SHOULD REPEAT FOR THE PARTICULAR CUTOMER */
CUSTOMER2 ABC
ORDER1 OF CUSTOMER1:-
ORDER NO. ORDER DETAILS
1 ZXC
2 VNVN
3 JJLK
I Think for this we need one-many relationship between customer and order table. I have only customer and order temp-tables for doing this.Can you please tell me How to repeat the loop inside customer and how to link the tables in one-many relationship. Thanks in advance.
you should write a stored procedure and then link that SP with your report.
I don't know why you would need anything more complicated than a join.
Something like:
select * from customer, order where order.custNum = customer.custNum.
Having said that -- you might find this Progress Knowledgebase article relevant. Some versions of Crystal apparently produce SQL that might need to be adjusted:
http://knowledgebase.progress.com/articles/Article/18979
It sounds like you are just having an issue with how it is shown, I would join the table like Tom suggested order.custNum = customer.custNum
but in the Design section I would do the following:
GH1a Customer Name
GH1b Customer Information
GH2 Order Number
Det Order Information
you could also place all of the Customer Information (name, addr, etc) into a formula so that if the customer doesn't have all the data filled in it won't be shown, and won't show a blank line.

Database design challenge

I'm creating an virtual stamp card program for the iphone and have run into an issue with implementing my database. The program essentially has a main points system that can be utitlized through all merchants (sort've like air miles), but i also want to keep track of how many times you've been to EACH merchant
So far, i have created 3 main tables for users, merchants, and transactions.
1) Users table contains basic info like user_id and total points collected.
2) Merchants table contains info like merchant_id, location, total points given.
3) Transactions table simply creates a new row for every time someone checks into each merchant, and records date-stamp, user name, merchant name, and points awarded.
So the most basic way to deal with finding out how many times you've been to each merchant is to query the entire transaction table for both user and merchant, and this will give me a transaction history of how many times you've been to that specific merchant(which is perfect), but in the long run, i feel this will be horrible for performance.
The other straightforward, yet "dumb" method for implementing this, would be to create a column in the users table for EACH merchant, and keep the running totals there. This seems inappropriate, as I will be adding new merchants on a regular basis, and there would need to be new columns added to every user for every time this happens.
I've looked into one-to-many and many-to-many relationships for mySQL databases, but can't seem to come up with something very concrete, as i'm extremely new to web/PHP/mySQL development but i'm guessing this is what i'm looking for...
I've also thought of creating a special transaction table for each user, which will have a column for merchant and another for the # of times visited. Again, not sure if this is the most efficient implementation.
Can someone point me in the right direction?
You're doing the right thing in the sense of thinking up the different options, and weighing up the good and bad for each.
Personally, I'd go with a MerchantCounter table which joins on your Merchant table by id_merchant (for example) and which you keep up-to-date explicitly.
Over time it does not get slower (unlike an activity-search), and does not take up lots of space.
Edit: based on your comment, Janan, no I would use a single MerchantCounter table. So you've got your Merchant table:
id_merchant nm_merchant
12 Jim
15 Tom
17 Wilbur
You would add a single additional table, MerchantCounter (edited to show how to tally totals for individual users):
id_merchant id_user num_visits
12 101 3
12 102 8
15 101 6007
17 102 88
17 104 19
17 105 1
You can see how id_merchant links the table to the Merchant table, and id_user links to a further User table.