mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
New: Add update method for web service product.
This commit is contained in:
parent
cf89a8e96a
commit
957ff08458
|
|
@ -91,6 +91,7 @@ For developers:
|
|||
- New: Add trigger CATEGORY_LINK and CATEGORY_UNLINK.
|
||||
- New: A trigger can return an array of error strings instead of one error string.
|
||||
- New: Add method to use a dictionnary as a combo box.
|
||||
- New: Add update method for web service product.
|
||||
|
||||
WARNING: Following change may create regression for some external modules, but was necessary to make
|
||||
Dolibarr better:
|
||||
|
|
|
|||
|
|
@ -453,10 +453,11 @@ class Product extends CommonObject
|
|||
$this->volume_units = trim($this->volume_units);
|
||||
if (empty($this->tva_tx)) $this->tva_tx = 0;
|
||||
if (empty($this->tva_npr)) $this->tva_npr = 0;
|
||||
//Local taxes
|
||||
if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
|
||||
if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
|
||||
|
||||
if (empty($this->status)) $this->status = 0;
|
||||
if (empty($this->status_buy)) $this->status_buy = 0;
|
||||
|
||||
if (empty($this->country_id)) $this->country_id = 0;
|
||||
|
||||
$this->accountancy_code_buy = trim($this->accountancy_code_buy);
|
||||
|
|
@ -464,33 +465,32 @@ class Product extends CommonObject
|
|||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
|
||||
$sql.= " SET label = '" . $this->db->escape($this->libelle) ."'";
|
||||
$sql.= ",ref = '" . $this->ref ."'";
|
||||
$sql.= ",tva_tx = " . $this->tva_tx;
|
||||
$sql.= ",recuperableonly = " . $this->tva_npr;
|
||||
$sql.= ", ref = '" . $this->ref ."'";
|
||||
$sql.= ", ref_ext = ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null");
|
||||
$sql.= ", tva_tx = " . $this->tva_tx;
|
||||
$sql.= ", recuperableonly = " . $this->tva_npr;
|
||||
$sql.= ", localtax1_tx = " . $this->localtax1_tx;
|
||||
$sql.= ", localtax2_tx = " . $this->localtax2_tx;
|
||||
|
||||
//Local taxes
|
||||
$sql.= ",localtax1_tx = " . $this->localtax1_tx;
|
||||
$sql.= ",localtax2_tx = " . $this->localtax2_tx;
|
||||
|
||||
$sql.= ",tosell = " . $this->status;
|
||||
$sql.= ",tobuy = " . $this->status_buy;
|
||||
$sql.= ",finished = " . ((empty($this->finished) || $this->finished < 0) ? "null" : $this->finished);
|
||||
$sql.= ",weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null');
|
||||
$sql.= ",weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null');
|
||||
$sql.= ",length = " . ($this->length!='' ? "'".$this->length."'" : 'null');
|
||||
$sql.= ",length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null');
|
||||
$sql.= ",surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null');
|
||||
$sql.= ",surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null');
|
||||
$sql.= ",volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null');
|
||||
$sql.= ",volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null');
|
||||
$sql.= ",seuil_stock_alerte = " . ((isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '') ? "'".$this->seuil_stock_alerte."'" : "null");
|
||||
$sql.= ",description = '" . $this->db->escape($this->description) ."'";
|
||||
$sql.= ",customcode = '" . $this->db->escape($this->customcode) ."'";
|
||||
$sql.= ",fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null');
|
||||
$sql.= ",note = '" . $this->db->escape($this->note) ."'";
|
||||
$sql.= ",duration = '" . $this->duration_value . $this->duration_unit ."'";
|
||||
$sql.= ",accountancy_code_buy = '" . $this->accountancy_code_buy."'";
|
||||
$sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'";
|
||||
$sql.= ", tosell = " . $this->status;
|
||||
$sql.= ", tobuy = " . $this->status_buy;
|
||||
$sql.= ", finished = " . ((empty($this->finished) || $this->finished < 0) ? "null" : $this->finished);
|
||||
$sql.= ", weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null');
|
||||
$sql.= ", weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null');
|
||||
$sql.= ", length = " . ($this->length!='' ? "'".$this->length."'" : 'null');
|
||||
$sql.= ", length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null');
|
||||
$sql.= ", surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null');
|
||||
$sql.= ", surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null');
|
||||
$sql.= ", volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null');
|
||||
$sql.= ", volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null');
|
||||
$sql.= ", seuil_stock_alerte = " . ((isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '') ? "'".$this->seuil_stock_alerte."'" : "null");
|
||||
$sql.= ", description = '" . $this->db->escape($this->description) ."'";
|
||||
$sql.= ", customcode = '" . $this->db->escape($this->customcode) ."'";
|
||||
$sql.= ", fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null');
|
||||
$sql.= ", note = '" . $this->db->escape($this->note) ."'";
|
||||
$sql.= ", duration = '" . $this->duration_value . $this->duration_unit ."'";
|
||||
$sql.= ", accountancy_code_buy = '" . $this->accountancy_code_buy."'";
|
||||
$sql.= ", accountancy_code_sell= '" . $this->accountancy_code_sell."'";
|
||||
$sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null");
|
||||
$sql.= " WHERE rowid = " . $id;
|
||||
|
||||
|
|
|
|||
|
|
@ -253,6 +253,20 @@ $server->register(
|
|||
'WS to create a product or service'
|
||||
);
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'updateProductOrService',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','product'=>'tns:product'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','id'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#updateProductOrService',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to update a product or service'
|
||||
);
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'getListOfProductsOrServices',
|
||||
|
|
@ -497,6 +511,117 @@ function createProductOrService($authentication,$product)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update an invoice
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param Product $product Product
|
||||
* @return array Array result
|
||||
*/
|
||||
function updateProductOrService($authentication,$product)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
dol_syslog("Function: updateProductOrService login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp=array();
|
||||
$errorcode='';$errorlabel='';
|
||||
$error=0;
|
||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||
// Check parameters
|
||||
if ($product['price_net'] > 0) $product['price_base_type']='HT';
|
||||
if ($product['price'] > 0) $product['price_base_type']='TTC';
|
||||
|
||||
if ($product['price_net'] > 0 && $product['price'] > 0)
|
||||
{
|
||||
$error++; $errorcode='KO'; $errorlabel="You must choose between price or price_net to provide price.";
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
|
||||
$newobject=new Product($db);
|
||||
$newobject->fetch($product['id'],$product['ref']);
|
||||
|
||||
if (isset($product['ref'])) $newobject->ref=$product['ref'];
|
||||
if (isset($product['ref_ext'])) $newobject->ref_ext=$product['ref_ext'];
|
||||
$newobject->type=$product['type'];
|
||||
$newobject->libelle=$product['label']; // TODO deprecated
|
||||
$newobject->label=$product['label'];
|
||||
$newobject->description=$product['description'];
|
||||
$newobject->note=$product['note'];
|
||||
$newobject->status=$product['status_tosell'];
|
||||
$newobject->status_buy=$product['status_tobuy'];
|
||||
$newobject->price=$product['price_net'];
|
||||
$newobject->price_ttc=$product['price'];
|
||||
$newobject->tva_tx=$product['vat_rate'];
|
||||
$newobject->price_base_type=$product['price_base_type'];
|
||||
$newobject->date_creation=$now;
|
||||
|
||||
$newobject->stock_reel=$product['stock_real'];
|
||||
$newobject->pmp=$product['pmp'];
|
||||
$newobject->seuil_stock_alert=$product['stock_alert'];
|
||||
|
||||
$newobject->country_id=$product['country_id'];
|
||||
if ($product['country_code']) $newobject->country_id=getCountry($product['country_code'],3);
|
||||
$newobject->customcode=$product['customcode'];
|
||||
|
||||
$newobject->canvas=$product['canvas'];
|
||||
/*foreach($product['lines'] as $line)
|
||||
{
|
||||
$newline=new FactureLigne($db);
|
||||
$newline->type=$line['type'];
|
||||
$newline->desc=$line['desc'];
|
||||
$newline->fk_product=$line['fk_product'];
|
||||
$newline->total_ht=$line['total_net'];
|
||||
$newline->total_vat=$line['total_vat'];
|
||||
$newline->total_ttc=$line['total'];
|
||||
$newline->vat=$line['vat_rate'];
|
||||
$newline->qty=$line['qty'];
|
||||
$newline->fk_product=$line['product_id'];
|
||||
}*/
|
||||
//var_dump($product['ref_ext']);
|
||||
//var_dump($product['lines'][0]['type']);
|
||||
|
||||
$db->begin();
|
||||
|
||||
$result=$newobject->update($newobject->id,$fuser);
|
||||
if ($result <= 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode='KO';
|
||||
$errorlabel=$newobject->error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getListOfProductsOrServices
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user