diff --git a/ChangeLog b/ChangeLog
index dc14290ae1c..9e4191329cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -57,6 +57,7 @@ For users:
- New: All professional id can contains up to 128 chars instead of 32.
- New: [ task #176 ] Allow to use ODT templates for proposals and orders like it's done for invoices
- New: Add hidden option MAIN_ADD_PDF_BACKGROUND to add a PDF as background of invoice/order generated PDF.
+- New: Can convert a product/service into service/product.
- Fix: Can use POS module with several concurrent users.
- Fix: Installer don't fails with Mysql version that added a ssl_cypher field.
- Fix: Sanitize input parameters.
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 8a5ac8db2ea..34baaf8b6ca 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -156,6 +156,16 @@ class Form
{
$ret.=$this->form_date($_SERVER['PHP_SELF'].'?id='.$object->id,$value,$htmlname);
}
+ else if (preg_match('/^select;/',$typeofdata))
+ {
+ $arraydata=explode(',',preg_replace('/^select;/','',$typeofdata));
+ foreach($arraydata as $val)
+ {
+ $tmp=explode(':',$val);
+ $arraylist[$tmp[0]]=$tmp[1];
+ }
+ $ret.=$this->selectarray($htmlname,$arraylist,$value);
+ }
else if (preg_match('/^ckeditor/',$typeofdata))
{
$tmp=explode(':',$typeofdata);
@@ -173,6 +183,16 @@ class Form
if ($typeofdata == 'email') $ret.=dol_print_email($value,0,0,0,0,1);
elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret.=dol_print_date($value,'day');
elseif ($typeofdata == 'text' || $typeofdata == 'textarea') $ret.=dol_htmlentitiesbr($value);
+ else if (preg_match('/^select;/',$typeofdata))
+ {
+ $arraydata=explode(',',preg_replace('/^select;/','',$typeofdata));
+ foreach($arraydata as $val)
+ {
+ $tmp=explode(':',$val);
+ $arraylist[$tmp[0]]=$tmp[1];
+ }
+ $ret.=$arraylist[$value];
+ }
else if (preg_match('/^ckeditor/',$typeofdata))
{
$tmpcontent=dol_htmlentitiesbr($value);
@@ -196,7 +216,7 @@ class Form
* @param string $inputType Type of input ('numeric', 'datepicker', 'textarea', 'ckeditor:dolibarr_zzz', 'select:xxx')
* @param string $editvalue When in edit mode, use this value as $value instead of value
* @param object $extObject External object
- * @param string $success Success message
+ * @param string $success Success message
* @return string HTML edit in place
*/
private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea', $editvalue=null, $extObject=null, $success=null)
@@ -284,7 +304,7 @@ class Form
if (! empty($success)) $out.= ''."\n";
//$out.= ''."\n";
//$out.= ''."\n";
-
+
$out.= '
'.$value.'
'."\n";
$out.= '
'.(! empty($editvalue) ? $editvalue : $value).'
'."\n";
}
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index b1140ac5740..abff74ca484 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -2813,11 +2813,38 @@ class Product extends CommonObject
}
}
+ /**
+ * Update product/service type
+ *
+ * @param User $user Utilisateur qui fait la modification
+ * @return void
+ * TODO Replace this by a method update_field into common
+ */
+ function update_type($user)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."product";
+ $sql.= " SET fk_product_type = '".$this->type."'";
+ $sql.= " WHERE rowid = ".$this->id;
+
+ dol_syslog(get_class($this)."::update_type sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
/**
* Mise a jour du code barre
*
* @param User $user Utilisateur qui fait la modification
* @return void
+ * TODO Replace this by a method update_field into common
*/
function update_barcode($user)
{
@@ -2843,6 +2870,7 @@ class Product extends CommonObject
*
* @param User $user Utilisateur qui fait la modification
* @return void
+ * TODO Replace this by a method update_field into common
*/
function update_barcode_type($user)
{
@@ -2871,14 +2899,7 @@ class Product extends CommonObject
*/
function isproduct()
{
- if ($this->type != 1)
- {
- return 1;
- }
- else
- {
- return 0;
- }
+ return ($this->type != 1 ? true : false);
}
/**
@@ -2888,14 +2909,7 @@ class Product extends CommonObject
*/
function isservice()
{
- if ($this->type==1)
- {
- return 1;
- }
- else
- {
- return 0;
- }
+ return ($this->type == 1 ? true : false);
}
/**
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index d310325d019..52ca1c8b68e 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -87,6 +87,17 @@ $error=$hookmanager->error; $errors=$hookmanager->errors;
if (empty($reshook))
{
+ // Type
+ if ($action == 'setproducttype' && $user->rights->produit->creer)
+ {
+ var_dump($action);
+ $object->fetch($id);
+ $object->type = $_POST['producttype'];
+ $result = $object->update_type($user);
+ Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
+ exit;
+ }
+
// Barcode type
if ($action == 'setbarcodetype' && $user->rights->barcode->creer)
{
@@ -1078,6 +1089,15 @@ else
print '';
+ // Type
+ if ($conf->produit->enabled && $conf->service->enabled)
+ {
+ $typeformat='select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
+ print '