project QadFinancials > class BCInvoice > method PreSave

Description

Actions to take before writing current instance to the database (inside the db transaction!).
Use the field tc_status to test the status of the updated records:
'' = unchanged
'N' = new
'C' = changed
'D' = deleted

If the consecutive numbering is active, the temporary voucher of the invoices will be changed to a permanent voucher in this method.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program/bcinvoice.p)

<ANCESTOR-CODE>

    
    /* ============================================================================================================= */
    /* The instance-dep temp-table tCInvoiceIDsForQCrossCompany that contains CInvoiceIDs for the CInvoices          */
    /* wherefor a tNewCrossCyPostingTable-record is created in method CreateCInvoiceMovement                         */
    /* (and the submethods of it). Based on this temp-table, PreSave-method will update the CInvoiceIsSelected-flag  */
    /* for these CInvoices (that are not loaded into the business-instance).                                         */
    /* Once everything is done then empty the class data-item to avoid problems the next time save is done           */
    /* ============================================================================================================= */

    assign vcWhereClause = '':U
           viCounterSub  = 0.

    if can-find(first tCInvoiceIDsForQCrossCompany)
    then do:
        <M-29 run StartPersistence
           (output vhFcComponent (ohPersistence), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper <> 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            empty temp-table tCInvoiceIDsForQCrossCompany.
 
            if oiReturnStatus < 0
            then return.
        end. /* if viFcReturnSuper <> 0 */
    end. /* if can-find(first tCInvoiceIDsForQCrossCompany) */

    for each tCInvoiceIDsForQCrossCompany:

        assign viCounterSub   = viCounterSub + 1
               vcWhereClause  = vcWhereClause + " ":U + 
                               (if vcWhereClause = '':U
                                then "for each CInvoice where ":U 
                                else " or ":U ) + 
                               "CInvoice.CInvoice_ID = ":U + string(tCInvoiceIDsForQCrossCompany.tiCInvoiceID).
        if viCounterSub = 100 
        then do :   
            <M-32 run WriteDirect
               (input  'CInvoice':U (icTableName), 
                input  vcWhereClause (icPrepare), 
                input  'CInvoiceIsSelected':U (icFieldList), 
                input  'L':U (icFieldListDataTypes), 
                input  'true':U (icAbsolute), 
                input  '':U (icIncremental), 
                input  {&TARGETPROCEDURE} (ihClass), 
                input  vcUserLogin (icUserLogin), 
                output viFcReturnSuper (oiReturnStatus)) in Progress>
            if viFcReturnSuper <> 0
            then do :
                assign oiReturnStatus = viFcReturnSuper.
                empty temp-table tCInvoiceIDsForQCrossCompany.

                if oiReturnStatus < 0
                then return.
            end. /* if viFcReturnSuper <> 0 */
        
            assign vcWhereClause = '':U
                   viCounterSub  = 0.
        
        end. /* if viCounterSub = 100 */

    end. /* for each tCInvoiceIDsForQCrossCompany */

    if viCounterSub > 0 
    then do :                
    
        <M-18 run WriteDirect
           (input  'CInvoice':U (icTableName), 
            input  vcWhereClause (icPrepare), 
            input  'CInvoiceIsSelected':U (icFieldList), 
            input  'L':U (icFieldListDataTypes), 
            input  'true':U (icAbsolute), 
            input  '':U (icIncremental), 
            input  {&TARGETPROCEDURE} (ihClass), 
            input  vcUserLogin (icUserLogin), 
            output viFcReturnSuper (oiReturnStatus)) in Progress>
        if viFcReturnSuper <> 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            empty temp-table tCInvoiceIDsForQCrossCompany.
        
            if oiReturnStatus < 0
            then return.
        end. /* if viFcReturnSuper <> 0 */
    end. /* if viCounterSub > 0 */

    empty temp-table tCInvoiceIDsForQCrossCompany.
    
    
    /* ===================================================================================== */
    /* Execute some extra validations to ensure sub-ledger and general ledger are in line    */
    /* ===================================================================================== */
    <M-63 run PreSaveValidate  (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then return.
    
    
    /* ======================================================================================================= */
    /* In case of Consecutive-invoice-numbering: Obtain a new voucher number and update the necessary records. */
    /* ======================================================================================================= */
    NUMBERBLOCK: DO: 
        
        /* ======================================================================================== */
        /* Replace all occurrences of the invoice voucher number when concecutive numbering is used */
        /* ======================================================================================== */
        if vlCIDomainIsConsecutNr = true
        then do:
            empty temp-table tUpdateInvoiceNumbers.
            for each tCInvoice where
                    (tCInvoice.tc_Status = "N":U or
                     tCInvoice.tc_Status = "C":U)                         and
                    (tCInvoice.CInvoiceType <> {&INVOICETYPE-PREPAYMENT}  and
     	  	         tCInvoice.CInvoiceType <> {&INVOICETYPE-ADJUSTMENT}) and
                    tCInvoice.CInvoiceIsInitialStatus = false:
                /* Allthough the consequtive numbering is on, invoices that come via integtration and wherefor the a posting weas already created by the integration-methods ccalling BPosting/BJournalEntry, will have a proper number and not a temporarely one. For these invoices we do not need to retrieve another new number as we will otherwise have gaps in our numbering. */ 
                if tCInvoice.CInvoiceVoucher <> 0                     and 
                   tCInvoice.CInvoiceVoucher <> ?                     and 
                   tCInvoice.CInvoiceVoucher  < viTempCInvoiceVoucher and 
                   tCInvoice.CInvoiceVoucher  < 999000000 
                then next.                
                /* if the initial status, the year and the journal haven't changed, then go to next record */
                if tCInvoice.tc_Status = "C":U
                then do:
                    find t_iCInvoice where
                         t_iCInvoice.tc_Rowid = tCInvoice.tc_Rowid
                         no-lock no-error.
                    if not available t_iCInvoice
                    then next.
    
                    if t_iCInvoice.CInvoicePostingYear     = tCInvoice.CInvoicePostingYear and
                       t_iCInvoice.tcJournalCode           = tCInvoice.tcJournalCode       and
                       t_iCInvoice.CInvoiceIsInitialStatus = false
                    then next.
                end. /* if tCInvoice.tc_Status = "C":U */
                assign vhFcComponent = ?.
                <M-80 run GetNumber
                   (input  tCInvoice.Company_ID (iiCompanyId), 
                    input  tCInvoice.CInvoicePostingYear (iiNumbrYear), 
                    input  tCInvoice.tcJournalCode (icNumbrType), 
                    output viNewVoucher (oiNumber), 
                    input  viFcCurrentInstanceId (iiInstanceId), 
                    input  vcFcComponentName (icClassName), 
                    output viFcReturnSuper (oiReturnStatus)) in BNumber>
                if viFcReturnSuper <> 0 and oiReturnStatus >= 0
                then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0
                then leave NUMBERBLOCK.
                /* =========================================================== */
                /* create temp-table with all numbers that need to be changed. */
                /* =========================================================== */
                create tUpdateInvoiceNumbers.
                assign tUpdateInvoiceNumbers.tiCompany_ID   = tCInvoice.Company_ID
                       tUpdateInvoiceNumbers.tiPeriodYear   = tCInvoice.CInvoicePostingYear
                       tUpdateInvoiceNumbers.tiPeriodPeriod = tCInvoice.CInvoicePostingPeriod
                       tUpdateInvoiceNumbers.tcJournalCode  = tCInvoice.tcJournalCode 
                       tUpdateInvoiceNumbers.tiTempVoucher  = tCInvoice.CInvoiceVoucher
                       tUpdateInvoiceNumbers.tiNewVoucher   = viNewVoucher.
                /* ====================== */
                /* Update Invoice Voucher */
                /* ====================== */
                assign tCInvoice.CInvoiceVoucher = viNewVoucher.
            end. /* for each tCInvoice where */
            /* ========================= */
            /* Update fields in BPosting */
            /* ========================= */
            if viBJournalEntryCIID <> 0 and viBJournalEntryCIID <> ?
            then do:
                <I-16 {bFcOpenInstance
                     &CLASS           = "Transaction"}>
                <M-22 run GetInstanceDetails
                   (input  'BJournalEntry':U (icComponentShortName), 
                    input  viCompanyId (iiCompanyIdOfInstance), 
                    output viDummy (oiInstanceId), 
                    output vhBJournalEntryCIInst (ohInstanceHandle), 
                    output viMethodReturnStatus (oiReturnStatus)) in Transaction>
                <I-49 {bFcCloseInstance
                     &CLASS           = "Transaction"}>
                if viMethodReturnStatus <> 0 and oiReturnStatus >= 0
                then assign oiReturnStatus = viMethodReturnStatus.
                if viMethodReturnStatus < 0
                then leave NUMBERBLOCK.
                if valid-handle(vhBJournalEntryCIInst)
                then do:
                    <M-67 run UpdateInvoiceNumbers
                       (input  tUpdateInvoiceNumbers (tUpdateInvoiceNumbersPosting), 
                        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                    if viFcReturnSuper <> 0 and oiReturnStatus >= 0
                    then assign oiReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0
                    then leave NUMBERBLOCK.
                end. /* if valid-handle(vhBJournalEntryCIInst) */
            end. /* if viBJournalEntryCIID <> 0 and viBJournalEntryCIID <> ? */
            /* =================================== */
            /* Update fields in BQCInvoiceMovement */
            /* =================================== */
            if viBQCInvoiceMovementID <> 0 and viBQCInvoiceMovementID <> ?
            then do:
                <I-57 {bFcOpenInstance
                     &CLASS           = "Transaction"}>
                <M-59 run GetInstanceDetails
                   (input  'BQCInvoiceMovement':U (icComponentShortName), 
                    input  viCompanyId (iiCompanyIdOfInstance), 
                    output viDummy (oiInstanceId), 
                    output vhBQCInvoiceMovementInst (ohInstanceHandle), 
                    output viMethodReturnStatus (oiReturnStatus)) in Transaction>
                <I-26 {bFcCloseInstance
                     &CLASS           = "Transaction"}>
                if viMethodReturnStatus <> 0 and oiReturnStatus >= 0
                then assign oiReturnStatus = viMethodReturnStatus.
                if viMethodReturnStatus < 0
                then leave NUMBERBLOCK.
                if valid-handle(vhBQCInvoiceMovementInst)
                then do:
                    <M-36 run UpdateInvoiceNumbers
                       (input  tUpdateInvoiceNumbers (tUpdateInvoiceNumbersQCIM), 
                        output viFcReturnSuper (oiReturnStatus)) in BQCInvoiceMovement>
                    if viFcReturnSuper <> 0 and oiReturnStatus >= 0
                    then assign oiReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0
                    then leave NUMBERBLOCK.
                end. /* if valid-handle(vhBQCInvoiceMovementInst) */
            end. /* if viBQCInvoiceMovementID <> 0 and viBQCInvoiceMovementID <> ? */
            /* ============================ */
            /* Update fields in BWorkObject */
            /* ============================ */
            if viBWorkObjectID <> 0 and viBWorkObjectID <> ?
            then do:
                <I-31 {bFcOpenInstance
                     &CLASS           = "Transaction"}>
                <M-11 run GetInstanceDetails
                   (input  'BWorkObject':U (icComponentShortName), 
                    input  viCompanyId (iiCompanyIdOfInstance), 
                    output viDummy (oiInstanceId), 
                    output vhBWorkObjectInst (ohInstanceHandle), 
                    output viMethodReturnStatus (oiReturnStatus)) in Transaction>
                <I-13 {bFcCloseInstance
                     &CLASS           = "Transaction"}>
                if viMethodReturnStatus <> 0 and oiReturnStatus >= 0
                then assign oiReturnStatus = viMethodReturnStatus.
                if viMethodReturnStatus < 0
                then leave NUMBERBLOCK.
                if valid-handle(vhBWorkObjectInst)
                then do:
                    <M-89 run UpdateInvoiceNumbers
                       (input  tUpdateInvoiceNumbers (tUpdateInvoiceNumbersWorkObj), 
                        output viFcReturnSuper (oiReturnStatus)) in BWorkObject>
                    if viFcReturnSuper <> 0 and oiReturnStatus >= 0
                    then assign oiReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0
                    then leave NUMBERBLOCK.
                end. /* if valid-handle(vhBWorkObjectInst) */
            end. /* if viBWorkObjectID <> 0 and viBWorkObjectID <> ? */
        end. /* if vlCIDomainIsConsecutNr = true */
    END. /* NUMBERBLOCK: */
    /* Releae number on errors */
    if oiReturnStatus < 0
    then do:
        for each tUpdateInvoiceNumbers:
            assign vhFcComponent = ?.
            <M-12 run ReleaseNumber
               (input  tUpdateInvoiceNumbers.tiCompany_ID (iiCompanyId), 
                input  tUpdateInvoiceNumbers.tiPeriodYear (iiNumbrYear), 
                input  tUpdateInvoiceNumbers.tcJournalCode (icNumbrType), 
                input  tUpdateInvoiceNumbers.tiNewVoucher (iiNumbr), 
                input  viFcCurrentInstanceId (iiInstanceId), 
                input  vcFcComponentName (icClassName), 
                output viFcReturnSuper (oiReturnStatus)) in BNumber>
            if viFcReturnSuper <> 0 and oiReturnStatus >= 0
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.        
        end. /* for each tUpdateInvoiceNumbers: */    
    end. /* if oiReturnStatus < 0 */
    
    /* ================================== */
    /* Assign Creation Date / Time fields */
    /* ================================== */
    for each tCInvoice where
             tCInvoice.tc_Status = "N":
        assign tCInvoice.CInvoiceCreationDate         = today
               tCInvoice.CInvoiceCreationTimeString   = string(time,"HH:MM:SS":U).
    end. /* for each tCInvoice where */
       
    /* ================================================================================================= */
    /* Invoice Certification: Fill the necessary fields for invoice certification and create a signature */
    /* ================================================================================================= */
    /* ========================================================= */
    /* Check if invoice certification is enabled for this domain */
    /* ========================================================= */
    <Q-44 run DomainPropertyByDomainCodeID (all) (Read) (Cache)
       (input vcDomainCode, (DomainCode)
        input viDomainID, (DomainID)
        output dataset tqDomainPropertyByDomainCodeID) in BDomainProperty>
    find first tqDomainPropertyByDomainCodeID where 
               tqDomainPropertyByDomainCodeID.tiDomain_ID = viDomainID
               no-lock no-error.
    if not available tqDomainPropertyByDomainCodeID
    then do:
        assign vcMessage      = #T-79'Unable to retrieve the domain settings.':255(576266750)T-79#
               oiReturnStatus = -3.
        <M-45 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  1 (iiSeverity), 
            input  '':U (icRowid), 
            input  'qadfin-363238':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        return.
    end. /* if not available tqDomainPropertyByDomainCodeID */
    if tqDomainPropertyByDomainCodeID.tlDomainPropertyIsInvCertific = true
    then do:
        /* ====================================================== */
        /* Retrieve the system settings for invoice certification */
        /* ====================================================== */
        <Q-84 run SystemPropertyByAll (all) (Read) (Cache)  (output dataset tqSystemPropertyByAll) in BSystemProperty>
        find first tqSystemPropertyByAll no-lock no-error.
        if not available tqSystemPropertyByAll
        then do:
            assign vcMessage      = #T-4'Unable to retrieve the system settings.':255(803317630)T-4#
                   oiReturnStatus = -3.
            <M-73 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  1 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-319539':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
            return.
        end. /* if not available tqSystemPropertyByAll */
        /* ================================================================ */
        /* Fill the class data item to use in method SignStringUsingOpenSSL */
        /* ================================================================ */
        assign vcOpenSSLDir = tqSystemPropertyByAll.tcSysPropertyInvCertOpenSSLDir.
        if vcOpenSSLDir <> "" and
           vcOpenSSLDIR <> ?  and
           substring(vcOpenSSLDir, length(vcOpenSSLDir, "CHARACTER"), 1, "CHARACTER") <> "~\"
        then assign vcOpenSSLDir = vcOpenSSLDir + "~\".
        /* ========================================= */
        /* Either the LC or the SC needs to be "EUR" */
        /* ========================================= */
        if tqDomainPropertyByDomainCodeID.tcCurrencyCode          <> "EUR" and
           tqDomainPropertyByDomainCodeID.tcStatutoryCurrencyCode <> "EUR" 
        then do:
            assign vcMessage      = substitute(#T-17'Either the base currency or the statutory currency of domain &1 need to be EUR when Invoice Certification is enabled.':255(11607730)T-17#, tqDomainPropertyByDomainCodeID.tcDomainCode)
                   oiReturnStatus = -3.
            <M-69 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  1 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-605106':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
            return.
        end. /* if tqDomainPropertyByDomainCodeID.tcCurrencyCode <> "EUR" and */
        
        /* =================================== */
        /* Loop through all new ERS invoices   */
        /* Only ERS Invoices need to be signed */
        /* =================================== */                
        for each tCInvoice where
                (tCInvoice.tc_Status               = "N" or
                 tCInvoice.tc_Status               = "C") and
                 tCInvoice.CInvoiceIsERS           = true and
                 tCInvoice.CInvoiceIsInitialStatus = false:
            if tCInvoice.tc_Status = "C"            
            then do:
                find t_iCInvoice where
                     t_iCInvoice.tc_Rowid = tCInvoice.tc_Rowid
                     no-lock no-error.
                if available t_iCInvoice and
                   t_iCInvoice.CInvoiceIsInitialStatus = false
                then next.
            end. /* if tCInvoice.tc_Status = "C" */
            
            /* ============================================================== */
            /* get the signature of the previous invoice                      */
            /* First check the instance, if nothing there, check the database */
            /* ============================================================== */
            find last btCInvoice where 
                      btCInvoice.Company_ID              = tCInvoice.Company_ID          and
                      btCInvoice.Journal_ID              = tCInvoice.Journal_ID          and
                      btCInvoice.CInvoicePostingYear     = tCInvoice.CInvoicePostingYear and
                      btCInvoice.CInvoiceIsERS           = true                          and
                      btCInvoice.CInvoiceIsInitialStatus = false                         and
                      btCInvoice.tc_Rowid               <> tCInvoice.tc_Rowid
                      use-index CyYearJrnlVoucher
                      no-error.
            if not available btCInvoice
            then do:
                find last btCInvoice where 
                          btCInvoice.Company_ID              = tCInvoice.Company_ID                and
                          btCInvoice.Journal_ID              = tCInvoice.Journal_ID                and
                          btCInvoice.CInvoicePostingYear     = (tCInvoice.CInvoicePostingYear - 1) and
                          btCInvoice.CInvoiceIsERS           = true                                and
                          btCInvoice.CInvoiceIsInitialStatus = false                               and
                          btCInvoice.tc_Rowid               <> tCInvoice.tc_Rowid
                          use-index CyYearJrnlVoucher
                          no-error.
                if not available btCInvoice
                then do:
                    <Q-68 run CInvoiceForInvCertification (all) (Read) (NoCache)
                       (input tCInvoice.Company_ID, (CompanyId)
                        input tCInvoice.Journal_ID, (JournalId)
                        input true, (CInvoiceIsERS)
                        input false, (CInvoiceIsInitialStatus)
                        output dataset tqCInvoiceForInvCertification) in BCInvoice>
                    find last tqCInvoiceForInvCertification where
                              tqCInvoiceForInvCertification.tiCompany_ID              = tCInvoice.Company_ID and
                              tqCInvoiceForInvCertification.tiJournal_ID              = tCInvoice.Journal_ID and
                              tqCInvoiceForInvCertification.tlCInvoiceIsERS           = true                 and
                              tqCInvoiceForInvCertification.tlCInvoiceIsInitialStatus = false
                              no-error.
                    if available tqCInvoiceForInvCertification
                    then assign vcPreviousSignature = tqCInvoiceForInvCertification.tcCInvoiceInvCertSignatureCurr.
                    else assign vcPreviousSignature = "".
                end. /* if not available bCInvoice */
                else assign vcPreviousSignature = btCInvoice.CInvoiceInvCertSignatureCurr.
            end. /* if not available bCInvoice */
            else assign vcPreviousSignature = btCInvoice.CInvoiceInvCertSignatureCurr.
            /* ============================================= */
            /* Fill in necessary fields to get our signature */
            /* ============================================= */
            assign tCInvoice.CInvoiceInvCertCertificate   = tqSystemPropertyByAll.tcSysPropertyInvCertCertificate
                   tCInvoice.CInvoiceInvCertSignaturePrev = vcPreviousSignature.
            if tqDomainPropertyByDomainCodeID.tcCurrencyCode = "EUR"
            then assign vdInvoiceAmountInEUR = abs(tCInvoice.CInvoiceOriginalDebitLC - tCInvoice.CInvoiceOriginalCreditLC).
            else assign vdInvoiceAmountInEUR = abs(tCInvoice.CInvoiceOriginalDebitCC - tCInvoice.CInvoiceOriginalCreditCC).
            /* ============================================================== */
            /* Create the Key for our invoice, so we can create the signature */
            /* This fields in this key need to semicolon separated.           */
            /* ============================================================== */
            if tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE} or
               tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
            then assign vcInvoiceType = "NC".
            else assign vcInvoiceType = "FT".
            assign tCInvoice.CInvoiceInvCertKey = 
                        string(year(tCInvoice.CInvoiceDate), "9999")         + "-" + string(month(tCInvoice.CInvoiceDate), "99")         + "-" + string(day(tCInvoice.CInvoiceDate), "99") + ";" +
                        string(year(tCInvoice.CInvoiceCreationDate), "9999") + "-" + string(month(tCInvoice.CInvoiceCreationDate), "99") + "-" + string(day(tCInvoice.CInvoiceCreationDate), "99") + "T" + trim(tCInvoice.CInvoiceCreationTimeString) + ";" +
                        trim(vcInvoiceType) + " " + string(tCInvoice.CInvoicePostingYear, "9999") + trim(caps(tCInvoice.tcJournalCode)) + "/" + string(tCInvoice.CInvoiceVoucher, "999999999") + ";" +
                        trim(string(vdInvoiceAmountInEUR, ">>>>>>>>>>>>>>>9.99")) + ";".
            /* ================================== */
            /* Get the signature for this invoice */
            /* ================================== */
            assign vhFcComponent = ?.
            <M-47 run SignStringUsingOpenSSL
               (input  tCInvoice.CInvoiceInvCertKey + vcPreviousSignature (icStringToSign), 
                input  vcOpenSSLDir (icOpenSSLDir), 
                input  viSessionId (iiSessionId), 
                output tCInvoice.CInvoiceInvCertSignatureCurr (ocSignatureForInputString), 
                output vcMessage (ocMessage), 
                output viFcReturnSuper (oiReturnStatus)) in TOpenSSL>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.
                        
            if viFcReturnSuper <> 0 and 
               vcMessage <> ''      and 
               vcMessage <> ?
            then do:
                <M-10 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  1 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-285184':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>                
            end. /* if viFcReturnSuper <> 0 and vcMessage <> '' */

            run gipr_DeleteProcedure in vhFcComponent.
            delete procedure vhFcComponent.
            if oiReturnStatus < 0
            then return.            
            
            /* Set the 4-character signature of the invoice based upon the full signature and redundantly store the invoice-certificate - that is stored on system-level - on the invoice itself */
            assign tCInvoice.CInvoiceInvCertSignatureShort = substring(tCInvoice.CInvoiceInvCertSignatureCurr,1,1,'Character':U) + 
                                                             substring(tCInvoice.CInvoiceInvCertSignatureCurr,11,1,'Character':U) + 
                                                             substring(tCInvoice.CInvoiceInvCertSignatureCurr,21,1,'Character':U) + 
                                                             substring(tCInvoice.CInvoiceInvCertSignatureCurr,31,1,'Character':U)  
                   tCInvoice.CInvoiceInvCertVersion        = tqSystemPropertyByAll.tcSysPropertyInvCertVersion.                           
        end. /* for each tCInvoice where */         
    end. /* if tqDomainPropertyByDomainCodeID.tlDomainPropertyIsInvCertific = true */