Skip to content

Commit

Permalink
feat: add price label UI Dolibarr#28544
Browse files Browse the repository at this point in the history
  • Loading branch information
FHenry committed Mar 1, 2024
1 parent 4f3a6d1 commit 255af0f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 6 deletions.
20 changes: 17 additions & 3 deletions htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class Product extends CommonObject
* @var string
*/
public $price_base_type;
public $price_label;

//! Arrays for multiprices
public $multiprices = array();
Expand Down Expand Up @@ -674,6 +675,7 @@ public function create($user, $notrigger = 0)
$this->price = (float) price2num($this->price);
$this->price_min_ttc = (float) price2num($this->price_min_ttc);
$this->price_min = (float) price2num($this->price_min);
$this->price_label = trim($this->price_label);
if (empty($this->tva_tx)) {
$this->tva_tx = 0;
}
Expand Down Expand Up @@ -816,6 +818,7 @@ public function create($user, $notrigger = 0)
$sql .= ", price";
$sql .= ", price_ttc";
$sql .= ", price_base_type";
$sql .= ", price_label";
$sql .= ", tobuy";
$sql .= ", tosell";
if (!getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
Expand Down Expand Up @@ -843,6 +846,7 @@ public function create($user, $notrigger = 0)
$sql .= ", ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
$sql .= ", ".((int) $user->id);
$sql .= ", ".((int) $this->type);
$sql .= ", ".(!empty($this->price_label) ? "'".$this->db->escape($this->price_label)."'" : "null");
$sql .= ", ".price2num($price_ht, 'MT');
$sql .= ", ".price2num($price_ttc, 'MT');
$sql .= ", '".$this->db->escape($this->price_base_type)."'";
Expand Down Expand Up @@ -1954,9 +1958,9 @@ private function _log_price($user, $level = 0)
}

// Add new price
$sql = "INSERT INTO ".$this->db->prefix()."product_price(price_level,date_price, fk_product, fk_user_author, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,";
$sql = "INSERT INTO ".$this->db->prefix()."product_price(price_level,date_price, fk_product, fk_user_author, price_label, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,";
$sql .= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, price_min,price_min_ttc,price_by_qty,entity,fk_price_expression) ";
$sql .= " VALUES(".($level ? ((int) $level) : 1).", '".$this->db->idate($now)."', ".((int) $this->id).", ".((int) $user->id).", ".((float) price2num($this->price)).", ".((float) price2num($this->price_ttc)).",'".$this->db->escape($this->price_base_type)."',".((int) $this->status).", ".((float) price2num($this->tva_tx)).", ".($this->default_vat_code ? ("'".$this->db->escape($this->default_vat_code)."'") : "null").", ".((int) $this->tva_npr).",";
$sql .= " VALUES(".($level ? ((int) $level) : 1).", '".$this->db->idate($now)."', ".((int) $this->id).", ".((int) $user->id).", ".(empty($this->price_label)?"null":"'".$this->db->escape($this->price_label)."'").", ".((float) price2num($this->price)).", ".((float) price2num($this->price_ttc)).",'".$this->db->escape($this->price_base_type)."',".((int) $this->status).", ".((float) price2num($this->tva_tx)).", ".($this->default_vat_code ? ("'".$this->db->escape($this->default_vat_code)."'") : "null").", ".((int) $this->tva_npr).",";
$sql .= " ".price2num($this->localtax1_tx).", ".price2num($this->localtax2_tx).", '".$this->db->escape($this->localtax1_type)."', '".$this->db->escape($this->localtax2_type)."', ".price2num($this->price_min).", ".price2num($this->price_min_ttc).", ".price2num($this->price_by_qty).", ".((int) $conf->entity).",".($this->fk_price_expression > 0 ? ((int) $this->fk_price_expression) : 'null');
$sql .= ")";

