hongji.li
2023-10-17 6a58456625b8ff9b895f87f3d5a5965ab574f87a
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Quintiq file version 2.0
#parent: #root
StaticMethod FromSupplyPlanning (
  const GlobalOTDTable otdTable,
  const GlobalOTDSOP otdSop,
  MacroPlan macroPlan,
  ProductInStockingPointInPeriod pispip,
  String userId
) as PRData
{
  TextBody:
  [*
    // yypsybs Sep-12-2023 (created)
    result := macroPlan.PRData( relnew );
    
    pisp := pispip.ProductInStockingPoint_MP();
    product := pisp.Product_MP();
    stockingPoint := pisp.StockingPoint_MP();
    period := pispip.Period_MP();
    // QID7
    mappingProduct := Global_MappingProduct_MP::GetByProductId( otdTable, product.ID() );
    // QID12
    mappingOperation := Global_MappingOperation::GetByProductId( otdTable, product.ID() );
    // QID15
    mappingProviderCapacity := Global_MappingProviderCapacity::GetByProductId( otdTable, product.ID() );
    
    // 物料标签属性
    matAttrSetting := MatAttrSettingAndPlanStrategy::GetByMatCode( otdSop, product.ID() )
    
    // 根据pispip
    result.MRPCalverNo( ifexpr( pispip.MRPCalverNo() = "", "暂无", pispip.MRPCalverNo() ) );
    result.Quantity( pispip.NewSupplyQuantity() );
    
    // 根据product
    result.ProductID( product.ID() );
    result.ProductName( product.Name() );
    
    // 根据stockingPoint
    result.StockingPointID( stockingPoint.ID() );
    
    // 根据period
    result.DeliveryDate( period.StartDate() );
    result.PRSuggestionDate( ifexpr( (result.DeliveryDate() - Duration::Days( 7 )).Date() >= Date::Today(),
                                     Date::Today(), (result.DeliveryDate() - Duration::Days( 7 )).Date() ) );
    
    // 根据 物料属性标签设定&物料计划策略
    result.IsPanelMaterial( "暂无" );
    if( isnull( matAttrSetting ) ) {
      result.IsGenericMaterial( "暂无" );
      result.IsLongLeadItem( "暂无" );
      result.MaterialMRPType( "暂无" );
    } else {
      result.IsGenericMaterial( matAttrSetting.FlagGeneric() );
      result.IsLongLeadItem( matAttrSetting.FlagLongTerm() );
      result.MaterialMRPType( ifexpr( matAttrSetting.PlanningStrategyCustom() <> "", matAttrSetting.PlanningStrategyCustom(), matAttrSetting.PlanningStrategyAuto() ) );
    }
    
    // 根据product中间表
    if( isnull( mappingProduct ) ) {
      result.BusinessType( "暂无" );  
    } else {
      result.BusinessType( mappingProduct.BusinessType() );   
    }
    result.InterfaceSourceCode( "Quintiq_" + result.BusinessType() );
    
    // 根据operation中间表
    if( isnull( mappingOperation ) ) {
      result.OrgId( "暂无" );
      result.OrganCode( "暂无" );
      result.OrganName( "暂无" );
      result.DestinationOrganizationID( "暂无" );
    } else {
      result.OrgId( mappingOperation.OrganId() );
      result.OrganCode( mappingOperation.OrganCode() );
      result.OrganName( mappingOperation.OrganName() );
      result.DestinationOrganizationID( mappingOperation.DestinationOrganizationId() );
    }
    
    // 根据供应商能力中间表
    if( isnull( mappingProviderCapacity ) ) {
      result.ProviderCode( "暂无" );
      result.ProviderName( "暂无" );
      result.LeadTime( 0.0 );
      result.UnitOfMeasure( "暂无" );
    } else {
      result.ProviderCode( "暂无" );
      result.ProviderName( mappingProviderCapacity.ProviderName() );
      result.LeadTime( mappingProviderCapacity.LeadTime() );
      result.UnitOfMeasure( mappingProviderCapacity.UnitOfMeasureName() );
    }
    
    // 根据erp接口 固定值
    result.RequisitionType( "PURCHASE" );
    result.DestinationTypeCode( "INVENTORY" );
    result.UnitPrice( 1.0 );
    result.AuthorizationStatus( "INCOMPLETE" );
    result.LineTypeId( "1" );
    result.LineType( "货物" );
    // 根据erp接口 todo
    result.LineAttribute1( "" );
    result.LineAttribute3( "" );
    result.LineAttribute6( "" );
    
    // 用户id/name
    result.PreparerId( userId );
    result.HeaderDescription( userId );
    result.DeliverToRequestorId( result.PreparerId() );
    
    // 生成id
    cnv := DateTimeToString::StandardConverter();
    cnv.SetCustomConversion();
    cnv.CustomFormatString( "yyyyMMdd_H:mm:ss" );
    result.DataID( cnv.Convert( DateTime::ActualTime() ) + "_" + [String]Number::Random( Number::MinNumber(), Number::MaxNumber() ) );
    
    // 发送信息
    result.PRReleaseStatus( "" );
    result.CreateBy( "" );
    result.CreateTime( DateTime::MinDateTime() );
    
    return result;
  *]
}