project QadFinancials > class BDInvoice > method DefaultValuesGeneralInfo
Description
Populate the associated tables once the keyfields are set
Parameters
| icDInvoiceRowId | input | character | |
| iiDInvoiceId | input | integer | |
| iiPeriodId | input | integer | |
| iiDebtorId | input | integer | |
| icDebtorCode | input | character | |
| idDInvoiceOriginalTC | input | decimal | |
| iiCurrencyId | input | integer | |
| icCurrencyCode | input | character | |
| icDocumentReference | input | character | |
| itDInvoiceTaxPointDate | input | date | |
| icShipFromTaxZone | input | character | |
| icShipToTaxZone | input | character | |
| ictxclTaxClass | input | character | |
| icTxuTaxUsage | input | character | |
| idDInvoiceExchangeRate | input | decimal | |
| idDInvoiceRateScale | input | decimal | |
| icPaymentConditionCode | input | character | |
| itDInvoicePostingDate | input | date | |
| ilDInvoiceIsTaxable | input | logical | |
| ilDInvoiceIsTaxExcluded | input | logical | |
| icDInvoiceType | input | character | |
| ilShipToAddressIsTaxInCity | input | logical | |
| idDInvoiceVatExchangeRate | input | decimal | |
| idDInvoiceVatRateScale | input | decimal | |
| iiDInvoicePostingYear | input | integer | |
| iiDInvoicePostingPeriod | input | integer | |
| iiDIvisionId | input | integer | |
| icDivisionCode | input | character | |
| iiJournalId | input | integer | |
| icJournalCode | input | character | |
| iiDInvoiceVoucher | input | integer | |
| icDInvoiceDescription | input | character | |
| idDInvoiceOriginalLC | input | decimal | |
| icDInvoiceDIText | input | character | |
| itDInvoiceDate | input | date | |
| icCostCentreCode | input | character | |
| icProjectCode | input | character | |
| icShipToCountryCode | input | character | |
| ilShipToCountryIsEUCountry | input | logical | |
| iiShipFromAddressId | input | integer | |
| iiShipToAddressId | input | integer | |
| icBusinessRelationCode | input | character | |
| iiInvControlGLProfileId | input | integer | |
| iiCnControlGLProfileId | input | integer | |
| icBusinessRelationICCode | input | character | |
| icShipFromCountryCode | input | character | |
| ilShipFromCountryIsEUCountry | input | logical | |
| iiPrepayControlGLProfileId | input | integer | Control GL Profile Id for prepayment |
| iiSalesAccGLProfileId | input | integer | GL Profile ID for sales account |
| iiFinChgGLProfileId | input | integer | GL Profile Id for finance charge |
| icSoldToDebtorCode | input | character | |
| ocTxenvTaxEnv | output | character | |
| oiJEInstanceId | output | integer | |
| oiDIPostingId | output | integer | |
| tApiDInvoice | output | temp-table | |
| tApiDInvoiceBank | output | temp-table | |
| tApiDInvoiceBankPayCode | output | temp-table | |
| tApiDInvoiceVat | output | temp-table | |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bdinvoice.p)
if iiCurrencyId = ? then assign iiCurrencyId = 0.
if icCurrencyCode = ? then assign icCurrencyCode = "":U.
empty temp-table tDIAccount.
empty temp-table tApiDInvoice.
empty temp-table tApiDInvoiceBank.
empty temp-table tApiDInvoiceBankPayCode.
empty temp-table tApiDInvoiceVat.
empty temp-table tDefaultSafsDI.
if iiDebtorId = 0 or
iiDebtorId = ?
then do:
assign vcMessageText = #T-1'The customer &1 (&2) is not defined in the system or is invalid.':255(1757)t-1#.
<M-2 run SetMessage
(input vcMessageText (icMessage),
input icDebtorCode (icArguments),
input ' ':U (icFieldName),
input ' ':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input icDInvoiceRowId (icRowid),
input 'QadFin-7647':U (icFcMsgNumber),
input ' ':U (icFcExplanation),
input ' ':U (icFcIdentification),
input ' ':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign oiReturnStatus = -1.
return.
end.
if iiCurrencyId = 0 and icCurrencyCode = "":U
then do:
assign vcMessageText = trim(substitute(#T-8'Invalid currency: &1 .':255(999890328)T-8#, icCurrencyCode))
oiReturnStatus = -1.
<M-7 run SetMessage
(input vcMessageText (icMessage),
input '':U (icArguments),
input ' ':U (icFieldName),
input ' ':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input icDInvoiceRowId (icRowid),
input 'QadFin-9018':U (icFcMsgNumber),
input ' ':U (icFcExplanation),
input ' ':U (icFcIdentification),
input ' ':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
else do:
<Q-11 assign vlFcQueryRecordsAvailable = CurrencyPrim (NoCache)
(input if iiCurrencyId = 0 then icCurrencyCode else ?, (CurrencyCode)
input iiCurrencyId, (Currency_ID)) in BCurrency >
if not vlFcQueryRecordsAvailable
then do:
assign vcMessageText = trim(substitute(#T-12'Invalid currency: &1 .':255(999890328)T-12#, (if iiCurrencyId = 0 then icCurrencyCode else string(iiCurrencyId))))
oiReturnStatus = -1.
<M-9 run SetMessage
(input vcMessageText (icMessage),
input '':U (icArguments),
input ' ':U (icFieldName),
input ' ':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input icDInvoiceRowId (icRowid),
input 'QadFin-9019':U (icFcMsgNumber),
input ' ':U (icFcExplanation),
input ' ':U (icFcIdentification),
input ' ':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
end.
if viCompanyCCId <> 0 and viCompanyCCId <> ?
then do:
if icCurrencyCode = vcCompanyCC
then assign vdCCExchangeRate = 1
vdCCExchangeRateScale = 1.
if vlDomainIsStatutory = false
then assign vdCCExchangeRate = idDInvoiceExchangeRate
vdCCExchangeRateScale = idDInvoiceRateScale.
else do:
<M-47 run GetExRateByEntityInvoiceFlag
(input itDInvoicePostingDate (itDInvoicePostingDate),
input itDInvoiceTaxPointDate (itDInvoiceTaxPointDate),
input ? (iiFromCurrencyId),
input icCurrencyCode (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyId),
input vcCompanyCC (icToCurrencyCode),
input ? (iiExchangeRateTypeId),
input {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode),
output vdCCExchangeRate (odDInvoiceExchangeRate),
output vdCCExchangeRateScale (odDInvoiceRateScale),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
end.
end.
/* Get default bank number for the selected customer */
<M-3 run DefaultValuesBank
(input iiDInvoiceId (iiDInvoiceId),
input icDInvoiceRowId (icRowId),
input idDInvoiceOriginalTC (idDInvoiceOriginalTC),
input iiDebtorId (iiDebtorId),
output tApiDInvoiceBank (tApiDInvoiceBank),
output tApiDInvoiceBankPayCode (tApiDInvoiceBankPayCode),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
/* Tax stuff */
<M-4 run DefaultValuesTax
(input iiDInvoiceId (iiDinvoiceId),
input icCurrencyCode (icCurrencyCode),
input icDocumentReference (icDocumentReference),
input itDInvoiceTaxPointDate (itTaxPointDate),
input icShipFromTaxZone (icShipFromTaxZone),
input icShipToTaxZone (icShipToTaxZone),
input icDebtorCode (icDebtorCode),
input icTxclTaxClass (icTxclTaxClass),
input icTxuTaxUsage (icTxuTaxUsage),
input idDInvoiceOriginalTC (idInvoiceAmountTC),
input idDInvoiceExchangeRate (idExchangeRate),
input idDInvoiceRateScale (idExchangeRateScale),
input icPaymentConditionCode (icPaymentConditionCode),
input itDInvoicePostingDate (itPostingDate),
input ilDInvoiceIsTaxable (ilTaxable),
input ilDInvoiceIsTaxExcluded (ilDInvoiceIsTaxExcluded),
input icDInvoiceType (icInvoiceType),
input ilShipToAddressIsTaxInCity (ilShipToAddressIsTaxInCity),
input idDInvoiceVatExchangeRate (idVatExchangeRate),
input idDInvoiceVatRateScale (idVatRateScale),
input vdCCExchangeRate (idCCExchangeRate),
input vdCCExchangeRateScale (idCCExchangeRateScale),
input iiShipToAddressId (iiShipToAddressID),
input iiShipFromAddressId (iiShipFromAddressID),
output ocTxenvTaxEnv (ocTxenvTaxEnv),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
for each tDInvoiceVat where
tDInvoiceVat.tc_Status <> "D":U:
create tApiDInvoiceVat.
raw-transfer tDInvoiceVat to tApiDInvoiceVat.
end.
/* Get Default Debtor SAF's here so they don't have to be fetched twice, in CreateDIPosting */
<Q-5 run DebtorSafDefaultsForDIDef (all) (Read) (NoCache)
(input iiDebtorId, (DebtorId)
output dataset tqDebtorSafDefaultsForDIDef) in BDebtor >
for each tqDebtorSafDefaultsForDIDef where
tqDebtorSafDefaultsForDIDef.tiDebtor_ID = iiDebtorId:
create tDefaultSafsDI.
assign tDefaultSafsDI.tcSafCode = tqDebtorSafDefaultsForDIDef.tcSafCode
tDefaultSafsDI.tcSafConceptCode = tqDebtorSafDefaultsForDIDef.tcSafConceptCode.
end.
/* Create CI Posting */
<M-6 run CreateDIPosting
(input iiDInvoiceId (iiDInvoiceId),
input iiPeriodId (iiPeriodId),
input iiDInvoicePostingYear (iiPeriodYear),
input iiDInvoicePostingPeriod (iiPeriodPeriod),
input itDInvoicePostingDate (itPostingDate),
input iiDebtorId (iiDebtorId),
input icDebtorCode (icDebtorCode),
input icDInvoiceType (icDInvoiceType),
input iiDivisionId (iiDivisionId),
input icDivisionCode (icDivisionCode),
input iiJournalId (iiJournalId),
input icJournalCode (icJournalCode),
input iiDInvoiceVoucher (iiVoucher),
input itDInvoiceTaxPointDate (itTaxPointDate),
input icDInvoiceDescription (icDescription),
input idDInvoiceOriginalTC (idInvoiceAmountTC),
input idDInvoiceOriginalLC (idInvoiceAmountLC),
input ? (idInvoiceAmountCC),
input iiCurrencyId (iiCurrencyId),
input icCurrencyCode (icCurrencyCode),
input idDInvoiceExchangeRate (idExchangeRate),
input idDInvoiceRateScale (idExchangeRateScale),
input icDInvoiceDIText (icDIText),
input itDInvoiceDate (itInvoiceDate),
input ' ':U (icPostingType),
input-output oiDIPostingId (biPostingId),
input-output viBJournalEntryCIID (biBJournalEntryId),
input tDIAccount (tDIAccount),
input-output tDInvoiceVat (tApiDInvoiceVat),
input ' ':U (icGLCode),
input icCostCentreCode (icCostCentreCode),
input icProjectCode (icProjectCode),
input false (ilOnlyControlAccount),
input icShipFromCountryCode (icShipFromCountryCode),
input icShipToCountryCode (icShipToCountryCode),
input ilShipFromCountryIsEUCountry (ilShipFromCountryIsEUCountry),
input ilShipToCountryIsEUCountry (ilShipToCountryIsEUCountry),
input icTxclTaxClass (icTxclTaxCls),
input icTxuTaxUsage (icTxuTaxUsage),
input icShipToTaxZone (icShipToTxzTaxZone),
input ocTxenvTaxEnv (icTxenvTaxEnv),
input icPaymentConditionCode (icPaymentCondition),
input ilShipToAddressIsTaxInCity (ilIsTaxInCityFromShipTo),
input ilDInvoiceIsTaxable (ilIsTaxable),
input icCostCentreCode (icControlCostCentreCode),
input icProjectCode (icControlProjectCode),
input iiShipFromAddressId (iiShipFromAddressId),
input iiShipToAddressId (iiShipToAddressId),
input icSoldToDebtorCode (icSoldToDebtorCode),
input ilDInvoiceIsTaxExcluded (ilDInvoiceIsTaxExcluded),
input icBusinessRelationCode (icBusinessRelationCode),
input icBusinessRelationICCode (icBusinessRelationICCode),
input iiInvControlGLProfileId (iiInvControlGLProfileId),
input iiCnControlGLProfileId (iiCnControlGLProfileId),
input iiPrepayControlGLProfileId (iiPrepayControlGLProfileId),
input iiSalesAccGLProfileId (iiSalesAccGLProfileId),
input iiFinChgGLProfileId (iiFinChgGLProfileId),
input icDivisionCode (icControlDivisionCode),
input 0 (iiDeductionControlGLProfileId),
input vdCCExchangeRate (idExchangeRateCC),
input vdCCExchangeRateScale (idExchangeRateScaleCC),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
if oiDIPostingId <> 0
then do:
/* If there has been any errors when creating the posting we need to make sure the postings that were created are removed from the instance */
if viBJournalEntryDIID = 0 or viBJournalEntryDIID = ?
then do:
<I-13 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "True"
&CLASS = "BJournalEntry"}>
assign vlBJEIsStartedFromDI = true.
end.
else do:
<I-14 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end.
for each tDinvoicePosting where
tDinvoicePosting.tc_parentrowid = tDinvoice.tc_rowid and
tDinvoicePosting.posting_id = oiDIPostingID:
delete tDinvoicePosting.
end.
<M-15 run MarkInstanceDataAsDeleted
(input oiDIPostingId (icPostingIDToDelete),
input '' (icPostingLineIDToDelete),
output vifcReturnSuper (oiReturnStatus)) in BJournalEntry>
<I-16 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
return.
end.
assign oiJEInstanceId = viBJournalEntryCIID.
find tDInvoice where
tDInvoice.tc_Rowid = icDInvoiceRowId
no-error.
if available tDInvoice
then do:
create tApiDInvoice.
raw-transfer tDInvoice to tApiDInvoice.
end.