Managing Taxes

 

Introduction.  Now we need to create an interface to display and modify state tax rates.  We need both a form for display and modification, ManageTax.asp, and a processing script to process the updates, UpdateTaxes.asp.  Each of these ASPs has a stored procedure to implement the database operations.

The following table gives the ASPs and stored procedures we will develop in this page.

 

Stored Procedure ASP Container
sp_RetrieveTaxRates ManageTax.asp
sp_UpdateTaxRate UpdateTaxes.asp

 

The Stored Procedures.  First we present the stored procedures.  Remember, you do not need to implement the stored procedures, this is to illustrate what you would need to do if you had the correct permissions in your database.  

The first stored procedure uses a  SELECT command in SQL to obtain all of the information from the Tax table.  The file should be called sp_RetrieveTaxRates.asp.

<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include File="adovbs.inc"-->

<%
' Open a connection to our SQL Server database
' We will use the ADO Driver connection

Dim connDeptProds, strSQLCreate
Set connDeptProds = Server.CreateObject("ADODB.Connection")
connDeptProds.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _
"Database=YourUserName;UID=cis; PWD=csatqu"

connDeptProds.Open

' Creating the SQL String to create the stored procedure
strSQLCreate = "CREATE PROCEDURE sp_RetrieveTaxRates AS " & _
"select * from tax"

connDeptProds.execute(strSQLCreate)

connDeptProds.Close
Set connDeptProds = Nothing

Response.Write "<font size = 5>The SQL has executed</font>"

%>

 

 

The second stored procedure uses an UPDATE command in SQL to modify the tax rate for the appropriate state in the Tax table.  This works for individual states identified by idState.  The file should be called sp_UpdateTaxRate.asp.
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include File="adovbs.inc"-->

<%
' Open a connection to our SQL Server database
' We will use the ADO Driver connection

Dim connDeptProds, strSQLCreate
Set connDeptProds = Server.CreateObject("ADODB.Connection")
connDeptProds.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _
"Database=YourUserName;UID=cis; PWD=csatqu"

connDeptProds.Open

' Creating the SQL String to create the stored procedure
strSQLCreate = "CREATE PROCEDURE sp_UpdateTaxRate " & _
"@fltTaxRate float, " & _
"@idState int AS " & _
"update tax set fltTaxRate = @fltTaxRate " & _
"where idState = @idState"

connDeptProds.execute(strSQLCreate)

connDeptProds.Close
Set connDeptProds = Nothing

Response.Write "<font size = 5>The SQL has executed</font>"

%>

 

 

As with all of the stored procedures you create, this file would only need to be executed once in your database.  After that you should get an error that the stored procedure already exists.  Since this is linked to the WildWillies database you do not even need to do this much.  But, remember, if you do execute such an ASP you can delete the ASP immediately after the stored procedure has been created.

The ManageTax.asp.  This is essentially a form page to display and allow modification of known tax rates.  You need to save this file and upload it to your StoreManager subdirectory.  Most of the lines of the code are due to the fact that tax rates are computed by each of fifty states and the District of Columbia. 

  1. It uses the validatecheck.asp include to make sure the user didn't try to circumvent the security.  
  2. It then uses the navinclude.asp to create the common navigation at the top of each page in the store manager.
  3. Connect to the database and execute the sp_RetrieveTaxRates stored procedure to return all of the states and their tax rates.
  4. Develops the form to display the information and accept modifications.

Call the file ManageTax.asp.

<%@ Language=VBScript %>
<!-- #Include file="include/validatecheck.asp" -->
<HTML>
<!-- ManageTax.asp - Supports managing the tax table 
settings for the store. -->


<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<!-- #include file="include/navinclude.asp" -->

<!-- Start the update display -->

<BR><B>Update the tax tables below:</b><BR>

<%

' Create an ADO database connection
set dbTax = server.createobject("adodb.connection")

' Create the record set
set rsTax = server.CreateObject("adodb.recordset")

' Open the connection using our SQL Server DSN-less connection
dbTax.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _
"Database=WildWillies;UID=cis; PWD=csatqu"

