#!/usr/bin/perl

print "Content-type: text/html\n\n";

$long = $ENV{'QUERY_STRING'};

if ($long) {
	@pairs=split(/&/,$long);
	foreach $item(@pairs) {
		($name,$content)=split (/=/,$item,2);
		$content=~tr/+/ /;
		$content=~ s/%(..)/pack("c",hex($1))/ge;
		if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$content; }
		else { $INPUT{$name} = $content; }
	}
}
else {
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
		else { $INPUT{$name} = $value; }
	}
}

if ($INPUT{action} eq "addclient") { &addclient; }
elsif ($INPUT{action} eq "showclients") { &showclients; }
elsif ($INPUT{action} eq "clientsearch") { &clientsearch; }
elsif ($INPUT{action} eq "doaddclient") { &doaddclient; }
elsif ($INPUT{action} eq "editclient") { &editclient; }
elsif ($INPUT{action} eq "viewclient") { &viewclient; }
elsif ($INPUT{action} eq "doeditclient") { &doeditclient; }
elsif ($INPUT{action} eq "addproperty") { &addproperty; }
elsif ($INPUT{action} eq "addpropertyset") { &addpropertyset; }
elsif ($INPUT{action} eq "doaddproperty") { &doaddproperty; }
elsif ($INPUT{action} eq "editproperty") { &editproperty; }
elsif ($INPUT{action} eq "doeditproperty") { &doeditproperty; }
elsif ($INPUT{action} eq "viewproperty") { &viewproperty; }
elsif ($INPUT{action} eq "showproperties") { &showproperties; }
elsif ($INPUT{action} eq "logwork") { &logwork; }
elsif ($INPUT{action} eq "logworkset") { &logworkset; }
elsif ($INPUT{action} eq "dologworkset") { &dologworkset; }
elsif ($INPUT{action} eq "logworkview") { &logworkview; }
elsif ($INPUT{action} eq "logwork_edit") { &logwork_edit; }
elsif ($INPUT{action} eq "createinvoice") { &createinvoice; }
elsif ($INPUT{action} eq "createinvoiceset") { &createinvoiceset; }
elsif ($INPUT{action} eq "readnewinvoice") { &readnewinvoice; }
elsif ($INPUT{action} eq "viewinvoice") { &viewinvoice; }
elsif ($INPUT{action} eq "viewinvoiceryan") { &viewinvoiceryan; }
elsif ($INPUT{action} eq "viewinvoicerange") { &viewinvoicerange; }
elsif ($INPUT{action} eq "printrange") { &printrange; }
elsif ($INPUT{action} eq "searchinvoices") { &searchinvoices; }
elsif ($INPUT{action} eq "changeinvoice") { &changeinvoice; }
elsif ($INPUT{action} eq "whileloop") { &whileloop; }
elsif ($INPUT{action} eq "whileprint") { &whileprint; }
elsif ($INPUT{action} eq "invoicetotals") { &invoicetotals; }
else { &showclients; }


## ADDED 1-4-2014 RPO

sub logwork_edit {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

    use DBI;
    my $dsn = "DBI:mysql:database=$d_name;host=localhost";
    my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

        if ($INPUT{doedit} eq "yes") {
            my $kasth = $dbh->do("update reporting set worktype = '$INPUT{worktype}', date = '$INPUT{date}', price = '$INPUT{price}', notes = '$INPUT{notes}' WHERE reportid = '$INPUT{reportid}'");
            $dbh->disconnect;
            $printmessage = "Updated Success!";
            &logworkview;
            exit 0;
        }
        if ($INPUT{dodelete} eq "yes") {
            my $kasth = $dbh->do("DELETE from reporting WHERE reportid = '$INPUT{reportid}'");
            $dbh->disconnect;
            $printmessage = "Updated Success!";
            &logworkview;
            exit 0;
        }


print qq~
<html>
<head>
<title>Client Management System</title>
<script language="javascript" type="text/javascript">
<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
// End -->
</script>
~;
&header;
print qq~
<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
	<table border="0" cellpadding="5" cellspacing="0" bgcolor="black" width="100%">
		<tr>
			<td valign="top" bgcolor="white" width="50%">
				<font size="4" face="Arial Black">View Pending Logged Completed Work (Not Invoiced)</font><br>
			<h3>Edit The Following File</h3>
~;
my $casth = $dbh->prepare("select description from pulldowns where type = 'worktype'");
$casth->execute;
my $aasth = $dbh->prepare("select reportid,propertyid,clientid,status,worktype,date,price,notes from reporting WHERE status = 'pending' AND reportid = '$INPUT{reportid}' order by reportid DESC");
$aasth->execute;
while (($reportid,$propertyid,$clientid,$status,$worktype,$date,$price,$notes) = $aasth->fetchrow_array()) {

print qq~
<form method="get" action="index.idx">
<input type="hidden" name="action" value="logwork_edit">
<input type="hidden" name="doedit" value="yes">
<input type="hidden" name="reportid" value="$reportid">
<input type="hidden" name="propertyid" value="$propetyid">
<input type="hidden" name="clientid" value="$clientid">
<input type="hidden" name="status" value="$status">
Logwork ID #$reportid<br>
Property: $propertyid<br>
Client: $clientid<br>
Status: $status<br>
Work Type: <select name="worktype">
<option value="$worktype">$worktype</option>
~;
while (($description) = $casth->fetchrow_array()) {
print "<option value=\"$description\">$description</option>";
}
print qq~
</select>
<br>
Date: <input type="text" name="date" value="$date"><br>
Price: <input type="text" name="price" value="$price"><br>
Notes: <br>
<textarea name=notes wrap=physical cols=50 rows=4 onKeyDown="textCounter(this.form.notes,this.form.remLen,50);" onKeyUp="textCounter(this.form.notes,this.form.remLen,50);">$notes</textarea><br><input readonly type=text name=remLen size=3 maxlength=3 value="50"> characters left
<input type="submit" value="Save Changes">
<br><br><br><br>
Delete Record: <a href="index.idx?action=logwork_edit&reportid=$reportid&dodelete=yes">Yes - Delete Now</a>
</form>
~;
}
print qq~
</td>
</tr>
</table>
~;
&footer;
### END SUB
}

sub logworkview {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

    use DBI;
    my $dsn = "DBI:mysql:database=$d_name;host=localhost";
    my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

print qq~
<html>
<head>
<title>Client Management System</title>
~;
&header;
print qq~
<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
	<table border="0" cellpadding="5" cellspacing="0" bgcolor="black" width="100%">
		<tr>
			<td valign="top" bgcolor="white" width="50%">
				<font size="4" face="Arial Black">View Pending Logged Completed Work (Not Invoiced)</font><br>
				<table cellpadding=3>
				<tr>
				<td><b>Report ID</b></td><td><b>Property ID</b></td><td><b>Client ID</b></td><td><b>Status</b></td><td><b>Worktype</b></td><td><b>Date</b></td><td><b>Price</b></td><td><b>Notes</b></td><td>&nbsp;</td>
				</tr>
~;
$row_count = "1";
my $aasth = $dbh->prepare("select reportid,propertyid,clientid,status,worktype,date,price,notes from reporting WHERE status = 'pending' order by reportid DESC");
$aasth->execute;
while (($reportid,$propertyid,$clientid,$status,$worktype,$date,$price,$notes) = $aasth->fetchrow_array()) {
if ($row_count eq "2") {
$showbgcolor = "FFFF99";
$row_count = "1";
}
else {
$showbgcolor = "white";
$row_count++;
}
print qq~
<tr bgcolor="$showbgcolor">
			<td>$reportid</td><td>$propertyid</td><td>$clientid</td><td>$status</td><td>$worktype</td><td>$date</td><td>$price</td><td>$notes</td><td nowrap><a href="index.idx?action=logwork_edit&reportid=$reportid">Edit</a></td>
</tr>
~;
}
print qq~
</table>
</td>
</tr>
</table>
~;
&footer;
### END SUB
}

