Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Wednesday, January 25, 2017

Code to get WBS and Summary cost and sales estimates of an smmActivity

public static void SummarySalesPriceEstimates()
{

    ProjWBSUpdateController                 controllerLoc;
    HierarchyIdBase                         hierarchyIdLoc;
    HierarchyTreeTable                      hierarchyTreeTableLoc;
    str                                           recordWBSId;
    smmActivities                           smmActivitiesLoc;
    ProjTable                               projTableLoc;
    CalendarId                              calendarIdLoc;
    PSAActivityEstimates                    localPSAActivityEstimates;
    HierarchyTreeTable                      localHierarchyTreeTable;
    smmActivities                           localSmmActivities;
    HierarchyPath                           descendantsRangeValue;
    SalesPrice                              summarySalesPriceLoc;
    CostPrice                               summaryCostPriceLoc;

    #Characters

    descendantsRangeValue = hierarchyTreeTable.Path + hierarchyTreeTable.ElementNumber + #sharp + "*";

    smmActivities = smmActivities::find("CDC-008005");
    hierarchyTreeTableLoc = hierarchyTreeTable::findRefRecId(smmActivities.RecId);

    calendarId = ProjTable::find(smmActivities.projId()).PSASchedCalendarId;

    hierarchyId = hierarchyTreeTable.HierarchyId;

    controller = new ProjWBSUpdateController(hierarchyId,calendarId);
    controller.updateOutlineNumbersAndPublishInPreOrder();
    recordWBSId = controller.outlineNumberFor(hierarchyTreeTable.ElementNumber);
    if (!controller.hasChildren(hierarchyTreeTable))
    {
        // Get sum for the task itself.
        select sum(TotalSalesPrice), sum(TotalCostPrice) from localPSAActivityEstimates
            where localPSAActivityEstimates.ActivityNumber == smmActivities.ActivityNumber;

        summarySalesPrice = localPSAActivityEstimates.TotalSalesPrice;
        summaryCostPrice = localPSAActivityEstimates.TotalCostPrice;
    }
    else
    {
        // Include sum for the selected summary task's descendents.
        select sum(TotalSalesPrice), sum(TotalCostPrice) from localPSAActivityEstimates
            join RecId from localSmmActivities
                where localSmmActivities.ActivityNumber == localPSAActivityEstimates.ActivityNumber
                join RecId from localHierarchyTreeTable
                    where localHierarchyTreeTable.RefRecId == localSmmActivities.RecId
                          && localHierarchyTreeTable.Path like descendantsRangeValue;

        summarySalesPrice = localPSAActivityEstimates.TotalSalesPrice;
        summaryCostPrice = localPSAActivityEstimates.TotalCostPrice;
    }
    info(recordWBSId);
    info(strFmt("%1-%2",summarySalesPrice,summaryCostPrice));

}

No comments:

Post a Comment

SQL code to upate one Legal entity banner to all the legal entity in D365

 Hi, update companyimage set  companyimage.Image  = companyimageA.Image  from  ( select Image from companyimage where dataAreaid = 'USF...