26if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL', 1);
29if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32if (!defined(
'NOREQUIREHTML')) {
33 define(
'NOREQUIREHTML',
'1');
35if (!defined(
'NOREQUIREAJAX')) {
36 define(
'NOREQUIREAJAX',
'1');
38if (!defined(
'NOHEADERNOFOOTER')) {
39 define(
'NOHEADERNOFOOTER',
'1');
42require
'../../main.inc.php';
57if (!
isModEnabled(
'accounting') || !$user->hasRight(
'accounting',
'mouvements',
'lire')) {
61$htmlname =
GETPOST(
'htmlname',
'aZ09') ?:
'account_num_aux';
62$searchkey =
GETPOST(str_replace(
'.',
'_', $htmlname),
'alpha');
65$minLength =
getDolGlobalInt(
'ACCOUNTANCY_AUXACCOUNT_USE_SEARCH_TO_SELECT', 2) - 1;
72if (strlen($searchkey) >= $minLength) {
74 $prefix =
getDolGlobalString(
'ACCOUNTANCY_AUXACCOUNT_DONOTSEARCH_ANYWHERE') ?
'' :
'%';
77 $sql =
"SELECT code_compta AS code_client, code_compta_fournisseur AS code_fourn, nom AS name";
78 $sql .=
" FROM ".$db->prefix().
"societe";
79 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
80 $sql .=
" AND (client IN (1,3) OR fournisseur = 1)";
81 $sql .=
" AND (code_compta LIKE '".$db->escape($prefix.$searchkey).
"%'";
82 $sql .=
" OR code_compta_fournisseur LIKE '".$db->escape($prefix.$searchkey).
"%'";
83 $sql .=
" OR nom LIKE '".$db->escape($prefix.$searchkey).
"%')";
84 $sql .=
$db->order(
"nom",
"ASC");
85 $sql .=
$db->plimit($limit, 0);
87 $resql =
$db->query($sql);
89 while ($obj =
$db->fetch_object($resql)) {
90 if (!empty($obj->code_client)) {
91 $key = $obj->code_client;
92 $results[$key] = array(
94 'value' => $key.
' ('.$obj->name.
')',
95 'label' => $key.
' ('.$obj->name.
')',
96 'label_name' => $obj->name,
99 if (!empty($obj->code_fourn) && !isset($results[$obj->code_fourn])) {
100 $key = $obj->code_fourn;
101 $results[$key] = array(
103 'value' => $key.
' ('.$obj->name.
')',
104 'label' => $key.
' ('.$obj->name.
')',
105 'label_name' => $obj->name,
111 dol_syslog(
"auxaccount.php: error societe query ".
$db->lasterror(), LOG_ERR);
115 $sql2 =
"SELECT DISTINCT accountancy_code, lastname, firstname";
116 $sql2 .=
" FROM ".$db->prefix().
"user";
117 $sql2 .=
" WHERE entity IN (".getEntity(
'user').
")";
118 $sql2 .=
" AND accountancy_code != ''";
119 $sql2 .=
" AND (accountancy_code LIKE '".$db->escape($prefix.$searchkey).
"%'";
120 $sql2 .=
" OR lastname LIKE '".$db->escape($prefix.$searchkey).
"%'";
121 $sql2 .=
" OR firstname LIKE '".$db->escape($prefix.$searchkey).
"%')";
122 $sql2 .=
$db->order(
"accountancy_code",
"ASC");
123 $sql2 .=
$db->plimit($limit, 0);
125 $resql2 =
$db->query($sql2);
127 while ($obj =
$db->fetch_object($resql2)) {
128 if (!empty($obj->accountancy_code) && !isset($results[$obj->accountancy_code])) {
129 $key = $obj->accountancy_code;
131 $results[$key] = array(
133 'value' => $key.
' ('.$fullname.
')',
134 'label' => $key.
' ('.$fullname.
')',
135 'label_name' => $fullname,
141 dol_syslog(
"auxaccount.php: error user query ".
$db->lasterror(), LOG_ERR);
149echo json_encode(array_values($results));
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.