From cdb63bada39a44c7e555c77bd617fb1a1e7e22f6 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 26 Jan 2018 18:13:55 +0100 Subject: [PATCH 1/7] FIX: #7974 Contract - Invalid reference on the document --- htdocs/contrat/card.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index a1a38d04626..ae1178adf9a 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2010-2015 Juanjo Menent + * Copyright (C) 2010-2017 Juanjo Menent * Copyright (C) 2013 Christophe Battarel * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014-2016 Ferran Marcet @@ -753,6 +753,30 @@ if (empty($reshook)) else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer) { $result = $object->validate($user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } } else if ($action == 'reopen' && $user->rights->contrat->creer) From ba58578d602796643c7612c34d3c38a6992f57fb Mon Sep 17 00:00:00 2001 From: kadogo Date: Sat, 27 Jan 2018 19:31:48 +0100 Subject: [PATCH 2/7] FIX: Global on $user parameter reset the variable When we use the fichinter API with global, the $user object is reset If global is not applied on $user we can retrieve the informations from it --- htdocs/fichinter/class/fichinter.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 70192c460d2..fb2359092a0 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -140,7 +140,7 @@ class Fichinter extends CommonObject */ function create($user, $notrigger=0) { - global $conf, $user, $langs; + global $conf, $langs; dol_syslog(get_class($this)."::create ref=".$this->ref); From 3c281ccefab54ddb9d2caad5bcaf7d8178fa7349 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Mon, 29 Jan 2018 17:50:00 +0100 Subject: [PATCH 3/7] FIX: Bad localtaxes assignment in cashdesk --- htdocs/cashdesk/class/Facturation.class.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/cashdesk/class/Facturation.class.php b/htdocs/cashdesk/class/Facturation.class.php index b55524a874a..6397e3d30da 100644 --- a/htdocs/cashdesk/class/Facturation.class.php +++ b/htdocs/cashdesk/class/Facturation.class.php @@ -1,7 +1,7 @@ +/* Copyright (C) 2007-2008 Jeremie Ollivier * Copyright (C) 2008-2010 Laurent Destailleur - * Copyright (C) 2010 Juanjo Menent + * Copyright (C) 2010-2018 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -117,7 +117,12 @@ class Facturation } // Define part of HT, VAT, TTC - $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, -1, -1, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); + + // Local Taxes + $localtax1_tx = get_localtax($txtva, 1, $societe); + $localtax2_tx = get_localtax($txtva, 2, $societe); + + $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, $localtax1_tx, $localtax2_tx, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); // Calcul du total ht sans remise $total_ht = $resultarray[0]; From 8102883356c5c56e1a877a7f7f8f694f651924b6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 29 Jan 2018 20:36:40 +0100 Subject: [PATCH 4/7] Fix error when email list contains ', ,' Fix output dir of notification --- htdocs/core/class/notify.class.php | 47 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 6f2f9e56d61..6190f2d3acf 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -58,7 +58,7 @@ class Notify 'SHIPPING_VALIDATE' ); - + /** * Constructor * @@ -85,14 +85,14 @@ class Notify $langs->load("mails"); $listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0); - + $nb=-1; if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo); if ($nb < 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend"); if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent"); if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent"); if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb); - + if (is_array($listofnotiftodo)) { $i=0; @@ -106,7 +106,7 @@ class Notify } if ($i) $texte.=')'; } - + return $texte; } @@ -149,9 +149,9 @@ class Notify } $sql.= " AND s.entity IN (".getEntity('societe').")"; if ($socid > 0) $sql.= " AND s.rowid = ".$socid; - + dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); - + $resql = $this->db->query($sql); if ($resql) { @@ -176,7 +176,7 @@ class Notify } } } - + if (! $error) { if ($userid >= 0 && in_array('user', $scope)) @@ -194,9 +194,9 @@ class Notify } $sql.= " AND c.entity IN (".getEntity('user').")"; if ($userid > 0) $sql.= " AND c.rowid = ".$userid; - + dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); - + $resql = $this->db->query($sql); if ($resql) { @@ -237,10 +237,10 @@ class Notify { if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; } - + $threshold = (float) $reg[1]; if ($valueforthreshold < $threshold) continue; - + $tmpemail=explode(',',$val); foreach($tmpemail as $key2 => $val2) { @@ -295,7 +295,7 @@ class Notify $hookmanager=new HookManager($this->db); } $hookmanager->initHooks(array('notification')); - + dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); $langs->load("other"); @@ -342,7 +342,7 @@ class Notify $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage else $sql.= " AND a.code = '".$notifcode."'"; // New usage - + $result = $this->db->query($sql); if ($result) { @@ -369,7 +369,7 @@ class Notify } $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification"); - + switch ($notifcode) { case 'BILL_VALIDATE': $link='/compta/facture/card.php?facid='.$object->id; @@ -397,13 +397,13 @@ class Notify break; case 'FICHINTER_ADD_CONTACT': $link='/fichinter/card.php?id='.$object->id; - $dir_output = $conf->facture->dir_output; + $dir_output = $conf->ficheinter->dir_output; $object_type = 'ficheinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$object->ref); break; case 'FICHINTER_VALIDATE': $link='/fichinter/card.php?id='.$object->id; - $dir_output = $conf->facture->dir_output; + $dir_output = $conf->ficheinter->dir_output; $object_type = 'ficheinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); break; @@ -462,7 +462,7 @@ class Notify if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; } - + $mailfile = new CMailFile( $subject, $sendto, @@ -478,16 +478,16 @@ class Notify ); if ($mailfile->sendfile()) - { + { if ($obj->type_target == 'touserid') { $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; - + } else { $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; - + } if (! $this->db->query($sql)) { @@ -651,8 +651,9 @@ class Notify } dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); - $sendto = preg_replace('/^[\s,]+/','',$sendto); // Clean start of string - $sendto = preg_replace('/[\s,]+$/','',$sendto); // Clean end of string + $sendto = preg_replace('/,\s*,/', ',', $sendto); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid + $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string + $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string } if ($sendto) @@ -664,7 +665,7 @@ class Notify if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; } - + $mailfile = new CMailFile( $subject, $sendto, From c80fa48225e489fe46a7b2225c13eef48afe683f Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Thu, 1 Feb 2018 09:31:04 +0100 Subject: [PATCH 5/7] FIX update_extras on fourn card --- htdocs/fourn/card.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 328157af7bf..d99df78c27c 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -101,6 +101,21 @@ if (empty($reshook)) $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int')); if ($result < 0) dol_print_error($db,$object->error); } + if ($action == 'update_extras') { + $object->fetch($id); + + // Fill array 'array_options' with data from update form + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); + + if ($ret < 0) $error++; + if (! $error) + { + $result = $object->insertExtraFields(); + if ($result < 0) $error++; + } + if ($error) $action = 'edit_extras'; + } } From 13106d34a6a0623c2f45fbf15a13cae843825883 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 2 Feb 2018 12:36:47 +0100 Subject: [PATCH 6/7] Fix: compatibility with multicompany sharing --- htdocs/core/class/commonobject.class.php | 47 +++++++++++++----------- htdocs/societe/class/societe.class.php | 20 +++++----- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 83c38477f28..fa59659ab31 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1183,33 +1183,38 @@ abstract class CommonObject } /** - * Load object from specific field + * Load object from specific field * - * @param string $table Table element or element line - * @param string $field Field selected - * @param string $key Import key - * @return int <0 if KO, >0 if OK + * @param string $table Table element or element line + * @param string $field Field selected + * @param string $key Import key + * @param string $element Element name + * @return int <0 if KO, >0 if OK */ - function fetchObjectFrom($table,$field,$key) - { - global $conf; + function fetchObjectFrom($table, $field, $key, $element = null) + { + global $conf; - $result=false; + $result=false; - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; - $sql.= " WHERE ".$field." = '".$key."'"; - $sql.= " AND entity = ".$conf->entity; + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE ".$field." = '".$key."'"; + if (! empty($element)) { + $sql.= " AND entity IN (".getEntity($element).")"; + } else { + $sql.= " AND entity = ".$conf->entity; + } - dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - $result = $this->fetch($row[0]); - } + dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $row = $this->db->fetch_row($resql); + $result = $this->fetch($row[0]); + } - return $result; - } + return $result; + } /** * Getter generic. Load value from a specific field diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index b950b2f2c46..afc33f110cf 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1051,16 +1051,16 @@ class Societe extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid'; if ($rowid) $sql .= ' WHERE s.rowid = '.$rowid; - else if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof5) $sql .= " WHERE s.idprof5 = '".$this->db->escape($idprof5)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($idprof6) $sql .= " WHERE s.idprof6 = '".$this->db->escape($idprof6)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($email) $sql .= " WHERE email = '".$this->db->escape($email)."' AND s.entity IN (".getEntity($this->element, 1).")"; + else if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof5) $sql .= " WHERE s.idprof5 = '".$this->db->escape($idprof5)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($idprof6) $sql .= " WHERE s.idprof6 = '".$this->db->escape($idprof6)."' AND s.entity IN (".getEntity($this->element).")"; + else if ($email) $sql .= " WHERE email = '".$this->db->escape($email)."' AND s.entity IN (".getEntity($this->element).")"; $resql=$this->db->query($sql); if ($resql) From 464ee6f9d6e9b5d9357d808a911010a1207eb21c Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 2 Feb 2018 17:46:25 +0100 Subject: [PATCH 7/7] Revert --- htdocs/cashdesk/class/Facturation.class.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/htdocs/cashdesk/class/Facturation.class.php b/htdocs/cashdesk/class/Facturation.class.php index 6397e3d30da..b55524a874a 100644 --- a/htdocs/cashdesk/class/Facturation.class.php +++ b/htdocs/cashdesk/class/Facturation.class.php @@ -1,7 +1,7 @@ +/* Copyright (C) 2007-2008 Jeremie Ollivier * Copyright (C) 2008-2010 Laurent Destailleur - * Copyright (C) 2010-2018 Juanjo Menent + * Copyright (C) 2010 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -117,12 +117,7 @@ class Facturation } // Define part of HT, VAT, TTC - - // Local Taxes - $localtax1_tx = get_localtax($txtva, 1, $societe); - $localtax2_tx = get_localtax($txtva, 2, $societe); - - $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, $localtax1_tx, $localtax2_tx, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); + $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, -1, -1, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); // Calcul du total ht sans remise $total_ht = $resultarray[0];