From 17dc904834ee19f0e57db374aaadea932acdaf00 Mon Sep 17 00:00:00 2001
From: lazhen <17772815105@139.com>
Date: 星期一, 01 七月 2024 14:43:05 +0800
Subject: [PATCH] 财务销量报表

---
 _Main/BL/Type_FinancialSalesSource/StaticMethod_Initialize.qbl |  131 +++++++++++++++++++++++++------------------
 1 files changed, 75 insertions(+), 56 deletions(-)

diff --git a/_Main/BL/Type_FinancialSalesSource/StaticMethod_Initialize.qbl b/_Main/BL/Type_FinancialSalesSource/StaticMethod_Initialize.qbl
index 7a5ef26..8f63f1f 100644
--- a/_Main/BL/Type_FinancialSalesSource/StaticMethod_Initialize.qbl
+++ b/_Main/BL/Type_FinancialSalesSource/StaticMethod_Initialize.qbl
@@ -4,77 +4,96 @@
   MacroPlan owner
 )
 {
+  Description: '鍒濆鍖�'
   TextBody:
   [*
     // 鐢勫叞楦� Jun-24-2024 (created)
-    owner.FinancialProductionSource( relflush );
-    ccunit                    := FinancialProductionReport::GetDefaultCCUnit();
-    dlunit                    := FinancialProductionReport::GetDefaultDLUnit();
-    allunit                   := FinancialProductionReport::GetDefaultAllUnit();
-    source                    := owner.FinancialProductionSource( relnew, IsImport := false, Name := FinancialProductionReport::GetDefaultName() );
-    table                     := source.FinancialProductionReport( relnew, ID := source.Name(), Name := source.Name(), IsImport := false );
-    showtable                 := source.FinancialProductionReport( relnew, ID := source.Name() + 'Show', Name := source.Name(), IsImport := false, IsShow := true );
+    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();
-    startofnextmonth          := owner.StartOfPlanning().StartOfNextMonth();
     startofyear               := startofplanning.StartOfYear();
     startofnextyear           := startofplanning.StartOfNextYear();
     
-    search                    := source.FinancialProductionSearch( relnew, Unit := allunit, Generation := allunit, MqbMlb := allunit, Power := allunit );
-    
-    products                  := construct( Product_MPs );
+    search                    := source.FinancialSalesSearch( relnew, Unit := allsalessegment, Generation := allsalessegment, MqbMlb := allsalessegment, Power := allsalessegment );
     
     table.GenerateColumn( owner );
     
-    traverse( owner, Product_MP.ProductInStockingPoint_MP, pisp, pisp.Product_MP().IsLeaf() and ( pisp.StockingPoint_MP().UnitID() = ccunit or pisp.StockingPoint_MP().UnitID() = dlunit ) ){
-      unit := pisp.StockingPoint_MP().UnitID();
-      info( unit, pisp.ProductID() );
-      ccrow := null( FinancialProductionRow );
-      dlrow := null( FinancialProductionRow );
-      allrow := selectobject( table, FinancialProductionRow, row, row.Name() = pisp.ProductID() and row.Unit() = allunit );
-      if( unit = ccunit ){
-        ccrow := table.FinancialProductionRow( relnew, Name := pisp.ProductID(), Unit := unit );
-      }else{
-        dlrow := table.FinancialProductionRow( relnew, Name := pisp.ProductID(), Unit := unit );
-      }
-      if( isnull( allrow ) ){
-        products.Add( pisp.Product_MP() );
-        allrow := table.FinancialProductionRow( relnew, Name := pisp.ProductID(), Unit := allunit );
-      }
+    //浠嶧orecast鏌ヨ
+    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(), startofyear, startofnextyear );
+      periodtime := forecast.StartDate().StartOfMonth();
+      periodname := periodtime.Format( "M2/D2/Y" );
       
-      for( start := startofyear; start < startofnextyear; start := start.StartOfNextMonth() ){
-        periodtime := start.Date();
-        periodname := periodtime.Format( "M2/D2/Y" );
-        column := selectobject( table, FinancialProductionColumn, column, column.Name() = periodname and column.Period() = periodtime );
-        
-        if( not isnull( ccrow ) ){
-          ccrow.Initialize( column, ccunit );
-        }
-        if( not isnull( dlrow ) ){
-          dlrow.Initialize( column, dlunit );
-        }
-        if( not exists( allrow, FinancialProductionCell, allcell, allcell.FinancialProductionColumn() = column ) ){
-          allrow.Initialize( column, allunit );
-        }
+      if( products.Find( product ) < 0 ){
+        products.Add( product );
       }
-      
-      traverse( pisp, ProductInStockingPointInPeriod, pispip, pispip.Start() >= startofplanning
-                and ( ( pispip.Start() < startofnextmonth and pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day() ) 
-                      or ( 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, FinancialProductionColumn, column, column.Name() = periodname and column.Period() = periodtime );
-        
-        if( not isnull( ccrow ) ){
-          ccrow.Initialize( column, pispip.NewSupplyProductionQuantity() );
+    //  info( '------------------------', periodname, periodtime );
+      column    := selectobject( table, FinancialSalesColumn, column, column.Name() = periodname and column.Period() = periodtime );
+    //  info( '------------------------', column.Name() );
+      //Forecast鐨凷ales Segment涓洪暱鏄ワ紝璇嗗埆鍑篗LB鐨勬墍鏈変骇鍝佹眹鎬�
+      if( forecast.SalesSegmentName() = ccsalessegment and product.MQBMLB() = 'MLB' ){
+    //    info( '------------------------', column.Name() );
+        ccrow := table.GetRow( ccsalessegment, product.ID(), startofyear, startofnextyear );
+    //    info( '------------------------', ccrow.FinancialSalesCell( relsize ), column.FinancialSalesCell( relsize ) );
+        ccrow.Initialize( column, forecast.Quantity() );
+      }else if( forecast.SalesSegmentName() = tjsalessegment or forecast.SalesSegmentName() = fssalessegment ){
+        //澶ц繛璐㈠姟閿�閲忥細棣栧厛鍦╢orecast鐣岄潰鏌ユ壘Sales Segment鏄ぉ娲ュ拰浣涘北鐨勬墍鏈夐渶姹傦紝姣忎釜浜у搧鎸夋湀姹囨�婚渶姹傛暟閲�
+    //    info( '------------------------', column.Name() );
+        dlrow := table.GetRow( dlsalessegment, product.ID(), startofyear, startofnextyear );
+    //    info( '------------------------', dlrow.FinancialSalesCell( relsize ), column.FinancialSalesCell( relsize ) );
+        dlrow.Initialize( column, forecast.Quantity() );
+      }
+      allrow.Initialize( column, forecast.Quantity() );
+    }
+    //浠嶱roduct planning鏌ユ壘搴撳瓨鐐逛负闀挎槬瑁呴厤绾胯竟搴撶殑鎵�鏈塎QB浜у搧锛屽彇Total Demand瀛楁鎸夋湀姹囨�婚渶姹傛暟閲�
+    traverse( owner, Product_MP, product, product.IsLeaf() and product.MQBMLB() = 'MQB' ){//浜у搧涓篗QB
+      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(), startofyear, startofnextyear );
+          ccrow.Initialize( column, pispip.DependentDemandAndSalesDemandQuantity() );//鍙朤otal Demand瀛楁鎸夋湀姹囨�婚渶姹傛暟閲�
+          
+          allrow     := table.GetRow( allsalessegment, product.ID(), startofyear, startofnextyear );
+          allrow.Initialize( column, pispip.DependentDemandAndSalesDemandQuantity() );
         }
-        if( not isnull( dlrow ) ){
-          dlrow.Initialize( column, pispip.NewSupplyProductionQuantity() );
-        }
-        allrow.Initialize( column, pispip.NewSupplyProductionQuantity() );
       }
     }
-    rows := selectsortedset( table, FinancialProductionRow, row, row.Name() );
+    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(), startofyear, startofnextyear );
+          dlrow.Initialize( column, pit.Quantity() );//鍙朤otal Demand瀛楁鎸夋湀姹囨�婚渶姹傛暟閲�
+          
+          allrow     := table.GetRow( allsalessegment, pit.ProductID(), startofyear, startofnextyear );
+          allrow.Initialize( column, pit.Quantity() );
+        }
+      }
+    }
+    
+    rows := selectsortedset( table, FinancialSalesRow, row, row.Name() );
     i    := 0;
     traverse( rows, Elements, e ){
       e.RowNr( i );

--
Gitblit v1.9.3