"; include "top.inc"; if ($action == "Add") { $SQL="insert into properties (address,town,postcode,agent,build_year,url,asking_price,value_price,wanted_price,required_price,rent_est,rent_required,deposit,depreciation,beds,baths,cars,land_size,house_size,added) values ('$address','$town','$postcode','$agent','$build_year','$url','$asking_price','$value_price','$wanted_price','$required_price','$rent_est','$rent_required','$deposit','$depreciation','$beds','$baths','$cars','$land_size','$house_size',current_timestamp)"; $result = mysql_query($SQL) or die('A error occured: ' . mysql_error()); $result = mysql_query("select MAX(prop_id) prop_id from properties") or die('A error occured: '. mysql_error()); $row = mysql_fetch_assoc($result); $prop_id=$row['prop_id']; } if ($action == "Update") { $SQL="update properties set address='$address',town='$town',postcode='$postcode',agent='$agent',build_year='$build_year',url='$url',asking_price='$asking_price',value_price='$value_price',wanted_price='$wanted_price',required_price='$required_price',rent_est='$rent_est',rent_required='$rent_required',deposit='$deposit',depreciation='$depreciation',beds='$beds',baths='$baths',cars='$cars',land_size='$land_size',house_size='$house_size' where prop_id = '$prop_id'"; $result = mysql_query($SQL) or die('A error occured: ' . mysql_error()); } if (($action == "Update") || ($action == "Add")) { if ($_FILES["image"]['error'] == UPLOAD_ERR_OK) { $filename=$_FILES["image"]['name']; $temp_file=$_FILES["image"]['tmp_name']; if (!is_dir("$site_root/images/$prop_id")) { mkdir("$site_root/images/$prop_id", 0755); } move_uploaded_file($temp_file, "$site_root/images/$prop_id/main.jpg"); } ### Get Depreciation #$SQL="select sum(dep_cost) dep_costs from depreciation where prop_id = '$prop_id'"; #$result_dep = mysql_query($SQL) or die('A error occured: ' . mysql_error()); #$row_dep = mysql_fetch_assoc($result_dep); #if ($row_dep) { # $total_depreciation=$row_dep[dep_costs]; # $year_depreciation=$total_depreciation*0.025; #} else { # $year_depreciation=0; #} if ($asking_price > 0) { $year_depreciation=$depreciation; $yearly_interest=$asking_price*$interest; $maint_costs=$asking_price*0.02; $yearly_costs=$yearly_interest+$maint_costs; $yearly_rent=$rent_est*52; $yearly_property_profit=$yearly_rent-$yearly_costs; $year_depreciation_refund=$year_depreciation*0.3; $yearly_taxback=-1*$yearly_property_profit*0.3; $yearly_refund=$year_depreciation_refund+$yearly_taxback; $yearly_income=$yearly_rent+$yearly_refund; $yearly_profit=$yearly_income-$yearly_costs; $SQL="update properties set profit=$yearly_profit where prop_id = '$prop_id'"; $result = mysql_query($SQL) or die('A error occured: ' . mysql_error()); unset($yearly_interest,$maint_costs,$yearly_costs,$yearly_rent,$yearly_property_profit,$year_depreciation_refund,$yearly_taxback,$yearly_refund,$yearly_income,$yearly_profit); } } if (isset($prop_id) && $prop_id > 0) { $button="Update"; $SQL="select * from properties where prop_id = '$prop_id'"; $result = mysql_query($SQL) or die('A error occured: ' . mysql_error()); $row = mysql_fetch_assoc($result); extract($row); #$SQL="select sum(dep_cost) dep_costs from depreciation where prop_id = '$prop_id'"; #$result_dep = mysql_query($SQL) or die('A error occured: ' . mysql_error()); #$row_dep = mysql_fetch_assoc($result_dep); #if ($row_dep) { # $total_depreciation=$row_dep[dep_costs]; # $year_depreciation=$total_depreciation*0.025; #} else { # $year_depreciation=0; #} if ($required_price) { $year_depreciation=$depreciation; $yearly_interest=($required_price-$deposit)*$interest; $monthly_interest=$yearly_interest/12; $maint_costs=$required_price*0.02; $yearly_costs=$yearly_interest+$maint_costs; $yearly_rent=$rent_required*52; $yearly_property_profit=$yearly_rent-$yearly_costs; $year_depreciation_refund=$year_depreciation*0.3; $yearly_taxback=-1*$yearly_property_profit*0.3; $yearly_refund=$year_depreciation_refund+$yearly_taxback; $yearly_income=$yearly_rent+$year_depreciation_refund+$yearly_taxback; $yearly_profit=$yearly_income-$yearly_costs; $weekly_profit=$yearly_profit/52; $year_depreciation_refund=sprintf("%01.2f", $year_depreciation_refund); $yearly_taxback=sprintf("%01.2f", $yearly_taxback); $yearly_refund=sprintf("%01.2f", $yearly_refund); $yearly_profit=sprintf("%01.2f", $yearly_profit); $weekly_profit=sprintf("%01.2f", $weekly_profit); } $button="Update"; } else { $address=$town=$postcode=$agent=$asking_price=$value_price=$rent_est=""; $button="Add"; } $agent_select=""; $properties_form = <<< END_FORM
Address
Year Built Land Size House Size Beds Baths Cars
New Image URL
Town Postcode Agent$agent_select $view_agent
Asking Price$ Value Price$ Wanted Price$ Required Price$
Rent Estimate$ Rent Required$ Deposit$ Depreciation$
Costs Interest = $$yearly_interest Maintenance = $$maint_costs Total Costs$-$yearly_costs
Income Yearly Rent = $$yearly_rent Total Income$+$yearly_rent
Tax Back Depreciation = $$year_depreciation Depreciation Refund = $$year_depreciation_refund Costs Refund = $$yearly_taxback Total Refunds$+$yearly_refund
Profit/Loss$$yearly_profit
Weekly Profit/Loss$$weekly_profit
END_FORM; echo "$properties_form"; include "bottom.inc"; ?>