project QadFinancials > class BCInvoiceAPMatching > method MaintainByDatasetWithOutput

Description

This method uses contents of the input class temp-tables (prefix t_s) to perform the action specified in icAction. (if icAction is empty, it gets the default value of "SAVE")
SAVE : validate contents and write to database if correct
SAVEDRAFT : validate contents, write to database if correct, copy the data to the class tables (prefix t_o) and create draft instance if incorrect
DRAFT : copy data to the class tables (prefix t_o) and create draft instance
VALIDATE : only validate data

It returns the object dataset if required (if ilProvideOutput = true).

See method ApiEDICInvoiceAPMatchingImportInitialDefaulting for all further details


Parameters


icActioninputcharacterSAVE
SAVEDRAFT
DRAFT
VALIDATE
ilReturnDatasetinputlogicalIndication whether the logic should return the official dataset of the object that has just been created/modified.
ilPartialUpdateinputlogicalIndication whether the input dataset is a full object or only a partial one.
icPartialUpdateExceptionListinputcharacterComma separated list with fields that need to be skipped in the test logic for partial update.
Fields in the list are specified as t<table>.<field>.
opPrimaryKeyoutputlongchar
opRowidoutputlongchar
oiDraftInstanceoutputinteger
ocPrimaryKeyNameoutputcharacterThe name of the field(s) in the primary key of the object. Normally this is the name of the object ID of the main table. (like creditor_ID)
ozObjectRepresentationoutputdataset-handleThe dataset containing the official representation of the object dataset. It should always be passed by-reference, meaning, the dataset handle should be created before the call.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program/bcinvoiceapmatching.p)

    
    /* ================================================================================================== */
    /* As this class has got a dataset in the class tables but CB does not provide the option to indicate */
    /* in this case which table is the primary and as such we cannot return a dataset for this method by  */
    /* using the default mechanism in the ancestor-class.                                                 */
    /* Therefore we define a local handle to the dataset in this class, fill it in the processing and     */
    /* then assign the the inheritted one after the ancestor-code again                                   */
    /* ================================================================================================== */
    assign vlReturnCInvoiceInstanceData = ilReturnDataset
           vhBCInvoiceInstanceData      = ?
           ilReturnDataset              = false    
           vlAllowOverAllocationPVO     = true.