sub printrange {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";
use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select invoiceid from invoices order by invoiceid DESC");
$aasth->execute;
while (($invoiceids) = $aasth->fetchrow_array()) {
$printinvoiceids .= "<option value=\"$invoiceids\">$invoiceids</option>\n";
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Lawn Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">Print All Invoices by Range</font><br>
<hr color="black">

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr bgcolor="navy">
<td valign="top">
	<b><font color="white">Select Range to Print Below</font></b>
</td>
</tr>
<tr>
<td valign="top">
<form method="post" action="index.idx" target="_blank">
<input type="hidden" name="action" value="viewinvoicerange">
Print from Invoice # <select name="startinvoice">$printinvoiceids</select> to Invoice # <select name="endinvoice">$printinvoiceids</select> <input type="submit" value="Preview">
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>

~;

&footer;
}

sub invoicetotals {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";
use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

if ($INPUT{the_year}) {
$the_year = "$INPUT{the_year}";
$the_year_display = "20$the_year";
$the_year_dd = "<option value=\"$INPUT{the_year}\">$the_year_display</option>";
}
else {
$the_year = "16";
$the_year_display = "20$the_year";
$the_year_dd = "<option value=\"16\">2016</option>";
}


my $aasth = $dbh->prepare("select totalprice,STATUS from invoices where STATUS = 'pending' AND invoicedate like '%$the_year'");
$aasth->execute;

my $basth = $dbh->prepare("select totalprice,STATUS from invoices where STATUS = 'paid' AND invoicedate like '%$the_year'");
$basth->execute;

my $casth = $dbh->prepare("select price,status from reporting where status = 'pending'");
$casth->execute;

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Lawn Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">Lawn Profits for $the_year_display</font>  <form method="get" action="index.idx"><input type="hidden" name="action" value="invoicetotals"><select name="the_year">$the_year_dd<option value="16"> - - - </option><option value="17">2017</option><option value="16">2016</option><option value="15">2015</option><option value="14">2014</option><option value="13">2013</option><option value="12">2012</option><option value="11">2011</option><option value="10">2010</option><option value="09">2009</option><option value="08">2008</option><option value="07">2007</option></select> <input type="submit" value="Update"></form><br>
<hr color="black">

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr bgcolor="navy">
<td valign="top">
	<b><font color="white">Total Pending Invoices for $the_year_display</font></b>
</td>
</tr>
~;
while (($totalprice,$STATUS) = $aasth->fetchrow_array()) {
$itotalprice = ($itotalprice+$totalprice);
}
$itotalprice = sprintf("%.2f",$itotalprice);
$dbh->disconnect;

print qq~
<tr>
<td valign="top" bgcolor="#f7f5ce">
<font size="3" face="Arial">\$$itotalprice</font>
</td>
</tr>
</table>

<table border="0" cellpadding="3" cellspacing="0" width="100%" bgcolor="#ffc6c0">
<tr bgcolor="navy">
<td valign="top">
	<b><font color="white">Total Uninvoiced Pending Logged Work - All Years</font></b>
</td>
</tr>
~;
while (($utotalprice,$uSTATUS) = $casth->fetchrow_array()) {
$iutotalprice = ($iutotalprice+$utotalprice);
}
$iutotalprice = sprintf("%.2f",$iutotalprice);
$dbh->disconnect;

print qq~
<tr>
<td valign="top">
<font size="3" face="Arial">\$$iutotalprice</font>
</td>
</tr>
</table>

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr bgcolor="navy">
<td valign="top">
	<b><font color="white">Total Paid Invoices for $the_year_display</font></b>
</td>
</tr>
~;
while (($ctotalprice,$cSTATUS) = $basth->fetchrow_array()) {
$ictotalprice = ($ictotalprice+$ctotalprice);
}
$ictotalprice = sprintf("%.2f",$ictotalprice);
$dbh->disconnect;

print qq~
<tr>
<td valign="top" bgcolor="#cbecca">
<font size="3" face="Arial">\$$ictotalprice</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>

~;

&footer;

}


sub whileprint {

$counter = 0;

while ($counter < 70) {
print "Line #$counter    Completed  on 8/6/03<br>";
$counter++;
}

$dbh->disconnect;

}

sub whileloop {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";
use DBI;

my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

$counter = 0;

while ($counter < 557) {
print "$counter<br>my $aasth = $dbh->do(\"INSERT INTO `invoices` VALUES ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')\");";
my $aasth = $dbh->do("INSERT INTO `invoices` VALUES ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')");
$counter++;
}

$dbh->disconnect;

}

sub searchinvoices {

if ($INPUT{status} eq "pending") {
$printstatus = " where status = '$INPUT{status}'";
}
elsif ($INPUT{status} eq "paid") {
$printstatus = " where status = '$INPUT{status}'";
}
elsif ($INPUT{status} eq "archive") {
$printstatus = " where status = '$INPUT{status}'";
}

else {
$printstatus = "";
}
 


    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from invoices$printstatus ORDER BY invoiceid DESC");
$aasth->execute;
print <<"STARTOFTHEPAGE";
<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">Showing All $INPUT{status} Invoices</font><br>
$printmessage
<hr color="black">
~;
while (($invoiceid,$propertyid,$clientid,$invoicedate,$billtoname,$billtoaddress,$billtoaddress2,$billtocity,$billtostate,$billtozip,$worktype_1,$address_1,$date_1,$price_1,$notes_1,$worktype_2,$address_2,$date_2,$price_2,$notes_2,$worktype_3,$address_3,$date_3,$price_3,$notes_3,$worktype_4,$address_4,$date_4,$price_4,$notes_4,$worktype_5,$address_5,$date_5,$price_5,$notes_5,$worktype_6,$address_6,$date_6,$price_6,$notes_6,$worktype_7,$address_7,$date_7,$price_7,$notes_7,$worktype_8,$address_8,$date_8,$price_8,$notes_8,$totalprice,$status) = $aasth->fetchrow_array()) {
if ($INPUT{status} eq "pending") {
$markaspaid = "<a href=\"index.idx?action=changeinvoice&invoiceid=$invoiceid&type=paid\">Mark As PAID</a>   --   ";
}
elsif ($INPUT{status} eq "paid") {
$markaspaid = "<a href=\"index.idx?action=changeinvoice&invoiceid=$invoiceid&type=archive\">Archive Invoice</a>   --   ";
}
elsif ($INPUT{status} eq "archive") {
$markaspaid = "<b>Archived   --   </b>";
}
else {
$markaspaid = "None";
}


print qq~
$markaspaid<a href="index.idx?action=viewinvoice&invoiceid=$invoiceid&status=$INPUT{status}" target="_blank">INVOICE $invoiceid - $invoicedate - $billtoname - \$$totalprice </a><br>
~;
}
print qq~
</td>
</tr>
</table>
</td>
~;
&footer;
}

sub changeinvoice {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;

my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;
my $kasth = $dbh->do("update invoices set status = '$INPUT{type}' WHERE invoiceid = '$INPUT{invoiceid}'");
$dbh->disconnect;
$printmessage = "Updated Success!";

&searchinvoices;

}


sub viewinvoice {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";
use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from invoices where invoiceid = '$INPUT{invoiceid}' AND status = '$INPUT{status}'");
$aasth->execute;
while (($invoiceid,$propertyid,$clientid,$invoicedate,$billtoname,$billtoaddress,$billtoaddress2,$billtocity,$billtostate,$billtozip,$worktype_1,$address_1,$date_1,$price_1,$notes_1,$worktype_2,$address_2,$date_2,$price_2,$notes_2,$worktype_3,$address_3,$date_3,$price_3,$notes_3,$worktype_4,$address_4,$date_4,$price_4,$notes_4,$worktype_5,$address_5,$date_5,$price_5,$notes_5,$worktype_6,$address_6,$date_6,$price_6,$notes_6,$worktype_7,$address_7,$date_7,$price_7,$notes_7,$worktype_8,$address_8,$date_8,$price_8,$notes_8,$totalprice,$status) = $aasth->fetchrow_array()) {

if ($notes_1) {
$notes_1 = "( $notes_1 )";
}
if ($notes_2) {
$notes_2 = "( $notes_2 )";
}
if ($notes_3) {
$notes_3 = "( $notes_3 )";
}
if ($notes_4) {
$notes_4 = "( $notes_4 )";
}
if ($notes_5) {
$notes_5 = "( $notes_5 )";
}
if ($notes_6) {
$notes_6 = "( $notes_6 )";
}
if ($notes_7) {
$notes_7 = "( $notes_7 )";
}
if ($notes_8) {
$notes_8 = "( $notes_8 )";
}


if ($price_1) {
$price_1 = "<br><b>\$$price_1</b><br>";
}
if ($price_2) {
$price_2 = "<br><b>\$$price_2</b><br>";
}
if ($price_3) {
$price_3 = "<br><b>\$$price_3</b><br>";
}
if ($price_4) {
$price_4 = "<br><b>\$$price_4</b><br>";
}
if ($price_5) {
$price_5 = "<br><b>\$$price_5</b><br>";
}
if ($price_6) {
$price_6 = "<br><b>\$$price_6</b><br>";
}
if ($price_7) {
$price_7 = "<br><b>\$$price_7</b><br>";
}
if ($price_8) {
$price_8 = "<br><b>\$$price_8</b><br>";
}
if ($worktype_1) {
$worktype_1 = "---> <b>$worktype_1</b>   $notes_1";
}
if ($worktype_2) {
$worktype_2 = "---> <b>$worktype_2</b>   $notes_2";
}
if ($worktype_3) {
$worktype_3 = "---> <b>$worktype_3</b>   $notes_3";
}
if ($worktype_4) {
$worktype_4 = "---> <b>$worktype_4</b>   $notes_4";
}
if ($worktype_5) {
$worktype_5 = "---> <b>$worktype_5</b>   $notes_5";
}
if ($worktype_6) {
$worktype_6 = "---> <b>$worktype_6</b>   $notes_6";
}
if ($worktype_7) {
$worktype_7 = "---> <b>$worktype_7</b>   $notes_7";
}
if ($worktype_8) {
$worktype_8 = "---> <b>$worktype_8</b>   $notes_8";
}
if ($address_1) {
$address_1 = "Service Performed At $address_1";
}
if ($address_2) {
$address_2 = "Service Performed At $address_2";
}
if ($address_3) {
$address_3 = "Service Performed At $address_3";
}
if ($address_4) {
$address_4 = "Service Performed At $address_4";
}
if ($address_5) {
$address_5 = "Service Performed At $address_5";
}
if ($address_6) {
$address_6 = "Service Performed At $address_6";
}
if ($address_7) {
$address_7 = "Service Performed At $address_7";
}
if ($address_8) {
$address_8 = "Service Performed At $address_8";
}


print qq~
<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<title>Services Invoice</title>

<style>
<!--
 /* Font Definitions */
 \@font-face
	{font-family:"Arial Black";
	panose-1:2 11 10 4 2 1 2 2 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
h1
	{margin:0in;
	margin-bottom:.0001pt;
	text-align:right;
	page-break-after:avoid;
	font-size:10.0pt;
	font-family:Arial;}
p.MsoHeader, li.MsoHeader, div.MsoHeader
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
p.MsoFooter, li.MsoFooter, div.MsoFooter
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
\@page Section1
	{size:8.5in 11.0in;
	margin:.5in .5in .5in .5in;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=EN-US>

<div class=Section1>

<p class=MsoNormal><span style='position:absolute;z-index:1;margin-left:470px;
margin-top:33px;width:208px;height:64px'>

<table cellpadding=0 cellspacing=0>
 <tr>
  <td width=208 height=64 bgcolor=white style='vertical-align:top;background:
  white'><span style='position:absolute;z-index:1'>
  <table cellpadding=0 cellspacing=0 width="100%">
   <tr>
    <td>
    <div style='padding:3.6pt 7.2pt 3.6pt 7.2pt'>
    <p class=MsoNormal><span style='font-size:28.0pt;font-family:"Arial Black";
    color:gray'>INVOICE</span></p>
    </div>
    </td>
   </tr>
  </table>
  </span></td>
 </tr>
</table>

</span><b><i><img width=360 height=109 src="adinvoice_files/image001.jpg"></i></b></p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0
 style='border-collapse:collapse'>
 <tr>
  <td width=547 valign=top style='width:5.7in;padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal>7101 S. Cowan Road</p>
  <p class=MsoNormal>Muncie, Indiana 47302</p>
  <p class=MsoNormal>Phone 765-808-0990</p><br>
</td>
  <td width=187 valign=top style='width:1.95in;padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b>DATE: </b><b>$invoicedate</b></p>
  <p class=MsoNormal><b>INVOICE # $invoiceid</b></p>
  <p class=MsoNormal>&nbsp;</p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0
 style='border-collapse:collapse'>
 <tr style='height:1.0in'>
  <td width=367 valign=top style='width:275.4pt;padding:0in 5.4pt 0in 5.4pt;
  height:1.0in'>
  <p class=MsoNormal><b>Bill To:</b></p>
  <p class=MsoNormal>
 $billtoname<br>
 $billtoaddress<br>
 $billtoaddress2
 $billtocity, $billtostate $billtozip<br>
   </p>
  </td>
  <td width=367 valign=top style='width:275.4pt;padding:0in 5.4pt 0in 5.4pt;
  height:1.0in'>
  <p class=MsoNormal><b></b></p>
  <p class=MsoNormal>
</p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=1 cellspacing=0 cellpadding=0
 style='margin-left:5.4pt;border-collapse:collapse;border:none'>
 <tr>
  <td width=619 valign=top style='width:6.45in;border:solid windowtext 1.0pt;
  border-top:solid windowtext 1.5pt;padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=center style='text-align:center'><b>DESCRIPTION</b></p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border-top:solid windowtext 1.5pt;
  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=center style='text-align:center'><b>AMOUNT</b></p>
  </td>
 </tr>
 <tr>
  <td width=619 valign=top style='width:6.45in;border-top:none;border-left:
  solid windowtext 1.0pt;border-bottom:none;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal>$address_1 $date_1<br>$worktype_1<br><br>$address_2 $date_2<br>$worktype_2<br><br>$address_3 $date_3<br>$worktype_3<br><br>$address_4 $date_4<br>$worktype_4<br><br>$address_5 $date_5<br>$worktype_5<br><br>$address_6 $date_6<br>$worktype_6<br><br>$address_7 $date_7<br>$worktype_7<br><br>$address_8 $date_8<br>$worktype_8<br><br></p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border:none;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=right style='text-align:right'>$price_1<br>$price_2<br>$price_3<br>$price_4<br>$price_5<br>$price_6<br>$price_7<br>$price_8<br></p>
  </td>
 </tr>
   <tr style='height:1.15pt'>
  <td width=619 valign=top style='width:6.45in;border:solid windowtext 1.0pt;
  border-top:none;padding:.05in .15in .05in .15in;height:1.15pt'>
  <p class=MsoNormal>&nbsp;</p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in;height:1.15pt'>
  <p class=MsoNormal align=right style='text-align:right'>&nbsp;</p>
  </td>
 </tr>
 <tr style='height:1.4pt'>
  <td width=619 valign=top style='width:6.45in;border:none;padding:.05in .15in .05in .15in;
  height:1.4pt'>
  <h1>TOTAL</h1>
  </td>
  <td width=105 valign=top style='width:78.8pt;border:solid windowtext 1.0pt;
  border-top:none;padding:.05in .15in .05in .15in;height:1.4pt'>
  <p class=MsoNormal><b><font size="3" face="Arial">\$$totalprice</font></b></p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal> Please make all checks payable to <b>John Jett Jr.</b></p>

<p class=MsoHeader>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal align=center style='text-align:center'><b>Thank you for your business!</b></p>

</div>

</body>

</html>

~;
}
}

sub viewinvoiceryan {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from invoices where invoiceid = '$INPUT{invoiceid}' AND status = '$INPUT{status}'");
$aasth->execute;
while (($invoiceid,$propertyid,$clientid,$invoicedate,$billtoname,$billtoaddress,$billtoaddress2,$billtocity,$billtostate,$billtozip,$worktype_1,$address_1,$date_1,$price_1,$notes_1,$worktype_2,$address_2,$date_2,$price_2,$notes_2,$worktype_3,$address_3,$date_3,$price_3,$notes_3,$worktype_4,$address_4,$date_4,$price_4,$notes_4,$worktype_5,$address_5,$date_5,$price_5,$notes_5,$worktype_6,$address_6,$date_6,$price_6,$notes_6,$worktype_7,$address_7,$date_7,$price_7,$notes_7,$worktype_8,$address_8,$date_8,$price_8,$notes_8,$totalprice,$status) = $aasth->fetchrow_array()) {

if ($notes_1) {
$notes_1 = "( $notes_1 )";
}
if ($notes_2) {
$notes_2 = "( $notes_2 )";
}
if ($notes_3) {
$notes_3 = "( $notes_3 )";
}
if ($notes_4) {
$notes_4 = "( $notes_4 )";
}
if ($notes_5) {
$notes_5 = "( $notes_5 )";
}
if ($notes_6) {
$notes_6 = "( $notes_6 )";
}
if ($notes_7) {
$notes_7 = "( $notes_7 )";
}
if ($notes_8) {
$notes_8 = "( $notes_8 )";
}


if ($price_1) {
$price_1 = "<br><b>\$$price_1</b><br>";
}
if ($price_2) {
$price_2 = "<br><b>\$$price_2</b><br>";
}
if ($price_3) {
$price_3 = "<br><b>\$$price_3</b><br>";
}
if ($price_4) {
$price_4 = "<br><b>\$$price_4</b><br>";
}
if ($price_5) {
$price_5 = "<br><b>\$$price_5</b><br>";
}
if ($price_6) {
$price_6 = "<br><b>\$$price_6</b><br>";
}
if ($price_7) {
$price_7 = "<br><b>\$$price_7</b><br>";
}
if ($price_8) {
$price_8 = "<br><b>\$$price_8</b><br>";
}
if ($worktype_1) {
$worktype_1 = "---> <b>$worktype_1</b>   $notes_1";
}
if ($worktype_2) {
$worktype_2 = "---> <b>$worktype_2</b>   $notes_2";
}
if ($worktype_3) {
$worktype_3 = "---> <b>$worktype_3</b>   $notes_3";
}
if ($worktype_4) {
$worktype_4 = "---> <b>$worktype_4</b>   $notes_4";
}
if ($worktype_5) {
$worktype_5 = "---> <b>$worktype_5</b>   $notes_5";
}
if ($worktype_6) {
$worktype_6 = "---> <b>$worktype_6</b>   $notes_6";
}
if ($worktype_7) {
$worktype_7 = "---> <b>$worktype_7</b>   $notes_7";
}
if ($worktype_8) {
$worktype_8 = "---> <b>$worktype_8</b>   $notes_8";
}
if ($address_1) {
$address_1 = "Service Performed At $address_1";
}
if ($address_2) {
$address_2 = "Service Performed At $address_2";
}
if ($address_3) {
$address_3 = "Service Performed At $address_3";
}
if ($address_4) {
$address_4 = "Service Performed At $address_4";
}
if ($address_5) {
$address_5 = "Service Performed At $address_5";
}
if ($address_6) {
$address_6 = "Service Performed At $address_6";
}
if ($address_7) {
$address_7 = "Service Performed At $address_7";
}
if ($address_8) {
$address_8 = "Service Performed At $address_8";
}


print qq~
<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<title>Services Invoice</title>

<style>
<!--
 /* Font Definitions */
 \@font-face
	{font-family:"Arial Black";
	panose-1:2 11 10 4 2 1 2 2 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
h1
	{margin:0in;
	margin-bottom:.0001pt;
	text-align:right;
	page-break-after:avoid;
	font-size:10.0pt;
	font-family:Arial;}
p.MsoHeader, li.MsoHeader, div.MsoHeader
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
p.MsoFooter, li.MsoFooter, div.MsoFooter
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
\@page Section1
	{size:8.5in 11.0in;
	margin:.5in .5in .5in .5in;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=EN-US>

<div class=Section1>

<p class=MsoNormal><span style='position:absolute;z-index:1;margin-left:470px;
margin-top:33px;width:208px;height:64px'>

<table cellpadding=0 cellspacing=0>
 <tr>
  <td width=208 height=64 bgcolor=white style='vertical-align:top;background:
  white'><span style='position:absolute;z-index:1'>
  <table cellpadding=0 cellspacing=0 width="100%">
   <tr>
    <td>
    <div style='padding:3.6pt 7.2pt 3.6pt 7.2pt'>
    <p class=MsoNormal><span style='font-size:28.0pt;font-family:"Arial Black";
    color:gray'>INVOICE</span></p>
    </div>
    </td>
   </tr>
  </table>
  </span></td>
 </tr>
</table>

</span><b><i><font size="5">Ryan Orr Lawn Mowing</font></i></b></p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0
 style='border-collapse:collapse'>
 <tr>
  <td width=547 valign=top style='width:5.7in;padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal>7101 S. Cowan Road</p>
  <p class=MsoNormal>Muncie, Indiana 47302</p>
  <p class=MsoNormal>Phone 765-808-0990</p><br>
</td>
  <td width=187 valign=top style='width:1.95in;padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b>DATE: </b><b>$invoicedate</b></p>
  <p class=MsoNormal><b>INVOICE # $invoiceid</b></p>
  <p class=MsoNormal>&nbsp;</p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0
 style='border-collapse:collapse'>
 <tr style='height:1.0in'>
  <td width=367 valign=top style='width:275.4pt;padding:0in 5.4pt 0in 5.4pt;
  height:1.0in'>
  <p class=MsoNormal><b>Bill To:</b></p>
  <p class=MsoNormal>
 $billtoname<br>
 $billtoaddress<br>
 $billtoaddress2
 $billtocity, $billtostate $billtozip<br>
   </p>
  </td>
  <td width=367 valign=top style='width:275.4pt;padding:0in 5.4pt 0in 5.4pt;
  height:1.0in'>
  <p class=MsoNormal><b></b></p>
  <p class=MsoNormal>
</p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=1 cellspacing=0 cellpadding=0
 style='margin-left:5.4pt;border-collapse:collapse;border:none'>
 <tr>
  <td width=619 valign=top style='width:6.45in;border:solid windowtext 1.0pt;
  border-top:solid windowtext 1.5pt;padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=center style='text-align:center'><b>DESCRIPTION</b></p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border-top:solid windowtext 1.5pt;
  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=center style='text-align:center'><b>AMOUNT</b></p>
  </td>
 </tr>
 <tr>
  <td width=619 valign=top style='width:6.45in;border-top:none;border-left:
  solid windowtext 1.0pt;border-bottom:none;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal>$address_1 $date_1<br>����$worktype_1<br><br>$address_2 $date_2<br>����$worktype_2<br><br>$address_3 $date_3<br>����$worktype_3<br><br>$address_4 $date_4<br>����$worktype_4<br><br>$address_5 $date_5<br>����$worktype_5<br><br>$address_6 $date_6<br>����$worktype_6<br><br>$address_7 $date_7<br>����$worktype_7<br><br>$address_8 $date_8<br>����$worktype_8<br><br></p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border:none;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=right style='text-align:right'>$price_1<br>$price_2<br>$price_3<br>$price_4<br>$price_5<br>$price_6<br>$price_7<br>$price_8<br></p>
  </td>
 </tr>
   <tr style='height:1.15pt'>
  <td width=619 valign=top style='width:6.45in;border:solid windowtext 1.0pt;
  border-top:none;padding:.05in .15in .05in .15in;height:1.15pt'>
  <p class=MsoNormal>&nbsp;</p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in;height:1.15pt'>
  <p class=MsoNormal align=right style='text-align:right'>&nbsp;</p>
  </td>
 </tr>
 <tr style='height:1.4pt'>
  <td width=619 valign=top style='width:6.45in;border:none;padding:.05in .15in .05in .15in;
  height:1.4pt'>
  <h1>TOTAL</h1>
  </td>
  <td width=105 valign=top style='width:78.8pt;border:solid windowtext 1.0pt;
  border-top:none;padding:.05in .15in .05in .15in;height:1.4pt'>
  <p class=MsoNormal><b><font size="3" face="Arial">\$$totalprice</font></b></p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>� Please make all checks payable to <b>Ryan Orr</b></p>

<p class=MsoHeader>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal align=center style='text-align:center'><b>THANK YOU FOR YOUR
BUSINESS!</b></p>

</div>

</body>

</html>

~;
}
}

sub viewinvoicerange {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from invoices where invoiceid BETWEEN '$INPUT{startinvoice}' AND '$INPUT{endinvoice}'");
$aasth->execute;
while (($invoiceid,$propertyid,$clientid,$invoicedate,$billtoname,$billtoaddress,$billtoaddress2,$billtocity,$billtostate,$billtozip,$worktype_1,$address_1,$date_1,$price_1,$notes_1,$worktype_2,$address_2,$date_2,$price_2,$notes_2,$worktype_3,$address_3,$date_3,$price_3,$notes_3,$worktype_4,$address_4,$date_4,$price_4,$notes_4,$worktype_5,$address_5,$date_5,$price_5,$notes_5,$worktype_6,$address_6,$date_6,$price_6,$notes_6,$worktype_7,$address_7,$date_7,$price_7,$notes_7,$worktype_8,$address_8,$date_8,$price_8,$notes_8,$totalprice,$status) = $aasth->fetchrow_array()) {

if ($notes_1) {
$notes_1 = "( $notes_1 )";
}
if ($notes_2) {
$notes_2 = "( $notes_2 )";
}
if ($notes_3) {
$notes_3 = "( $notes_3 )";
}
if ($notes_4) {
$notes_4 = "( $notes_4 )";
}
if ($notes_5) {
$notes_5 = "( $notes_5 )";
}
if ($notes_6) {
$notes_6 = "( $notes_6 )";
}
if ($notes_7) {
$notes_7 = "( $notes_7 )";
}
if ($notes_8) {
$notes_8 = "( $notes_8 )";
}


if ($price_1) {
$price_1 = "<br><b>\$$price_1</b><br>";
}
if ($price_2) {
$price_2 = "<br><b>\$$price_2</b><br>";
}
if ($price_3) {
$price_3 = "<br><b>\$$price_3</b><br>";
}
if ($price_4) {
$price_4 = "<br><b>\$$price_4</b><br>";
}
if ($price_5) {
$price_5 = "<br><b>\$$price_5</b><br>";
}
if ($price_6) {
$price_6 = "<br><b>\$$price_6</b><br>";
}
if ($price_7) {
$price_7 = "<br><b>\$$price_7</b><br>";
}
if ($price_8) {
$price_8 = "<br><b>\$$price_8</b><br>";
}
if ($worktype_1) {
$worktype_1 = "---> <b>$worktype_1</b>   $notes_1";
}
if ($worktype_2) {
$worktype_2 = "---> <b>$worktype_2</b>   $notes_2";
}
if ($worktype_3) {
$worktype_3 = "---> <b>$worktype_3</b>   $notes_3";
}
if ($worktype_4) {
$worktype_4 = "---> <b>$worktype_4</b>   $notes_4";
}
if ($worktype_5) {
$worktype_5 = "---> <b>$worktype_5</b>   $notes_5";
}
if ($worktype_6) {
$worktype_6 = "---> <b>$worktype_6</b>   $notes_6";
}
if ($worktype_7) {
$worktype_7 = "---> <b>$worktype_7</b>   $notes_7";
}
if ($worktype_8) {
$worktype_8 = "---> <b>$worktype_8</b>   $notes_8";
}
if ($address_1) {
$address_1 = "Service Performed At $address_1";
}
if ($address_2) {
$address_2 = "Service Performed At $address_2";
}
if ($address_3) {
$address_3 = "Service Performed At $address_3";
}
if ($address_4) {
$address_4 = "Service Performed At $address_4";
}
if ($address_5) {
$address_5 = "Service Performed At $address_5";
}
if ($address_6) {
$address_6 = "Service Performed At $address_6";
}
if ($address_7) {
$address_7 = "Service Performed At $address_7";
}
if ($address_8) {
$address_8 = "Service Performed At $address_8";
}


print qq~
<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<title>Services Invoice</title>

<style>
<!--
 /* Font Definitions */
 \@font-face
	{font-family:"Arial Black";
	panose-1:2 11 10 4 2 1 2 2 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
h1
	{margin:0in;
	margin-bottom:.0001pt;
	text-align:right;
	page-break-after:avoid;
	font-size:10.0pt;
	font-family:Arial;}
p.MsoHeader, li.MsoHeader, div.MsoHeader
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
p.MsoFooter, li.MsoFooter, div.MsoFooter
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:Arial;}
\@page Section1
	{size:8.5in 11.0in;
	margin:.5in .5in .5in .5in;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=EN-US>

<div class=Section1>

<p class=MsoNormal><span style='position:absolute;z-index:1;margin-left:470px;
margin-top:33px;width:208px;height:64px'>

<table cellpadding=0 cellspacing=0>
 <tr>
  <td width=208 height=64 bgcolor=white style='vertical-align:top;background:
  white'><span style='position:absolute;z-index:1'>
  <table cellpadding=0 cellspacing=0 width="100%">
   <tr>
    <td>
    <div style='padding:3.6pt 7.2pt 3.6pt 7.2pt'>
    <p class=MsoNormal><span style='font-size:28.0pt;font-family:"Arial Black";
    color:gray'>INVOICE</span></p>
    </div>
    </td>
   </tr>
  </table>
  </span>�</td>
 </tr>
</table>

</span><b><i>�<img width=360 height=109 src="adinvoice_files/image001.jpg"></i></b></p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0
 style='border-collapse:collapse'>
 <tr>
  <td width=547 valign=top style='width:5.7in;padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal>300 E. Highland</p>
  <p class=MsoNormal>Muncie, Indiana 47303</p>
  <p class=MsoNormal>Phone 765.288-1826</p><br>
</td>
  <td width=187 valign=top style='width:1.95in;padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b>DATE:� </b><b>$invoicedate</b></p>
  <p class=MsoNormal><b>INVOICE # $invoiceid</b></p>
  <p class=MsoNormal>&nbsp;</p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0
 style='border-collapse:collapse'>
 <tr style='height:1.0in'>
  <td width=367 valign=top style='width:275.4pt;padding:0in 5.4pt 0in 5.4pt;
  height:1.0in'>
  <p class=MsoNormal><b>Bill To:</b></p>
  <p class=MsoNormal>
 $billtoname<br>
 $billtoaddress<br>
 $billtoaddress2
 $billtocity, $billtostate $billtozip<br>
   </p>
  </td>
  <td width=367 valign=top style='width:275.4pt;padding:0in 5.4pt 0in 5.4pt;
  height:1.0in'>
  <p class=MsoNormal><b></b></p>
  <p class=MsoNormal>
</p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<table class=MsoNormalTable border=1 cellspacing=0 cellpadding=0
 style='margin-left:5.4pt;border-collapse:collapse;border:none'>
 <tr>
  <td width=619 valign=top style='width:6.45in;border:solid windowtext 1.0pt;
  border-top:solid windowtext 1.5pt;padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=center style='text-align:center'><b>DESCRIPTION</b></p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border-top:solid windowtext 1.5pt;
  border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=center style='text-align:center'><b>AMOUNT</b></p>
  </td>
 </tr>
 <tr>
  <td width=619 valign=top style='width:6.45in;border-top:none;border-left:
  solid windowtext 1.0pt;border-bottom:none;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal>$address_1 $date_1<br>����$worktype_1<br><br>$address_2 $date_2<br>����$worktype_2<br><br>$address_3 $date_3<br>����$worktype_3<br><br>$address_4 $date_4<br>����$worktype_4<br><br>$address_5 $date_5<br>����$worktype_5<br><br>$address_6 $date_6<br>����$worktype_6<br><br>$address_7 $date_7<br>����$worktype_7<br><br>$address_8 $date_8<br>����$worktype_8<br><br></p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border:none;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in'>
  <p class=MsoNormal align=right style='text-align:right'>$price_1<br>$price_2<br>$price_3<br>$price_4<br>$price_5<br>$price_6<br>$price_7<br>$price_8<br></p>
  </td>
 </tr>
   <tr style='height:1.15pt'>
  <td width=619 valign=top style='width:6.45in;border:solid windowtext 1.0pt;
  border-top:none;padding:.05in .15in .05in .15in;height:1.15pt'>
  <p class=MsoNormal>&nbsp;</p>
  </td>
  <td width=105 valign=top style='width:78.8pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  padding:.05in .15in .05in .15in;height:1.15pt'>
  <p class=MsoNormal align=right style='text-align:right'>&nbsp;</p>
  </td>
 </tr>
 <tr style='height:1.4pt'>
  <td width=619 valign=top style='width:6.45in;border:none;padding:.05in .15in .05in .15in;
  height:1.4pt'>
  <h1>TOTAL</h1>
  </td>
  <td width=105 valign=top style='width:78.8pt;border:solid windowtext 1.0pt;
  border-top:none;padding:.05in .15in .05in .15in;height:1.4pt'>
  <p class=MsoNormal><b><font size="3" face="Arial">\$$totalprice</font></b></p>
  </td>
 </tr>
</table>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>� Please make all checks payable to <b>John Jett Jr.</b></p>

<p class=MsoHeader>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal align=center style='text-align:center'><b>Thank you for your business!</b></p>

</div>

</body>

</html>

~;
}
}

sub readnewinvoice {

if ($INPUT{rids}) {
$updaterids = "\(";
@rids = split(/\,/,$INPUT{rids});
	foreach $place (@rids) {
		$updaterids .= "reportid = \'$place\' OR ";
	}
$updaterids .= "reportid = \'IHAVENOIDEA\'\)";
}
else {
$updaterids = "reportid LIKE \'\%\'";
}

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;

my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;
my $oasth = $dbh->do("insert into invoices values('','$INPUT{propertyid}','$INPUT{clientid}','$INPUT{invoicedate}','$INPUT{billtoname}','$INPUT{billtoaddress}','$INPUT{billtoaddress2}','$INPUT{billtocity}','$INPUT{billtostate}','$INPUT{billtozip}','$INPUT{worktype_1}','$INPUT{address_1}','$INPUT{date_1}','$INPUT{price_1}','$INPUT{notes_1}','$INPUT{worktype_2}','$INPUT{address_2}','$INPUT{date_2}','$INPUT{price_2}','$INPUT{notes_2}','$INPUT{worktype_3}','$INPUT{address_3}','$INPUT{date_3}','$INPUT{price_3}','$INPUT{notes_3}','$INPUT{worktype_4}','$INPUT{address_4}','$INPUT{date_4}','$INPUT{price_4}','$INPUT{notes_4}','$INPUT{worktype_5}','$INPUT{address_5}','$INPUT{date_5}','$INPUT{price_5}','$INPUT{notes_5}','$INPUT{worktype_6}','$INPUT{address_6}','$INPUT{date_6}','$INPUT{price_6}','$INPUT{notes_6}','$INPUT{worktype_7}','$INPUT{address_7}','$INPUT{date_7}','$INPUT{price_7}','$INPUT{notes_7}','$INPUT{worktype_8}','$INPUT{address_8}','$INPUT{date_8}','$INPUT{price_8}','$INPUT{notes_8}','$INPUT{totalprice}','$INPUT{status}')");
my $kasth = $dbh->do("update reporting set status = 'invoiced' WHERE clientid = '$INPUT{clientid}' AND $updaterids");
$dbh->disconnect;

print qq~
<html>
<head>
<title>Creating New Invoice</title>
<meta http-equiv="Refresh" content="3; URL=http://www.orrnetworks.com/droopy/index.idx?action=searchinvoices&status=pending">
</head>
<body bgcolor="white">
<br><br><br><br>
<center><font size="3" face="Arial" color="Red">Please wait, While your new invoice is saved</font><br>You will be redirected to back to the pending invoice screen when finished.  If not <a href="http://www.orrnetworks.com/droopy/index.idx?action=searchinvoices&status=pending">Click Here</a>.</center>
</body>
</html>
~;

}

sub createinvoiceset {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";


use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select customerid,firstname,lastname,company from clients where customerid = '$INPUT{clientid}'");
$aasth->execute;

my $fasth = $dbh->prepare("select DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 HOUR),'%m\/%d\/%y')");
$fasth->execute;
while (($dmysql) = $fasth->fetchrow_array()) {
$mysqldate = "$dmysql";
}

my $gasth = $dbh->prepare("select firstname,lastname,company,address,address2,city,state,zip from clients where customerid = '$INPUT{clientid}'");
$gasth->execute;
while (($firstname,$lastname,$company,$address,$address2,$city,$state,$zip) = $gasth->fetchrow_array()) {
if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$bprintname = "$firstname $lastname";
	}
	else {
		$bprintname = "$firstname $lastname, $company";
	}
}
if ($address2) {
$fbaddress2 = "$address2<br>";
}
else {
$fbaddress2 = "";
}
$baddress = $address;
$bcity = $city;
$bstate = $state;
$bcity = $city;
$bzip = $zip;
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

while (($customerid,$firstname,$lastname,$company) = $aasth->fetchrow_array()) {
if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}

my $easth = $dbh->prepare("select COUNT(reportid) from reporting where clientid = '$customerid' and status = 'pending'");
$easth->execute;
while (($reportidnumber) = $easth->fetchrow_array()) {
$totalreportidnumber = "$reportidnumber";
if ($reportidnumber > 1) {
$item = "Items"
}
else {
$item = "Item";
}

}



print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">Create Invoice For $printname</font><br>Review The Following <b>$totalreportidnumber</b> $item To Be Invoiced<br>
<hr color="black">
<form method="get" action="index.idx">
<input type="hidden" value="readnewinvoice" name="action">
<input type="hidden" value="$INPUT{clientid}" name="clientid">
<input type="hidden" value="$mysqldate" name="invoicedate">
<input type="hidden" value="$bprintname" name="billtoname">
<input type="hidden" value="$baddress" name="billtoaddress">
<input type="hidden" value="$baddress2" name="billtoaddress2">
<input type="hidden" value="$bcity" name="billtocity">
<input type="hidden" value="$bstate" name="billtostate">
<input type="hidden" value="$bzip" name="billtozip">
<input type="hidden" value="pending" name="status">
<b>Invoiceid</b> - Auto<br>
<b>Invoice Date</b> - $mysqldate<br>
$bprintname<br>
$baddress<br>
$fbaddress2
$bcity, $bstate $bzip<br><br><br>
<font size="4" face="Arial Black">The Following Pending Completed Jobs Will Be Billed</font><br><hr color="black" width="100%">

<table border="0" cellpadding="3" cellspacing="0" width="100%">

~;

my $basth = $dbh->prepare("select * from reporting where clientid = '$customerid' and status = 'pending' order by reportid asc");
$basth->execute;

while (($reportid,$propertyid,$clientid,$status,$date,$price,$worktype,$notes) = $basth->fetchrow_array()) {

my $casth = $dbh->prepare("select address,city,state,zip from properties where propertyid = '$propertyid'");
$casth->execute;

while (($address,$city,$state,$zip) = $casth->fetchrow_array()) {

$fieldnumber++;

if ($fieldnumber > "8") {

}
else {
$totalprice = ($totalprice+$price);





if ($notes) {
$fixednotes = "<br><b>notes</b> $notes";
}

print qq~
<tr>
<td colspan="2"><font size="2"><b>$fieldnumber</b>    //    <b>$address $city, $state $zip</b></font></td>
</tr>
<tr>
<td>$worktype Performed On $date$fixednotes</td>
<td>\$$price</td>
<input type=hidden name="worktype\_$fieldnumber" value="$worktype">
<input type=hidden name="date\_$fieldnumber" value="$date">
<input type=hidden name="price\_$fieldnumber" value="$price">
<input type="hidden" name="address\_$fieldnumber" value="$address $city">
<input type="hidden" name="propertyid" value="$propertyid">
<input type="hidden" name="notes\_$fieldnumber" value="$notes">
<input type="hidden" name="rids" value="$reportid">
</tr>
<tr>
<td colspan="2"><hr color="silver" width="100%"></td>
</tr>
~;
}


}
}
}
print qq~
<tr>
<td><b><font size="3" face="Arial Black">TOTAL INVOICE AMOUNT</font></b></td>
<td><b><font size="3" face="Arial Black">\$$totalprice<input type="hidden" value="$totalprice" name="totalprice"></font></b></td>
</tr>
</table>

<br><input type="submit" value="Create Invoice Now">
</form>
</td>
</tr>
</table>
</form>
~;
&footer;


}

sub createinvoice {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select customerid,firstname,lastname,company from clients");
$aasth->execute;

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">Create Invoice</font><br>Select The Client(s) That Many Be Invoiced<br>
<hr color="black">
~;
while (($customerid,$firstname,$lastname,$company) = $aasth->fetchrow_array()) {


my $basth = $dbh->prepare("select clientid from reporting where clientid = '$customerid' and status = 'pending' group by clientid");
$basth->execute;

my $casth = $dbh->prepare("select COUNT(propertyid) from reporting where clientid = '$customerid' and status = 'pending'");
$casth->execute;

my $dasth = $dbh->prepare("select COUNT(propertyid) from reporting where clientid = '$customerid' and status = 'pending' group by propertyid");
$dasth->execute;

while (($thepnumberfound) = $dasth->fetchrow_array()) {
$pnumberfound = "$thepnumberfound";
}


while (($thenumberfound) = $casth->fetchrow_array()) {
$numberfound = "$thenumberfound";
}

while (($clientid) = $basth->fetchrow_array()) {

if ($firstname eq "" && $lastname eq "") {

$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}
if ($numberfound eq "1") {
$property = "Work Order";
}
else {
$property = "Work Orders";
}

print qq~
<a href="index.idx?action=createinvoiceset&clientid=$clientid">$printname - (Found $numberfound $property to invoice on (?$pnumberfound) properties)</a><br>
~;
}
}
print qq~
</td>
</tr>
</table>
~;
&footer;
}


sub dologworkset {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;

my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;
my $oasth = $dbh->do("insert into reporting values('','$INPUT{propertyid}','$INPUT{clientid}','$INPUT{status}','$INPUT{date}','$INPUT{price}','$INPUT{worktype}','$INPUT{notes}')");
$dbh->disconnect;

print qq~
<html>
<head>
<title>Logging Completed Work</title>
<meta http-equiv="Refresh" content="3; URL=http://www.orrnetworks.com/droopy/index.idx?action=logwork">
</head>
<body bgcolor="white">
<br><br><br><br>
<center><font size="3" face="Arial" color="Red">Please wait, While your work log is saved</font><br>You will be redirected to back to the logwork screen when finished.  If not <a href="http://www.orrnetworks.com/droopy/index.idx?action=logwork">Click Here</a>.</center>
</body>
</html>
~;

}


sub logworkset {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select propertyid,clientid,address,city,state,zip,nmowprice,imowprice from properties where propertyid = '$INPUT{propertyid}'");
$aasth->execute;

my $basth = $dbh->prepare("select firstname,lastname,company from clients where customerid = '$INPUT{clientid}'");
$basth->execute;

my $casth = $dbh->prepare("select description from pulldowns where type = 'worktype'");
$casth->execute;

my $dasth = $dbh->prepare("select DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 HOUR),'%m\/%d\/%y %h:%i%p')");
$dasth->execute;

while (($mysqldate) = $dasth->fetchrow_array()) {

while (($propertyid,$clientid,$address,$city,$state,$zip,$nmowprice,$imowprice) = $aasth->fetchrow_array()) {

while (($firstname,$lastname,$company) = $basth->fetchrow_array()) {

if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}
$spropertyid = "$propertyid";
$sclientid = "$clientid";
$snmowprice = "$nmowprice";
$simowprice = "$imowprice";

print <<"STARTOFTHEPAGE";

<html>
<head>
<script language="javascript" type="text/javascript">
<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}
// End -->
</script>

<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
	<table border="0" cellpadding="5" cellspacing="0" bgcolor="black" width="100%">
		<tr>
			<td valign="top" bgcolor="white" width="50%">
				<font size="4" face="Arial Black">Log Completed Work</font><br>
				Work Will Be Billed To Account --><br>
			</td>
			<td valign="top" bgcolor="navy" width="50%">
~;
print qq~
<font color="white"><font size="2"><b>
$printname<br>$address<br>$city, $state $zip</a>
</font></font></b><br>
~;
}
}

print qq~
			</td>
			</tr>
			</table>

<form name="myform" method="get" action="index.idx">
<input type="hidden" value="dologworkset" name="action">
<input type="hidden" value="$spropertyid" name="propertyid">
<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td valign="top"><b>Reporting ID</b></td>
<td valign="top"><b>AutoNumber</b></td>
</tr>
<tr>
<td valign="top"><b>Property ID</b></td>
<td valign="top"><b>$spropertyid</b></td>
</tr>
<tr>
<td valign="top"><b>Client ID</b></td>
<td valign="top"><b>$sclientid</b><input name="clientid" type="hidden" value="$sclientid"></td>
</tr>
<tr>
<td valign="top"><b>Price</b></td>
<td valign="top"><b>\$</b><input type="text" name="price" value="$snmowprice" size="5"> (Normal Mow Price Populated) \$$simowprice Initial</td>
</tr>
<tr>
<td valign="top"><b>Date & Time Of Completion</b></td>
<td valign="top"><input type="text" name="date" value="$mysqldate" size="25"> (For Invoicing Work)</td>
</tr>
<tr>
<td valign="top"><b>Billing Status</b></td>
<td valign="top"><select name="status"><option value="paid">Paid</option><option value="pending" selected>Pending</option></select></td>
</tr>
<tr>
<td valign="top"><b>Work Type</b></td>
<td valign="top"><select name="worktype">
~;
while (($description) = $casth->fetchrow_array()) {
print "<option value=\"$description\">$description</option>";
}
print qq~
</select></td>
</tr>
<tr>
<td valign="top"><b>Notes</b><br><b>max 50 characters</b></td>
<td valign="top"><textarea name=notes wrap=physical cols=50 rows=4 onKeyDown="textCounter(this.form.notes,this.form.remLen,50);" onKeyUp="textCounter(this.form.notes,this.form.remLen,50);"></textarea><br><input readonly type=text name=remLen size=3 maxlength=3 value="50"> characters left</td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" value="Log Work Into System Now"></center></td>
</tr>
</table>
</form>


</td>
</tr>
</table>
~;
&footer;

}
}



sub logwork {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select propertyid,clientid,address,city,state,zip from properties where status = 'a'");
$aasth->execute;

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">Log Completed Work</font><br>Select The Property To Log Completed Work<br>
<hr color="black">
~;
while (($propertyid,$clientid,$address,$city,$state,$zip) = $aasth->fetchrow_array()) {
my $basth = $dbh->prepare("select firstname,lastname,company from clients where customerid = '$clientid'");
$basth->execute;
while (($firstname,$lastname,$company) = $basth->fetchrow_array()) {
if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}
print qq~
<a href="index.idx?action=logworkset&propertyid=$propertyid&clientid=$clientid">$printname - $address $city, $state $zip</a><br>
~;
}
}
print qq~
</td>
</tr>
</table>
~;
&footer;
}

sub doaddproperty {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;
my $oasth = $dbh->do("insert into properties values('','$INPUT{clientid}','$INPUT{address}','$INPUT{address2}','$INPUT{city}','$INPUT{state}','$INPUT{zip}','$INPUT{directions}','$INPUT{notes}','$INPUT{nmowprice}','$INPUT{imowprice}','$INPUT{status}',now())");
$dbh->disconnect;

print qq~
<html>
<head>
<title>Adding Contact To Database</title>
<meta http-equiv="Refresh" content="1; URL=http://www.orrnetworks.com/droopy/index.idx?action=viewclient&customerid=$INPUT{clientid}">
</head>
<body bgcolor="white">
<br><br><br><br>
<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://www.orrnetworks.com/droopy/index.idx?action=viewclient&customerid=$INPUT{clientid}">Click Here</a>.</center>
</body>
</html>
~;
}

sub doaddclient {

print qq~
$INPUT{firstname} $INPUT{lastname}
~;

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

$INPUT{firstname} =~ s/\"/CHR2/gi;
$INPUT{firstname} =~ s/\'/CHR1/gi;
$INPUT{lastname} =~ s/\"/CHR2/gi;
$INPUT{lastname} =~ s/\'/CHR1/gi;
$INPUT{company} =~ s/\"/CHR2/gi;
$INPUT{company} =~ s/\'/CHR1/gi;
$INPUT{address} =~ s/\"/CHR2/gi;
$INPUT{address} =~ s/\'/CHR1/gi;
$INPUT{address2} =~ s/\"/CHR2/gi;
$INPUT{address2} =~ s/\'/CHR1/gi;
$INPUT{city} =~ s/\"/CHR2/gi;
$INPUT{city} =~ s/\'/CHR1/gi;
$INPUT{referredby} =~ s/\"/CHR2/gi;
$INPUT{referredby} =~ s/\'/CHR1/gi;
$INPUT{information} =~ s/\"/CHR2/gi;
$INPUT{information} =~ s/\'/CHR1/gi;


my $oasth = $dbh->do("insert into clients values('','$INPUT{firstname}','$INPUT{lastname}','$INPUT{company}','$INPUT{address}','$INPUT{address2}','$INPUT{city}','$INPUT{state}','$INPUT{zip}','$INPUT{workphone1}','$INPUT{workphone2}','$INPUT{workphone3}','$INPUT{homephone1}','$INPUT{homephone2}','$INPUT{homephone3}','$INPUT{mobilephone1}','$INPUT{mobilephone2}','$INPUT{mobilephone3}','$INPUT{referredby}','$INPUT{information}',now())");
$dbh->disconnect;

my $zaasth = $dbh->prepare("select customerid from clients ORDER BY customerid  DESC LIMIT 0,1");
$zaasth->execute;
while (($newcid) = $zaasth->fetchrow_array()) {
print qq~
<html>
<head>
<title>Adding Contact To Database</title>
<meta http-equiv="Refresh" content="1; URL=http://www.orrnetworks.com/droopy/index.idx?action=viewclient&customerid=$newcid">
</head>
<body bgcolor="white">
<br><br><br><br>
<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://www.orrnetworks.com/droopy/index.idx?action=viewclient&customerid=$newcid">Click Here</a>.</center>
</body>
</html>
~;
}


}

sub doeditclient {

$tempprintsql = "<font size=1 color=green><b>update clients set firstname = '$INPUT{firstname}' , lastname = '$INPUT{lastname}' , company = '$INPUT{company}' , address = '$INPUT{address}' , address2 = '$INPUT{address2}' , city = '$INPUT{city}' , state = '$INPUT{state}' , zip = '$INPUT{zip}' , workphone1 = '$INPUT{workphone1}' , workphone2 = '$INPUT{workphone2}' , workphone3 = '$INPUT{workphone3}' , homephone1 = '$INPUT{homephone1}' , homephone2 = '$INPUT{homephone2}' , homephone3 = '$INPUT{homephone3}' , mobilephone1 = '$INPUT{mobilephone1}' , mobilephone2 = '$INPUT{mobilephone2}' , mobilephone3 = '$INPUT{mobilephone3}' , referredby = '$INPUT{referredby}' , information = '$INPUT{information}' WHERE customerid = '7'</b></font><br><br>";

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

$INPUT{firstname} =~ s/\"/CHR2/gi;
$INPUT{firstname} =~ s/\'/CHR1/gi;
$INPUT{lastname} =~ s/\"/CHR2/gi;
$INPUT{lastname} =~ s/\'/CHR1/gi;
$INPUT{company} =~ s/\"/CHR2/gi;
$INPUT{company} =~ s/\'/CHR1/gi;
$INPUT{address} =~ s/\"/CHR2/gi;
$INPUT{address} =~ s/\'/CHR1/gi;
$INPUT{address2} =~ s/\"/CHR2/gi;
$INPUT{address2} =~ s/\'/CHR1/gi;
$INPUT{city} =~ s/\"/CHR2/gi;
$INPUT{city} =~ s/\'/CHR1/gi;
$INPUT{referredby} =~ s/\"/CHR2/gi;
$INPUT{referredby} =~ s/\'/CHR1/gi;
$INPUT{information} =~ s/\"/CHR2/gi;
$INPUT{information} =~ s/\'/CHR1/gi;

my $kasth = $dbh->do("update clients set firstname = '$INPUT{firstname}' , lastname = '$INPUT{lastname}' , company = '$INPUT{company}' , address = '$INPUT{address}' , address2 = '$INPUT{address2}' , city = '$INPUT{city}' , state = '$INPUT{state}' , zip = '$INPUT{zip}' , workphone1 = '$INPUT{workphone1}' , workphone2 = '$INPUT{workphone2}' , workphone3 = '$INPUT{workphone3}' , homephone1 = '$INPUT{homephone1}' , homephone2 = '$INPUT{homephone2}' , homephone3 = '$INPUT{homephone3}' , mobilephone1 = '$INPUT{mobilephone1}' , mobilephone2 = '$INPUT{mobilephone2}' , mobilephone3 = '$INPUT{mobilephone3}' , referredby = '$INPUT{referredby}' , information = '$INPUT{information}' WHERE customerid = '$INPUT{customerid}'");

$dbh->disconnect;

print qq~

<font size=5><b>Updated Client $INPUT{firstname} $INPUT{lastname} <font color=green>ok</font></b></font><br>
<br><br>
<a href=\"index.idx?action=showclients\">View Clients</a> | <a href=\"index.idx?action=editclient&customerid=$INPUT{customerid}\">Edit $INPUT{firstname} $INPUT{lastname}</a> |  <a href=\"index.idx?action=viewclient&customerid=$INPUT{customerid}\">View $INPUT{firstname} $INPUT{lastname}</a>
<br><br><br><br>
<b>Display Update SQL:</b><br> $tempprintsql
~;
}

sub viewclient {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";


use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from clients WHERE customerid = '$INPUT{customerid}'");
$aasth->execute;

my $basth = $dbh->prepare("select * from properties WHERE clientid = '$INPUT{customerid}'");
$basth->execute;

while (($customerid,$firstname,$lastname,$company,$address,$address2,$city,$state,$zip,$workphone1,$workphone2,$workphone3,$homephone1,$homephone2,$homephone3,$mobilephone1,$mobilephone2,$mobilephone3,$referredby,$information,$datejoined) = $aasth->fetchrow_array()) {
if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">View Client $printname</font><br>
<hr color="black">
<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td valign="top"><b>Customer ID</b></td>
<td valign="top">$customerid</td>
</tr>
<tr>
<td valign="top"><b>Firstname</b></td>
<td valign="top">$firstname</td>
</tr>
<tr>
<td valign="top"><b>Lastname</b></td>
<td valign="top">$lastname</td>
</tr>
<tr>
<td valign="top"><b>Company</b></td>
<td valign="top">$company</td>
</tr>
<tr>
<td valign="top"><b>Address</b></td>
<td valign="top">$address</td>
</tr>
<tr>
<td valign="top"><b>Address2</b></td>
<td valign="top">$address2</td>
</tr>
<tr>
<td valign="top"><b>City, State, Zip</b></td>
<td valign="top">$city,$state $zip</td>
</tr>
<tr>
<td valign="top">Work Phone</td>
<td valign="top">$workphone1-$workphone2-$workphone3</td>
</tr>
<tr>
<td valign="top">Home Phone</td>
<td valign="top">$homephone1-$homephone2-$homephone3</td>
</tr>
<tr>
<td valign="top">Mobile Phone</td>
<td valign="top">$mobilephone1-$mobilephone2-$mobilephone3</td>
</tr>
<tr>
<td valign="top" colspan="2">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" width="50%" bgcolor="navy">
<font color="white" size="3"><b>Properties Under Account</b></font><br>
</td>
<td valign="top" width="50%" bgcolor="navy" align="right">
<table border="0" cellpadding="3" cellspacing="1" bgcolor="white">
<tr>
<td valign="top" width="100%" bgcolor="navy">
<a class="navheader" href=index.idx?action=addpropertyset&client=$customerid>Add New Property</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" width="100%" colspan="2"><font size="2">
~;
while (($propertyid,$clientid,$address,$address2,$city,$state,$zip,$directions,$notes,$imowprice,$smowprice,$status,$dateadded) = $basth->fetchrow_array()) {
$propertyfound = "yes";

if ($status eq "a") {
$status = "<font color=green>Active</font> | ";
}
elsif ($status eq "n") {
$status = "<font color=red>Not Active</font> | ";
}
else {
$status = "<font color=red>Bad Database Contact Ryan Orr NOW! | </font>";
}
print "$status<font color=green><b><a href=index.idx?action=viewproperty&propertyid=$propertyid>$address $city $state $zip</a>  |  <a href=index.idx?action=editproperty&propertyid=$propertyid>Edit</a>  |  <a href=index.idx?action=viewproperty&propertyid=$propertyid>View</a></b></font><br>";
}
unless ($propertyfound eq "yes") {
print "<font color=red><b>No Properties Added!</b></font><br>";
}

print qq~
</font>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">Referred By</td>
<td valign="top">
	$referredby
</td>
</tr>
<tr>
<td valign="top">Customer Notes</td>
<td valign="top">
$information
</td>
</tr>
<tr>
<td valign="top"><b>Date Added</b></td>
<td valign="top">$datejoined</td>
</tr>
<tr>
<td colspan="2"><center>
<form method="post" action="index.idx">
<input type="hidden" value="editclient" name="action">
<input type="hidden" value="$customerid" name="customerid">
<input type="submit" value="Edit $firstname $lastname Now">
</form>
</center></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
~;

&footer;

}
}

sub editclient {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from clients WHERE customerid = '$INPUT{customerid}'");
$aasth->execute;

while (($customerid,$firstname,$lastname,$company,$address,$address2,$city,$state,$zip,$workphone1,$workphone2,$workphone3,$homephone1,$homephone2,$homephone3,$mobilephone1,$mobilephone2,$mobilephone3,$referredby,$information,$datejoined) = $aasth->fetchrow_array()) {
$referredby = "<option value=\"$referredby\">$referredby</option>";

if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">Edit Client $printname</font><br>
<hr color="black">
<form method="post" action="index.idx">
<input type="hidden" value="doeditclient" name="action">
<input type="hidden" value="$customerid" name="customerid">
<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td valign="top"><b>Customer ID</b></td>
<td valign="top">$customerid</td>
</tr>
<tr>
<td valign="top"><b>Firstname</b></td>
<td valign="top"><input name="firstname" type="text" value="$firstname"></td>
</tr>
<tr>
<td valign="top"><b>Lastname</b></td>
<td valign="top"><input name="lastname" type="text" value="$lastname"></td>
</tr>
<tr>
<td valign="top"><b>Company</b></td>
<td valign="top"><input name="company" type="text" value="$company"></td>
</tr>
<tr>
<td valign="top"><b>Address</b></td>
<td valign="top"><input name="address" type="text" value="$address"></td>
</tr>
<tr>
<td valign="top"><b>Address2</b></td>
<td valign="top"><input name="address2" type="text" value="$address2"></td>
</tr>
<tr>
<td valign="top"><b>City, State, Zip</b></td>
<td valign="top"><input name="city" type="text" value="$city" size="12">,<select name="state">$state<option value="Indiana">Indiana</option></select> <input name="zip" type="text" value="$zip" size="5"></td>
</tr>
<tr>
<td valign="top">Work Phone</td>
<td valign="top"><input name="workphone1" type="text" value="$workphone1" size="3">-<input name="workphone2" type="text" value="$workphone2" size="3">-<input name="workphone3" type="text" value="$workphone3" size="4"></td>
</tr>
<tr>
<td valign="top">Home Phone</td>
<td valign="top"><input name="homephone1" type="text" value="$homephone1" size="3">-<input name="homephone2" type="text" value="$homephone2" size="3">-<input name="homephone3" type="text" value="$homephone3" size="4"></td>
</tr>
<tr>
<td valign="top">Mobile Phone</td>
<td valign="top"><input name="mobilephone1" type="text" value="$mobilephone1" size="3">-<input name="mobilephone2" type="text" value="$mobilephone2" size="3">-<input name="mobilephone3" type="text" value="$mobilephone3" size="4"></td>
</tr>
<tr>
<td valign="top">Referred By</td>
<td valign="top">
	<select name="referredby">
	$referredby
	<option value="">-- Select Preference --</option>
	<option value="">- - - - - - - - - - - -</option>
	<option value="Door To Door Contact">Door To Door Contact</option>
	<option value="Flyer">Flyer</option>
	<option value="Friend">Friend</option>
	<option value="Current Customer Referral">Current Customer Referral</option>
	<option value="Other">Other</option>
	</select>
</td>
</tr>
<tr>
<td valign="top">Customer Notes</td>
<td valign="top">
<textarea name="information" cols="50" rows="10">$information</textarea>
</td>
</tr>
<tr>
<td valign="top"><b>Date Added</b></td>
<td valign="top">$datejoined</td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" value="Save $firstname $lastname Now"></center></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

~;

&footer;
}
}

sub addclient {

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Add New Property For $INPUT{client}</title>
STARTOFTHEPAGE

&header;

print qq~
<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">

	<table border="0" cellpadding="5" cellspacing="0" bgcolor="black" width="100%">
		<tr>
			<td valign="top" bgcolor="white" width="50%">
				<font size="4" face="Arial Black">Add New Client</font><br>
			</td>
			<td valign="top" bgcolor="navy" width="50%">
			</td>
		</tr>
	</table>

<form method="post" action="index.idx">
<input type="hidden" value="doaddclient" name="action">
<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td valign="top"><b>Firstname</b></td>
<td valign="top"><input name="firstname" type="text" value="$INPUT{firstname}"></td>
</tr>
<tr>
<td valign="top"><b>Lastname</b></td>
<td valign="top"><input name="lastname" type="text" value="$INPUT{lastname}"></td>
</tr>
<tr>
<td valign="top"><b>Company</b></td>
<td valign="top"><input name="company" type="text" value="$INPUT{company}"></td>
</tr>
<tr>
<td valign="top"><b>Address</b></td>
<td valign="top"><input name="address" type="text" value="$INPUT{address}"></td>
</tr>
<tr>
<td valign="top"><b>Address2</b></td>
<td valign="top"><input name="address2" type="text" value="$INPUT{address2}"></td>
</tr>
<tr>
<td valign="top"><b>City, State Zip</b></td>
<td valign="top"><input name="city" type="text" value="$INPUT{city}">,<select name="state"><option value="Indiana">Indiana</option></select> <input name="zip" type="text" value="$INPUT{zip}" size="5"></td>
</tr>
<tr>
<td valign="top"><b>Work Phone</b></td>
<td valign="top"><input name="workphone1" type="text" value="$INPUT{workphone1}" size="3">-<input name="workphone2" type="text" value="$INPUT{workphone2}" size="3">-<input name="workphone3" type="text" value="$INPUT{workphone3}" size="4"></td>
</tr>
<tr>
<td valign="top"><b>Home Phone</b></td>
<td valign="top"><input name="homephone1" type="text" value="$INPUT{homephone1}" size="3">-<input name="homephone2" type="text" value="$INPUT{homephone2}" size="3">-<input name="homephone3" type="text" value="$INPUT{homephone3}" size="4"></td>
</tr>
<tr>
<td valign="top"><b>Mobile Phone</b></td>
<td valign="top"><input name="mobilephone1" type="text" value="$INPUT{mobilephone1}" size="3">-<input name="mobilephone2" type="text" value="$INPUT{mobilephone2}" size="3">-<input name="mobilephone3" type="text" value="$INPUT{mobilephone3}" size="4"></td>
</tr>
<tr>
<td valign="top"><b>Referred By</b></td>
<td valign="top">
	<select name="referredby">
	<option value="">-- Select Preference --</option>
	<option value="">- - - - - - - - - - - -</option>
	<option value="Door To Door Contact">Door To Door Contact</option>
	<option value="Flyer">Flyer</option>
	<option value="Friend">Friend</option>
	<option value="Current Customer Referral">Current Customer Referral</option>
	<option value="Other">Other</option>
	</select>
</td>
</tr>
<tr>
<td valign="top"><b>Customer Notes</b></td>
<td valign="top">
<textarea name="information" cols="32" rows="10">Enter Information Here</textarea>
</td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" value="Enter New Client Now"></center></td>
</tr>
</table>
</form>

</td>
</tr>
</table>
</td>
~;

&footer;

}


sub showclients {

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">

<font size="4" face="Arial Black">Droopys Lawn & Maintenance Client List</font><br>
<hr color="black">

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr bgcolor="navy">
<td valign="top">
	<b><font color="white">Customer ID</font></b>
</td>
<td valign="top">
	<b><font color="white">Customer Name</font></b>
</td>
<td valign="top">
	<b><font color="white">Company</font></b>
</td>
<td valign="top">
	<b><font color="white">\# Of Properties</font></b>
</td>
<td valign="top">
	<b><font color="white">Actions</font></b>
</td>
</tr>
~;

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from clients");
$aasth->execute;
$startcountingit = "1";
while (($customerid,$firstname,$lastname,$company,$address,$address2,$city,$state,$zip,$workphone1,$workphone2,$workphone3,$homephone1,$homephone2,$homephone3,$mobilephone1,$mobilephone2,$mobilephone3,$referredby,$information,$datejoined) = $aasth->fetchrow_array()) {

my $basth = $dbh->prepare("select COUNT(clientid) from properties where clientid = '$customerid'");
$basth->execute;



if ($startcountingit eq "2") {
$showbgcolor = "FFFF99";
$startcountingit = "1";
}
else {
$showbgcolor = "white";
$startcountingit++;
}
while (($countnumber) = $basth->fetchrow_array()) {
print qq~
<tr bgcolor="$showbgcolor">
<td valign="top">
	<b><a href="index.idx?action=viewclient&customerid=$customerid">$customerid</a></b><br>
</td>
<td valign="top">
	<b><a href="index.idx?action=viewclient&customerid=$customerid">$firstname $lastname</a><br>
</td>
<td valign="top">
	<a href="index.idx?action=viewclient&customerid=$customerid">$company</a><br>
</td>
<td valign="top">
	$countnumber<br>
</td>
<td valign="top">
	<a href="index.idx?action=viewclient&customerid=$customerid">View</a> ..|.. <a href="index.idx?action=editclient&customerid=$customerid">Edit</a><br>
</td>
</tr>
~;
}
}

$dbh->disconnect;

print qq~
</table>
</td>
</tr>
</table>
</td>

~;

&footer;

}

sub clientsearch {

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Search Results</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">

<font size="4" face="Arial Black">Client Search Results</font><br>
<hr color="black">
Searching for $INPUT{find}<br><br>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top">
	<b>Customer ID</b>
</td>
<td valign="top">
	<b>Customer Name</b>
</td>
<td valign="top">
	<b>Company</b>
</td>
<td valign="top">
	<b>Actions</b>
</td>
</tr>
~;

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("SELECT * FROM clients WHERE $INPUT{type} LIKE '%$INPUT{find}%'");
$aasth->execute;

while (($customerid,$firstname,$lastname,$company,$address,$address2,$city,$state,$zip,$workphone1,$workphone2,$workphone3,$homephone1,$homephone2,$homephone3,$mobilephone1,$mobilephone2,$mobilephone3,$referredby,$information,$datejoined) = $aasth->fetchrow_array()) {

$foundsearch = "Yes";

if ($startcountingit eq "2") {
$showbgcolor = "FFFF99";
$startcountingit = "1";
}
else {
$showbgcolor = "white";
$startcountingit++;
}

print qq~
<tr bgcolor="$showbgcolor">
<td valign="top">
	<b>$customerid</b><br>
</td>
<td valign="top">
	<b>$firstname $lastname<br>
</td>
<td valign="top">
	$company<br>
</td>
<td valign="top">
	<a href="index.idx?action=viewclient&customerid=$customerid">View</a> ..|.. <a href="index.idx?action=editclient&customerid=$customerid">Edit</a><br>
</td>
</tr>
~;
}
$dbh->disconnect;

unless ($foundsearch eq "Yes") {
print "<tr><td colspan=4><font color=red><b>Cannot Find Your Search For <u>$INPUT{find}</u>!</b></font></font></td></tr>";
}

print qq~
</table>
</td>
</tr>
</table>
</td>

~;

&footer;

}

sub addproperty {

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Add New Property</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">

<font size="4" face="Arial Black">Add New Property</font><br>
Select Client To Add Property For Below<br><br>
<hr color="black">

<table border="0" cellpadding="0" cellspacing="0" width="100%">
~;

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from clients");
$aasth->execute;
$startcountingit = "1";
$starttablecount = "1";

while (($customerid,$firstname,$lastname,$company,$address,$address2,$city,$state,$zip,$workphone1,$workphone2,$workphone3,$homephone1,$homephone2,$homephone3,$mobilephone1,$mobilephone2,$mobilephone3,$referredby,$information,$datejoined) = $aasth->fetchrow_array()) {

if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}

if ($startcountingit eq "2") {
$showbgcolor = "FFFF99";
$startcountingit = "1";
}
else {
$showbgcolor = "white";
$startcountingit++;
}


print qq~
<tr bgcolor="$showbgcolor">
<td valign="top">
	<b><a href="index.idx?action=addpropertyset&client=$customerid">$printname</a><br>
</td>
</tr>
~;

}

$dbh->disconnect;

print qq~
</table>
</td>
</tr>
</table>
</td>

~;

&footer;

}

