From d65528aec93e9a61530a0ff076f24256599cf42a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 Nov 2010 11:22:41 +0000 Subject: [PATCH] New: Add custom code and origin country --- htdocs/langs/en_US/products.lang | 5 ++- htdocs/langs/fr_FR/products.lang | 5 ++- htdocs/lib/functions.lib.php | 16 ++++----- htdocs/product/class/product.class.php | 50 ++++++++++++++++---------- htdocs/product/fiche.php | 50 ++++++++++++++++++++++---- 5 files changed, 92 insertions(+), 34 deletions(-) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 3c9ba5910a8..49c714ce62b 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -163,4 +163,7 @@ ClonePricesProduct=Clone main informations and prices ProductIsUsed=This product is used NewRefForClone=Ref. of new product/service CustomerPrices=Customers prices -SuppliersPrices=Suppliers prices \ No newline at end of file +SuppliersPrices=Suppliers prices +CustomCode=Custom code +CountryOrigin=Origin country +HiddenIntoCombo=Hidden into select lists \ No newline at end of file diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index d0584f9a283..363334852a8 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -163,4 +163,7 @@ ClonePricesProduct=Cloner les informations générales et les prix ProductIsUsed=Ce produit est utilisé NewRefForClone=Réf. du nouveau produit/service CustomerPrices=Prix clients -SuppliersPrices=Prix fournisseurs \ No newline at end of file +SuppliersPrices=Prix fournisseurs +CustomCode=Code douane +CountryOrigin=Pays d'origine +HiddenIntoCombo=Caché dans les listes \ No newline at end of file diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index c62b76f29e6..bcf99a9e3de 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1073,7 +1073,7 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8') function img_object($alt, $object, $cssclass='') { global $conf,$langs; - + $cssclass = (!empty($cssclass)?'class="'.$cssclass.'"':''); if (preg_match('/^([^@]+)@([^@]+)$/i',$object,$regs)) @@ -3373,13 +3373,13 @@ function dol_osencode($str) /** - * \brief Return an id from a Code. Store Code-Id in a cache. - * \param db Database handler - * \param key Code to get Id - * \param tablename Table name without prefix - * \param fieldkey Field for code - * \param fieldid Field for id - * \return int Id of code + * Return an id from a Code. Store Code-Id in a cache. + * @param db Database handler + * @param key Code to get Id + * @param tablename Table name without prefix + * @param fieldkey Field for code + * @param fieldid Field for id + * @return int Id of code */ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id') { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index ce5e9bb980e..b2c5b7febb0 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -91,6 +91,11 @@ class Product extends CommonObject // Statut indique si le produit est un produit fini '1' ou une matiere premiere '0' var $finished; + var $customcode; // Custom code + var $country_id; // Country origin id + var $country_code; // Country origin code (US, FR, ...) + + // Hidden into combo boxes var $hidden; //! Unites de mesure @@ -185,9 +190,9 @@ class Product extends CommonObject } /** - * \brief Insert product into database - * \param user User making insert - * \return int id of product/service if OK or number of error < 0 + * Insert product into database + * @param user User making insert + * @return int id of product/service if OK or number of error < 0 */ function create($user) { @@ -405,10 +410,10 @@ class Product extends CommonObject /** - * \brief Mise a jour du produit en base - * \param id id du produit - * \param user utilisateur qui effectue l'insertion - * \return int 1 si ok, -1 si ref deja existante, -2 autre erreur + * Update a record into database + * @param id Id of product + * @param user Object user making update + * @return int 1 if OK, -1 if ref already exists, -2 if other error */ function update($id, $user) { @@ -417,7 +422,7 @@ class Product extends CommonObject // Verification parametres if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT'; - // Nettoyage parametres + // Clean parameters $this->ref = dol_string_nospecial(trim($this->ref)); $this->libelle = trim($this->libelle); $this->description = trim($this->description); @@ -437,6 +442,8 @@ class Product extends CommonObject if (empty($this->finished)) $this->finished = 0; if (empty($this->hidden)) $this->hidden = 0; + if (empty($this->country_id)) $this->country_id = 0; + $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell= trim($this->accountancy_code_sell); @@ -463,7 +470,9 @@ class Product extends CommonObject $sql.= ",volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null'); $sql.= ",seuil_stock_alerte = " . ((isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '') ? "'".$this->seuil_stock_alerte."'" : "null"); $sql.= ",description = '" . addslashes($this->description) ."'"; - $sql.= ",note = '" . addslashes($this->note) ."'"; + $sql.= ",customcode = '" . addslashes($this->customcode) ."'"; + $sql.= ",fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null'); + $sql.= ",note = '" . addslashes($this->note) ."'"; $sql.= ",duration = '" . $this->duration_value . $this->duration_unit ."'"; $sql.= ",accountancy_code_buy = '" . $this->accountancy_code_buy."'"; $sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'"; @@ -538,9 +547,9 @@ class Product extends CommonObject /** - * \brief Delete a product from database (if not used) - * \param id Product id - * \return int < 0 if KO, >= 0 if OK + * Delete a product from database (if not used) + * @param id Product id + * @return int < 0 if KO, >= 0 if OK */ function delete($id) { @@ -951,13 +960,15 @@ class Product extends CommonObject /** - * \brief Load a product in memory from database - * \param id Id of product/service to load - * \param ref Ref of product/service to load - * \return int <0 if KO, >0 if OK + * Load a product in memory from database + * @param id Id of product/service to load + * @param ref Ref of product/service to load + * @return int <0 if KO, >0 if OK */ function fetch($id='',$ref='') { + include_once(DOL_DOCUMENT_ROOT.'/lib/company.lib.php'); + global $langs; global $conf; @@ -971,7 +982,7 @@ class Product extends CommonObject return -1; } - $sql = "SELECT rowid, ref, label, description, note, price, price_ttc,"; + $sql = "SELECT rowid, ref, label, description, note, customcode, fk_country, price, price_ttc,"; $sql.= " price_min, price_min_ttc, price_base_type, tva_tx, recuperableonly as tva_npr, localtax1_tx, localtax2_tx, tosell,"; $sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas,"; $sql.= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished, hidden,"; @@ -992,7 +1003,10 @@ class Product extends CommonObject $this->libelle = $result["label"]; $this->description = $result["description"]; $this->note = $result["note"]; - $this->price = $result["price"]; + $this->customcode = $result["customcode"]; + $this->country_id = $result["fk_country"]; + $this->country_code = getCountry($this->country_id,2,$this->db); + $this->price = $result["price"]; $this->price_ttc = $result["price_ttc"]; $this->price_min = $result["price_min"]; $this->price_min_ttc = $result["price_min_ttc"]; diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index cbd43079d0a..e8398684d78 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -34,6 +34,7 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php"); if ($conf->facture->enabled) require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); @@ -159,6 +160,8 @@ if ($_POST["action"] == 'add' && ($user->rights->produit->creer || $user->rights $product->status_buy = $_POST["statut_buy"]; $product->description = dol_htmlcleanlastbr($_POST["desc"]); $product->note = dol_htmlcleanlastbr($_POST["note"]); + $product->customcode = $_POST["customcode"]; + $product->country_id = $_POST["country_id"]; $product->duration_value = $_POST["duration_value"]; $product->duration_unit = $_POST["duration_unit"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]?$_POST["seuil_stock_alerte"]:0; @@ -234,6 +237,8 @@ if ($_POST["action"] == 'update' && ($user->rights->produit->creer || $user->rig $product->libelle = $_POST["libelle"]; $product->description = dol_htmlcleanlastbr($_POST["desc"]); $product->note = dol_htmlcleanlastbr($_POST["note"]); + $product->customcode = $_POST["customcode"]; + $product->country_id = $_POST["country_id"]; $product->status = $_POST["statut"]; $product->status_buy = $_POST["statut_buy"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; @@ -745,7 +750,17 @@ if ($_GET["action"] == 'create' && ($user->rights->produit->creer || $user->righ print ''; } - // Hidden + // Custom code + print ''.$langs->trans("CustomCode").''; + + // Origin country + print ''.$langs->trans("CountryOrigin").''; + $html->select_pays($_POST["country_id"],'country_id'); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); + print ''; + + // Hidden + /* if (($_GET["type"] != 1 && $user->rights->produit->hidden) || ($_GET["type"] == 1 && $user->rights->service->hidden)) { @@ -759,6 +774,7 @@ if ($_GET["action"] == 'create' && ($user->rights->produit->creer || $user->righ print yn("No"); print ''; } + */ // Note (invisible sur facture, propales...) print ''.$langs->trans("NoteNotVisibleOnBill").''; @@ -867,7 +883,11 @@ if ($_GET["id"] || $_GET["ref"]) print ''; print ''; print ''; + + // Ref print ''; + + // Label print ''; // Status @@ -971,20 +991,31 @@ if ($_GET["id"] || $_GET["ref"]) print ''; } - // Hidden + // Custom code + print ''; + + // Origin country + print ''; + + // Hidden + /* if ((! $product->isservice() && $user->rights->produit->hidden) || ($product->isservice() && $user->rights->service->hidden)) { - print ''; } else { - print ''; } + */ // Note print '\n"; } + // Custom code + print ''; + // Origin country code + print ''; + // Hidden + /* if ((! $product->isservice() && $user->rights->produit->hidden) || ($product->isservice() && $user->rights->service->hidden)) { - print '\n"; } else { - print ''; } + */ // Note print '';
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("CustomCode").'
'.$langs->trans("CountryOrigin").''; + $html->select_pays($product->country_id,'country_id'); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); + print '
'.$langs->trans("Hidden").''; + print '
'.$langs->trans("HiddenIntoCombo").''; print $html->selectyesno('hidden',$product->hidden); print '
'.$langs->trans("Hidden").''; + print '
'.$langs->trans("HiddenIntoCombo").''; print yn("No"); print '
'.$langs->trans("NoteNotVisibleOnBill").''; @@ -1145,20 +1176,27 @@ if ($_GET["id"] || $_GET["ref"]) print "
'.$langs->trans("CustomCode").''.$product->customcode.'
'.$langs->trans("CountryOrigin").''.getCountry($product->country_id,0,$db).'
'.$langs->trans("Hidden").''; + print '
'.$langs->trans("HiddenIntoCombo").''; print yn($product->hidden); print "
'.$langs->trans("Hidden").''; + print '
'.$langs->trans("HiddenIntoCombo").''; print yn("No"); print '
'.$langs->trans("Note").''.nl2br($product->note).'