| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod Initialize ( | 
|   MacroPlan owner | 
| ) | 
| { | 
|   Description: '初始化' | 
|   TextBody: | 
|   [* | 
|     // 甄兰鸽 Jun-24-2024 (created) | 
|     owner.FinancialSalesSource( relflush ); | 
|     products                  := construct( Product_MPs ); | 
|     allsalessegment           := FinancialSalesReport::GetSalesSegmentAll(); | 
|     ccsalessegment            := FinancialSalesReport::GetSalesSegmentCC(); | 
|     dlsalessegment            := FinancialSalesReport::GetSalesSegmentDL(); | 
|     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(); | 
|     //startofyear               := startofplanning.StartOfYear(); | 
|     startofnextyear           := startofplanning.StartOfNextYear(); | 
|      | 
|     search                    := source.FinancialSalesSearch( relnew, Unit := allsalessegment, Generation := allsalessegment, MqbMlb := allsalessegment, Power := allsalessegment ); | 
|      | 
|     table.GenerateColumn( owner ); | 
|      | 
|     //从Forecast查询 | 
|     traverse( owner, SalesDemand.astype( Forecast ), forecast, forecast.StartDate() < startofnextyear.Date() and ( ( forecast.SalesSegmentName() = ccsalessegment and forecast.Product_MP().MQBMLB() = 'MLB' )  | 
|               or forecast.SalesSegmentName() = tjsalessegment or forecast.SalesSegmentName() = fssalessegment ) ){ | 
|       product    := forecast.Product_MP(); | 
|       allrow     := table.GetRow( allsalessegment, product.ID() ); | 
|       periodtime := forecast.StartDate().StartOfMonth(); | 
|       periodname := periodtime.Format( "M2/D2/Y" ); | 
|        | 
|       if( products.Find( product ) < 0 ){ | 
|         products.Add( product ); | 
|       } | 
|     //  info( '------------------------', periodname, periodtime ); | 
|       column    := selectobject( table, FinancialSalesColumn, column, column.Name() = periodname and column.Period() = periodtime ); | 
|     //  info( '------------------------', column.Name() ); | 
|       //Forecast的Sales Segment为长春,识别出MLB的所有产品汇总 | 
|       if( forecast.SalesSegmentName() = ccsalessegment and product.MQBMLB() = 'MLB' ){ | 
|     //    info( '------------------------', column.Name() ); | 
|         ccrow := table.GetRow( ccsalessegment, product.ID() ); | 
|     //    info( '------------------------', ccrow.FinancialSalesCell( relsize ), column.FinancialSalesCell( relsize ) ); | 
|         ccrow.Initialize( column, forecast.Quantity() ); | 
|       }else if( forecast.SalesSegmentName() = tjsalessegment or forecast.SalesSegmentName() = fssalessegment ){ | 
|         //大连财务销量:首先在forecast界面查找Sales Segment是天津和佛山的所有需求,每个产品按月汇总需求数量 | 
|     //    info( '------------------------', column.Name() ); | 
|         dlrow := table.GetRow( dlsalessegment, product.ID() ); | 
|     //    info( '------------------------', dlrow.FinancialSalesCell( relsize ), column.FinancialSalesCell( relsize ) ); | 
|         dlrow.Initialize( column, forecast.Quantity() ); | 
|       } | 
|       allrow.Initialize( column, forecast.Quantity() ); | 
|     } | 
|     //从Product planning查找库存点为长春装配线边库的所有MQB产品,取Total Demand字段按月汇总需求数量 | 
|     traverse( owner, Product_MP, product, product.IsLeaf() and product.MQBMLB() = 'MQB' ){//产品为MQB | 
|       traverse( product, ProductInStockingPoint_MP, pisp, pisp.StockingPointID() = ccspline ){//库存点为长春装配线边库 | 
|         traverse( pisp, ProductInStockingPointInPeriod, pispip, pispip.Start() >= startofplanning | 
|                 and pispip.Start() < startofnextyear and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Month() ){ | 
|           periodtime := pispip.Start().StartOfMonth().Date(); | 
|           periodname := periodtime.Format( "M2/D2/Y" ); | 
|           column    := selectobject( table, FinancialSalesColumn, column, column.Name() = periodname and column.Period() = periodtime ); | 
|           ccrow := table.GetRow( ccsalessegment, product.ID() ); | 
|           ccrow.Initialize( column, pispip.DependentDemandAndSalesDemandQuantity() );//取Total Demand字段按月汇总需求数量 | 
|            | 
|           allrow     := table.GetRow( allsalessegment, product.ID() ); | 
|           allrow.Initialize( column, pispip.DependentDemandAndSalesDemandQuantity() ); | 
|         } | 
|       } | 
|     } | 
|     startofnextyearlead       := startofplanning.StartOfNextYear() + FinancialSalesReport::GetDefaultTripLeadingTime(); | 
|     //大连财务销量:长春的需求需要在trip plan里面找到起始库存点为大连装配线边库,目的地为长春外租库的产品,由于需要考虑产品运输lead time,每个月的汇总数据需要推迟两天进行计算 | 
|     traverse( owner, Unit.Lane.LaneLeg, laneleg, laneleg.OriginStockingPointID() = dlspline and laneleg.DestinationStockingPointID() = ccrent ){ | 
|       traverse( laneleg, Trip, trip, trip.Arrival() < startofnextyearlead ){ | 
|         periodtime := ( trip.Arrival() - FinancialSalesReport::GetDefaultTripLeadingTime() ).StartOfMonth().Date(); | 
|         periodname := periodtime.Format( "M2/D2/Y" ); | 
|          | 
|         column    := selectobject( table, FinancialSalesColumn, column, column.Name() = periodname and column.Period() = periodtime ); | 
|         traverse( trip, ProductInTrip, pit ){ | 
|           dlrow      := table.GetRow( dlsalessegment, pit.ProductID() ); | 
|           dlrow.Initialize( column, pit.Quantity() );//取Total Demand字段按月汇总需求数量 | 
|            | 
|           allrow     := table.GetRow( allsalessegment, pit.ProductID() ); | 
|           allrow.Initialize( column, pit.Quantity() ); | 
|         } | 
|       } | 
|     } | 
|      | 
|     rows := selectsortedset( table, FinancialSalesRow, row, row.Name() ); | 
|     i    := 0; | 
|     traverse( rows, Elements, e ){ | 
|       e.RowNr( i ); | 
|       i := i + 1; | 
|     } | 
|     showtable.Generate( search, products ); | 
|   *] | 
| } |