Search code examples
axaptadynamics-ax-2009x++ax

Changing ProdRouteJob has no effect to WrkCtrCapRes or recalculating the capacity reservations


I'm changing the route jobs (ProdRouteJob) with optimised data from an external optimisation tool. The changed data is written with a simple ax class and a prodRouteJob.update(). The problem now is, that the capacity reservations (WrkCtrCapRes) will not get updated. Is the a way to recalculate the capacity reservations? Or create new capacity reservations?


Solution

  • The only place where WrkCtrCapRes is updated is in the WrkCtrJobData.updateCapacityReservations() method. The class WrkCtrJobData requires WrkCtrScheduleJobs and other deep down complexities.

    The ProdRouteJob does not have the full knowledge to update capacity reservation, it will have to take calendar into consideration.

    I have made the following method to do a similar update. It does not support "Base calendar", but otherwise did what I needed.

    Hours updateWrkCtrCapRes(ProdRouteJob prodRouteJob, WrkCtrTable wrkCtrTable = WrkCtrTable::find(prodRouteJob.WrkCtrId))
    {
        WrkCtrCapRes         wrkCtrCapRes;
        WorkCalendarDateLine workCalendarDateLine;
        Seconds              sec;    
        delete_from wrkCtrCapRes
            where wrkCtrCapRes.RefType     == WrkCtrCapRefType::Production &&
                  wrkCtrCapRes.RefId       == prodRouteJob.ProdId &&
                  wrkCtrCapRes.OprNum      == prodRouteJob.OprNum &&
                  wrkCtrCapRes.OprPriority == prodRouteJob.OprPriority &&
                  wrkCtrCapRes.JobId       == prodRouteJob.JobId;    
        wrkCtrCapRes.ReqPlanId     = ReqPlanSched::defaultDynamicId();
        wrkCtrCapRes.LoadType      = WrkCtrCapacityType::JobSched;
        wrkCtrCapRes.RefType       = WrkCtrCapRefType::Production;
        wrkCtrCapRes.RefId         = prodRouteJob.ProdId;
        wrkCtrCapRes.OprNum        = prodRouteJob.OprNum;
        wrkCtrCapRes.OprPriority   = prodRouteJob.OprPriority;
        wrkCtrCapRes.JobType       = prodRouteJob.JobType;
        wrkCtrCapRes.JobId         = prodRouteJob.JobId;
        wrkCtrCapRes.Locked        = prodRouteJob.Locked;    
        wrkCtrCapRes.WrkCtrGroupId = wrkCtrTable.WrkCtrGroupId;
        wrkCtrCapRes.WrkCtrId      = wrkCtrTable.WrkCtrId;
        wrkCtrCapRes.WrkCtrLoadPct = 100.0;    
        while select workCalendarDateLine
            where workCalendarDateLine.CalendarId == wrkCtrTable.CalendarId &&
                  workCalendarDateLine.TransDate  >= prodRouteJob.FromDate &&
                  workCalendarDateLine.TransDate  <= prodRouteJob.ToDate
        {
            if (workCalendarDateLine.TransDate == prodRouteJob.FromDate)
                workCalendarDateLine.FromTime   = max(workCalendarDateLine.FromTime, prodRouteJob.FromTime);
            if (workCalendarDateLine.TransDate == prodRouteJob.ToDate)
                workCalendarDateLine.ToTime     = min(workCalendarDateLine.ToTime, prodRouteJob.ToTime);
            if (workCalendarDateLine.FromTime < workCalendarDateLine.ToTime)
            {
                wrkCtrCapRes.TransDate = workCalendarDateLine.TransDate;
                wrkCtrCapRes.StartTime = workCalendarDateLine.FromTime;
                wrkCtrCapRes.EndTime   = workCalendarDateLine.ToTime;
                wrkCtrCapRes.WrkCtrSec = wrkCtrCapRes.EndTime - wrkCtrCapRes.StartTime;
                wrkCtrCapRes.insert();
                sec += wrkCtrCapRes.WrkCtrSec;
            }
        }
        return decRound(sec / 3600.0, 5);
    }