<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/
|
| Inventory Control - Functions
| $Source: /home/cvs/merchant/Merchant/features/inv/inv_rt.mv,v $
|
| Prefix         : MER-INV-
| Next Error Code: 
0    
2    
| Next Text ID   : 
|
</MvCOMMENT>

<MvFUNCTION NAME = "INV_ShowProduct" PARAMETERS = "prod_id" STANDARDOUTPUTLEVEL = "">
	<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.found" VALUE = "{ INV_InventorySettings_Find() }">
	<MvIF EXPR = "{ l.found AND InventorySettings.d.active }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.product_found" VALUE = "{ INV_InventoryProductSettings_Find_ProdID( l.prod_id ) }">

		<MvIF EXPR = "{ l.product_found AND InventoryProductSettings.d.active }">
			<MvIF EXPR = "{ (InventoryProductSettings.d.out_hide EQ 'y') OR ( (InventoryProductSettings.d.out_hide EQ '') AND (InventorySettings.d.out_hide) ) }">
				<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.current_stock" VALUE = "{ INV_InventoryProductCount( l.prod_id ) }">

				<MvIF EXPR = "{ InventoryProductSettings.d.out_lvl_d }">
					<MvIF EXPR = "{ l.current_stock LE InventorySettings.d.out_level }">
						<MvFUNCTIONRETURN VALUE = "0">
					</MvIF>
				<MvELSE>
					<MvIF EXPR = "{ l.current_stock LE InventoryProductSettings.d.out_level }">
						<MvFUNCTIONRETURN VALUE = "0">
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>

	<MvFUNCTIONRETURN VALUE = 1>
</MvFUNCTION>

<MvFUNCTION NAME = "INV_Sell_Product" PARAMETERS = "prod_id" STANDARDOUTPUTLEVEL = "">
	<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.found" VALUE = "{ INV_InventorySettings_Find() }">
	<MvIF EXPR = "{ l.found AND InventorySettings.d.active }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.product_found" VALUE = "{ INV_InventoryProductSettings_Find_ProdID( l.prod_id ) }">

		<MvIF EXPR = "{ l.product_found AND InventoryProductSettings.d.active }">
			<MvIF EXPR = "{ (InventoryProductSettings.d.out_track EQ 'y') OR ( (InventoryProductSettings.d.out_track EQ '') AND (InventorySettings.d.out_track) ) }">
				<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.current_stock" VALUE = "{ INV_InventoryProductCount( l.prod_id ) }">
				<MvIF EXPR = "{ InventoryProductSettings.d.out_lvl_d }">
					<MvIF EXPR = "{ l.current_stock LE InventorySettings.d.out_level }">
						<MvFUNCTIONRETURN VALUE = "0">
					</MvIF>
				<MvELSE>
					<MvIF EXPR = "{ l.current_stock LE InventoryProductSettings.d.out_level }">
						<MvFUNCTIONRETURN VALUE = "0">
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>
		
	<MvFUNCTIONRETURN VALUE = 1>
</MvFUNCTION>

<MvFUNCTION NAME = "INV_Quantity_Available" PARAMETERS = "prod_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.available" VALUE = "">
	<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.found" VALUE = "{ INV_InventorySettings_Find() }">
	<MvIF EXPR = "{ l.found AND InventorySettings.d.active }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.product_found" VALUE = "{ INV_InventoryProductSettings_Find_ProdID( l.prod_id ) }">
		<MvIF EXPR = "{ l.product_found AND InventoryProductSettings.d.active }">
			<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.current_stock" VALUE = "{ INV_InventoryProductCount( l.prod_id ) }">
			<MvIF EXPR = "{ ( InventoryProductSettings.d.out_track EQ 'y' ) OR ( (InventoryProductSettings.d.out_track EQ '') AND InventorySettings.d.out_track ) }">
				<MvIF EXPR = "{ InventoryProductSettings.d.out_lvl_d }">
					<MvASSIGN NAME = "l.available" VALUE = "{ l.current_Stock - InventorySettings.d.out_level }">
				<MvELSE>
					<MvASSIGN NAME = "l.available" VALUE = "{ l.current_Stock - InventoryProductSettings.d.out_level }">
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.available }">
</MvFUNCTION>

