lazhen
2024-09-27 d65ca044060c02ed74022a273429ee741f61e1f0
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
Quintiq file version 2.0
#parent: #root
StaticMethod Initialize (
  MacroPlan owner
)
{
  TextBody:
  [*
    // 甄兰鸽 Jun-24-2024 (created)
    owner.FinancialProductionSource( relflush );
    productparent             := MachiningPipelineReport::GetDefaultProductParent();
    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                    := owner.MachiningPipelineSearch( 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() );
    
    //生成装配(长内库)、生产(的DL和库存数据
    traverse( owner, StockingPoint_MP, stockingpoint ){
      unit                    := stockingpoint.Unit();
      parentunits             := unit.GetAllParent();
      //是否属于长春工厂
      iscc                    := stockingpoint.ID().StartsWith( 'CC' ) or unit.ID().StartsWith( 'CC' ) or exists( parentunits, Elements, punit, punit.ID().StartsWith( 'CC' ) );//unit.ID() = ccunit or exists( parentunits, Elements, punit, punit.ID() = ccunit );
      //是否属于大连工厂
      isdl                    := stockingpoint.ID().StartsWith( 'DL' ) or unit.ID().StartsWith( 'DL' ) or exists( parentunits, Elements, punit, punit.ID().StartsWith( 'DL' ) );//unit.ID() = dlunit or exists( parentunits, Elements, punit, punit.ID() = dlunit );
      //是否属于长春装配线CC厂内库
      isccassemnly            := stockingpoint.ID().EndsWith( '厂内库' ) and ( stockingpoint.ID().StartsWith( 'CC' ) or stockingpoint.ID().StartsWith( '长春' ) );//unit.ID() = MachiningPipelineReport::GetDefaultCCAssemnlyUnit() or exists( parentunits, Elements, punit, punit.ID() = MachiningPipelineReport::GetDefaultCCAssemnlyUnit() );
      //是否属于大连装配线DL厂内库
      isdlassemnly            := stockingpoint.ID().EndsWith( '厂内库' ) and ( stockingpoint.ID().StartsWith( 'DL' ) or stockingpoint.ID().StartsWith( '大连' ) );//unit.ID() = MachiningPipelineReport::GetDefaultDLAssemnlyUnit() or exists( parentunits, Elements, punit, punit.ID() = MachiningPipelineReport::GetDefaultDLAssemnlyUnit() );
      //是否属于长春机加产线
      isccproduction          := stockingpoint.ID().EndsWith( '线边库' ) and ( stockingpoint.ID().StartsWith( 'CC' ) or stockingpoint.ID().StartsWith( '长春' ) );//unit.ID() = MachiningPipelineReport::GetDefaultCCProductionUnit() or exists( parentunits, Elements, punit, punit.ID() = MachiningPipelineReport::GetDefaultCCProductionUnit() );
      //是否属于大连机加产线
      isdlproduction          := unit.ID().EndsWith( 'MoMo' ) and unit.ID().StartsWith( 'DL' );//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() 
    //              and exists( pisp.Product_MP().GetAllParent(), Elements, e, e.ID() = productparent ) 
                  and exists( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day() and ( pispip.NewSupplyQuantity() <> 0 or pispip.PlannedInventoryLevelEnd() <> 0 ) ) ){
          pispips             := selectsortedset( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() 
                                                  and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day() and ( pispip.NewSupplyQuantity() <> 0 or pispip.PlannedInventoryLevelEnd() <> 0 ), pispip.Start() );
          traverse( pispips, Elements, pispip ){
            supplyquantity    := [Number]pispip.NewSupplyQuantity();//四舍五入
            //天
            daycolumn         := table.GetColumnByUnit( Translations::MP_GlobalParameters_Day(), pispip.Start().Date() );
            //周
            weekcolumn        := table.GetColumnByUnit( Translations::MP_GlobalParameters_Week(), pispip.Start().Date() );
            
            //装配线
            if( isccassemnly or isdlassemnly ){
              if( isccassemnly ){
                daycolumn.CCAssemblyPlanQty( daycolumn.CCAssemblyPlanQty() + supplyquantity );
                weekcolumn.CCAssemblyPlanQty( weekcolumn.CCAssemblyPlanQty() + supplyquantity );
              } else {
                daycolumn.DLAssemblyPlanQty( daycolumn.DLAssemblyPlanQty() + supplyquantity );
                weekcolumn.DLAssemblyPlanQty( weekcolumn.DLAssemblyPlanQty() + supplyquantity );
              } 
            }
            
            product           := pisp.Product_MP();
            productparents    := product.GetAllParent();
            if( exists( productparents, Elements, e, e.ID() = productparent ) ){//查询产品类型是发动机
              row             := table.GetRow( pisp.ProductID() );
              products.Add( pisp.Product_MP() );
    
              inventoryquantity:= [Number]pispip.PlannedInventoryLevelEnd();//四舍五入
              
              //机加线
              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( weekcolumn.EndDate() = pispip.Start().Date() or pispip.Period_MP() = endperiod ){
                  row.SetCellInventoryValue( weekcolumn, iscc, [Real]inventoryquantity );
                }
              }
            }
          }
        }
      }
    }
    
    //生成调拨数据
    traverse( owner, TransferPlanRow, tprow ){
      product               := selectobject( owner, Product_MP, product, product.ID() = tprow.ProductID() );
      productparents        := product.GetAllParent();
      if( exists( productparents, Elements, e, e.ID() = productparent ) ){//查询产品类型是发动机
        //起始库存点是否是大连or长春
    //    originsp              := selectobject( owner, StockingPoint_MP, sp, sp.ID() = tprow.SourceStockpoingPointID() );
    //    originunit            := originsp.Unit();
    //    originparentunits     := originunit.GetAllParent();
        originiscc            := tprow.SourceStockpoingPointID() = 'CC';//originsp.ID() = ccunit or originunit.ID() = ccunit or exists( originparentunits, Elements, punit, punit.ID() = ccunit );
        originisdl            := tprow.SourceStockpoingPointID() = 'DL';//originsp.ID() = dlunit or originunit.ID() = dlunit or exists( originparentunits, Elements, punit, punit.ID() = dlunit );
        //目的地是否是长春外租库
    //    destisp               := selectobject( owner, StockingPoint_MP, sp, sp.ID() = tprow.TargetStockpoingPointID() );
    //    destiunit             := destisp.Unit();
    //    destiparentunits      := destiunit.GetAllParent();
        destiiscc             := tprow.TargetStockpoingPointID() = 'CC';//destisp.ID() = ccunit or destiunit.ID() = ccunit or exists( destiparentunits, Elements, punit, punit.ID() = ccunit );
        destiisdl             := tprow.TargetStockpoingPointID() = 'DL';//destisp.ID() = dlunit or destiunit.ID() = dlunit or exists( destiparentunits, Elements, punit, punit.ID() = dlunit );
        if( ( originiscc and destiisdl ) or ( originisdl and destiiscc ) ){
          row := table.GetRow( tprow.ProductID() );
          traverse( tprow, TransferPlanCell, tpcell, tpcell.TransferPlanColumn().ColumnDate() <> Date::MinDate() ){
            //天
            daycolumn        := table.GetColumnByUnit( Translations::MP_GlobalParameters_Day(), tpcell.TransferPlanColumn().ColumnDate() );
            //周
            weekcolumn       := table.GetColumnByUnit( Translations::MP_GlobalParameters_Week(), tpcell.TransferPlanColumn().ColumnDate() );
            quantity         := [Real]tpcell.Value();//四舍五入
            
            if( not isnull( daycolumn ) ){
              row.SetCellTransferValue( daycolumn, ( originiscc and destiisdl ), quantity );
            }
            if( not isnull( weekcolumn ) ){
              row.SetCellTransferValue( weekcolumn, ( originiscc and destiisdl ), quantity );
            }
          }
        }
      }
    }
    
    rows := selectsortedset( table, Row, row, row.Name() );
    i    := 0;
    traverse( rows, Elements, e ){
      e.RowNr( i );
      traverse( e, Cell, cell ){
        cell.CCAssemblyPlanQty( cell.Column().CCAssemblyPlanQty() );
        cell.DLAssemblyPlanQty( cell.Column().DLAssemblyPlanQty() );
      }
      i := i + 1;
    }
    showtable.Generate( search, products );
  *]
}