FUNC160
:MPRF:6
:VERS:A2LN
:RELE:a7
:CUST:FP7
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
Sub KeepDumps()

dump 100
dump 110
dump 111
dump 112
dump 114
dump 120
dump 121
dump 122
dump 124
dump 400

End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:6
:VERS:A2LN
:RELE:a7
:CUST:FP7
:TCPAC:tc
:TCMOD:com
:TFLNO:130
:FUNC:START
' | Determine default messaging method

sub determine.defa()
' | SITA not used

	if len(trim(Addresses.Telephone)) > 0 then
	var.defa = to.target(tccom.defa.phone)
		return
	end if

	if not isempty(Addresses.Email) then
		var.defa = to.target(tccom.defa.email)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.fax)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.telex)
		return
	end if

	if not isempty(Addresses.SMSNumber) then
		var.defa = to.target(tccom.defa.sms)
		return
	end if

	var.defa = to.target(tccom.defa.not.applicable)
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:6
:VERS:A2LN
:RELE:a7
:CUST:FP7
:TCPAC:tc
:TCMOD:com
:TFLNO:145
:FUNC:START
'Sub 1DeterminePrimary(ByVal BP as string, ByVal Contact as String, ByRef var.ctpr as Long) as long
' Use this fucntion to check if the contact is also listed as contact on the businesspartner.
' If so then the contact will be the primary for all roles.
'
'	var.ctpr = 2
'
'	select	BusinessPartner.Contact
'	from	BusinessPartner
'	where	BusinessPartner.BusinessPartner = BP	  
'	and	BusinessPartner.Contact = Contact
'	selectdo	
'		var.ctpr = 1
'	endselect
'	
''	var.ctpr = 1
'
'End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:6
:VERS:A2LN
:RELE:a7
:CUST:FP7
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
Function DetermineSrce(Varint.ItemType)

	'| This function determines the value of the tcibd001.scre field.
	'| The function can be called from the dump.
	'| ItemType: target-value (= long) of the tckitm-enum

	'|#Cost/Service	
	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable

	'|# Purchased	
	If Varint.ItemType = 1 then 
		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
	End If

	'|#Manufactured
	If Varint.ItemType = 2 then 
		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
	End If
			
End Function
'|#249608.en
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:6
:VERS:A2LN
:RELE:a7
:CUST:FP7
:TCPAC:ti
:TCMOD:edm
:TFLNO:010
:FUNC:START
function temp
{
dump 010
}
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:6
:VERS:A2LN
:RELE:a7
:CUST:FP7
:TCPAC:wh
:TCMOD:wmd
:TFLNO:220
:FUNC:START
'|#249610.sn
Sub DetermineShipFromToBusinessPartner(_
			DockType,_ 
			BusinessPartner,_ 
			ByRef ShipFromType,_
			ByRef ShipFromCode,_
			ByRef ShipToType,_	
			ByRef ShipToCode)

	'|initialize
	ShipFromType = 10		'| Not aplicable
	ShipFromCode = ""
	ShipToType = 10		'| Not aplicable	
	ShipToCode = ""

	if Trim(BusinessPartner) = "" then 
		exit Sub
	end if
		
	If  DockType = 3 then			'|Receiving
		ShipFromType = 2		'|Business Partner
		ShipFromCode = Trim(BusinessPartner)
		ShipToType = 10		'|Not aplicable	
		ShipToCode = ""
		exit Sub
	end if

	If  DockType = 3 then			'|Staging
		ShipFromType = 10		'|Not aplicable
		ShipFromCode = ""
		ShipToType = 2		'|Business Partner	
		ShipToCode = Trim(BusinessPartner)
		exit Sub
	end if

end Sub
							'|#249610.en
							'|#249610.so
'|Sub DetermineShipFromToBusinessPartnerOld(DockType, BusinessPartner)
'|
'|	'|initialize
'|	var.whwmd220.sfty = 10		'| Not aplicable
'|	var.whwmd220.sfco = ""
'|	var.whwmd220.stty = 10		'| Not aplicable	
'|	var.whwmd220.stco = ""
'|
'|	if Trim(BusinessPartner) = "" then 
'|		exit Sub
'|	end if
'|		
'|	If  DockType = 3 then			'|Receiving
'|		var.whwmd220.sfty = 2		'|Business Partner
'|		var.whwmd220.sfco = Trim(BusinessPartner)
'|		var.whwmd220.stty = 10		'|Not aplicable	
'|		var.whwmd220.stco = ""
'|		exit Sub
'|	end if
'|
'|	If  DockType = 3 then			'|Staging
'|		var.whwmd220.sfty = 10		'|Not aplicable
'|		var.whwmd220.sfco = ""
'|		var.whwmd220.stty = 2		'|Business Partner	
'|		var.whwmd220.stco = Trim(BusinessPartner)
'|		exit Sub
'|	end if
'|
'|end Sub	
									'|#249610.eo
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:cp
:TCMOD:rpd
:TFLNO:710
:FUNC:START
function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tc
:TCMOD:com
:TFLNO:130
:FUNC:START
' | Determine default messaging method

sub determine.defa()
' | SITA not used

	if len(trim(Addresses.Telephone)) > 0 then
	var.defa = to.target(tccom.defa.phone)
		return
	end if

	if not isempty(Addresses.Email) then
		var.defa = to.target(tccom.defa.email)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.fax)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.telex)
		return
	end if

	if not isempty(Addresses.SMSNumber) then
		var.defa = to.target(tccom.defa.sms)
		return
	end if

	var.defa = to.target(tccom.defa.not.applicable)
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
Function DetermineSrce(Varint.ItemType)

	'| This function determines the value of the tcibd001.scre field.
	'| The function can be called from the dump.
	'| ItemType: target-value (= long) of the tckitm-enum

	'|#Cost/Service	
	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable

	'|# Purchased	
	If Varint.ItemType = 1 then 
		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
	End If

	'|#Manufactured
	If Varint.ItemType = 2 then 
		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
	End If
			
End Function
'|#249608.en
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tf
:TCMOD:gld
:TFLNO:008
:FUNC:START
function DimensionTypePresent(varint.dimensionType)
	DimensionTypePresent = target(tfgld.dopt.no)
	select DimensionType.Type
	from DimensionType
	where  DimensionType.Type = varint.dimensionType
	selectdo
            	if DimensionType.Type = 1 then
                        	DimensionTypePresent = target(tfgld.dopt.mandatory) '|3
	            end if
		if DimensionType.Type > 1 then
            	            DimensionTypePresent = target(tfgld.dopt.optional) '|2
		end if 
		if DimensionType.Type = " " then		
	            	DimensionTypePresent = target(tfgld.dopt.no) '|1
		end if
	endselect
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tf
:TCMOD:gld
:TFLNO:009
:FUNC:START
function get.ledger.account(varstr.ledger.account)
	
	select	ChartOfAccounts.*
	from	ChartOfAccounts
	where	ChartOfAccounts.LedgerAccount = varstr.ledger.account
	selectdo
		get.ledger.account = ChartOfAccounts.LedgerAccount
	endselect

end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tf
:TCMOD:gld
:TFLNO:010
:FUNC:START
function DetermineDepthStructure(varstr.dimcode,ByRef varint.depth, varint.CurrLevel)
	
	varstr.prev.dimcode = ""
	
	select	Dimensions.*
	from	Dimensions
	where	Dimensions.ParentDimension = varstr.dimcode
	selectdo
		varstr.childnode = Dimensions.Dimension
		if varstr.prev.dimcode <> Dimensions.ParentDimension then
			varint.CurrLevel = varint.CurrLevel + 1
		end if
		varstr.prev.dimcode = Dimensions.ParentDimension
		MaxDepth = DetermineDepthStructure(varstr.childnode,varint.depth, varint.CurrLevel)
	endselect
	If varint.depth <= varint.CurrLevel then
		varint.depth = varint.CurrLevel
		varint.CurrLevel = 0
	end if
	DetermineDepthStructure = varint.depth
end function

function DetermineChildrenStructure(varstr.dimcode,varint.CurrLevel)
	
	varstr.prev.dimcode = ""
	varint.Level = varint.CurrLevel
	
	select	Dimensions.*
	from	Dimensions
	where	Dimensions.ParentDimension = varstr.dimcode
	selectdo
		varstr.childnode = Dimensions.Dimension
		if varstr.prev.dimcode <> Dimensions.ParentDimension and Dimensions.PostingTypeInforFMS = 1 then
			varint.CurrLevel = varint.CurrLevel - 1
			varint.Level = varint.CurrLevel
		end if
		varstr.prev.dimcode = Dimensions.ParentDimension
		if Dimensions.PostingTypeInforFMS = 1 then
			varint.sublevel = varint.Level
		else
			varint.sublevel = 0
		end if
		if varstr.source.gl.version  =  "GL2" then  
	   		var.tfgld010.bloc  =  1 '  |  tfgld.bloc.free  
	  	else  
	   		if Dimensions.StatusInforFMS  =  "Open" then  
	   	   		var.tfgld010.bloc  =  1 '  |  tfgld.bloc.free  
	   	  	else  	   	   
	   	   		var.tfgld010.bloc  =  3 '  |  tfgld.bloc.all.input  
	   	  	end if  
	  	end if 
		if var.tfgld010.bloc  =  1 then
	   		var.tfgld010.bfdt  =  ""  
	   	   	var.tfgld010.budt  =  ""  
		else
	   		if Dimensions.OpenDateInforFMS  =  0 or Dimensions.OpenDateInforFMS  =  "" then  
	   	   		var.tfgld010.bfdt  =  Date()  
	   	   	else  
	   	   		var.tfgld010.bfdt  =  Dimensions.OpenDateInforFMS
	   	   	end if  
	   	   	if Dimensions.ClosedDateInforFMS =  0 or Dimensions.ClosedDateInforFMS =  "" then  
	   	   		var.tfgld010.budt  =  CDate("12/31/2038") 
	   	   	else  
	   	   		var.tfgld010.budt  =  Dimensions.ClosedDateInforFMS
	   	   	end if  
	   	  end if  
 
		dump 910
		MaxDepth = DetermineChildrenStructure(varstr.childnode, varint.sublevel)
	endselect
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tf
:TCMOD:gld
:TFLNO:014
:FUNC:START
Function get.user()

	select GeneralParameters.MigrationUser
	from GeneralParameters
	selectdo

		get.user= GeneralParameters.MigrationUser
		
	endselect

End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tf
:TCMOD:gld
:TFLNO:100
:FUNC:START
Function Get_User()

	select GeneralParameters.MigrationUser
	from GeneralParameters
	selectdo
		Get_User = GeneralParameters.MigrationUser
	endselect

End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tf
:TCMOD:gld
:TFLNO:106
:FUNC:START
Function get.debit.credit(varstr.DebitCredit)
	
	If varstr.DebitCredit = "C" then
		get.debit.credit = target(tfgld.dbcr.credit)
	Else
		get.debit.credit = target(tfgld.dbcr.debit)
	End If

End Function

Function get.rate( vardouble.rate , ByRef var.RateFactor ) 
	strrate = LTrim ( CStr ( vardouble.rate )) 
	get.rate = 0.0 
	var.RateFactor = 1 
	If len (strrate ) > 13 then 
		varstr.rate = Mid ( strrate , 1 , 13 ) 
	else
		varstr.rate = strrate
	End If
	varint.subst = Instr(varstr.rate,".")
	if varint.subst = 0 then
		varstr.rate = strrate & ".00"
	else
		varint.subst = varint.subst -1
	End If
	str1 = Mid ( varstr.rate, 1, varint.subst) 
	str2 = Mid ( varstr.rate, ( Instr ( varstr.rate , "." ) + 1 ), 13 ) 
	If len ( str2 ) > 6 then 
		pownum = len ( str2 ) - 6 
		ratedbl = CDbl ( rate ) 
		get.rate = ratedbl * ( 10 ^ pownum ) 
		var.RateFactor = 10 ^ pownum 
	Else 
		get.rate = vardouble.rate 
		var.RateFactor = 1 
	End If 
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tf
:TCMOD:gld
:TFLNO:205
:FUNC:START
function get.dimension.mapping(varstr.DimSource)

	If Trim(varstr.DimSource) = "" Then Exit Function

	get.dimension.mapping = varstr.DimSource		

	select	DimensionMapping.*
	from	DimensionMapping
	where	DimensionMapping.DimCodeSource = varstr.DimSource
	selectdo
		get.dimension.mapping = DimensionMapping.DimCodeTarget
	endselect
