<MvCOMMENT>
|
| Miva Merchant v4.x
|
| This file and the source codes contained herein are the property 
| of Miva Corporation.  Use of this file is restricted to the specific 
| terms and conditions in the License Agreement associated with this 
| file.  Distribution of this file or portions of this file for uses
| not covered by the License Agreement is not allowed without a written 
| agreement signed by an officer of Miva Corporation.
| 
| Copyright 1998-2001 Miva Corporation.  All rights reserved.
| http://www.miva.com/
|
| dBase III Database Layer
| $Source: /home/cvs/merchant/Merchant/features/aff/aff_db.mv,v $
|
| Prefix         : MER-ADB-
| Next Error Code: 52   
| Next Text ID   : 26   
|
</MvCOMMENT>

<MvCOMMENT>
|
| Privileges
|
</MvCOMMENT>

<MvFUNCTION NAME = "AFF_Create_Data_Files" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvLOCALIZED NAME = "l.privilege" ID = "MER-ADB-00000">
		<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliates</MvLOCALIZED-TEXT>
	</MvLOCALIZED>
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ Privilege_Insert( 'AFLT', l.privilege ) }">

	<MvLOCALIZED NAME = "l.privilege" ID = "MER-ADB-00001">
		<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate Money</MvLOCALIZED-TEXT>
	</MvLOCALIZED>
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ Privilege_Insert( 'MONY', l.privilege ) }">

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Create_A" PARAMETERS = "" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'Affiliates', 1 ) }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'AffiliateEarnings', 1 ) }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'AffiliatePayouts', 1 ) }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'AffiliateEarningsVoid', 1 ) }">

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Store_Create_B" PARAMETERS = "email" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "Affiliates"
					DATABASE = "{ g._DB_Store_Directory $ 'affil.dbf' }"
					FIELDS = "	id 			NUMBER,
								code		CHAR( 50 ),
								password	CHAR( 40 ),
								lpasseml	CHAR( 254 ),
								site_name	CHAR( 254 ),
								site_url	CHAR( 254 ),
								con_name	CHAR( 254 ),
								email		CHAR( 254 ),
								company		CHAR( 50 ),
								phone		CHAR( 50 ),
								fax			CHAR( 50 ),
								addr		CHAR( 100 ),
								city		CHAR( 50 ),
								state		CHAR( 50 ),
								zip			CHAR( 50 ),
								cntry		CHAR( 50 ),
								hits		NUMBER( 10.4 ),
								percent		NUMBER( 10.2 ),
								flat		NUMBER( 10.2 ),
								lstpay_id	NUMBER,
								lstpay_amt	NUMBER( 10.2 ),
								lstpay_dt	NUMBER,
								lstpay_by	NUMBER,
								balance		NUMBER( 10.4 ),
								status		CHAR( 10 ),
								status_dt	NUMBER,
								status_by	NUMBER,
								session_id  CHAR( 40 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00000', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Affiliates_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Affiliates"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affil_i.mvx' }"
						 EXPRESSION = "{ Affiliates.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00001', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Affiliates"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affil_c.mvx' }"
						 EXPRESSION = "{ toupper( Affiliates.d.code ) }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00002', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "Affiliates"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affil_s.mvx' }"
						 EXPRESSION = "{ Affiliates.d.session_id }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00003', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "Affiliates">
			<MvASSIGN NAME = "g._DB_Store_Affiliates_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AffiliateEarnings"
					DATABASE = "{ g._DB_Store_Directory $ 'affern.dbf' }"
					FIELDS = "	id			NUMBER,
								aff_id 		NUMBER,
								date		NUMBER,
								type		CHAR( 10 ),
								order_id	NUMBER,
								order_amt	NUMBER( 10.2 ),
								percent		NUMBER( 10.2 ),
								amount		NUMBER( 10.4 ),
								void		BOOL,
								void_reasn	CHAR( 250 ),
								void_by		NUMBER,
								adjst_reas	CHAR( 250 ),
								adjst_by	NUMBER,
								payout_id	NUMBER,
								ip_address	CHAR( 50 )">

		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00004', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AffiliateEarnings_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AffiliateEarnings"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affern_i.mvx' }"
						 EXPRESSION = "{ AffiliateEarnings.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00005', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AffiliateEarnings"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affern_a.mvx' }"
						 EXPRESSION = "{ AffiliateEarnings.d.aff_id $ ':' $ padl( AffiliateEarnings.d.date, 10, 0 ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00006', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AffiliateEarnings"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affern_p.mvx' }"
						 EXPRESSION = "{ AffiliateEarnings.d.payout_id $ ':' $ padl( AffiliateEarnings.d.aff_id, 10, 0 ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00007', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AffiliateEarnings">
			<MvASSIGN NAME = "g._DB_Store_AffiliateEarnings_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AffiliatePayouts"
					DATABASE = "{ g._DB_Store_Directory $ 'affpay.dbf' }"
					FIELDS = "	id			NUMBER,
								date		NUMBER,
								amount		NUMBER( 10.2 ),
								count		NUMBER,
								user_id		NUMBER,
								pay_by		NUMBER,
								processed	BOOL,
								proc_by		NUMBER,
								proc_date	NUMBER,
								void		BOOL,
								void_reasn	CHAR( 250 ),
								void_date	NUMBER,
								void_by		NUMBER">

		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00008', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AffiliatePayouts_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AffiliatePayouts"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affpay_i.mvx' }"
						 EXPRESSION = "{ AffiliatePayouts.d.id }"
						 FLAGS = "unique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00009', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AffiliatePayouts"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affpay_d.mvx' }"
						 EXPRESSION = "{ AffiliatePayouts.d.date }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00010', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AffiliatePayouts"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'affpay_u.mvx' }"
						 EXPRESSION = "{ AffiliatePayouts.d.user_id $ ':' $ padl( AffiliatePayouts.d.date, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00011', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AffiliatePayouts">
			<MvASSIGN NAME = "g._DB_Store_AffiliatePayouts_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AffiliateEmail"
				  DATABASE = "{ g._DB_Store_Directory $ 'afileml.dbf' }"
				  FIELDS = "from		CHAR( 254 ),
							cc			CHAR( 254 ),
							subject		CHAR( 254 ),
							header   	MEMO">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00012', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AffiliateEmail_Open" VALUE = 1>

			<MvASSIGN NAME = "AffiliateEmail.d.from" VALUE = "{ l.email }">
			<MvASSIGN NAME = "AffiliateEmail.d.cc" VALUE = "">

			<MvLOCALIZED NAME = "AffiliateEmail.d.subject" ID = "MER-ADB-00002">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Your affiliate password</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvLOCALIZED NAME = "AffiliateEmail.d.header" ID = "MER-ADB-00003">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Here is the Affiliate Account information you requested.</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvADD NAME = "AffiliateEmail">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AffiliateEmail">
			<MvASSIGN NAME = "g._DB_Store_AffiliateEmail_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "AffiliateManage"
				  DATABASE = "{ g._DB_Store_Directory $ 'afilmng.dbf' }"
				  FIELDS = "active 		BOOL,
							useto		BOOL,
							usefrom		BOOL,
							usecc		BOOL,
							from		CHAR( 254 ),
							to		   	CHAR( 254 ),
							cc			CHAR( 254 ),
							subject		CHAR( 254 ),
							header		MEMO">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00013', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AffiliateManage_Open" VALUE = 1>

			<MvASSIGN NAME = "AffiliateManage.d.usefrom" VALUE = "1">
			<MvASSIGN NAME = "AffiliateManage.d.useto" VALUE = "1">
			<MvASSIGN NAME = "AffiliateManage.d.usecc" VALUE = "1">						
			<MvASSIGN NAME = "AffiliateManage.d.from" VALUE = "{ l.email }">
			<MvASSIGN NAME = "AffiliateManage.d.to" VALUE = "{ l.email }">
			<MvASSIGN NAME = "AffiliateManage.d.cc" VALUE = "">

			<MvLOCALIZED NAME = "AffiliateManage.d.subject" ID = "MER-ADB-00004">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">New Affiliate Created</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvLOCALIZED NAME = "AffiliateManage.d.header" ID = "MER-ADB-00005">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">The following affiliate has been created:</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvADD NAME = "AffiliateManage">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AffiliateManage">
			<MvASSIGN NAME = "g._DB_Store_AffiliateManage_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE	NAME = "AffiliateOptions"
					DATABASE = "{ g._DB_Store_Directory $ 'afilopt.dbf' }"
					FIELDS = "	active 		BOOL,
								signup 		CHAR( 10 ),
								hits		NUMBER( 10.4 ),
								percent		NUMBER( 10.2 ),
								pct_slt		CHAR( 10 ),
								flat		NUMBER( 10.2 ),
								terms		MEMO,
								pay_thresh	NUMBER( 10.2 ),
								link_image	CHAR( 254 ),
								link_text	CHAR( 254 )">


		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00014', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AffiliateOptions_Open" VALUE = 1>

			<MvASSIGN NAME = "AffiliateOptions.d.active" VALUE = "">
			<MvASSIGN NAME = "AffiliateOptions.d.signup" VALUE = "A">
			<MvASSIGN NAME = "AffiliateOptions.d.hits" VALUE = "0.00">
			<MvASSIGN NAME = "AffiliateOptions.d.percent" VALUE = "0.00">
			<MvASSIGN NAME = "AffiliateOptions.d.pct_slt" VALUE = "O">
			<MvASSIGN NAME = "AffiliateOptions.d.flat" VALUE = "0.00">
			<MvASSIGN NAME = "AffiliateOptions.d.terms" VALUE = "">
			<MvASSIGN NAME = "AffiliateOptions.d.pay_thresh" VALUE = "0.00">
			<MvASSIGN NAME = "AffiliateOptions.d.link_image" VALUE = "">
			<MvASSIGN NAME = "AffiliateOptions.d.link_text" VALUE = "">

			<MvADD NAME = "AffiliateOptions">
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AffiliateOptions">
			<MvASSIGN NAME = "g._DB_Store_AffiliateOptions_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE	NAME = "AffiliateSession"
					DATABASE = "{ g._DB_Store_Directory $ 'affsess.dbf' }"
					FIELDS = "	session_id	CHAR( 40 ),
								affil_code	CHAR( 50 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00015', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AffiliateSession_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AffiliateSession"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'aff_cod.mvx' }"
						 EXPRESSION = "{ AffiliateSession.d.affil_code }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00050', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "AffiliateSession"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'aff_sid.mvx' }"
						 EXPRESSION = "{ AffiliateSession.d.session_id }"
						 FLAGS = "nounique, ascending, string">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00016', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvCLOSE NAME = "AffiliateSession">
			<MvASSIGN NAME = "g._DB_Store_AffiliateSession_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AFF_Store_Delete" PARAMETERS = "directory">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'oop_line.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'oop_line.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'oop_line.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'oop_line.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'oop_line.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affil.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affil_i.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affil_c.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affil_s.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affern.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affern_i.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affern_a.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affern_p.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affpay.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affpay_i.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affpay_d.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affpay_u.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'afileml.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'afilmng.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'afilopt.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'affsess.dbf' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'aff_sid.mvx' ) }">
		<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'aff_cod.mvx' ) }">
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>
<MvCOMMENT>
|
| Affiliate Packing/Removing
|
</MvCOMMENT>

