New: Possibilit de saisir plusieurs avoir. Ajout d'un motif sur la saisie d'un avoir.

This commit is contained in:
Laurent Destailleur 2006-04-02 12:15:56 +00:00
parent f1d6fdc0f0
commit 0d3a3dcf38
3 changed files with 158 additions and 77 deletions

View File

@ -1,6 +1,6 @@
<?PHP
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,51 +33,73 @@ $user->getrights('propale');
$user->getrights('commande');
$user->getrights('projet');
$langs->load("orders");
$langs->load("bills");
$langs->load("companies");
if ($_POST["action"] == 'setremise')
{
$soc = New Societe($db);
$soc->fetch($_GET["id"]);
$soc->set_remise_except($_POST["remise"],$user);
Header("Location: remx.php?id=".$_GET["id"]);
}
llxHeader();
$_socid = $_GET["id"];
// Sécurité si un client essaye d'accéder à une autre fiche que la sienne
$_socid = $_GET["id"];
if ($user->societe_id > 0)
{
$_socid = $user->societe_id;
}
/*********************************************************************************
*
* Mode fiche
*
*
*********************************************************************************/
/*
* Actions
*/
if ($_POST["action"] == 'setremise')
{
$soc = New Societe($db);
$soc->fetch($_GET["id"]);
$soc->set_remise_except($_POST["remise"],$user,$_POST["desc"]);
if ($result > 0)
{
Header("Location: remx.php?id=".$_GET["id"]);
exit;
}
else
{
$mesg='<div class="error">'.$soc->error.'</div>';
}
}
if ($_GET["action"] == 'remove')
{
$soc = New Societe($db);
$soc->fetch($_GET["id"]);
$result=$soc->del_remise_except($_GET["remid"]);
if ($result > 0)
{
Header("Location: remx.php?id=".$_GET["id"]);
exit;
}
else
{
$mesg='<div class="error">'.$soc->error.'</div>';
}
}
/*
* Fiche avoirs
*/
llxHeader();
if ($_socid > 0)
{
if ($mesg) print "$mesg<br>";
// On recupere les donnees societes par l'objet
$objsoc = new Societe($db);
$objsoc->id=$_socid;
$objsoc->fetch($_socid,$to);
$dac = strftime("%Y-%m-%d %H:%M", time());
if ($errmesg)
{
print "<b>$errmesg</b><br>";
}
/*
* Affichage onglets
@ -149,17 +171,23 @@ if ($_socid > 0)
print '<table class="border" width="100%">';
// Calcul avoirs en cours
$remise_all=$remise_user=0;
$sql = "SELECT rc.amount_ht,".$db->pdate("rc.datec")." as dc, rc.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql .= " WHERE rc.fk_soc =". $objsoc->id;
$sql .= " AND fk_facture IS NULL";
$sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql.= " WHERE rc.fk_soc =". $objsoc->id;
$sql.= " AND fk_facture IS NULL";
$sql.= " GROUP BY rc.fk_user";
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
$remise_all+=$obj->amount_ht;
if ($obj->fk_user == $user->id) $remise_user+=$obj->amount_ht;
$remise_all+=$obj->amount;
if ($obj->fk_user == $user->id) $remise_user+=$obj->amount;
}
else
{
dolibarr_print_error($db);
}
print '<tr><td width="33%">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
@ -167,10 +195,16 @@ if ($_socid > 0)
print '<tr><td width="33%">'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>';
print '<td>'.$remise_user.'&nbsp;'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
print '<tr><td>'.$langs->trans("NewValue").'</td>';
print '<td><input type="text" size="5" name="remise" value="'.$remise_user.'">&nbsp;'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
print "</table>";
print '<br>';
print '<table class="border" width="100%">';
print '<tr><td width="33%">'.$langs->trans("NewGlobalDiscount").'</td>';
print '<td><input type="text" size="5" name="remise" value="'.$_POST["remise"].'">&nbsp;'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
print '<tr><td width="33%">'.$langs->trans("ReasonDiscount").'</td>';
print '<td><input type="text" size="60" name="desc" value="'.$_POST["desc"].'"></td></tr>';
print '<tr><td align="center" colspan="2">&nbsp;<input type="submit" class="button" value="'.$langs->trans("Save").'"></td></tr>';
print '<tr><td align="center" colspan="2"><input type="submit" class="button" value="'.$langs->trans("AddGlobalDiscount").'"></td></tr>';
print "</table></form>";
@ -179,15 +213,16 @@ if ($_socid > 0)
print '<br>';
/*
* Liste
* Liste avoir restant dus
*/
$sql = "SELECT rc.amount_ht,".$db->pdate("rc.datec")." as dc, u.code, u.rowid as user_id";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql .= " , ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE rc.fk_soc =". $objsoc->id;
$sql .= " AND u.rowid = rc.fk_user AND fk_facture IS NULL";
$sql .= " ORDER BY rc.datec DESC";
$sql = "SELECT rc.rowid, rc.amount_ht,".$db->pdate("rc.datec")." as dc, rc.description,";
$sql.= " u.code, u.rowid as user_id";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE rc.fk_soc =". $objsoc->id;
$sql.= " AND u.rowid = rc.fk_user AND fk_facture IS NULL";
$sql.= " ORDER BY rc.datec DESC";
$resql=$db->query($sql);
if ($resql)
@ -195,7 +230,11 @@ if ($_socid > 0)
print_titre($langs->trans("Ristournes restant dues"));
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre"><td width="80">'.$langs->trans("Date").'</td>';
print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td><td>&nbsp;</td><td width="100">'.$langs->trans("Accordée par").'</td></tr>';
print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
print '<td>'.$langs->trans("ReasonDiscount").'</td>';
print '<td align="center" width="100">'.$langs->trans("DiscountOfferedBy").'</td>';
print '<td width="20">&nbsp;</td>';
print '</tr>';
$var = true;
$i = 0 ;
@ -207,9 +246,11 @@ if ($_socid > 0)
print "<tr $bc[$var]>";
print '<td>'.dolibarr_print_date($obj->dc).'</td>';
print '<td align="right">'.price($obj->amount_ht).'</td>';
print '<td>&nbsp;</td>';
print '<td><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'</td></tr>';
print '<td>'.$obj->description.'</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.'</td>';
if ($obj->user_id == $user->id) print '<td><a href="'.$_SERVER["PHP_SELF"].'?id='.$objsoc->id.'&amp;action=remove&amp;remid='.$obj->rowid.'">'.img_delete($langs->trans("RemoveDiscount")).'</td>';
else print '<td>&nbsp;</td>';
print '</tr>';
$i++;
}
$db->free($resql);
@ -225,8 +266,9 @@ if ($_socid > 0)
/*
* Liste ristournes appliquées
*/
$sql = "SELECT rc.amount_ht,".$db->pdate("rc.datec")." as dc, u.code, u.rowid as user_id,";
$sql.= " rc.fk_facture, f.facnumber";
$sql = "SELECT rc.rowid, rc.amount_ht,".$db->pdate("rc.datec")." as dc, rc.description, rc.fk_facture,";
$sql.= " u.code, u.rowid as user_id,";
$sql.= " f.facnumber";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
$sql.= " , ".MAIN_DB_PREFIX."user as u";
$sql.= " , ".MAIN_DB_PREFIX."facture as f";
@ -241,7 +283,12 @@ if ($_socid > 0)
print_titre($langs->trans("Ristournes appliquées"));
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="80">'.$langs->trans("Date").'</td>';
print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td><td align="center">'.$langs->trans("Bill").'</td><td width="100">'.$langs->trans("Author").'</td></tr>';
print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
print '<td>'.$langs->trans("ReasonDiscount").'</td>';
print '<td align="center">'.$langs->trans("Bill").'</td>';
print '<td align="center" width="100">'.$langs->trans("Author").'</td>';
print '<td width="20">&nbsp;</td>';
print '</tr>';
$var = true;
$i = 0 ;
@ -253,9 +300,11 @@ if ($_socid > 0)
print "<tr $bc[$var]>";
print '<td>'.dolibarr_print_date($obj->dc).'</td>';
print '<td align="right">'.price($obj->amount_ht).'</td>';
print '<td>'.$obj->description.'</td>';
print '<td align="center"><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->fk_facture.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
print '<td>'.$obj->code.'</td></tr>';
print '<td align="center">'.$obj->code.'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
$i++;
}
$db->free($resql);