<ANCESTOR-CODE>

        
    
    /* ========================================================================================================== */
    /* vhBCInvoiceInstanceDatafill is filled in the called methods from the ancestor-code when requested  and now */
    /* we use it to assign the inheritted output param that is a handle with the structure of the class dataset   */
    /* ========================================================================================================== */
    if vlReturnCInvoiceInstanceData = true and 
       valid-handle (vhBCInvoiceInstanceData) 
    then do :
        /* ========================================================================================================= */
        /* Copy the main fields of the main table of the CInvoice-instance (stored in vhBCInvoiceInstanceData) into  */
        /* tCInvoiceAPM (belonging to dataset BCInvoiceAPMatchingO) that will then be copied into the output dataset */
        /* Note that there can be multiple records in the input and thus also in vhBCInvoiceInstanceData             */
        /* ========================================================================================================= */
        if can-find (first tCInvoiceCIAPM) and 
           valid-handle(vhBCInvoiceInstanceData)
        THEN COPYBLOCK: DO : 
            /* Build up the buffer and the query for going through the dataset-handle */
            assign vhtCInvoiceBuffer = vhBCInvoiceInstanceData:get-buffer-handle("tCInvoice":U) no-error.
            if error-status:error or 
               valid-handle(vhtCInvoiceBuffer) = false
            then Leave COPYBLOCK.        
            Create query vhtCInvoiceQuery in widget-pool "non-persistent":U.
            vhtCInvoiceQuery:add-buffer(vhtCInvoiceBuffer) no-error.
            if error-status:error or 
               valid-handle(vhtCInvoiceBuffer) = false
            then Leave COPYBLOCK. 
            vhtCInvoiceQuery:query-prepare("for each " +  vhtCInvoiceBuffer:name  ) no-error.
            if error-status:error or 
               valid-handle(vhtCInvoiceBuffer) = false
            then Leave COPYBLOCK.
            /* Open the query and get the first one */
            vhtCInvoiceQuery:query-open() no-error.
            if error-status:error or 
               valid-handle(vhtCInvoiceBuffer) = false
            then Leave COPYBLOCK.
            vhtCInvoiceQuery:get-first() no-error.
            /* Cycle through all records in the query */
            do while valid-handle(vhtCInvoiceBuffer) and 
                     valid-handle(vhtCInvoiceQuery)  and 
                     vhtCInvoiceBuffer:available :
                /* Release tCInvoiceCIAPM to make sure we really find the one we need */
                release tCInvoiceCIAPM.
                /* Find the associated tCInvoiceCIAPM based upon CInvoice_ID or based upon CInvoiceReference */
                if vhtCInvoiceBuffer::CInvoice_ID <> 0 and 
                   vhtCInvoiceBuffer::CInvoice_ID <> ? 
                then Find tCInvoiceCIAPM where 
                          tCInvoiceCIAPM.tiCInvoice_ID = vhtCInvoiceBuffer::CInvoice_ID
                          no-error.
                if vhtCInvoiceBuffer::CInvoiceReference <> "":U and 
                   vhtCInvoiceBuffer::CInvoiceReference <> ?    and 
                   not available tCInvoiceCIAPM 
                then Find tCInvoiceCIAPM where 
                          tCInvoiceCIAPM.tcCInvoiceReference = vhtCInvoiceBuffer::CInvoiceReference
                          no-error.                             
                if vhtCInvoiceBuffer::CInvoicePostingYear <> 0  and 
                   vhtCInvoiceBuffer::CInvoicePostingYear <> ?  and 
                   vhtCInvoiceBuffer::tcJournalCode       <> "" and
                   vhtCInvoiceBuffer::tcJournalCode       <> ?  and
                   vhtCInvoiceBuffer::CInvoiceVoucher     <> 0  and
                   vhtCInvoiceBuffer::CInvoiceVoucher     <> ?  and
                   not available tCInvoiceCIAPM 
                then Find tCInvoiceCIAPM where 
                          tCInvoiceCIAPM.tiCInvoicePostingYear = vhtCInvoiceBuffer::CInvoicePostingYear and
                          tCInvoiceCIAPM.tcJournalCode         = vhtCInvoiceBuffer::tcJournalCode       and
                          tCInvoiceCIAPM.tiCInvoiceVoucher     = vhtCInvoiceBuffer::CInvoiceVoucher
                          no-error.
                /* Update the associated tCInvoiceCIAPM based upon the dataset-handle */
                if available tCInvoiceCIAPM
                then do: 
                    assign tCInvoiceCIAPM.tiCInvoice_ID             = vhtCInvoiceBuffer::CInvoice_ID
                           tCInvoiceCIAPM.tcCInvoiceReference       = vhtCInvoiceBuffer::CInvoiceReference
                           tCInvoiceCIAPM.tcCreditorCode            = vhtCInvoiceBuffer::tcCreditorCode
                           tCInvoiceCIAPM.ttCInvoiceDate            = vhtCInvoiceBuffer::CInvoiceDate
                           tCInvoiceCIAPM.ttCInvoicePostingDate     = vhtCInvoiceBuffer::CInvoicePostingDate
                           tCInvoiceCIAPM.tcCInvoiceCurrencyCode    = vhtCInvoiceBuffer::tcCurrencyCode
                           tCInvoiceCIAPM.tcCInvoicePaymentCondCode = vhtCInvoiceBuffer::tcNormalPaymentConditionCode
                           tCInvoiceCIAPM.ttCInvoiceDiscountDueDate = vhtCInvoiceBuffer::CInvoiceDiscountDueDate
                           tCInvoiceCIAPM.ttCInvoiceDueDate         = vhtCInvoiceBuffer::CInvoiceDueDate
                           tCInvoiceCIAPM.tcCInvoiceControlGLCode   = vhtCInvoiceBuffer::tcControlGLCode
                           tCInvoiceCIAPM.tcCInvoiceCostCentreCode  = vhtCInvoiceBuffer::tcCostCentreCode
                           tCInvoiceCIAPM.tcCInvoiceDivisionCode    = vhtCInvoiceBuffer::tcDivisionCode
                           tCInvoiceCIAPM.tcCInvoiceRemark          = vhtCInvoiceBuffer::CInvoiceCommentNote
                           tCInvoiceCIAPM.tdCInvoiceHoldAmountTC    = vhtCInvoiceBuffer::CInvoiceHoldAmountTC
                           tCInvoiceCIAPM.tcCInvoiceTSMNumber       = vhtCInvoiceBuffer::CInvoiceTSMNumber
                           tCInvoiceCIAPM.tiCinvoiceVoucher         = vhtCinvoiceBuffer::CinvoiceVoucher 
                           tCInvoiceCIAPM.tiCInvoicePostingYear     = vhtCInvoiceBuffer::CInvoicePostingYear
                           tCInvoiceCIAPM.tcJournalCode             = vhtCInvoiceBuffer::tcJournalCode.

                    if tCInvoiceCIAPM.tcCInvoiceReferenceInt = "":U or 
                       tCInvoiceCIAPM.tcCInvoiceReferenceInt = ? 
                    then assign tCInvoiceCIAPM.tcCInvoiceReferenceInt = string(vhtCInvoiceBuffer::CInvoicePostingYear) + "/":U + 
                                                                        vhtCInvoiceBuffer::tcJournalCode + "/":U + 
                                                                        string(vhtCInvoiceBuffer::CInvoiceVoucher,"999999999":U).
                end. /* if available(tCInvoiceCIAPM) */
                /* Get the next record in the query */
                vhtCInvoiceQuery:get-next() no-error.
            end. /* do while valid-handle(vhtCInvoiceBuffer) */
        END. /* COPYBLOCK */ 
        /* clean the query-handle */
        if valid-handle(vhtCInvoiceQuery)  
        then delete object vhtCInvoiceQuery  no-error.
        /* Create a new dataset like the class-dataset and with the same data in it: the output dataset and the input dataset of this method needs to have the same structure as the class-dataset */
        ozObjectRepresentation:copy-dataset(dataset BCInvoiceAPMatchingO:handle, /* handle to the class dataset that contains tCInvoiceCIAPM and from which to copy */
                                            true, /* Append-mode */
                                            false, /* Replace-mode */ 
                                            false, /* Loose-copy-mode; it relaxes the requirement that the metaschema for the source and target temp-tables be the same */
                                            "":U, /* pairs-list; comma-separated list of the target and source temp-table pairs to be copied */
                                            false, /* Current-only: copy only the current record of every table? */
                                            "":U). /* Name-prefix: optional character expression used as the prefix for naming the target ProDataSet */
        /* Delete the object with the dataset of BCInvoice (vhBCInvoiceInstanceDataCIJE) as we have copied it already and thus no longer need it */
        delete object vhBCInvoiceInstanceData. 
    end. /* if valid-handle (vhBCInvoiceInstanceData)  */
    

    /* ============================================================================================================================== */
    /* If there is only a single invoice record in the input and in the output tables and this single invoice record was not saved    */
    /* succesfully (meaning field CInvoice_ID in it is empty) then we set the global returnstatus of this method to a negative value  */
    /* to indicate an error occured. The fact that normally the global returnstatus does not reflect the individual invoices is       */
    /* because every invoice can be tackled in a single transaction.                                                                  */
    /* The request that when a single invoice-record is passed the global return status reflects the one of that invoice came from    */
    /* QXtend as they only look at the global return status to check if errors occured.                                               */
    /* Note we only set oiReturnStatus here as the error-messages are already created                                                 */
    /* ============================================================================================================================== */
    if oiReturnStatus >= 0 and 
       can-find (first tFcMessages)
    then do :
        find first tCInvoiceCIAPM no-lock no-error.
        if available tCInvoiceCIAPM and
           (tCInvoiceCIAPM.tiCInvoice_ID = 0 or 
            tCInvoiceCIAPM.tiCInvoice_ID = ?) and 
           not can-find (first btCInvoiceCIAPM where 
                               rowid(btCInvoiceCIAPM) <> rowid(tCInvoiceCIAPM))
        then do:
            if can-find(first tFcMessages where
                              tFcMessages.tcFcType <> 'W':U)
            then assign oiReturnStatus = -1.
            else assign oiReturnStatus = 1.
        end. /* if available tCInvoiceCIAPM and */
    end. /* if oiReturnStatus >= 0 and */