From 23eddf3d7adcdd2994c97c611dd2dd83895e38f3 Mon Sep 17 00:00:00 2001
From: lazhen <17772815105@139.com>
Date: 星期五, 02 八月 2024 20:59:38 +0800
Subject: [PATCH] 财务产量报表修改

---
 _Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultDLUnit.qbl |    2 
 _Main/BL/Type_FinancialProductionRow/Method_Initialize.qbl                |    4 
 _Main/BL/Type_FinancialProductionReport/Method_GetCurrentPeriod.qbl       |   53 +++++++++++++++++
 _Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultCCUnit.qbl |    2 
 _Main/BL/Type_FinancialProductionSource/StaticMethod_Initialize.qbl       |   90 +++++++++++++-----------------
 _Main/BL/Type_FinancialProductionReport/Method_GetRowByUnit.qbl           |   22 +++++++
 _Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultDLUnit.qbl    |    2 
 _Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultCCUnit.qbl    |    2 
 8 files changed, 120 insertions(+), 57 deletions(-)

diff --git a/_Main/BL/Type_FinancialProductionReport/Method_GetCurrentPeriod.qbl b/_Main/BL/Type_FinancialProductionReport/Method_GetCurrentPeriod.qbl
new file mode 100644
index 0000000..6e9b192
--- /dev/null
+++ b/_Main/BL/Type_FinancialProductionReport/Method_GetCurrentPeriod.qbl
@@ -0,0 +1,53 @@
+Quintiq file version 2.0
+#parent: #root
+Method GetCurrentPeriod (
+  Date startofplanning,
+  Period_MPs periods
+) as owning Period_MPs
+{
+  Description: '鑾峰彇褰撳墠鏈堢殑璁″垝鍛ㄦ湡---------------搴熷純'
+  TextBody:
+  [*
+    // 鐢勫叞楦� Aug-2-2024 (created)
+    //寮�濮嬫棩鏈熷埌涓嬩釜鏈堢殑闂撮殧澶╂暟
+    currentperiods            := construct( Period_MPs );
+    startofnextmonth          := startofplanning.StartOfNextMonth();
+    //鐗规畩鎯呭喌锛屽綋寮�濮嬫棩鏈熸濂芥槸杩欎釜鏈堢涓�澶╋紝 鍒欑洿鎺ヤ娇鐢═imeUnit涓烘湀鐨勬暟鎹�
+    if( startofplanning.StartOfMonth() = startofplanning ){
+      period                  := selectobject( periods, Elements, period, period.TimeUnit() = Translations::MP_GlobalParameters_Month() and period.StartDate() = startofplanning );
+      currentperiods.Add( period );
+    } else if( startofplanning.StartOfWeek() = startofplanning ){
+      //鐗规畩鎯呭喌锛屽綋寮�濮嬫棩鏈熸濂芥槸杩欎釜鍛ㄧ涓�澶╋紝 鍒欑洿鎺ヤ娇鐢═imeUnit涓哄懆鐨勬暟鎹紝 璺ㄥ懆鏃朵娇鐢╠ay
+      traverse( periods, Elements, period, ( period.TimeUnit() =  Translations::MP_GlobalParameters_Week() and period.StartDate() < startofnextmonth ) 
+                or (  period.TimeUnit() =  Translations::MP_GlobalParameters_Day() and period.EndDate() = startofnextmonth ) ){
+        currentperiods.Add( period );
+      }
+    } else {
+      duration                := startofplanning.StartOfNextMonth() - startofplanning;
+      //濡傛灉璁″垝寮�濮嬫棩鏈熷埌涓嬩釜鏈堝皬浜�7澶╋紝鍒欏彲浠ョ洿鎺ヤ娇鐢≒eriod鐨凾imeUnit涓哄ぉ鐨勬暟鎹�
+      if( duration <= 7 ){
+        i := 1;
+        traverse( periods, Elements, period, period.TimeUnit() = Translations::MP_GlobalParameters_Day() and i < duration ){
+          currentperiods.Add( period );
+          i ++;
+        }
+      }else{
+        //鍙嶄箣闇�瑕佸湪鍔犱笂Period鐨凾imeUnit涓哄懆鐨勬暟鎹�
+        day := startofplanning;
+        while( day < startofnextmonth ){
+          if( day = day.StartOfWeek() ){
+            period     := selectobject( periods, Elements, cperiod, cperiod.TimeUnit() = Translations::MP_GlobalParameters_Week() and cperiod.StartDate() = day );
+            day        := period.EndDate();
+            currentperiods.Add( period );
+          } else {
+            period     := selectobject( periods, Elements, cperiod, cperiod.TimeUnit() = Translations::MP_GlobalParameters_Day() and cperiod.StartDate() = day );
+            day        := period.EndDate();
+            currentperiods.Add( period );
+          }
+        }
+      }
+    }
+    
+    return &currentperiods;
+  *]
+}
diff --git a/_Main/BL/Type_FinancialProductionReport/Method_GetRowByUnit.qbl b/_Main/BL/Type_FinancialProductionReport/Method_GetRowByUnit.qbl
new file mode 100644
index 0000000..8de3af4
--- /dev/null
+++ b/_Main/BL/Type_FinancialProductionReport/Method_GetRowByUnit.qbl
@@ -0,0 +1,22 @@
+Quintiq file version 2.0
+#parent: #root
+Method GetRowByUnit (
+  String product,
+  String unit
+) as FinancialProductionRow
+{
+  Description: '鏍规嵁宸ュ巶鑾峰彇琛�'
+  TextBody:
+  [*
+    // 鐢勫叞楦� Aug-2-2024 (created)
+    row := selectobject( this, FinancialProductionRow, row, row.Name() = product and row.Unit() = unit );
+    if( isnull( row ) ){
+      //鍒濆鍖栧崟鍏冩牸
+      row := this.FinancialProductionRow( relnew, Name := product, Unit := unit );
+      traverse( this, FinancialProductionColumn, column ){
+        row.Initialize( column, unit );
+      }
+    }
+    return row;
+  *]
+}
diff --git a/_Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultCCUnit.qbl b/_Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultCCUnit.qbl
index 77d1f16..4a17ee3 100644
--- a/_Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultCCUnit.qbl
+++ b/_Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultCCUnit.qbl
@@ -5,7 +5,7 @@
   TextBody:
   [*
     // 鐢勫叞楦� Jun-25-2024 (created)
-    return '闀挎槬';
+    return '闀挎槬宸ュ巶';
     //return 'Assembly Plant (France)';
   *]
 }