View File

@ -117,3 +117,7 @@ RecurringBills=Factures r
ExportDataset_invoice_1=Factures clients et lignes de facture
ProformaBill=Facture Proforma :
VATIsUsed=Assujéti à TVA
NewGlobalDiscount=Nouvel avoir
ReasonDiscount=Motif
AddGlobalDiscount=Ajouter avoir
DiscountOfferedBy=Accordé par

View File

@ -841,35 +841,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_except($remise, $user)
{
if ($this->id)
{
$remise = price2num($remise);
/**
* \brief Ajoute un avoir pour la société
* \param remise Montant de la remise
* \param user Utilisateur qui accorde la remise
* \param desc Motif de l'avoir
* \return int <0 si ko, id de l'avoir si ok
*/
function set_remise_except($remise, $user, $desc)
{
if ($this->id)
{
$remise = price2num($remise);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except ";
$sql .= " (datec, fk_soc, amount_ht, fk_user, description)";
$sql .= " VALUES (now(),".$this->id.",'".$remise."',".$user->id.",'".addslashes($desc)."')";
if (! $this->db->query($sql) )
{
$this->error=$this->db->lasterror();
return -1;
}
else
{
return $this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except");
}
}
else return 0;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except ";
$sql .= " WHERE fk_soc = " . $this->id ." AND fk_facture IS NULL;";
/**
* \brief Supprime un avoir (à condition que non affecté à une facture)
* \param id Id de l'avoir à supprimer
* \return int <0 si ko, id de l'avoir si ok
*/
function del_remise_except($id)
{
if ($this->id)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except ";
$sql.= " WHERE rowid = ".$id." AND fk_facture IS NULL";
$this->db->query($sql);
if (! $this->db->query($sql))
{
$this->error=$this->db->lasterror();
return -1;
}
else
{
return 1;
}
}
else return 0;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except ";
$sql .= " ( datec, fk_soc, amount_ht, fk_user )";
$sql .= " VALUES (now(),".$this->id.",'".$remise."',".$user->id.")";
if (! $this->db->query($sql) )
{
dolibarr_print_error($this->db);
}
}
}
function set_price_level($price_level, $user)
function set_price_level($price_level, $user)
{
if ($this->id)
{