Вы находитесь на странице: 1из 10

Option Strict Off

Option Explicit On
Module Module1
Const LedesHeader As String = "LEDES1998B[]INVOICE_DATE|INVOICE_NUMBER|
CLIENT_ID|LAW_FIRM_MATTER_ID|INVOICE_TOTAL|BILLING_START_DATE|BILLING_END_DATE|
INVOICE_DESCRIPTION|LINE_ITEM_NUMBER|EXP/FEE/INV_ADJ_TYPE|
LINE_ITEM_NUMBER_OF_UNITS|LINE_ITEM_ADJUSTMENT_AMOUNT|LINE_ITEM_TOTAL|
LINE_ITEM_DATE|LINE_ITEM_TASK_CODE|LINE_ITEM_EXPENSE_CODE|LINE_ITEM_ACTIVITY_CODE|
TIMEKEEPER_ID|LINE_ITEM_DESCRIPTION|LAW_FIRM_ID|LINE_ITEM_UNIT_COST|
TIMEKEEPER_NAME|TIMEKEEPER_CLASSIFICATION|CLIENT_MATTER_ID[]"

Structure ledes_type
Dim InvoiceDate As String
Dim InvoiceNumber As String
Dim ClientID As String
Dim LawFirmMatterID As String
Dim InvoiceTotal As String
Dim BillingStartDate As String
Dim BillingEndDate As String
Dim InvoiceDescription As String
Dim LineItemNumber As String
Dim FeeAdjustmentCode As String
Dim LineItemNumberOfUnits As String
Dim LineItemAdjustmentAmount As String
Dim LineItemTotal As String
Dim LineItemDate As String
Dim LineItemTaskCode As String
Dim LineItemExpenseCode As String
Dim LineItemActivityCode As String
Dim TimekeeperID As String
Dim LineItemDescription As String
Dim LawFirmID As String
Dim LineItemUnitCost As String
Dim TimekeeperName As String
Dim TimekeeperClassification As String
Dim ClientMatterID As String
End Structure

Structure HeaderType
Dim ClientName As String
Dim InvoiceDate As String
Dim InvoiceNumber As String
Dim ClientCaseNum As String
Dim CM3ID As String
Dim ClientCaseSubject As String
End Structure

Dim LedesRecords(10000) As ledes_type


Dim NumRecords As Short
Dim fileBuf(10000) As String
Dim CurHeader As HeaderType
Dim strBeginDate As String
Dim strEndDate As String
Dim IntTotal As Double
Dim intLineTotal As Double
Dim strClient As String
Dim strExpenseCode As String
Dim intUnitCost As Double
Public Function TestLine(ByRef whichone As Short) As Short
Dim b As String
Dim a As String

a = fileBuf(whichone)

b = Trim(a)

If Len(a) > 6 Then


If Mid(a, 6, 1) = "(" Then
TestLine = 0
Exit Function
End If
End If

' *** SUMMARY OF CHARGES *** -- end of file indicator


If InStr(1, b, "*** SUMMARY OF CHARGES ***", CompareMethod.Binary) = 1
Then
TestLine = 4
Exit Function
End If

' Balance Due line


If InStr(1, b, "Balance Due for This Case", CompareMethod.Binary) = 1
Then
TestLine = 0
Exit Function
End If

' Total line


If InStr(1, b, "Total Current Services and Fees", CompareMethod.Binary)
= 1 Then
TestLine = 0
Exit Function
End If

' subtotal line


If LCase(Left(b, 8)) = "subtotal" Then
TestLine = 0
Exit Function
End If

' dashed lines after totals


If Left(b, 4) = "----" Then
TestLine = 0
Exit Function
End If

' dashed lines after grand total


If Left(b, 4) = "====" Then
TestLine = 0
Exit Function
End If

' summation charge lines


If Left(b, 1) = "$" Then
TestLine = 0
Exit Function
End If

' TERMS lines


If Left(b, 5) = "TERMS" Then
TestLine = 0
Exit Function
End If

' test for at page header line


If Len(a) > 77 Then
b = Left(a, 77)
If b = "
Page: " Then
' at page header.
TestLine = 1
Exit Function
End If
End If

'Should stop here


If Len(a) > 12 Then
If Left(a, 1) <> " " Then
If Mid(a, 3, 1) = "/" Then
' charge record with a date header
TestLine = 2
Exit Function
End If
End If
End If

If Len(a) > 12 Then


If Mid(a, 9, 1) = " " Then
If Mid(a, 13, 1) = " " Then
If Mid(a, 10, 1) <> " " Then
If Mid(a, 11, 1) <> " " Then
If Mid(a, 12, 1) <> " " Then
' charge record without a date
header
TestLine = 3
Exit Function
End If
End If
End If
End If
End If
End If

TestLine = 0
End Function

Public Sub Read_Tabs_File()


Dim a3 As String
Dim a7 As String
Dim a2 As String
Dim a1 As String
Dim a6 As String
Dim a5 As String
Dim a4 As String
Dim c As String
Dim a As String
Dim NumLines As Short
Dim Y As Short
Dim X As Short
Dim z As Short

z = 0
X = FreeFile()
NumRecords = 0
NumLines = 1
Dim strFileName As String
strFileName = Form1.DefInstance.txtBill.Text

FileOpen(X, strFileName, OpenMode.Input)


While Not EOF(X)
If NumLines = 10000 Then
MsgBox("Error: Statement too long. 10,000 lines max.")
End
End If
fileBuf(NumLines) = LineInput(X)
NumLines = NumLines + 1
End While
FileClose(X)

' loop through lines, removing any printer control chars

For Y = 1 To NumLines
If fileBuf(Y) <> "" Then
If Asc(Left(fileBuf(Y), 1)) = 12 Then
fileBuf(Y) = Right(fileBuf(Y), Len(fileBuf(Y)) - 1)
End If
End If
Next Y

Dim charge As Short


Static last_charge_date As String
For Y = 1 To NumLines
If Trim(fileBuf(Y)) <> "" Then
' we have text. Is this a charge line, header info or misc junk?
Select Case TestLine(Y)
Case 0 ' misc junk
' skip it
Case 1 'header
a = fileBuf(Y + 1)
a = Trim(Left(a, 50))
CurHeader.ClientName = a
' get this and next 5 lines lines, fill in header structure

' line 1, 55: statement date (preceding blank characters)


a = fileBuf(Y + 1)
If Len(a) < 56 Then
MsgBox("Error processing header field 1. Line #" &
Trim(Str(Y + 1)))
End
End If
c = Trim(Right(a, Len(a) - 55))
CurHeader.InvoiceDate = VB6.Format(c, "YYYYMMDD")
' line 2, 46: client case id number, Client-Case ID No.:
718060-5002A
a = fileBuf(Y + 2)
If Len(a) < 66 Then
MsgBox("Error processing header field 2. Line #" &
Trim(Str(Y + 2)))
End
End If
CurHeader.ClientCaseNum = Trim(Right(a, Len(a) - 65))

' line 3, 43: invoice number Statement/Invoice No.:


177156
a = fileBuf(Y + 3)
If Len(a) < 56 Then
Exit For
End If
CurHeader.InvoiceNumber = Trim(Right(a, Len(a) - 65))

' variable number of blank lines


For X = Y + 4 To NumLines
If Trim(fileBuf(X)) <> "" Then
Exit For
End If
Next X

' line 4+: client name


a = fileBuf(X + 5)
CurHeader.ClientCaseSubject = Trim(a)

' line 5+: cm3 number


a = fileBuf(X + 6)
If Form1.DefInstance.txtHolder.Text = "" Then
CurHeader.CM3ID = Trim(Left(Trim(a), 10))
strClient = CurHeader.CM3ID
Form1.DefInstance.txtHolder.Text = strClient
End If

' line 5+: cm3 number


a = fileBuf(X + 8)
If Form1.DefInstance.txtMatter.Text = "" Then
Form1.DefInstance.txtMatter.Text = Trim(Left(Trim(a),
15))
End If

' update loop counter


Y = X + 1

Case 2, 3 ' charge


' get this and any remaining lines; assemble into charge
structure
' send charge structure to ledes outputter

charge = 0
a4 = ""
a5 = ""
a6 = ""
For X = Y To NumLines
a = fileBuf(X)
If charge = 0 Then
NumRecords = NumRecords + 1
a1 = Trim(Left(a, 9))
If a1 = "" Then
If last_charge_date = "" Then
MsgBox("Bad charge records.")
End
End If
a1 = last_charge_date
Else
c = a1
a1 = VB6.Format(c, "YYYYMMDD")
last_charge_date = a1
End If
a2 = Mid(a, 10, 4)
a7 = Mid(a, 14, 2)
'a7$ = Trim$(Right$(a$, 1))
a3 = Mid(a, 16, 33)
charge = 1
Else
If charge = 1 Then
a3 = a3 & " " & Mid(a, 14, 35)
End If
End If
If Len(a) > 68 Then
a4 = Mid(a, 49, 12)
a5 = Mid(a, 61, 8)
a6 = Right(a, Len(a) - 68)
charge = 2
Exit For
End If
Next X

If charge <> 2 Then


MsgBox("Bad exit from charge data collection loop.")
End
End If
a1 = Trim(a1)
a2 = Trim(a2)
a3 = Trim(a3)
a4 = Trim(a4)
a5 = Trim(a5)
a6 = Trim(a6)
a7 = Trim(a7)

System.Diagnostics.Debug.WriteLine("CHARGE: " & a1 & " " &


a2 & " " & a3 & " " & a4 & " " & a5 & " " & a6)

'Convert the line item amount from 1,200 to 1200 format


intLineTotal = CDbl(a6)
a6 = CStr(intLineTotal)

'Convert the unit cost from 1,200 to 1200 format

If a4 <> "" Then


intUnitCost = CDbl(a4)
a4 = CStr(intUnitCost)
End If
Add_ledes_charge(a1, a2, a3, a4, a5, a6, a7)

Case 4
' it's all over
Exit For
Case Else
' shouldn't happen
MsgBox("Error handling return value from TestLine
function.")
End
End Select
End If
z = z + 1
Form1.DefInstance.Label1.Text = CStr(z)
Next Y

End Sub

Public Sub Add_ledes_charge(ByRef a1 As String, ByRef a2 As String, ByRef a3 As


String, ByRef a4 As String, ByRef a5 As String, ByRef a6 As String, ByRef a7 As
String)

Static lineNum As Short

lineNum = lineNum + 1

LedesRecords(NumRecords).InvoiceDate = CurHeader.InvoiceDate
LedesRecords(NumRecords).InvoiceNumber = CurHeader.InvoiceNumber
LedesRecords(NumRecords).ClientID = Form1.DefInstance.txtHolder.Text
LedesRecords(NumRecords).LawFirmMatterID = CurHeader.ClientCaseNum
LedesRecords(NumRecords).BillingStartDate = Form1.DefInstance.txtBegin.Text
LedesRecords(NumRecords).BillingEndDate = Form1.DefInstance.txtEnd.Text
LedesRecords(NumRecords).InvoiceDescription = CurHeader.ClientCaseSubject
LedesRecords(NumRecords).LineItemNumber = CStr(lineNum)
LedesRecords(NumRecords).FeeAdjustmentCode = a7
LedesRecords(NumRecords).LineItemNumberOfUnits = a5
If a7 = "E" Then GoTo AdjustmentNotExists
If a7 = "e" Then GoTo AdjustmentNotExists
If a7 = "f" Then GoTo AdjustmentNotExists
If a7 = "F" Then GoTo AdjustmentNotExists
LedesRecords(NumRecords).LineItemAdjustmentAmount = a6
GoTo AdjustmentExists

AdjustmentNotExists:
LedesRecords(NumRecords).LineItemAdjustmentAmount = ""
GoTo ByPassAdjustment

AdjustmentExists:
If a5 = "" Then
a5 = "0"
a4 = "0"
End If
intLineTotal = CDbl(a6)
a6 = CStr(intLineTotal)
If IntTotal <> 0 Then
IntTotal = IntTotal + CDbl(a6)
End If
If IntTotal = 0 Then
IntTotal = CDbl(a6)
End If
LedesRecords(NumRecords).LineItemNumberOfUnits = a5
LedesRecords(NumRecords).InvoiceTotal = CStr(IntTotal)

ByPassAdjustment:
LedesRecords(NumRecords).LineItemTotal = a6
LedesRecords(NumRecords).LineItemDate = a1
LedesRecords(NumRecords).LineItemTaskCode = ""
If a7 <> "F" Then
If a7 = "f" Then GoTo ByPassExpenseCode
If a7 = "IF" Then GoTo ByPassExpenseCode
If a7 = "if" Then GoTo ByPassExpenseCode
ExpenseCode.DefInstance.Show()

EnterExpense:
If a5 = "" Then
a5 = CStr(1)
a4 = a6
End If
intLineTotal = CDbl(a6)
a6 = CStr(intLineTotal)
If IntTotal <> 0 Then
IntTotal = IntTotal + CDbl(a6)
End If
If IntTotal = 0 Then
IntTotal = CDbl(a6)
End If
LedesRecords(NumRecords).LineItemNumberOfUnits = a5
LedesRecords(NumRecords).InvoiceTotal = CStr(IntTotal)

strExpenseCode = InputBox("Found the following expense item: " & a3


& ".... Please enter the appropriate expense code from the list", "Expense Code
Selection")
If Len(strExpenseCode) > 4 Then
MsgBox("Expense Code must be entered using the four digit Exxx code
only", MsgBoxStyle.OKOnly)
GoTo EnterExpense
End If
If Len(strExpenseCode) < 4 Then
MsgBox("Expense Code must be entered using the four digit Exxx code
only", MsgBoxStyle.OKOnly)
GoTo EnterExpense
End If
ExpenseCode.DefInstance.Hide()
GoTo ByPassExpenseCode

End If

IntTotal = IntTotal + CDbl(a6)


LedesRecords(NumRecords).InvoiceTotal = CStr(IntTotal)

ByPassExpenseCode:
LedesRecords(NumRecords).LineItemExpenseCode = strExpenseCode
LedesRecords(NumRecords).LineItemActivityCode = ""
LedesRecords(NumRecords).TimekeeperID = a2
LedesRecords(NumRecords).LineItemDescription = a3
'LawFirmID to be changed according to actual ID of LawFirm doing
submissions
LedesRecords(NumRecords).LawFirmID = "123456789"
LedesRecords(NumRecords).LineItemUnitCost = a4

'The XXX_NAME should be replaced with the time keeper initials


'The TimekeeperName should be popultated with the full legal name of the
time keeper
'Possible values for TimekeeperClassification = PT (Partner), OT (Other),
LA (Legal Assistant)

If a2 = "XXX_NAME" Then
LedesRecords(NumRecords).TimekeeperName = "LastName, FirstName"
LedesRecords(NumRecords).TimekeeperClassification = "PT"
End If

LedesRecords(NumRecords).ClientMatterID = Form1.DefInstance.txtMatter.Text

End Sub

Public Sub Write_LEDES_File()


Dim Y As Object
Dim X As Short
Dim strFileName As String

Form1.DefInstance.txtFile.Text = CurHeader.InvoiceNumber
strFileName = "L:\LEDES\" & CurHeader.InvoiceNumber & ".txt"
Y = FreeFile()

FileOpen(Y, strFileName, OpenMode.Output)


PrintLine(Y, LedesHeader & Chr(13) & Chr(10))
For X = 1 To NumRecords
PrintLine(Y, LedesDataFormat(X))
Next X
FileClose(Y)

End Sub

Public Function LedesDataFormat(ByRef which As Short) As Object


Dim a As String

Dim crlf As String


crlf = Chr(13) & Chr(10)

a = ""
a = a & LedesRecords(which).InvoiceDate & "|"
a = a & LedesRecords(which).InvoiceNumber & "|"
a = a & LedesRecords(which).ClientID & "|"
a = a & LedesRecords(which).LawFirmMatterID & "|"
a = a & IntTotal & "|"
a = a & LedesRecords(which).BillingStartDate & "|"
a = a & LedesRecords(which).BillingEndDate & "|"
a = a & LedesRecords(which).InvoiceDescription & "|"
a = a & LedesRecords(which).LineItemNumber & "|"
a = a & LedesRecords(which).FeeAdjustmentCode & "|"
a = a & LedesRecords(which).LineItemNumberOfUnits & "|"
a = a & LedesRecords(which).LineItemAdjustmentAmount & "|"
a = a & LedesRecords(which).LineItemTotal & "|"
a = a & LedesRecords(which).LineItemDate & "|"
a = a & LedesRecords(which).LineItemTaskCode & "|"
a = a & LedesRecords(which).LineItemExpenseCode & "|"
a = a & LedesRecords(which).LineItemActivityCode & "|"
a = a & LedesRecords(which).TimekeeperID & "|"
a = a & LedesRecords(which).LineItemDescription & "|"
a = a & LedesRecords(which).LawFirmID & "|"
a = a & LedesRecords(which).LineItemUnitCost & "|"
a = a & LedesRecords(which).TimekeeperName & "|"
a = a & LedesRecords(which).TimekeeperClassification & "|"
a = a & LedesRecords(which).ClientMatterID
a = a & "[]" & crlf
LedesDataFormat = a
End Function
End Module

Вам также может понравиться