[wiaflos-devel] COMMIT - r267 - in trunk/wiaflos: client/cmdline server
svn at linuxrulz.org
svn at linuxrulz.org
Tue Dec 30 06:26:35 GMT 2008
Author: nkukard
Date: 2008-12-30 06:26:35 +0000 (Tue, 30 Dec 2008)
New Revision: 267
Modified:
trunk/wiaflos/client/cmdline/Reporting.pm
trunk/wiaflos/server/Reporting.pm
Log:
* Added job control to reporting and added a background option to the commandline interface
Modified: trunk/wiaflos/client/cmdline/Reporting.pm
===================================================================
--- trunk/wiaflos/client/cmdline/Reporting.pm 2008-12-30 06:23:07 UTC (rev 266)
+++ trunk/wiaflos/client/cmdline/Reporting.pm 2008-12-30 06:26:35 UTC (rev 267)
@@ -54,7 +54,7 @@
MenuItem => "Send",
Regex => "send",
Desc => "Send report",
- Help => 'send template="<template>" start="<yyyy-mm-dd>" [account="<gl_account>"] [subject="<subject>"] sendto="<email[:addy1,addy2...] or file:filename>"',
+ Help => 'send template="<template>" start="<yyyy-mm-dd>" [account="<gl_account>"] [subject="<subject>"] [background="<1|y|yes>"] sendto="<email[:addy1,addy2...] or file:filename>"',
Function => \&send,
},
],
@@ -197,6 +197,7 @@
$detail->{'SendTo'} = $parms->{'sendto'};
$detail->{'GLAccountNumber'} = $parms->{'account'};
$detail->{'Subject'} = $parms->{'subject'};
+ $detail->{'Background'} = $parms->{'background'};
my $res = soapCall($OUT,"Reporting","sendReport",$detail);
if ($res->{'Result'} != RES_OK) {
soapDebug($OUT,$res);
Modified: trunk/wiaflos/server/Reporting.pm
===================================================================
--- trunk/wiaflos/server/Reporting.pm 2008-12-30 06:23:07 UTC (rev 266)
+++ trunk/wiaflos/server/Reporting.pm 2008-12-30 06:26:35 UTC (rev 267)
@@ -31,6 +31,7 @@
use wiaflos::server::dblayer;
use wiaflos::server::templating;
use wiaflos::server::GL;
+use wiaflos::server::jobs;
use Math::BigFloat;
@@ -234,6 +235,7 @@
# @li Subject - Optional Subject of the report
# @li StartDate - Optional statement start date
# @li EndDate - Optional statement end date
+# @li Background - Optional, allow this report to be sent in the background
#
# @returns RES_OK on success, < 0 otherwise
sub sendReport
@@ -390,6 +392,81 @@
}
+ # Reporting API function to retrieve GL transactions
+ sub api_gl_transactions
+ {
+ my $resdata = ();
+
+ # Get account data
+ my $accounts = wiaflos::server::GL::getGLAccounts();
+ if (ref($accounts) ne "ARRAY") {
+ wiaflos::server::templating::abort('api_gl_transactions',$accounts);
+ }
+ # Sort based on account number
+ @{$accounts} = sort { $a->{'Number'} cmp $b->{'Number'} } @{$accounts};
+ foreach my $account (@{$accounts}) {
+
+ my $aitem;
+ $aitem->{'ID'} = $account->{'ID'};
+ $aitem->{'Number'} = $account->{'Number'};
+ $aitem->{'Name'} = $account->{'Name'};
+
+ # Grab transactions
+ my $tmp;
+ $tmp->{'AccountID'} = $account->{'ID'};
+ $tmp->{'StartDate'} = $detail->{'StartDate'};
+ $tmp->{'EndDate'} = $detail->{'EndDate'};
+ my $transactions = wiaflos::server::GL::getGLTransactions($tmp);
+ # Sort based on transaction date
+ @{$transactions} = sort { $a->{'TransactionDate'} cmp $b->{'TransactionDate'} } @{$transactions};
+ # Loop and process
+ foreach my $transaction (@{$transactions}) {
+ # Only report on posted transactions
+ next if (!$transaction->{'Posted'});
+
+ # Setup our transaction item
+ my $titem;
+ $titem->{'ID'} = $transaction->{'ID'};
+ $titem->{'TransactionDate'} = $transaction->{'TransactionDate'};
+ $titem->{'Reference'} = $transaction->{'Reference'};
+
+ # Pull in transaction entries
+ $tmp = undef;
+ $tmp->{'ID'} = $transaction->{'ID'};
+ my $transactionEntries = wiaflos::server::GL::getGLTransactionEntries($tmp);
+ # Loop and process
+ foreach my $transactionEntry (@{$transactionEntries}) {
+ my $eitem;
+
+ # Start creating our transaction entry
+ $eitem->{'ID'} = $transactionEntry->{'ID'};
+ $eitem->{'GLAccountID'} = $transactionEntry->{'GLAccountID'};
+ $eitem->{'GLAccountName'} = $transactionEntry->{'GLAccountName'};
+ $eitem->{'GLAccountNumber'} = $transactionEntry->{'GLAccountNumber'};
+
+ # Clean up amount
+ my $cleanAmount = Math::BigFloat->new($transactionEntry->{'Amount'});
+ $cleanAmount->precision(-2);
+ $eitem->{'Amount'} = $cleanAmount->bstr();
+
+ $eitem->{'Reference'} = $transactionEntry->{'Reference'};
+
+ # Add entry to transaction
+ push(@{$titem->{'Entries'}},$eitem);
+ }
+ # Add transaction to account
+ push(@{$aitem->{'Transactions'}},$titem);
+ }
+ # Add account to return data
+ push(@{$resdata},$aitem);
+
+# use Data::Dumper; print(STDERR Dumper($aitem));
+ }
+
+ return $resdata;
+ }
+
+
# Reporting API function to retrieve account entries
sub api_account_entries
{
@@ -667,6 +744,8 @@
return ERR_PARAM;
}
+ my $background = $detail->{'Background'};
+
# Pull in config
my $config = wiaflos::server::config::getConfig();
@@ -682,7 +761,9 @@
'API_RPT_BALANCE_BF' => REPORT_BALANCE_BF,
'api_account_entries' => \&api_account_entries,
+
'api_inventory_stock_balances' => \&api_inventory_stock_balances,
+ 'api_gl_transactions' => \&api_gl_transactions,
'api_variable_new' => \&api_variable_new,
'api_variable_add' => \&api_variable_add,
@@ -699,8 +780,21 @@
# Client
'StartDate' => defined($detail->{'StartDate'}) ? $detail->{'StartDate'} : "-",
'EndDate' => defined($detail->{'EndDate'}) ? $detail->{'EndDate'} : "CURRENT",
+
};
+ # Check if we must background this...
+ if ($background) {
+ my $job = wiaflos::server::jobs::createJob();
+ if ($job < RES_OK) {
+ setError(wiaflos::jobs::Error());
+ return $job;
+ } elsif ($job > RES_OK) {
+ # Parent job
+ return RES_OK;
+ }
+ }
+
# Set template to use
my $template = $detail->{'Template'};
@@ -708,6 +802,7 @@
if ($detail->{'SendTo'} =~ /^file:(\S+)/i) {
my $filename = $1;
+ wiaflos::server::jobs::setStatus("Loading report template '$template'...");
# Load template
my $res = loadTemplate($template,$vars,$filename);
if (!$res) {
@@ -743,6 +838,7 @@
my $message_template = $config->{'reports'}{'email_message_template'};
my $emailBody = "";
if (defined($message_template) && $message_template ne "") {
+ wiaflos::server::jobs::setStatus("Loading message template '$message_template'...");
# Variables for our template
my $vars2 = {
'ReportFilename' => $reportFilename,
@@ -758,6 +854,8 @@
$emailBody =~ s/(?<!\r)\n/\r\n/sg; # Sanitize eol for crypt-gpg
}
+ wiaflos::server::jobs::setStatus("Loading report template '$template'...");
+
# This is our entire report
my $reportData = "";
my $res = loadTemplate($template,$vars,\$reportData);
@@ -771,6 +869,7 @@
my $use_gpg_key = $config->{'reports'}{'use_gpg_key'};
my $sign;
if (defined($use_gpg_key) && $use_gpg_key ne "") {
+ wiaflos::server::jobs::setStatus("Signing report...");
# Setup GnuPG
my $gpg = new Crypt::GPG;
$gpg->gpgbin('/usr/bin/gpg');
@@ -785,6 +884,7 @@
}
}
+ wiaflos::server::jobs::setStatus("Composing mail...");
# Create message
my $msg = MIME::Lite->new(
From => $config->{'reports'}{'email_from'},
@@ -822,6 +922,7 @@
);
}
+ wiaflos::server::jobs::setStatus("Sending mail...");
# Send email
my @SMTPParams;
if (!(my $res = $msg->send("smtp",$server))) {
@@ -834,8 +935,10 @@
return ERR_PARAM;
}
+ wiaflos::server::jobs::setStatus("Done");
- return RES_OK;
+# return RES_OK;
+ exit 0;
}
More information about the wiaflos-devel
mailing list