FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tc
:TCMOD:com
:TFLNO:100
:FUNC:START
#include	"itcmcs0095"



|#201931.sn

function	 create.bps.for.delivery.adresses()   
{
	string	l.adress.key(9)


	if bcstc000.bpda = tcyesno.no then		|#209387.sn
		return
	endif						|#209387.en


	hold.tccom100.bpid = var.tccom100.bpid
	hold.tccom010.cadr = var.tccom010.cadr
	hold.tccom111.cadr = var.tccom111.cadr
	hold.tccom110.ccnt = var.tccom110.ccnt

	select	tccom013.*
	from	tccom013
	where	tccom013._index1 = {:tccom010.cuno}
	selectdo
		|* build id for new business partner. E.g cuno = "   ABC"; cdel = "  1"
		|* bpid will be: "ABC     1". cuno is shifted left, cdel not. Reasons for this:
		|* - minimize risks for duplicates,
		|* - maxime ease of use when doing a Find in session tccom1117m000
		|*. NB If this logic is changed, also change migration object tccom117. 
		var.tccom100.bpid = ""
		var.tccom100.bpid(1;6) = shiftl$(tccom013.cuno)
		var.tccom100.bpid(7;3) = tccom013.cdel

		|* determine adress codes
		l.adress.key = ""
		l.adress.key(1;6) = tccom013.cuno 
		l.adress.key(7;3) = tccom013.cdel 
		if get.addresses("tccom013", l.adress.key, o.mess) then  
 	 	 	var.tccom010.cadr =  ""                                                                                                                                                                                                                                                                                                                                                                                                    
			var.tccom111.cadr = ""
 		 else  
			var.tccom010.cadr =  bcstc004.cadr  
			var.tccom111.cadr =  bcstc004.cadr
	 	 endif 	 	

		|* new bp's (for delivery adress) do not have a contact code
		var.tccom110.ccnt = ""

		|* create general business partner
		dump 1

		|* create Sold to Role
		dump3

	endselect
	
	var.tccom100.bpid = hold.tccom100.bpid
	var.tccom010.cadr = hold.tccom010.cadr
	var.tccom111.cadr = hold.tccom111.cadr
	var.tccom110.ccnt = hold.tccom110.ccnt
}

|#201931.en


function create.default.parent.bp(		|#200003.sn
		ref	domain	bcstc.bpid	o.dpbp)
{

	|**************************************************************
	|* This functions creates and returns de default parent business partner.
	|* The code of the default parent (target format)  is defined in bcstc000 
	|* Only tccom100 will be created (using dump13).
	|**************************************************************
	
	|* early return if def. parent is not defined 
	if isspace(bcstc000.dpbp) then
		o.dpbp = ""
		return
	else
		o.dpbp = bcstc000.dpbp
	endif
	
	|* make sure that name is filled
	if isspace(bcstc000.nama) then
		bcstc000.nama = "Default Parent"
	endif

	
	|* get adress code of company (via mapping table bcst004)
	 if get.addresses("tccom000", edit$(hold.cmpnr, "999"), o.mess) then  
 	 	 var.tccom010.cadr =  ""                                                                                                                                                                                                                                                                                                                                
 	 else  
 	 	 var.tccom010.cadr =  bcstc004.cadr  
 	 endif 	 	

	|* language and currency are read from tccom000. 
	|* this record is already current; will be used in dump. 
	|*  no furthur action required here

	|* all other fields will be empy or default (dump)
	  
	dump 13
}						|#200003.en
	



function add.business.partner.to.list(domain bcstc.bpid i.business.partner)	|#800-141749.sn
{
        get.next.code.depth(bp.code.depth)
        bp.code.list(1, bp.code.depth) = i.business.partner
}									|#800-141749.en

function sort.bp.code.list()				|#800-141749.sn
{
	long 	rt

	rt = qss.sort(bp.code.list, sorted.bp.code.def, bp.code.depth)

        	if rt <> 0 then
                bp.code.depth = 0
        	endif
}								|#800-141749.en

function get.next.code.depth(REF long  i)				|#800-141749.sn
{
                long    rt
        static  long    already.allocated
        static  long    allocated.length

        i = i + 1

        if not already.allocated or i > allocated.length then
                if not already.allocated then
                        allocated.length = MEMORY_ALLOCATION_SIZE
                        already.allocated = true
                else
                        allocated.length = allocated.length + MEMORY_ALLOCATION_SIZE
                endif

                rt = alloc.mem(bp.code.list, bp.code.length, allocated.length)
        endif
}								|#800-141749.en

