project QadFinancials > class BAPMatching > method DefaultValuesInvoice

Description

This is a remoting-enabled method that returns a bunch of information of the invoice.


Parameters


icAPMatchingTcRowidinputcharacterField tc_rowid of the tAPMatching record these defaults are retrieved for.
biInvoiceYearinput-outputinteger
bcInvoiceJournalinput-outputcharacter
biInvoiceVoucherinput-outputinteger
bcInvoiceReferenceinput-outputcharacter
biInvoiceRegistrationNrinput-outputinteger
bcCreditorCodeinput-outputcharacter
iiOldReasonIDinputintegerReason-id of the invoice before the invoice is matched
biNewReasonIDinput-outputintegerNewReasonID: Default value for the new reason-ID of the invoice once it is matched
bcNewReasonCodeinput-outputcharacterNewReasonCode: Default value for the new reason-code of the invoice once it is matched
oiBusinessRelationIDoutputintegerID of business relation
ocBusinessRelationCodeoutputcharacter
ocBusinessRelationICCodeoutputcharacterBusinessRelationICCode
ocCurrencyCodeoutputcharacter
odAmountToMatchTCoutputdecimal
odAmountToMatchLCoutputdecimal
oiCInvoiceIdoutputinteger
odCInvoiceExchangeRateoutputdecimal
odCInvoiceRateScaleoutputdecimal
odCInvoiceCCRateoutputdecimalCInvoiceCCRate: ExchangeRate between TC and SC as specified on the invoice
odCInvoiceCCScaleoutputdecimalCInvoiceCCScale: Exchange-rate Scale between TC and SC as specified on the invoice
odCInvoiceLCCCRateoutputdecimalRate between LC and SC at the moment of the invoice (type: Statutory - optional: accounting)
odCInvoiceLCCCScaleoutputdecimalScale between LC and SC at the moment of the invoice (type: Statutory - optional: accounting)
otCInvoiceDateoutputdate
otCInvoicePostingDateoutputdatePostingDate of the invoice
otCInvoiceTaxPointDateoutputdateTaxpoint date of the invoice
ocCInvoiceTypeoutputcharacterType of the invoice (credit-note, invoice, ...)
ocCInvoicePaymentConditionoutputcharacterPayment Condition of the Invoice
olCInvoiceIsInitialStatusoutputlogical
odTaxAcrueReceiptRecovTCoutputdecimal
odTaxAcrueReceiptNonRecovTCoutputdecimal
odTaxAcrueInvoiceRecovTCoutputdecimal
odTaxAcrueInvoiceNonRecovTCoutputdecimal
odInvoiceDiscountPercentageoutputdecimal
ocCreditorAddrTaxIDFederaloutputcharacter
ocCreditorAddrTaxIDStateoutputcharacter
ocCreditorAddrTaxIDMisc1outputcharacter
ocCreditorAddrTaxIDMisc2outputcharacter
ocCreditorAddrTaxIDMisc3outputcharacter
olCreditorAddrIsTaxInCityoutputlogical
olCreditorAddrIsEUCountryoutputlogical
ocCreditorAddrCountryCodeoutputcharacter
oiCreditorAddrIDoutputintegerHead Office Address ID of the Creditor
ocShipToAddrTaxIDFederaloutputcharacter
ocShipToAddrTaxIDStateoutputcharacter
ocShipToAddrTaxIDMisc1outputcharacter
ocShipToAddrTaxIDMisc2outputcharacter
ocShipToAddrTaxIDMisc3outputcharacter
oiShipToAddrTaxDeclaratoutputinteger
olShipToAddrIsTaxInCityoutputlogical
olShipToAddrIsEUCountryoutputlogical
ocShipToAddrCountryCodeoutputcharacter
oiOriginalAPMatchingIDoutputinteger
tOrderFilterAPMoutputtemp-tableTemp-table containing the matching-scope of the invocie
otPostingDateoutputdatePosting Date
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AddAPMatching
method BAPMatching.ReplaceAPMatching


