From c9944a6b9b47e9e121124c53ca459edd433be8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a?= Date: Mon, 15 Oct 2012 00:49:39 +0200 Subject: [PATCH] Created function to retrieve total discounted amount of a commonobject Also added an ODT tag to let people add it to their invoices, etc.. --- ChangeLog | 3 +++ htdocs/core/class/commonobject.class.php | 22 +++++++++++++++++++ .../doc/doc_generic_invoice_odt.modules.php | 1 + 3 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index f12ff21e0a6..fb11afc57ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -54,6 +54,8 @@ For users: - New: [ task #210 ] Can choose cash account during POS login - New: [ task #104 ] Can create an invoice from several orders - New: Update libs/tools/logo for DoliWamp (now use PHP 5.3). +- New: Added ODT Template tag {object_total_discount} + New experimental modules: - New: Add margin management module. - New: Add commissions management module. @@ -81,6 +83,7 @@ For developers: expedition, order supplier and order invoice (lines included), intervention card, project, tasks. - New: Add ChromePHP output into syslog module. - New: Add PRODUCT_PRICE_MODIFY trigger. +- New: Created function to retrieve total amount of discount of an invoice/proposal... For translators: - New: Update language files (de, tr, pt, ca, es, en, fr). diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0b2c8acf531..0cb132d23c6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2012 Christophe Battarel * Copyright (C) 2011-2012 Philippe Grand + * Copyright (C) 2012 Marcos GarcĂ­a * * 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 @@ -2214,6 +2215,27 @@ abstract class CommonObject return $nb; } + /** + * Function that returns the total amount of discounts applied. + * + * @return false|float False is returned if the discount couldn't be retrieved + */ + function getTotalDiscount() + { + $sql = 'SELECT (SUM(`subprice`) - SUM(`total_ht`)) as `discount` FROM '.MAIN_DB_PREFIX.$this->table_element.'det WHERE `'.$this->fk_element.'` = '.$this->id; + + $query = $this->db->query($sql); + + if ($query) + { + $result = $this->db->fetch_object($query); + + return price2num($result->discount); + } + + return false; + } + /** * Set extra parameters * diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php index c8cd2a46e32..12e4fc86119 100644 --- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -124,6 +124,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures 'object_total_ht'=>price($object->total_ht,0,$outputlangs), 'object_total_vat'=>price($object->total_tva,0,$outputlangs), 'object_total_ttc'=>price($object->total_ttc,0,$outputlangs), + 'object_total_discount' => price($object->getTotalDiscount(), 0, $outputlangs), 'object_vatrate'=>(isset($object->tva)?vatrate($object->tva):''), 'object_note_private'=>$object->note, 'object_note'=>$object->note_public,