From bfc0b1d0712613278dc218c5a7aa2ca797a3fbe2 Mon Sep 17 00:00:00 2001
From: lazhen <17772815105@139.com>
Date: 星期四, 21 十一月 2024 17:41:31 +0800
Subject: [PATCH] Merge branch 'dev' of http://47.101.211.7:10101/r/VWED into dev-zlg

---
 _Main/BL/Type_LocalCell_Default/StaticMethod_GenerateAnnualPlanReport.qbl                                  |  189 +++++++++++++++++++++++++++++++++++++++++++++++
 _Main/Sys/Repr/Global/NewOfflinePlanCell.qrp                                                               |    8 ++
 _Main/BL/Type_NewOfflinePlanCell/StaticMethod_SynchronizeToNewSupply.qbl                                   |    4 
 _Main/UI/MacroPlannerWebApp/Component_FormAnnualPlanReport/Response_pRibbonUp_bCreateFullTable_OnClick.def |    4 
 4 files changed, 202 insertions(+), 3 deletions(-)

diff --git a/_Main/BL/Type_LocalCell_Default/StaticMethod_GenerateAnnualPlanReport.qbl b/_Main/BL/Type_LocalCell_Default/StaticMethod_GenerateAnnualPlanReport.qbl
new file mode 100644
index 0000000..16a39ea
--- /dev/null
+++ b/_Main/BL/Type_LocalCell_Default/StaticMethod_GenerateAnnualPlanReport.qbl
@@ -0,0 +1,189 @@
+Quintiq file version 2.0
+#parent: #root
+StaticMethod GenerateAnnualPlanReport (
+  const MacroPlan macroPlan,
+  const InterfaceDataset interfaceDataset,
+  RecycleBin recycleBin
+) as LocalTable
+{
+  Description: '鍏ㄥ勾璁″垝鎶ヨ〃'
+  TextBody:
+  [*
+    // Akari Nov-20-2024 (created)
+    traverse( recycleBin,LocalTable,table,table.Name() = ArchiveCell_AnnualPlanReport::GetTableName() ){
+      table.Delete();
+    }
+    localTable := recycleBin.LocalTable( relnew,Name := ArchiveCell_AnnualPlanReport::GetTableName() );
+    
+    archiveOfflinePlan := select( interfaceDataset,OfflinePlanArchiveVersion,offlinePlan,not offlinePlan.IsShow() );
+    
+    startDate := minselect( archiveOfflinePlan,Column,column,column.TimeUnit() = "Day",column.StartDate() ).StartDate();
+    endDate := macroPlan.StartOfPlanning().Date();
+    
+    localCells := construct( LocalCell_Defaults );
+    localCellIndexTree := NamedValueTree::Create();
+    
+    localRows := construct( LocalRows );
+    localRowIndexTree := NamedValueTree::Create();
+    localColumns := construct( LocalColumns );
+    localColumnIndexTree := NamedValueTree::Create();
+    for( i := startDate; i <= endDate; i := i + 1 ){
+       localColumn := localTable.LocalColumn( relnew,CustomDate := i ,TimeUnit := "Day");
+       localColumnHandle := localColumnIndexTree.GetHandle( i.AsQUILL() );
+       localColumns.Add( localColumn );
+       localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 );
+    }
+    
+    traverse( archiveOfflinePlan,Row,row ){
+      localRow := null( LocalRow );
+      {
+        localRowHandle := localRowIndexTree.GetHandle( row.ProductID() + row.ProductionLine() );
+        localRowIndex := guard( localRowIndexTree.Root().Child( localRowHandle ),null( NamedValue ));
+        if( isnull( localRowIndex )){
+          localRow := localTable.LocalRow( relnew,CustomName := row.ProductID() + " in " + row.ProductionLine(),ProductID := row.ProductID(),ProductionLine := row.ProductionLine(),Index := localTable.GetRowIndexCache() );
+          localRows.Add( localRow );
+          localRowIndexTree.Root().AddChild( localRowHandle,localRows.Size() - 1 );
+        }else{
+          localRow := localRows.Element( localRowIndex.GetValueAsNumber() );
+        }
+      }
+      
+       traverse( row,Cell,cell ){
+         localColumnHandle := localColumnIndexTree.GetHandle( cell.Column().StartDate().AsQUILL());
+         localColumnIndex := guard( localColumnIndexTree.Root().Child( localColumnHandle ),null( NamedValue ));
+         if( not isnull( localColumnIndex )){
+           localColumn := localColumns.Element( localColumnIndex.GetValueAsNumber() );
+           
+           localCellHandle := localCellIndexTree.GetHandle( localRow.ProductID() + localRow.ProductionLine() + localColumn.CustomDate().AsQUILL() + localColumn.TimeUnit() );
+           localCellIndex := guard( localCellIndexTree.Root().Child( localCellHandle ),null( NamedValue ));
+           if( isnull( localCellIndex )){
+             localCell := localRow.LocalCell( relnew,LocalCell_Default,LocalColumn := localColumn );
+             localCell.RealValue( cell.Quantity() );
+             localCells.Add( localCell );
+             localCellIndexTree.Root().AddChild( localCellHandle,localCells.Size() - 1 );
+           }else{
+             localCell := localCells.Element( localCellIndex.GetValueAsNumber() );
+             localCell.RealValue( localCell.RealValue() + cell.Quantity() );
+           }
+         }
+       }
+    }
+    
+    traverse( macroPlan,Product_MP.ProductInStockingPoint_MP,pisp_mp ){
+      pispippls := selectset( pisp_mp,ProductInStockingPointInPeriod.astype( ProductInStockingPointInPeriodPlanningLeaf ),pispippl,
+                              pispippl.Period_MP().StartDate() > endDate 
+                              and pispippl.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day());
+    
+      if( pispippls.Size() <> 0 ){
+        localRow := null( LocalRow );
+        {
+          localRowHandle := localRowIndexTree.GetHandle( pisp_mp.ProductID() + pisp_mp.StockingPoint_MP().Unit().Name() );
+          localRowIndex := guard( localRowIndexTree.Root().Child( localRowHandle ),null( NamedValue ));
+          if( isnull( localRowIndex )){
+            localRow := localTable.LocalRow( relnew,CustomName := pisp_mp.ProductID() + " in " + pisp_mp.StockingPoint_MP().Unit().Name(),ProductID := pisp_mp.ProductID(),ProductionLine := pisp_mp.StockingPoint_MP().Unit().Name(),Index := localTable.GetRowIndexCache() );
+            localRows.Add( localRow );
+            localRowIndexTree.Root().AddChild( localRowHandle,localRows.Size() - 1 );
+          }else{
+            localRow := localRows.Element( localRowIndex.GetValueAsNumber() );
+          }
+        }
+    
+        traverse( pispippls,Elements,pispippl ){
+          column := null( LocalColumn );
+          {
+            columnHandle := localColumnIndexTree.GetHandle( pispippl.Period_MP().StartDate().AsQUILL() );
+            columnIndex := guard( localColumnIndexTree.Root().Child( columnHandle ),null( NamedValue ));
+            if( not isnull( columnIndex )){
+              column := localColumns.Element( columnIndex.GetValueAsNumber() );
+            }else{
+              column := localTable.LocalColumn( relnew,CustomDate := pispippl.Period_MP().StartDate() ,TimeUnit := "Day");
+              localColumns.Add( column );
+              localColumnIndexTree.Root().AddChild( columnHandle,localColumns.Size() - 1 );
+            }
+          }
+          
+          localCellHandle := localCellIndexTree.GetHandle( localRow.ProductID() + localRow.ProductionLine() + column.CustomDate().AsQUILL() + column.TimeUnit() );
+          localCellIndex := guard( localCellIndexTree.Root().Child( localCellHandle ),null( NamedValue ));
+          if( isnull( localCellIndex )){
+            localCell := localRow.LocalCell( relnew,LocalCell_Default,LocalColumn := column );
+            localCell.RealValue( pispippl.NewSupplyQuantity() );
+            localCells.Add( localCell );
+            localCellIndexTree.Root().AddChild( localCellHandle,localCells.Size() - 1 );
+          }else{
+            localCell := localCells.Element( localCellIndex.GetValueAsNumber() );
+            localCell.RealValue( localCell.RealValue() + pispippl.NewSupplyQuantity() );
+          }
+        }
+      }
+    }
+    
+    endDate := maxselect( localColumns,Elements,column,column.CustomDate() ).CustomDate();
+    for( i := startDate.StartOfWeek(); i <= endDate.StartOfNextWeek(); i := i.StartOfNextWeek() ){
+       localColumn := localTable.LocalColumn( relnew,CustomDate := i ,TimeUnit := "Week");
+       localColumnHandle := localColumnIndexTree.GetHandle( i.AsQUILL() + "Week" );
+       localColumns.Add( localColumn );
+       localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 );
+    }
+    for( i := startDate.StartOfMonth(); i <= endDate.StartOfNextMonth(); i := i.StartOfNextMonth() ){
+       localColumn := localTable.LocalColumn( relnew,CustomDate := i ,TimeUnit := "Month");
+       localColumnHandle := localColumnIndexTree.GetHandle( i.AsQUILL() + "Month" );
+       localColumns.Add( localColumn );
+       localColumnIndexTree.Root().AddChild( localColumnHandle,localColumns.Size() - 1 );
+    }
+    
+    traverse( localTable,LocalRow,row ){
+      traverse( localTable,LocalColumn,column,column.TimeUnit() = "Week" ){
+        value := sum( row,LocalCell.astype( LocalCell_Default ),cell,
+                      cell.LocalColumn().TimeUnit() = "Day" and 
+                      cell.LocalColumn().CustomDate() >= column.CustomDate() and 
+                      cell.LocalColumn().CustomDate() < column.CustomDate().StartOfNextWeek(),cell.RealValue());
+        localCell := row.LocalCell( relnew,LocalCell_Default,LocalColumn := column,RealValue := value );
+        
+        localCellHandle := localCellIndexTree.GetHandle( row.ProductID() + row.ProductionLine() + column.CustomDate().AsQUILL() + column.TimeUnit() );
+        localCells.Add( localCell );
+        localCellIndexTree.Root().AddChild( localCellHandle,localCells.Size() - 1 );
+      }
+      traverse( localTable,LocalColumn,column,column.TimeUnit() = "Month" ){
+        value := sum( row,LocalCell.astype( LocalCell_Default ),cell,
+                      cell.LocalColumn().TimeUnit() = "Day" and 
+                      cell.LocalColumn().CustomDate() >= column.CustomDate() and 
+                      cell.LocalColumn().CustomDate() < column.CustomDate().StartOfNextMonth(),cell.RealValue());
+        localCell := row.LocalCell( relnew,LocalCell_Default,LocalColumn := column,RealValue := value );
+        
+        localCellHandle := localCellIndexTree.GetHandle( row.ProductID() + row.ProductionLine() + column.CustomDate().AsQUILL() + column.TimeUnit() );
+        localCells.Add( localCell );
+        localCellIndexTree.Root().AddChild( localCellHandle,localCells.Size() - 1 );
+      }
+    }
+    
+    traverse( localTable,LocalColumn,column,column.LocalCell( relsize ) = 0 ){
+      column.Delete();
+    }
+    
+    traverse( localTable,LocalRow,row,row.LocalCell( relsize ) = 0 ){
+      row.Delete();
+    }
+    
+    traverse( localTable,LocalRow,row ){
+      cells := selectset( row,LocalCell,cell,true );
+      cellIndexTree := NamedValueTree::Create();
+      for( i := 0;i < cells.Size(); i++){
+        cell := cells.Element( i );
+        cellHandle := cellIndexTree.GetHandle( row.CustomName() + cell.LocalColumn().CustomDate().AsQUILL() + cell.LocalColumn().TimeUnit() );
+        cellIndexTree.Root().AddChild( cellHandle,i );
+      }
+      traverse( localTable,LocalColumn,column ){
+        cellHandle := cellIndexTree.GetHandle( row.CustomName() + column.CustomDate().AsQUILL() + column.TimeUnit() );
+        cellIndex := guard( cellIndexTree.Root().Child( cellHandle ),null( NamedValue ));
+        if( isnull( cellIndex )){
+          cell := row.LocalCell( relnew,LocalCell_Default,LocalColumn := column,RealValue := 0 );
+          cells.Add( cell );
+          cellIndexTree.Root().AddChild( cellHandle,cells.Size() - 1 );
+        }
+      } 
+    }
+    
+    
+    return localTable;
+  *]
+}
diff --git a/_Main/BL/Type_NewOfflinePlanCell/StaticMethod_SynchronizeToNewSupply.qbl b/_Main/BL/Type_NewOfflinePlanCell/StaticMethod_SynchronizeToNewSupply.qbl
index d00ed54..befdd60 100644
--- a/_Main/BL/Type_NewOfflinePlanCell/StaticMethod_SynchronizeToNewSupply.qbl
+++ b/_Main/BL/Type_NewOfflinePlanCell/StaticMethod_SynchronizeToNewSupply.qbl
@@ -21,11 +21,11 @@
         o  := select( macroPlan, Unit.Operation, tempO, tempO.ID() = cell.NewOfflinePlanRow().OperationID() );
         up := select( macroPlan, Unit.UnitPeriod, tempUP, tempUP.UnitID() = cell.NewOfflinePlanRow().ProductionLine() and tempUP.StartDate() = cell.NewOfflinePlanColumn().StartDate() );
         if ( not isnull( o ) and not isnull( up ) ) {
-          PeriodTaskOperation::Create( o, up, cell.Quantity(), false );
+          PeriodTaskOperation::Create( o, up, cell.Quantity(), true );
         }
       } else if ( not isnull( pto ) ) {
         if ( [Number]cell.Quantity() <> [Number]pto.Quantity() ) {
-          pto.Update( cell.Quantity(), false );
+          pto.Update( cell.Quantity(), true );
         }
       }
       