end function


function DimensionTypePresent(varint.dimensionType)

	DimensionTypePresent = "Not Existing"

	select DimensionType.Type
	from DimensionType
	where  DimensionType.Type = varint.dimensionType
	selectdo
                       	DimensionTypePresent = "present"
	endselect
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:tf
:TCMOD:gld
:TFLNO:206
:FUNC:START
function get.dimension.mapping(varstr.DimSource)

	If Trim(varstr.DimSource) = "" Then Exit Function

	get.dimension.mapping = varstr.DimSource		

	select	DimensionMapping.*
	from	DimensionMapping
	where	DimensionMapping.DimCodeSource = varstr.DimSource
	selectdo
		get.dimension.mapping = DimensionMapping.DimCodeTarget
	endselect
end function

function get.account.source(varstr.AccountSource)

	If Trim(varstr.AccountSource) = "" Then Exit Function

	get.account.source = varstr.AccountSource

	select	ChartOfAccountsMapping.*
	from	ChartOfAccountsMapping
	where	ChartOfAccountsMapping.AccountSource = varstr.AccountSource
	selectdo
		get.account.source = ChartOfAccountsMapping.AccountTarget
	endselect
end function

function DimensionTypePresent(varint.dimensionType)
	DimensionTypePresent = target(tfgld.dopt.no)
	select DimensionType.Type
	from DimensionType
	where  DimensionType.Type = varint.dimensionType
	selectdo
            	if DimensionType.Type = 1 then
                        	DimensionTypePresent = target(tfgld.dopt.mandatory) '|3
	            end if
		if DimensionType.Type > 1 then
            	            DimensionTypePresent = target(tfgld.dopt.optional) '|2
		end if 
		if DimensionType.Type = " " then		
	            	DimensionTypePresent = target(tfgld.dopt.no) '|1
		end if
	endselect
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:wh
:TCMOD:inh
:TFLNO:520
:FUNC:START
function	generate.order.number(varstr.series, varint.counter )

   	  length.counter = len(varint.counter) 
	  length.series 	= len(varstr.series)		
   	  var.order.length  =  9  -  length.series  -  length.counter  
   	  varstr.remaining.positions  =  Replace(Space(var.order.length), " ", "0")  
   	  varstr.order.number =  varstr.series  &  varstr.remaining.positions  &  varint.counter  

	  generate.order.number = varstr.order.number

End Function

function read.item.settings(varstr.item, varstr.cprj,  o.location.controlled, o.lot.controlled, o.serialized, o.lots.in.inv, o.serials.in.inv)

	'| Initialize
	o.location.controlled = 2
	o.lot.controlled = 2
	o.serialized = 2
	o.lots.in.inv = 2 
	o.serials.in.inv = 2

	if varstr.cprj = "" or IsNull(varstr.cprj) then
		select	Items.*
		from	Items
		where	Items.Item = varstr.item
		selectdo
			o.location.controlled = Items.LocationControlled
			o.lot.controlled = Items.LotControlled
			o.serialized = Items.Serialized
			o.lots.in.inv = Items.LotsInInventory
			o.serials.in.inv = Items.SerialsInInventory
		endselect
	else
		select	Items.*
		from	Items
		where	Items.Project = varstr.cprj
		and	Items.Item = varstr.item
		selectdo
			o.location.controlled = Items.LocationControlled
			o.lot.controlled = Items.LotControlled
			o.serialized = Items.Serialized
			o.lots.in.inv = Items.LotsInInventory
			o.serials.in.inv = Items.SerialsInInventory
		endselect
	end if
	read.item.settings = "temp"		
End function

function get.inventory.valuation.method(varstr.cwar, varstr.cprj, varstr.item)

	o.valm = 1

	if varstr.cprj = "" or IsNull(varstr.cprj) then
		select	WarehouseItem.InventoryValuationMethod
		from	WarehouseItem
		where	WarehouseItem.Warehouse = varstr.cwar 
		and	WarehouseItem.Item = varstr.item
		selectdo
			if WarehouseItem.Project = "" then
				o.valm = WarehouseItem.InventoryValuationMethod
			end if
		endselect
	else
		select	WarehouseItem.InventoryValuationMethod
		from	WarehouseItem
		where	WarehouseItem.Warehouse = varstr.cwar 
		and	WarehouseItem.Project = varstr.cprj
		and	WarehouseItem.Item = varstr.item
		selectdo
			o.valm = WarehouseItem.InventoryValuationMethod
		endselect
	end if

	get.inventory.valuation.method = o.valm

End function

function determine.total.line.quantity(varstr.cwar, varstr.cprj, varstr.item)

	o.quantity = 0
	if trim(varstr.cprj)  <>  "" then  
		select	AdjustmentOrders.Quantity  
	   	from	AdjustmentOrders  
	   	where 	AdjustmentOrders.Warehouse  = varstr.cwar  
	   	and  	AdjustmentOrders.Project  = varstr.cprj 
	   	and 	AdjustmentOrders.Item  =  varstr.item 
	   	and	AdjustmentOrders.SerialNumber  <>  ""  
	   	selectdo  
	   		o.quantity  =  o.quantity  +  AdjustmentOrders.Quantity  
	   	endselect  
	else  
		select	AdjustmentOrders.Quantity  
	   	from	AdjustmentOrders  
	   	where 	AdjustmentOrders.Warehouse  =  varstr.cwar
	   	and 	AdjustmentOrders.Item  =  varstr.item  
	   	and  	AdjustmentOrders.SerialNumber  <>  ""  
	   	selectdo
	   		if AdjustmentOrders.Project  =  "" then  
				o.quantity  =  o.quantity  +  AdjustmentOrders.Quantity  
			end if
	   	endselect  
	end if
	determine.total.line.quantity = o.quantity
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:wh
:TCMOD:wmd
:TFLNO:220
:FUNC:START
' |  KH20110804.so 
'|'|#249610.sn
'|Sub DetermineShipFromToBusinessPartner(_
'|			DockType,_ 
'|			BusinessPartner,_ 
'|			ByRef ShipFromType,_
'|			ByRef ShipFromCode,_
'|			ByRef ShipToType,_	
'|			ByRef ShipToCode)
'|
'|	'|initialize
'|	ShipFromType = 10		'| Not aplicable
'|	ShipFromCode = ""
'|	ShipToType = 10		'| Not aplicable	
'|	ShipToCode = ""
'|
'|	if Trim(BusinessPartner) = "" then 
'|		exit Sub
'|	end if
'|		
'|	If  DockType = 3 then			'|Receiving
'|		ShipFromType = 2		'|Business Partner
'|		ShipFromCode = Trim(BusinessPartner)
'|		ShipToType = 10		'|Not aplicable	
'|		ShipToCode = ""
'|		exit Sub
'|	end if
'|
'|	If  DockType = 3 then			'|Staging
'|		ShipFromType = 10		'|Not aplicable
'|		ShipFromCode = ""
'|		ShipToType = 2		'|Business Partner	
'|		ShipToCode = Trim(BusinessPartner)
'|		exit Sub
'|	end if
'|
'|end Sub
'|							'|#249610.en
'| KH20110804.eo
							'|#249610.so
'|Sub DetermineShipFromToBusinessPartnerOld(DockType, BusinessPartner)
'|
'|	'|initialize
'|	var.whwmd220.sfty = 10		'| Not aplicable
'|	var.whwmd220.sfco = ""
'|	var.whwmd220.stty = 10		'| Not aplicable	
'|	var.whwmd220.stco = ""
'|
'|	if Trim(BusinessPartner) = "" then 
'|		exit Sub
'|	end if
'|		
'|	If  DockType = 3 then			'|Receiving
'|		var.whwmd220.sfty = 2		'|Business Partner
'|		var.whwmd220.sfco = Trim(BusinessPartner)
'|		var.whwmd220.stty = 10		'|Not aplicable	
'|		var.whwmd220.stco = ""
'|		exit Sub
'|	end if
'|
'|	If  DockType = 3 then			'|Staging
'|		var.whwmd220.sfty = 10		'|Not aplicable
'|		var.whwmd220.sfco = ""
'|		var.whwmd220.stty = 2		'|Business Partner	
'|		var.whwmd220.stco = Trim(BusinessPartner)
'|		exit Sub
'|	end if
'|
'|end Sub	
									'|#249610.eo
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:7
:VERS:A2LN
:RELE:a7
:CUST:FP7R
:TCPAC:wh
:TCMOD:wmd
:TFLNO:300
:FUNC:START
function get.infinite.location(varstr.cwar, varstr.loc)

	o.infinite.location = 1

	select	LocationCapacity.*
	from	LocationCapacity
	where	LocationCapacity.Warehouse = varstr.cwar
	and	LocationCapacity.Location = varstr.loc
	selectdo
		o.infinite.location = 2
	endselect

	get.infinite.location = o.infinite.location 

End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:TCPAC:cp
:TCMOD:rpd
:TFLNO:710
:FUNC:START
function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
Sub KeepDumps()

dump 100
dump 110
dump 111
dump 112
dump 114
dump 120
dump 121
dump 122
dump 124
dump 400

End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:TCPAC:tc
:TCMOD:com
:TFLNO:130
:FUNC:START
' | Determine default messaging method

sub determine.defa()
' | SITA not used

	if len(trim(Addresses.Telephone)) > 0 then
	var.defa = to.target(tccom.defa.phone)
		return
	end if

	if not isempty(Addresses.Email) then
		var.defa = to.target(tccom.defa.email)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.fax)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.telex)
		return
	end if

	if not isempty(Addresses.SMSNumber) then
		var.defa = to.target(tccom.defa.sms)
		return
	end if

	var.defa = to.target(tccom.defa.not.applicable)
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
Function DetermineSrce(Varint.ItemType)

	'| This function determines the value of the tcibd001.scre field.
	'| The function can be called from the dump.
	'| ItemType: target-value (= long) of the tckitm-enum

	'|#Cost/Service	
	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable

	'|# Purchased	
	If Varint.ItemType = 1 then 
		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
	End If

	'|#Manufactured
	If Varint.ItemType = 2 then 
		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
	End If
			
End Function
'|#249608.en
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function

									'|#FP8.sn
Function set.source.of.price(Varint.ItemType)				

'''''|This function will set the Source of price based upon the item type field.
'''''|Item Type values			-> Source of Price Values
'''''|	1 = "Purchased"			-> Price Book / Contract (2)
'''''|	2 = "Manufactured"		-> Price Book / Contract (2)
'''''|	3 = "Generic"			-> Price Book / Contract (2)
'''''|	4 = "Cost"			-> Not Applicable	 (3)
'''''|	5 = "Service"			-> Not Applicable	 (3)
'''''|	6 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

	if Varint.ItemType = 6 then
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if

	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 3 then
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function
									'|#FP8.en
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:TCPAC:td
:TCMOD:pcg
:TFLNO:010
:FUNC:START
function keep.dumps()
	dump 010
end function

function tdpcg010.get.matrix.sequences(varint.Type, varstr.definition, o.Level, o.Sequence)

	l.Matrix.Level.found = false

	select	MatrixSequences.*   
	from	MatrixSequences   
	where	MatrixSequences.MatrixDefinition  = varstr.definition 
	selectdo  
		if MatrixSequences.MatrixType = varint.Type then 
			l.Matrix.Level.found  =  true  
			'For 1 or more matrix levels fill malv and mapr with values of  
			'first found record.  
			o.Sequence  =  MatrixSequences.MatrixSequences
			o.Level	  =  MatrixSequences.MatrixLevel 

		end if
		if l.Matrix.Level.found then Exit Do  	   
	endselect  
	tdpcg010.get.matrix.sequences = l.Matrix.Level.found

	if l.Matrix.Level.found then
		' Only for dicsounts the level needs to be set else set to not applicable
		if varint.type <> 2 AND _
		   varint.type <> 3 AND _
		   varint.type <> 5 AND _
		   varint.type <> 6 then
			o.Level	  =  6	'Not Applicable
		end if			
	end if
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:TCPAC:tf
:TCMOD:gld
:TFLNO:008
:FUNC:START
function DimensionTypePresent(varint.dimensionType)
	DimensionTypePresent = target(tfgld.dopt.no)
	select DimensionType.Type
	from DimensionType
	where  DimensionType.Type = varint.dimensionType
	selectdo
            	if DimensionType.Type = 1 then
                        	DimensionTypePresent = target(tfgld.dopt.mandatory) '|3
	            end if
		if DimensionType.Type > 1 then
            	            DimensionTypePresent = target(tfgld.dopt.optional) '|2
		end if 
		if DimensionType.Type = " " then		
	            	DimensionTypePresent = target(tfgld.dopt.no) '|1
		end if
	endselect
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:TCPAC:tf
:TCMOD:gld
:TFLNO:106
:FUNC:START
Function get.debit.credit(varstr.DebitCredit)
	
	If varstr.DebitCredit = "C" then
		get.debit.credit = target(tfgld.dbcr.credit)
	Else
		get.debit.credit = target(tfgld.dbcr.debit)
	End If

