From 7aec22769449badcb723578a7bcc84f5ee481ecb Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 17:52:53 +0200 Subject: [PATCH] New: More import options. Products stocks --- htdocs/core/modules/modProduct.class.php | 22 +++++++++++++++++++ htdocs/product/stock/class/entrepot.class.php | 17 ++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index ec6971689b7..87114427243 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -223,6 +223,28 @@ class modProduct extends DolibarrModules 'sp.remise_percent'=>'0' ); } + + if (! empty($conf->stock->enabled)) + { + // Import stocks + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="Stocks"; // Translation key + $this->import_icon[$r]='stock'; + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r]=array('ps'=>MAIN_DB_PREFIX.'product_stock'); + $this->import_fields_array[$r]=array('ps.fk_product'=>"Product*",'ps.fk_entrepot'=>"Warehouse*", + 'ps.reel'=>"Stock*",'ps.pmp'=>"PMP" + ); + + $this->import_convertvalue_array[$r]=array( + 'ps.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product'), + 'ps.fk_entrepot'=>array('rule'=>'fetchidfromref','classfile'=>'/product/stock/class/entrepot.class.php','class'=>'Entrepot','method'=>'fetch','element'=>'label') + ); + $this->import_examplevalues_array[$r]=array('ps.fk_product'=>"PREF123456",'ps.fk_entrepot'=>"ALM001", + 'ps.reel'=>"10",'ps.pmp'=>"25" + ); + } } diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 30a590016e5..eec0b8b22cf 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -240,13 +240,26 @@ class Entrepot extends CommonObject * Load warehouse data * * @param int $id Warehouse id + * @param string $ref Warehouse label * @return int >0 if OK, <0 if KO */ - function fetch($id) + function fetch($id, $ref='') { + global $conf; + $sql = "SELECT rowid, label, description, statut, lieu, address, cp as zip, ville as town, fk_pays as country_id"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; - $sql .= " WHERE rowid = ".$id; + + if ($id) + { + $sql.= " WHERE rowid = '".$id."'"; + } + + else + { + $sql.= " WHERE entity = " .$conf->entity; + if ($ref) $sql.= " AND label = '".$this->db->escape($ref)."'"; + } dol_syslog(get_class($this)."::fetch sql=".$sql); $result = $this->db->query($sql);