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
Quintiq file version 2.0
#parent: #root
StaticMethod CreateOrUpdateForPISPIP (
  ProductInStockingPointInPeriodPlanning pispip,
  Real penalty
)
{
  Description: "Create or update the postponed SD cost when we want only the particular product in stocking point in period's cost (get from postponed SD cost) change."
  TextBody:
  [*
    // Wayne June-6-2013 (created)
    
    psdcost := pispip.PostponedSalesDemandCost();
    pisp := pispip.ProductInStockingPoint_MP();
    
    /* Case1: all pispip are referring to Jan, penalty 100.
    PISPIP     psd penalty
      Jan      Jan, 100
      Feb
      Mar
      Apr
    
    Case2: when user edit postponed sd penalty via context menu in pispip list on Mar (penalty = 200), (a) and (b) are created.
    PISPIP     psd penalty
      Jan      Jan, 100
      Feb      Mar, 200 (a)
      Mar      Apr, 100 (b)
      Apr
    
    
    Case3: when user edit postponed sd penalty for Mar via context menu in pispip list again (now set penalty = 300), (a) is updated.
    PISPIP     psd penalty
      Jan      Jan, 100
      Feb      Mar, 300 (a)
      Mar      Apr, 100 (b)
      Apr
    */
    nextpispip := pispip.NextPlanningPISPIP();
    nextpsdcost := guard( nextpispip.PostponedSalesDemandCost(), null( PostponedSalesDemandCost ) );
    
    if( not isnull( nextpispip )
        and nextpsdcost = psdcost )
    {
      // Case2: creating (b)
      PostponedSalesDemandCost::Create( pisp.Product_MP(),
                                        pisp.StockingPoint_MP(),
                                        nextpispip.Start().Date(),
                                        guard( psdcost.Penalty(), 0.0 ),
                                        false );
    
      // Propogate the relation to pispips.
      // This is needed for the following checking.
      Transaction::Transaction().Propagate();
    }
    
    // Create a new postponed sd cost for that particular pispip if it does not bind to any postponed sd cost, or if it already has an postponed sd cost,
    // the related postponed sd cost doesn't have the same start as the pispip.
    if( not pispip.GetHasPostponedSalesDemandCost()
        or PostponedSalesDemandCost::IsPrimaryKeysUnique( pisp.Product_MP(), pisp.StockingPoint_MP(), pispip.Start().Date(), null( PostponedSalesDemandCost ) ) )
    {
      // Case2: creating (a)
      PostponedSalesDemandCost::Create( pisp.Product_MP(),
                                        pisp.StockingPoint_MP(),
                                        pispip.Start().Date(),
                                        penalty,
                                        false );
    }
    
    else
    {
      // Case3, (a) is updated.
      // The to-be created postponed sd cost has the same primary keys with existing data. Therefore, we update it instead of creating a new data to avoid duplication.
      psdcost.Update( pisp.Product_MP(),
                      pisp.StockingPoint_MP(),
                      psdcost.Start(),
                      penalty,
                      false );
    }
  *]
}