function define.length.and.search.def()				|#800-141749.sn
{
	long	dummy.convert

        rdi.domain.string("bcstc.bpid", bp.code.length, dummy.convert)

        qss.start(sorted.bp.code.def, 1, 1)
        qss.way(sorted.bp.code.def, 1, QSS.UP)
        qss.type(sorted.bp.code.def, 1, DB.STRING)
        qss.length(sorted.bp.code.def, 1, bp.code.length)
}								|#800-141749.en

function domain tcbool bp.code.in.sorted.list(domain bcstc.bpid i.bp.code)	|#800-141749.sn
{
	long ret
	if bp.code.depth = 0 then
		return(false)
	endif

	ret = qss.search(QSS.EQUAL+QSS.SRC.IS.SORTED, i.bp.code,
			 bp.code.list, sorted.bp.code.def,
			 bp.code.depth)

	if ret > 0 then
		return(true)
	endif
	return(false)
}								|#800-141749.en

								|#800-142237.sn
function domain tcbool purchase.contract.or.order.found(domain tcsuno i.suno)
{
	|* check for purchase contract present
	select	tdpur300.cono, tdpur300.suno
	from	tdpur300
	where	tdpur300._index2 = {:i.suno}
	as set with 1 rows
	selectdo
		return(true)
	endselect

	|* check for purchase orders present
	select 	tdpur040.orno, tdpur040.suno
	from	tdpur040
	where	tdpur040._index2 = {:i.suno}
	as set with 1 rows
	selectdo
		return(true)
	endselect
	
	return(false)
}								|#800-142237.en


|#FBU.sn
function get.mstm.docm()
{
	var.mstm = ""
	var.docm = ""

	select tfacp316.mstm:var.mstm
	from  tfacp316
	where tfacp316._index1 = {:tccom020.suno}
	selectdo
	endselect	 

	select tfacp262.suno,tfacp262.docm:var.docm
	from  tfacp262
	where tfacp262._index1 = {:tccom020.suno}
	selectdo
	endselect	 
}
								|#FBU.en
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tc
:TCMOD:mcs
:TFLNO:010
:FUNC:START
function void read.tccom999.bnch()
{
	select	tccom999.bnch
	from	tccom999
	where	tccom999._index1 = {1}
	as set with 1 rows
	selectdo
	endselect
}
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:acp
:TFLNO:005
:FUNC:START
function void convert.kind.of.transaction(
		domain	tfacp.tran	org.transaction.type,
	ref	long			conv.transaction.type)
{
	conv.transaction.type = 0

	on case org.transaction.type
	case tfacp.tran.advance:
		conv.transaction.type = target(tfacp.tran.advance)
		|* Advance Payments-Tangible Assets
		break
	case tfacp.tran.real.curr.prof:
		conv.transaction.type = target(tfacp.tran.real.curr.prof)
		|* Realized Currency Profit
		break
	case tfacp.tran.real.curr.loss:
		conv.transaction.type = target(tfacp.tran.real.curr.loss)
		|* Realized Currency Loss
		break
	case tfacp.tran.not.real.curr.p:
		conv.transaction.type = target(tfacp.tran.not.real.curr.p)
		|* Unrealized Currency Profit
		break
	case tfacp.tran.not.real.curr.l:
		conv.transaction.type = target(tfacp.tran.not.real.curr.l)
		|* Unrealized Currency Loss
		break	
	case tfacp.tran.payment.diff:
		conv.transaction.type = target(tfacp.tran.payment.diff)
		|* Payment Differences
		break
	case tfacp.tran.discount:
		conv.transaction.type = target(tfacp.tran.discount)
		|* Discount
		break
	case tfacp.tran.surcharge:
		conv.transaction.type = target(tfacp.tran.surcharge)
		|* Late Payment Surcharge
		break
	case tfacp.tran.inv.receipts:
		conv.transaction.type = target(tfacp.tran.inv.receipts)
		|* Invoice Receipts
		break
	case tfacp.tran.anticipated:
		conv.transaction.type = target(tfacp.tran.anticipated)
		|* Anticipated Payments
		break
	case tfacp.tran.deductions:
		conv.transaction.type = target(tfacp.tran.deductions)
		|* Deductions Antipated Payments
		break
	case tfacp.tran.net.advance:
		conv.transaction.type = target(tfacp.tran.net.advance)
		|* Nett Advanced Payments-Tangible Assets
		break
	case tfacp.tran.gross.advance:	
		conv.transaction.type = target(tfacp.tran.gross.advance)
		|* Gross Advanced Payments-Tangible Assets
		break
	case tfacp.tran.price.diff:
		conv.transaction.type = target(tfacp.tran.price.diff)
		|* Price Differences
		break
	case tfacp.tran.unall.payment:
		conv.transaction.type = target(tfacp.tran.unall.payment)
		|* Unallocated Payments
		break
	case tfacp.tran.advance.intang:				|#200511.sn
		conv.transaction.type = target(tfacp.tran.advance.intng)
		|* Advance Payments-Intangible Assets
		break
	case tfacp.tran.gross.adv.intan:
		conv.transaction.type = target(tfacp.tran.gross.adv.intng)
		|* Gross Advance Payments-Intangible Assets
		break
	case tfacp.tran.net.adv.intang:
		conv.transaction.type = target(tfacp.tran.net.adv.intng)
		|* Net Advance Payments-Intangible Assets
		break
	case tfacp.tran.adv.inventory:
		conv.transaction.type = target(tfacp.tran.adv.inventory)
		|* Advance Payments-Inventory
		break
	case tfacp.tran.net.adv.invent:
		conv.transaction.type = target(tfacp.tran.net.adv.invent)
		|* Net Advance Payments-Inventories
		break
	case tfacp.tran.gross.adv.inven:
		conv.transaction.type = target(tfacp.tran.gross.adv.inven)
		|* Gross Advance Payments-Inventories
		break
	case tfacp.tran.advance.other:
		conv.transaction.type = target(tfacp.tran.advance.other)
		|* Advance Payments-Other Assets
		break
	case tfacp.tran.net.adv.other:
		conv.transaction.type = target(tfacp.tran.net.adv.other)
		|* Net Advance Payments-Other Assets
		break
	case tfacp.tran.gross.adv.other:
		conv.transaction.type = target(tfacp.tran.gross.adv.other)
		|* Gross Advance Payments-Other Assets
		break						|#200511.en
	endcase
}

