diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index c64ce815ca2..5b5a5e1bc6c 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -81,7 +81,7 @@ if (isset($_GET["action"]) && $_GET["action"] == 'del_bookmark') /* - * Affichage page + * View */ $html = new Form($db); diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index b5d96f4d69b..a7c08218a92 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -896,7 +896,7 @@ if ($_GET['propalid'] > 0) // Remise dispo de type non avoir $filter='fk_facture_source IS NULL'; print '
'; - print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?propalid='.$propal->id,0,'remise_id',$societe->id,$absolute_discount,$filter); + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?propalid='.$propal->id,0,'remise_id',$societe->id,$absolute_discount,$filter); } } if ($absolute_creditnote) diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index 56bd8116c68..1d94133f35a 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -19,11 +19,11 @@ */ /** - \file htdocs/comm/remx.php - \ingroup commercial, invoice - \brief Onglet de définition des avoirs - \version $Id$ -*/ + * \file htdocs/comm/remx.php + * \ingroup commercial, invoice + * \brief Onglet de définition des avoirs + * \version $Id$ + */ require_once("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); @@ -95,7 +95,7 @@ if ($_GET["action"] == 'remove') /* - * Affichage fiche des remises fixes + * View */ $form=new Form($db); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 7461a4a5b16..d268b87d7e6 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1204,7 +1204,7 @@ else // Remise dispo de type non avoir $filter='fk_facture_source IS NULL'; print '
'; - print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount,$filter); + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount,$filter); } } if ($absolute_creditnote) diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index d778b50bcf2..d9316fa15ab 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -191,7 +191,7 @@ if ($_GET["id"] > 0) // Remise dispo de type non avoir $filter='fk_facture_source IS NULL'; print '
'; - print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount,$filter); + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount,$filter); } } if ($absolute_creditnote) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index b29f09b503a..87c32fead81 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1809,15 +1809,21 @@ else $soc = new Societe($db, $fac->socid); $soc->fetch($fac->socid); - $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); - $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); - $totalpaye = $fac->getSommePaiement(); $totalavoir = $fac->getSommeCreditNote(); - $resteapayer = $fac->total_ttc - $totalpaye - $totalavoir; + + // We cal also use bcadd to avoid pb with floating points + // For example print 239.2 - 229.3 - 9.9; does not return 0. + //$resteapayer=bcadd($fac->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); + //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); + $resteapayer = price2num($fac->total_ttc - $totalpaye - $totalavoir,'MT'); + if ($fac->paye) $resteapayer=0; $resteapayeraffiche=$resteapayer; + $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); + $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); + $author = new User($db); if ($fac->user_author) { @@ -2080,7 +2086,7 @@ else if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); print '. '; - if ($absolute_discount) + if ($absolute_discount > 0) { if ($fac->statut > 0 || $fac->type == 2) { @@ -2091,10 +2097,10 @@ else // Remise dispo de type non avoir $filter='fk_facture_source IS NULL'; print '
'; - print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id',$soc->id,$absolute_discount,$filter); + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id',$soc->id,$absolute_discount,$filter,$resteapayer); } } - if ($absolute_creditnote) + if ($absolute_creditnote > 0) { // If validated, we show link "add credit note to payment" if ($fac->statut != 1 || $fac->type == 2) @@ -2106,7 +2112,7 @@ else // Remise dispo de type avoir $filter='fk_facture_source IS NOT NULL'; if (! $absolute_discount) print '
'; - print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id_for_payment',$soc->id,$absolute_creditnote,$filter); + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id_for_payment',$soc->id,$absolute_creditnote,$filter,$resteapayer); } } if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; @@ -2143,7 +2149,7 @@ else print ''.($fac->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).''; print ''.$langs->trans('Type').''; print ''.$langs->trans('Amount').''; - print ' '; + print ' '; print ''; if ($fac->type != 2) @@ -2158,16 +2164,16 @@ else print dolibarr_print_date($objp->dp,'day').''; print ''.$objp->paiement_type.' '.$objp->num_paiement.''; print ''.price($objp->amount).''; - print ''.$langs->trans('Currency'.$conf->monnaie).''; + print ' '; print ''; $i++; } // Already payed - print ''.$langs->trans('AlreadyPayed').' :'.price($totalpaye).''.$langs->trans('Currency'.$conf->monnaie).''; + print ''.$langs->trans('AlreadyPayed').' :'.price($totalpaye).' '; // Billed - print ''.$langs->trans("Billed").' :'.price($fac->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).''; + print ''.$langs->trans("Billed").' :'.price($fac->total_ttc).' '; $resteapayeraffiche=$resteapayer; // Loop on each credit note applied @@ -2189,8 +2195,8 @@ else print $invoice->getNomUrl(0); print ' :'; print ''.price($obj->amount_ttc).''; - print ''.$langs->trans('Currency'.$conf->monnaie); - print ' rowid.'">'.img_delete().''; + print ''; + print 'rowid.'">'.img_delete().''; print ''; $i++; } @@ -2205,7 +2211,7 @@ else { print ''; print $html->textwithhelp($langs->trans("Escompte").':',$langs->trans("HelpEscompte"),-1); - print ''.price($fac->total_ttc - $totalpaye).''.$langs->trans('Currency'.$conf->monnaie).''; + print ''.price($fac->total_ttc - $totalpaye).' '; $resteapayeraffiche=0; } // Payé partiellement ou Abandon 'badcustomer' @@ -2213,7 +2219,7 @@ else { print ''; print $html->textwithhelp($langs->trans("Abandoned").':',$langs->trans("HelpAbandonBadCustomer"),-1); - print ''.price($fac->total_ttc - $totalpaye).''.$langs->trans('Currency'.$conf->monnaie).''; + print ''.price($fac->total_ttc - $totalpaye).' '; //$resteapayeraffiche=0; } // Payé partiellement ou Abandon 'product_returned' @@ -2221,7 +2227,7 @@ else { print ''; print $html->textwithhelp($langs->trans("ProductReturned").':',$langs->trans("HelpAbandonProductReturned"),-1); - print ''.price($fac->total_ttc - $totalpaye).''.$langs->trans('Currency'.$conf->monnaie).''; + print ''.price($fac->total_ttc - $totalpaye).' '; $resteapayeraffiche=0; } // Payé partiellement ou Abandon 'abandon' @@ -2231,7 +2237,7 @@ else $text=$langs->trans("HelpAbandonOther"); if ($fac->close_note) $text.='

