| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod Initialize ( | 
|   MacroPlan owner | 
| ) | 
| { | 
|   TextBody: | 
|   [* | 
|     // 甄兰鸽 Jun-24-2024 (created) | 
|     owner.FinancialProductionSource( relflush ); | 
|     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.PlannedInventoryLevelEnd() <> 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.PlannedInventoryLevelEnd() <> 0 or pispip.DependentDemandAndSalesDemandQuantity() <> 0 ), pispip.Start() ); | 
|           traverse( pispips, Elements, pispip){//, pispip.Start().Month() = 1 and pispip.Start().Day() = 2 | 
|             products.Add( pisp.Product_MP() ); | 
|              | 
|             //天 | 
|             daycolumn         := table.GetColumnByUnit( Translations::MP_GlobalParameters_Day(), pispip.Start().Date() ); | 
|             //周 | 
|             weekcolumn        := table.GetColumnByUnit( Translations::MP_GlobalParameters_Week(), pispip.Start().Date() ); | 
|              | 
|             row               := table.GetRow( pisp.ProductID() ); | 
|                | 
|              | 
|             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, 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 ); | 
|       i := i + 1; | 
|     } | 
|     showtable.Generate( search, products ); | 
|   *] | 
| } |