diff --git a/_Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultDLUnit.qbl b/_Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultDLUnit.qbl
index 4759121..ba77240 100644
--- a/_Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultDLUnit.qbl
+++ b/_Main/BL/Type_FinancialProductionReport/StaticMethod_GetDefaultDLUnit.qbl
@@ -5,7 +5,7 @@
   TextBody:
   [*
     // 鐢勫叞楦� Jun-25-2024 (created)
-    return '澶ц繛';
+    return '澶ц繛宸ュ巶';
     //return 'Assembly Plant (Spain)';
   *]
 }
diff --git a/_Main/BL/Type_FinancialProductionRow/Method_Initialize.qbl b/_Main/BL/Type_FinancialProductionRow/Method_Initialize.qbl
index 2bdcc0c..da223ae 100644
--- a/_Main/BL/Type_FinancialProductionRow/Method_Initialize.qbl
+++ b/_Main/BL/Type_FinancialProductionRow/Method_Initialize.qbl
@@ -2,7 +2,7 @@
 #parent: #root
 Method Initialize (
   FinancialProductionColumn column,
-  Real quantity
+  Number quantity
 )
 {
   TextBody:
@@ -10,7 +10,7 @@
     // 鐢勫叞楦� Jun-24-2024 (created)
     cell := selectobject( this, FinancialProductionCell, cell, cell.FinancialProductionColumn() = column );
           
-    value := [Real]cell.Value() + quantity;
+    value := [Number]cell.Value() + quantity;
     cell.Value( [String]value );
   *]
 }
diff --git a/_Main/BL/Type_FinancialProductionSource/StaticMethod_Initialize.qbl b/_Main/BL/Type_FinancialProductionSource/StaticMethod_Initialize.qbl
index e9e00a2..63d3a59 100644
--- a/_Main/BL/Type_FinancialProductionSource/StaticMethod_Initialize.qbl
+++ b/_Main/BL/Type_FinancialProductionSource/StaticMethod_Initialize.qbl
@@ -14,66 +14,54 @@
     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 );
-    startofplanning           := owner.StartOfPlanning();
-    startofnextmonth          := owner.StartOfPlanning().StartOfNextMonth();
-    startofyear               := startofplanning.StartOfYear();
+    startofplanning           := owner.StartOfPlanning().Date();
+    //startofnextmonth          := startofplanning.StartOfNextMonth();
     startofnextyear           := startofplanning.StartOfNextYear();
     
     search                    := source.FinancialProductionSearch( relnew, Unit := allunit, Generation := allunit, MqbMlb := allunit, Power := allunit );
     
     products                  := construct( Product_MPs );
-    
+    //闇�瑕佺殑鏃ユ湡鍖洪棿锛� 鍛ㄥ拰澶╃殑鍙渶瑕佸綋鍓嶆湀
+    //periods                   := selectset( owner, Period_MP, period, not period.IsHistorical() 
+    //                                        and period.StartDate() < startofnextmonth 
+    //                                        and period.TimeUnit() <> Translations::MP_GlobalParameters_Quarter()
+    //                                        );
+    //鑾峰彇褰撳墠鏈堥渶瑕佺殑Period
+    //currentperiods            := table.GetCurrentPeriod( startofplanning, periods );
     table.GenerateColumn( owner );
