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 ); 
 | 
    } 
 | 
  *] 
 | 
} 
 |