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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Quintiq file version 2.0
#parent: #root
Method Update (
  Product_MP owner,
  StockingPoint_MP stockingpoint,
  Date startdate,
  Date enddate,
  Real quantity,
  Real price,
  String priorityname,
  Real demanduncertaintypercentage,
  String salessegmentname,
  String currencyname,
  String unitofmeasurename,
  Boolean isexcludedfromfulfillmentkpi,
  Boolean isfromdb
)
{
  Description: 'Update sales demand'
  TextBody:
  [*
    //Don't change these if the owner being passed in is null
    if( not isnull( owner ) )
    {
      this.ProductID( owner.ID() );
      this.StockingPointID( guard( stockingpoint.ID(), '' ) );
    
        //There may be cases when sales demand is not linked to a PISP
      oldpisp := this.ProductInStockingPoint_MP();
      needsync := isnull( oldpisp )
                  or oldpisp.Product_MP() <> owner
                  or oldpisp.StockingPoint_MP() <> stockingpoint;
    
      if( needsync )
      {
        owner.SalesDemand( relmove, this );
    
        // Get new pisp and remove old pisp
        owner.AddToStockingPoint( stockingpoint );
    
        //This is needed to get the pispip when synchronizing sdip
        Transaction::Transaction().Propagate( relation( ProductInStockingPoint_MP, SalesDemand ) );
      }
    }
    
    // If quantity had been updated, reset the optimizer fulfillment of SDIP
    resetoptimizerfulfillment := this.SalesDemandInPeriod( relsize ) > 0
                                 and sum( this, SalesDemandInPeriod, sdip, sdip.Quantity() ) <> quantity;
    
    this.StartDate( startdate );
    
    if ( enddate.IsInfinite() )
    {
      // Customer order don't had an end date, need to set it to start date
      enddate := startdate;
    }
    
    this.EndDate( enddate );
    this.Quantity( quantity );
    this.ExpectedQuantity( quantity );
    this.Price( price );
    this.PriorityName( ifexpr( not isexcludedfromfulfillmentkpi, priorityname, '' ) );
    this.DemandUncertaintyPercentage( demanduncertaintypercentage );
    this.SalesSegmentName( salessegmentname );
    this.CurrencyID( currencyname );
    this.UnitOfMeasureName( unitofmeasurename );
    this.IsExcludedFromFulfillmentKPIUser( isexcludedfromfulfillmentkpi );
    this.IsManuallyConfigured( not isfromdb );
    
    // Sychronize sales demand in period
    if( not isfromdb )
    {
      this.SynchronizeSalesDemandInPeriod( resetoptimizerfulfillment );
    }
    
    // Create decision log
    description := Translations::MP_SalesDemand_Commit_Description( this );
    this.Product_MP().MacroPlan().CreateDecisionLog( description, true );
  *]
  InterfaceProperties { Accessibility: 'Extensible' }
}