program code (program7/bapmatching.p)

    
    /* ============================ */
    /* Exception handling           */
    /* ============================ */
    assign oiReturnStatus = -98
           oiCInvoiceId   = ?.
    
    /* ========================== */
    /* Validate input parameters  */
    /* ========================== */
    if biInvoiceYear           = 0      then assign biInvoiceYear           = ?.
    if bcInvoiceJournal        = '':U   then assign bcInvoiceJournal        = ?.
    if biInvoiceVoucher        = 0      then assign biInvoiceVoucher        = ?.
    if bcInvoiceReference      = '':U   then assign bcInvoiceReference      = ?.
    if biInvoiceRegistrationNr = 0      then assign biInvoiceRegistrationNr = ?.
    if bcCreditorCode     = '':U        then assign bcCreditorCode          = ?.
    if (bcInvoiceReference      = ? and 
        biInvoiceRegistrationNr = ? and 
        (biInvoiceYear      = ? or
         bcInvoiceJournal   = ? or
         biInvoiceVoucher   = ?))
    then do:
         assign oiReturnStatus = 0.
         return.
    end.
    find tAPMatching where 
         tAPMatching.tc_Rowid = icAPMatchingTcRowid
         no-error.
    if not available tAPMatching
    then do :
        assign vcMessage      = trim(substitute(#T-6'The system cannot find the matching based upon its row ID (&1)':255(999890413)T-6#,icAPMatchingTcRowid))
               oiReturnStatus = -3.
        <M-7 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-7678':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Return.
    end. /* if not available tAPMatching */
    
    /* ============================ */
    /* Query the invoice            */
    /* ============================ */
    <Q-1 run CInvoiceForAPMSelection (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input biInvoiceYear, (CInvoicePostingYear)
        input bcInvoiceJournal, (JournalCode)
        input biInvoiceVoucher, (CInvoiceVoucher)
        input ?, (CInvoiceId)
        input bcCreditorCode, (CreditorCode)
        input bcInvoiceReference, (CInvoiceReference)
        input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
        input biInvoiceRegistrationNr, (CInvoiceRegistrationNr)
        output dataset tqCInvoiceForAPMSelection) in BCInvoice>
    find tqCInvoiceForAPMSelection no-error.
    if not available tqCInvoiceForAPMSelection
    then do:
        assign oiReturnStatus = 0.
        return.
    end. /* if not available tqCInvoiceForAPMSelection */
    
    /* ============================ */
    /* Check CI-properties          */
    /* ============================ */
    <M-4 run ValCInvoice
       (input  String(tqCInvoiceForAPMSelection.tiCInvoiceRegistrationNr) (icTargetField), 
        input  'tAPMatching.tiCInvoiceRegistrationNr':U (icTargetFieldName), 
        input  icAPMatchingTcRowid (icRowid), 
        input  string(tqCInvoiceForAPMSelection.tiCInvoicePostingYear) + '/':U + tqCInvoiceForAPMSelection.tcJournalCode + '/':U + string(tqCInvoiceForAPMSelection.tiCInvoiceVoucher,'999999999':U) (icYearJournalVoucher), 
        input  tqCInvoiceForAPMSelection.tcCInvoiceType (icCInvoiceType), 
        input  tqCInvoiceForAPMSelection.tlCInvoiceIsLogisticMatching (ilCInvoiceIsLogisticMatching), 
        input  tqCInvoiceForAPMSelection.tcCInvoiceAllocationStatus (icCInvoiceAllocationStatus), 
        input  tqCInvoiceForAPMSelection.tlCInvoiceIsInvoiceApproved (ilCInvoiceIsInvoiceApproved), 
        input  tqCInvoiceForAPMSelection.tiCompany_ID (iiCInvoiceCompanyID), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then Return.
    
    /* ============================ */
    /* Assign output-params         */
    /* ============================ */
    assign biInvoiceYear               = tqCInvoiceForAPMSelection.tiCInvoicePostingYear
           bcInvoiceJournal            = tqCInvoiceForAPMSelection.tcJournalCode
           biInvoiceVoucher            = tqCInvoiceForAPMSelection.tiCInvoiceVoucher
           bcInvoiceReference          = tqCInvoiceForAPMSelection.tcCInvoiceReference
           biInvoiceRegistrationNr     = tqCInvoiceForAPMSelection.tiCInvoiceRegistrationNr
           bcCreditorCode              = tqCInvoiceForAPMSelection.tcCreditorCode
           oiBusinessRelationID        = tqCInvoiceForAPMSelection.tiBusinessRelation_ID
           ocBusinessRelationCode      = tqCInvoiceForAPMSelection.tcBusinessRelationCode
           ocBusinessRelationICCode    = tqCInvoiceForAPMSelection.tcBusinessRelationICCode
           ocCurrencyCode              = tqCInvoiceForAPMSelection.tcCurrencyCode
           oiCInvoiceId                = tqCInvoiceForAPMSelection.tiCInvoice_ID
           odCInvoiceExchangeRate      = round(tqCInvoiceForAPMSelection.tdCInvoiceExchangeRate,10)
           odCInvoiceRateScale         = tqCInvoiceForAPMSelection.tdCInvoiceRateScale
           odCInvoiceCCRate            = round(tqCInvoiceForAPMSelection.tdCInvoiceCCRate,10)
           odCInvoiceCCScale           = tqCInvoiceForAPMSelection.tdCInvoiceCCScale
           otCInvoiceDate              = tqCInvoiceForAPMSelection.ttCInvoiceDate
           otCInvoicePostingDate       = tqCInvoiceForAPMSelection.ttCInvoicePostingDate
           odInvoiceDiscountPercentage = tqCInvoiceForAPMSelection.tdPaymentConditionPercentage
           otCInvoiceTaxPointDate      = tqCInvoiceForAPMSelection.ttCInvoiceTaxPointDate
           ocCInvoiceType              = tqCInvoiceForAPMSelection.tcCInvoiceType
           ocCInvoicePaymentCondition  = tqCInvoiceForAPMSelection.tcPaymentConditionCode
           olCInvoiceIsInitialStatus   = tqCInvoiceForAPMSelection.tlCInvoiceIsInitialStatus
           viReplaceCInvoiceID         = tqCInvoiceForAPMSelection.tiReplacedCInvoice_ID.
    
    /* ========================================================================================================================= */
    /* Fields tAPMatching.tdCInvoiceLCCCRate and tAPMatching.tdCInvoiceLCCCScale represent the rate and scale between LC and SC  */
    /* at the moment of the invoice (type: Statutory - optional: accounting) but these fields are not stored on the CInvoice as  */
    /* we do not need that information on the invoice itself. BUT; the pvod use this value to assign the CC-amounts based upon   */
    /* the LC-amounts in the PO-receipt-posting and we store that rate here to be able to compare the values.                    */
    /* In fact, we do not use these values for making calculations: they are information-only                                    */  
    /* ========================================================================================================================= */
    if viCompanyCCId = viCompanyLCId
    then assign odCInvoiceLCCCRate  = 1
                odCInvoiceLCCCScale = 1.
    else do :
         <M-73 run GetExchangeRate
            (input  tAPMatching.Company_ID (iiCompanyID), 
             input  viCompanyLCId (iiFromCurrencyID), 
             input  ? (icFromCurrencyCode), 
             input  viCompanyCCId (iiToCurrencyID), 
             input  ? (icToCurrencyCode), 
             input  ? (iiExchangeRateTypeID), 
             input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
             input  otCInvoicePostingDate (itValidityDate), 
             output odCInvoiceLCCCRate (odExchangeRate), 
             output odCInvoiceLCCCScale (odExchangeScaleFactor), 
             output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then Return.
    end. /* not if viCompanyCCId = viCompanyLCId */
    
    <Q-66 run PeriodByStartEndDate (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input tqCInvoiceForAPMSelection.ttCInvoicePostingDate, (Date)
        output dataset tqPeriodByStartEndDate) in BPeriod >
        
    find first tqPeriodByStartEndDate where
       tqPeriodByStartEndDate.tcPeriodStatus              = {&PERIODSTATUS-OPEN}                             and
       tqPeriodByStartEndDate.ttPeriodStartDate          <=  tqCInvoiceForAPMSelection.ttCInvoicePostingDate and
       tqPeriodByStartEndDate.ttPeriodEndDate            >=  tqCInvoiceForAPMSelection.ttCInvoicePostingDate             
       no-error.
    if available tqPeriodByStartEndDate
    then assign otPostingDate = tqCInvoiceForAPMSelection.ttCInvoicePostingDate.
    else assign otPostingDate = Today.     
    
    /* ============================================= */
    /* Call submethod for the invoice-amount details */
    /* ============================================= */
    <M-2 run DefaultValuesInvoiceAmount
       (input  tqCInvoiceForAPMSelection.tiCInvoice_ID (iiCInvoiceID), 
        input  tAPMatching.APMatching_ID (iiAPMatchingID), 
        input  tqCInvoiceForAPMSelection.tiReason_ID (iiOldReasonID), 
        input-output biNewReasonID (biNewReasonID), 
        input-output bcNewReasonCode (bcNewReasonCode), 
        output vcDummy (ocCurrency), 
        output odAmountToMatchTC (odAmountToMatchTC), 
        output odAmountToMatchLC (odAmountToMatchLC), 
        output odTaxAcrueReceiptRecovTC (odTaxAcrueReceiptRecovTC), 
        output odTaxAcrueReceiptNonRecovTC (odTaxAcrueReceiptNonRecovTC), 
        output odTaxAcrueInvoiceRecovTC (odTaxAcrueInvoiceRecovTC), 
        output odTaxAcrueInvoiceNonRecovTC (odTaxAcrueInvoiceNonRecovTC), 
        output odInvoiceDiscountPercentage (odInvoiceDiscountPercentage), 
        input  false (ilBCInvoiceIsAlreadyOpen), 
        output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then Return.
    
    /* ==================================================================== */
    /* Store all the output parameters also in the tAPMatching record       */
    /* Store all address-details as well as we need them when GTM is called */
    /* ==================================================================== */
    assign tAPMatching.APMatchingTotalAmountTC        = odAmountToMatchTC
           tAPMatching.APMatchingTotalAmountLC        = odAmountToMatchLC
           tAPMatching.APMatchingAIRecTaxTC           = odTaxAcrueInvoiceRecovTC
           tAPMatching.APMatchingAINRecTaxTC          = odTaxAcrueInvoiceNonRecovTC
           tAPMatching.APMatchingARRecTaxTC           = odTaxAcrueReceiptRecovTC
           tAPMatching.APMatchingARNRecTaxTC          = odTaxAcrueReceiptNonRecovTC
           tAPMatching.APMatchingCInvoiceDiscPct      = odInvoiceDiscountPercentage
           tAPMatching.ttCInvoiceTaxPointDate         = otCInvoiceTaxPointDate
           tAPMatching.tcCInvoiceType                 = ocCInvoiceType
           tAPMatching.tcCInvoicePaymentConditionCode = ocCInvoicePaymentCondition
           tAPMatching.tcCurrencyCode                 = ocCurrencyCode
           tAPMatching.tdCInvoiceExchangeRate         = odCInvoiceExchangeRate
           tAPMatching.tdCInvoiceRateScale            = odCInvoiceRateScale
           tAPMatching.tdCInvoiceCCRate               = odCInvoiceCCRate
           tAPMatching.tdCInvoiceCCScale              = odCInvoiceCCScale
           tAPMatching.tlCInvoiceIsInitialStatus      = olCInvoiceIsInitialStatus
           tAPMatching.tiCInvoiceRegistrationNr       = biInvoiceRegistrationNr
           tAPMatching.CInvoice_ID                    = oiCInvoiceId
           tAPMatching.tiBusinessRelationID           = oiBusinessRelationID
           tAPMatching.tcBusinessRelationCode         = ocBusinessRelationCode
           tAPMatching.tcBusinessRelationICC          = ocBusinessRelationICCode
           tAPMatching.ttCInvoicePostingDate          = otCInvoicePostingDate
           tAPMatching.tdCInvoiceLCCCRate             = odCInvoiceLCCCRate
           tAPMatching.tdCInvoiceLCCCScale            = odCInvoiceLCCCScale
           ocCreditorAddrTaxIDFederal                 = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDFederal
           ocCreditorAddrTaxIDState                   = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDState
           ocCreditorAddrTaxIDMisc1                   = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc1
           ocCreditorAddrTaxIDMisc2                   = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc2
           ocCreditorAddrTaxIDMisc3                   = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc3
           olCreditorAddrIsTaxInCity                  = tqCInvoiceForAPMSelection.tlCreditorAddrTaxInCity
           olCreditorAddrIsEUCountry                  = tqCInvoiceForAPMSelection.tlCreditorAddrIsEUCountry
           ocCreditorAddrCountryCode                  = tqCInvoiceForAPMSelection.tcCreditorAddrCountryCode
           oiCreditorAddrID                           = tqCInvoiceForAPMSelection.tiCreditorAddr_ID
           ocShipToAddrTaxIDFederal                   = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDFederal
           ocShipToAddrTaxIDState                     = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDState
           ocShipToAddrTaxIDMisc1                     = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc1
           ocShipToAddrTaxIDMisc2                     = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc2
           ocShipToAddrTaxIDMisc3                     = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc3
           oiShipToAddrTaxDeclarat                    = tqCInvoiceForAPMSelection.tiShipToAddrTaxDeclarat
           olShipToAddrIsTaxInCity                    = tqCInvoiceForAPMSelection.tlShipToAddrIsTaxInCity
           olShipToAddrIsEUCountry                    = tqCInvoiceForAPMSelection.tlShipToAddrIsEUCountry
           ocShipToAddrCountryCode                    = tqCInvoiceForAPMSelection.tcShipToAddrCountryCode
           tAPMatching.tcCreditorAddrTaxIDFederal     = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDFederal
           tAPMatching.tcCreditorAddrTaxIDState       = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDState
           tAPMatching.tcCreditorAddrTaxIDMisc1       = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc1
           tAPMatching.tcCreditorAddrTaxIDMisc2       = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc2
           tAPMatching.tcCreditorAddrTaxIDMisc3       = tqCInvoiceForAPMSelection.tcCreditorAddrTaxIDMisc3
           tAPMatching.tlCreditorAddrIsTaxInCity      = tqCInvoiceForAPMSelection.tlCreditorAddrTaxInCity
           tAPMatching.tlCreditorAddrIsEUCountry      = tqCInvoiceForAPMSelection.tlCreditorAddrIsEUCountry
           tAPMatching.tcCreditorAddrCountryCode      = tqCInvoiceForAPMSelection.tcCreditorAddrCountryCode
           tAPMatching.tiCreditorAddr_ID              = tqCInvoiceForAPMSelection.tiCreditorAddr_ID
           tAPMatching.tcShipToAddrTaxIDFederal       = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDFederal
           tAPMatching.tcShipToAddrTaxIDState         = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDState
           tAPMatching.tcShipToAddrTaxIDMisc1         = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc1
           tAPMatching.tcShipToAddrTaxIDMisc2         = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc2
           tAPMatching.tcShipToAddrTaxIDMisc3         = tqCInvoiceForAPMSelection.tcShipToAddrTaxIDMisc3
           tAPMatching.tiShipToAddrTaxDeclaration     = tqCInvoiceForAPMSelection.tiShipToAddrTaxDeclarat
           tAPMatching.tlShipToAddrIsTaxInCity        = tqCInvoiceForAPMSelection.tlShipToAddrIsTaxInCity
           tAPMatching.tlShipToAddrIsEUCountry        = tqCInvoiceForAPMSelection.tlShipToAddrIsEUCountry
           tAPMatching.tcShipToAddrCountryCode        = tqCInvoiceForAPMSelection.tcShipToAddrCountryCode
           tAPMatching.tiShipToAddress_ID             = tqCInvoiceForAPMSelection.tiShipToAddress_ID
           tAPMatching.tcCreditorCode                 = tqCInvoiceForAPMSelection.tcCreditorCode.     

    /* ================================================== */
    /* Get Original APmatching ID for replaced CInvoice   */
    /* ================================================== */
    assign oiOriginalAPMatchingID = 0.
    if viReplaceCInvoiceID <> 0 and viReplaceCInvoiceID <> ?
    then do:
        <Q-9 run APMatchingByCInvoice (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input viReplaceCInvoiceID, (CInvoiceId)
            input ?, (CInvoiceYear)
            input ?, (CInvoiceJournalCode)
            input ?, (CInvoiceVoucher)
            output dataset tqAPMatchingByCInvoice) in BAPMatching >
        find first tqAPMatchingByCInvoice where
                   tqAPMatchingByCInvoice.tiCInvoice_ID = viReplaceCInvoiceID no-error.
        if available tqAPMatchingByCInvoice
        then assign oiOriginalAPMatchingID = tqAPMatchingByCInvoice.tiAPMatching_ID.
    end. /* if viReplaceCInvoiceID <> 0 and */

    /* ================================================== */
    /* Call query on CInvoicePO to get the matching-scope */
    /* ================================================== */
    <Q-5 run CInvoicePOByCInvoicePO (all) (Read) (NoCache)
       (input tqCInvoiceForAPMSelection.tiCInvoice_ID, (CInvoiceID)
        input ?, (PODomain)
        input ?, (PONbr)
        output dataset tqCInvoicePOByCInvoicePO) in BCInvoice >
    empty temp-table tOrderFilterAPM.
    for each tqCInvoicePOByCInvoicePO : 
        create tOrderFilterAPM.
        assign tOrderFilterAPM.tcPONbr = tqCInvoicePOByCInvoicePO.tcCInvoicePOPoNbr.
    end. /* for each tqCInvoicePOByCInvoicePO */
    
    /* ============================ */
    /* Exception handling           */
    /* ============================ */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.