Update server_thirdparty.php

For the method getListOfThirdParties, return all the extrafieldsOptions of the thirdParty Object
This commit is contained in:
fxw 2014-04-16 16:33:36 +02:00
parent df6e580dfb
commit f86d49c1ac

View File

@ -290,7 +290,7 @@ function getThirdParty($authentication,$id='',$ref='',$ref_ext='')
$result=$thirdparty->fetch($id,$ref,$ref_ext); $result=$thirdparty->fetch($id,$ref,$ref_ext);
if ($result > 0) if ($result > 0)
{ {
$thirdparty_result_fields=array( $thirdparty_result_fields=array(
'id' => $thirdparty->id, 'id' => $thirdparty->id,
'ref' => $thirdparty->name, 'ref' => $thirdparty->name,
@ -328,16 +328,16 @@ function getThirdParty($authentication,$id='',$ref='',$ref_ext='')
'vat_number' => $thirdparty->tva_intra, 'vat_number' => $thirdparty->tva_intra,
'note_private' => $thirdparty->note_private, 'note_private' => $thirdparty->note_private,
'note_public' => $thirdparty->note_public); 'note_public' => $thirdparty->note_public);
//Retreive all extrafield for thirdsparty //Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extrafields=new ExtraFields($db); $extrafields=new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('societe',true); $extralabels=$extrafields->fetch_name_optionals_label('societe',true);
//Get extrafield values //Get extrafield values
$thirdparty->fetch_optionals($thirdparty->id,$extralabels); $thirdparty->fetch_optionals($thirdparty->id,$extralabels);
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
$thirdparty_result_fields=array_merge($thirdparty_result_fields,array('options_'.$key => $thirdparty->array_options['options_'.$key])); $thirdparty_result_fields=array_merge($thirdparty_result_fields,array('options_'.$key => $thirdparty->array_options['options_'.$key]));
} }
@ -444,7 +444,7 @@ function createThirdParty($authentication,$thirdparty)
$newobject->canvas=$thirdparty['canvas']; $newobject->canvas=$thirdparty['canvas'];
$newobject->particulier=$thirdparty['individual']; $newobject->particulier=$thirdparty['individual'];
//Retreive all extrafield for thirdsparty //Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extrafields=new ExtraFields($db); $extrafields=new ExtraFields($db);
@ -520,16 +520,16 @@ function updateThirdParty($authentication,$thirdparty)
if (! $error) if (! $error)
{ {
$objectfound=false; $objectfound=false;
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$object=new Societe($db); $object=new Societe($db);
$result=$object->fetch($thirdparty['id']); $result=$object->fetch($thirdparty['id']);
if (!empty($object->id)) { if (!empty($object->id)) {
$objectfound=true; $objectfound=true;
$object->ref=$thirdparty['ref']; $object->ref=$thirdparty['ref'];
$object->name=$thirdparty['ref']; $object->name=$thirdparty['ref'];
$object->ref_ext=$thirdparty['ref_ext']; $object->ref_ext=$thirdparty['ref_ext'];
@ -546,12 +546,12 @@ function updateThirdParty($authentication,$thirdparty)
$object->address=$thirdparty['address']; $object->address=$thirdparty['address'];
$object->zip=$thirdparty['zip']; $object->zip=$thirdparty['zip'];
$object->town=$thirdparty['town']; $object->town=$thirdparty['town'];
$object->country_id=$thirdparty['country_id']; $object->country_id=$thirdparty['country_id'];
if ($thirdparty['country_code']) $object->country_id=getCountry($thirdparty['country_code'],3); if ($thirdparty['country_code']) $object->country_id=getCountry($thirdparty['country_code'],3);
$object->province_id=$thirdparty['province_id']; $object->province_id=$thirdparty['province_id'];
//if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3); //if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3);
$object->phone=$thirdparty['phone']; $object->phone=$thirdparty['phone'];
$object->fax=$thirdparty['fax']; $object->fax=$thirdparty['fax'];
$object->email=$thirdparty['email']; $object->email=$thirdparty['email'];
@ -562,15 +562,15 @@ function updateThirdParty($authentication,$thirdparty)
$object->idprof4=$thirdparty['profid4']; $object->idprof4=$thirdparty['profid4'];
$object->idprof5=$thirdparty['profid5']; $object->idprof5=$thirdparty['profid5'];
$object->idprof6=$thirdparty['profid6']; $object->idprof6=$thirdparty['profid6'];
$object->capital=$thirdparty['capital']; $object->capital=$thirdparty['capital'];
$object->barcode=$thirdparty['barcode']; $object->barcode=$thirdparty['barcode'];
$object->tva_assuj=$thirdparty['vat_used']; $object->tva_assuj=$thirdparty['vat_used'];
$object->tva_intra=$thirdparty['vat_number']; $object->tva_intra=$thirdparty['vat_number'];
$object->canvas=$thirdparty['canvas']; $object->canvas=$thirdparty['canvas'];
//Retreive all extrafield for thirdsparty //Retreive all extrafield for thirdsparty
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extrafields=new ExtraFields($db); $extrafields=new ExtraFields($db);
@ -580,9 +580,9 @@ function updateThirdParty($authentication,$thirdparty)
$key='options_'.$key; $key='options_'.$key;
$object->array_options[$key]=$thirdparty[$key]; $object->array_options[$key]=$thirdparty[$key];
} }
$db->begin(); $db->begin();
$result=$object->update($thirdparty['id'],$fuser); $result=$object->update($thirdparty['id'],$fuser);
if ($result <= 0) { if ($result <= 0) {
$error++; $error++;
@ -640,6 +640,7 @@ function getListOfThirdParties($authentication,$filterthirdparty)
// Init and check authentication // Init and check authentication
$objectresp=array(); $objectresp=array();
$arraythirdparties=array(); $arraythirdparties=array();
$errorcode='';$errorlabel=''; $errorcode='';$errorlabel='';
$error=0; $error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
@ -647,9 +648,11 @@ function getListOfThirdParties($authentication,$filterthirdparty)
if (! $error) if (! $error)
{ {
$sql ="SELECT s.rowid, s.nom as ref, s.ref_ext, s.address, s.zip, s.town, p.libelle as country, s.phone, s.fax, s.url"; $sql ="SELECT s.rowid as socRowid, s.nom as ref, s.ref_ext, s.address, s.zip, s.town, p.libelle as country, s.phone, s.fax, s.url, extra.*";
$sql.=" FROM ".MAIN_DB_PREFIX."societe as s"; $sql.=" FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON s.fk_pays = p.rowid'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON s.fk_pays = p.rowid';
$sql.=" LEFT JOIN ".MAIN_DB_PREFIX."societe_extrafields as extra ON s.rowid=fk_object";
$sql.=" WHERE entity=".$conf->entity; $sql.=" WHERE entity=".$conf->entity;
foreach($filterthirdparty as $key => $val) foreach($filterthirdparty as $key => $val)
{ {
@ -658,6 +661,11 @@ function getListOfThirdParties($authentication,$filterthirdparty)
if ($key == 'category' && $val != '') $sql.=" AND s.rowid IN (SELECT fk_societe FROM ".MAIN_DB_PREFIX."categorie_societe WHERE fk_categorie=".$db->escape($val).") "; if ($key == 'category' && $val != '') $sql.=" AND s.rowid IN (SELECT fk_societe FROM ".MAIN_DB_PREFIX."categorie_societe WHERE fk_categorie=".$db->escape($val).") ";
} }
dol_syslog("Function: getListOfThirdParties sql=".$sql); dol_syslog("Function: getListOfThirdParties sql=".$sql);
$extrafields=new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('societe',true);
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
@ -666,18 +674,25 @@ function getListOfThirdParties($authentication,$filterthirdparty)
$i=0; $i=0;
while ($i < $num) while ($i < $num)
{ {
$extrafieldsOptions=array();
$obj=$db->fetch_object($resql); $obj=$db->fetch_object($resql);
$arraythirdparties[]=array('id'=>$obj->rowid, foreach($extrafields->attribute_label as $key=>$label)
'ref'=>$obj->ref, {
'ref_ext'=>$obj->ref_ext, $extrafieldsOptions['options_'.$key] = $obj->{$key};
'adress'=>$obj->adress, }
'zip'=>$obj->zip, $arraythirdparties[]=array('id'=>$obj->socRowid,
'town'=>$obj->town, 'ref'=>$obj->ref,
'country'=>$obj->country, 'ref_ext'=>$obj->ref_ext,
'phone'=>$obj->phone, 'adress'=>$obj->adress,
'fax'=>$obj->fax, 'zip'=>$obj->zip,
'url'=>$obj->url 'town'=>$obj->town,
'country'=>$obj->country,
'phone'=>$obj->phone,
'fax'=>$obj->fax,
'url'=>$obj->url
); );
$arraythirdparties[$i] = array_merge($arraythirdparties[$i],$extrafieldsOptions);
$i++; $i++;
} }
} }