From bab2b22b3a811843a041743f0325bc9c704446ff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 20 Mar 2010 18:39:32 +0000 Subject: [PATCH] New: Can set accountancy code for product (buy and sell) --- ChangeLog | 2 + htdocs/compta/fiche.php | 63 +++--------- htdocs/html.form.class.php | 41 +++++++- htdocs/install/upgrade2.php | 4 +- htdocs/langs/en_US/products.lang | 2 + htdocs/langs/fr_FR/products.lang | 2 + htdocs/product.class.php | 77 ++++++++------ htdocs/product/fiche.php | 169 +++++++++---------------------- 8 files changed, 152 insertions(+), 208 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7bc3e729ec2..ae6da3e2653 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,8 +3,10 @@ English Dolibarr ChangeLog ***** ChangeLog for 2.9 compared to 2.8 ***** For users: +- New: Can set accountancy code for product (buy and sell). - New: Can filter third parties lists on categories. - New: Can filter products and services lists on categories. +- New: Can use categories for members. - New: Can build documents for third parties (Use ODT templates, need PHP 5.2+). - New: Support products property length and area. - New: Add "payment due before" field in invoice exports diff --git a/htdocs/compta/fiche.php b/htdocs/compta/fiche.php index 6f06a590fa9..717b1ecf1d2 100644 --- a/htdocs/compta/fiche.php +++ b/htdocs/compta/fiche.php @@ -151,31 +151,12 @@ if ($socid > 0) print ''; print ''; - // TODO Use a html->editfield function - print ''; - if ($_GET['action'] != 'editcustomeraccountancycode' && $user->rights->societe->creer) print ''; - print '
'; - print $langs->trans("CustomerAccountancyCode"); - print 'id.'">'.img_edit($langs->trans('Edit'),1).'
'; + print ''; + print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$societe->code_compta,'socid',$societe->id,$user->rights->societe->creer); print ''; - if ($_GET['action'] == 'editcustomeraccountancycode') - { - print "\n".'
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'; - print ''; - print '
'."\n"; - } - else print $societe->code_compta; + print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$societe->code_compta,'socid',$societe->id,$user->rights->societe->creer); print ''; - // End editfield print ''; - } if ($societe->fournisseur) @@ -188,29 +169,11 @@ if ($socid > 0) print ''; print ''; - // TODO Use a html->editfield function - print ''; - if ($_GET['action'] != 'editsupplieraccountancycode' && $user->rights->societe->creer) print ''; - print '
'; - print $langs->trans("SupplierAccountancyCode"); - print 'id.'">'.img_edit($langs->trans('Edit'),1).'
'; + print ''; + print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$societe->code_compta_fournisseur,'socid',$societe->id,$user->rights->societe->creer); print ''; - if ($_GET['action'] == 'editsupplieraccountancycode') - { - print "\n".'
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'; - print ''; - print '
'."\n"; - } - else print $societe->code_compta_fournisseur; + print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$societe->code_compta_fournisseur,'socid',$societe->id,$user->rights->societe->creer); print ''; - // End editfield print ''; } @@ -407,35 +370,35 @@ if ($socid > 0) if ($num > 0) { require_once(DOL_DOCUMENT_ROOT."/projet/project.class.php"); - + $projectstatic = new Project($db); - + print ''; print '
'.$langs->trans("LastProjects",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllProjects").' ('.$num.')
'; print ''; - + $var=true; $i = 0 ; while ($i < $num && $i < $MAXLIST) { $obj = $db->fetch_object($result); $projectstatic->fetch($obj->rowid); - + // To verify role of users $userAccess = $projectstatic->restrictedProjectArea($user,1); - + if ($user->rights->projet->lire && $userAccess > 0) { $var = !$var; print ""; - + // Ref print ''.img_object($langs->trans("ShowProject"),($obj->public?'projectpub':'project'))." ".$obj->ref.''; // Label print ''.$obj->title.''; // Date print ''.dol_print_date($obj->do,"day").''; - + print ''; } $i++; diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index c7d62c68278..4d1fe557f14 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -61,6 +61,46 @@ class Form return 1; } + /** + * \brief Output key field for an editable field + */ + function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm) + { + global $langs; + $ret=''; + $ret.=''; + if ($_GET['action'] != 'edit'.$htmlname && $perm) $ret.=''; + $ret.='
'; + $ret.=$langs->trans($text); + $ret.=''.img_edit($langs->trans('Edit'),1).'
'; + return $ret; + } + + /** + * \brief Output val field for an editable field + */ + function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm) + { + global $langs; + $ret=''; + if ($_GET['action'] == 'edit'.$htmlname) + { + $ret.="\n"; + $ret.='
'; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.='
'; + $ret.=''; + $ret.='
'."\n"; + $ret.='
'."\n"; + } + else $ret.=$preselected; + return $ret; + } /** * \brief Old version of textwithtooltip. Kept for backward compatibility with modules for 2.6. @@ -68,7 +108,6 @@ class Form */ function textwithhelp($text,$htmltext,$tooltipon=1) { - global $conf; return $this->textwithtooltip($text,$htmltext,$tooltipon); } diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 21220679ae8..d4df8a76d38 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -1165,7 +1165,7 @@ function migrate_price_facture($db,$langs,$conf) $facligne->total_ttc = $total_ttc; dolibarr_install_syslog("upgrade2: Line $rowid: facid=$obj->facid pu=$pu qty=$qty tva_taux=$txtva remise_percent=$remise_percent remise_global=$remise_percent_global -> $total_ht, $total_tva, $total_ttc"); - print "."; + print ". "; $facligne->update_total(); @@ -2992,7 +2992,7 @@ function migrate_shipping_delivery($db,$langs,$conf) $error++; dol_print_error($db); } - print "."; + print ". "; } else { diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 6b22516bab9..779de18cb56 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -18,6 +18,8 @@ BookList=List of books NewService=New service ProductCode=Product code ServiceCode=Service code +ProductAccountancyBuyCode=Accountancy code (buy) +ProductAccountancySellCode=Accountancy code (sell) ProductOrService=Product or Service ProductsAndServices=Products and Services ProductsOrServices=Products or Services diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 4441f6507b8..a739f6e9f9c 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -18,6 +18,8 @@ BookList=Liste livres NewService=Nouveau service ProductCode=Code produit ServiceCode=Code service +ProductAccountancyBuyCode=Code compta achat +ProductAccountancySellCode=Code compta vente ProductOrService=Produit ou Service ProductsOrServices=Produits ou Services ProductsAndServices=Produits et Services diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 9857cdba2cd..d54a68e04c9 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -95,6 +95,9 @@ class Product extends CommonObject var $volume; var $volume_units; + var $accountancy_code_buy; + var $accountancy_code_sell; + //! Codes barres var $barcode; var $barcode_type; @@ -409,27 +412,31 @@ class Product extends CommonObject if (empty($this->tva_tx)) $this->tva_tx = 0; if (empty($this->finished)) $this->finished = 0; if (empty($this->hidden)) $this->hidden = 0; + $this->accountancy_code_buy = trim($this->accountancy_code_buy); + $this->accountancy_code_sell= trim($this->accountancy_code_sell); - $sql = "UPDATE ".MAIN_DB_PREFIX."product "; - $sql .= " SET label = '" . addslashes($this->libelle) ."'"; - $sql .= ",ref = '" . $this->ref ."'"; - $sql .= ",tva_tx = " . $this->tva_tx; - $sql .= ",envente = " . $this->status; - $sql .= ",finished = " . ($this->finished<0 ? "null" : $this->finished); - $sql .= ",hidden = " . ($this->hidden<0 ? "null" : $this->hidden); - $sql .= ",weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null'); - $sql .= ",weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null'); - $sql .= ",length = " . ($this->length!='' ? "'".$this->length."'" : 'null'); - $sql .= ",length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null'); - $sql .= ",surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null'); - $sql .= ",surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null'); - $sql .= ",volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null'); - $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 .= ",duration = '" . $this->duration_value . $this->duration_unit ."'"; - $sql .= " WHERE rowid = " . $id; + $sql = "UPDATE ".MAIN_DB_PREFIX."product"; + $sql.= " SET label = '" . addslashes($this->libelle) ."'"; + $sql.= ",ref = '" . $this->ref ."'"; + $sql.= ",tva_tx = " . $this->tva_tx; + $sql.= ",envente = " . $this->status; + $sql.= ",finished = " . ($this->finished<0 ? "null" : $this->finished); + $sql.= ",hidden = " . ($this->hidden<0 ? "null" : $this->hidden); + $sql.= ",weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null'); + $sql.= ",weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null'); + $sql.= ",length = " . ($this->length!='' ? "'".$this->length."'" : 'null'); + $sql.= ",length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null'); + $sql.= ",surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null'); + $sql.= ",surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null'); + $sql.= ",volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null'); + $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.= ",duration = '" . $this->duration_value . $this->duration_unit ."'"; + $sql.= ",accountancy_code_buy = '" . $this->accountancy_code_buy."'"; + $sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'"; + $sql.= " WHERE rowid = " . $id; dol_syslog("Product::update sql=".$sql); $resql=$this->db->query($sql); @@ -920,7 +927,7 @@ class Product extends CommonObject $sql.= " price_min, price_min_ttc, price_base_type, tva_tx, envente,"; $sql.= " 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,"; - $sql.= " stock, pmp,"; + $sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,"; $sql.= " import_key"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; if ($id) $sql.= " WHERE rowid = '".$id."'"; @@ -963,6 +970,9 @@ class Product extends CommonObject $this->barcode = $result["barcode"]; $this->barcode_type = $result["fk_barcode_type"]; + $this->accountancy_code_buy = $result["accountancy_code_buy"]; + $this->accountancy_code_sell= $result["accountancy_code_sell"]; + $this->stock_reel = $result["stock"]; $this->pmp = $result["pmp"]; @@ -2434,14 +2444,17 @@ class Product extends CommonObject /** - * \brief Affiche toutes les photos du produit (nbmax maximum) - * \param sdir Directory to scan - * \param size 0=taille origine, 1 taille vignette - * \param nbmax Nombre maximum de photos (0=pas de max) - * \param nbbyrow Nombre vignettes par ligne (si mode vignette) - * \return int Nombre de photos affichees + * \brief Show photos of a product (nbmax maximum) + * \param sdir Directory to scan + * \param size 0=original size, 1 use thumbnail if possible + * \param nbmax Nombre maximum de photos (0=pas de max) + * \param nbbyrow Nombre vignettes par ligne (si mode vignette) + * \param showfilename 1=Show filename + * \param showaction 1=Show icon with action links (resize, delete) + * \param maxheight Max height of image when size=1 + * \return int Number of photos shown */ - function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showaction=0) + function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showaction=0,$maxheight=120) { global $conf,$user,$langs; @@ -2490,17 +2503,17 @@ class Product extends CommonObject print "\n"; print ''; - // Show image (width height=120) + // Show image (width height=$maxheight) // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine $alt=$langs->transnoentitiesnoconv('File').': '.$pdir.$photo; $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; - if ($photo_vignette && $imgarray['height'] > 120) { + if ($photo_vignette && $imgarray['height'] > $maxheight) { print ''; - print ''; + print ''; } else { print ''; - print ''; + print ''; } print ''; diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 187aed1ba6f..46317f65b01 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -56,6 +56,36 @@ $mesg = ''; * Actions */ +if ($_POST['action'] == 'setproductaccountancycodebuy') +{ + $product = new Product($db); + $result=$product->fetch($_POST['id']); + $product->accountancy_code_buy=$_POST["productaccountancycodebuy"]; + $result=$product->update($product->id,$user,1,0,1); + if ($result < 0) + { + $mesg=join(',',$product->errors); + } + $POST["action"]=""; + $id=$_POST["id"]; + $_GET["id"]=$_POST["id"]; +} + +if ($_POST['action'] == 'setproductaccountancycodesell') +{ + $product = new Product($db); + $result=$product->fetch($_POST['id']); + $product->accountancy_code_sell=$_POST["productaccountancycodesell"]; + $result=$product->update($product->id,$user,1,0,1); + if ($result < 0) + { + $mesg=join(',',$product->errors); + } + $POST["action"]=""; + $id=$_POST["id"]; + $_GET["id"]=$_POST["id"]; +} + if ($_GET["action"] == 'fastappro') { $product = new Product($db); @@ -886,142 +916,35 @@ if ($_GET["id"] || $_GET["ref"]) print ''; // Ref - print ''; - $nblignes=3; - if (! empty($conf->global->PRODUIT_MULTIPRICES_LIMIT) && empty($socid)) $nblignes+=$conf->global->PRODUIT_MULTIPRICES_LIMIT; - else $nblignes+=3; + print ''; + // Label + print ''; + + $nblignes=4; if ($product->is_photo_available($conf->produit->dir_output)) { // Photo print ''; } + print ''; - // Label - print ''; + // Accountancy buy code + print ''; - // MultiPrix - if($conf->global->PRODUIT_MULTIPRICES) - { - if ($socid) - { - $soc = new Societe($db); - $soc->id = $socid; - $soc->fetch($socid); - - print ''; - - if ($product->multiprices_base_type["$soc->price_level"] == 'TTC') - { - print ''; - - // Prix mini - print ''; - - // TVA - print ''; - } - else - { - for ($i=1; $i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) - { - print ''; - - if ($product->multiprices_base_type["$i"] == 'TTC') - { - print ''; - - // Prix mini - print ''; - - // TVA - print ''; - } - } - } - else - { - // Prix - print ''; - - // Prix mini - print ''; - - // TVA - print ''; - } + // Accountancy sell code + print ''; // Statut print '
'.$langs->trans("Ref").''; + print ''.$langs->trans("Ref").''; print $html->showrefnav($product,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$product->libelle.''; - $nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0); + $nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0,0,0,80); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$html->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$product->accountancy_code_sell,'id',$product->id,$user->rights->produit->creer).''; + print $html->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$product->accountancy_code_sell,'id',$product->id,$user->rights->produit->creer); + print '
'.$langs->trans("SellingPrice").''.price($product->multiprices_ttc["$soc->price_level"]); - } - else - { - print ''.price($product->multiprices["$soc->price_level"]); - } - - if ($product->multiprices_base_type["$soc->price_level"]) - { - print ' '.$langs->trans($product->multiprices_base_type["$soc->price_level"]); - } - else - { - print ' '.$langs->trans($product->price_base_type); - } - print '
'.$langs->trans("MinPrice").''; - if ($product->multiprices_base_type["$soc->price_level"] == 'TTC') - { - print price($product->multiprices_min_ttc["$soc->price_level"]).' '.$langs->trans($product->multiprices_base_type["$soc->price_level"]); - } - else - { - print price($product->multiprices_min["$soc->price_level"]).' '.$langs->trans($product->multiprices_base_type["$soc->price_level"]); - } - print '
'.$langs->trans("VATRate").''.vatrate($product->multiprices_tva_tx["$soc->price_level"],true).'
'.$langs->trans("SellingPrice").' '.$i.''.price($product->multiprices_ttc["$i"]); - } - else - { - print ''.price($product->multiprices["$i"]); - } - - if ($product->multiprices_base_type["$i"]) - { - print ' '.$langs->trans($product->multiprices_base_type["$i"]); - } - else - { - print ' '.$langs->trans($product->price_base_type); - } - print '
'.$langs->trans("MinPrice").' '.$i.''; - if ($product->multiprices_base_type["$i"] == 'TTC') - { - print price($product->multiprices_min_ttc["$i"]).' '.$langs->trans($product->multiprices_base_type["$i"]); - } - else - { - print price($product->multiprices_min["$i"]).' '.$langs->trans($product->multiprices_base_type["$i"]); - } - print '
'.$langs->trans("VATRate").' '.$i.''.vatrate($product->multiprices_tva_tx["$i"],true).'
'.$langs->trans("SellingPrice").''; - if ($product->price_base_type == 'TTC') - { - print price($product->price_ttc).' '.$langs->trans($product->price_base_type); - } - else - { - print price($product->price).' '.$langs->trans($product->price_base_type); - } - print '
'.$langs->trans("MinPrice").''; - if ($product->price_base_type == 'TTC') - { - print price($product->price_min_ttc).' '.$langs->trans($product->price_base_type); - } - else - { - print price($product->price_min).' '.$langs->trans($product->price_base_type); - } - print '
'.$langs->trans("VATRate").''.vatrate($product->tva_tx,true).'
'.$html->editfieldkey("ProductAccountancySellCode",'productaccountancycodebuy',$product->accountancy_code_buy,'id',$product->id,$user->rights->produit->creer).''; + print $html->editfieldval("ProductAccountancySellCode",'productaccountancycodebuy',$product->accountancy_code_buy,'id',$product->id,$user->rights->produit->creer); + print '
'.$langs->trans("Status").'';