// updated stock classes

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12022 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone
2012-01-02 17:41:57 +00:00
parent 8fa12fda5b
commit e20374e6f7
10 changed files with 123 additions and 108 deletions
+4 -2
View File
@@ -607,7 +607,7 @@ class StockManagerCore implements StockManagerInterface
* @param float $price_te
* @return int WA
*/
protected function calculateWA($stock, $quantity, $price_te)
protected function calculateWA(Stock $stock, $quantity, $price_te)
{
return (float)Tools::ps_round(((($stock->physical_quantity * $stock->price_te) + ($quantity * $price_te)) / ($stock->physical_quantity + $quantity)), 6);
}
@@ -617,7 +617,9 @@ class StockManagerCore implements StockManagerInterface
*
* @param int $id_product
* @param int $id_product_attribute
* @return Collection
* @param int $id_warehouse Optional
* @param int $price_te Optional
* @return Collection of Stock
*/
protected function getStockCollection($id_product, $id_product_attribute, $id_warehouse = null, $price_te = null)
{
+5 -4
View File
@@ -105,8 +105,8 @@ interface StockManagerInterface
* @param int $quantity
* @param int $warehouse_from
* @param int $warehouse_to
* @param bool $usable_from true by default
* @param bool $usable_to true by default
* @param bool $usable_from Optional, true by default
* @param bool $usable_to Optional, true by default
* @return bool
*/
public function transferBetweenWarehouses($id_product, $id_product_attribute, $quantity, $warehouse_from, $warehouse_to, $usable_from = true, $usable_to = true);
@@ -118,8 +118,9 @@ interface StockManagerInterface
* @param int $id_product
* @param int $id_product_attribute
* @param int $coverage
* @param int $id_warehouse optional
* @param int $id_warehouse Optional
* @return int time
*/
public function getProductCoverage($id_product, $id_product_attribute, $coverage, $id_warehouse = null);
}
}
+4 -2
View File
@@ -178,7 +178,7 @@ class StockMvtCore extends ObjectModel
* @since 1.5.0
* @param int $id_order
* @param int $id_product
* @param int $id_product_attribute
* @param int $id_product_attribute Use 0 if the product does not have attributes
* @param int $quantity
* @param int $id_warehouse Optional
* @return Array mvts
@@ -213,8 +213,10 @@ class StockMvtCore extends ObjectModel
/**
* For a given product, gets the last positive stock mvt
*
* @since 1.5.0
* @param int $id_product
* @param int $id_product_attribute
* @param int $id_product_attribute Use 0 if the product does not have attributes
* @return bool|array
*/
public static function getLastPositiveStockMvt($id_product, $id_product_attribute)
+21 -22
View File
@@ -51,7 +51,7 @@ class SupplyOrderCore extends ObjectModel
public $id_warehouse;
/**
* @var int State of the order
* @var int Current state of the order
*/
public $id_supply_order_state;
@@ -120,10 +120,6 @@ class SupplyOrderCore extends ObjectModel
*/
public $is_template = 0;
/**
* @var array Contains object definition
* @see ObjectModel::definition
*/
/**
* @see ObjectModel::$definition
*/
@@ -209,10 +205,8 @@ class SupplyOrderCore extends ObjectModel
}
/**
* Check all products in this order and calculate prices
* Apply global discount if necessary
*
* @return array
* Checks all products in this order and calculate prices
* Applies the global discount if necessary
*/
protected function calculatePrices()
{
@@ -249,6 +243,7 @@ class SupplyOrderCore extends ObjectModel
/**
* Retrieves the product entries for the current order
*
* @param int $id_lang Optional Id Lang - Uses Context::language::id by default
* @return array
*/
public function getEntries($id_lang = null)
@@ -283,9 +278,9 @@ class SupplyOrderCore extends ObjectModel
}
/**
* Retrieves the product entries collection for the current order
* Retrieves the details entries (i.e. products) collection for the current order
*
* @return Collection
* @return Collection of SupplyOrderDetail
*/
public function getEntriesCollection()
{
@@ -298,7 +293,7 @@ class SupplyOrderCore extends ObjectModel
/**
* Check if the order has entries
*
* @return bool
* @return bool Has/Has not
*/
public function hasEntries()
{
@@ -311,13 +306,12 @@ class SupplyOrderCore extends ObjectModel
}
/**
* Check if the current state allow to edit the current order
* Check if the current state allows to edit the current order
*
* @return bool
*/
public function isEditable()
{
// build query
$query = new DbQuery();
$query->select('s.editable');
$query->from('supply_order_state', 's');
@@ -333,7 +327,6 @@ class SupplyOrderCore extends ObjectModel
*/
public function isDeliveryNoteAvailable()
{
// build query
$query = new DbQuery();
$query->select('s.delivery_note');
$query->from('supply_order_state', 's');
@@ -343,13 +336,12 @@ class SupplyOrderCore extends ObjectModel
}
/**
* Checks if the current state allows add products in stock
* Checks if the current state allows to add products in stock
*
* @return bool
*/
public function isInReceiptState()
{
// build query
$query = new DbQuery();
$query->select('s.receipt_state');
$query->from('supply_order_state', 's');
@@ -410,7 +402,7 @@ class SupplyOrderCore extends ObjectModel
/**
* For a given $id_supplier, tells if it has pending supply orders
*
* @param int $id_supplier
* @param int $id_supplier Id Supplier
* @return bool
*/
public static function supplierHasPendingOrders($id_supplier)
@@ -431,8 +423,9 @@ class SupplyOrderCore extends ObjectModel
/**
* For a given id or reference, tells if the supply order exists
* @param int|string $match
* @return int id
*
* @param int|string $match Either the reference of the order, or the Id of the order
* @return int SupplyOrder Id
*/
public static function exists($match)
{
@@ -451,7 +444,7 @@ class SupplyOrderCore extends ObjectModel
/**
* For a given reference, returns the corresponding supply order
*
* @param striing $reference
* @param string $reference Reference of the order
* @return bool|SupplyOrder
*/
public static function getSupplyOrderByReference($reference)
@@ -465,12 +458,18 @@ class SupplyOrderCore extends ObjectModel
$query->where('so.reference = "'.pSQL($reference).'"');
$id = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
if ($id === false)
if ($id == false)
return false;
return (new SupplyOrder((int)$id));
}
/*********************************\
*
* Webservices Specific Methods
*
*********************************/
/**
* Webservice : gets the ids supply_order_detail associated to this order
* @return array
+8 -5
View File
@@ -26,6 +26,7 @@
*/
/**
* Represents one product ordered
* @since 1.5.0
*/
class SupplyOrderDetailCore extends ObjectModel
@@ -211,11 +212,9 @@ class SupplyOrderDetailCore extends ObjectModel
}
/**
* Determines all prices for this product based on its quantity and unit price
* Calculates all prices for this product based on its quantity and unit price
* Applies discount if necessary
* Calculates tax value in function of tax rate
*
* @return array
* Calculates tax value, function of tax rate
*/
protected function calculatePrices()
{
@@ -239,7 +238,8 @@ class SupplyOrderDetailCore extends ObjectModel
}
/**
* Applies a global order discount rate on the current product entity
* Applies a global order discount rate, for the current product (i.e detail)
* Calls ObjectModel::update()
*
* @param $discount_rate The discount rate in percent (Ex. 5 for 5 percents)
*/
@@ -261,6 +261,9 @@ class SupplyOrderDetailCore extends ObjectModel
/**
* @see ObjectModel::validateController()
*
* @param $htmlentities Optional
* @return $errors If any..
*/
public function validateController($htmlentities = true)
{
+3 -3
View File
@@ -31,12 +31,12 @@
class SupplyOrderHistoryCore extends ObjectModel
{
/**
* @var int Supply order
* @var int Supply order Id
*/
public $id_supply_order;
/**
* @var int Employee
* @var int Employee Id
*/
public $id_employee;
@@ -51,7 +51,7 @@ class SupplyOrderHistoryCore extends ObjectModel
public $employee_lastname;
/**
* @var int State
* @var int State of the supply order
*/
public $id_state;
+2 -1
View File
@@ -26,12 +26,13 @@
*/
/**
* History of receipts
* @since 1.5.0
*/
class SupplyOrderReceiptHistoryCore extends ObjectModel
{
/**
* @var int Detail of the supply order
* @var int Detail of the supply order (i.e. One particular product)
*/
public $id_supply_order_detail;
+6 -6
View File
@@ -41,7 +41,7 @@ class SupplyOrderStateCore extends ObjectModel
public $delivery_note;
/**
* @var bool Tells if the order is still editable by an employee
* @var bool Tells if the order is still editable by an employee (i.e. you can add products)
*/
public $editable;
@@ -56,12 +56,12 @@ class SupplyOrderStateCore extends ObjectModel
public $pending_receipt;
/**
* @var bool Tells if the the order is in an enclosed state
* @var bool Tells if the the order is in an enclosed state (i.e. terminated, canceled)
*/
public $enclosed;
/**
* @var string Display state in the specified color (Ex. #FFFF00)
* @var string Color used to display the state in the specified color (Ex. #FFFF00)
*/
public $color;
@@ -96,9 +96,9 @@ class SupplyOrderStateCore extends ObjectModel
/**
* Gets the list of supply order states
*
* @param int $id_state_referrer The state refferer id used to know what state is available after the current state refferer
* @param int $id_lang The language id
* @return array
* @param int $id_state_referrer Optional, used to know what state is available after this one
* @param int $id_lang Optional Id Language
* @return array States
*/
public static function getSupplyOrderStates($id_state_referrer = null, $id_lang = null)
{
+57 -49
View File
@@ -50,7 +50,7 @@ class WarehouseCore extends ObjectModel
/** @var int Id of the valuation currency of the warehouse */
public $id_currency;
/** @var boolean True if warehouse has been deleted (hence, no deletion in DB) */
/** @var bool True if warehouse has been deleted (hence, no deletion in DB) */
public $deleted = 0;
/**
@@ -111,9 +111,9 @@ class WarehouseCore extends ObjectModel
);
/**
* Gets the shops (id and name) associated to the current warehouse
* Gets the shops associated to the current warehouse
*
* @return array
* @return array Shops (id, name)
*/
public function getShops()
{
@@ -130,7 +130,7 @@ class WarehouseCore extends ObjectModel
/**
* Sets the shops associated to the current warehouse
*
* @param array $ids_shop
* @param array $ids_shop Ids to set
*/
public function setShops($ids_shop)
{
@@ -151,7 +151,7 @@ class WarehouseCore extends ObjectModel
/**
* Gets the carriers associated to the current warehouse
*
* @return array ids
* @return array Ids of the associated carriers
*/
public function getCarriers()
{
@@ -197,8 +197,8 @@ class WarehouseCore extends ObjectModel
* For a given carrier, removes it from the warehouse/carrier association
* If $id_warehouse is set, it only removes the carrier for this warehouse
*
* @param int $id_carrier
* @param int $id_warehouse optional
* @param int $id_carrier Id of the carrier to remove
* @param int $id_warehouse optional Id of the warehouse to filter
*/
public static function removeCarrier($id_carrier, $id_warehouse = null)
{
@@ -209,7 +209,7 @@ class WarehouseCore extends ObjectModel
}
/**
* Checks if a warehouse is empty - i.e. holds no stock
* Checks if a warehouse is empty - i.e. has no stock
*
* @return bool
*/
@@ -226,7 +226,7 @@ class WarehouseCore extends ObjectModel
* Checks if the given warehouse exists
*
* @param int $id_warehouse
* @return bool
* @return bool Exists/Does not exist
*/
public static function exists($id_warehouse)
{
@@ -240,33 +240,34 @@ class WarehouseCore extends ObjectModel
/**
* For a given {product, product attribute} sets its location in the given warehouse
* First, for the given parameters, it cleans the database before updating
*
* @param int $id_product
* @param int $id_product_attribute
* @param int $id_warehouse
* @param string $location
* @return bool
* @param int $id_product ID of the product
* @param int $id_product_attribute Use 0 if this product does not have attributes
* @param int $id_warehouse ID of the warehouse
* @param string $location Describes the location (no lang id required)
* @return bool Success/Failure
*/
public static function setProductLocation($id_product, $id_product_attribute, $id_warehouse, $location)
{
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'warehouse_product_location` wpl
WHERE wpl.`id_product` = '.(int)$id_product.'
AND wpl.`id_product_attribute` = '.(int)$id_product_attribute.'
AND wpl.`id_warehouse` = '.(int)$id_warehouse);
$query = '
UPDATE `'._DB_PREFIX_.'warehouse_product_location`
SET `location` = \''.pSQL($location).'\'
DELETE FROM `'._DB_PREFIX_.'warehouse_product_location`
WHERE `id_product` = '.(int)$id_product.'
AND `id_product_attribute` = '.(int)$id_product_attribute.'
AND `id_warehouse` = '.(int)$id_warehouse;
AND `id_warehouse` = '.(int)$id_warehouse);
return (Db::getInstance()->execute($query));
$row_to_insert = array(
'id_product' => (int)$id_product,
'id_product_attribute' => (int)$id_product_attribute,
'id_warehouse' => (int)$id_warehouse,
'location' => pSQL($location),
);
return Db::getInstance()->autoExecute(_DB_PREFIX_.'warehouse_product_location', $row_to_insert, 'INSERT');
}
/**
* Reset all product locations for this warehouse
* Resets all product locations for this warehouse
*/
public function resetProductsLocations()
{
@@ -278,10 +279,10 @@ class WarehouseCore extends ObjectModel
/**
* For a given {product, product attribute} gets its location in the given warehouse
*
* @param int $id_product
* @param int $id_product_attribute
* @param int $id_warehouse
* @return string
* @param int $id_product ID of the product
* @param int $id_product_attribute Use 0 if this product does not have attributes
* @param int $id_warehouse ID of the warehouse
* @return string Location of the product
*/
public static function getProductLocation($id_product, $id_product_attribute, $id_warehouse)
{
@@ -298,10 +299,10 @@ class WarehouseCore extends ObjectModel
/**
* For a given {product, product attribute} gets warehouse list
*
* @param int $id_product
* @param int $id_product_attribute
* @param int $id_shop
* @return array
* @param int $id_product ID of the product
* @param int $id_product_attribute Optional, uses 0 if this product does not have attributes
* @param int $id_shop Optional, ID of the shop. Uses the context shop id (@see Context::shop)
* @return array Warehouses (ID, reference/name concatenated)
*/
public static function getProductWarehouseList($id_product, $id_product_attribute = 0, $id_shop = null)
{
@@ -325,9 +326,9 @@ class WarehouseCore extends ObjectModel
* Gets available warehouses
* It is possible via ignore_shop and id_shop to filter the list with shop id
*
* @param bool $ignore_shop false by default
* @param int $id_shop null by default
* @return array
* @param bool $ignore_shop Optional, false by default - Allows to get only the warehouses that are associated to one/some shops (@see $id_shop)
* @param int $id_shop Optional, Context::shop::Id by default - Allows to define a specific shop to filter.
* @return array Warehouses (ID, reference/name concatenated)
*/
public static function getWarehouses($ignore_shop = false, $id_shop = null)
{
@@ -347,9 +348,9 @@ class WarehouseCore extends ObjectModel
}
/**
* Gets ids of warehouses, grouped by ids of shops
* Gets warehouses grouped by shops
*
* @return array
* @return array (of array) Warehouses ID are grouped by shops ID
*/
public static function getWarehousesGroupedByShops()
{
@@ -369,7 +370,7 @@ class WarehouseCore extends ObjectModel
/**
* Gets the number of products in the current warehouse
*
* @return int
* @return int Number of different id_stock
*/
public function getNumberOfProducts()
{
@@ -389,7 +390,7 @@ class WarehouseCore extends ObjectModel
/**
* Gets the number of quantities - for all products - in the current warehouse
*
* @return int
* @return int Total Quantity
*/
public function getQuantitiesOfProducts()
{
@@ -406,7 +407,7 @@ class WarehouseCore extends ObjectModel
/**
* Gets the value of the stock in the current warehouse
*
* @return int
* @return int Value of the stock
*/
public function getStockValue()
{
@@ -419,10 +420,10 @@ class WarehouseCore extends ObjectModel
}
/**
* For a given employee, gets the warehouse(s) he manages
* For a given employee, gets the warehouse(s) he/she manages
*
* @param int $id_employee
* @return array ids_warehouse
* @param int $id_employee Manager ID
* @return array ids_warehouse Ids of the warehouses
*/
public static function getWarehousesByEmployee($id_employee)
{
@@ -437,9 +438,9 @@ class WarehouseCore extends ObjectModel
/**
* For a given product, returns the warehouses it is stored in
*
* @param int $id_product
* @param int $id_product_attribute
* @return array
* @param int $id_product Product Id
* @param int $id_product_attribute Optional, Product Attribute Id - 0 by default (no attribues)
* @return array Warehouses Ids and names
*/
public static function getWarehousesByProductId($id_product, $id_product_attribute = 0)
{
@@ -461,8 +462,9 @@ class WarehouseCore extends ObjectModel
/**
* For a given $id_warehouse, returns its name
* @param int $id_warehouse
* @return string name
*
* @param int $id_warehouse Warehouse Id
* @return string Name
*/
public static function getWarehouseNameById($id_warehouse)
{
@@ -473,6 +475,12 @@ class WarehouseCore extends ObjectModel
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
/*********************************\
*
* Webservices Specific Methods
*
*********************************/
/**
* Webservice : gets the value of the warehouse
* @return int
+13 -14
View File
@@ -30,22 +30,22 @@
class WarehouseProductLocationCore extends ObjectModel
{
/**
* @var integer product ID
* @var int product ID
* */
public $id_product;
/**
* @var integer product attribute ID
* @var int product attribute ID
* */
public $id_product_attribute;
/**
* @var integer the warehouse ID
* @var int warehouse ID
* */
public $id_warehouse;
/**
* @var string The location of the product
* @var string location of the product
* */
public $location;
@@ -77,12 +77,12 @@ class WarehouseProductLocationCore extends ObjectModel
);
/**
* For a given product and warehouse, get the location
* For a given product and warehouse, gets the location
*
* @param int $id_product
* @param int $id_product_attribute
* @param int $id_warehouse
* @return array
* @param int $id_product product ID
* @param int $id_product_attribute product attribute ID
* @param int $id_warehouse warehouse ID
* @return string $location Location of the product
*/
public static function getProductLocation($id_product, $id_product_attribute, $id_warehouse)
{
@@ -99,12 +99,12 @@ class WarehouseProductLocationCore extends ObjectModel
}
/**
* For a given product and warehouse, get the WarehouseProductLocation corresponding ID
* For a given product and warehouse, gets the WarehouseProductLocation corresponding ID
*
* @param int $id_product
* @param int $id_product_attribute
* @param int $id_supplier
* @return array
* @return int $id_warehouse_product_location ID of the WarehouseProductLocation
*/
public static function getIdByProductAndWarehouse($id_product, $id_product_attribute, $id_warehouse)
{
@@ -121,11 +121,10 @@ class WarehouseProductLocationCore extends ObjectModel
}
/**
* For a given product, retrieves its warehouses
* For a given product, gets its warehouses
*
* @param int $id_product
* @param int $id_lang
* @return Collection
* @return Collection The type of the collection is WarehouseProductLocation
*/
public static function getCollection($id_product)
{