function void add.defaults.new.type.of.transactions()
{
|* For each Type of Transaction that is new compared to BaanIV a record is added to tfacp005.
|* This is consistent with adding ledger accounts for a financial business partner group in Baan 6. 
|* The dimension types are filled if in the group  parameters the Dimension Used is set to yes.

	set.default.dimensions(
		var.tfacp005.typ1,
		var.tfacp005.typ2,
		var.tfacp005.typ3,
		var.tfacp005.typ4,
		var.tfacp005.typ5)
	
	var.tfacp005.tran = target(tfacp.tran.commissions)
	|* Commission Invoice Accrual
	dump 3
	
|	var.tfacp005.tran = target(tfacp.tran.advance.intng)	|#200511.so
|	|* Advance Payments Intangible Assets 
|	dump 3
|	
|	var.tfacp005.tran = target(tfacp.tran.net.adv.intng)
|	|* Nett Advance Payments Intangible Assets 
|	dump 3
|	
|	var.tfacp005.tran = target(tfacp.tran.gross.adv.intng)
|	|* Gross Advance Payments Intangible Assets 
|	dump 3
|	
|	var.tfacp005.tran = target(tfacp.tran.adv.inventory)
|	|* Advance Payments Inventory
|	dump 3
|	
|	var.tfacp005.tran = target(tfacp.tran.net.adv.invent)
|	|* Nett Advance Payments Inventory
|	dump 3
|	
|	var.tfacp005.tran = target(tfacp.tran.gross.adv.inven)
|	|* Gross Advance Payments Inventory
|	dump 3
|	
|	var.tfacp005.tran = target(tfacp.tran.advance.other)
|	|* Advance Payments-Other Assets
|	dump 3
|	
|	var.tfacp005.tran = target(tfacp.tran.net.adv.other)
|	|* Net Advance Payments- Other Assets
|	dump 3
|	
|	var.tfacp005.tran = target(tfacp.tran.gross.adv.other)
|	|* Gross Advance Payments- Other Assets
|	dump 3							|#200511.eo
	
	var.tfacp005.tran = target(tfacp.tran.doc.issued)
	|* Document Issued
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.to.bp)
	|* Document Sent to Business Partner
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.received)
	|* Document Received
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.payable)
	|* Document Payable
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.accepted)
	|* Document Accepted/Sent
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.matured)
	|* Document Matured
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.cancelled)
	|* Document Canceled
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.dishonored)
	|* Document Dishonored
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.paid)
	|* Document Paid
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.endorsed)
	|* Document Endorsed/Discounted/Collateral
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.doc.void)
	|* Document Void
	dump 3
	
	var.tfacp005.tran = target(tfacp.tran.adunal.ant.py)
	|* Anticipate Advance/Unallocated Payment
	dump 3
}	

