I'm trying to add multiple AR Receipt and put the batch number in to a list so that when posting batch it is inside the loop. But upon Posting the batch I've got an error "Cannot post batch XX. Batch status is not Ready To Post or Post In Progress. - Error occurred during posting. No error batch created."
I know there's a problem in this line:
Here's the full code:
I know there's a problem in this line:
Code:
For Each batch In arr_batch
ARRECMAC1detail4.Cancel()
ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(vbNull) ' Starting Date
ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("3") ' Process Command
ARRECMAC1batch.Process()
ARRECMAC1batchFields.FieldByName("BATCHSTAT").PutWithoutVerification("7") ' Batch Status
ARRECMAC1batch.Update()
ARRECMAC1batch.Update()
ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("1") ' Process Command
ARRECMAC1batch.Process()
ARPAYMPOST2Fields.FieldByName("BATCHIDFR").PutWithoutVerification(batch) ' Post Batch From
ARPAYMPOST2Fields.FieldByName("BATCHIDTO").PutWithoutVerification(batch) ' Post Batch To
ARPAYMPOST2.Process()
ARRECMAC1batch.Read()
ARRECMAC1detail4.Cancel()
ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", 1)
ARRECMAC1detail2Fields.FieldByName("CNTSEQ").PutWithoutVerification("-99999") ' Sequence No.
ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", -1)
ARRECMAC1detail2.Fetch()
ARRECMAC1headerFields.FieldByName("CNTITEM").PutWithoutVerification("-9999999") ' Entry Number
ARRECMAC1header.Browse("", 1)
ARRECMAC1header.Fetch()
ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", 1)
ARRECMAC1detail2Fields.FieldByName("CNTSEQ").PutWithoutVerification("-99999") ' Sequence No.
ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", -1)
ARRECMAC1detail2.Fetch()
Next
Here's the full code:
Code:
Dim newDs As DataSet
newDs = New DataSet
newDs = drDetails
Dim oInvoiceNo As String = ""
Dim ctr As Integer = 0
For Each oDr As DataRow In newDs.Tables(0).Rows
ARRECMAC1batch.RecordClear()
ARRECMAC1batchFields.FieldByName("CODEPYMTYP").PutWithoutVerification("CA") ' Batch Type
ARRECMAC1batchFields.FieldByName("CNTBTCH").PutWithoutVerification("0") ' Batch Number
ARRECMAC1batch.RecordCreate(1)
ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("2") ' Process Command
ARRECMAC1batch.Process()
ARRECMAC1detail4.Cancel()
temp = ARRECMAC1header.Exists
ARRECMAC1header.RecordCreate(2)
ARRECMAC1detail4.Cancel()
temp = ARRECMAC1header.Exists
ARRECMAC1batchFields.FieldByName("BATCHDESC").PutWithoutVerification("Astute Import - " & Date.Now) ' Description
'Get Batch number
_newBatch = ARRECMAC1batchFields.FieldByName("CNTBTCH").Value
arr_batch.Add(_newBatch)
ARRECMAC1batch.Update()
'ARRECMAC1headerFields.FieldByName("TEXTRMIT").Value = "BB" ' Entry Description
ARRECMAC1headerFields.FieldByName("IDCUST").Value = oDr("Card ID") ' Customer Number
ARRECMAC1detail1.Cancel()
ARRECMAC1headerFields.FieldByName("PROCESSCMD").PutWithoutVerification("0") ' Process Command Code
ARRECMAC1header.Process()
ARRECMAC1detail4.Cancel()
ARRECMAC1detail4Fields.FieldByName("PAYMTYPE").Value = "CA" ' Batch Type
'ARRECMAC1detail4Fields.FieldByName("CNTBTCH").Value = "10" ' Batch Number
ARRECMAC1detail4Fields.FieldByName("CNTITEM").Value = "0" ' Entry Number
ARRECMAC1detail4Fields.FieldByName("IDCUST").Value = oDr("Card ID") ' ID Customer
ARRECMAC1detail4Fields.FieldByName("AMTRMIT").Value = "0.000" ' Receipt Amount
ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(DateSerial(100, 1, 1)) ' Starting Date
ARRECMAC1detail4Fields.FieldByName("PROTYPE").PutWithoutVerification("1") ' Process Type
ARRECMAC1detail4.Process()
ARRECMAC1detail4Fields.FieldByName("STDOCSTR").PutWithoutVerification("") ' Starting Doc. Number
ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(vbNull) ' Starting Date
ARRECMAC1detail4Fields.FieldByName("STDOCAMT").PutWithoutVerification("-999999999999999.999") ' Starting Amount
ARRECMAC1detail1.RecordClear()
ARRECMAC1detail1.RecordCreate(0)
ARRECMAC1detail1Fields.FieldByName("IDINVC").Value = oDr("Invoice No") ' Document Number
ARRECMAC1detail1Fields.FieldByName("CNTPAYM").Value = "1" ' Payment Number
ARRECMAC1detail1Fields.FieldByName("AMTPAYM").Value = oDr("Amount Applied") ' Document Number
ARRECMAC1detail1.Insert()
ARRECMAC1detail1Fields.FieldByName("CNTLINE").PutWithoutVerification("-1") ' Line Number
ARRECMAC1detail1.Read()
ARRECMAC1headerFields.FieldByName("AMTRMIT").Value = oDr("Amount Applied") ' Bank Receipt Amount
Dim _date As String
_date = oDr("Receipt Date").ToString.Replace(".", "/")
Dim adate As DateTime = DateTime.ParseExact(_date, "dd/MM/yyyy", CultureInfo.InvariantCulture)
Dim reformatted As String = adate.ToString("yyyyMMdd", CultureInfo.InvariantCulture)
ARRECMAC1headerFields.FieldByName("DATERMIT").Value = adate ' Receipt Date/Adjustment Date
ARRECMAC1headerFields.FieldByName("DATEBUS").Value = Date.Today ' Posting Date
ARRECMAC1detail5Fields.FieldByName("OPTFIELD").PutWithoutVerification("JOBCODE") ' Optional Field
ARRECMAC1detail5.Read()
ARRECMAC1detail5Fields.FieldByName("SWSET").Value = "1" ' Value Set
ARRECMAC1detail5.Update()
ARRECMAC1detail5Fields.FieldByName("OPTFIELD").PutWithoutVerification("RECHCLIENT") ' Optional Field
ARRECMAC1detail5.Read()
ARRECMAC1detail5Fields.FieldByName("SWSET").Value = "1" ' Value Set
ARRECMAC1detail5.Update()
ARRECMAC1detail5.Read()
ARRECMAC1header.Insert()
ARRECMAC1detail4.Cancel()
ARRECMAC1detail4Fields.FieldByName("PAYMTYPE").Value = "CA" ' Batch Type
'ARRECMAC1detail4Fields.FieldByName("CNTBTCH").Value = "10" ' Batch Number
ARRECMAC1detail4Fields.FieldByName("CNTITEM").Value = "1" ' Entry Number
ARRECMAC1detail4Fields.FieldByName("IDCUST").Value = oDr("Card ID") ' ID Customer
ARRECMAC1detail4Fields.FieldByName("AMTRMIT").Value = oDr("Amount Applied") ' Receipt Amount
ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(DateSerial(100, 1, 1)) ' Starting Date
ARRECMAC1detail4Fields.FieldByName("PROTYPE").PutWithoutVerification("1") ' Process Type
ARRECMAC1detail4.Process()
ARRECMAC1detail4Fields.FieldByName("STDOCSTR").PutWithoutVerification("") ' Starting Doc. Number
ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(vbNull) ' Starting Date
ARRECMAC1detail4Fields.FieldByName("STDOCAMT").PutWithoutVerification("-999999999999999.999") ' Starting Amount
ARRECMAC1batch.Read()
ARRECMAC1headerFields.FieldByName("CNTITEM").PutWithoutVerification("0") ' Entry Number
ARRECMAC1header.RecordCreate(2)
ctr += 1
Next
Catch ex As Exception
isErrHeader = True
line_no = 0
sError = Err.Description
fHandleSageErrors(sError)
sError = "ERR~~<Document Number - " & _newBatch & "> " & sError
fLogIt("[Err]-fCreateARReceiptTransaction-<Document Number - " & _newBatch & "> Error: " & sError)
For Each batch In arr_batch
ARRECMAC1batchFields.FieldByName("CNTBTCH").Value = batch ' Batch Number
ARRECMAC1batch.Read()
ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("2") ' Process Command
ARRECMAC1batch.Process()
ARRECMAC1batchFields.FieldByName("BATCHSTAT").Value = "4" ' Batch Status 4 = Delete
ARRECMAC1batch.Update()
ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("0") ' Process Command
ARRECMAC1batch.Process()
Next
Return False
End Try
'Post Command
'Dim batchNumber As String = ""
'batchNumber = ARRECMAC1headerFields.FieldByName("CNTBTCH").Value
For Each batch In arr_batch
ARRECMAC1detail4.Cancel()
ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(vbNull) ' Starting Date
ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("3") ' Process Command
ARRECMAC1batch.Process()
ARRECMAC1batchFields.FieldByName("BATCHSTAT").PutWithoutVerification("7") ' Batch Status
ARRECMAC1batch.Update()
ARRECMAC1batch.Update()
ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("1") ' Process Command
ARRECMAC1batch.Process()
ARPAYMPOST2Fields.FieldByName("BATCHIDFR").PutWithoutVerification(batch) ' Post Batch From
ARPAYMPOST2Fields.FieldByName("BATCHIDTO").PutWithoutVerification(batch) ' Post Batch To
ARPAYMPOST2.Process()
ARRECMAC1batch.Read()
ARRECMAC1detail4.Cancel()
ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", 1)
ARRECMAC1detail2Fields.FieldByName("CNTSEQ").PutWithoutVerification("-99999") ' Sequence No.
ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", -1)
ARRECMAC1detail2.Fetch()
ARRECMAC1headerFields.FieldByName("CNTITEM").PutWithoutVerification("-9999999") ' Entry Number
ARRECMAC1header.Browse("", 1)
ARRECMAC1header.Fetch()
ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", 1)
ARRECMAC1detail2Fields.FieldByName("CNTSEQ").PutWithoutVerification("-99999") ' Sequence No.
ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", -1)
ARRECMAC1detail2.Fetch()
Next