<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/sta/sta_db.mv,v $
|
| Prefix         : MER-DTB-
| Next Error Code: 403  
| Next Text ID   : 184  
|
</MvCOMMENT>

<MvCOMMENT>
|
| Stats
|
</MvCOMMENT>

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

	<MvIF EXPR = "{ NOT g._DB_Store_Stats_Open OR ( l.store_id NE g._DB_Store_Stats_Open ) }">
		<MvIF EXPR = "{ g._DB_Store_Stats_Open }">
			<MvCLOSE NAME = "Stats">
		</MvIF>
		<MvOPEN NAME = "Stats"
			    DATABASE = "{g.MerchantPath $ padl( l.store_id, 8, '0' ) $ '/' $ 'stats.dbf' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00395', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_Stats_Open" VALUE = "{ l.store_id }">
		</MvIF>
	</MvIF>

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

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

	<MvIF EXPR = "{ NOT g._DB_Store_ProdStats_Open OR ( l.store_id NE g._DB_Store_ProdStats_Open )}">
		<MvIF EXPR = "{ g._DB_Store_ProdStats_Open }">
			<MvCLOSE NAME = "ProdStats">
		</MvIF>
		<MvOPEN NAME = "ProdStats"
				DATABASE = "{ g.MerchantPath $ padl( l.store_id, 8, '0' ) $ '/' $ 'prdsta.dbf' }"
				INDEXES = "{ g.MerchantPath $ padl( l.store_id, 8, '0' ) $ '/' $ 'prdsta_p.mvx, ' $
							 g.MerchantPath $ padl( l.store_id, 8, '0' ) $ '/' $ 'prdsta_c.mvx' }">
		<MvIF EXPR = "{ MvOPEN_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00396', MvOPEN_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_ProdStats_Open" VALUE = "{ l.store_id }">
		</MvIF>
	</MvIF>

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

<MvFUNCTION NAME = "STA_Store_Create" PARAMETERS = "store_id" STANDARDOUTPUTLEVEL = "" ERROROUTPUTLEVEL = "syntax, expression">
	<MvASSIGN NAME = "l.ok" VALUE = 1>
	<MvCREATE NAME = "Stats"
			  DATABASE = "{ g.MerchantPath $ padl( l.store_id, 8, '0' ) $ '/' $ 'stats.dbf' }"
			  FIELDS = "hits		NUMBER,
						visits		NUMBER,
						orders		NUMBER,
						revenue 	NUMBER ( 10.2 ),
						products	NUMBER,
						resetdate	DATE">
	<MvIF EXPR = "{ MvCREATE_Error }">
		<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00397', MvCREATE_Error ) }">
	<MvELSE>
		<MvASSIGN NAME = "Stats.d.hits" 	VALUE = "0">
		<MvASSIGN NAME = "Stats.d.visits" 	VALUE = "0">
		<MvASSIGN NAME = "Stats.d.orders" 	VALUE = "0">
		<MvASSIGN NAME = "Stats.d.revenue" 	VALUE = "0.00">
		<MvASSIGN NAME = "Stats.d.products" VALUE = "0">
		<MvASSIGN NAME = "Stats.d.resetdate" VALUE = "{s.dyn_time_t}">

		<MvADD NAME = "Stats">

	</MvIF>

	<MvIF EXPR = "{ l.ok }">	
		<MvCLOSE NAME = "Stats">
		<MvASSIGN NAME = "g._DB_Store_Stats_Open" VALUE = 0>
	</MvIF>
	
	<MvIF EXPR = "{ l.ok }">
		<MvCREATE NAME = "ProdStats"
				  DATABASE = "{ g.MerchantPath $ padl( l.store_id, 8, '0' ) $ '/' $ 'prdsta.dbf' }"
				  FIELDS = "product_id	NUMBER,
							count		NUMBER,
							prod_name	CHAR( 100 )">
		<MvIF EXPR = "{ MvCREATE_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00398', MvCREATE_Error ) }">
		<MvELSE>
			<MvASSIGN NAME = "g._DB_Store_ProdStats_Open" VALUE = 1>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "ProdStats"
						 INDEXFILE = "{ g.MerchantPath $ padl( l.store_id, 8, '0' ) $ '/' $ 'prdsta_p.mvx' }"
						 EXPRESSION = "{ ProdStats.d.product_id }"
						 FLAGS = "nounique, ascending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00399', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

		<MvIF EXPR = "{ l.ok }">
			<MvMAKEINDEX NAME = "ProdStats"
						 INDEXFILE = "{ g.MerchantPath $ padl( l.store_id, 8, '0' ) $ '/' $ 'prdsta_c.mvx' }"
						 EXPRESSION = "{ ProdStats.d.count }"
						 FLAGS = "nounique, descending">
			<MvIF EXPR = "{ MvMAKEINDEX_Error }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00400', MvMAKEINDEX_Error ) }">
			</MvIF>
		</MvIF>

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

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

<MvFUNCTION NAME = "STA_Store_Pack" PARAMETERS = "id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_Stats( l.id ) }">
	<MvIF EXPR = "{ l.ok }">
		<MvPACK NAME = "Stats">
		<MvIF EXPR = "{ MvPACK_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00401', MvPACK_Error ) }">
		<MvELSE>
			<MvCLOSE NAME = "Stats">
			<MvASSIGN NAME = "g._DB_Store_Stats_Open" VALUE = 0>
		</MvIF>
	</MvIF>

	<MvASSIGN NAME = "l.ok" VALUE = "{ _DB_Store_Open_ProdStats( l.id ) }">
	<MvIF EXPR = "{ l.ok }">
		<MvPACK NAME = "ProdStats">
		<MvIF EXPR = "{ MvPACK_Error }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-DTB-00402', MvPACK_Error ) }">
		<MvELSE>
			<MvCLOSE NAME = "ProdStats">
			<MvASSIGN NAME = "g._DB_Store_ProdStats_Open" VALUE = 0>
		</MvIF>
	</MvIF>

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