lazhen
2025-01-08 adb6335399c5a1658d8d8172a91042585f3e30b1
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Quintiq file version 2.0
#parent: #root
StaticMethod Initialize (
  MacroPlan owner
)
{
  TextBody:
  [*
    // 甄兰鸽 Jun-24-2024 (created)
    owner.FinancialProductionSource( relflush );
    startinventorydate        := owner.StartOfPlanning() - Duration::Days( 1 );
    startyearmonth            := owner.StartOfPlanning().StartOfMonth().Date();
    productparent             := MachiningPipelineReport::GetDefaultProductParent();
    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 );
      if( iscc or isdl ){
        traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf() and not pisp.IsSystem()// and pisp.ProductID() = '06K103011CM'
                  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.DependentDemandAndSalesDemandQuantity() <> 0 ) ) ){
          isccassemnly        := stockingpoint.ID().EndsWith( pisp.Product_MP().ParentID() + '线边库' ) and ( stockingpoint.ID().StartsWith( 'CC' ) or stockingpoint.ID().StartsWith( '长春' ) );
          isdlassemnly        := stockingpoint.ID().EndsWith( pisp.Product_MP().ParentID() ) and ( stockingpoint.ID().StartsWith( 'DL' ) or stockingpoint.ID().StartsWith( '大连' ) );
          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.DependentDemandAndSalesDemandQuantity() <> 0 ), pispip.Start() );
          products.Add( pisp.Product_MP() );
          row               := table.GetRow( pisp.ProductID() );
          inventoryqty      := sum( pisp, ProductInStockingPointInPeriod, pispip, pispip.Start() = startinventorydate and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day() and pispip.ActualInventoryLevelEnd() <> 0, pispip.ActualInventoryLevelEnd() );
          if( isccassemnly ){
            row.CCInventoryQty( row.CCInventoryQty() + inventoryqty );
          }
          if( isdlassemnly ){
            row.DLInventoryQty( row.DLInventoryQty() + inventoryqty );
          }
          traverse( pispips, Elements, pispip){//, pispip.Start().Month() = 1 and pispip.Start().Day() = 2
    
            //天
            daycolumn         := table.GetColumnByUnit( Translations::MP_GlobalParameters_Day(), pispip.Start().Date() );
            //周
    //        weekcolumn        := table.GetColumnByUnit( Translations::MP_GlobalParameters_Week(), pispip.Start().Date() );
            
            if( isccassemnly or isdlassemnly ){
              //装配线
              quantity        := [Number]pispip.DependentDemandAndSalesDemandQuantity();//四舍五入
              row.SetAssemblyPlanValue(  daycolumn, isccassemnly, [Real]quantity );
    //          row.SetAssemblyPlanValue( weekcolumn, isccassemnly, [Real]quantity );
              //生产
              supplyqty       := [Number]pispip.NewSupplyQuantity();//四舍五入
    //          info( '****************', quantity, supplyqty );
              row.SetCellProductionValue( daycolumn, isccassemnly, [Real]supplyqty );
    //          row.SetCellProductionValue( weekcolumn, isccassemnly, [Real]supplyqty );
            }
            
            //库存
    //        if( iscc or isdl ){
    //          inventoryqty    := [Number]pispip.PlannedInventoryLevelEnd();//四舍五入
    //          row.SetCellInventoryValue( daycolumn, iscc, [Real]inventoryqty );
    //          if( weekcolumn.EndDate() = pispip.Start().Date() or pispip.Period_MP() = endperiod ){
    //            row.SetCellInventoryValue( weekcolumn, iscc, [Real]inventoryqty );
    //          }
    //        }
          }
        }
      }
    }
    //生成调拨数据
    traverse( owner, Unit.Lane.LaneLeg, laneleg ){
      originspid             := laneleg.OriginStockingPointID();
      destinationspid        := laneleg.DestinationStockingPointID();
      //CC to DL 长春工厂到大连工厂
      iscctodl               := ( originspid.StartsWith( '长春' ) or originspid.StartsWith( 'CC' ) ) and ( destinationspid.StartsWith( '大连' ) or destinationspid.StartsWith( 'DL' ) );
      //DL to CC 大连厂内库到大连发动机的长春外租库
      isdltocc               := originspid.EndsWith( '厂内库' ) and ( originspid.StartsWith( '大连' ) or originspid.StartsWith( 'DL' ) ) and destinationspid = '大连发动机的长春外租库';
      if( iscctodl or isdltocc ){
    //    info( '------iscctodl------', originspid, destinationspid, iscctodl );
        traverse( table, Column, column  ){//, column.StartDate().Month() = 1
          alltrips           := selectset( laneleg, Trip, trip, trip.Arrival().Date() = column.StartDate()
                                           or trip.Departure().Date() = column.StartDate() );
          producttrips      := selectuniquevalues( alltrips, Elements.ProductInTrip, pit, pit.Quantity() <> 0 and exists( pit.Product_MP().GetAllParent(), Elements, e, e.ID() = productparent ), pit.ProductID() );
    //      info( '---------Column----------', alltrips.Size(), producttrips.Size(), column.StartDate() );
          traverse( producttrips, Elements, producttrip ){//, producttrip = '06K103011CP'
            row             := table.GetRow( producttrip );
            product         := selectobject( owner, Product_MP, product, product.ID() = producttrip );
            products.Add( product );
            departureqty    := sum( alltrips, Elements.ProductInTrip, pit, pit.Trip().Departure().Date() = column.StartDate() and pit.Product_MP() = product, pit.Quantity() );
            arrivalqty      := sum( alltrips, Elements.ProductInTrip, pit, pit.Trip().Arrival().Date() = column.StartDate() and pit.Product_MP() = product, pit.Quantity() );
    //        info( '---------***************8---------', departureqty, arrivalqty, column.StartDate() );
            row.SetDepartureAndArrivalValue( column, iscctodl, departureqty, arrivalqty );
          }
        }
      }
    }
    //生成调拨数据
    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 );
    //        }
          }
        }
      }
    }
    
    traverse( table, Row, row ){
      traverse( table, Column, column, column.TimeUnit() = Translations::MP_GlobalParameters_Day() ){
        maxinventory        := selectobject( row, Cell, cell, cell.Column() = column );
        ccinventoryqty      := 0.0;
        dlinventoryqty      := 0.0;
        if( column.StartDate() = startyearmonth ){//当日期是计划开始第一个月时,计算库存是实际库存
          ccinventoryqty    := row.CCInventoryQty() + maxinventory.CCProductionQty() - maxinventory.CCToDLDepartureQty() + maxinventory.DLToCCArrivalQty() - maxinventory.CCAssemblyPlanQty();
          dlinventoryqty    := row.DLInventoryQty() + maxinventory.DLProductionQty() - maxinventory.DLToCCDepartureQty() + maxinventory.CCToDLArrivalQty() - maxinventory.DLAssemblyPlanQty();
        }else{
          beforecolumn      := column.PreviousColumn();
          beforeinventory   := selectobject( row, Cell, c, c.Column() = beforecolumn );
          beCCinventoryqty  := 0.0;
          beDLinventoryqty  := 0.0;
          if( not isnull( beforeinventory ) ){
            beCCinventoryqty := beforeinventory.CCInventoryQty();
            beDLinventoryqty := beforeinventory.DLInventoryQty();
          }
          ccinventoryqty    := beCCinventoryqty + maxinventory.CCProductionQty() - maxinventory.CCToDLDepartureQty() + maxinventory.DLToCCArrivalQty() - maxinventory.CCAssemblyPlanQty();
          dlinventoryqty    := beDLinventoryqty + maxinventory.DLProductionQty() - maxinventory.DLToCCDepartureQty() + maxinventory.CCToDLArrivalQty() - maxinventory.DLAssemblyPlanQty();
        }
        maxinventory.CCInventoryQty( ccinventoryqty );
        maxinventory.DLInventoryQty( dlinventoryqty );
      }
    }
    showtable.Generate( search, products );
  *]
}