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,7 +239,8 @@ 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);
} }
@ -249,10 +250,13 @@ class Proposals extends DolibarrApi
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; $request_data = (object) $request_data;
$updateRes = $this->propal->addline( $updateRes = $this->propal->addline(
$request_data->desc, $request_data->desc,
$request_data->subprice, $request_data->subprice,
@ -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) { 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 <= 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; $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( $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,6 +3654,8 @@ class PropaleLigne extends CommonObjectLine
{ {
$objp = $this->db->fetch_object($result); $objp = $this->db->fetch_object($result);
if ($objp)
{
$this->id = $objp->rowid; $this->id = $objp->rowid;
$this->rowid = $objp->rowid; // deprecated $this->rowid = $objp->rowid; // deprecated
$this->fk_propal = $objp->fk_propal; $this->fk_propal = $objp->fk_propal;
@ -3709,6 +3711,11 @@ class PropaleLigne extends CommonObjectLine
return 1; return 1;
} }
else else
{
return 0;
}
}
else
{ {
return -1; return -1;
} }