Ajout modification de la valeur du code barre et du type de code barre

This commit is contained in:
Regis Houssin 2007-09-29 13:20:07 +00:00
parent 77646e79e7
commit e45f4bae77
3 changed files with 132 additions and 7 deletions

View File

@ -3570,6 +3570,28 @@ class Form
dolibarr_print_error($this->db);
}
}
/**
* \brief Affiche formulaire de selection du type de code barre
* \param page Page
* \param selected Id condition présélectionnée
* \param htmlname Nom du formulaire select
*/
function form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
{
global $langs,$conf;
if ($htmlname != "none")
{
print '<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="setbarcodetype">';
print '<table class="noborder" cellpadding="0" cellspacing="0">';
print '<tr><td>';
$this->select_barcode_type($selected, $htmlname, 1);
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</td></tr></table></form>';
}
}
}

View File

@ -2493,6 +2493,52 @@ class Product
return -1;
}
}
/**
* \brief Mise à jour du code barre
* \param user Utilisateur qui fait la modification
*/
function update_barcode($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
$sql .= " SET barcode = '".$this->barcode."'";
$sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Product::update_barcode sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/**
* \brief Mise à jour du type de code barre
* \param user Utilisateur qui fait la modification
*/
function update_barcode_type($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
$sql .= " SET fk_barcode_type = '".$this->barcode_type."'";
$sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Product::update_barcode_type sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/**
\brief Affecte les valeurs smarty

View File

@ -41,9 +41,38 @@ if (!$user->rights->barcode->lire)
accessforbidden();
/*
* Affiche historique prix
* Actions
*/
// Modification du type de code barre
if ($_POST['action'] == 'setbarcodetype' && $user->rights->barcode->creer)
{
$product = new Product($db);
$product->fetch($_GET["id"]);
$product->barcode_type = $_POST['barcodetype_id'];
$result = $product->update_barcode_type($user);
Header("Location: barcode.php?id=".$_GET["id"]);
exit;
}
// Modification du code barre
if ($_POST['action'] == 'setbarcode' && $user->rights->barcode->creer)
{
$product = new Product($db);
$product->fetch($_GET["id"]);
$product->barcode = $_POST['barcode']; //Todo: ajout vérification de la validité du code barre en fonction du type
$result = $product->update_barcode($user);
Header("Location: barcode.php?id=".$_GET["id"]);
exit;
}
/* *****************************************/
/* */
/* Mode vue et edition */
/* */
/* *************************************** */
llxHeader("","",$langs->trans("BarCode"));
$html = new Form($db);
@ -92,18 +121,46 @@ print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
print $product->getLibStatut(2);
print '</td></tr>';
// Barcode type
print '<tr><td>'.$langs->trans("BarcodeType").'</td><td colspan="2">';
print $product->barcode_type_label;
// Barcode type
print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("BarcodeType");
print '<td>';
if (($_GET['action'] != 'editbarcodetype') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&amp;id='.$product->id.'">'.img_edit($langs->trans('SetBarcodeType'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editbarcodetype')
{
$html->form_barcode_type($_SERVER['PHP_SELF'].'?id='.$product->id,$product->barcode_type,'barcodetype_id');
}
else
{
print $product->barcode_type_label;
}
print '</td></tr>';
// Barcode
print '<tr><td>'.$langs->trans("Barcode").'</td><td colspan="2">';
print $product->barcode;
print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("Barcode");
print '<td>';
if (($_GET['action'] != 'editbarcode') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&amp;id='.$product->id.'">'.img_edit($langs->trans('SetBarcode'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editbarcode')
{
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'">';
print '<input type="hidden" name="action" value="setbarcode">';
print '<input size="40" type="text" name="barcode" value="'.$product->barcode.'">';
print '&nbsp;<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
}
else
{
print $product->barcode;
}
print '</td></tr>';
print "</table>\n";
print "</div>\n";