diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index 992ac9bd90d..cfae2ed2a2a 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -127,7 +127,7 @@ if ($_GET["action"] == 'create') print ''.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$soc->getCurrentDiscount(); + $absolute_discount=$soc->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index 7ee3dad09ff..195fd725558 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -265,7 +265,7 @@ if ($socid > 0) print ''; print ''; print ''; - $amount_discount=$objsoc->getcurrentDiscount(); + $amount_discount=$objsoc->getAvailableDiscounts(); if ($amount_discount < 0) dolibarr_print_error($db,$societe->error); if ($amount_discount > 0) print price($amount_discount).' '.$langs->trans("Currency".$conf->monnaie); else print $langs->trans("DiscountNone"); diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 211ed76ff22..49ef8a046fe 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -823,8 +823,8 @@ if ($_GET['propalid'] > 0) print ''.$langs->trans('Discounts').''; if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$societe->getCurrentDiscount('','fk_facture_source IS NULL'); - $absolute_creditnote=$societe->getCurrentDiscount('','fk_facture_source IS NOT NULL'); + $absolute_discount=$societe->getAvailableDiscounts('','fk_facture_source IS NULL'); + $absolute_creditnote=$societe->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); print '. '; if ($absolute_discount) { diff --git a/htdocs/comm/propal/apercu.php b/htdocs/comm/propal/apercu.php index b35f740f8a6..e8be4f4c57a 100644 --- a/htdocs/comm/propal/apercu.php +++ b/htdocs/comm/propal/apercu.php @@ -110,7 +110,7 @@ if ($_GET["propalid"] > 0) print ''.$langs->trans('Discounts').''; if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$societe->getCurrentDiscount(); + $absolute_discount=$societe->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); diff --git a/htdocs/comm/propal/note.php b/htdocs/comm/propal/note.php index ec8dade72d5..12367e7f67a 100644 --- a/htdocs/comm/propal/note.php +++ b/htdocs/comm/propal/note.php @@ -118,7 +118,7 @@ if ($_GET['propalid']) print ''.$langs->trans('Discounts').''; if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$societe->getCurrentDiscount(); + $absolute_discount=$societe->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index a2d01abddfc..8900f8fb080 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -786,7 +786,7 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer) print ''.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$soc->getCurrentDiscount(); + $absolute_discount=$soc->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); @@ -1111,8 +1111,8 @@ else print ''.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$soc->getCurrentDiscount('','fk_facture_source IS NULL'); - $absolute_creditnote=$soc->getCurrentDiscount('','fk_facture_source IS NOT NULL'); + $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); + $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); print '. '; if ($absolute_discount) { diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index bc724aa78ce..fa27846eb1c 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -135,8 +135,8 @@ if ($_GET["id"] > 0) print ''.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$soc->getCurrentDiscount('','fk_facture_source IS NULL'); - $absolute_creditnote=$soc->getCurrentDiscount('','fk_facture_source IS NOT NULL'); + $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); + $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); print '. '; if ($absolute_discount) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 4b738f1da01..5b4f21ea73c 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1138,7 +1138,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post } } -llxHeader('',$langs->trans('Bill'),'Facture'); +llxHeader('',$langs->trans('Bill'),'HelpInvoice'); $html = new Form($db); @@ -1693,8 +1693,11 @@ else /* *************************************************************************** */ if ($mesg) print $mesg.'
'; - $fac = New Facture($db); - if ($fac->fetch($_GET['facid'])) + $facstatic = new Facture($db); + + $fac = new Facture($db); + $result=$fac->fetch($_GET['facid']); + if ($result > 0) { if ($user->societe_id>0 && $user->societe_id!=$fac->socid) accessforbidden('',0); @@ -1702,12 +1705,14 @@ else $soc = new Societe($db, $fac->socid); $soc->fetch($fac->socid); - $absolute_discount=$soc->getCurrentDiscount('','fk_facture_source IS NULL'); - $absolute_creditnote=$soc->getCurrentDiscount('','fk_facture_source IS NOT NULL'); + $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); + $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); - $totalpaye = $fac->getSommePaiement(); - $resteapayer = $fac->total_ttc - $totalpaye; + $totalpaye = $fac->getSommePaiement(); + $totalavoir = $fac->getSommeCreditNote(); + $resteapayer = $fac->total_ttc - $totalpaye - $totalavoir; if ($fac->paye) $resteapayer=0; + $resteapayeraffiche=$resteapayer; $author = new User($db); if ($fac->user_author) @@ -1873,6 +1878,7 @@ else /* * Facture */ + print ''; // Reference @@ -1942,7 +1948,7 @@ else $facreplaced->fetch($fac->fk_facture_source); print ' ('.$langs->transnoentities("CorrectInvoice",$facreplaced->getNomUrl(1)).')'; } - $facidavoir=$fac->getIdAvoirInvoice(); + $facidavoir=$fac->getListIdAvoirFromInvoice(); if (sizeof($facidavoir) > 0) { print ' ('.$langs->transnoentities("InvoiceHasAvoir"); @@ -2057,13 +2063,35 @@ else // Facturé print ''; - $resteapayeraffiche=$resteapayer; // Boucle sur chaque facture avoir appliquee - - - + $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; + $sql.= " re.description, re.fk_facture_source, re.fk_facture_source"; + $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; + $sql.= " WHERE fk_facture = ".$fac->id; + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + $invoice=new Facture($db); + while ($i < $num) + { + $obj = $db->fetch_object($resql); + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + // Payé partiellement 'escompte' if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'escompte') { @@ -2177,6 +2205,7 @@ else // Lit lignes de facture pour déterminer montant // On s'en sert pas mais ca sert pour debuggage + /* $sql = 'SELECT l.price as price, l.qty, l.rowid, l.tva_taux,'; $sql .= ' l.remise_percent, l.subprice'; $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet as l '; @@ -2201,6 +2230,7 @@ else $i++; } } + */ // Montants print ''; @@ -2736,8 +2766,9 @@ else if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0 && $user->rights->facture->paiement) { - if ($totalpaye > 0) + if ($totalpaye > 0 || $totalavoir > 0) { + // If one payment or one credit note was linked to this invoice print ''.$langs->trans('ClassifyPayedPartially').''; } else diff --git a/htdocs/compta/fiche.php b/htdocs/compta/fiche.php index 3d52ade133b..d29cdab89e2 100644 --- a/htdocs/compta/fiche.php +++ b/htdocs/compta/fiche.php @@ -204,7 +204,7 @@ if ($socid > 0) print '
'.$langs->trans("Billed").' :'.price($fac->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans("CreditNote").' '; + $invoice->fetch($obj->fk_facture_source); + print $invoice->getNomUrl(0); + print ' :'.price($obj->amount_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountHT').'
'; print ''; print ''; - $amount_discount=$societe->getCurrentDiscount(); + $amount_discount=$societe->getAvailableDiscounts(); if ($amount_discount < 0) dolibarr_print_error($db,$societe->error); if ($amount_discount > 0) print price($amount_discount).' '.$langs->trans("Currency".$conf->monnaie); else print $langs->trans("DiscountNone"); diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index 38c10944c30..71b6546677a 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -171,7 +171,7 @@ if ($_GET["propalid"] > 0) print ''.$langs->trans('Discounts').''; if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$societe->getCurrentDiscount(); + $absolute_discount=$societe->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); diff --git a/htdocs/contrat/contact.php b/htdocs/contrat/contact.php index 0f75dd27bbd..79fd2e4d629 100644 --- a/htdocs/contrat/contact.php +++ b/htdocs/contrat/contact.php @@ -191,7 +191,7 @@ if ($id > 0) print ''.$langs->trans('Discount').''; if ($contrat->societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$contrat->societe->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$contrat->societe->getCurrentDiscount(); + $absolute_discount=$contrat->societe->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 20c7a8bc4bd..767ebbf69c1 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -428,7 +428,7 @@ if ($_GET["action"] == 'create') print ''.$langs->trans('Discount').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$soc->getCurrentDiscount(); + $absolute_discount=$soc->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); @@ -679,7 +679,7 @@ else print ''.$langs->trans('Discount').''; if ($contrat->societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$contrat->societe->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$contrat->societe->getCurrentDiscount(); + $absolute_discount=$contrat->societe->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); diff --git a/htdocs/contrat/ligne.php b/htdocs/contrat/ligne.php index ff3abc72ca9..f23fa2923c4 100644 --- a/htdocs/contrat/ligne.php +++ b/htdocs/contrat/ligne.php @@ -176,7 +176,7 @@ if ($lineid > 0) print ''.$langs->trans('Discount').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$soc->getCurrentDiscount(); + $absolute_discount=$soc->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); diff --git a/htdocs/contrat/note.php b/htdocs/contrat/note.php index cb4413f926e..315ebea8ac5 100644 --- a/htdocs/contrat/note.php +++ b/htdocs/contrat/note.php @@ -145,7 +145,7 @@ if ($_GET["id"]) print ''.$langs->trans('Discount').''; if ($contrat->societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$contrat->societe->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$contrat->societe->getCurrentDiscount(); + $absolute_discount=$contrat->societe->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); diff --git a/htdocs/discount.class.php b/htdocs/discount.class.php index 154f454a0a0..d1ad304d5b8 100644 --- a/htdocs/discount.class.php +++ b/htdocs/discount.class.php @@ -271,7 +271,7 @@ class DiscountAbsolute * \param filter Filtre autre * \return int <0 si ko, montant avoir sinon */ - function getCurrentDiscount($company='', $user='',$filter='') + function getAvailableDiscounts($company='', $user='',$filter='') { $sql = "SELECT SUM(rc.amount_ttc) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; @@ -280,7 +280,7 @@ class DiscountAbsolute if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id; if ($filter) $sql.=' AND '.$filter; - dolibarr_syslog("Discount::getCurrentDiscount sql=".$sql,LOG_DEBUG); + dolibarr_syslog("Discount::getAvailableDiscounts sql=".$sql,LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -291,6 +291,30 @@ class DiscountAbsolute } + /** + * \brief Renvoie montant TTC des avoirs utilises par la facture + * \return int <0 if KO, Credit note amount otherwise + */ + function getSommeCreditNote($invoice) + { + $sql = 'SELECT sum(rc.amount_ttc) as amount'; + $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); + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + return $obj->amount; + } + else + { + return -1; + } + } + + /** \brief Renvoie nom clicable (avec eventuellement le picto) \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 4eadedb0998..6e6340b8b6b 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -1814,36 +1814,57 @@ class Facture extends CommonObject } } - /** - * \brief Renvoie tableau des ids de facture avoir issus de la facture - * \return array Tableau d'id de factures avoirs - */ - function getIdAvoirInvoice() - { - $idarray=array(); + /** + * \brief Renvoie montant TTC des avoirs utilises par la facture + * \return int <0 if KO, Credit note amount otherwise + */ + function getSommeCreditNote() + { + require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); - $sql = 'SELECT rowid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'facture'; - $sql.= ' WHERE fk_facture_source = '.$this->id; - $sql.= ' AND type = 2'; - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $idarray[]=$row[0]; - $i++; - } - } - else - { - dolibarr_print_error($this->db); - } - return $idarray; - } + $discountstatic=new DiscountAbsolute($this->db); + $result=$discountstatic->getSommeCreditNote($this); + if ($result >= 0) + { + return $result; + } + else + { + $this->error=$discountstatic->error; + return -1; + } + } + + /** + * \brief Renvoie tableau des ids de facture avoir issus de la facture + * \return array Tableau d'id de factures avoirs + */ + function getListIdAvoirFromInvoice() + { + $idarray=array(); + + $sql = 'SELECT rowid'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'facture'; + $sql.= ' WHERE fk_facture_source = '.$this->id; + $sql.= ' AND type = 2'; + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $idarray[]=$row[0]; + $i++; + } + } + else + { + dolibarr_print_error($this->db); + } + return $idarray; + } /** * \brief Renvoie l'id de la facture qui la remplace diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 55663945b9a..c03640e20d6 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -745,7 +745,7 @@ class Form { global $langs,$conf; - // On recherche les societes + // On recherche les remises $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql.= " re.description, re.fk_facture_source"; $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 447e6dd35fe..7ee37f4b8a1 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -843,10 +843,10 @@ function top_menu($head, $title="", $target="") /** * \brief Affiche barre de menu gauche * \param menu_array Tableau des entrees de menu - * \param help_url Url pour le lien aide ('' par defaut) + * \param helppagename Url pour le lien aide ('' par defaut) * \param form_search Formulaire de recherche permanant supplementaire */ -function left_menu($menu_array, $help_url='', $form_search='') +function left_menu($menu_array, $helppagename='', $form_search='') { global $user, $conf, $langs, $db; @@ -908,12 +908,23 @@ function left_menu($menu_array, $help_url='', $form_search='') } // Lien vers l'aide en ligne (uniquement si langue fr_FR) - if ($help_url) + if ($helppagename) { + $langs->load("help"); + $helpbaseurl=''; if ($langs->defaultlang == "fr_FR") $helpbaseurl='http://www.dolibarr.com/wikidev/index.php/%s'; - - if ($helpbaseurl) print '
'.$langs->trans("Help").'
'; + + $helppage=$langs->trans($helppagename); + + if ($helpbaseurl) + { + print '
'; + print ''.$langs->trans("Help").''; + print '
'; + } } if ($conf->global->MAIN_SHOW_BUGTRACK_LINK == 1) diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 71eeac3d268..8bbd9de8644 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -1031,23 +1031,22 @@ class Societe * \param filter Filtre autre * \return int <0 if KO, Credit note amount otherwise */ - function getCurrentDiscount($user='',$filter='') + function getAvailableDiscounts($user='',$filter='') { require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); $discountstatic=new DiscountAbsolute($this->db); - $result=$discountstatic->getCurrentDiscount($this,$user,$filter); + $result=$discountstatic->getAvailableDiscounts($this,$user,$filter); if ($result >= 0) { return $result; } else { - $this->error=$discount->error; + $this->error=$discountstatic->error; return -1; } } - function set_price_level($price_level, $user) {