project QadFinancials > class BExpenseNote > method CreateExpNoteLineSafs


Parameters


icParentRowidinputcharacter
icSafParentTypeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BExpenseNote.PreValidateComponent


program code (program1/bexpensenote.p)

find first t_sExpNoteLine where t_sExpNoteLine.tc_Rowid = icParentRowid no-error.
if not available t_sExpNoteLine
then return.

if t_sExpNoteLine.tcSafStructureCode <> "":U and 
   t_sExpNoteLine.tcSafStructureCode <> "?":U and
   t_sExpNoteLine.tcSafStructureCode <> ?
then do:
    <Q-9 run SafStructureByCode (all) (Read) (NoCache)
          (input t_sExpNoteLine.tcSafStructureCode, (SafStructureCode)
           output dataset tqSafStructureByCode) in BSafStructure >
    find first tqSafStructureByCode no-error.
    if available tqSafStructureByCode
    then assign viSafStructure_ID = tqSafStructureByCode.tiSafStructure_ID.
end.
do viSafSeq = 1 to 5:
    if (viSafSeq = 1 and
        (t_sExpNoteLine.tcSAFConcept1 = "":U or
         t_sExpNoteLine.tcSAFConcept1 = "?":U or
         t_sExpNoteLine.tcSAFConcept1 = ?)) or
        (viSafSeq = 2 and
        (t_sExpNoteLine.tcSAFConcept2 = "":U or
         t_sExpNoteLine.tcSAFConcept2 = "?":U or
         t_sExpNoteLine.tcSAFConcept2 = ?)) or
        (viSafSeq = 3 and
        (t_sExpNoteLine.tcSAFConcept3 = "":U or
         t_sExpNoteLine.tcSAFConcept3 = "?":U or
         t_sExpNoteLine.tcSAFConcept3 = ?)) or
        (viSafSeq = 4 and
        (t_sExpNoteLine.tcSAFConcept4 = "":U or
         t_sExpNoteLine.tcSAFConcept4 = "?":U or
         t_sExpNoteLine.tcSAFConcept4 = ?)) or
        (viSafSeq = 5 and
        (t_sExpNoteLine.tcSAFConcept5 = "":U or
         t_sExpNoteLine.tcSAFConcept5 = "?":U or
         t_sExpNoteLine.tcSAFConcept5 = ?))
    then do:
        find first t_sExpNoteLineSaf where
               t_sExpNoteLineSaf.tc_ParentRowid              = icParentRowid and
               t_sExpNoteLineSaf.ExpNoteLineSafInputSeq = viSafSeq
               no-error.
        /* delete obsolete tExpNoteLineSaf*/          
        if available t_sExpNoteLineSaf
        then do:
            if t_sExpNoteLineSaf.tc_Status = "N":U
            then assign t_sExpNoteLineSaf.tc_Status = "":U.
            else assign t_sExpNoteLineSaf.tc_Status = "D":U.
        end.
    end.
    else do:
        case viSafSeq:
            when 1
            then do:
                if t_sExpNoteLine.tcSAFCode1 <> "":U and
                   t_sExpNoteLine.tcSAFCode1 <> "?":U and
                   t_sExpNoteLine.tcSAFCode1 <> ?
                then do:
                    <Q-4 run SafByCode (all) (Read) (NoCache)
          (input t_sExpNoteLine.tcSAFCode1, (SafCode)
           output dataset tqSafByCode) in BSaf >
                    find first tqSafByCode no-error.
                    if available tqSafByCode
                    then assign viSaf_ID = tqSafByCode.tiSaf_ID.
                end.
            end.
            when 2
            then do:
                if t_sExpNoteLine.tcSAFCode2 <> "":U and
                   t_sExpNoteLine.tcSAFCode2 <> "?":U and
                   t_sExpNoteLine.tcSAFCode2 <> ?
                then do:
                    <Q-5 run SafByCode (all) (Read) (NoCache)
          (input t_sExpNoteLine.tcSAFCode2, (SafCode)
           output dataset tqSafByCode) in BSaf >
                    find first tqSafByCode no-error.
                    if available tqSafByCode
                    then assign viSaf_ID = tqSafByCode.tiSaf_ID.
                end.
            end.
            when 3
            then do:
                if t_sExpNoteLine.tcSAFCode3 <> "":U and
                   t_sExpNoteLine.tcSAFCode3 <> "?":U and
                   t_sExpNoteLine.tcSAFCode3 <> ?
                then do:
                    <Q-6 run SafByCode (all) (Read) (NoCache)
          (input t_sExpNoteLine.tcSAFCode3, (SafCode)
           output dataset tqSafByCode) in BSaf >
                    find first tqSafByCode no-error.
                    if available tqSafByCode
                    then assign viSaf_ID = tqSafByCode.tiSaf_ID.
                end.
            end.
            when 4
            then do:
                if t_sExpNoteLine.tcSAFCode4 <> "":U and
                   t_sExpNoteLine.tcSAFCode4 <> "?":U and
                   t_sExpNoteLine.tcSAFCode4 <> ?
                then do:
                    <Q-7 run SafByCode (all) (Read) (NoCache)
          (input t_sExpNoteLine.tcSAFCode4, (SafCode)
           output dataset tqSafByCode) in BSaf >
                    find first tqSafByCode no-error.
                    if available tqSafByCode
                    then assign viSaf_ID = tqSafByCode.tiSaf_ID.
                end.
            end.
            when 5
            then do:
                if t_sExpNoteLine.tcSAFCode5 <> "":U and
                   t_sExpNoteLine.tcSAFCode5 <> "?":U and
                   t_sExpNoteLine.tcSAFCode5 <> ?
                then do:
                    <Q-8 run SafByCode (all) (Read) (NoCache)
          (input t_sExpNoteLine.tcSAFCode5, (SafCode)
           output dataset tqSafByCode) in BSaf >
                    find first tqSafByCode no-error.
                    if available tqSafByCode
                    then assign viSaf_ID = tqSafByCode.tiSaf_ID.
                end.
            end.
        end case.
        find first tExpNoteLineSaf where
                   tExpNoteLineSaf.tc_ParentRowid              = icParentRowid and
                   tExpNoteLineSaf.ExpNoteLineSafInputSeq = viSafSeq
                   no-error.
        /*create tExpNoteLineSaf and t_sExpNoteLineSaf*/          
        if not available tExpNoteLineSaf
        then do:
            <M-1 run AddDetailLine (input  'ExpNoteLineSaf':U (icTable), 
                            input  icParentRowid (icParentRowid), 
                            output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
            if viFcReturnSuper <> 0
            then do:
                assign vcMessage      = trim(#T-10'The system cannot create a new expense note line SAF record.':200(1903)t-10#)
                       oiReturnStatus = -3.
                <M-2 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  icParentRowid (icRowid),
                     input  'QADFIN-2710':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
                return.                     
            end.
                                             
            assign tExpNoteLineSaf.ExpNoteLineSafParentType    = icSafParentType
                   tExpNoteLineSaf.ExpNoteLineSafInputSeq = viSafSeq
                   tExpNoteLineSaf.Saf_ID                      = viSaf_ID
                   tExpNoteLineSaf.SafStructure_ID             = viSafStructure_ID
                   tExpNoteLineSaf.tc_Status                   = 'N':U.
        
            /*For newly created tExpNoteLineSaf records create t_s equivalent*/
            create t_sExpNoteLineSaf.
            buffer-copy tExpNoteLineSaf to t_sExpNoteLineSaf.    
        end.  
        /*create or update t_sExpNoteLineSaf*/
        else do:
            if viSaf_ID <> tExpNoteLineSaf.Saf_ID or
               viSafStructure_ID <> tExpNoteLineSaf.SafStructure_ID
            then do:
                assign tExpNoteLineSaf.Saf_ID = viSaf_ID
                       tExpNoteLineSaf.SafStructure_ID = viSafStructure_ID.
                if tExpNoteLineSaf.tc_Status = "":U
                then assign tExpNoteLineSaf.tc_Status = "C":U.
            end.
            find first t_sExpNoteLineSaf where 
                       t_sExpNoteLineSaf.ExpNoteLineSaf_ID = tExpNoteLineSaf.ExpNoteLineSaf_ID no-error.
            if not available t_sExpNoteLineSaf
            then create t_sExpNoteLineSaf.
            buffer-copy tExpNoteLineSaf to t_sExpNoteLineSaf.
        end.


    end.
end.