End Function

Function get.rate( vardouble.rate , ByRef var.RateFactor ) 
	strrate = LTrim ( CStr ( vardouble.rate )) 
	get.rate = 0.0 
	var.RateFactor = 1 
	If len (strrate ) > 13 then 
		varstr.rate = Mid ( strrate , 1 , 13 ) 
	else
		varstr.rate = strrate
	End If
	varint.subst = Instr(varstr.rate,".")
	if varint.subst = 0 then
		varstr.rate = strrate & ".00"
	else
		varint.subst = varint.subst -1
	End If
	str1 = Mid ( varstr.rate, 1, varint.subst) 
	str2 = Mid ( varstr.rate, ( Instr ( varstr.rate , "." ) + 1 ), 13 ) 
	If len ( str2 ) > 6 then 
		pownum = len ( str2 ) - 6 
		ratedbl = CDbl ( rate ) 
		get.rate = ratedbl * ( 10 ^ pownum ) 
		var.RateFactor = 10 ^ pownum 
	Else 
		get.rate = vardouble.rate 
		var.RateFactor = 1 
	End If 
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:8
:VERS:A2LN
:RELE:a8
:CUST:fp8
:TCPAC:wh
:TCMOD:inh
:TFLNO:520
:FUNC:START
function	generate.order.number(varstr.series, varint.counter )

   	  length.counter = len(varint.counter) 
	  length.series 	= len(varstr.series)		
   	  var.order.length  =  9  -  length.series  -  length.counter  
   	  varstr.remaining.positions  =  Replace(Space(var.order.length), " ", "0")  
   	  varstr.order.number =  varstr.series  &  varstr.remaining.positions  &  varint.counter  

	  generate.order.number = varstr.order.number

End Function

function read.item.settings(varstr.item, varstr.cprj,  o.location.controlled, o.lot.controlled, o.serialized, o.lots.in.inv, o.serials.in.inv)

	'| Initialize
	o.location.controlled = 2
	o.lot.controlled = 2
	o.serialized = 2
	o.lots.in.inv = 2 
	o.serials.in.inv = 2

	if varstr.cprj = "" or IsNull(varstr.cprj) then
		select	Items.*
		from	Items
		where	Items.Item = varstr.item
		selectdo
			o.location.controlled = Items.LocationControlled
			o.lot.controlled = Items.LotControlled
			o.serialized = Items.Serialized
			o.lots.in.inv = Items.LotsInInventory
			o.serials.in.inv = Items.SerialsInInventory
		endselect
	else
		select	Items.*
		from	Items
		where	Items.Project = varstr.cprj
		and	Items.Item = varstr.item
		selectdo
			o.location.controlled = Items.LocationControlled
			o.lot.controlled = Items.LotControlled
			o.serialized = Items.Serialized
			o.lots.in.inv = Items.LotsInInventory
			o.serials.in.inv = Items.SerialsInInventory
		endselect
	end if
	read.item.settings = "temp"		
End function

function get.inventory.valuation.method(varstr.cwar, varstr.cprj, varstr.item)

	o.valm = 1

	if varstr.cprj = "" or IsNull(varstr.cprj) then
		select	WarehouseItem.InventoryValuationMethod
		from	WarehouseItem
		where	WarehouseItem.Warehouse = varstr.cwar 
		and	WarehouseItem.Item = varstr.item
		selectdo
			if WarehouseItem.Project = "" then
				o.valm = WarehouseItem.InventoryValuationMethod
			end if
		endselect
	else
		select	WarehouseItem.InventoryValuationMethod
		from	WarehouseItem
		where	WarehouseItem.Warehouse = varstr.cwar 
		and	WarehouseItem.Project = varstr.cprj
		and	WarehouseItem.Item = varstr.item
		selectdo
			o.valm = WarehouseItem.InventoryValuationMethod
		endselect
	end if

	get.inventory.valuation.method = o.valm

End function

function determine.total.line.quantity(varstr.cwar, varstr.cprj, varstr.item)

	o.quantity = 0
	if trim(varstr.cprj)  <>  "" then  
		select	AdjustmentOrders.Quantity  
	   	from	AdjustmentOrders  
	   	where 	AdjustmentOrders.Warehouse  = varstr.cwar  
	   	and  	AdjustmentOrders.Project  = varstr.cprj 
	   	and 	AdjustmentOrders.Item  =  varstr.item 
	   	and	AdjustmentOrders.SerialNumber  <>  ""  
	   	selectdo  
	   		o.quantity  =  o.quantity  +  AdjustmentOrders.Quantity  
	   	endselect  
	else  
		select	AdjustmentOrders.Quantity  
	   	from	AdjustmentOrders  
	   	where 	AdjustmentOrders.Warehouse  =  varstr.cwar
	   	and 	AdjustmentOrders.Item  =  varstr.item  
	   	and  	AdjustmentOrders.SerialNumber  <>  ""  
	   	selectdo
	   		if AdjustmentOrders.Project  =  "" then  
				o.quantity  =  o.quantity  +  AdjustmentOrders.Quantity  
			end if
	   	endselect  
	end if
	determine.total.line.quantity = o.quantity
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:9
:VERS:A2LN
:RELE:a9
:CUST:fp9
:TCPAC:cp
:TCMOD:rpd
:TFLNO:710
:FUNC:START
function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:9
:VERS:A2LN
:RELE:a9
:CUST:fp9
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
Sub KeepDumps()

dump 100
dump 110
dump 111
dump 112
dump 114
dump 120
dump 121
dump 122
dump 124
dump 400

End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:9
:VERS:A2LN
:RELE:a9
:CUST:fp9
:TCPAC:tc
:TCMOD:com
:TFLNO:130
:FUNC:START
' | Determine default messaging method

sub determine.defa()
' | SITA not used

	if len(trim(Addresses.Telephone)) > 0 then
	var.defa = to.target(tccom.defa.phone)
		return
	end if

	if not isempty(Addresses.Email) then
		var.defa = to.target(tccom.defa.email)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.fax)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.telex)
		return
	end if

	if not isempty(Addresses.SMSNumber) then
		var.defa = to.target(tccom.defa.sms)
		return
	end if

	var.defa = to.target(tccom.defa.not.applicable)
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:9
:VERS:A2LN
:RELE:a9
:CUST:fp9
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
Function DetermineSrce(Varint.ItemType)

	'| This function determines the value of the tcibd001.scre field.
	'| The function can be called from the dump.
	'| ItemType: target-value (= long) of the tckitm-enum

	'|#Cost/Service	
	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable

	'|# Purchased	
	If Varint.ItemType = 1 then 
		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
	End If

	'|#Manufactured
	If Varint.ItemType = 2 then 
		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
	End If
			
End Function
'|#249608.en
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
									'|#FP9.sn
