NEW products categories in inventory card

This commit is contained in:
lvessiller 2022-04-13 15:44:27 +02:00
parent 914b037a9a
commit 1cb56adb2e
5 changed files with 40 additions and 5 deletions

View File

@ -55,7 +55,7 @@ if ($action == 'add' && !empty($permissiontoadd)) {
continue; // The field was not submited to be saved
}
} else {
if (!GETPOSTISSET($key)) {
if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type'])) {
continue; // The field was not submited to be saved
}
}
@ -85,6 +85,12 @@ if ($action == 'add' && !empty($permissiontoadd)) {
} elseif ($object->fields[$key]['type'] == 'reference') {
$tmparraykey = array_keys($object->param_list);
$value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2');
} elseif (preg_match('/^chkbxlst:(.*)/', $object->fields[$key]['type'])) {
$value = '';
$values_arr = GETPOST($key, 'array');
if (!empty($values_arr)) {
$value = implode(',', $values_arr);
}
} else {
if ($key == 'lang') {
$value = GETPOST($key, 'aZ09') ?GETPOST($key, 'aZ09') : "";
@ -168,7 +174,7 @@ if ($action == 'update' && !empty($permissiontoadd)) {
continue;
}
} else {
if (!GETPOSTISSET($key)) {
if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type'])) {
continue; // The field was not submited to be saved
}
}
@ -206,6 +212,12 @@ if ($action == 'update' && !empty($permissiontoadd)) {
$value = ((GETPOST($key, 'aZ09') == 'on' || GETPOST($key, 'aZ09') == '1') ? 1 : 0);
} elseif ($object->fields[$key]['type'] == 'reference') {
$value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2');
} elseif (preg_match('/^chkbxlst:/', $object->fields[$key]['type'])) {
$value = '';
$values_arr = GETPOST($key, 'array');
if (!empty($values_arr)) {
$value = implode(',', $values_arr);
}
} else {
if ($key == 'lang') {
$value = GETPOST($key, 'aZ09');

View File

@ -6649,6 +6649,9 @@ abstract class CommonObject
} elseif (preg_match('/^(sellist):(.*):(.*)/i', $val['type'], $reg)) {
$param['options'] = array($reg[2].':'.$reg[3] => 'N');
$type = 'sellist';
} elseif (preg_match('/^chkbxlst:(.*)/i', $val['type'], $reg)) {
$param['options'] = array($reg[1] => 'N');
$type = 'chkbxlst';
} elseif (preg_match('/varchar\((\d+)\)/', $val['type'], $reg)) {
$param['options'] = array();
$type = 'varchar';
@ -7098,7 +7101,7 @@ abstract class CommonObject
}
$this->db->free($resql);
$out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%');
$out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, $morecss, 0, '100%');
} else {
print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>';
}
@ -7261,6 +7264,9 @@ abstract class CommonObject
} elseif (preg_match('/^sellist:(.*):(.*)/i', $val['type'], $reg)) {
$param['options'] = array($reg[1].':'.$reg[2] => 'N');
$type = 'sellist';
} elseif (preg_match('/^chkbxlst:(.*)/i', $val['type'], $reg)) {
$param['options'] = array($reg[1] => 'N');
$type = 'chkbxlst';
}
$langfile = empty($val['langfile']) ? '' : $val['langfile'];

View File

@ -324,3 +324,5 @@ ALTER TABLE llx_actioncomm MODIFY COLUMN note mediumtext;
DELETE FROM llx_boxes WHERE box_id IN (select rowid FROM llx_boxes_def WHERE file IN ('box_bom.php@bom', 'box_bom.php'));
DELETE FROM llx_boxes_def WHERE file IN ('box_bom.php@bom', 'box_bom.php');
ALTER TABLE llx_inventory ADD COLUMN fk_categories_product VARCHAR(255) DEFAULT NULL AFTER fk_product;

View File

@ -28,8 +28,9 @@ CREATE TABLE llx_inventory
fk_user_modif integer, -- user making last change
fk_user_valid integer, -- valideur de la fiche
fk_warehouse integer DEFAULT NULL,
fk_product integer DEFAULT NULL,
status integer DEFAULT 0,
fk_product integer DEFAULT NULL,
fk_categories_product varchar(255) DEFAULT NULL, -- product categories id separated by comma
status integer DEFAULT 0,
title varchar(255) NOT NULL,
date_inventory datetime DEFAULT NULL,
date_validation datetime DEFAULT NULL,

View File

@ -102,6 +102,7 @@ class Inventory extends CommonObject
'title' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>25, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax200'),
'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Warehouse', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'index'=>1, 'help'=>'InventoryForASpecificWarehouse', 'picto'=>'stock', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'visible'=>1, 'enabled'=>1, 'position'=>32, 'index'=>1, 'help'=>'InventoryForASpecificProduct', 'picto'=>'product', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'),
'fk_categories_product' => array('type'=>'chkbxlst:categorie:label:rowid::type=0', 'label'=>'ProductsCategoriesShort', 'visible'=>3, 'enabled'=>1, 'position'=>33, 'help'=>'', 'picto'=>'category', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx'),
'date_inventory' => array('type'=>'date', 'label'=>'DateValue', 'visible'=>1, 'enabled'=>'$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE', 'position'=>35), // This date is not used so disabled by default.
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
@ -139,6 +140,11 @@ class Inventory extends CommonObject
*/
public $fk_product;
/**
* @var int Categories id
*/
public $fk_categories_product;
public $date_inventory;
public $title;
@ -291,6 +297,14 @@ class Inventory extends CommonObject
if ($this->fk_warehouse > 0) {
$sql .= " AND ps.fk_entrepot = ".((int) $this->fk_warehouse);
}
if (!empty($this->fk_categories_product)) {
$sql .= " AND EXISTS (";
$sql .= " SELECT cp.fk_product";
$sql .= " FROM ".$this->db->prefix()."categorie_product AS cp";
$sql .= " WHERE cp.fk_product = ps.fk_product";
$sql .= " AND cp.fk_categorie IN (".$this->db->sanitize($this->fk_categories_product).")";
$sql .= ")";
}
$inventoryline = new InventoryLine($this->db);