• Exhibit BOM number code


    /****
    The following X++ code was used to exhibit BOM number
    Remark by Jimmy August 27th 2010
    */

    Class name QVS_ExhibitBOM

    /****
    The following X++ code was used to exhibit BOM number
    Remark by Jimmy August 27th 2010
    */
    class QVS_ExhibitBOM
    {
        int             i;
        Real           NetConsum;
    }
    

     The method of ParmExhibitBOM

     

    void ParmExhibitBOM(ItemId     _ItemId = "") //Exhibit standard BOM method
    {
         query                           q;
         queryRun                        queryRun;
         QueryBuildDataSource            qbdsIT,qbdsVersion,qbdsBOM;
         InventTable                     _InventTable;
         BOM                             _BOM;
         BomVersion                      _BomVersion;
    ;
         q  = new query();
    
         qbdsIT  = q.addDataSource(tablenum(InventTable));
    
         if(_ItemId)
            qbdsIT.addRange(fieldnum(InventTable,Itemid)).value(_ItemId);
         qbdsIT.addRange(fieldnum(InventTable,Itemtype)).value(queryValue(ItemType::BOM));
    
         qbdsVersion = qbdsIT.addDataSource(tablenum(BomVersion));
         qbdsVersion.addLink(fieldnum(InventTable,ItemId),fieldnum(BomVersion,ItemId));
         qbdsVersion.addRange(fieldnum(BomVersion,Active)).value(queryValue(Noyes::Yes));
         qbdsVersion.addRange(fieldnum(BomVersion,Approved)).value(queryValue(Noyes::Yes));
    
         qbdsBOM = qbdsVersion.addDataSource(Tablenum(BOM));
         qbdsBOM.addLink(fieldnum(BomVersion,BomId),fieldnum(BOM,BomId));
    
         queryRun = new QueryRun(q);
         while (queryRun.next())
         {
             _BOM          = queryRun.get(tablenum(BOM));
             _InventTable  = queryRun.get(tablenum(InventTable));
             _BomVersion   = queryRun.get(tablenum(BomVersion));
    
             i             = 1;
             if(_BOM.BOMQtySerie)
                NetConsum = _BOM.BOMQty / _BOM.BOMQtySerie;
             else if(_BOM.BOMQty)
                NetConsum = _BOM.BOMQty;
             else
                NetConsum = 1;
    
             if(Inventtable::find(_BOM.ItemID).ItemType == ItemType::BOM)//Exhibit next BOM number
             {
                this.insertConsumeListNext(_InventTable,_BOM,_BOM.BomId,_BomVersion.BOMId,i,NetConsum);
                i++;
                this.RankGetItem(_BOM.ItemId,_InventTable,i,NetConsum);
             }
             else
                 this.insertConsumeListNext(_InventTable,_BOM,_BOM.BomId,_BomVersion.BOMId,i,NetConsum);//get Item number of Item type is Item
        }
    }

     

    The method of RankGetItem

     

    void RankGetItem(ItemId             _ItemId,//finished BOM number
                     InventTable        InventTable,
                     int                level,
                     Price              _NetConsum)
    {
         BOM                _bom;
         BomVersion         _bomversion;
         Inventtable        _Inventtable;
         Int                TmpLevel = 1;
    ;
        NetConsum  = _NetConsum;
        while select _bomversion index hint BomIdx
                where _bomversion.ItemId == _ItemId
                &&    _bomversion.Active == Noyes::Yes && _bomversion.Approved == Noyes::Yes
           join _bom index hint NumIdx
                order by BOMId where _bom.BOMId == _bomversion.BOMId
           join  _Inventtable
                where _Inventtable.ItemId ==  _bom.ItemId //&& _Inventtable.ItemType != ItemType::Service
        {
            if(_bom.BOMQtySerie)
                _NetConsum = NetConsum * (_bom.BOMQty / _bom.BOMQtySerie);
            else if(_bom.BOMQty)
                _NetConsum = NetConsum * _bom.BOMQty;
            else
                _NetConsum = NetConsum;
    
            if(_Inventtable.ItemType == ItemType::BOM)
            {
                this.insertConsumeListNext(InventTable,_bom,_bom.ItemId,_bomversion.BOMId,level,_NetConsum);
                TmpLevel = level + 1;
                this.RankGetItem(_bom.ItemId,InventTable,TmpLevel,_NetConsum);
            }
            else
                this.insertConsumeListNext(InventTable,_bom,_bom.ItemId,_bomversion.BOMId,level,_NetConsum);
    
        }
    }
    

    The method of insertConsumeListNext

    void insertConsumeListNext(InventTable              _InventTable    ,//finished production
                               BOM                      _BOM            ,
                               ItemId                   _ItemId = ','   ,
                               BomId                    _BomId  = ""    ,
                               int                      _level          ,
                               Price                    _NetConsum)//BomBersion
    {
        QVS_ExhibitBOMList        _ExhibitBOMList;
    ;
        _ExhibitBOMList.clear();
    
        _ExhibitBOMList.BomId           = _InventTable.ItemId;
        _ExhibitBOMList.SubBomId        = _BOM.BOMId;
        _ExhibitBOMList.ItemID          = _BOM.ItemId;
        _ExhibitBOMList.BOMVersion      = _BOMId;
    
        _ExhibitBOMList.BomQty          = _BOM.BOMQty;
        _ExhibitBOMList.BOMQtySerie     = _BOM.BOMQtySerie;
        if(_BOM.BOMQtySerie)
            _ExhibitBOMList.BOMUsege    = _BOM.BOMQty / _BOM.BOMQtySerie;
        else
            _ExhibitBOMList.BOMUsege    = _BOM.BOMQty;
    
        _ExhibitBOMList.ItemType        = _BOM.itemType();
    
        _ExhibitBOMList.LevelRecId      = _BOM.RecId;
        _ExhibitBOMList.NetConsumption  = _NetConsum;
        _ExhibitBOMList.Level           = _level;
        _ExhibitBOMList.flag            = StrFmt("%1 Level",_level);
    
        _ExhibitBOMList.insert();
    
    }
    

    Job demo(version)

    Jimmy 2010-09-14

    static void Jimmy_ExhibitBOMItemList(Args _args)
    {
        InventTable InventTable,g_IT;
        BOMVersion  BOMVersion;
        Bom         SelectBom;
        Int         g_Level,_TmpLevel;
        Test        Test;
        BOM         BOM;
        ItemId      g_ItemId;
        int         MM;
        Dialog      dlg = new Dialog("Please enter the Productin Number!");
        DialogField dlgItemId = dlg.addField(typeid(ItemId));
    
    void insertTable(BOM            _Bom,
                     InventTable    _InventTable)
    
    {
    ;
        test.g_ItemId   = g_ItemId;
        test.BomId      = _Bom.BOMId;
        test.ItemId     = _Bom.ItemId;
        test.Id         = g_Level;
        test.ItemType   = _InventTable.ItemType;
        test.Insert();
        MM++;
    }
    
    void LevelBomGen(Int _level, Bom _Bom)
    {
        BOM         _TmpBom;
        int         TmpLevel;
        InventTable IT;
    ;
        if (_level ==20)
            return;
        IT = InventTable::find(_Bom.ItemId);
        if (IT.ItemType == ItemType::BOM)
        {
            insertTable(_Bom,IT);
            g_Level++;
            while select _TmpBom where _TmpBom.BOMId == _Bom.ItemId
            {
                TmpLevel = g_Level;
                LevelBomGen(g_Level,_TmpBom);
                g_Level = TmpLevel;
            }
        }
        else
            insertTable(_Bom,IT);
    }
    ;
        dlg.doInit();
        dlgItemId.value("20-3805");
        if(!dlg.run())
            return ;
    
        g_ItemId = dlgItemId.value();
        delete_from test;
    
        while select InventTable
                where InventTable.ItemId == g_ItemId //"20-3805"
            join BOMVersion
                where BOMVersion.ItemId == InventTable.ItemId
            join BOM
                where BOM.BOMId == BOMVersion.BOMId
        {
            g_Level = 1;
            g_IT = InventTable::find(BOM.ItemId);
            if(g_IT.ItemType == ItemType::BOM)
            {
                insertTable(BOM,g_IT);
                g_Level++;
                while select * from SelectBom where SelectBom.BOMId == BOM.ItemId
                {
                    _TmpLevel = g_Level;
                    LevelBomGen(g_Level,SelectBom);
                    g_Level = _TmpLevel;
                }
            }
            else
                insertTable(BOM,g_IT);
        }
        info(strfmt("Total %1 records!s",MM));
    }
    
  • 相关阅读:
    Python3 之 列表推导式
    python3 之 趣味数学题(爱因斯坦)
    python3 之 判断闰年小实例
    python3 之 判断字符串是否只为数字(isdigit()方法、isnumeric()方法)
    116.Populating Next Right Pointers in Each Node
    115.Distinct Subsequences
    114.Flatten Binary Tree to Linked List
    113.Path Sum II
    112.Path Sum
    111.Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1810392.html
Copyright © 2020-2023  润新知