Quintiq file version 2.0
|
#parent: #root
|
Method MappingOperationBOMData (
|
Strings businessTypes,
|
Boolean isKeyProduct,
|
Boolean createPurchaseSupplyMaterial
|
)
|
{
|
TextBody:
|
[*
|
// keyProduct
|
keyProductIds := selectuniquevalues( this, MappingProduct, prod, prod.KeyProduct() = true, prod.ID() );
|
// 获取有序的待处理记录
|
toDealOps := construct( MappingOperations );
|
toDealBoms := construct( MappingBOMs );
|
if( not isnull( businessTypes ) and businessTypes.Size() > 0 ) {
|
toDealOps := selectsortedset( this, MappingOperation, item,
|
businessTypes.Find( item.BusinessType() ) >= 0
|
and ( not isKeyProduct or keyProductIds.Find( item.ProductID() ) >= 0 ),
|
item.SequenceNumber() );
|
toDealBoms := selectset( this, MappingBOM, item,
|
businessTypes.Find( item.BusinessType() ) >= 0
|
and ( not isKeyProduct or keyProductIds.Find( item.ComponentCode() ) >= 0 ) );
|
} else {
|
toDealOps := selectsortedset( this, MappingOperation, item,
|
not isKeyProduct or keyProductIds.Find( item.ProductID() ) >= 0 ,
|
item.SequenceNumber() );
|
toDealBoms := selectset( this, MappingBOM, item,
|
businessTypes.Find( item.BusinessType() ) >= 0
|
and ( not isKeyProduct or keyProductIds.Find( item.ComponentCode() ) >= 0 ) );
|
}
|
// 对每个routing计算inputGroupId
|
inputGroupId := 1
|
// 对每个Routing进行投入产出处理
|
routingKeys := selectuniquevalues( toDealOps, Elements, item, item.OrganCode() + "_" + item.ProductID() );
|
traverse( routingKeys, Elements, routingKey ) {
|
// ==== 产出 ====
|
// 找最大seq
|
maxSeq := max( toDealOps, Elements, item, item.OrganCode() + "_" + item.ProductID() = routingKey, item.SequenceNumber() );
|
maxSeqElements := selectset( toDealOps, Elements, item,
|
item.OrganCode() + "_" + item.ProductID() = routingKey and item.SequenceNumber() = maxSeq );
|
traverse( maxSeqElements, Elements, maxSeqELement ) {
|
operationId := maxSeqELement.OrganCode() + "_" + maxSeqELement.ProductID() + "_" + maxSeqELement.ProcessSection();
|
if( maxSeqELement.Line() <> "" ) {
|
operationId := operationId + "_" + maxSeqELement.Line();
|
}
|
this.IOOperationBOM( relnew,
|
OperationID := operationId,
|
ProductID := maxSeqELement.ProductID(),
|
StockingPointID := maxSeqELement.OrganCode() + "_" + this.GetProductTypeByProductId( maxSeqELement.ProductID() ) + "_STOCK",
|
Quantity := 1,
|
IsInput := false );
|
}
|
// ==== 投入 ====
|
// 对Operation中的每个ProcessSection, 找seq最小的list,每条bom对该list生成operationBOM
|
processSectionList := selectuniquevalues( toDealOps, Elements, toDeal,
|
toDeal.OrganCode() + "_" + toDeal.ProductID() = routingKey,
|
toDeal.ProcessSection() );
|
traverse( processSectionList, Elements, processSection ) {
|
minSeq := min( toDealOps, Elements, item,
|
item.OrganCode() + "_" + item.ProductID() = routingKey
|
and item.ProcessSection() = processSection,
|
item.SequenceNumber() );
|
operationRecordsWithMinSeq := selectset( toDealOps, Elements, minSeqWithProcessSectionElement,
|
minSeqWithProcessSectionElement.OrganCode() + "_" + minSeqWithProcessSectionElement.ProductID() = routingKey
|
and minSeqWithProcessSectionElement.ProcessSection() = processSection
|
and minSeqWithProcessSectionElement.SequenceNumber() = minSeq );
|
bomRecords := selectset( toDealBoms, Elements, bom,
|
bom.OrganCode() + "_" + bom.ProductCode() = routingKey
|
and bom.ProcessSection() = processSection );
|
// 按是否有替换料分组
|
bomWithoutAlters := selectset( bomRecords, Elements, bomRecord, bomRecord.AlternativeMaterialCode() = "" );
|
bomWithAlters := selectset( bomRecords, Elements, bomRecord, bomRecord.AlternativeMaterialCode() <> "" );
|
// 处理不带替换料的input
|
traverse( operationRecordsWithMinSeq, Elements, op ) {
|
traverse( bomWithoutAlters, Elements, bom ) {
|
operationId := op.OrganCode() + "_" + op.ProductID() + "_" + op.ProcessSection();
|
if( op.Line() <> "" ) {
|
operationId := operationId + "_" + op.Line();
|
}
|
this.IOOperationBOM( relnew,
|
OperationID := operationId,
|
ProductID := op.ProductID(),
|
StockingPointID := op.OrganCode() + "_" + bom.ComponentType() + "_STOCK",
|
IsInput := true,
|
Quantity := bom.UnitUsageOfComponents() / bom.ComponentOutputRate() );
|
}
|
}
|
// 处理带替换料的,按line和主料分组
|
lineList := selectuniquevalues( operationRecordsWithMinSeq, Elements, item, item.Line() );
|
mainProdList := selectuniquevalues( bomWithAlters, Elements, item, item.ComponentCode() );
|
traverse( lineList, Elements, line ) {
|
opWithLine := select( operationRecordsWithMinSeq, Elements, item, item.Line() = line );
|
opId := opWithLine.OrganCode() + "_" + opWithLine.ProductID() + "_" + opWithLine.ProcessSection();
|
if( opWithLine.Line() <> "" ) {
|
opId := opId + "_" + opWithLine.Line();
|
}
|
traverse( mainProdList, Elements, mainProd ) {
|
// 每种主料一个group
|
inputGroupId := inputGroupId + 1;
|
bomWithMainProdList := selectset( bomWithAlters, Elements, item, item.ComponentCode() = mainProd );
|
bomRandom := bomWithMainProdList.First();
|
// 总数量
|
maxQuantityInGroup := bomRandom.UnitUsageOfComponents() / bomRandom.ComponentOutputRate();
|
// 替代料总比例
|
alterRateTotal := sum( bomWithMainProdList, Elements, item, item.AlternativeRate() );
|
// 创建inputGroup
|
this.IOOperationInputGroup( relnew, InputGroupID := inputGroupId, OperationID := opId, InputGroupQuantity := maxQuantityInGroup );
|
// 创建主料的input bom
|
this.IOOperationBOM( relnew,
|
OperationID := opId,
|
InputGroupID := inputGroupId,
|
ProductID := bomRandom.ComponentCode(),
|
StockingPointID := bomRandom.OrganCode() + "_" + bomRandom.ComponentType() + "_STOCK",
|
IsInput := true,
|
Quantity := maxQuantityInGroup * ( 1 - alterRateTotal ),
|
MinQuantityInGroup := 0.0,
|
MaxQuantityInGroup := maxQuantityInGroup );
|
// 替代料input bom
|
traverse( bomWithMainProdList, Elements, bom ) {
|
this.IOOperationBOM( relnew,
|
OperationID := opId,
|
InputGroupID := inputGroupId,
|
ProductID := bom.AlternativeMaterialCode(),
|
StockingPointID := bom.OrganCode() + "_" + bom.ComponentType() + "_STOCK",
|
IsInput := true,
|
Quantity := maxQuantityInGroup * bom.AlternativeRate(),
|
MinQuantityInGroup := 0.0,
|
MaxQuantityInGroup := maxQuantityInGroup );
|
}
|
}
|
}
|
}
|
// 针对每个routing 重置 inputGroupId
|
inputGroupId := 1;
|
}
|
// 对每个OrgCode_ComponentCode组合,创建采购routing
|
if( createPurchaseSupplyMaterial ) {
|
toCreateKeys := selectuniquevalues( toDealBoms, Elements, bom,
|
bom.ComponentType() = "P",
|
bom.OrganCode() + "_" + bom.ComponentCode() );
|
traverse( toCreateKeys, Elements, toCreateKey ) {
|
bomRandom := selectset( toDealBoms, Elements, bom, bom.ComponentType() = "P" and bom.OrganCode() + "_" + bom.ComponentCode() = toCreateKey ).First();
|
routingId := bomRandom.OrganCode() + "_" + bomRandom.ComponentCode();
|
routingName := routingId;
|
routingStepName := "采购";
|
routingStepSeq := 1;
|
operationId := "PR_" + bomRandom.OrganCode() + bomRandom.ComponentCode();
|
operationName := operationId;
|
unitId := "供应商";
|
// ==== 创建 ====
|
// 创建routing
|
this.IORouting( relnew,
|
ID := routingId, Name := routingName, IsEnabled := true, Start := Date::MinDate(), End := Date::MaxDate() );
|
// 创建routingStep
|
IORoutingStep::CreateIfNotExist( this,
|
routingId,
|
routingStepName,
|
routingStepSeq );
|
// 创建op
|
ioOp := IOOperation::CreateIfNotExist( this, operationId );
|
ioOp.UnitID( unitId );
|
ioOp.RoutingID( routingId );
|
ioOp.RoutingStepName( routingStepName );
|
ioOp.Name( operationName );
|
ioOp.UserLeadTime( Duration::Zero() );
|
ioOp.Throughput( 1.0 );
|
ioOp.HasUserMaximumQuantity( false );
|
ioOp.UserMinimumQuantity( Real::MinReal() );
|
ioOp.UserMaximumQuantity( Real::MaxReal() );
|
// 创建opBOM
|
this.IOOperationBOM( relnew,
|
OperationID := operationId,
|
ProductID := bomRandom.ComponentCode(),
|
StockingPointID := bomRandom.OrganCode() + "_" + bomRandom.ProductType() + "_STOCK",
|
IsInput := true,
|
Quantity := 1 );
|
}
|
}
|
*]
|
}
|