From f70dd8ec06ff2c9f3c5b64d2a844849ba962f1f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Feb 2020 00:22:53 +0100 Subject: [PATCH] Clean code. Load thirdparty for correct lang before generating doc --- htdocs/comm/propal/class/propal.class.php | 16 +++++++++------- htdocs/commande/class/commande.class.php | 14 ++++++++------ htdocs/compta/facture/class/facture.class.php | 16 +++++++++------- htdocs/compta/paiement/class/paiement.class.php | 14 ++++++++++---- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 33e33301cfd..c6d1af1287e 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1365,7 +1365,7 @@ class Propal extends CommonObject } /** - * Load a proposal from database and its ligne array + * Load a proposal from database. Get also lines. * * @param int $rowid id of object to load * @param string $ref Ref of proposal @@ -1373,7 +1373,6 @@ class Propal extends CommonObject */ public function fetch($rowid, $ref = '') { - $sql = "SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc"; $sql .= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht"; $sql .= ", p.datec"; @@ -1437,8 +1436,13 @@ class Propal extends CommonObject $this->total_localtax1 = $obj->localtax1; $this->total_localtax2 = $obj->localtax2; $this->total_ttc = $obj->total; - $this->socid = $obj->fk_soc; - $this->fk_project = $obj->fk_project; + + $this->socid = $obj->fk_soc; + $this->thirdparty = null; // Clear if another value was already set by fetch_thirdparty + + $this->fk_project = $obj->fk_project; + $this->project = null; // Clear if another value was already set by fetch_projet + $this->modelpdf = $obj->model_pdf; $this->last_main_doc = $obj->last_main_doc; $this->note = $obj->note_private; // TODO deprecated @@ -1506,9 +1510,7 @@ class Propal extends CommonObject $this->lines = array(); - /* - * Lines - */ + // Lines $result = $this->fetch_lines(); if ($result < 0) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 21b8c983d8e..f095a814652 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1680,7 +1680,7 @@ class Commande extends CommonOrder /** - * Get object and lines from database + * Get object from database. Get also lines. * * @param int $id Id of object to load * @param string $ref Ref of object @@ -1690,7 +1690,6 @@ class Commande extends CommonOrder */ public function fetch($id, $ref = '', $ref_ext = '', $ref_int = '') { - // Check parameters if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1; @@ -1740,7 +1739,13 @@ class Commande extends CommonOrder $this->ref_customer = $obj->ref_client; $this->ref_ext = $obj->ref_ext; $this->ref_int = $obj->ref_int; + $this->socid = $obj->fk_soc; + $this->thirdparty = null; // Clear if another value was already set by fetch_thirdparty + + $this->fk_project = $obj->fk_project; + $this->project = null; // Clear if another value was already set by fetch_projet + $this->statut = $obj->fk_statut; $this->user_author_id = $obj->fk_user_author; $this->user_valid = $obj->fk_user_valid; @@ -1762,7 +1767,6 @@ class Commande extends CommonOrder $this->note = $obj->note_private; // deprecated $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; - $this->fk_project = $obj->fk_project; $this->modelpdf = $obj->model_pdf; $this->last_main_doc = $obj->last_main_doc; $this->mode_reglement_id = $obj->fk_mode_reglement; @@ -1810,9 +1814,7 @@ class Commande extends CommonOrder $this->db->free($result); - /* - * Lines - */ + // Lines $result = $this->fetch_lines(); if ($result < 0) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 294493ed081..0cc72fdcdcc 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1436,7 +1436,7 @@ class Facture extends CommonInvoice } /** - * Get object and lines from database + * Get object from database. Get also lines. * * @param int $rowid Id of object to load * @param string $ref Reference of invoice @@ -1517,7 +1517,13 @@ class Facture extends CommonInvoice $this->paye = $obj->paye; $this->close_code = $obj->close_code; $this->close_note = $obj->close_note; - $this->socid = $obj->fk_soc; + + $this->socid = $obj->fk_soc; + $this->thirdparty = null; // Clear if another value was already set by fetch_thirdparty + + $this->fk_project = $obj->fk_project; + $this->project = null; // Clear if another value was already set by fetch_projet + $this->statut = $obj->fk_statut; $this->date_lim_reglement = $this->db->jdate($obj->dlr); $this->mode_reglement_id = $obj->fk_mode_reglement; @@ -1528,7 +1534,6 @@ class Facture extends CommonInvoice $this->cond_reglement = $obj->cond_reglement_libelle; $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc; $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account : null; - $this->fk_project = $obj->fk_project; $this->fk_facture_source = $obj->fk_facture_source; $this->fk_fac_rec_source = $obj->fk_fac_rec_source; $this->note = $obj->note_private; // deprecated @@ -1574,10 +1579,7 @@ class Facture extends CommonInvoice // fetch optionals attributes and labels $this->fetch_optionals(); - /* - * Lines - */ - + // Lines $this->lines = array(); $result = $this->fetch_lines(); diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 75dcb837df9..ad20599ce94 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -272,7 +272,9 @@ class Paiement extends CommonObject return -1; } - $this->db->begin(); + dol_syslog(get_class($this)."::create insert paiement", LOG_DEBUG); + + $this->db->begin(); $this->ref = $this->getNextNumRef(is_object($thirdparty)?$thirdparty:''); @@ -293,7 +295,6 @@ class Paiement extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, ext_payment_id, ext_payment_site, fk_user_creat)"; $sql.= " VALUES (".$conf->entity.", '".$this->db->escape($this->ref)."', '". $this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', ".$total.", ".$mtotal.", ".$this->paiementid.", '".$this->db->escape($num_payment)."', '".$this->db->escape($note)."', ".($this->ext_payment_id?"'".$this->db->escape($this->ext_payment_id)."'":"null").", ".($this->ext_payment_site?"'".$this->db->escape($this->ext_payment_site)."'":"null").", ".$user->id.")"; - dol_syslog(get_class($this)."::Create insert paiement", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -309,7 +310,7 @@ class Paiement extends CommonObject $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount)'; $sql .= ' VALUES ('.$facid.', '. $this->id.', \''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')'; - dol_syslog(get_class($this).'::Create Amount line '.$key.' insert paiement_facture', LOG_DEBUG); + dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -409,9 +410,14 @@ class Paiement extends CommonObject // Regenerate documents of invoices if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + dol_syslog(get_class($this).'::create Regenerate the document after inserting payment for thirdparty default_lang='.(is_object($invoice->thirdparty) ? $invoice->thirdparty->default_lang : 'null'), LOG_DEBUG); + $newlang=''; $outputlangs = $langs; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $invoice->fetch_thirdparty(); + $newlang = $invoice->thirdparty->default_lang; + } if (! empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang);