diff --git a/dev/examples/create_product.php b/dev/examples/create_product.php index 8fe36260c98..cdb6cdae9e2 100755 --- a/dev/examples/create_product.php +++ b/dev/examples/create_product.php @@ -70,7 +70,7 @@ $myproduct->libelle = 'libelle'; $myproduct->price = '10'; $myproduct->price_base_type = 'HT'; $myproduct->tva_tx = '19.6'; -$myproduct->type = 0; +$myproduct->type = Product::TYPE_PRODUCT; $myproduct->status = 1; $myproduct->description = 'Description'; $myproduct->note = 'Note'; diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index e116ac668ab..76af3708c8b 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -343,7 +343,7 @@ else if ($id || $ref) $head=product_prepare_head($product, $user); $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type==1?'service':'product'); + $picto=($product->type== Product::TYPE_SERVICE?'service':'product'); dol_fiche_head($head, 'category', $titre,0,$picto); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index ae7b0e2d1e8..eb63f76319f 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3872,7 +3872,7 @@ class Form { $prodstatic=new Product($this->db); $prodstatic->fetch($idprod); - if ($prodstatic->type == 1) // We know product is a service + if ($prodstatic->type == Product::TYPE_SERVICE) // We know product is a service { $code_country.=",'".$societe_acheteuse->country_code."'"; } diff --git a/htdocs/core/photos_resize.php b/htdocs/core/photos_resize.php index 3a51a5f7567..80f849a0494 100644 --- a/htdocs/core/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -70,8 +70,8 @@ if ($id > 0) $result = $object->fetch($id); if ($result <= 0) dol_print_error($db,'Failed to load object'); $dir=$conf->product->multidir_output[$object->entity]; // By default - if ($object->type == 0) $dir=$conf->product->multidir_output[$object->entity]; - if ($object->type == 1) $dir=$conf->service->multidir_output[$object->entity]; + if ($object->type == Product::TYPE_PRODUCT) $dir=$conf->product->multidir_output[$object->entity]; + if ($object->type == Product::TYPE_SERVICE) $dir=$conf->service->multidir_output[$object->entity]; } /* diff --git a/htdocs/margin/tabs/productMargins.php b/htdocs/margin/tabs/productMargins.php index d811f898c0b..2123f683c21 100644 --- a/htdocs/margin/tabs/productMargins.php +++ b/htdocs/margin/tabs/productMargins.php @@ -79,7 +79,7 @@ if ($id > 0 || ! empty($ref)) { $head=product_prepare_head($object, $user); $titre=$langs->trans("CardProduct".$object->type); - $picto=($object->type==1?'service':'product'); + $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); dol_fiche_head($head, 'margin', $titre, 0, $picto); print '
| '.$langs->trans("Nature").' | '; $statutarray=array('-1'=>' ', '1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial")); @@ -1308,7 +1308,7 @@ else { $head=product_prepare_head($object, $user); $titre=$langs->trans("CardProduct".$object->type); - $picto=($object->type==1?'service':'product'); + $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); dol_fiche_head($head, 'card', $titre, 0, $picto); $showphoto=$object->is_photo_available($conf->product->multidir_output[$object->entity]); @@ -1331,7 +1331,7 @@ else $nblignes=7; if (! empty($conf->produit->enabled) && ! empty($conf->service->enabled)) $nblignes++; if ($showbarcode) $nblignes+=2; - if ($object->type!=1) $nblignes++; + if ($object->type!= Product::TYPE_SERVICE) $nblignes++; if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) $nblignes+=2; if ($object->isservice()) $nblignes++; else $nblignes+=4; @@ -1464,7 +1464,7 @@ else print ' | ||
| '.$langs->trans("Nature").' | ';
print $object->getLibFinished();
@@ -1628,8 +1628,8 @@ if (empty($reshook))
}
$object_is_used = $object->isObjectUsed($object->id);
- if (($object->type == 0 && $user->rights->produit->supprimer)
- || ($object->type == 1 && $user->rights->service->supprimer))
+ if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer)
+ || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer))
{
if (empty($object_is_used) && (! isset($object->no_button_delete) || $object->no_button_delete <> 1))
{
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index d08ed699b7f..8c811a57a1a 100755
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -61,8 +61,12 @@ class Product extends CommonObject
var $libelle; // TODO deprecated
var $label;
var $description;
- //! Type 0 for regular product, 1 for service (Advanced feature: 2 for assembly kit, 3 for stock kit)
- var $type;
+
+ /**
+ * Check TYPE constants
+ * @var int
+ */
+ var $type = self::TYPE_PRODUCT;
//! Selling price
var $price; // Price net
var $price_ttc; // Price with tax
@@ -171,6 +175,23 @@ class Product extends CommonObject
var $fk_price_expression;
+ /**
+ * Regular product
+ */
+ const TYPE_PRODUCT = 0;
+ /**
+ * Service
+ */
+ const TYPE_SERVICE = 1;
+ /**
+ * Advanced feature: assembly kit
+ */
+ const TYPE_ASSEMBLYKIT = 2;
+ /**
+ * Advanced feature: stock kit
+ */
+ const TYPE_STOCKKIT = 3;
+
/**
* Constructor
*
@@ -233,7 +254,6 @@ class Product extends CommonObject
// Clean parameters
$this->ref = dol_string_nospecial(trim($this->ref));
$this->libelle = trim($this->libelle);
- if (empty($this->type)) $this->type=0;
$this->price_ttc=price2num($this->price_ttc);
$this->price=price2num($this->price);
$this->price_min_ttc=price2num($this->price_min_ttc);
@@ -795,7 +815,7 @@ class Product extends CommonObject
$this->error = "Object must be fetched before calling delete";
return -1;
}
- if (($this->type == 0 && empty($user->rights->produit->supprimer)) || ($this->type == 1 && empty($user->rights->service->supprimer)))
+ if (($this->type == Product::TYPE_PRODUCT && empty($user->rights->produit->supprimer)) || ($this->type == Product::TYPE_SERVICE && empty($user->rights->service->supprimer)))
{
$this->error = "ErrorForbidden";
return 0;
@@ -2932,8 +2952,8 @@ class Product extends CommonObject
$result='';
$newref=$this->ref;
if ($maxlength) $newref=dol_trunc($newref,$maxlength,'middle');
- if ($this->type == 0) $label = '' . $langs->trans("ShowProduct") . '';
- if ($this->type == 1) $label = '' . $langs->trans("ShowService") . '';
+ if ($this->type == Product::TYPE_PRODUCT) $label = '' . $langs->trans("ShowProduct") . '';
+ if ($this->type == Product::TYPE_SERVICE) $label = '' . $langs->trans("ShowService") . '';
if (! empty($this->ref))
$label .= ' ' . $langs->trans('ProductRef') . ': ' . $this->ref; if (! empty($this->label)) @@ -2968,8 +2988,8 @@ class Product extends CommonObject } if ($withpicto) { - if ($this->type == 0) $result.=($link.img_object($langs->trans("ShowProduct").' '.$this->label, 'product', 'class="classfortooltip"').$linkend.' '); - if ($this->type == 1) $result.=($link.img_object($langs->trans("ShowService").' '.$this->label, 'service', 'class="classfortooltip"').$linkend.' '); + if ($this->type == Product::TYPE_PRODUCT) $result.=($link.img_object($langs->trans("ShowProduct").' '.$this->label, 'product', 'class="classfortooltip"').$linkend.' '); + if ($this->type == Product::TYPE_SERVICE) $result.=($link.img_object($langs->trans("ShowService").' '.$this->label, 'service', 'class="classfortooltip"').$linkend.' '); } $result.=$link.$newref.$linkend; return $result; @@ -3666,7 +3686,7 @@ class Product extends CommonObject */ function isproduct() { - return ($this->type != 1 ? true : false); + return ($this->type != Product::TYPE_PRODUCT ? true : false); } /** @@ -3676,7 +3696,7 @@ class Product extends CommonObject */ function isservice() { - return ($this->type == 1 ? true : false); + return ($this->type == Product::TYPE_SERVICE ? true : false); } /** @@ -3733,7 +3753,6 @@ class Product extends CommonObject $this->tosell=1; $this->tobuy=1; $this->tobatch=0; - $this->type=0; $this->note='This is a comment (private)'; $this->barcode=-1; // Create barcode automatically diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php index 53f79266c25..96f2a589429 100644 --- a/htdocs/product/composition/card.php +++ b/htdocs/product/composition/card.php @@ -176,7 +176,7 @@ llxHeader("","",$langs->trans("CardProduct".$object->type)); $head=product_prepare_head($object, $user); $titre=$langs->trans("CardProduct".$object->type); -$picto=($object->type==1?'service':'product'); +$picto=($object->type==Product::TYPE_SERVICE?'service':'product'); dol_fiche_head($head, 'subproduct', $titre, 0, $picto); @@ -207,7 +207,7 @@ if ($id > 0 || ! empty($ref)) print ' | ||
| '.$langs->trans("Nature").' | ';
print $object->getLibFinished();
@@ -474,7 +474,7 @@ if ($id > 0 || ! empty($ref))
// check if a product is not already a parent product of this one
$prod_arbo=new Product($db);
$prod_arbo->id=$objp->rowid;
- if ($prod_arbo->type==2 || $prod_arbo->type==3)
+ if ($prod_arbo->type==Product::TYPE_ASSEMBLYKIT || $prod_arbo->type== Product::TYPE_STOCKKIT)
{
$is_pere=0;
$prod_arbo->get_sousproduits_arbo();
diff --git a/htdocs/product/document.php b/htdocs/product/document.php
index e46dc0384b2..9a71eac4f55 100644
--- a/htdocs/product/document.php
+++ b/htdocs/product/document.php
@@ -102,7 +102,7 @@ if ($object->id)
{
$head=product_prepare_head($object, $user);
$titre=$langs->trans("CardProduct".$object->type);
- $picto=($object->type==1?'service':'product');
+ $picto=($object->type== Product::TYPE_SERVICE?'service':'product');
dol_fiche_head($head, 'documents', $titre, 0, $picto);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
@@ -146,7 +146,7 @@ if ($object->id)
print '';
$modulepart = 'produit';
- $permission = (($object->type == 0 && $user->rights->produit->creer) || ($object->type == 1 && $user->rights->service->creer));
+ $permission = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer));
$param = '&id=' . $object->id;
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
}
diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php
index b360829a341..c2196aba00b 100644
--- a/htdocs/product/fournisseurs.php
+++ b/htdocs/product/fournisseurs.php
@@ -259,7 +259,7 @@ if ($id || $ref)
$head=product_prepare_head($product, $user);
$titre=$langs->trans("CardProduct".$product->type);
- $picto=($product->type==1?'service':'product');
+ $picto=($product->type== Product::TYPE_SERVICE?'service':'product');
dol_fiche_head($head, 'suppliers', $titre, 0, $picto);
diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php
index 0ae65a7dec6..8a6e2ddbd6b 100644
--- a/htdocs/product/photos.php
+++ b/htdocs/product/photos.php
@@ -102,7 +102,7 @@ if ($object->id)
*/
$head=product_prepare_head($object, $user);
$titre=$langs->trans("CardProduct".$object->type);
- $picto=($object->type==1?'service':'product');
+ $picto=($object->type== Product::TYPE_SERVICE?'service':'product');
dol_fiche_head($head, 'photos', $titre, 0, $picto);
/*
@@ -145,8 +145,8 @@ if ($object->id)
$permtoedit=0;
- if ($user->rights->produit->creer && $object->type == 0) $permtoedit=1;
- if ($user->rights->service->creer && $object->type == 1) $permtoedit=1;
+ if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoedit=1;
+ if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoedit=1;
if (empty($conf->global->MAIN_UPLOAD_DOC)) $permtoedit=0;
/* ************************************************************************** */
diff --git a/htdocs/product/price.php b/htdocs/product/price.php
index f6cd6187e85..da61ccc45b8 100644
--- a/htdocs/product/price.php
+++ b/htdocs/product/price.php
@@ -347,7 +347,7 @@ llxHeader("", "", $langs->trans("CardProduct" . $object->type));
$head = product_prepare_head($object, $user);
$titre = $langs->trans("CardProduct" . $object->type);
-$picto = ($object->type == 1 ? 'service' : 'product');
+$picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
dol_fiche_head($head, 'price', $titre, 0, $picto);
print ' | ||