project QadFinancials > class BDDocument > method UpdateDDocument

Description

Create the DDocument records from the passed in tables


Parameters


tDDocToUpdateinputtemp-table
tDDocInvXRefToUpdateinputtemp-table
tDDocInvXRefStageToUpdateinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDPaymentSelection.AdditionalUpdatesDDocument


program code (program1/bddocument.p)

/* load up the keys for existing DDocuments */
for each tDDocToUpdate where
         tDDocToUpdate.DDocument_ID <> 0 and
         tDDocToUpdate.DDocument_ID <> ?
         on error undo, throw:

    assign vcPKeys = if vcPKeys = "":U
                     then string(tDDocToUpdate.DDocument_ID)
                     else if lookup(string(tDDocToUpdate.DDocument_ID), vcPKeys,chr(4)) = 0
                          then vcPKeys + chr(4) + string(tDDocToUpdate.DDocument_ID)
                          else vcPKeys.
end.
if vcPKeys <> "":U
then do:
    <M-92 run DataLoad
       (input  '':U (icRowids), 
        input  vcPKeys (icPkeys), 
        input  '':U (icObjectIds), 
        input  '':U (icFreeform), 
        input  false (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>

    if viFcReturnSuper < 0 or
       oiReturnStatus  = 0
    then assign oiReturnStatus = viFcReturnSuper.

    if oiReturnStatus < 0
    then return.
end. /* if vcPKeys <> "":U */

for each tDDocToUpdate where tDDocToUpdate.tc_Status = "N":U 
    on error undo, throw:
   
    if tDDocToUpdate.DDocument_ID = 0 or tDDocToUpdate.DDocument_ID = ?
    then do:
         <M-85 run AddDetailLine
            (input  'DDocument':U (icTable), 
             input  tDDocToUpdate.tc_ParentRowid (icParentRowid), 
             output viFcReturnSuper (oiReturnStatus)) in BDDocument>
                     
        buffer-copy tDDocToUpdate
             except 
                    tDDocToUpdate.DDocument_ID
                    tDDocToUpdate.tc_ParentRowid
                    tDDocToUpdate.tc_Rowid
                    tDDocToUpdate.tc_Status
                    /* set in Initial Values (will be called by DataNew above) */
                    tDDocToUpdate.Company_ID                 
                    tDDocToUpdate.DDocumentCreationDate      
                    tDDocToUpdate.DDocumentCreationTime      
                    tDDocToUpdate.DDocumentTimesPrinted      
                    tDDocToUpdate.tcCreationUsrLogin         
                    tDDocToUpdate.tlInvoicesLinked                          
                 to tDDocument.

        assign tDDocToUpdate.DDocument_ID = tDDocument.DDocument_ID
        
        vhFcComponent                        = ?.
         <M-14 run GetNumber
            (input  tDDocument.Company_ID (iiCompanyId), 
             input  tDDocument.DDocumentYear (iiNumbrYear), 
             input  'D':U + tDDocument.DDocumentType (icNumbrType), 
             output tDDocument.DDocumentNumber (oiNumber), 
             input  viFcCurrentInstanceId (iiInstanceId), 
             input  vcFcComponentName (icClassName), 
             output viFcReturnSuper (oiReturnStatus)) in BNumber>
             
        assign tDDocToUpdate.DDocumentNumber = tDDocument.DDocumentNumber.
    end. /* if tDDocToUpdate.DDocument_ID = 0 */   
    else do:
        find tDDocument where
             tDDocument.DDocument_ID = tDDocToUpdate.DDocument_ID
             no-error.

        if not available tDDocument
        then do:
            <M-36 run SetMessage
               (input  trim(#T-13'The previously loaded Customer Document $1 cannot be found.':250(543721930)T-13#) (icMessage), 
                input  string(tDDocument.DDocument_ID) (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-229380':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDDocument>

            assign oiReturnStatus = -1.
            return.
        end. /* if not available tDDocument */
    end. /* else do */        

    for each tDDocInvXRefToUpdate where 
        tDDocInvXRefToUpdate.tc_ParentRowid = tDDocToUpdate.tc_Rowid on error undo, throw:
        
        <M-63 run AddDetailLine
           (input  'DDocumentInvoiceXref':U (icTable), 
            input  tDDocument.tc_Rowid (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BDDocument>
        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.
    
        if oiReturnStatus < 0
        then return.
                    
        buffer-copy tDDocInvXRefToUpdate
             except 
                    tDDocInvXRefToUpdate.DDocument_ID
                    tDDocInvXRefToUpdate.DDocumentInvoiceXref_ID
                    tDDocInvXRefToUpdate.tc_ParentRowid
                    tDDocInvXRefToUpdate.tc_Rowid
                    tDDocInvXRefToUpdate.tc_Status
                 to tDDocumentInvoiceXref.
                 
        /* Assign the invoice posting id to DDocumentInvoiceXref record. */ 
        
        <Q-9 run DInvoicePostingByDIPostingID (all) (Read) (NoCache)
           (input ?, (PostingID)
            input tDDocumentInvoiceXref.DInvoice_ID, (DInvoiceID)
            input ?, (CompanyId)
            output dataset tqDInvoicePostingByDIPostingID) in BDInvoice>
        
        find first tqDInvoicePostingByDIPostingID where
                  tqDInvoicePostingByDIPostingID.tiDInvoice_ID = tDDocumentInvoiceXref.DInvoice_ID no-error.
                 
        if available tqDInvoicePostingByDIPostingID
        then assign tDDocumentInvoiceXref.tiDInvoicePostingId = tqDInvoicePostingByDIPostingID.tiPosting_ID.                  

        assign tDDocInvXRefToUpdate.DDocument_ID = tDDocument.DDocument_ID.         
    
        for each tDDocInvXRefStageToUpdate where 
            tDDocInvXRefStageToUpdate.tc_ParentRowid = tDDocInvXRefToUpdate.tc_Rowid on error undo, throw:
            
            <M-43 run AddDetailLine
               (input  'DDocInvoiceXrefStage':U (icTable), 
                input  tDDocumentInvoiceXref.tc_Rowid (icParentRowid), 
                output viFcReturnSuper (oiReturnStatus)) in BDDocument>
                
            if viFcReturnSuper < 0 or
               oiReturnStatus  = 0
            then assign oiReturnStatus = viFcReturnSuper.
        
            if oiReturnStatus < 0
            then return.
                
            buffer-copy tDDocInvXRefStageToUpdate
                 except 
                        tDDocInvXRefStageToUpdate.DDocumentInvoiceXref_ID   
                        tDDocInvXRefStageToUpdate.DDocInvoiceXrefStage_ID                                    
                        tDDocInvXRefStageToUpdate.tc_ParentRowid
                        tDDocInvXRefStageToUpdate.tc_Rowid
                        tDDocInvXRefStageToUpdate.tc_Status
                     to tDDocInvoiceXrefStage.
    
            assign tDDocInvXRefStageToUpdate.DDocumentInvoiceXref_ID = tDDocInvXRefToUpdate.DDocumentInvoiceXref_ID.         
        end. /* for each tDDocInvXRefStageToUpdate */
    end. /* for each tDDocInvXRefToUpdate */
end. /* for each tDDocToUpdate: */

<M-96 run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BDDocument>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.