cancel
Showing results for 
Search instead for 
Did you mean: 

Freight (expense on header)

former_member687054
Participant
0 Kudos

Hi,

Is it possible with the DI API, to create a delivery base on a sales order and to have the freight assigned correctly in the delivery according to the drawing method set in the freight ?

Actually, except by setting manually my oDelivery.Expenses.xxx, it doesn't seems to work.

I've try in SAP 2005 and also in SAP 2007, same results.

Thank you for your help.

Jo

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dear Joderick Picard,

You could refer to following code to add a delivery with expense based on the sales order.



        myDelivery = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)

        myDelivery.DocDate = Now
        myDelivery.DocDueDate = Now

        myDelivery.Lines.BaseEntry = 167
        myDelivery.Lines.BaseType = 17
        myDelivery.Lines.WarehouseCode = "01"
        myDelivery.Lines.BaseLine = 0
        myDelivery.Lines.Quantity = 1

        myDelivery.Expenses.BaseDocEntry = 167
        myDelivery.Expenses.BaseDocType = 17
        myDelivery.Expenses.BaseDocLine = 0

        RetVal = myDelivery.Add

Best Regards

Jane Jing

SAP Business One Forums team

former_member687054
Participant
0 Kudos

Hi Jane Jing,

If I have an order with a quantity of 5 and I have 3 delivery for it (one of 1 unit, one of 3 units and one of 1). Using your code I have all my expenses on the first delivery and nothing on the two last delivery.

For my test, I've set 3 freight, one for each drawing method (quantity, total and All).

My goal is the have the same result with the DI API then in SAP B1 when creating the deilvery in the delivery screen using the "copy from" wizard.

So, right now I have with the SDK (column 1 : freight, column 2 : 1st delivery, column 3 : 2nd delivery, column 4 : 3rd delivery)

Freight 1 (Quantity): 20 0 0

Freight 2 (Total): 20 0 0

Freight 3 (All): 20 0 0

and with SAP

Freight 1 (Quantity): 4 12 4

Freight 2 (Total): 4 12 4

Freight 3 (All): 20 0 0

So, the question is : is it possible to have the same result with the DI API then with SAP business one ?

Thank you

former_member687054
Participant
0 Kudos

Hi all,

if it is not possible, I'll have no other choice then calculate manually the expense amount according to the drawing method.

I have no problem with none, quantity and all, but Total seem different from time to time, can someone told me how it works ?

(some time I have all the amount on the last delivery while other time I have the same result for my expense set with total and another with All.

Thank you for your help

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Joderic and other interested parties,

One possible workaround for this issue is to calculate the LineTotal in the AddOn code and set it accordingly. Example:


           ' Get the relevant information of the base doc required to calculate the Header Expenses
           Set RecSet = oCompany.GetBusinessObject(BoRecordset)
           RecSet.DoQuery ("SELECT SUM(Quantity), Max(LineNum), SUM(LineTotal) 
           FROM RDR1 WHERE DocEntry = " & iBaseDocEntry)
            
            iBaseTotalQuantity = RecSet.Fields.Item(0).Value
            iBaseNoOfLines = RecSet.Fields.Item(1).Value + 1
            dBaseDocTotal = RecSet.Fields.Item(2).Value
            
            Set RecSet = Nothing
            
            ' get the decimal settings in the company to do the corrcet rounding
            Set RecSet = oCompany.GetBusinessObject(BoRecordset)
            RecSet.DoQuery ("SELECT SumDec FROM OADM")
            iDecSettings = RecSet.Fields.Item(0).Value
            
            ' Define expenses on Header level
            .Expenses.Add
            .Expenses.SetCurrentLine (0)
            oBaseDoc.Expenses.SetCurrentLine (0)
            .Expenses.BaseDocEntry = oBaseDoc.DocEntry
            .Expenses.BaseDocType = 17
            .Expenses.BaseDocLine = 0

            ' Set the Distribution Method and Line Total
            ' Calculate the Line Total according to the Business Requirements
            
            .Expenses.DistributionMethod = oBaseDoc.Expenses.DistributionMethod
            Select Case oBaseDoc.Expenses.DistributionMethod
             Case 0 ' = aed_None
                .Expenses.LineTotal = Round(InputBox("Enter First Expenses: ", "", ""), iDecSettings)
            Case 1 ' = aed_Quantity
                .Expenses.LineTotal = Round(oBaseDoc.Expenses.LineTotal / 
                iBaseTotalQuantity * iQuantity, iDecSettings)
            Case 4 ' = aed_Equally
                .Expenses.LineTotal = Round(oBaseDoc.Expenses.LineTotal / 
                iBaseNoOfLines, iDecSettings)
            Case 5 ' = aed_LineTotal
                .Expenses.LineTotal = Round(oBaseDoc.Expenses.LineTotal /  
                dBaseDocTotal * oBaseDoc.Lines.LineTotal, iDecSettings)
            End Select

In the meantime the issue is under investigation by SAP Business One development.

Regards,

Friederike

SAP Business One Forums Team

Former Member
0 Kudos

Hello Joderick,

I think that you take a better look at this object: AdditionalExpenses

This object represents the freight in an order...

Hope this helps.

Regards,