Implemented constants for Product class

This commit is contained in:
Marcos García de La Fuente 2015-03-30 03:14:07 +02:00
parent cc1d298f29
commit 831177ef99
24 changed files with 68 additions and 48 deletions

View File

@ -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';

View File

@ -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);

View File

@ -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."'";
}

View File

@ -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];
}
/*

View File

@ -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 '<table class="border" width="100%">';

View File

@ -143,7 +143,7 @@ class ActionsCardProduct
$this->tpl['showrefnav'] = $form->showrefnav($this->object,'ref','',1,'ref');
$titre=$langs->trans("CardProduct".$this->object->type);
$picto=($this->object->type==1?'service':'product');
$picto=($this->object->type==Product::TYPE_SERVICE?'service':'product');
$this->tpl['showhead']=dol_get_fiche_head($head, 'card', $titre, 0, $picto);
$this->tpl['showend']=dol_get_fiche_end();

View File

@ -142,7 +142,7 @@ class ActionsCardService
$this->tpl['showrefnav'] = $form->showrefnav($this->object,'ref','',1,'ref');
$titre=$langs->trans("CardProduct".$this->object->type);
$picto=($this->object->type==1?'service':'product');
$picto=($this->object->type==Product::TYPE_SERVICE?'service':'product');
$this->tpl['showhead']=dol_get_fiche_head($head, 'card', $titre, 0, $picto);
$this->tpl['showend']=dol_get_fiche_end();

View File

@ -461,7 +461,7 @@ if (empty($reshook))
if ($action == 'confirm_delete' && $confirm != 'yes') { $action=''; }
if ($action == 'confirm_delete' && $confirm == 'yes')
{
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))
{
$result = $object->delete($object->id);
}
@ -768,8 +768,8 @@ if (GETPOST("cancel") == $langs->trans("Cancel"))
*/
$helpurl='';
if (GETPOST("type") == '0' || ($object->type == '0')) $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
if (GETPOST("type") == '1' || ($object->type == '1')) $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
if (isset($_GET['type'])) $title = $langs->trans('CardProduct'.GETPOST('type'));
else $title = $langs->trans('ProductServiceCard');
@ -1193,7 +1193,7 @@ else
}*/
// Nature
if($object->type!=1)
if($object->type!= Product::TYPE_SERVICE)
{
print '<tr><td>'.$langs->trans("Nature").'</td><td colspan="3">';
$statutarray=array('-1'=>'&nbsp;', '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 '</td></tr>';
// Nature
if($object->type!=1)
if($object->type!= Product::TYPE_SERVICE)
{
print '<tr><td>'.$langs->trans("Nature").'</td><td colspan="2">';
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))
{

View File

@ -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 = '<u>' . $langs->trans("ShowProduct") . '</u>';
if ($this->type == 1) $label = '<u>' . $langs->trans("ShowService") . '</u>';
if ($this->type == Product::TYPE_PRODUCT) $label = '<u>' . $langs->trans("ShowProduct") . '</u>';
if ($this->type == Product::TYPE_SERVICE) $label = '<u>' . $langs->trans("ShowService") . '</u>';
if (! empty($this->ref))
$label .= '<br><b>' . $langs->trans('ProductRef') . ':</b> ' . $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

View File

@ -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 '</tr>';
// Nature
if($object->type!=1)
if($object->type!=Product::TYPE_SERVICE)
{
print '<tr><td>'.$langs->trans("Nature").'</td><td colspan="2">';
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();

View File

@ -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 '</div>';
$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';
}

View File

@ -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);

View File

@ -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;
/* ************************************************************************** */

View File

@ -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 '<table class="border" width="100%">';

View File

@ -69,7 +69,7 @@ if (! empty($id) || ! 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, 'stats', $titre, 0, $picto);

View File

@ -91,7 +91,7 @@ if ($id > 0 || ! empty($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, 'referers', $titre, 0, $picto);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook

View File

@ -98,7 +98,7 @@ if ($id > 0 || ! empty($ref)) {
if ($result > 0) {
$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, 'referers', $titre, 0, $picto);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook

View File

@ -81,7 +81,7 @@ if ($id > 0 || ! empty($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, 'referers', $titre, 0, $picto);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook

View File

@ -92,7 +92,7 @@ if ($id > 0 || ! empty($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, 'referers', $titre, 0, $picto);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook

View File

@ -93,7 +93,7 @@ if ($id > 0 || ! empty($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, 'referers', $titre, 0, $picto);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook

View File

@ -91,7 +91,7 @@ if ($id > 0 || ! empty($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, 'referers', $titre, 0, $picto);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook

View File

@ -117,7 +117,7 @@ class MouvementStock extends CommonObject
// Define if we must make the stock change (If product type is a service or if stock is used also for services)
$movestock=0;
if ($product->type != 1 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock=1;
if ($product->type != Product::TYPE_SERVICE || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock=1;
if ($movestock && $entrepot_id > 0) // Change stock for current product, change for subproduct is done after
{

View File

@ -7,6 +7,7 @@
* Copyright (C) 2013 Cédric Salvador <csalvador.gpcsolutions.fr>
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014-2015 Cédric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -385,7 +386,7 @@ if ($id > 0 || $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, 'stock', $titre, 0, $picto);
dol_htmloutput_events();

View File

@ -170,7 +170,7 @@ $formadmin=new FormAdmin($db);
$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, 'translation', $titre, 0, $picto);
print '<table class="border" width="100%">';