<MvFUNCTION NAME = "INV_StockLevelCode" PARAMETERS = "prod_id" STANDARDOUTPUTLEVEL = "">
	<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.found" VALUE = "{ INV_InventorySettings_Find() }">
	<MvIF EXPR = "{ l.found AND InventorySettings.d.active }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.current_stock" VALUE = "{ INV_InventoryProductCount( l.prod_id ) }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.product_found" VALUE = "{ INV_InventoryProductSettings_Find_ProdID( l.prod_id ) }">

		<MvIF EXPR = "{ l.product_found AND InventoryProductSettings.d.active }">
			<MvIF EXPR = "{ InventoryProductSettings.d.out_track NE 'n' }">
				<MvIF EXPR = "{ (InventoryProductSettings.d.out_track EQ 'y') OR ( (InventoryProductSettings.d.out_track EQ '') AND (InventorySettings.d.out_track) ) }">
					<MvIF EXPR = "{ InventoryProductSettings.d.out_lvl_d }">
						<MvIF EXPR = "{ l.current_Stock LE InventorySettings.d.out_level }">
							<MvFUNCTIONRETURN VALUE = "out">
						</MvIF>
					<MvELSE>
						<MvIF EXPR = "{ l.current_Stock LE InventoryProductSettings.d.out_level }">
							<MvFUNCTIONRETURN VALUE = "out">
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>

			<MvIF EXPR = "{ InventoryProductSettings.d.low_track NE 'n' }">
				<MvIF EXPR = "{ (InventoryProductSettings.d.low_track EQ 'y') OR InventorySettings.d.low_track }">
					<MvIF EXPR = "{ InventoryProductSettings.d.low_lvl_d }">
						<MvIF EXPR = "{ l.current_stock LE InventorySettings.d.low_level }">
							<MvFUNCTIONRETURN VALUE = "low">
						</MvIF>
					<MvELSE>
						<MvIF EXPR = "{ l.current_stock LE InventoryProductSettings.d.low_level }">
							<MvFUNCTIONRETURN VALUE = "low">
						</MvIF>
					</MvIF>
				</MvIF>
			</MvIF>
			<MvFUNCTIONRETURN VALUE = "in">
		</MvIF>

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

<MvFUNCTION NAME = "INV_StockLevelShort" PARAMETERS = "prod_id" STANDARDOUTLEVEL = "">
	<MvASSIGN NAME = "l.code" VALUE = "{ INV_StockLevelCode( l.prod_id ) }">
	
	<MvIF EXPR = "{ l.code EQ 'in' }">
		<MvIF EXPR = "{ len( InventoryProductSettings.d.in_short ) }">
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventoryProductSettings.d.in_short ) }">
		<MvELSE>
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventorySettings.d.in_short ) }">
		</MvIF>
	</MvIF>
			
	<MvIF EXPR = "{ l.code EQ 'low' }">
		<MvIF EXPR = "{ len( InventoryProductSettings.d.low_short ) }">
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventoryProductSettings.d.low_short ) }">
		<MvELSE>
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventorySettings.d.low_short ) }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.code EQ 'out' }">
		<MvIF EXPR = "{ len( InventoryProductSettings.d.out_short ) }">
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventoryProductSettings.d.out_short ) }">
		<MvELSE>
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventorySettings.d.out_short ) }">
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "">
</MvFUNCTION>

<MvFUNCTION NAME = "INV_StockLevelLong" PARAMETERS = "prod_id">
	<MvASSIGN NAME = "l.code" VALUE = "{ INV_StockLevelCode( l.prod_id ) }">
	
	<MvIF EXPR = "{ l.code EQ 'in' }">
		<MvIF EXPR = "{ len( InventoryProductSettings.d.in_long ) }">
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventoryProductSettings.d.in_long ) }">
		<MvELSE>
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventorySettings.d.in_long ) }">
		</MvIF>
	</MvIF>
			
	<MvIF EXPR = "{ l.code EQ 'low' }">
		<MvIF EXPR = "{ len( InventoryProductSettings.d.low_long ) }">
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventoryProductSettings.d.low_long ) }">
		<MvELSE>
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventorySettings.d.low_long ) }">
		</MvIF>
	</MvIF>

	<MvIF EXPR = "{ l.code EQ 'out' }">
		<MvIF EXPR = "{ len( InventoryProductSettings.d.out_long ) }">
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventoryProductSettings.d.out_long ) }">
		<MvELSE>
			<MvFUNCTIONRETURN VALUE = "{ _INV_Tokenize( prod_id, InventorySettings.d.out_long ) }">
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "">
</MvFUNCTION>