<MvFUNCTION NAME = "AFF_Store_Pack" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "Affiliates">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00017', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "Affiliates">
				<MvASSIGN NAME = "g._DB_Store_Affiliates_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AffiliateEarnings">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00018', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AffiliateEarnings">
				<MvASSIGN NAME = "g._DB_Store_AffiliateEarnings_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliatePayouts() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AffiliatePayouts">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00019', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AffiliatePayouts">
				<MvASSIGN NAME = "g._DB_Store_AffiliatePayouts_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateOptions() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AffiliateOptions">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00020', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AffiliateOptions">
				<MvASSIGN NAME = "g._DB_Store_AffiliateOptions_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateEmail() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AffiliateEmail">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00021', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AffiliateEmail">
				<MvASSIGN NAME = "g._DB_Store_AffiliateEmail_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateManage() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AffiliateManage">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00022', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AffiliateManage">
				<MvASSIGN NAME = "g._DB_Store_AffiliateManage_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateSession() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "AffiliateSession">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00051', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "AffiliateSession">
				<MvASSIGN NAME = "g._DB_Store_AffiliateSession_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AFF_Store_Close" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ g._DB_Store_Affiliates_Open }">
		<MvCLOSE NAME = "Affiliates">
		<MvASSIGN NAME = "g._DB_Store_Affiliates_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AffiliateEarnings_Open }">
		<MvCLOSE NAME = "AffiliateEarnings">
		<MvASSIGN NAME = "g._DB_Store_AffiliateEarnings_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AffiliateEmail_Open }">
		<MvCLOSE NAME = "AffiliateEmail">
		<MvASSIGN NAME = "g._DB_Store_AffiliateEmail_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AffiliateManage_Open }">
		<MvCLOSE NAME = "AffiliateManage">
		<MvASSIGN NAME = "g._DB_Store_AffiliateManage_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AffiliatePayouts_Open }">
		<MvCLOSE NAME = "AffiliatePayouts">
		<MvASSIGN NAME = "g._DB_Store_AffiliatePayouts_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AffiliateOptions_Open }">
		<MvCLOSE NAME = "AffiliateOptions">
		<MvASSIGN NAME = "g._DB_Store_AffiliateOptions_Open" VALUE = 0>
	</MvIF>

	<MvIF EXPR = "{ g._DB_Store_AffiliateSession_Open }">
		<MvCLOSE NAME = "AffiliateSession">
		<MvASSIGN NAME = "g._DB_Store_AffiliateSession_Open" VALUE = 0>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = 1>
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate Basket/Session management
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_AffiliateSession" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_AffiliateSession_Open }">
		<MvOPEN NAME = "AffiliateSession"	
				DATABASE = "{ g._DB_Store_Directory $ 'affsess.dbf' }"
				INDEXES = "{ g._DB_Store_Directory $ 'aff_sid.mvx, ' $ 
							 g._DB_Store_Directory $ 'aff_cod.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00023', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_AffiliateSession_Open" VALUE = 1>
			<MvFILTER NAME = "AffiliateSession" FILTER = "{ NOT AffiliateSession.d.deleted }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliate_Insert_SessionID" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ _DB_Store_Open_AffiliateSession() }">
		<MvASSIGN NAME = "AffiliateSession.d.session_id" VALUE = "{ l.session_id }">
		<MvASSIGN NAME = "AffiliateSession.d.affil_code" VALUE = "{ g.Affiliate }">

		<MvADD NAME = "AffiliateSession">

		<MvIF EXPR = "{ len( g.Affiliate ) }">
			<MvASSIGN NAME = "l.foo" VALUE = "{ Affiliate_Update_Balance( g.Affiliate, 'hit', '', '' ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = 1>
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliate_Clean_Earnings" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateEarnings() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_a.mvx' }">

		<MvFIND NAME = "AffiliateEarnings" VALUE = "{ l.id $ ':' }">
		<MvWHILE EXPR = "{ ( NOT AffiliateEarnings.d.EOF ) AND ( l.id EQ AffiliateEarnings.d.aff_id ) }">
			<MvDELETE NAME = "AffiliateEarnings">

			<MvFIND NAME = "AffiliateEarnings" VALUE = "{ l.id $ ':' }">
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "1">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliate_Delete_Session" PARAMETERS = "affil_code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateSession() }">
	<MvIF EXPR = "{ l.ok }">
		<MvSETINDEX NAME = "AffiliateSession" INDEXES = "{ g._DB_Store_Directory $ 'aff_cod.mvx, ' $ g._DB_Store_Directory $ 'aff_sid.mvx' }">

		<MvFIND NAME = "AffiliateSession" VALUE = "{ l.affil_code }" EXACT>
		<MvWHILE EXPR = "{ ( NOT AffiliateSession.d.EOF ) AND ( l.affil_code EQ AffiliateSession.d.affil_code ) }">
			<MvDELETE NAME = "AffiliateSession">

			<MvFIND NAME = "AffiliateSession" VALUE = "{ l.affil_code }" EXACT>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "1">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliate_Find_SessionCode" PARAMETERS = "old_code, new_code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateSession() }">
	<MvIF EXPR = "{ l.ok }">
		<MvSETINDEX NAME = "AffiliateSession" INDEXES = "{ g._DB_Store_Directory $ 'aff_cod.mvx, ' $ g._DB_Store_Directory $ 'aff_sid.mvx' }">

		<MvFIND NAME = "AffiliateSession" VALUE = "{ l.old_code }" EXACT>
		<MvWHILE EXPR = "{ ( NOT AffiliateSession.d.EOF ) AND ( l.old_code EQ AffiliateSession.d.affil_code ) }">
			<MvASSIGN NAME = "AffiliateSession.d.affil_code" VALUE = "{ l.new_code }">
			<MvUPDATE NAME = "AffiliateSession">

			<MvFIND NAME = "AffiliateSession" VALUE = "{ l.old_code }" EXACT>
		</MvWHILE>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "1">
