diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 89f324d2450..eba6fa42288 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -77,6 +77,7 @@ class FactureRec extends CommonInvoice public $total; public $db_table; public $propalid; + public $ref_client; public $date_last_gen; public $date_when; @@ -166,6 +167,7 @@ class FactureRec extends CommonInvoice $sql.= ", fk_account"; $sql.= ", fk_cond_reglement"; $sql.= ", fk_mode_reglement"; + $sql.= ", ref_client"; $sql.= ", usenewprice"; $sql.= ", frequency"; $sql.= ", unit_frequency"; @@ -194,6 +196,7 @@ class FactureRec extends CommonInvoice $sql.= ", ".(! empty($facsrc->fk_account)?"'".$facsrc->fk_account."'":"null"); $sql.= ", ".($facsrc->cond_reglement_id > 0 ? $this->db->escape($facsrc->cond_reglement_id) : "null"); $sql.= ", ".($facsrc->mode_reglement_id > 0 ? $this->db->escape($facsrc->mode_reglement_id) : "null"); + $sql.= ",'".$this->db->escape($this->ref_client)."'"; $sql.= ", ".$this->usenewprice; $sql.= ", ".$this->frequency; $sql.= ", '".$this->db->escape($this->unit_frequency)."'"; @@ -382,7 +385,7 @@ class FactureRec extends CommonInvoice $sql.= ', f.note_private, f.note_public, f.fk_user_author'; $sql.= ', f.modelpdf'; $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project'; - $sql.= ', f.fk_account'; + $sql.= ', f.fk_account, f.ref_client'; $sql.= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate'; $sql.= ', f.generate_pdf'; $sql.= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc"; @@ -1127,6 +1130,7 @@ class FactureRec extends CommonInvoice $facture->brouillon = 1; $facture->date = (empty($facturerec->date_when)?$now:$facturerec->date_when); // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later. $facture->socid = $facturerec->socid; + $facture->ref_client = $facturerec->ref_client; $invoiceidgenerated = $facture->create($user); if ($invoiceidgenerated <= 0) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index c2dc89c903e..9e9005d471d 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -358,6 +358,7 @@ class Facture extends CommonInvoice $this->socid = $_facrec->socid; // Invoice created on same thirdparty than template $this->entity = $_facrec->entity; // Invoice created in same entity than template + $this->ref_client = $_facrec->ref_client; // Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI $this->fk_project = GETPOST('projectid', 'int') > 0 ? ((int) GETPOST('projectid', 'int')) : $_facrec->fk_project; diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index fa8af87ac29..25144edbcb3 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -174,6 +174,7 @@ if (empty($reshook)) if (! $error) { $object->titre = GETPOST('titre', 'alpha'); + $object->ref_client = GETPOST('ref_client', 'alpha'); $object->note_private = GETPOST('note_private', 'none'); $object->note_public = GETPOST('note_public', 'none'); $object->modelpdf = GETPOST('modelpdf', 'alpha'); @@ -274,7 +275,7 @@ if (empty($reshook)) { $object->setProject(GETPOST('projectid', 'int')); } - // Set bank account + // Set titre elseif ($action == 'setref' && $user->rights->facture->creer) { //var_dump(GETPOST('ref', 'alpha'));exit; @@ -286,6 +287,15 @@ if (empty($reshook)) } else dol_print_error($db, $object->error, $object->errors); } + elseif ($action == 'setref_client' && $user->rights->facture->creer) + { + $result=$object->setValueFrom('ref_client', GETPOST('ref_client', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY'); + if ($result > 0) + { + $object->ref_client = GETPOST('ref_client', 'alpha'); + } + else dol_print_error($db, $object->error, $object->errors); + } // Set bank account elseif ($action == 'setbankaccount' && $user->rights->facture->creer) { @@ -997,6 +1007,11 @@ if ($action == 'create') print ''; print ''; + // Ref Client + print '