function void set.default.dimensions(
	ref	domain	tfgld.dimn	o.dimension.type.1,
	ref	domain	tfgld.dimn	o.dimension.type.2,
	ref	domain	tfgld.dimn	o.dimension.type.3,
	ref	domain	tfgld.dimn	o.dimension.type.4,
	ref	domain	tfgld.dimn	o.dimension.type.5)
{
	domain	tcncmp 		group.company

	domain	tcyesno		dimension.type.1
	domain	tcyesno		dimension.type.2
	domain	tcyesno		dimension.type.3
	domain	tcyesno		dimension.type.4
	domain	tcyesno		dimension.type.5
	
	o.dimension.type.1 = 0
	o.dimension.type.2 = 0
	o.dimension.type.3 = 0
	o.dimension.type.4 = 0
	o.dimension.type.5 = 0

	select	tfgld004.gcmp:group.company
	from	tfgld004
	where	tfgld004._index1 = {1}
	as set with 1 rows
	selectdo
	endselect

	select	tfgld003.dim1:dimension.type.1,
		tfgld003.dim2:dimension.type.2,
		tfgld003.dim3:dimension.type.3,
		tfgld003.dim4:dimension.type.4,
		tfgld003.dim5:dimension.type.5
	from	tfgld003
	where	tfgld003._index1 = {1}
	and	tfgld003._compnr = :group.company
	as set with 1 rows
	selectdo
		if dimension.type.1 = tcyesno.yes then
			o.dimension.type.1 = 1
		endif	
		if dimension.type.2 = tcyesno.yes then
			o.dimension.type.2 = 2
		endif	
		if dimension.type.3 = tcyesno.yes then
			o.dimension.type.3 = 3
		endif	
		if dimension.type.4 = tcyesno.yes then
			o.dimension.type.4 = 4
		endif	
		if dimension.type.5 = tcyesno.yes then
			o.dimension.type.5 = 5
		endif	
	endselect	
}
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:cmg
:TFLNO:002
:FUNC:START
function fill.serv()
{
	var.tfcmg002.serv = tcyesno.no

	select  tfcmg118.*
	from    tfcmg118, tfcmg002
	where tfcmg118.rept = tfcmg.rept.service
	and     tfcmg118.reas = :tfcmg002.reas
	selectdo
	         var.tfcmg002.serv = tcyesno.yes
	endselect	

}
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:cmg
:TFLNO:101
:FUNC:START
function domain tcbool standing.is.advance()
{

	select	tfcmg104.*
	from	tfcmg104 
	where   tfcmg104._index1 = {:tfcmg101.suno,:tfcmg101.ninv}
	and	tfcmg104.post = tfcmg.post.advance
	order by tfcmg104._index1
	as set with 1 rows
	selectdo 
		return(true)
	endselect

	return(false)
}

				|FBU.sn
function fill.adty()
{
	select tfcmg295.adty:var.tfcmg101.adty
	from  tfcmg295, tfcmg101
	where tfcmg295._index1 = {:tfcmg101.btno,
				      :tfcmg101.suno,
				      :tfcmg101.comp,
				      :tfcmg101.tadv,
				      :tfcmg101.ttyp,
				      :tfcmg101.ninv,
				      :tfcmg101.srno}
	selectdo
	endselect

}

				|FBU.en
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:cmg
:TFLNO:104
:FUNC:START
|FBU.sn
function fill.adty()
{
	select tfcmg297.adty:var.tfcmg104.adty
	from  tfcmg297, tfcmg104
	where tfcmg297._index1 = {:tfcmg104.suno,:tfcmg104.orno}
	selectdo
	endselect

}

				|FBU.en
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:cmg
:TFLNO:111
:FUNC:START
function get.rate.date.and.rate.type.acp.record()
{
	 select 	 tfacp200.docd  
	 from 	 tfacp200  
	 where 	 tfacp200._index1 =  {:tfcmg111.ttyp, :tfcmg111.docn, :tfcmg111.srno,"",0,0}  
	 as set with 1 rows  
	 selectdo  
	 	 var.str.rdin =  utc (tfacp200.docd,0)  
	 	 var.str.rtin =  var.str.pur.rtyp  
	 selectempty  
	 	 var.str.rdin =  utc.default  
	 	 var.str.rtin =  var.str.pur.rtyp  
	 endselect  
}