dbTax.Open

' Execute the Retrieve Tax Rates stored 
' procedure to retrieve all of the current tax rates.

sql = "execute sp_RetrieveTaxRates"

' Execute the statement
set rsTax = dbTax.Execute(sql)

' Loop through the tax rates.
do until rsTax.EOF

' We will retrieve the tax rate for each state
' and store it in a variable.

select case ucase(rsTax("chrState"))

case "AL"
fltAL = rsTax("fltTaxRate")
case "AK"
fltAK = rsTax("fltTaxRate")
case "AZ"
fltAZ = rsTax("fltTaxRate")
case "AR"
fltAR = rsTax("fltTaxRate")
case "CA"
fltCA = rsTax("fltTaxRate")
case "CT"
fltCT = rsTax("fltTaxRate")
case "CO"
fltCO = rsTax("fltTaxRate")
case "DC"
fltDC = rsTax("fltTaxRate")
case "DE"
fltDE = rsTax("fltTaxRate")
case "FL"
fltFL = rsTax("fltTaxRate")
case "GA"
fltGA = rsTax("fltTaxRate")
case "HI"
fltHI = rsTax("fltTaxRate")
case "ID"
fltID = rsTax("fltTaxRate")
case "IL"
fltIL = rsTax("fltTaxRate")
case "IN"
fltIN = rsTax("fltTaxRate")
case "IA"
fltIA = rsTax("fltTaxRate")
case "KS"
fltKS = rsTax("fltTaxRate")
case "KY"
fltKY = rsTax("fltTaxRate")
case "LA"
fltLA = rsTax("fltTaxRate")
case "ME"
fltME = rsTax("fltTaxRate")
case "MA"
fltMA = rsTax("fltTaxRate")
case "MD"
fltMD = rsTax("fltTaxRate")
case "MI"
fltMI = rsTax("fltTaxRate")
case "MN"
fltMN = rsTax("fltTaxRate")
case "MS"
fltMS = rsTax("fltTaxRate")
case "MO"
fltMO = rsTax("fltTaxRate")
case "MT"
fltMT = rsTax("fltTaxRate")
case "NE"
fltNE = rsTax("fltTaxRate")
case "NV"
fltNV = rsTax("fltTaxRate")
case "NH"
fltNH = rsTax("fltTaxRate")
case "NJ"
fltNJ = rsTax("fltTaxRate")
case "NM"
fltNM = rsTax("fltTaxRate")
case "NY"
fltNY = rsTax("fltTaxRate")
case "NC"
fltNC = rsTax("fltTaxRate")
case "ND"
fltND = rsTax("fltTaxRate")
case "OH"
fltOH = rsTax("fltTaxRate")
case "OK"
fltOK = rsTax("fltTaxRate")
case "OR"
fltOR = rsTax("fltTaxRate")
case "PA"
fltPA = rsTax("fltTaxRate")
case "RI"
fltRI = rsTax("fltTaxRate")
case "SC"
fltSC = rsTax("fltTaxRate")
case "SD"
fltSD = rsTax("fltTaxRate")
case "TN"
fltTN = rsTax("fltTaxRate")
case "TX"
fltTX = rsTax("fltTaxRate")
case "UT"
fltUT = rsTax("fltTaxRate")
case "VT"
fltVT = rsTax("fltTaxRate")
case "VA"
fltVA = rsTax("fltTaxRate")
case "WA"
fltWA = rsTax("fltTaxRate")
case "WY"
fltWY = rsTax("fltTaxRate")
case "WI"
fltWI = rsTax("fltTaxRate")
case "WV"
fltWV = rsTax("fltTaxRate")

end select

rsTax.movenext

Loop

%>

<!-- The form is created to post the changes -->
<form method="post" action="UpdateTaxes.asp">

