Saturday, May 18, 2019

Close Old Price Agreements


static void OGSCloseOldPriceAgreements(Args _args)
{
    PriceDiscTable getTable, setTable, getTop;
    DataAreaId comp;
    Int recCount;
    ToDate toDate;

    getTable = null;
    while select count(RecId) from getTable
        order by getTable.FromDate Desc
        group by getTable.dataAreaId, getTable.ItemRelation
        where getTable.ToDate == dateNull() // && getTable.ItemRelation == 'FP-GIP503-ASI'
    {
        //comp = getTable.getFieldValue("dataAreaId");
        //changeCompany(comp)
        //{
        if (getTable.RecId > 1)
        {
            getTop = null;
            select firstOnly getTop
            order by getTop.FromDate desc
            where getTop.dataAreaId == getTable.getFieldValue("dataAreaId") &&
            getTop.ItemRelation == getTable.getFieldValue("ItemRelation") &&
            getTop.ToDate == dateNull();

            setTable = null;
            While select forUpdate setTable
            where setTable.dataAreaId == getTable.getFieldValue("dataAreaId") &&
            setTable.ItemRelation == getTable.getFieldValue("ItemRelation") &&
            setTable.RecId != getTop.RecId &&
            setTable.ToDate == dateNull()
            {
                ttsBegin;
                setTable.ToDate = getTop.FromDate - 1;
                setTable.update();
                ttsCommit;
                recCount++;
            }
        }
        //}
    }
    info(strFmt("Records processed : %1",recCount));
}

No comments:

Post a Comment