From ab4a1af224ca2a47a35c30b0300601941ad4768b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 24 Feb 2011 15:22:30 +0000 Subject: [PATCH] New: add function to sort the total qty of products or/and services --- htdocs/lib/pdf.lib.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/htdocs/lib/pdf.lib.php b/htdocs/lib/pdf.lib.php index ac6b3364909..ca2b0341840 100644 --- a/htdocs/lib/pdf.lib.php +++ b/htdocs/lib/pdf.lib.php @@ -915,4 +915,42 @@ function pdf_getlinetotalexcltax($object,$i,$outputlangs) } } +/** + * Return total quantity of products and/or services + * @param object Object + * @param type Type of line (all=all, 0=product, 1=service, 9=other) + * @param outputlang Object lang for output + */ +function pdf_getTotalQty($object,$type='',$outputlangs) +{ + $total=0; + $nblignes=sizeof($object->lines); + + // Loop on each lines + for ($i = 0 ; $i < $nblignes ; $i++) + { + if ($object->lines[$i]->special_code != 3) + { + if ($type=='all') + { + $total += $object->lines[$i]->qty; + } + else if ($type==9 && !empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) + { + // TODO add hook function + } + else if ($type==0 && $object->lines[$i]->product_type == 0) + { + $total += $object->lines[$i]->qty; + } + else if ($type==1 && $object->lines[$i]->product_type == 1) + { + $total += $object->lines[$i]->qty; + } + } + } + + return $total; +} + ?>