<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/pgr/pgr_db.mv,v $
|
| Prefix         : MER-PGR-DB-
| Next Error Code: 1    
| Next Text ID   : 15   
|
</MvCOMMENT>

<MvFUNCTION NAME = "PGR_Store_Create" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvCREATE NAME = "PriceGroups"
			  DATABASE = "{ g._DB_Store_Directory $ 'prcgrps.dbf' }"
			  FIELDS = "id			NUMBER,
						name		CHAR( 40 ),
						rate        CHAR( 1 ),
						discount    NUMBER( 10.2 ),
						markup      NUMBER( 10.2 )">
	<MvIF EXPR = "{ MvCREATE_Error }">
		<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00218', MvCREATE_Error ) }">
	<MvELSE>
		<MvASSIGN NAME = "g._DB_Store_PriceGroups_Open" VALUE = 1>
	</MvIF>

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

	<MvIF EXPR = "{ l.ok }">
		<MvMAKEINDEX NAME = "PriceGroups"
					 INDEXFILE = "{ g._DB_Store_Directory $ 'pgrp_nm.mvx' }"
					 EXPRESSION = "{ toupper( PriceGroups.d.name ) }"
					 FLAGS = "nounique, ascending, string">
		<MvIF EXPR = "{ MvMAKEINDEX_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00220', MvMAKEINDEX_Error ) }">
		</MvIF>
	</MvIF>

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

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "PriceGroupXProduct"
				  DATABASE = "{ g._DB_Store_Directory $ 'pgpxprod.dbf' }"
				  FIELDS = "pgrp_id		NUMBER,
							product_id	NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00221', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_PriceGroupXProduct_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "PriceGroupXProduct"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }"
						 EXPRESSION = "{ PriceGroupXProduct.d.pgrp_id $ ':' $ padl( PriceGroupXProduct.d.product_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00222', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "PriceGroupXProduct"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'pgxp_prd.mvx' }"
						 EXPRESSION = "{ PriceGroupXProduct.d.product_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00223', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

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

	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "PriceGroupXCustomer"
				  DATABASE = "{ g._DB_Store_Directory $ 'pgpxcust.dbf' }"
				  FIELDS = "pgrp_id		NUMBER,
							cust_id		NUMBER">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00224', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_PriceGroupXCustomer_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "PriceGroupXCustomer"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'pgxc_grp.mvx' }"
						 EXPRESSION = "{ PriceGroupXCustomer.d.pgrp_id $ ':' $ padl( PriceGroupXCustomer.d.cust_id, 10, '0' ) }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00225', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "PriceGroupXCustomer"
						 INDEXFILE = "{ g._DB_Store_Directory $ 'pgxc_cst.mvx' }"
						 EXPRESSION = "{ PriceGroupXCustomer.d.cust_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00226', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

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

	<MvIF EXPR = "{ l.ok }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ StoreKey_Insert( 'PriceGroups', 1 ) }">
	</MvIF>

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

<MvFUNCTION NAME = "PGR_Create_Data_Files" STANDARDOUTPUTLEVEL = "">
	<MvLOCALIZED NAME = "l.privilege" ID = "MER-PGR-DB-00000">
		<MvLOCALIZED-TEXT LANGUAGE = "en-US">Price Groups</MvLOCALIZED-TEXT>
	</MvLOCALIZED>
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ Privilege_Insert( 'PGRP', l.privilege ) }">

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

<MvFUNCTION NAME = "PGR_Store_Delete" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvASSIGN NAME = "l.directory" VALUE = "{ g.MerchantPath $ padl( Stores.d.id, 8, '0' ) $ '/' }">

	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'prcgrps.dbf' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'pgrp_id.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'pgrp_nm.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'pgpxprod.dbf' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'pgxp_grp.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'pgxp_prd.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'pgpxcust.dbf' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'pgxc_grp.mvx' ) }">
	<MvASSIGN NAME = "l.deleted" VALUE = "{ fdelete( l.directory $ 'pgxc_cst.mvx' ) }">

	<MvFUNCTIONRETURN VALUE = 1>
</MvFUNCTION>