<MvFUNCTION NAME = "INV_AdjustInventoryAsNeeded" PARAMETERS = "prod_id, adjustment"  STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "1">
	<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.found" VALUE = "{ INV_InventorySettings_Find() }">
	<MvIF EXPR = "{ l.found AND InventorySettings.d.active }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.product_found" VALUE = "{ INV_InventoryProductSettings_Find_ProdID( l.prod_id ) }">
		<MvIF EXPR = "{ l.product_found AND InventoryProductSettings.d.active }">
			<MvASSIGN NAME = "l.continue" VALUE = 1>
		
			<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ StoreModule_FindFirst_Type( 'SYSTEM' ) }">
			<MvWHILE EXPR = "{ l.found }">
				<MvDO FILE = "{ g.Module_Root $ Modules.d.module }" NAME = "l.version" VALUE = "{ Module_API_Version() }">
				
				<MvIF EXPR = "{ l.version GE 4.00 }">
					<MvDO FILE = "{ g.Module_Root $ Modules.d.module }" NAME = "l.result" VALUE = "{ SystemModule_Action_AdjustInventory() }">
		
					<MvIF EXPR = "{ l.result LE 0 }">
						<MvASSIGN NAME = "l.continue" VALUE = 0>

						<MvIF EXPR = "{ l.result EQ 0 }">
							<MvASSIGN NAME = "l.ok" VALUE = 0>
						</MvIF>

						<MvWHILESTOP>
					</MvIF>
				</MvIF>
		
				<MvDO FILE = "{ g.Module_Library_DB }" NAME = "l.found" VALUE = "{ StoreModule_FindNext_Type( 'SYSTEM' ) }">
			</MvWHILE>
		
			<MvIF EXPR = "{ l.ok }">
				<MvIF EXPR = "{ l.continue }">
					<MvASSIGN NAME = "l.old_stock_level" VALUE = "{ INV_StockLevelCode( l.prod_id ) }">
					<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.ok" VALUE = "{ INV_InventoryProductCounts_Adjust( l.prod_id, l.adjustment ) }">
					<MvASSIGN NAME = "l.new_stock_level" VALUE = "{ INV_StockLevelCode( l.prod_id ) }">
					<MvIF EXPR = "{ (l.adjustment LT 0) AND ( l.old_stock_level NE l.new_stock_level)}">
						<MvIF EXPR = "{ InventorySettings.d.eml_out AND (l.new_stock_level EQ 'out')}">
							<MvASSIGN NAME = "l.ok" VALUE = "{ _INV_EmailNotification( l.prod_id ) }">
						<MvELSE>
							<MvIF EXPR = "{ InventorySettings.d.eml_low AND (l.old_stock_level EQ 'in')}">
								<MvASSIGN NAME = "l.ok" VALUE = "{ _INV_EmailNotification( l.prod_id ) }">
							</MvIF>
						</MvIF>
						<MvIF EXPR = "{ l.ok }">
							<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Log_Action_InventoryLevelChange( l.old_stock_level, l.new_stock_level ) }">
						</MvIF>

					</MvIF>
					<MvIF EXPR = "{ l.ok }">
						<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Log_Action_InventoryAdjustment( l.adjustment ) }">
					</MvIF>
				</MvIF>
			</MvIF>
		</MvIF>
	</MvIF>
	
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "_INV_EmailNotification" PARAMETERS = "prod_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "1">

	<MvASSIGN NAME = "l.from" VALUE = "{ InventorySettings.d.eml_from }">
	<MvASSIGN NAME = "l.to" VALUE = "{ InventorySettings.d.eml_to }">
	<MvASSIGN NAME = "l.cc" VALUE = "{ InventorySettings.d.eml_cc }">
	<MvASSIGN NAME = "l.subject" VALUE = "{ _INV_Tokenize( prod_id, InventorySettings.d.eml_sub ) }">
	<MvASSIGN NAME = "l.message" VALUE = "{ _INV_Tokenize( prod_id, InventorySettings.d.eml_msg ) }">

	<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.null" VALUE = "{ SendEmail( l.to,l.from,l.cc,l.subject,l.headers,l.message ) }">
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "INV_Quantity_Not_Available" PARAMETERS = "prod_id, available" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.ok" VALUE = "1">
	
	<MvIF EXPR = "{ l.available LE 0 }" >
		<MvIF EXPR = "{ len( InventoryProductSettings.d.out_long ) }">
			<MvASSIGN NAME = "l.message" VALUE = "{ _INV_Tokenize( l.prod_id, InventoryProductSettings.d.out_long ) }">
		<MvELSE>
			<MvASSIGN NAME = "l.message" VALUE = "{ _INV_Tokenize( l.prod_id, InventorySettings.d.out_long) }">
		</MvIF>
		<MvDO FILE = "{ g.module_root $ g.Store_Module_UI }" NAME = "l.ui_api_version" VALUE = "{ Module_API_Version() }">

		<MvIF EXPR = "{ l.ui_api_version LT 4.0 }">
			<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-INV-00000', l.message ) }">
		<MvELSE>
			<MvDO FILE = "{ g.module_root $ g.Store_Module_UI }" NAME = "l.ui_api_version" VALUE = "{ UIModule_Product_Out( l.message ) }">
		</MvIF>
	<MvELSE>
		<MvIF EXPR = "{ (l.available LE g.Quantity ) AND ( (InventoryProductSettings.d.out_track EQ 'y') OR ( (InventoryProductSettings.d.out_track EQ '') AND ( InventorySettings.d.out_track ) ) )}">
			<MvIF EXPR = "{ len( InventoryProductSettings.d.ltd_long ) }">
				<MvASSIGN NAME = "l.message" VALUE = "{ _INV_Tokenize( l.prod_id, InventoryProductSettings.d.ltd_long) }">
			<MvELSE>
				<MvASSIGN NAME = "l.message" VALUE = "{ _INV_Tokenize( l.prod_id, InventorySettings.d.ltd_long) }">
			</MvIF>
			<MvDO FILE = "{ g.module_root $ g.Store_Module_UI }" NAME = "l.ui_api_version" VALUE = "{ Module_API_Version() }">

			<MvIF EXPR = "{ l.ui_api_version LT 4.0 }">
				<MvDO FILE = "{ g.Module_Library_Utilities }" NAME = "l.ok" VALUE = "{ Error( 'MER-INV-00001', l.message ) }">
			<MvELSE>
				<MvDO FILE = "{ g.module_root $ g.Store_Module_UI }" NAME = "l.ui_api_version" VALUE = "{ UIModule_Product_Limited( l.message, l.available ) }">
			</MvIF>
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "{ l.ok }">
</MvFUNCTION>

