lihongji
2024-10-17 6a46bc01eb703e49a18058b5dd0e47435a4bac0b
包装计划优化
已添加1个文件
已修改1个文件
117 ■■■■■ 文件已修改
_Main/BL/Type_PackagingPlanCell/StaticMethod_Package.qbl 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValues.qbl 56 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
_Main/BL/Type_PackagingPlanCell/StaticMethod_Package.qbl
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,61 @@
Quintiq file version 2.0
#parent: #root
StaticMethod Package (
  MacroPlan macroPlan,
  PackagingPlanRow ppr,
  PackagingPlanColumn ppc,
  output Number needPackagingQuantity
)
{
  TextBody:
  [*
    // è®¡åˆ’开始时间
    plannedStartDate := macroPlan.StartOfPlanning().Date();
    traverse ( ppr, PackagingPlanCell, ppcell, ppcell.PackagingPlanColumn() = ppc ) {
      // Product_MP
      pmp                     := select( macroPlan, Product_MP, tempPMP, tempPMP.IsLeaf() and tempPMP.ID() = ppr.ProductID() );
      // åŒ…装lotsize
      ppls                    := select( macroPlan, PackagingPlanLotSize, tempPPLS, tempPPLS.Factory() = ppr.Factory() and
                                         tempPPLS.ProductID() = ifexpr( exists( macroPlan, PackagingPlanLotSize, tempPPLS1, tempPPLS1.ProductID() = pmp.ID() ),
                                                                        pmp.ID(),
                                                                        pmp.ParentID() ) );
      // ä¸€æ—¥åŒ…装容量
      ppnc                    := select( macroPlan, PackagingPlanNewCapability, tempPPNC, tempPPNC.Factory() = ppr.Factory() and
                                         tempPPNC.ProductID() = ifexpr( exists( macroPlan, PackagingPlanNewCapability, tempPPNC1, tempPPNC1.ProductID() = pmp.ID() ),
                                                                        pmp.ID(),
                                                                        pmp.ParentID() ) );
      // Unit
      us                      := selectset( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
      // åŒ…装库存出现负值,需要设置包装量
      if ( not isnull( ppls ) and not isnull( ppnc ) ) {
        // åŒ…装开始的索引
        indexPPCell           := ppcell.Previous();
    //      info( "产线个数:", us.Size(), "    å¼€å§‹æ—¶é—´ï¼š", ppcell.StartDate().Format( "Y-M2-D2" ), "    åŒ…装库存数量:", ppcell.PackagingInventory(), "    éœ€è¦åŒ…装的数量:", needPackagingQuantity,
    //            "    åŒ…装lotsize:",guard( ppls.LotSize(), 0 ), "    æœ€å¤§åŒ…装容量:", ppnc.MaximumDailyPackagingQuantity() );
        while ( not isnull( indexPPCell )                                                   and
                indexPPCell.StartDate() >= plannedStartDate                                 and
                exists( us, Elements.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan, tempSP,
                        tempSP.UnitPeriodTime().StartDate() = indexPPCell.StartDate(),
                        tempSP.Outcome() <> "" )                                            and
                needPackagingQuantity > 0 ) {
          // èƒ½åŒ…装的数量
          canPackagingQuantity  := ifexpr( ceil( needPackagingQuantity / ppls.LotSize() ) < floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ),
                                           ceil( needPackagingQuantity / ppls.LotSize() ),
                                           floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ) ) * ppls.LotSize();
    //        info( "开始包装的日期:", indexPPCell.StartDate().Format( "Y-M2-D2" ), "    èƒ½åŒ…装的数量:", canPackagingQuantity );
          indexPPCell.Package( canPackagingQuantity );
          Transaction::Transaction().Propagate( attribute( PackagingPlanCell, PackagingInventory ) );
          Transaction::Transaction().Propagate( attribute( PackagingPlanCell, UnpackagedInventory ) );
          needPackagingQuantity := needPackagingQuantity - canPackagingQuantity;
          indexPPCell           := indexPPCell.Previous();
        }
      }
    }
  *]
}
_Main/BL/Type_PackagingPlanCell/StaticMethod_SetPackagingAndUnpackingValues.qbl
@@ -6,9 +6,12 @@
{
  TextBody:
  [*
    // è®¡åˆ’开始时间
    plannedStartDate := macroPlan.StartOfPlanning().Date();
    // è®¾ç½®åŒ…装值(符合lotsize和一日最大包装量)
    traverse ( macroPlan, PackagingPlanRow, ppr, ppr.Factory() = "大连工厂" and ppr.ProductID() = "06K103011CM" ) {
      traverse ( ppr, PackagingPlanCell, ppcell, ppcell.StartDate() <= Date::Construct( 2025, 1, 3 ) ) {
    traverse ( macroPlan, PackagingPlanRow, ppr/*, ppr.Factory() = "大连工厂" and ppr.ProductID() = "06K103011CM"*/ ) {
      traverse ( ppr, PackagingPlanCell, ppcell/*, ppcell.StartDate() <= Date::Construct( 2025, 1, 4 )*/ ) {
        // Product_MP
        pmp                     := select( macroPlan, Product_MP, tempPMP, tempPMP.IsLeaf() and tempPMP.ID() = ppr.ProductID() );
        // åŒ…装lotsize
@@ -22,7 +25,7 @@
                                                                          pmp.ID(),
                                                                          pmp.ParentID() ) );
        // Unit
        u                       := select( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
        us                      := selectset( macroPlan, Unit, tempU, tempU.ID().Regex( ppr.FactoryAbbreviation() + " " + ppr.Category() ) );
         
        // åŒ…装库存出现负值,需要设置包装量
        if ( ppcell.PackagingInventory() < 0 and not isnull( ppls ) and not isnull( ppnc ) ) {
@@ -31,17 +34,24 @@
          // åŒ…装开始的索引
          indexPPCell           := ppcell.Previous();
          
          info( "产线名:", u.ID(), "    å¼€å§‹æ—¶é—´ï¼š", ppcell.StartDate().Format( "Y-M2-D2" ), "    åŒ…装库存数量:", ppcell.PackagingInventory(), "    éœ€è¦åŒ…装的数量:", needPackagingQuantity,
                "    åŒ…装lotsize:",guard( ppls.LotSize(), 0 ), "    æœ€å¤§åŒ…装容量:", ppnc.MaximumDailyPackagingQuantity() );
    //      info( "产线个数:", us.Size(), "    å¼€å§‹æ—¶é—´ï¼š", ppcell.StartDate().Format( "Y-M2-D2" ), "    åŒ…装库存数量:", ppcell.PackagingInventory(), "    éœ€è¦åŒ…装的数量:", needPackagingQuantity,
    //            "    åŒ…装lotsize:",guard( ppls.LotSize(), 0 ), "    æœ€å¤§åŒ…装容量:", ppnc.MaximumDailyPackagingQuantity() );
          
          while ( not isnull( indexPPCell ) and needPackagingQuantity > 0 ) {
          while ( not isnull( indexPPCell )                                                   and
                  indexPPCell.StartDate() >= plannedStartDate                                 and
                  exists( us, Elements.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan, tempSP,
                          tempSP.UnitPeriodTime().StartDate() = indexPPCell.StartDate(),
                          tempSP.Outcome() <> "" )                                            and
                  needPackagingQuantity > 0 ) {
            // èƒ½åŒ…装的数量
            canPackagingQuantity  := ifexpr( ceil( needPackagingQuantity / ppls.LotSize() ) < floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ),
                                             ceil( needPackagingQuantity / ppls.LotSize() ),
                                             floor( ppnc.MaximumDailyPackagingQuantity() / ppls.LotSize() ) ) * ppls.LotSize();
            info( "开始包装的日期:", indexPPCell.StartDate().Format( "Y-M2-D2" ), "    èƒ½åŒ…装的数量:", canPackagingQuantity );
    //        info( "开始包装的日期:", indexPPCell.StartDate().Format( "Y-M2-D2" ), "    èƒ½åŒ…装的数量:", canPackagingQuantity );
            
            indexPPCell.Package( canPackagingQuantity );
            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, PackagingInventory ) );
            Transaction::Transaction().Propagate( attribute( PackagingPlanCell, UnpackagedInventory ) );
            
            needPackagingQuantity := needPackagingQuantity - canPackagingQuantity;
            indexPPCell           := indexPPCell.Previous();
@@ -50,6 +60,36 @@
      }
    }
    
    // è®¾ç½®åŒ…装值(符合大类下所有产品包装量加和不能大于最大包装量)
    // è®¾ç½®åŒ…装值(符合大类下所有产品非包装量库存加和不能大于系统值)
    factorys               := selectuniquevalues( macroPlan, PackagingPlanRow, tempPPR, true, tempPPR.FactoryAbbreviation() );
    categorys              := selectuniquevalues( macroPlan, PackagingPlanRow, tempPPR, true, tempPPR.Category() );
    traverse ( factorys, Elements, f/*, f = "DL"*/ ) {
      traverse ( categorys, Elements, c/*, c = "ZKG"*/ ) {
        // ç³»ç»Ÿè§„定的最大非包装库存数量
        ppmqReflection     := Reflection::FindAttribute( "PackagingPlanMaximumQuantity", f + "_" + c );
        maxPackageQuantity := guard( ppmqReflection.GetNumber( macroPlan.PackagingPlanMaximumQuantity() ), 0 );
        // å½“前工厂下一类产品行
        pprs               := selectset( macroPlan, PackagingPlanRow, tempPPR, tempPPR.FactoryAbbreviation() = f and tempPPR.Category() = c );
    //    info( "当前工厂:", f, "    å½“前大类:", c, "    å¤§ç±»ä¸‹çš„æœ€å¤§åŒ…装数量:", maxPackageQuantity );
        traverse ( macroPlan, PackagingPlanColumn, ppc, ppc.StartDate() > plannedStartDate and maxPackageQuantity > 0 ) {
          sumUnpackagedInventoryQuantity := sum( pprs, Elements.PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc, tempPPCell.UnpackagedInventory() ).Round( 0 );
          // éœ€è¦åŒ…装
          if ( sumUnpackagedInventoryQuantity > maxPackageQuantity ) {
            // éœ€è¦åŒ…装的数量
            needPackagingQuantity := [Number] ( sumUnpackagedInventoryQuantity - maxPackageQuantity );
            // æŒ‰éžåŒ…装库存排序后的行
            itemPPRs              := selectsortedset( pprs, Elements, tempPPR, true,
                                                      -select( tempPPR, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc ).UnpackagedInventory() );
    //        info( "需要包装时间:", ppc.StartDate().Format( "Y-M2-D2" ), "    éœ€è¦åŒ…装的数量:", needPackagingQuantity );
            traverse ( itemPPRs, Elements, ppr, needPackagingQuantity > 0 ) {
              PackagingPlanCell::Package( macroPlan, ppr, ppc, needPackagingQuantity );
            }
          }
        }
      }
    }
  *]
}