Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
19cba51f9e
3 changed files with 76 additions and 3 deletions
|
|
@ -325,12 +325,36 @@ class Products extends DolibarrApi
|
|||
throw new RestException(500, "Error creating product", array_merge(array($this->product->error), $this->product->errors));
|
||||
}
|
||||
|
||||
if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
|
||||
$key_max = getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT');
|
||||
for ($key = 1; $key <= $key_max ; $key++) {
|
||||
$newvat = $this->product->multiprices_tva_tx[$key];
|
||||
$newnpr = 0;
|
||||
$newvatsrccode = $this->product->default_vat_code;
|
||||
$newprice = $this->product->multiprices[$key];
|
||||
$newpricemin = $this->product->multiprices_min[$key];
|
||||
$newbasetype = $this->product->multiprices_base_type[$key];
|
||||
if (empty($newbasetype) || $newbasetype == '') {
|
||||
$newbasetype = $this->product->price_base_type;
|
||||
}
|
||||
if ($newbasetype == 'TTC') {
|
||||
$newprice = $this->product->multiprices_ttc[$key];
|
||||
$newpricemin = $this->product->multiprices_min_ttc[$key];
|
||||
}
|
||||
if ($newprice > 0) {
|
||||
$result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->product->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update product.
|
||||
* Price will be updated by this API only if option is set on "One price per product". See other APIs for other price modes.
|
||||
* Price will be updated by this API only if option is set on "One price per product" or
|
||||
* if PRODUIT_MULTIPRICES is set (1 price per segment)
|
||||
* See other APIs for other price modes.
|
||||
*
|
||||
* @param int $id Id of product to update
|
||||
* @param array $request_data Datas
|
||||
|
|
@ -434,6 +458,42 @@ class Products extends DolibarrApi
|
|||
}
|
||||
}
|
||||
|
||||
if ($result > 0 && getDolGlobalString('PRODUIT_MULTIPRICES')) {
|
||||
$key_max = getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT');
|
||||
for ($key = 1; $key <= $key_max ; $key++) {
|
||||
$pricemodified = false;
|
||||
if ($this->product->multiprices_base_type[$key] != $oldproduct->multiprices_base_type[$key]) {
|
||||
$pricemodified = true;
|
||||
} else {
|
||||
if ($this->product->multiprices_tva_tx[$key] != $oldproduct->multiprices_tva_tx[$key]) $pricemodified = true;
|
||||
if ($this->product->multiprices_base_type[$key] == 'TTC') {
|
||||
if ($this->product->multiprices_ttc[$key] != $oldproduct->multiprices_ttc[$key]) $pricemodified = true;
|
||||
if ($this->product->multiprices_min_ttc[$key] != $oldproduct->multiprices_min_ttc[$key]) $pricemodified = true;
|
||||
} else {
|
||||
if ($this->product->multiprices[$key] != $oldproduct->multiprices[$key]) $pricemodified = true;
|
||||
if ($this->product->multiprices_min[$key] != $oldproduct->multiprices[$key]) $pricemodified = true;
|
||||
}
|
||||
}
|
||||
if ($pricemodified && $result > 0) {
|
||||
$newvat = $this->product->multiprices_tva_tx[$key];
|
||||
$newnpr = 0;
|
||||
$newvatsrccode = $this->product->default_vat_code;
|
||||
$newprice = $this->product->multiprices[$key];
|
||||
$newpricemin = $this->product->multiprices_min[$key];
|
||||
$newbasetype = $this->product->multiprices_base_type[$key];
|
||||
if (empty($newbasetype) || $newbasetype == '') {
|
||||
$newbasetype = $this->product->price_base_type;
|
||||
}
|
||||
if ($newbasetype == 'TTC') {
|
||||
$newprice = $this->product->multiprices_ttc[$key];
|
||||
$newpricemin = $this->product->multiprices_min_ttc[$key];
|
||||
}
|
||||
|
||||
$result = $this->product->updatePrice($newprice, $newbasetype, DolibarrApiAccess::$user, $newvat, $newpricemin, $key, $newnpr, 0, 0, array(), $newvatsrccode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($result <= 0) {
|
||||
throw new RestException(500, "Error updating product", array_merge(array($this->product->error), $this->product->errors));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -793,6 +793,10 @@ class Product extends CommonObject
|
|||
|
||||
$now = dol_now();
|
||||
|
||||
if (empty($this->date_creation)) {
|
||||
$this->date_creation = $now;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
|
||||
|
|
@ -847,7 +851,7 @@ class Product extends CommonObject
|
|||
$sql .= ", fk_unit";
|
||||
$sql .= ", mandatory_period";
|
||||
$sql .= ") VALUES (";
|
||||
$sql .= "'".$this->db->idate($now)."'";
|
||||
$sql .= "'".$this->db->idate($this->date_creation)."'";
|
||||
$sql .= ", ".(!empty($this->entity) ? (int) $this->entity : (int) $conf->entity);
|
||||
$sql .= ", '".$this->db->escape($this->ref)."'";
|
||||
$sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null");
|
||||
|
|
@ -880,6 +884,7 @@ class Product extends CommonObject
|
|||
$sql .= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::Create", LOG_DEBUG);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$id = $this->db->last_insert_id($this->db->prefix()."product");
|
||||
|
|
|
|||
|
|
@ -954,6 +954,10 @@ class Societe extends CommonObject
|
|||
|
||||
$now = dol_now();
|
||||
|
||||
if (empty($this->date_creation)) {
|
||||
$this->date_creation = $now;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
|
||||
|
|
@ -992,7 +996,10 @@ class Societe extends CommonObject
|
|||
$sql .= ", accountancy_code_buy";
|
||||
$sql .= ", accountancy_code_sell";
|
||||
}
|
||||
$sql .= ") VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".((int) $this->entity).", '".$this->db->idate($now)."'";
|
||||
$sql .= ") VALUES ('".$this->db->escape($this->name)."',";
|
||||
$sql .= " '".$this->db->escape($this->name_alias)."',";
|
||||
$sql .= " ".((int) $this->entity).",";
|
||||
$sql .= " '".$this->db->idate($this->date_creation)."'";
|
||||
$sql .= ", ".(!empty($user->id) ? ((int) $user->id) : "null");
|
||||
$sql .= ", ".(!empty($this->typent_id) ? ((int) $this->typent_id) : "null");
|
||||
$sql .= ", ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null");
|
||||
|
|
@ -1012,6 +1019,7 @@ class Societe extends CommonObject
|
|||
$sql .= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
|
||||
|
|
|
|||
Loading…
Reference in a new issue