Problem: Would like to manipulate Document Additional Expenses in code with the UI-API before clicking on "Add" for the main form and adding the record, and without opening the "Expenses" form (3007). Creating an object with the DI API won't work because the order record has not yet been saved to the database so can't be retrieved and updated.
The reason this is needed is that the customer wants to create the additional expenses automatically based on the specifics of the order, e.g. the shipping method, tax code, etc. The customer does not want to have to open the expenses screen and manually enter the expenses for each sale. Also, the customer wants to see the total expenses before adding the order the first time.
Example: The sales order form (139) has an "Add Expenses" field with a golden arrow. Clicking the arrow opens an "Expenses" form (3007) where expenses can be added. In the case of a brand new order, these items are apparently stored by SBO in the DocumentsAdditionalExpenses object until the add button on form 139 is clicked and the record added.
Question: Is there a way in code using the UI-API, (not the DI-API) to access the DocumentsAdditionalExpenses of the new sales order? If not is there any other way to manipulate the expenses before the sale is added?
Thanks for your help.
Mel
Mel,
I have achieved this but found it quite slow when you had about 20 or more products entered.
I used the properties in inventory item to flag additional expenses ex1, ex2 or ex3 (In my case damage waiver and stamp duty). A formatted search would query this when an item is entered into a sales order and flag the additional expenses combo boxes in the matrix.
The following code then queries every line or a single line in the matrix and inserts the calculated additional expenses.
It then sums these amounts to show them separately on the order form.
Hope this code below helps, but remember it is quite low. I'm trying to find a faster way at the moment. If you know of any please let me know.
Cheers,
Richard
Private Sub Recalculate_Expenses()
'This routine will calculate the Damage waiver and Stamp duty in an order/quote
Dim DamageWaiverTotal As Double
Dim StampDutyTotal As Double
Dim DamageWaiverPercentage As Double
Dim StampDutyPercentage As Double
Dim oObject As Object
oMatrix = oOrderForm.Items.Item("38").Specific
DamageWaiverTotal = 0
StampDutyTotal = 0
For i = 1 To oMatrix.VisualRowCount
oComboBox = oMatrix.Columns.Item("257").Cells.Item(i).Specific 'Line type combo box
If oComboBox.Selected.Value = "" Then
oItemText = oMatrix.Columns.Item("112").Cells.Item(i).Specific
DamageWaiverTotal = DamageWaiverTotal + CDbl(Replace(oItemText.String, "AUD", ""))
oItemText = oMatrix.Columns.Item("116").Cells.Item(i).Specific
StampDutyTotal = StampDutyTotal + CDbl(Replace(oItemText.String, "AUD", ""))
End If
Next
oItemText = oOrderForm.Items.Item("txtDamage").Specific
oItemText.String = Format(DamageWaiverTotal, "$###,##0.00")
oItemText = oOrderForm.Items.Item("txtSDamt").Specific
oItemText.String = Format(StampDutyTotal, "$###,##0.00")
End Sub
Private Sub Recalculate_DamageWaiver_StampDuty(ByVal PerLine As Integer)
'This routine will calculate the Damage waiver and Stamp duty in an order/quote
Dim DamageWaiverTotal As Double
Dim StampDutyTotal As Double
Dim DamageWaiverPercentage As Double
Dim StampDutyPercentage As Double
Dim oObject As Object
DamageWaiverPercentage = 0.06
StampDutyPercentage = 0.0075
oMatrix = oOrderForm.Items.Item("38").Specific
DamageWaiverTotal = 0
StampDutyTotal = 0
For i = 1 To oMatrix.VisualRowCount
If PerLine = 0 Or PerLine = i Then
oComboBox = oMatrix.Columns.Item("257").Cells.Item(i).Specific 'Line type combo box
If oComboBox.Selected.Value = "" Then
'Damage Waiver
oComboBox = oMatrix.Columns.Item("111").Cells.Item(i).Specific 'Damage waiver flag
If oComboBox.Selected.Value <> "-1" Then
oItemText = oMatrix.Columns.Item("21").Cells.Item(i).Specific 'Item total price exGST
DamageWaiverTotal = CDbl(Replace(oItemText.String, "AUD", "")) * DamageWaiverPercentage
oItemText = oMatrix.Columns.Item("112").Cells.Item(i).Specific 'Damage waiver Amt
If CDbl(Replace(oItemText.String, "AUD ", "")) <> Math.Round(DamageWaiverTotal, 3) Then
oItemText.Value = Math.Round(DamageWaiverTotal, 3)
End If
End If
'Stamp Duty
oComboBox = oMatrix.Columns.Item("115").Cells.Item(i).Specific 'Stamp duty flag
If oComboBox.Selected.Value <> "-1" Then
oItemText = oMatrix.Columns.Item("21").Cells.Item(i).Specific 'Item total price exGST
StampDutyTotal = CDbl(Replace(oItemText.String, "AUD", "")) * StampDutyPercentage
oItemText = oMatrix.Columns.Item("116").Cells.Item(i).Specific 'Stamp Duty Amt
If CDbl(Replace(oItemText.String, "AUD ", "")) <> Math.Round(StampDutyTotal, 3) Then
oItemText.Value = Math.Round(StampDutyTotal, 3)
End If
End If
End If
End If
Next
Recalculate_Expenses()
End Sub
Add a comment