<MvFUNCTION NAME = "INV_TrackOut" PARAMETERS = "prod_id" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.track" VALUE = "0">
	<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.found" VALUE = "{ INV_InventorySettings_Find() }">
	<MvIF EXPR = "{ l.found AND InventorySettings.d.active }">
		<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.product_found" VALUE = "{ INV_InventoryProductSettings_Find_ProdID( l.prod_id ) }">
		<MvIF EXPR = "{ l.product_found AND InventoryProductSettings.d.active AND ( ( InventoryProductSettings.d.out_track EQ 'y' ) OR ( ( InventoryProductSettings.d.out_track EQ '' ) AND ( InventorySettings.d.out_track ) ) ) }">
			<MvASSIGN NAME = "l.track" VALUE = "1">
		</MvIF>
	</MvIF>
	
	<MvFUNCTIONRETURN VALUE = "l.track">
</MvFUNCTION>

<MvFUNCTION NAME = "_INV_Tokenize" PARAMETERS = "prod_id, text" STANDARDOUTPUTLEVEL = "">
	<MvASSIGN NAME = "l.text" VALUE = "{ glosub( l.text, '%product_name%', Products.d.name ) }">	
	<MvASSIGN NAME = "l.text" VALUE = "{ glosub( l.text, '%product_code%', Products.d.code ) }">

	<MvDO FILE = "{ g.Module_Feature_INV_DB }" NAME = "l.current_stock" VALUE = "{ INV_InventoryProductCount( l.prod_id ) }">

	<MvIF EXPR = "{ InventoryProductSettings.d.low_lvl_d }">
		<MvASSIGN NAME = "l.in_stock" VALUE = "{ l.current_Stock - InventorySettings.d.low_level }">
	<MvELSE>
		<MvASSIGN NAME = "l.in_stock" VALUE = "{ l.current_Stock - InventoryProductSettings.d.low_level }">
	</MvIF>
	<MvASSIGN NAME = "l.text" VALUE = "{ glosub( l.text, '%inv_instock%', l.in_stock ) }">

	<MvIF EXPR = "{ InventoryProductSettings.d.out_lvl_d }">
		<MvASSIGN NAME = "l.available" VALUE = "{ l.current_Stock - InventorySettings.d.out_level }">
	<MvELSE>
		<MvASSIGN NAME = "l.available" VALUE = "{ l.current_Stock - InventoryProductSettings.d.out_level }">
	</MvIF>
	<MvASSIGN NAME = "l.text" VALUE = "{ glosub( l.text, '%inv_available%', l.available ) }">
	
	<MvASSIGN NAME = "l.text" VALUE = "{ glosub( l.text, '%inv_level%', INV_StockLevelCode( prod_id ) ) }">

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