New: Ajout d'un champ note/motif sur la modif de la remise commerciale permanente de socit

This commit is contained in:
Laurent Destailleur 2006-05-21 00:33:21 +00:00
parent f7f1c89792
commit 050a267351
2 changed files with 79 additions and 32 deletions

View File

@ -44,10 +44,17 @@ if ($_POST["action"] == 'setremise')
{
$soc = New Societe($db);
$soc->fetch($_GET["id"]);
$soc->set_remise_client($_POST["remise"],$user);
Header("Location: remise.php?id=".$_GET["id"]);
exit;
$result=$soc->set_remise_client($_POST["remise"],$_POST["note"],$user);
if ($result > 0)
{
Header("Location: remise.php?id=".$_GET["id"]);
exit;
}
else
{
$errmesg=$soc->error;
}
}
@ -99,12 +106,19 @@ if ($_socid > 0)
print '<tr><td valign="top">';
print '<table class="border" width="100%">';
// Remise
print '<tr><td colspan="2" width="25%">';
print $langs->trans("CustomerRelativeDiscount").'</td><td colspan="2">'.$objsoc->remise_client."%</td></tr>";
// Nouvelle valeur
print '<tr><td colspan="2">';
print $langs->trans("NewValue").'</td><td colspan="2"><input type="text" size="5" name="remise" value="'.$objsoc->remise_client.'">%</td></tr>';
print '<tr><td colspan="4" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td></tr>';
// Motif/Note
print '<tr><td colspan="2" width="25%">';
print $langs->trans("Note").'</td><td colspan="2"><input type="text" size="60" name="note" value=""></td></tr>';
print '<tr><td colspan="4" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
print "</table>";
print "</form>";
@ -120,7 +134,7 @@ if ($_socid > 0)
/*
* Liste de l'historique des avoirs
*/
$sql = "SELECT rc.rowid,rc.remise_client,".$db->pdate("rc.datec")." as dc,";
$sql = "SELECT rc.rowid,rc.remise_client,rc.note,".$db->pdate("rc.datec")." as dc,";
$sql.= " u.rowid as user_id, u.code";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE rc.fk_soc =". $objsoc->id;
@ -133,8 +147,9 @@ if ($_socid > 0)
print '<table class="noborder" width="100%">';
$tag = !$tag;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Date").'</td>';
print '<td>'.$langs->trans("CreditNote").'</td>';
print '<td width="160">'.$langs->trans("Date").'</td>';
print '<td width="160" align="center">'.$langs->trans("CustomerRelativeDiscountShort").'</td>';
print '<td align="left">'.$langs->trans("Note").'</td>';
print '<td align="center">'.$langs->trans("User").'</td>';
print '</tr>';
$i = 0 ;
@ -146,7 +161,8 @@ if ($_socid > 0)
$tag = !$tag;
print '<tr '.$bc[$tag].'>';
print '<td>'.dolibarr_print_date($obj->dc,"%d %B %Y %H:%M").'</td>';
print '<td>'.$obj->remise_client.' %</td>';
print '<td align="center">'.$obj->remise_client.' %</td>';
print '<td align="left">'.$obj->note.'</td>';
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'</a></td>';
print '</tr>';
$i++;

View File

@ -864,32 +864,63 @@ class Societe
}
}
/**
* \brief Définit la société comme un client
* \param remise montant de la remise
* \param user utilisateur qui place la remise
*/
function set_remise_client($remise, $user)
{
if ($this->id)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
$sql .= " SET remise_client = '".$remise."'";
$sql .= " WHERE idp = " . $this->id .";";
/**
* \brief Définit la société comme un client
* \param remise Valeur en % de la remise
* \param note Note/Motif de modification de la remise
* \param user Utilisateur qui définie la remise
* \return int <0 si ko, >0 si ok
*/
function set_remise_client($remise, $note, $user)
{
global $langs;
// Nettoyage parametres
$note=trim($note);
if (! $note)
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Note"));
return -2;
}
$this->db->query($sql);
dolibarr_syslog("Societe::set_remise_client $remise, $note, $user");
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise ";
$sql .= " ( datec, fk_soc, remise_client, fk_user_author )";
$sql .= " VALUES (now(),".$this->id.",'".$remise."',".$user->id.")";
if ($this->id)
{
$this->db->begin();
// Positionne remise courante
$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
$sql.= " SET remise_client = '".$remise."'";
$sql.= " WHERE idp = " . $this->id .";";
$resql=$this->db->query($sql);
if (! $resql)
{
$this->db->rollback();
$this->error=$this->db->error();
return -1;
}
// Ecrit trace dans historique des remises
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise ";
$sql.= " (datec, fk_soc, remise_client, note, fk_user_author)";
$sql.= " VALUES (now(), ".$this->id.", '".$remise."',";
$sql.= " '".addslashes($note)."',";
$sql.= " ".$user->id;
$sql.= ")";
if (! $this->db->query($sql) )
{
dolibarr_print_error($this->db);
}
}
}
$resql=$this->db->query($sql);
if (! $resql)
{
$this->db->rollback();
$this->error=$this->db->error();
return -1;
}
$this->db->commit();
return 1;
}
}
/**
* \brief Ajoute un avoir pour la société