So here is the basic question:
US Federal Income Taxes can change yearly, or even in mid year. They're based on Tax Tables, whether or not you're single or married, how often you get paid and how many allowances you claim. Here is an example Tax table for someone who is Single and gets paid Bi-Weekly (for 2013):
Gross income between $42 and $214 - $0.00 plus 10% of excess over $85
Gross income between $214 and $739 - $17.20 plus 15% of excess over $214
Gross income between $1479 and $3463 - $191.95 plus 25% of excess over $1479
Gross income between $3463 and $7133 - $687.95 plus 28% of excess over $3463
Gross income between $7133 and $15406 - $1715.55 plus 33% of excess over $7133
Gross income between $15406 and $15469 - $4445.64 plus 35% of excess over $15406
Gross income between $15469+ - $4467.69 plus 39.6% of excess over $15469
So the different pay schedules are Weekly, BiWeekly, Semimonthly, Monthly, Quarterly, Semiannually, Annual and Daily. There are two tax tables per schedule (Married and Single) with different figures in each.
So, to calculate a payroll you have to pull in an employees Deductions (health insurance, etc) Pay type, Pay schedule, garnishments (if any) then take the range of their gross pay and figure out where in these tax tables that figure falls then calculate taxes.
What is the best way to setup the DB so I can edit any or all of these figures as needed - but at the same time not make my SQL queries 100 lines long when trying to calculate a payroll for a group of employees? (If possible)
Create a table for each Pay Schedule? Two tables (married and single) for each Pay Schedule? At this point I think that is the way to go, but I just want to make sure I'm not over complicating. Any or all advice welcome. Thanks in advance.
I have done complete payroll (Indian)primarily using MySQL stored procedures...
Based on my experience
Using stored procedure it can be done (will reduce considerable code)
Sum (total)Income from monthly/bi-monthly table payout..
Create a separate table for all exemptions.
You can use if / case condition to calculate tax based on your requirement.
Hope you have employee personal data table, you can store Married or Single status, while calculating tax you can pull from there.
If you wish will paste my code
Related
EDIT comments pointed out my question was too broad so I have done my best to focus it.
Trying to build a finance tracker in MS Access 2016 for spending analysis. I want to bring together multiple records from various bank accounts each one having a respective table that is identical to the bank statements (for ease of correcting). So lets say I have Bank1-T and Bank2-T. All bank account tables will have identical fields.
However I would also like to have the ability to, on occasion (where needed), replace certain records with subtotals to increase spending tracking granularity.
For example say I went to the gas station and paid for petrol as well
as lunch in the same payment, I would like Bank1-T to
have the single entry for payment to the petrol station, but to have
Accounts-T have the separate entries for payment of petrol and food.
Since I don't want to edit the bank account tables, I though I'd go ahead and store the split subtotals for payments in a table PayDetails-T. As there would only be a few payments I would store in PayDetails-T, how would I go about setting up a Query that brings together the payments from the various bank tables, and replaces the specific payment records from the bank tables with the ones in PayDetails-T? Can it be done in a single Query or would multiple be needed?
I am working with money expiration tracking problem at the moment (originally it is not money, but I have used it as a more convenient example).
An user can earn money from a platform for some mysterious reason and spent them for buying stuff (products, gifts etc.).
I am looking an algorithm (SQL query best case) to find a current balance of an user balance.
The events of spending and earning money are stored different database (MySQL) tables (let's say user_earned and user_spent). So in normal case, I would simply count user totals from user_earned and subtract spent money (total of user_spent).
BUT! There is a condition, that earned user money expires in 2 years if they are not used.
That means, if user have not used his money or used just a part of it, they will expire. If an user uses his money, they are used from the oldest not expired money record, so the balance (bonus) could be calculated in user's favor.
These are 5 scenarios with events in time, to have a better understanding on the case:
Both tables (user_earned and user_spent) have timestamps for date tracking.
I did something similar in one of my projects.
Looks like you need an additional table spends_covering with columns
spend_id, earhed_id, sum
So for each spends record you need to insert one or many rows into the spends_covering to mark 'used' money.
Then balance would be just sum of not used where date is less than 2 years.
select sum(sub.earned_sum-sub.spent_sum) as balance
from
(select e.sum as earned_sum, sum(sc.sum) as spent_sum
from earned e
left join spends_covering sc on e.earhed_id=sc.earhed_id
where e.date BETWEEN ...
group by e.earhed_id
having earned_sum > spent_sum) sub
It may be worth it to have two tables -- one (or more) with all the historical details, one with just the current balances for each 'user'. Be sure to use transactions to keep the two in sync.
Assume a simple database for hotel reservations with three tables.
Table 1: Reservations
This table contains a check-in and check-out date as well as a reference to one or more rooms and a coupon if applicable.
Table 2: Rooms
This table holds the data of all the hotel rooms with prices per night and number of beds.
Table 3: Coupons
This table holds the data of all the coupons.
Option #1:
If you want to get an overview of the reservations for a particular month with the total cost of each reservation, you'd have to fetch the reservations, the rooms for each reservation, and the coupon (if one is present).
With this data, you can then calculate the total amount for the reservation.
Option #2:
However, there is also another option, which is to store the total cost and discount in the reservation table so that it is much easier to fetch these calculations. The downside is that your data becomes much more dependent and much less flexible to work with. What I mean is that you have to manually update the total cost and discount of the reservation table every time you change a room or a coupon that is linked to a reservation.
What is generally recommended in terms of performance (option #2) version data independence (option #1).
UPDATE:
It is a MySQL database with over 500 000 rows (reservations) at this point, but is growing rapidly. I want to optimize database performance at an early stage to make sure that the UX remains fast and responsive.
Let me start to answer this with a story. (Somewhat simplified.)
2011-01-01 I reserve a room for two nights, 2011-03-01 and 2011-03-02. You don't tell me which room I'll get. (Because you don't know yet which room I'll get.) You tell me it will cost $40 per night. I have no coupons. You enter my reservation into your computer, even though you're already fully reserved for both those nights. In fact, you already have one person on the waiting list for both those nights. (Overbooking is a normal thing, not an abnormal thing.)
2011-01-15 You raise the rates for every room by $5.
2011-02-01 I call again to make sure you still have my reservation. You confirm that I have a reservation for two nights, 2011-03-01 and 2011-03-02, at $40. (Not $45, your current rate. That wasn't our deal. Our deal was $40 a night.)
2011-02-12 One person calls and cancels their reservation for 2011-03-01 and 2011-03-02. You still don't yet have a room you know for certain that I'll be able to check in to. The other person from the waiting list now has a room; I'm still on the waiting list.
2011-02-15 One person calls and cancels their reservation for 2011-03-01 and 2011-03-02. Now I have a room.
2011-03-01 I check in with a coupon.
You can store the "current" or "default" price with each room, or with each class of
rooms, but you need to store the price we agreed to with my
reservation.
Reservations don't reserve rooms; they reserve potential rooms. You
don't know who will leave early, who will leave late, who will
cancel, and so on. (Based on my experience, once in a while a room will
be sealed with crime scene tape. You don't know how long that will last, either.)
You can have more reservations than room-nights.
Coupons can presumably appear at any time before check out.
If you want to get an overview of the reservations for a particular
month with the total cost of each reservation, you'd have to fetch the
reservations, the rooms for each reservation, and the coupon (if one
is present).
I don't think so. The price you agreed to should be in the reservation itself. Specific rooms can't resonably be assigned until the last minute. If there's one coupon per reservation, that might need to be stored with the reservation, too.
The only reporting problem is in making sure your reports clearly report how much expected revenue should be ignored due to overbooking.
The response of your answer depends of the size of your database. For small database option #1 is better, but for huge database option #2 is better. So if you could say how many rows you got in table, and the database used (oracle, sqlserver etc.) you will have a more precise answer.
You can add a table holds the data of the rooms`s historical prices and reason for change.
Table 2 only records the latest price.
I am creating a website where members of the family can book a vacation in the family's sea cottage.
Each member is assigned 40 credits each year. A member must have enough credit points to book a vacation. (this credit system makes sure every member has equal opportunity to stay at the cottage)
However, not all weeks require the same amount of credit points, and last minute bookings require no credit points.
My question is: how should I store the credit points in the database? What is most efficient? Per day/per couple of days/per week? And how do I efficiently check how much credit points are needed for a given date range using mysql?
BTW: I am using the Zend Framework and I am familiar with the code etc., I just need some conceptual advice ;)
I don't know if I understand right the problematic here but :
You need to store in a "users" table the amount of credit remaining for each user.
You need to have another table with fields like "start period", "end period", "duration", "amount of points needed"
In the duration field, it could be an enum with values like "day", "week", "last_minute".
Then the logic will be in your PHP code, but with that, you'll be able to have the right number of credits needed whenever the user wants to use the cottage.
If I understand your case correctly, I think I would store something like:
number of remaining credits per user
a default number of credits per day
number of days before that counts as "last minute"
periods of deviating credit cost, with (start date, end date, cost per day)
Then, I would calculate the cost to book dynamically from this information whenever the user needs to make a booking. The last minute booking rule can be seen as a special deviating period where start date is now, end date is now+"number of days" and cost is zero.
I assume that no-one will book the cottage for a shorter duration than one day. If they will, I would change the use of "day" above to whatever unit of time would be sensible.
Just my thoughts. :-)
I am selling a high volume product that costs a minimal amount per piece. ($0.001 USD each to be exact).
I allow my customers to purchase a one time amount of product or a recurring payment amount of product at their desired choice of USD per payment.
How can I limit my customers to only spending $10 USD or more per payment through PayPal? They limit it at $10,000 USD, can I limit it at $10 USD?
Right now, I am not processing payments of less than $10 USD, and recommending that customers do not, but it is still possible to make them.
The problem arises when a customer purchases $1 worth of product and paypal takes 40 odd percent of that payment due to per-payment fees.
I do not believe PayPal offers a setting for minimum allowed payment. This is something you would need to handle on the server side. It would be easy enough to do. Just don't display the "Pay with PayPal" button unless the order total is $10 or more.