diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index be60d721d6a..1abd3bc4818 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -302,7 +302,7 @@ if (empty($reshook)) $object->modelpdf = GETPOST('model'); $object->author = $user->id; // deprecated $object->note = GETPOST('note'); - $object->statut = 0; + $object->statut = Propal::STATUS_DRAFT; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); @@ -549,7 +549,7 @@ if (empty($reshook)) // Reopen proposal else if ($action == 'confirm_reopen' && $user->rights->propal->cloturer && ! GETPOST('cancel')) { // prevent browser refresh from reopening proposal several times - if ($object->statut == 2 || $object->statut == 3 || $object->statut == 4) { + if ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED) { $object->reopen($user, 1); } } @@ -561,7 +561,7 @@ if (empty($reshook)) $action = 'statut'; } else { // prevent browser refresh from closing proposal several times - if ($object->statut == 1) { + if ($object->statut == Propal::STATUS_VALIDATED) { $object->cloture($user, GETPOST('statut'), GETPOST('note')); } } @@ -575,7 +575,7 @@ if (empty($reshook)) // Reopen proposal else if ($action == 'confirm_reopen' && $user->rights->propal->cloturer && ! GETPOST('cancel')) { // prevent browser refresh from reopening proposal several times - if ($object->statut == 2 || $object->statut == 3 || $object->statut == 4) { + if ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED) { $object->reopen($user, 1); } } @@ -587,7 +587,7 @@ if (empty($reshook)) $action = 'statut'; } else { // prevent browser refresh from closing proposal several times - if ($object->statut == 1) { + if ($object->statut == Propal::STATUS_VALIDATED) { $object->cloture($user, GETPOST('statut'), GETPOST('note')); } } @@ -1735,7 +1735,7 @@ if ($action == 'create') $absolute_discount = price2num($absolute_discount, 'MT'); $absolute_creditnote = price2num($absolute_creditnote, 'MT'); if ($absolute_discount) { - if ($object->statut > 0) { + if ($object->statut > Propal::STATUS_DRAFT) { print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount, 0, $langs, 0, 0, -1, $conf->currency)); } else { // Remise dispo de type non avoir @@ -1797,7 +1797,7 @@ if ($action == 'create') } else { if (! empty($object->fin_validite)) { print dol_print_date($object->fin_validite, 'daytext'); - if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) + if ($object->statut == Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); } else { print ' '; @@ -2081,7 +2081,7 @@ if ($action == 'create') '; - if (! empty($conf->use_javascript_ajax) && $object->statut == 0) { + if (! empty($conf->use_javascript_ajax) && $object->statut == Propal::STATUS_DRAFT) { include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } @@ -2091,7 +2091,7 @@ if ($action == 'create') $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); // Form to add new line - if ($object->statut == 0 && $user->rights->propal->creer) + if ($object->statut == Propal::STATUS_DRAFT && $user->rights->propal->creer) { if ($action != 'editline') { @@ -2154,7 +2154,7 @@ if ($action == 'create') if ($action != 'statut' && $action != 'editline') { // Validate - if ($object->statut == 0 && $object->total_ttc >= 0 && count($object->lines) > 0 && + if ($object->statut == Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->creer)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->propal_advance->validate))) ) { @@ -2168,18 +2168,18 @@ if ($action == 'create') print '' . $langs->trans("AddAction") . ''; } // Edit - if ($object->statut == 1 && $user->rights->propal->creer) { + if ($object->statut == Propal::STATUS_VALIDATED && $user->rights->propal->creer) { print '
' . $langs->trans('Modify') . '
'; } // ReOpen - if (($object->statut == 2 || $object->statut == 3 || $object->statut == 4) && $user->rights->propal->cloturer) { + if (($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED) && $user->rights->propal->cloturer) { print '
global->MAIN_JUMP_TAG) ? '' : '#reopen') . '"'; print '>' . $langs->trans('ReOpen') . '
'; } // Send - if ($object->statut == 1 || $object->statut == 2) { + if ($object->statut == Propal::STATUS_VALIDATED || $object->statut == Propal::STATUS_SIGNED) { if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) { print '
' . $langs->trans('SendByMail') . '
'; } else @@ -2187,14 +2187,14 @@ if ($action == 'create') } // Create an order - if (! empty($conf->commande->enabled) && $object->statut == 2) { + if (! empty($conf->commande->enabled) && $object->statut == Propal::STATUS_SIGNED) { if ($user->rights->commande->creer) { print '
' . $langs->trans("AddOrder") . '
'; } } // Create contract - if ($conf->contrat->enabled && $object->statut == 2) { + if ($conf->contrat->enabled && $object->statut == Propal::STATUS_SIGNED) { $langs->load("contracts"); if ($user->rights->contrat->creer) { @@ -2203,7 +2203,7 @@ if ($action == 'create') } // Create an invoice and classify billed - if ($object->statut == 2) { + if ($object->statut == Propal::STATUS_SIGNED) { if (! empty($conf->facture->enabled) && $user->rights->facture->creer) { print '
' . $langs->trans("AddBill") . '
'; @@ -2217,7 +2217,7 @@ if ($action == 'create') } // Close - if ($object->statut == 1 && $user->rights->propal->cloturer) { + if ($object->statut == Propal::STATUS_VALIDATED && $user->rights->propal->cloturer) { print '
global->MAIN_JUMP_TAG) ? '' : '#close') . '"'; print '>' . $langs->trans('Close') . '
'; } diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index ce773b4e953..c1442aa403e 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -54,19 +54,56 @@ class Propal extends CommonObject var $id; - var $socid; // Id client - var $client; // Objet societe client (a charger par fetch_client) + /** + * ID of the client + * @var int + */ + var $socid; + /** + * Client (loaded by fetch_client) + * @var Societe + */ + var $client; var $contactid; var $fk_project; var $author; var $ref; var $ref_client; - var $statut; // 0 (draft), 1 (validated), 2 (signed), 3 (not signed), 4 (billed) - var $datec; // Date of creation - var $datev; // Date of validation - var $date; // Date of proposal - var $datep; // Same than date + + /** + * Status of the quote + * Check the following constants: + * - STATUS_DRAFT + * - STATUS_VALIDATED + * - STATUS_SIGNED + * - STATUS_NOTSIGNED + * - STATUS_BILLED + * @var int + */ + var $statut; + + /** + * Date of creation + * @var + */ + var $datec; + /** + * Date of validation + * @var + */ + var $datev; + /** + * Date of the quote + * @var + */ + var $date; + + /** + * Same than date ¿? + * @var + */ + var $datep; var $date_livraison; var $fin_validite; @@ -79,9 +116,19 @@ class Propal extends CommonObject var $total_localtax1; // Total Local Taxes 1 var $total_localtax2; // Total Local Taxes 2 var $total_ttc; // Total with tax - var $price; // deprecated (for compatibility) - var $tva; // deprecated (for compatibility) - var $total; // deprecated (for compatibility) + + /** + * @deprecated + */ + var $price; + /** + * @deprecated + */ + var $tva; + /** + * @deprecated + */ + var $total; var $cond_reglement_id; var $cond_reglement_code; @@ -91,10 +138,16 @@ class Propal extends CommonObject var $remise; var $remise_percent; var $remise_absolue; - var $note; // deprecated (for compatibility) + /** + * @deprecated + */ + var $note; var $note_private; var $note_public; - var $fk_delivery_address; // deprecated (for compatibility) + /** + * @deprecated + */ + var $fk_delivery_address; var $fk_address; var $address_type; var $address; @@ -126,6 +179,26 @@ class Propal extends CommonObject var $location_incoterms; var $libelle_incoterms; //Used into tooltip + /** + * Draft status + */ + const STATUS_DRAFT = 0; + /** + * Validated status + */ + const STATUS_VALIDATED = 1; + /** + * Signed quote + */ + const STATUS_SIGNED = 2; + /** + * Not signed quote + */ + const STATUS_NOTSIGNED = 3; + /** + * Billed quote + */ + const STATUS_BILLED = 4; /** * Constructor @@ -361,7 +434,7 @@ class Propal extends CommonObject // Check parameters if ($type < 0) return -1; - if ($this->statut == 0) + if ($this->statut == self::STATUS_DRAFT) { $this->db->begin(); @@ -525,7 +598,7 @@ class Propal extends CommonObject if (empty($qty) && empty($special_code)) $special_code=3; // Set option tag if (! empty($qty) && $special_code == 3) $special_code=0; // Remove option tag - if ($this->statut == 0) + if ($this->statut == self::STATUS_DRAFT) { $this->db->begin(); @@ -650,7 +723,7 @@ class Propal extends CommonObject */ function deleteline($lineid) { - if ($this->statut == 0) + if ($this->statut == self::STATUS_DRAFT) { $line=new PropaleLigne($this->db); @@ -1007,7 +1080,7 @@ class Propal extends CommonObject } $this->id=0; - $this->statut=0; + $this->statut=self::STATUS_DRAFT; if (empty($conf->global->PROPALE_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php")) { @@ -1192,7 +1265,7 @@ class Propal extends CommonObject $this->location_incoterms = $obj->location_incoterms; $this->libelle_incoterms = $obj->libelle_incoterms; - if ($obj->fk_statut == 0) + if ($obj->fk_statut == self::STATUS_DRAFT) { $this->brouillon = 1; } @@ -1385,8 +1458,8 @@ class Propal extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; $sql.= " SET ref = '".$num."',"; - $sql.= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + $sql.= " fk_statut = ".self::STATUS_VALIDATED.", date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id; + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; dol_syslog(get_class($this)."::valid", LOG_DEBUG); $resql=$this->db->query($sql); @@ -1441,7 +1514,7 @@ class Propal extends CommonObject $this->ref=$num; $this->brouillon=0; - $this->statut = 1; + $this->statut = self::STATUS_VALIDATED; $this->user_valid_id=$user->id; $this->datev=$now; @@ -1476,7 +1549,7 @@ class Propal extends CommonObject if (! empty($user->rights->propal->creer)) { $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET datep = '".$this->db->idate($date)."'"; - $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); if ($this->db->query($sql) ) @@ -1505,7 +1578,7 @@ class Propal extends CommonObject if (! empty($user->rights->propal->creer)) { $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite!=''?"'".$this->db->idate($date_fin_validite)."'":'null'); - $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) ) { $this->fin_validite = $date_fin_validite; @@ -1655,7 +1728,7 @@ class Propal extends CommonObject $remise = price2num($remise); $sql = "UPDATE ".MAIN_DB_PREFIX."propal 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) ) { @@ -1689,7 +1762,7 @@ class Propal extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $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; if ($this->db->query($sql) ) { @@ -1797,7 +1870,7 @@ class Propal extends CommonObject $modelpdf=$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED?$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED:$this->modelpdf; $trigger_name='PROPAL_CLOSE_REFUSED'; - if ($statut == 2) + if ($statut == self::STATUS_SIGNED) { $trigger_name='PROPAL_CLOSE_SIGNED'; $modelpdf=$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL?$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL:$this->modelpdf; @@ -1814,7 +1887,7 @@ class Propal extends CommonObject return -2; } } - if ($statut == 4) + if ($statut == self::STATUS_BILLED) { $trigger_name='PROPAL_CLASSIFY_BILLED'; } @@ -1864,11 +1937,11 @@ class Propal extends CommonObject */ function classifyBilled() { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = 4'; - $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;'; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = '.self::STATUS_BILLED; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT.' ;'; if ($this->db->query($sql) ) { - $this->statut=4; + $this->statut=self::STATUS_BILLED; return 1; } else @@ -1896,12 +1969,12 @@ class Propal extends CommonObject */ function set_draft($user) { - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 0"; + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = ".self::STATUS_DRAFT; $sql.= " WHERE rowid = ".$this->id; if ($this->db->query($sql)) { - $this->statut = 0; + $this->statut = self::STATUS_DRAFT; $this->brouillon = 1; return 1; } @@ -1945,7 +2018,7 @@ class Propal extends CommonObject $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; } if ($socid) $sql.= " AND s.rowid = ".$socid; - if ($draft) $sql.= " AND p.fk_statut = 0"; + if ($draft) $sql.= " AND p.fk_statut = ".self::STATUS_DRAFT; if ($notcurrentuser > 0) $sql.= " AND p.fk_user_author <> ".$user->id; $sql.= $this->db->order($sortfield,$sortorder); $sql.= $this->db->plimit($limit,$offset); @@ -2215,7 +2288,7 @@ class Propal extends CommonObject function availability($availability_id) { dol_syslog('Propale::availability('.$availability_id.')'); - if ($this->statut >= 0) + if ($this->statut >= self::STATUS_DRAFT) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal'; $sql .= ' SET fk_availability = '.$availability_id; @@ -2249,7 +2322,7 @@ class Propal extends CommonObject function demand_reason($demand_reason_id) { dol_syslog('Propale::demand_reason('.$demand_reason_id.')'); - if ($this->statut >= 0) + if ($this->statut >= self::STATUS_DRAFT) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal'; $sql .= ' SET fk_input_reason = '.$demand_reason_id; @@ -2356,11 +2429,11 @@ class Propal extends CommonObject global $langs; $langs->load("propal"); - if ($statut==0) $statuttrans='statut0'; - if ($statut==1) $statuttrans='statut1'; - if ($statut==2) $statuttrans='statut3'; - if ($statut==3) $statuttrans='statut5'; - if ($statut==4) $statuttrans='statut6'; + if ($statut==self::STATUS_DRAFT) $statuttrans='statut0'; + if ($statut==self::STATUS_VALIDATED) $statuttrans='statut1'; + if ($statut==self::STATUS_SIGNED) $statuttrans='statut3'; + if ($statut==self::STATUS_NOTSIGNED) $statuttrans='statut5'; + if ($statut==self::STATUS_BILLED) $statuttrans='statut6'; if ($mode == 0) return $this->labelstatut[$statut]; if ($mode == 1) return $this->labelstatut_short[$statut]; @@ -2393,8 +2466,8 @@ class Propal extends CommonObject $clause = " AND"; } $sql.= $clause." p.entity = ".$conf->entity; - if ($mode == 'opened') $sql.= " AND p.fk_statut = 1"; - if ($mode == 'signed') $sql.= " AND p.fk_statut = 2"; + if ($mode == 'opened') $sql.= " AND p.fk_statut = ".self::STATUS_VALIDATED; + if ($mode == 'signed') $sql.= " AND p.fk_statut = ".self::STATUS_SIGNED; if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id; $resql=$this->db->query($sql); @@ -2405,12 +2478,12 @@ class Propal extends CommonObject if ($mode == 'opened') { $delay_warning=$conf->propal->cloture->warning_delay; - $statut = 1; + $statut = self::STATUS_VALIDATED; $label = $langs->trans("PropalsToClose"); } if ($mode == 'signed') { $delay_warning=$conf->propal->facturation->warning_delay; - $statut = 2; + $statut = self::STATUS_SIGNED; $label = $langs->trans("PropalsToBill"); } @@ -2815,7 +2888,14 @@ class PropaleLigne extends CommonObject var $fk_parent_line; var $desc; // Description ligne var $fk_product; // Id produit predefini - var $product_type = 0; // Type 0 = product, 1 = Service + /** + * Product type. + * Use the following constants: + * - Product::TYPE_PRODUCT + * - Product::TYPE_SERVICE + * @var int + */ + var $product_type = Product::TYPE_PRODUCT; var $qty; var $tva_tx; diff --git a/htdocs/comm/propal/note.php b/htdocs/comm/propal/note.php index 9292684d06f..05cd2db3f04 100644 --- a/htdocs/comm/propal/note.php +++ b/htdocs/comm/propal/note.php @@ -126,7 +126,7 @@ if ($id > 0 || ! empty($ref)) if ($object->fin_validite) { print dol_print_date($object->fin_validite,'daytext'); - if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); + if ($object->statut == Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); } else { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index edf380b2e36..f95482f5e06 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -51,8 +51,17 @@ class Commande extends CommonOrder var $id; - var $socid; // Id client - var $client; // Objet societe client (a charger par fetch_client) + /** + * Client ID + * @var int + */ + var $socid; + + /** + * Client (loaded by fetch_client) + * @var Societe + */ + var $client; var $ref; var $ref_client; @@ -69,31 +78,13 @@ class Commande extends CommonOrder * - STATUS_CLOSED * @var int */ - var $statut; // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Delivered=Sent/Received, billed or not) + var $statut; + /** + * @deprecated + */ 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; @@ -153,6 +144,27 @@ class Commande extends CommonOrder */ const STOCK_NOT_ENOUGH_FOR_ORDER = -3; + /** + * 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; + /** * Constructor diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 9e8544bc0e9..42265846d04 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -60,6 +60,34 @@ abstract class CommonInvoice extends CommonObject */ const TYPE_SITUATION = 5; + /** + * Draft + */ + const STATUS_DRAFT = 0; + + /** + * Validated (need to be paid) + */ + const STATUS_VALIDATED = 1; + + /** + * Classified paid. + * If paid partially, $this->close_code can be: + * - CLOSECODE_DISCOUNTVAT + * - CLOSECODE_BADDEBT + * If paid completelly, this->close_code will be null + */ + const STATUS_CLOSED = 2; + + /** + * Classified abandoned and no payment done. + * $this->close_code can be: + * - CLOSECODE_BADDEBT + * - CLOSECODE_ABANDONED + * - CLOSECODE_REPLACED + */ + const STATUS_ABANDONED = 3; + /** * Return amount of payments already done * diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index f0abed84cbb..22ac415b511 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -52,7 +52,11 @@ class CommandeFournisseur extends CommonOrder var $id; - var $ref; // TODO deprecated + /** + * TODO: Remove + * @deprecated + */ + var $ref; var $product_ref; var $ref_supplier; var $brouillon; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 19cb26cf17b..99e9cca639c 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -55,10 +55,15 @@ class FactureFournisseur extends CommonInvoice var $socid; //Check constants for types var $type = self::TYPE_STANDARD; - //! 0=draft, - //! 1=validated - //! 2=classified paid partially (close_code='discount_vat','badcustomer') or completely (close_code=null), - //! Also 2, should be 3=classified abandoned and no payment done (close_code='badcustomer','abandon' ou 'replaced') + + /** + * Check constants for more info: + * - STATUS_DRAFT + * - STATUS_VALIDATED + * - STATUS_PAID + * - STATUS_ABANDONED + * @var int + */ var $statut; //! 1 si facture payee COMPLETEMENT, 0 sinon (ce champ ne devrait plus servir car insuffisant) var $paye; @@ -438,7 +443,7 @@ class FactureFournisseur extends CommonInvoice $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); $this->fetch_optionals($this->id,$extralabels); - if ($this->statut == 0) $this->brouillon = 1; + if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; $result=$this->fetch_lines(); if ($result < 0) @@ -886,7 +891,7 @@ class FactureFournisseur extends CommonInvoice $error=0; // Protection - if ($this->statut > 0) // This is to avoid to validate twice (avoid errors on logs and stock management) + if ($this->statut > self::STATUS_DRAFT) // This is to avoid to validate twice (avoid errors on logs and stock management) { dol_syslog(get_class($this)."::validate no draft status", LOG_WARNING); return 0; @@ -995,7 +1000,7 @@ class FactureFournisseur extends CommonInvoice if (! $error) { $this->ref = $num; - $this->statut=1; + $this->statut=self::STATUS_VALIDATED; //$this->date_validation=$now; this is stored into log table } @@ -1032,7 +1037,7 @@ class FactureFournisseur extends CommonInvoice $error=0; - if ($this->statut == 0) + if ($this->statut == self::STATUS_DRAFT) { dol_syslog(get_class($this)."::set_draft already draft status", LOG_WARNING); return 0; @@ -1746,7 +1751,7 @@ class FactureFournisseur extends CommonInvoice // Load source object $object->fetch($fromid); $object->id=0; - $object->statut=0; + $object->statut=self::STATUS_DRAFT; // Clear fields $object->ref_supplier=$langs->trans("CopyOf").' '.$object->ref_supplier; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index e93d06ad530..28fbe44fc9f 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -288,7 +288,7 @@ if (empty($reshook)) elseif ($action == 'deletepaiement' && $user->rights->fournisseur->facture->creer) { $object->fetch($id); - if ($object->statut == 1 && $object->paye == 0) + if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0) { $paiementfourn = new PaiementFourn($db); $result=$paiementfourn->fetch(GETPOST('paiement_id')); @@ -867,8 +867,8 @@ if (empty($reshook)) elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer) { $result = $object->fetch($id); - if ($object->statut == 2 - || ($object->statut == 3 && $object->close_code != 'replaced')) + if ($object->statut == FactureFournisseur::STATUS_CLOSED + || ($object->statut == FactureFournisseur::STATUS_ABANDONED && $object->close_code != 'replaced')) { $result = $object->set_unpaid($user); if ($result > 0) @@ -1739,8 +1739,8 @@ else print "\n"; // Ref supplier - print ''.$form->editfieldkey("RefSupplier",'ref_supplier',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; - print $form->editfieldval("RefSupplier",'ref_supplier',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)); + print ''.$form->editfieldkey("RefSupplier",'ref_supplier',$object->ref_supplier,$object,($object->statutrights->fournisseur->facture->creer)).''; + print $form->editfieldval("RefSupplier",'ref_supplier',$object->ref_supplier,$object,($object->statutrights->fournisseur->facture->creer)); print ''; // Third party @@ -1788,8 +1788,8 @@ else print ''; // Label - print ''.$form->editfieldkey("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; - print ''.$form->editfieldval("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; + print ''.$form->editfieldkey("Label",'label',$object->label,$object,($object->statutrights->fournisseur->facture->creer)).''; + print ''.$form->editfieldval("Label",'label',$object->label,$object,($object->statutrights->fournisseur->facture->creer)).''; /* * List of payments @@ -1853,7 +1853,7 @@ else } print ''.price($objp->amount).''; print ''; - if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) + if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->societe_id == 0) { print 'rowid.'">'; print img_delete(); @@ -1891,15 +1891,17 @@ else print ''; + $form_permission = $object->statutrights->fournisseur->facture->creer && $object->getSommePaiement() <= 0; + // Date - print ''.$form->editfieldkey("Date",'datef',$object->datep,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker').''; - print $form->editfieldval("Date",'datef',$object->datep,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker'); + print ''.$form->editfieldkey("Date",'datef',$object->datep,$object,$form_permission,'datepicker').''; + print $form->editfieldval("Date",'datef',$object->datep,$object,$form_permission,'datepicker'); print ''; // Due date - print ''.$form->editfieldkey("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker').''; - print $form->editfieldval("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker'); - if ($action != 'editdate_lim_reglement' && $object->statut < 2 && $object->date_echeance && $object->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_warning($langs->trans('Late')); + print ''.$form->editfieldkey("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,$form_permission,'datepicker').''; + print $form->editfieldval("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,$form_permission,'datepicker'); + if ($action != 'editdate_lim_reglement' && $object->statut < FactureFournisseur::STATUS_CLOSED && $object->date_echeance && $object->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_warning($langs->trans('Late')); print ''; // Conditions de reglement par defaut @@ -2081,7 +2083,7 @@ else '; - if (! empty($conf->use_javascript_ajax) && $object->statut == 0) { + if (! empty($conf->use_javascript_ajax) && $object->statut == FactureFournisseur::STATUS_DRAFT) { include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } @@ -2279,7 +2281,7 @@ else } */ // Form to add new line - if ($object->statut == 0 && $user->rights->fournisseur->facture->creer) + if ($object->statut == FactureFournisseur::STATUS_DRAFT && $user->rights->fournisseur->facture->creer) { if ($action != 'editline') { @@ -2310,7 +2312,7 @@ else print '
'; // Modify a validated invoice with no payments - if ($object->statut == 1 && $action != 'edit' && $object->getSommePaiement() == 0 && $user->rights->fournisseur->facture->creer) + if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $action != 'edit' && $object->getSommePaiement() == 0 && $user->rights->fournisseur->facture->creer) { print ''.$langs->trans('Modify').''; } @@ -2329,7 +2331,7 @@ else } // Send by mail - if (($object->statut == 1 || $object->statut == 2)) + if (($object->statut == FactureFournisseur::STATUS_VALIDATED || $object->statut == FactureFournisseur::STATUS_CLOSED)) { if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send) { @@ -2340,13 +2342,13 @@ else // Make payments - if ($action != 'edit' && $object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) + if ($action != 'edit' && $object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->societe_id == 0) { print ''.$langs->trans('DoPayment').''; // must use facid because id is for payment id not invoice } // Classify paid - if ($action != 'edit' && $object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) + if ($action != 'edit' && $object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->societe_id == 0) { print ''.$langs->trans('ClassifyPaid').''; @@ -2355,7 +2357,7 @@ else } // Validate - if ($action != 'edit' && $object->statut == 0) + if ($action != 'edit' && $object->statut == FactureFournisseur::STATUS_DRAFT) { if (count($object->lines)) {