project QadFinancials > class BDInvoice > method CreateDInvoiceMovementsCrossCyJrnl

Description

CreateDInvoiceMovementsCrossCyJrnl; sub -method of CreateDInvoiceMovementsCrossCyt that is called in case the control-posting-line of the posting should be replaced by a cross-company account.


Parameters


icPostingRowIdinputcharacterPostingRowid
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.CreateDInvoiceMovementsCrossCy


program code (program3/bdinvoice.p)

assign oiReturnStatus = -98
       viLocalReturn  = 0.

MAIN_BLOCK:
do on error undo, return:
    /* ================================================================================= */
    /* Get the JournalCode of the current posting. This JournalCode should also exist in */
    /* the company of the CInvoice and the type of these 2 Journals should be the same   */
    /* ================================================================================= */
    
    /* ==================================================================================== */
    /* Get the Journal of the current Posting; an instance of BJournalEntry is already open */
    /* ==================================================================================== */
    <M-1 run GetPostingHeaderByPostingId
       (input  ? (iiPostingId), 
        input  icPostingRowId (icPostingRowID), 
        output viDummy (oiPostingYear), 
        output viDummy (oiPostingPeriod), 
        output vtDummy (otPostingDate), 
        output vcCurrentPostingJournalCode (ocPostingJournalCode), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper             <  0    or 
       vcCurrentPostingJournalCode = "":U or 
       vcCurrentPostingJournalCode = ?
    then do :
        assign vcMessage      = trim(substitute(#T-9'A cross-company error occurred. The system cannot find the originating posting.':255(31362)t-9#)) + chr(10) + 
                                trim(substitute(#T-10'Searched for a posting instance with row ID: &1':222(31363)T-10#,icPostingRowId)).
        <M-2 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-4826':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        assign viLocalReturn = -1.
        leave MAIN_BLOCK.
    end. /* if */
    
    /* ==================================================================================== */
    /* Get the JournalType of Journal of the current Posting (in the current company)       */      
    /* ==================================================================================== */
    <Q-3 run JournalByJournalIDCodeType (all) (Read) (Cache)
       (input viCompanyId, (CompanyId)
        input ?, (JournalID)
        input vcCurrentPostingJournalCode, (JournalCode)
        input ?, (JournalTypeCode)
        output dataset tqJournalByJournalIDCodeType) in BJournal>
    find tqJournalByJournalIDCodeType where 
         tqJournalByJournalIDCodeType.tcJournalCode = vcCurrentPostingJournalCode
         no-lock no-error.
    if not available tqJournalByJournalIDCodeType  
    then do :
        assign vcMessage      = trim(substitute(#T-11'A cross-company error occurred. The daybook used in the originating posting has not been defined.':255(31364)t-11#,vcCurrentPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-12'Daybook code: &1':222(31365)T-12#,vcCurrentPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-13'Entity ID of the posting: &1':222(31369)T-13#,string(viCompanyId))).
        <M-4 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-4827':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        assign viLocalReturn = -1.
        leave MAIN_BLOCK.
    end. /* if */

    if tqJournalByJournalIDCodeType.tcJournalTypeCode = "":U or 
       tqJournalByJournalIDCodeType.tcJournalTypeCode = ? 
    then do :
        assign vcMessage      = trim(substitute(#T-14'A cross-company error occurred. The daybook type of the daybook (&1) used in the originating posting has not been defined.':255(31367)t-14#,vcCurrentPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-15'Daybook code: &1':222(31365)T-15#,vcCurrentPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-16'Entity ID of the posting: &1':222(31369)T-16#,string(viCompanyId))).
        <M-5 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-4828':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        assign viLocalReturn = -1.
        leave MAIN_BLOCK.
    end. /* if */
    assign vcCurrentPostingJournalTypeCode = tqJournalByJournalIDCodeType.tcJournalTypeCode.
    
    /* ==================================================================================== */
    /* Get the Journal in the company of the DInvoice (not the current company)             */            
    /* ==================================================================================== */
    <Q-6 run JournalByJournalIDCodeType (all) (Read) (Cache)
       (input tqDInvoiceForPaymentExt.tiCompany_ID, (CompanyId)
        input ?, (JournalID)
        input vcCurrentPostingJournalCode, (JournalCode)
        input ?, (JournalTypeCode)
        output dataset tqJournalByJournalIDCodeType) in BJournal>
    find tqJournalByJournalIDCodeType where 
         tqJournalByJournalIDCodeType.tcJournalCode = vcCurrentPostingJournalCode
         no-lock no-error.
    if not available tqJournalByJournalIDCodeType 
    then do :
        assign vcMessage      = trim(substitute(#T-17'A cross-company error occurred. The system cannot find the daybook (&1) used in the originating posting.':255(31368)t-17#,vcCurrentPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-18'This daybook should be defined in the entity of the invoice also.':255(31372)T-18#)) + chr(10) + 
                                trim(substitute(#T-19'Daybook code: &1':222(31365)T-19#,vcCurrentPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-20'Entity ID of the posting: &1':222(31369)T-20#,string(viCompanyId))) + chr(10) + 
                                trim(substitute(#T-21'Entity ID of the invoice: &1':222(31371)T-21#,string(tqDInvoiceForPaymentExt.tiCompany_ID))).
        <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-4829':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        assign viLocalReturn = -1.
        leave MAIN_BLOCK.
    end. /* if */
    
    if tqJournalByJournalIDCodeType.tcJournalTypeCode <> vcCurrentPostingJournalTypeCode
    then do :
        assign vcMessage      = trim(substitute(#T-22'A cross-company error occurred. The daybook type (&1) of the originating posting is different than the daybook type used with the same daybook code in the entity of the invoice.':255(31373)t-22#,vcCurrentPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-23'You must define this daybook with the same daybook type in both the entity of the invoice and the current entity.':255(31374)t-23#)) + chr(10) + 
                                trim(substitute(#T-24'Daybook code: &1':222(31365)T-24#,vcCurrentPostingJournalCode)) + chr(10) + 
                                trim(substitute(#T-25'Daybook type of the daybook in the entity of the posting: &1':222(31375)T-25#,vcCurrentPostingJournalTypeCode)) + chr(10) + 
                                trim(substitute(#T-26'Daybook type of the daybook in the entity of the invoice: &1':222(31376)T-26#,tqJournalByJournalIDCodeType.tcJournalTypeCode)) + chr(10) + 
                                trim(substitute(#T-27'Entity ID of the posting: &1':222(31369)T-27#,string(viCompanyId))) + chr(10) + 
                                trim(substitute(#T-28'Entity ID of the invoice: &1':222(31371)T-28#,string(tqDInvoiceForPaymentExt.tiCompany_ID))).
        <M-8 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-4830':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        assign viLocalReturn = -1.
        leave MAIN_BLOCK.
    end. /* if */

end. /* MAIN_BLOCK */

assign oiReturnStatus = viLocalReturn.