chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
88
89
Quintiq file version 2.0
#parent: #root
StaticMethod GetProcessQuantity (
  ProductInStockingPointInPeriod pispip,
  output String tooltip
) declarative remote as Real
{
  Description: 'Return quantities of a pispip related sales demands.'
  TextBody:
  [*
    quantity := 0.0
    fulfilledQuantity := 0.0
    unfulfilledQuantity := 0.0
    totalQuantity := 0.0
    totalFulfilledQuantity := 0.0
    totalUnfulfileldQuantity := 0.0
    // Insert table tag for tooltip
    // Product
    tooltip := "<table>";
    tooltip := tooltip + '<tr><td><b>Product: </b></td><td>' 
               + pispip.ProductInStockingPoint_MP().Product_MP().Name() + '</td></tr>';
    
    // Routing name
    tooltip := tooltip + '<tr><td><b>Stocking point: </b></td><td>' 
               + pispip.ProductInStockingPoint_MP().StockingPoint_MP().Name() + '</td></tr>';
    
    // Period
    tooltip := tooltip + '<tr><td><b>Period: </b></td><td>' 
               + pispip.Start().Format( 'D-MM-Y' ) + ' until ' + pispip.End().Format( 'D-MM-Y' ) + '</td></tr>'; 
    
    // A separating line
    tooltip := tooltip + '</table><hr>';
    
    // Headers
    tooltip := tooltip + '<table><tr><td><b>Sales segment:</b></td>' 
               + '<td><b>Quantity:</b></td>'
               + '<td><b>Fulfilled:</b></td>'
               + '<td><b>Unfulfilled:</b></td>'
               + '<td><b>Price:</b></td><td></tr>';
    
    // Sort them w.r.t sales segment name for grouping
    sdips := selectsortedset( pispip, SalesDemandInPeriodBase, sdip, true, sdip.SalesSegmentName() );
    ssName := sdips.Element( 0 ).SalesSegmentName();
    
    traverse( sdips, Elements, e )
    {
      // When we see a different sales segment, create a new row for tooltip
      if( ssName <> e.SalesSegmentName() )
      {
        tooltip := tooltip + '<tr><td>' + ssName + '</td>' 
                   + '<td>' + quantity.AsQUILL() + '</td>'
                   + '<td>' + fulfilledQuantity.AsQUILL() + '</td>'
                   + '<td>' + unfulfilledQuantity.AsQUILL() + '</td>'
                   + '<td>' + e.Price().AsQUILL() + '</td>';    
        
        // Reset value
        ssName := e.SalesSegmentName();
        quantity := 0;
        unfulfilledQuantity := 0;
        fulfilledQuantity := 0;
      }
      
      quantity := quantity + e.Quantity();
      fulfilledQuantity := fulfilledQuantity + e.FulfilledQuantity();
      unfulfilledQuantity := unfulfilledQuantity + e.UnfulfilledQuantity();
      totalQuantity := totalQuantity + e.Quantity();
      totalFulfilledQuantity := totalFulfilledQuantity + e.FulfilledQuantity();
      totalUnfulfileldQuantity := totalUnfulfileldQuantity + e.UnfulfilledQuantity();
    }
    // Last row handling
    tooltip := tooltip + '<tr><td>' + ssName + '</td>' 
               + '<td>' + quantity.AsQUILL() + '</td>'
               + '<td>' + fulfilledQuantity.AsQUILL() + '</td>'
               + '<td>' + unfulfilledQuantity.AsQUILL() + '</td>'
               + '<td>' + sdips.Element( sdips.Size() - 1 ).Price().AsQUILL() + '</td>';
    
    // Sum for multi sales segment demands
    if( selectuniquevalues( sdips, Elements, e, true, e.SalesSegmentName() ).Size() > 1 )
    {
      tooltip := tooltip + '<tr><td><b>All</b></td>' 
                 + '<td>' + totalQuantity.AsQUILL() + '</td>'
                 + '<td>' + totalFulfilledQuantity.AsQUILL() + '</td>'
                 + '<td>' + totalUnfulfileldQuantity.AsQUILL() + '</td></table>'
    }
    
    // Return fulfilled quantity sum
    return totalFulfilledQuantity;
  *]
}