project QadFinancials > class BDInvoice > method ApiStdMaintainTTWithExtPost

Description

This method is a submethod of ApiStdMaintainTT.

this method just copies the input temp-tables into the DB tables.
No DI Posting is made.


Parameters


icActioninputcharacterThis 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.
bcLstReturninput-outputcharacterChar 4 separated list with the return status of the newly created main-table records. Zero means not errors occurred.
bcLstPrimKeyinput-outputcharacterCharacter 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.
bcLstRowIdinput-outputcharacterChar 4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records.
olSaveAsDraftoutputlogicalOutput parameter that keeps if the data is saved as draft or not
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.ApiStdMaintainTT


program code (program9/bdinvoice.p)

assign oiReturnStatus = -98.

/* Initialise and Create new instance */
/* Validate the value for the Company */
assign vlWarningsFound = false.
<M-1 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BDInvoice> 
find first tDInvoice no-error.
if not available tDInvoice 
then assign viFcReturnSuper = -3.
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.
if tApiDInvoice.Company_ID <> 0 and
   tApiDInvoice.Company_ID <> ? and 
   tApiDInvoice.Company_ID <> viCompanyId
then do :
    assign vcMessage      = trim(substitute(#T-29'The entity of the customer invoice (&1) must match the current entity (&2).':255(14472)T-29#, string(tApiDInvoice.Company_ID),string(viCompanyId)))
           oiReturnStatus = -1
           bcLstReturn    = bcLstReturn  + chr(4) + string(-1)
           bcLstPrimKey   = bcLstPrimKey + chr(4) + "*":U
           bcLstRowid     = bcLstRowid   + chr(4) + "*":U
           vlSaveAsDraft  = false.
    <M-30 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-3354':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    Return.
end.
assign tDInvoice.Company_ID = viCompanyId.

/* Copy all data into the new Dinvoice                                                         */
/* Before continuing, we copy the primary-key-fields of the main table to the input parameters */
/* This is just to hold it there so it can be assigned to ocPrimKey if the save succeeds. This */
/* is done because tDInvoice is no longer available after the save. We use ocRowid in stead    */
buffer-copy tApiDInvoice 
    except DInvoice_ID  
           company_ID
           tc_rowid 
           tc_ParentRowid 
           tc_status
    to tDInvoice.
assign tApiDInvoice.DInvoice_ID        = tDInvoice.DInvoice_ID
       vcDInvoiceRowId                 = tDInvoice.tc_Rowid
       tDInvoice.tcLocalCurrencyCode   = vcCompanyLC
       tDInvoice.tdDInvoiceOriginalTC  = if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                         then tDInvoice.DInvoiceOriginalDebitTC
                                         else tDInvoice.DInvoiceOriginalCreditTC
       tDInvoice.tdDInvoiceOriginalLC  = if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                         then tDInvoice.DInvoiceOriginalDebitLC
                                         else tDInvoice.DInvoiceOriginalCreditLC
       tDInvoice.tdTotalAmountDebitTC  = tDInvoice.DInvoiceVatBaseDebitTC + tDInvoice.DInvoiceVatDebitTC
       tDInvoice.tdTotalAmountCreditTC = tDInvoice.DInvoiceVatBaseCreditTC + tDInvoice.DInvoiceVatCreditTC.

/* Default unfilled values */
assign tDInvoice.DInvoiceIsOpen           = true
       tDInvoice.DInvoiceIsSelected       = false
       tDInvoice.DInvoiceIsPaymentAllowed = false
       vcCommitNumber                     = vcCommitNumber + ",":U + tDInvoice.tc_Rowid.

/* If no ship from address is specified the default from the company head-office address */
if ((tDInvoice.ShipFromAddress_ID = 0 or tDInvoice.ShipFromAddress_ID = ?) and
    tDInvoice.tcShipFromBusinessRelationCode = "":U or tDInvoice.tcShipFromBusinessRelationCode = ?)
then do:
    <Q-34 run CompanyPropertyByActBusRelAddr (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        output dataset tqCompanyPropertyByActBusRelAddr) in BCompanyProperty >
        
    find first tqCompanyPropertyByActBusRelAddr no-error.
    if available tqCompanyPropertyByActBusRelAddr then do:
        <Q-36 run AddressByAddressBusRelType (all) (Read) (NoCache)
           (input ?, (AddressTypeId)
            input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
            input tqCompanyPropertyByActBusRelAddr.tiBusinessRelation_ID, (BusinessRelationId)
            input '':U, (BusinessRelationCode)
            input ?, (AddressId)
            output dataset tqAddressByAddressBusRelType) in BBusinessRelation >
    
        find first tqAddressByAddressBusRelType no-error.
        if available tqAddressByAddressBusRelType then do:
            assign tDInvoice.ShipFromAddress_ID = tqAddressByAddressBusRelType.tiAddress_ID
                tDInvoice.tcShipFromBusinessRelationCode = tqAddressByAddressBusRelType.tcBusinessRelationCode
                tDInvoice.tcShipFromAddressCity = tqAddressByAddressBusRelType.tcAddressCity
                tDInvoice.tcShipFromAddressState = tqAddressByAddressBusRelType.tcAddressState
                tDInvoice.tcShipFromAddressStreet1 = tqAddressByAddressBusRelType.tcAddressStreet1
                tDInvoice.tcShipFromAddressStreet2 = tqAddressByAddressBusRelType.tcAddressStreet2
                tDInvoice.tcShipFromAddressStreet3 = tqAddressByAddressBusRelType.tcAddressStreet3
                tDInvoice.tcShipFromAddressTypeCode = tqAddressByAddressBusRelType.tcAddressTypeCode
                tDInvoice.tcShipFromAddressZip = tqAddressByAddressBusRelType.tcAddressZip
                tDInvoice.tcShipFromBusinessRelationCode = tqAddressByAddressBusRelType.tcBusinessRelationCode
                tDInvoice.tcShipFromCountryCode = tqAddressByAddressBusRelType.tcCountryCode.  
                
        end. 
    end.
end.      

/* Populate the ship from address fields from the id */
if ((tDInvoice.ShipFromAddress_ID <> 0 and tDInvoice.ShipFromAddress_ID <> ?) and
    (tDInvoice.tcShipFromBusinessRelationCode = "":U or tDInvoice.tcShipFromBusinessRelationCode = ?))
then do:
    <Q-38 run AddressByAddressBusRelType (all) (Read) (NoCache)
       (input ?, (AddressTypeId)
        input '':U, (AddressTypeCode)
        input ?, (BusinessRelationId)
        input '':U, (BusinessRelationCode)
        input tDInvoice.ShipFromAddress_ID, (AddressId)
        output dataset tqAddressByAddressBusRelType) in BBusinessRelation >
    find first tqAddressByAddressBusRelType no-error.
    if available tqAddressByAddressBusRelType
    then assign tDInvoice.tcShipFromBusinessRelationCode = tqAddressByAddressBusRelType.tcBusinessRelationCode
                tDInvoice.tcShipFromAddressCity = tqAddressByAddressBusRelType.tcAddressCity
                tDInvoice.tcShipFromAddressState = tqAddressByAddressBusRelType.tcAddressState
                tDInvoice.tcShipFromAddressStreet1 = tqAddressByAddressBusRelType.tcAddressStreet1
                tDInvoice.tcShipFromAddressStreet2 = tqAddressByAddressBusRelType.tcAddressStreet2
                tDInvoice.tcShipFromAddressStreet3 = tqAddressByAddressBusRelType.tcAddressStreet3
                tDInvoice.tcShipFromAddressTypeCode = tqAddressByAddressBusRelType.tcAddressTypeCode
                tDInvoice.tcShipFromAddressZip = tqAddressByAddressBusRelType.tcAddressZip
                tDInvoice.tcShipFromBusinessRelationCode = tqAddressByAddressBusRelType.tcBusinessRelationCode
                tDInvoice.tcShipFromCountryCode = tqAddressByAddressBusRelType.tcCountryCode.
end.

/* Populate the ship to address fields from the id */
if ((tDInvoice.ShipToAddress_ID <> 0 and tDInvoice.ShipToAddress_ID <> ?) and
    (tDInvoice.tcShipToBusinessRelationCode = "":U or tDInvoice.tcShipToBusinessRelationCode = ?))
then do:
    <Q-39 run AddressByAddressBusRelType (all) (Read) (NoCache)
       (input ?, (AddressTypeId)
        input '':U, (AddressTypeCode)
        input ?, (BusinessRelationId)
        input '':U, (BusinessRelationCode)
        input tDInvoice.ShipToAddress_ID, (AddressId)
        output dataset tqAddressByAddressBusRelType) in BBusinessRelation >
    find first tqAddressByAddressBusRelType no-error.
    if available tqAddressByAddressBusRelType
    then assign tDInvoice.tcShipToBusinessRelationCode = tqAddressByAddressBusRelType.tcBusinessRelationCode
                tDInvoice.tcShipToAddressCity = tqAddressByAddressBusRelType.tcAddressCity
                tDInvoice.tcShipToAddressState = tqAddressByAddressBusRelType.tcAddressState
                tDInvoice.tcShipToAddressStreet1 = tqAddressByAddressBusRelType.tcAddressStreet1
                tDInvoice.tcShipToAddressStreet2 = tqAddressByAddressBusRelType.tcAddressStreet2
                tDInvoice.tcShipToAddressStreet3 = tqAddressByAddressBusRelType.tcAddressStreet3
                tDInvoice.tcShipToAddressTypeCode = tqAddressByAddressBusRelType.tcAddressTypeCode
                tDInvoice.tcShipToAddressZip = tqAddressByAddressBusRelType.tcAddressZip
                tDInvoice.tcShipToBusinessRelationCode = tqAddressByAddressBusRelType.tcBusinessRelationCode
                tDInvoice.tcShipToCountryCode = tqAddressByAddressBusRelType.tcCountryCode.
end.

/* add detail tables */
<M-43 run ApiStdMaintainTTWithExtPostDetail
   (input  icAction (icAction), 
    input-output bcLstReturn (bcLstReturn), 
    input-output bcLstPrimKey (bcLstPrimKey), 
    input-output bcLstRowId (bcLstRowId), 
    output olSaveAsDraft (olSaveAsDraft), 
    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.

/* Add DInvoicePosting details (ControlAccount) */
<Q-13 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-15 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-11 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-12 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-3 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-31'The posting must be on control account (&1): for &2 or &3 on &4, for &5 or &6 on &7.':255(13948)T-31# , 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-16 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-1900':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        return.
    end.
end.

/* This is where it ends if only SaveAsDraft is needed */
if vlSaveAsDraft
then do:
    assign oiReturnStatus = -1
           bcLstReturn    = bcLstReturn  + chr(4) + "-1":U
           bcLstPrimKey   = bcLstPrimKey + chr(4) + "*":U
           bcLstRowid     = bcLstRowid   + chr(4) + "*":U.
    Return.
end.

/* Add method which can be implemented to set some defaults */
<M-72 run ApiStdMaintainTTDefaulting  (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.

/* Validate the data and performa AddUpd */
<M-7 run ValidateBC (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.
<M-8 run AdditionalUpdates (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.

/* Save the data */
if icAction <> {&DAEMONACTION-VALIDATE}
then do: 
    if vlReturnDatasetDI
    then do:
        <M-41 run GetXmlRepresentationDataset
           (input  '' (icObjectRowId), 
            input  false (ilHeaderOnly), 
            input  0 (iiPriority), 
            output vhTempDS by-reference (ozXMLDataset), 
            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.
        /* Make a deep-copy of the dataset to prevent any further updates in the class tables from being reflected into the published dataset. */ 
        vhDatasetToReturnDI:copy-dataset (vhTempDS, true, false, false, "", false, "").
        delete object vhTempDS no-error.
        /* Get the KeyField indications */
        assign vcTableName = "".
        <M-42 run GetKeyFields
           (input-output vcTableName (bcTableName), 
            output vcPrimKeyDI (ocPrimaryKey), 
            output vcDummy (ocAlternateKey), 
            output vcDummy (ocObjectID), 
            output vcDummy (ocObjectStatus), 
            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.
    end.
    <M-9 run DataSave (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.
end.

/* Indicate that everything was saved correctly */
/* Set return status = OK                       */
assign bcLstReturn    = bcLstReturn  + chr(4) + (if vlWarningsFound = true then "1":U else "0":U)
       bcLstPrimKey   = bcLstPrimKey + chr(4) + string(tApiDInvoice.DInvoice_ID)
       bcLstRowid     = bcLstRowid   + chr(4) + vcDInvoiceRowId
       oiReturnStatus = (if vlWarningsFound = true then 1 else 0).