yanyuan
2023-10-27 610f71ce06abbfc1a3f082e7639fed476717a56e
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
Quintiq file version 2.0
#parent: #root
Method DoASyncMappingOperationCostData (
  const GlobalOTDTable globalOTDTable,
  Strings businesstypes,
  Strings organcodelist
)
{
  Description: 'Get operation cost data from operation mapping'
  TextBody:
  [*
    // Administrator Aug-21-2023 (created)
    // list to deal
    listtodeal := construct( structured[Global_MappingOperation], constcontent );
    
    if( isnull( businesstypes ) or businesstypes.Size() = 0 ) {
        listtodeal := selectset( globalOTDTable, Global_MappingOperation, item, true );
    } else {
        listtodeal := selectset( globalOTDTable, Global_MappingOperation, 
                                 item, 
                                 ( businesstypes.Find( item.BusinessType() ) <> -1 ) and 
                                 ( organcodelist.Find( item.OrganCode() ) >= 0 ) );
    }
    
    // Get the list to deal with max sequence number
    listtodealwithmaxsn := construct( structured[Global_MappingOperation], constcontent );
    traverse( listtodeal, Elements, item ){
      maxsn := maxselect( globalOTDTable, Global_MappingOperation, 
                          moperation, 
                          moperation.OrganCode() = item.OrganCode(), 
                          moperation.ProductID() = item.ProductID(), 
                          moperation.SequenceNumber() ).SequenceNumber()
      if( item.SequenceNumber() = maxsn ){
          listtodealwithmaxsn.Add( item );
        }
      }
    
    totalcount := listtodealwithmaxsn.Size();
    info( "OperationCost has " + totalcount.AsQUILL() + " rows in total" );
    
    count := 0;
    // Get the operation cost data
    traverse( listtodealwithmaxsn, Elements, item ){
      count := count + 1;
      if( count - [Number](count/1000) * 1000 = 0 or count = totalcount ){
        info( "Now is dealing with the " + count.AsQUILL() + "OperationCost " + "( " + count.AsQUILL() + "/" + totalcount.AsQUILL() + " ) " + (count/totalcount*100).Round( 1 ).AsQUILL() + "%" );
        }
      id := item.OrganCode() + "_" + item.ProductID() + "_" + item.ProcessSection()+"_" + [String]item.SequenceNumber();
      if( guard( item.Line(), "" ).Length() > 0 ) {
          id := id + "_" + item.Line();
        }
      operation := Operation::FindOperationTypeIndex( id );
      if(not isnull(operation)){
            account := Account_MP::FindByName( this, "Operating cost" );
            isfromdb := false;
            existoperationcost := OperationCost::FindOperationCostTypeIndex( id );
            if( isnull( existoperationcost ) ){
              connecteditem := select( globalOTDTable,
                                       Global_MappingOperationCost,
                                       moperationcost,
                                       moperationcost.OrgCode() = item.OrganCode(),
                                       moperationcost.ProductID() = item.ProductID() );
              if( not isnull( connecteditem)){
                  cost := connecteditem.Cost();
                  lengthoftime := connecteditem.LengthOfTime();
                  start := connecteditem.Start();
                  timeunit := connecteditem.TimeUnit();
                  OperationCost::Create( id, operation, account, "Volume", start, timeunit, lengthoftime, cost, isfromdb );
                }
    
              }
      }
    }
  *]
}