-    
-    traverse( owner, Product_MP.ProductInStockingPoint_MP, pisp, pisp.Product_MP().IsLeaf() and not isnull( pisp.StockingPoint_MP() ) 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 );
-      }
-      
-      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 );
+    //鍙栧綋鍓嶇増鏈殑product planning閲宯ew supply瀛楁锛屽垎澶ц繛鍜岄暱鏄ュ伐鍘傜殑浜х嚎锛岃繘琛屽姞鎬�
+    traverse( owner, StockingPoint_MP, stockingpoint ){
+      unit         := stockingpoint.Unit();
+      parentunits  := unit.GetAllParent();
+      //鏄惁灞炰簬闀挎槬宸ュ巶
+      iscc         := unit.ID() = ccunit or exists( parentunits, Elements, punit, punit.ID() = ccunit );
+      //鏄惁灞炰簬澶ц繛宸ュ巶
+      isdl         := unit.ID() = dlunit or exists( parentunits, Elements, punit, punit.ID() = dlunit );
+      if( iscc or isdl ){
+        traverse( stockingpoint, ProductInStockingPoint_MP, pisp,  pisp.Product_MP().IsLeaf() ){
+          //鑾峰彇宸ュ巶琛�
+          factoryrow := table.GetRowByUnit( pisp.ProductID(), ifexpr( iscc, ccunit, dlunit ) );
+          //鑾峰彇鍚堣琛�
+          allrow     := table.GetRowByUnit( pisp.ProductID(), allunit );
+          products.Add( pisp.Product_MP() );
+          //褰損roduct planning鐨勬棩鏈熷尯闂村湪闇�瑕佺殑鏃ユ湡鍖洪棿鍐� 
+          traverse( pisp, ProductInStockingPointInPeriod, pispip, not pispip.Period_MP().IsHistorical() and pispip.Period_MP().StartDate() < startofnextyear
+    //                and ( ( pispip.Period_MP().StartDate().StartOfMonth() = startofplanning.StartOfMonth() and currentperiods.Find( pispip.Period_MP() ) >= 0 )
+    //                 or ( pispip.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Month() and pispip.Period_MP().StartDate() < startofnextyear ) ) 
+                    ){
+            periodtime := pispip.Start().StartOfMonth().Date();
+            periodname := periodtime.Format( "M2/D2/Y" );
+            quantity   := ceil( pispip.NewSupplyQuantity() );//鍚戜笂鍙栨暣
+            
+            column := selectobject( table, FinancialProductionColumn, column, column.Name() = periodname and column.Period() = periodtime );
+            
+            factoryrow.Initialize( column, quantity );
+            allrow.Initialize( column, quantity );
+          }    
         }
-        if( not isnull( dlrow ) ){
-          dlrow.Initialize( column, dlunit );
-        }
-        if( not exists( allrow, FinancialProductionCell, allcell, allcell.FinancialProductionColumn() = column ) ){
-          allrow.Initialize( column, allunit );
-        }
-      }
-      
-      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() );
-        }
-        if( not isnull( dlrow ) ){
-          dlrow.Initialize( column, pispip.NewSupplyProductionQuantity() );
-        }
-        allrow.Initialize( column, pispip.NewSupplyProductionQuantity() );
       }
     }
+    
     rows := selectsortedset( table, FinancialProductionRow, row, row.Name() );
     i    := 0;
     traverse( rows, Elements, e ){
diff --git a/_Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultCCUnit.qbl b/_Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultCCUnit.qbl
index 739a84b..e504a84 100644
--- a/_Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultCCUnit.qbl
+++ b/_Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultCCUnit.qbl
@@ -5,7 +5,7 @@
   TextBody:
   [*
     // 鐢勫叞楦� Jun-28-2024 (created)
-    return '闀挎槬';
+    return '闀挎槬宸ョ▼';
     //return 'Assembly Plant (France)';
   *]
 }
diff --git a/_Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultDLUnit.qbl b/_Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultDLUnit.qbl
index d544c74..781dc80 100644
--- a/_Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultDLUnit.qbl
+++ b/_Main/BL/Type_InventorySummaryReport/StaticMethod_GetDefaultDLUnit.qbl
@@ -5,7 +5,7 @@
   TextBody:
   [*
     // 鐢勫叞楦� Jun-28-2024 (created)
-    return '澶ц繛';
+    return '澶ц繛宸ュ巶';
     //return 'Assembly Plant (Spain)';
   *]
 }

--
Gitblit v1.9.3