yypsybs
2023-09-09 3cb5a54def670d97301f07170fcaad213bfc54f2
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
82
83
84
85
86
87
Quintiq file version 2.0
#parent: #root
Function CalcShelfLifeSupplyAgeAndQuantityVectorAsBinaryValue
{
  TextBody:
  [*
    // Construct the leading vectors
    quantityvector := RealVector::Construct();
    agevector := RealVector::Construct();
    prev_quantityvectorend := RealVector::Construct( );
    prev_agevectorend := RealVector::Construct();
    pispippl := this.ProductInStockingPointInPeriodPlanningLeaf();
    prev_inventorylevelend :=0.0;
            
    // Check if the product has shelf life or maturation
    if( pispippl.ProductInStockingPoint_MP().Product_MP().HasShelfLifeOrMaturation() )
    {
        prev_pispippl := guard( pispippl.PreviousPlanningPISPIP().astype( ProductInStockingPointInPeriodPlanningLeaf ), null( ProductInStockingPointInPeriodPlanningLeaf ) );
        prev_pispippl_shelflife := guard( prev_pispippl.ShelfLife(), null( ShelfLife ) );
        
        
        if ( not isnull( prev_pispippl_shelflife ) )
        {
         // Get shelf life end vectors from previous planning PISPIP
          prev_quantityvectorend := RealVector::Construct( prev_pispippl_shelflife.ShelfLifeEndQuantityVectorAsBinaryValue() );
          prev_agevectorend := RealVector::Construct( prev_pispippl_shelflife.ShelfLifeEndAgeVectorAsBinaryValue() );
              
          // Append the vectors into the leading vector
          quantityvector.Append( prev_quantityvectorend );
          agevector.Append( prev_agevectorend );
          prev_inventorylevelend := prev_quantityvectorend.Sum();
       
        }
    
        // if has total avaialable supply user
        if ( this.ProductInStockingPointInPeriodPlanningLeaf().HasTotalAvailableSupplyUser() )
        {
        
          agefromcurrentpisp := ShelfLife::GetShelfLifeDaysToAdd( pispippl.Period_MP(), pispippl.Period_MP() )
          balancewithoutsupply := pispippl.TotalAvailableSupplyUser() - pispippl.InventorySupplyAndNewSupplyQuantity();
          // totalavailablesupplyuser - inventorysupplyandnewsupplyquantity - previous inventory level end
          balancediffwithprevious := pispippl.TotalAvailableSupplyUser() - pispippl.InventorySupplyAndNewSupplyQuantity() - prev_inventorylevelend;
          if ( balancediffwithprevious > 0 )
          {
           quantityvector.Append( balancediffwithprevious );
           agevector.Append( agefromcurrentpisp );
          } 
          else if ( this.ProductInStockingPointInPeriodPlanningLeaf().TotalAvailableSupplyUser() < prev_inventorylevelend ) 
          {
            quantityvector.Remove( 0 );// when less than previous inventory end, removed previous, only append current totalavaialableuser
            agevector.Remove( 0 );// when less than previous, removed previous
            if( balancewithoutsupply > 0 )
            {
              quantityvector.Append( balancewithoutsupply );
              agevector.Append( agefromcurrentpisp );
            }    
          }
        }
       
        // Traverse all new supplies and get their shelf life supply vectors
        traverse( pispippl, NewSupply, newsupply )
        {
          ns_quantityvector := RealVector::Construct( newsupply.ShelfLifeQuantityVectorAsBinaryValue() );
          ns_agevector := RealVector::Construct( newsupply.ShelfLifeAgeVectorAsBinaryValue() );
          
          quantityvector.Append( ns_quantityvector );
          agevector.Append( ns_agevector );
        }
        
        // Traverse all inventory supplies and get their quantity and age
        traverse( pispippl, InventorySupply, invsupply, invsupply.Quantity() > 0 )
        {
          quantityvector.Append( invsupply.Quantity() );
          agevector.Append( invsupply.Age() );
        }
      
        // Merge expired (expired in previous period, still need the info of expired stock in current period for constraint and sanity check)
        // shelf life supplies into a single element in the vector to reduce the size of the vector
        ShelfLife::MergeVectorAccordingToAgeAndExpiration( quantityvector, agevector,
                                                           pispippl,
                                                           pispippl.Start() );
    }
    
    this.ShelfLifeSupplyQuantityVectorAsBinaryValue( quantityvector.AsBinaryValue() );
    this.ShelfLifeSupplyAgeVectorAsBinaryValue( agevector.AsBinaryValue() );
  *]
}