function get.rate.date.and.rate.type.acr.record()
{
	 select 	 tfacr200.docd  
	 from 	 tfacr200  
	 where 	 tfacr200._index1 =  {:tfcmg111.ttyp, :tfcmg111.docn, :tfcmg111.srno,"",0,0}  
	 as set with 1 rows  
	 selectdo  
		 var.str.rdin =  utc (tfacr200.docd,0)  
	 	 var.str.rtin =  var.str.sls.rtyp  
	 selectempty  
	 	 var.str.rdin =  utc.default  
	 	 var.str.rtin =  var.str.sls.rtyp  
	 endselect  
}

					|FBU.sn
function fill.adty()
{
	select tfcmg296.adty:var.tfcmg111.adty
	from  tfcmg296, tfcmg111
	where tfcmg296._index1 = {:tfcmg111.bank,
				      :tfcmg111.tdoc,
				      :tfcmg111.pdoc,
				      :tfcmg111.cono,
				      :tfcmg111.tant,
				      :tfcmg111.cuno,
				      :tfcmg111.suno,
				      :tfcmg111.ttyp,
				      :tfcmg111.docn,
				      :tfcmg111.srno }
	selectdo
	endselect

}

				|FBU.en
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:cmg
:TFLNO:204
:FUNC:START
|FBU.sn
function fill.adty()
{
	select tfcmg294.adty:var.tfcmg204.adty
	from  tfcmg294, tfcmg204
	where tfcmg294._index1 = {:tfcmg204.year,
				      :tfcmg204.btno,
				      :tfcmg204.ttyp,
				      :tfcmg204.docn,
				      :tfcmg204.lino}
				      
	selectdo
	endselect

}

				|FBU.en
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:gld
:TFLNO:008
:FUNC:START
function void read.dimensions.used(				|#210751.sn
	ref	domain	tcyesno		o.dimension1.used,
	ref	domain	tcyesno		o.dimension2.used,
	ref	domain	tcyesno		o.dimension3.used,
	ref	domain	tcyesno		o.dimension4.used,
	ref	domain	tcyesno		o.dimension5.used)
{
	|* Initialize
	o.dimension1.used = empty
	o.dimension2.used = empty
	o.dimension3.used = empty
	o.dimension4.used = empty
	o.dimension5.used = empty
	
	select	tfgld003.dim1:o.dimension1.used,
		tfgld003.dim2:o.dimension2.used, 
		tfgld003.dim3:o.dimension3.used, 
		tfgld003.dim4:o.dimension4.used, 
		tfgld003.dim5:o.dimension5.used 
	from	tfgld003
	as set with 1 rows
	selectdo
	endselect
}								|#210751.en

function void set.attributes.non.integration.account()
{
	if tfgld008.atyp =  tfgld.atyp.profitloss then 
	 	 if tfgld008.subl >  0 then  
	 	 	 var.tfgld008.alat =  target(tfgld.atat.primary)
			 |* Primary 
	 	 else  
	 	 	 if tfgld008.dbcr =  tfgld.dbcr.debit then  
	 	 	 	 var.tfgld008.alat =
				 	target(tfgld.atat.sec.debit) 
				 	|* Secondary Debit
	 	 	 else  
	 	 	 	 var.tfgld008.alat = 
				 	target(tfgld.atat.sec.credit) 
				   	|* Secondary Credit
	 	 	 endif  
	 	 endif  
	 else  
	 	 var.tfgld008.alat =  target(tfgld.atat.not.applicable)
		 	|* Not Applicable
	 endif
  
	 if tfgld008.iprj =  empty then  
	  	 var.tfgld008.iprj =  target(tfgld.intr.not.applicable)	
		 			|* Not Applicable 
	 else  
	 	if (etol (tfgld008.iprj) <  7) and (tfgld008.iprj <> empty) then
		|* Transportation enums are expired	
	 	 	 var.tfgld008.iprj =  etol(tfgld008.iprj)  
	 	else  
	 	 	 var.tfgld008.iprj =  target(tfgld.intr.not.applicable)	
			 			|* Not Applicable
	 	endif  
	 endif  

	if tfgld008.subl > 0 then
		set.value.all.dimensions(
			tfgld.dopt.no,
	 		var.tfgld008.dim1,
	 		var.tfgld008.dim2,
	 		var.tfgld008.dim3,
	 		var.tfgld008.dim4,
	 		var.tfgld008.dim5)
	else
		if account.is.interim.account(tfgld008.leac) or
		   account.is.control.account(tfgld008.leac) then
|			set.value.all.dimensions(		|#210751.so
|				tfgld.dopt.optional,
|	 			var.tfgld008.dim1,
|	 			var.tfgld008.dim2,
|	 			var.tfgld008.dim3,
|	 			var.tfgld008.dim4,
|				var.tfgld008.dim5)		|#210751.eo
			|* Add dimension ranges by ledger account (if needed)
			if dimension1.used = tcyesno.yes then	|#210751.sn
	 			var.tfgld008.dim1 = tfgld.dopt.optional 
								|#210751.en
				add.dimension.range.by.ledger.account(
					tfgld008.leac,
					1)
			else					|#210751.sn
	 			var.tfgld008.dim1 = tfgld.dopt.no 
			endif					|#210751.en
			if dimension2.used = tcyesno.yes then	|#210751.sn
	 			var.tfgld008.dim2 = tfgld.dopt.optional 
								|#210751.en
				add.dimension.range.by.ledger.account(
					tfgld008.leac,
					2)
			else					|#210751.sn
	 			var.tfgld008.dim2 = tfgld.dopt.no 
			endif					|#210751.en
			if dimension3.used = tcyesno.yes then	|#210751.sn
	 			var.tfgld008.dim3 = tfgld.dopt.optional 
								|#210751.en
				add.dimension.range.by.ledger.account(
					tfgld008.leac,
					3)
			else					|#210751.sn
	 			var.tfgld008.dim3 = tfgld.dopt.no 
			endif					|#210751.en
			if dimension4.used = tcyesno.yes then	|#210751.sn
	 			var.tfgld008.dim4 = tfgld.dopt.optional 
								|#210751.en
				add.dimension.range.by.ledger.account(
					tfgld008.leac,
					4)
			else					|#210751.sn
	 			var.tfgld008.dim4 = tfgld.dopt.no 
			endif					|#210751.en
			if dimension5.used = tcyesno.yes then	|#210751.sn
	 			var.tfgld008.dim5 = tfgld.dopt.optional 
								|#210751.en
				add.dimension.range.by.ledger.account(
					tfgld008.leac,
					5)
			else					|#210751.sn
	 			var.tfgld008.dim5 = tfgld.dopt.no 
			endif					|#210751.en

		else
			var.tfgld008.dim1 = tfgld008.dim1
			var.tfgld008.dim2 = tfgld008.dim2
			var.tfgld008.dim3 = tfgld008.dim3
			var.tfgld008.dim4 = tfgld008.dim4
			var.tfgld008.dim5 = tfgld008.dim5
		endif	

	endif	
	 
	 if tfgld008.ifas =  empty then  
	  	 var.tfgld008.ifas =  target(tfgld.ifas.not.applicable)
		 			|* Not Applicable
	 else  
	  	 var.tfgld008.ifas =  etol(tfgld008.ifas)  
	 endif  

	if tfgld008.cuac = tcyesno.yes then			|#148329.sn
		 var.tfgld008.dmsq = get.default.matching.sequence(
		 			tfgld008.leac)
	else
		 var.tfgld008.dmsq = 0
	endif							|#148329.en
}

function void set.common.attributes()
{
	 if (tfgld008.leac =  tfgld004.clac) or 
	    (tfgld008.leac =  tfgld004.clcl) then  
	 	 var.tfgld008.icur =  tcicur.not.required  
	 else  
	 	 var.tfgld008.icur =  tfgld008.icur  
	 endif
 
	 if tfgld008.dbcr =  empty then  
	 	 var.tfgld008.dbcr =  tfgld.dbcr.debit 

	 else
		 var.tfgld008.dbcr = tfgld008.dbcr 
	 endif

}

function domain tfgld.atyp get.account.type(domain tfgld.leac i.account)
{
	domain	tfgld.atyp	account.type

	select	tfgld008.atyp:account.type
	from	tfgld008
	where	tfgld008._index1 = {:i.account}
	as set with 1 rows
	selectdo
	endselect

	return(account.type)
}

function void set.value.all.dimensions(
		domain	tfgld.dopt	i.dimension.value,
	ref	domain	tfgld.dopt	o.dimension.1,
	ref	domain	tfgld.dopt	o.dimension.2,
	ref	domain	tfgld.dopt	o.dimension.3,
	ref	domain	tfgld.dopt	o.dimension.4,
	ref	domain	tfgld.dopt	o.dimension.5)
{
	o.dimension.1 = i.dimension.value
	o.dimension.2 = i.dimension.value
	o.dimension.3 = i.dimension.value
	o.dimension.4 = i.dimension.value
	o.dimension.5 = i.dimension.value
}

function domain tcbool account.is.interim.account(
		domain	tfgld.leac	i.account)
{
		domain	tfgld.srno	dummy.srno

	select	tfgld004.srno:dummy.srno
	from	tfgld004
	where	tfgld004.srno = 1
	and	(tfgld004.fpor = :i.account or
		 tfgld004.fpnw = :i.account or
		 tfgld004.rpor = :i.account or
		 tfgld004.rpnw = :i.account )
	as set with 1 rows
	selectdo
		return(true)
	endselect

	return(false)
}	

function domain tcbool account.is.control.account(
		domain	tfgld.leac	i.account)
{
		domain	tfgld.leac	dummy.account

	select	tfacp005.leac:dummy.account
	from	tfacp005
	where	tfacp005.leac = :i.account
	selectdo
		return(true)
	endselect

	select	tfacr005.leac:dummy.account
	from	tfacr005
	where	tfacr005.leac = :i.account
	selectdo
		return(true)
	endselect

	return(false)
}

function void add.dimension.range.by.ledger.account(
		domain	tfgld.leac	i.account,
		domain	tfgld.srno	i.dimension)
{
		domain	tfgld.leac	dummy.account

	select	tfgld009.leac:dummy.account
	from	tfgld009
	where	tfgld009._index1 = {:i.account, :i.dimension}
	as set with 1 rows
	selectdo
	selectempty
		var.tfgld009.leac = i.account
		var.tfgld009.dtyp = i.dimension
		var.tfgld009.fdim = ""
		set.fmax(var.tfgld009.udim)
		dump 5
	endselect
}

function domain tfgld.seri get.default.matching.sequence(	|#148329.sn
		domain	tfgld.leac	i.account)
{
		domain	tfgld.seri	sequence

	|* Initialize
	sequence = 0

	select	tfgld198.sera:sequence
	from	tfgld198
	where	tfgld198._index1 = {:i.account}
	and	tfgld198.stnd = tcyesno.yes
	as set with 1 rows
	selectdo
	endselect

	return(sequence)
}								|#148329.en
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:gld
:TFLNO:102
:FUNC:START
function  long fill.adty.from.tfcmg294() 
{
	select tfcmg294.*
	from  tfcmg294
	where tfcmg294.year = :tfgld102.year
	and     tfcmg294.ttyp = :tfgld102.ttyp 
	and    tfcmg294.docn = :tfgld102.docn
	and    tfcmg294.lino = :tfgld102.lino 
	order by tfcmg294._index1
	as set with 1 rows
	selectdo
		return(etol(tfcmg294.adty))
	endselect

	return(0)
}

function  long fill.adty.from.tfcmg295() 
{
	select tfcmg101.*,tfcmg295.*
	from  tfcmg101,tfcmg295
	where tfcmg101.tadv = tfcmg.tadv.advance
	and   tfcmg101.ptyp = :tfgld102.ttyp
	and   tfcmg101.pdoc  = :tfgld102.docn
	and    tfcmg295._index1 = tfcmg101._index1 
	order by tfcmg295._index1
	as set with 1 rows
	selectdo
		return(etol(tfcmg295.adty))
	endselect

	return(0)

}
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:gld
:TFLNO:106
:FUNC:START
function  long fill.adty.from.tfcmg294() 
{
	select tfcmg294.*
	from  tfcmg294
	where tfcmg294.year = :tfgld106.oyer
	and    tfcmg294.ttyp = :tfgld106.otyp 
	and    tfcmg294.docn = :tfgld106.odoc
	and    tfcmg294.lino = :tfgld106.olin 
	order by tfcmg294._index1
	as set with 1 rows
	selectdo
		return(etol(tfcmg294.adty))
	endselect

	return(0)
}

function  long fill.adty.from.tfcmg295() 
{
	select tfcmg101.*,tfcmg295.*
	from  tfcmg101,tfcmg295
	where tfcmg101.tadv = tfcmg.tadv.advance
	and    tfcmg101.ptyp = :tfgld106.otyp 
	and    tfcmg101.pdoc = :tfgld106.odoc
	and    tfcmg295._index1 = tfcmg101._index1 
	order by tfcmg295._index1
	as set with 1 rows
	selectdo
		return(etol(tfcmg295.adty))
	endselect

	return(0)

}
:FUNC:END
:TEXT:

:TEXT:END
FUNC160
:MPRF:28
:VERS:B4fb
:RELE:61
:CUST:sy30
:TCPAC:tf
:TCMOD:gld
:TFLNO:116
:FUNC:START
function void get.tax.information.from.transaction(  
		domain	tcncmp		i.company,
		domain 	tfgld.ttyp 	i.transaction.type,  
 		domain	tfgld.docn	i.document,  
 		domain	tfgld.lino	i.line.number,  
 		domain	tfgld.serl	i.sequence.number,  
 		domain	tfgld.srno	i.background.number,  
 	ref	domain	tcccty	 	o.tax.country,
	ref	domain 	tccvat		o.tax.code)
{
		domain	tfgld.year	year
		domain	tfgld.btno	batch

	o.tax.country = ""
	o.tax.code = ""
	year = 0
	batch = 0
	
	if transaction.is.finalized(
		i.transaction.type,
		i.document,
		year,
		batch) then
		read.tax.info.finalized.transactions(
			i.transaction.type,  
 			i.document,  
 			i.line.number,  
 			i.sequence.number,  
 			i.background.number,  
 			o.tax.country,
			o.tax.code)
	else	
		read.tax.info.non.finalized.transactions(
			i.company,
			year,
			batch,
			i.transaction.type,  
 			i.document,  
 			i.line.number,  
 			i.sequence.number,  
 			i.background.number,  
 			o.tax.country,
			o.tax.code)
	endif
}

function domain tcbool transaction.is.finalized(
		domain 	tfgld.ttyp 	i.transaction.type,  
 		domain	tfgld.docn	i.document,  
	ref	domain	tfgld.year	o.year,
	ref	domain	tfgld.btno	o.batch)
{
	static	domain 	tfgld.ttyp 	hold.transaction.type
 	static	domain	tfgld.docn	hold.document
	static	domain	tcbool		hold.return
	static	domain	tfgld.year	hold.year
	static	domain	tfgld.btno	hold.batch
	
	
	if i.transaction.type = hold.transaction.type and
	   i.document = hold.document then
	   	o.year = hold.year
		o.batch = hold.batch
	   	return(hold.return)
	endif

	hold.transaction.type = i.transaction.type
	hold.document = i.document
	
	select	tfgld018.trun:o.year,
		tfgld018.btno:o.batch,
		tfgld018.trun
	from	tfgld018
	where	tfgld018._index1 = {:i.transaction.type, :i.document}
	as set with 1 rows
	selectdo
		if tfgld018.trun <> 0 then
			hold.return = true
		else
			hold.return = false
		endif	
		hold.year = o.year
		hold.batch = o.batch
		return(hold.return)
	endselect

	|* This statement must not be reached
	hold.return = false
	hold.batch = 0
	return(false)
}

function void read.tax.info.finalized.transactions(  
		domain 	tfgld.ttyp 	i.transaction.type,  
 		domain	tfgld.docn	i.document,  
 		domain	tfgld.lino	i.line.number,  
 		domain	tfgld.serl	i.sequence.number,  
 		domain	tfgld.srno	i.background.number,  
 	ref	domain	tcccty	 	o.tax.country,
	ref	domain 	tccvat		o.tax.code)
{
	o.tax.country = ""
	o.tax.code = ""

	select	tfgld106.ccty:o.tax.country, tfgld106.cvat:o.tax.code
	from	tfgld106
	where	tfgld106._index1 = {	:i.transaction.type,  
 					:i.document,  
			 		:i.line.number,  
 					:i.sequence.number,  
 					:i.background.number}
	as set with 1 rows
	selectdo
	endselect
}	

function void read.tax.info.non.finalized.transactions(  
		domain	tcncmp		i.company,
		domain	tfgld.year	i.year,
		domain	tfgld.btno	i.batch,
		domain 	tfgld.ttyp 	i.transaction.type,  
 		domain	tfgld.docn	i.document,  
 		domain	tfgld.lino	i.line.number,  
 		domain	tfgld.serl	i.sequence.number,  
 		domain	tfgld.srno	i.background.number,  
 	ref	domain	tcccty	 	o.tax.country,
	ref	domain 	tccvat		o.tax.code)
{
	o.tax.country = ""
	o.tax.code = ""

	select	tfgld102.ccty:o.tax.country, tfgld102.cvat:o.tax.code
	from	tfgld102
	where	tfgld102._index1 = {	:i.company,
					:i.year,
					:i.batch,
					:i.transaction.type,  
 					:i.document,  
			 		:i.line.number,  
 					:i.sequence.number,  
 					:i.background.number}
	as set with 1 rows
	selectdo
	endselect
}

function domain tfgld.catg get.category.from.transaction.type(
		domain	tfgld.ttyp	i.transaction.type)
{
		domain	tfgld.catg	category

	category = empty

	select	tfgld011.catg:category
	from	tfgld011
	where	tfgld011._index1 = {:i.transaction.type}
	as set with 1 rows
	selectdo
	endselect

	return(category)
}
:FUNC:END
:TEXT:

:TEXT:END