<!-- Start the table to dispay the tax rates -->
<table cellpadding="3" cellspacing="3" border="1">
<!-- Show the header row -->
<tr>
<th>State</th><th>Rate</th>
<th>State</th><th>Rate</th>
<th>State</th><th>Rate</th>
<th>State</th><th>Rate</th>
</tr>
<!-- Build the first row of four tax rates. -->
<tr>
<!-- Display the Alabama symbol and the Alabama tax rate and then for other states-->
<td>Alabama</td><td><input type="text" name="AL" value="<%=fltAL%>" size="5"></td>
<td>Alaska</td><td><input type="text" name="AK" value="<%=fltAK%>" size="5"></td>
<td>Arizona</td><td><input type="text" name="AZ" value="<%=fltAZ%>" size="5"></td>
<td>Arkansas</td><td><input type="text" name="AR" value="<%=fltAR%>" size="5"></td>
</tr>
<tr>
<td>California</td><td><input type="text" name="CA" value="<%=fltCA%>" size="5"></td>
<td>Connecticut</td><td><input type="text" name="CT" value="<%=fltCT%>" size="5"></td>
<td>Colorado</td><td><input type="text" name="CO" value="<%=fltCO%>" size="5"></td>
<td>District of Columbia</td><td><input type="text" name="DC" value="<%=fltDC%>" size="5"></td>
</tr>
<tr>
<td>Delaware</td><td><input type="text" name="DE" value="<%=fltDE%>" size="5"></td>
<td>Florida</td><td><input type="text" name="FL" value="<%=fltFL%>" size="5"></td>
<td>Georgia</td><td><input type="text" name="GA" value="<%=fltGA%>" size="5"></td>
<td>Hawaii</td><td><input type="text" name="HI" value="<%=fltHI%>" size="5"></td>
</tr>
<tr>
<td>Idaho</td><td><input type="text" name="ID" value="<%=fltID%>" size="5"></td>
<td>Illinois</td><td><input type="text" name="IL" value="<%=fltIL%>" size="5"></td>
<td>Indiana</td><td><input type="text" name="IN" value="<%=fltIN%>" size="5"></td>
<td>Iowa</td><td><input type="text" name="IA" value="<%=fltIA%>" size="5"></td>
</tr>
<tr>
<td>Kansas</td><td><input type="text" name="KS" value="<%=fltKS%>" size="5"></td>
<td>Kentucky</td><td><input type="text" name="KY" value="<%=fltKY%>" size="5"></td>
<td>Lousiana</td><td><input type="text" name="LA" value="<%=fltLA%>" size="5"></td>
<td>Maine</td><td><input type="text" name="ME" value="<%=fltME%>" size="5"></td>
</tr>
<tr>
<td>Massachusetts</td><td><input type="text" name="MA" value="<%=fltMA%>" size="5"></td>
<td>Maryland</td><td><input type="text" name="MD" value="<%=fltMD%>" size="5"></td>
<td>Michigan</td><td><input type="text" name="MI" value="<%=fltMI%>" size="5"></td>
<td>Minnesota</td><td><input type="text" name="MN" value="<%=fltMN%>" size="5"></td>
</tr>
<tr>
<td>Mississippi</td><td><input type="text" name="MS" value="<%=fltMS%>" size="5"></td>
<td>Missouri</td><td><input type="text" name="MO" value="<%=fltMO%>" size="5"></td>
<td>Montana</td><td><input type="text" name="MT" value="<%=fltMT%>" size="5"></td>
<td>Nebraska</td><td><input type="text" name="NE" value="<%=fltNE%>" size="5"></td>
</tr>
<tr>
<td>Nevada</td><td><input type="text" name="NV" value="<%=fltNV%>" size="5"></td>
<td>New Hampshire</td><td><input type="text" name="NH" value="<%=fltNH%>" size="5"></td>
<td>New Jersey</td><td><input type="text" name="NJ" value="<%=fltNJ%>" size="5"></td>
<td>New Mexico</td><td><input type="text" name="NM" value="<%=fltNM%>" size="5"></td>
</tr>
<tr>
<td>New York</td><td><input type="text" name="NY" value="<%=fltNY%>" size="5"></td>
<td>North Carolina</td><td><input type="text" name="NC" value="<%=fltNC%>" size="5"></td>
<td>North Dakota</td><td><input type="text" name="ND" value="<%=fltND%>" size="5"></td>
<td>Ohio</td><td><input type="text" name="OH" value="<%=fltOH%>" size="5"></td>
</tr>
<tr>
<td>Oklahoma</td><td><input type="text" name="OK" value="<%=fltOK%>" size="5"></td>
<td>Oregon</td><td><input type="text" name="OR" value="<%=fltOR%>" size="5"></td>
<td>Pennsylvania</td><td><input type="text" name="PA" value="<%=fltPA%>" size="5"></td>
<td>Rhode Island</td><td><input type="text" name="RI" value="<%=fltRI%>" size="5"></td>
</tr>
<tr>
<td>South Carolina</td><td><input type="text" name="SC" value="<%=fltSC%>" size="5"></td>
<td>South Dakota</td><td><input type="text" name="SD" value="<%=fltSD%>" size="5"></td>
<td>Tennessee</td><td><input type="text" name="TN" value="<%=fltTN%>" size="5"></td>
<td>Texas</td><td><input type="text" name="TX" value="<%=fltTX%>" size="5"></td>
</tr>
<tr>
<td>Utah</td><td><input type="text" name="UT" value="<%=fltUT%>" size="5"></td>
<td>Vermont</td><td><input type="text" name="VT" value="<%=fltVT%>" size="5"></td>
<td>Virginia</td><td><input type="text" name="VA" value="<%=fltVA%>" size="5"></td>
<td>Washington</td><td><input type="text" name="WA" value="<%=fltWA%>" size="5"></td>
</tr>
<tr>
<td>Wyoming</td><td><input type="text" name="WY" value="<%=fltWY%>" size="5"></td>
<td>Wisconsin</td><td><input type="text" name="WI" value="<%=fltWI%>" size="5"></td>
<td>West Virgnia</td><td><input type="text" name="WV" value="<%=fltWV%>" size="5"></td>
<td></td><td></td>
</tr>
<tr>
<td colspan="8" align="center">
<input type="submit" value="Update Tax Table" name="Submit">
</td>
</tr>
</table>