Expand Down Expand Up @@ -2301,10 +2305,11 @@ public function get_buyprice($prodfournprice, $qty, $product_id = 0, $fourn_ref
* @param int $ignore_autogen Used to avoid infinite loops
* @param array $localtaxes_array Array with localtaxes info array('0'=>type1,'1'=>rate1,'2'=>type2,'3'=>rate2) (loaded by getLocalTaxesFromRate(vatrate, 0, ...) function).
* @param string $newdefaultvatcode Default vat code
* @param string $price_label Price Label
* @param int $notrigger Disable triggers
* @return int Return integer <0 if KO, >0 if OK
*/
public function updatePrice($newprice, $newpricebase, $user, $newvat = '', $newminprice = 0, $level = 0, $newnpr = 0, $newpbq = 0, $ignore_autogen = 0, $localtaxes_array = array(), $newdefaultvatcode = '', $notrigger = 0)
public function updatePrice($newprice, $newpricebase, $user, $newvat = '', $newminprice = 0, $level = 0, $newnpr = 0, $newpbq = 0, $ignore_autogen = 0, $localtaxes_array = array(), $newdefaultvatcode = '', $price_label = '', $notrigger = 0)
{
global $conf, $langs;

Expand Down Expand Up @@ -2431,6 +2436,7 @@ public function updatePrice($newprice, $newpricebase, $user, $newvat = '', $newm
$sql .= " localtax1_type = ".($localtaxtype1 != '' ? "'".$this->db->escape($localtaxtype1)."'" : "'0'").",";
$sql .= " localtax2_type = ".($localtaxtype2 != '' ? "'".$this->db->escape($localtaxtype2)."'" : "'0'").",";
$sql .= " default_vat_code = ".($newdefaultvatcode ? "'".$this->db->escape($newdefaultvatcode)."'" : "null").",";
$sql .= " price_label = ".(!empty($price_label) ? "'".$this->db->escape($price_label)."'" : "null").",";
$sql .= " tva_tx = ".(float) price2num($newvat).",";
$sql .= " recuperableonly = '".$this->db->escape($newnpr)."'";
$sql .= " WHERE rowid = ".((int) $id);
Expand All @@ -2448,13 +2454,15 @@ public function updatePrice($newprice, $newpricebase, $user, $newvat = '', $newm
$this->multiprices_recuperableonly[$level] = $newnpr;

$this->price = $price;
$this->price_label = $price_label;
$this->price_ttc = $price_ttc;
$this->price_min = $price_min;
$this->price_min_ttc = $price_min_ttc;
$this->price_base_type = $newpricebase;
$this->default_vat_code = $newdefaultvatcode;
$this->tva_tx = $newvat;
$this->tva_npr = $newnpr;

//Local taxes
$this->localtax1_tx = $localtax1;
$this->localtax2_tx = $localtax2;
Expand Down Expand Up @@ -2572,6 +2580,7 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_
}
$sql .= " p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.sell_or_eat_by_mandatory, p.batch_mask, p.fk_unit,";
$sql .= " p.fk_price_expression, p.price_autogen, p.model_pdf,";
$sql .= " p.price_label,";
if ($separatedStock) {
$sql .= " SUM(sp.reel) as stock";
} else {
Expand Down Expand Up @@ -2615,6 +2624,7 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_
}
$sql .= " p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.sell_or_eat_by_mandatory, p.batch_mask, p.fk_unit,";
$sql .= " p.fk_price_expression, p.price_autogen, p.model_pdf";
$sql .= " ,p.price_label";
if (!$separatedStock) {
$sql .= ", p.stock";
}
Expand All @@ -2638,6 +2648,7 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_
$this->note = $obj->note_private; // deprecated

$this->type = $obj->fk_product_type;
$this->price_label = $obj->price_label;
$this->status = $obj->tosell;
$this->status_buy = $obj->tobuy;
$this->status_batch = $obj->tobatch;
Expand Down Expand Up @@ -2734,6 +2745,7 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
$sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
$sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly";
$sql .= " ,price_label";
$sql .= " FROM ".$this->db->prefix()."product_price";
$sql .= " WHERE entity IN (".getEntity('productprice').")";
$sql .= " AND price_level=".((int) $i);
Expand Down Expand Up @@ -4802,6 +4814,7 @@ public function clone_price($fromId, $toId)
$sql .= ", price_min";
$sql .= ", price_min_ttc";
$sql .= ", price_base_type";
$sql .= ", price_label";
$sql .= ", default_vat_code";
$sql .= ", tva_tx";
$sql .= ", recuperableonly";
Expand Down Expand Up @@ -4829,6 +4842,7 @@ public function clone_price($fromId, $toId)
$sql .= ", price_min";
$sql .= ", price_min_ttc";
$sql .= ", price_base_type";
$sql .= ", price_label";
$sql .= ", default_vat_code";
$sql .= ", tva_tx";
$sql .= ", recuperableonly";
Expand Down
23 changes: 23 additions & 0 deletions htdocs/product/class/productcustomerprice.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ProductCustomerPrice extends CommonObject
'price_ttc' => array('type' => 'decimal(20,6)', 'label' => 'TTC', 'enabled' => 1, 'visible' => 1, 'position' => 8, 'notnull' => -1, 'comment' => 'Price TTC'),
'price_min' => array('type' => 'decimal(20,6)', 'label' => 'MinPriceHT', 'enabled' => 1, 'visible' => 1, 'position' => 9, 'notnull' => -1, 'comment' => 'Minimum Price'),
'price_min_ttc' => array('type' => 'decimal(20,6)', 'label' => 'MinPriceTTC', 'enabled' => 1, 'visible' => 1, 'position' => 10, 'notnull' => -1, 'comment' => 'Minimum Price TTC'),
'price_label' => array('type' => 'varchar(255)', 'label' => 'PriceLabel', 'enabled' => 1, 'visible' => 1, 'position' => 20, 'notnull' => -1, 'comment' => 'Price Label'),
'fk_user' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>1, 'position'=>510, 'notnull'=>1, 'foreignkey'=>'user.rowid', 'csslist'=>'tdoverflowmax100'),
);

Expand Down Expand Up @@ -89,6 +90,7 @@ class ProductCustomerPrice extends CommonObject
public $localtax1_tx;
public $localtax2_type;
public $localtax2_tx;
public $price_label;

/**
* @var int User ID
Expand Down Expand Up @@ -168,6 +170,9 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
if (isset($this->fk_user)) {
$this->fk_user = (int) $this->fk_user;
}
if (isset($this->price_label)) {
$this->price_label = trim($this->price_label);
}
if (isset($this->import_key)) {
$this->import_key = trim($this->import_key);
}
Expand Down Expand Up @@ -226,6 +231,7 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
$sql .= "localtax2_type,";
$sql .= "localtax2_tx,";
$sql .= "fk_user,";
$sql .= "price_label,";
$sql .= "import_key";
$sql .= ") VALUES (";
$sql .= " ".((int) $conf->entity).",";
Expand All @@ -246,6 +252,7 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
$sql .= " ".(empty($this->localtax2_type) ? "'0'" : "'".$this->db->escape($this->localtax2_type)."'").",";
$sql .= " ".(!isset($this->localtax2_tx) ? 'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)).",";
$sql .= " ".((int) $user->id).",";
$sql .= " ".(!isset($this->price_label) ? 'NULL' : "'".$this->db->escape($this->price_label)."'").",";
$sql .= " ".(!isset($this->import_key) ? 'NULL' : "'".$this->db->escape($this->import_key)."'");
$sql .= ")";

Expand Down Expand Up @@ -319,6 +326,7 @@ public function fetch($id)
$sql .= " t.localtax1_tx,";
$sql .= " t.localtax2_tx,";
$sql .= " t.fk_user,";
$sql .= " t.price_label,";
$sql .= " t.import_key";
$sql .= " FROM ".$this->db->prefix()."product_customer_price as t";
$sql .= " WHERE t.rowid = ".((int) $id);
Expand Down Expand Up @@ -348,6 +356,7 @@ public function fetch($id)
$this->localtax1_tx = $obj->localtax1_tx;
$this->localtax2_tx = $obj->localtax2_tx;
$this->fk_user = $obj->fk_user;
$this->price_label = $obj->price_label;
$this->import_key = $obj->import_key;

$this->db->free($resql);
Expand Down Expand Up @@ -405,6 +414,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset =
$sql .= " t.localtax1_type,";
$sql .= " t.localtax2_type,";
$sql .= " t.fk_user,";
$sql .= " t.price_label,";
$sql .= " t.import_key,";
$sql .= " soc.nom as socname,";
$sql .= " prod.ref as prodref";
Expand Down Expand Up @@ -467,6 +477,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset =
$line->localtax1_type = $obj->localtax1_type;
$line->localtax2_type = $obj->localtax2_type;
$line->fk_user = $obj->fk_user;
$line->price_label = $obj->price_label;
$line->import_key = $obj->import_key;
$line->socname = $obj->socname;
$line->prodref = $obj->prodref;
Expand Down Expand Up @@ -519,6 +530,7 @@ public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = a
$sql .= " t.localtax1_tx,";
$sql .= " t.localtax2_tx,";
$sql .= " t.fk_user,";
$sql .= " t.price_label,";
$sql .= " t.import_key,";
$sql .= " soc.nom as socname,";
$sql .= " prod.ref as prodref";
Expand Down Expand Up @@ -574,6 +586,7 @@ public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = a
$line->localtax1_tx = $obj->localtax1_tx;
$line->localtax2_tx = $obj->localtax2_tx;
$line->fk_user = $obj->fk_user;
$line->price_label = $obj->price_label;
$line->import_key = $obj->import_key;
$line->socname = $obj->socname;
$line->prodref = $obj->prodref;
Expand Down Expand Up @@ -646,6 +659,9 @@ public function update(User $user, $notrigger = 0, $forceupdateaffiliate = 0)
if (isset($this->fk_user)) {
$this->fk_user = (int) $this->fk_user;
}
if (isset($this->price_label)) {
$this->price_label = trim($this->price_label);
}
if (isset($this->import_key)) {
$this->import_key = trim($this->import_key);
}
Expand Down Expand Up @@ -706,6 +722,7 @@ public function update(User $user, $notrigger = 0, $forceupdateaffiliate = 0)
$sql .= "localtax1_type,";
$sql .= "localtax2_type,";
$sql .= "fk_user,";
$sql .= "price_label,";
$sql .= "import_key";

$sql .= ") ";
Expand All @@ -729,6 +746,7 @@ public function update(User $user, $notrigger = 0, $forceupdateaffiliate = 0)
$sql .= " t.localtax1_type,";
$sql .= " t.localtax2_type,";
$sql .= " t.fk_user,";
$sql .= " t.price_label,";
$sql .= " t.import_key";

$sql .= " FROM ".$this->db->prefix()."product_customer_price as t";
Expand Down Expand Up @@ -764,6 +782,7 @@ public function update(User $user, $notrigger = 0, $forceupdateaffiliate = 0)
$sql .= " localtax1_type=".(!empty($this->localtax1_type) ? "'".$this->db->escape($this->localtax1_type)."'" : "'0'").",";
$sql .= " localtax2_type=".(!empty($this->localtax2_type) ? "'".$this->db->escape($this->localtax2_type)."'" : "'0'").",";
$sql .= " fk_user=".$user->id.",";
$sql .= " price_label=".(isset($this->price_label) ? "'".$this->db->escape($this->price_label)."'" : "null").",";
$sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");

$sql .= " WHERE rowid=".((int) $this->id);
Expand Down Expand Up @@ -860,6 +879,7 @@ public function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate)
$prodsocpriceupd->price_base_type = $this->price_base_type;
$prodsocpriceupd->tva_tx = $this->tva_tx;
$prodsocpriceupd->recuperableonly = $this->recuperableonly;
$prodsocpriceupd->price_label = $this->price_label;

$resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
if ($resultupd < 0) {
Expand All @@ -878,6 +898,7 @@ public function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate)
$prodsocpricenew->price_base_type = $this->price_base_type;
$prodsocpricenew->tva_tx = $this->tva_tx;
$prodsocpricenew->recuperableonly = $this->recuperableonly;
$prodsocpricenew->price_label = $this->price_label;

$resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
if ($resultupd < 0) {
Expand Down Expand Up @@ -1023,6 +1044,7 @@ public function initAsSpecimen()
$this->localtax1_tx = '';
$this->localtax2_tx = '';
$this->fk_user = 0;
$this->price_label = '';
$this->import_key = '';
}
}
Expand Down Expand Up @@ -1075,6 +1097,7 @@ class PriceByCustomerLine
* @var int User ID
*/
public $fk_user;
public $price_label;

public $import_key;
public $socname;
Expand Down
Loading

0 comments on commit 255af0f

Please sign in to comment.