project QadFinancials > class BDInvoice > method DefaultValuesDebtor
Description
Called when the customer is set or changed - sets up related default values
Parameters
bcDebtorCode | input-output | character | |
icDInvoiceType | input | character | |
itDInvoicePostingDate | input | date | |
itDInvoiceDate | input | date | |
icOwnVatCurrencyCode | input | character | |
itDInvoiceTaxPointDate | input | date | |
icDInvoiceRowID | input | character | |
idDInvoiceOriginalTC | input | decimal | |
iiDInvoicePostingYear | input | integer | |
icDInvoiceJournalCode | input | character | |
iiDInvoiceVoucher | input | integer | |
ocBusinessRelationCode | output | character | |
ocBusinessRelationName1 | output | character | |
ocDInvoiceDebtorVatNumber | output | character | |
ocCurrencyCode | output | character | |
ocNormalPaymentConditionCode | output | character | |
ocNormalPaymentConditionType | output | character | |
ocReasonCode | output | character | |
olDInvoiceIsTaxable | output | logical | |
ocDebtorTaxClass | output | character | |
ocDebtorTaxUsage | output | character | |
ocDebtorTaxZone | output | character | |
oiDebtorCnControlGLProfileId | output | integer | |
oiDebtorInvControlGLProfileId | output | integer | |
oiDebtorDivisionProfileId | output | integer | |
ocDebtVatNumberCountryCode | output | character | |
ocTransactionStartCountryCode | output | character | |
oiShipFromAddressId | output | integer | |
olControlGlIsDivisionAccount | output | logical | |
ocDivisionCode | output | character | |
ocCostCentreCode | output | character | |
ocProjectCode | output | character | |
odDInvoiceExchangeRate | output | decimal | |
odDInvoiceRateScale | output | decimal | |
otDInvoiceDueDate | output | date | |
otDInvoiceDiscountDueDate | output | date | |
odDInvoiceVatExchangeRate | output | decimal | |
odDInvoiceVatRateScale | output | decimal | |
oiDebtorId | output | integer | |
olBusinessRelationIsInterCo | output | logical | |
ocBusinessRelationICCode | output | character | |
olCountryIsEUCountry | output | logical | |
tApiDInvoiceStage | output | temp-table | |
ocDefaultJournalCode | output | character | |
tShipToShipFromAddress | output | temp-table | |
oiDInvoiceVoucher | output | integer | |
oiDebtorPrepayControlGLProfileId | output | integer | Control gl profile id of prepayment |
oiDebtorSalesAccGLProfileId | output | integer | gl profile id of sales account |
oiDebtorFinChgGLProfileId | output | integer | gl profile id of finance charge |
ocControlGLCode | output | character | Control gl account |
oiControlGLID | output | integer | ID of the control gl account |
oiBusinessRelationID | output | integer | Business Relation ID |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bdinvoice.p)
if bcDebtorCode = ?
then assign bcDebtorCode = "":U.
if bcDebtorCode = "":U
then return.
find first tDInvoice where
tDInvoice.tc_Rowid = icDInvoiceRowId
no-error.
if not available tDInvoice
then do:
<M-17 run SetMessage
(input #T-18'Invalid Customer Invoice':255(999890856)T-18# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-9372':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign oiReturnStatus = -3.
return.
end.
empty temp-table tShipToShipFromAddress.
<Q-16 run DebtorForDIDefault (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input bcDebtorCode, (DebtorCode)
output dataset tqDebtorForDIDefault) in BDebtor >
find first tqDebtorForDIDefault no-error.
if not available tqDebtorForDIDefault
then do:
assign oiReturnStatus = -4.
return.
end.
else do:
find first tqDebtorForDIDefault
where tqDebtorForDIDefault.tcDebtorCode = bcDebtorCode no-error.
if not available tqDebtorForDIDefault
then do:
find tqDebtorForDIDefault
where tqDebtorForDIDefault.tcDebtorCode BEGINS bcDebtorCode no-error.
/* if there's only one record */
if available tqDebtorForDIDefault
then do:
assign bcDebtorCode = tqDebtorForDIDefault.tcDebtorCode.
end.
/* Ambiguous records will not be found and available will be false */
else do:
oiReturnStatus = -4.
return.
end.
end.
end.
assign ocBusinessRelationCode = tqDebtorForDIDefault.tcBusinessRelationCode
ocBusinessRelationName1 = tqDebtorForDIDefault.tcBusinessRelationName1
olBusinessRelationIsInterco = tqDebtorForDIDefault.tlBusinessRelationIsInterco
ocBusinessRelationICCode = if olBusinessRelationIsInterco
then tqDebtorForDIDefault.tcBusinessRelationICCode
else "":U
ocDInvoiceDebtorVatNumber = tqDebtorForDIDefault.tcDebtorTaxIDState
ocCurrencyCode = tqDebtorForDIDefault.tcCurrencyCode
ocNormalPaymentConditionCode = tqDebtorForDIDefault.tcPaymentConditionCode
ocNormalPaymentConditionType = tqDebtorForDIDefault.tcPaymentConditionPaymentTyp
ocReasonCode = tqDebtorForDIDefault.tcReasonCode
olDInvoiceIsTaxable = tqDebtorForDIDefault.tlDebtorIsTaxable
ocDebtorTaxClass = tqDebtorForDIDefault.tcTxclTaxCls
ocDebtorTaxUsage = tqDebtorForDIDefault.tcTxuTaxUsage
ocDebtorTaxZone = tqDebtorForDIDefault.tcTxzTaxZone
oiDebtorCnControlGLProfileId = tqDebtorForDIDefault.tiCnControlGLProfile_ID
oiDebtorInvControlGLProfileId = tqDebtorForDIDefault.tiInvControlGLProfile_ID
oiDebtorPrepayControlGLProfileId = tqDebtorForDIDefault.tiPrePayControlGLProfile_ID
oiDebtorSalesAccGLProfileId = tqDebtorForDIDefault.tiSalesAccountGLProfile_ID
oiDebtorFinChgGLProfileId = tqDebtorForDIDefault.tiFinChgGLProfile_ID
oiDebtorDivisionProfileId = tqDebtorForDIDefault.tiDivisionProfile_ID
oiDebtorId = tqDebtorForDIDefault.tiDebtor_ID
oiBusinessRelationID = tqDebtorForDIDefault.tiBusinessRelation_ID.
/* get control account */
assign viControlGLProfileId = if icDInvoiceType = {&INVOICETYPE-PREPAYMENT}
then tqDebtorForDIDefault.tiPrePayControlGLProfile_ID
else if icDInvoiceType = {&INVOICETYPE-INVOICE} or
icDInvoiceType = {&INVOICETYPE-FINANCECHARGE} or
icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then tqDebtorForDIDefault.tiInvControlGLProfile_ID
else tqDebtorForDIDefault.tiCnControlGLProfile_ID.
if viControlGLProfileId = ? or viControlGLProfileId = 0
then assign vlError = true.
else do:
<Q-19 run ProfileLinkByGL (all) (Read) (NoCache)
(input viControlGLProfileId, (GlProfileId)
input tDInvoice.Company_ID, (CompanyId)
output dataset tqProfileLinkByGL) in BProfile >
find first tqProfileLinkByGl where
tqProfileLinkByGL.tiProfile_ID = viControlGLProfileId
no-error.
if not available tqProfileLinkByGl
then assign vlError = true.
end.
if vlError
then do:
<M-23 run SetMessage
(input #T-24'The specified customer control account is not defined in the system.':150(49402)T-24# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'D':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-9373':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign oiReturnStatus = -1.
return.
end.
assign tDInvoice.tcControlGLCode = tqProfileLinkByGL.tcGLCode
tDInvoice.ControlGL_ID = tqProfileLinkByGL.tiGL_ID
/* needed on ui for drafts, otherwise ui overwrite values of business */
ocControlGLCode = tqProfileLinkByGL.tcGLCode
oiControlGLID = tqProfileLinkByGL.tiGL_ID.
<Q-8 run AddressForInvoiceDefault (all) (Read) (NoCache)
(input tqDebtorForDIDefault.tiBusinessRelation_ID, (BusinessRelationId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
output dataset tqAddressForInvoiceDefault) in BBusinessRelation >
find first tqAddressForInvoiceDefault where
tqAddressForInvoiceDefault.tiBusinessRelation_ID = tqDebtorForDIDefault.tiBusinessRelation_ID and
tqAddressForInvoiceDefault.tcAddressTypeCode = {&ADDRESSTYPECODESYSTEM-HEADOFFICE}
no-error.
assign ocDebtVatNumberCountryCode = if available tqAddressForInvoiceDefault
then tqAddressForInvoiceDefault.tcCountryCode
else "":U
ocTransactionStartCountryCode = if available tqAddressForInvoiceDefault
then tqAddressForInvoiceDefault.tcCountryCode
else "":U
olCountryIsEUCountry = if available tqAddressForInvoiceDefault
then tqAddressForInvoiceDefault.tlCountryIsEUCountry
else false
oiShipFromAddressId = if available tqAddressForInvoiceDefault
then tqAddressForInvoiceDefault.tiAddress_ID
else 0.
<M-9 run DefaultValuesInvoiceType
(input icDInvoiceRowID (icDInvoiceRowId),
input icDInvoiceType (icDInvoiceType),
input tqDebtorForDIDefault.tiInvControlGLProfile_ID (iiDebtorInvControlGLProfileId),
input tqDebtorForDIDefault.tiCnControlGLProfile_ID (iiDebtorCnControlGLProfileId),
input tqDebtorForDIDefault.tiDivisionProfile_ID (iiDivisionProfileId),
input iiDInvoiceVoucher (iiOldDInvoiceVoucher),
input icDInvoiceJournalCode (icOldJournalCode),
input iiDInvoicePostingYear (iiJournalYear),
output olControlGLIsDivisionAccount (olControlGLIsDivisionAccount),
output ocDivisionCode (ocDivisionCode),
output ocCostCentreCode (ocCostCentreCode),
output ocProjectCode (ocProjectCode),
output ocDefaultJournalCode (ocJournalCode),
output oiDInvoiceVoucher (oiDInvoiceVoucher),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
<M-10 run DefaultValuesCurrency
(input tqDebtorForDIDefault.tcCurrencyCode (icCurrencyCode),
input tqDebtorForDIDefault.tiCurrency_ID (iiCurrencyId),
input itDInvoicePostingDate (itDInvoicePostingDate),
input icOwnVatCurrencyCode (icOwnVatCurrencyCode),
input itDInvoiceTaxPointDate (itDInvoiceTaxPointDate),
output odDInvoiceExchangeRate (odDInvoiceExchangeRate),
output odDInvoiceRateScale (odDInvoiceRateScale),
output odDInvoiceVatExchangeRate (odDInvoiceVatExchangeRate),
output odDInvoiceVatRateScale (odDInvoiceVatRateScale),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
assign viPaymentConditionID = if tqDebtorForDIDefault.tcPaymentConditionPaymentTyp = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED}
then tqDebtorForDIDefault.tiNormalPaymentCondition_ID
else ?.
<M-11 run DefaultValuesPaymentCondition
(input ? (icPaymentConditionCode),
input viPaymentConditionId (iiPaymentConditionID),
input itDInvoiceDate (itDInvoiceDate),
input icDInvoiceRowID (icDInvoiceRowID),
input idDInvoiceOriginalTC (idDInvoiceOriginalTC),
input ocCurrencyCode (icCurrencyCode),
input tqDebtorForDIDefault.tcPaymentConditionPaymentTyp (icPaymentConditionPaymentType),
input tqDebtorForDIDefault.tcPaymentConditionPeriodType (icPaymentConditionPeriodType),
input tqDebtorForDIDefault.ttPaymentConditionBaseDate (itPaymentConditionBaseDate),
input tqDebtorForDIDefault.tiPaymentConditionDaysMonths (iiPaymentConditionDaysMonths),
input tqDebtorForDIDefault.tiPaymentConditionSupplDays (iiPaymentconditionSupplDays),
input tqDebtorForDIDefault.tiPaymentConditionBaseDays (iiPaymentConditionBaseDays),
input tqDebtorForDIDefault.tiPaymentConditionDueDays (iiPaymentConditionDueDays),
input tqDebtorForDIDefault.tcPaymentConditionDescript (icPaymentConditionDescription),
input tqDebtorForDIDefault.tdPaymentConditionPercentage (idPaymentConditionPercentage),
input tqDebtorForDIDefault.tcPaymentConditionPdDiscType (icPaymentConditionPdtypediscount),
input tqDebtorForDIDefault.tiPaymentConditionDayMthDisc (iiPaymentConditionDayMthsDisc),
input tqDebtorForDIDefault.tiPaymentConditionSupDayDisc (iiPaymentConditionSupDaysDisc),
output ocNormalPaymentConditionType (ocPaymentConditionPaymentType),
output otDInvoiceDueDate (otDInvoiceDueDate),
output otDInvoiceDiscountDueDate (otDInvoiceDiscountDueDate),
output tApiDInvoiceStage (tApiDInvoiceStage),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
create tShipToShipFromAddress.
<M-12 run DefaultValuesShipFromShipTo
(input tqDebtorForDIDefault.tiDebtor_ID (iiDebtorId),
input bcDebtorCode (icDebtorCode),
output tShipToShipFromAddress.tcShipToBusinessRelationCode (ocShipToBusinessRelationCode),
output tShipToShipFromAddress.tcShipToTypeCode (ocShipToAddressTypeCode),
output tShipToShipFromAddress.tcShipToStreet1 (ocShipToAddressStreet1),
output tShipToShipFromAddress.tcShipToStreet2 (ocShipToAddressStreet2),
output tShipToShipFromAddress.tcShipToStreet3 (ocShipToAddressStreet3),
output tShipToShipFromAddress.tcShipToZip (ocShipToAddressZip),
output tShipToShipFromAddress.tcShipToCity (ocShipToAddressCity),
output tShipToShipFromAddress.tcShipToState (ocShipToAddressState),
output tShipToShipFromAddress.tcShipToCountryCode (ocShipToCountryCode),
output tShipToShipFromAddress.tlShipToIsTaxInCity (olShipToAddressIsTaxInCity),
output tShipToShipFromAddress.tlShipToCountryIsEUCountry (olShipToCountryIsEUCountry),
output tShipToShipFromAddress.tcShipToTaxZone (ocShipToTxzTaxZone),
output tShipToShipFromAddress.tiShipToId (oiShipToAddressId),
output tShipToShipFromAddress.tcShipToCode (ocDebtorShipToCode),
output tShipToShipFromAddress.tcShipFromBusinessRelationCode (ocShipFromBusinessRelationCode),
output tShipToShipFromAddress.tcShipFromTypeCode (ocShipFromAddressTypeCode),
output tShipToShipFromAddress.tcShipFromStreet1 (ocShipFromAddressStreet1),
output tShipToShipFromAddress.tcShipFromStreet2 (ocShipFromAddressStreet2),
output tShipToShipFromAddress.tcShipFromStreet3 (ocShipFromAddressStreet3),
output tShipToShipFromAddress.tcShipFromZip (ocShipFromAddressZip),
output tShipToShipFromAddress.tcShipFromCity (ocShipFromAddressCity),
output tShipToShipFromAddress.tcShipFromState (ocShipFromAddressState),
output tShipToShipFromAddress.tcShipFromCountryCode (ocShipFromCountryCode),
output tShipToShipFromAddress.tcShipFromStateTaxId (ocShipFromTaxIdState),
output tShipToShipFromAddress.tlShipFromCountryIsEUCountry (olShipFromCountryIsEUCountry),
output tShipToShipFromAddress.tcShipFromTaxZone (ocShipFromTaxZone),
output tShipToShipFromAddress.tiShipFromAddressID (oiShipFromAddressId),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
/* ====================================================================================================== */
/* Check credit limit of customer */
/* ====================================================================================================== */
<I-13 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BDebtor"}>
<M-14 run ApiCheckCreditLimit
(input oiDebtorId (iiDebtorId),
input bcDebtorCode (icDebtorCode),
input 0 (idCurrentAmount),
input 0 (idOldAmount),
input ocCurrencyCode (icCurrencyCode),
input {&DEBTORCREDITLIMIT-BEFOREDI} (icContext),
input itDInvoicePostingDate (itExchangeRateDate),
output viLocalReturnStatus (oiReturnStatus)) in BDebtor>
<I-15 {bFcCloseAndStopInstance
&CLASS = "BDebtor"}>
if viLocalReturnStatus < 0 or (viLocalReturnStatus > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viLocalReturnStatus.
if viLocalReturnStatus < 0
then return.