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/commande/card.php b/htdocs/commande/card.php index c091817d606..206de4d523c 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -144,7 +144,7 @@ if (empty($reshook)) // Reopen a closed order else if ($action == 'reopen' && $user->rights->commande->creer) { - if ($object->statut == 3) + if ($object->statut == Commande::STATUS_CLOSED) { $result = $object->set_reopen($user); if ($result > 0) @@ -1810,7 +1810,7 @@ if ($action == 'create' && $user->rights->commande->creer) $absolute_discount = price2num($absolute_discount, 'MT'); $absolute_creditnote = price2num($absolute_creditnote, 'MT'); if ($absolute_discount) { - if ($object->statut > 0) { + if ($object->statut > Commande::STATUS_DRAFT) { print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency)); } else { // Remise dispo de type remise fixe (not credit note) @@ -2105,7 +2105,7 @@ if ($action == 'create' && $user->rights->commande->creer) '; - if (! empty($conf->use_javascript_ajax) && $object->statut == 0) { + if (! empty($conf->use_javascript_ajax) && $object->statut == Commande::STATUS_DRAFT) { include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } @@ -2120,7 +2120,7 @@ if ($action == 'create' && $user->rights->commande->creer) /* * Form to add new line */ - if ($object->statut == 0 && $user->rights->commande->creer) + if ($object->statut == Commande::STATUS_DRAFT && $user->rights->commande->creer) { if ($action != 'editline') { @@ -2150,7 +2150,7 @@ if ($action == 'create' && $user->rights->commande->creer) // modified by hook if (empty($reshook)) { // Valid - if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && + if ($object->statut == Commande::STATUS_DRAFT && $object->total_ttc >= 0 && $numlines > 0 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) ) @@ -2158,7 +2158,7 @@ if ($action == 'create' && $user->rights->commande->creer) print '
'; } // Edit - if ($object->statut == 1 && $user->rights->commande->creer) { + if ($object->statut == Commande::STATUS_VALIDATED && $user->rights->commande->creer) { print ''; } // Create event @@ -2169,7 +2169,7 @@ if ($action == 'create' && $user->rights->commande->creer) print '' . $langs->trans("AddAction") . ''; } // Send - if ($object->statut > 0) { + if ($object->statut > Commande::STATUS_DRAFT) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) { print ''; } else @@ -2181,7 +2181,7 @@ if ($action == 'create' && $user->rights->commande->creer) if (! empty($conf->expedition->enabled)) { $numshipping = $object->nb_expedition(); - if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0) { + if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && $object->getNbOfProductsLines() > 0) { if (($conf->expedition_bon->enabled && $user->rights->expedition->creer) || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)) { if ($user->rights->expedition->creer) { print ''; @@ -2199,7 +2199,7 @@ if ($action == 'create' && $user->rights->commande->creer) if ($conf->ficheinter->enabled) { $langs->load("interventions"); - if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfServicesLines() > 0) { + if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && $object->getNbOfServicesLines() > 0) { if ($user->rights->ficheinter->creer) { print ''; } else { @@ -2209,12 +2209,12 @@ if ($action == 'create' && $user->rights->commande->creer) } // Reopen a closed order - if ($object->statut == 3 && $user->rights->commande->creer) { + if ($object->statut == Commande::STATUS_CLOSED && $user->rights->commande->creer) { print ''; } // Create contract - if ($conf->contrat->enabled && ($object->statut == 1 || $object->statut == 2)) { + if ($conf->contrat->enabled && ($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_ACCEPTED)) { $langs->load("contracts"); if ($user->rights->contrat->creer) { @@ -2224,17 +2224,17 @@ if ($action == 'create' && $user->rights->commande->creer) // Create bill and Classify billed // Note: Even if module invoice is not enabled, we should be able to use button "Classified billed" - if ($object->statut > 0 && ! $object->billed) { + if ($object->statut > Commande::STATUS_DRAFT && ! $object->billed) { if (! empty($conf->facture->enabled) && $user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) { print ''; } - if ($user->rights->commande->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { + if ($user->rights->commande->creer && $object->statut > Commande::STATUS_ACCEPTED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { print ''; } } // Set to shipped - if (($object->statut == 1 || $object->statut == 2) && $user->rights->commande->cloturer) { + if (($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_ACCEPTED) && $user->rights->commande->cloturer) { print ''; } @@ -2244,7 +2244,7 @@ if ($action == 'create' && $user->rights->commande->creer) } // Cancel order - if ($object->statut == 1 && + if ($object->statut == Commande::STATUS_VALIDATED && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->cloturer)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->annuler))) ) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index ac567742f0f..1a5d8bf2ceb 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -60,10 +60,39 @@ class Commande extends CommonOrder var $ref_int; var $contactid; var $fk_project; - var $statut; // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not) + /** + * Status of the order. Check the following constants: + * - STATUS_CANCELED + * - STATUS_DRAFT + * - STATUS_ACCEPTED + * - STATUS_CLOSED + * @var int + */ + var $statut; var $facturee; // deprecated var $billed; // billed or not + /** + * Canceled status + */ + const STATUS_CANCELED = -1; + /** + * Draft status + */ + const STATUS_DRAFT = 0; + /** + * Validated status + */ + const STATUS_VALIDATED = 1; + /** + * Accepted/On process not managed for customer orders + */ + const STATUS_ACCEPTED = 2; + /** + * Closed (Sent/Received, billed or not) + */ + const STATUS_CLOSED = 3; + var $brouillon; var $cond_reglement_id; var $cond_reglement_code; @@ -212,7 +241,7 @@ class Commande extends CommonOrder $error=0; // Protection - if ($this->statut == 1) + if ($this->statut == self::STATUS_VALIDATED) { dol_syslog(get_class($this)."::valid no draft status", LOG_WARNING); return 0; @@ -251,7 +280,7 @@ class Commande extends CommonOrder // Validate $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql.= " SET ref = '".$num."',"; - $sql.= " fk_statut = 1,"; + $sql.= " fk_statut = ".self::STATUS_VALIDATED.","; $sql.= " date_valid='".$this->db->idate($now)."',"; $sql.= " fk_user_valid = ".$user->id; $sql.= " WHERE rowid = ".$this->id; @@ -341,7 +370,7 @@ class Commande extends CommonOrder if (! $error) { $this->ref = $num; - $this->statut = 1; + $this->statut = self::STATUS_VALIDATED; } if (! $error) @@ -370,7 +399,7 @@ class Commande extends CommonOrder $error=0; // Protection - if ($this->statut <= 0) + if ($this->statut <= self::STATUS_DRAFT) { return 0; } @@ -385,7 +414,7 @@ class Commande extends CommonOrder $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET fk_statut = 0"; + $sql.= " SET fk_statut = ".self::STATUS_DRAFT; $sql.= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::set_draft", LOG_DEBUG); @@ -411,7 +440,7 @@ class Commande extends CommonOrder if (!$error) { - $this->statut=0; + $this->statut=self::STATUS_DRAFT; $this->db->commit(); return $result; } @@ -423,7 +452,7 @@ class Commande extends CommonOrder } } - $this->statut=0; + $this->statut=self::STATUS_DRAFT; $this->db->commit(); return 1; } @@ -448,7 +477,7 @@ class Commande extends CommonOrder global $conf,$langs; $error=0; - if ($this->statut != 3) + if ($this->statut != self::STATUS_CLOSED) { dol_syslog(get_class($this)."::set_reopen order has not status closed", LOG_WARNING); return 0; @@ -457,7 +486,7 @@ class Commande extends CommonOrder $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $sql.= ' SET fk_statut=1, facture=0'; + $sql.= ' SET fk_statut='.self::STATUS_VALIDATED.', facture=0'; $sql.= ' WHERE rowid = '.$this->id; dol_syslog(get_class($this)."::set_reopen", LOG_DEBUG); @@ -478,7 +507,7 @@ class Commande extends CommonOrder if (! $error) { - $this->statut = 1; + $this->statut = self::STATUS_VALIDATED; $this->billed = 0; $this->facturee = 0; // deprecated @@ -517,10 +546,10 @@ class Commande extends CommonOrder $now=dol_now(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; - $sql.= ' SET fk_statut = 3,'; + $sql.= ' SET fk_statut = '.self::STATUS_CLOSED.','; $sql.= ' fk_user_cloture = '.$user->id.','; $sql.= " date_cloture = '".$this->db->idate($now)."'"; - $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; + $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; if ($this->db->query($sql)) { @@ -531,7 +560,7 @@ class Commande extends CommonOrder if (! $error) { - $this->statut=3; + $this->statut=self::STATUS_CLOSED; $this->db->commit(); return 1; @@ -568,9 +597,9 @@ class Commande extends CommonOrder $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql.= " SET fk_statut = -1"; + $sql.= " SET fk_statut = ".self::STATUS_CANCELED; $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND fk_statut = 1"; + $sql.= " AND fk_statut = ".self::STATUS_VALIDATED; dol_syslog(get_class($this)."::cancel", LOG_DEBUG); if ($this->db->query($sql)) @@ -609,7 +638,7 @@ class Commande extends CommonOrder if (! $error) { - $this->statut=-1; + $this->statut=self::STATUS_CANCELED; $this->db->commit(); return 1; } @@ -933,7 +962,7 @@ class Commande extends CommonOrder } $this->id=0; - $this->statut=0; + $this->statut=self::STATUS_DRAFT; // Clear fields $this->user_author_id = $user->id; @@ -1178,7 +1207,7 @@ class Commande extends CommonOrder // Check parameters if ($type < 0) return -1; - if ($this->statut == 0) + if ($this->statut == self::STATUS_DRAFT) { $this->db->begin(); @@ -1494,7 +1523,7 @@ class Commande extends CommonOrder $this->lines = array(); - if ($this->statut == 0) $this->brouillon = 1; + if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; // Retreive all extrafield for invoice // fetch optionals attributes and labels @@ -1806,7 +1835,7 @@ class Commande extends CommonOrder * * TODO deprecated, move to Shipping class */ - function livraison_array($filtre_statut=-1) + function livraison_array($filtre_statut=self::STATUS_CANCELED) { $delivery = new Livraison($this->db); $deliveryArray = $delivery->livraison_array($filtre_statut); @@ -1821,7 +1850,7 @@ class Commande extends CommonOrder * * TODO FONCTION NON FINIE A FINIR */ - function stock_array($filtre_statut=-1) + function stock_array($filtre_statut=self::STATUS_CANCELED) { $this->stocks = array(); @@ -1863,7 +1892,7 @@ class Commande extends CommonOrder { global $user; - if ($this->statut == 0) + if ($this->statut == self::STATUS_DRAFT) { $this->db->begin(); @@ -1946,7 +1975,7 @@ class Commande extends CommonOrder $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql.= ' SET remise_percent = '.$remise; - $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; + $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;'; if ($this->db->query($sql)) { @@ -1980,7 +2009,7 @@ class Commande extends CommonOrder $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql.= ' SET remise_absolue = '.$remise; - $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; + $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;'; dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG); @@ -2012,7 +2041,7 @@ class Commande extends CommonOrder { $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql.= " SET date_commande = ".($date ? $this->db->idate($date) : 'null'); - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; dol_syslog(get_class($this)."::set_date",LOG_DEBUG); $resql=$this->db->query($sql); @@ -2156,7 +2185,7 @@ class Commande extends CommonOrder $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; } if ($socid) $sql.= " AND s.rowid = ".$socid; - if ($draft) $sql.= " AND c.fk_statut = 0"; + if ($draft) $sql.= " AND c.fk_statut = ".self::STATUS_DRAFT; if (is_object($excluser)) $sql.= " AND c.fk_user_author <> ".$excluser->id; $sql.= $this->db->order($sortfield,$sortorder); $sql.= $this->db->plimit($limit,$offset); @@ -2207,7 +2236,7 @@ class Commande extends CommonOrder function availability($availability_id) { dol_syslog('Commande::availability('.$availability_id.')'); - if ($this->statut >= 0) + if ($this->statut >= self::STATUS_DRAFT) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql .= ' SET fk_availability = '.$availability_id; @@ -2241,7 +2270,7 @@ class Commande extends CommonOrder function demand_reason($demand_reason_id) { dol_syslog('Commande::demand_reason('.$demand_reason_id.')'); - if ($this->statut >= 0) + if ($this->statut >= self::STATUS_DRAFT) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql .= ' SET fk_input_reason = '.$demand_reason_id; @@ -2312,7 +2341,7 @@ class Commande extends CommonOrder $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1'; - $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; + $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; dol_syslog(get_class($this)."::classifyBilled", LOG_DEBUG); if ($this->db->query($sql)) @@ -2790,7 +2819,7 @@ class Commande extends CommonOrder } $sql.= $clause." c.entity = ".$conf->entity; //$sql.= " AND c.fk_statut IN (1,2,3) AND c.facture = 0"; - $sql.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected + $sql.= " AND ((c.fk_statut IN (".self::STATUS_VALIDATED.",".self::STATUS_ACCEPTED.")) OR (c.fk_statut = ".self::STATUS_CLOSED." AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id; $resql=$this->db->query($sql); @@ -2864,57 +2893,57 @@ class Commande extends CommonOrder //print 'x'.$statut.'-'.$billed; if ($mode == 0) { - if ($statut==-1) return $langs->trans('StatusOrderCanceled'); - if ($statut==0) return $langs->trans('StatusOrderDraft'); - if ($statut==1) return $langs->trans('StatusOrderValidated'); - if ($statut==2) return $langs->trans('StatusOrderSentShort'); - if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderToBill'); - if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderProcessed'); + if ($statut==self::STATUS_CANCELED) return $langs->trans('StatusOrderCanceled'); + if ($statut==self::STATUS_DRAFT) return $langs->trans('StatusOrderDraft'); + if ($statut==self::STATUS_VALIDATED) return $langs->trans('StatusOrderValidated'); + if ($statut==self::STATUS_ACCEPTED) return $langs->trans('StatusOrderSentShort'); + if ($statut==self::STATUS_CLOSED && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderToBill'); + if ($statut==self::STATUS_CLOSED && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderProcessed'); } elseif ($mode == 1) { - if ($statut==-1) return $langs->trans('StatusOrderCanceledShort'); - if ($statut==0) return $langs->trans('StatusOrderDraftShort'); - if ($statut==1) return $langs->trans('StatusOrderValidatedShort'); - if ($statut==2) return $langs->trans('StatusOrderSentShort'); - if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderToBillShort'); - if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderProcessed'); + if ($statut==self::STATUS_CANCELED) return $langs->trans('StatusOrderCanceledShort'); + if ($statut==self::STATUS_DRAFT) return $langs->trans('StatusOrderDraftShort'); + if ($statut==self::STATUS_VALIDATED) return $langs->trans('StatusOrderValidatedShort'); + if ($statut==self::STATUS_ACCEPTED) return $langs->trans('StatusOrderSentShort'); + if ($statut==self::STATUS_CLOSED && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderToBillShort'); + if ($statut==self::STATUS_CLOSED && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderProcessed'); } elseif ($mode == 2) { - if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5').' '.$langs->trans('StatusOrderCanceledShort'); - if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraftShort'); - if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidatedShort'); - if ($statut==2) return img_picto($langs->trans('StatusOrderSent'),'statut3').' '.$langs->trans('StatusOrderSentShort'); - if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBillShort'); - if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessedShort'); + if ($statut==self::STATUS_CANCELED) return img_picto($langs->trans('StatusOrderCanceled'),'statut5').' '.$langs->trans('StatusOrderCanceledShort'); + if ($statut==self::STATUS_DRAFT) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraftShort'); + if ($statut==self::STATUS_VALIDATED) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidatedShort'); + if ($statut==self::STATUS_ACCEPTED) return img_picto($langs->trans('StatusOrderSent'),'statut3').' '.$langs->trans('StatusOrderSentShort'); + if ($statut==self::STATUS_CLOSED && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBillShort'); + if ($statut==self::STATUS_CLOSED && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessedShort'); } elseif ($mode == 3) { - if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5'); - if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0'); - if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1'); - if ($statut==2) return img_picto($langs->trans('StatusOrderSentShort'),'statut3'); - if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7'); - if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6'); + if ($statut==self::STATUS_CANCELED) return img_picto($langs->trans('StatusOrderCanceled'),'statut5'); + if ($statut==self::STATUS_DRAFT) return img_picto($langs->trans('StatusOrderDraft'),'statut0'); + if ($statut==self::STATUS_VALIDATED) return img_picto($langs->trans('StatusOrderValidated'),'statut1'); + if ($statut==self::STATUS_ACCEPTED) return img_picto($langs->trans('StatusOrderSentShort'),'statut3'); + if ($statut==self::STATUS_CLOSED && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7'); + if ($statut==self::STATUS_CLOSED && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6'); } elseif ($mode == 4) { - if ($statut==-1) return img_picto($langs->trans('StatusOrderCanceled'),'statut5').' '.$langs->trans('StatusOrderCanceled'); - if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraft'); - if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidated'); - if ($statut==2) return img_picto($langs->trans('StatusOrderSentShort'),'statut3').' '.$langs->trans('StatusOrderSent'); - if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBill'); - if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessed'); + if ($statut==self::STATUS_CANCELED) return img_picto($langs->trans('StatusOrderCanceled'),'statut5').' '.$langs->trans('StatusOrderCanceled'); + if ($statut==self::STATUS_DRAFT) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraft'); + if ($statut==self::STATUS_VALIDATED) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidated'); + if ($statut==self::STATUS_ACCEPTED) return img_picto($langs->trans('StatusOrderSentShort'),'statut3').' '.$langs->trans('StatusOrderSent'); + if ($statut==self::STATUS_CLOSED && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBill'); + if ($statut==self::STATUS_CLOSED && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessed'); } elseif ($mode == 5) { - if ($statut==-1) return ''.$langs->trans('StatusOrderCanceledShort').' '.img_picto($langs->trans('StatusOrderCanceled'),'statut5'); - if ($statut==0) return ''.$langs->trans('StatusOrderDraftShort').' '.img_picto($langs->trans('StatusOrderDraft'),'statut0'); - if ($statut==1) return ''.$langs->trans('StatusOrderValidatedShort').' '.img_picto($langs->trans('StatusOrderValidated'),'statut1'); - if ($statut==2) return ''.$langs->trans('StatusOrderSentShort').' '.img_picto($langs->trans('StatusOrderSent'),'statut3'); - if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return ''.$langs->trans('StatusOrderToBillShort').' '.img_picto($langs->trans('StatusOrderToBill'),'statut7'); - if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return ''.$langs->trans('StatusOrderProcessedShort').' '.img_picto($langs->trans('StatusOrderProcessed'),'statut6'); + if ($statut==self::STATUS_CANCELED) return ''.$langs->trans('StatusOrderCanceledShort').' '.img_picto($langs->trans('StatusOrderCanceled'),'statut5'); + if ($statut==self::STATUS_DRAFT) return ''.$langs->trans('StatusOrderDraftShort').' '.img_picto($langs->trans('StatusOrderDraft'),'statut0'); + if ($statut==self::STATUS_VALIDATED) return ''.$langs->trans('StatusOrderValidatedShort').' '.img_picto($langs->trans('StatusOrderValidated'),'statut1'); + if ($statut==self::STATUS_ACCEPTED) return ''.$langs->trans('StatusOrderSentShort').' '.img_picto($langs->trans('StatusOrderSent'),'statut3'); + if ($statut==self::STATUS_CLOSED && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return ''.$langs->trans('StatusOrderToBillShort').' '.img_picto($langs->trans('StatusOrderToBill'),'statut7'); + if ($statut==self::STATUS_CLOSED && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return ''.$langs->trans('StatusOrderProcessedShort').' '.img_picto($langs->trans('StatusOrderProcessed'),'statut6'); } } diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index 8f03e33bb03..340df8172dc 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -147,16 +147,16 @@ if ($id > 0 || ! empty($ref)) if ($absolute_discount > 0) { print '. '; - if ($object->statut > 0 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) + if ($object->statut > Facture::STATUS_DRAFT || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { - if ($object->statut == 0) + if ($object->statut == Facture::STATUS_DRAFT) { print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency)); print '. '; } else { - if ($object->statut < 1 || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) + if ($object->statut < Facture::STATUS_VALIDATED || $object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency)); 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 ' | ||