'.$langs->trans("Reason").':'.$fac->close_note; print $html->textwithhelp($langs->trans("Abandoned").':',$text,-1); - print ''.price($fac->total_ttc - $totalpaye).''.$langs->trans('Currency'.$conf->monnaie).''; + print ''.price($fac->total_ttc - $totalpaye).' '; $resteapayeraffiche=0; } print ''; @@ -2239,13 +2245,13 @@ else else print $langs->trans('ExcessReceived'); print ' :'; print ''.price($resteapayeraffiche).''; - print ''.$langs->trans('Currency'.$conf->monnaie).''; + print ' '; } else { // Solde avoir print ''.$langs->trans('TotalTTCToYourCredit').' :'; - print ''.price(abs($fac->total_ttc)).''.$langs->trans('Currency'.$conf->monnaie).''; + print ''.price(abs($fac->total_ttc)).' '; } print ''; $db->free($result); diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 239724b3d85..c044730ce29 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -396,7 +396,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P print ''; // Reste a payer - print ''.price($objp->total_ttc - $objp->am - $creditnote).''; + print ''.price(price2num($objp->total_ttc - $objp->am - $creditnote,'MT')).''; // Montant print ''; @@ -430,7 +430,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P print ''.price($totalrecu); if ($totalrecucreditnote) print '+'.price($totalrecucreditnote); print ''; - print ''.price($total_ttc - $totalrecu - $totalrecucreditnote).''; + print ''.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote,'MT')).''; print ' '; print ' '; print "\n"; diff --git a/htdocs/discount.class.php b/htdocs/discount.class.php index f8365ae2aa6..2d2138fc49a 100644 --- a/htdocs/discount.class.php +++ b/htdocs/discount.class.php @@ -18,18 +18,17 @@ */ /** - \file htdocs/discount.class.php - \ingroup propal facture commande - \brief Fichier de la classe de gestion des remises - \version $Id$ -*/ + * \file htdocs/discount.class.php + * \ingroup propal facture commande + * \brief Fichier de la classe de gestion des remises + * \version $Id$ + */ /** - \class DiscountAbsolute - \brief Classe permettant la gestion des remises fixes -*/ - + * \class DiscountAbsolute + * \brief Classe permettant la gestion des remises fixes + */ class DiscountAbsolute { var $db; @@ -145,8 +144,8 @@ class DiscountAbsolute $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; $sql.= " fk_facture_source"; $sql.= ")"; - $sql.= " VALUES (now(),".$this->fk_soc.",".$user->id.",'".addslashes($this->desc)."',"; - $sql.= " '".$this->amount_ht."','".$this->amount_tva."','".$this->amount_ttc."','".$this->tva_tx."',"; + $sql.= " VALUES (now(), ".$this->fk_soc.", ".$user->id.", '".addslashes($this->desc)."',"; + $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; $sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null"); $sql.= ")"; @@ -289,26 +288,34 @@ class DiscountAbsolute /** - * \brief Renvoie montant TTC des avoirs en cours disponibles - * \param fk_soc Filtre sur une societe + * \brief Renvoie montant TTC des reductions/avoirs en cours disponibles + * \param company Object third party for filter * \param user Filtre sur un user auteur des remises * \param filter Filtre autre - * \return int <0 si ko, montant avoir sinon + * \param maxvalue Filter on max value for discount + * \return int <0 si ko, montant avoir sinon */ - function getAvailableDiscounts($company='', $user='',$filter='') + function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0) { $sql = "SELECT SUM(rc.amount_ttc) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; +// $sql = "SELECT rc.amount_ttc as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; $sql.= " WHERE (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id; if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id; - if ($filter) $sql.=' AND '.$filter; + if ($filter) $sql.=' AND '.$filter; + if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue); - dolibarr_syslog("Discount::getAvailableDiscounts sql=".$sql,LOG_DEBUG); + dolibarr_syslog("DiscountAbsolute::getAvailableDiscounts sql=".$sql,LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); + //while ($obj) + //{ + //print 'zz'.$obj->amount; + //$obj = $this->db->fetch_object($resql); + //} return $obj->amount; } return -1; @@ -325,7 +332,7 @@ class DiscountAbsolute $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; $sql.= ' WHERE rc.fk_facture = '.$invoice->id; - dolibarr_syslog("Discount::getSommeCreditNote sql=".$sql,LOG_DEBUG); + dolibarr_syslog("DiscountAbsolute::getSommeCreditNote sql=".$sql,LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 5f226e9497b..fbd49e53189 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -748,12 +748,14 @@ class Form /** - * \brief Retourne la liste déroulante des remises fixes - * \param selected Id remise fixe pré-sélectionnée - * \param htmlname Nom champ formulaire - * \param filter Criteres optionnels de filtre + * \brief Retourne la liste déroulante des remises fixes + * \param selected Id remise fixe pré-sélectionnée + * \param htmlname Nom champ formulaire + * \param filter Criteres optionnels de filtre + * \param maxvalue Max value for lines that can be selected + * \return int Return number of qualifed lines in list */ - function select_remises($selected='',$htmlname='remise_id',$filter='',$socid) + function select_remises($selected='',$htmlname='remise_id',$filter='',$socid, $maxvalue=0) { global $langs,$conf; @@ -771,6 +773,9 @@ class Form { print ''; + return $qualifiedlines; } - else { + else + { dolibarr_print_error($this->db); + return -1; } } @@ -2256,15 +2267,16 @@ class Form /** - * \brief Affiche formulaire de selection de la remise fixe - * \param page Page - * \param selected Valeur a appliquer - * \param htmlname Nom du formulaire select. Si none, non modifiable - * \param socid - * \param amount - * \param filter Filtre + * \brief Affiche formulaire de selection de la remise fixe + * \param page Page URL where form is shown + * \param selected Value pre-selected + * \param htmlname Nom du formulaire select. Si none, non modifiable + * \param socid Third party id + * \param amount Total amount available + * \param filter SQL filter on discounts + * \param maxvalue Max value for lines that can be selected */ - function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $amount, $filter='') + function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $amount, $filter='', $maxvalue=0) { global $conf,$langs; if ($htmlname != "none") @@ -2278,12 +2290,17 @@ class Form // print $langs->trans("AvailableGlobalDiscounts").': '; $newfilter='fk_facture IS NULL AND fk_facture_line IS NULL'; // Remises disponibles if ($filter) $newfilter.=' AND '.$filter; - print $this->select_remises('',$htmlname,$newfilter,$socid); + $nbqualifiedlines=$this->select_remises('',$htmlname,$newfilter,$socid,$maxvalue); + print ''; + print ''; + if ($nbqualifiedlines > 0) + { + print ' trans("UseCreditNoteInInvoicePayment"); + print '">'; + } print ''; - print ' trans("UseCreditNoteInInvoicePayment"); - print '">'; print ''; } else diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index e43b04eb3d0..153991c8d6e 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1955,14 +1955,14 @@ function vatrate($rate,$addpercent=false,$info_bits=0) /** - * \brief Fonction qui retourne un montant mon�taire format� pour visualisation - * \remarks Fonction utilis�e dans les pdf et les pages html + * \brief Fonction qui formate un montant pour visualisation + * \remarks Fonction utilisee dans les pdf et les pages html * \param amount Montant a formater - * \param html Formatage html ou pas (0 par defaut) + * \param html Type de formatage, html ou pas (par defaut) * \param outlangs Objet langs pour formatage text - * \param trunc 1=Tronque affichage si trop de d�cimales,0=Force le non troncage + * \param trunc 1=Tronque affichage si trop de decimales,0=Force le non troncage * \param nbdecimal Nbre decimals minimum. - * \return string Chaine avec montant format� + * \return string Chaine avec montant formate * \seealso price2num Fonction inverse de price */ function price($amount, $html=0, $outlangs='', $trunc=1, $nbdecimal=2) @@ -2021,7 +2021,7 @@ function price($amount, $html=0, $outlangs='', $trunc=1, $nbdecimal=2) * \remarks Fonction a appeler sur montants saisis avant un insert en base * \param amount Montant a formater * \param rounding 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT) - * 'MT'=Round to Max with Tax (MAIN_MAX_DECIMALS_TOT) + * 'MT'=Round to Max for totals with Tax (MAIN_MAX_DECIMALS_TOT) * 'MS'=Round to Max Shown (MAIN_MAX_DECIMALS_SHOWN) * ''=No rounding * \return string Montant au format num�rique PHP et SQL (Exemple: '99.99999') diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index a44d521a01c..a6de7b8718d 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -1024,17 +1024,18 @@ class Societe extends CommonObject /** - * \brief Renvoie montant TTC des avoirs en cours disponibles de la societe + * \brief Renvoie montant TTC des reductions/avoirs en cours disponibles de la societe * \param user Filtre sur un user auteur des remises * \param filter Filtre autre + * \param maxvalue Filter on max value for discount * \return int <0 if KO, Credit note amount otherwise */ - function getAvailableDiscounts($user='',$filter='') + function getAvailableDiscounts($user='',$filter='',$maxvalue=0) { require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); $discountstatic=new DiscountAbsolute($this->db); - $result=$discountstatic->getAvailableDiscounts($this,$user,$filter); + $result=$discountstatic->getAvailableDiscounts($this,$user,$filter,$maxvalue); if ($result >= 0) { return $result; @@ -1046,6 +1047,13 @@ class Societe extends CommonObject } } + + /** + * Enter description here... + * + * @param unknown_type $price_level + * @param unknown_type $user + */ function set_price_level($price_level, $user) { if ($this->id)