diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index fd0f3faa95a..3e6deac6814 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -64,6 +64,8 @@ class Commande extends CommonObject var $mode_reglement_code; var $availability_id; var $availability_code; + var $demand_reason_id; + var $demand_reason_code; var $fk_delivery_address; var $adresse; var $date; // Date commande @@ -567,7 +569,7 @@ class Commande extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande ("; $sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, note_public, ref_client"; - $sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_availability, date_livraison, fk_adresse_livraison"; + $sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_availability, fk_demand_reason, date_livraison, fk_adresse_livraison"; $sql.= ", remise_absolue, remise_percent"; $sql.= ", entity"; $sql.= ")"; @@ -580,6 +582,7 @@ class Commande extends CommonObject $sql.= ", ".($this->cond_reglement_id>0?"'".$this->cond_reglement_id."'":"null"); $sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"null"); $sql.= ", ".($this->availability_id>0?"'".$this->availability_id."'":"null"); + $sql.= ", ".($this->demand_reason_id>0?"'".$this->demand_reason_id."'":"null"); $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null"); $sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:'NULL'); $sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL'); @@ -854,6 +857,7 @@ class Commande extends CommonObject $this->cond_reglement_id = $object->cond_reglement_id; $this->mode_reglement_id = $object->mode_reglement_id; $this->availability_id = $object->availability_id; + $this->demand_reason_id = $object->demand_reason_id; $this->date_livraison = $object->date_livraison; $this->fk_delivery_address = $object->fk_delivery_address; $this->contact_id = $object->contactid; @@ -1142,7 +1146,7 @@ class Commande extends CommonObject if (empty($id) && empty($ref)) return -1; $sql = 'SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut'; - $sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability'; + $sql.= ', c.amount_ht, c.total_ht, c.total_ttc, c.tva as total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_demand_reason'; $sql.= ', c.date_commande'; $sql.= ', c.date_livraison'; $sql.= ', c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as facturee'; @@ -1150,11 +1154,13 @@ class Commande extends CommonObject $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= ', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_doc'; $sql.= ', ca.code as availability_code'; + $sql.= ', dr.code as demand_reason_code'; $sql.= ', el.fk_source'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON (c.fk_cond_reglement = cr.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON (c.fk_availability = ca.rowid)'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_demand_reason as dr ON (c.fk_demand_reason = ca.rowid)'; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = c.rowid AND el.targettype = '".$this->element."'"; $sql.= " WHERE c.entity = ".$conf->entity; if ($ref) $sql.= " AND c.ref='".$ref."'"; @@ -1198,6 +1204,8 @@ class Commande extends CommonObject $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc; $this->availability_id = $obj->fk_availability; $this->availability_code = $obj->availability_code; + $this->demand_reason_id = $obj->fk_demand_reason; + $this->demand_reason_code = $obj->demand_reason_code; $this->date_livraison = $this->db->jdate($obj->date_livraison); $this->fk_delivery_address = $obj->fk_adresse_livraison; $this->propale_id = $obj->fk_source; @@ -1810,6 +1818,34 @@ class Commande extends CommonObject } } + /** + * \brief Set source of demand + * \param user Objet utilisateur qui modifie + * \param delivery delai de livraison + * \return int <0 si ko, >0 si ok + */ + function set_demand_reason($user, $id) + { + if ($user->rights->commande->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; + $sql.= " SET fk_demand_reason = '".$id."'"; + $sql.= " WHERE rowid = ".$this->id; + + if ($this->db->query($sql)) + { + $this->fk_demand_reason = $id; + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog("Commande::set_demand_reason Erreur SQL"); + return -1; + } + } + } + /** * \brief Return list of orders (eventuelly filtered on a user) into an array * \param brouillon 0=non brouillon, 1=brouillon @@ -1954,6 +1990,39 @@ class Commande extends CommonObject } } + /** + * \brief Change la source de la demande + * \param mode Id du nouveau mode + * \return int >0 si ok, <0 si ko + */ + function demand_reason($demand_reason_id) + { + dol_syslog('Commande::demand_reason('.$demand_reason_id.')'); + if ($this->statut >= 0) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; + $sql .= ' SET fk_demand_reason = '.$demand_reason_id; + $sql .= ' WHERE rowid='.$this->id; + if ( $this->db->query($sql) ) + { + $this->demand_reason_id = $demand_reason_id; + return 1; + } + else + { + dol_syslog('Commande::demand_reason Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + dol_syslog('Commande::demand_reason, etat facture incompatible', LOG_ERR); + $this->error='Etat commande incompatible '.$this->statut; + return -2; + } + } + /** * \brief Set customer ref * \param user User that make change @@ -2495,6 +2564,7 @@ class Commande extends CommonObject $this->cond_reglement_code = 'RECEP'; $this->mode_reglement_code = 'CHQ'; $this->availability_code = 'DSP'; + $this->demand_reason_code = 'SRC_00'; $this->note_public='This is a comment (public)'; $this->note='This is a comment (private)'; // Lines diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 61071567483..78bc6b0cd95 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -208,6 +208,7 @@ if ($action == 'add' && $user->rights->commande->creer) $object->cond_reglement_id = $_POST['cond_reglement_id']; $object->mode_reglement_id = $_POST['mode_reglement_id']; $object->availability_id = $_POST['availability_id']; + $object->demand_reason_id = $_POST['demand_reason_id']; $object->date_livraison = $datelivraison; $object->fk_delivery_address = $_POST['fk_address']; $object->contactid = $_POST['contactidp']; @@ -463,6 +464,13 @@ if ($action == 'setavailability' && $user->rights->commande->creer) if ($result < 0) dol_print_error($db,$object->error); } +if ($action == 'setdemandreason' && $user->rights->commande->creer) +{ + $object->fetch($id); + $result=$object->demand_reason($_POST['demand_reason_id']); + if ($result < 0) dol_print_error($db,$object->error); +} + if ($action == 'setconditions' && $user->rights->commande->creer) { $object->fetch($id); @@ -1161,6 +1169,7 @@ if ($action == 'create' && $user->rights->commande->creer) $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); $availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0)); + $demand_reason_id = (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0)); $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; @@ -1174,6 +1183,7 @@ if ($action == 'create' && $user->rights->commande->creer) $cond_reglement_id = $soc->cond_reglement_id; $mode_reglement_id = $soc->mode_reglement_id; $availability_id = $soc->availability_id; + $demand_reason_id = $soc->demand_reason_id; $remise_percent = $soc->remise_percent; $remise_absolue = 0; $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; @@ -1265,6 +1275,11 @@ if ($action == 'create' && $user->rights->commande->creer) // delai de livraison print '
| '; + print $langs->trans('Source'); + print ' | '; + if ($_GET['action'] != 'editdemandreason' && $object->brouillon) print 'id.'">'.img_edit($langs->trans('SetDemandReason'),1).' | '; + print '