From 0d3a3dcf38e581a0f13aa4c21f936f6ef990fcc0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 2 Apr 2006 12:15:56 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Possibilit=E9=20de=20saisir=20plusieurs?= =?UTF-8?q?=20avoir.=20Ajout=20d'un=20motif=20sur=20la=20saisie=20d'un=20a?= =?UTF-8?q?voir.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/remx.php | 153 ++++++++++++++++++++++------------ htdocs/langs/fr_FR/bills.lang | 4 + htdocs/societe.class.php | 78 +++++++++++------ 3 files changed, 158 insertions(+), 77 deletions(-) diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index b0c5f51691f..6e92cfdc78e 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2006 Laurent Destailleur * * 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='
'.$soc->error.'
'; + } +} + +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='
'.$soc->error.'
'; + } +} + + +/* + * Fiche avoirs + */ + +llxHeader(); + if ($_socid > 0) { + if ($mesg) print "$mesg
"; + // 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 "$errmesg
"; - } /* * Affichage onglets @@ -149,17 +171,23 @@ if ($_socid > 0) print ''; + // 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 ''; @@ -167,10 +195,16 @@ if ($_socid > 0) print ''; print ''; - print ''; - print ''; + print "
'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'
'.$langs->trans("CustomerAbsoluteDiscountMy").''.$remise_user.' '.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("NewValue").' '.$langs->trans("Currency".$conf->monnaie).'
"; + print '
'; + + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; + print ''; print "
'.$langs->trans("NewGlobalDiscount").' '.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("ReasonDiscount").'
 
"; @@ -179,15 +213,16 @@ if ($_socid > 0) print '
'; + /* - * 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 ''; print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; $var = true; $i = 0 ; @@ -207,9 +246,11 @@ if ($_socid > 0) print ""; print ''; print ''; - print ''; - print ''; - + print ''; + print ''; + if ($obj->user_id == $user->id) print ''; + else print ''; + print ''; $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 '
'.$langs->trans("Date").''.$langs->trans("AmountTTC").' '.$langs->trans("Accordée par").'
'.$langs->trans("AmountTTC").''.$langs->trans("ReasonDiscount").''.$langs->trans("DiscountOfferedBy").' 
'.dolibarr_print_date($obj->dc).''.price($obj->amount_ht).' '.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'
'.$obj->description.''.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'rowid.'">'.img_delete($langs->trans("RemoveDiscount")).' 
'; print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; $var = true; $i = 0 ; @@ -253,9 +300,11 @@ if ($_socid > 0) print ""; print ''; print ''; + print ''; print ''; - print ''; - + print ''; + print ''; + print ''; $i++; } $db->free($resql); diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index c5df66ad1b7..cf225fbba20 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -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 diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index e1e889a1d86..e93e6406b85 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -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) {
'.$langs->trans("Date").''.$langs->trans("AmountTTC").''.$langs->trans("Bill").''.$langs->trans("Author").'
'.$langs->trans("AmountTTC").''.$langs->trans("ReasonDiscount").''.$langs->trans("Bill").''.$langs->trans("Author").' 
'.dolibarr_print_date($obj->dc).''.price($obj->amount_ht).''.$obj->description.''.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.''.$obj->code.'
'.$obj->code.'