<MvFUNCTION NAME = "PGR_Store_Pack" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroups() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPACK NAME = "PriceGroups">
		<MvIF EXPR = "{ MvPACK_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00346', MvPACK_Error ) }">
		<MvELSE>
			<MvCLOSE NAME = "PriceGroups">
			<MvASSIGN NAME = "g._DB_Store_PriceGroups_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroupXProduct() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "PriceGroupXProduct">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00347', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "PriceGroupXProduct">
				<MvASSIGN NAME = "g._DB_Store_PriceGroupXProduct_Open" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.ok }">
		<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroupXCustomer() }">
		<MvIF EXPR = "{ l.ok }">
			<MvPACK NAME = "PriceGroupXCustomer">
			<MvIF EXPR = "{ MvPACK_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00348', MvPACK_Error ) }">
			<MvELSE>
				<MvCLOSE NAME = "PriceGroupXCustomer">
				<MvASSIGN NAME = "g._DB_Store_PriceGroupXCustomer" VALUE = 0>
			</MvIF>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PGR_Store_Close" STANDARDOUTPUTLEVEL = "">
	<MvIF EXPR = "{ g._DB_Store_PriceGroups_Open }">
		<MvCLOSE NAME = "PriceGroups">
		<MvASSIGN NAME = "g._DB_Store_PriceGroups_Open" VALUE = 0>
	</MvIF>

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

	<MvIF EXPR = "{ g._DB_Store_PriceGroupXCustomer_Open }">
		<MvCLOSE NAME = "PriceGroupXCustomer">
		<MvASSIGN NAME = "g._DB_Store_PriceGroupXCustomer_Open" VALUE = 0>
	</MvIF>
</MvFUNCTION>

<MvFUNCTION NAME = "Product_FindFirst_PriceGroup" PARAMETERS = "pgrp_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_prod" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ _DB_Store_Open_PriceGroupXProduct() AND l.open_prod }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">

		<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.pgrp_id $ ':' }">
		<MvIF EXPR = "{ ( NOT PriceGroupXProduct.d.EOF ) AND ( PriceGroupXProduct.d.pgrp_id EQ l.pgrp_id ) }">
			<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
			<MvFIND NAME = "Products" VALUE = "{ PriceGroupXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
			</MvIF>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "Product_FindNext_PriceGroup" PARAMETERS = "pgrp_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>

	<MvSKIP NAME = "PriceGroupXProduct" ROWS = 1>
	<MvIF EXPR = "{ ( PriceGroupXProduct.d.EOF ) OR ( PriceGroupXProduct.d.pgrp_id NE l.pgrp_id ) }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvELSE>
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ PriceGroupXProduct.d.product_id }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 0>
		</MvIF>
	</MvIF>

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

<MvCOMMENT>
|
| PriceGroups
|
</MvCOMMENT>

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

	<MvIF EXPR = "{ NOT g._DB_Store_PriceGroups_Open }">
		<MvOPEN NAME = "PriceGroups" 
				DATABASE = "{ g._DB_Store_Directory $ 'prcgrps.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'pgrp_id.mvx, ' $ g._DB_Store_Directory $ 'pgrp_nm.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00299', MvOPEN_Error ) }">
		<MvELSE>
			<MvFILTER NAME = "PriceGroups" FILTER = "{ NOT PriceGroups.d.deleted }">
			<MvASSIGN NAME = "g._DB_Store_PriceGroups_Open" VALUE = 1>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_Insert" PARAMETERS = "name, rate, discount, markup" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.pricegrp" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_PriceGroups() }">
		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "PriceGroups.d.id" VALUE = "{ StoreKey_Generate( 'PriceGroups' ) }">
		<MvASSIGN NAME = "PriceGroups.d.name" 		VALUE = "{ l.name }">
		<MvASSIGN NAME = "PriceGroups.d.rate" 		VALUE = "{ l.rate }">
		<MvASSIGN NAME = "PriceGroups.d.discount" 	VALUE = "{ l.discount }">
		<MvASSIGN NAME = "PriceGroups.d.markup" 	VALUE = "{ l.markup }">

		<MvADD NAME = "PriceGroups">
		<MvASSIGN NAME = "l.pricegrp" VALUE = "{ PriceGroups.d.id }">
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_Update" PARAMETERS = "id, name, rate, discount, markup" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroups() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "PriceGroups" INDEX = "{ g._DB_Store_Directory $ 'pgrp_id.mvx' }">
		<MvFIND NAME = "PriceGroups" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ PriceGroups.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00001">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Price Group '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00300', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "PriceGroups.d.name" 		VALUE = "{ l.name }">
			<MvASSIGN NAME = "PriceGroups.d.rate" 		VALUE = "{ l.rate }">
			<MvASSIGN NAME = "PriceGroups.d.discount" 	VALUE = "{ l.discount }">
			<MvASSIGN NAME = "PriceGroups.d.markup" 	VALUE = "{ l.markup }">

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

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

<MvFUNCTION NAME = "PriceGroup_Delete" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_prod" VALUE = "{ _DB_Store_Open_Products() }">
	<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.open_cus" VALUE = "{ _DB_Store_Open_Customers() }">

	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroups() 
					   AND l.open_prod
					   AND l.open_cus
	                                   AND _DB_Store_Open_PriceGroupXProduct() 
	                                   AND _DB_Store_Open_PriceGroupXCustomer() }"> 
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "PriceGroups" INDEX = "{ g._DB_Store_Directory $ 'pgrp_id.mvx' }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">
		<MvPRIMARY NAME = "Customers" INDEX = "{ g._DB_Store_Directory $ 'cust_id.mvx' }">
		<MvPRIMARY NAME = "PriceGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'pgxc_grp.mvx' }">

		<MvFIND NAME = "PriceGroups" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ PriceGroups.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00002">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Price Group '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00301', l.error ) }">
		<MvELSE>
			<MvFIND NAME = "PriceGroupXCustomer" VALUE = "{ l.id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT PriceGroupXCustomer.d.EOF ) AND ( PriceGroupXCustomer.d.pgrp_id EQ l.id ) }">
				<MvFIND NAME = "Customers" VALUE = "{ PriceGroupXCustomer.d.cust_id }" EXACT>

				<MvIF EXPR = "{ Customers.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00014">
						<MvLOCALIZED-TOKEN NAME = "cus_id" VALUE = "{ encodeentities( PriceGroupXCustomer.d.cust_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Customer id '%cus_id%' not found</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-PGR-DB-00000', l.error ) }">
				<MvELSE>
					<MvIF EXPR = "{ Customers.d.pgrpcount GT 0 }">
						<MvASSIGN NAME = "Customers.d.pgrpcount" VALUE = "{ Customers.d.pgrpcount - 1 }">
						<MvUPDATE NAME = "Customers">
					</MvIF>
				</MvIF>
						
				<MvDELETE NAME = "PriceGroupXCustomer">
				<MvSKIP NAME = "PriceGroupXCustomer" ROWS = 1>
			</MvWHILE>

			<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.id $ ':' }">
			<MvWHILE EXPR = "{ ( NOT PriceGroupXProduct.d.EOF ) AND ( PriceGroupXProduct.d.pgrp_id EQ l.id ) }">
				<MvFIND NAME = "Products" VALUE = "{ PriceGroupXProduct.d.product_id }" EXACT>

				<MvIF EXPR = "{ Products.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00003">
						<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( PriceGroupXProduct.d.product_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' not found</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00302', l.error ) }">
				<MvELSE>
					<MvIF EXPR = "{ Products.d.pgrpcount GT 0 }">
						<MvASSIGN NAME = "Products.d.pgrpcount" VALUE = "{ Products.d.pgrpcount - 1 }">
						<MvUPDATE NAME = "Products">
					</MvIF>
				</MvIF>
						
				<MvDELETE NAME = "PriceGroupXProduct">
				<MvSKIP NAME = "PriceGroupXProduct" ROWS = 1>
			</MvWHILE>

			<MvDELETE NAME = "PriceGroups">
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroupXProduct_Delete_Product" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroupXProduct() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_prd.mvx' }">
		<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.id }" EXACT>
		<MvWHILE EXPR = "{ ( NOT PriceGroupXProduct.d.EOF ) AND ( PriceGroupXProduct.d.product_id EQ l.id ) }">
			<MvDELETE NAME = "PriceGroupXProduct">
			<MvSKIP NAME = "PriceGroupXProduct" ROWS = 1>
		</MvWHILE>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_Find_Name" PARAMETERS = "name" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.id" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_PriceGroups() }">
		<MvPRIMARY NAME = "PriceGroups" INDEX = "{ g._DB_Store_Directory $ 'pgrp_nm.mvx' }">
		<MvFIND NAME = "PriceGroups" VALUE = "{ toupper( l.name ) }" EXACT>
		<MvIF EXPR = "{ NOT PriceGroups.d.EOF }">
			<MvASSIGN NAME = "l.id" VALUE = "{ PriceGroups.d.id }">
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00004">
				<MvLOCALIZED-TOKEN NAME = "name" VALUE = "{ encodeentities( l.name ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Price Group '%name%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

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

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

