<?php
// - rcinfo.php
session_start();
require_once "main.php";
Logger::configure('log4php.xml');
$log = Logger::getLogger('rcinfo');
if ($_SESSION['access']<3){
	if ($_GET['submitType']=='cust') {
		$result = bill_get_rates($_SESSION['comnum']);
?>
		<script>
   			function setType(type)
   			{
      			//formName is the name of your form
      			document.accinform.submitType.value = type;
   			}
		</script>
		<table border="1">
    		<tr>
        		<th>Name</th>
        		<th>Description</th>
    		</tr>
			<?php
    		$zrx = 'edit';
    		for ($i=0;$i<count($result);$i++) {
        	?>
    		<tr>
        		<td><button <?php if ($_SESSION['access']>2){ echo 'disabled="disabled"';}?> type="button" value="arates" onClick="dynamic_Select('includes/rcinfo.php', '#setinfo','edit', <?php echo $result[$i]['id'];?>)"><?php echo $result[$i]['name'];?></button>
				</td>
        	<?php
         		echo '<td>'.$result[$i]['rdesc'].'</td></tr>';
    		}
			?>        
    	</table>
    	<button type="button" <?php if ($_SESSION['access']>2){ echo 'disabled="disabled"';}?> value="arates" onClick="dynamic_Select('includes/rcinfo.php', '#setinfo','add', '0')">Add a Rate Code</button>
		<?php
	} 
	else if ($_GET['submitType']=='rcUpdate') {
		$test = bill_update_rcode($_GET['id'], $_GET['name'], $_GET['rdesc'],
        	$_GET['gal1'], $_GET['amount1'], $_GET['gal2'], $_GET['amount2'], $_GET['gal3'], $_GET['amount3'], $_GET['gal4'], $_GET['amount4'], $_GET['gal5'], $_GET['amount5'], $_GET['gal6'], $_GET['amount6'], $_GET['gal7'], $_GET['amount7'], $_GET['gal8'], $_GET['amount8'], $_GET['gal9'], $_GET['amount9'], $_GET['gal10'], $_GET['amount10'], $_GET['gal11'], $_GET['amount11'], $_GET['lorder'], $_GET['tax']);
		$log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum'].' = '.$_GET['id']);
		$result = bill_get_rate($_GET['id']);
		if ($test) {
			echo '<script type=text/javascript>alert("Account updated successfully!");</script>';
		}
		?>
		<script>
   			function setType(type)
   			{
      			//formName is the name of your form
      			document.accinform.submitType.value = type;
   			}
		</script>
		<form name="accinform" action="#" onsubmit="jQuery.ajax({url:'includes/rcinfo.php', data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#setinfo').html(data);}});return false;">
    	<table>
        	<tr>
            	<td>
					<table border="1">
                    	<tr>
                        	<td><input type="hidden" name="id" id="id" value="<?php echo $result[0]['id']?>">
                        		<label for="name">Name</label>
							</td>
                        	<td><input type="text" name="name" id="name" value="<?php echo $result[0]['name']?>"></td>
                        	<td><label for="rdesc">Description</label></td>
                        	<td><input type="text" name="rdesc" id="rdesc" value="<?php echo $result[0]['rdesc']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal1">Monthly Base Gallons</label></td>
                        	<td><input type="text" name="gal1" id="gal1" value="<?php echo $result[0]['gal1']?>"></td>
                        	<td><label for="amount1">Amount</label></td>
                        	<td><input type="text" name="amount1" id="amount1" value="<?php echo $result[0]['amount1']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal2">Tier One Gallons</label></td>
                        	<td><input type="text" name="gal2" id="gal2" value="<?php echo $result[0]['gal2']?>"></td>
                        	<td><label for="amount2">Amount</label></td>
                        	<td><input type="text" name="amount2" id="amount2" value="<?php echo $result[0]['amount2']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal3">Tier Two Gallons</label></td>
                        	<td><input type="text" name="gal3" id="gal3" value="<?php echo $result[0]['gal3']?>"></td>
                        	<td><label for="amount3">Amount</label></td>
                        	<td><input type="text" name="amount3" id="amount3" value="<?php echo $result[0]['amount3']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal4">Tier Three Gallons</label></td>
                        	<td><input type="text" name="gal4" id="gal4" value="<?php echo $result[0]['gal4']?>"></td>
                        	<td><label for="amount4">Amount</label></td>
                        	<td><input type="text" name="amount4" id="amount4" value="<?php echo $result[0]['amount4']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal5">Tier Four Gallons</label></td>
                        	<td><input type="text" name="gal5" id="gal5" value="<?php echo $result[0]['gal5']?>"></td>
                        	<td><label for="amount5">Amount</label></td>
                        	<td><input type="text" name="amount5" id="amount5" value="<?php echo $result[0]['amount5']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal6">Tier Five Gallons</label></td>
                        	<td><input type="text" name="gal6" id="gal6" value="<?php echo $result[0]['gal6']?>"></td>
                        	<td><label for="amount6">Amount</label></td>
                        	<td><input type="text" name="amount6" id="amount6" value="<?php echo $result[0]['amount6']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal7">Tier Six Gallons</label></td>
                        	<td><input type="text" name="gal7" id="gal7" value="<?php echo $result[0]['gal7']?>"></td>
                        	<td><label for="amount7">Amount</label></td>
                        	<td><input type="text" name="amount7" id="amount7" value="<?php echo $result[0]['amount7']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal8">Tier Seven Gallons</label></td>
                        	<td><input type="text" name="gal8" id="gal8" value="<?php echo $result[0]['gal8']?>"></td>
                        	<td><label for="amount8">Amount</label></td>
                        	<td><input type="text" name="amount8" id="amount8" value="<?php echo $result[0]['amount8']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal9">Tier Eight Gallons</label></td>
                        	<td><input type="text" name="gal9" id="gal9" value="<?php echo $result[0]['gal9']?>"></td>
                        	<td><label for="amount9">Amount</label></td>
                        	<td><input type="text" name="amount9" id="amount9" value="<?php echo $result[0]['amount9']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal10">Tier Nine Gallons</label></td>
                        	<td><input type="text" name="gal10" id="gal10" value="<?php echo $result[0]['gal10']?>"></td>
                        	<td><label for="amount10">Amount</label></td>
                        	<td><input type="text" name="amount10" id="amount10" value="<?php echo $result[0]['amount10']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal11">Tier Ten Gallons</label></td>
                        	<td><input type="text" name="gal11" id="gal11" value="<?php echo $result[0]['gal11']?>"></td>
                        	<td><label for="amount11">Amount</label></td>
                        	<td><input type="text" name="amount11" id="amount11" value="<?php echo $result[0]['amount11']?>"></td>
                    	</tr>
                    	<tr>
	                        <td><label for="lorder">List Order</label></td>
    	                    <td><input type="text" name="lorder" id="lorder" value="<?php echo $result[0]['lorder']?>"></td>
        	                <td><label for="tax">Tax</label></td>
            	            <td><input type="text" name="tax" id="tax" value="<?php echo $result[0]['tax']?>"></td>                   
                    	</tr>
                    	<tr>
	                        <td><input type="hidden" name="submitType">
    		                    <input type="submit" onclick="setType('rcUpdate')" value="Update Rate"/>
							</td>
							<td></td>
							<td></td>
							<td></td>
                    	</tr>
            		</table>
				</td>
            	<td><p>The rate code can be a simple monthly flat fee by using only the monthly fields.  You
                	would enter the amount of the fee in the Amount box and place a 0 in the Gallons box.  You
                	would also enter a zero if you do not include any water in the base rate.  For a more 
                	complicated rate code with multiple usage levels, you fill in the levels you need.  The
                	list order is simply the order that the rate code is listed on reports etc when there are
                	more than one.</p>
				</td> 
        	</tr>
    	</table>
	</form>
<?php
	} 
	else if ($_GET['submitType']=='edit') {
		$result = bill_get_rate($_GET['id']);
?>
		<script>
   			function setType(type)
   			{
      			//formName is the name of your form
      			document.accinform.submitType.value = type;
   			}
		</script>
		<form name="accinform" action="#" onsubmit="jQuery.ajax({url:'includes/rcinfo.php', data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#setinfo').html(data);}});return false;">
    	<table>
        	<tr>
            	<td>
					<table border="1">
                    <tr>
                        <td><input type="hidden" name="id" id="id" value="<?php echo $result[0]['id']?>">
                        	<label for="name">Name</label>
						</td>
                        <td><input type="text" name="name" id="name" value="<?php echo $result[0]['name']?>"></td>
                        <td><label for="rdesc">Description</label></td>
                        <td><input type="text" name="rdesc" id="rdesc" value="<?php echo $result[0]['rdesc']?>"></td>
                    </tr>
                    <tr>
                        <td><label for="gal1">Monthly Base Gallons</label></td>
                        <td><input type="text" name="gal1" id="gal1" value="<?php echo $result[0]['gal1']?>"></td>
                        <td><label for="amount1">Amount</label></td>
                        <td><input type="text" name="amount1" id="amount1" value="<?php echo $result[0]['amount1']?>"></td>
                    </tr>
                    <tr>
                        <td><label for="gal2">Tier One Gallons</label></td>
                        <td><input type="text" name="gal2" id="gal2" value="<?php echo $result[0]['gal2']?>"></td>
                        <td><label for="amount2">Amount</label></td>
                        <td><input type="text" name="amount2" id="amount2" value="<?php echo $result[0]['amount2']?>"></td>
                    </tr>
                    <tr>
                        <td><label for="gal3">Tier Two Gallons</label></td>
                        <td><input type="text" name="gal3" id="gal3" value="<?php echo $result[0]['gal3']?>"></td>
                        <td><label for="amount3">Amount</label></td>
                        <td><input type="text" name="amount3" id="amount3" value="<?php echo $result[0]['amount3']?>"></td>
                    </tr>
                    <tr>
                        <td><label for="gal4">Tier Three Gallons</label></td>
                        <td><input type="text" name="gal4" id="gal4" value="<?php echo $result[0]['gal4']?>"></td>
                        <td><label for="amount4">Amount</label></td>
                        <td><input type="text" name="amount4" id="amount4" value="<?php echo $result[0]['amount4']?>"></td>
                    </tr>
                    <tr>
                        <td><label for="gal5">Tier Four Gallons</label></td>
                        <td><input type="text" name="gal5" id="gal5" value="<?php echo $result[0]['gal5']?>"></td>
                        <td><label for="amount5">Amount</label></td>
                        <td><input type="text" name="amount5" id="amount5" value="<?php echo $result[0]['amount5']?>"></td>
                    </tr>
                    <tr>
                        <td><label for="gal6">Tier Five Gallons</label></td>
                        <td><input type="text" name="gal6" id="gal6" value="<?php echo $result[0]['gal6']?>"></td>
                        <td><label for="amount6">Amount</label></td>
                        <td><input type="text" name="amount6" id="amount6" value="<?php echo $result[0]['amount6']?>"></td>
                    </tr>
                    <tr>
                        	<td><label for="gal7">Tier Six Gallons</label></td>
                        	<td><input type="text" name="gal7" id="gal7" value="<?php echo $result[0]['gal7']?>"></td>
                        	<td><label for="amount7">Amount</label></td>
                        	<td><input type="text" name="amount7" id="amount7" value="<?php echo $result[0]['amount7']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal8">Tier Seven Gallons</label></td>
                        	<td><input type="text" name="gal8" id="gal8" value="<?php echo $result[0]['gal8']?>"></td>
                        	<td><label for="amount8">Amount</label></td>
                        	<td><input type="text" name="amount8" id="amount8" value="<?php echo $result[0]['amount8']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal9">Tier Eight Gallons</label></td>
                        	<td><input type="text" name="gal9" id="gal9" value="<?php echo $result[0]['gal9']?>"></td>
                        	<td><label for="amount9">Amount</label></td>
                        	<td><input type="text" name="amount9" id="amount9" value="<?php echo $result[0]['amount9']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal10">Tier Nine Gallons</label></td>
                        	<td><input type="text" name="gal10" id="gal10" value="<?php echo $result[0]['gal10']?>"></td>
                        	<td><label for="amount10">Amount</label></td>
                        	<td><input type="text" name="amount10" id="amount10" value="<?php echo $result[0]['amount10']?>"></td>
                    	</tr>
                    	<tr>
                        	<td><label for="gal11">Tier Ten Gallons</label></td>
                        	<td><input type="text" name="gal11" id="gal11" value="<?php echo $result[0]['gal11']?>"></td>
                        	<td><label for="amount11">Amount</label></td>
                        	<td><input type="text" name="amount11" id="amount11" value="<?php echo $result[0]['amount11']?>"></td>
                    	</tr>
                    <tr>
                        <td><label for="lorder">List Order</label></td>
                        <td><input type="text" name="lorder" id="lorder" value="<?php echo $result[0]['lorder']?>"></td>
                        <td><label for="tax">Tax</label></td>
                        <td><input type="text" name="tax" id="tax" value="<?php echo $result[0]['tax']?>"></td>
                    
                    </tr>
                    <tr>
                        <td><input type="hidden" name="submitType">
                        	<input type="submit" onclick="setType('rcUpdate')" value="Update Rate"/>
						</td>
						<td></td>
						<td></td>
						<td>
                        	<input type="submit" onclick="setType('cust')" value="Cancel"/>
						</td>
                    </tr>
            		</table>
				</td>
            	<td><p>The rate code can be a simple monthly flat fee by using only the monthly fields.  You
                	would enter the amount of the fee in the Amount box and place a 0 in the Gallons box.  You
                	would also enter a zero if you do not include any water in the base rate.  For a more 
                	complicated rate code with multiple usage levels, you fill in the levels you need.  The
                	list order is simply the order that the rate code is listed on reports etc when there are
                	more than one.</p>
				</td> 
        	</tr>
    	</table>
		</form>
<?php
	} 
	else if ($_GET['submitType']=='add') {
	?>
		<script>
   			function setType(type)
   			{
      			//formName is the name of your form
      			document.accinform.submitType.value = type;
   			}
		</script>
		<form name="accinform" action="#" onsubmit="jQuery.ajax({url:'includes/rcinfo.php', data: jQuery(this).serialize(), cache: false, success: function(data){jQuery('#setinfo').html(data);}});return false;">
    	<table>
        	<tr>
            	<td>
					<table border="1">
                    <tr>
                        <td><label for="name">Name</label></td>
                        <td><input type="text" name="name" id="name" ></td>
                        <td><label for="rdesc">Description</label></td>
                        <td><input type="text" name="rdesc" id="rdesc"></td>
                    </tr>
                    <tr>
                        <td><label for="gal1">Monthly Base Gallons</label></td>
                        <td><input type="text" name="gal1" id="gal1"></td>
                        <td><label for="amount1">Amount</label></td>
                        <td><input type="text" name="amount1" id="amount1"></td>
                    </tr>
                    <tr>
                        <td><label for="gal2">Tier One Gallons</label></td>
                        <td><input type="text" name="gal2" id="gal2"></td>
                        <td><label for="amount2">Amount</label></td>
                        <td><input type="text" name="amount2" id="amount2"></td>
                    </tr>
                    <tr>
                        <td><label for="gal3">Tier Two Gallons</label></td>
                        <td><input type="text" name="gal3" id="gal3"></td>
                        <td><label for="amount3">Amount</label></td>
                        <td><input type="text" name="amount3" id="amount3"></td>
                    </tr>
                    <tr>
                        <td><label for="gal4">Tier Three Gallons</label></td>
                        <td><input type="text" name="gal4" id="gal4"></td>
                        <td><label for="amount4">Amount</label></td>
                        <td><input type="text" name="amount4" id="amount4"></td>
                    </tr>
                    <tr>
                        <td><label for="gal5">Tier Four Gallons</label></td>
                        <td><input type="text" name="gal5" id="gal5"></td>
                        <td><label for="amount5">Amount</label></td>
                        <td><input type="text" name="amount5" id="amount5"></td>
                    </tr>
                    <tr>
                        <td><label for="gal6">Tier Five Gallons</label></td>
                        <td><input type="text" name="gal6" id="gal6"></td>
                        <td><label for="amount6">Amount</label></td>
                        <td><input type="text" name="amount6" id="amount6"></td>
                    </tr>
                    <tr>
                        <td><label for="gal7">Tier Six Gallons</label></td>
                        <td><input type="text" name="gal7" id="gal7"></td>
                        <td><label for="amount7">Amount</label></td>
                        <td><input type="text" name="amount7" id="amount7"></td>
                    </tr>
                    <tr>
                        <td><label for="gal8">Tier Seven Gallons</label></td>
                        <td><input type="text" name="gal8" id="gal8"></td>
                        <td><label for="amount8">Amount</label></td>
                        <td><input type="text" name="amount8" id="amount8"></td>
                    </tr>
                    <tr>
                        <td><label for="gal9">Tier Eight Gallons</label></td>
                        <td><input type="text" name="gal9" id="gal9"></td>
                        <td><label for="amount9">Amount</label></td>
                        <td><input type="text" name="amount9" id="amount9"></td>
                    </tr>
                    <tr>
                        <td><label for="gal10">Tier Nine Gallons</label></td>
                        <td><input type="text" name="gal10" id="gal10"></td>
                        <td><label for="amount10">Amount</label></td>
                        <td><input type="text" name="amount10" id="amount10"></td>
                    </tr>
                    <tr>
                        <td><label for="gal11">Tier Ten Gallons</label></td>
                        <td><input type="text" name="gal11" id="gal11"></td>
                        <td><label for="amount11">Amount</label></td>
                        <td><input type="text" name="amount11" id="amount11"></td>
                    </tr>
                    <tr>
                        <td><label for="lorder">List Order</label></td>
                        <td><input type="text" name="lorder" id="lorder"></td>
                        <td><label for="tax">Tax</label></td>
                        <td><input type="text" name="tax" id="tax" ></td>
                    </tr>
                    <tr>
                        <td><input type="hidden" name="submitType">
                        	<input type="submit" onclick="setType('rcAdd')" value="Add Rate"/>
						</td>
						<td></td>
						<td></td>
						<td>
                        	<input type="submit" onclick="setType('cust')" value="Cancel"/>
						</td>						
                    </tr>
            		</table>
				</td>
            	<td><p>The rate code can be a simple monthly flat fee by using only the monthly fields.  You
                	would enter the amount of the fee in the Amount box and place a 0 in the Gallons box.  You
                	would also enter a zero if you do not include any water in the base rate.  For a more 
                	complicated rate code with multiple usage levels, you fill in the levels you need.  The
                	list order is simply the order that the rate code is listed on reports etc when there are
                	more than one.</p>
				</td>
        	</tr>
    	</table>
		</form>
	<?php
	} 
	else if ($_GET['submitType']=='rcAdd') {
		$test = bill_insert_rcode($_SESSION['comnum'], $_GET['name'], $_GET['rdesc'],	$_GET['gal1'], $_GET['amount1'], $_GET['gal2'], $_GET['amount2'], $_GET['gal3'], $_GET['amount3'], $_GET['gal4'], $_GET['amount4'], $_GET['gal5'], $_GET['amount5'], $_GET['gal6'], $_GET['amount6'], $_GET['gal7'], $_GET['amount7'], $_GET['gal8'], $_GET['amount8'], $_GET['gal9'], $_GET['amount9'], $_GET['gal10'], $_GET['amount10'], $_GET['gal11'], $_GET['amount11'], $_GET['lorder'], $_GET['tax']);
		$log->info($_GET['submitType'].' - user = '.$_SESSION['user'].' - '.$_SESSION['comnum']);
		$result = bill_get_rates($_SESSION['comnum']);
	?>
		<table border="1">
    		<tr>
        		<th>Name</th>
        		<th>Description</th>
    		</tr>
		<?php
    		$zrx = 'edit';
    		for ($i=0;$i<count($result);$i++) {
        ?>
        	<tr>
            	<td><button type="button" value="arates" onClick="dynamic_Select('includes/rcinfo.php', '#setinfo','edit', <?echo $result[$i]['id'];?>,<?echo $_SESSION['comnum'];?>)"><?echo $result[$i]['name'];?></button>
				</td>
        <?php
         		echo '<td>'.
            	$result[$i]['rdesc'].'</td></td></tr>';
    		}
		?>
    	</table>
    	<button type="button" value="arates" onClick="dynamic_Select('includes/rcinfo.php', '#setinfo','add', '0',<?echo $_SESSION['comnum'];?>)">Add a Rate Code</button>
		<?php
	}
} else {
?>
<script>alert('You do not have a high enough access level to post payments\n\
or charges!\n\
Please see your administrator.');</script>
<?php } ?>