haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
90
91
92
93
94
95
96
Quintiq file version 2.0
#parent: #root
StaticMethod CreateOrUpdate (
  MacroPlan macroPlan,
  String currencyId,
  String customerName,
  String customerId,
  String id,
  Date orderDate,
  String orderId,
  String orderLineId,
  Real price,
  String priorityName,
  String productId,
  String stockingPointId,
  String salesSegmentName,
  Real quantity,
  String unitOfMeasureName,
  String orderType,
  Boolean isAvailable
) as CustomerOrder
{
  TextBody:
  [*
    // yypsybs Aug-14-2023 (created)
    // 查依赖项
    product := Product_MP::FindById( macroPlan, productId );
    salesSegment := SalesSegment_MP::FindByName( macroPlan, salesSegmentName );
    stockingPoint := StockingPoint_MP::FindById(  macroPlan, stockingPointId );
    //currency := Currency_MP::FindById( macroPlan, currencyId );
    unitOfMeasure := null( UnitOfMeasure_MP )
    priority := null( Priority );
    if( unitOfMeasureName <> "" ) {
        unitOfMeasure := UnitOfMeasure_MP::FindByName( macroPlan, unitOfMeasureName );  
    }
    if( priorityName <> "" ) {
        priority := Priority::FindByName( macroPlan, priorityName );
    }
    // 检查依赖项
    if( isnull( product) ) {
        info( "product not found" + productId);  
    }
    if( isnull( salesSegment) ) {
        info( "sales segment not found" + salesSegmentName);  
    }
    if( isnull( stockingPoint) ) {
        info( "stock point not found" + stockingPointId);  
    }
    //if( isnull( currency) ) {
    //    error( "currency not found" );  
    //}
    if( unitOfMeasureName <> "" and isnull( unitOfMeasure) ) {
        info( "unit of measure not found" + unitOfMeasureName);  
    }
    //if( priorityName <> "" and isnull( stockingPoint) ) {
    //    info( "priority not found" );  
    //}
    // 新增/更新
    result := CustomerOrder::FindById( macroPlan, id );
    if( isnull( result ) ) {
        result := CustomerOrder::Create( product, stockingPoint, id, orderDate, quantity, price, 
                               priorityName, salesSegmentName, currencyId, unitOfMeasureName, 
                               false, customerName, customerId, orderId, orderLineId, true, true, true );
    } else {
        if( result.ProductID() = productId 
            and result.StockingPointID() = stockingPointId 
            and result.StartDate() = orderDate 
            and result.Quantity() = quantity 
            and result.Price() = price 
            and result.PriorityName() = priorityName 
            and result.SalesSegmentName() = salesSegmentName 
            and result.CurrencyID() = currencyId 
            and result.UnitOfMeasureName() = unitOfMeasureName 
            and result.CustomerName() = customerName 
            and result.CustomerID() = customerId 
            and result.OrderID() = orderId 
            and result.OrderLineID() = orderLineId ){
              info( "No need to update this order: " + id );
              }else{
                if( result.IsLocked() = true ){
                  pispips := selectset( result, ProductInStockingPoint_MP.ProductInStockingPointInPeriod, pispip, true );
                  pispipLeafs := selectset( pispips, 
                                            Elements.astype( ProductInStockingPointInPeriodPlanningLeaf ), 
                                            pispip, 
                                            true );
                  ProductInStockingPointInPeriod::LockUnlockPlanning( pispipLeafs, false, true );
                }
                result.Update( product, stockingPoint, orderDate, quantity, price, 
                               priorityName, salesSegmentName, currencyId, unitOfMeasureName, 
                               false, customerName, customerId, orderId, orderLineId, true, true, true );
                result.IsLocked( false );
                }
    }
    return result;
  *]
}