lazhen
2024-08-14 94ab2bd0381925ecf01a2f1a812b114d0f82d5bb
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
Quintiq file version 2.0
#parent: #root
StaticMethod Initialize (
  MacroPlan owner
)
{
  Description: '初始化'
  TextBody:
  [*
    // 甄兰鸽 Jun-24-2024 (created)
    owner.FinancialSalesSource( relflush );
    products                  := construct( Product_MPs );
    allunit                   := FinancialSalesReport::GetDefaultAllUnit();
    ccunit                    := FinancialSalesReport::GetDefaultCCUnit();
    dlunit                    := FinancialSalesReport::GetDefaultDLUnit();
    ccsalessegment            := FinancialSalesReport::GetSalesSegmentCC();
    tjsalessegment            := FinancialSalesReport::GetSalesSegmentTJ();
    fssalessegment            := FinancialSalesReport::GetSalesSegmentFS();
    ccspline                  := FinancialSalesReport::GetStockingPointCCLine();
    dlspline                  := FinancialSalesReport::GetStockingPointDLLine();
    ccrent                    := FinancialSalesReport::GetStockingPointCCRent();
    
    source                    := owner.FinancialSalesSource( relnew, IsImport := false, Name := FinancialSalesReport::GetDefaultName() );
    table                     := source.FinancialSalesReport( relnew, ID := source.Name(), Name := source.Name(), IsImport := false );
    showtable                 := source.FinancialSalesReport( relnew, ID := source.Name() + 'Show', Name := source.Name(), IsImport := false, IsShow := true );
    startofplanning           := owner.StartOfPlanning().Date();
    //startofyear               := startofplanning.StartOfYear();
    startofnextyear           := startofplanning.StartOfNextYear();
    
    search                    := source.FinancialSalesSearch( relnew, Unit := allunit, Generation := allunit, MqbMlb := allunit, Power := allunit );
    
    table.GenerateColumn( owner );
    
    //首先在forecast界面查找sales segment为长春的所有需求,识别出MLB的所有产品,每个产品按月汇总需求数量
    traverse( owner, SalesDemand.astype( Forecast ), forecast, forecast.StartDate() < startofnextyear and forecast.Quantity() <> 0 
              and exists( forecast, PlanningSalesDemandInPeriod, psdip, psdip.Quantity() <> 0 ) ){
      salessegment            := forecast.SalesSegment_MP();
      parentsalessegments     := salessegment.GetAllParent();
      //是否属于长春
      iscc                    := salessegment.Name() = ccsalessegment or exists( parentsalessegments, Elements, psalessegment, psalessegment.Name() = ccsalessegment );
      //是否属于大连, 即天津和佛山
      isdl                    := salessegment.Name() = tjsalessegment or salessegment.Name() = fssalessegment 
                                  or exists( parentsalessegments, Elements, psalessegment, psalessegment.Name() = tjsalessegment ) 
                                  or exists( parentsalessegments, Elements, psalessegment, psalessegment.Name() = fssalessegment );
      //Forecast的Sales Segment为长春,识别出MLB的所有产品汇总
      //大连财务销量:首先在forecast界面查找Sales Segment是天津和佛山的所有需求,每个产品按月汇总需求数量
      if( ( iscc and forecast.Product_MP().MQBMLB() = 'MLB' ) or isdl ){
        product              := forecast.Product_MP();
        //获取合计行
        allrow               := table.GetRow( allunit, product );
        //获取工厂行
        factoryrow           := table.GetRow( ifexpr( iscc and forecast.Product_MP().MQBMLB() = 'MLB', ccunit, dlunit ), product );
      
        products.Add( product );
        traverse( forecast, PlanningSalesDemandInPeriod, psdip, psdip.Quantity() <> 0 ){
          periodtime         := psdip.StartDate().StartOfMonth();
          periodname         := periodtime.Format( "M2/D2/Y" );
    //      info( '-------------------------', periodname, periodtime );
          column             := selectobject( table, FinancialSalesColumn, column, column.Name() = periodname and column.Period() = periodtime );
    //      info( '-------------------------', column.Name() );
          quantity   := [Number]psdip.Quantity();//四舍五入
          
          factoryrow.Initialize( column, quantity );
          allrow.Initialize( column, quantity );
        }
      }
    }
    //从Product planning查找库存点为长春装配线边库的所有MQB产品,取Total Demand字段按月汇总需求数量
    traverse( owner, StockingPoint_MP, stockingpoint ){
    //  unit                  := stockingpoint.Unit();
    //  parentunits           := unit.GetAllParent();
      //是否属于长春装配线
    //  iscc                  := unit.ID() = ccspline or exists( parentunits, Elements, punit, punit.ID() = ccspline );
      if( table.IsInUnit( stockingpoint, ccspline ) ){
        traverse( stockingpoint, ProductInStockingPoint_MP, pisp, pisp.Product_MP().IsLeaf() and pisp.Product_MP().MQBMLB() = 'MQB' 
                  and exists( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear and pispip.DependentDemandAndSalesDemandQuantity() <> 0 ) ){//产品为MQB
          product           := pisp.Product_MP();
          allrow            := table.GetRow( allunit, product );
          ccrow             := table.GetRow( ccunit, product );
          products.Add( product );
          traverse( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear and pispip.DependentDemandAndSalesDemandQuantity() <> 0 ){
            periodtime      := pispip.Start().StartOfMonth().Date();
            periodname      := periodtime.Format( "M2/D2/Y" );
            column          := selectobject( table, FinancialSalesColumn, column, column.Name() = periodname and column.Period() = periodtime );
            quantity        := [Number]pispip.DependentDemandAndSalesDemandQuantity();//四舍五入
            
            ccrow.Initialize( column, quantity );//取Total Demand字段按月汇总需求数量
            allrow.Initialize( column, quantity );
          }
        }
      }
    }
    startofnextyearlead       := startofplanning.StartOfNextYear() + FinancialSalesReport::GetDefaultTripLeadingTime();
    //大连财务销量:长春的需求需要在trip plan里面找到起始库存点为大连装配线边库,目的地为长春外租库的产品,由于需要考虑产品运输lead time,每个月的汇总数据需要推迟两天进行计算
    traverse( owner, Unit.Lane.LaneLeg, laneleg ){
      //起始库存点是否是大连装配线边库
      originsp              := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.OriginStockingPointID() );
      isdlspline            := table.IsInUnit( originsp, dlspline );
      //目的地是否是长春外租库
      destisp               := selectobject( owner, StockingPoint_MP, sp, sp.ID() = laneleg.DestinationStockingPointID() );
      isccrent              := table.IsInUnit( destisp, ccrent );
      if( isdlspline and isccrent ){
        traverse( laneleg, Trip, trip, trip.Arrival() < startofnextyearlead and exists( trip, ProductInTrip, pit, pit.Quantity() <> 0 ) ){
    //      periodtime        := ( trip.Arrival() - FinancialSalesReport::GetDefaultTripLeadingTime() ).StartOfMonth().Date();
          periodtime        := trip.Departure().StartOfMonth().Date();
          periodname        := periodtime.Format( "M2/D2/Y" );
          
          column            := selectobject( table, FinancialSalesColumn, column, column.Name() = periodname and column.Period() = periodtime );
          if( not isnull( column ) ){
            traverse( trip, ProductInTrip, pit, pit.Quantity() <> 0 ){
              product       := pit.Product_MP();
              products.Add( product );
              quantity      := [Number]pit.Quantity();//四舍五入
              dlrow         := table.GetRow( dlunit, pit.Product_MP() );
              dlrow.Initialize( column, quantity );//汇总数量
              
              allrow        := table.GetRow( allunit, pit.Product_MP() );
              allrow.Initialize( column, quantity );
            }
          }
        }
      }
    }
    
    rows := selectsortedset( table, FinancialSalesRow, row, row.Name() );
    i    := 0;
    traverse( rows, Elements, e ){
      e.RowNr( i );
      i := i + 1;
    }
    showtable.Generate( search, products );
  *]
}