</MvFUNCTION>

<MvFUNCTION NAME = "BasketList_Update_Affiliate" PARAMETERS = "session_id, affil_code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateSession() }">
	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "AffiliateSession" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ AffiliateSession.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00006">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00024', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "AffiliateSession.d.affil_code" VALUE = "{ l.affil_code }">
			<MvUPDATE NAME = "AffiliateSession">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Bask_Delete" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateSession() }">

	<MvIF EXPR = "{ l.ok }">
		<MvFIND NAME = "AffiliateSession" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ AffiliateSession.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00007">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00025', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "AffiliateSession">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliate_Create_Order" PARAMETERS = "session_id, total" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() AND _DB_Store_Open_AffiliateSession() AND _DB_Store_Open_AffiliateOptions() }">
		<MvFIND NAME = "AffiliateSession" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ AffiliateSession.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00008">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Basket '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00026', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ len( AffiliateSession.d.affil_code ) AND ( Affiliates.d.status EQ 'Approved' ) }">
				<MvIF EXPR = "{ AffiliateOptions.d.pct_slt EQ 'S' }">
					<MvASSIGN NAME = "l.order_total" VALUE = "{ g.Affiliate_Basket_Total }">
				<MvELSE>
					<MvASSIGN NAME = "l.order_total" VALUE = "{ l.total }">
				</MvIF>

				<MvASSIGN NAME = "l.ok" VALUE = "{ Affiliate_Update_Balance( AffiliateSession.d.affil_code, 'order', l.order_total, Orders.d.id ) }">
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate Opens
|
</MvCOMMENT>

<MvFUNCTION NAME = "_DB_Store_Open_AffiliateOptions" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_AffiliateOptions_Open }">
		<MvOPEN NAME = "AffiliateOptions" DATABASE = "{ g._DB_Store_Directory $ 'afilopt.dbf' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00027', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "AffiliateOptions" FILTER = "{ NOT AffiliateOptions.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_AffiliateOptions_Open" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_AffiliateEmail" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_AffiliateEmail_Open }">
		<MvOPEN NAME = "AffiliateEmail" DATABASE = "{ g._DB_Store_Directory $ 'afileml.dbf' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00028', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "AffiliateEmail" FILTER = "{ NOT AffiliateEmail.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_AffiliateEmail_Open" VALUE = 1>
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_AffiliateManage" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_AffiliateManage_Open }">
		<MvOPEN NAME = "AffiliateManage" DATABASE = "{ g._DB_Store_Directory $ 'afilmng.dbf' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00029', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "AffiliateManage" FILTER = "{ NOT AffiliateManage.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_AffiliateManage_Open" VALUE = 1>
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_Affiliates" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Affiliates_Open }">
		<MvOPEN NAME = "Affiliates" 
				DATABASE = "{ g._DB_Store_Directory $ 'affil.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'affil_c.mvx,' $
					         g._DB_Store_Directory $ 'affil_i.mvx,' $
					         g._DB_Store_Directory $ 'affil_s.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00030', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "Affiliates" FILTER = "{ NOT Affiliates.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_Affiliates_Open" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_AffiliateEarnings" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Open_AffiliateEarnings }">
		<MvOPEN NAME = "AffiliateEarnings" 
				DATABASE = "{ g._DB_Store_Directory $ 'affern.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'affern_a.mvx, ' $
							 g._DB_Store_Directory $ 'affern_p.mvx, ' $
							 g._DB_Store_Directory $ 'affern_i.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00031', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "AffiliateEarnings" FILTER = "{ NOT AffiliateEarnings.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_Open_AffiliateEarnings" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_DB_Store_Open_AffiliatePayouts" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>

	<MvIF EXPR = "{ NOT g._DB_Store_Open_AffiliatePayouts }">
		<MvOPEN NAME = "AffiliatePayouts" 
				DATABASE = "{ g._DB_Store_Directory $ 'affpay.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'affpay_i.mvx, ' $
							 g._DB_Store_Directory $ 'affpay_d.mvx, ' $
							 g._DB_Store_Directory $ 'affpay_u.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00032', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "AffiliatePayouts" FILTER = "{ NOT AffiliatePayouts.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_Open_AffiliatePayouts" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate Filters
|
</MvCOMMENT>

<MvFUNCTION NAME = "_Affiliates_Filter" PARAMETERS = "search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.word" VALUE = 1>
	<MvASSIGN NAME = "g._affiliate_word" INDEX = "{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	<MvWHILE EXPR = "{ g._affiliate_word[ l.word ] }">
		<MvASSIGN NAME = "l.word" VALUE = "{ l.word + 1 }">
		<MvASSIGN NAME = "g._affiliate_word" INDEX = "{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	</MvWHILE>																		   

	<MvASSIGN NAME = "l.filter" VALUE = "( NOT Affiliates.d.deleted )">
	<MvASSIGN NAME = "l.pos" VALUE = 1>
	<MvWHILE EXPR = "{ l.pos LE ( l.word - 1 ) }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ l.filter $ ' AND ( 
			( g._affiliate_word[' $ l.pos $ '] CIN Affiliates.d.code ) OR
			( g._affiliate_word[' $ l.pos $ '] CIN Affiliates.d.site_name ) OR
			( g._affiliate_word[' $ l.pos $ '] CIN Affiliates.d.email ) OR
			( g._affiliate_word[' $ l.pos $ '] CIN Affiliates.d.site_url ) OR
			( g._affiliate_word[' $ l.pos $ '] CIN Affiliates.d.company ) OR
			( g._affiliate_word[' $ l.pos $ '] CIN Affiliates.d.con_name ) OR
			( g._affiliate_word[' $ l.pos $ '] CIN Affiliates.d.addr ) )' }">
		<MvASSIGN NAME = "l.pos" VALUE = "{ l.pos + 1 }">
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.filter }">
</MvFUNCTION>

