From 8f45fa7e1821669b1ad7a0b9eea3267f00b4a579 Mon Sep 17 00:00:00 2001 From: sunsetsystems Date: Tue, 17 Feb 2009 00:41:47 +0000 Subject: [PATCH] added grouping by service category --- interface/reports/sales_by_item.php | 115 ++++++++++++++++++++++++++++-------- 1 file changed, 91 insertions(+), 24 deletions(-) diff --git a/interface/reports/sales_by_item.php b/interface/reports/sales_by_item.php index 0e68b198f..02fdd3a72 100644 --- a/interface/reports/sales_by_item.php +++ b/interface/reports/sales_by_item.php @@ -1,5 +1,5 @@ +// Copyright (C) 2006-2009 Rod Roark // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -26,33 +26,36 @@ function display_desc($desc) { return $desc; } -function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty, $amount) { - global $product, $producttotal, $productqty, $grandtotal, $grandqty; +function thisLineItem($patient_id, $encounter_id, $rowcat, $description, $transdate, $qty, $amount) { + global $product, $category, $producttotal, $productqty, $cattotal, $catqty, $grandtotal, $grandqty; + global $productleft, $catleft; $invnumber = "$patient_id.$encounter_id"; $rowamount = sprintf('%01.2f', $amount); - // Extract only the first word as the payment method because any following - // text will be some petty detail like a check number. + if (empty($rowcat)) $rowcat = 'None'; $rowproduct = $description; if (! $rowproduct) $rowproduct = 'Unknown'; - if ($product != $rowproduct) { + if ($product != $rowproduct || $category != $rowcat) { if ($product) { // Print product total. if ($_POST['form_csvexport']) { if (! $_POST['form_details']) { - echo '"' . display_desc($product) . '",'; - echo '"' . $productqty . '",'; + echo '"' . display_desc($category) . '",'; + echo '"' . display_desc($product) . '",'; + echo '"' . $productqty . '",'; echo '"'; bucks($producttotal); echo '"' . "\n"; } } else { ?> - + + + - + @@ -70,9 +73,39 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty $productleft = $product; } + if ($category != $rowcat) { + if ($category) { + // Print category total. + if (!$_POST['form_csvexport']) { +?> + + + +   + + + + + + + + + + + + + + + @@ -102,8 +138,10 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty } // End not csv export } // end details $producttotal += $rowamount; + $cattotal += $rowamount; $grandtotal += $rowamount; $productqty += $qty; + $catqty += $qty; $grandqty += $qty; } // end function @@ -126,6 +164,7 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty header("Content-Description: File Transfer"); // CSV headers: if ($_POST['form_details']) { + echo '"Category",'; echo '"Item",'; echo '"Date",'; echo '"Invoice",'; @@ -133,11 +172,12 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty echo '"Amount"' . "\n"; } else { + echo '"Category",'; echo '"Item",'; echo '"Qty",'; echo '"Total"' . "\n"; } - } + } // end export else { ?> @@ -206,19 +246,22 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty - + + + + - + - + - + - + = '$from_date 00:00:00' AND fe.date <= '$to_date 23:59:59'"; // If a facility was specified. if ($form_facility) { $query .= " AND fe.facility_id = '$form_facility'"; } - $query .= " ORDER BY b.code, fe.date, fe.id"; + $query .= " ORDER BY lo.title, b.code, fe.date, fe.id"; // $res = sqlStatement($query); while ($row = sqlFetchArray($res)) { thisLineItem($row['pid'], $row['encounter'], - $row['code'] . ' ' . $row['code_text'], + $row['title'], $row['code'] . ' ' . $row['code_text'], substr($row['date'], 0, 10), $row['units'], $row['fee']); } // @@ -271,7 +320,7 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty // $res = sqlStatement($query); while ($row = sqlFetchArray($res)) { - thisLineItem($row['pid'], $row['encounter'], $row['name'], + thisLineItem($row['pid'], $row['encounter'], xl('Products'), $row['name'], substr($row['date'], 0, 10), $row['quantity'], $row['fee']); } } @@ -295,7 +344,7 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty "facility_id = '$form_facility'"); if (empty($tmp['count'])) continue; } - thisLineItem($patient_id, $encounter_id, $row['description'], + thisLineItem($patient_id, $encounter_id, '', $row['description'], $row['transdate'], $row['qty'], $row['sellprice'] * $row['qty']); } // end for } // end not $INTEGRATED_AR @@ -311,8 +360,11 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty ?> + + + - + @@ -323,7 +375,22 @@ function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty + +   + + + + + + + + + + + + + -- 2.11.4.GIT