Function set.source.of.price(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price Values
'	|	1 = "Purchased"			-> Price Book / Contract (2)
'	|	2 = "Manufactured"		-> Price Book / Contract (2)
'	|	3 = "Generic"			-> Price Book / Contract (2)
'	|	4 = "Cost"			-> Not Applicable	 (3)
'	|	5 = "Service"			-> Not Applicable	 (3)
'	|	6 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

	if Varint.ItemType = 6 then
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if

	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 3 then
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function
									'|#FP9.en

Function keep.dumps()
' just a dummy function to leave dumps linked to the object.

	dump 001 '  |   *  Dump for tcibd001
	dump 400 '  |   *  Dump for whwmd400
	dump 003 '  |   *  Dump for tdisa001  
	dump 004 '  |   *  Dump for tiipd001
	dump 007 '  |   *  Dump for ticpr007
	dump 100 '  |   *  Dump for tcibd100
	dump 101 '  |   *  Dump for cprpd100  
	dump 120 '  |   *  Dump for cprpd120 	|#Obsolete for FP9 
	dump 200 '  |   *  Dump for tcibd200
	dump 201 '  |   *  Dump for tsmdm200
	dump 005 '  |   *  Dump for tppdm005  
	dump 61 '  |   *  SE to tcibd001  
	dump 62 '  |   *  SE to tdipu001  
	dump 63 '  |   *  SE to tdisa001
	dump 64 '  |  PE to tcibd001  
	dump 65 '  |  PE to tdipu001  
	dump 66 '  |  PE to tdisa001
	dump 71 '  |   *  SS to tcibd001  
	dump 72 '  |   *  SS to tdipu001  
	dump 73 '  |   *  SS to tdisa001
	dump 74 '  |   *  PS to tcibd001  
	dump 75 '  |   *  PS to tdipu001  
	dump 76 '  |   *  PS to tdisa001


end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:9
:VERS:A2LN
:RELE:a9
:CUST:fp9
:TCPAC:td
:TCMOD:pcg
:TFLNO:010
:FUNC:START
function keep.dumps()
	dump 010
end function

function tdpcg010.get.matrix.sequences(varint.Type, varstr.definition, o.Level, o.Sequence)

	l.Matrix.Level.found = false

	select	MatrixSequences.*   
	from	MatrixSequences   
	where	MatrixSequences.MatrixDefinition  = varstr.definition 
	selectdo  
		if MatrixSequences.MatrixType = varint.Type then 
			l.Matrix.Level.found  =  true  
			'For 1 or more matrix levels fill malv and mapr with values of  
			'first found record.  
			o.Sequence  =  MatrixSequences.MatrixSequences
			o.Level	  =  MatrixSequences.MatrixLevel 

		end if
		if l.Matrix.Level.found then Exit Do  	   
	endselect  
	tdpcg010.get.matrix.sequences = l.Matrix.Level.found

	if l.Matrix.Level.found then
		' Only for dicsounts the level needs to be set else set to not applicable
		if varint.type <> 2 AND _
		   varint.type <> 3 AND _
		   varint.type <> 5 AND _
		   varint.type <> 6 then
			o.Level	  =  6	'Not Applicable
		end if			
	end if
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:10
:VERS:A2LN
:RELE:LN
:CUST:10-4
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
Sub KeepDumps()

dump 100
dump 110
dump 111
dump 112
dump 114
dump 120
dump 121
dump 122
dump 124
dump 400

End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:10
:VERS:A2LN
:RELE:LN
:CUST:10-4
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
Function DetermineSrce(Varint.ItemType)

	'| This function determines the value of the tcibd001.scre field.
	'| The function can be called from the dump.
	'| ItemType: target-value (= long) of the tckitm-enum

	'|#Cost/Service	
	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable

	'|# Purchased	
	If Varint.ItemType = 1 then 
		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
	End If

	'|#Manufactured
	If Varint.ItemType = 2 then 
		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
	End If
			
End Function
'|#249608.en
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
									'|#FP9.sn
Function set.source.of.price(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price Values
'	|	1 = "Purchased"			-> Price Book / Contract (2)
'	|	2 = "Manufactured"		-> Price Book / Contract (2)
'	|	3 = "Generic"			-> Price Book / Contract (2)
'	|	4 = "Cost"			-> Not Applicable	 (3)
'	|	5 = "Service"			-> Not Applicable	 (3)
'	|	6 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

	if Varint.ItemType = 6 then
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if

	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 3 then
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function
									'|#FP9.en

									'LN10_4.sn
Function set.source.of.price.for.service.subcontracting(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price for.service.subcontracting Values
'	|	1 = "Purchased"			-> Reference Activity (4)
'	|	2 = "Manufactured"		-> Reference Activity (4)
'	|	3 = "Generic"			-> Not Applicable	 (3)
'	|	4 = "Cost"			-> Reference Activity (4)
'	|	5 = "Service"			-> Reference Activity (4)
'	|	6 = "Subcontracted Service"	-> Not Applicable	 (3)

	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 4 or Varint.ItemType = 5 then
		set.source.of.price.for.service.subcontracting = target(tcsopr.reference.act)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price.for.service.subcontracting = target(tcsopr.not.appl)
End Function
							

Function get.purchase.price(Varint.ItemType, Varint.PurchasePrice )

	' for Subcontracting the purchase price is not applicable.
	' field is made empty
	if Varint.ItemType = 6 then
		get.purchase.price = 0.0
	end if
		
	get.purchase.price = Varint.PurchasePrice

End Function
		
			
									'LN10_4.en



Function keep.dumps()
' just a dummy function to leave dumps linked to the object.

	dump 001 '  |   *  Dump for tcibd001
	dump 002 '  |   *  Dump for tdipu001
	dump 400 '  |   *  Dump for whwmd400
	dump 003 '  |   *  Dump for tdisa001  
	dump 004 '  |   *  Dump for tiipd001
	dump 007 '  |   *  Dump for ticpr007
	dump 100 '  |   *  Dump for tcibd100
	dump 101 '  |   *  Dump for cprpd100  
	dump 102 '  |   *  Dump for tdipu100
	dump 120 '  |   *  Dump for cprpd120 	|#Obsolete for FP9 
	dump 200 '  |   *  Dump for tcibd200
	dump 201 '  |   *  Dump for tsmdm200
	dump 005 '  |   *  Dump for tppdm005  
	dump 61 '  |   *  SE to tcibd001  
	dump 62 '  |   *  SE to tdipu001  
	dump 63 '  |   *  SE to tdisa001
	dump 64 '  |  PE to tcibd001  
	dump 65 '  |  PE to tdipu001  
	dump 66 '  |  PE to tdisa001
	dump 71 '  |   *  SS to tcibd001  
	dump 72 '  |   *  SS to tdipu001  
	dump 73 '  |   *  SS to tdisa001
	dump 74 '  |   *  PS to tcibd001  
	dump 75 '  |   *  PS to tdipu001  
	dump 76 '  |   *  PS to tdisa001


end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:10
:VERS:A2LN
:RELE:LN
:CUST:10-4
:TCPAC:tf
:TCMOD:gld
:TFLNO:009
:FUNC:START
function get.ledger.account(varstr.ledger.account)
	
	select	ChartOfAccounts.*
	from	ChartOfAccounts
	where	ChartOfAccounts.LedgerAccount = varstr.ledger.account
	selectdo
		get.ledger.account = ChartOfAccounts.LedgerAccount
	endselect

end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:TCPAC:cp
:TCMOD:rpd
:TFLNO:710
:FUNC:START
function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
Sub KeepDumps()

dump 100
dump 110
dump 111
dump 112
dump 114
dump 120
dump 121
dump 122
dump 124
dump 400

End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:TCPAC:tc
:TCMOD:com
:TFLNO:130
:FUNC:START
' | Determine default messaging method

sub determine.defa()
' | SITA not used

	if len(trim(Addresses.Telephone)) > 0 then
	var.defa = to.target(tccom.defa.phone)
		return
	end if

	if not isempty(Addresses.Email) then
		var.defa = to.target(tccom.defa.email)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.fax)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.telex)
		return
	end if

	if not isempty(Addresses.SMSNumber) then
		var.defa = to.target(tccom.defa.sms)
		return
	end if

	var.defa = to.target(tccom.defa.not.applicable)
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
Function DetermineSrce(Varint.ItemType)

	'| This function determines the value of the tcibd001.scre field.
	'| The function can be called from the dump.
	'| ItemType: target-value (= long) of the tckitm-enum

	'|#Cost/Service	
	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable

	'|# Purchased	
	If Varint.ItemType = 1 then 
		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
	End If

	'|#Manufactured
	If Varint.ItemType = 2 then 
		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
	End If
			
End Function
'|#249608.en
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
									'|#FP9.sn
Function set.source.of.price(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price Values
'	|	1 = "Purchased"			-> Price Book / Contract (2)
'	|	2 = "Manufactured"		-> Price Book / Contract (2)
'	|	3 = "Generic"			-> Price Book / Contract (2)
'	|	4 = "Cost"			-> Not Applicable	 (3)
'	|	5 = "Service"			-> Not Applicable	 (3)
'	|	6 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

	if Varint.ItemType = 6 then
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if

	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 3 then
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function
									'|#FP9.en

									'LN10_4.sn
Function set.source.of.price.for.service.subcontracting(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price for.service.subcontracting Values
'	|	1 = "Purchased"			-> Reference Activity (4)
'	|	2 = "Manufactured"		-> Reference Activity (4)
'	|	3 = "Generic"			-> Not Applicable	 (3)
'	|	4 = "Cost"			-> Reference Activity (4)
'	|	5 = "Service"			-> Reference Activity (4)
'	|	6 = "Subcontracted Service"	-> Not Applicable	 (3)

	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 4 or Varint.ItemType = 5 then
		set.source.of.price.for.service.subcontracting = target(tcsopr.reference.act)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price.for.service.subcontracting = target(tcsopr.not.appl)
End Function
							

Function get.purchase.price(Varint.ItemType, Varint.PurchasePrice )

	' for Subcontracting the purchase price is not applicable.
	' field is made empty
	if Varint.ItemType = 6 then
		get.purchase.price = 0.0
	end if
		
	get.purchase.price = Varint.PurchasePrice

End Function
		
			
									'LN10_4.en



Function keep.dumps()
' just a dummy function to leave dumps linked to the object.

	dump 001 '  |   *  Dump for tcibd001
	dump 002 '  |   *  Dump for tdipu001
	dump 400 '  |   *  Dump for whwmd400
	dump 003 '  |   *  Dump for tdisa001  
	dump 004 '  |   *  Dump for tiipd001
	dump 007 '  |   *  Dump for ticpr007
	dump 100 '  |   *  Dump for tcibd100
	dump 101 '  |   *  Dump for cprpd100  
	dump 102 '  |   *  Dump for tdipu100
	dump 120 '  |   *  Dump for cprpd120 	|#Obsolete for FP9 
	dump 200 '  |   *  Dump for tcibd200
	dump 201 '  |   *  Dump for tsmdm200
	dump 005 '  |   *  Dump for tppdm005  
	dump 61 '  |   *  SE to tcibd001  
	dump 62 '  |   *  SE to tdipu001  
	dump 63 '  |   *  SE to tdisa001
	dump 64 '  |  PE to tcibd001  
	dump 65 '  |  PE to tdipu001  
	dump 66 '  |  PE to tdisa001
	dump 71 '  |   *  SS to tcibd001  
	dump 72 '  |   *  SS to tdipu001  
	dump 73 '  |   *  SS to tdisa001
	dump 74 '  |   *  PS to tcibd001  
	dump 75 '  |   *  PS to tdipu001  
	dump 76 '  |   *  PS to tdisa001


end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:TCPAC:tf
:TCMOD:gld
:TFLNO:008
:FUNC:START
function DimensionTypePresent(varint.dimensionType)
	DimensionTypePresent = target(tfgld.dopt.no)
	select DimensionType.Type
	from DimensionType
	where  DimensionType.Type = varint.dimensionType
	selectdo
            	if DimensionType.Type = 1 then
                        	DimensionTypePresent = target(tfgld.dopt.mandatory) '|3
	            end if
		if DimensionType.Type > 1 then
            	            DimensionTypePresent = target(tfgld.dopt.optional) '|2
		end if 
		if DimensionType.Type = " " then		
	            	DimensionTypePresent = target(tfgld.dopt.no) '|1
		end if
	endselect
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:TCPAC:tf
:TCMOD:gld
:TFLNO:106
:FUNC:START
Function get.debit.credit(varstr.DebitCredit)
	
	If varstr.DebitCredit = "C" then
		get.debit.credit = target(tfgld.dbcr.credit)
	Else
		get.debit.credit = target(tfgld.dbcr.debit)
	End If

End Function

Function get.rate( vardouble.rate , ByRef var.RateFactor ) 
	strrate = LTrim ( CStr ( vardouble.rate )) 
	get.rate = 0.0 
	var.RateFactor = 1 
	If len (strrate ) > 13 then 
		varstr.rate = Mid ( strrate , 1 , 13 ) 
	else
		varstr.rate = strrate
	End If
	varint.subst = Instr(varstr.rate,".")
	if varint.subst = 0 then
		varstr.rate = strrate & ".00"
	else
		varint.subst = varint.subst -1
	End If
	str1 = Mid ( varstr.rate, 1, varint.subst) 
	str2 = Mid ( varstr.rate, ( Instr ( varstr.rate , "." ) + 1 ), 13 ) 
	If len ( str2 ) > 6 then 
		pownum = len ( str2 ) - 6 
		ratedbl = CDbl ( rate ) 
		get.rate = ratedbl * ( 10 ^ pownum ) 
		var.RateFactor = 10 ^ pownum 
	Else 
		get.rate = vardouble.rate 
		var.RateFactor = 1 
	End If 
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:TCPAC:ti
:TCMOD:rou
:TFLNO:001
:FUNC:START
function keepdumps()


	  dump 001 '  |   *  tirou001  
	  dump 065 '  |   *  tcmcs065  
	  dump 110 '  |   *  tcemm110  
	  dump 124 '  |   *  tcemm124  
	  dump 200 '  |   *  cprpd200
	  dump 365 '  |   *  pddp tcmcs065  
	  dump 310 '  |   *  pddp tcemm110  
	  dump 324 '  |   *  pddp tcemm124  

	  dump 600 '  |   *  tppdm600  
	  dump 113 '  |   *  tcemm113  
	  dump 610 '  |   *  tcemm110 for tp

end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:11
:VERS:A2LN
:RELE:LN
:CUST:105
:TCPAC:wh
:TCMOD:wmd
:TFLNO:220
:FUNC:START
' |  KH20110804.so 
'|'|#249610.sn
'|Sub DetermineShipFromToBusinessPartner(_
'|			DockType,_ 
'|			BusinessPartner,_ 
'|			ByRef ShipFromType,_
'|			ByRef ShipFromCode,_
'|			ByRef ShipToType,_	
'|			ByRef ShipToCode)
'|
'|	'|initialize
'|	ShipFromType = 10		'| Not aplicable
'|	ShipFromCode = ""
'|	ShipToType = 10		'| Not aplicable	
'|	ShipToCode = ""
'|
'|	if Trim(BusinessPartner) = "" then 
'|		exit Sub
'|	end if
'|		
'|	If  DockType = 3 then			'|Receiving
'|		ShipFromType = 2		'|Business Partner
'|		ShipFromCode = Trim(BusinessPartner)
'|		ShipToType = 10		'|Not aplicable	
'|		ShipToCode = ""
'|		exit Sub
'|	end if
'|
'|	If  DockType = 3 then			'|Staging
'|		ShipFromType = 10		'|Not aplicable
'|		ShipFromCode = ""
'|		ShipToType = 2		'|Business Partner	
'|		ShipToCode = Trim(BusinessPartner)
'|		exit Sub
'|	end if
'|
'|end Sub
'|							'|#249610.en
'| KH20110804.eo
							'|#249610.so
'|Sub DetermineShipFromToBusinessPartnerOld(DockType, BusinessPartner)
'|
'|	'|initialize
'|	var.whwmd220.sfty = 10		'| Not aplicable
'|	var.whwmd220.sfco = ""
'|	var.whwmd220.stty = 10		'| Not aplicable	
'|	var.whwmd220.stco = ""
'|
'|	if Trim(BusinessPartner) = "" then 
'|		exit Sub
'|	end if
'|		
'|	If  DockType = 3 then			'|Receiving
'|		var.whwmd220.sfty = 2		'|Business Partner
'|		var.whwmd220.sfco = Trim(BusinessPartner)
'|		var.whwmd220.stty = 10		'|Not aplicable	
'|		var.whwmd220.stco = ""
'|		exit Sub
'|	end if
'|
'|	If  DockType = 3 then			'|Staging
'|		var.whwmd220.sfty = 10		'|Not aplicable
'|		var.whwmd220.sfco = ""
'|		var.whwmd220.stty = 2		'|Business Partner	
'|		var.whwmd220.stco = Trim(BusinessPartner)
'|		exit Sub
'|	end if
'|
'|end Sub	
									'|#249610.eo
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:12
:VERS:A2LN
:RELE:10
:CUST:52CS
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
Sub KeepDumps()

dump 100
dump 110
dump 111
dump 112
dump 114
dump 120
dump 121
dump 122
dump 124
dump 400

End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:12
:VERS:A2LN
:RELE:10
:CUST:52CS
:TCPAC:tc
:TCMOD:com
:TFLNO:130
:FUNC:START
' | Determine default messaging method

sub determine.defa()
' | SITA not used

	if len(trim(Addresses.Telephone)) > 0 then
	var.defa = to.target(tccom.defa.phone)
		return
	end if

	if not isempty(Addresses.Email) then
		var.defa = to.target(tccom.defa.email)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.fax)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.telex)
		return
	end if

	if not isempty(Addresses.SMSNumber) then
		var.defa = to.target(tccom.defa.sms)
		return
	end if

	var.defa = to.target(tccom.defa.not.applicable)
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:12
:VERS:A2LN
:RELE:10
:CUST:52CS
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
Function DetermineSrce(Varint.ItemType)

	'| This function determines the value of the tcibd001.scre field.
	'| The function can be called from the dump.
	'| ItemType: target-value (= long) of the tckitm-enum

	'|#Cost/Service	
	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable

	'|# Purchased	
	If Varint.ItemType = 1 then 
		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
	End If

	'|#Manufactured
	If Varint.ItemType = 2 then 
		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
	End If
			
End Function
'|#249608.en
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
									'|#FP9.sn
Function set.source.of.price(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price Values
'	|	1 = "Purchased"			-> Price Book / Contract (2)
'	|	2 = "Manufactured"		-> Price Book / Contract (2)
'	|	3 = "Generic"			-> Price Book / Contract (2)
'	|	4 = "Cost"			-> Not Applicable	 (3)
'	|	5 = "Service"			-> Not Applicable	 (3)
'	|	6 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

	if Varint.ItemType = 6 then
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if

	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 3 then
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function
									'|#FP9.en

									'LN10_4.sn
Function set.source.of.price.for.service.subcontracting(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price for.service.subcontracting Values
'	|	1 = "Purchased"			-> Reference Activity (4)
'	|	2 = "Manufactured"		-> Reference Activity (4)
'	|	3 = "Generic"			-> Not Applicable	 (3)
'	|	4 = "Cost"			-> Reference Activity (4)
'	|	5 = "Service"			-> Reference Activity (4)
'	|	6 = "Subcontracted Service"	-> Not Applicable	 (3)

	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 4 or Varint.ItemType = 5 then
		set.source.of.price.for.service.subcontracting = target(tcsopr.reference.act)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price.for.service.subcontracting = target(tcsopr.not.appl)
End Function
							

Function get.purchase.price(Varint.ItemType, Varint.PurchasePrice )

	' for Subcontracting the purchase price is not applicable.
	' field is made empty
	if Varint.ItemType = 6 then
		get.purchase.price = 0.0
	end if
		
	get.purchase.price = Varint.PurchasePrice

End Function
		
			
									'LN10_4.en




Function keep.dumps()
' just a dummy function to leave dumps linked to the object.

	dump 001 '  |   *  Dump for tcibd001
	dump 002 '  |   *  Dump for tdipu001
	dump 400 '  |   *  Dump for whwmd400
	dump 003 '  |   *  Dump for tdisa001  
	dump 004 '  |   *  Dump for tiipd001
	dump 007 '  |   *  Dump for ticpr007
	dump 100 '  |   *  Dump for tcibd100
	dump 101 '  |   *  Dump for cprpd100  
	dump 102 '  |   *  Dump for tdipu100
	dump 120 '  |   *  Dump for cprpd120 	|#Obsolete for FP9 
	dump 200 '  |   *  Dump for tcibd200
	dump 201 '  |   *  Dump for tsmdm200
	dump 005 '  |   *  Dump for tppdm005  
	dump 61 '  |   *  SE to tcibd001  
	dump 62 '  |   *  SE to tdipu001  
	dump 63 '  |   *  SE to tdisa001
	dump 64 '  |  PE to tcibd001  
	dump 65 '  |  PE to tdipu001  
	dump 66 '  |  PE to tdisa001
	dump 71 '  |   *  SS to tcibd001  
	dump 72 '  |   *  SS to tdipu001  
	dump 73 '  |   *  SS to tdisa001
	dump 74 '  |   *  PS to tcibd001  
	dump 75 '  |   *  PS to tdipu001  
	dump 76 '  |   *  PS to tdisa001


end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:12
:VERS:A2LN
:RELE:10
:CUST:52CS
:TCPAC:tf
:TCMOD:gld
:TFLNO:008
:FUNC:START
function DimensionTypePresent(varint.dimensionType)
	DimensionTypePresent = target(tfgld.dopt.no)
	select DimensionType.Type
	from DimensionType
	where  DimensionType.Type = varint.dimensionType
	selectdo
            	if DimensionType.Type = 1 then
                        	DimensionTypePresent = target(tfgld.dopt.mandatory) '|3
	            end if
		if DimensionType.Type > 1 then
            	            DimensionTypePresent = target(tfgld.dopt.optional) '|2
		end if 
		if DimensionType.Type = " " then		
	            	DimensionTypePresent = target(tfgld.dopt.no) '|1
		end if
	endselect
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:12
:VERS:A2LN
:RELE:10
:CUST:52CS
:TCPAC:tf
:TCMOD:gld
:TFLNO:106
:FUNC:START
Function get.debit.credit(varstr.DebitCredit)
	
	If varstr.DebitCredit = "C" then
		get.debit.credit = target(tfgld.dbcr.credit)
	Else
		get.debit.credit = target(tfgld.dbcr.debit)
	End If

End Function

Function get.rate( vardouble.rate , ByRef var.RateFactor ) 
	strrate = LTrim ( CStr ( vardouble.rate )) 
	get.rate = 0.0 
	var.RateFactor = 1 
	If len (strrate ) > 13 then 
		varstr.rate = Mid ( strrate , 1 , 13 ) 
	else
		varstr.rate = strrate
	End If
	varint.subst = Instr(varstr.rate,".")
	if varint.subst = 0 then
		varstr.rate = strrate & ".00"
	else
		varint.subst = varint.subst -1
	End If
	str1 = Mid ( varstr.rate, 1, varint.subst) 
	str2 = Mid ( varstr.rate, ( Instr ( varstr.rate , "." ) + 1 ), 13 ) 
	If len ( str2 ) > 6 then 
		pownum = len ( str2 ) - 6 
		ratedbl = CDbl ( rate ) 
		get.rate = ratedbl * ( 10 ^ pownum ) 
		var.RateFactor = 10 ^ pownum 
	Else 
		get.rate = vardouble.rate 
		var.RateFactor = 1 
	End If 
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:12
:VERS:A2LN
:RELE:10
:CUST:52CS
:TCPAC:ti
:TCMOD:rou
:TFLNO:001
:FUNC:START
function keepdumps()


	  dump 001 '  |   *  tirou001  
	  dump 065 '  |   *  tcmcs065  
	  dump 110 '  |   *  tcemm110  
	  dump 124 '  |   *  tcemm124  
	  dump 200 '  |   *  cprpd200
	  dump 365 '  |   *  pddp tcmcs065  
	  dump 310 '  |   *  pddp tcemm110  
	  dump 324 '  |   *  pddp tcemm124  

	  dump 600 '  |   *  tppdm600  
	  dump 113 '  |   *  tcemm113  
	  dump 610 '  |   *  tcemm110 for tp

end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:cp
:TCMOD:rpd
:TFLNO:100
:FUNC:START
Function defaults.planning.present()

	defaults.planning.present = false
	select      ItemDefaultsPlanning.*   
	from       ItemDefaultsPlanning
	as set with 1 rows
	selectdo
		defaults.planning.present = true
	endselect

end function

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	'Intitialize default values
	if i.cprj.field = "PROJEMPTY" then
		i.cprj.field = ""
	end if

	s.cp.StartPosition.cluster 	= 1
	s.cp.segmentLength.cluster 	= 3
	s.cp.StartPosition.project 	= 4
	s.cp.segmentLength.project 	= 9
	s.cp.StartPosition.item 	= 13		
	s.cp.segmentLength.item 	= 38
	s.cp.segmentAlignment.cluster 	= "left"	
	s.cp.segmentAlignment.project 	= "left"	
	s.cp.segmentAlignment.item 	= "left"	
		
	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:cp
:TCMOD:rpd
:TFLNO:710
:FUNC:START
function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
												'|#LN10605.sn			
	'| For templates with Item (project segment/itemsegment) in the primary key it requires the project segement must always have a value.
	'| Therefore the default value vor project segment in the templates is set as 'PROJEMPTY', meaning the project segment should be regarded as empty.
	'| The below section is to clear the project segment field when the access field contains the value 'PROJEMPTY'.
	if ProjectSegment = "PROJEMPTY" then
		ProjectSegment = " "
	end if	
												'|#LN10605.en		
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
Sub KeepDumps()

dump 100
dump 110
dump 111
dump 112
dump 114
dump 120
dump 121
dump 122
dump 124
dump 400

End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:tc
:TCMOD:com
:TFLNO:130
:FUNC:START
' | Determine default messaging method

sub determine.defa()
' | SITA not used

	if len(trim(Addresses.Telephone)) > 0 then
	var.defa = to.target(tccom.defa.phone)
		return
	end if

	if not isempty(Addresses.Email) then
		var.defa = to.target(tccom.defa.email)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.fax)
		return
	end if

	if not isempty(Addresses.Telex) then
		var.defa = to.target(tccom.defa.telex)
		return
	end if

	if not isempty(Addresses.SMSNumber) then
		var.defa = to.target(tccom.defa.sms)
		return
	end if

	var.defa = to.target(tccom.defa.not.applicable)
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
'|LN10605.so
'|* Field became obsolete in 10.6. willbe filled with default value
'|Function DetermineSrce(Varint.ItemType)
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|#Cost/Service	
'|	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable
'|
'|	'|# Purchased	
'|	If Varint.ItemType = 1 then 
'|		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
'|	End If
'|
'|	'|#Manufactured
'|	If Varint.ItemType = 2 then 
'|		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
'|	End If
'|			
'|End Function
'|#249608.en
'|LN10605.eo
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
												''|#LN10605.sn			
	''| For templates with Item (project segment/itemsegment) in the primary key it requires the project segement must always have a value.
	''| Therefore the default value vor project segment in the templates is set as "PROJEMPTY", meaning the project segment should be regarded as empty.
	''| The below section is to clear the project segment field when the access field contains the value "PROJEMPTY".
	if ProjectSegment = "PROJEMPTY" then
		ProjectSegment = ""
	end if	
												''|#LN10605.en	
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
									'|#FP9.sn
Function set.source.of.price(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price Values
'	|	1 = "Purchased"			-> Price Book / Contract (2)
'	|	2 = "Manufactured"		-> Price Book / Contract (2)
'	|	3 = "Generic"			-> Price Book / Contract (2)
'	|	4 = "Cost"			-> Not Applicable	 (3)
'	|	5 = "Service"			-> Not Applicable	 (3)
'	|	6 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

'|LN10605.sc
'|	if Varint.ItemType = 6 then
	if Varint.ItemType = 60 then
'|LN10605.ec
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if
'|LN10605.sc
'|	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 3 then
	if Varint.ItemType = 30 or Varint.ItemType = 90 then
'|LN10605.ec
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function
									'|#FP9.en

									'LN10_4.sn
Function set.source.of.price.for.service.subcontracting(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price for.service.subcontracting Values
'	|	1 = "Purchased"			-> Reference Activity (4)
'	|	2 = "Manufactured"		-> Reference Activity (4)
'	|	3 = "Generic"			-> Not Applicable	 (3)
'	|	4 = "Cost"			-> Reference Activity (4)
'	|	5 = "Service"			-> Reference Activity (4)
'	|	6 = "Subcontracted Service"	-> Not Applicable	 (3)

'|LN10605.sc
'|	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 4 or Varint.ItemType = 5 then
	if Varint.ItemType = 30 or Varint.ItemType = 70 or Varint.ItemType = 80 then
'|LN10605.ec
		set.source.of.price.for.service.subcontracting = target(tcsopr.reference.act)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price.for.service.subcontracting = target(tcsopr.not.appl)
End Function
							

Function get.purchase.price(Varint.ItemType, Varint.PurchasePrice )

	' for Subcontracting the purchase price is not applicable.
	' field is made empty
'|LN10605.sc
'|	if Varint.ItemType = 6 then
	if Varint.ItemType = 60 then
'|LN10605.ec
		get.purchase.price = 0.0
		exit function			
	end if
		
	get.purchase.price = Varint.PurchasePrice

End Function
		
			
									'LN10_4.en

									'|* LN10605.sn

'|* Read Item defaults initialy before dump. 
'|* If now item defaults available, reading of item default table will be skipped during dump.
'|* This results in a performance improvement during dumping
Function defaults.general.present()

            defaults.general.present = false
            select      ItemDefaultsGeneral.*   
            from       ItemDefaultsGeneral
            as set with 1 rows
            selectdo
                        defaults.general.present = true
            endselect

end function

Function defaults.purchase.present()

            defaults.purchase.present = false
            select      ItemDefaultsPurchase.*   
            from       ItemDefaultsPurchase
            as set with 1 rows
            selectdo
                        defaults.purchase.present = true
            endselect

end function

Function defaults.sales.present()

            defaults.sales.present = false
            select      ItemDefaultsSales.*   
            from       ItemDefaultsSales
            as set with 1 rows
            selectdo
                        defaults.sales.present = true
            endselect

end function

Function defaults.ordering.present()

            defaults.ordering.present = false
            select      ItemDefaultsOrdering.*   
            from       ItemDefaultsOrdering
            as set with 1 rows
            selectdo
                        defaults.ordering.present = true
            endselect

end function

Function defaults.planning.present()


            defaults.planning.present = false
            select      ItemDefaultsPlanning.*   
            from       ItemDefaultsPlanning
            as set with 1 rows
            selectdo
                        defaults.planning.present = true
            endselect

end function

Function defaults.production.present()

            defaults.production.present = false
            select      ItemDefaultsProduction.*   
            from       ItemDefaultsProduction
            as set with 1 rows
            selectdo
                        defaults.production.present = true
            endselect

end function

Function defaults.costing.present()

            defaults.costing.present = false
            select      ItemDefaultsCosting.*   
            from       ItemDefaultsCosting
            as set with 1 rows
            selectdo
                        defaults.costing.present = true
            endselect

end function

Function defaults.warehousing.present()

            defaults.warehousing.present = false
            select      ItemDefaultsWarehousing.*   
            from       ItemDefaultsWarehousing
            as set with 1 rows
            selectdo
                        defaults.warehousing.present = true
            endselect

end function

Function defaults.project.present()

            defaults.project.present = false
            select      ItemDefaultsProject.*   
            from       ItemDefaultsProject
            as set with 1 rows
            selectdo
                        defaults.project.present = true
            endselect

end function

Function defaults.service.present()

            defaults.service.present = false
            select      ItemDefaultsService.*   
            from       ItemDefaultsService
            as set with 1 rows
            selectdo
                        defaults.service.present = true
            endselect

end function

										'|* LN10605.en

Function keep.dumps()
' just a dummy function to leave dumps linked to the object.

	dump 001 '  |   *  Dump for tcibd001
	dump 002 '  |   *  Dump for tdipu001
	dump 400 '  |   *  Dump for whwmd400
	dump 003 '  |   *  Dump for tdisa001  
	dump 004 '  |   *  Dump for tiipd001
'|	dump007 '  |   *  Dump for ticpr007	|# Moved to its own scripts  LN10605
'|	dump100 '  |   *  Dump for tcibd100	|# Obsolete LN1050
'|	dump101 '  |   *  Dump for cprpd100      	|# Moved to its own scripts  LN10605
	dump 102 '  |   *  Dump for tdipu100
'|	dump120 '  |   *  Dump for cprpd120 	|#Obsolete for FP9 
	dump 200 '  |   *  Dump for tcibd200
	dump 201 '  |   *  Dump for tsmdm200
	dump 005 '  |   *  Dump for tppdm005  
	dump 61 '  |   *  SE to tcibd001  
	dump 62 '  |   *  SE to tdipu001  
	dump 63 '  |   *  SE to tdisa001
	dump 64 '  |  PE to tcibd001  
	dump 65 '  |  PE to tdipu001  
	dump 66 '  |  PE to tdisa001
	dump 71 '  |   *  SS to tcibd001  
	dump 72 '  |   *  SS to tdipu001  
	dump 73 '  |   *  SS to tdisa001
	dump 74 '  |   *  PS to tcibd001  
	dump 75 '  |   *  PS to tdipu001  
	dump 76 '  |   *  PS to tdisa001


end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:tc
:TCMOD:ibd
:TFLNO:150
:FUNC:START
Function set.source.of.price(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price Values
'	|	30 = "Product"			-> Price Book / Contract (2)
'	|	90 = "Generic"			-> Price Book / Contract (2)
'	|	70 = "Cost"			-> Not Applicable	 (3)
'	|	80 = "Service"			-> Not Applicable	 (3)
'	|	60 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

	if Varint.ItemType = 60 then
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if

	if Varint.ItemType = 30 or Varint.ItemType = 90 then
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function

Function set.source.of.price.for.service.subcontracting(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price for.service.subcontracting Values
'	|	30 = "Product"			-> Reference Activity (4)
'	|	90 = "Generic"			-> Not Applicable	 (3)
'	|	70 = "Cost"			-> Reference Activity (4)
'	|	80 = "Service"			-> Reference Activity (4)
'	|	60 = "Subcontracted Service"	-> Not Applicable	 (3)

	if Varint.ItemType = 30 or Varint.ItemType = 70 or Varint.ItemType = 80 then
		set.source.of.price.for.service.subcontracting = target(tcsopr.reference.act)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price.for.service.subcontracting = target(tcsopr.not.appl)
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:tf
:TCMOD:gld
:TFLNO:008
:FUNC:START
function DimensionTypePresent(varint.dimensionType)
	DimensionTypePresent = target(tfgld.dopt.no)
	select DimensionType.Type
	from DimensionType
	where  DimensionType.Type = varint.dimensionType
	selectdo
            	if DimensionType.Type = 1 then
                        	DimensionTypePresent = target(tfgld.dopt.mandatory) '|3
	            end if
		if DimensionType.Type > 1 then
            	            DimensionTypePresent = target(tfgld.dopt.optional) '|2
		end if 
		if DimensionType.Type = " " then		
	            	DimensionTypePresent = target(tfgld.dopt.no) '|1
		end if
	endselect
end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:tf
:TCMOD:gld
:TFLNO:106
:FUNC:START
Function get.debit.credit(varstr.DebitCredit)
	
	If varstr.DebitCredit = "C" then
		get.debit.credit = target(tfgld.dbcr.credit)
	Else
		get.debit.credit = target(tfgld.dbcr.debit)
	End If

End Function

Function get.rate( vardouble.rate , ByRef var.RateFactor ) 
	strrate = LTrim ( CStr ( vardouble.rate )) 
	get.rate = 0.0 
	var.RateFactor = 1 
	If len (strrate ) > 13 then 
		varstr.rate = Mid ( strrate , 1 , 13 ) 
	else
		varstr.rate = strrate
	End If
	varint.subst = Instr(varstr.rate,".")
	if varint.subst = 0 then
		varstr.rate = strrate & ".00"
	else
		varint.subst = varint.subst -1
	End If
	str1 = Mid ( varstr.rate, 1, varint.subst) 
	str2 = Mid ( varstr.rate, ( Instr ( varstr.rate , "." ) + 1 ), 13 ) 
	If len ( str2 ) > 6 then 
		pownum = len ( str2 ) - 6 
		ratedbl = CDbl ( rate ) 
		get.rate = ratedbl * ( 10 ^ pownum ) 
		var.RateFactor = 10 ^ pownum 
	Else 
		get.rate = vardouble.rate 
		var.RateFactor = 1 
	End If 
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:ti
:TCMOD:cpr
:TFLNO:007
:FUNC:START
Function defaults.costing.present()

	defaults.costing.present = false
	select  	  ItemDefaultsCosting.*   
	from  	  ItemDefaultsCosting
	as set with 1 rows
	selectdo
		defaults.costing.present = true
	endselect

end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:ti
:TCMOD:rou
:TFLNO:001
:FUNC:START
function keepdumps()


	  dump 001 '  |   *  tirou001  
	  dump 065 '  |   *  tcmcs065  


	  dump 200 '  |   *  cprpd200
	  dump 365 '  |   *  pddp tcmcs065  





end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:ti
:TCMOD:sfc
:TFLNO:010
:FUNC:START
sub time.fields()
' | SITA not used
	  var.cyti  =  ProductionOrderOperations.CycleTime  
	  var.tisfc010.prte  =  (60/var.cyti)  
	  var.tisfc010.prte  =  round(var.tisfc010.prte, 2)  
	  var.tisfc010.prtm  =  ProductionOrderOperations.CycleTime/60*ProductionOrders.Quantity  

	
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:wh
:TCMOD:inh
:TFLNO:520
:FUNC:START
function	generate.order.number(varstr.series, varint.counter )

   	  length.counter = len(varint.counter) 
	  length.series 	= len(varstr.series)		
   	  var.order.length  =  9  -  length.series  -  length.counter  
   	  varstr.remaining.positions  =  Replace(Space(var.order.length), " ", "0")  
   	  varstr.order.number =  varstr.series  &  varstr.remaining.positions  &  varint.counter  

	  generate.order.number = varstr.order.number

End Function

function read.item.settings(varstr.item, varstr.cprj,  o.location.controlled, o.lot.controlled, o.serialized, o.lots.in.inv, o.serials.in.inv)

	'| Initialize
	o.location.controlled = 2
	o.lot.controlled = 2
	o.serialized = 2
	o.lots.in.inv = 2 
	o.serials.in.inv = 2

	if varstr.cprj = "" or IsNull(varstr.cprj) then
		select	Items.*
		from	Items
		where	Items.Item = varstr.item
		selectdo
			o.location.controlled = Items.LocationControlled
			o.lot.controlled = Items.LotControlled
			o.serialized = Items.Serialized
			o.lots.in.inv = Items.LotsInInventory
			o.serials.in.inv = Items.SerialsInInventory
		endselect
	else
		select	Items.*
		from	Items
		where	Items.Project = varstr.cprj
		and	Items.Item = varstr.item
		selectdo
			o.location.controlled = Items.LocationControlled
			o.lot.controlled = Items.LotControlled
			o.serialized = Items.Serialized
			o.lots.in.inv = Items.LotsInInventory
			o.serials.in.inv = Items.SerialsInInventory
		endselect
	end if
	read.item.settings = "temp"		
End function

function get.inventory.valuation.method(varstr.cwar, varstr.cprj, varstr.item)

	o.valm = 1

	if varstr.cprj = "" or IsNull(varstr.cprj) then
		select	WarehouseItem.InventoryValuationMethod
		from	WarehouseItem
		where	WarehouseItem.Warehouse = varstr.cwar 
		and	WarehouseItem.Item = varstr.item
		selectdo
			if WarehouseItem.Project = "" then
				o.valm = WarehouseItem.InventoryValuationMethod
			end if
		endselect
	else
		select	WarehouseItem.InventoryValuationMethod
		from	WarehouseItem
		where	WarehouseItem.Warehouse = varstr.cwar 
		and	WarehouseItem.Project = varstr.cprj
		and	WarehouseItem.Item = varstr.item
		selectdo
			o.valm = WarehouseItem.InventoryValuationMethod
		endselect
	end if

	get.inventory.valuation.method = o.valm

End function

function determine.total.line.quantity(varstr.cwar, varstr.cprj, varstr.item)

	o.quantity = 0
	if trim(varstr.cprj)  <>  "" then  
		select	AdjustmentOrders.Quantity  
	   	from	AdjustmentOrders  
	   	where 	AdjustmentOrders.Warehouse  = varstr.cwar  
	   	and  	AdjustmentOrders.Project  = varstr.cprj 
	   	and 	AdjustmentOrders.Item  =  varstr.item 
	   	and	AdjustmentOrders.SerialNumber  <>  ""  
	   	selectdo  
	   		o.quantity  =  o.quantity  +  AdjustmentOrders.Quantity  
	   	endselect  
	else  
		select	AdjustmentOrders.Quantity  
	   	from	AdjustmentOrders  
	   	where 	AdjustmentOrders.Warehouse  =  varstr.cwar
	   	and 	AdjustmentOrders.Item  =  varstr.item  
	   	and  	AdjustmentOrders.SerialNumber  <>  ""  
	   	selectdo
	   		if AdjustmentOrders.Project  =  "" then  
				o.quantity  =  o.quantity  +  AdjustmentOrders.Quantity  
			end if
	   	endselect  
	end if
	determine.total.line.quantity = o.quantity
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:14
:VERS:A2LN
:RELE:LN
:CUST:1060
:TCPAC:wh
:TCMOD:wmd
:TFLNO:300
:FUNC:START
function get.infinite.location(varstr.cwar, varstr.loc)

	o.infinite.location = 1

	select	LocationCapacity.*
	from	LocationCapacity
	where	LocationCapacity.Warehouse = varstr.cwar
	and	LocationCapacity.Location = varstr.loc
	selectdo
		o.infinite.location = 2
	endselect

	get.infinite.location = o.infinite.location 

End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:15
:VERS:A2LN
:RELE:LN
:CUST:1070
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
Sub KeepDumps()

dump 100
dump 110
dump 111
dump 112
dump 114
dump 120
dump 121
dump 122
dump 124
dump 400

End Sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:15
:VERS:A2LN
:RELE:LN
:CUST:1070
:TCPAC:tc
:TCMOD:ibd
:TFLNO:001
:FUNC:START
'|#FP6.sn
'|#249608.sn
'|LN10605.so
'|* Field became obsolete in 10.6. willbe filled with default value
'|Function DetermineSrce(Varint.ItemType)
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|#Cost/Service	
'|	DetermineSrce = target(tcsrce.not.appl)	'|#10: Not Applicable
'|
'|	'|# Purchased	
'|	If Varint.ItemType = 1 then 
'|		DetermineSrce = target(tcsrce.purchase) '|# 40: Purchase
'|	End If
'|
'|	'|#Manufactured
'|	If Varint.ItemType = 2 then 
'|		DetermineSrce = target(tcsrce.shopfloor) '|# 20: Shopfloor
'|	End If
'|			
'|End Function
'|#249608.en
'|LN10605.eo
'|#249608.so
'|Sub DetermineSrce()
'|
'|	'| This function determines the value of the tcibd001.scre field.
'|	'| The function can be called from the dump.
'|	'| ItemType: target-value (= long) of the tckitm-enum
'|
'|	'|# Purchased	
'|	if Item.ItemType = 1 then 
'|		var.tcibd001.srce = 40 '|# Purchase
'|		exit sub
'|	end if
'|
'|	'|#Manufactured
'|	if Item.ItemType = 2 then 
'|		var.tcibd001.srce = 20 '|#Shopfloor
'|		exit sub
'|	end if
'|			
'|	'|#Cost/Service	
'|	var.tcibd001.srce = 10	'|#Not Applicable
'|
'|end Sub
'|#249608.eo
'|#FP6.en

function get.segment.cp.item.code(i.clus.field, i.cprj.field, i.item.field)

	' Read the segmentation parameters.
	if s.cp.ItemCodeSegmentationParameters.Read <> 2 Then
		'Intitialize default values
		s.cp.StartPosition.cluster 	= 1
		s.cp.segmentLength.cluster 	= 3
		s.cp.StartPosition.project 	= 4
		s.cp.segmentLength.project 	= 9
		s.cp.StartPosition.item 	= 13		
		s.cp.segmentLength.item 	= 38
		s.cp.segmentAlignment.cluster 	= "left"	
		s.cp.segmentAlignment.project 	= "left"	
		s.cp.segmentAlignment.item 	= "left"	
		
		s.cp.ItemCodeSegmentationParameters.Read = 2
		Select	ItemCodeSegmentationParameters.*
		From	ItemCodeSegmentationParameters
		Where	ItemCodeSegmentationParameters.cpac = "cp"
		And	ItemCodeSegmentationParameters.pdom = "item"
		Selectdo
			If ItemCodeSegmentationParameters.apco = "project" Then
				s.cp.StartPosition.project 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.project 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.project	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "item" Then
				s.cp.StartPosition.item 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.item 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.item	= ItemCodeSegmentationParameters.adju	
			End If
			If ItemCodeSegmentationParameters.apco = "cluster" Then
				s.cp.StartPosition.cluster 	= ItemCodeSegmentationParameters.spos
				s.cp.segmentLength.cluster 	= ItemCodeSegmentationParameters.leng
				s.cp.segmentAlignment.cluster	= ItemCodeSegmentationParameters.adju	
			End If
		endselect
	end If	

	' This seqtions fills the segment field in the item code. 
	' The segment part is always considered as UpperCase and Left- or Right Aligned
	
	ClusterSegment 	= Trim(i.clus.field)
	ProjectSegment 	= Trim(i.cprj.field)
												''|#LN10605.sn			
	''| For templates with Item (project segment/itemsegment) in the primary key it requires the project segement must always have a value.
	''| Therefore the default value vor project segment in the templates is set as "PROJEMPTY", meaning the project segment should be regarded as empty.
	''| The below section is to clear the project segment field when the access field contains the value "PROJEMPTY".
	if ProjectSegment = "PROJEMPTY" then
		ProjectSegment = ""
	end if	
												''|#LN10605.en	
	ItemSegment 	= Trim(i.item.field)
	ClusterLength	= len(ClusterSegment)	
	ProjectLength	= len(ProjectSegment)	
	ItemLength	= len(ItemSegment)	

	'|* Format the segments. 
	'|* For aligment only 'left' or 'right' is possible and remaining positions will be filled with spaces.
	
	'| Formatting the cluster segment 
	if s.cp.segmentAlignment.cluster = "left" then
		ClusterSegment = ClusterSegment & Space(s.cp.segmentLength.cluster - ClusterLength)
	else
		ClusterSegment = Space(s.cp.segmentLength.cluster - ClusterLength) & ClusterSegment
	end if
	'| Formatting the project segment			
	if s.cp.segmentAlignment.project = "left" then
		ProjectSegment = ProjectSegment & Space(s.cp.segmentLength.project - ProjectLength)
	else
		ProjectSegment = Space(s.cp.segmentLength.project - ProjectLength) & ProjectSegment
	end if
	'| Formatting the item segment
	if s.cp.segmentAlignment.item = "left" then
		ItemSegment = ItemSegment & Space(s.cp.segmentLength.item - ItemLength)
	else
		ItemSegment = Space(s.cp.segmentLength.item - ItemLength) & ItemSegment
	end if
	
	'| Project segment before Item Segment: Cluster - Project - Item
	if s.cp.StartPosition.project < s.cp.StartPosition.item then
		if s.cp.StartPosition.cluster < s.cp.StartPosition.project then
			CombinedSegments = ClusterSegment & ProjectSegment & ItemSegment	
		else
			'|Cluster segment before Item segment: Project - Cluster - Item
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ProjectSegment & ClusterSegment & ItemSegment	
			else
			'|Cluster segment after Item segment: Project - Item - Cluster
				CombinedSegments = ProjectSegment & ItemSegment	& ClusterSegment 
			end if	
		end if	
	else
	'|Project segment after Item segment: Item - Project - Cluster
		if s.cp.StartPosition.cluster > s.cp.StartPosition.project then
			CombinedSegments = ItemSegment & ProjectSegment & ClusterSegment
		else	
			'|Cluster segment before Item segment: Cluster - Item - Project
			if s.cp.StartPosition.cluster < s.cp.StartPosition.item then
				CombinedSegments = ClusterSegment & ItemSegment	& ProjectSegment 
			else
			'|Cluster segment after Item segment: Item - Cluster - Project
				CombinedSegments = ItemSegment	& ClusterSegment & ProjectSegment 
			end if	
		end if	
	end if

	get.segment.cp.item.code = UCase(CombinedSegments)
end Function
									'|#FP9.sn
Function set.source.of.price(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price Values
'	|	1 = "Purchased"			-> Price Book / Contract (2)
'	|	2 = "Manufactured"		-> Price Book / Contract (2)
'	|	3 = "Generic"			-> Price Book / Contract (2)
'	|	4 = "Cost"			-> Not Applicable	 (3)
'	|	5 = "Service"			-> Not Applicable	 (3)
'	|	6 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

'|LN10605.sc
'|	if Varint.ItemType = 6 then
	if Varint.ItemType = 60 then
'|LN10605.ec
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if
'|LN10605.sc
'|	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 3 then
	if Varint.ItemType = 30 or Varint.ItemType = 90 then
'|LN10605.ec
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function
									'|#FP9.en

									'LN10_4.sn
Function set.source.of.price.for.service.subcontracting(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price for.service.subcontracting Values
'	|	1 = "Purchased"			-> Reference Activity (4)
'	|	2 = "Manufactured"		-> Reference Activity (4)
'	|	3 = "Generic"			-> Not Applicable	 (3)
'	|	4 = "Cost"			-> Reference Activity (4)
'	|	5 = "Service"			-> Reference Activity (4)
'	|	6 = "Subcontracted Service"	-> Not Applicable	 (3)

'|LN10605.sc
'|	if Varint.ItemType = 1 or Varint.ItemType = 2 or Varint.ItemType = 4 or Varint.ItemType = 5 then
	if Varint.ItemType = 30 or Varint.ItemType = 70 or Varint.ItemType = 80 then
'|LN10605.ec
		set.source.of.price.for.service.subcontracting = target(tcsopr.reference.act)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price.for.service.subcontracting = target(tcsopr.not.appl)
End Function
							

Function get.purchase.price(Varint.ItemType, Varint.PurchasePrice )

	' for Subcontracting the purchase price is not applicable.
	' field is made empty
'|LN10605.sc
'|	if Varint.ItemType = 6 then
	if Varint.ItemType = 60 then
'|LN10605.ec
		get.purchase.price = 0.0
		exit function			
	end if
		
	get.purchase.price = Varint.PurchasePrice

End Function
		
			
									'LN10_4.en

									'|* LN10605.sn

'|* Read Item defaults initialy before dump. 
'|* If now item defaults available, reading of item default table will be skipped during dump.
'|* This results in a performance improvement during dumping
Function defaults.general.present()

            defaults.general.present = false
            select      ItemDefaultsGeneral.*   
            from       ItemDefaultsGeneral
            as set with 1 rows
            selectdo
                        defaults.general.present = true
            endselect

end function

Function defaults.purchase.present()

            defaults.purchase.present = false
            select      ItemDefaultsPurchase.*   
            from       ItemDefaultsPurchase
            as set with 1 rows
            selectdo
                        defaults.purchase.present = true
            endselect

end function

Function defaults.sales.present()

            defaults.sales.present = false
            select      ItemDefaultsSales.*   
            from       ItemDefaultsSales
            as set with 1 rows
            selectdo
                        defaults.sales.present = true
            endselect

end function

Function defaults.ordering.present()

            defaults.ordering.present = false
            select      ItemDefaultsOrdering.*   
            from       ItemDefaultsOrdering
            as set with 1 rows
            selectdo
                        defaults.ordering.present = true
            endselect

end function

Function defaults.planning.present()


            defaults.planning.present = false
            select      ItemDefaultsPlanning.*   
            from       ItemDefaultsPlanning
            as set with 1 rows
            selectdo
                        defaults.planning.present = true
            endselect

end function

Function defaults.production.present()

            defaults.production.present = false
            select      ItemDefaultsProduction.*   
            from       ItemDefaultsProduction
            as set with 1 rows
            selectdo
                        defaults.production.present = true
            endselect

end function

Function defaults.costing.present()

            defaults.costing.present = false
            select      ItemDefaultsCosting.*   
            from       ItemDefaultsCosting
            as set with 1 rows
            selectdo
                        defaults.costing.present = true
            endselect

end function

Function defaults.warehousing.present()

            defaults.warehousing.present = false
            select      ItemDefaultsWarehousing.*   
            from       ItemDefaultsWarehousing
            as set with 1 rows
            selectdo
                        defaults.warehousing.present = true
            endselect

end function

Function defaults.project.present()

            defaults.project.present = false
            select      ItemDefaultsProject.*   
            from       ItemDefaultsProject
            as set with 1 rows
            selectdo
                        defaults.project.present = true
            endselect

end function

Function defaults.service.present()

            defaults.service.present = false
            select      ItemDefaultsService.*   
            from       ItemDefaultsService
            as set with 1 rows
            selectdo
                        defaults.service.present = true
            endselect

end function

										'|* LN10605.en
										'|*  LN1070.sn
Function defaults.tool.present()

            defaults.tool.present = false
            select      ItemDefaultsTool.*   
            from       ItemDefaultsTool
            as set with 1 rows
            selectdo
                        defaults.tool.present = true
            endselect

end function

Function defaults.quality.present()

            defaults.quality.present = false
            select      ItemDefaultsQuality.*   
            from       ItemDefaultsQuality
            as set with 1 rows
            selectdo
                        defaults.quality.present = true
            endselect

end function

Function defaults.freight.present()

            defaults.freight.present = false
            select      ItemDefaultsFreight.*   
            from       ItemDefaultsFreight
            as set with 1 rows
            selectdo
                        defaults.freight.present = true
            endselect

end function	

Function Create.Item.Subentity(Item.fieldValue, ItemDefault.FieldValue,ItemException)
	
	'| Item.FieldValue = Create subentity based upon Item template
	'| ItemDefault.FieldValue = Create subentity based upon Item Default template
	'| ItemException = Is the record in the Item template marked as exception
	
	if Item.fieldValue = 0 then
		'| If not specified then always take the default if specified else No
		if ItemDefault.FieldValue <> 0 then
			Create.Item.Subentity = ItemDefault.FieldValue
		else
			Create.Item.Subentity = 2	'| No	
		end if	
		exit function
	end if	
		
	if ItemException = 1 then
		'| record in Item template is leading
		Create.Item.Subentity = Item.fieldValue			
	else
		'| record in item default is leading. if empty fallback on item template value
		if ItemDefault.FieldValue <> 0 then
			Create.Item.Subentity = ItemDefault.FieldValue
		else
			Create.Item.Subentity = Item.fieldValue	
		end if	
	end if
			
end function			
							
										'|*  LN1070.en

Function keep.dumps()
' just a dummy function to leave dumps linked to the object.

	dump 001 '  |   *  Dump for tcibd001
	dump 002 '  |   *  Dump for tdipu001
	dump 400 '  |   *  Dump for whwmd400
	dump 003 '  |   *  Dump for tdisa001  
	dump 004 '  |   *  Dump for tiipd001
'|	dump007 '  |   *  Dump for ticpr007	|# Moved to its own scripts  LN10605
'|	dump100 '  |   *  Dump for tcibd100	|# Obsolete LN1050
'|	dump101 '  |   *  Dump for cprpd100      	|# Moved to its own scripts  LN10605
	dump 102 '  |   *  Dump for tdipu100
'|	dump120 '  |   *  Dump for cprpd120 	|#Obsolete for FP9 
	dump 200 '  |   *  Dump for tcibd200
	dump 201 '  |   *  Dump for tsmdm200
	dump 005 '  |   *  Dump for tppdm005  
	dump 61 '  |   *  SE to tcibd001  
	dump 62 '  |   *  SE to tdipu001  
	dump 63 '  |   *  SE to tdisa001
	dump 64 '  |  PE to tcibd001  
	dump 65 '  |  PE to tdipu001  
	dump 66 '  |  PE to tdisa001
	dump 71 '  |   *  SS to tcibd001  
	dump 72 '  |   *  SS to tdipu001  
	dump 73 '  |   *  SS to tdisa001
	dump 74 '  |   *  PS to tcibd001  
	dump 75 '  |   *  PS to tdipu001  
	dump 76 '  |   *  PS to tdisa001
	dump 401 '  |   *  Dump for titrp001	'* LN1070.n
	dump 402 '  |   *  Dump for qmptc018	'* LN1070.n
	dump 403 '  |   *  Dump for fmfmd100	'* LN1070.n

end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:15
:VERS:A2LN
:RELE:LN
:CUST:1070
:TCPAC:tc
:TCMOD:ibd
:TFLNO:150
:FUNC:START
Function set.source.of.price(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price Values
'	|	30 = "Product"			-> Price Book / Contract (2)
'	|	90 = "Generic"			-> Price Book / Contract (2)
'	|	70 = "Cost"			-> Not Applicable	 (3)
'	|	80 = "Service"			-> Not Applicable	 (3)
'	|	60 = "Subcontracted Service"	-> Subcontracting Rate	 (1)

	if Varint.ItemType = 60 then
		set.source.of.price = target(tcsopr.rate)
		exit function
	end if

	if Varint.ItemType = 30 or Varint.ItemType = 90 then
		set.source.of.price = target(tcsopr.price.book)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price = target(tcsopr.not.appl)
End Function

Function set.source.of.price.for.service.subcontracting(Varint.ItemType)				

'	|This function will set the Source of price based upon the item type field.
'	|Item Type values			-> Source of Price for.service.subcontracting Values
'	|	30 = "Product"			-> Reference Activity (4)
'	|	90 = "Generic"			-> Not Applicable	 (3)
'	|	70 = "Cost"			-> Reference Activity (4)
'	|	80 = "Service"			-> Reference Activity (4)
'	|	60 = "Subcontracted Service"	-> Not Applicable	 (3)

	if Varint.ItemType = 30 or Varint.ItemType = 70 or Varint.ItemType = 80 then
		set.source.of.price.for.service.subcontracting = target(tcsopr.reference.act)
		exit function
	end if     						

	'| In all other cases
	set.source.of.price.for.service.subcontracting = target(tcsopr.not.appl)
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:15
:VERS:A2LN
:RELE:LN
:CUST:1070
:TCPAC:tf
:TCMOD:gld
:TFLNO:106
:FUNC:START
Function get.debit.credit(varstr.DebitCredit)
	
	If varstr.DebitCredit = "C" then
		get.debit.credit = target(tfgld.dbcr.credit)
	Else
		get.debit.credit = target(tfgld.dbcr.debit)
	End If

End Function

Function get.rate( vardouble.rate , ByRef var.RateFactor ) 
	strrate = LTrim ( CStr ( vardouble.rate )) 
	get.rate = 0.0 
	var.RateFactor = 1 
	If len (strrate ) > 13 then 
		varstr.rate = Mid ( strrate , 1 , 13 ) 
	else
		varstr.rate = strrate
	End If
	varint.subst = Instr(varstr.rate,".")
	if varint.subst = 0 then
		varstr.rate = strrate & ".00"
	else
		varint.subst = varint.subst -1
	End If
	str1 = Mid ( varstr.rate, 1, varint.subst) 
	str2 = Mid ( varstr.rate, ( Instr ( varstr.rate , "." ) + 1 ), 13 ) 
	If len ( str2 ) > 6 then 
		pownum = len ( str2 ) - 6 
		ratedbl = CDbl ( rate ) 
		get.rate = ratedbl * ( 10 ^ pownum ) 
		var.RateFactor = 10 ^ pownum 
	Else 
		get.rate = vardouble.rate 
		var.RateFactor = 1 
	End If 
End Function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:15
:VERS:A2LN
:RELE:LN
:CUST:1070
:TCPAC:ti
:TCMOD:cpr
:TFLNO:007
:FUNC:START
Function defaults.costing.present()

	defaults.costing.present = false
	select  	  ItemDefaultsCosting.*   
	from  	  ItemDefaultsCosting
	as set with 1 rows
	selectdo
		defaults.costing.present = true
	endselect

end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:15
:VERS:A2LN
:RELE:LN
:CUST:1070
:TCPAC:ti
:TCMOD:rou
:TFLNO:001
:FUNC:START
function keepdumps()


	  dump 001 '  |   *  tirou001  
	  dump 065 '  |   *  tcmcs065  


	  dump 200 '  |   *  cprpd200
	  dump 365 '  |   *  pddp tcmcs065  





end function
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:15
:VERS:A2LN
:RELE:LN
:CUST:1070
:TCPAC:ti
:TCMOD:sfc
:TFLNO:010
:FUNC:START
sub time.fields()
' | SITA not used
	  var.cyti  =  ProductionOrderOperations.CycleTime  
	  var.tisfc010.prte  =  (60/var.cyti)  
	  var.tisfc010.prte  =  round(var.tisfc010.prte, 2)  
	  var.tisfc010.prtm  =  ProductionOrderOperations.CycleTime/60*ProductionOrders.Quantity  

	
end sub
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:15
:VERS:A2LN
:RELE:LN
:CUST:1070
:TCPAC:wh
:TCMOD:inh
:TFLNO:520
:FUNC:START
function	generate.order.number(varstr.series, varint.counter )

   	  length.counter = len(varint.counter) 
	  length.series 	= len(varstr.series)		
   	  var.order.length  =  9  -  length.series  -  length.counter  
   	  varstr.remaining.positions  =  Replace(Space(var.order.length), " ", "0")  
   	  varstr.order.number =  varstr.series  &  varstr.remaining.positions  &  varint.counter  

	  generate.order.number = varstr.order.number

End Function

function read.item.settings(varstr.item, varstr.cprj,  o.location.controlled, o.lot.controlled, o.serialized, o.lots.in.inv, o.serials.in.inv)

	'| Initialize
	o.location.controlled = 2
	o.lot.controlled = 2
	o.serialized = 2
	o.lots.in.inv = 2 
	o.serials.in.inv = 2

	if varstr.cprj = "" or IsNull(varstr.cprj) then
		select	Items.*
		from	Items
		where	Items.Item = varstr.item
		selectdo
			o.location.controlled = Items.LocationControlled
			o.lot.controlled = Items.LotControlled
			o.serialized = Items.Serialized
			o.lots.in.inv = Items.LotsInInventory
			o.serials.in.inv = Items.SerialsInInventory
		endselect
	else
		select	Items.*
		from	Items
		where	Items.Project = varstr.cprj
		and	Items.Item = varstr.item
		selectdo
			o.location.controlled = Items.LocationControlled
			o.lot.controlled = Items.LotControlled
			o.serialized = Items.Serialized
			o.lots.in.inv = Items.LotsInInventory
			o.serials.in.inv = Items.SerialsInInventory
		endselect
	end if
	read.item.settings = "temp"		
End function

function get.inventory.valuation.method(varstr.cwar, varstr.cprj, varstr.item)

	o.valm = 1

	if varstr.cprj = "" or IsNull(varstr.cprj) then
		select	WarehouseItem.InventoryValuationMethod
		from	WarehouseItem
		where	WarehouseItem.Warehouse = varstr.cwar 
		and	WarehouseItem.Item = varstr.item
		selectdo
			if WarehouseItem.Project = "" then
				o.valm = WarehouseItem.InventoryValuationMethod
			end if
		endselect
	else
		select	WarehouseItem.InventoryValuationMethod
		from	WarehouseItem
		where	WarehouseItem.Warehouse = varstr.cwar 
		and	WarehouseItem.Project = varstr.cprj
		and	WarehouseItem.Item = varstr.item
		selectdo
			o.valm = WarehouseItem.InventoryValuationMethod
		endselect
	end if

	get.inventory.valuation.method = o.valm

End function

function determine.total.line.quantity(varstr.cwar, varstr.cprj, varstr.item)

	o.quantity = 0
	if trim(varstr.cprj)  <>  "" then  
		select	AdjustmentOrders.Quantity  
	   	from	AdjustmentOrders  
	   	where 	AdjustmentOrders.Warehouse  = varstr.cwar  
	   	and  	AdjustmentOrders.Project  = varstr.cprj 
	   	and 	AdjustmentOrders.Item  =  varstr.item 
	   	and	AdjustmentOrders.SerialNumber  <>  ""  
	   	selectdo  
	   		o.quantity  =  o.quantity  +  AdjustmentOrders.Quantity  
	   	endselect  
	else  
		select	AdjustmentOrders.Quantity  
	   	from	AdjustmentOrders  
	   	where 	AdjustmentOrders.Warehouse  =  varstr.cwar
	   	and 	AdjustmentOrders.Item  =  varstr.item  
	   	and  	AdjustmentOrders.SerialNumber  <>  ""  
	   	selectdo
	   		if AdjustmentOrders.Project  =  "" then  
				o.quantity  =  o.quantity  +  AdjustmentOrders.Quantity  
			end if
	   	endselect  
	end if
	determine.total.line.quantity = o.quantity
End Function
:FUNC:END
:TEXT:

:TEXT:END