diff --git a/_Main/Sys/Repr/Global/NewOfflinePlanCell.qrp b/_Main/Sys/Repr/Global/NewOfflinePlanCell.qrp
index 35f26fa..5dda34e 100644
--- a/_Main/Sys/Repr/Global/NewOfflinePlanCell.qrp
+++ b/_Main/Sys/Repr/Global/NewOfflinePlanCell.qrp
@@ -20,6 +20,14 @@
         DefaultBackgroundColor: false
         InheritConversion: false
       }
+      DataRepresentation.Conditional
+      {
+        BackgroundColor: 'Red'
+        ConditionBody: 'object.Quantity() < 0.0'
+        ConversionBody: ''
+        DefaultBackgroundColor: false
+        InheritConversion: false
+      }
     ]
   }
   AttributeRepresentation ShiftPatternEnd
diff --git a/_Main/UI/MacroPlannerWebApp/Component_FormAnnualPlanReport/Response_pRibbonUp_bCreateFullTable_OnClick.def b/_Main/UI/MacroPlannerWebApp/Component_FormAnnualPlanReport/Response_pRibbonUp_bCreateFullTable_OnClick.def
index e5bc6b4..74f1c03 100644
--- a/_Main/UI/MacroPlannerWebApp/Component_FormAnnualPlanReport/Response_pRibbonUp_bCreateFullTable_OnClick.def
+++ b/_Main/UI/MacroPlannerWebApp/Component_FormAnnualPlanReport/Response_pRibbonUp_bCreateFullTable_OnClick.def
@@ -9,7 +9,9 @@
   {
     Body:
     [*
-      table := ArchiveCell_AnnualPlanReport::CreateFullTable( Archive,RecycleBin,MacroPlan ); 
+      //table := ArchiveCell_AnnualPlanReport::CreateFullTable( Archive,RecycleBin,MacroPlan ); 
+      
+      table := LocalCell_Default::GenerateAnnualPlanReport( MacroPlan,InterfaceDataset, RecycleBin ); 
       dhAnnualPlanTable.Data( table );
       WebMessageBox::Success( "Success" );
       

--
Gitblit v1.9.3