sub addpropertyset {

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Add New Property For $INPUT{client}</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">

	<table border="0" cellpadding="5" cellspacing="0" bgcolor="black" width="100%">
		<tr>
			<td valign="top" bgcolor="white" width="50%">
				<font size="4" face="Arial Black">Add New Property</font><br>
				Property Will Be Listed Under Account --><br>
			</td>
			<td valign="top" bgcolor="navy" width="50%">
~;

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from clients where customerid = '$INPUT{client}'");
$aasth->execute;
$starttablecount = "1";

while (($customerid,$firstname,$lastname,$company,$address,$address2,$city,$state,$zip,$workphone1,$workphone2,$workphone3,$homephone1,$homephone2,$homephone3,$mobilephone1,$mobilephone2,$mobilephone3,$referredby,$information,$datejoined) = $aasth->fetchrow_array()) {

if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}

if ($startcountingit eq "2") {
$showbgcolor = "FFFF99";
$startcountingit = "1";
}
else {
$showbgcolor = "white";
$startcountingit++;
}

if ($address2 eq "") {
$address2 = "";
}
else {
$address2 = "$address2<br>";
}

print qq~
<font color="white"><font size="2">
<b>$printname<br>
$address<br>
$address2
$city, $state $zip</b>
</font></font>
</td>
</tr>
</table>

<form method="post" action="index.idx">
<input type="hidden" value="doaddproperty" name="action">
<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td valign="top"><b>Property ID</b></td>
<td valign="top"><b>Auto Number</b></td>
</tr>
<tr>
<td valign="top"><b>Client ID</b></td>
<td valign="top"><b>$INPUT{client}</b><input name="clientid" type="hidden" value="$INPUT{client}"></td>
</tr>
<tr>
<td valign="top"><b>Address</b></td>
<td valign="top"><input name="address" type="text"></td>
</tr>
<tr>
<td valign="top"><b>Address2</b></td>
<td valign="top"><input name="address2" type="text"></td>
</tr>
<tr>
<td valign="top"><b>City, State Zip</b></td>
<td valign="top"><input name="city" type="text">,<select name="state"><option value="Indiana">Indiana</option></select> <input name="zip" type="text" size="5"></td>
</tr>
<tr>
<td valign="top"><b>Normal Mow Price</b></td>
<td valign="top"><b>\$</b><input type="text" name="nmowprice" value="20" size="5"></td>
</tr>
<tr>
<td valign="top"><b>Initial Mow Price</b></td>
<td valign="top"><b>\$</b><input type="text" name="imowprice" value="40" size="5"></td>
</tr>
<tr>
<td valign="top"><b>Property Status</b></td>
<td valign="top"><select name="status"><option value="a">Active (Servicing Property)</option><option value="n">Non-Active (Services)</option></select></td>
</tr>
<tr>
<td valign="top">Directions</td>
<td valign="top"><textarea name="directions" cols="50" rows="10">Enter Directions Here</textarea></td>
</tr>
<tr>
<td valign="top">Notes</td>
<td valign="top"><textarea name="notes" cols="50" rows="10">Enter Notes Here</textarea></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" value="Enter New Property Into System Now"></center></td>
</tr>
</table>
</form>

~;

}

