project QadFinancials > class BDInvoice > method ApiStdMaintainTTWithExtPostDetail
Description
This method is a submethod of ApiStdMaintainTTWithExtPost.
this method just copies the detail input temp-tables into the DB tables.
Parameters
icAction | input | character | This parameter defines what should happen with the input data : -SAVE: Save the data if there were no errors, -SAVESTORE : Save the data if there were no errors. If there were errors, save as draft. -STORE : Save the data as draft -VALIDATE : Validate the input data, but do no save the data. |
bcLstReturn | input-output | character | Char 4 separated list with the return status of the newly created main-table records. Zero means not errors occurred. |
bcLstPrimKey | input-output | character | Character 4 separated list with the primary keys of the newly created main-table records. The fields of the primary key are separated with Character 2. |
bcLstRowId | input-output | character | Char 4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records. |
olSaveAsDraft | output | logical | Output parameter that keeps if the data is saved as draft or not |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bdinvoice.p)
/* Add the Stage details */
for each tApiDInvoiceStage where
tApiDInvoiceStage.tc_ParentRowid = tApiDInvoice.tc_Rowid
by tApiDInvoiceStage.tc_Rowid:
<M-56 run AddDetailLine
(input 'DInvoiceStage':U (icTable),
input tDInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end.
else assign vlWarningsFound = true.
end.
buffer-copy tApiDInvoiceStage
except tApiDInvoiceStage.DInvoiceStage_ID
tApiDInvoiceStage.DInvoice_ID
tApiDInvoiceStage.tc_ParentRowid
tApiDInvoiceStage.tc_Rowid
tApiDInvoiceStage.tc_Status
to tDInvoiceStage.
end.
/* Add the VAT details */
for each tApiDInvoiceVat where
tApiDInvoiceVat.tc_ParentRowid = tApiDInvoice.tc_Rowid
by tApiDInvoiceVat.tc_Rowid :
if tApiDInvoiceVat.DInvoiceVatVatBaseCreditTC = ? then assign tApiDInvoiceVat.DInvoiceVatVatBaseCreditTC = 0.
if tApiDInvoiceVat.DInvoiceVatVatBaseDebitTC = ? then assign tApiDInvoiceVat.DInvoiceVatVatBaseDebitTC = 0.
if tApiDInvoiceVat.DInvoiceVatNTBaseDebitTC = ? then assign tApiDInvoiceVat.DInvoiceVatNTBaseDebitTC = 0.
if tApiDInvoiceVat.DInvoiceVatNTBaseCreditTC = ? then assign tApiDInvoiceVat.DInvoiceVatNTBaseCreditTC = 0.
if tApiDInvoiceVat.DInvoiceVatVatCreditTC = ? then assign tApiDInvoiceVat.DInvoiceVatVatCreditTC = 0.
if tApiDInvoiceVat.DInvoiceVatVatDebitTC = ? then assign tApiDInvoiceVat.DInvoiceVatVatDebitTC = 0.
/* Create a new DInvoiceVat and copy all data */
<M-55 run AddDetailLine
(input 'DInvoiceVat':U (icTable),
input tDInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end.
else assign vlWarningsFound = true.
end.
buffer-copy tApiDInvoiceVat
except DInvoiceVat_ID
DInvoice_ID
tc_rowid
tc_ParentRowid
tc_status
to tDInvoiceVat.
end.
/* Add the DI-Bank details */
for each tApiDInvoiceBank where
tApiDInvoiceBank.tc_ParentRowid = tApiDInvoice.tc_Rowid
by tApiDInvoiceBank.tc_Rowid :
<M-58 run AddDetailLine
(input 'DInvoiceBank':U (icTable),
input tDInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end.
else assign vlWarningsFound = true.
end.
buffer-copy tApiDInvoiceBank
except tApiDInvoiceBank.DInvoiceBank_ID
tApiDInvoiceBank.DInvoice_ID
tApiDInvoiceBank.tc_ParentRowid
tApiDInvoiceBank.tc_Rowid
tApiDInvoiceBank.tc_Status
to tDInvoiceBank.
/* Add the DI-BankPayCode details */
for each tApiDInvoiceBankPayCode where
tApiDInvoiceBankPayCode.tc_ParentRowid = tApiDInvoice.tc_Rowid
by tApiDInvoiceBankPayCode.tc_Rowid :
<M-60 run AddDetailLine
(input 'DInvoiceBankPayCode':U (icTable),
input tDInvoiceBank.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end.
else assign vlWarningsFound = true.
end.
buffer-copy tApiDInvoiceBankPayCode
except tApiDInvoiceBankPayCode.DInvoiceBankPayCode_ID
tApiDInvoiceBankPayCode.DInvoiceBank_ID
tApiDInvoiceBankPayCode.tc_ParentRowid
tApiDInvoiceBankPayCode.tc_Rowid
tApiDInvoiceBankPayCode.tc_Status
to tDInvoiceBankPayCode.
/* have to set the PayFormatGroupID - not set as a related business field */
if (vlStartedQueryPayCodeGroupByID <> true)
then do:
<Q-69 run PayFormatGroupForID (Start) in BPaymentFormat >
assign vlStartedQueryPayCodeGroupByID = true.
end. /* if vlStartedQueryPayCodeGroupByID */
<Q-70 run PayFormatGroupForID (all) (Read) (NoCache)
(input tApiDInvoiceBank.tcPayFormatTypeCode, (PayFormatTypeCode)
input tApiDInvoiceBankPayCode.tcPayFormatGroupCode, (PayFormatGroupCode)
output dataset tqPayFormatGroupForID) in BPaymentFormat >
find first tqPayFormatGroupForID where
tqPayFormatGroupForID.tcPayFormatGroupCode = tApiDInvoiceBankPayCode.tcPayFormatGroupCode and
tqPayFormatGroupForID.tcPayFormatTypeCode = tApiDInvoiceBank.tcPayFormatTypeCode
no-lock no-error.
if available tqPayFormatGroupForID
then assign tDInvoiceBankPayCode.PayFormatGroup_ID = tqPayFormatGroupForID.tiPayFormatGroup_ID.
else do:
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-75'The payment attribute (tcpayFormatGroupCode) with name &1 is not defined for the payment format &2.':255(73463996)T-75# , tApiDInvoiceBankPayCode.tcPayFormatGroupCode, tApiDInvoiceBank.tcPayFormatTypeCode))
olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
<M-71 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-9750':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
end. /* end for each tApiDInvoiceBankPayCode */
end. /* end for each tApiDInvoiceBank */
if (vlStartedQueryPayCodeGroupByID = true)
then do:
<Q-72 run PayFormatGroupForID (Stop) in BPaymentFormat >
end. /* if vlStartedQueryPayCodeGroupByID */
/* Add the OpInfo details */
for each tApiDInvoiceOpInfo where
tApiDInvoiceOpInfo.tc_ParentRowid = tApiDInvoice.tc_Rowid
by tApiDInvoiceOpInfo.tc_Rowid:
<M-59 run AddDetailLine
(input 'DInvoiceOpInfo':U (icTable),
input tDInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end.
else assign vlWarningsFound = true.
end.
buffer-copy tApiDInvoiceOpInfo
except tApiDInvoiceOpInfo.DInvoiceOpInfo_ID
tApiDInvoiceOpInfo.DInvoice_ID
tApiDInvoiceOpInfo.tc_ParentRowid
tApiDInvoiceOpInfo.tc_Rowid
tApiDInvoiceOpInfo.tc_Status
to tDInvoiceOpInfo.
end.
/* Add DInvoicePosting details (ControlAccount) */
<Q-63 run DebtorByDebtor (first) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
input tDInvoice.Debtor_ID, (DebtorId)
input if tDInvoice.Debtor_ID = 0 then tDInvoice.tcDebtorCode else '':U, (DebtorCode)
output dataset tqDebtorByDebtor) in BDebtor >
find first tqDebtorByDebtor NO-error.
if available tqDebtorByDebtor
then do:
assign viControlGLProfileId = if tDInvoice.DInvoiceType = {&INVOICETYPE-PREPAYMENT}
then tqDebtorByDebtor.tiPrePayControlGLProfile_ID
else if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then tqDebtorByDebtor.tiInvControlGLProfile_ID
else tqDebtorByDebtor.tiCnControlGLProfile_ID.
<Q-64 run ProfileLinkByGL (all) (Read) (NoCache)
(input viControlGLProfileId, (GlProfileId)
input viCompanyId, (CompanyId)
output dataset tqProfileLinkByGL) in BProfile >
find first tqProfileLinkByGl no-error.
if available tqProfileLinkByGl
then assign vcControlGLCode = tqProfileLinkByGL.tcGLCode.
assign tDInvoice.tcControlGLCode = vcControlGLCode.
end.
find first tApiDInvoicePosting where
tApiDInvoicePosting.tc_ParentRowid = tApiDInvoice.tc_Rowid
no-error.
if available tApiDInvoicePosting
then do:
/* Create a new DInvoicePosting and copy all data */
<M-52 run AddDetailLine
(input 'DInvoicePosting':U (icTable),
input tDInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end.
else assign vlWarningsFound = true.
end.
buffer-copy tApiDInvoicePosting
except DInvoicePosting_ID DInvoice_ID tc_rowid tc_ParentRowid tc_status
to tDInvoicePosting.
/* fill in the dinvoice voucher, search in instance */
<M-53 run GetPostingInfoByPostingId
(input tDInvoicePosting.Posting_ID (iiPostingId),
input vcControlGLCode (icGLCode),
output viDummy (oiPostingPeriodYear),
output vcDummy (ocPostingJournalCode),
output tDInvoice.DInvoiceVoucher (oiPostingVoucher),
output viDummy (oiPostingPeriodPeriod),
output viControlPostingLineId (oiPostingLineId),
output vdControlPostingDebitTC (odPostingLineDebitTC),
output vdControlPostingCreditTC (odPostingLineCreditTC),
output vdControlPostingDebitLC (odPostingLineDebitLC),
output vdControlPostingCreditLC (odPostingLineCreditLC),
output vdControlPostingDebitCC (odPostingLineDebitCC),
output vdControlPostingCreditCC (odPostingLineCreditCC),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end.
else assign vlWarningsFound = true.
end.
/* Create a new DInvoiceMovement and copy all data */
assign vlControlPostingError = false.
if viControlPostingLineId <> ? and viControlPostingLineId <> 0
then do:
<M-48 run AddDetailLine
(input 'DInvoiceMovement':U (icTable),
input tDInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then assign vlControlPostingError = true.
assign tDInvoiceMovement.DInvoiceMovementType = {&MOVEMENTTYPE-INITIAL}
tDInvoiceMovement.PostingLine_ID = viControlPostingLineId.
end.
else assign vlControlPostingError = true.
/* posting must be on control account, and on right side */
if vlControlPostingError = true
then do:
assign oiReturnStatus = -1
vcMessage = trim(substitute(#T-74'The posting must be on control account (&1): for &2 or &3 on &4, for &5 or &6 on &7.':255(13948)T-74# , vcControlGLCode, {&INVOICETYPE-INVOICE-TR}, {&INVOICETYPE-INVOICECORRECTION-TR}, {&CREDITDEBITABBREVIATION-DEBIT-TR}, {&INVOICETYPE-CREDITNOTE-TR}, {&INVOICETYPE-CREDITNOTECORRECTION-TR}, {&CREDITDEBITABBREVIATION-CREDIT-TR} ))
olSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
<M-54 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':u (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-9748':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
return.
end.
end.