[wiaflos-devel] COMMIT - r249 - trunk/wiaflos/server
svn at linuxrulz.org
svn at linuxrulz.org
Sun Nov 2 11:26:11 GMT 2008
Author: nkukard
Date: 2008-11-02 11:26:11 +0000 (Sun, 02 Nov 2008)
New Revision: 249
Modified:
trunk/wiaflos/server/Reporting.pm
Log:
* Various small cleanups
* Added support to return only a certain list of accounts for balances
* Added support for inventory stock lists
Modified: trunk/wiaflos/server/Reporting.pm
===================================================================
--- trunk/wiaflos/server/Reporting.pm 2008-11-02 11:24:14 UTC (rev 248)
+++ trunk/wiaflos/server/Reporting.pm 2008-11-02 11:26:11 UTC (rev 249)
@@ -90,6 +90,7 @@
# @li StartDate - Optional statement start date
# @li EndDate - Optional statement end date
# @li Levels - Optional depth to go into on each parent account
+# @li AccountNumberList - Optional list of account numbers to return balances for, comma/semicolon separated
#
# @returns Array ref of hash refs containing the accounts and their balances
# @li ID - Account ID
@@ -109,11 +110,6 @@
our $flags = shift;
my $data = shift;
- # GL search criteria
- my $search;
- $search->{'StartDate'} = $data->{'StartDate'};
- $search->{'EndDate'} = $data->{'EndDate'};
- $search->{'Levels'} = $data->{'Levels'};
# Get our account tree
my $res = wiaflos::server::GL::getGLAccountTree();
@@ -122,6 +118,12 @@
return $res;
}
+ # GL search criteria
+ my $search;
+ $search->{'StartDate'} = $data->{'StartDate'};
+ $search->{'EndDate'} = $data->{'EndDate'};
+ $search->{'Levels'} = $data->{'Levels'};
+
# Loop with the parent accounts, remember they're top level
foreach my $account (@{$res}) {
@@ -221,12 +223,12 @@
-## @fn sendReport
+## @fn sendReport($detail)
# Function to send a report
#
# @param detail Parameter hash ref
# @li Template - Tempalte to use
-# @li GLAccountNumber - Optional GL account number used for some reports
+# @li GLAccountNumber - Optional GL account number(s) used for some reports
# @li SendTo - Send to, email: , file: , return
# @li Subject - Optional Subject of the report
# @li StartDate - Optional statement start date
@@ -245,6 +247,7 @@
my $search;
$search->{'StartDate'} = $detail->{'StartDate'};
$search->{'EndDate'} = $detail->{'EndDate'};
+
my $entries = getAccountBalances(REPORT_BALANCE_BF,$search);
if (ref($entries) ne "ARRAY") {
# FIXME
@@ -252,6 +255,11 @@
# return $entries;
return;
}
+
+ our @accountList = ();
+ if (defined($detail->{'GLAccountNumber'})) {
+ @accountList = split(/[,;]/,$detail->{'GLAccountNumber'});
+ }
# Result to return
our $resdata;
@@ -307,8 +315,24 @@
}
}
+ my $add = 0;
+ # Check if we have a limit list on the accounts to return
+ if (@accountList > 0) {
+ # Try find a match
+ foreach my $j (@accountList) {
+ if ($i->{'Number'} =~ /^$j:/) {
+ $add = 1;
+ last;
+ }
+ }
+ } else {
+ $add = 1;
+ }
+
# File balance under account number
- $resdata->{'AccountBalances'}{$i->{'Number'}} = $i;
+ if ($add) {
+ $resdata->{'AccountBalances'}{$i->{'Number'}} = $i;
+ }
return $i;
}
@@ -316,8 +340,24 @@
# Process top level item
my $pitem = processItem($item);
+ my $add = 0;
+ # Check if we have a limit list on the accounts to return
+ if (@accountList > 0) {
+ # Try find a match
+ foreach my $j (@accountList) {
+ if ($pitem->{'Number'} =~ /^$j:/) {
+ $add = 1;
+ last;
+ }
+ }
+ } else {
+ $add = 1;
+ }
+
# File under report write category code
- push(@{$resdata->{'ReportWriterCategoryToAccounts'}{$pitem->{'ReportWriterCategoryCode'}}},$pitem);
+ if ($add) {
+ push(@{$resdata->{'ReportWriterCategoryToAccounts'}{$pitem->{'ReportWriterCategoryCode'}}},$pitem);
+ }
}
# Load report write categories
@@ -343,7 +383,6 @@
my $tmp;
$tmp->{'AccountNumber'} = $detail->{'GLAccountNumber'};
my $account = wiaflos::server::GL::getGLAccount($tmp);
-use Data::Dumper; print STDERR Dumper($account);
if (ref($account) ne "HASH") {
# FIXME
return;
@@ -402,6 +441,63 @@
}
+ # Reporting API function to retrieve inventory stock balances
+ sub api_inventory_stock_balances
+ {
+ my $resdata;
+
+ # Get inventory data
+ my $tmp;
+ $tmp->{'EndDate'} = $detail->{'EndDate'};
+ my $res = wiaflos::server::Inventory::getInventoryStockBalance($tmp);
+ if (ref($res) ne "HASH") {
+# FIXME
+ return;
+ }
+
+ # Work out closing balance
+ my $totalValue = Math::BigFloat->new();
+ $totalValue->precision(-2);
+
+ # Loop with stock codes
+ foreach my $itemCode (keys %{$res}) {
+ my $entry;
+
+ $entry->{'TotalQuantity'} = Math::BigFloat->new();
+ $entry->{'TotalQuantity'}->precision(-4);
+ $entry->{'TotalValue'} = Math::BigFloat->new();
+
+ # Loop with stock items
+ foreach my $itemSerial (keys %{$res->{$itemCode}}) {
+ my $stockItem = $res->{$itemCode}->{$itemSerial};
+
+ $entry->{'TotalQuantity'}->badd($stockItem->{'Quantity'});
+ $entry->{'TotalValue'}->badd($stockItem->{'Value'});
+
+ $totalValue->badd($stockItem->{'Value'});
+
+ # If its zero, we don't want it
+ if (!$stockItem->{'Quantity'}->is_zero() && !$stockItem->{'Value'}->is_zero()) {
+ my $sentry;
+ $sentry->{'TotalQuantity'} = sprintf('%.4f',$stockItem->{'Quantity'}->bstr());
+ $sentry->{'TotalValue'} = sprintf('%.4f',$stockItem->{'Value'}->bstr());
+ $resdata->{'StockItemBalances'}->{$itemCode}->{$itemSerial} = $sentry;
+ }
+ }
+ # If its zero, we don't need it
+ if (!$entry->{'TotalQuantity'}->is_zero() && !$entry->{'TotalValue'}->is_zero()) {
+ $entry->{'TotalQuantity'} = sprintf('%.4f',$entry->{'TotalQuantity'}->bstr());
+ $entry->{'TotalValue'} = sprintf('%.2f',$entry->{'TotalValue'}->bstr());
+ $resdata->{'StockBalances'}->{$itemCode} = $entry;
+ }
+ }
+
+ $resdata->{'TotalValue'} = sprintf('%.2f',$totalValue->bstr());
+
+ return $resdata;
+ }
+
+
# Verify Template
if (!defined($detail->{'Template'}) || $detail->{'Template'} eq "") {
setError("Template was not provided");
@@ -434,6 +530,7 @@
# API
'api_account_balances' => \&api_account_balances,
'api_account_entries' => \&api_account_entries,
+ 'api_inventory_stock_balances' => \&api_inventory_stock_balances,
# TODO - Optional??
More information about the wiaflos-devel
mailing list