<MvFUNCTION NAME = "PriceGroup_Find_ID" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_PriceGroups() }">
		<MvPRIMARY NAME = "PriceGroups" INDEX = "{ g._DB_Store_Directory $ 'pgrp_id.mvx' }">
		<MvFIND NAME = "PriceGroups" VALUE = "{ l.id }" EXACT>
		<MvIF EXPR = "{ NOT PriceGroups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		<MvELSE>
			<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00005">
				<MvLOCALIZED-TOKEN NAME = "id" VALUE = "{ encodeentities( l.id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Price Group '%id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

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

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

<MvFUNCTION NAME = "PriceGroup_FindFirst" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_PriceGroups() }">
		<MvGO NAME = "PriceGroups" ROW = "top">
		<MvIF EXPR = "{ NOT PriceGroups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_FindFirst_Offset" PARAMETERS = "offset" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvIF EXPR = "{ _DB_Store_Open_PriceGroups() }">
		<MvGO NAME = "PriceGroups" ROW = "top">
		<MvSKIP NAME = "PriceGroups" ROWS = "{ l.offset }">
		<MvIF EXPR = "{ NOT PriceGroups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_FindNext" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 1>
	
	<MvSKIP NAME = "PriceGroups" ROWS = 1>
	<MvIF EXPR = "{ PriceGroups.d.EOF }">
		<MvASSIGN NAME = "l.found" VALUE = 0>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_FindFirst_CustomerProduct" PARAMETERS = "cust_id, product_id">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.pgrp_id" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_PriceGroupXCustomer() AND _DB_Store_Open_PriceGroupXProduct() }">
		<MvPRIMARY NAME = "PriceGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'pgxc_cst.mvx' }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">

		<MvFIND NAME = "PriceGroupXCustomer" VALUE = "{ l.cust_id }" EXACT>
		<MvWHILE EXPR = "{ ( NOT PriceGroupXCustomer.d.EOF ) AND ( PriceGroupXCustomer.d.cust_id EQ l.cust_id ) }">
			<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ PriceGroupXCustomer.d.pgrp_id $ ':' $ padl( l.product_id, 10, '0' ) }" EXACT>
			<MvIF EXPR = "{ NOT PriceGroupXProduct.d.EOF }">
				<MvASSIGN NAME = "l.pgrp_id" VALUE = "{ PriceGroupXProduct.d.pgrp_id }">
				<MvWHILESTOP>
			</MvIF>

			<MvSKIP NAME = "PriceGroupXCustomer" ROWS = 1>
		</MvWHILE>

		<MvIF EXPR = "{ l.pgrp_id }">
			<MvIF EXPR = "{ _DB_Store_Open_PriceGroups() }">
				<MvPRIMARY NAME = "PriceGroups" INDEX = "{ g._DB_Store_Directory $ 'pgrp_id.mvx' }">
				<MvFIND NAME = "PriceGroups" VALUE = "{ l.pgrp_id }" EXACT>
				<MvIF EXPR = "{ NOT PriceGroups.d.EOF }">
					<MvASSIGN NAME = "l.found" VALUE = 1>
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_FindNext_CustomerProduct" PARAMETERS = "cust_id, product_id">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.pgrp_id" VALUE = 0>

	<MvSKIP NAME = "PriceGroupXCustomer" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT PriceGroupXCustomer.d.EOF ) AND ( PriceGroupXCustomer.d.cust_id EQ l.cust_id ) }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">
		<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ PriceGroupXCustomer.d.pgrp_id $ ':' $ padl( l.product_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ NOT PriceGroupXProduct.d.EOF }">
			<MvASSIGN NAME = "l.pgrp_id" VALUE = "{ PriceGroupXProduct.d.pgrp_id }">
			<MvWHILESTOP>
		</MvIF>

		<MvSKIP NAME = "PriceGroupXCustomer" ROWS = 1>
	</MvWHILE>

	<MvIF EXPR = "{ l.pgrp_id }">
		<MvPRIMARY NAME = "PriceGroups" INDEX = "{ g._DB_Store_Directory $ 'pgrp_id.mvx' }">
		<MvFIND NAME = "PriceGroups" VALUE = "{ l.pgrp_id }" EXACT>
		<MvIF EXPR = "{ NOT PriceGroups.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

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

