diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index 44e5f48eaab..a56552b3fa0 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -367,17 +367,10 @@ if ($socidp > 0) print ''; print ''; print ''; - $sql = "SELECT rc.amount_ht,".$db->pdate("rc.datec")." as dc"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; - $sql .= " WHERE rc.fk_soc =". $objsoc->id; - $sql .= " AND rc.fk_user = ".$user->id." AND fk_facture IS NULL"; - $resql=$db->query($sql); - if ($resql) - { - $obj = $db->fetch_object($resql); - if ($obj->amount_ht) print $obj->amount_ht.' '.$langs->trans("Currency".$conf->monnaie); + $amount_discount=$objsoc->getcurrentDiscount(); + if ($amount_discount < 0) dolibarr_print_error($db,$societe->error); + if ($amount_discount > 0) print $amount_discount.' '.$langs->trans("Currency".$conf->monnaie); else print $langs->trans("None"); - } print ''; print ''; diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index 6e92cfdc78e..d5e3fe2946c 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -230,8 +230,8 @@ if ($_socid > 0) print_titre($langs->trans("Ristournes restant dues")); print ''; print ''; - print ''; print ''; + print ''; print ''; print ''; print ''; @@ -245,8 +245,8 @@ if ($_socid > 0) $var = !$var; print ""; print ''; - print ''; print ''; + print ''; print ''; if ($obj->user_id == $user->id) print ''; else print ''; @@ -283,8 +283,8 @@ if ($_socid > 0) print_titre($langs->trans("Ristournes appliquées")); print '
'.$langs->trans("Date").''.$langs->trans("AmountTTC").''.$langs->trans("ReasonDiscount").''.$langs->trans("Amount").''.$langs->trans("DiscountOfferedBy").' 
'.dolibarr_print_date($obj->dc).''.price($obj->amount_ht).''.$obj->description.''.price($obj->amount_ht).''.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'rowid.'">'.img_delete($langs->trans("RemoveDiscount")).' 
'; print ''; - print ''; print ''; + print ''; print ''; print ''; print ''; @@ -299,8 +299,8 @@ if ($_socid > 0) $var = !$var; print ""; print ''; - print ''; print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/compta/fiche.php b/htdocs/compta/fiche.php index 2e54768db5f..5eeebcc7e1e 100644 --- a/htdocs/compta/fiche.php +++ b/htdocs/compta/fiche.php @@ -285,17 +285,10 @@ if ($socid > 0) print '
'.$langs->trans("Date").''.$langs->trans("AmountTTC").''.$langs->trans("ReasonDiscount").''.$langs->trans("Amount").''.$langs->trans("Bill").''.$langs->trans("Author").' 
'.dolibarr_print_date($obj->dc).''.price($obj->amount_ht).''.$obj->description.''.price($obj->amount_ht).''.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.''.$obj->code.' 
'; print ''; print ''; - $sql = "SELECT rc.amount_ht,".$db->pdate("rc.datec")." as dc"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; - $sql .= " WHERE rc.fk_soc =". $societe->id; - $sql .= " AND rc.fk_user = ".$user->id." AND fk_facture IS NULL"; - $resql=$db->query($sql); - if ($resql) - { - $obj = $db->fetch_object($resql); - if ($obj->amount_ht) print $obj->amount_ht.' '.$langs->trans("Currency".$conf->monnaie); - else print $langs->trans("None"); - } + $amount_discount=$societe->getcurrentDiscount(); + if ($amount_discount < 0) dolibarr_print_error($db,$societe->error); + if ($amount_discount > 0) print $amount_discount.' '.$langs->trans("Currency".$conf->monnaie); + else print $langs->trans("None"); print ''; print ''; } diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index e93e6406b85..dfb53418e8c 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -897,8 +897,30 @@ class Societe } + /** + * \brief Renvoie montant des avoirs en cours + * \param user Filtre sur un user auteur des l'avoir + * \return int <0 si ko, montant avoir sinon + */ + function getCurrentDiscount($user='') + { + $sql = "SELECT SUM(rc.amount_ht) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; + $sql.= " WHERE rc.fk_soc =". $this->id; + if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id. + $sql.= " AND rc.fk_facture IS NULL"; + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + return $obj->amount; + } + return -1; + } + + function set_price_level($price_level, $user) - { + { if ($this->id) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe ";