# Pay Calculator

/ Published in: PHP

Just a simple pay calculator that I use to estimate income. I generally set the taxes to 20% as that gives me a rough idea of deductions taken out by state and federal. This number will vary depending on where you live obviously. This is just an estimation tool, I didn't code in actual tax code into it or anything like that.

1. <!DOCTYPE html>
2. <html>
4. <title>Pay Calculator</title>
6. <body>
7. <h1>Salary Calculator</h1>
8. <?php if ( isset(\$_POST['tax_rate']) && isset(\$_POST['hourly_wage'])): ?>
9. <h2>Results</h2>
10. <?php
11. // Convert tax_rate to a percentage
12. \$rate = \$_POST['tax_rate'] / 100;
13. \$wage = \$_POST['hourly_wage'];
14.
15. // figure out hours
16. \$hours_day = 8;
17. \$hours_week = \$hours_day * 5;
18. \$hours_year = \$hours_week * 52;
19. \$hours_month = \$hours_year / 12;
20.
21. // calculate gross wages
22. \$gross_day = \$wage * \$hours_day;
23. \$gross_week = \$wage * \$hours_week;
24. \$gross_month = \$wage * \$hours_month;
25. \$gross_year = \$wage * \$hours_year;
26.
27. // Deductions
28. \$deductions_day = \$gross_day * \$rate;
29. \$deductions_week = \$gross_week * \$rate;
30. \$deductions_month = \$gross_month * \$rate;
31. \$deductions_year = \$gross_year * \$rate;
32.
33. // Net Pay
34. \$net_day = \$gross_day - \$deductions_day;
35. \$net_week = \$gross_week - \$deductions_week;
36. \$net_month = \$gross_month - \$deductions_month;
37. \$net_year = \$gross_year - \$deductions_year;
38.
39. \$r = array(
40. // One day
41. 'Daily' => array(
42. 'Hours Worked' => \$hours_day,
43. 'Taxes Withheld' => \$deductions_day,
44. 'Gross Earnings' => \$gross_day,
45. 'Net Earnings' => \$net_day,
46. ),
47.
48. // One week
49. 'Weekly' => array(
50. 'Hours Worked' => \$hours_week,
51. 'Taxes Withheld' => \$deductions_week,
52. 'Gross Earnings' => \$gross_week,
53. 'Net Earnings' => \$net_week,
54. ),
55.
56. // One Month
57. 'Monthly' => array(
58. 'Hours Worked' => \$hours_month,
59. 'Taxes Withheld' => \$deductions_month,
60. 'Gross Earnings' => \$gross_month,
61. 'Net Earnings' => \$net_month,
62. ),
63.
64. // One Year
65. 'Annual' => array(
66. 'Hours Worked' => \$hours_year,
67. 'Taxes Withheld' => \$deductions_year,
68. 'Gross Earnings' => \$gross_year,
69. 'Net Earnings' => \$net_year,
70. ),
71. );
72.
73.
74. ?>
75.
76. <?php foreach (\$r as \$period => \$results) { ?>
77. <h3><?=\$period?></h3>
78. <table>
79. <?php foreach (\$results as \$k => \$v): ?>
80. <tr>
81. <td><?=\$k?></td>
82. <?php if (\$k == "Hours Worked"): ?>
83. <td><?=number_format(\$v, 2, '.', '')?></td>
84. <?php else: ?>
85. <td>\$<?=number_format(\$v, 2, '.', '')?></td>
86. <?php endif ?>
87. </tr>
88. <?php endforeach ?>
89. </table>
90. <?php } ?>
91.
92. <?php else: ?>
93. <h2>Enter Your Wage and Taxes</h2>
94. <div class="form">
95. <form name="wage_calculator" action="<?=\$_SERVER['PHP_SELF']?>" method="post">
96. <div class="'form_label"><label>Hourly Wage</label></div>
97. <div class="form_input"><input type="text" name="hourly_wage" id="hourly_wage"></div>
98. <div class="form_label"><label>Tax Rate</label></div>
99. <div class="form_input"><input type="text" name="tax_rate" id="tax_rate"></div>
100. <div class="form_submit"><input type="submit"></div>
101. </form>
102. </div>
103. <?php endif ?>
104. </body>
105. </html>