Bài viết liên quan

Tạo class BOMStructureExploding


29/09/2020- duocnt    733 Views    

CÁC PHƯƠNG THỨC.

    1 - boolean hasChild(ItemId _itemId).
    2 - private int BOMRoot(int _level,BOMId _bomId)
    3 - void BOMStructureExploding(BOMId  _BOMId,int _level)
    4 - Full code.



CODE X++

1 - Phương thức hasChild().

 - Kiểm tra 1 ItemId nào đó xem có BOM con hay không?

    boolean hasChild(ItemId _itemId)
    {
        BOMVersion  bomVersion;
        ;
        //Check if the item is also a BOM item.
        select firstonly bomVersion
            where bomVersion.ItemId == _itemid
            && bomVersion.Active
            && bomVersion.FromDate <= systemdateget ()
            && (!bomVersion.ToDate || bomVersion.ToDate >= systemdateget ());
        if (bomVersion.RecId)
        return true ;
        return false ;
    }


2 - Phương thưc BOMRoot().

 - Chỉ thực hiện với BOM level 0.

    private int BOMRoot(int _level,BOMId _bomId)
    {
        InventTable _inventTable;
        BOMVersion  _bomVersion;
               
        select firstonly _bomVersion
            where _bomVersion.BOMId == _bomId
            && _bomVersion.Active
            && _bomVersion.FromDate <= systemdateget()
            && (!_bomVersion.ToDate || _bomVersion.ToDate >= systemdateget());
 
        select firstOnly _inventTable where _inventTable.ItemId == _bomVersion.ItemId;
        tmpBOM.clear();
        tmpBOM.rawItemId        =  _bomVersion.ItemId ;
        tmpBOM.displayItemId    =  _bomVersion.ItemId;
        tmpBOM.displayCombined  =   "BOM Number: "+_bomVersion.BOMId;
        tmpBOM.Level            =  _level;
        tmpBOM.insert();
        return _level+ 1 ;
    }


3 - Phương thức BOMStructureExploding.

    void BOMStructureExploding(BOMId  _BOMId,int _level)
    {
        BOM         _bom;
        InventTable _inventTable;
        BOMVersion  _bomVersion;
       
       
        while select  _bomVersion
            where _bomVersion.BOMId   ==  _BOMId
            && _bomVersion.Active
            && _bomVersion.FromDate <= systemdateget()
            && (!_bomVersion.ToDate || _bomVersion.ToDate >= systemdateget())
        {
           
            if (_level == 0)
            {
                _level = this.BOMRoot(_level,_bomVersion.BOMId);
            }
            if (_bomVersion.RecId)
            {
                //From level 1
                tmpBOM.clear();
                While select _bom
                    where _bom.BOMId == _bomVersion.BOMId
                {
                    select   _inventTable
                        where  _bom.ItemId == _inventTable.ItemId;
                   
                    tmpBOM.rawRefItemId    = _bomVersion.ItemId ;    
                    tmpBOM.rawItemId       = _bom.ItemId ;
                    tmpBOM.displayItemId   = _bom.ItemId;
                    tmpBOM.displayCombined = _bom.ItemId+ "/"+ _inventTable.itemName();                   
                    tmpBOM.Level           = _level;                                      
                    tmpBOM.insert();
 
                    if (this.hasChild(_bom.ItemId))
                    {
                        this.BOMStructureExploding(_bom.ItemId,_level+1);
                    }                                    
                }
            }
        }
    }


4 - Full Code

class BOMStructureExploding
{
    BOMStructureExplodingTmp    tmpBOM;
 
    boolean hasChild(ItemId _itemId)
    {
        BOMVersion  bomVersion;
        ;
        //Check if the item is also a BOM item.
        select firstonly bomVersion
            where bomVersion.ItemId == _itemid
            && bomVersion.Active
            && bomVersion.FromDate <= systemdateget ()
            && (!bomVersion.ToDate || bomVersion.ToDate >= systemdateget ());
        if (bomVersion.RecId)
        return true ;
        return false ;
    }
 
    private int BOMRoot(int _level,BOMId _bomId)
    {
        InventTable _inventTable;
        BOMVersion  _bomVersion;
               
        select firstonly _bomVersion
            where _bomVersion.BOMId == _bomId
            && _bomVersion.Active
            && _bomVersion.FromDate <= systemdateget()
            && (!_bomVersion.ToDate || _bomVersion.ToDate >= systemdateget());
 
        select firstOnly _inventTable where _inventTable.ItemId == _bomVersion.ItemId;
        tmpBOM.clear();
        tmpBOM.rawItemId        =  _bomVersion.ItemId ;
        tmpBOM.displayItemId    =  _bomVersion.ItemId;
        tmpBOM.displayCombined  =   "BOM Number: "+_bomVersion.BOMId;
        tmpBOM.Level            =  _level;
        tmpBOM.insert();
        return _level+ 1 ;
    }
 
    void BOMStructureExploding(BOMId  _BOMId,int _level)
    {
        BOM         _bom;
        InventTable _inventTable;
        BOMVersion  _bomVersion;
       
       
        while select  _bomVersion
            where _bomVersion.BOMId   ==  _BOMId
            && _bomVersion.Active
            && _bomVersion.FromDate <= systemdateget()
            && (!_bomVersion.ToDate || _bomVersion.ToDate >= systemdateget())
        {
            //Insert parent Item
            if (_level == 0)
            {
                _level = this.BOMRoot(_level,_bomVersion.BOMId);
            }
            if (_bomVersion.RecId)
            {
                //From level 1
                tmpBOM.clear();
                While select _bom
                    where _bom.BOMId == _bomVersion.BOMId
                {
                    select   _inventTable
                        where  _bom.ItemId == _inventTable.ItemId;
                   
                    tmpBOM.rawRefItemId    = _bomVersion.ItemId ;    
                    tmpBOM.rawItemId       = _bom.ItemId ;
                    tmpBOM.displayItemId   = _bom.ItemId;
                    tmpBOM.displayCombined = _bom.ItemId + "/" +_inventTable.itemName();                   
                    tmpBOM.Level           = _level;                                       
                    tmpBOM.insert();
 
                    if (this.hasChild(_bom.ItemId))
                    {
                        this.BOMStructureExploding(_bom.ItemId,_level+1);
                    }                                     
                }
            }
        }
    }
 
}



Góp ý kiến

;
;