Another script issue

Discussion in 'Programming' started by glens1234, Dec 16, 2007.

  1. #1
    ok i have one more page left which is causing issues.

    Can anyone see anthing in my code which may cause be causing problems?

    <!--- define DSN name --->

    <CFSET appDSN = "tt380eca">

    <CFIF NOT IsDefined ("FORM.SupplierCode")>
    <CFLOCATION URL="admin_index.cfm">
    </CFIF>

    <CFQUERY NAME="qryGetSuppliers" DATASOURCE="#appDSN#">
    SELECT PurchaseDate
    FROM PurchaseOrders;
    </CFQUERY>

    <!--- Format PurchaseDate to DD:MM:YYYY --->
    <CFSET PurchaseDate = #NOW()#>
    <CFSET DateRange = DateFormat(PurchaseDate, "dd:mm:yyyy")>

    <!--- convert start date to DD:MM:YYYY. --->
    <CFQUERY NAME="qryGetSuppliers" DATASOURCE="#appDSN#">
    SELECT CONCAT_WS(DAYOFMONTH(#FORM.txtStartDay#),':',MONTH(#FORM.txtStartMonth#),':',#FORM.txtStartYear#) As StartDate; <!--- Im not sure if this is syntactically correct --->
    </CFQUERY>


    <!--- convert end date to DD:MM:YYYY. --->
    <CFQUERY NAME="qryGetSuppliers" DATASOURCE="#appDSN#">
    SELECT CONCAT_WS(DAYOFMONTH(#FORM.txtEndDay#),':',MONTH(#FORM.txtEndMonth#),':',#FORM.txtEndYear#) As EndDate;
    </CFQUERY>

    <!--- select all columns from each table based on selected date range and SupplierCode --->
    <CFQUERY NAME="qryGetSuppliers" DATASOURCE="#appDSN#">
    SELECT * FROM PurchaseOrders,Suppliers,PurchaseLines
    WHERE (DateRange GE #StartDate#) AND (DateRange LE #EndDate#) AND (SupplierCode = '#FORM.SupplierCode#');
    </CFQUERY>

    <!--- Calculate total number of transactions --->
    <CFSET TotalTransactions = qryGetSuppliers.RecordCount>
    <!--- Calculate total Value --->
    <CFQUERY NAME="qryGetSuppliers" DATASOURCE="#appDSN#">
    SELECT SUM(NetValue) As TotalValue
    FROM PurchaseOrders;
    </CFQUERY>


    <!--- Select all data from every table in order to calculate values and display results --->
    <CFQUERY NAME="qryGetSuppliers" DATASOURCE="#appDSN#">
    SELECT * FROM Suppliers,PurchaseOrders,PurchaseLines;
    </CFQUERY>

    <CFLOOP INDEX="1"
    FROM="1"
    TO="#TotalTransactions#"><!--loop though all records-->
    <!--- Calculate the amount of VAT payable by dividing the UnitCost by 100 and then multiplying by the VATRate. The resulting value will be stored in VATTotal --->
    <CFSET VATTotal = (UnitCost/100)*VATRate>
    <!--- Format VATTotal to specified format. i.e. 13,2--->
    <CFSET TotalVAT = LSNumberFormat(VATTotal, "-------------.--")>
    <!--- Accumulate total vat payable on each iteration of loop --->
    <CFSET TotalVATPayable = TotalVATPayable + TotalVAT>
    </CFLOOP>

    <!--- Print out results --->
    <table border="0" cellspacing="0" cellpadding="0">
    <!--- Use the query attribute of CFOUTPUT to display all data stored --->
    <CFOUTPUT QUERY="qryGetSuppliers">
    <tr>
    <td>Supplier Name:</td><td>#qryGetSuppliers.SupplierName#</td>
    </tr>
    <tr>
    <td>Address 1:</td><td>#qryGetSuppliers.Address1#</td>
    </tr>
    <tr>
    <td>Address 2:</td><td>#qryGetSuppliers.Address2#</td>
    </tr>
    <tr>
    <td>City:</td><td>#qryGetSuppliers.City#</td>
    </tr>
    <tr>
    <td>Post Code:</td><td>#qryGetSuppliers.PostCode#</td>
    </tr>
    <tr>
    <td>Sales Rep Name:</td><td>#qryGetSuppliers.SalesRepName#</td>
    </tr>
    <tr>
    <td>Sales Rep Phone:</td><td>#qryGetSuppliers.SalesRepPhone#</td>
    </tr>
    <tr>
    <td>Sales Rep Email:</td><td>#qryGetSuppliers.SalesRepEmail#</td>
    </tr>
    <tr>
    <td>Payment Terms:</td><td>#qryGetSuppliers.PaymentTerms#</td>
    </tr>
    <tr>
    <td>Note:</td><td>#qryGetSuppliers.Notes#</td>
    </tr>
    <tr>
    <td>Net Value:</td><td>#qryGetSuppliers.NetValue#</td>
    </tr>
    <tr>
    <td>Total VAT:</td><td>#qryGetSuppliers.TotalVAT#</td>
    </tr>
    <tr>
    <td>Purchase Date:</td><td>#qryGetSuppliers.PurchaseDate#</td>
    </tr>
    <tr>
    <td>Planned Delivery:</td><td>#qryGetSuppliers.PlannedDelivery#</td>
    </tr>
    <tr>
    <td>Payment Due:</td><td>#qryGetSuppliers.PaymentDue#</td>
    </tr>
    <tr>
    <td>Qunatity:</td><td>#qryGetSuppliers.Quantity#</td>
    </tr>
    <tr>
    <td>Unit Cost:</td><td>#qryGetSuppliers.UnitCost#</td>
    </tr>
    <tr>
    <td>Description:</td><td>#qryGetSuppliers.Description#</td>
    </tr>
    <tr>
    <td>Total Number of Transations:</td><td>#TotalTransations#</td>
    </tr>
    <tr>
    <td>Total Value of Transations:</td><td>#TotalValue#</td>
    </tr>
    <tr>
    <td>Total VAT Payable:</td><td>#TotalVATPayable#</td>
    </tr>
    </table>
    </CFOUTPUT>
     
    glens1234, Dec 16, 2007 IP
  2. glens1234

    glens1234 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i may need to revise this further as i as spotted a few errors already.
     
    glens1234, Dec 16, 2007 IP
  3. glens1234

    glens1234 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok ive ive narrowed down my problem to this statement....

    <CFSET DateRange = DateFormat(PurchaseDate, "dd:mm:yyyy")>

    I have printed PurchaseDate to the screen and it contains a value in the format YYYY:DD:MM

    The error msg i am getting is....

    Variable PURCHASEDATE is undefined.

    The error occurred in /home/gs4492/web/eca/purchase_report_temp.cfm: line 19

    17 : </CFQUERY>
    18 :
    19 : <CFSET DateRange = DateFormat(PurchaseDate, "dd:mm:yyyy")>
    20 : <!--- Select all from Purchase orders in order to count the num of records--->
    21 :

    can anyone see anything wrong with this code?

    Thanks.
     
    glens1234, Dec 16, 2007 IP
  4. glens1234

    glens1234 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry...

    just figured it out!

    It's always immediately after you've made a post that things become clear :)
     
    glens1234, Dec 16, 2007 IP