$dbh->disconnect;

print qq~






</td>
</tr>
</table>
</td>

~;

&footer;

}

sub editproperty {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from properties WHERE propertyid = '$INPUT{propertyid}'");
$aasth->execute;

my $casth = $dbh->prepare("select customerid,firstname,lastname,company from clients");
$casth->execute;

while (($propertyid,$clientid,$address,$address2,$city,$state,$zip,$directions,$notes,$nmowprice,$imowprice,$status,$dateadded) = $aasth->fetchrow_array()) {

if ($status eq "a") {
$dstatus = "Active (Servicing Property)";
}
elsif ($status eq "n") {
$dstatus = "Non-Active (Services)";
}
else {
$dstatus = "BAD SETUP CONTACT RYAN";
}

$status = "<option value=$status>$dstatus</option>";

my $basth = $dbh->prepare("select * from clients WHERE customerid = '$clientid'");
$basth->execute;

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">Edit Property $address</font><br>
<hr color="black">
<form method="post" action="index.idx">
<input type="hidden" value="doeditproperty" name="action">
<input type="hidden" value="$propertyid" name="propertyid">
<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td valign="top"><b>Currently Linked To Customer</b></td>
<td valign="top">
~;

while (($customerid,$firstname,$lastname,$company) = $basth->fetchrow_array()) {
if ($firstname eq "" && $lastname eq "") {
$printname = "$company";
}
else {
	if ($company eq "N/A") {
		$printname = "$firstname $lastname";
	}
	else {
		$printname = "$firstname $lastname, $company";
	}
}
$buildcurrentclient = "<option value=$customerid>Do Not Move</option>";
print "<b>$printname</b>";
}

while (($customerid,$firstname,$lastname,$company) = $casth->fetchrow_array()) {
$buildclientlist .= "<option value=$customerid>$firstname $lastname $company</option>";
}


print qq~
<br>
Move To Client?
<select name="clientid">
$buildcurrentclient
<option value="">----------</option>
$buildclientlist
</select>
</td>
</tr>
<tr>
<td valign="top"><b>Property ID</b></td>
<td valign="top"><b>$propertyid</b><br>May Not Be Changed</td>
</tr>
<tr>
<td valign="top"><b>Address</b></td>
<td valign="top"><input name="address" type="text" value="$address"></td>
</tr>
<tr>
<td valign="top"><b>Address2</b></td>
<td valign="top"><input name="address2" type="text" value="$address2"></td>
</tr>
<tr>
<td valign="top"><b>City, State, Zip</b></td>
<td valign="top"><input name="city" type="text" value="$city" size="12">,<select name="state">$state<option value="Indiana">Indiana</option></select> <input name="zip" type="text" value="$zip" size="5"></td>
</tr>
<tr>
<td valign="top"><b>Normal Mow Price</b></td>
<td valign="top"><b>\$</b><input type="text" name="nmowprice" value="$nmowprice" size="5"></td>
</tr>
<tr>
<td valign="top"><b>Initial Mow Price</b></td>
<td valign="top"><b>\$</b><input type="text" name="imowprice" value="$imowprice" size="5"></td>
</tr>
<tr>
<td valign="top"><b>Property Status</b></td>
<td valign="top"><select name="status">$status<option value="">---------</option><option value="a">Active (Servicing Property)</option><option value="n">Non-Active (Services)</option></select></td>
</tr>
<tr>
<td valign="top">Directions</td>
<td valign="top"><textarea name="directions" cols="50" rows="10">$directions</textarea></td>
</tr>
<tr>
<td valign="top">Notes</td>
<td valign="top"><textarea name="notes" cols="50" rows="10">$notes</textarea></td>
</tr>


<tr>
<td valign="top"><b>Date Added</b></td>
<td valign="top">$dateadded</td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" value="Save $address Now"></center></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

~;
&footer;
}
}