<MvFUNCTION NAME = "_AffiliatePayouts_Filter" PARAMETERS = "search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.word" VALUE = 1>
	<MvASSIGN NAME = "g._affiliatepayout_word" INDEX = "{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	<MvWHILE EXPR = "{ g._affiliatepayout_word[ l.word ] }">
		<MvASSIGN NAME = "l.word" VALUE = "{ l.word + 1 }">
		<MvASSIGN NAME = "g._affiliatepayout_word" INDEX = "{ l.word }" VALUE = "{ gettoken( l.search, ' ', l.word ) }">
	</MvWHILE>																		   

	<MvASSIGN NAME = "l.filter" VALUE = "( NOT AffiliatePayouts.d.deleted )">
	<MvASSIGN NAME = "l.pos" VALUE = 1>
	<MvWHILE EXPR = "{ l.pos LE ( l.word - 1 ) }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ l.filter $ ' AND ( 
			( g._affiliatepayout_word[' $ l.pos $ '] CIN AffiliatePayouts.d.date_raw ) OR
			( g._affiliatepayout_word[' $ l.pos $ '] CIN AffiliatePayouts.d.amount ) OR
			( g._affiliatepayout_word[' $ l.pos $ '] CIN AffiliatePayouts.d.user_id ) )' }">
		<MvASSIGN NAME = "l.pos" VALUE = "{ l.pos + 1 }">
	</MvWHILE>

	<MvFUNCTIONRETURN VALUE = "{ l.filter }">
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate Inserts
|
</MvCOMMENT>

<MvFUNCTION NAME = "Affiliates_Insert" PARAMETERS = "code, password, lpass, site_name, site_url, con_name, email, company, phone, fax, addr, city, state, zip, cntry, hits, percent, flat, status, session_id"  STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
	
	<MvASSIGN NAME = "l.affil_id" VALUE = 0>

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "Affiliates.d.id" VALUE = "{ StoreKey_Generate( 'Affiliates' ) }">
		<MvASSIGN NAME = "Affiliates.d.code" VALUE = "{ l.code }">
		<MvASSIGN NAME = "Affiliates.d.password" VALUE = "{ l.password }">
		<MvASSIGN NAME = "Affiliates.d.lpasseml" VALUE = "{ l.lpass }">			
		<MvASSIGN NAME = "Affiliates.d.site_name" VALUE = "{ l.site_name }">
		<MvASSIGN NAME = "Affiliates.d.site_url" VALUE = "{ l.site_url }">
		<MvASSIGN NAME = "Affiliates.d.con_name" VALUE = "{ l.con_name }">
		<MvASSIGN NAME = "Affiliates.d.email" VALUE = "{ l.email }">
		<MvASSIGN NAME = "Affiliates.d.company" VALUE = "{ l.company }">
		<MvASSIGN NAME = "Affiliates.d.phone" VALUE = "{ l.phone }">
		<MvASSIGN NAME = "Affiliates.d.fax" VALUE = "{ l.fax }">
		<MvASSIGN NAME = "Affiliates.d.addr" VALUE = "{ l.addr }">
		<MvASSIGN NAME = "Affiliates.d.city" VALUE = "{ l.city }">
		<MvASSIGN NAME = "Affiliates.d.state" VALUE = "{ l.state }">
		<MvASSIGN NAME = "Affiliates.d.zip" VALUE = "{ l.zip }">
		<MvASSIGN NAME = "Affiliates.d.cntry" VALUE = "{ l.cntry }">
		<MvASSIGN NAME = "Affiliates.d.hits" VALUE = "{ l.hits }">
		<MvASSIGN NAME = "Affiliates.d.percent" VALUE = "{ l.percent }">
		<MvASSIGN NAME = "Affiliates.d.flat" VALUE = "{ l.flat }">		
		<MvASSIGN NAME = "Affiliates.d.lstpay_id" VALUE = "0">
		<MvASSIGN NAME = "Affiliates.d.lstpay_dt" VALUE = "0">
		<MvASSIGN NAME = "Affiliates.d.lstpay_amt" VALUE = "0">
		<MvASSIGN NAME = "Affiliates.d.lstpay_by" VALUE = "0">
		<MvASSIGN NAME = "Affiliates.d.balance" VALUE = 0>

		<MvIF EXPR = "{ l.status EQ 'Approved' }">
			<MvASSIGN NAME = "Affiliates.d.status" VALUE = "{ l.status }">
			<MvASSIGN NAME = "Affiliates.d.status_dt" VALUE = "{ s.time_t }">
			<MvASSIGN NAME = "Affiliates.d.status_by" VALUE = "{ g.Admin_User_ID }">
		</MvIF>

		<MvIF EXPR = "{ l.status EQ 'Pending' }">
			<MvASSIGN NAME = "Affiliates.d.status" VALUE = "{ l.status }">
			<MvASSIGN NAME = "Affiliates.d.status_dt" VALUE = "{ s.time_t }">
			<MvASSIGN NAME = "Affiliates.d.status_by" VALUE = "{ g.Admin_User_ID }">
		</MvIF>

		<MvIF EXPR = "{ l.status EQ 'Rejected' }">
			<MvASSIGN NAME = "Affiliates.d.status" VALUE = "{ l.status }">
			<MvASSIGN NAME = "Affiliates.d.status_dt" VALUE = "{ s.time_t }">
			<MvASSIGN NAME = "Affiliates.d.status_by" VALUE = "{ g.Admin_User_ID }">
		</MvIF>

		<MvASSIGN NAME = "Affiliates.d.session_id" VALUE = "{ l.session_id }">

		<MvADD NAME = "Affiliates">

		<MvASSIGN NAME = "l.affil_id" VALUE = "{ Affiliates.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.affil_id }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_Insert" PARAMETERS = "aff_id, type, order_id, order_amt, percent, amount, payout_id, ip_addr" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "0">

	<MvIF EXPR = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "AffiliateEarnings.d.id" VALUE = "{ StoreKey_Generate( 'AffiliateEarnings' ) }">
		<MvASSIGN NAME = "AffiliateEarnings.d.aff_id" VALUE = "{ l.aff_id }">
		<MvASSIGN NAME = "AffiliateEarnings.d.type" VALUE = "{ l.type }">
		<MvASSIGN NAME = "AffiliateEarnings.d.order_id" VALUE = "{ l.order_id }">
		<MvASSIGN NAME = "AffiliateEarnings.d.order_amt" VALUE = "{ l.order_amt }">
		<MvASSIGN NAME = "AffiliateEarnings.d.percent" VALUE = "{ l.percent }">
		<MvASSIGN NAME = "AffiliateEarnings.d.amount" VALUE = "{ l.amount }">
		<MvASSIGN NAME = "AffiliateEarnings.d.payout_id" VALUE = "{ l.payout_id }">
		<MvASSIGN NAME = "AffiliateEarnings.d.date" VALUE = "{ s.time_t }"> 
		<MvASSIGN NAME = "AffiliateEarnings.d.void" VALUE = ""> 
		<MvASSIGN NAME = "AffiliateEarnings.d.void_reasn" VALUE = "">
		<MvASSIGN NAME = "AffiliateEarnings.d.void_by" VALUE = "">
		<MvASSIGN NAME = "AffiliateEarnings.d.ip_address" VALUE = "{ l.ip_addr }">

		<MvADD NAME = "AffiliateEarnings">

		<MvASSIGN NAME = "l.ok" VALUE = "{ AffiliateEarnings.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarningsVoid_Insert" PARAMETERS = "id,type,void,reas,order_id,order_amt,earned,by,date,ajst_rsn,ajst_by">
	<MvASSIGN NAME = "l.ok" VALUE = "0">

	<MvIF EXPR = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "AffiliateEarnings.d.id" VALUE = "{ StoreKey_Generate( 'AffiliateEarnings' ) }">
		<MvASSIGN NAME = "AffiliateEarnings.d.aff_id" VALUE = "{ l.id }">
		<MvASSIGN NAME = "AffiliateEarnings.d.type" VALUE = "{ l.type }">
		<MvASSIGN NAME = "AffiliateEarnings.d.void" VALUE = "{ l.void }">
		<MvASSIGN NAME = "AffiliateEarnings.d.void_reasn" VALUE = "{ l.reas }">
		<MvASSIGN NAME = "AffiliateEarnings.d.order_id" VALUE = "{ l.order_id }">
		<MvASSIGN NAME = "AffiliateEarnings.d.order_amt" VALUE = "{ l.order_amt }">
		<MvASSIGN NAME = "AffiliateEarnings.d.amount" VALUE = "{ l.earned }">
		<MvASSIGN NAME = "AffiliateEarnings.d.void_by" VALUE = "{ l.by }">
		<MvASSIGN NAME = "AffiliateEarnings.d.date" VALUE = "{ l.date }">
		<MvASSIGN NAME = "AffiliateEarnings.d.adjst_reas" VALUE = "{ l.ajst_rsn }">
		<MvASSIGN NAME = "AffiliateEarnings.d.adjst_by" VALUE = "{ l.ajst_by }">
		
		<MvADD NAME = "AffiliateEarnings">

		<MvASSIGN NAME = "l.ok" VALUE = "{ AffiliateEarnings.d.id }">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_Insert" PARAMETERS = "user" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "0">
	
	<MvIF EXPR = "{ _DB_Store_Open_AffiliatePayouts() }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "AffiliatePayouts.d.id" VALUE = "{ StoreKey_Generate( 'AffiliatePayouts' ) }">
		<MvASSIGN NAME = "AffiliatePayouts.d.amount" VALUE = "">
		<MvASSIGN NAME = "AffiliatePayouts.d.count" VALUE = "">
		<MvASSIGN NAME = "AffiliatePayouts.d.date" VALUE = "{ s.time_t }">
		<MvASSIGN NAME = "AffiliatePayouts.d.pay_by" VALUE = "{ l.user }">
		<MvASSIGN NAME = "AffiliatePayouts.d.processed" VALUE = "">
		<MvASSIGN NAME = "AffiliatePayouts.d.proc_by" VALUE = "">
		<MvASSIGN NAME = "AffiliatePayouts.d.void" VALUE = "">
		<MvASSIGN NAME = "AffiliatePayouts.d.void_reasn" VALUE = "">
		<MvASSIGN NAME = "AffiliatePayouts.d.void_date" VALUE = "">
		<MvASSIGN NAME = "AffiliatePayouts.d.void_by" VALUE = "">

		<MvADD NAME = "AffiliatePayouts">
		
		<MvASSIGN NAME = "l.ok" VALUE = "{ AffiliatePayouts.d.id }">
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate Updates
|
</MvCOMMENT>

