Primary stock functions

The primary stock functions are located directly on the MySQL server as stored functions/procedures. The reason to do this is the fact that those functions relarte to huge tables with high usage rate so they have to be implemented as “close” as possible to the data storage.

The following functions are implemented:

FUNCTION `canAlterStock`(`_productId` INT, `_date` DATETIME, `_theStock` DECIMAL(12,2)) RETURNS tinyint(1)

This function tells if the stock can be altered in the stock table
for the specified product and quantity, at the specified stock date.

Usage:
_theStock = positive => will increase the stock
_theStock = negative => will decrease the stock

Returns:
-1 : stock cannot be added as it will violate earlier stocks
-2 : stock cannot be added as it will violate later stock
1 : stock can be added safely

FUNCTION `getStock`(_productId INT) RETURNS decimal(12,2)

This function returns the current available stock for the specified product.

FUNCTION `getStockAtDate`(_productId INT, _date DATETIME) RETURNS decimal(12,2)

This function returns the stock for the specified product at the specified date.

About

Software Development Manager, Architect

Leave a Reply

Your email address will not be published. Required fields are marked *

[TOP]