sub doeditproperty {

$tempprintsql = "<font size=1 color=green><b>update properties set clientid = '$INPUT{clientid}' , address = '$INPUT{address}' , address2 = '$INPUT{address2}' , city = '$INPUT{city}' , state = '$INPUT{state}' , zip = '$INPUT{zip}' , directions = '$INPUT{directions}' , notes = '$INPUT{notes}' , nmowprice = '$INPUT{nmowprice}' , imowprice = '$INPUT{imowprice}' , status = '$INPUT{status}'</b></font><br><br>";

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;
my $aasth = $dbh->do("update properties set clientid = '$INPUT{clientid}' , address = '$INPUT{address}' , address2 = '$INPUT{address2}' , city = '$INPUT{city}' , state = '$INPUT{state}' , zip = '$INPUT{zip}' , directions = '$INPUT{directions}' , notes = '$INPUT{notes}' , nmowprice = '$INPUT{nmowprice}' , imowprice = '$INPUT{imowprice}' , status = '$INPUT{status}' WHERE propertyid = '$INPUT{propertyid}'");

$dbh->disconnect;

print qq~

<font size=5><b>Updated property $INPUT{Address} <font color=green>Successful</font></b></font><br>
<br><br>
<a href=\"index.idx?action=showclients\">View Clients</a> | <a href=\"index.idx?action=editproperty&propertyid=$INPUT{propertyid}\">Edit $address again</a>
<br><br><br><br>
<b>Display Update SQL:</b><br> $tempprintsql
~;
}

