陈清红
2025-04-14 0b84c9999f07bc46275f5947c4b8ebf5ce0c25cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Quintiq file version 2.0
#parent: #root
StaticMethod GenerateData (
  MacroPlan macroPlan,
  InterfaceDataset interfaceDataset
)
{
  Description: '生成计划库存存档数据'
  TextBody:
  [*
    //interfaceDataset.InventoryPlanArchiveVersion( relflush );
    info( '-------------------------Start---------------------' );
    //machineproductparent   := MachiningPipelineReport::GetDefaultProductParent(); // 机加件
    //engineproductparent    := EnginePipelineReport::GetDefaultProductParent(); // 发动机
    allunit                := AssemblyOnlinePlanVersion::GetDefaultAllUnit(); // <All>
    name                   := InventoryPlanArchiveVersion::GetDefaultName(); // Inventory plan archive 
    interfaceDataset.InventoryPlanArchiveVersionSearch( relnew, 
                                                        Product   := allunit, 
                                                        Unit      := allunit, 
                                                        StartDate := Date::MinDate(), 
                                                        EndDate   := Date::MaxDate() );//, TimeUnit := Translations::MP_GlobalParameters_Day()
    
    // 创建显示表格
    table                  := selectobject( interfaceDataset, InventoryPlanArchiveVersion, version, not version.IsShow() );
    if( isnull( table ) ){
      table                := interfaceDataset.InventoryPlanArchiveVersion( relnew, ID := name, Name := name );
    }
    
    //showtable              := selectobject( interfaceDataset, InventoryPlanArchiveVersion, version, version.IsShow() );
    //if( isnull( showtable ) ){ 
    //  showtable               := interfaceDataset.InventoryPlanArchiveVersion( relnew, ID := name, Name := name, IsShow := true );
    //}
    
    // 创建不存在列
    periods                := selectuniquevalues(  macroPlan, Period_MP, period, not period.IsHistorical() and period.TimeUnit() = Translations::MP_GlobalParameters_Day()
                                                   and not exists( table, Column, column, column.StartDate() = period.StartDate() ), period.StartDate() );//column.TimeUnit() = Translations::MP_GlobalParameters_Day() and 
    if( periods.Size() > 0 ){
      table.GenerateColumn( periods, false );
    }
    
    // 最小时间
    minDate := minselect( table, Column, tempC, true, tempC.StartDate() ).StartDate();
    maxDate := maxselect( table, Column, tempC, true, tempC.StartDate() ).StartDate();
    info( "最小时间:", minDate.Format( "Y-M2-D2" ), "    最大时间:", maxDate.Format( "Y-M2-D2" ) );
    
    actinventorytree       := NamedValueTree::Create();
    // 机加实际库存
    traverse ( interfaceDataset,InterfaceLoginfo.MachineStockData, actinventory, 
    //           actinventory.Fac() = "CC" and actinventory.MaterialNo() = "06U105101A" and actinventory.DDay() = Date::Construct( 2025, 4, 9 ) and// 测试过滤(生产需要注释)
               actinventory.DDay() >= minDate and actinventory.DDay() <= maxDate ) {
      // 库位是否绑定库存点
      iid  := select( interfaceDataset, InventoryInterfaceData, tempIID, tempIID.Date() = actinventory.DDay()             and 
                                                                         tempIID.PartNumber() = actinventory.MaterialNo() );
      iidd := select( iid, InventoryInterfaceDataDetail, tempIIDD, tempIIDD.InventoryPoint() = actinventory.Lgort() and
                                                                   tempIIDD.Fac()            = actinventory.Fac() );
      flag := guard( iidd.InventoryPointSelection().IsIncluded(), false );
    //  info( "是否被库存点选择:", flag,  "    数量:", actinventory.Total() );
      actinventoryKey      := ifexpr( actinventory.Fac() = "DL", FinancialProductionReport::GetDefaultDLUnit(), FinancialProductionReport::GetDefaultCCUnit() ) +
                              actinventory.MaterialNo()                                                                                                         + 
                              actinventory.DDay().Format( "Y-M2-D2" );
      actinventoryhandle   := actinventorytree.GetHandle( actinventoryKey );
      if ( guard( actinventorytree.Root().Child( actinventoryhandle ).GetValueAsReal() > 0, false ) ) { // 判断是否存在,存在
        if ( flag ) {
          targetNV := actinventorytree.Root().Child( actinventoryhandle );
          targetNV.SetValue( targetNV.GetValueAsReal() + actinventory.Total() );
        }
      } else { // 不存在
        if ( flag ) {
          actinventorytree.Root().AddChild( actinventoryhandle, actinventory.Total() );
        }
      }
    }
    // 发动机实际库存
    traverse ( interfaceDataset, InterfaceLoginfo.FinishedEngineInventory, actinventory, 
    //           actinventory.Fac() = "CC" and actinventory.FourCode() = "6908" and actinventory.DDay() = Date::Construct( 2025, 4, 2 ) and// 测试过滤(生产需要注释)
               actinventory.DDay() >= minDate and actinventory.DDay() <= maxDate ) {
      // 库位是否绑定库存点
      iid  := select( interfaceDataset, InventoryInterfaceData, tempIID, tempIID.Date() = actinventory.DDay()           and 
                                                                         tempIID.PartNumber() = actinventory.FourCode() );
      iidd := select( iid, InventoryInterfaceDataDetail, tempIIDD, tempIIDD.InventoryPoint() = actinventory.BIPlace() and
                                                                   tempIIDD.Fac()            = actinventory.Fac() );
      flag := guard( iidd.InventoryPointSelection().IsIncluded(), false );
      
      product               := selectobject( macroPlan, Product_MP, product, product.ID() = actinventory.FourCode() );
      if ( not isnull( product ) ) {
        actinventoryKey     := ifexpr( actinventory.Fac() = "DL", FinancialProductionReport::GetDefaultDLUnit(), FinancialProductionReport::GetDefaultCCUnit() ) +
                               actinventory.FourCode() + 
                               actinventory.DDay().Format( "Y-M2-D2" );
        actinventoryhandle  := actinventorytree.GetHandle( actinventoryKey );
        if ( guard( actinventorytree.Root().Child( actinventoryhandle ).GetValueAsReal() > 0, false ) ) { // 判断是否存在,存在
          if ( flag ) {
            targetNV := actinventorytree.Root().Child( actinventoryhandle );
            targetNV.SetValue( targetNV.GetValueAsReal() + actinventory.Total() );
          }
        } else { // 不存在
          if ( flag ) {
            actinventorytree.Root().AddChild( actinventoryhandle, actinventory.Total() );
          }
        }
      }
    }
    
    //handle := actinventorytree.GetHandle( "VWED CC06U105101A2025-04-09" );
    //info( "数量:", guard( actinventorytree.Root().Child( handle ).GetValueAsReal(), 0 ) );
    
    // 保存已重置0的产品
    resetNVT := NamedValueTree::Create();
    
    traverse ( macroPlan, Product_MP, product
    //           ,product.ID() = "6909" 
              ) { 
      traverse ( product, ProductInStockingPoint_MP, pispmp, not pispmp.IsSystem() and pispmp.IsLeaf() ) {
        unit                 := ifexpr( pispmp.StockingPointID().Regex( "大连" ) or pispmp.StockingPointID().Regex( "DL" ), 
                                        FinancialProductionReport::GetDefaultDLUnit(), 
                                        FinancialProductionReport::GetDefaultCCUnit() ); // 工厂
        inventoryrow         := table.GetRowByUnit( pispmp.Product_MP(), unit ); // 创建库存存档行
    //    info( pispmp.Name() );
        
        traverse ( pispmp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispippl, 
    //               pispmp.ProductID() = "6909" and pispippl.Start().Date() = Date::Construct( 2025, 3, 31 ) and // 测试过滤(生产需要注释)
                   not pispippl.IsPeriodFrozen() ) {
          startdate          := pispippl.Start().Date();
          daycolumn          := table.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Day(), startdate ); // 获取库存存档列
    //      weekcolumn         := table.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Week(), startdate );
    //      monthcolumn        := table.GetColumnByTimeUnit( Translations::MP_GlobalParameters_Month(), startdate );
          actinventoryKey    := unit + pispmp.ProductID() + startdate.Format( "Y-M2-D2" );
          actinventoryhandle := actinventorytree.GetHandle( actinventoryKey );
          actinventoryQty    := guard( actinventorytree.Root().Child( actinventoryhandle ).GetValueAsReal(), 0 );
    //      info( "数量:", actinventoryQty );
          inventoryrow.SetQuantity( daycolumn, pispippl.InventoryLevelEnd(), actinventoryQty, resetNVT );
    //      inventoryrow.SetQuantity( weekcolumn, pispippl.InventoryLevelEnd(), actinventoryqty );
    //      inventoryrow.SetQuantity( monthcolumn, pispippl.InventoryLevelEnd(), actinventoryqty );
      
        }
      }
    }
    
    info( '-------------------------End---------------------' );
    //productids             := selectuniquevalues( table, Row, row, row.Name() );
    //productlines           := selectuniquevalues( table, Row, row, row.Unit() );
    //showtable.Generate( search, productids, productlines );
  *]
}