Kevin Kok Khah Whey
2023-11-07 5ae534ab606e6f2ba5ea60914224d665b0447d5a
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
Quintiq file version 2.0
#parent: #root
Method DoASyncMappingCustomerOrderData (
  Strings businessTypes,
  const GlobalOTDTable globalOTDTable,
  Strings organcodelist
)
{
  Description: 'ETL订单预测'
  TextBody:
  [*
    // yypsybs Aug-15-2023 (created)
    // 待处理数据
    listToDeal := construct( Global_MappingCustomOrders, constcontent );
    if( isnull( businessTypes ) or businessTypes.Size() = 0 ) {
        listToDeal := selectset( globalOTDTable, Global_MappingCustomOrder, item, true );
    } else {
        listToDeal := selectset( globalOTDTable, 
                                 Global_MappingCustomOrder, 
                                 item, 
                                 ( businessTypes.Find( item.BusinessType() ) <> -1 ) and 
                                 ( organcodelist.Find( item.StockingPointID().SubString( 0, 3 ) ) >= 0 ) );
    }
    queryStartDate := guard( min( this, Period_MP, item, true, item.StartDate() ) - Duration::Days( 30 ), DateTime::MinDateTime() ).Date();
    //queryEndDate := guard( max( this, Period_MP, item, true, item.EndDate() ), Date::MaxDate() );
    listToDeal := selectset( listToDeal, Elements, item, item.OrderDate() >= queryStartDate /*and item.OrderDate() <= queryEndDate*/, not isnull( Product_MP::FindById( this, item.ProductID() ) ) and not isnull( StockingPoint_MP::FindById( this, item.StockingPointID() ) ) and not isnull( SalesSegment_MP::FindByName( this, item.SalesSegmentName() ) ) );
    
    totalcount := listToDeal.Size();
    info( "CustomerOrder has " + totalcount.AsQUILL() + " rows in total" );
    
    count := 0;
    priorityName :="Normal";
    // 处理
    traverse( listToDeal, Elements, item ) {
      count := count + 1;
      if( count - [Number](count/100) * 100 = 0 or count = totalcount ){
        info( "Now is dealing with the " + count.AsQUILL() + "CustomerOrder " + "( " + count.AsQUILL() + "/" + totalcount.AsQUILL() + " ) " + (count/totalcount*100).Round( 1 ).AsQUILL() + "%" );
        }
    //  if( not isnull( Product_MP::FindById( this, item.ProductID() ) ) ){
    //    info( item.ProductID().AsQUILL() );
      customOrder := CustomerOrder::CreateOrUpdate( this, item.CurrencyID(), item.Customer(), item.CustomerID(), item.ID(), 
                                                    item.OrderDate(), item.OrderID(), item.OrderLineID(), item.Price(), 
                                                    priorityName, item.ProductID(), 
                                                    item.StockingPointID(), 
                                                    item.SalesSegmentName(), 
                                                    item.Quantity(), item.UnitOfMeasureName(), item.OrderType(), item.IsAvailable());
      customOrder.BusinessType( item.BusinessType() );
      customOrder.OrderType( item.OrderType() );
      customOrder.OrderTime( item.OrderTime() );
      customOrder.ProductGrade( item.ProductGrade() );
      customOrder.SegmentPriority( item.SegmentPriority() );
      customOrder.SheetProfitability( item.SheetProfitability() );
    //  }else{
    //    info( "invaild product: " + item.ProductID().AsQUILL() );
    //    }
    }
  *]
}