|
@@ -951,36 +951,40 @@ class Form
|
|
|
/**
|
|
|
* Output html form to select a third party
|
|
|
*
|
|
|
- * @param string $selected Preselected type
|
|
|
- * @param string $htmlname Name of field in form
|
|
|
- * @param string $filter optional filters criteras (example: 's.rowid <> x', 's.client IN (1,3)')
|
|
|
- * @param string $showempty Add an empty field (Can be '1' or text key to use on empty line like 'SelectThirdParty')
|
|
|
- * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
|
|
|
- * @param int $forcecombo Force to use combo box
|
|
|
- * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
|
|
|
- * @param int $limit Maximum number of elements
|
|
|
- * @param string $morecss Add more css styles to the SELECT component
|
|
|
- * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
|
|
|
- * @return string HTML string with select box for thirdparty.
|
|
|
+ * @param string $selected Preselected type
|
|
|
+ * @param string $htmlname Name of field in form
|
|
|
+ * @param string $filter optional filters criteras (example: 's.rowid <> x', 's.client IN (1,3)')
|
|
|
+ * @param string $showempty Add an empty field (Can be '1' or text key to use on empty line like 'SelectThirdParty')
|
|
|
+ * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
|
|
|
+ * @param int $forcecombo Force to use combo box
|
|
|
+ * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
|
|
|
+ * @param int $limit Maximum number of elements
|
|
|
+ * @param string $morecss Add more css styles to the SELECT component
|
|
|
+ * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
|
|
|
+ * @param string $selected_input_value Value of preselected input text (for use with ajax)
|
|
|
+ * @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after)
|
|
|
+ * @param array $ajaxoptions Options for ajax_autocompleter
|
|
|
+ * @return string HTML string with select box for thirdparty.
|
|
|
*/
|
|
|
- function select_company($selected='', $htmlname='socid', $filter='', $showempty='', $showtype=0, $forcecombo=0, $events=array(), $limit=0, $morecss='minwidth100', $moreparam='')
|
|
|
+ function select_company($selected='', $htmlname='socid', $filter='', $showempty='', $showtype=0, $forcecombo=0, $events=array(), $limit=0, $morecss='minwidth100', $moreparam='', $selected_input_value='', $hidelabel=1, $ajaxoptions=array())
|
|
|
{
|
|
|
+ global $conf,$user,$langs;
|
|
|
+
|
|
|
$out='';
|
|
|
|
|
|
- /* TODO Use ajax_autocompleter like for products (not finished)
|
|
|
if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo)
|
|
|
{
|
|
|
$placeholder='';
|
|
|
-
|
|
|
if ($selected && empty($selected_input_value))
|
|
|
{
|
|
|
- require_once DOL_DOCUMENT_ROOT.'/societe/ajaxcompanies.php';
|
|
|
- $societe = new Societe($this->db);
|
|
|
- $societe->fetch($selected);
|
|
|
- $selected_input_value=$societe->ref;
|
|
|
+ require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
|
|
|
+ $societetmp = new Societe($this->db);
|
|
|
+ $societetmp->fetch($selected);
|
|
|
+ $selected_input_value=$societetmp->name;
|
|
|
+ unset($societetmp);
|
|
|
}
|
|
|
- // mode=1 means customers products
|
|
|
- $urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished;
|
|
|
+ // mode 1
|
|
|
+ $urloption='htmlname='.$htmlname.'&outjson=1&filter='.$filter;
|
|
|
print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
|
|
|
if (empty($hidelabel)) print $langs->trans("RefOrLabel").' : ';
|
|
|
else if ($hidelabel > 1) {
|
|
@@ -990,15 +994,15 @@ class Form
|
|
|
print img_picto($langs->trans("Search"), 'search');
|
|
|
}
|
|
|
}
|
|
|
- print '<input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
|
|
|
+ print '<input type="text" class="minwidth100" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' '.(!empty($conf->global->THIRDPARTY_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />';
|
|
|
if ($hidelabel == 3) {
|
|
|
print img_picto($langs->trans("Search"), 'search');
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
- {*/
|
|
|
+ {
|
|
|
$out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss, $moreparam);
|
|
|
- //}
|
|
|
+ }
|
|
|
|
|
|
return $out;
|
|
|
}
|
|
@@ -1024,7 +1028,8 @@ class Form
|
|
|
{
|
|
|
global $conf,$user,$langs;
|
|
|
|
|
|
- $out=''; $num=0;
|
|
|
+ $out='';
|
|
|
+ $num=0;
|
|
|
$outarray=array();
|
|
|
|
|
|
// On recherche les societes
|
|
@@ -1040,19 +1045,18 @@ class Form
|
|
|
if ($filterkey && $filterkey != '')
|
|
|
{
|
|
|
$sql.=" AND (";
|
|
|
- if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index
|
|
|
- {
|
|
|
- $sql.="(s.name LIKE '".$this->db->escape($filterkey)."%')";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // For natural search
|
|
|
- $scrit = explode(' ', $filterkey);
|
|
|
- foreach ($scrit as $crit) {
|
|
|
- $sql.=" AND (s.name LIKE '%".$this->db->escape($crit)."%')";
|
|
|
- }
|
|
|
+ $prefix=empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if COMPANY_DONOTSEARCH_ANYWHERE is on
|
|
|
+ // For natural search
|
|
|
+ $scrit = explode(' ', $filterkey);
|
|
|
+ $i=0;
|
|
|
+ if (count($scrit) > 1) $sql.="(";
|
|
|
+ foreach ($scrit as $crit) {
|
|
|
+ if ($i > 0) $sql.=" AND ";
|
|
|
+ $sql.="(s.nom LIKE '".$this->db->escape($prefix.$crit)."%')";
|
|
|
+ $i++;
|
|
|
}
|
|
|
- if (! empty($conf->barcode->enabled))
|
|
|
+ if (count($scrit) > 1) $sql.=")";
|
|
|
+ if (! empty($conf->barcode->enabled))
|
|
|
{
|
|
|
$sql .= " OR s.barcode LIKE '".$this->db->escape($filterkey)."%'";
|
|
|
}
|
|
@@ -1061,10 +1065,13 @@ class Form
|
|
|
$sql.=$this->db->order("nom","ASC");
|
|
|
if ($limit > 0) $sql.=$this->db->plimit($limit);
|
|
|
|
|
|
+ // Build output string
|
|
|
dol_syslog(get_class($this)."::select_thirdparty_list", LOG_DEBUG);
|
|
|
$resql=$this->db->query($sql);
|
|
|
if ($resql)
|
|
|
{
|
|
|
+ $events = null;
|
|
|
+
|
|
|
if ($conf->use_javascript_ajax && ! $forcecombo)
|
|
|
{
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
|
@@ -1085,7 +1092,7 @@ class Form
|
|
|
}
|
|
|
if ($showempty) $out.= '<option value="-1">'.$textifempty.'</option>'."\n";
|
|
|
|
|
|
- $num = $this->db->num_rows($resql);
|
|
|
+ $num = $this->db->num_rows($resql);
|
|
|
$i = 0;
|
|
|
if ($num)
|
|
|
{
|
|
@@ -1128,7 +1135,7 @@ class Form
|
|
|
$out.= '<option value="'.$obj->rowid.'">'.$label.'</option>';
|
|
|
}
|
|
|
|
|
|
- array_push($outarray, array('key'=>$obj->rowid, 'value'=>$obj->rowid, 'label'=>$label));
|
|
|
+ array_push($outarray, array('key'=>$obj->rowid, 'value'=>$label, 'label'=>$label));
|
|
|
|
|
|
$i++;
|
|
|
if (($i % 10) == 0) $out.="\n";
|
|
@@ -3370,11 +3377,14 @@ class Form
|
|
|
print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
|
print '</form>';
|
|
|
} else {
|
|
|
+
|
|
|
+ $langs->load('banks');
|
|
|
+
|
|
|
if ($selected) {
|
|
|
require_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php';
|
|
|
$bankstatic=new Account($this->db);
|
|
|
$bankstatic->fetch($selected);
|
|
|
- print $this->textwithpicto($bankstatic->label,$langs->trans("AccountCurrency").' '.$bankstatic->currency_code);
|
|
|
+ print $this->textwithpicto($bankstatic->getNomUrl(1),$langs->trans("AccountCurrency").' '.$bankstatic->currency_code);
|
|
|
} else {
|
|
|
print " ";
|
|
|
}
|
|
@@ -5576,19 +5586,19 @@ class Form
|
|
|
$possiblelinks=array();
|
|
|
if (is_object($object->thirdparty) && ! empty($object->thirdparty->id) && $object->thirdparty->id > 0)
|
|
|
{
|
|
|
- $listofidcompanytoscan=$object->thirdparty->id;
|
|
|
- if (($object->thirdparty->parent > 0) && ! empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) $listofidcompanytoscan.=','.$object->thirdparty->parent;
|
|
|
-
|
|
|
- $possiblelinks=array(
|
|
|
- 'propal'=>array('enabled'=>$conf->propal->enabled, 'perms'=>1, 'label'=>'LinkToProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.')'),
|
|
|
- 'order'=>array('enabled'=>$conf->commande->enabled, 'perms'=>1, 'label'=>'LinkToOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.')'),
|
|
|
- 'invoice'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.facnumber as ref, t.ref_client, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.')'),
|
|
|
- 'contrat'=>array('enabled'=>$conf->contrat->enabled , 'perms'=>1, 'label'=>'LinkToContract', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, '' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.')'),
|
|
|
- 'fichinter'=>array('enabled'=>$conf->ficheinter->enabled, 'perms'=>1, 'label'=>'LinkToIntervention', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.')'),
|
|
|
- 'supplier_proposal'=>array('enabled'=>$conf->supplier_proposal->enabled , 'perms'=>1, 'label'=>'LinkToSupplierProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.')'),
|
|
|
- 'order_supplier'=>array('enabled'=>$conf->fournisseur->commande->enabled , 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.')'),
|
|
|
- 'invoice_supplier'=>array('enabled'=>$conf->fournisseur->facture->enabled , 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.')')
|
|
|
- );
|
|
|
+ $listofidcompanytoscan=$object->thirdparty->id;
|
|
|
+ if (($object->thirdparty->parent > 0) && ! empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) $listofidcompanytoscan.=','.$object->thirdparty->parent;
|
|
|
+
|
|
|
+ $possiblelinks=array(
|
|
|
+ 'propal'=>array('enabled'=>$conf->propal->enabled, 'perms'=>1, 'label'=>'LinkToProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('propal',1).')'),
|
|
|
+ 'order'=>array('enabled'=>$conf->commande->enabled, 'perms'=>1, 'label'=>'LinkToOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande',1).')'),
|
|
|
+ 'invoice'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.facnumber as ref, t.ref_client, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('facture',1).')'),
|
|
|
+ 'contrat'=>array('enabled'=>$conf->contrat->enabled , 'perms'=>1, 'label'=>'LinkToContract', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, '' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('contract',1).')'),
|
|
|
+ 'fichinter'=>array('enabled'=>$conf->ficheinter->enabled, 'perms'=>1, 'label'=>'LinkToIntervention', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('intervention',1).')'),
|
|
|
+ 'supplier_proposal'=>array('enabled'=>$conf->supplier_proposal->enabled , 'perms'=>1, 'label'=>'LinkToSupplierProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('supplier_proposal',1).')'),
|
|
|
+ 'order_supplier'=>array('enabled'=>$conf->fournisseur->commande->enabled , 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande_fournisseur',1).')'),
|
|
|
+ 'invoice_supplier'=>array('enabled'=>$conf->fournisseur->facture->enabled , 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('facture_fourn',1).')')
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
global $action;
|