From 11c94a9d3bbae21382b4b1bc9029abfaafac9020 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Sun, 12 Jul 2015 16:50:27 +0200 Subject: [PATCH] Clean code --- htdocs/langs/en_US/products.lang | 2 +- .../class/productcustomerprice.class.php | 63 ++++++++++--------- htdocs/product/price.php | 6 +- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 140cbab05d3..8e7a171ac5b 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -264,7 +264,7 @@ PriceCatalogue=Unique price per product/service PricingRule=Rules for customer prices AddCustomerPrice=Add price by customer ForceUpdateChildPriceSoc=Set same price on customer subsidiaries -PriceByCustomerLog=Price by customer log +PriceByCustomerLog=Log of previous customer prices MinimumPriceLimit=Minimum price can't be lower then %s MinimumRecommendedPrice=Minimum recommended price is : %s PriceExpressionEditor=Price expression editor diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index 62d9bb0a406..1bca4579070 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -232,9 +232,10 @@ class Productcustomerprice extends CommonObject * @param int $id object * @return int <0 if KO, >0 if OK */ - function fetch($id) { - + function fetch($id) + { global $langs; + $sql = "SELECT"; $sql .= " t.rowid,"; @@ -293,18 +294,22 @@ class Productcustomerprice extends CommonObject } /** - * Load all objects in memory from database + * Load all customer prices in memory from database * - * @param string $sortorder order - * @param string $sortfield field - * @param int $limit page - * @param int $offset offset - * @param array $filter output - * @return int <0 if KO, >0 if OK + * @param string $sortorder order + * @param string $sortfield field + * @param int $limit page + * @param int $offset offset + * @param array $filter Filter for select + * @return int <0 if KO, >0 if OK */ - function fetch_all($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = array()) { - + function fetch_all($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = array()) + { global $langs; + + if (! empty($sortfield)) $sortfield = "t.rowid"; + if (! empty($sortorder)) $sortorder = "DESC"; + $sql = "SELECT"; $sql .= " t.rowid,"; @@ -347,12 +352,8 @@ class Productcustomerprice extends CommonObject } } - if (! empty($sortfield)) { - $sql .= " ORDER BY " . $sortfield . ' ' . $sortorder; - } - if (! empty($limit)) { - $sql .= ' ' . $this->db->plimit($limit + 1, $offset); - } + $sql.= $this->db->order($sortfield, $sortorder); + if (! empty($limit)) $sql .= ' ' . $this->db->plimit($limit + 1, $offset); dol_syslog(get_class($this) . "::fetch_all", LOG_DEBUG); $resql = $this->db->query($sql); @@ -400,16 +401,20 @@ class Productcustomerprice extends CommonObject /** * Load all objects in memory from database * - * @param string $sortorder order - * @param string $sortfield field - * @param int $limit page - * @param int $offset offset - * @param array $filter output - * @return int <0 if KO, >0 if OK + * @param string $sortorder order + * @param string $sortfield field + * @param int $limit page + * @param int $offset offset + * @param array $filter Filter for sql request + * @return int <0 if KO, >0 if OK */ - function fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter = array()) { - + function fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter = array()) + { global $langs; + + if (! empty($sortfield)) $sortfield = "t.rowid"; + if (! empty($sortorder)) $sortorder = "DESC"; + $sql = "SELECT"; $sql .= " t.rowid,"; @@ -451,12 +456,8 @@ class Productcustomerprice extends CommonObject } } - if (! empty($sortfield)) { - $sql .= " ORDER BY " . $sortfield . ' ' . $sortorder; - } - if (! empty($limit)) { - $sql .= ' ' . $this->db->plimit($limit + 1, $offset); - } + $sql.= $this->db->order($sortfield, $sortorder); + if (! empty($limit)) $sql .= ' ' . $this->db->plimit($limit + 1, $offset); dol_syslog(get_class($this) . "::fetch_all_log", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 915f1988843..5ea2ff538b0 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -829,7 +829,7 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights-> } } -// Liste des evolutions du prix +// List of price changes (ordered by descending date) $sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.recuperableonly,"; $sql .= " p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,"; $sql .= " p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login"; @@ -1156,7 +1156,6 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) } elseif ($action == 'showlog_customer_price') { - $filter = array('t.fk_product' => $object->id,'t.fk_soc' => GETPOST('socid', 'int')); // Count total nb of records @@ -1199,6 +1198,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) foreach ($prodcustprice->lines as $line) { + $var = ! $var; print "<tr ".$bc[$var].">"; // Date $staticsoc = new Societe($db); @@ -1237,7 +1237,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) // Count total nb of records $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $nbtotalofrecords = $prodcustprice->fetch_all('', '', 0, 0, $filter); + $nbtotalofrecords = $prodcustprice->fetch_all($sortfield, $sortorder, 0, 0, $filter); } $result = $prodcustprice->fetch_all($sortorder, $sortfield, $conf->liste_limit, $offset, $filter); -- GitLab