// Stock : updated Stock & StockMvt & StockMvtReason
This commit is contained in:
Executable → Regular
+34
-20
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -20,25 +20,47 @@
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 1.4 $
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents the products kept in warehouses
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class StockCore extends ObjectModel
|
||||
{
|
||||
public $id_warehouse;
|
||||
public $id_product;
|
||||
public $id_product_attribute;
|
||||
public $id_group_shop;
|
||||
public $id_shop;
|
||||
public $quantity;
|
||||
public $physical_quantity;
|
||||
public $usable_quantity;
|
||||
public $price_te;
|
||||
public $id_currency;
|
||||
|
||||
protected $fieldsRequired = array(
|
||||
'id_warehouse',
|
||||
'id_product',
|
||||
'id_product_attribute',
|
||||
'physical_quantity',
|
||||
'usable_quantity',
|
||||
'price_te',
|
||||
'id_currency'
|
||||
);
|
||||
|
||||
protected $fieldsRequired = array('id_shop', 'id_group_shop', 'id_product', 'id_product_attribute');
|
||||
protected $fieldsSize = array();
|
||||
protected $fieldsValidate = array();
|
||||
|
||||
protected $fieldsValidate = array(
|
||||
'id_warehouse' => 'isUnsignedId',
|
||||
'id_product' => 'isUnsignedId',
|
||||
'id_product_attribute' => 'isUnsignedId',
|
||||
'physical_quantity' => 'isUnsignedInt',
|
||||
'usable_quantity' => 'isInt',
|
||||
'price_te' => 'isPrice',
|
||||
'id_currency' => 'isUnsignedInt'
|
||||
);
|
||||
|
||||
protected $table = 'stock';
|
||||
protected $identifier = 'id_stock';
|
||||
@@ -46,21 +68,13 @@ class StockCore extends ObjectModel
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields['id_warehouse'] = (int)$this->id_warehouse;
|
||||
$fields['id_product'] = (int)$this->id_product;
|
||||
$fields['id_product_attribute'] = (int)$this->id_product_attribute;
|
||||
$fields['id_group_shop'] = (int)$this->id_group_shop;
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
$fields['quantity'] = (int)$this->quantity;
|
||||
$fields['physical_quantity'] = (int)$this->physical_quantity;
|
||||
$fields['usable_quantity'] = (int)$this->usable_quantity;
|
||||
$fields['price_te'] = (float)$this->price_te;
|
||||
$fields['id_currency'] = (int)$this->id_currency;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public static function getStockId($id_product, $id_product_attribute, $shopID)
|
||||
{
|
||||
$sql = 'SELECT id_stock
|
||||
FROM '._DB_PREFIX_.'stock
|
||||
WHERE id_product = '.(int)$id_product.'
|
||||
AND id_product_attribute = '.(int)$id_product_attribute.'
|
||||
AND id_shop = '.(int)$shopID;
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
}
|
||||
Executable → Regular
+104
-35
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -20,73 +20,142 @@
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7307 $
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class StockMvtCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
public $id;
|
||||
public $date_add;
|
||||
public $id_employee;
|
||||
|
||||
/**
|
||||
* @since 1.5.0 id_stock replace old id_product and id_product_attribute fields in this table
|
||||
* @since 1.5.0
|
||||
* @var int
|
||||
*/
|
||||
public $id_stock;
|
||||
public $id_stock;
|
||||
|
||||
public $id_order = NULL;
|
||||
public $id_employee = NULL;
|
||||
public $quantity;
|
||||
public $id_stock_mvt_reason;
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @var int
|
||||
*/
|
||||
public $physical_quantity;
|
||||
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
public $id_stock_mvt_reason;
|
||||
public $id_order = null;
|
||||
|
||||
protected $table = 'stock_mvt';
|
||||
protected $identifier = 'id_stock_mvt';
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @var int
|
||||
*/
|
||||
public $sign;
|
||||
|
||||
protected $fieldsRequired = array('id_stock', 'id_stock_mvt_reason', 'quantity');
|
||||
protected $fieldsValidate = array(
|
||||
'id_stock' => 'isUnsignedId',
|
||||
'id_order' => 'isUnsignedId',
|
||||
'id_employee' => 'isUnsignedId',
|
||||
'quantity' => 'isInt',
|
||||
'id_stock_mvt_reason' => 'isUnsignedId',
|
||||
);
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @var int Will be used when supplier order are implemented
|
||||
*/
|
||||
public $id_supplier_order = null;
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @var float Last value of the weighted-average method
|
||||
*/
|
||||
public $last_wa = null;
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @var float Current value of the weighted-average method
|
||||
*/
|
||||
public $current_wa = null;
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @var float
|
||||
*/
|
||||
public $price_te;
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @var int Refers to an other id_stock_mvt : used for LIFO/FIFO implementation in StockManager
|
||||
*/
|
||||
public $referer;
|
||||
|
||||
/**
|
||||
* @deprecated since 1.5.0
|
||||
* @deprecated stock movement will not be updated anymore
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @deprecated since 1.5.0
|
||||
* @see physical_quantity
|
||||
* @var int
|
||||
*/
|
||||
public $quantity;
|
||||
|
||||
protected $table = 'stock_mvt';
|
||||
protected $identifier = 'id_stock_mvt';
|
||||
|
||||
protected $fieldsRequired = array(
|
||||
'date_add',
|
||||
'id_employee',
|
||||
'id_stock',
|
||||
'physical_quantity',
|
||||
'id_stock_mvt_reason',
|
||||
'sign',
|
||||
'price_te'
|
||||
);
|
||||
|
||||
protected $fieldsValidate = array(
|
||||
'date_add' => 'isDate',
|
||||
'id_employee' => 'isUnsignedId',
|
||||
'id_stock' => 'isUnsignedId',
|
||||
'physical_quantity' => 'isUnsignedInt',
|
||||
'id_stock_mvt_reason' => 'isUnsignedId',
|
||||
'id_order' => 'isUnsignedId',
|
||||
'sign' => 'isInt',
|
||||
'last_wa' => 'isPrice',
|
||||
'current_wa' => 'isPrice',
|
||||
'price_te' => 'isPrice',
|
||||
'referer' => 'isUnsignedId'
|
||||
);
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'objectsNodeName' => 'stock_movements',
|
||||
'objectNodeName' => 'stock_movement',
|
||||
'fields' => array(
|
||||
'id_product' => array('xlink_resource'=> 'products'),
|
||||
'id_product_attribute' => array('xlink_resource'=> 'product_option_values'),
|
||||
'id_order' => array('xlink_resource'=> 'orders'),
|
||||
'id_employee' => array('xlink_resource'=> 'employees'),
|
||||
'id_stock' => array('xlink_resource'=> 'stock'),
|
||||
'id_stock_mvt_reason' => array('xlink_resource'=> 'stock_movement_reasons'),
|
||||
'id_order' => array('xlink_resource'=> 'orders')
|
||||
),
|
||||
);
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields['id_stock'] = (int)$this->id_stock;
|
||||
$fields['id_order'] = (int)$this->id_order;
|
||||
$fields['id_employee'] = (int)$this->id_employee;
|
||||
$fields['id_stock_mvt_reason'] = (int)$this->id_stock_mvt_reason;
|
||||
$fields['quantity'] = (int)$this->quantity;
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
$fields['id_employee'] = (int)$this->id_employee;
|
||||
$fields['id_stock'] = (int)$this->id_stock;
|
||||
$fields['physical_quantity'] = (int)$this->physical_quantity;
|
||||
$fields['id_stock_mvt_reason'] = (int)$this->id_stock_mvt_reason;
|
||||
$fields['id_order'] = (int)$this->id_order;
|
||||
$fields['sign'] = (int)$this->sign;
|
||||
$fields['last_wa'] = (float)$this->last_wa;
|
||||
$fields['current_wa'] = (float)$this->current_wa;
|
||||
$fields['price_te'] = (float)$this->price_te;
|
||||
$fields['referer'] = (int)$this->referer;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add missing stock movement (compare the quantity of a products with all movements : if there is a difference, create a stock movement to correct it)
|
||||
*
|
||||
* @param int $id_employee
|
||||
* @deprecated since 1.5.0
|
||||
*/
|
||||
public static function addMissingMvt($id_employee)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
// Search missing stock movement on products without attributes
|
||||
$sql = 'SELECT s.id_stock, (stock.quantity - SUM(IFNULL(sm.quantity, 0))) AS qty
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
@@ -119,7 +188,7 @@ class StockMvtCore extends ObjectModel
|
||||
// Add missing stock movements
|
||||
$products = array_merge($products_without_attributes, $products_with_attributes);
|
||||
if ($products)
|
||||
foreach ($products AS $product)
|
||||
foreach ($products as $product)
|
||||
{
|
||||
$mvt = new StockMvt();
|
||||
$mvt->id_stock = $product['id_stock'];
|
||||
Executable → Regular
+37
-25
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -20,34 +20,30 @@
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7307 $
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class StockMvtReasonCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
public $name;
|
||||
|
||||
public $sign;
|
||||
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
|
||||
protected $table = 'stock_mvt_reason';
|
||||
protected $identifier = 'id_stock_mvt_reason';
|
||||
|
||||
public $id;
|
||||
public $name;
|
||||
public $sign;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
protected $table = 'stock_mvt_reason';
|
||||
protected $identifier = 'id_stock_mvt_reason';
|
||||
|
||||
protected $fieldsRequiredLang = array('name');
|
||||
protected $fieldsSizeLang = array('name' => 255);
|
||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
protected $fieldsRequiredLang = array('name');
|
||||
protected $fieldsSizeLang = array('name' => 255);
|
||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'objectsNodeName' => 'stock_movement_reasons',
|
||||
'objectNodeName' => 'stock_movement_reason',
|
||||
);
|
||||
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
@@ -56,18 +52,34 @@ class StockMvtReasonCore extends ObjectModel
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
public function getTranslationsFieldsChild()
|
||||
{
|
||||
$this->validateFieldsLang();
|
||||
return $this->getTranslationsFields(array('name'));
|
||||
}
|
||||
|
||||
|
||||
public static function getStockMvtReasons($id_lang)
|
||||
{
|
||||
$sql = 'SELECT smrl.name, smr.id_stock_mvt_reason, smr.sign
|
||||
FROM '._DB_PREFIX_.'stock_mvt_reason smr
|
||||
LEFT JOIN '._DB_PREFIX_.'stock_mvt_reason_lang smrl ON (smr.id_stock_mvt_reason = smrl.id_stock_mvt_reason AND smrl.id_lang='.(int)$id_lang.')';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
$query = new DbQuery();
|
||||
$query->select('smrl.name, smr.id_stock_mvt_reason, smr.sign');
|
||||
$query->from('stock_mvt_reason smr');
|
||||
$query->leftjoin('stock_mvt_reason_lang smrl ON (smr.id_stock_mvt_reason = smrl.id_stock_mvt_reason AND smrl.id_lang='.(int)$id_lang.')');
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param int $id_stock_mvt_reason
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($id_stock_mvt_reason)
|
||||
{
|
||||
$query = new DbQuery();
|
||||
$query->select('smr.id_stock_mvt_reason');
|
||||
$query->from('stock_mvt_reason smr');
|
||||
$query->where('smr.id_stock_mvt_reason = '.(int)$id_stock_mvt_reason);
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user