project QadFinancials > class TConCheck > method TechnicalValidation08DHist

Description

Submethod of TechnicalValidation for checking DHist


Parameters


iiCompanyIDinputinteger
itFromDateinputdate
itToDateinputdate
oiErrorNumbersoutputinteger
iiYearPeriodinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method TConCheck.TechnicalValidation


program code (program1/tconcheck.p)

/**********************************************************************************/
/* IPR_AR_CHECK_HIST                                                              */
/**********************************************************************************/
PUT STREAM sTechOut unformatted " " skip. 
PUT STREAM sTechOut unformatted vcPrefix2 + "Start Validation of AR HISTORY (" + STRING (itFromDate) + ") " skip.

IPR_AR_CHECK_HIST:
do:
    if can-find (first QDinvoiceMovement no-lock where QDInvoiceMovement.Company_ID = iiCompanyID 
                                    and QDInvoiceMovement.MovementYearPeriod <= iiYearPeriod)
    then do :
       PUT STREAM sTechOut unformatted vcPrefix + " History cannot be checked as there are still records in the daemon queue (QDinvoiceMovement)" skip.
       assign oiErrorNumbers = oiErrorNumbers + 1.
       leave IPR_AR_CHECK_HIST.
    end.
    
    for each DHist fields (DHist.Company_ID DHist.DHist_ID) where DHist.dHistYearPeriodFrom = iiYearPeriod
       no-lock break by DHist.Company_ID :
       if first-of (DHist.Company_ID) and not can-find (Company of DHist)
       then do:
           PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (DHist.DHist_ID) + ";DHist(s) found with no valid company" skip.
           assign oiErrorNumbers = oiErrorNumbers + 1.
       end.
    end.
    
    for each Company no-lock where company.company_id = iiCompanyID:
        ASSIGN viYearPeriod = 0.
        FOR FIRST period of Company where 
                      period.PeriodStartDate <= itFromDate AND
                      Period.PeriodEndDate   >= itFromDate
                      NO-LOCK:
                ASSIGN viYearPeriod = Period.PeriodYearPeriod.
        END.
 		/* Get sharedset of the company */
		for each companysharedset no-lock where companysharedset.company_id = company.company_id,
			each sharedset of companysharedset no-lock:
			if sharedsettype = {&SHAREDSETTYPE-GL} then
				assign viGLShareSetID = sharedset.sharedset_id.
			if sharedsettype = {&SHAREDSETTYPE-DIVISION} then
				assign viDivisionSharedSetID = sharedset.sharedset_id.
			if sharedsettype = {&SHAREDSETTYPE-COSTCENTRE} then
				assign viCostCenterSharedSetID = sharedset.sharedset_id.
			if sharedsettype = {&SHAREDSETTYPE-PROJECT} then 
				assign viProjectSharedSetID = sharedset.sharedset_id.
			if sharedsettype = {&SHAREDSETTYPE-JOURNAL}  then
				assign viJournalSharedSetID = sharedset.sharedset_id.
			if sharedsettype = {&SHAREDSETTYPE-DEBTOR}  then
				assign viDebtorSharedSetID = sharedset.sharedset_id.
		end. /* end each companysharedset */
   
        /* Check Consisttency of DHist */
        for each DHist of Company NO-LOCK WHERE
                 DHist.DHistYearPeriodFrom = viYearPeriod :
    
            /* Check GL */
            find first GL where
                       GL.GL_ID = DHist.GL_ID 
                       AND GL.SharedSet_ID = viGLShareSetID no-lock no-error.
            if not available GL
            then do:
                    if GL.GLType <> 'DEBTORCONTROL'
                    then do:
                        PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (DHist.DHist_ID) + ";DHist found with GL of wrong type" skip.
                        assign oiErrorNumbers = oiErrorNumbers + 1.
                    end.
            end.
            else do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (DHist.DHist_ID) + ";GL was not found" skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
    
            /* Check Debtor */
            find first Debtor where
                       Debtor.Debtor_id = DHist.Debtor_ID 
                       AND Debtor.SharedSet_ID = viDebtorSharedSetID no-lock no-error.
            if not available Debtor
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (DHist.DHist_ID) + ";Debtor was not found" skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
    
            /* Check Journal */
            find first Journal where
                       Journal.Journal_id = DHist.Journal_ID 
                       AND Journal.SharedSet_ID = viJournalSharedSetID no-lock no-error.
            if not available Journal
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (DHist.DHist_ID) + ";Journal was not found" skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.        
    
            /* Check Division */
            if DHist.Division_ID <> 0 and DHist.Division_ID <> ?
            then do :
                find first Division where
                           Division.Division_id = DHist.Division_ID 
                           AND Division.SharedSet_ID = viDivisionSharedSetID no-lock no-error.
                if not available Division
                then do:
                    PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (DHist.DHist_ID) + ";Division was not found" skip.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                end.
            end.
        end. /* for each DHist */
    
    
        /* Check the balance for each debtor */
        for each Debtor where Debtor.SharedSet_ID = viDebtorSharedSetID no-lock:
    
            assign vdBalance1TC = 0 vdBalance2TC = 0 vdBalance3TC = 0 vdBalance4TC = 0
                   vdBalance1LC = 0 vdBalance2LC = 0 vdBalance3LC = 0 vdBalance4LC = 0
                   vdBalance1CC = 0 vdBalance2CC = 0 vdBalance3CC = 0 vdBalance4CC = 0.
    
            /* Get the current balance of the debtor using DInvoice */
            for each dinvoice where
                     dinvoice.Company_ID = company.company_id and
                     dinvoice.debtor_ID  = debtor.debtor_id and
                     dInvoice.dInvoiceIsOpen
                     no-lock :
                assign vdBalance1TC = vdBalance1TC + DInvoice.DInvoiceBalanceTC
                       vdBalance1LC = vdBalance1LC + DInvoice.DInvoicebalancelc
                       vdBalance1CC = vdBalance1CC + DInvoice.DInvoiceBalanceCC.
            end.
    
            /* Get the current balance of the debtor using DHist */
            for each DHist where
                     DHist.Company_ID          = company.company_id and
                     DHist.debtor_ID           = debtor.debtor_id
                     no-lock :
    
                if DHist.DHistYearPeriodTill = 999999
                then assign vdBalance2TC = vdBalance2TC + DHist.DHistBalanceTC
                            vdBalance2LC = vdBalance2LC + DHist.DHistBalanceLC
                            vdBalance2CC = vdBalance2CC + DHist.DHistBalanceCC.
    
                assign vdBalance3TC = vdBalance3TC + DHist.DHistMovementDebitTC - DHist.DHistMovementCreditTC
                       vdBalance3LC = vdBalance3LC + DHist.DHistMovementDebitLC - DHist.DHistMovementCreditLC
                       vdBalance3CC = vdBalance3CC + DHist.DHistMovementDebitCC - DHist.DHistMovementCreditCC.
    
            end. /* for each DHist */
    
    
            /* Get the current balance of the debtor using DBalance */
            for each DBalance where
                     DBalance.Company_ID = company.company_id and
                     DBalance.debtor_ID  = debtor.debtor_id
                     no-lock :
                assign vdBalance4TC = vdBalance4TC + DBalance.DBalanceTC
                       vdBalance4LC = vdBalance4LC + DBalance.DBalanceLC
                       vdBalance4CC = vdBalance4CC + DBalance.DBalanceCC.
            end. /* for each DBalance */
    
    
            /* 1: DInvoice
               2:  DHist Balance
               3:  DHist Movement
               4:  DBlance Balance */		
            if vdBalance1TC <> vdBalance3TC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in TC Amount for this debtor (Dinvoice vs DHist), " +
                      "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1TC) + ' * ' + string (vdBalance3TC) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            if vdBalance3TC <> vdBalance2TC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in TC Amount for this debtor (DHist vs DHist Balance), " +
                      "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1TC) + ' * ' + string (vdBalance3TC) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            if vdBalance1TC <> vdBalance4TC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in TC Amount for this debtor (Dinvoice vs DBalance), " +
                    "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1TC) + ' * ' + string (vdBalance3TC) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
    
            if vdBalance1LC <> vdBalance3LC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in LC Amount for this debtor (Dinvoice vs DHist Movement), " +
                   "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1LC) + ' * ' + string (vdBalance3LC) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            
            if vdBalance3LC <> vdBalance2LC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in LC Amount for this debtor (DHist Movement vs DHist Balance), " +
                      "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1LC) + ' * ' + string (vdBalance3LC) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            
            if vdBalance1LC <> vdBalance4LC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in LC Amount for this debtor (Dinvoice vs DBalance), " +
                      "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1LC) + ' * ' + string (vdBalance3LC) skip.        
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
    
            if vdBalance1CC <> vdBalance3CC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in CC Amount for this debtor (Dinvoice vs DHist Movement), " +
                      "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1CC) + ' * ' + string (vdBalance3CC) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            
            if vdBalance3CC <> vdBalance2CC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in CC Amount for this debtor (DHist Movement vs DHist Balance), " +
                      "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1CC) + ' * ' + string (vdBalance3CC) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
            
            if vdBalance1CC <> vdBalance4CC
            then do:
                PUT STREAM sTechOut unformatted vcPrefix + "DHist;" + string (debtor.Debtor_ID) + ";Mismatch in CC Amount for this debtor (Dinvoice vs DBalance), " +
                      "DebtorCode= " + debtor.DebtorCode + ', ' + string (vdBalance1CC) + ' * ' + string (vdBalance3CC) skip.
                assign oiErrorNumbers = oiErrorNumbers + 1.
            end.
    
        end. /* for each ttDebtor */
    
    end. /* for each Company */

end. /* IPR_AR_CHECK_HIST */

PUT STREAM sTechOut unformatted vcPrefix2 + "END Validation of AR HISTORY" skip.