// Manage SQL upgrade for stock management
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
function add_stock_tab()
|
||||
{
|
||||
// Patch for the 1.0.1 sql update
|
||||
Db::getInstance()->query('
|
||||
DELETE
|
||||
FROM `'._DB_PREFIX_.'tab`
|
||||
WHERE id_parent = 1
|
||||
AND class_name = "AdminStocks"');
|
||||
|
||||
// Create new tabs
|
||||
$id_parent = add_new_tab(
|
||||
'AdminStock',
|
||||
'en:Stock|fr:Stock|es:Stock|de:Stock|it:Stock',
|
||||
0,
|
||||
true);
|
||||
|
||||
add_new_tab(
|
||||
'AdminWarehouses',
|
||||
'en:Warehouses|fr:Entrepôts|es:Warehouses|de:Warehouses|it:Warehouses',
|
||||
$id_parent);
|
||||
|
||||
add_new_tab(
|
||||
'AdminStockManagement',
|
||||
'en:Stock Management|fr:Gestion du stock|es:Stock Management|de:Stock Management|it:Stock Management',
|
||||
$id_parent);
|
||||
|
||||
add_new_tab(
|
||||
'AdminStockMvt',
|
||||
'en:Stock Movement|fr:Mouvements de Stock|es:Stock Movement|de:Stock Movement|it:Stock Movement',
|
||||
$id_parent);
|
||||
|
||||
add_new_tab(
|
||||
'AdminStockInstantState',
|
||||
'en:Stock instant state|fr:Etat instantané du stock|es:Stock instant state|de:Stock instant state|it:Stock instant state',
|
||||
$id_parent);
|
||||
|
||||
add_new_tab(
|
||||
'AdminStockCover',
|
||||
'en:Stock cover|fr:Couverture du stock|es:Stock cover|de:Stock cover|it:Stock cover',
|
||||
$id_parent);
|
||||
|
||||
add_new_tab(
|
||||
'AdminSupplyOrders',
|
||||
'en:Supply orders|fr:Commandes fournisseurs|es:Supply orders|de:Supply orders|it:Supply orders',
|
||||
$id_parent);
|
||||
|
||||
add_new_tab(
|
||||
'AdminStockConfiguration',
|
||||
'en:Configuration|fr:Configuration|es:Configuration|de:Configuration|it:Configuration',
|
||||
$id_parent);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
function set_product_suppliers()
|
||||
{
|
||||
//Get all products with positive quantity
|
||||
$resource = Db::getInstance()->query('
|
||||
SELECT id_supplier, id_product, supplier_reference, wholesale_price
|
||||
FROM `'._DB_PREFIX_.'product`
|
||||
WHERE `id_supplier` > 0
|
||||
');
|
||||
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
{
|
||||
//Set default supplier for product
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'product_supplier`
|
||||
(`id_product`, `id_product_attribute`, `id_supplier`, `product_supplier_reference`, `product_supplier_price_te`, `id_currency`)
|
||||
VALUES
|
||||
("'.(int)$row['id_product'].'", "0", "'.(int)$row['id_supplier'].'", "'.(int)$row['supplier_reference'].'", "'.(int)$row['wholesale_price'].'", "'.(int)Configuration::get('PS_CURRENCY_DEFAULT').'")
|
||||
');
|
||||
|
||||
//Try to get product attribues
|
||||
$attributes = Db::getInstance()->ExecuteS('
|
||||
SELECT id_product_attribute, supplier_reference, wholesale_price
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.(int)$row['id_product']
|
||||
);
|
||||
|
||||
//Add each attribute to stock_available
|
||||
foreach ($attributes as $attribute)
|
||||
{
|
||||
// add to global quantity
|
||||
$quantity += $attribute['quantity'];
|
||||
|
||||
// set supplier for attribute
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'product_supplier`
|
||||
(`id_product`, `id_product_attribute`, `id_supplier`, `product_supplier_reference`, `product_supplier_price_te`, `id_currency`)
|
||||
VALUES
|
||||
("'.(int)$row['id_product'].'", "'.(int)$attribute['id_product_attribute'].'", "'.(int)$row['id_supplier'].'", "'.(int)$attribute['supplier_reference'].'", "'.(int)$attribute['wholesale_price'].'", "'.(int)Configuration::get('PS_CURRENCY_DEFAULT').'")
|
||||
');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
function set_stock_available()
|
||||
{
|
||||
//Get all products with positive quantity
|
||||
$resource = Db::getInstance()->query('
|
||||
SELECT quantity, id_product, out_of_stock
|
||||
FROM `'._DB_PREFIX_.'product`
|
||||
WHERE `active` = 1
|
||||
');
|
||||
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
{
|
||||
$quantity = 0;
|
||||
|
||||
//Try to get product attribues
|
||||
$attributes = Db::getInstance()->ExecuteS('
|
||||
SELECT quantity, id_product_attribute
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.(int)$row['id_product']
|
||||
);
|
||||
|
||||
//Add each attribute to stock_available
|
||||
foreach ($attributes as $attribute)
|
||||
{
|
||||
// add to global quantity
|
||||
$quantity += $attribute['quantity'];
|
||||
|
||||
//add stock available for attributes
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'stock_available`
|
||||
(`id_product`, `id_product_attribute`, `id_shop`, `id_group_shop`, `quantity`, `depends_on_stock`, `out_of_stock`)
|
||||
VALUES
|
||||
("'.(int)$row['id_product'].'", "'.(int)$attribute['id_product_attribute'].'", "1", "0", "'.(int)$attribute['quantity'].'", "0", "'.(int)$row['out_of_stock'].'")
|
||||
');
|
||||
}
|
||||
|
||||
if (count($attributes) == 0)
|
||||
$quantity = (int)$row['quantity'];
|
||||
|
||||
if ($quantity == 0)
|
||||
continue;
|
||||
|
||||
//Add stock available for product
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'stock_available`
|
||||
(`id_product`, `id_product_attribute`, `id_shop`, `id_group_shop`, `quantity`, `depends_on_stock`, `out_of_stock`)
|
||||
VALUES
|
||||
("'.(int)$row['id_product'].'", "0", "1", "0", "'.(int)$quantity.'", "0", "'.(int)$row['out_of_stock'].'")
|
||||
');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
function update_stock_mvt_reason()
|
||||
{
|
||||
//Get all stock mvts reasons already presents in the solution (from 1.4.x)
|
||||
//Remove standard movements to keep only custom movement
|
||||
$mvts = Db::getInstance()->ExecuteS('
|
||||
SELECT smr.*
|
||||
FROM `'._DB_PREFIX_.'stock_mvt_reason`
|
||||
WHERE `id` > 5
|
||||
');
|
||||
|
||||
//Get all stock mvts reasons language traduction already presents in the solution (from 1.4.x)
|
||||
//Remove standard movements to keep only custom movement
|
||||
$mvts_lang = Db::getInstance()->ExecuteS('
|
||||
SELECT smrl.*
|
||||
FROM `'._DB_PREFIX_.'stock_movement_reason_lang`
|
||||
WHERE `id_stock_mvt_reason` > 5
|
||||
');
|
||||
|
||||
//Clean table
|
||||
Db::getInstance()->query('TRUNCATE TABLE `'._DB_PREFIX_.'stock_movement_reason`');
|
||||
Db::getInstance()->query('TRUNCATE TABLE `'._DB_PREFIX_.'stock_movement_reason_lang`');
|
||||
|
||||
//Recreate new standards movements
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `PREFIX_stock_mvt_reason` (`id_stock_mvt_reason`, `sign`, `date_add`, `date_upd`)
|
||||
VALUES
|
||||
(1, 1, NOW(), NOW()),
|
||||
(2, -1, NOW(), NOW()),
|
||||
(3, -1, NOW(), NOW()),
|
||||
(4, -1, NOW(), NOW()),
|
||||
(5, 1, NOW(), NOW()),
|
||||
(6, -1, NOW(), NOW()),
|
||||
(7, 1, NOW(), NOW()),
|
||||
(8, 1, NOW(), NOW())
|
||||
');
|
||||
|
||||
Db::getInstance()->execute("
|
||||
INSERT INTO `PREFIX_stock_mvt_reason_lang` (`id_stock_mvt_reason`, `id_lang`, `name`)
|
||||
VALUES
|
||||
(1, 1, 'Increase'),
|
||||
(1, 2, 'Augmenter'),
|
||||
(1, 3, 'Aumentar'),
|
||||
(1, 4, 'Erhöhen'),
|
||||
(1, 5, 'Increase'),
|
||||
(2, 1, 'Decrease'),
|
||||
(2, 2, 'Diminuer'),
|
||||
(2, 3, 'Disminuir'),
|
||||
(2, 4, 'Reduzieren'),
|
||||
(2, 5, 'Decrease'),
|
||||
(3, 1, 'Customer Order'),
|
||||
(3, 2, 'Commande client'),
|
||||
(3, 3, 'Pedido'),
|
||||
(3, 4, 'Bestellung'),
|
||||
(3, 5, 'Ordine'),
|
||||
(4, 1, 'Regulation following an inventory of stock'),
|
||||
(4, 2, 'Régularisation du stock suite à un inventaire'),
|
||||
(4, 3, 'Regulation following an inventory of stock'),
|
||||
(4, 4, 'Regulation following an inventory of stock'),
|
||||
(4, 5, 'Regulation following an inventory of stock'),
|
||||
(5, 1, 'Regulation following an inventory of stock'),
|
||||
(5, 2, 'Régularisation du stock suite à un inventaire'),
|
||||
(5, 3, 'Regulation following an inventory of stock'),
|
||||
(5, 4, 'Regulation following an inventory of stock'),
|
||||
(5, 5, 'Regulation following an inventory of stock'),
|
||||
(6, 1, 'Transfer to another warehouse'),
|
||||
(6, 2, 'Transfert vers un autre entrepôt'),
|
||||
(6, 3, 'Transfer to another warehouse'),
|
||||
(6, 4, 'Transfer to another warehouse'),
|
||||
(6, 5, 'Transfer to another warehouse'),
|
||||
(7, 1, 'Transfer from another warehouse'),
|
||||
(7, 2, 'Transfert depuis un autre entrepôt'),
|
||||
(7, 3, 'Transfer from another warehouse'),
|
||||
(7, 4, 'Transfer from another warehouse'),
|
||||
(7, 5, 'Transfer from another warehouse'),
|
||||
(8, 1, 'Supply Order'),
|
||||
(8, 2, 'Commande fournisseur'),
|
||||
(8, 3, 'Supply Order'),
|
||||
(8, 4, 'Supply Order'),
|
||||
(8, 5, 'Supply Order')
|
||||
");
|
||||
|
||||
//Add custom movements
|
||||
foreach ($mvts as $mvt)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `PREFIX_stock_mvt_reason` (`sign`, `date_add`, `date_upd`)
|
||||
VALUES ("'.(int)$mvt['sign'].'", "'.pSQL($mvt['date_add']).'", "'.pSQL($mvt['date_upd']).'")
|
||||
');
|
||||
|
||||
$row_id = Db::getInstance()->Insert_ID();
|
||||
|
||||
foreach ($mvts_lang as $mvt_lang)
|
||||
{
|
||||
if ($mvt_lang['id_stock_mvt_reason'] != $mvt['id'])
|
||||
continue;
|
||||
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `PREFIX_stock_mvt_reason_lang` (`id_stock_mvt_reason`, `id_lang`, `name`)
|
||||
VALUES ("'.(int)$row_id.'", "'.(int)$mvt_lang['id_lang'].'", "'.pSQL($mvt_lang['name']).'")
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user