<MvCOMMENT>
|
| PriceGroupXProduct 
|
</MvCOMMENT>

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

	<MvIF EXPR = "{ NOT g._DB_Store_PriceGroupXProduct_Open }">
		<MvOPEN NAME = "PriceGroupXProduct"
				DATABASE = "{ g._DB_Store_Directory $ 'pgpxprod.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx, ' $
						     g._DB_Store_Directory $ 'pgxp_prd.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Moudle_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00305', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_PriceGroupXProduct_Open" VALUE = 1>
			<MvFILTER NAME = "PriceGroupXProduct" FILTER = "{ NOT PriceGroupXProduct.d.deleted }">
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroupXProduct_Insert" PARAMETERS = "pgrp_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroupXProduct() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">

		<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.pgrp_id $ ':' $ padl( l.product_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ NOT PriceGroupXProduct.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00006">
				<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
				<MvLOCALIZED-TOKEN NAME = "pgrp_id" VALUE = "{ encodeentities( l.pgrp_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' is already in price group '%pgrp_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00306', l.error ) }">
		<MvELSE>
			<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
				<MvFIND NAME = "Products" VALUE = "{ l.product_id }" EXACT>
				<MvIF EXPR = "{ Products.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00007">
						<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' not found</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00307', l.error ) }">
				<MvELSE>
					<MvASSIGN NAME = "Products.d.pgrpcount" VALUE = "{ Products.d.pgrpcount + 1 }">
					<MvUPDATE NAME = "Products">

					<MvASSIGN NAME = "PriceGroupXProduct.d.pgrp_id" VALUE = "{ l.pgrp_id }">
					<MvASSIGN NAME = "PriceGroupXProduct.d.product_id" VALUE = "{ l.product_id }">
					<MvADD NAME = "PriceGroupXProduct">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroupXProduct_Find" PARAMETERS = "pgrp_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_PriceGroupXProduct() }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">

		<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.pgrp_id $ ':' $ padl( l.product_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ NOT PriceGroupXProduct.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroupXProduct_Delete" PARAMETERS = "pgrp_id, product_id" STANDARDOUTPUTLEVEL = "">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Products() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">

		<MvFIND NAME = "Products" VALUE = "{ l.product_id }" EXACT>
		<MvIF EXPR = "{ Products.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00008">
				<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00308', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroupXProduct() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">
				<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.pgrp_id $ ':' $ padl( l.product_id, 10, '0' ) }" EXACT>
				<MvIF EXPR = "{ PriceGroupXProduct.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00009">
						<MvLOCALIZED-TOKEN NAME = "product_id" VALUE = "{ encodeentities( l.product_id ) }">
						<MvLOCALIZED-TOKEN NAME = "pgrp_id" VALUE = "{ encodeentities( l.pgrp_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Product '%product_id%' is not in price group '%pgrp_id%'</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00309', l.error ) }">
				<MvELSE>
					<MvIF EXPR = "{ Products.d.pgrpcount GT 0 }">
						<MvASSIGN NAME = "Products.d.pgrpcount" VALUE = "{ Products.d.pgrpcount - 1 }">
						<MvUPDATE NAME = "Products">
					</MvIF>

					<MvDELETE NAME = "PriceGroupXProduct">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_Product_FindOffset_Unassigned" PARAMETERS = "pgrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_prod" VALUE = "{ _DB_Store_Open_Products() }">

	<MvIF EXPR = "{ l.open_prod AND _DB_Store_Open_PriceGroupXProduct() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_ord.mvx' }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">

		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.filter" VALUE = "{ _Product_Filter( l.search ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Products" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT Products.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.pgrp_id $ ':' $ padl( Products.d.id, 10, '0' ) }" EXACT>
			<MvIF EXPR = "{ PriceGroupXProduct.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

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

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

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

	<MvSKIP NAME = "Products" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Products.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.pgrp_id $ ':' $ padl( Products.d.id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ PriceGroupXProduct.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

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

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

<MvFUNCTION NAME = "PriceGroup_Product_FindOffset_Assigned" PARAMETERS = "pgrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.open_prod" VALUE = "{ _DB_Store_Open_Products() }">

	<MvIF EXPR = "{ l.open_prod AND _DB_Store_Open_PriceGroupXProduct() }">
		<MvPRIMARY NAME = "Products" INDEX = "{ g._DB_Store_Directory $ 'prd_id.mvx' }">
		<MvPRIMARY NAME = "PriceGroupXProduct" INDEX = "{ g._DB_Store_Directory $ 'pgxp_grp.mvx' }">

		<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.filter" VALUE = "{ _Product_Filter( l.search ) }">
		<MvFILTER NAME = "Products" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvFIND NAME = "PriceGroupXProduct" VALUE = "{ l.pgrp_id $ ':' }">
		<MvSKIP NAME = "PriceGroupXProduct" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT PriceGroupXProduct.d.EOF ) AND ( PriceGroupXProduct.d.pgrp_id EQ l.pgrp_id ) AND ( NOT l.found ) }">
			<MvFIND NAME = "Products" VALUE = "{ PriceGroupXProduct.d.product_id }" EXACT>
			<MvIF EXPR = "{ NOT Products.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

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

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

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

	<MvSKIP NAME = "PriceGroupXProduct" ROWS = 1>

	<MvWHILE EXPR = "{ ( NOT PriceGroupXProduct.d.EOF ) AND ( PriceGroupXProduct.d.pgrp_id EQ l.pgrp_id ) AND ( NOT l.found ) }">
		<MvFIND NAME = "Products" VALUE = "{ PriceGroupXProduct.d.product_id }" EXACT>
		<MvIF EXPR = "{ NOT Products.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

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

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

<MvCOMMENT>
|
| PriceGroupXCustomer 
|
</MvCOMMENT>

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

	<MvIF EXPR = "{ NOT g._DB_Store_PriceGroupXCustomer_Open }">
		<MvOPEN NAME = "PriceGroupXCustomer"
				DATABASE = "{ g._DB_Store_Directory $ 'pgpxcust.dbf' }" 
				INDEXES = "{ g._DB_Store_Directory $ 'pgxc_grp.mvx, ' $
						     g._DB_Store_Directory $ 'pgxc_cst.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00310', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_PriceGroupXCustomer_Open" VALUE = 1>
			<MvFILTER NAME = "PriceGroupXCustomer" FILTER = "{ NOT PriceGroupXCustomer.d.deleted }">
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroupXCustomer_Insert" PARAMETERS = "pgrp_id, cust_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroupXCustomer() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "PriceGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'pgxc_grp.mvx' }">

		<MvFIND NAME = "PriceGroupXCustomer" VALUE = "{ l.pgrp_id $ ':' $ padl( l.cust_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ NOT PriceGroupXCustomer.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00010">
				<MvLOCALIZED-TOKEN NAME = "cust_id" VALUE = "{ encodeentities( l.cust_id ) }">
				<MvLOCALIZED-TOKEN NAME = "pgrp_id" VALUE = "{ encodeentities( l.pgrp_id ) }">

				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Customer '%cust_id%' is already in price group '%pgrp_id%'</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00311', l.error ) }">
		<MvELSE>
			<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Customers() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "Customers" INDEX = "{ g._DB_Store_Directory $ 'cust_id.mvx' }">
				<MvFIND NAME = "Customers" VALUE = "{ l.cust_id }" EXACT>
				<MvIF EXPR = "{ Customers.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00011">
						<MvLOCALIZED-TOKEN NAME = "cust_id" VALUE = "{ encodeentities( l.cust_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Customer '%cust_id%' not found</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00312', l.error ) }">
				<MvELSE>
					<MvASSIGN NAME = "Customers.d.pgrpcount" VALUE = "{ Customers.d.pgrpcount + 1 }">
					<MvUPDATE NAME = "Customers">

					<MvASSIGN NAME = "PriceGroupXCustomer.d.pgrp_id" VALUE = "{ l.pgrp_id }">
					<MvASSIGN NAME = "PriceGroupXCustomer.d.cust_id" VALUE = "{ l.cust_id }">
					<MvADD NAME = "PriceGroupXCustomer">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroupXCustomer_Find" PARAMETERS = "pgrp_id, cust_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>

	<MvIF EXPR = "{ _DB_Store_Open_PriceGroupXCustomer() }">
		<MvPRIMARY NAME = "PriceGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'pgxc_grp.mvx' }">

		<MvFIND NAME = "PriceGroupXCustomer" VALUE = "{ l.pgrp_id $ ':' $ padl( l.cust_id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ NOT PriceGroupXCustomer.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroupXCustomer_Delete" PARAMETERS = "pgrp_id, cust_id" STANDARDOUTPUTLEVEL = "">
	<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.ok" VALUE = "{ _DB_Store_Open_Customers() }">
	<MvIF EXPR = "{ l.ok }">
		<MvPRIMARY NAME = "Customers" INDEX = "{ g._DB_Store_Directory $ 'cust_id.mvx' }">

		<MvFIND NAME = "Customers" VALUE = "{ l.cust_id }" EXACT>
		<MvIF EXPR = "{ Customers.d.EOF }">
			<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00012">
				<MvLOCALIZED-TOKEN NAME = "cust_id" VALUE = "{ encodeentities( l.cust_id ) }">
				<MvLOCALIZED-TEXT LANGUAGE = "en-US">Customer '%cust_id%' not found</MvLOCALIZED-TEXT>
			</MvLOCALIZED>

			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00313', l.error ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_PriceGroupXCustomer() }">
			<MvIF EXPR = "{ l.ok }">
				<MvPRIMARY NAME = "PriceGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'pgxc_grp.mvx' }">
				<MvFIND NAME = "PriceGroupXCustomer" VALUE = "{ l.pgrp_id $ ':' $ padl( l.cust_id, 10, '0' ) }" EXACT>
				<MvIF EXPR = "{ PriceGroupXCustomer.d.EOF }">
					<MvLOCALIZED NAME = "l.error" ID = "MER-PGR-DB-00013">
						<MvLOCALIZED-TOKEN NAME = "cust_id" VALUE = "{ encodeentities( l.cust_id ) }">
						<MvLOCALIZED-TOKEN NAME = "pgrp_id" VALUE = "{ encodeentities( l.pgrp_id ) }">
						<MvLOCALIZED-TEXT LANGUAGE = "en-US">Customer '%cust_id%' is not in price group '%pgrp_id%'</MvLOCALIZED-TEXT>
					</MvLOCALIZED>

					<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00314', l.error ) }">
				<MvELSE>
					<MvIF EXPR = "{ Customers.d.pgrpcount GT 0 }">
						<MvASSIGN NAME = "Customers.d.pgrpcount" VALUE = "{ Customers.d.pgrpcount - 1 }">
						<MvUPDATE NAME = "Customers">
					</MvIF>

					<MvDELETE NAME = "PriceGroupXCustomer">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "PriceGroup_Customer_FindOffset_Unassigned" PARAMETERS = "pgrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.open_cus" VALUE = "{ _DB_Store_Open_Customers() }">

	<MvIF EXPR = "{ l.open_cus AND _DB_Store_Open_PriceGroupXCustomer() }">
		<MvPRIMARY NAME = "Customers" INDEX = "{ g._DB_Store_Directory $ 'cust_id.mvx' }">
		<MvPRIMARY NAME = "PriceGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'pgxc_grp.mvx' }">

		<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.filter" VALUE = "{ _Customer_Filter( l.search ) }">
		<MvFILTER NAME = "Customers" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvSKIP NAME = "Customers" ROWS = "{ l.offset }">
		<MvWHILE EXPR = "{ ( NOT Customers.d.EOF ) AND ( NOT l.found ) }">
			<MvFIND NAME = "PriceGroupXCustomer" VALUE = "{ l.pgrp_id $ ':' $ padl( Customers.d.id, 10, '0' ) }" EXACT>
			<MvIF EXPR = "{ PriceGroupXCustomer.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

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

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

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

	<MvSKIP NAME = "Customers" ROWS = 1>
	<MvWHILE EXPR = "{ ( NOT Customers.d.EOF ) AND ( NOT l.found ) }">
		<MvFIND NAME = "PriceGroupXCustomer" VALUE = "{ l.pgrp_id $ ':' $ padl( Customers.d.id, 10, '0' ) }" EXACT>
		<MvIF EXPR = "{ PriceGroupXCustomer.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

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

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

<MvFUNCTION NAME = "PriceGroup_Customer_FindOffset_Assigned" PARAMETERS = "pgrp_id, offset, search" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.found" VALUE = 0>
	<MvASSIGN NAME = "l.newoffset" VALUE = "{ l.offset + 1 }">
	<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.open_cus" VALUE = "{ _DB_Store_Open_Customers() }">

	<MvIF EXPR = "{ l.open_cus AND _DB_Store_Open_PriceGroupXCustomer() }">
		<MvPRIMARY NAME = "Customers" INDEX = "{ g._DB_Store_Directory $ 'cust_id.mvx' }">
		<MvPRIMARY NAME = "PriceGroupXCustomer" INDEX = "{ g._DB_Store_Directory $ 'pgxc_grp.mvx' }">

		<MvDO FILE = "{ g.Module_Feature_CUS_DB }" NAME = "l.filter" VALUE = "{ _Customer_Filter( l.search ) }">
		<MvFILTER NAME = "Customers" FILTER = "l.filter" FILTER_TYPE = "variable">

		<MvFIND NAME = "PriceGroupXCustomer" VALUE = "{ l.pgrp_id $ ':' }">
		<MvSKIP NAME = "PriceGroupXCustomer" ROWS = "{ l.offset }">

		<MvWHILE EXPR = "{ ( NOT PriceGroupXCustomer.d.EOF ) AND ( PriceGroupXCustomer.d.pgrp_id EQ l.pgrp_id ) AND ( NOT l.found ) }">
			<MvFIND NAME = "Customers" VALUE = "{ PriceGroupXCustomer.d.cust_id }" EXACT>
			<MvIF EXPR = "{ NOT Customers.d.EOF }">
				<MvASSIGN NAME = "l.found" VALUE = 1>
				<MvWHILESTOP>
			</MvIF>

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

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

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

	<MvSKIP NAME = "PriceGroupXCustomer" ROWS = 1>

	<MvWHILE EXPR = "{ ( NOT PriceGroupXCustomer.d.EOF ) AND ( PriceGroupXCustomer.d.pgrp_id EQ l.pgrp_id ) AND ( NOT l.found ) }">
		<MvFIND NAME = "Customers" VALUE = "{ PriceGroupXCustomer.d.cust_id }" EXACT>
		<MvIF EXPR = "{ NOT Customers.d.EOF }">
			<MvASSIGN NAME = "l.found" VALUE = 1>
			<MvWHILESTOP>
		</MvIF>

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

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

