diff --git a/dev/initdata/import-thirdparties.php b/dev/initdata/import-thirdparties.php index a5ccbf2c45d..0c32c7ea6a3 100755 --- a/dev/initdata/import-thirdparties.php +++ b/dev/initdata/import-thirdparties.php @@ -149,7 +149,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape)) $condpayment = trim($fields[36]); if ($condpayment == 'A la commande') $condpayment = 'A réception de commande'; if ($condpayment == 'A reception facture') $condpayment = 'Réception de facture'; - $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', getEntity('c_payment_term')); + $object->cond_reglement_id = dol_getIdFromCode($db, $condpayment, 'c_payment_term', 'libelle_facture', 'rowid', 1); if (empty($object->cond_reglement_id)) { print " - Error cant find payment mode for ".$condpayment."\n"; diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index 132d616e17b..71ff2b12cb9 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -461,7 +461,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && ! $paiement = new Paiement($db); $paiement->datepaye = $paymentdate; $paiement->amounts = $amounts; - $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement','code','id',getEntity('c_paiement')); + $paiement->paiementid = dol_getIdFromCode($db,$operation,'c_paiement','code','id',1); $paiement->num_paiement = $num_chq; $paiement->note = $label; diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index 9937deab531..399e2984ea8 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -136,7 +136,7 @@ switch ($action) $cond_reglement_id = 0; break; case 'ESP': - $mode_reglement_id = dol_getIdFromCode($db,'LIQ','c_paiement','code','id',getEntity('c_paiement')); + $mode_reglement_id = dol_getIdFromCode($db,'LIQ','c_paiement','code','id',1); $cond_reglement_id = 0; $note .= $langs->trans("Cash")."\n"; $note .= $langs->trans("Received").' : '.$obj_facturation->montantEncaisse()." ".$conf->currency."\n"; @@ -145,11 +145,11 @@ switch ($action) $note .= '--------------------------------------'."\n\n"; break; case 'CB': - $mode_reglement_id = dol_getIdFromCode($db,'CB','c_paiement','code','id',getEntity('c_paiement')); + $mode_reglement_id = dol_getIdFromCode($db,'CB','c_paiement','code','id',1); $cond_reglement_id = 0; break; case 'CHQ': - $mode_reglement_id = dol_getIdFromCode($db,'CHQ','c_paiement','code','id',getEntity('c_paiement')); + $mode_reglement_id = dol_getIdFromCode($db,'CHQ','c_paiement','code','id',1); $cond_reglement_id = 0; break; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ad56afe5d33..d1ad15ea2fe 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3660,7 +3660,7 @@ class Facture extends CommonInvoice if (! $error) { // Force payment mode of invoice to withdraw - $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', getEntity('c_paiement')); + $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', 1); if ($payment_mode_id > 0) { $result=$this->setPaymentMethods($payment_mode_id); diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index b2ba863d096..fe379045de0 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -251,7 +251,7 @@ if (empty($reshook)) $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching - $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement','code','id',getEntity('c_paiement')); + $paiement->paiementid = dol_getIdFromCode($db,GETPOST('paiementcode'),'c_paiement','code','id',1); $paiement->num_paiement = GETPOST('num_paiement'); $paiement->note = GETPOST('comment'); diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index 7aa0641f3bc..3458e6bc82a 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -478,8 +478,8 @@ class RemiseCheque extends CommonObject return ""; } } - - + + /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) * @@ -489,9 +489,9 @@ class RemiseCheque extends CommonObject function load_board($user) { global $conf, $langs; - + if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe - + $sql = "SELECT b.rowid, b.datev as datefin"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; @@ -500,28 +500,28 @@ class RemiseCheque extends CommonObject $sql.= " AND b.fk_type = 'CHQ'"; $sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.amount > 0"; - + $resql=$this->db->query($sql); if ($resql) { $langs->load("banks"); $now=dol_now(); - + $response = new WorkboardResponse(); $response->warning_delay=$conf->bank->cheque->warning_delay/60/60/24; $response->label=$langs->trans("BankChecksToReceipt"); $response->url=DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&mainmenu=bank'; $response->img=img_object('',"payment"); - + while ($obj=$this->db->fetch_object($resql)) { $response->nbtodo++; - + if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) { $response->nbtodolate++; } } - + return $response; } else @@ -531,8 +531,8 @@ class RemiseCheque extends CommonObject return -1; } } - - + + /** * Charge indicateurs this->nb de tableau de bord * @@ -541,9 +541,9 @@ class RemiseCheque extends CommonObject function load_state_board() { global $user; - + if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe - + $sql = "SELECT count(b.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; @@ -551,11 +551,11 @@ class RemiseCheque extends CommonObject $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.fk_type = 'CHQ'"; $sql.= " AND b.amount > 0"; - + $resql=$this->db->query($sql); if ($resql) { - + while ($obj=$this->db->fetch_object($resql)) { $this->nb["cheques"]=$obj->nb; @@ -792,7 +792,7 @@ class RemiseCheque extends CommonObject $rejectedPayment = new Paiement($db); $rejectedPayment->amounts = array(); $rejectedPayment->datepaye = $rejection_date; - $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',getEntity('c_paiement')); + $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',1); $rejectedPayment->num_paiement = $payment->numero; while($obj = $db->fetch_object($resql)) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 28a98d6df7c..688e93362b7 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5954,16 +5954,16 @@ function dol_osencode($str) * Return an id or code from a code or id. * Store also Code-Id into a cache to speed up next request on same key. * - * @param DoliDB $db Database handler - * @param string $key Code or Id to get Id or Code - * @param string $tablename Table name without prefix - * @param string $fieldkey Field for code - * @param string $fieldid Field for id - * @param int $entity Field for filter by entity - * @return int <0 if KO, Id of code if OK + * @param DoliDB $db Database handler + * @param string $key Code or Id to get Id or Code + * @param string $tablename Table name without prefix + * @param string $fieldkey Field for code + * @param string $fieldid Field for id + * @param int $entityfilter Filter by entity + * @return int <0 if KO, Id of code if OK * @see $langs->getLabelFromKey */ -function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id',$entity=null) +function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id',$entityfilter=0) { global $cache_codes; @@ -5979,8 +5979,8 @@ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id',$e $sql = "SELECT ".$fieldid." as valuetoget"; $sql.= " FROM ".MAIN_DB_PREFIX.$tablename; $sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'"; - if (! is_null($entity)) - $sql.= " AND entity = " . (int) $entity; + if (! empty($entityfilter)) + $sql.= " AND entity IN (" . getEntity($tablename) . ")"; dol_syslog('dol_getIdFromCode', LOG_DEBUG); $resql = $db->query($sql); if ($resql)