Sub ProCall(callLine As String, callStr As CallStructure, showthisCall As Boolean)
'On Error GoTo errHandle
Dim temStore$, curYear As Integer
Dim logfile As Integer
Dim Block1 As Integer
Dim songuyen As Integer
Dim sodu As Integer
Dim sogiay As Integer
Dim sotien As Double
Dim callLineS As String
' frmMain.fraViewEvent.Visible = True
If solanGoi < 1 Then callLine = " " & callLine
solanGoi = solanGoi + 1
If solanGoi > 1 Then solanGoi = 10
logfile = FreeFile
Open "LogFile.log" For Append As #logfile
callStr.call_charge = 0
callLine = lamsach_word(callLine)
Print #logfile, "" & callLine
Close #logfile
' For sodu = 0 To UBound(arrCall)
' MsgBox arrCall(sodu), , ""
' Next
If rstExType!UseSuccessCallCode Then
If Trim(Mid(callLine, rstExType!SCCode_Start, rstExType!SCCode_Len)) <> Trim(rstExType!SCCode_Value) Then
Call ShowTextLine(frmMain.txtEvent, "Unsuccessful call or called party is busy. " & Chr(10) & Chr(13))
Exit Sub
End If
End If
' MsgBox callLine
Dim found As Boolean, isHoliday As Boolean, callInMin As Integer, affect_range As Integer
curYear = Trim(Str(Year(wrkMonth)))
'AParty_Start
'AParty_Len
'
callLineS = callLine
callLineS = xu_ly_ky_tu13(callLineS)
Call ArrGetCharSpace(callLineS)
' For sodu = 0 To UBound(arrCall)
' Debug.Print "arrCall(" & sodu & ")" & arrCall(sodu) ', , ""
'Next
'arrCall(0) = "23/08/07"
'arrCall(1) = "11:24PM"
'arrCall(2) = "11"
'arrCall(3) = "01"
'arrCall(4) = "0904229075"
'arrCall(5) = "00:01'13"
'arrCall(6) = "1907"
'Trung_ke0 = 0
' So_may_goi1 = 1
' So_may_nghe2 = 2
' Ngay_goi3 = 3
' Gio_goi4 = 4
' So_phut5 = 5
' Noi_den6 = 6
' Tien_cuoc6 = 7
'Nguoi_goi8 = 8
'23/08/07 11:24PM 11 01 0904229075 00:01'13" 1907
'bungra callLine
'0.callStr.call_party so may goi = 11
'1.callStr.call_accCode ma nguoi dung = 1907
' 2.callStr.call_date ngay goi
'3.callStr.call_int so phut
'4.callStr.call_time gio goi
'5.callStr.call_type trung ke
'6.callStr.call_des so goi
'callStr.call_party =" & callStr.call_party
'SELECT
'[Ex_ID],
'[Exchange_Type],
'[Call_Len],
'[AParty_Len],
'[BParty_Len],
'[CallInt_Len],
'[CallTime_Len],
'[CallDate_Len],
'[ConCode_Len],
'[ONCode_Len],
'[AParty_Format],
'[CallInt_Format],
'[CallTime_Format],
'[CallDate_Format],
'[ConCode_Format],
'[ONCode_Format],
'[ONCode_Start],
'[AParty_Start],
'[BParty_Start],
'[CallInt_Start],
'[CallTime_Start],
'[CallDate_Start],
'[ConCode_Start],
'[Active],
'[UseSuccessCallCode],
'[SCCode_Start],
'[SCCode_Len],
'[SCCode_Value]
'From [tong_dai]
callStr.call_accCode = "0"
callStr.call_party = arrCall(rstExType!AParty_Start) ' Mid(callLine, rstExType!AParty_Start, rstExType!AParty_Len)
If rstExType!ONCode_Len <> 0 Then ' N�u c� s� d�ng m� tho�t m�ng
' temStore = Trim(Mid(callLine, rstExType!ONCode_Start, rstExType!ONCode_Len))
callStr.call_accCode = arrCall(rstExType!ONCode_Start) 'Trim(Mid(callLine, rstExType!ONCode_Start, rstExType!ONCode_Len))
callStr.called_party = arrCall(rstExType!BParty_Start) ' Trim(Mid(callLine, rstExType!BParty_Start, rstExType!BParty_Len))
Else ' N�u kh�ng s� d�ng
callStr.called_party = arrCall(callLine, rstExType!BParty_Start) 'Trim(Mid(callLine, rstExType!BParty_Start, rstExType!BParty_Len))
'callStr.called_party = vCallFormat.call_6
End If
temStore = arrCall(rstExType!CallDate_Start) 'Trim(Mid(callLine, rstExType!CallDate_Start, rstExType!CallDate_Len))
temStore = Replace(temStore, " ", "")
Debug.Print "callStr.call_accCode = " & callStr.call_accCode '=
Select Case Trim(rstExType!CallDate_Format)
Case "mmdd"
callStr.call_date = Right(temStore, 2) & "-" & Left(temStore, 2) & "-" & curYear
Case "ddmm"
callStr.call_date = Left(temStore, 2) & "-" & Right(temStore, 2) & "-" & curYear
Case "ddmmyy"
callStr.call_date = Left(temStore, 2) & "-" & Mid(temStore, 3, 2) & "-" & curYear
Case "dd/mm/yy" ' Ki�u lu s� li�u c�a Elcom
If IsDate(temStore) Then
' temStore = Format(temStore, "dd/mm/yy")
temStore = Right("0" & Day(Format(temStore, "dd/mm/yy")), 2) & "/" & Right("0" & Month(Format(temStore, "dd/mm/yy")), 2) & "/" & Right(temStore, 2)
End If
' MsgBox temStore
callStr.call_date = Left(temStore, 2) & "-" & Mid(temStore, 4, 2) & "-" & curYear
Case "mm/dd" ' Philip
callStr.call_date = Mid(temStore, 4, 2) & "-" & Left(temStore, 2) & "-" & curYear
Case "dd-mm-yy"
callStr.call_date = Left(temStore, 2) & "-" & Mid(temStore, 4, 2) & "-" & curYear
Case "ddmmyyyy"
callStr.call_date = Left(temStore, 2) & "-" & Mid(temStore, 3, 2) & "-" & Right(temStore, 4)
Case "mmddyy"
callStr.call_date = Mid(temStore, 3, 2) & "-" & Left(temStore, 2) & "-" & curYear
Case "mmddyyyy"
callStr.call_date = Mid(temStore, 3, 2) & "-" & Left(temStore, 2) & "-" & Right(temStore, 4)
End Select
'callStr.call_date = Format("24-03-1975", Trim(rstExType!CallDate_Format))
'If Not IsDate(callStr.call_date) Then callStr.call_date = Format(Date, "dd-mm-yy")
'MsgBox callStr.call_date
If Not IsDate(callStr.call_date) Then
Call ShowTextLine(frmMain.txtEvent, "Invalid Date Of Call In CDR." & Chr(10) & Chr(13))
Exit Sub
End If
' Ki�m tra l�i th�ng xem c� chuy�n th�ng kh�ng
' If wrkMonth <> Right(callStr.call_date, 7) And IsDate(Right(callStr.call_date, 7)) And NextMonth(wrkMonth) = Right(callStr.call_date, 7) Then
' Call ShowTextLine(frmMain.txtEvent, " Working Month has changed to : " & Right(callStr.call_date, 7) & Chr(13))
' wrkMonth = Right(callStr.call_date, 7)
' Call closeDB(True)
' Call openDB(True)
' End If
' Time_Interval t�nh theo block
temStore = arrCall(rstExType("CallInt_Start")) 'Trim(Mid(callLine, rstExType("CallInt_Start"), rstExType("CallInt_Len")))
temStore = Replace(temStore, """", "")
temStore = Trim(temStore) ', "", "")
Select Case Trim(rstExType("CallInt_Format"))
Case "hmmb"
callStr.call_int = Val(Left(temStore, 1)) * 600 + Val(Mid(temStore, 2, 2)) * 10 + Val(Right(temStore, 1))
' Block1 = Val(Right(temStore, 1))
Case "hmmss"
callStr.call_int = Val(Left(temStore, 1)) * 600 + Val(Mid(temStore, 2, 2)) * 10 + Val(Right(temStore, 2)) / 6
' Block1 = Val(Right(temStore, 2))
Case "hhmmss"
callStr.call_int = Val(Left(temStore, 2)) * 600 + Val(Mid(temStore, 3, 2)) * 10 + Val(Right(temStore, 2)) / 6
' Block1 = Val(Right(temStore, 2))
Case "hh:mm:ss" ' Ki�u lu s� li�u c�a Elcom
callStr.call_int = Val(Left(temStore, 2)) * 600 + Val(Mid(temStore, 4, 2)) * 10 + Val(Right(temStore, 2)) / 6
' Block1 = Val(Right(temStore, 2))
Case "mmmss"
callStr.call_int = Val(Left(temStore, 3)) * 10 + Val(Right(temStore, 2)) / 6
' Block1 = Val(Right(temStore, 2))
Case "hh:mm'ss"
callStr.call_int = Val(Left(temStore, 2)) * 600 + Val(Mid(temStore, 4, 2)) * 10 + Val(Right(temStore, 2)) / 6
' Block1 = Val(Right(temStore, 2))
End Select
If Not IsNumeric(callStr.call_int) Then
Call ShowTextLine(frmMain.txtEvent, "Call Interval is not valid." & Chr(10) & Chr(13))
Exit Sub
End If
'callStr.call_int = callStr.call_int + 1
' Call_Time
temStore = arrCall(rstExType!CallTime_Start) 'Trim(Mid(callLine, rstExType!CallTime_Start, rstExType!CallTime_Len))
' temStore = vCallFormat.call_2
temStore = Replace(temStore, "'", ":")
temStore = Replace(temStore, """", "")
Select Case Trim(rstExType("CallTime_Format"))
Case "hhmmss"
callStr.call_time = Format(TimeSerial(Val(Left(temStore, 2)), Val(Mid(temStore, 3, 2)), Val(Right(temStore, 2))), "hh:mm:ss")
Case "hh:mm:ss" ' Ki�u s� li�u c�a Elcom
callStr.call_time = temStore
Case "hhmm"
callStr.call_time = Format(TimeSerial(Val(Left(temStore, 2)), Val(Right(temStore, 2)), 0), "hh:mm:ss")
Case "hh:mm"
callStr.call_time = Format(TimeSerial(Val(Left(temStore, 2)), Val(Right(temStore, 2)), 0), "hh:mm:ss")
End Select
If Not IsDate(callStr.call_time) Then
Call ShowTextLine(frmMain.txtEvent, "Invalid Of Call Time In CDR." & Chr(10) & Chr(13))
Exit Sub
End If
' Ki�u cu�c g�i
callStr.call_type = arrCall(rstExType!ConCode_Start) ' Trim(Mid(callLine, rstExType!ConCode_Start, rstExType!ConCode_Len))
callStr.call_trungke = callStr.call_type
If InStr(1, callStr.call_type, Trim(rstCallType!ma_goi_vao)) <> 0 Then
callStr.call_type = "INC" ' cu�c g�i v�o m�ng
Else
Select Case UCase(Trim(callStr.call_type))
Case Trim(rstCallType!ma_nc)
callStr.call_type = "MAN"
Case Trim(rstCallType!ma_tsl)
callStr.call_type = "DTC"
Case Else
callStr.call_type = "AUT"
End Select
End If
If Trim(callStr.call_type) = "AUT" Or Trim(callStr.call_type) = "MAN" Then
rstAreaCode.MoveFirst
found = False
callStr.call_vung_cuoc = "0"
Do While Not rstAreaCode.EOF
If Left(Trim(callStr.called_party), Len(Trim(rstAreaCode!ma_vung))) = Trim(rstAreaCode!ma_vung) Then
found = True
callStr.call_vung_cuoc = Trim(rstAreaCode("ma_vung").Value)
Exit Do
End If
rstAreaCode.MoveNext
Loop
If found Then
If rstAreaCode!huong_goi = "NAC" Then
isIntercall = False
Else
isIntercall = True
End If
callStr.call_des = rstAreaCode!Noi_den
If callStr.call_int > 0 Then
rstPrice.MoveFirst
rstPrice.Find ("vung_cuoc='" & Trim(rstAreaCode!vung_cuoc) & "'")
If rstPrice.BOF Then
callStr.call_des = rstAreaCode!Noi_den
callStr.call_charge = 0
Else ' c� t�m th�y
If Trim(rstPrice!vung_cuoc) = "0" Then ' If local call then consider as manual call
callStr.call_type = "MAN"
End If
If callStr.call_type = "MAN" Then ' Nh�n c�ng
If callStr.call_int <= 30 Then ' nh� h�n ho�c b�ng 3 ph�t
callStr.call_charge = rstPrice!nc_3_pd
Else
'callInMin = Int((callStr.call_int - 30) / 10) + IIf((callStr.call_int - 30) Mod 10 > 0, 1, 0)
'callStr.call_charge = rstPrice!nc_3_pd + callInMin * rstPrice!nc_pt
sogiay = rstPrice("block_p")
Block1 = ((((callStr.call_int * 6) Mod 3600) Mod 60))
If Block1 <= 1 Then Block1 = 0
If Block1 > 0 Then
'Block1 = (Block1 * 6)
songuyen = Block1 \ sogiay
sodu = Block1 Mod sogiay
If sodu > 0 Then songuyen = songuyen + 1
sotien = (rstPrice!td_pt / (60 / sogiay)) * songuyen
Else
sotien = 0
End If
callInMin = Int((callStr.call_int - 10) / 10) '+ IIf((callStr.call_int - 10) Mod 10 > 0, 1, 0)
' MsgBox callInMin & "|" & Int((callStr.call_int - 10) / 10) & "||" & IIf((callStr.call_int - 10) Mod 10 > 0, 1, 0)
callStr.call_charge = rstPrice!td_pd + callInMin * rstPrice!td_pt + sotien
End If
Else ' T� ��ng
If Not isIntercall Then ' Trong n�c t�nh theo ph�ng th�c 1+1
If callStr.call_int < 10 Then ' nh� h�n ho�c b�ng 1 ph�t
sogiay = rstPrice("block_p")
Block1 = callStr.call_int * 6 ' ((((callStr.call_int * 6) Mod 3600) Mod 60))
If Block1 <= 1 Then Block1 = 0
If Block1 > 0 Then
'Block1 = (Block1 * 6)
songuyen = Block1 \ sogiay
sodu = Block1 Mod sogiay
If sodu > 0 Then songuyen = songuyen + 1
sotien = (rstPrice!td_pt / (60 / sogiay)) * songuyen
Else
sotien = 0
End If
callStr.call_charge = sotien ' rstPrice!td_pd
Else
'
sogiay = rstPrice("block_p")
Block1 = ((((callStr.call_int * 6) Mod 3600) Mod 60))
If Block1 <= 1 Then Block1 = 0
If Block1 > 0 Then
'Block1 = (Block1 * 6)
songuyen = Block1 \ sogiay
sodu = Block1 Mod sogiay
If sodu > 0 Then songuyen = songuyen + 1
sotien = (rstPrice!td_pt / (60 / sogiay)) * songuyen
Else
sotien = 0
End If
callInMin = Int((callStr.call_int - 10) / 10) '+ IIf((callStr.call_int - 10) Mod 10 > 0, 1, 0)
' MsgBox callInMin & "|" & Int((callStr.call_int - 10) / 10) & "||" & IIf((callStr.call_int - 10) Mod 10 > 0, 1, 0)
callStr.call_charge = rstPrice!td_pd + callInMin * rstPrice!td_pt + sotien
End If
Else ' qu�c t� t�nh theo ph�ng th�c 1+1/6
If callStr.call_int <= 10 Then ' nh� h�n ho�c b�ng 1 ph�t
callStr.call_charge = rstPrice!td_pd
Else
callStr.call_charge = rstPrice!td_pd + (callStr.call_int - 10) * rstPrice!td_pt
End If
End If
End If ' n�u l� g�i nh�n c�ng
' Ki�m tra �� gi�m gi� ngo�i gi� ho�c ng�y l�
rstHoliday.MoveFirst
isHoliday = False
Do While Not rstHoliday.EOF
If Format(rstHoliday!ngay, "dd-mm-yyyy") = callStr.call_date Then
isHoliday = True
affect_range = rstHoliday!anh_huong
Exit Do
End If
rstHoliday.MoveNext
Loop
' N�u ��t coi ch� nh�t v� th� b�y l� ng�y ngh� v� gi�m gi�
If rstBillMethod!td_xl_ngay Then
If Weekday(Format(callStr.call_date, "dd-mm-yyyy")) = vbSaturday Then
isHoliday = True
affect_range = 2
End If
End If
If rstBillMethod!td_in_bc_ngay Then
If Weekday(Format(callStr.call_date, "dd-mm-yyyy")) = vbSunday Then
isHoliday = True
affect_range = 2
End If
End If
If isHoliday Then
Select Case affect_range
Case 0: ' Trong n�c
If Not isIntercall Then
callStr.call_charge = callStr.call_charge * rstPrice!ti_le
End If
Case 1: ' Qu�c t�
If isIntercall Then
callStr.call_charge = callStr.call_charge * rstPrice!ti_le
End If
Case 2: 'To�n b�
callStr.call_charge = callStr.call_charge * rstPrice!ti_le
Case Else
callStr.call_charge = callStr.call_charge * rstPrice!ti_le
End Select
Else
' T�nh ngo�i gi� qu�c t�
If isIntercall Then
If Hour(callStr.call_time) >= rstBillMethod!bd_ng_qt Or Hour(callStr.call_time) < rstBillMethod!kt_ng_qt Then
callStr.call_charge = callStr.call_charge * rstPrice!ti_le
isHoliday = True
End If
Else
' T�nh ngo�i gi� li�n t�nh
If Hour(callStr.call_time) >= rstBillMethod!bd_ng_lt Or Hour(callStr.call_time) < rstBillMethod!kt_ng_lt Then
callStr.call_charge = callStr.call_charge * rstPrice!ti_le
isHoliday = True
End If
End If
End If
End If
End If ' n�u th�i gian g�i >0
Else
callStr.call_des = "Unknown Destination"
callStr.call_charge = 0
End If
End If
If rstBillMethod!ti_le_tang Then
If Not isIntercall Then
callStr.call_charge = Int(callStr.call_charge * ((100 + rstBillMethod!ti_le_tang) / 100))
Else
callStr.call_charge = callStr.call_charge * ((100 + rstBillMethod!ti_le_tang) / 100)
End If
End If
If autoPrintLocalCall = True Then
If callStr.call_charge = 0 Then
callStr.call_des = "Ghise Local Call"
callStr.call_charge = ((Int(callStr.call_int / 10) + IIf(callStr.call_int Mod 10 > 0, 1, 0)) * AddedPriceForLocalCall)
isIntercall = False
End If
End If
If callStr.call_type = "DTC" Then
callStr.call_des = "Data Call On ISDN"
callStr.call_charge = (rstBillMethod!tsl_tren_isdn * callStr.call_int) / 10
callStr.call_type = "AUT"
isIntercall = False
End If
If callStr.call_type = "INC" Then
callStr.call_des = "Incoming Call"
callStr.call_charge = 0
End If
If sendToRemote Then
Dim thisCall As Variant
thisCall = callLine & Chr(10) & Chr(13)
If Not useSendTable Then
Select Case sendType
Case 0: ' Kh�ng �a ra
Case 1: ' Cu�c c� c�c
If callStr.call_charge <> 0 Then
frmMain.mscRemote.Output = thisCall
End If
Case 2:
If callStr.call_type <> "INC" Then
frmMain.mscRemote.Output = thisCall
End If
Case Else
frmMain.mscRemote.Output = thisCall
End Select
Else
found = False
rstSendList.MoveFirst
Do While Not rstSendList.EOF
If Val(callStr.call_party) = rstSendList!ext Then
found = True
Exit Do
End If
rstSendList.MoveNext
Loop
rstSendList.MoveFirst
If found = True Then
Select Case sendType
Case 0: ' Kh�ng �a ra
Case 1: ' Cu�c c� c�c
If callStr.call_charge <> 0 Then
frmMain.mscRemote.Output = thisCall
End If
Case 2:
If callStr.call_type <> "INC" Then
frmMain.mscRemote.Output = thisCall
End If
Case Else
frmMain.mscRemote.Output = thisCall
End Select
End If
End If
End If
Select Case oCall.to_screen
Case 0: ' Kh�ng �a ra
Case 1: ' Cu�c c� c�c
If callStr.call_charge <> 0 Then
Call showCall(callStr, isIntercall)
End If
Case 2:
If callStr.call_type <> "INC" Then
Call showCall(callStr, isIntercall)
End If
Case Else
Call showCall(callStr, isIntercall)
End Select
Select Case oCall.to_disk
Case 0: ' Kh�ng �a ra
Case 1: ' Cu�c c� c�c
If callStr.call_charge <> 0 Then
Call SaveCall(callStr, dbmain)
End If
Case 2:
If callStr.call_type <> "INC" Then
Call SaveCall(callStr, dbmain)
End If
Case Else
Call SaveCall(callStr, dbmain)
End Select
Select Case oCall.to_printer
Case 0: ' Kh�ng �a ra
Case 1: ' Cu�c c� c�c
If callStr.call_charge <> 0 Then
Printer.Print "| " & callStr.call_party; Tab(10); " | " & Trim(callStr.called_party); Tab(26); "| " & callStr.call_date; Tab(40); "| " & callStr.call_time; Tab(53); "| " & Format(Int(callStr.call_int / 10) + IIf(callStr.call_int Mod 10, 1, 0), "###.0"); Tab(67); "| " & callStr.call_charge; Tab(83); "|"
Printer.Print
End If
Case 2:
If callStr.call_type <> "INC" Then
Printer.Print "| " & callStr.call_party; Tab(10); " | " & Trim(callStr.called_party); Tab(26); "| " & callStr.call_date; Tab(40); "| " & callStr.call_time; Tab(53); "| " & Format(Int(callStr.call_int / 10) + IIf(callStr.call_int Mod 10, 1, 0), "###.0"); Tab(67); "| " & callStr.call_charge; Tab(83); "|"
Printer.Print
End If
Case Else
Printer.Print "| " & callStr.call_party; Tab(10); " | " & Trim(callStr.called_party); Tab(26); "| " & callStr.call_date; Tab(40); "| " & callStr.call_time; Tab(53); "| " & Format(Int(callStr.call_int / 10) + IIf(callStr.call_int Mod 10, 1, 0), "###.0"); Tab(67); "| " & callStr.call_charge; Tab(83); "|"
Printer.Print
End Select
errHandle:
If Err.Number <> 0 Then
' MsgBox Err.Description
Call ShowTextLine(frmMain.txtEvent, "Error On Processing Call : " & Err.Description & " - Error Code :" & Str(Err.Number) & Chr(10) & Chr(13))
Err.Clear
Exit Sub
End If
End Sub