FIX Only modified values must be modified

This commit is contained in:
Laurent Destailleur 2017-10-06 15:01:31 +02:00
parent 1becbb8805
commit ed467aa74b
2 changed files with 108 additions and 88 deletions

View File

@ -239,21 +239,25 @@ class Proposals extends DolibarrApi
* *
* @return int * @return int
*/ */
function postLine($id, $request_data = NULL) { function postLine($id, $request_data = NULL)
if(! DolibarrApiAccess::$user->rights->propal->creer) { {
if(! DolibarrApiAccess::$user->rights->propal->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->propal->fetch($id); $result = $this->propal->fetch($id);
if( ! $result ) { if (! $result) {
throw new RestException(404, 'Commercial Proposal not found'); throw new RestException(404, 'Commercial Proposal not found');
} }
if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) { if (! DolibarrApi::_checkAccessToResource('propal',$this->propal->id))
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); {
} throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
$request_data = (object) $request_data; }
$updateRes = $this->propal->addline(
$request_data = (object) $request_data;
$updateRes = $this->propal->addline(
$request_data->desc, $request_data->desc,
$request_data->subprice, $request_data->subprice,
$request_data->qty, $request_data->qty,
@ -300,43 +304,52 @@ class Proposals extends DolibarrApi
* *
* @return object * @return object
*/ */
function putLine($id, $lineid, $request_data = NULL) { function putLine($id, $lineid, $request_data = NULL)
if(! DolibarrApiAccess::$user->rights->propal->creer) { {
throw new RestException(401); if(! DolibarrApiAccess::$user->rights->propal->creer) {
} throw new RestException(401);
}
$result = $this->propal->fetch($id); $result = $this->propal->fetch($id);
if( ! $result ) { if($result <= 0) {
throw new RestException(404, 'Proposal not found'); throw new RestException(404, 'Proposal not found');
} }
if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) { if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$request_data = (object) $request_data;
$updateRes = $this->propal->updateline( $request_data = (object) $request_data;
$propalline = new PropaleLigne($this->db);
$result = $propalline->fetch($lineid);
if ($result <= 0) {
throw new RestException(404, 'Proposal line not found');
}
$updateRes = $this->propal->updateline(
$lineid, $lineid,
$request_data->subprice, isset($request_data->subprice)?$request_data->subprice:$propalline->subprice,
$request_data->qty, isset($request_data->qty)?$request_data->qty:$propalline->qty,
$request_data->remise_percent, isset($request_data->remise_percent)?$request_data->remise_percent:$propalline->remise_percent,
$request_data->tva_tx, isset($request_data->tva_tx)?$request_data->tva_tx:$propalline->tva_tx,
$request_data->localtax1_tx, isset($request_data->localtax1_tx)?$request_data->localtax1_tx:$propalline->localtax1_tx,
$request_data->localtax2_tx, isset($request_data->localtax2_tx)?$request_data->localtax2_tx:$propalline->localtax2_tx,
$request_data->desc, isset($request_data->desc)?$request_data->desc:$propalline->desc,
'HT', 'HT',
$request_data->info_bits, isset($request_data->info_bits)?$request_data->info_bits:$propalline->info_bits,
$request_data->special_code, isset($request_data->special_code)?$request_data->special_code:$propalline->special_code,
$request_data->fk_parent_line, isset($request_data->fk_parent_line)?$request_data->fk_parent_line:$propalline->fk_parent_line,
0, 0,
$request_data->fk_fournprice, isset($request_data->fk_fournprice)?$request_data->fk_fournprice:$propalline->fk_fournprice,
$request_data->pa_ht, isset($request_data->pa_ht)?$request_data->pa_ht:$propalline->pa_ht,
$request_data->label, isset($request_data->label)?$request_data->label:$propalline->label,
$request_data->product_type, isset($request_data->product_type)?$request_data->product_type:$propalline->product_type,
$request_data->date_start, isset($request_data->date_start)?$request_data->date_start:$propalline->date_start,
$request_data->date_end, isset($request_data->date_end)?$request_data->date_end:$propalline->date_end,
$request_data->array_options, isset($request_data->array_options)?$request_data->array_options:$propalline->array_options,
$request_data->fk_unit, isset($request_data->fk_unit)?$request_data->fk_unit:$propalline->fk_unit,
$request_data->multicurrency_subprice isset($request_data->multicurrency_subprice)?$request_data->multicurrency_subprice:$propalline->subprice
); );
if ($updateRes > 0) { if ($updateRes > 0) {

View File

@ -3654,59 +3654,66 @@ class PropaleLigne extends CommonObjectLine
{ {
$objp = $this->db->fetch_object($result); $objp = $this->db->fetch_object($result);
$this->id = $objp->rowid; if ($objp)
$this->rowid = $objp->rowid; // deprecated {
$this->fk_propal = $objp->fk_propal; $this->id = $objp->rowid;
$this->fk_parent_line = $objp->fk_parent_line; $this->rowid = $objp->rowid; // deprecated
$this->label = $objp->custom_label; $this->fk_propal = $objp->fk_propal;
$this->desc = $objp->description; $this->fk_parent_line = $objp->fk_parent_line;
$this->qty = $objp->qty; $this->label = $objp->custom_label;
$this->price = $objp->price; // deprecated $this->desc = $objp->description;
$this->subprice = $objp->subprice; $this->qty = $objp->qty;
$this->vat_src_code = $objp->vat_src_code; $this->price = $objp->price; // deprecated
$this->tva_tx = $objp->tva_tx; $this->subprice = $objp->subprice;
$this->remise = $objp->remise; // deprecated $this->vat_src_code = $objp->vat_src_code;
$this->remise_percent = $objp->remise_percent; $this->tva_tx = $objp->tva_tx;
$this->fk_remise_except = $objp->fk_remise_except; $this->remise = $objp->remise; // deprecated
$this->fk_product = $objp->fk_product; $this->remise_percent = $objp->remise_percent;
$this->info_bits = $objp->info_bits; $this->fk_remise_except = $objp->fk_remise_except;
$this->fk_product = $objp->fk_product;
$this->info_bits = $objp->info_bits;
$this->total_ht = $objp->total_ht; $this->total_ht = $objp->total_ht;
$this->total_tva = $objp->total_tva; $this->total_tva = $objp->total_tva;
$this->total_ttc = $objp->total_ttc; $this->total_ttc = $objp->total_ttc;
$this->fk_fournprice = $objp->fk_fournprice; $this->fk_fournprice = $objp->fk_fournprice;
$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht); $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
$this->pa_ht = $marginInfos[0]; $this->pa_ht = $marginInfos[0];
$this->marge_tx = $marginInfos[1]; $this->marge_tx = $marginInfos[1];
$this->marque_tx = $marginInfos[2]; $this->marque_tx = $marginInfos[2];
$this->special_code = $objp->special_code; $this->special_code = $objp->special_code;
$this->product_type = $objp->product_type; $this->product_type = $objp->product_type;
$this->rang = $objp->rang; $this->rang = $objp->rang;
$this->ref = $objp->product_ref; // deprecated $this->ref = $objp->product_ref; // deprecated
$this->product_ref = $objp->product_ref; $this->product_ref = $objp->product_ref;
$this->libelle = $objp->product_label; // deprecated $this->libelle = $objp->product_label; // deprecated
$this->product_label = $objp->product_label; $this->product_label = $objp->product_label;
$this->product_desc = $objp->product_desc; $this->product_desc = $objp->product_desc;
$this->fk_unit = $objp->fk_unit; $this->fk_unit = $objp->fk_unit;
$this->date_start = $this->db->jdate($objp->date_start); $this->date_start = $this->db->jdate($objp->date_start);
$this->date_end = $this->db->jdate($objp->date_end); $this->date_end = $this->db->jdate($objp->date_end);
// Multicurrency // Multicurrency
$this->fk_multicurrency = $objp->fk_multicurrency; $this->fk_multicurrency = $objp->fk_multicurrency;
$this->multicurrency_code = $objp->multicurrency_code; $this->multicurrency_code = $objp->multicurrency_code;
$this->multicurrency_subprice = $objp->multicurrency_subprice; $this->multicurrency_subprice = $objp->multicurrency_subprice;
$this->multicurrency_total_ht = $objp->multicurrency_total_ht; $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
$this->multicurrency_total_tva = $objp->multicurrency_total_tva; $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
$this->multicurrency_total_ttc = $objp->multicurrency_total_ttc; $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
$this->db->free($result); $this->db->free($result);
return 1; return 1;
}
else
{
return 0;
}
} }
else else
{ {