lazhen
2024-08-09 23e251ff1d124de2fb13fe195a8b4575bc0676a1
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
Quintiq file version 2.0
#parent: #root
StaticMethod Initialize (
  MacroPlan owner
)
{
  TextBody:
  [*
    // 甄兰鸽 Jun-24-2024 (created)
    owner.FinancialProductionSource( relflush );
    ccunit                    := MachiningPipelineReport::GetDefaultCCUnit();
    dlunit                    := MachiningPipelineReport::GetDefaultDLUnit();
    //allunit                   := EnginePipelineReport::GetDefaultAllUnit();
    source                    := owner.MachiningPipelineSource( relnew, Name := MachiningPipelineReport::GetDefaultName() );
    table                     := source.Report( relnew, ID := source.Name(), Name := source.Name() );
    showtable                 := source.Report( relnew, ID := source.Name() + 'Show', Name := source.Name(), IsShow := true );
    
    search                    := source.Search( relnew, StartDate := Date::MinDate(), EndDate := Date::MaxDate(), TimeUnit := Translations::MP_GlobalParameters_Day() );
    
    products                  := construct( Product_MPs );
    //初始化列
    table.GenerateColumn( owner, 'All', search.StartDate(), search.EndDate() );
    endperiod                 := maxobject( owner, Period_MP, period, not period.IsHistorical() and period.TimeUnit() = Translations::MP_GlobalParameters_Day(), period.StartDate() );
    
    //生成装配、生产和库存数据
    traverse( owner, StockingPoint_MP, stockingpoint ){
      unit                    := stockingpoint.Unit();
      parentunits             := unit.GetAllParent();
      //是否属于长春工厂
      iscc                    := unit.ID() = ccunit or exists( parentunits, Elements, punit, punit.ID() = ccunit );
      //是否属于大连工厂
      isdl                    := unit.ID() = dlunit or exists( parentunits, Elements, punit, punit.ID() = dlunit );
      //是否属于长春装配线
      isccassemnly            := unit.ID() = MachiningPipelineReport::GetDefaultCCAssemnlyUnit() or exists( parentunits, Elements, punit, punit.ID() = MachiningPipelineReport::GetDefaultCCAssemnlyUnit() );
      //是否属于大连装配线
      isdlassemnly            := unit.ID() = MachiningPipelineReport::GetDefaultDLAssemnlyUnit() or exists( parentunits, Elements, punit, punit.ID() = MachiningPipelineReport::GetDefaultDLAssemnlyUnit() );
      //是否属于长春机加产线
      isccproduction          := unit.ID() = MachiningPipelineReport::GetDefaultCCProductionUnit() or exists( parentunits, Elements, punit, punit.ID() = MachiningPipelineReport::GetDefaultCCProductionUnit() );
      //是否属于大连机加产线
      isdlproduction          := unit.ID() = MachiningPipelineReport::GetDefaultDLProductionUnit() or exists( parentunits, Elements, punit, punit.ID() = MachiningPipelineReport::GetDefaultDLProductionUnit() );
      if( iscc or isdl ){
        traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf() and not pisp.IsSystem() ){
          row := table.GetRow( pisp.ProductID() );
          
          weekstart             := owner.StartOfPlanning().Date();
          pispips               := selectsortedset( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() 
                                                  and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day(), pispip.Start() );
          
          traverse( pispips, Elements, pispip ){
            //天
            daycolumn           := table.GetColumnByUnit( Translations::MP_GlobalParameters_Day(), pispip.Start().Date() );
            //周
            weekcolumn          := table.GetColumnByUnit( Translations::MP_GlobalParameters_Week(), weekstart );
            
            supplyquantity      := [Number]pispip.NewSupplyQuantity();//四舍五入
            inventoryquantity   := [Number]pispip.PlannedInventoryLevelEnd();//四舍五入
            
            //装配线
            if( isccassemnly or isdlassemnly ){
              row.SetCellAssemblyValue( daycolumn, isccassemnly, [Real]supplyquantity );
              row.SetCellAssemblyValue( weekcolumn, isccassemnly, [Real]supplyquantity );
            }
            
            //机加线
            if( isccproduction or isdlproduction ){
              row.SetCellProductionValue( daycolumn, isccproduction, [Real]supplyquantity );
              row.SetCellProductionValue( weekcolumn, isccproduction, [Real]supplyquantity );
            }
            //库存
            if( iscc or isdl ){
              row.SetCellInventoryValue( daycolumn, iscc, [Real]inventoryquantity );
              if( pispip.Start() = weekstart + Duration::Days( 6 ) or pispip.Period_MP() = endperiod ){
                weekstart         := ( weekstart + Duration::Days( 7 ) ).Date();
                row.SetCellInventoryValue( weekcolumn, iscc, [Real]inventoryquantity );
              }
            }
          }
        }
      }
    }
    
    //生成调拨数据
    traverse( owner, TransferPlanRow, tprow, ( tprow.SourceStockpoingPointID() = 'CC' and tprow.TargetStockpoingPointID() = 'DL' ) or ( tprow.SourceStockpoingPointID() = 'DL' and tprow.TargetStockpoingPointID() = 'CC' ) ){
      row := selectobject( table, Row, row, row.Name() = tprow.Name() );
      traverse( table, Column, column ){
        cell := selectobject( row, Cell, cell, cell.Column() = column );
        if( column.TimeUnit() = Translations::MP_GlobalParameters_Day() ){
          tpcell := selectobject( tprow, TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() = column.Period() );
          if( tprow.SourceStockpoingPointID() = 'CC' and tprow.TargetStockpoingPointID() = 'DL' ){
            cell.CCTransferQty( [Real]tpcell.Value() );
          }else if( tprow.SourceStockpoingPointID() = 'DL' and tprow.TargetStockpoingPointID() = 'CC' ){
            cell.DLTransferQty( [Real]tpcell.Value() );
          }
        }else if( column.TimeUnit() = Translations::MP_GlobalParameters_Week() ){
          period := column.Period() + Duration::Days( 6 );
          tpcell := selectobject( tprow, TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() = period.Date() );
          
          if( tprow.SourceStockpoingPointID() = 'CC' and tprow.TargetStockpoingPointID() = 'DL' ){
            cell.CCTransferQty( [Real]tpcell.Value() );
          }else if( tprow.SourceStockpoingPointID() = 'DL' and tprow.TargetStockpoingPointID() = 'CC' ){
            cell.DLTransferQty( [Real]tpcell.Value() );
          }
        }
      }
    }
    
    rows := selectsortedset( table, Row, row, row.Name() );
    i    := 0;
    traverse( rows, Elements, e ){
      e.RowNr( i );
      i := i + 1;
    }
    showtable.Generate( search, products );
  *]
}