admin
2024-10-17 d060843d402641d8cdeadad086ed5c867de7f2ea
_Main/BL/Type_PackagingPlanCell/StaticMethod_GenerateReport.qbl
@@ -6,95 +6,96 @@
{
  TextBody:
  [*
    macroPlan.PackagingPlanRow( relflush );
    macroPlan.PackagingPlanColumn( relflush );
    // 创建计划前一天列
    planPre     := macroPlan.PackagingPlanColumn( relnew, StartDate := macroPlan.StartOfPlanning().Date() - 1 );
    // 生成报表
    traverse ( macroPlan, Product_MP.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() and not pisp.IsSystem() and
               ( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "DL" ) or pisp.StockingPointID().Regex( "大连" ) or pisp.StockingPointID().Regex( "长春" ) ) ) {
      // 当前pisp所处地点
      factory             := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "长春" ), "长春工厂", "大连工厂" );
      factoryAbbreviation := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "长春" ), "CC", "DL" );
      // 创建行
      ppr := select( macroPlan, PackagingPlanRow, tempPPR, tempPPR.ProductID() = pisp.ProductID() and tempPPR.Factory() = factory );
      if ( isnull( ppr ) ) {
        ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), Factory := factory, Category := guard( pisp.Product_MP().ParentID(), "" ) );
      }
      // 循环pispippl
      traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispipl, not pispipl.IsPeriodFrozen() ) {
        // 创建列
        ppc := select( macroPlan, PackagingPlanColumn, tempPPC, tempPPC.StartDate() = pispipl.Start().Date() );
        if ( isnull( ppc ) ) {
          ppc := macroPlan.PackagingPlanColumn( relnew, StartDate := pispipl.Start().Date() );
        }
        // 创建单元格
        cell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc );
        if ( isnull( cell ) ) {
          cell := ppr.PackagingPlanCell( relnew );
          cell.NetDemand( pispipl.InventoryLevelEnd() + pispipl.NewSupplyQuantity() - pispipl.DependentDemandAndSalesDemandQuantity() );
          cell.EndingInventory( pispipl.InventoryLevelEnd() );
          cell.PackagingPlanColumn( relset, ppc );
        } else {
          cell.NetDemand( cell.NetDemand() + ( pispipl.InventoryLevelEnd() + pispipl.NewSupplyQuantity() - pispipl.DependentDemandAndSalesDemandQuantity() ) );
          cell.EndingInventory( cell.EndingInventory() + pispipl.InventoryLevelEnd() );
        }
        // 设置调出
        traverse ( pispipl, AsDeparturePISPIP, pit,
                   pit.Quantity()                > 0                                                                         and
                   pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation )      and
                   TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
                  )
        {
          cell.Out( cell.Out() + pit.Quantity() );
        }
        // 设置调进
        traverse ( pispipl, AsArrivalPISPIP, pit,
                   pit.Quantity()              > 0                                                                           and
                   pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation ) and
                   TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
                  )
        {
          cell.TransferIn( cell.TransferIn() + pit.Quantity() );
        }
        // 长春工厂特殊情况设置包装库存和非包装库存
        if ( factory = "长春工厂" ) {
          if ( pisp.StockingPointID().Regex( "外租库" ) ) {
            cell.CC_PackagingInventory( pispipl.InventoryLevelEnd() );
          } else if ( pisp.StockingPointID().Regex( "线边库" ) ) {
            cell.CC_UnpackagedInventory( pispipl.InventoryLevelEnd() );
          }
        }
        // 设置前一天库存
        if ( pispipl.Start().Date() = macroPlan.StartOfPlanning().Date() ) {
          prePISPIPL  := pispipl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf ); // 前一个pispippl
          // 创建计划前一天格子
          preCell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = planPre );
          if ( isnull( preCell ) ) {
            preCell := ppr.PackagingPlanCell( relnew );
            preCell.EndingInventory( prePISPIPL.InventoryLevelEnd() );
            preCell.PackagingPlanColumn( relset, planPre );
          } else {
            preCell.EndingInventory( preCell.EndingInventory() + prePISPIPL.InventoryLevelEnd() );
          }
        }
      }
    }
    Transaction::Transaction().Propagate( attribute( PackagingPlanRow, FactoryAbbreviation ) );
    PackagingPlanCell::CalculationPackagingPlanProperties();
    Transaction::Transaction().Propagate( relation( PackagingPlanCell, Next ) );
    //macroPlan.PackagingPlanRow( relflush );
    //macroPlan.PackagingPlanColumn( relflush );
    //
    //// 创建计划前一天列
    //planPre     := macroPlan.PackagingPlanColumn( relnew, StartDate := macroPlan.StartOfPlanning().Date() - 1 );
    //
    //// 生成报表
    //traverse ( macroPlan, Product_MP.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() and not pisp.IsSystem() and
    //           ( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "DL" ) or pisp.StockingPointID().Regex( "大连" ) or pisp.StockingPointID().Regex( "长春" ) ) ) {
    //  // 当前pisp所处地点
    //  factory             := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "长春" ), "长春工厂", "大连工厂" );
    //  factoryAbbreviation := ifexpr( pisp.StockingPointID().Regex( "CC" ) or pisp.StockingPointID().Regex( "长春" ), "CC", "DL" );
    //
    //  // 创建行
    //  ppr := select( macroPlan, PackagingPlanRow, tempPPR, tempPPR.ProductID() = pisp.ProductID() and tempPPR.Factory() = factory );
    //  if ( isnull( ppr ) ) {
    //    ppr := macroPlan.PackagingPlanRow( relnew, ProductID := pisp.ProductID(), Factory := factory, Category := guard( pisp.Product_MP().ParentID(), "" ) );
    //  }
    //
    //  // 循环pispippl
    //  traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispipl, not pispipl.IsPeriodFrozen() ) {
    //    // 创建列
    //    ppc := select( macroPlan, PackagingPlanColumn, tempPPC, tempPPC.StartDate() = pispipl.Start().Date() );
    //    if ( isnull( ppc ) ) {
    //      ppc := macroPlan.PackagingPlanColumn( relnew, StartDate := pispipl.Start().Date() );
    //    }
    //
    //    // 创建单元格
    //    cell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = ppc );
    //    if ( isnull( cell ) ) {
    //      cell := ppr.PackagingPlanCell( relnew );
    //      cell.NetDemand( pispipl.InventoryLevelEnd() + pispipl.NewSupplyQuantity() - pispipl.DependentDemandAndSalesDemandQuantity() );
    //      cell.EndingInventory( pispipl.InventoryLevelEnd() );
    //      cell.PackagingPlanColumn( relset, ppc );
    //    } else {
    //      cell.NetDemand( cell.NetDemand() + ( pispipl.InventoryLevelEnd() + pispipl.NewSupplyQuantity() - pispipl.DependentDemandAndSalesDemandQuantity() ) );
    //      cell.EndingInventory( cell.EndingInventory() + pispipl.InventoryLevelEnd() );
    //    }
    //
    //    // 设置调出
    //    traverse ( pispipl, AsDeparturePISPIP, pit,
    //               pit.Quantity()                > 0                                                                         and
    //               pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation )      and
    //               TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
    //              )
    //    {
    //      cell.Out( cell.Out() + pit.Quantity() );
    //    }
    //
    //    // 设置调进
    //    traverse ( pispipl, AsArrivalPISPIP, pit,
    //               pit.Quantity()              > 0                                                                           and
    //               pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP().ID().Regex( factoryAbbreviation ) and
    //               TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsOriginStockingPointLeg().StockingPoint_MP() ) <> TransferPlanRow::IdentifyTheFactory( pit.Trip().LaneLeg().AsDestinationStockingPointLeg().StockingPoint_MP() )
    //              )
    //    {
    //      cell.TransferIn( cell.TransferIn() + pit.Quantity() );
    //    }
    //
    //    // 长春工厂特殊情况设置包装库存和非包装库存
    //    if ( factory = "长春工厂" ) {
    //      if ( pisp.StockingPointID().Regex( "外租库" ) ) {
    //        cell.CC_PackagingInventory( pispipl.InventoryLevelEnd() );
    //      } else if ( pisp.StockingPointID().Regex( "线边库" ) ) {
    //        cell.CC_UnpackagedInventory( pispipl.InventoryLevelEnd() );
    //      }
    //    }
    //
    //    // 设置前一天库存
    //    if ( pispipl.Start().Date() = macroPlan.StartOfPlanning().Date() ) {
    //      prePISPIPL  := pispipl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf ); // 前一个pispippl
    //      // 创建计划前一天格子
    //      preCell := select( ppr, PackagingPlanCell, tempPPCell, tempPPCell.PackagingPlanColumn() = planPre );
    //      if ( isnull( preCell ) ) {
    //        preCell := ppr.PackagingPlanCell( relnew );
    //        preCell.EndingInventory( prePISPIPL.InventoryLevelEnd() );
    //        preCell.PackagingPlanColumn( relset, planPre );
    //      } else {
    //        preCell.EndingInventory( preCell.EndingInventory() + prePISPIPL.InventoryLevelEnd() );
    //      }
    //    }
    //  }
    //}
    //
    //Transaction::Transaction().Propagate( attribute( PackagingPlanRow, FactoryAbbreviation ) );
    //PackagingPlanCell::CalculationPackagingPlanProperties();
    //Transaction::Transaction().Propagate( relation( PackagingPlanCell, Next ) );
    
    // 设置包装&拆包-数量
    PackagingPlanCell::SetPackagingAndUnpackingValues( macroPlan );
    //traverse ( macroPlan, PackagingPlanRow, ppr, ( ppr.ProductID() = "Windshield" and ppr.StockingPointID() = "Bosch" ) or ( ppr.ProductID() = "Windshield" and ppr.StockingPointID() = "Components (Spain)" ) ) {
    //  traverse ( ppr, PackagingPlanCell, ppc/*, ppc.StartDate() = Date::Construct( 2020, 4, 1 )*/ ) {
    //    // 设置包装数量