</form>

</BODY>
</HTML>

 

The form page should look like the following.

 

 

The UpdateTaxes.asp.  This is essentially a processing page to update a particular state's tax rate in the Tax table.   You need to save this file and upload it to your StoreManager subdirectory.  Since this ASP is completely an internal processing ASP it will do the following.

  1. Connect to the database and execute the sp_RetrieveTaxRates stored procedure to get all of the tax rates.
  2. Connect to the database and execute the sp_UpdateTaxRate for every state even if they weren't changed.
  3. Redirect the user back to the ManageTax.asp so that they can continue managing the taxes.

This coding is unusual for Jerke in its lack of efficiency, though it does allow the user to update several states at once.  While coding practices and what is considered good programming can be quite ambiguous and the source of disagreement, and Jerke really is a coder of merit, this code requires some worthwhile improvements.  Looks to me like it will be the source of a homework problem.  So we can first get this implemented for later improvement, call the file UpdateTaxes.asp.

<%@ Language=VBScript %>
<%
' ****************************************************
' UpdateTaxes.asp - Handles the updates of the tax
' tables.
' ****************************************************

' Create an ADO database connection

set dbTaxUpd = server.createobject("adodb.connection")

' Create the record set
set rsTaxUpd = server.CreateObject("adodb.recordset")

' Open the connection using our SQL Server DSN-less connection
dbTaxUpd.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _
"Database=WildWillies;UID=cis; PWD=csatqu"

dbTaxUpd.Open

' Create an ADO database connection
set dbTax = server.createobject("adodb.connection")

' Create the record set
set rsTax = server.CreateObject("adodb.recordset")

' Open the connection using our SQL Server DSN-less connection
dbTax.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _
"Database=WildWillies;UID=cis; PWD=csatqu"

dbTax.Open

