New: Can set accountancy code for product (buy and sell)

This commit is contained in:
Laurent Destailleur 2010-03-20 18:39:32 +00:00
parent 2da9b9df22
commit bab2b22b3a
8 changed files with 152 additions and 208 deletions

View File

@ -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

View File

@ -151,31 +151,12 @@ if ($socid > 0)
print '</tr>';
print '<tr>';
// TODO Use a html->editfield function
print '<td><table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
print $langs->trans("CustomerAccountancyCode");
print '</td>';
if ($_GET['action'] != 'editcustomeraccountancycode' && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editcustomeraccountancycode&amp;socid='.$societe->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
print '</tr></table>';
print '<td>';
print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$societe->code_compta,'socid',$societe->id,$user->rights->societe->creer);
print '</td><td colspan="3">';
if ($_GET['action'] == 'editcustomeraccountancycode')
{
print "\n".'<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="action" value="setcustomeraccountancycode">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="socid" value="'.$societe->id.'">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
print '<tr><td>';
print '<input type="text" name="customeraccountancycode" value="'.$societe->code_compta.'">';
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>'."\n";
}
else print $societe->code_compta;
print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$societe->code_compta,'socid',$societe->id,$user->rights->societe->creer);
print '</td>';
// End editfield
print '</tr>';
}
if ($societe->fournisseur)
@ -188,29 +169,11 @@ if ($socid > 0)
print '</tr>';
print '<tr>';
// TODO Use a html->editfield function
print '<td><table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
print $langs->trans("SupplierAccountancyCode");
print '</td>';
if ($_GET['action'] != 'editsupplieraccountancycode' && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editsupplieraccountancycode&amp;socid='.$societe->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
print '</tr></table>';
print '<td>';
print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$societe->code_compta_fournisseur,'socid',$societe->id,$user->rights->societe->creer);
print '</td><td colspan="3">';
if ($_GET['action'] == 'editsupplieraccountancycode')
{
print "\n".'<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="action" value="setsupplieraccountancycode">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="socid" value="'.$societe->id.'">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
print '<tr><td>';
print '<input type="text" name="supplieraccountancycode" value="'.$societe->code_compta_fournisseur.'">';
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print '</tr></table></form>'."\n";
}
else print $societe->code_compta_fournisseur;
print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$societe->code_compta_fournisseur,'socid',$societe->id,$user->rights->societe->creer);
print '</td>';
// End editfield
print '</tr>';
}
@ -407,35 +370,35 @@ if ($socid > 0)
if ($num > 0)
{
require_once(DOL_DOCUMENT_ROOT."/projet/project.class.php");
$projectstatic = new Project($db);
print '<tr class="liste_titre">';
print '<td colspan="3"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastProjects",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/projet/liste.php?socid='.$objsoc->id.'">'.$langs->trans("AllProjects").' ('.$num.')</td></tr></table></td>';
print '</tr>';
$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 "<tr $bc[$var]>";
// Ref
print '<td><a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowProject"),($obj->public?'projectpub':'project'))." ".$obj->ref.'</a></td>';
// Label
print '<td>'.$obj->title.'</td>';
// Date
print '<td align="right">'.dol_print_date($obj->do,"day").'</td>';
print '</tr>';
}
$i++;

View File

@ -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.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
$ret.=$langs->trans($text);
$ret.='</td>';
if ($_GET['action'] != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramkey.'='.$paramvalue.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
$ret.='</tr></table>';
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.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
$ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
$ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$ret.='<input type="hidden" name="'.$paramkey.'" value="'.$paramvalue.'">';
$ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
$ret.='<tr><td>';
$ret.='<input type="text" name="'.$htmlname.'" value="'.$preselected.'">';
$ret.='</td>';
$ret.='<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
$ret.='</tr></table>'."\n";
$ret.='</form>'."\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);
}

View File

@ -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
{

View File

@ -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

View File

@ -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

View File

@ -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 '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'" target="_blank">';
// 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 '<!-- Show thumb -->';
print '<img class="photo" border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
print '<img class="photo" border="0" height="'.$maxheight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
}
else {
print '<!-- Show original file -->';
print '<img class="photo" border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">';
print '<img class="photo" border="0" height="'.$maxheight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">';
}
print '</a>';

View File

@ -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 '<table class="border" width="100%"><tr>';
// Ref
print '<td width="15%">'.$langs->trans("Ref").'</td><td>';
print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
print $html->showrefnav($product,'ref','',1,'ref');
print '</td>';
$nblignes=3;
if (! empty($conf->global->PRODUIT_MULTIPRICES_LIMIT) && empty($socid)) $nblignes+=$conf->global->PRODUIT_MULTIPRICES_LIMIT;
else $nblignes+=3;
print '</tr>';
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
$nblignes=4;
if ($product->is_photo_available($conf->produit->dir_output))
{
// Photo
print '<td valign="middle" align="center" width="30%" rowspan="'.$nblignes.'">';
$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 '</td>';
}
print '</tr>';
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td></tr>';
// Accountancy buy code
print '<tr><td>'.$html->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$product->accountancy_code_sell,'id',$product->id,$user->rights->produit->creer).'</td><td>';
print $html->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$product->accountancy_code_sell,'id',$product->id,$user->rights->produit->creer);
print '</td></tr>';
// MultiPrix
if($conf->global->PRODUIT_MULTIPRICES)
{
if ($socid)
{
$soc = new Societe($db);
$soc->id = $socid;
$soc->fetch($socid);
print '<tr><td>'.$langs->trans("SellingPrice").'</td>';
if ($product->multiprices_base_type["$soc->price_level"] == 'TTC')
{
print '<td>'.price($product->multiprices_ttc["$soc->price_level"]);
}
else
{
print '<td>'.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 '</td></tr>';
// Prix mini
print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
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 '</td></tr>';
// TVA
print '<tr><td>'.$langs->trans("VATRate").'</td><td>'.vatrate($product->multiprices_tva_tx["$soc->price_level"],true).'</td></tr>';
}
else
{
for ($i=1; $i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
if ($product->multiprices_base_type["$i"] == 'TTC')
{
print '<td>'.price($product->multiprices_ttc["$i"]);
}
else
{
print '<td>'.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 '</td></tr>';
// Prix mini
print '<tr><td>'.$langs->trans("MinPrice").' '.$i.'</td><td>';
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 '</td></tr>';
// TVA
print '<tr><td>'.$langs->trans("VATRate").' '.$i.'</td><td>'.vatrate($product->multiprices_tva_tx["$i"],true).'</td></tr>';
}
}
}
else
{
// Prix
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
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 '</td></tr>';
// Prix mini
print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
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 '</td></tr>';
// TVA
print '<tr><td>'.$langs->trans("VATRate").'</td><td>'.vatrate($product->tva_tx,true).'</td></tr>';
}
// Accountancy sell code
print '<tr><td>'.$html->editfieldkey("ProductAccountancySellCode",'productaccountancycodebuy',$product->accountancy_code_buy,'id',$product->id,$user->rights->produit->creer).'</td><td>';
print $html->editfieldval("ProductAccountancySellCode",'productaccountancycodebuy',$product->accountancy_code_buy,'id',$product->id,$user->rights->produit->creer);
print '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>';