<MvFUNCTION NAME = "AffiliateOptions_Update" PARAMETERS = "activated, signup, hits, percent, pselect, flat, pay_thresh, terms, link_image, link_text" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateOptions() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "AffiliateOptions.d.active" VALUE = "{ l.activated }">
		<MvASSIGN NAME = "AffiliateOptions.d.signup" VALUE = "{ l.signup }">
		<MvASSIGN NAME = "AffiliateOptions.d.hits" VALUE = "{ l.hits }">
		<MvASSIGN NAME = "AffiliateOptions.d.percent" VALUE = "{ l.percent }">
		<MvASSIGN NAME = "AffiliateOptions.d.pct_slt" VALUE = "{ l.pselect }">
		<MvASSIGN NAME = "AffiliateOptions.d.flat" VALUE = "{ l.flat }">
		<MvASSIGN NAME = "AffiliateOptions.d.pay_thresh" VALUE = "{ l.pay_thresh }">
		<MvASSIGN NAME = "AffiliateOptions.d.terms" VALUE = "{ l.terms }">
		<MvASSIGN NAME = "AffiliateOptions.d.link_image" VALUE = "{ l.link_image }">
		<MvASSIGN NAME = "AffiliateOptions.d.link_text" VALUE = "{ l.link_text }">

		<MvUPDATE NAME = "AffiliateOptions">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEmail_Update" PARAMETERS = "from, cc, subject, header" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateEmail() }">
	
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "AffiliateEmail.d.from" VALUE = "{ l.from }">
		<MvASSIGN NAME = "AffiliateEmail.d.cc" VALUE = "{ l.cc }">
		<MvASSIGN NAME = "AffiliateEmail.d.subject" VALUE = "{ l.subject }">
		<MvASSIGN NAME = "AffiliateEmail.d.header" VALUE = "{ l.header }">

		<MvUPDATE NAME = "AffiliateEmail">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateManage_Update" PARAMETERS = "activated, use_from, from, useto, to, use_cc, cc, subject, header" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateManage() }">
	
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "AffiliateManage.d.active" VALUE = "{ l.activated }">
		<MvASSIGN NAME = "AffiliateManage.d.usefrom" VALUE = "{ l.use_from }">
		<MvASSIGN NAME = "AffiliateManage.d.from" VALUE = "{ l.from }">
		<MvASSIGN NAME = "AffiliateManage.d.useto" VALUE = "{ l.useto }">
		<MvASSIGN NAME = "AffiliateManage.d.to" VALUE = "{ l.to }">
		<MvASSIGN NAME = "AffiliateManage.d.usecc" VALUE = "{ l.use_cc }">
		<MvASSIGN NAME = "AffiliateManage.d.cc" VALUE = "{ l.cc }">
		<MvASSIGN NAME = "AffiliateManage.d.subject" VALUE = "{ l.subject }">
		<MvASSIGN NAME = "AffiliateManage.d.header" VALUE = "{ l.header }">

		<MvUPDATE NAME = "AffiliateManage">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliates_Update" PARAMETERS = "id, code, password, lpass, site_name, site_url, con_name, email, company, phone, fax, addr, city, state, zip, cntry, hits, percent, flat, status, status_by"  STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
		<MvFIND NAME = "Affiliates" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Affiliates.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00009">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00033', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Affiliates.d.code" VALUE = "{ l.code }">
			<MvIF EXPR = "{ len( l.password ) }">
				<MvASSIGN NAME = "Affiliates.d.password" VALUE = "{ l.password }">
			</MvIF>
			<MvASSIGN NAME = "Affiliates.d.lpasseml" VALUE = "{ l.lpass }">			
			<MvASSIGN NAME = "Affiliates.d.site_name" VALUE = "{ l.site_name }">
			<MvASSIGN NAME = "Affiliates.d.site_url" VALUE = "{ l.site_url }">
			<MvASSIGN NAME = "Affiliates.d.con_name" VALUE = "{ l.con_name }">
			<MvASSIGN NAME = "Affiliates.d.email" VALUE = "{ l.email }">
			<MvASSIGN NAME = "Affiliates.d.company" VALUE = "{ l.company }">
			<MvASSIGN NAME = "Affiliates.d.phone" VALUE = "{ l.phone }">
			<MvASSIGN NAME = "Affiliates.d.fax" VALUE = "{ l.fax }">
			<MvASSIGN NAME = "Affiliates.d.addr" VALUE = "{ l.addr }">
			<MvASSIGN NAME = "Affiliates.d.city" VALUE = "{ l.city }">
			<MvASSIGN NAME = "Affiliates.d.state" VALUE = "{ l.state }">
			<MvASSIGN NAME = "Affiliates.d.zip" VALUE = "{ l.zip }">
			<MvASSIGN NAME = "Affiliates.d.cntry" VALUE = "{ l.cntry }">
			<MvASSIGN NAME = "Affiliates.d.hits" VALUE = "{ l.hits }">
			<MvASSIGN NAME = "Affiliates.d.percent" VALUE = "{ l.percent }">
			<MvASSIGN NAME = "Affiliates.d.flat" VALUE = "{ l.flat }">	
			
			<MvIF EXPR = "{ Affiliates.d.status NE l.status }">
				<MvASSIGN NAME = "Affiliates.d.status" VALUE = "{ l.status }">
				<MvASSIGN NAME = "Affiliates.d.status_by" VALUE = "{ l.status_by }">
				
				<MvASSIGN NAME = "Affiliates.d.status_dt" VALUE = "{ s.time_t }">
			</MvIF>

			<MvUPDATE NAME = "Affiliates">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarningsVoid_Update" PARAMETERS = "id,void,reas,by" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateEarnings() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_i.mvx' }">
		<MvFIND NAME = "AffiliateEarnings" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ AffiliateEarnings.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00010">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00034', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "AffiliateEarnings.d.void" VALUE = "{ l.void }">
			<MvASSIGN NAME = "AffiliateEarnings.d.void_reasn" VALUE = "{ l.reas }">
			<MvASSIGN NAME = "AffiliateEarnings.d.void_by" VALUE = "{ l.by }">
			<MvUPDATE NAME = "AffiliateEarnings">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_Update" PARAMETERS = "id, count, amount" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliatePayouts() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AffiliatePayouts" INDEX = "{ g._DB_Store_Directory $ 'affpay_i.mvx' }">
		<MvFIND NAME = "AffiliatePayouts" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ AffiliatePayouts.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00011">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate Payout '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00035', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "AffiliatePayouts.d.count" VALUE = "{ l.count }">
			<MvASSIGN NAME = "AffiliatePayouts.d.amount" VALUE = "{ l.amount }">

			<MvUPDATE NAME = "AffiliatePayouts">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayoutsVoid_Update" PARAMETERS = "id, processed, proc_by, proc_time, void, voidres, date, by" STANDARDOUTPUTLEVEL = "text,html">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliatePayouts() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AffiliatePayouts" INDEX = "{ g._DB_Store_Directory $ 'affpay_i.mvx' }">
		<MvFIND NAME = "AffiliatePayouts" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ AffiliatePayouts.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00012">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate Payout '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00036', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ len( l.processed ) }">
				<MvASSIGN NAME = "AffiliatePayouts.d.processed" VALUE = "{ l.processed }">
				<MvASSIGN NAME = "AffiliatePayouts.d.proc_date" VALUE = "{ l.proc_time }">
				<MvASSIGN NAME = "AffiliatePayouts.d.proc_by"	VALUE = "{ l.proc_by }">
			</MvIF> 
			
			<MvASSIGN NAME = "AffiliatePayouts.d.void" VALUE = "{ l.void }">
			<MvASSIGN NAME = "AffiliatePayouts.d.void_reasn" VALUE = "{ l.voidres }">
			<MvASSIGN NAME = "AffiliatePayouts.d.void_date" VALUE = "{ l.date }">
			<MvASSIGN NAME = "AffiliatePayouts.d.void_by" VALUE = "{ l.by }">
			
			<MvUPDATE NAME = "AffiliatePayouts">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayout_VoidEarnings_Update" PARAMETERS = "void, voidres, by" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateEarnings() }">
	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "AffiliateEarnings.d.void" VALUE = "{ l.void }">
		<MvASSIGN NAME = "AffiliateEarnings.d.void_reasn" VALUE = "{ l.voidres }">
		<MvASSIGN NAME = "AffiliateEarnings.d.void_by" VALUE = "{ l.by }">

		<MvUPDATE NAME = "AffiliateEarnings">
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateVoid_Balance_Update" PARAMETERS = "id, void, old_void" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
		<MvFIND NAME = "Affiliates" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Affiliates.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00013">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00037', l.error ) }">
		<MvELSE>
			<MvIF EXPR = "{ ( l.void ) AND ( NOT l.old_void ) }">
				<MvASSIGN NAME = "Affiliates.d.balance" VALUE = "{ Affiliates.d.balance - AffiliateEarnings.d.amount }">
			<MvELSE>
				<MvIF EXPR = "{ ( NOT l.void ) AND ( l.old_void ) }">
					<MvASSIGN NAME = "Affiliates.d.balance" VALUE = "{ Affiliates.d.balance + AffiliateEarnings.d.amount }">
				</MvIF>
			</MvIF>

			<MvUPDATE NAME = "Affiliates">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateLast_Payout_Update" PARAMETERS = "id, payout, payout_id, time" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
		<MvFIND NAME = "Affiliates" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Affiliates.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00014">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00038', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Affiliates.d.balance" VALUE = "{ Affiliates.d.balance - l.payout }">
			<MvASSIGN NAME = "Affiliates.d.lstpay_id" VALUE = "{ l.payout_id }">
			<MvASSIGN NAME = "Affiliates.d.lstpay_amt" VALUE = "{ l.payout }">
			<MvASSIGN NAME = "Affiliates.d.lstpay_dt" VALUE = "{ l.time }">
			<MvASSIGN NAME = "Affiliates.d.lstpay_by" VALUE = "{ g.Admin_User_ID }">

			<MvUPDATE NAME = "Affiliates">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_Process" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliatePayouts() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AffiliatePayouts" INDEX = "{ g._DB_Store_Directory $ 'affpay_i.mvx' }">
		<MvFIND NAME = "AffiliatePayouts" VALUE = "{ toupper( l.id ) }" EXACT>
		<MvIF EXPR = "{ AffiliatePayouts.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00015">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate Payout '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00039', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "AffiliatePayouts.d.processed" VALUE = 1>

			<MvUPDATE NAME = "AffiliatePayouts">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliates_Update_ContactInfo" PARAMETERS = "id, code, lostemail, password, site_name, site_url, con_name, email, company, phone, fax, addr, city, state, zip, cntry" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
		<MvFIND NAME = "Affiliates" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Affiliates.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00016">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00040', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Affiliates.d.code" VALUE = "{ l.code }">
			<MvIF EXPR = "{ len( l.password ) }">
				<MvASSIGN NAME = "Affiliates.d.password" VALUE = "{ l.password }">
			</MvIF>

			<MvASSIGN NAME = "Affiliates.d.lpasseml" VALUE = "{ l.lostemail }">
			<MvASSIGN NAME = "Affiliates.d.site_name" VALUE = "{ l.site_name }">
			<MvASSIGN NAME = "Affiliates.d.site_url" VALUE = "{ l.site_url }">
			<MvASSIGN NAME = "Affiliates.d.con_name" VALUE = "{ l.con_name }">
			<MvASSIGN NAME = "Affiliates.d.email" VALUE = "{ l.email }">
			<MvASSIGN NAME = "Affiliates.d.company" VALUE = "{ l.company }">
			<MvASSIGN NAME = "Affiliates.d.phone" VALUE = "{ l.phone }">
			<MvASSIGN NAME = "Affiliates.d.fax" VALUE = "{ l.fax }">
			<MvASSIGN NAME = "Affiliates.d.addr" VALUE = "{ l.addr }">
			<MvASSIGN NAME = "Affiliates.d.city" VALUE = "{ l.city }">
			<MvASSIGN NAME = "Affiliates.d.state" VALUE = "{ l.state }">
			<MvASSIGN NAME = "Affiliates.d.zip" VALUE = "{ l.zip }">
			<MvASSIGN NAME = "Affiliates.d.cntry" VALUE = "{ l.cntry }">

			<MvUPDATE NAME = "Affiliates">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliate_Update_Balance" PARAMETERS = "code, type, amt, by" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
	<MvASSIGN NAME = "l.open" VALUE = "{ _DB_Store_Open_AffiliateOptions() }">

	<MvIF EXPR = "{ l.ok and l.open }">
		<MvIF EXPR = "{ AffiliateOptions.d.active }">
			<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_c.mvx' }">
			<MvFIND NAME = "Affiliates" VALUE = "{ toupper( l.code ) }" EXACT>
			<MvIF EXPR = "{ Affiliates.d.EOF }">
				<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00017">
					<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
					<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
				</MvLOCALIZED>

				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00041', l.error ) }">
			<MvELSE>
				<MvIF EXPR = "{ Affiliates.d.status EQ 'Approved' }">
					<MvIF EXPR = "{ ( l.type EQ 'hit' ) }">
						<MvIF EXPR = "{ Affiliates.d.hits NE 0 }">
							<MvIF EXPR = "unique_hit">
								<MvIF EXPR = "{ AffiliateEarnings_Insert( Affiliates.d.id, 'hit', '', '', '', Affiliates.d.hits, '', s.remote_addr ) }">
									<MvASSIGN NAME = "Affiliates.d.balance" VALUE = "{ Affiliates.d.balance + Affiliates.d.hits }">
								</MvIF>
							</MvIF>
						</MvIF>
					<MvELSE>
						<MvIF EXPR = "{ l.type EQ 'order' }">
							<MvIF EXPR = "{ Affiliates.d.percent NE 0 }">
								<MvASSIGN NAME = "l.commission" VALUE = "{ l.amt * ( Affiliates.d.percent / 100 ) }">
								<MvIF EXPR = "{ AffiliateEarnings_Insert( Affiliates.d.id, 'percent', l.by, l.amt, Affiliates.d.percent, commission, '', '' ) }">
									<MvASSIGN NAME = "Affiliates.d.balance" VALUE = "{ Affiliates.d.balance + l.commission }">
								</MvIF>
							</MvIF>
							<MvIF EXPR = "{ Affiliates.d.flat NE 0 }">
								<MvASSIGN NAME = "l.commission" VALUE = "{ Affiliates.d.flat }">
								<MvIF EXPR = "{ AffiliateEarnings_Insert( Affiliates.d.id, 'flat', l.by, '', '', l.commission, '', '' ) }">

									<MvASSIGN NAME = "Affiliates.d.balance" VALUE = "{ Affiliates.d.balance + l.commission }">
								</MvIF>
							</MvIF>
						<MvELSE>
							<MvIF EXPR = "{ AffiliateEarnings_Insert( Affiliates.d.id, l.type, '', '', '', l.amt, '', '' ) }">
								<MvASSIGN NAME = "Affiliates.d.balance" VALUE = "{ Affiliates.d.balance + l.amt }">
							</MvIF>
						</MvIF>
					</MvIF>

					<MvUPDATE NAME = "Affiliates">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliates_Update_Session" PARAMETERS = "code, session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_c.mvx' }">
		<MvFIND NAME = "Affiliates" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ Affiliates.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00018">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00042', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "Affiliates.d.session_id" VALUE = "{ l.session_id }">

			<MvUPDATE NAME = "Affiliates">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate Deletes
|
</MvCOMMENT>

<MvFUNCTION NAME = "Affiliates_Delete" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Affiliates() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
		<MvFIND NAME = "Affiliates" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ Affiliates.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00019">
				<MvLOCALIZED-TOKEN NAME = "code" VALUE = "{ encodeentities( l.code ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">affiliate '%code%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00043', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "Affiliates">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateEarnings() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_i.mvx' }">
		<MvFIND NAME = "AffiliateEarnings" VALUE = "{ toupper( l.id ) }" EXACT>
		<MvIF EXPR = "{ AffiliateEarnings.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00020">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00044', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "AffiliateEarnings">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayout_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliatePayouts() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "AffiliatePayouts" INDEX = "{ g._DB_Store_Directory $ 'affpay_i.mvx' }">
		<MvFIND NAME = "AffiliatePayouts" VALUE = "{ toupper( l.id ) }" EXACT>
		<MvIF EXPR = "{ AffiliatePayouts.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00022">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate payout '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00046', l.error ) }">
		<MvELSE>
			<MvDELETE NAME = "AffiliatePayouts">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate FindID/Code
|
</MvCOMMENT>

<MvFUNCTION NAME = "Affiliates_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
		<MvFIND NAME = "Affiliates" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ Affiliates.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00023">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00047', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression, runtime">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_i.mvx' }">
		<MvFIND NAME = "AffiliateEarnings" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ AffiliateEarnings.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00024">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliate '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-ADB-00048', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarning_Find_AffiliateID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression, runtime">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_a.mvx' }">
		<MvFIND NAME = "AffiliateEarnings" VALUE = "{ l.id $ ':' }">
		<MvIF EXPR = "{ NOT AffiliateEarnings.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarning_FindNext_AffiliateID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression, runtime">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "AffiliateEarnings" ROWS = "1">
	<MvIF EXPR = "{ ( NOT AffiliateEarnings.d.EOF ) AND ( l.id EQ AffiliateEarnings.d.aff_id ) }">		
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression, runtime">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AffiliatePayouts() }">
		<MvPRIMARY NAME = "AffiliatePayouts" INDEX = "{ g._DB_Store_Directory $ 'affpay_i.mvx' }">
		<MvFIND NAME = "AffiliatePayouts" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT AffiliatePayouts.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_Find_PayoutID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression, runtime">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_p.mvx' }">
		<MvFIND NAME = "AffiliateEarnings" VALUE = "{ l.id $ ':' }">
		<MvIF EXPR = "{ NOT AffiliateEarnings.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_FindNext_PayoutID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression, runtime">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "AffiliateEarnings" ROWS = "1">
	<MvIF EXPR = "{ ( NOT AffiliateEarnings.d.EOF ) AND ( l.id EQ AffiliateEarnings.d.payout_id ) }">		
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliates_Find_Code" PARAMETERS = "code" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_c.mvx' }">

		<MvFIND NAME = "Affiliates" VALUE = "{ toupper( l.code ) }" EXACT>
		<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvASSIGN NAME = "l.found" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate FindFirst/FindNext
|
</MvCOMMENT>

<MvFUNCTION NAME = "Affiliates_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">

		<MvGO NAME = "Affiliates" ROW = "top">
		<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliates_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "Affiliates" ROWS = 1>
	<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_i.mvx' }">

		<MvGO NAME = "AffiliateEarnings" ROW = "top">
		<MvIF EXPR = "{ NOT AffiliateEarnings.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "AffiliateEarnings" ROWS = 1>
	<MvIF EXPR = "{ NOT AffiliateEarnings.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_AffiliatePayouts() }">
		<MvPRIMARY NAME = "AffiliatePayouts" INDEX = "{ g._DB_Store_Directory $ 'affpay_i.mvx' }">

		<MvGO NAME = "AffiliatePayouts" ROW = "top">
		<MvIF EXPR = "{ NOT AffiliatePayouts.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvSKIP NAME = "AffiliatePayouts" ROWS = 1>
	<MvIF EXPR = "{ NOT AffiliatePayouts.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliates_FindLast" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
		<MvGO NAME = "Affiliates" ROW = "bottom">

		<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>


<MvFUNCTION NAME = "Affiliate_FindNext_AffiliateOrder" PARAMETERS = "login" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
		<MvASSIGN NAME = "l.found" VALUE = "{ Affiliates_Find_Code( l.login ) }">
		<MvIF EXPR = "{ l.found }">
			<MvASSIGN NAME = "l.id" VALUE = "{ Affiliates.d.id }">
			<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
			<MvASSIGN NAME = "l.found" VaLUE = "{ Affiliates_Find_ID( l.id ) }">
			<MvIF EXPR = "{ l.found }">
				<MvSKIP NAME = "Affiliates" ROWS = 1>
				<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = 0>
				</MvIF>
			<MvELSE>
				<MvASSIGN NAME = "l.found" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliate_FindPrev_AffiliateOrder" PARAMETERS = "login" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
		<MvASSIGN NAME = "l.found" VALUE = "{ Affiliates_Find_Code( l.login ) }">
		<MvIF EXPR = "{ l.found }">
			<MvASSIGN NAME = "l.id" VALUE =  "{ Affiliates.d.id }">
			<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
			<MvASSIGN NAME = "l.found" VaLUE = "{ Affiliates_Find_ID( l.id ) }">
			<MvIF EXPR = "{ l.found }">
				<MvSKIP NAME = "Affiliates" ROWS = -1>
				<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = 0>
				</MvIF>
			<MvELSE>
				<MvASSIGN NAME = "l.found" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate FindFirstOffset/FindNextOffset
|
</MvCOMMENT>

