Fix: change the parameter value of dol_getIdFromCode

This commit is contained in:
Regis Houssin
2017-10-02 11:59:17 +02:00
parent 09e71f1390
commit e65b21a3bf
7 changed files with 33 additions and 33 deletions

View File

@@ -149,7 +149,7 @@ while ($fields=fgetcsv($fhandle, $linelength, $delimiter, $enclosure, $escape))
$condpayment = trim($fields[36]); $condpayment = trim($fields[36]);
if ($condpayment == 'A la commande') $condpayment = 'A réception de commande'; if ($condpayment == 'A la commande') $condpayment = 'A réception de commande';
if ($condpayment == 'A reception facture') $condpayment = 'Réception de facture'; 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)) if (empty($object->cond_reglement_id))
{ {
print " - Error cant find payment mode for ".$condpayment."\n"; print " - Error cant find payment mode for ".$condpayment."\n";

View File

@@ -461,7 +461,7 @@ if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !
$paiement = new Paiement($db); $paiement = new Paiement($db);
$paiement->datepaye = $paymentdate; $paiement->datepaye = $paymentdate;
$paiement->amounts = $amounts; $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->num_paiement = $num_chq;
$paiement->note = $label; $paiement->note = $label;

View File

@@ -136,7 +136,7 @@ switch ($action)
$cond_reglement_id = 0; $cond_reglement_id = 0;
break; break;
case 'ESP': 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; $cond_reglement_id = 0;
$note .= $langs->trans("Cash")."\n"; $note .= $langs->trans("Cash")."\n";
$note .= $langs->trans("Received").' : '.$obj_facturation->montantEncaisse()." ".$conf->currency."\n"; $note .= $langs->trans("Received").' : '.$obj_facturation->montantEncaisse()." ".$conf->currency."\n";
@@ -145,11 +145,11 @@ switch ($action)
$note .= '--------------------------------------'."\n\n"; $note .= '--------------------------------------'."\n\n";
break; break;
case 'CB': 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; $cond_reglement_id = 0;
break; break;
case 'CHQ': 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; $cond_reglement_id = 0;
break; break;
} }

View File

@@ -3660,7 +3660,7 @@ class Facture extends CommonInvoice
if (! $error) if (! $error)
{ {
// Force payment mode of invoice to withdraw // 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) if ($payment_mode_id > 0)
{ {
$result=$this->setPaymentMethods($payment_mode_id); $result=$this->setPaymentMethods($payment_mode_id);

View File

@@ -251,7 +251,7 @@ if (empty($reshook))
$paiement->datepaye = $datepaye; $paiement->datepaye = $datepaye;
$paiement->amounts = $amounts; // Array with all payments dispatching with invoice id $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id
$paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching $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->num_paiement = GETPOST('num_paiement');
$paiement->note = GETPOST('comment'); $paiement->note = GETPOST('comment');

View File

@@ -478,8 +478,8 @@ class RemiseCheque extends CommonObject
return ""; return "";
} }
} }
/** /**
* Load indicators for dashboard (this->nbtodo and this->nbtodolate) * Load indicators for dashboard (this->nbtodo and this->nbtodolate)
* *
@@ -489,9 +489,9 @@ class RemiseCheque extends CommonObject
function load_board($user) function load_board($user)
{ {
global $conf, $langs; global $conf, $langs;
if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
$sql = "SELECT b.rowid, b.datev as datefin"; $sql = "SELECT b.rowid, b.datev as datefin";
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $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_type = 'CHQ'";
$sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.fk_bordereau = 0";
$sql.= " AND b.amount > 0"; $sql.= " AND b.amount > 0";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$langs->load("banks"); $langs->load("banks");
$now=dol_now(); $now=dol_now();
$response = new WorkboardResponse(); $response = new WorkboardResponse();
$response->warning_delay=$conf->bank->cheque->warning_delay/60/60/24; $response->warning_delay=$conf->bank->cheque->warning_delay/60/60/24;
$response->label=$langs->trans("BankChecksToReceipt"); $response->label=$langs->trans("BankChecksToReceipt");
$response->url=DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&mainmenu=bank'; $response->url=DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&mainmenu=bank';
$response->img=img_object('',"payment"); $response->img=img_object('',"payment");
while ($obj=$this->db->fetch_object($resql)) while ($obj=$this->db->fetch_object($resql))
{ {
$response->nbtodo++; $response->nbtodo++;
if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) { if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
$response->nbtodolate++; $response->nbtodolate++;
} }
} }
return $response; return $response;
} }
else else
@@ -531,8 +531,8 @@ class RemiseCheque extends CommonObject
return -1; return -1;
} }
} }
/** /**
* Charge indicateurs this->nb de tableau de bord * Charge indicateurs this->nb de tableau de bord
* *
@@ -541,9 +541,9 @@ class RemiseCheque extends CommonObject
function load_state_board() function load_state_board()
{ {
global $user; global $user;
if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
$sql = "SELECT count(b.rowid) as nb"; $sql = "SELECT count(b.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $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 ba.entity IN (".getEntity('bank_account').")";
$sql.= " AND b.fk_type = 'CHQ'"; $sql.= " AND b.fk_type = 'CHQ'";
$sql.= " AND b.amount > 0"; $sql.= " AND b.amount > 0";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
while ($obj=$this->db->fetch_object($resql)) while ($obj=$this->db->fetch_object($resql))
{ {
$this->nb["cheques"]=$obj->nb; $this->nb["cheques"]=$obj->nb;
@@ -792,7 +792,7 @@ class RemiseCheque extends CommonObject
$rejectedPayment = new Paiement($db); $rejectedPayment = new Paiement($db);
$rejectedPayment->amounts = array(); $rejectedPayment->amounts = array();
$rejectedPayment->datepaye = $rejection_date; $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; $rejectedPayment->num_paiement = $payment->numero;
while($obj = $db->fetch_object($resql)) while($obj = $db->fetch_object($resql))

View File

@@ -5954,16 +5954,16 @@ function dol_osencode($str)
* Return an id or code from a code or id. * 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. * Store also Code-Id into a cache to speed up next request on same key.
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
* @param string $key Code or Id to get Id or Code * @param string $key Code or Id to get Id or Code
* @param string $tablename Table name without prefix * @param string $tablename Table name without prefix
* @param string $fieldkey Field for code * @param string $fieldkey Field for code
* @param string $fieldid Field for id * @param string $fieldid Field for id
* @param int $entity Field for filter by entity * @param int $entityfilter Filter by entity
* @return int <0 if KO, Id of code if OK * @return int <0 if KO, Id of code if OK
* @see $langs->getLabelFromKey * @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; global $cache_codes;
@@ -5979,8 +5979,8 @@ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id',$e
$sql = "SELECT ".$fieldid." as valuetoget"; $sql = "SELECT ".$fieldid." as valuetoget";
$sql.= " FROM ".MAIN_DB_PREFIX.$tablename; $sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
$sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'"; $sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'";
if (! is_null($entity)) if (! empty($entityfilter))
$sql.= " AND entity = " . (int) $entity; $sql.= " AND entity IN (" . getEntity($tablename) . ")";
dol_syslog('dol_getIdFromCode', LOG_DEBUG); dol_syslog('dol_getIdFromCode', LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)