on 09-16-2008 4:48 PM
Hi @All !
Does anybody know a function within B1-SDK which calculates a DueDate by PaymentTerms from a given Start-Date?
I've found the
StartFrom-
NumberOfAdditionalMonths- and
NumberOfAdditionalDays-
propertys of the PaymentTermsTypes Object. The last two are nice for .NET-date calculation-methods.
But StartFrom must be "interpreted" correctly from a given Date. Is there any existing function like
Public Shared Function GetDueDate( _
ByVal RefDate As System.DateTime, _
ByVal PaymTerms As SAPbobsCOM.PaymentTermsTypes _
) As System.DateTime
which does everything automatically like it's done in an invoice when changing the PaymentTerms in B1 GUI?
Thanks,
Roland
Dear Roland Toschek,
You could use the PaymentGroupCode property of the document to set the PaymentTerms and the document's
DueDate will calculate by the DocDate and PaymentTerms.
Sample code:
myInvoice = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
myInvoice.CardCode = "C1000"
myInvoice.DocDate = Now
myInvoice.PaymentGroupCode = 1 ' --- PaymentTerms : 30 days
myInvoice.Lines.ItemCode = "A1000"
myInvoice.Lines.Quantity = 1
myInvoice.Lines.Price = 10
RetVal = myInvoice.Add()
Best Regards
Jane Jing
SAP Business One Forums team
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Jane Jing,
thanks for your answer but it seems as if I must clarify my issue a little bit more
Yes: I know that the due date is automatically set in an invoice by DocDate and PaymentGroupCode when adding the invoice.
But what I wanna do is making the DueDate visible to the user on our own AddOn-Form before the user clicks "Add". I wanna do exactly the same as B1 on the system A/R-Invoice-form: On combo-selection of PaymentTerms an EditText with DueDate ought to change to the correctly calculated DueDate.
Cheers,
Roland
Hello Allan,
thanks for your answer.
I'm ashamed: I didn't discover this method until now.
But unfortunatly this function does not help. It works as expected but the result-date is always based on the Businesspartners default-payment-terms.
What I need is a function where the payment-terms could be changed as a one-time-option (for one document) and the resulting date can be written into an EditText (by AddOn-code) on the AddOn form before adding the document.
The only way I see at the moment is to make my own function as
Public Shared Function GetDueDate( _
ByVal RefDate As System.DateTime, _
ByVal PaymTerms As SAPbobsCOM.PaymentTermsTypes _
) As System.DateTime
But I don't know how to calculate with especially the "Half month" setting in the Payment-Terms -Setup
How is a DueDate Calculated from e.g. now for...
...Month End
...Half Month
...Month End
settings?
How is half month defined in February? How is it defined in month with 30 and 31 days?
Adding the other payment-setup-fields (month and days) should not be the problem...
Hi Roland,
In the SDK documentation it's indicated that SBO calculates the due date following this method :
" Payment due date = StartFrom + NumberOfAdditionalMonths + NumberOfAdditionalDays
But it's not totally excact, because the "Half of month" is based on the number of days in the month of the DateRef and "End of Month" is based on the number of days in the month of the DueDate.
For "Half of Month", SBO takes the integer inferior of this operation : number of days of month of due date divided by 2 [(DaysInMonth(DueDate.Month, DueDate.Year)]
That means "15" for the months with 30 or 31 days and "14" for february.
I wrote the function below for you, let me know if it's ok. She's works fine on my side.
Public Shared Function myGetDueDate( _
ByVal RefDate As System.DateTime, _
ByVal PaymTerms As SAPbobsCOM.PaymentTermsTypes) As System.DateTime
Dim oDay As Integer
Dim oDate As Date
oDay = RefDate.Day
oDate = DateAdd(DateInterval.Month, PaymTerms.NumberOfAdditionalMonths, RefDate)
Select Case PaymTerms.StartFrom
Case SAPbobsCOM.BoPayTermDueTypes.pdt_HalfMonth
If RefDate.Month = 2 Then : oDay = 14
Else : oDay = 15
End If
Case SAPbobsCOM.BoPayTermDueTypes.pdt_MonthStart
oDay = 1
Case SAPbobsCOM.BoPayTermDueTypes.pdt_MonthEnd
oDay = Date.DaysInMonth(oDate.Year, oDate.Month)
End Select
oDate = DateAdd(DateInterval.Day, (oDate.Day * -1) + oDay, oDate)
oDate = DateAdd(DateInterval.Day, PaymTerms.NumberOfAdditionalDays, oDate)
Return oDate
End Function
Alan.
Hello Allan,
thanks for your answer and code
I've tested SDK-GetDueDate versus automatic DueDate after adding an invoice versus your myGetDueDate.
Here are the results of the test:
I've changed the DefaultPaym.-Terms of a BP for each test a) to c) to compare with SDK-GetDueDate.
RefDate=07.10.2008
Tested PaymentTerms:
a) MonthStart + 0 Month + 60 Days
GetDueDate => 31.12.2008 (Does this calculate from the next MonthStart?)
AddingInvoice => 31.12.2008
myGetDueDate => 30.11.2008
b) HalfMonth + 0 Month + 60 Days
GetDueDate => 06.12.2008
AddingInvoice => 14.12.2008
myGetDueDate => 14.12.2008
c) MonthEnd + 0 Month + 60 Days
GetDueDate => 06.12.2008
AddingInvoice => 30.12.2008
myGetDueDate => 30.12.2008
It seems to me that SDK-GetDueDate has a Bug and your Function works correctly except case a)
AND: Does MonthStart calculate from the next MonthStart?
If so:
I've modified your Function a little bit. Only MonthStart is different. The rest is copied into the two other Case-Blocks.
It returns now the same DueDate for MonthStart as SAP when adding an invoice.
(...and the Function now works with the PaymentTermsID instead of the PaymentTerms-Object - this is more useful here because I get the ID from a Combo)
Public Shared Function myGetDueDate( _
ByVal RefDate As System.DateTime, _
ByVal PaymTermsID As Integer _
) As System.DateTime
Dim PaymTerms As SAPbobsCOM.PaymentTermsTypes
PaymTerms = SboCon.SboDI.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPaymentTermsTypes)
If Not PaymTerms.GetByKey(PaymTermsID) Then
Throw New Exception("PaymentTerms ID " & PaymTermsID & " not found")
End If
Dim oDay As Integer
Dim oDate As Date
oDay = RefDate.Day
Select Case PaymTerms.StartFrom
Case SAPbobsCOM.BoPayTermDueTypes.pdt_HalfMonth
If RefDate.Month = 2 Then : oDay = 14
Else : oDay = 15
End If
oDate = DateAdd(DateInterval.Month, PaymTerms.NumberOfAdditionalMonths, RefDate)
oDate = DateAdd(DateInterval.Day, (oDate.Day * -1) + oDay, oDate)
oDate = DateAdd(DateInterval.Day, PaymTerms.NumberOfAdditionalDays, oDate)
Case SAPbobsCOM.BoPayTermDueTypes.pdt_MonthStart
oDate = DateAdd(DateInterval.Month, 1, RefDate) ' Go to next month...
oDate = DateAdd(DateInterval.Day, ((oDate.Day - 1) * -1), oDate) '...and first day of next month
oDate = DateAdd(DateInterval.Month, PaymTerms.NumberOfAdditionalMonths, oDate) ' Add the PymTerm Month...
oDate = DateAdd(DateInterval.Day, PaymTerms.NumberOfAdditionalDays, oDate) '...and days
Case SAPbobsCOM.BoPayTermDueTypes.pdt_MonthEnd
oDay = Date.DaysInMonth(oDate.Year, oDate.Month)
oDate = DateAdd(DateInterval.Month, PaymTerms.NumberOfAdditionalMonths, RefDate)
oDate = DateAdd(DateInterval.Day, (oDate.Day * -1) + oDay, oDate)
oDate = DateAdd(DateInterval.Day, PaymTerms.NumberOfAdditionalDays, oDate)
Case SAPbobsCOM.BoPayTermDueTypes.pdt_None
oDate = DateAdd(DateInterval.Month, PaymTerms.NumberOfAdditionalMonths, RefDate)
oDate = DateAdd(DateInterval.Day, PaymTerms.NumberOfAdditionalDays, oDate)
End Select
Return oDate
End Function
Edited by: Roland Toschek on Oct 7, 2008 4:00 PM
=> I forgot SAPbobsCOM.BoPayTermDueTypes.pdt_None
User | Count |
---|---|
103 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.