<MvFUNCTION NAME = "Affiliates_FindOffset_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ _Affiliates_Filter( l.search ) }">
		<MvFILTER NAME = "Affiliates" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Affiliates" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliates_FindNext_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "Affiliates" ROWS = 1>
	<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Affiliates" FILTER = "{ NOT Affiliates.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_FindOffset_Payout" PARAMETERS = "offset, payout_id, search" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvIF EXPR = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">

			<MvASSIGN NAME = "l.filter" VALUE = "{ _Affiliates_Filter( l.search ) }">
			<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_i.mvx' }">
			<MvFILTER NAME = "Affiliates" FILTER = "l.filter" FILTER_TYPE = "variable">

			<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_p.mvx' }">
			<MvFIND NAME = "AffiliateEarnings" VALUE = "{ payout_id $ ':' }">
			<MvIF EXPR = "{ l.offset }">
				<MvSKIP NAME = "AffiliateEarnings" ROWS = "{ l.offset }">
			</MvIF>

			<MvWHILE EXPR = "{ ( NOT l.found ) AND ( NOT AffiliateEarnings.d.EOF ) AND ( payout_id EQ AffiliateEarnings.d.payout_id ) }">
				<MvFIND NAME = "Affiliates" VALUE = "{ AffiliateEarnings.d.aff_id }" EXACT>
				<MvIF EXPR = "{ Affiliates.d.EOF }">
					<MvSKIP NAME = "AffiliateEarnings" ROWS = "1">
					<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
				<MvELSE>
					<MvASSIGN NAME = "l.found" VALUE = "1">
				</MvIF>
			</MvWHILE>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Affiliates" FILTER = "{ NOT Affiliates.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_FindNextOffset_Payout" PARAMETERS = "offset, payout_id, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "AffiliateEarnings" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT l.found ) AND ( NOT AffiliateEarnings.d.EOF ) AND ( payout_id EQ AffiliateEarnings.d.payout_id ) }">
		<MvFIND NAME = "Affiliates" VALUE = "{ AffiliateEarnings.d.aff_id }" EXACT>
		<MvIF EXPR = "{ Affiliates.d.EOF }">
			<MvSKIP NAME = "AffiliateEarnings" ROWS = "1">
			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
		<MvELSE>
			<MvASSIGN NAME = "l.found" VALUE = "1">
		</MvIF>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Affiliates" FILTER = "{ NOT Affiliates.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_FindOffset_Affiliate" PARAMETERS = "offset, affiliate_id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvIF EXPR = "{ _DB_Store_Open_AffiliateEarnings() }">
		<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
			<MvPRIMARY NAME = "AffiliateEarnings" INDEX = "{ g._DB_Store_Directory $ 'affern_a.mvx' }">
			<MvFIND NAME = "AffiliateEarnings" VALUE = "{ affiliate_id $ ':' }">
			<MvIF EXPR = "{ l.offset }">
				<MvSKIP NAME = "AffiliateEarnings" ROWS = "{ l.offset }">
			</MvIF>
			<MvIF EXPR = "{ NOT AffiliateEarnings.d.EOF }">
				<MvIF EXPR = "{ Affiliate_id EQ AffiliateEarnings.d.Aff_id }">
					<MvASSIGN NAME = "l.found" VALUE = "1">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "Affiliates" FILTER = "{ NOT Affiliates.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEarnings_FindNextOffset_Affiliate" PARAMETERS = "offset, affiliate_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "AffiliateEarnings" ROWS = 1>

	<MvIF EXPR = "{ ( NOT AffiliateEarnings.d.EOF ) AND ( l.affiliate_id EQ AffiliateEarnings.d.Aff_id ) }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>

</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_FindOffset_Unprocessed" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_AffiliatePayouts() }">
		<MvPRIMARY NAME = "AffiliatePayouts" INDEX = "{ g._DB_Store_Directory $ 'affpay_i.mvx' }">

		<MvASSIGN NAME = "l.filter" VALUE = "{ _AffiliatePayouts_Filter( l.search ) }">
		<MvFILTER NAME = "AffiliatePayouts" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "AffiliatePayouts" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT AffiliatePayouts.d.EOF ) AND ( NOT l.found ) }">
			<MvIF EXPR = "{ NOT AffiliatePayouts.d.processed }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "AffiliatePayouts" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_FindNext_Unprocessed" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "AffiliatePayouts" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT AffiliatePayouts.d.EOF ) AND ( NOT l.found ) }">
		<MvIF EXPR = "{ NOT AffiliatePayouts.d.processed }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "AffiliatePayouts" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "AffiliatePayouts" FILTER = "{ NOT AffiliatePayouts.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_FindNext_Processed" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "AffiliatePayouts" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT AffiliatePayouts.d.EOF ) AND ( NOT l.found ) }">
		<MvIF EXPR = "{ AffiliatePayouts.d.processed }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

		<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
		<MvSKIP NAME = "AffiliatePayouts" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "AffiliatePayouts" FILTER = "{ NOT AffiliatePayouts.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_FindOffset_Processed" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_AffiliatePayouts() }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ _AffiliatePayouts_Filter( l.search ) }">
		<MvFILTER NAME = "AffiliatePayouts" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "AffiliatePayouts" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT AffiliatePayouts.d.EOF ) AND ( NOT l.found ) }">
			<MvIF EXPR = "{ AffiliatePayouts.d.processed }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

			<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.newoffset + 1 }">
			<MvSKIP NAME = "AffiliatePayouts" ROWS = 1>
		</MvWHILE>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_FindOffset_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvIF EXPR = "{ _DB_Store_Open_AffiliatePayouts() }">
		<MvPRIMARY NAME = "AffiliatePayouts" INDEX = "{ g._DB_Store_Directory $ 'affpay_d.mvx' }">
		<MvASSIGN NAME = "l.filter" VALUE = "{ _AffiliatePayouts_Filter( l.search ) }">
		<MvFILTER NAME = "AffiliatePayouts" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "AffiliatePayouts" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT AffiliatePayouts.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliatePayouts_FindNext_All" PARAMETERS = "offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">

	<MvSKIP NAME = "AffiliatePayouts" ROWS = 1>
	<MvIF EXPR = "{ NOT AffiliatePayouts.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 1>
	</MvIF>

	<MvIF EXPR = "{ l.found }">
		<MvFUNCTIONRETURN VALUE = "{ l.newoffset }">
	<MvELSE>
		<MvFILTER NAME = "AffiliatePayouts" FILTER = "{ NOT AffiliatePayouts.d.deleted }">
		<MvFUNCTIONRETURN VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvCOMMENT>
|
| Affiliate Other
|
</MvCOMMENT>

<MvFUNCTION NAME = "AffiliateOptions_Find" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_AffiliateOptions() }">
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateEmail_Load" STANDARDOUTPUTLEVEL = "">
	<MvFUNCTIONRETURN VALUE = "{ _DB_Store_Open_AffiliateEmail() }">
</MvFUNCTION>

<MvFUNCTION NAME = "AffiliateManage_EmailLoad" STANDARDOUTPUTLEVEL = "">
	<MvFUNCTIONRETURN VALUE = "{ _DB_Store_Open_AffiliateManage() }">
</MvFUNCTION>

<MvFUNCTION NAME = "Affiliates_Find_Session" PARAMETERS = "session_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_Affiliates() }">
		<MvPRIMARY NAME = "Affiliates" INDEX = "{ g._DB_Store_Directory $ 'affil_s.mvx' }">
		<MvFIND NAME = "Affiliates" VALUE = "{ l.session_id }" EXACT>
		<MvIF EXPR = "{ NOT Affiliates.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-ADB-00025">
				<MvLOCALIZED-TOKEN NAME = "session_id" VALUE = "{ encodeentities( l.session_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Affiliates Session '%session_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.found" VALUE = "{ Error( 'MER-ADB-00049', l.error ) }">
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = "{ l.found }">
</MvFUNCTION>