sub viewproperty {

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from properties WHERE propertyid = '$INPUT{propertyid}'");
$aasth->execute;

while (($propertyid,$clientid,$address,$address2,$city,$state,$zip,$directions,$notes,$nmowprice,$imowprice,$status,$dateadded) = $aasth->fetchrow_array()) {

if ($status eq "a") {
$status = "<font color=green>Active</font>";
}
else {
$status = "<font color=red>Not Active</font>";
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<font size="4" face="Arial Black">View Property $address</font><br>
<hr color="black">
<table border="0" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td valign="top"><b>Customer ID</b></td>
<td valign="top">$clientid</td>
</tr>
<tr>
<td valign="top"><b>Address</b></td>
<td valign="top">$address</td>
</tr>
<tr>
<td valign="top"><b>Address2</b></td>
<td valign="top">$address2</td>
</tr>
<tr>
<td valign="top"><b>City, State, Zip</b></td>
<td valign="top">$city,$state $zip</td>
</tr>
<tr>
<td valign="top"><b>Directions</b></td>
<td valign="top">$directions</td>
</tr>
<tr>
<td valign="top"><b>Notes</b></td>
<td valign="top">$notes</td>
</tr>
<tr>
<td valign="top"><b>Pricing</b></td>
<td valign="top">Initial $imowprice<br>Normal $nmowprice</td>
</tr>
<tr>
<td valign="top"><b>Status</b></td>
<td valign="top">
$status
</td>
</tr>
<tr>
<td valign="top"><b>Date Added</b></td>
<td valign="top">$dateadded</td>
</tr>
<tr>
<td colspan="2" bgcolor="navy"><font color="white" face="Arial" size="3">Invoice History</font></td>
</tr>
<tr>
<td colspan="2">
~;

$oasth = $dbh->prepare("select * from invoices where propertyid = ?");
$oasth->execute($INPUT{propertyid});
while ($data_ref = $oasth->fetchrow_hashref()) {
%db = %$data_ref;
$found = "yes";
print qq~
<a href="index.idx?action=viewinvoice&invoiceid=$db{invoiceid}&status=$db{STATUS}" target="_blank">INVOICE $db{invoiceid} - $db{invoicedate} - \$$db{totalprice} </a><br>
~;
}
unless ($found eq "yes") {
print qq~
<font color="red">No Invoices Found</font>
~;
}
print qq~
</td>
</tr>
<tr>
<td colspan="2"><center>
<form method="post" action="index.idx">
<input type="hidden" value="editproperty" name="action">
<input type="hidden" value="$propertyid" name="propertyid">
<input type="submit" value="Edit $address Now">
</form>
</center></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
~;
&footer;
}
}
sub showproperties {

if ($INPUT{status} eq "a") {
$status = "WHERE status = 'a'";
$statusname = "Active";
}
elsif ($INPUT{status} eq "n") {
$status = "WHERE status = 'n'";
$statusname = "Non-Active";
}
else {
$status = "";
$statusname = "All";
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>Client Management System</title>
STARTOFTHEPAGE

&header;

print qq~

<td valign="top" width="581">
<table border="0" cellpadding="7" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">

<font size="4" face="Arial Black">$statusname Property List</font><br>
<hr color="black">

<table border="0" cellpadding="3" cellspacing="2" width="100%">
<tr>
<td valign="top">
	<b>Address</b>
</td>
<td valign="top">
	<b>City</b>
</td>
<td valign="top">
	<b>State</b>
</td>
<td valign="top">
	<b>Zip</b>
</td>
<td valign="top">
	<b>Actions</b>
</td>
</tr>
~;

    $d_name = "orrnet_droopylawn";
    $d_username = "orrnet_droopylaw";
    $d_pass = "1687Secure";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $aasth = $dbh->prepare("select * from properties $status");
$aasth->execute;
$startcountingit = "1";
while (($propertyid,$clientid,$address,$address2,$city,$state,$zip) = $aasth->fetchrow_array()) {

if ($startcountingit eq "2") {
$showbgcolor = "FFFF99";
$startcountingit = "1";
}
else {
$showbgcolor = "white";
$startcountingit++;
}

print qq~
<tr bgcolor="$showbgcolor">
<td valign="top">
	<b>$address</b><br>
</td>
<td valign="top">
	<b>$city<br>
</td>
<td valign="top">
	$state<br>
</td>
<td valign="top">
	$zip<br>
</td>
<td valign="top">
	<a href="index.idx?action=viewproperty&propertyid=$propertyid">View</a> ..|.. <a href="index.idx?action=editproperty&propertyid=$propertyid">Edit</a><br>
</td>
</tr>
~;
}

$dbh->disconnect;

print qq~
</table>
</td>
</tr>
</table>
</td>

~;

&footer;

}


sub header {

open(HEADER,"includes/mainpage.txt");
@header = <HEADER>;
close(HEADER);



foreach $line (@header) {
$line =~ s/\$navbarcode/$navbarcode/g;
print "$line";
}


}



sub footer {

open(FOOTER,"includes/footer.txt");
@footer = <FOOTER>;
close(FOOTER);

foreach $line (@footer) {
print "$line";
}

}



sub commas {
	local($_)=@_;
	1 while s/(.*\d)(\d\d\d)/$1,$2/;
	$_;
}

