[wiaflos-devel] COMMIT - r246 - in trunk: contrib/templates/reports soap/Plugins wiaflos/client/cmdline wiaflos/server
svn at linuxrulz.org
svn at linuxrulz.org
Sun Oct 26 11:28:41 GMT 2008
Author: nkukard
Date: 2008-10-26 11:28:41 +0000 (Sun, 26 Oct 2008)
New Revision: 246
Added:
trunk/contrib/templates/reports/balancesheet1.tt2
trunk/contrib/templates/reports/incomestatement1.tt2
trunk/contrib/templates/reports/transactions1.tt2
trunk/contrib/templates/reports/trialbalance1.tt2
Modified:
trunk/contrib/templates/reports/chartofaccounts1.tt2
trunk/soap/Plugins/Reporting.pm
trunk/wiaflos/client/cmdline/Reporting.pm
trunk/wiaflos/server/Receipting.pm
trunk/wiaflos/server/Reporting.pm
Log:
* Added more reporting templates
* Addedd report api & updated remplates
* Added GL account number option to reporting
Added: trunk/contrib/templates/reports/balancesheet1.tt2
===================================================================
--- trunk/contrib/templates/reports/balancesheet1.tt2 (rev 0)
+++ trunk/contrib/templates/reports/balancesheet1.tt2 2008-10-26 11:28:41 UTC (rev 246)
@@ -0,0 +1,73 @@
+[% INCLUDE header.tt2 %]
+
+<head>
+ <title>Balance Sheet<title>
+ [% INCLUDE styles.tt2 %]
+</head>
+
+<body>
+
+[% SET data = api_account_balances() %]
+
+<table id="page" width="100%">
+ <colgroup span="2" width="50%">
+ </colgroup>
+ [% INCLUDE companydetails.tt2 %]
+ <tr>
+ <td colspan="2" class="bigtext border centeralign bold">
+ B A L A N C E S H E E T
+ <br />
+ [% StartDate %] to [% EndDate %]
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3" class="smalltext">
+ <table width="100%">
+ <tr>
+ <td class="border centeralign">Account</td>
+ <td class="border centeralign">Description</td>
+ <td class="border centeralign">Balance</td>
+ </tr>
+ [% FOREACH rwcatcode = [ '00', '20', '40' ] %]
+ <tr>
+ <td class="centeralign bold" colspan="6">
+ [% data.ReportWriterCategories.${rwcatcode}.Code %]
+ -
+ [% data.ReportWriterCategories.${rwcatcode}.Description %]
+ </td>
+ </tr>
+ [% FOREACH item = data.ReportWriterCategoryToAccounts.${rwcatcode} %]
+ <tr>
+ <td class="bold">[% item.Number %]</td>
+ <td class="bold">[% item.Name %]</td>
+ <td class="rightalign bold">[% item.ClosingBalance %]</td>
+ </tr>
+ [% IF item.Children %]
+ [% FOREACH child = item.Children %]
+ <tr>
+ <td>[% child.Number %]</td>
+ <td >[% child.Name %]</td>
+ <td class="rightalign">[% child.ClosingBalance %]</td>
+ </tr>
+ [% END %]
+ [% END %]
+ [% END %]
+ [% END %]
+ <tr>
+ <td class="bold" colspan="2">TOTAL LIABILITIES AND EQUITY</td>
+ <td class="rightalign bold">xyz</td>
+ </tr>
+ <tr>
+ <td class="centeralign" colspan="4">All values in <span class="bold">USD</span> funds.</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+<div class="smalltext centeralign">[% WiaflosString %]</div>
+
+
+
+</body>
+
+</html>
Modified: trunk/contrib/templates/reports/chartofaccounts1.tt2
===================================================================
--- trunk/contrib/templates/reports/chartofaccounts1.tt2 2008-10-19 06:38:06 UTC (rev 245)
+++ trunk/contrib/templates/reports/chartofaccounts1.tt2 2008-10-26 11:28:41 UTC (rev 246)
@@ -7,6 +7,7 @@
<body>
+[% SET data = api_account_balances() %]
<table id="page" width="100%">
<colgroup span="2" width="50%">
@@ -31,10 +32,12 @@
[% FOREACH rwcatcode = [ '00', '20', '40', '60', '80' ] %]
<tr>
<td class="centeralign bold" colspan="4">
- [% ReportWriterCategories.${rwcatcode}.Code %] - [% ReportWriterCategories.${rwcatcode}.Description %]
+ [% data.ReportWriterCategories.${rwcatcode}.Code %]
+ -
+ [% data.ReportWriterCategories.${rwcatcode}.Description %]
</td>
</tr>
- [% FOREACH item = ReportWriterCategoryToAccounts.${rwcatcode} %]
+ [% FOREACH item = data.ReportWriterCategoryToAccounts.${rwcatcode} %]
<tr>
<td class="bold">[% item.Number %]</td>
<td class="bold">[% item.Name %]</td>
Added: trunk/contrib/templates/reports/incomestatement1.tt2
===================================================================
--- trunk/contrib/templates/reports/incomestatement1.tt2 (rev 0)
+++ trunk/contrib/templates/reports/incomestatement1.tt2 2008-10-26 11:28:41 UTC (rev 246)
@@ -0,0 +1,72 @@
+[% INCLUDE header.tt2 %]
+
+<head>
+ <title>Income Statement<title>
+ [% INCLUDE styles.tt2 %]
+</head>
+
+<body>
+
+[% SET data = api_account_balances() %]
+
+<table id="page" width="100%">
+ <colgroup span="2" width="50%">
+ </colgroup>
+ [% INCLUDE companydetails.tt2 %]
+ <tr>
+ <td colspan="2" class="bigtext border centeralign bold">
+ I N C O M E S T A T E M E N T
+ <br />
+ [% StartDate %] to [% EndDate %]
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3" class="smalltext">
+ <table width="100%">
+ <tr>
+ <td class="border centeralign">Account</td>
+ <td class="border centeralign">Description</td>
+ </tr>
+ [% FOREACH rwcatcode = [ '60', '80' ] %]
+ <tr>
+ <td class="centeralign bold" colspan="6">
+ [% data.ReportWriterCategories.${rwcatcode}.Code %]
+ -
+ [% data.ReportWriterCategories.${rwcatcode}.Description %]
+ </td>
+ </tr>
+ [% FOREACH item = data.ReportWriterCategoryToAccounts.${rwcatcode} %]
+ <tr>
+ <td class="bold">[% item.Number %]</td>
+ <td class="bold">[% item.Name %]</td>
+ <td class="rightalign bold">[% item.EndingBalance %]</td>
+ </tr>
+ [% IF item.Children %]
+ [% FOREACH child = item.Children %]
+ <tr>
+ <td>[% child.Number %]</td>
+ <td >[% child.Name %]</td>
+ <td class="rightalign">[% child.EndingBalance %]</td>
+ </tr>
+ [% END %]
+ [% END %]
+ [% END %]
+ [% END %]
+ <tr>
+ <td class="bold" colspan="2">INCOME / (LOSS)</td>
+ <td class="rightalign bold">xyz</td>
+ </tr>
+ <tr>
+ <td class="centeralign" colspan="4">All values in <span class="bold">USD</span> funds.</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+<div class="smalltext centeralign">[% WiaflosString %]</div>
+
+
+
+</body>
+
+</html>
Added: trunk/contrib/templates/reports/transactions1.tt2
===================================================================
--- trunk/contrib/templates/reports/transactions1.tt2 (rev 0)
+++ trunk/contrib/templates/reports/transactions1.tt2 2008-10-26 11:28:41 UTC (rev 246)
@@ -0,0 +1,57 @@
+[% INCLUDE header.tt2 %]
+
+<head>
+ <title>Account Transactions<title>
+ [% INCLUDE styles.tt2 %]
+</head>
+
+<body>
+
+[% SET data = api_account_entries() %]
+
+<table id="page" width="100%">
+ <colgroup span="2" width="50%">
+ </colgroup>
+ [% INCLUDE companydetails.tt2 %]
+ <tr>
+ <td colspan="2" class="bigtext border centeralign bold">
+ A C C O U N T T R A N S A C T I O N S
+ <br />
+ Account: [% data.Account.Name %]
+ <br />
+ [% StartDate %] to [% EndDate %]
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3" class="smalltext">
+ <table width="100%">
+ <tr>
+ <td class="border centeralign">Date</td>
+ <td class="border centeralign">Reference</td>
+ <td class="border centeralign">Transaction Reference</td>
+ <td class="border centeralign">Amount</td>
+ <td class="border centeralign">Balance</td>
+ </tr>
+ [% FOREACH item = data.Entries %]
+ <tr>
+ <td class="bold">[% item.TransactionDate %]</td>
+ <td class="bold">[% item.Reference %]</td>
+ <td class="bold">[% item.TransactionReference %]</td>
+ <td class="bold">[% item.Amount %]</td>
+ <td class="bold">[% item.Balance %]</td>
+ </tr>
+ [% END %]
+ <tr>
+ <td class="centeralign" colspan="4">All values in <span class="bold">USD</span> funds.</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+<div class="smalltext centeralign">[% WiaflosString %]</div>
+
+
+
+</body>
+
+</html>
Added: trunk/contrib/templates/reports/trialbalance1.tt2
===================================================================
--- trunk/contrib/templates/reports/trialbalance1.tt2 (rev 0)
+++ trunk/contrib/templates/reports/trialbalance1.tt2 2008-10-26 11:28:41 UTC (rev 246)
@@ -0,0 +1,78 @@
+[% INCLUDE header.tt2 %]
+
+<head>
+ <title>Trial balance<title>
+ [% INCLUDE styles.tt2 %]
+</head>
+
+<body>
+
+[% SET data = api_account_balances() %]
+
+<table id="page" width="100%">
+ <colgroup span="2" width="50%">
+ </colgroup>
+ [% INCLUDE companydetails.tt2 %]
+ <tr>
+ <td colspan="2" class="bigtext border centeralign bold">
+ T R I A L B A L A N C E
+ <br />
+ [% StartDate %] to [% EndDate %]
+ </td>
+ </tr>
+ <tr>
+ <td colspan="4" class="smalltext">
+ <table width="100%">
+ <tr>
+ <td class="border centeralign">Account</td>
+ <td class="border centeralign">Description</td>
+ <td class="border centeralign">Beginning Balance</td>
+ <td class="border centeralign">Debit</td>
+ <td class="border centeralign">Credit</td>
+ <td class="border centeralign">Ending Balance</td>
+ </tr>
+ [% FOREACH rwcatcode = [ '00', '20', '40', '60', '80' ] %]
+ <tr>
+ <td class="centeralign bold" colspan="6">
+ [% data.ReportWriterCategories.${rwcatcode}.Code %]
+ -
+ [% data.ReportWriterCategories.${rwcatcode}.Description %]
+ </td>
+ </tr>
+ [% FOREACH item = data.ReportWriterCategoryToAccounts.${rwcatcode} %]
+ <tr>
+ <td class="bold">[% item.Number %]</td>
+ <td class="bold">[% item.Name %]</td>
+ <td class="rightalign bold">[% item.OpeningBalance %]</td>
+ <td class="rightalign bold">[% item.DebitBalance %]</td>
+ <td class="rightalign bold">[% item.CreditBalance %]</td>
+ <td class="rightalign bold">[% item.ClosingBalance %]</td>
+ </tr>
+ [% IF item.Children %]
+ [% FOREACH child = item.Children %]
+ <tr>
+ <td>[% child.Number %]</td>
+ <td >[% child.Name %]</td>
+ <td class="rightalign">[% child.OpeningBalance %]</td>
+ <td class="rightalign">[% child.DebitBalance %]</td>
+ <td class="rightalign">[% child.CreditBalance %]</td>
+ <td class="rightalign">[% child.ClosingBalance %]</td>
+ </tr>
+ [% END %]
+ [% END %]
+ [% END %]
+ [% END %]
+ <tr>
+ <td class="centeralign" colspan="4">All values in <span class="bold">USD</span> funds.</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+<div class="smalltext centeralign">[% WiaflosString %]</div>
+
+
+
+</body>
+
+</html>
Modified: trunk/soap/Plugins/Reporting.pm
===================================================================
--- trunk/soap/Plugins/Reporting.pm 2008-10-19 06:38:06 UTC (rev 245)
+++ trunk/soap/Plugins/Reporting.pm 2008-10-26 11:28:41 UTC (rev 246)
@@ -110,6 +110,7 @@
# Parameters:
# Template - Report template to use
# SendTo - Send statement to here
+# GLAccountNumber - GL account number
# StartDate - Start date
# EndDate - End date
# Subject - Statement subject
@@ -130,6 +131,7 @@
my $detail;
$detail->{'Template'} = $data->{'Template'};
$detail->{'SendTo'} = $data->{'SendTo'};
+ $detail->{'GLAccountNumber'} = $data->{'GLAccountNumber'};
$detail->{'StartDate'} = $data->{'StartDate'};
$detail->{'EndDate'} = $data->{'EndDate'};
$detail->{'Subject'} = $data->{'Subject'};
Modified: trunk/wiaflos/client/cmdline/Reporting.pm
===================================================================
--- trunk/wiaflos/client/cmdline/Reporting.pm 2008-10-19 06:38:06 UTC (rev 245)
+++ trunk/wiaflos/client/cmdline/Reporting.pm 2008-10-26 11:28:41 UTC (rev 246)
@@ -54,7 +54,7 @@
MenuItem => "Send",
Regex => "send",
Desc => "Send report",
- Help => 'send template="<template>" start="<yyyy-mm-dd>" [subject="<subject>"] sendto="<email[:addy1,addy2...] or file:filename>"',
+ Help => 'send template="<template>" start="<yyyy-mm-dd>" [account="<gl_account>"] [subject="<subject>"] sendto="<email[:addy1,addy2...] or file:filename>"',
Function => \&send,
},
],
@@ -195,6 +195,7 @@
$detail->{'StartDate'} = $parms->{'start'};
$detail->{'EndDate'} = $parms->{'end'};
$detail->{'SendTo'} = $parms->{'sendto'};
+ $detail->{'GLAccountNumber'} = $parms->{'account'};
$detail->{'Subject'} = $parms->{'subject'};
my $res = soapCall($OUT,"Reporting","sendReport",$detail);
if ($res->{'Result'} != RES_OK) {
Modified: trunk/wiaflos/server/Receipting.pm
===================================================================
--- trunk/wiaflos/server/Receipting.pm 2008-10-19 06:38:06 UTC (rev 245)
+++ trunk/wiaflos/server/Receipting.pm 2008-10-26 11:28:41 UTC (rev 246)
@@ -504,7 +504,7 @@
# Link from GL
$data = undef;
$data->{'ID'} = $GLTransactionID;
-# $data->{'Reference'} = $receipt->{'Reference'};
+ $data->{'Reference'} = $receipt->{'Reference'};
$data->{'GLAccountID'} = $receipt->{'GLAccountID'};
$data->{'Amount'} = $transValue->bstr();
if ((my $res = wiaflos::server::GL::linkGLTransaction($data)) < 1) {
Modified: trunk/wiaflos/server/Reporting.pm
===================================================================
--- trunk/wiaflos/server/Reporting.pm 2008-10-19 06:38:06 UTC (rev 245)
+++ trunk/wiaflos/server/Reporting.pm 2008-10-26 11:28:41 UTC (rev 246)
@@ -103,7 +103,7 @@
# @li CreditBalance - Optional, this is the total of all credits
#
# @li BalanceBroughtForward - Optional, returned when REPORT_BALANCE_BF is specified
-# Thi is the balance of the account for the period up until this reporting period
+# This is the balance of the account for the period up until this reporting period
sub getAccountBalances
{
our $flags = shift;
@@ -117,7 +117,7 @@
# Get our account tree
my $res = wiaflos::server::GL::getGLAccountTree();
- if (ref $res ne "ARRAY") {
+ if (ref($res) ne "ARRAY") {
setError(wiaflos::server::GL::Error());
return $res;
}
@@ -165,7 +165,7 @@
$info->{'AccountID'} = $paccount->{'ID'};
# Get our own account balance
my $res = wiaflos::server::GL::getGLAccountBalance($info);
- if (ref $res ne "HASH") {
+ if (ref($res) ne "HASH") {
setError(wiaflos::server::GL::Error());
return $res;
}
@@ -187,7 +187,7 @@
$bfinfo->{'AccountID'} = $paccount->{'ID'};
# Pull in balance brought forward
$res = wiaflos::server::GL::getGLAccountBalance($bfinfo);
- if (ref $res ne "HASH") {
+ if (ref($res) ne "HASH") {
setError(wiaflos::server::GL::Error());
return $res;
}
@@ -202,7 +202,7 @@
$paccount->{'OpeningDebitBalance'} = $openingDebitBalance->bstr();
$paccount->{'OpeningBalance'} = $openingBalance->bstr();
# Set closing balance
- $paccount->{'ClosingBalance'} = $openingBalance->copy()->badd($balance);
+ $paccount->{'ClosingBalance'} = $openingBalance->copy()->badd($balance)->bstr();
}
return 0;
@@ -220,19 +220,188 @@
}
-# Send report
-# Parameters:
-# Template - Report template
-# StartDate - Start date
-# EndDate - Start date
-# SendTo - Send to, email: , file: , return
-# Optional:
-# Subject - Subject of the report
+
+## @fn sendReport
+# 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 SendTo - Send to, email: , file: , return
+# @li Subject - Optional Subject of the report
+# @li StartDate - Optional statement start date
+# @li EndDate - Optional statement end date
+#
+# @returns RES_OK on success, < 0 otherwise
sub sendReport
{
- my ($detail) = @_;
+ our ($detail) = @_;
+ # Reporting API function to retrieve account balances
+ sub api_account_balances
+ {
+ # GL search criteria
+ my $search;
+ $search->{'StartDate'} = $detail->{'StartDate'};
+ $search->{'EndDate'} = $detail->{'EndDate'};
+ my $entries = getAccountBalances(REPORT_BALANCE_BF,$search);
+ if (ref($entries) ne "ARRAY") {
+# FIXME
+# setError(Error());
+# return $entries;
+ return;
+ }
+
+ # Result to return
+ our $resdata;
+
+ # Load line items for GL
+ foreach my $item (@{$entries}) {
+
+ # Process item
+ sub processItem
+ {
+ my $account = shift;
+
+
+ my $i;
+
+ # Fix some stuff up
+ $i->{'Number'} = $account->{'Number'};
+ $i->{'Name'} = $account->{'Name'};
+
+ # Pull in the normal balances
+ $i->{'DebitBalance'} = $account->{'DebitBalance'};
+ $i->{'CreditBalance'} = $account->{'CreditBalance'};
+ $i->{'Balance'} = $account->{'Balance'};
+ # Check if we need the opening balances
+ $i->{'OpeningDebitBalance'} = $account->{'OpeningDebitBalance'};
+ $i->{'OpeningCreditBalance'} = $account->{'OpeningCreditBalance'};
+ $i->{'OpeningBalance'} = $account->{'OpeningBalance'};
+ # And closing balance
+ $i->{'ClosingBalance'} = $account->{'ClosingBalance'};
+
+ # Check balance
+ my $balance = Math::BigFloat->new();
+ $balance->precision(-2);
+ $balance->badd($account->{'Balance'});
+ # Check if its negative or positive
+ if ($balance->is_neg()) {
+ $balance->babs();
+ $i->{'CreditAmount'} = sprintf('%.2f',$balance->bstr());
+ } else {
+ $i->{'DebitAmount'} = sprintf('%.2f',$balance->bstr());
+ }
+
+ $i->{'ReportWriterCategoryCode'} = $account->{'RwCatCode'};
+
+ # If we have children, process them
+ if ($account->{'Children'}) {
+ # Loop with child accounts
+ foreach my $caccount (@{$account->{'Children'}}) {
+ # Process
+ my $citem = processItem($caccount);
+ # Add to child list
+ push(@{$i->{'Children'}},$citem);
+ }
+ }
+
+ # File balance under account number
+ $resdata->{'AccountBalances'}{$i->{'Number'}} = $i;
+
+ return $i;
+ }
+
+ # Process top level item
+ my $pitem = processItem($item);
+
+ # File under report write category code
+ push(@{$resdata->{'ReportWriterCategoryToAccounts'}{$pitem->{'ReportWriterCategoryCode'}}},$pitem);
+ }
+
+ # Load report write categories
+ $entries = wiaflos::server::GL::getGLRwCats();
+ if (ref($entries) ne "ARRAY") {
+ setError(wiaflos::server::GL::Error());
+ return $entries;
+ }
+ foreach my $item (@{$entries}) {
+ $resdata->{'ReportWriterCategories'}{$item->{'Code'}} = $item;
+ }
+
+ return $resdata;
+ }
+
+
+ # Reporting API function to retrieve account entries
+ sub api_account_entries
+ {
+ my $resdata;
+
+ # Get account data
+ 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;
+ }
+ $resdata->{'Account'} = $account;
+
+ $tmp = undef;
+ $tmp->{'AccountID'} = $account->{'ID'};
+ $tmp->{'StartDate'} = $detail->{'StartDate'};
+ $tmp->{'EndDate'} = $detail->{'EndDate'};
+ $tmp->{'BalanceBroughtForward'} = 1;
+ my $res = wiaflos::server::GL::getGLAccountEntries($tmp);
+ if (ref($res) ne "ARRAY") {
+# FIXME
+ return;
+ }
+
+ # Sort so our balance makes sense
+ @{$res} = sort { $a->{'TransactionDate'} cmp $b->{'TransactionDate'} } @{$res};
+
+ # Work out closing balance
+ my $closingBalance = Math::BigFloat->new();
+ $closingBalance->precision(-2);
+
+ # Fetch items
+ foreach my $item (@{$res}) {
+ my $entry;
+
+ $entry->{'ID'} = $item->{'ID'};
+ $entry->{'GLTransactionID'} = $item->{'GLTransactionID'};
+ $entry->{'Reference'} = defined($item->{'Reference'}) ? $item->{'Reference'} : $item->{'TransactionReference'};
+ $entry->{'Amount'} = $item->{'Amount'};
+ # Calculate balance so far
+ $closingBalance->badd($entry->{'Amount'});
+ # Make it pretty
+ $entry->{'Balance'} = sprintf('%.2f',$closingBalance->bstr());
+
+ $entry->{'TransactionDate'} = $item->{'TransactionDate'};
+ $entry->{'TransactionReference'} = $item->{'TransactionReference'};
+
+ push(@{$resdata->{'Entries'}},$entry);
+ }
+ # Generate closing balance entry
+ my $entry;
+ $entry->{'ID'} = -99;
+ $entry->{'TransactionID'} = -99;
+ $entry->{'Reference'} = "* Closing Balance *";
+ $entry->{'Balance'} = sprintf('%.2f',$closingBalance->bstr());
+ $entry->{'TransactionDate'} = $detail->{'EndDate'};
+ push(@{$resdata->{'Entries'}},$entry);
+
+ # Sort results
+ @{$resdata->{'Entries'}} = sort { $a->{'TransactionDate'} cmp $b->{'TransactionDate'} } @{$resdata->{'Entries'}};
+
+ return $resdata;
+ }
+
+
# Verify Template
if (!defined($detail->{'Template'}) || $detail->{'Template'} eq "") {
setError("Template was not provided");
@@ -245,105 +414,39 @@
return ERR_PARAM;
}
- # GL search criteria
- my $search;
- $search->{'StartDate'} = $detail->{'StartDate'};
- $search->{'EndDate'} = $detail->{'EndDate'};
- my $entries = getAccountBalances(REPORT_BALANCE_BF,$search);
- if (ref $entries ne "ARRAY") {
- setError(Error());
- return $entries;
- }
+# TODO - Generic
+
+
# Pull in config
my $config = wiaflos::server::config::getConfig();
+
+# TODO - Customize per report?
+
# Check if subject was overridden
my $subject = (defined($detail->{'Subject'}) && $detail->{'Subject'} ne "") ? $detail->{'Subject'} : "Chart of accounts";
# Build array of stuff we can use
- our $vars = {
+ my $vars = {
'WiaflosString' => $GENSTRING,
+ # API
+ 'api_account_balances' => \&api_account_balances,
+ 'api_account_entries' => \&api_account_entries,
+
+# TODO - Optional??
+
# Client
'StartDate' => defined($detail->{'StartDate'}) ? $detail->{'StartDate'} : "-",
'EndDate' => defined($detail->{'EndDate'}) ? $detail->{'EndDate'} : "CURRENT",
};
- # Load invoice line items
- foreach my $item (@{$entries}) {
- # Process item
- sub processItem
- {
- my $account = shift;
- my $i;
+# TODO - Generic?
- # Fix some stuff up
- $i->{'Number'} = $account->{'Number'};
- $i->{'Name'} = $account->{'Name'};
-
- # Pull in the normal balances
- $i->{'DebitBalance'} = $account->{'DebitBalance'};
- $i->{'CreditBalance'} = $account->{'CreditBalance'};
- $i->{'Balance'} = $account->{'Balance'};
- # Check if we need the opening balances
- $i->{'OpeningDebitBalance'} = $account->{'OpeningDebitBalance'};
- $i->{'OpeningCreditBalance'} = $account->{'OpeningCreditBalance'};
- $i->{'OpeningBalance'} = $account->{'OpeningBalance'};
- # And closing balance
- $i->{'ClosingBalance'} = $account->{'ClosingBalance'};
-
- # Check balance
- my $balance = Math::BigFloat->new();
- $balance->precision(-2);
- $balance->badd($account->{'Balance'});
- # Check if its negative or positive
- if ($balance->is_neg()) {
- $balance->babs();
- $i->{'CreditAmount'} = sprintf('%.2f',$balance->bstr());
- } else {
- $i->{'DebitAmount'} = sprintf('%.2f',$balance->bstr());
- }
-
- $i->{'ReportWriterCategoryCode'} = $account->{'RwCatCode'};
-
- # If we have children, process them
- if ($account->{'Children'}) {
- # Loop with child accounts
- foreach my $caccount (@{$account->{'Children'}}) {
- # Process
- my $citem = processItem($caccount);
- # Add to child list
- push(@{$i->{'Children'}},$citem);
- }
- }
-
- # File balance under account number
- $vars->{'AccountBalances'}{$i->{'Number'}} = $i;
-
- return $i;
- }
-
- # Process top level item
- my $pitem = processItem($item);
-
- # File under report write category code
- push(@{$vars->{'ReportWriterCategoryToAccounts'}{$pitem->{'ReportWriterCategoryCode'}}},$pitem);
- }
-
- # Load report write categories
- $entries = wiaflos::server::GL::getGLRwCats();
- if (ref($entries) ne "ARRAY") {
- setError(wiaflos::server::GL::Error());
- return $entries;
- }
- foreach my $item (@{$entries}) {
- $vars->{'ReportWriterCategories'}{$item->{'Code'}} = $item;
- }
-
# Set template to use
my $template = $detail->{'Template'};
More information about the wiaflos-devel
mailing list