I have a client upgrading (from 115) to 149. A plugin is failing as property TaxID no longer exists. I have looked through the associated Line class, but cannot work out your intention for deriving this information now. Can you point me in the right direction?
- Code: Select all
Private Sub CreateCreditorPurchase(purchaseOrder As PurchaseOrder)
Dim poLines As IEnumerable(Of Line) = From poLine As Line In purchaseOrder.Lines Where poLine.UserDefinedString1.Length >= 8 And poLine.UserDefinedString2 = "Yes" And poLine.UserDefinedString3 = ""
If poLines.Count() = 0 Then Throw New System.Exception("There are no purchase order lines to process.")
Dim closePurchaseOrder = GetCustomField("ClosePurchaseOrder").ToString() = "True"
Dim creditorInvoiceNumber = GetCustomField("CreditorInvoiceNumber").ToString()
Dim creditorInvoiceDate = IIf(GetCustomField("CreditorInvoiceDate") Is Nothing, System.DateTime.Today, GetCustomField("CreditorInvoiceDate"))
Dim total As Decimal = poLines.Sum(Function(x) x.LineTotal)
Dim purchasesUi = JiwaApplication.Manager.Instance.FormFactory.CreateForm(Of JiwaCRBatchTXUI.CreditorPurchases)()
purchasesUi.InitialReadMode = JiwaApplication.IJiwaNavigable.ReadModes.None
purchasesUi.Start()
purchasesUi.CRBatchTransObject.CreateNew()
purchasesUi.CRBatchTransObject.Description = String.Format("PO{0}/{1}/{2}/{3}/{4}", purchaseOrder.OrderNo, purchaseOrder.Reference.Trim, GetCustomField("AuthorisedBy"), purchaseOrder.Staff.DisplayName.Trim, total)
purchasesUi.CRBatchTransObject.BatchType = CreditorBatchTrans.CreditorBatchTypes.Creditor_Purchase
Dim item = New CRBatchTranLine()
item.Creditor.ReadRecord(purchaseOrder.Creditor.CreditorID)
item.HomeTransAmount = total
item.RemitNo = creditorInvoiceNumber
purchasesUi.CRBatchTransObject.TransLines.Add(item)
' NOTE: If we try to set ReceiptDate BEFORE adding it to the collection it doesn't stick
item.ReceiptDate = creditorInvoiceDate
Dim dispersalNum = 1
For Each poLine As Line In poLines
Dim dispersal = New CRBatchDispersal()
If dispersalNum = 1 Then
' The adding of a line to the batch automatically also adds a dispersal for the line - all lines must have at least one disperals, so we adjust that with:
dispersal = item.Dispersals(1)
Else
' And now if we choose to, we can add another dispersal
item.Dispersals.Add(dispersal)
End If
' NOTE: If we try to set the dispersed amount BEFORE adding it to the collection, then we have issues (this is bug)
dispersal.OtherLedger.ReadRecordFromAccountNo(poLine.UserDefinedString1.Substring(0, 8))
dispersal.TaxRate.Read(poLine.TaxID)
dispersal.HomeDispersedAmount = poLine.LineTotal - poLine.TaxAmount
dispersal.Remark = String.Format("{0} - {1} (x{2:N0})", poLine.PartNo, poLine.Description, poLine.Quantity)
dispersalNum += 1
Next
purchasesUi.CRBatchTransObject.Save()
For Each poLine As Line In poLines
poLine.UserDefinedString3 = purchasesUi.CRBatchTransObject.BatchNumber
Next
If closePurchaseOrder Then purchaseOrder.OrderStatus = Workflow.Status.Closed
purchaseOrder.Save()
End Sub
(TaxID is about 14 lines up from the bottom)
Cheers,
Neil.