' Exeute the stored procedure to retrieve the 
' current tax rate settings.

sql = "execute sp_RetrieveTaxRates"

' Execute the statement
set rsTax = dbTax.Execute(sql)

' Loop through the tax rate settings.
do until rsTax.EOF

' Do a select case to check which state we are
' going to update.

select case ucase(rsTax("chrState"))

' Check for Alabama
case "AL"
' Execute the sp_UpdateTaxRate stored procedure
' to change the tax rate setting for Alabama

dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("AL") & ", " & rsTax("idState")

case "AK"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("AK") & ", " & rsTax("idState")

case "AZ"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("AZ") & ", " & rsTax("idState")

case "AR"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("AR") & ", " & rsTax("idState")

case "CA"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("CA") & ", " & rsTax("idState")

case "CT"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("CT") & ", " & rsTax("idState")

case "CO"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("CO") & ", " & rsTax("idState")

case "DC"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("DC") & ", " & rsTax("idState")

case "DE"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("DE") & ", " & rsTax("idState")

case "FL"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("FL") & ", " & rsTax("idState")

case "GA"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("GA") & ", " & rsTax("idState")

case "HI"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request ("HI") & ", " & rsTax("idState")

case "ID"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("ID") & ", " & rsTax("idState")

case "IL"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("IL") & ", " & rsTax("idState")

case "IN"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("IN") & ", " & rsTax("idState")

case "IA"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("IA") & ", " & rsTax("idState")

case "KS"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("KS") & ", " & rsTax("idState")

case "KY"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("KY") & ", " & rsTax("idState")

case "LA"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("LA") & ", " & rsTax("idState")

case "ME"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("ME") & ", " & rsTax("idState")

case "MA"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("MA") & ", " & rsTax("idState")

case "MD"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("MD") & ", " & rsTax("idState")

case "MI"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("MI") & ", " & rsTax("idState")

case "MN"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("MN") & ", " & rsTax("idState")

case "MS"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("MS") & ", " & rsTax("idState")

case "MO"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("MO") & ", " & rsTax("idState")

case "MT"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("MT") & ", " & rsTax("idState")

case "NE"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("NE") & ", " & rsTax("idState")

case "NV"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("NV") & ", " & rsTax("idState")

case "NH"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("NH") & ", " & rsTax("idState")

case "NJ"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("NJ") & ", " & rsTax("idState")

case "NM"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("NM") & ", " & rsTax("idState")

case "NY"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("NY") & ", " & rsTax("idState")

case "NC"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("NC") & ", " & rsTax("idState")

case "ND"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("ND") & ", " & rsTax("idState")

case "OH"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("OH") & ", " & rsTax("idState")

case "OK"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("OK") & ", " & rsTax("idState")

case "OR"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("OR") & ", " & rsTax("idState")

case "PA"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("PA") & ", " & rsTax("idState")

case "RI"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("RI") & ", " & rsTax("idState")

case "SC"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("SC") & ", " & rsTax("idState")

case "SD"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("SD") & ", " & rsTax("idState")

case "TN"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("TN") & ", " & rsTax("idState")

case "TX"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("TX") & ", " & rsTax("idState")

case "UT"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("UT") & ", " & rsTax("idState")

case "VT"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("VT") & ", " & rsTax("idState")

case "VA"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("VA") & ", " & rsTax("idState")

case "WA"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("WA") & ", " & rsTax("idState")

case "WY"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("WY") & ", " & rsTax("idState")

case "WI"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("WI") & ", " & rsTax("idState")

case "WV"
dbTaxUpd.execute "execute sp_UpdateTaxRate " & _
request("WV") & ", " & rsTax("idState")

end select

' Move to the next state.
rsTax.movenext

Loop

' Send the user back to the tax manager 
' for a final check on the tax rate
' settings.

Response.Redirect "managetax.asp"

%>

 

You aren't likely to notice either ASP that much because they only run when a particular link on the ManageTax.asp is selected.  At the end of each ASP the tax information is updated and the user is routed back to the ManageTax.asp.