project QadFinancials > class BBalanceDaemonQueue > method CreateBalanceDaemonQueue

Description

This method will create DaemonQueue records


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBalanceDaemonProcessor.LoadExternalWork


program code (program6/bbalancedaemonqueue.p)

/* ===================================== */
/* Start with a clean and empty instance */
/* ===================================== */
<M-18 run ClearData  (output viFcReturnSuper (oiReturnStatus)) in BBalanceDaemonQueue>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* ============================== */
/* Find the Balance Daemon-record */
/* ============================== */
<Q-1 run DaemonPrim (all) (Read) (NoCache)
          (input {&BALANCEDAEMON}, (DaemonName)
           input ?, (DaemonId)
           output dataset tqDaemonPrim) in BBaseDaemon >
find tqDaemonPrim where
     tqDaemonPrim.tcDaemonName = {&BALANCEDAEMON}
     no-lock no-error.
if not available tqDaemonPrim
then do:
    assign vcBalanceDQMsg = trim(#T-17'The Balance daemon record is not defined in the system.':100(264)t-17#)
           oiReturnStatus = -3.
    <M-5 run SetMessage (input  vcBalanceDQMsg (icMessage),
                     input  '':U (icArguments),
                     input  'tqDaemonPrim.tcDaemonName':U (icFieldName),
                     input  {&BALANCEDAEMON} (icFieldValue),
                     input  'E':U (icType),
                     input  2 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1310':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBalanceDaemonQueue>
    return.
end.

/* ================================= */
/* Get the QCInvoiceMovement records */
/* ================================= */
/* Instead of reading all the QRecords, just take the first 100, including */
/* the ones which gave an error during the last run                                   */
/* Note the next query-call was changed but this is not reflected in the CB Editor    */
assign viNbrRecordsToRead = viCountErrorQueuesCI + 100.
<Q-2 run QCInvoiceMovementAll (firstviNbrRecordsToRead) (Read) (NoCache)
   (input ?, (CompanyId)
    input tqDaemonPrim.tiDaemonId, (DaemonId)
    output dataset tqQCInvoiceMovementAll) in BQCInvoiceMovement>

/* Start the Persistence Layer for BQposting */
if can-find (first tqQCInvoiceMovementAll) and vhPerstistenceLayerHandleLocal = ?
then do :
    <M-43 run StartPersistence
       (output vhPerstistenceLayerHandleLocal (ohPersistence), 
        output viFcReturnSuper (oiReturnStatus)) in BBalanceDaemonQueue>
end. /* IF can-find (first tqQCInvoiceMovementAll) and .. */
assign viCount = 0
       viCountErrorQueuesCI = 0.
           
for each tqQCInvoiceMovementAll no-lock:
    assign viCountErrorQueuesCI = viCountErrorQueuesCI + 1.

    /* ============================================== */
    /* Check if DaemonQueue record is already created */
    /* ============================================== */
    if tqQCInvoiceMovementAll.tiQCInvoiceMovement_ID = 0 or 
       tqQCInvoiceMovementAll.tiQCInvoiceMovement_ID = ? or 
       tqQCInvoiceMovementAll.tiCompany_ID           = 0 or
       tqQCInvoiceMovementAll.tiCompany_ID           = ?
    then next.

    /* Skip if already in a queue */       
    if tqQCInvoiceMovementAll.tiDaemonQueueId <> 0 and 
       tqQCInvoiceMovementAll.tiDaemonQueueId <> ? and 
       tqQCInvoiceMovementAll.tiDaemonId = tqDaemonPrim.tiDaemonId
    then next.

    /* if qRecord is still locked, then skip it */
    assign vcRowID = ?.
    if vhPerstistenceLayerHandleLocal <> ?
    then do :        
          assign vcRowID = entry (1,tqQCInvoiceMovementAll.tc_RowID).
          if vcRowID <> '' and vcRowID <> ?
          then do :
             assign vhFcComponent = vhPerstistenceLayerHandleLocal.
             if <M-75 RecordIsLocked
                   (input  'QCinvoiceMovement' (icTableName), 
                    input  vcRowID (icRecordRowid)) in Progress> = true
             then next.
         end. /* IF vcRowID <> '' and vcRowID <> ? */
     end. /* IF vhPerstistenceLayerHandleLocal <> ? */

    assign viCountErrorQueuesCI = viCountErrorQueuesCI - 1.

    <M-3 run AddDetailLine (input  'fcDaemonQueue':U (icTable), 
                        input  ? (icParentRowid), 
                        output oiReturnStatus (oiReturnStatus)) in BBalanceDaemonQueue>
    if oiReturnStatus <> 0
    then leave.

    assign tfcDaemonQueue.DaemonId                  = tqDaemonPrim.tiDaemonId
           tfcDaemonQueue.DaemonQueueStatus         = {&DAEMONQUEUESTATUS-WAITING}
           tfcDaemonQueue.DaemonQueuePriority       = 1
           tfcDaemonQueue.DaemonQueueRef            = string(tqQCInvoiceMovementAll.tiQCInvoiceMovement_ID)
           tfcDaemonQueue.DaemonQueueRefDescription = 'CI: ':U + trim(tqQCInvoiceMovementAll.tcCInvoiceMovementInfo) + '  ((':U + trim(string(tqQCInvoiceMovementAll.tiCompany_ID)) + '))':U.       
    
    /* Just process first 100 records  */
    assign viCount = viCount + 1.
    if viCount > 100
    then leave.
               
end.

/* ================================= */
/* Get the QCDnvoiceMovement records */
/* ================================= */

if viCount > 100
then empty temp-table tqQDInvoiceMovementAll.
else do: 
    assign viNbrRecordsToRead = viCountErrorQueuesDI + 100.    
     <Q-16 run QDInvoiceMovementAll (firstviNbrRecordsToRead) (Read) (NoCache)
        (input ?, (CompanyId)
         input tqDaemonPrim.tiDaemonId, (DaemonId)
         output dataset tqQDInvoiceMovementAll) in BQDInvoiceMovement>           
end. /* not if viCount > 100 */
assign viCountErrorQueuesDI = 0.

for each tqQDInvoiceMovementAll no-lock:
    assign viCountErrorQueuesDI = viCountErrorQueuesDI + 1.

    /* Check if DaemonQueue record is already created or if the QPostingLine is already created properly */
    if tqQDInvoiceMovementAll.tiQDInvoiceMovement_ID = 0 or 
       tqQDInvoiceMovementAll.tiQDInvoiceMovement_ID = ? or 
       (tqQDInvoiceMovementAll.tiDaemonQueueId <> 0 and 
        tqQDInvoiceMovementAll.tiDaemonQueueId <> ? and 
        tqQDInvoiceMovementAll.tiDaemonId       = tqDaemonPrim.tiDaemonId)
    then next.

    /* if qRecord is still locked, then skip it */
    assign vcRowID = ?.
    if vhPerstistenceLayerHandleLocal <> ?
    then do :        
         assign vcRowID = entry (1,tqQDInvoiceMovementAll.tc_Rowid).
         if vcRowID <> '' and vcRowID <> ?
         then do :
            assign vhFcComponent = vhPerstistenceLayerHandleLocal.
            if <M-25 RecordIsLocked
                  (input  'QDinvoiceMovement' (icTableName), 
                   input  vcRowID (icRecordRowid)) in Progress> = true
            then next.
        end. /* IF vcRowID <> '' and vcRowID <> ? */
    end. /* IF vhPerstistenceLayerHandleLocal <> ? */ 

    assign viCountErrorQueuesDI = viCountErrorQueuesDI - 1.
    <M-14 run AddDetailLine (input  'fcDaemonQueue':U (icTable), 
                        input  ? (icParentRowid), 
                        output oiReturnStatus (oiReturnStatus)) in BBalanceDaemonQueue>
    if oiReturnStatus <> 0
    then leave.

    assign tfcDaemonQueue.DaemonId                  = tqDaemonPrim.tiDaemonId
           tfcDaemonQueue.DaemonQueueStatus         = {&DAEMONQUEUESTATUS-WAITING}
           tfcDaemonQueue.DaemonQueuePriority       = 1
           tfcDaemonQueue.DaemonQueueRef            = string(tqQDInvoiceMovementAll.tiQDInvoiceMovement_ID)
           tfcDaemonQueue.DaemonQueueRefDescription = 'DI: ':U + trim(tqQDInvoiceMovementAll.tcDInvoiceMovementInfo) + ' ((':U + trim(string(tqQDInvoiceMovementAll.tiCompany_ID)) + '))':U.       
    
    /* Just process first 100 records  */
    assign viCount = viCount + 1.
    if viCount > 100
    then leave.
    
end.

if oiReturnStatus < 0
then return.

if viCount > 0
then do :

    /* ========================================== */
    /* Run Validate Component BBalanceDaemonQueue */
    /* ========================================== */
    <M-6 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BBalanceDaemonQueue>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.   
    if oiReturnStatus < 0
    then return.    
    
    /* ==================== */
    /* Run Addition Updates */
    /* ==================== */
    <M-7 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BBalanceDaemonQueue>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.        
    if oiReturnStatus < 0
    then return.    
    
    /* ============================================================== */
    /* Run Datasave for BBalanceDaemonQueue                           */
    /* ============================================================== */
    <M-8 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BBalanceDaemonQueue>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnstatus = viFcReturnSuper.        
    if oiReturnStatus < 0
    then return.    

end. /* viCount */