yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Quintiq file version 2.0
#parent: #root
Method SynchronizeDisaggregatedSalesDemandInPeriod (
  Boolean isdeleteinvalid
)
{
  Description: 'Create or delete disaggregatedSDiP based on fulfillment restriction.'
  TextBody:
  [*
    // Create leaf pisps
    leafpisps := construct( ProductInStockingPoint_MPs );
    pisp := guard( this.AsSalesDemandInPeriodBase().ProductInStockingPoint_MP(), null( ProductInStockingPoint_MP ) );
    
    if( not isnull( pisp ) )
    {
      traverse( pisp.Product_MP().GetLeaves(), Elements, leafproduct )
      {                                         
        sp := pisp.StockingPoint_MP();
        if( isnull( leafproduct.FindProductInStockingPoint( sp.ID() ) ) ) //pisp not found
        {
          leafpisp := leafproduct.AddToStockingPoint( sp );
          leafpisps.Add( leafpisp );    
        }
      }
    } 
    
    // Propagate all PISPIP to SPIP relations
    Transaction::Transaction().Propagate( relation( ProductInStockingPointInPeriod, StockingPointInPeriod ) );
    
    allchild := this.AsSalesDemandInPeriodBase().GetLeafPISPIPs();
    
    updateddsdip := construct( DisaggregatedSalesDemandInPeriods ); 
    traverse( allchild, Elements.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispip, this.SalesDemand().GetIsProductAllowed( pispip ) )
    {
      dsdip := select( this, DisaggregatedSalesDemandInPeriod, dsdip, dsdip.AsPlanningBaseSalesDemandInPeriod() = pispip );
      if( isnull( dsdip ) )
      {
        dsdip := DisaggregatedSalesDemandInPeriod::Create( this, pispip, 0.0, false );
      }                                                                   
      
      updateddsdip.Add( dsdip );
    }
    
    if( isdeleteinvalid )
    {
      trash := selectset( this, DisaggregatedSalesDemandInPeriod, d, true );
      trash := trash.Difference( updateddsdip );
      
      DisaggregatedSalesDemandInPeriod::Delete( trash );
    }
  *]
}