Location: PHPKode > scripts > Small Business Break-Even Analyzer > small-business-break-even-analyzer/sbbe_analyzer.php
<?php
	include('sbbe_files/functions.php');
	
	
			if ($_POST['income_percent'] != '') {
				$new_income = $income * (1+ ($_POST['income_percent']/100));
			} else {
				$new_income = $income + $_POST['income_amount'];
			}
			if ($_POST['expenses_percent'] != '') {
				$new_expenses = $expenses * (1+ ($_POST['expenses_percent']/100));
			} else {
				$new_expenses = $expenses + $_POST['expenses_amount'];
	
	// If calculating a payment amount
	if ($_POST['action'] == "calculate") {
		if (!checkValidChars($_POST['startup_cost'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your startup costs');
		}	
		if (!checkValidChars($_POST['income'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your income');
		}
		if (!checkValidChars($_POST['income_percent'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your income increase');
		}
		if (!checkValidChars($_POST['income_amount'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your income increase');
		}
		if (strlen($_POST['income_percent']) < 1 && strlen($_POST['income_amount']) < 1) {
			$error_div .= getResultDiv('Please enter an income increase, either in percentage or flat amount');
		}
		if (!checkValidChars($_POST['lease'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your lease');
		}
		if (!checkValidChars($_POST['payroll'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your payroll');
		}
		if (!checkValidChars($_POST['taxes'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your taxes');
		}
		if (!checkValidChars($_POST['loan_payment'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your loan payment');
		}
		if (!checkValidChars($_POST['utilities'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for utilities');
		}
		if (!checkValidChars($_POST['supplies'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for supplies');
		}
		if (!checkValidChars($_POST['travel'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for travel');
		}
		if (!checkValidChars($_POST['other'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for other expenses');
		}
		if (!checkValidChars($_POST['expenses_percent'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your income increase');
		}
		if (!checkValidChars($_POST['expenses_amount'],"0123456789.")) {
			$error_div .= getResultDiv('Please enter only numbers for your income increase');
		}
		if (strlen($_POST['expenses_percent']) < 1 && strlen($_POST['expenses_amount']) < 1) {
			$error_div .= getResultDiv('Please enter an expenses increase, either in percentage or flat amount');
		}
		$result_div .= $error_div;
		// If no errors, go ahead and perform calculations
		if ($error_div == '') {

			$expenses = $_POST['utilities'] + $_POST['supplies'] + $_POST['lease'] + $_POST['payroll'] + $_POST['travel'] + $_POST['taxes'] + $_POST['loan_payment'] + $_POST['phone'] + $_POST['other'];
			$total_months = 5*12;
			$month_i = 0;
			$income = $_POST['income'];
			$investment = $_POST['startup_cost'] - $_POST['startup_cost'] - $_POST['startup_cost'];
			$cash_flow = $income - $expenses;
			$row_style = 'main-row-1';
			$compare_table = '
				<table class="main-table">
					<tr>
						<th>Month</th>
						<th>Income</th>
						<th>Expenses</th>
						<th>Cash Flow</th>
						<th>Investment</th>
						<th>Income Rise</th>
						<th>Expense Rise</th>
					</tr>
					<tr>
						<td class="main-row-alert">Starting</td>
						<td class="main-row-alert">$' . costFormat($income,1) . '</td>
						<td class="main-row-alert">$' . costFormat($expenses,1) . '</td>
						<td class="main-row-alert">$' . costFormat($cash_flow,1) . '</td>
						<td class="main-row-alert">$' . costFormat($investment,1) . '</td>
						<td class="main-row-alert">$0</td>
						<td class="main-row-alert">$0</td>
					</tr>';
			$breakeven = false;
			while ($month_i < $total_months) {
				$do_style_change = 0;
				$is_year = ($month_i) / 12;
				if (round($is_year) == $is_year) {
					$row_style = ternary($row_style,'main-row-2','main-row-1');
				}
				$month_i++;
				if ($_POST['income_percent'] != '') {
					$new_income = $income * (1+ ($_POST['income_percent']/100));
				} else {
					$new_income = $income + $_POST['income_amount'];
				}
				if ($_POST['expenses_percent'] != '') {
					$new_expenses = $expenses * (1+ ($_POST['expenses_percent']/100));
				} else {
					$new_expenses = $expenses + $_POST['expenses_amount'];
				}
				$income_increase = $new_income - $income;
				$expense_increase = $new_expenses - $expenses;
				$income = $new_income;
				$expenses = $new_expenses;
				$cash_flow = $income - $expenses;
				$investment = $investment + $cash_flow; 
				if ($investment >= 0 && $breakeven == false) {
					$row_style = 'main-row-alert';
					$breakeven = true;
					$do_style_change = 1;
					$years = round(($month_i / 12),1);
					$breakeven_quote = 'You will break even after <strong>' . $month_i .' months</strong>, or <strong>' .$years . ' years</strong>';
				}
				$compare_table .= '
					<tr>
						<td class="' . $row_style . '">' . $month_i . '</td>
						<td class="' . $row_style . '">$' . costFormat(round($income),1) . '</td>
						<td class="' . $row_style . '">$' . costFormat(round($expenses),1) . '</td>
						<td class="' . $row_style . '">$' . costFormat(round($cash_flow),1) . '</td>
						<td class="' . $row_style . '">$' . costFormat(round($investment),1) . '</td>
						<td class="' . $row_style . '">$' . costFormat(round($income_increase),1) . '</td>
						<td class="' . $row_style . '">$' . costFormat(round($expense_increase),1) . '</td>
					</tr>';
				if ($do_style_change == 1) {
					$row_style = ternary($row_style,'main-row-2','main-row-1');
				}
				if ($breakeven_quote == '') {
					$breakeven_quote = 'You will not break even within 5 years.';
				}
			}
			$breakeven_quote = '<p><span class="result-span">' . $breakeven_quote . '</span></p>';
			$result_block = '<h2>Your Result:</h2>' . $breakeven_quote . $compare_table;
			$explaination = 'See below form for your results.';
		}
	}
	}
	
	if ($result_block == '') {
		$result_block = '<h2>Your results will display here</h2>';
		$explaination = 'If you\'re considering starting a small business, this break-even analizer is a great way to test out different financial scenarios before you start. Just fill in the form with your initial business costs, income, and expense information and you can see just when you\'ll hit the "break-even" point, or where your investment in the business finally pays for itself. Try different scenarios and compare results to really get the most out of this analyzer.';
	}
?>
<html>
<head>
<link href="sbbe_files/styles.css" rel="stylesheet" type="text/css"></link>	
<script type="text/javascript" src="sbbe_files/sbbe_analyzer.js"></script>
</head>

<body>
<h1>Small Business Break-Even Analyzer</h1>
<?php echo $result_div; ?>
<p><?php echo $explaination; ?><p>
<form action="sbbe_analyzer.php" onsubmit="return checkform(this);" method="post">
	<input type="hidden" name="action" value="calculate" />
	<table>
		<tr>
			<td class="half-width"></td>
			<td>
				<table class="calc-table">
					<tr>
						<td width="10"><img src="sbbe_files/qmark.gif" title="How much money was put into business initially" /></td>
						<td class="nowrap">Startup Costs: </td>
						<td width="100%">$<input type="text" name="startup_cost" value="<?php echo $_POST['startup_cost']; ?>"  size="10"/></td>
					</tr>
					<tr>
						<td colspan="3"><hr /><strong>Monthly Income:</strong></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="How much money was put into business initially" /></td>
						<td class="nowrap">Monthly Income: </td>
						<td>$<input type="text" name="income" value="<?php echo $_POST['income']; ?>"  size="10"/></td>
					</tr>
					<tr>
						<td colspan="3">
						<img src="sbbe_files/qmark.gif" title="The amount your income will increase each month" />
						Income Increase, either percentage: 
						<input type="text" name="income_percent" id="income_percent" onFocus="clearIncomeAmount();" value="<?php echo $_POST['income_percent']; ?>"  size="3"/>%, or flat amount: 
						$<input type="text" name="income_amount" id="income_amount" onFocus="clearIncomePercent();" value="<?php echo $_POST['income_amount']; ?>"  size="10"/>
						</td>
					</tr>
					<tr>
						<td colspan="3"><hr /><strong>Monthly Expenses:</strong></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="The amount you pay each month for office or other property" /></td>
						<td>Lease / Rent: </td>
						<td>$<input type="text" name="lease" value="<?php echo $_POST['lease']; ?>"  size="7"/></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="How much you pay staff and yourself each month" /></td>
						<td>Payroll: </td>
						<td>$<input type="text" name="payroll" value="<?php echo $_POST['payroll']; ?>"  size="7"/></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="Your yearly tax amount divided by 12 (for each month)" /></td>
						<td>Taxes: </td>
						<td>$<input type="text" name="taxes" value="<?php echo $_POST['taxes']; ?>"  size="7"/></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="Payment amount on your business loan (if applicable)" /></td>
						<td>Loan Payment: </td>
						<td>$<input type="text" name="loan_payment" value="<?php echo $_POST['loan_payment']; ?>"  size="7"/></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="Monthly expenses for water, gas and electricity" /></td>
						<td>Utilities: </td>
						<td>$<input type="text" name="utilities" value="<?php echo $_POST['utilities']; ?>"  size="7"/></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="Cost for office supplies, equipment, etc." /></td>
						<td>Supplies: </td>
						<td>$<input type="text" name="supplies" value="<?php echo $_POST['supplies']; ?>"  size="7"/></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="Cost of traveling, including commute costs, car, plane, hotel, food, etc." /></td>
						<td>Travel: </td>
						<td>$<input type="text" name="travel" value="<?php echo $_POST['travel']; ?>"  size="7"/></td>
					</tr>
					<tr>
						<td><img src="sbbe_files/qmark.gif" title="Any other expenses" /></td>
						<td>Other: </td>
						<td>$<input type="text" name="other" value="<?php echo $_POST['other']; ?>"  size="7"/></td>
					</tr><tr>
						<td colspan="3">
						<img src="sbbe_files/qmark.gif" title="The amount your expenses will increase each month" />
						Expense Increase, either percentage: 
						<input type="text" name="expenses_percent" id="expenses_percent" onFocus="clearExpenseAmount();" value="<?php echo $_POST['expenses_percent']; ?>"  size="3"/>%, or flat amount: 
						$<input type="text" name="expenses_amount" id="expenses_amount" onFocus="clearExpensePercent();" value="<?php echo $_POST['expenses_amount']; ?>"  size="10"/>
						</td>
					</tr>
					<tr>
						<td colspan="3"><p class="align-center"><br /><strong><input type="submit" value="Calculate &gt;&gt;" /></strong></p></td>
					</tr>
					
				</table>
				<p class="align-center">Powered by <a href="http://www.small-business-ideas.net">www.Small-Business-Ideas.net</a></p>
			</td>
			<td class="half-width">
		</tr>
	</table>
	</form>
	<hr />
	<?php echo $result_block; ?>
</body>
</html>
Return current item: Small Business Break-Even Analyzer