Welcome !
         

 VBS SCRIPT DEFINITION

Author Message
mcbritt60

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 3/20/2017
  • Status: offline
VBS SCRIPT DEFINITION Monday, March 20, 2017 3:48 AM (permalink)
0
I read the below script line to indicate that the Scheduled Date can only be the current date, is this accurate?
scheduledDate = oDateHelper.ConvertToMMDDYY(cdate(fields.List.Item(CURRENT_DATE).Value))
If my assumption is accurate, what is the best way to make 'scheduledDate' except today's date or a future date?
 
#1
    59cobalt

    • Total Posts : 2625
    • Scores: 253
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:VBS SCRIPT DEFINITION Monday, March 20, 2017 10:39 AM (permalink)
    0
    You will have to give anyone not sitting in front of your computer a lot more context before they can answer the question.
     
    #2
      mcbritt60

      • Total Posts : 4
      • Scores: 0
      • Reward points : 0
      • Joined: 3/20/2017
      • Status: offline
      Re:VBS SCRIPT DEFINITION Tuesday, March 21, 2017 6:18 AM (permalink)
      0
      Ok, I'm attaching the file as it doesn't have any confidential information. It is a fairly long script.
       
       
       
      Option Explicit

      '******************************************************************************
      ' constants and public variables
      '******************************************************************************
      public const CURRENT_DATE = "CurrentDate"
      public const LN_ACTION = "Action"
      public const LN_AMOUNT = "Amount"
      public const LN_PAYMENTS = "Payments"
      public const LN_OVERRIDES = "Overrides"
      public const LN_CURTAILMENT = "Curtailment"
      public const LN_ADD_ESCROW = "AdditionalEscrow"
      public const LN_SUSPENSE = "Suspense"
      public const LN_SUSPENSE_CODE = "SuspenseCode"
      public const LN_FEE = "Fee"
      public const LN_FEE_CODE = "FeeCode"
      public const LN_ADD_FEE_1 = "AdditionalFeeOne"
      public const LN_ADD_FEE_1_CODE = "AdditionalFeeOneCode"
      public const LN_ADD_FEE_2 = "AdditionalFeeTwo"
      public const LN_ADD_FEE_2_CODE = "AdditionalFeeTwoCode"
      public const LN_ADD_FEE_3 = "AdditionalFeeThree"
      public const LN_ADD_FEE_3_CODE = "AdditionalFeeThreeCode"

      public const LN_CORP_ADV_PAYEE = "CorpAdvancePayee"
      public const LN_CORP_ADV_REASON = "CorpAdvanceReason"
      public const LN_CORP_ADV_AMT = "CorpAdvanceAmount"

      public const LN_1ST_PRIN_BA = "LN_1ST_PRIN_BA"
      public const LN_PROCESS_STOP_CD = "LN_PROCESS_STOP_CD"
      public const OG_LOAN_MAT_DT = "OG_LOAN_MAT_DT"
      public const LN_NXT_PMT_DUE_DT = "LN_NXT_PMT_DUE_DT"
      public const MORT_BILL_NAME = "MORT_BILL_NAME"
      public const LN_TELEPHONE_NO = "LN_TELEPHONE_NO"
      public const NO_PAYMENTS_DUE = "NO_PAYMENTS_DUE"
      public const LN_MONTHLY_PMT_AM = "LN_MONTHLY_PMT_AM"
      public const ESCROW_PAYMENT = "ESCROW_PAYMENT"


      public const DELINQUENCY_FEE = "DelinquencyFee"
      public const ROUTING_NUMBER = "RoutingNumber"
      public const ACCOUNT_NUMBER = "AccountNumber"
      public const ACCOUNT_TYPE = "AccountType"
      public const ACCOUNT_NAME = "ACCOUNT_NAME"

      public const LN_FEE_CAPTION = "Fee"
      public const LN_FEE_CODE_CAPTION = "Code"
      public const LN_ADD_FEE_1_CAPTION = "Addl Fee"
      public const LN_ADD_FEE_1_CODE_CAPTION = "Code"
      public const LN_ADD_FEE_2_CAPTION = "Addl Fee"
      public const LN_ADD_FEE_2_CODE_CAPTION = "Code"
      public const LN_ADD_FEE_3_CAPTION = "Addl Fee"
      public const LN_ADD_FEE_3_CODE_CAPTION = "Code"

      public const DELINQUENCY_FEE_CAPTION = "Delq Fee"
      public const ROUTING_NUMBER_CAPTION = "Routing Number"
      public const ACCOUNT_NUMBER_CAPTION = "Account Number"
      public const ACCOUNT_TYPE_CAPTION = "Account Type"
      public const ACCOUNT_NAME_CAPTION = "Account Name"

      public const ADDL_FEES = "AdditionalFees"
      public const ADDL_FEES_CAPTION = "Addl Fees"

      public const LN_RECEIVED_AMT = "AmountReceived"
      public const LN_RECEIVED_AMT_CAPTION = "Amount Received"

      public const LN_CORP_ADV_PAYEE_CAPTION = "Adv Payee"
      public const LN_CORP_ADV_REASON_CAPTION = "Adv Reason"
      public const LN_CORP_ADV_AMT_CAPTION = "Adv Amount"

      public const REQ_STRIP = 2
      public const EMPTY_STRING = ""
      public const BLANK_SPACE = " "
      public const UNDERSCORE = "_"
      public const DFT4 = "DFT4"
      public const SER1 = "SER1"
      public const ZERO_DOLLARS = "$0.00"
      public const PERIOD = "."

      dim PAYMENT_CODES
      PAYMENT_CODES = "0 - Misc Fee|" & _
      "1 - Late Change Fee|" & _
      "2 - NSF Fee|" & _
      "3 - Loan Assumption Fee|" & _
      "4 - Recording Fee|" & _
      "5 - Sterling Ext. Fee|" & _
      "C - Partial Release Fee|" & _
      "D - Doc Copy/Am Sch|" & _
      "F - Fax Fee|" & _
      "I - Modification/Ext Fee|" & _
      "J - BPO|" & _
      "K - One Time Draft Fee"

      dim SUSPENSE_CODES
      SUSPENSE_CODES = "01 - Reapplication Pndg|" & _
      "02 - Hold For Corp Adv|" & _
      "03 - Partial Payment|" & _
      "04 - Repmt Plan/P9 Stop|" & _
      "05 - Partial Pymt Bkrptcy|" & _
      "06 - Opt Ins No Bucket|" & _
      "07 - Pymt Over No Expla|" & _
      "08 - New Loan Transfer|" & _
      "09 - FHA Hud Funds|" & _
      "10 - Lockbox Edit Reject|" & _
      "11 - Modific In Process|" & _
      "12 - Special Loans Resrch|" & _
      "13 - Pymt Hist Research|" & _
      "14 - Refend To Customer|" & _
      "15 - Life Ins Proceeds|" & _
      "16 - Esc Probl Reserch|" & _
      "17 - Service Release Fund|" & _
      "18 - Transmission Error|" & _
      "19 - Applied Incorrectly|" & _
      "20 - Undefined|" & _
      "21 - Undefined|" & _
      "22 - Undefined|" & _
      "23 - Undefined|" & _
      "24 - Undefined|" & _
      "25 - Undefined|" & _
      "26 - Undefined|" & _
      "27 - Undefined|" & _
      "28 - Undefined|" & _
      "29 - Undefined|" & _
      "30 - Undefined|" & _
      "31 - Undefined|" & _
      "32 - Undefined|" & _
      "33 - Undefined|" & _
      "34 - Undefined|" & _
      "35 - Undefined|" & _
      "36 - Undefined|" & _
      "37 - Undefined|" & _
      "38 - Undefined|" & _
      "39 - Undefined|" & _
      "40 - Undefined|" & _
      "41 - Undefined|" & _
      "42 - Undefined|" & _
      "43 - Undefined|" & _
      "44 - Undefined|" & _
      "45 - Undefined|" & _
      "46 - Undefined|" & _
      "47 - Undefined|" & _
      "48 - Undefined|" & _
      "49 - Undefined|" & _
      "50 - Undefined"
      ' generic
      public const SCRIPT_TITLE = "One Time Draft Payment"
      public const SCRIPT_ERROR_TITLE = "Script Error"
      public const VALIDATE_ERROR_TITLE = "Validation Error"
      public const OK = 1
      public const CANCEL = 2
      public const CLOSE = 0

      '******************************************************************************
      ' General classes
      '******************************************************************************
      class Field
      private pvtKey
      private pvtValue
      private pvtLabel
      private pvtHandle
      private pvtErrorCode
      private pvtTag
      private pvtRow
      private pvtCol
      private pvtLength
      private pvtDataType

      public sub Class_Initialize()
      end sub

      ' *********************************************************************
      ' Key = FIS fieldname
      ' Value = Field value
      ' Label = Display name
      ' Handle =  Window handle. Initialize with 0
      ' Tag = Catch all. Initialize with Empty String
      ' DataType = 0-String, 1-Numeric, 2-Currency, 3-Date
      ' *********************************************************************
      public function Init(vKey, vValue, vLabel, vHandle, vErrorCode, vTag, vRow, vCol, vLength, vDataType)
      pvtKey = vKey
      pvtValue = vValue
      pvtLabel = vLabel
      pvtHandle = vHandle
      pvtErrorCode = vErrorCode
      pvtTag = vTag
      pvtRow = vRow
      pvtCol = vCol
      pvtLength = vLength
      pvtDataType = vDataType
      Init = true
      end function

      public function Clone
      dim fld
      set fld = new Field
      fld.Init pvtKey, pvtValue, pvtLabel, pvtHandle, pvtErrorCode, pvtTag, pvtRow, pvtCol, pvtLength, pvtDataType 
      set Clone = fld
      end function

      property get Key
      Key = pvtKey
      end property

      property get Value
      Value = pvtValue
      end property

      property let Value(val)
      pvtValue = val
      end property

      property get Label
      Label = pvtLabel
      end property

      property get Handle
      Handle = pvtHandle
      end property

      property let Handle(val)
      pvtHandle = val
      end property

      property get ErrorCode
      ErrorCode = pvtErrorCode
      end property

      property get Tag
      Tag = pvtTag
      end property

      property get Row
      Row = pvtRow
      end property

      property get Col
      Col = pvtCol
      end property

      property get Length
      Length = pvtLength
      end property

      property get DataType
      DataType = pvtDataType
      end property

      public function ToString()
      ToString =  pvtKey & ": " & pvtValue
      end function

      public sub Class_Terminate()
      end sub

      end class

      class Fields
      private pvtList, pvtOriginal
      public sub Class_Initialize()
      set pvtList = CreateObject("Scripting.Dictionary")
      set pvtOriginal = CreateObject("Scripting.Dictionary")
      end sub

      public function Add(vKey, vValue, vLabel, vHandle, vErrorCode, vTag, vRow, vCol, vLength, vDataType)
      dim field
      set field = new Field

      if field.Init(vKey, vValue, vLabel, vHandle, vErrorCode, vTag, vRow, vCol, vLength, vDataType) then
      pvtList.Add vKey, field
      pvtOriginal.Add vKey, field.Clone()
      end if

      Add = true
      end function

      property get List
      set List = pvtList
      end property

      property get OriginalList
      set OriginalList = pvtOriginal
      end property

      public function ToString()
      dim key, output, field
      output = ""
      for each key in pvtList.Keys
      set field = pvtList.Item(key)
      output = output  & vbCr & vbLf & field.ToString()
      next
      ToString = output
      end function

      public sub Append(vFields)
      dim key
      for each key in vFields.List.Keys
      dim fld
      set fld = vFields.List.Item(key)
      pvtList.Add key, fld
      pvtOriginal.Add Key, fld.Clone()
      next
      end sub

      public sub Class_Terminate()
      set pvtList = nothing
      end sub
      end class

      class DateHelper
      public sub Class_Initialize()
      end sub

      public function ConvertToMMDDYY(dt)
      dim d, items
      d = FormatDateTime(dt,2)
      items = split(d,"/")
      ConvertToMMDDYY = Lpad(items(0),"0",2) & Lpad(items(1),"0",2) & Lpad(right(items(2),2),"0",2)
      end function

      Function Lpad (MyValue, MyPadChar, MyPaddedLength)
      Lpad = String(MyPaddedLength - Len(MyValue),MyPadChar) & MyValue
      End Function


      public sub Class_Terminate()
      end sub

      end class

      class XmlHelper
      private pvtXmlDoc
      public sub Class_Initialize()
      set pvtXmlDoc = CreateObject("Microsoft.XMLDOM")
      end sub

      property get Doc
      set Doc = pvtXmlDoc
      end property

      public function LoadXML(Data)
      Dim Node
      pvtXmlDoc.async = False
      pvtXmlDoc.LoadXML(Data)
      set Node = pvtXmlDoc.SelectSingleNode("RpcData")
      set Node = nothing
      set LoadXML = pvtXmlDoc
      end function


      public function GetFieldValue(name)
      Dim RootNode, FldList, FldNode, Found, Value
      Found = False
      Value = ""
      set FldList = pvtXmlDoc.SelectSingleNode("RpcData").SelectNodes("Fld")
      For each FldNode in FldList
      If FldNode.attributes.GetNamedItem("Nm").nodeValue = name Then
      Value = FldNode.text
      exit For
      End If
      Next
      GetFieldValue = Value 
      end function

      public sub Class_Terminate()
      set pvtXmlDoc = nothing
      end sub

      end class

      class SnapShotLoader
      private Director, Tool, SnapShotName, xmlData

      public sub Class_Initialize()
      end sub

      public function Load(vDirector, vTool, vSnapShotName)
      dim doc, fields, utils
      set fields = new Fields
      xmlData = ReadSnapShot(vTool, vSnapShotName, "623" ,vDirector.LoanNo)
      set utils = new XmlHelper

      if Len(xmlData) > 0 then
      set doc = utils.LoadXML(xmlData)
      Doc2Fields doc, fields 
      end if
      set Load = fields
      end function

      public function ToString()
      ToString = xmlData
      end function

      private function ReadSnapShot(vTool, vSnapShotName, vClientId, vLoanNumber)
      dim Data
      dim ErrMsg
      vTool.SnapshotName = name
      vTool.ClientId = vClientId
      vTool.LoanNo = vLoanNumber
      If vTool.Retrieve(ErrMsg) = 0 Then
      vTool.GetSnapshotData 2, Data, ErrMsg
      End If
      ReadSnapShot = Data
      end function

      private sub Doc2Fields(vDoc, vFields)
      Dim RootNode, FldList, FldNode

      set FldList = vDoc.SelectSingleNode("RpcData").SelectNodes("Fld")
      For each FldNode in FldList
      dim key, name, value, tag
      key = FldNode.attributes.GetNamedItem("Nm").nodeValue
      name = FldNode.attributes.GetNamedItem("BusinessName").nodeValue
      value = FldNode.text
      if not vFields.Add(key, value, name, 0, 0, "", 0,0,0,tag) then
      msgbox "Failed to add field: " & key, vbOKonly + vbCritical, "XML Field Load Error"
      end if
      Next
      end sub

      public sub Class_Terminate()
      end sub
      end class

      class ScreenManager
          dim ErrMsg, original_loan, original_screen, original_window, oTool

          public sub Class_Initialize()
      end sub

      public function ToString()
      ToString = oTool.CurrentScreen & "/" & oTool.CurrentWindow 
      end function

      public sub Load(tool, loan)
      set oTool = tool
      ' grab the current state of the 3270
      ' we use these later to reset to the former state
      original_loan = loan
      original_screen = oTool.CurrentScreen
      original_window = oTool.CurrentWindow
      end sub

      public sub Reset()
      oTool.ShowScreen original_screen, original_window, original_loan, ErrMsg
      end sub

      public sub Clear()
      oTool.SendKeyStrokes "@CLEAR", ErrMsg
      end sub

      public sub Class_Terminate()
      end sub
      end class

      '******************************************************************************
      ' Script specific classes
      '******************************************************************************

      class OtdpTasker
      dim ErrMsg, atl3270Tool

      public sub Class_Initialize()
      end sub

      public sub CreateTask(tool, taskId, employeeId, employeeName)
      set at13270Tool = tool
      atl3270Tool.ShowScreen "TSK1", " ", atl3270Tool.LoanNo, ErrMsg   ' Opens Screen TSK1 for current loan
      atl3270Tool.WaitForString 4, 3, 5, "TASK", ErrMsg      ' Waits for screen to finish loading.
      atl3270Tool.MoveCursor 5, 9, ErrMsg    'Moves cursor to Task ID line
      atl3270Tool.SendKeyStrokes taskId, ErrMsg  ' INputs task ID CUS016
      atl3270Tool.SendKeyStrokes "@ENTER", ErrMsg ' Presses enter to continue setting up task
      atl3270Tool.MoveCursor 6, 6, ErrMsg       'Moves cursor to action code
      atl3270Tool.SendKeyStrokes "A", ErrMsg ' Types in A for Add in action code
      atl3270Tool.MoveCursor 7, 6, ErrMsg    ' Moves cursor to SRC field (source)
      atl3270Tool.SendKeyStrokes "01", ErrMsg ' Types in 01 in SRC field
      atl3270Tool.MoveCursor 7, 9, ErrMsg  ' Moves cursor to source description
      atl3270Tool.SendKeyStrokes "Phone Request", ErrMsg ' Types in phone request into source description
      atl3270Tool.MoveCursor 9, 47, ErrMsg ' Moves cursor to ID field
      atl3270Tool.SendKeyStrokes employeeId, ErrMsg ' Types in OBM for Obon McIntyre in User ID field
      atl3270Tool.MoveCursor 9, 51, ErrMsg ' Moves cursor to User ID description field
      atl3270Tool.SendKeyStrokes employeeName, ErrMsg ' Types in Obon McIntyre
      atl3270Tool.SendKeyStrokes "@ENTER", ErrMsg ' Presses enter to complete adding task.
      atl3270Tool.ClearScreen False, ErrMsg ' Clears screen
      end sub

      public sub Class_Terminate()
      end sub
      end class

      class CrossFooter
          dim payments, payment, curt, add_escrow, suspense, corpadv, fee, fee1, fee2, fee3, delq_fee
      dim base_fees, additional_fees
      public sub Class_Initialize()
      end sub

      function Total(oFields)
      payment = lCCur(oFields.List.Item(LN_MONTHLY_PMT_AM).Value())
      payments = lCCur(oFields.List.Item(LN_PAYMENTS).Value())
      curt = lCCur(oFields.List.Item(LN_CURTAILMENT).Value())
      add_escrow = lCCur(oFields.List.Item(LN_ADD_ESCROW).Value())
      suspense = lCCur(oFields.List.Item(LN_SUSPENSE).Value())
      corpadv = lCCur(oFields.List.Item(LN_CORP_ADV_AMT).Value())
      fee = lCCur(oFields.List.Item(LN_FEE).Value())
      fee1 = lCCur(oFields.List.Item(LN_ADD_FEE_1).Value())
      fee2 = lCCur(oFields.List.Item(LN_ADD_FEE_2).Value())
      fee3 = lCCur(oFields.List.Item(LN_ADD_FEE_3).Value())
      delq_fee = lCCur(oFields.List.Item(DELINQUENCY_FEE).Value())

      base_fees = curt + add_escrow + suspense + corpadv + fee + delq_fee
      additional_fees = fee1 + fee2 + fee3

      if oFields.List.Item(ADDL_FEES).Value() = "Y" then
      Total = GetTotalWithAddlFees(oFields)
      else
      Total = GetTotalWithoutAddlFees(oFields)
      end if
      end function

      function lCCur(value)
      if value = "" then
      lCCur = CCur(0)
      else
      lCCur = CCur(value)
      end if
      end function

      function GetTotalWithAddlFees(oFields)
      dim total
      total = (payment * payments) + base_fees + additional_fees
      GetTotalWithAddlFees = total
      end function

      function GetTotalWithoutAddlFees(oFields)
      dim total
      total = (payment * payments) + base_fees
      GetTotalWithoutAddlFees = total
      end function

      public sub Class_Terminate()
      end sub
      end class

      class OtdpSaver
      dim ErrorMessages, AdditionalMessages, ErrMsg, atl3270Tool, oDateHelper

      public sub Class_Initialize()
      end sub

      function Errors()
      Errors = "Error: " & ErrorMessages & vbCr & vbLf & vbCr & vbLf & "Additional info: " & AdditionalMessages
      end function

      sub SetErrorMessage(msg)
      ErrorMessages = ErrorMessages & vbCr & vbLf & msg
      end sub

      sub SetErrorAdditional(msg)
      AdditionalMessages = AdditionalMessages & vbCr & vbLf & msg
      end sub

      function DateIsValid(tool, fields, screenManager)
      dim oDateHelper, scheduledDate
         screenManager.Clear
      set atl3270Tool = tool
      set oDateHelper = new DateHelper
      scheduledDate = oDateHelper.ConvertToMMDDYY(cdate(fields.List.Item(CURRENT_DATE).Value))

      tool.ShowScreen "DFT4", " ", tool.LoanNo, ErrMsg   ' Opens Screen DFT4 for current loan
      tool.WaitForString 5, 3, 5, "SCH", ErrMsg       ' Waits for DFT4 screen to load before proceeding.

      tool.MoveCursor 6, 3, ErrMsg                    ' Moves cursor to Scheduled Date
      tool.SendKeyStrokes scheduledDate, ErrMsg    ' Writes date to Scheduled Date
      tool.SendKeyStrokes "@ENTER", ErrMsg  ' Presses enter so information can be added to the scheduled date
      tool.WaitForString 5, 3, 5, "SCH", ErrMsg

      DateIsValid = not IsWeekendDate() and not IsHolidayDate()

      end function

      function Purge(tool, fields, screenManager)
      dim oDateHelper, scheduledDate

         'screenManager.Clear
      set oDateHelper = new DateHelper
      scheduledDate = oDateHelper.ConvertToMMDDYY(cdate(fields.List.Item(CURRENT_DATE).Value))

      'tool.ShowScreen "DFT4", " ", tool.LoanNo, ErrMsg   ' Opens Screen DFT4 for current loan
      'tool.WaitForString 5, 3, 5, "SCH", ErrMsg       ' Waits for DFT4 screen to load before proceeding.

      'tool.MoveCursor 6, 3, ErrMsg                    ' Moves cursor to Scheduled Date
      'tool.SendKeyStrokes scheduledDate, ErrMsg    ' Writes date to Scheduled Date
      'tool.SendKeyStrokes "@ENTER", ErrMsg  ' Presses enter so information can be added to the scheduled date
      'tool.WaitForString 5, 3, 5, "SCH", ErrMsg

      dim ErrMsg
      dim Amount
      tool.ReadScreen 6, 16, 10, Amount, ErrMsg

      'groom the data
      Amount = Replace(Amount, UNDERSCORE, EMPTY_STRING)
      'if InStr(value, PERIOD) > 0 then
      if Amount = PERIOD then
      Amount = ZERO_DOLLARS
      else
      Amount = trim(Amount)
      end if

      if Amount > 0 then
      CancelTransaction tool, fields, screenManager
      end if


      end function

      function Save(tool, fields, screenManager)
         dim PassedCrossFoot, PassedRouting, PageOneHeaderAdded, PageTwoHeaderAdded, PageThreeHeaderAdded, IsNotHoliday

      Purge tool, fields, screenManager

      'screenManager.Clear
      set atl3270Tool = tool

      'only process the save if we have routing number data
      If HasRoutingNumber(fields) Then
      'screen one
      DFT4_Page1(fields)
      NextScreen()

      'screen two
      if HasAdditionalFees(fields) then
      if HasNewDollarAmount(fields) then
      DFT4_Page2(fields)
      NextScreen()
      else
      NextScreen()
      end if
      else
      NextScreen()
      end if

      'screen three
      if ValidateCrossFoot() then
      DFT4_Page3(fields)
      NextScreen()
      Save = ValidateHeaderAdded() and ValidateRouting()
      else
      Save = false
      end if
      else
      Save = false
      end if
      end function

      sub DFT4_Page1(fields)
      dim scheduledDate, actionCode
      dim paymentAmount, numberOfPayments, overrideCode
      dim curtailmentAmount, addlEscrowAmount, suspenseAmount
      dim suspenseCode, delinquencyFeeAmount, feeAmount, feeCode, AdditionalFees
      set oDateHelper = new DateHelper

      scheduledDate = oDateHelper.ConvertToMMDDYY(cdate(fields.List.Item(CURRENT_DATE).Value))
      actionCode = fields.List.Item(LN_ACTION).Value
      paymentAmount = ccur(fields.List.Item(LN_AMOUNT).Value)
      numberOfPayments = fields.List.Item(LN_PAYMENTS).Value
      overrideCode = fields.List.Item(LN_OVERRIDES).Value
      curtailmentAmount = ccur(fields.List.Item(LN_CURTAILMENT).Value)
      addlEscrowAmount = ccur(fields.List.Item(LN_ADD_ESCROW).Value)
      suspenseAmount = ccur(fields.List.Item(LN_SUSPENSE).Value)
      suspenseCode = fields.List.Item(LN_SUSPENSE_CODE).Value
      delinquencyFeeAmount = ccur(fields.List.Item(DELINQUENCY_FEE).Value)
      feeAmount = ccur(fields.List.Item(LN_FEE).Value)
      feeCode = fields.List.Item(LN_FEE_CODE).Value
      AdditionalFees = fields.List.Item(ADDL_FEES).Value

      'atl3270Tool.ShowScreen "DFT4", " ", atl3270Tool.LoanNo, ErrMsg   ' Opens Screen DFT4 for current loan
      'atl3270Tool.WaitForString 5, 3, 5, "SCH", ErrMsg       ' Waits for DFT4 screen to load before proceeding.

      'atl3270Tool.MoveCursor 6, 3, ErrMsg                    ' Moves cursor to Scheduled Date
      'atl3270Tool.SendKeyStrokes scheduledDate, ErrMsg    ' Writes date to Scheduled Date
      'atl3270Tool.SendKeyStrokes "@ENTER", ErrMsg  ' Presses enter so information can be added to the scheduled date
      'atl3270Tool.WaitForString 5, 3, 5, "SCH", ErrMsg

      atl3270Tool.MoveCursor 6, 12, ErrMsg                   ' Moves cursor to Action Code
      atl3270Tool.SendKeyStrokes actionCode, ErrMsg       ' Writes Action Code to Action Code

      atl3270Tool.MoveCursor 6, 16, ErrMsg    ' Moves cursor to Amount Received field
      atl3270Tool.SendKeyStrokes "@DELETE", ErrMsg
      atl3270Tool.SendKeyStrokes FormatCurrencyInput(paymentAmount, "0", 10), ErrMsg   ' must pad input so it overwrites existing data

      atl3270Tool.MoveCursor 6, 30, ErrMsg    ' Moves cursor to Number of Payments field
      atl3270Tool.SendKeyStrokes numberOfPayments, ErrMsg ' Writes Number of payments to Payments field

      atl3270Tool.MoveCursor 6, 34, ErrMsg    ' Moves cursor to Override
      atl3270Tool.SendKeyStrokes overrideCode, ErrMsg  ' Writes Override Code to Override field

      if curtailmentAmount > 0 then
      atl3270Tool.MoveCursor 6, 51, ErrMsg    ' Moves cursor to Curtailment Amount
      atl3270Tool.SendKeyStrokes FormatCurrencyInput(curtailmentAmount, "0", 9), ErrMsg  ' Writes Curtailment Amt to Curtailment field
      end if

      if addlEscrowAmount > 0 then
      atl3270Tool.MoveCursor 8, 6, ErrMsg     ' Moves cursor to Additional Escrow field
      atl3270Tool.SendKeyStrokes FormatCurrencyInput(addlEscrowAmount, "0", 9), ErrMsg  ' Writes Additional Escrow to Addl Escrow field
      end if

      if suspenseAmount > 0 then
      atl3270Tool.MoveCursor 8, 19, ErrMsg    ' Moves cursor to Suspense field
      atl3270Tool.SendKeyStrokes FormatCurrencyInput(suspenseAmount, "0", 9), ErrMsg  ' Writes Suspense amount to Suspense field

      atl3270Tool.MoveCursor 8, 33, ErrMsg    ' Moves cursor to Suspense Reason Code
      atl3270Tool.SendKeyStrokes suspenseCode, ErrMsg  ' Writes Suspense reason code to CD field
      end if

      'If the Delq Fee is being Removed, the system requires the delete key to be pressed 9 times
      'rather than overwriting the current amount with 0.00.
      ' Edit 04-17-09.  Found out the ERASEEOF command works instead and is more practical.
      If delinquencyFeeAmount = 0 Then
      atl3270Tool.MoveCursor 10, 16, ErrMsg    ' Moves cursor to Delinquency Fee
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears Delinquency Fee
      Else
      atl3270Tool.MoveCursor 10, 16, ErrMsg    ' Moves cursor to Delinquency Fee
      atl3270Tool.SendKeyStrokes FormatCurrencyInput(delinquencyFeeAmount, "0", 9), ErrMsg  ' Writes Delinquency Fee to Delq Fee field
      End If

      if feeAmount > 0 then
      atl3270Tool.MoveCursor 10, 28, ErrMsg    ' Moves cursor to Fee Amount field
      atl3270Tool.SendKeyStrokes FormatCurrencyInput(feeAmount, "0", 7), ErrMsg  ' Writes Fee Amount to Fee field on first screen of DFT4

      atl3270Tool.MoveCursor 10, 38, ErrMsg    ' Moves cursor to Fee Code field
      atl3270Tool.SendKeyStrokes feeCode, ErrMsg  ' Writes Fee Code
      end if

      If HasAdditionalFees(fields) then
      atl3270Tool.MoveCursor 10, 48, ErrMsg                   ' Moves cursor to Additional Fees Code
      atl3270Tool.SendKeyStrokes "Y", ErrMsg       ' Writes Additional Fees to Action Code
      else 
      atl3270Tool.MoveCursor 10, 48, ErrMsg                   ' Moves cursor to Additional Fees Code
      atl3270Tool.SendKeyStrokes "N", ErrMsg       ' Writes Additional Fees to Action Code
      end if

      end sub

      sub DFT4_Page2(fields)
      dim FeeCode1, FeeAmt1, FeeCode2, FeeAmt2, FeeCode3, FeeAmt3
      dim Payee, Reason, CorpAmount

      FeeCode1 = fields.List.Item(LN_ADD_FEE_1_CODE).Value
      FeeAmt1 = ccur(fields.List.Item(LN_ADD_FEE_1).Value)
      FeeAmt1 = FormatCurrencyInput(FeeAmt1, "0", 8) ' must pad input so it overwrites existing data

      FeeCode2 = fields.List.Item(LN_ADD_FEE_2_CODE).Value
      FeeAmt2 = ccur(fields.List.Item(LN_ADD_FEE_2).Value)
      FeeAmt2 = FormatCurrencyInput(FeeAmt2, "0", 8) ' must pad input so it overwrites existing data

      FeeCode3 = fields.List.Item(LN_ADD_FEE_3_CODE).Value
      FeeAmt3 = ccur(fields.List.Item(LN_ADD_FEE_3).Value)
      FeeAmt3 = FormatCurrencyInput(FeeAmt3, "0", 8) ' must pad input so it overwrites existing data

      Payee = fields.List.Item(LN_CORP_ADV_PAYEE).Value
      Reason = fields.List.Item(LN_CORP_ADV_REASON).Value
      CorpAmount = ccur(fields.List.Item(LN_CORP_ADV_AMT).Value)
      CorpAmount = FormatCurrencyInput(CorpAmount, "0", 8) ' must pad input so it overwrites existing data

      atl3270Tool.WaitForString 5, 3, 5, "CD", ErrMsg       ' Waits for Additional Fees window off DFT4 screen to load before proceeding.

      if FeeAmt1 > 0 then
      atl3270Tool.MoveCursor 6, 3, ErrMsg  ' Moves cursor to first Additional Fee Code field
      atl3270Tool.SendKeyStrokes FeeCode1, ErrMsg   ' Writes Additional Fee Code1 to screen.
      atl3270Tool.MoveCursor 6, 6, ErrMsg  ' Moves cursor to first Additional Fee Amt field
      atl3270Tool.SendKeyStrokes FeeAmt1, ErrMsg  ' Writes first Additional Fee
      else
      atl3270Tool.MoveCursor 6, 3, ErrMsg    ' Moves cursor to first Additional Fee Code field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
      atl3270Tool.MoveCursor 6, 6, ErrMsg ' Moves cursor to the first Additional Fee Amt field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
      end if

      if FeeAmt2 > 0 then
      atl3270Tool.MoveCursor 6, 18, ErrMsg ' Moves cursor to second Additional Fee Code field
      atl3270Tool.SendKeyStrokes FeeCode2, ErrMsg ' Writes second Additional Fee Code
      atl3270Tool.MoveCursor 6, 21, ErrMsg ' Moves cursor to second Additional Fee Amt field
      atl3270Tool.SendKeyStrokes FeeAmt2, ErrMsg  ' Writes second Additional Fee
      else
      atl3270Tool.MoveCursor 6, 18, ErrMsg    ' Moves cursor to second Additional Fee Code field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
      atl3270Tool.MoveCursor 6, 21, ErrMsg ' Moves cursor to the second Additional Fee Amt field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
      end if

      if FeeAmt3 > 0 then
      atl3270Tool.MoveCursor 6, 33, ErrMsg ' Moves cursor to third Additional Fee Code field
      atl3270Tool.SendKeyStrokes FeeCode3, ErrMsg ' Writes third Additional Fee Code
      atl3270Tool.MoveCursor 6, 36, ErrMsg ' Moves cursor to third Additional Fee Amt field
      atl3270Tool.SendKeyStrokes FeeAmt3, ErrMsg  ' Writes third Additional Fee Amt
      else
      atl3270Tool.MoveCursor 6, 33, ErrMsg    ' Moves cursor to third Additional Fee Code field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
      atl3270Tool.MoveCursor 6, 36, ErrMsg ' Moves cursor to the third Additional Fee Amt field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
      end if

      atl3270Tool.MoveCursor 6, 57, ErrMsg ' Moves cursor to Payee field
      atl3270Tool.SendKeyStrokes Payee, ErrMsg ' Writes Payee to payee field
      atl3270Tool.MoveCursor 6, 63, ErrMsg ' Moves cursor to RSN field
      atl3270Tool.SendKeyStrokes Reason, ErrMsg  ' Writes RSN to RSN field
      atl3270Tool.MoveCursor 6, 68, ErrMsg ' Moves cursor to Corp Amount field

      if CorpAmount > 0 then
      atl3270Tool.SendKeyStrokes CorpAmount, ErrMsg  ' Writes Corp Amount to field
      end if
      end sub

      sub DFT4_Page3(fields)
      dim RoutingNumber, AccountNumber, AccountName, AccountType, Requestor, PhoneNumber

      RoutingNumber = fields.List.Item(ROUTING_NUMBER).Value
      AccountNumber = fields.List.Item(ACCOUNT_NUMBER).Value
      AccountName = fields.List.Item(ACCOUNT_NAME).Value
      AccountType = fields.List.Item(ACCOUNT_TYPE).Value
      Requestor = fields.List.Item(MORT_BILL_NAME).Value
      PhoneNumber = fields.List.Item(LN_TELEPHONE_NO).Value

      atl3270Tool.WaitForString 5, 2, 5, "ACCT", ErrMsg ' Waits for Routing/Acct screen to load before proceeding

      atl3270Tool.MoveCursor 6, 8, ErrMsg  ' Moves cursor to Routing Number
      atl3270Tool.SendKeyStrokes RoutingNumber, ErrMsg ' Writes Routing Number to screen

      atl3270Tool.MoveCursor 6, 20, ErrMsg  ' Moves cursor to Account Number
      atl3270Tool.SendKeyStrokes AccountNumber, ErrMsg ' Writes Account Number to field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears rest of field after account number

      atl3270Tool.MoveCursor 6, 38, ErrMsg ' Moves cursor to Account Name
      atl3270Tool.SendKeyStrokes AccountName, ErrMsg ' Writes Account Name to account name field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears rest of field after account name

      atl3270Tool.MoveCursor 6, 61, ErrMsg ' Moves cursor to account type field
      atl3270Tool.SendKeyStrokes AccountType, ErrMsg ' Writes Account Type to account type field

      atl3270Tool.MoveCursor 7, 13, ErrMsg ' Moves cursor to Requestor field
      atl3270Tool.SendKeyStrokes Requestor, ErrMsg ' Writes requestor to requestor field
      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears rest of field after requestor

      atl3270Tool.MoveCursor 7, 49, ErrMsg ' Moves cursor to Phone Number field
      atl3270Tool.SendKeyStrokes PhoneNumber, ErrMsg ' Writes Phone Number to phone number field

      end sub

      function FormatCurrencyInput(MyValue, MyPadChar, MyPaddedLength)
      FormatCurrencyInput = String(MyPaddedLength - Len(MyValue),MyPadChar) & MyValue
      end function

      sub NextScreen()
      atl3270Tool.SendKeyStrokes "@PF5", ErrMsg ' Presses F5 to complete input information
      end sub

      public sub CancelTransaction(o3270, fields, screenManager)
      set oTool = o3270

      oTool.SendKeyStrokes "@ENTER", ErrMsg
      oTool.SendKeyStrokes "@PF12", ErrMsg
      oTool.SendKeyStrokes "@PF12", ErrMsg
      end sub

      function ValidateHeaderAdded()
      dim msg
         atl3270Tool.ReadScreen 13, 2, 33, msg, ErrMsg ' Checks for successfully completed message
         If msg = "*** HEADER SUCCESSFULLY ADDED ***" Then
      ValidateHeaderAdded = true
         Else
      ValidateHeaderAdded = false
      SetErrorMessage("HEADER NOT ADDED")
      SetErrorAdditional(msg)
         End If
      end function

      function ValidateRouting()
      Dim msg
      atl3270Tool.ReadScreen 13, 2, 62, msg, ErrMsg
      If msg = "*** ROUTING AND TRANSIT NUMBER IS INVALID ***" Then
         SetErrorMessage("ROUTING AND TRANSIT NUMBER IS INVALID")
      SetErrorAdditional(msg)
      ValidateRouting = false
      Else
      ValidateRouting = true
      End If
      end function

      function ValidateCrossFoot()
      ValidateCrossFoot = (CrossfootCheck = 0)
      end function

      function IsHolidayDate()
      Dim msg
      atl3270Tool.ReadScreen 13, 2, 39, msg, ErrMsg
      If msg = "*** DRAFT DATE CAN NOT BE A HOLIDAY ***" Then
      SetErrorMessage("Holiday Error")
      SetErrorAdditional(msg)
      IsHolidayDate = true
      Else
      IsHolidayDate = false
      End If
      end function

      function IsWeekendDate()
      Dim msg
      atl3270Tool.ReadScreen 13, 2, 39, msg, ErrMsg
      If msg = "*** DRAFT DATE MUST BE A PROCESSING DAY" Then
      SetErrorMessage("Weekend Error")
      SetErrorAdditional(msg)
      IsWeekendDate = true
      Else
      IsWeekendDate = false
      End If
      end function


      function IsNewBankData(fields)
      dim old_route, new_route
      old_route = fields.List.Item(ROUTING_NUMBER).Value
      new_route = fields.OriginalList.Item(ROUTING_NUMBER).Value

      IsNewBankData = (old_route <> new_route)
      end function

      function HasNewDollarAmount(fields)
         dim F, F1, F2, F3, CA


      F = fields.List.Item(LN_FEE).Value <> fields.OriginalList.Item(LN_FEE).Value
      'if F then
      ' msgbox(fields.List.Item(LN_FEE).Value & " and " & fields.OriginalList.Item(LN_FEE).Value & " are not equal")
      'else
      ' msgbox(fields.List.Item(LN_FEE).Value & " and " & fields.OriginalList.Item(LN_FEE).Value & " are equal")
      'end if
      F1 = fields.List.Item(LN_ADD_FEE_1).Value <> fields.OriginalList.Item(LN_ADD_FEE_1).Value
      F2 = fields.List.Item(LN_ADD_FEE_2).Value <> fields.OriginalList.Item(LN_ADD_FEE_2).Value
      F3 = fields.List.Item(LN_ADD_FEE_3).Value <> fields.OriginalList.Item(LN_ADD_FEE_3).Value
      CA = fields.List.Item(LN_CORP_ADV_AMT).Value <> fields.OriginalList.Item(LN_CORP_ADV_AMT).Value
      HasNewDollarAmount = F or F1 or F2 or F3 or CA
      end function

      function CrossfootCheck()
      Dim msg, amount
      atl3270Tool.ReadScreen 13, 2, 37, msg, ErrMsg
      If msg = "*** TRANSACTION OUT OF CROSSFOOT BY $" Then
      atl3270Tool.ReadScreen 13, 49, 10, amount, ErrMsg  'grabs the amount of crossfoot error
      CrossfootCheck = ccur(amount)
      SetErrorMessage("Crossfoot Check Failed")
      SetErrorAdditional(msg)
      Else
      CrossfootCheck = ccur(0)
      End If
      end function

      function HasRoutingNumber(fields)
      HasRoutingNumber = fields.List.Item(ROUTING_NUMBER).Value <> ""
      end function

      function HasAdditionalFees(fields)
      dim Flag, F1, F2, F3, CA, Total
      Flag = fields.List.Item(ADDL_FEES).Value = "Y"
      F1 = fields.List.Item(LN_ADD_FEE_1).Value
      F2 = fields.List.Item(LN_ADD_FEE_2).Value
      F3 = fields.List.Item(LN_ADD_FEE_3).Value
      CA = fields.List.Item(LN_CORP_ADV_AMT).Value
      Total = CCur(F1) + CCur(F2) + CCur(F3) + CCur(CA)
      HasAdditionalFees = Flag and (Total > 0)
      end function

      public sub Class_Terminate()
      set oDateHelper = nothing
      end sub
      end class

      class OtdpScraper
      private oFields
      private HasAdditionalFees

      public sub Class_Initialize()
      set oFields = new Fields
      HasAdditionalFees = false

      oFields.Add DELINQUENCY_FEE, EMPTY_STRING, DELINQUENCY_FEE_CAPTION, 0, 0, EMPTY_STRING, 10, 16, 8 , 0
      oFields.Add ROUTING_NUMBER, EMPTY_STRING, ROUTING_NUMBER_CAPTION,   0, 0, EMPTY_STRING, 6 , 8 , 9 , 0
      oFields.Add ACCOUNT_NUMBER, EMPTY_STRING, ACCOUNT_NUMBER_CAPTION,   0, 0, EMPTY_STRING, 6 , 20, 17, 0
      oFields.Add ACCOUNT_TYPE, EMPTY_STRING, ACCOUNT_TYPE_CAPTION,       0, 0, EMPTY_STRING, 6 , 61, 1 , 0
      oFields.Add ADDL_FEES, EMPTY_STRING, ADDL_FEES_CAPTION,       0, 0, REQ_STRIP, 10 , 48, 1 , 0
      oFields.Add LN_FEE, 0, LN_FEE_CAPTION, 0, 0, EMPTY_STRING, 10, 28, 8,0
      oFields.Add LN_FEE_CODE, EMPTY_STRING, LN_FEE_CODE_CAPTION, 0, 0, REQ_STRIP, 10, 38, 1,0
      oFields.Add LN_ADD_FEE_1, 0, LN_ADD_FEE_1_CAPTION, 0, 0, EMPTY_STRING, 6, 6, 8,0
      oFields.Add LN_ADD_FEE_1_CODE, EMPTY_STRING, LN_ADD_FEE_1_CODE_CAPTION, 0, 0, REQ_STRIP, 6, 3, 2,0
      oFields.Add LN_ADD_FEE_2, 0, LN_ADD_FEE_2_CAPTION, 0, 0, EMPTY_STRING, 6, 21, 8,0
      oFields.Add LN_ADD_FEE_2_CODE, EMPTY_STRING, LN_ADD_FEE_2_CODE_CAPTION, 0, 0, REQ_STRIP, 6, 18, 2,0
      oFields.Add LN_ADD_FEE_3, 0, LN_ADD_FEE_3_CAPTION, 0, 0, EMPTY_STRING, 6, 36, 8,0
      oFields.Add LN_ADD_FEE_3_CODE, EMPTY_STRING, LN_ADD_FEE_3_CODE_CAPTION, 0, 0, REQ_STRIP, 6, 33, 2,0

      oFields.Add LN_CORP_ADV_PAYEE, EMPTY_STRING, LN_CORP_ADV_PAYEE_CAPTION, 0, 0, EMPTY_STRING, 6, 57, 5,0
      oFields.Add LN_CORP_ADV_REASON, EMPTY_STRING, LN_CORP_ADV_REASON_CAPTION, 0, 0, EMPTY_STRING, 6, 63, 4,0
      oFields.Add LN_CORP_ADV_AMT, 0, LN_CORP_ADV_AMT_CAPTION, 0, 0, EMPTY_STRING, 6, 68, 8,0

      oFields.Add LN_RECEIVED_AMT, 0, LN_RECEIVED_AMT_CAPTION, 0, 0, EMPTY_STRING, 6, 68, 8,0

      end sub

      public function Load(o3270, loan, screenManager)
      dim ErrMsg

      screenManager.Clear
      o3270.ShowScreen DFT4, BLANK_SPACE, loan, ErrMsg
      o3270.WaitForString 5, 3, 5, "SCH", ErrMsg
      ReadScreen oFields.List.Item(DELINQUENCY_FEE)
      ReadScreen oFields.List.Item(LN_FEE)           ' New
      ReadScreen oFields.List.Item(LN_FEE_CODE)     ' New

      dim flag
      o3270.ReadScreen 10, 48, 1, flag, ErrMsg ' New
      ReadScreen oFields.List.Item(ADDL_FEES)
      HasAdditionalFees = trim(flag) = "Y"

      o3270.SendKeyStrokes "@PF5", ErrMsg
      o3270.WaitForString 5, 3, 5, "CD", ErrMsg

      if HasAdditionalFees then
      ReadScreen oFields.List.Item(LN_ADD_FEE_1_CODE)            ' New
      ReadScreen oFields.List.Item(LN_ADD_FEE_1)                  ' New
      ReadScreen oFields.List.Item(LN_ADD_FEE_2_CODE)            ' New
      ReadScreen oFields.List.Item(LN_ADD_FEE_2)                  ' New
      ReadScreen oFields.List.Item(LN_ADD_FEE_3_CODE)            ' New
      ReadScreen oFields.List.Item(LN_ADD_FEE_3)                  ' New
      ReadScreen oFields.List.Item(LN_CORP_ADV_PAYEE)        ' New
      ReadScreen oFields.List.Item(LN_CORP_ADV_REASON)       ' New
      ReadScreen oFields.List.Item(LN_CORP_ADV_AMT)       ' New
      end if

      o3270.SendKeyStrokes "@PF5", ErrMsg
      o3270.WaitForString 5, 2, 5, "ACCT", ErrMsg
      ReadScreen oFields.List.Item(ROUTING_NUMBER)
      ReadScreen oFields.List.Item(ACCOUNT_NUMBER)
      ReadScreen oFields.List.Item(ACCOUNT_TYPE)

      set Load = oFields
      end function

      private sub ReadScreen(vField)
      dim ErrMsg
      dim value
      o3270.ReadScreen vField.Row, vField.Col, vField.Length, value, ErrMsg
      value = Replace(value, UNDERSCORE, EMPTY_STRING)
      'if InStr(value, PERIOD) > 0 then
      if value = PERIOD then
      vField.Value = ZERO_DOLLARS
      else
      vField.Value = trim(value)
      end if
      end sub

      public sub Class_Terminate()
      set oFields = nothing
      end sub
      end class

      class Otdp
      private oFields
      private curDeliquncyFee
      private oErrors

      public sub Class_Initialize()
      curDeliquncyFee = CCur(15.00)
      set oErrors = CreateObject("Scripting.Dictionary")
      end sub

      public sub Init(vFields)
      set oFields = vFields
      end sub

      property get ValidStopCode
      dim ProcessStop
      ProcessStop = Left(oFields.List.Item(LN_PROCESS_STOP_CD).Value,1)
      ValidStopCode = InStr("04CEHMOU", ProcessStop) > 0
      end property

      property get HasBalance
      dim PrincipalBalance
      PrincipalBalance = CDbl(oFields.List.Item(LN_1ST_PRIN_BA).Value)
      HasBalance = PrincipalBalance > 0
      end property

      property get DelinquentBy(days)
      DelinquentBy = days < DaysDelinquent
      end property

      property get DaysDelinquent
      dim Today, Delinquent, DueDate
      Today = Date
      DueDate = oFields.List.Item(LN_NXT_PMT_DUE_DT).Value
      Delinquent = DateDiff("d", DueDate, Today)
      DaysDelinquent = Delinquent
      'IMPORTANT remove the next line before full testing and production release
      'DaysDelinquent = 0
      end property

      property get IsMature
      dim Today, PartialMaturityDate, FullMaturityDate
      Today = Date
      PartialMaturityDate = oFields.List.Item(OG_LOAN_MAT_DT).Value
      FullMaturityDate = DateSerial(Year(PartialMaturityDate),Month(PartialMaturityDate),Day(PartialMaturityDate))
      IsMature = Today > FullMaturityDate
      end property

      property get HasEscrow
      dim Escrow
      Escrow = oFields.List.Item(ESCROW_PAYMENT).Value
      HasEscrow = Escrow > 0
      end property

      property get Valid
      dim pvtHasBalance, pvtMature, pvtTooDelinquent, pvtValidStopCode

      oErrors.RemoveAll

      pvtHasBalance = HasBalance
      pvtMature = IsMature
      pvtTooDelinquent = DelinquentBy(46)
      pvtValidStopCode = ValidStopCode

      if not pvtValidStopCode then
      if not oErrors.Exists("ProcessStopError") then
      oErrors.Add "ProcessStopError", "Loan has a invalid ProcessStop of " & oFields.List.Item(LN_PROCESS_STOP_CD).Value & "."
      end if
      end if

      if pvtTooDelinquent then
      if not oErrors.Exists("DelinquentError") then
      oErrors.Add "DelinquentError", "Loan is " & DaysDelinquent & " days delinquent."
      end if
      end if

      if pvtMature then
      if not oErrors.Exists("MaturityError") then
      oErrors.Add "MaturityError", "Loan Maturity date is " & oFields.List.Item(OG_LOAN_MAT_DT).Value & "."
      end if
      end if

      if not pvtHasBalance then
      if not oErrors.Exists("BalanceError") then
      oErrors.Add "BalanceError", "Loan has a balance of " & oFields.List.Item(LN_1ST_PRIN_BA).Value & "."
      end if
      end if

      Valid = pvtValidStopCode and pvtHasBalance and (not pvtTooDelinquent) and (not pvtMature)
      end property

      public function ErrToString()
      dim key, output
      for each key in oErrors.Keys
      output = output & vbCr & vbLf & oErrors.Item(key)
      next
      ErrToString = output
      end function

      public sub Class_Terminate()
      set oErrors = nothing
      end sub
      end class

      Class OneTimeDraftPaymentForm
        private oFields
        private Dialog
        private btnPanelId

        public sub Class_Initialize()
          set oFields = CreateObject("Scripting.Dictionary")
        end sub

        public function Show(fields, loanNumber, showEscrow)
          dim vOffset, mode
          set oFields = fields
          vOffset = 40

          set Dialog = CreateObject("MstrComponent.PaneledWindow")

          Dialog.Title = "One Time Draft Payment - " & loanNumber
          Dialog.Layout = 4
          Dialog.Width = 750

      dim key, fld

      AddTextField CURRENT_DATE, 0, "Date", Date, 35, 0, 0, 140, 50
      AddComboBox LN_ACTION, "Action", "A", 1, 45, 140, 0, 100, 50
      AddFeeField LN_AMOUNT, 10, "Amount", EMPTY_STRING, 40, 235, 0, 140, 50
      AddComboBox LN_PAYMENTS,"Payments", "0|1|2|3|4|5|6|7|8|9", 1, 50, 375, 0, 140, 50
      AddComboBox LN_OVERRIDES,"Overrides", "3", 1, 45, 595, 0, 140, 50
      AddTextField ROUTING_NUMBER, 9, EMPTY_STRING, EMPTY_STRING, 42, 0, vOffset * 1, 180, 50
      AddTextField ACCOUNT_NUMBER, 17, EMPTY_STRING, EMPTY_STRING, 36, 180, vOffset * 1, 210, 50
      AddTextField ACCOUNT_NAME, 22,  "Name", EMPTY_STRING, 30, 380, vOffset * 1, 250, 50 'name
      AddTextField MORT_BILL_NAME, 22,  "Requestor", EMPTY_STRING, 30, 380, vOffset * 2, 250, 50 'requestor
      AddTextField ACCOUNT_TYPE, 1, EMPTY_STRING, EMPTY_STRING, 42, 0, vOffset * 2, 180, 50
      AddTextField LN_TELEPHONE_NO, 20, "Phone #", EMPTY_STRING, 42, 180, vOffset * 2, 180, 50
      AddFeeField LN_CURTAILMENT, 10, "Curtailment", ZERO_DOLLARS, 50, 0, vOffset * 4, 140, 50
      if showEscrow then
      AddFeeField LN_ADD_ESCROW, 9, "Addl Escrow", ZERO_DOLLARS, 50, 0, vOffset * 5, 140, 50
      end if
      AddFeeField LN_SUSPENSE, 10, "Suspense", ZERO_DOLLARS, 50, 0, vOffset * 6, 140, 50
      AddComboBox LN_SUSPENSE_CODE, "Code", SUSPENSE_CODES, 1, 28, 130, vOffset * 6, 225, 50

      ' only show the delinquency field if there is a dollar amount already present
      if GetValue(DELINQUENCY_FEE) > 0 then
      AddFeeField DELINQUENCY_FEE, 8, EMPTY_STRING, ZERO_DOLLARS, 50, 0, vOffset * 7, 140, 50
      end if

      AddComboBox ADDL_FEES, "Addl Fees", "Y - Additional Fees|N - No Additional Fees", 1, 28, 140, vOffset * 7, 225, 50
      AddFeeField LN_FEE, 9, EMPTY_STRING, ZERO_DOLLARS, 50, 350, vOffset * 4, 135, 50
      AddComboBox LN_FEE_CODE, EMPTY_STRING, PAYMENT_CODES, 1, 28, 480, vOffset * 4, 225, 50

      if GetValue(LN_ADD_FEE_1) > 0 then
      AddFeeField LN_ADD_FEE_1, 9, EMPTY_STRING, ZERO_DOLLARS, 50, 350, vOffset * 5, 135, 50
      AddComboBox LN_ADD_FEE_1_CODE, EMPTY_STRING, PAYMENT_CODES, 1, 28, 480, vOffset * 5, 225, 50
      end if

      if GetValue(LN_ADD_FEE_2) > 0 then
      AddFeeField LN_ADD_FEE_2, 9, EMPTY_STRING, ZERO_DOLLARS, 50, 350, vOffset * 6, 135, 50
      AddComboBox LN_ADD_FEE_2_CODE, EMPTY_STRING, PAYMENT_CODES, 1, 28, 480, vOffset * 6, 225, 50
      end if

      if GetValue(LN_ADD_FEE_3) > 0 then
      AddFeeField LN_ADD_FEE_3, 9, EMPTY_STRING, ZERO_DOLLARS,50, 350, vOffset * 7, 135, 50
      AddComboBox LN_ADD_FEE_3_CODE, EMPTY_STRING, PAYMENT_CODES, 1, 28, 480, vOffset * 7, 225, 50
      end if

      if GetValue(LN_CORP_ADV_PAYEE) <> "" then
      AddTextField LN_CORP_ADV_PAYEE, 5, EMPTY_STRING, EMPTY_STRING, 42, 350, vOffset * 8, 180, 50
      end if

      if GetValue(LN_CORP_ADV_REASON) <> "" then
      AddTextField LN_CORP_ADV_REASON, 4, EMPTY_STRING, EMPTY_STRING, 42, 350, vOffset * 9, 180, 50
      end if

      dim lcaa
      if GetValue(LN_CORP_ADV_AMT) > 0 then
      AddFeeField LN_CORP_ADV_AMT, 9, EMPTY_STRING, ZERO_DOLLARS, 42, 480, vOffset * 10, 180, 50
      end if

      AddPhoneInstruction LN_TELEPHONE_NO

          btnPanelId = Dialog.AddPanel(9)
          Dialog.AddItems btnPanelId, "&OK|&Cancel"
          Dialog.SetPanelBounds btnPanelId, 580, vOffset * 11, 170, 50
          Dialog.SetDefault btnPanelId, 1 

          mode = Dialog.ShowWindow
      if mode = 1 then ' 1 is Ok 
      LoadFields
      end if
          Show = mode
        end function
        
        private sub AddPhoneInstruction(key)
      dim fld
      set fld = oFields.List.Item(key)
      Dialog.CustomInstruction  fld.Handle, 0, "PhoneNumber", True
        end sub
        
        private sub AddTextField(key, maxColumns, label, default_value, vdivider, top, left, width, height)
          dim pnl, fld
      set fld = oFields.List.Item(key)
      ' AddTextField REQUESTOR, 22,  "Requestor", EMPTY_STRING, 30, 380, vOffset * 2, 250, 50 'requestor

      ' check parameters and set defaults if they are Empty String
      if label = EMPTY_STRING then
      label = fld.Label
      end if

      if default_value = EMPTY_STRING then
         'Added functionality 6-25-09 to trim long names if greater than 22 characters
      if key = "ACCOUNT_NAME" or key = "MORT_BILL_NAME" then
      default_value = leftb(fld.Value,44)
      else
      default_value = fld.Value
      end if
      end if

      pnl = Dialog.AddPanel(7)
      Dialog.SetColumns pnl, maxColumns
          Dialog.AddMessage pnl, label
          Dialog.AddItems pnl, Trim(default_value)
          Dialog.MoveVertDivider pnl, vdivider
          Dialog.SetPanelBounds pnl, top, left, width, height 
      fld.Handle = pnl
        end sub
        
        private sub AddFeeField(key, maxColumns, label, default_value, vdivider, top, left, width, height)
          dim pnl, fld
      set fld = oFields.List.Item(key)

      ' check parameters and set defaults if they are Empty String
      if label = EMPTY_STRING then
      label = fld.Label
      end if

      if default_value = ZERO_DOLLARS then
      default_value = fld.Value
      end if

      pnl = Dialog.AddPanel(7)
      Dialog.SetColumns pnl, maxColumns
          Dialog.AddMessage pnl, label
      if default_value = "" then
      default_value = ZERO_DOLLARS
      end if
          Dialog.AddItems pnl, CCur(default_value)
          Dialog.MoveVertDivider pnl, vdivider
          Dialog.SetPanelBounds pnl, top, left, width, height 
      Dialog.CustomInstruction  pnl, 0, "Currency", True
      fld.Handle = pnl
        end sub
        
        private sub AddComboBox(key, label, items, default_item, vdivider, top, left, width, height)
          dim pnl, fld
      set fld = oFields.List.Item(key)

      ' check parameters and set defaults if they are Empty String
      if label = EMPTY_STRING then
      label = fld.Label
      end if

      ' Loop through the items [delimeted string] 
      if fld.Value <> EMPTY_STRING then
      dim list_items, list_keys, item_key, item, index
      index = 1
      list_items = split(items,"|")
      for each item in list_items
      item_key = trim(split(item, "-")(0))
      if item_key = fld.Value then
      default_item = index
      end if
      index = index + 1
      next
      end if

      pnl = Dialog.AddPanel(3)
          Dialog.AddMessage pnl, label
          Dialog.AddItems pnl, items
          Dialog.MoveVertDivider pnl, vdivider
          Dialog.SetPanelBounds pnl, top, left, width, height 
      Dialog.SetDefault pnl, default_item
      fld.Handle = pnl
        end sub
        
        private function GetValue(key)
          dim pnl, fld
      set fld = oFields.List.Item(key)
      GetValue = fld.value
        end function

        private sub LoadFields()
      dim key
      for each key in oFields.List.Keys
      dim fld, oldValue
      set fld = oFields.List.Item(key)
      oldValue = fld.Value
      if fld.Handle > 0 then
      if fld.Tag = REQ_STRIP then
      fld.Value = CodeSplit(Dialog.GetText(fld.Handle))
      else
         fld.Value = Dialog.GetText(fld.Handle)
      end if
      end if
      'msgbox fld.Key & ": " & oldValue & ", " & fld.Value
      next
        end sub
        
        private function CodeSplit(delimText)
      dim items
      items = split(delimText, "-")
      if ubound(items) > 0 then
      CodeSplit = trim(items(0))
      else
         CodeSplit = ""
      end if
        end function
        
        private function CleanCurrency(value)
      if InStr(value, "_") > 0 then
      value = 0
      end if
      CleanCurrency = value
        end function
        
        private function CleanString(value)
      if InStr(value, "_") > 0 then
      value = ""
      end if
      CleanString = value
        end function

        property get Fields
          set Fields = oFields
        end property
        
        property get UserCancelled
      UserCancelled = Cancelled
        end property

        public sub Class_Terminate()
          set Dialog = nothing
          set oFields = nothing
        end sub
      end class

      '******************************************************************************
      ' config section
      '******************************************************************************
      dim taskId, employeeName, employeeId

      taskId = "CUS016"
      employeeName = "Obon McIntyre"
      employeeId = "OBM"


      '******************************************************************************
      ' Start script
      '******************************************************************************

      dim oDirector, o3270, oTool, oLoader, oFields, oForm, oScrapedFields, oOTDP
      dim oOTDPscraper, oAdditionalFields, oCrossFooter, oSaver, oTasker, oScreenManager
      dim name, ErrMsg, expectedFieldCount, mode, total_payment

      set oDirector = CreateObject("atlDirectorObject.atlDirector")
      name = "Payment Drafting"
      expectedFieldCount = 9

      set oAdditionalFields = new Fields
      oAdditionalFields.Add CURRENT_DATE, Date, "CurrentDate", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_ACTION, EMPTY_STRING, "Action", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_AMOUNT, 0, "Amount", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_PAYMENTS, EMPTY_STRING, "Payments", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_OVERRIDES, EMPTY_STRING, "Overrides", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_CURTAILMENT, 0, "Curtailment", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_ADD_ESCROW, 0, "AdditionalEscrow", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_SUSPENSE, 0, "Suspense", 0, 0, "", 0,0,0,0
      oAdditionalFields.Add LN_SUSPENSE_CODE, EMPTY_STRING, "SuspenseCode", 0, 0, REQ_STRIP, 0,0,0,0
      oAdditionalFields.Add ACCOUNT_NAME, EMPTY_STRING, ACCOUNT_NAME_CAPTION, 0, 0, EMPTY_STRING, 0,0,0,0


      ' Set up the Director tools
      if (oDirector.CreateTool("3270", 0, TRUE, False, 0, o3270, ErrMsg) = 0) then
      set oScreenManager = new ScreenManager
      oScreenManager.Load o3270, oDirector.LoanNo
      if (oDirector.CreateTool("Snapshot", 1, False, False, 0, oTool, ErrMsg) = 0) then
      ' create a loader to load the snapshot data into the fields class
      set oLoader = new SnapShotLoader
      set oFields = oLoader.Load(oDirector, oTool, name)
      'msgbox oLoader.ToString() 'debug statement used to view the xml string
      ' if we got the expected number of fields then we can load the fields data into the OTDP so we can
      ' check some specific data for business rules

      if oFields.List.Count = expectedFieldCount then
      set oOTDP = new Otdp
      oOTDP.Init oFields ' OTDP contains business rules so we load the fields into it.
      if oOTDP.Valid then
      ' we have a valid loan so we need to scrap some data from the 3270
      set oOTDPscraper = new OtdpScraper
      set oScrapedFields = oOTDPscraper.Load(o3270, oDirector.LoanNo, oScreenManager)
      ' now we combined the original snap shot fields with the screen scraped fields
      oFields.Append(oScrapedFields)
      oFields.Append(oAdditionalFields)
                                      oFields.List.Item(ACCOUNT_NAME).Value() = oFields.List.Item(MORT_BILL_NAME).Value() 'Prefil account name
      set oForm = new OneTimeDraftPaymentForm
      mode = oForm.Show(oFields, oDirector.LoanNo, oOTDP.HasEscrow)
      if mode = OK then
      'MsgBox "Modified results:" & vbCr & vbLf & oFields.ToString(), vbOKonly + vbInformation, "User Edited Results"
      set oCrossFooter = new CrossFooter
      total_payment = oCrossFooter.Total(oFields)
      dim retval
      retval = MsgBox("Post Payment in the amount of " + cstr(total_payment) + "?", vbYesNo + vbDefaultButton2 + vbQuestion + vbApplicationModal, SCRIPT_TITLE) 
      if retval = vbYes then
      oFields.List.Item(LN_AMOUNT).Value = total_payment
      set oSaver = new OtdpSaver
      if oSaver.DateIsValid(o3270, oFields, oScreenManager) then
      if oSaver.Save(o3270, oFields, oScreenManager) then
      MsgBox "Draft Header Added.", vbOKonly + vbInformation, "Script Completed"
      else
      oSaver.CancelTransaction o3270, oFields, oScreenManager
      MsgBox "The payment was not posted correctly." & vbCr & vbLf &  vbCr & vbLf & oSaver.Errors(), vbOKonly + vbCritical, "Script Error"
      end if
      else
      oSaver.CancelTransaction o3270, oFields, oScreenManager
      MsgBox "The posting date is either a holiday or weekend." & vbCr & vbLf &  vbCr & vbLf & oSaver.Errors(), vbOKonly + vbCritical, "Script Error"
      end if
      else
      MsgBox "User has cancelled the script.", vbOKonly + vbInformation, "Script Cancelled"
      end if
      else 
      MsgBox "User has cancelled the script.", vbOKonly + vbInformation, "Script Cancelled"
      end if
      else
      ' this is not a valid loan we are try to process
      if oOTDP.IsMature then
      set oTasker = new OtdpTasker
      oTasker.CreateTask o3270, taskId, employeeId, employeeName
      msgbox "This loan is past its maturity date. A " & taskId & _
      " task has been assigned to '" & employeeName & "'.", vbOKonly + vbInformation, SCRIPT_TITLE
      else
      msgbox "This loan can not recieve deposits for the following reasons: " _
      & vbLf & vbCr & oOTDP.ErrToString() , vbOKonly + vbInformation, VALIDATE_ERROR_TITLE
      end if
      end if
      oScreenManager.Reset()
      else
      msgbox "Snapshot Loader did not load correctly for snapshot '" & name & "'.", vbOKonly + vbCritical, SCRIPT_ERROR_TITLE
      end if
      else
      msgbox "Failed to create snapshot '" & name & "'.", vbOKonly + vbCritical, SCRIPT_ERROR_TITLE
      end if
      else
      msgbox "Failed to create 3270.", vbOKonly + vbCritical, SCRIPT_ERROR_TITLE
      end if

      set oDirector = nothing
      set o3270 = nothing
      set oTool = nothing
      set oLoader = nothing
      set oFields = nothing
      set oScrapedFields = nothing
      set oCrossFooter = nothing
      set oSaver = nothing
      set oScreenManager = nothing


      Option Explicit
       
      '******************************************************************************
      ' constants and public variables
      '******************************************************************************
      public const CURRENT_DATE = "CurrentDate"
      public const LN_ACTION = "Action"
      public const LN_AMOUNT = "Amount"
      public const LN_PAYMENTS = "Payments"
      public const LN_OVERRIDES = "Overrides"
      public const LN_CURTAILMENT = "Curtailment"
      public const LN_ADD_ESCROW = "AdditionalEscrow"
      public const LN_SUSPENSE = "Suspense"
      public const LN_SUSPENSE_CODE = "SuspenseCode"
      public const LN_FEE = "Fee"
      public const LN_FEE_CODE = "FeeCode"
      public const LN_ADD_FEE_1 = "AdditionalFeeOne"
      public const LN_ADD_FEE_1_CODE = "AdditionalFeeOneCode"
      public const LN_ADD_FEE_2 = "AdditionalFeeTwo"
      public const LN_ADD_FEE_2_CODE = "AdditionalFeeTwoCode"
      public const LN_ADD_FEE_3 = "AdditionalFeeThree"
      public const LN_ADD_FEE_3_CODE = "AdditionalFeeThreeCode"
       
      public const LN_CORP_ADV_PAYEE = "CorpAdvancePayee"
      public const LN_CORP_ADV_REASON = "CorpAdvanceReason"
      public const LN_CORP_ADV_AMT = "CorpAdvanceAmount"
       
      public const LN_1ST_PRIN_BA = "LN_1ST_PRIN_BA"
      public const LN_PROCESS_STOP_CD = "LN_PROCESS_STOP_CD"
      public const OG_LOAN_MAT_DT = "OG_LOAN_MAT_DT"
      public const LN_NXT_PMT_DUE_DT = "LN_NXT_PMT_DUE_DT"
      public const MORT_BILL_NAME = "MORT_BILL_NAME"
      public const LN_TELEPHONE_NO = "LN_TELEPHONE_NO"
      public const NO_PAYMENTS_DUE = "NO_PAYMENTS_DUE"
      public const LN_MONTHLY_PMT_AM = "LN_MONTHLY_PMT_AM"
      public const ESCROW_PAYMENT = "ESCROW_PAYMENT"
       
       
      public const DELINQUENCY_FEE = "DelinquencyFee"
      public const ROUTING_NUMBER = "RoutingNumber"
      public const ACCOUNT_NUMBER = "AccountNumber"
      public const ACCOUNT_TYPE = "AccountType"
      public const ACCOUNT_NAME = "ACCOUNT_NAME"
       
      public const LN_FEE_CAPTION = "Fee"
      public const LN_FEE_CODE_CAPTION = "Code"
      public const LN_ADD_FEE_1_CAPTION = "Addl Fee"
      public const LN_ADD_FEE_1_CODE_CAPTION = "Code"
      public const LN_ADD_FEE_2_CAPTION = "Addl Fee"
      public const LN_ADD_FEE_2_CODE_CAPTION = "Code"
      public const LN_ADD_FEE_3_CAPTION = "Addl Fee"
      public const LN_ADD_FEE_3_CODE_CAPTION = "Code"
       
      public const DELINQUENCY_FEE_CAPTION = "Delq Fee"
      public const ROUTING_NUMBER_CAPTION = "Routing Number"
      public const ACCOUNT_NUMBER_CAPTION = "Account Number"
      public const ACCOUNT_TYPE_CAPTION = "Account Type"
      public const ACCOUNT_NAME_CAPTION = "Account Name"
       
      public const ADDL_FEES = "AdditionalFees"
      public const ADDL_FEES_CAPTION = "Addl Fees"
       
      public const LN_RECEIVED_AMT = "AmountReceived"
      public const LN_RECEIVED_AMT_CAPTION = "Amount Received"
       
      public const LN_CORP_ADV_PAYEE_CAPTION = "Adv Payee"
      public const LN_CORP_ADV_REASON_CAPTION = "Adv Reason"
      public const LN_CORP_ADV_AMT_CAPTION = "Adv Amount"
       
      public const REQ_STRIP = 2
      public const EMPTY_STRING = ""
      public const BLANK_SPACE = " "
      public const UNDERSCORE = "_"
      public const DFT4 = "DFT4"
      public const SER1 = "SER1"
      public const ZERO_DOLLARS = "$0.00"
      public const PERIOD = "."
       
      dim PAYMENT_CODES
      PAYMENT_CODES =        "0 - Misc Fee|" & _
                                                                      "1 - Late Change Fee|" & _
                                                                      "2 - NSF Fee|" & _
                                                                      "3 - Loan Assumption Fee|" & _
                                                                      "4 - Recording Fee|" & _
                                                                      "5 - Sterling Ext. Fee|" & _
                                                                      "C - Partial Release Fee|" & _
                                                                      "D - Doc Copy/Am Sch|" & _
                                                                      "F - Fax Fee|" & _
                                                                      "I - Modification/Ext Fee|" & _
                                                                      "J - BPO|" & _
                                                                      "K - One Time Draft Fee"
       
      dim SUSPENSE_CODES
      SUSPENSE_CODES =       "01 - Reapplication Pndg|" & _
                                                                                      "02 - Hold For Corp Adv|" & _
                                                                                      "03 - Partial Payment|" & _
                                                                                      "04 - Repmt Plan/P9 Stop|" & _
                                                                                      "05 - Partial Pymt Bkrptcy|" & _
                                                                                      "06 - Opt Ins No Bucket|" & _
                                                                                      "07 - Pymt Over No Expla|" & _
                                                                                      "08 - New Loan Transfer|" & _
                                                                                      "09 - FHA Hud Funds|" & _
                                                                                      "10 - Lockbox Edit Reject|" & _
                                                                                      "11 - Modific In Process|" & _
                                                                                      "12 - Special Loans Resrch|" & _
                                                                                      "13 - Pymt Hist Research|" & _
                                                                                      "14 - Refend To Customer|" & _
                                                                                      "15 - Life Ins Proceeds|" & _
                                                                                      "16 - Esc Probl Reserch|" & _
                                                                                      "17 - Service Release Fund|" & _
                                                                                      "18 - Transmission Error|" & _
                                                                                      "19 - Applied Incorrectly|" & _
                                                                                      "20 - Undefined|" & _
                                                                                      "21 - Undefined|" & _
                                                                                      "22 - Undefined|" & _
                                                                                      "23 - Undefined|" & _
                                                                                      "24 - Undefined|" & _
                                                                                      "25 - Undefined|" & _
                                                                                      "26 - Undefined|" & _
                                                                                      "27 - Undefined|" & _
                                                                                      "28 - Undefined|" & _
                                                                                      "29 - Undefined|" & _
                                                                                      "30 - Undefined|" & _
                                                                                      "31 - Undefined|" & _
                                                                                      "32 - Undefined|" & _
                                                                                      "33 - Undefined|" & _
                                                                                      "34 - Undefined|" & _
                                                                                      "35 - Undefined|" & _
                                                                                      "36 - Undefined|" & _
                                                                                      "37 - Undefined|" & _
                                                                                      "38 - Undefined|" & _
                                                                                      "39 - Undefined|" & _
                                                                                      "40 - Undefined|" & _
                                                                                      "41 - Undefined|" & _
                                                                                      "42 - Undefined|" & _
                                                                                      "43 - Undefined|" & _
                                                                                      "44 - Undefined|" & _
                                                                                      "45 - Undefined|" & _
                                                                                      "46 - Undefined|" & _
                                                                                      "47 - Undefined|" & _
                                                                                      "48 - Undefined|" & _
                                                                                      "49 - Undefined|" & _
                                                                                      "50 - Undefined"
      ' generic
      public const SCRIPT_TITLE = "One Time Draft Payment"
      public const SCRIPT_ERROR_TITLE = "Script Error"
      public const VALIDATE_ERROR_TITLE = "Validation Error"
      public const OK = 1
      public const CANCEL = 2
      public const CLOSE = 0
       
      '******************************************************************************
      ' General classes
      '******************************************************************************
      class Field
                      private pvtKey
                      private pvtValue
                      private pvtLabel
                      private pvtHandle
                      private pvtErrorCode
                      private pvtTag
                      private pvtRow
                      private pvtCol
                      private pvtLength
                      private pvtDataType
       
                      public sub Class_Initialize()
                      end sub
       
                      ' *********************************************************************
                      ' Key = FIS fieldname
                      ' Value = Field value
                      ' Label = Display name
                      ' Handle =  Window handle. Initialize with 0
                      ' Tag = Catch all. Initialize with Empty String
                      ' DataType = 0-String, 1-Numeric, 2-Currency, 3-Date
                      ' *********************************************************************
                      public function Init(vKey, vValue, vLabel, vHandle, vErrorCode, vTag, vRow, vCol, vLength, vDataType)
                                      pvtKey = vKey
                                      pvtValue = vValue
                                      pvtLabel = vLabel
                                      pvtHandle = vHandle
                                      pvtErrorCode = vErrorCode
                                      pvtTag = vTag
                                      pvtRow = vRow
                                      pvtCol = vCol
                                      pvtLength = vLength
                                      pvtDataType = vDataType
                                      Init = true
                      end function
       
                      public function Clone
                                      dim fld
                                      set fld = new Field
                                      fld.Init pvtKey, pvtValue, pvtLabel, pvtHandle, pvtErrorCode, pvtTag, pvtRow, pvtCol, pvtLength, pvtDataType
                                      set Clone = fld
                      end function
       
                      property get Key
                                      Key = pvtKey
                      end property
       
                      property get Value
                                      Value = pvtValue
                      end property
       
                      property let Value(val)
                                      pvtValue = val
                      end property
       
                      property get Label
                                      Label = pvtLabel
                      end property
       
                      property get Handle
                                      Handle = pvtHandle
                      end property
       
                      property let Handle(val)
                                      pvtHandle = val
                      end property
       
                      property get ErrorCode
                                      ErrorCode = pvtErrorCode
                      end property
       
                      property get Tag
                                      Tag = pvtTag
                      end property
       
                      property get Row
                                      Row = pvtRow
                      end property
       
                      property get Col
                                      Col = pvtCol
                      end property
       
                      property get Length
                                      Length = pvtLength
                      end property
       
                      property get DataType
                                      DataType = pvtDataType
                      end property
       
                      public function ToString()
                                      ToString =  pvtKey & ": " & pvtValue
                      end function
       
                      public sub Class_Terminate()
                      end sub
       
      end class
       
      class Fields
                      private pvtList, pvtOriginal
                      public sub Class_Initialize()
                                      set pvtList = CreateObject("Scripting.Dictionary")
                                      set pvtOriginal = CreateObject("Scripting.Dictionary")
                      end sub
       
                      public function Add(vKey, vValue, vLabel, vHandle, vErrorCode, vTag, vRow, vCol, vLength, vDataType)
                                      dim field
                                      set field = new Field
       
                                      if field.Init(vKey, vValue, vLabel, vHandle, vErrorCode, vTag, vRow, vCol, vLength, vDataType) then
                                                      pvtList.Add vKey, field
                                                      pvtOriginal.Add vKey, field.Clone()
                                      end if
       
                                      Add = true
                      end function
       
                      property get List
                                      set List = pvtList
                      end property
       
                      property get OriginalList
                                      set OriginalList = pvtOriginal
                      end property
       
                      public function ToString()
                                      dim key, output, field
                                      output = ""
                                      for each key in pvtList.Keys
                                                      set field = pvtList.Item(key)
                                                      output = output  & vbCr & vbLf & field.ToString()
                                      next
                                      ToString = output
                      end function
       
                      public sub Append(vFields)
                                      dim key
                                      for each key in vFields.List.Keys
                                                      dim fld
                                                      set fld = vFields.List.Item(key)
                                                      pvtList.Add key, fld
                                                      pvtOriginal.Add Key, fld.Clone()
                                      next
                      end sub
       
                      public sub Class_Terminate()
                                      set pvtList = nothing
                      end sub
      end class
       
      class DateHelper
                      public sub Class_Initialize()
                      end sub
       
                      public function ConvertToMMDDYY(dt)
                                      dim d, items
                                      d = FormatDateTime(dt,2)
                                      items = split(d,"/")
                                      ConvertToMMDDYY = Lpad(items(0),"0",2) & Lpad(items(1),"0",2) & Lpad(right(items(2),2),"0",2)
                      end function
       
                      Function Lpad (MyValue, MyPadChar, MyPaddedLength)
                                      Lpad = String(MyPaddedLength - Len(MyValue),MyPadChar) & MyValue
                      End Function
       
       
                      public sub Class_Terminate()
                      end sub
       
      end class
       
      class XmlHelper
                      private pvtXmlDoc
                      public sub Class_Initialize()
                                      set pvtXmlDoc = CreateObject("Microsoft.XMLDOM")
                      end sub
       
                      property get Doc
                                      set Doc = pvtXmlDoc
                      end property
       
                      public function LoadXML(Data)
                                      Dim Node
                                      pvtXmlDoc.async = False
                                      pvtXmlDoc.LoadXML(Data)
                                      set Node = pvtXmlDoc.SelectSingleNode("RpcData")
                                      set Node = nothing
                                      set LoadXML = pvtXmlDoc
                      end function
       
       
                      public function GetFieldValue(name)
                                      Dim RootNode, FldList, FldNode, Found, Value
                                      Found = False
                                      Value = ""
                                      set FldList = pvtXmlDoc.SelectSingleNode("RpcData").SelectNodes("Fld")
                                      For each FldNode in FldList
                                                      If FldNode.attributes.GetNamedItem("Nm").nodeValue = name Then
                                                                      Value = FldNode.text
                                                                      exit For
                                                      End If
                                      Next
                                      GetFieldValue = Value
                      end function
       
                      public sub Class_Terminate()
                      set pvtXmlDoc = nothing
                      end sub
       
      end class
       
      class SnapShotLoader
                      private Director, Tool, SnapShotName, xmlData
       
                      public sub Class_Initialize()
                      end sub
       
                      public function Load(vDirector, vTool, vSnapShotName)
                                      dim doc, fields, utils
                                      set fields = new Fields
                                      xmlData = ReadSnapShot(vTool, vSnapShotName, "623" ,vDirector.LoanNo)
                                      set utils = new XmlHelper
       
                                      if Len(xmlData) > 0 then
                                                      set doc = utils.LoadXML(xmlData)
                                                      Doc2Fields doc, fields
                                      end if
                                      set Load = fields
                      end function
       
                      public function ToString()
                                      ToString = xmlData
                      end function
       
                      private function ReadSnapShot(vTool, vSnapShotName, vClientId, vLoanNumber)
                                      dim Data
                                      dim ErrMsg
                                      vTool.SnapshotName = name
                                      vTool.ClientId = vClientId
                                      vTool.LoanNo = vLoanNumber
                                      If vTool.Retrieve(ErrMsg) = 0 Then
                                                      vTool.GetSnapshotData 2, Data, ErrMsg
                                      End If
                                      ReadSnapShot = Data
                      end function
       
                      private sub Doc2Fields(vDoc, vFields)
                                      Dim RootNode, FldList, FldNode
       
                                      set FldList = vDoc.SelectSingleNode("RpcData").SelectNodes("Fld")
                                      For each FldNode in FldList
                                                      dim key, name, value, tag
                                                      key = FldNode.attributes.GetNamedItem("Nm").nodeValue
                                                      name = FldNode.attributes.GetNamedItem("BusinessName").nodeValue
                                                      value = FldNode.text
                                                      if not vFields.Add(key, value, name, 0, 0, "", 0,0,0,tag) then
                                                                      msgbox "Failed to add field: " & key, vbOKonly + vbCritical, "XML Field Load Error"
                                                      end if
                                      Next
                      end sub
       
                      public sub Class_Terminate()
                      end sub
      end class
       
      class ScreenManager
          dim ErrMsg, original_loan, original_screen, original_window, oTool
       
          public sub Class_Initialize()
                      end sub
       
                      public function ToString()
                                      ToString = oTool.CurrentScreen & "/" & oTool.CurrentWindow
                      end function
       
                      public sub Load(tool, loan)
                                      set oTool = tool
                                      ' grab the current state of the 3270
                                      ' we use these later to reset to the former state
                                      original_loan = loan
                                      original_screen = oTool.CurrentScreen
                                      original_window = oTool.CurrentWindow
                      end sub
       
                      public sub Reset()
                                      oTool.ShowScreen original_screen, original_window, original_loan, ErrMsg
                      end sub
       
                      public sub Clear()
                                      oTool.SendKeyStrokes "@CLEAR", ErrMsg
                      end sub
       
                      public sub Class_Terminate()
                      end sub
      end class
       
      '******************************************************************************
      ' Script specific classes
      '******************************************************************************
       
      class OtdpTasker
                      dim ErrMsg, atl3270Tool
       
                      public sub Class_Initialize()
                      end sub
       
                      public sub CreateTask(tool, taskId, employeeId, employeeName)
                                      set at13270Tool = tool
                                      atl3270Tool.ShowScreen "TSK1", " ", atl3270Tool.LoanNo, ErrMsg   ' Opens Screen TSK1 for current loan
                                      atl3270Tool.WaitForString 4, 3, 5, "TASK", ErrMsg      ' Waits for screen to finish loading.
                                      atl3270Tool.MoveCursor 5, 9, ErrMsg    'Moves cursor to Task ID line
                                      atl3270Tool.SendKeyStrokes taskId, ErrMsg  ' INputs task ID CUS016
                                      atl3270Tool.SendKeyStrokes "@ENTER", ErrMsg ' Presses enter to continue setting up task
                                      atl3270Tool.MoveCursor 6, 6, ErrMsg       'Moves cursor to action code
                                      atl3270Tool.SendKeyStrokes "A", ErrMsg ' Types in A for Add in action code
                                      atl3270Tool.MoveCursor 7, 6, ErrMsg    ' Moves cursor to SRC field (source)
                                      atl3270Tool.SendKeyStrokes "01", ErrMsg ' Types in 01 in SRC field
                                      atl3270Tool.MoveCursor 7, 9, ErrMsg  ' Moves cursor to source description
                                      atl3270Tool.SendKeyStrokes "Phone Request", ErrMsg ' Types in phone request into source description
                                      atl3270Tool.MoveCursor 9, 47, ErrMsg ' Moves cursor to ID field
                                      atl3270Tool.SendKeyStrokes employeeId, ErrMsg ' Types in OBM for Obon McIntyre in User ID field
                                      atl3270Tool.MoveCursor 9, 51, ErrMsg ' Moves cursor to User ID description field
                                      atl3270Tool.SendKeyStrokes employeeName, ErrMsg ' Types in Obon McIntyre
                                      atl3270Tool.SendKeyStrokes "@ENTER", ErrMsg ' Presses enter to complete adding task.
                                      atl3270Tool.ClearScreen False, ErrMsg ' Clears screen
                      end sub
       
                      public sub Class_Terminate()
                      end sub
      end class
       
      class CrossFooter
          dim payments, payment, curt, add_escrow, suspense, corpadv, fee, fee1, fee2, fee3, delq_fee
                      dim base_fees, additional_fees
                      public sub Class_Initialize()
                      end sub
       
                      function Total(oFields)
                                      payment = lCCur(oFields.List.Item(LN_MONTHLY_PMT_AM).Value())
                                      payments = lCCur(oFields.List.Item(LN_PAYMENTS).Value())
                                      curt = lCCur(oFields.List.Item(LN_CURTAILMENT).Value())
                                      add_escrow = lCCur(oFields.List.Item(LN_ADD_ESCROW).Value())
                                      suspense = lCCur(oFields.List.Item(LN_SUSPENSE).Value())
                                      corpadv = lCCur(oFields.List.Item(LN_CORP_ADV_AMT).Value())
                                      fee = lCCur(oFields.List.Item(LN_FEE).Value())
                                      fee1 = lCCur(oFields.List.Item(LN_ADD_FEE_1).Value())
                                      fee2 = lCCur(oFields.List.Item(LN_ADD_FEE_2).Value())
                                      fee3 = lCCur(oFields.List.Item(LN_ADD_FEE_3).Value())
                                      delq_fee = lCCur(oFields.List.Item(DELINQUENCY_FEE).Value())
       
                                      base_fees = curt + add_escrow + suspense + corpadv + fee + delq_fee
                                      additional_fees = fee1 + fee2 + fee3
       
                                      if oFields.List.Item(ADDL_FEES).Value() = "Y" then
                                                      Total = GetTotalWithAddlFees(oFields)
                                      else
                                                      Total = GetTotalWithoutAddlFees(oFields)
                                      end if
                      end function
       
                      function lCCur(value)
                                      if value = "" then
                                                      lCCur = CCur(0)
                                      else
                                                      lCCur = CCur(value)
                                      end if
                      end function
       
                      function GetTotalWithAddlFees(oFields)
                                      dim total
                                      total = (payment * payments) + base_fees + additional_fees
                                      GetTotalWithAddlFees = total
                      end function
       
                      function GetTotalWithoutAddlFees(oFields)
                                      dim total
                                      total = (payment * payments) + base_fees
                                      GetTotalWithoutAddlFees = total
                      end function
       
                      public sub Class_Terminate()
                      end sub
      end class
       
      class OtdpSaver
                      dim ErrorMessages, AdditionalMessages, ErrMsg, atl3270Tool, oDateHelper
       
                      public sub Class_Initialize()
                      end sub
       
                      function Errors()
                                      Errors = "Error: " & ErrorMessages & vbCr & vbLf & vbCr & vbLf & "Additional info: " & AdditionalMessages
                      end function
       
                      sub SetErrorMessage(msg)
                                      ErrorMessages = ErrorMessages & vbCr & vbLf & msg
                      end sub
       
                      sub SetErrorAdditional(msg)
                                      AdditionalMessages = AdditionalMessages & vbCr & vbLf & msg
                      end sub
       
                      function DateIsValid(tool, fields, screenManager)
                                      dim oDateHelper, scheduledDate
                          screenManager.Clear
                                      set atl3270Tool = tool
                                      set oDateHelper = new DateHelper
                                      scheduledDate = oDateHelper.ConvertToMMDDYY(cdate(fields.List.Item(CURRENT_DATE).Value))
       
                                      tool.ShowScreen "DFT4", " ", tool.LoanNo, ErrMsg   ' Opens Screen DFT4 for current loan
                                      tool.WaitForString 5, 3, 5, "SCH", ErrMsg       ' Waits for DFT4 screen to load before proceeding.
       
                                      tool.MoveCursor 6, 3, ErrMsg                    ' Moves cursor to Scheduled Date
                                      tool.SendKeyStrokes scheduledDate, ErrMsg    ' Writes date to Scheduled Date
                                      tool.SendKeyStrokes "@ENTER", ErrMsg  ' Presses enter so information can be added to the scheduled date
                                      tool.WaitForString 5, 3, 5, "SCH", ErrMsg
       
                                      DateIsValid = not IsWeekendDate() and not IsHolidayDate()
       
                      end function
       
                      function Purge(tool, fields, screenManager)
                                      dim oDateHelper, scheduledDate
       
                          'screenManager.Clear
                                      set oDateHelper = new DateHelper
                                      scheduledDate = oDateHelper.ConvertToMMDDYY(cdate(fields.List.Item(CURRENT_DATE).Value))
       
                                      'tool.ShowScreen "DFT4", " ", tool.LoanNo, ErrMsg   ' Opens Screen DFT4 for current loan
                                      'tool.WaitForString 5, 3, 5, "SCH", ErrMsg       ' Waits for DFT4 screen to load before proceeding.
       
                                      'tool.MoveCursor 6, 3, ErrMsg                    ' Moves cursor to Scheduled Date
                                      'tool.SendKeyStrokes scheduledDate, ErrMsg    ' Writes date to Scheduled Date
                                      'tool.SendKeyStrokes "@ENTER", ErrMsg  ' Presses enter so information can be added to the scheduled date
                                      'tool.WaitForString 5, 3, 5, "SCH", ErrMsg
       
                                      dim ErrMsg
                                      dim Amount
                                      tool.ReadScreen 6, 16, 10, Amount, ErrMsg
       
                                      'groom the data
                                      Amount = Replace(Amount, UNDERSCORE, EMPTY_STRING)
                                      'if InStr(value, PERIOD) > 0 then
                                      if Amount = PERIOD then
                                                      Amount = ZERO_DOLLARS
                                      else
                                                      Amount = trim(Amount)
                                      end if
       
                                      if Amount > 0 then
                                                      CancelTransaction tool, fields, screenManager
                                      end if
       
       
                      end function
       
                      function Save(tool, fields, screenManager)
                          dim PassedCrossFoot, PassedRouting, PageOneHeaderAdded, PageTwoHeaderAdded, PageThreeHeaderAdded, IsNotHoliday
       
                                      Purge tool, fields, screenManager
       
                                      'screenManager.Clear
                                      set atl3270Tool = tool
       
                                      'only process the save if we have routing number data
                                      If HasRoutingNumber(fields) Then
                                                      'screen one
                                                      DFT4_Page1(fields)
                                                      NextScreen()
       
                                                      'screen two
                                                      if HasAdditionalFees(fields) then
                                                                      if HasNewDollarAmount(fields) then
                                                                                      DFT4_Page2(fields)
                                                                                      NextScreen()
                                                                      else
                                                                                      NextScreen()
                                                                      end if
                                                      else
                                                                      NextScreen()
                                                      end if
       
                                                      'screen three
                                                      if ValidateCrossFoot() then        
                                                                      DFT4_Page3(fields)
                                                                      NextScreen()
                                                                      Save = ValidateHeaderAdded() and ValidateRouting()
                                                      else
                                                                      Save = false
                                                      end if
                                      else
                                                      Save = false
                                      end if
                      end function
       
                      sub DFT4_Page1(fields)
                                      dim scheduledDate, actionCode
                                      dim paymentAmount, numberOfPayments, overrideCode
                                      dim curtailmentAmount, addlEscrowAmount, suspenseAmount
                                      dim suspenseCode, delinquencyFeeAmount, feeAmount, feeCode, AdditionalFees
                                      set oDateHelper = new DateHelper
       
                                      scheduledDate = oDateHelper.ConvertToMMDDYY(cdate(fields.List.Item(CURRENT_DATE).Value))
                                      actionCode = fields.List.Item(LN_ACTION).Value
                                      paymentAmount = ccur(fields.List.Item(LN_AMOUNT).Value)
                                      numberOfPayments = fields.List.Item(LN_PAYMENTS).Value
                                      overrideCode = fields.List.Item(LN_OVERRIDES).Value
                                      curtailmentAmount = ccur(fields.List.Item(LN_CURTAILMENT).Value)
                                      addlEscrowAmount = ccur(fields.List.Item(LN_ADD_ESCROW).Value)
                                      suspenseAmount = ccur(fields.List.Item(LN_SUSPENSE).Value)
                                      suspenseCode = fields.List.Item(LN_SUSPENSE_CODE).Value
                                      delinquencyFeeAmount = ccur(fields.List.Item(DELINQUENCY_FEE).Value)
                                      feeAmount = ccur(fields.List.Item(LN_FEE).Value)
                                      feeCode = fields.List.Item(LN_FEE_CODE).Value
                                      AdditionalFees = fields.List.Item(ADDL_FEES).Value
       
                                      'atl3270Tool.ShowScreen "DFT4", " ", atl3270Tool.LoanNo, ErrMsg   ' Opens Screen DFT4 for current loan
                                      'atl3270Tool.WaitForString 5, 3, 5, "SCH", ErrMsg       ' Waits for DFT4 screen to load before proceeding.
       
                                      'atl3270Tool.MoveCursor 6, 3, ErrMsg                    ' Moves cursor to Scheduled Date
                                      'atl3270Tool.SendKeyStrokes scheduledDate, ErrMsg    ' Writes date to Scheduled Date
                                      'atl3270Tool.SendKeyStrokes "@ENTER", ErrMsg  ' Presses enter so information can be added to the scheduled date
                                      'atl3270Tool.WaitForString 5, 3, 5, "SCH", ErrMsg
       
                                      atl3270Tool.MoveCursor 6, 12, ErrMsg                   ' Moves cursor to Action Code
                                      atl3270Tool.SendKeyStrokes actionCode, ErrMsg       ' Writes Action Code to Action Code
       
                                      atl3270Tool.MoveCursor 6, 16, ErrMsg    ' Moves cursor to Amount Received field
                                      atl3270Tool.SendKeyStrokes "@DELETE", ErrMsg
                                      atl3270Tool.SendKeyStrokes FormatCurrencyInput(paymentAmount, "0", 10), ErrMsg   ' must pad input so it overwrites existing data
       
                                      atl3270Tool.MoveCursor 6, 30, ErrMsg    ' Moves cursor to Number of Payments field
                                      atl3270Tool.SendKeyStrokes numberOfPayments, ErrMsg ' Writes Number of payments to Payments field
       
                                      atl3270Tool.MoveCursor 6, 34, ErrMsg    ' Moves cursor to Override
                                      atl3270Tool.SendKeyStrokes overrideCode, ErrMsg  ' Writes Override Code to Override field
       
                                      if curtailmentAmount > 0 then
                                                      atl3270Tool.MoveCursor 6, 51, ErrMsg    ' Moves cursor to Curtailment Amount
                                                      atl3270Tool.SendKeyStrokes FormatCurrencyInput(curtailmentAmount, "0", 9), ErrMsg  ' Writes Curtailment Amt to Curtailment field
                                      end if
       
                                      if addlEscrowAmount > 0 then
                                                      atl3270Tool.MoveCursor 8, 6, ErrMsg     ' Moves cursor to Additional Escrow field
                                                      atl3270Tool.SendKeyStrokes FormatCurrencyInput(addlEscrowAmount, "0", 9), ErrMsg  ' Writes Additional Escrow to Addl Escrow field
                                      end if
       
                                      if suspenseAmount > 0 then
                                                      atl3270Tool.MoveCursor 8, 19, ErrMsg    ' Moves cursor to Suspense field
                                                      atl3270Tool.SendKeyStrokes FormatCurrencyInput(suspenseAmount, "0", 9), ErrMsg  ' Writes Suspense amount to Suspense field
       
                                                      atl3270Tool.MoveCursor 8, 33, ErrMsg    ' Moves cursor to Suspense Reason Code
                                                      atl3270Tool.SendKeyStrokes suspenseCode, ErrMsg  ' Writes Suspense reason code to CD field
                                      end if
       
                                      'If the Delq Fee is being Removed, the system requires the delete key to be pressed 9 times
                                      'rather than overwriting the current amount with 0.00.
                                      ' Edit 04-17-09.  Found out the ERASEEOF command works instead and is more practical.
                                      If delinquencyFeeAmount = 0 Then
                                                      atl3270Tool.MoveCursor 10, 16, ErrMsg    ' Moves cursor to Delinquency Fee
                                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears Delinquency Fee                                    
                                      Else
                                                      atl3270Tool.MoveCursor 10, 16, ErrMsg    ' Moves cursor to Delinquency Fee
                                                      atl3270Tool.SendKeyStrokes FormatCurrencyInput(delinquencyFeeAmount, "0", 9), ErrMsg  ' Writes Delinquency Fee to Delq Fee field
                                      End If
       
                                      if feeAmount > 0 then
                                                      atl3270Tool.MoveCursor 10, 28, ErrMsg    ' Moves cursor to Fee Amount field
                                                      atl3270Tool.SendKeyStrokes FormatCurrencyInput(feeAmount, "0", 7), ErrMsg  ' Writes Fee Amount to Fee field on first screen of DFT4
       
                                                      atl3270Tool.MoveCursor 10, 38, ErrMsg    ' Moves cursor to Fee Code field
                                                      atl3270Tool.SendKeyStrokes feeCode, ErrMsg  ' Writes Fee Code
                                      end if
       
                                      If HasAdditionalFees(fields) then
                                                      atl3270Tool.MoveCursor 10, 48, ErrMsg                   ' Moves cursor to Additional Fees Code
                                                      atl3270Tool.SendKeyStrokes "Y", ErrMsg       ' Writes Additional Fees to Action Code
                                      else
                                                      atl3270Tool.MoveCursor 10, 48, ErrMsg                   ' Moves cursor to Additional Fees Code
                                                      atl3270Tool.SendKeyStrokes "N", ErrMsg       ' Writes Additional Fees to Action Code
                                      end if
       
                      end sub
       
                      sub DFT4_Page2(fields)
                                      dim FeeCode1, FeeAmt1, FeeCode2, FeeAmt2, FeeCode3, FeeAmt3
                                      dim Payee, Reason, CorpAmount
       
                                      FeeCode1 = fields.List.Item(LN_ADD_FEE_1_CODE).Value
                                      FeeAmt1 = ccur(fields.List.Item(LN_ADD_FEE_1).Value)
                                      FeeAmt1 = FormatCurrencyInput(FeeAmt1, "0", 8) ' must pad input so it overwrites existing data
       
                                      FeeCode2 = fields.List.Item(LN_ADD_FEE_2_CODE).Value
                                      FeeAmt2 = ccur(fields.List.Item(LN_ADD_FEE_2).Value)
                                      FeeAmt2 = FormatCurrencyInput(FeeAmt2, "0", 8) ' must pad input so it overwrites existing data
       
                                      FeeCode3 = fields.List.Item(LN_ADD_FEE_3_CODE).Value
                                      FeeAmt3 = ccur(fields.List.Item(LN_ADD_FEE_3).Value)
                                      FeeAmt3 = FormatCurrencyInput(FeeAmt3, "0", 8) ' must pad input so it overwrites existing data
       
                                      Payee = fields.List.Item(LN_CORP_ADV_PAYEE).Value
                                      Reason = fields.List.Item(LN_CORP_ADV_REASON).Value
                                      CorpAmount = ccur(fields.List.Item(LN_CORP_ADV_AMT).Value)
                                      CorpAmount = FormatCurrencyInput(CorpAmount, "0", 8) ' must pad input so it overwrites existing data
       
                                      atl3270Tool.WaitForString 5, 3, 5, "CD", ErrMsg       ' Waits for Additional Fees window off DFT4 screen to load before proceeding.
       
                                      if FeeAmt1 > 0 then
                                                      atl3270Tool.MoveCursor 6, 3, ErrMsg  ' Moves cursor to first Additional Fee Code field
                                                      atl3270Tool.SendKeyStrokes FeeCode1, ErrMsg   ' Writes Additional Fee Code1 to screen.
                                                      atl3270Tool.MoveCursor 6, 6, ErrMsg  ' Moves cursor to first Additional Fee Amt field
                                                      atl3270Tool.SendKeyStrokes FeeAmt1, ErrMsg  ' Writes first Additional Fee
                                      else
                                                      atl3270Tool.MoveCursor 6, 3, ErrMsg    ' Moves cursor to first Additional Fee Code field
                                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
                                                      atl3270Tool.MoveCursor 6, 6, ErrMsg ' Moves cursor to the first Additional Fee Amt field
                                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
                                      end if
       
                                      if FeeAmt2 > 0 then
                                                      atl3270Tool.MoveCursor 6, 18, ErrMsg ' Moves cursor to second Additional Fee Code field
                                                      atl3270Tool.SendKeyStrokes FeeCode2, ErrMsg ' Writes second Additional Fee Code
                                                      atl3270Tool.MoveCursor 6, 21, ErrMsg ' Moves cursor to second Additional Fee Amt field
                                                      atl3270Tool.SendKeyStrokes FeeAmt2, ErrMsg  ' Writes second Additional Fee
                                      else
                                                      atl3270Tool.MoveCursor 6, 18, ErrMsg    ' Moves cursor to second Additional Fee Code field
                                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
                                                      atl3270Tool.MoveCursor 6, 21, ErrMsg ' Moves cursor to the second Additional Fee Amt field
                                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
                                      end if
       
                                      if FeeAmt3 > 0 then
                                                      atl3270Tool.MoveCursor 6, 33, ErrMsg ' Moves cursor to third Additional Fee Code field
                                                      atl3270Tool.SendKeyStrokes FeeCode3, ErrMsg ' Writes third Additional Fee Code
                                                      atl3270Tool.MoveCursor 6, 36, ErrMsg ' Moves cursor to third Additional Fee Amt field
                                                      atl3270Tool.SendKeyStrokes FeeAmt3, ErrMsg  ' Writes third Additional Fee Amt
                                      else
                                                      atl3270Tool.MoveCursor 6, 33, ErrMsg    ' Moves cursor to third Additional Fee Code field
                                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
                                                      atl3270Tool.MoveCursor 6, 36, ErrMsg ' Moves cursor to the third Additional Fee Amt field
                                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears field
                                      end if
       
                                      atl3270Tool.MoveCursor 6, 57, ErrMsg ' Moves cursor to Payee field
                                      atl3270Tool.SendKeyStrokes Payee, ErrMsg ' Writes Payee to payee field
                                      atl3270Tool.MoveCursor 6, 63, ErrMsg ' Moves cursor to RSN field
                                      atl3270Tool.SendKeyStrokes Reason, ErrMsg  ' Writes RSN to RSN field
                                      atl3270Tool.MoveCursor 6, 68, ErrMsg ' Moves cursor to Corp Amount field
       
                                      if CorpAmount > 0 then
                                                      atl3270Tool.SendKeyStrokes CorpAmount, ErrMsg  ' Writes Corp Amount to field
                                      end if
                      end sub
       
                      sub DFT4_Page3(fields)
                                      dim RoutingNumber, AccountNumber, AccountName, AccountType, Requestor, PhoneNumber
       
                                      RoutingNumber = fields.List.Item(ROUTING_NUMBER).Value
                                      AccountNumber = fields.List.Item(ACCOUNT_NUMBER).Value
                                      AccountName = fields.List.Item(ACCOUNT_NAME).Value
                                      AccountType = fields.List.Item(ACCOUNT_TYPE).Value
                                      Requestor = fields.List.Item(MORT_BILL_NAME).Value
                                      PhoneNumber = fields.List.Item(LN_TELEPHONE_NO).Value
       
                                      atl3270Tool.WaitForString 5, 2, 5, "ACCT", ErrMsg ' Waits for Routing/Acct screen to load before proceeding
       
                                      atl3270Tool.MoveCursor 6, 8, ErrMsg  ' Moves cursor to Routing Number
                                      atl3270Tool.SendKeyStrokes RoutingNumber, ErrMsg ' Writes Routing Number to screen
       
                                      atl3270Tool.MoveCursor 6, 20, ErrMsg  ' Moves cursor to Account Number
                                      atl3270Tool.SendKeyStrokes AccountNumber, ErrMsg ' Writes Account Number to field
                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears rest of field after account number
       
                                      atl3270Tool.MoveCursor 6, 38, ErrMsg ' Moves cursor to Account Name
                                      atl3270Tool.SendKeyStrokes AccountName, ErrMsg ' Writes Account Name to account name field
                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears rest of field after account name
       
                                      atl3270Tool.MoveCursor 6, 61, ErrMsg ' Moves cursor to account type field
                                      atl3270Tool.SendKeyStrokes AccountType, ErrMsg ' Writes Account Type to account type field
       
                                      atl3270Tool.MoveCursor 7, 13, ErrMsg ' Moves cursor to Requestor field
                                      atl3270Tool.SendKeyStrokes Requestor, ErrMsg ' Writes requestor to requestor field
                                      atl3270Tool.SendKeyStrokes "@ERASEEOF", ErrMsg ' Clears rest of field after requestor
       
                                      atl3270Tool.MoveCursor 7, 49, ErrMsg ' Moves cursor to Phone Number field
                                      atl3270Tool.SendKeyStrokes PhoneNumber, ErrMsg ' Writes Phone Number to phone number field
       
                      end sub
       
                      function FormatCurrencyInput(MyValue, MyPadChar, MyPaddedLength)
                                      FormatCurrencyInput = String(MyPaddedLength - Len(MyValue),MyPadChar) & MyValue
                      end function
       
                      sub NextScreen()
                                      atl3270Tool.SendKeyStrokes "@PF5", ErrMsg ' Presses F5 to complete input information
                      end sub
       
                      public sub CancelTransaction(o3270, fields, screenManager)
                                      set oTool = o3270
       
                                      oTool.SendKeyStrokes "@ENTER", ErrMsg
                                      oTool.SendKeyStrokes "@PF12", ErrMsg
                                      oTool.SendKeyStrokes "@PF12", ErrMsg
                      end sub
       
                      function ValidateHeaderAdded()
                                      dim msg
                          atl3270Tool.ReadScreen 13, 2, 33, msg, ErrMsg ' Checks for successfully completed message
                          If msg = "*** HEADER SUCCESSFULLY ADDED ***" Then
                                                      ValidateHeaderAdded = true
                          Else
                                                      ValidateHeaderAdded = false
                                                      SetErrorMessage("HEADER NOT ADDED")
                                                      SetErrorAdditional(msg)
                          End If
                      end function
       
                      function ValidateRouting()
                                      Dim msg
                                      atl3270Tool.ReadScreen 13, 2, 62, msg, ErrMsg
                                      If msg = "*** ROUTING AND TRANSIT NUMBER IS INVALID ***" Then
                                          SetErrorMessage("ROUTING AND TRANSIT NUMBER IS INVALID")
                                                      SetErrorAdditional(msg)
                                                      ValidateRouting = false
                                      Else
                                                      ValidateRouting = true
                                      End If
                      end function
       
                      function ValidateCrossFoot()
                                      ValidateCrossFoot = (CrossfootCheck = 0)
                      end function
       
                      function IsHolidayDate()
                                      Dim msg
                                      atl3270Tool.ReadScreen 13, 2, 39, msg, ErrMsg
                                      If msg = "*** DRAFT DATE CAN NOT BE A HOLIDAY ***" Then
                                                      SetErrorMessage("Holiday Error")
                                                      SetErrorAdditional(msg)
                                                      IsHolidayDate = true
                                      Else
                                                      IsHolidayDate = false
                                      End If
                      end function     
       
                      function IsWeekendDate()
                                      Dim msg
                                      atl3270Tool.ReadScreen 13, 2, 39, msg, ErrMsg
                                      If msg = "*** DRAFT DATE MUST BE A PROCESSING DAY" Then
                                                      SetErrorMessage("Weekend Error")
                                                      SetErrorAdditional(msg)
                                                      IsWeekendDate = true
                                      Else
                                                      IsWeekendDate = false
                                      End If
                      end function
       
       
                      function IsNewBankData(fields)
                                      dim old_route, new_route
                                      old_route = fields.List.Item(ROUTING_NUMBER).Value
                                      new_route = fields.OriginalList.Item(ROUTING_NUMBER).Value
       
                                      IsNewBankData = (old_route <> new_route)
                      end function
       
                      function HasNewDollarAmount(fields)
                          dim F, F1, F2, F3, CA
       
       
                                      F = fields.List.Item(LN_FEE).Value <> fields.OriginalList.Item(LN_FEE).Value
                                      'if F then
                                      '               msgbox(fields.List.Item(LN_FEE).Value & " and " & fields.OriginalList.Item(LN_FEE).Value & " are not equal")
                                      'else
                                      '               msgbox(fields.List.Item(LN_FEE).Value & " and " & fields.OriginalList.Item(LN_FEE).Value & " are equal")
                                      'end if
                                      F1 = fields.List.Item(LN_ADD_FEE_1).Value <> fields.OriginalList.Item(LN_ADD_FEE_1).Value
                                      F2 = fields.List.Item(LN_ADD_FEE_2).Value <> fields.OriginalList.Item(LN_ADD_FEE_2).Value
                                      F3 = fields.List.Item(LN_ADD_FEE_3).Value <> fields.OriginalList.Item(LN_ADD_FEE_3).Value
                                      CA = fields.List.Item(LN_CORP_ADV_AMT).Value <> fields.OriginalList.Item(LN_CORP_ADV_AMT).Value
                                      HasNewDollarAmount = F or F1 or F2 or F3 or CA
                      end function
       
                      function CrossfootCheck()
                                      Dim msg, amount
                                      atl3270Tool.ReadScreen 13, 2, 37, msg, ErrMsg
                                      If msg = "*** TRANSACTION OUT OF CROSSFOOT BY $" Then
                                                      atl3270Tool.ReadScreen 13, 49, 10, amount, ErrMsg  'grabs the amount of crossfoot error
                                                      CrossfootCheck = ccur(amount)
                                                      SetErrorMessage("Crossfoot Check Failed")
                                                      SetErrorAdditional(msg)
                                      Else
                                                      CrossfootCheck = ccur(0)
                                      End If
                      end function
       
                      function HasRoutingNumber(fields)
                                      HasRoutingNumber = fields.List.Item(ROUTING_NUMBER).Value <> ""
                      end function
       
                      function HasAdditionalFees(fields)
                                      dim Flag, F1, F2, F3, CA, Total
                                      Flag = fields.List.Item(ADDL_FEES).Value = "Y"
                                      F1 = fields.List.Item(LN_ADD_FEE_1).Value
                                      F2 = fields.List.Item(LN_ADD_FEE_2).Value
                                      F3 = fields.List.Item(LN_ADD_FEE_3).Value
                                      CA = fields.List.Item(LN_CORP_ADV_AMT).Value
                                      Total = CCur(F1) + CCur(F2) + CCur(F3) + CCur(CA)
                                      HasAdditionalFees = Flag and (Total > 0)
                      end function
       
                      public sub Class_Terminate()
                                      set oDateHelper = nothing
                      end sub
      end class
       
      class OtdpScraper
                      private oFields
                      private HasAdditionalFees
       
                      public sub Class_Initialize()
                                      set oFields = new Fields
                                      HasAdditionalFees = false
       
                                      oFields.Add DELINQUENCY_FEE, EMPTY_STRING, DELINQUENCY_FEE_CAPTION, 0, 0, EMPTY_STRING, 10, 16, 8 , 0
                                      oFields.Add ROUTING_NUMBER, EMPTY_STRING, ROUTING_NUMBER_CAPTION,   0, 0, EMPTY_STRING, 6 , 8 , 9 , 0
                                      oFields.Add ACCOUNT_NUMBER, EMPTY_STRING, ACCOUNT_NUMBER_CAPTION,   0, 0, EMPTY_STRING, 6 , 20, 17, 0
                                      oFields.Add ACCOUNT_TYPE, EMPTY_STRING, ACCOUNT_TYPE_CAPTION,       0, 0, EMPTY_STRING, 6 , 61, 1 , 0
                                      oFields.Add ADDL_FEES, EMPTY_STRING, ADDL_FEES_CAPTION,       0, 0, REQ_STRIP, 10 , 48, 1 , 0
                                      oFields.Add LN_FEE, 0, LN_FEE_CAPTION, 0, 0, EMPTY_STRING, 10, 28, 8,0
                                      oFields.Add LN_FEE_CODE, EMPTY_STRING, LN_FEE_CODE_CAPTION, 0, 0, REQ_STRIP, 10, 38, 1,0
                                      oFields.Add LN_ADD_FEE_1, 0, LN_ADD_FEE_1_CAPTION, 0, 0, EMPTY_STRING, 6, 6, 8,0
                                      oFields.Add LN_ADD_FEE_1_CODE, EMPTY_STRING, LN_ADD_FEE_1_CODE_CAPTION, 0, 0, REQ_STRIP, 6, 3, 2,0
                                      oFields.Add LN_ADD_FEE_2, 0, LN_ADD_FEE_2_CAPTION, 0, 0, EMPTY_STRING, 6, 21, 8,0
                                      oFields.Add LN_ADD_FEE_2_CODE, EMPTY_STRING, LN_ADD_FEE_2_CODE_CAPTION, 0, 0, REQ_STRIP, 6, 18, 2,0
                                      oFields.Add LN_ADD_FEE_3, 0, LN_ADD_FEE_3_CAPTION, 0, 0, EMPTY_STRING, 6, 36, 8,0
                                      oFields.Add LN_ADD_FEE_3_CODE, EMPTY_STRING, LN_ADD_FEE_3_CODE_CAPTION, 0, 0, REQ_STRIP, 6, 33, 2,0
       
                                      oFields.Add LN_CORP_ADV_PAYEE, EMPTY_STRING, LN_CORP_ADV_PAYEE_CAPTION, 0, 0, EMPTY_STRING, 6, 57, 5,0
                                      oFields.Add LN_CORP_ADV_REASON, EMPTY_STRING, LN_CORP_ADV_REASON_CAPTION, 0, 0, EMPTY_STRING, 6, 63, 4,0
                                      oFields.Add LN_CORP_ADV_AMT, 0, LN_CORP_ADV_AMT_CAPTION, 0, 0, EMPTY_STRING, 6, 68, 8,0
       
                                      oFields.Add LN_RECEIVED_AMT, 0, LN_RECEIVED_AMT_CAPTION, 0, 0, EMPTY_STRING, 6, 68, 8,0
       
                      end sub
       
                      public function Load(o3270, loan, screenManager)
                                      dim ErrMsg
       
                                      screenManager.Clear
                                      o3270.ShowScreen DFT4, BLANK_SPACE, loan, ErrMsg
                                      o3270.WaitForString 5, 3, 5, "SCH", ErrMsg
                                      ReadScreen oFields.List.Item(DELINQUENCY_FEE)
                                      ReadScreen oFields.List.Item(LN_FEE)           ' New
                                      ReadScreen oFields.List.Item(LN_FEE_CODE)     ' New
       
                                      dim flag
                                      o3270.ReadScreen 10, 48, 1, flag, ErrMsg ' New
                                      ReadScreen oFields.List.Item(ADDL_FEES)
                                      HasAdditionalFees = trim(flag) = "Y"
       
                                      o3270.SendKeyStrokes "@PF5", ErrMsg
                                      o3270.WaitForString 5, 3, 5, "CD", ErrMsg
       
                                      if HasAdditionalFees then
                                                      ReadScreen oFields.List.Item(LN_ADD_FEE_1_CODE)            ' New
                                                      ReadScreen oFields.List.Item(LN_ADD_FEE_1)                  ' New
                                                      ReadScreen oFields.List.Item(LN_ADD_FEE_2_CODE)            ' New
                                                      ReadScreen oFields.List.Item(LN_ADD_FEE_2)                  ' New
                                                      ReadScreen oFields.List.Item(LN_ADD_FEE_3_CODE)            ' New
                                                      ReadScreen oFields.List.Item(LN_ADD_FEE_3)                  ' New
                                                      ReadScreen oFields.List.Item(LN_CORP_ADV_PAYEE)        ' New
                                                      ReadScreen oFields.List.Item(LN_CORP_ADV_REASON)       ' New
                                                      ReadScreen oFields.List.Item(LN_CORP_ADV_AMT)       ' New
                                      end if
       
                                      o3270.SendKeyStrokes "@PF5", ErrMsg
                                      o3270.WaitForString 5, 2, 5, "ACCT", ErrMsg
                                      ReadScreen oFields.List.Item(ROUTING_NUMBER)
                                      ReadScreen oFields.List.Item(ACCOUNT_NUMBER)
                                      ReadScreen oFields.List.Item(ACCOUNT_TYPE)
       
                                      set Load = oFields
                      end function
       
                      private sub ReadScreen(vField)
                                      dim ErrMsg
                                      dim value
                                      o3270.ReadScreen vField.Row, vField.Col, vField.Length, value, ErrMsg
                                      value = Replace(value, UNDERSCORE, EMPTY_STRING)
                                      'if InStr(value, PERIOD) > 0 then
                                      if value = PERIOD then
                                                      vField.Value = ZERO_DOLLARS
                                      else
                                                      vField.Value = trim(value)
                                      end if
                      end sub
       
                      public sub Class_Terminate()
                                      set oFields = nothing
                      end sub
      end class
       
      class Otdp
                      private oFields
                      private curDeliquncyFee
                      private oErrors
       
                      public sub Class_Initialize()
                                      curDeliquncyFee = CCur(15.00)
                                      set oErrors = CreateObject("Scripting.Dictionary")
                      end sub
       
                      public sub Init(vFields)
                                      set oFields = vFields
                      end sub
       
                      property get ValidStopCode
                                      dim ProcessStop
                                      ProcessStop = Left(oFields.List.Item(LN_PROCESS_STOP_CD).Value,1)
                                      ValidStopCode = InStr("04CEHMOU", ProcessStop) > 0
                      end property
       
                      property get HasBalance
                                      dim PrincipalBalance
                                      PrincipalBalance = CDbl(oFields.List.Item(LN_1ST_PRIN_BA).Value)
                                      HasBalance = PrincipalBalance > 0
                      end property
       
                      property get DelinquentBy(days)
                                      DelinquentBy = days < DaysDelinquent
                      end property
       
                      property get DaysDelinquent
                                      dim Today, Delinquent, DueDate
                                      Today = Date
                                      DueDate = oFields.List.Item(LN_NXT_PMT_DUE_DT).Value
                                      Delinquent = DateDiff("d", DueDate, Today)
                                      DaysDelinquent = Delinquent
                                      'IMPORTANT remove the next line before full testing and production release
                                      'DaysDelinquent = 0
                      end property
       
                      property get IsMature
                                      dim Today, PartialMaturityDate, FullMaturityDate
                                      Today = Date
                                      PartialMaturityDate = oFields.List.Item(OG_LOAN_MAT_DT).Value
                                      FullMaturityDate = DateSerial(Year(PartialMaturityDate),Month(PartialMaturityDate),Day(PartialMaturityDate))
                                      IsMature = Today > FullMaturityDate
                      end property
       
                      property get HasEscrow
                                      dim Escrow
                                      Escrow = oFields.List.Item(ESCROW_PAYMENT).Value
                                      HasEscrow = Escrow > 0
                      end property
       
                      property get Valid
                                      dim pvtHasBalance, pvtMature, pvtTooDelinquent, pvtValidStopCode
       
                                      oErrors.RemoveAll
       
                                      pvtHasBalance = HasBalance
                                      pvtMature = IsMature
                                      pvtTooDelinquent = DelinquentBy(46)
                                      pvtValidStopCode = ValidStopCode
       
                                      if not pvtValidStopCode then
                                                      if not oErrors.Exists("ProcessStopError") then
                                                                      oErrors.Add "ProcessStopError", "Loan has a invalid ProcessStop of " & oFields.List.Item(LN_PROCESS_STOP_CD).Value & "."
                                                      end if
                                      end if
       
                                      if pvtTooDelinquent then            
                                                      if not oErrors.Exists("DelinquentError") then
                                                                      oErrors.Add "DelinquentError", "Loan is " & DaysDelinquent & " days delinquent."
                                                      end if
                                      end if
       
                                      if pvtMature then
                                                      if not oErrors.Exists("MaturityError") then
                                                                      oErrors.Add "MaturityError", "Loan Maturity date is " & oFields.List.Item(OG_LOAN_MAT_DT).Value & "."
                                                      end if
                                      end if
       
                                      if not pvtHasBalance then
                                                      if not oErrors.Exists("BalanceError") then
                                                                      oErrors.Add "BalanceError", "Loan has a balance of " & oFields.List.Item(LN_1ST_PRIN_BA).Value & "."
                                                      end if
                                      end if
       
                                      Valid = pvtValidStopCode and pvtHasBalance and (not pvtTooDelinquent) and (not pvtMature)
                      end property
       
                      public function ErrToString()
                                      dim key, output
                                      for each key in oErrors.Keys
                                                      output = output & vbCr & vbLf & oErrors.Item(key)
                                      next
                                      ErrToString = output
                      end function
       
                      public sub Class_Terminate()
                                      set oErrors = nothing
                      end sub
      end class
       
      Class OneTimeDraftPaymentForm
        private oFields
        private Dialog
        private btnPanelId
       
        public sub Class_Initialize()
          set oFields = CreateObject("Scripting.Dictionary")
        end sub
       
        public function Show(fields, loanNumber, showEscrow)
          dim vOffset, mode
          set oFields = fields
          vOffset = 40
       
          set Dialog = CreateObject("MstrComponent.PaneledWindow")
       
          Dialog.Title = "One Time Draft Payment - " & loanNumber
          Dialog.Layout = 4
          Dialog.Width = 750
       
                      dim key, fld
       
                      AddTextField CURRENT_DATE, 0, "Date", Date, 35, 0, 0, 140, 50
                      AddComboBox LN_ACTION, "Action", "A", 1, 45, 140, 0, 100, 50
                      AddFeeField LN_AMOUNT, 10, "Amount", EMPTY_STRING, 40, 235, 0, 140, 50
                      AddComboBox LN_PAYMENTS,"Payments", "0|1|2|3|4|5|6|7|8|9", 1, 50, 375, 0, 140, 50
                      AddComboBox LN_OVERRIDES,"Overrides", "3", 1, 45, 595, 0, 140, 50
                      AddTextField ROUTING_NUMBER, 9, EMPTY_STRING, EMPTY_STRING, 42, 0, vOffset * 1, 180, 50
                      AddTextField ACCOUNT_NUMBER, 17, EMPTY_STRING, EMPTY_STRING, 36, 180, vOffset * 1, 210, 50
                      AddTextField ACCOUNT_NAME, 22,  "Name", EMPTY_STRING, 30, 380, vOffset * 1, 250, 50 'name
                      AddTextField MORT_BILL_NAME, 22,  "Requestor", EMPTY_STRING, 30, 380, vOffset * 2, 250, 50 'requestor
                      AddTextField ACCOUNT_TYPE, 1, EMPTY_STRING, EMPTY_STRING, 42, 0, vOffset * 2, 180, 50
                      AddTextField LN_TELEPHONE_NO, 20, "Phone #", EMPTY_STRING, 42, 180, vOffset * 2, 180, 50
                      AddFeeField LN_CURTAILMENT, 10, "Curtailment", ZERO_DOLLARS, 50, 0, vOffset * 4, 140, 50
                      if showEscrow then
                                      AddFeeField LN_ADD_ESCROW, 9, "Addl Escrow", ZERO_DOLLARS, 50, 0, vOffset * 5, 140, 50
                      end if
                      AddFeeField LN_SUSPENSE, 10, "Suspense", ZERO_DOLLARS, 50, 0, vOffset * 6, 140, 50
                      AddComboBox LN_SUSPENSE_CODE, "Code", SUSPENSE_CODES, 1, 28, 130, vOffset * 6, 225, 50
       
                      ' only show the delinquency field if there is a dollar amount already present
                      if GetValue(DELINQUENCY_FEE) > 0 then
                                      AddFeeField DELINQUENCY_FEE, 8, EMPTY_STRING, ZERO_DOLLARS, 50, 0, vOffset * 7, 140, 50
                      end if
       
                      AddComboBox ADDL_FEES, "Addl Fees", "Y - Additional Fees|N - No Additional Fees", 1, 28, 140, vOffset * 7, 225, 50
                      AddFeeField LN_FEE, 9, EMPTY_STRING, ZERO_DOLLARS, 50, 350, vOffset * 4, 135, 50
                      AddComboBox LN_FEE_CODE, EMPTY_STRING, PAYMENT_CODES, 1, 28, 480, vOffset * 4, 225, 50
       
                      if GetValue(LN_ADD_FEE_1) > 0 then
                                      AddFeeField LN_ADD_FEE_1, 9, EMPTY_STRING, ZERO_DOLLARS, 50, 350, vOffset * 5, 135, 50
                                      AddComboBox LN_ADD_FEE_1_CODE, EMPTY_STRING, PAYMENT_CODES, 1, 28, 480, vOffset * 5, 225, 50
                      end if
       
                      if GetValue(LN_ADD_FEE_2) > 0 then
                                      AddFeeField LN_ADD_FEE_2, 9, EMPTY_STRING, ZERO_DOLLARS, 50, 350, vOffset * 6, 135, 50
                                      AddComboBox LN_ADD_FEE_2_CODE, EMPTY_STRING, PAYMENT_CODES, 1, 28, 480, vOffset * 6, 225, 50
                      end if
       
                      if GetValue(LN_ADD_FEE_3) > 0 then
                                      AddFeeField LN_ADD_FEE_3, 9, EMPTY_STRING, ZERO_DOLLARS,50, 350, vOffset * 7, 135, 50
                                      AddComboBox LN_ADD_FEE_3_CODE, EMPTY_STRING, PAYMENT_CODES, 1, 28, 480, vOffset * 7, 225, 50
                      end if
       
                      if GetValue(LN_CORP_ADV_PAYEE) <> "" then
                                      AddTextField LN_CORP_ADV_PAYEE, 5, EMPTY_STRING, EMPTY_STRING, 42, 350, vOffset * 8, 180, 50
                      end if
       
                      if GetValue(LN_CORP_ADV_REASON) <> "" then
                                      AddTextField LN_CORP_ADV_REASON, 4, EMPTY_STRING, EMPTY_STRING, 42, 350, vOffset * 9, 180, 50
                      end if
       
                      dim lcaa
                      if GetValue(LN_CORP_ADV_AMT) > 0 then
                                      AddFeeField LN_CORP_ADV_AMT, 9, EMPTY_STRING, ZERO_DOLLARS, 42, 480, vOffset * 10, 180, 50
                      end if
       
                      AddPhoneInstruction LN_TELEPHONE_NO
       
          btnPanelId = Dialog.AddPanel(9)
          Dialog.AddItems btnPanelId, "&OK|&Cancel"
          Dialog.SetPanelBounds btnPanelId, 580, vOffset * 11, 170, 50
          Dialog.SetDefault btnPanelId, 1
       
          mode = Dialog.ShowWindow
                      if mode = 1 then ' 1 is Ok
                                      LoadFields
                      end if
          Show = mode
        end function
       
        private sub AddPhoneInstruction(key)
                      dim fld
                      set fld = oFields.List.Item(key)
                      Dialog.CustomInstruction  fld.Handle, 0, "PhoneNumber", True
        end sub
       
        private sub AddTextField(key, maxColumns, label, default_value, vdivider, top, left, width, height)
          dim pnl, fld
                      set fld = oFields.List.Item(key)
      '               AddTextField REQUESTOR, 22,  "Requestor", EMPTY_STRING, 30, 380, vOffset * 2, 250, 50 'requestor
       
                      ' check parameters and set defaults if they are Empty String
                      if label = EMPTY_STRING then
                                      label = fld.Label
                      end if
       
                      if default_value = EMPTY_STRING then
                          'Added functionality 6-25-09 to trim long names if greater than 22 characters
                                      if key = "ACCOUNT_NAME" or key = "MORT_BILL_NAME" then
                                                      default_value = leftb(fld.Value,44)
                                      else
                                                      default_value = fld.Value
                                      end if
                      end if
       
                      pnl = Dialog.AddPanel(7)
                      Dialog.SetColumns pnl, maxColumns
          Dialog.AddMessage pnl, label
          Dialog.AddItems pnl, Trim(default_value)
          Dialog.MoveVertDivider pnl, vdivider
          Dialog.SetPanelBounds pnl, top, left, width, height
                      fld.Handle = pnl
        end sub
       
        private sub AddFeeField(key, maxColumns, label, default_value, vdivider, top, left, width, height)
          dim pnl, fld
                      set fld = oFields.List.Item(key)
       
                      ' check parameters and set defaults if they are Empty String
                      if label = EMPTY_STRING then
                                      label = fld.Label
                      end if
       
                      if default_value = ZERO_DOLLARS then
                                      default_value = fld.Value
                      end if
       
                      pnl = Dialog.AddPanel(7)
                      Dialog.SetColumns pnl, maxColumns
          Dialog.AddMessage pnl, label
                      if default_value = "" then
                                      default_value = ZERO_DOLLARS
                      end if
          Dialog.AddItems pnl, CCur(default_value)
          Dialog.MoveVertDivider pnl, vdivider
          Dialog.SetPanelBounds pnl, top, left, width, height
                      Dialog.CustomInstruction  pnl, 0, "Currency", True
                      fld.Handle = pnl
        end sub
       
        private sub AddComboBox(key, label, items, default_item, vdivider, top, left, width, height)
          dim pnl, fld
                      set fld = oFields.List.Item(key)
       
                      ' check parameters and set defaults if they are Empty String
                      if label = EMPTY_STRING then
                                      label = fld.Label
                      end if
       
                      ' Loop through the items [delimeted string]
                      if fld.Value <> EMPTY_STRING then
                                      dim list_items, list_keys, item_key, item, index
                                      index = 1
                                      list_items = split(items,"|")
                                      for each item in list_items
                                                      item_key = trim(split(item, "-")(0))
                                                      if item_key = fld.Value then
                                                                      default_item = index
                                                      end if
                                                      index = index + 1
                                      next
                      end if
       
                      pnl = Dialog.AddPanel(3)
          Dialog.AddMessage pnl, label
          Dialog.AddItems pnl, items
          Dialog.MoveVertDivider pnl, vdivider
          Dialog.SetPanelBounds pnl, top, left, width, height
                      Dialog.SetDefault pnl, default_item
                      fld.Handle = pnl
        end sub
       
        private function GetValue(key)
          dim pnl, fld
                      set fld = oFields.List.Item(key)
                      GetValue = fld.value
        end function
       
        private sub LoadFields()
                      dim key
                      for each key in oFields.List.Keys
                                      dim fld, oldValue
                                      set fld = oFields.List.Item(key)
                                      oldValue = fld.Value
                                      if fld.Handle > 0 then
                                                      if fld.Tag = REQ_STRIP then
                                                                      fld.Value = CodeSplit(Dialog.GetText(fld.Handle))
                                                      else
                                                          fld.Value = Dialog.GetText(fld.Handle)
                                                      end if
                                      end if
                                      'msgbox fld.Key & ": " & oldValue & ", " & fld.Value
                      next
        end sub
       
        private function CodeSplit(delimText)
                      dim items
                      items = split(delimText, "-")
                      if ubound(items) > 0 then
                                      CodeSplit = trim(items(0))
                      else
                          CodeSplit = ""
                      end if
        end function
       
        private function CleanCurrency(value)
                      if InStr(value, "_") > 0 then
                                      value = 0
                      end if
                      CleanCurrency = value
        end function
       
        private function CleanString(value)
                      if InStr(value, "_") > 0 then
                                      value = ""
                      end if
                      CleanString = value
        end function
       
        property get Fields
          set Fields = oFields
        end property
       
        property get UserCancelled
                      UserCancelled = Cancelled
        end property
       
        public sub Class_Terminate()
          set Dialog = nothing
          set oFields = nothing
        end sub
      end class
       
      '******************************************************************************
      ' config section
      '******************************************************************************
      dim taskId, employeeName, employeeId
       
      taskId = "CUS016"
      employeeName = "Obon McIntyre"
      employeeId = "OBM"
       
       
      '******************************************************************************
      ' Start script
      '******************************************************************************
       
      dim oDirector, o3270, oTool, oLoader, oFields, oForm, oScrapedFields, oOTDP
      dim oOTDPscraper, oAdditionalFields, oCrossFooter, oSaver, oTasker, oScreenManager
      dim name, ErrMsg, expectedFieldCount, mode, total_payment
       
      set oDirector = CreateObject("atlDirectorObject.atlDirector")
      name = "Payment Drafting"
      expectedFieldCount = 9
       
      set oAdditionalFields = new Fields
      oAdditionalFields.Add CURRENT_DATE, Date, "CurrentDate", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_ACTION, EMPTY_STRING, "Action", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_AMOUNT, 0, "Amount", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_PAYMENTS, EMPTY_STRING, "Payments", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_OVERRIDES, EMPTY_STRING, "Overrides", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_CURTAILMENT, 0, "Curtailment", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_ADD_ESCROW, 0, "AdditionalEscrow", 0, 0, EMPTY_STRING, 0,0,0,0
      oAdditionalFields.Add LN_SUSPENSE, 0, "Suspense", 0, 0, "", 0,0,0,0
      oAdditionalFields.Add LN_SUSPENSE_CODE, EMPTY_STRING, "SuspenseCode", 0, 0, REQ_STRIP, 0,0,0,0
      oAdditionalFields.Add ACCOUNT_NAME, EMPTY_STRING, ACCOUNT_NAME_CAPTION, 0, 0, EMPTY_STRING, 0,0,0,0
       
       
      ' Set up the Director tools
      if (oDirector.CreateTool("3270", 0, TRUE, False, 0, o3270, ErrMsg) = 0) then
                      set oScreenManager = new ScreenManager
                      oScreenManager.Load o3270, oDirector.LoanNo
                      if (oDirector.CreateTool("Snapshot", 1, False, False, 0, oTool, ErrMsg) = 0) then
                                      ' create a loader to load the snapshot data into the fields class
                                      set oLoader = new SnapShotLoader
                                      set oFields = oLoader.Load(oDirector, oTool, name)
                                      'msgbox oLoader.ToString() 'debug statement used to view the xml string
                                      ' if we got the expected number of fields then we can load the fields data into the OTDP so we can
                                      ' check some specific data for business rules
       
                                      if oFields.List.Count = expectedFieldCount then
                                                      set oOTDP = new Otdp
                                                      oOTDP.Init oFields ' OTDP contains business rules so we load the fields into it.
                                                      if oOTDP.Valid then
                                                                      ' we have a valid loan so we need to scrap some data from the 3270
                                                                      set oOTDPscraper = new OtdpScraper
                                                                      set oScrapedFields = oOTDPscraper.Load(o3270, oDirector.LoanNo, oScreenManager)
                                                                      ' now we combined the original snap shot fields with the screen scraped fields
                                                                      oFields.Append(oScrapedFields)
                                                                      oFields.Append(oAdditionalFields)
                                      oFields.List.Item(ACCOUNT_NAME).Value() = oFields.List.Item(MORT_BILL_NAME).Value() 'Prefil account name
                                                                      set oForm = new OneTimeDraftPaymentForm
                                                                      mode = oForm.Show(oFields, oDirector.LoanNo, oOTDP.HasEscrow)
                                                                      if mode = OK then
                                                                                      'MsgBox "Modified results:" & vbCr & vbLf & oFields.ToString(), vbOKonly + vbInformation, "User Edited Results"
                                                                                      set oCrossFooter = new CrossFooter
                                                                                      total_payment = oCrossFooter.Total(oFields)
                                                                                      dim retval
                                                                                      retval = MsgBox("Post Payment in the amount of " + cstr(total_payment) + "?", vbYesNo + vbDefaultButton2 + vbQuestion + vbApplicationModal, SCRIPT_TITLE)
                                                                                      if retval = vbYes then
                                                                                                      oFields.List.Item(LN_AMOUNT).Value = total_payment
                                                                                                      set oSaver = new OtdpSaver
                                                                                                      if oSaver.DateIsValid(o3270, oFields, oScreenManager) then
                                                                                                                      if oSaver.Save(o3270, oFields, oScreenManager) then
                                                                                                                                      MsgBox "Draft Header Added.", vbOKonly + vbInformation, "Script Completed"
                                                                                                                      else
                                                                                                                                      oSaver.CancelTransaction o3270, oFields, oScreenManager
                                                                                                                                      MsgBox "The payment was not posted correctly." & vbCr & vbLf &  vbCr & vbLf & oSaver.Errors(), vbOKonly + vbCritical, "Script Error"
                                                                                                                      end if
                                                                                                      else
                                                                                                                      oSaver.CancelTransaction o3270, oFields, oScreenManager
                                                                                                                      MsgBox "The posting date is either a holiday or weekend." & vbCr & vbLf &  vbCr & vbLf & oSaver.Errors(), vbOKonly + vbCritical, "Script Error"
                                                                                                      end if
                                                                                      else
                                                                                                      MsgBox "User has cancelled the script.", vbOKonly + vbInformation, "Script Cancelled"
                                                                                      end if
                                                                      else
                                                                                      MsgBox "User has cancelled the script.", vbOKonly + vbInformation, "Script Cancelled"
                                                                      end if
                                                      else
                                                                      ' this is not a valid loan we are try to process
                                                                      if oOTDP.IsMature then
                                                                                      set oTasker = new OtdpTasker
                                                                                      oTasker.CreateTask o3270, taskId, employeeId, employeeName
                                                                                      msgbox "This loan is past its maturity date. A " & taskId & _
                                                                                                                      " task has been assigned to '" & employeeName & "'.", vbOKonly + vbInformation, SCRIPT_TITLE
                                                                      else
                                                                      msgbox "This loan can not recieve deposits for the following reasons: " _
                                                                      & vbLf & vbCr & oOTDP.ErrToString() , vbOKonly + vbInformation, VALIDATE_ERROR_TITLE
                                                                      end if
                                                      end if
                                                      oScreenManager.Reset()
                                      else
                                                      msgbox "Snapshot Loader did not load correctly for snapshot '" & name & "'.", vbOKonly + vbCritical, SCRIPT_ERROR_TITLE
                                      end if
                      else
                                      msgbox "Failed to create snapshot '" & name & "'.", vbOKonly + vbCritical, SCRIPT_ERROR_TITLE
                      end if
      else
                      msgbox "Failed to create 3270.", vbOKonly + vbCritical, SCRIPT_ERROR_TITLE
      end if
       
      set oDirector = nothing
      set o3270 = nothing
      set oTool = nothing
      set oLoader = nothing
      set oFields = nothing
      set oScrapedFields = nothing
      set oCrossFooter = nothing
      set oSaver = nothing
      set oScreenManager = nothing
       
       
       


       
      #3
        59cobalt

        • Total Posts : 2625
        • Scores: 253
        • Reward points : 0
        • Joined: 7/17/2011
        • Status: offline
        Re:VBS SCRIPT DEFINITION Tuesday, March 21, 2017 11:44 AM (permalink)
        0
        3000 lines? Seriously? You do realize that there's a middle ground between "no context at all" and "full 3000-line script", don't you?
         
        #4
          mcbritt60

          • Total Posts : 4
          • Scores: 0
          • Reward points : 0
          • Joined: 3/20/2017
          • Status: offline
          Re:VBS SCRIPT DEFINITION Tuesday, March 21, 2017 11:52 PM (permalink)
          0
          This was created by someone long before me and I'm stuck with it to create the form and permit the input of data.
          Still trying to figure out why a user can't post a date greater than current date and how to fix it.
           
          #5
            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2017 ASPPlayground.NET Forum Version 3.9