lazhen
2024-07-03 d043f7992783c85310aab0afd2c13f2e63839c3d
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
Quintiq file version 2.0
#parent: #root
StaticMethod Initialize (
  MacroPlan owner,
  InterfaceDataset interface
)
{
  Description: '初始化'
  TextBody:
  [*
    // 甄兰鸽 Jun-24-2024 (created)
    owner.InventorySummarySource( relflush );
    products                  := construct( Product_MPs );
    allunit                   := InventorySummaryReport::GetDefaultAllUnit();
    ccunit                    := InventorySummaryReport::GetDefaultCCUnit();
    dlunit                    := InventorySummaryReport::GetDefaultDLUnit();
    
    source                    := owner.InventorySummarySource( relnew, ID := InventorySummaryReport::GetDefaultName(), Name := InventorySummaryReport::GetDefaultName() );
    table                     := source.InventorySummaryReport( relnew, ID := source.Name(), Name := source.Name() );
    showtable                 := source.InventorySummaryReport( relnew, ID := source.Name() + 'Show', Name := source.Name(), IsShow := true );
    startofplanning           := owner.StartOfPlanning();
    startofyear               := startofplanning.StartOfYear();
    startofnextyear           := startofplanning.StartOfNextYear();
    
    search                    := source.InventorySummarySearch( relnew, Unit := allunit, Generation := allunit, MqbMlb := allunit, Power := allunit, StartDate := Date::MinDate(), EndDate := Date::MaxDate() );
    
    table.GenerateColumn( owner, 'All', startofyear, startofnextyear );
    //info( '-----------------------------------', table.InventorySummaryColumn( relsize ) );
    //库存数量为Actual inventories里面的点Planned inventories字段库存量加总
    traverse( owner, Product_MP.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() and not pisp.IsSystem() and ( pisp.StockingPoint_MP().UnitID() = ccunit or pisp.StockingPoint_MP().UnitID() = dlunit ) ){
      unit := pisp.StockingPoint_MP().UnitID();
      product := pisp.Product_MP();
    //  info( '-----------------------------------', unit, product.ID() );
      weekpispips := construct( ProductInStockingPointInPeriods );
      monthpispips := construct( ProductInStockingPointInPeriods );
      nextweek := startofplanning.StartOfNextWeek();
      nextmonth := startofplanning.StartOfNextMonth();
      
      unitrow := table.GetRow( unit, product.ID() );
      allrow     := table.GetRow( allunit, product.ID() );
      pispips := selectsortedset( pisp, ProductInStockingPointInPeriod, pispip, pispip.Start() >= startofplanning and pispip.Start() < startofnextyear and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day(), pispip.Start() );
    //  info( '-----------------------------------', isnull( allrow ), pispips.Size() );
      traverse( pispips, Elements, pispip, pispip.Start() = startofplanning ){
    //    info( '-----------------------------------', pispip.Start() );
        period     := pispip.Period_MP();
        periodtime := period.Start().Date();
        periodname := periodtime.Format( "M2/D2/Y" );
        //天,选择日颗粒度时,期末库存,最小库存,最大库存和平均库存的数值保持一致
        daycolumn := selectobject( table, InventorySummaryColumn, column, column.Name() = periodname, column.Period() = periodtime, column.TimeUnit() = Translations::MP_GlobalParameters_Day() );
        info( daycolumn.Name(), daycolumn.Period(), daycolumn.TimeUnit() );
        unitrow.SetCellValue( daycolumn, pispip.PlannedInventoryLevelEnd() );
        allrow.SetCellValue( daycolumn, pispip.PlannedInventoryLevelEnd() );
        
        //周,选择周时,期末库存为每一周最后一天的汇总库存信息,最小库存为这一周库存量最小的一天的数值,最大库存为这一周库存量最大的一天的数值,平均库存为该周的平均值
        if( period.Start() < nextweek ){
          weekpispips.Add( pispip );
          
          weekend := nextweek - Duration::Days( 1 );
          if( period.Start() = weekend ){
            weekcolumn := selectobject( table, InventorySummaryColumn, column, column.Name() = periodname, column.Period() = periodtime, column.TimeUnit() = Translations::MP_GlobalParameters_Week() );
            
            maxinventory := max( weekpispips, Elements, e, e.PlannedInventoryLevelEnd() );
            mininventory := min( weekpispips, Elements, e, e.PlannedInventoryLevelEnd() );
            aveinventory := average( weekpispips, Elements, e, e.PlannedInventoryLevelEnd() );
            unitrow.SetCellValue( weekcolumn, pispip.PlannedInventoryLevelEnd(), mininventory, maxinventory, aveinventory );
            allrow.SetCellValue( weekcolumn, pispip.PlannedInventoryLevelEnd(), mininventory, maxinventory, aveinventory );
          }
        }else{
          weekpispips.Flush();
          weekpispips.Add( pispip );
          nextweek := nextweek.StartOfNextWeek();
        }
        
        //月,选择月时,期末库存为每一月最后一天的汇总库存信息,最小库存为这一个月库存量最小的一天的数值,最大库存为这一个月库存量最大的一天的数值,平均库存为该月的平均值
        if( period.Start() < nextmonth ){
          monthpispips.Add( pispip );
          
          monthend := nextmonth - Duration::Days( 1 );
          if( period.Start() = monthend ){
            monthcolumn := selectobject( table, InventorySummaryColumn, column, column.Name() = periodname, column.Period() = periodtime, column.TimeUnit() = Translations::MP_GlobalParameters_Month() );
            
            maxinventory := max( monthpispips, Elements, e, e.PlannedInventoryLevelEnd() );
            mininventory := min( monthpispips, Elements, e, e.PlannedInventoryLevelEnd() );
            aveinventory := average( monthpispips, Elements, e, e.PlannedInventoryLevelEnd() );
            unitrow.SetCellValue( monthcolumn, pispip.PlannedInventoryLevelEnd(), mininventory, maxinventory, aveinventory );
            allrow.SetCellValue( monthcolumn, pispip.PlannedInventoryLevelEnd(), mininventory, maxinventory, aveinventory );
          }
        }else{
          monthpispips.Flush();
          monthpispips.Add( pispip );
          nextmonth := nextmonth.StartOfNextMonth();
        }
      }
    }
    //首先在Entities里识别父级Unit为长春/大连的所有库存点
    //长春库存点
    ccsps := construct( Strings );
    //大连库存点
    dlsps := construct( Strings );
    allsps := construct( Strings );
    traverse( owner, Unit, unit, unit.ID() = ccunit or unit.ID() = dlunit ){
      if( unit.ID() = ccunit ){
        ccsps := selectuniquevalues( unit, StockingPoint_MP, sp, sp.ID() );
      }
      if( unit.ID() = dlunit ){
        dlsps := selectuniquevalues( unit, StockingPoint_MP, sp, sp.ID() );
      }
      allsps := allsps.Union( selectuniquevalues( unit, StockingPoint_MP, sp, sp.ID() ) );
    }
    //再在库存更新的子界面库存点选择中找到这些库存点所关联的已勾选库位
    selections := selectset( interface, InventoryPointSelection, selection, allsps.Find( selection.StockpoingPoint() ) >= 0 and selection.IsIncluded() );
    productids := selectuniquevalues( selections, Elements, selection, selection.ProductID() );
    //最后将这些库位中零件号的数量进行加总
    traverse( table, InventorySummaryColumn, column, column.Period() < startofplanning.Date() ){
      traverse( productids, Elements, productid ){
        if( column.TimeUnit() = Translations::MP_GlobalParameters_Day() ){//天
          column.GenerateCell( selections, ccsps, dlsps, table, column.Period(), column.Period(), productid, allunit, ccunit, dlunit );
        }else if( column.TimeUnit() = Translations::MP_GlobalParameters_Week() ){//周
          column.GenerateCell( selections, ccsps, dlsps, table, column.Period().StartOfWeek(), column.Period(), productid, allunit, ccunit, dlunit );
        }else if( column.TimeUnit() = Translations::MP_GlobalParameters_Month() ){//月
          column.GenerateCell( selections, ccsps, dlsps, table, column.Period().StartOfMonth(), column.Period(), productid, allunit, ccunit, dlunit );
        }
      }
    }
      
        
    rows := selectsortedset( table, InventroySummaryRow, row, row.Name() );
    i    := 0;
    traverse( rows, Elements, e ){
      e.RowNr( i );
      i := i + 1;
    }
    showtable.Generate( search, products );
  *]
}