Commit 1df970ef authored by Nigel Kukard's avatar Nigel Kukard
Browse files

getGLAccountEntries:

- Added support for end date and optional bbf
- Added support to Clients & Suppliers for end date and optional bbf
- Force bbf for Statements
parent a9a44a2f
......@@ -445,9 +445,21 @@ sub removeClient {
}
# Return list of client GL account entries
# Parameters:
# AccountNumber - GL account number
## @fn getClientGLAccountEntries($data)
# Return list of supplier GL account entries
#
# @param data Parameter hash ref
# @li Code Supplier code
# @li StartDate Start date
# @li EndDate End date
#
# @returns Array ref of hash refs
# @li ID ID of GL account entry
# @li TransactionID Transaction ID
# @li Reference GL account entry reference
# @li TransactionDate Transaction date
# @li Amount Amount
# @li TransactionReference Transaction reference
sub getClientGLAccountEntries {
my (undef,$data) = @_;
......@@ -462,6 +474,9 @@ sub getClientGLAccountEntries {
# Grab and sanitize data
my $detail;
$detail->{'Code'} = $data->{'Code'};
$detail->{'StartDate'} = $data->{'StartDate'};
$detail->{'EndDate'} = $data->{'EndDate'};
$detail->{'BalanceBroughtForward'} = 1;
my $rawData = wiaflos::server::Clients::getGLAccountEntries($detail);
if (ref $rawData ne "ARRAY") {
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::GL::Error());
......
......@@ -288,9 +288,22 @@ sub getGLTransactionEntries {
}
## @fn getGLAccountEntries($data)
# Return list of GL account entries
# Parameters:
# AccountNumber - GL account number
#
# @param data Parameter hash ref
# @li AccountNumber Supplier code
# @li StartDate Start date
# @li EndDate End date
# @li BalanceBroughtForward Flag to indicate if we must generate a BBF
#
# @returns Array ref of hash refs
# @li ID ID of GL account entry
# @li TransactionID Transaction ID
# @li Reference GL account entry reference
# @li TransactionDate Transaction date
# @li Amount Amount
# @li TransactionReference Transaction reference
sub getGLAccountEntries {
my (undef,$data) = @_;
......@@ -305,6 +318,9 @@ sub getGLAccountEntries {
# Grab and sanitize data
my $detail;
$detail->{'AccountNumber'} = $data->{'AccountNumber'};
$detail->{'StartDate'} = $data->{'StartDate'};
$detail->{'EndDate'} = $data->{'EndDate'};
$detail->{'BalanceBroughtForward'} = $data->{'BalanceBroughtForward'};
my $rawData = wiaflos::server::GL::getGLAccountEntries($detail);
if (ref $rawData ne "ARRAY") {
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::GL::Error());
......
......@@ -433,9 +433,21 @@ sub removeSupplier {
}
## @fn getSupplierGLAccountEntries($data)
# Return list of supplier GL account entries
# Parameters:
# AccountNumber - GL account number
#
# @param data Parameter hash ref
# @li Code Supplier code
# @li StartDate Start date
# @li EndDate End date
#
# @returns Array ref of hash refs
# @li ID ID of GL account entry
# @li TransactionID Transaction ID
# @li Reference GL account entry reference
# @li TransactionDate Transaction date
# @li Amount Amount
# @li TransactionReference Transaction reference
sub getSupplierGLAccountEntries {
my (undef,$data) = @_;
......@@ -450,6 +462,9 @@ sub getSupplierGLAccountEntries {
# Grab and sanitize data
my $detail;
$detail->{'Code'} = $data->{'Code'};
$detail->{'StartDate'} = $data->{'StartDate'};
$detail->{'EndDate'} = $data->{'EndDate'};
$detail->{'BalanceBroughtForward'} = 1;
my $rawData = wiaflos::server::Suppliers::getGLAccountEntries($detail);
if (ref $rawData ne "ARRAY") {
return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::GL::Error());
......
......@@ -91,7 +91,7 @@ our $pluginInfo = {
MenuItem => "ShowGL",
Regex => "showgl",
Desc => "Show GL account entries",
Help => 'showGL client="<supplier code>"',
Help => 'showGL client="<supplier code>" [start="<start date>"] [end="<end date>"] [balance-brought-forward="<y|n>"]',
Function => \&showGLAccountEntries,
},
],
......@@ -408,6 +408,9 @@ sub showGLAccountEntries
}
my $detail;
$detail->{'Code'} = $parms->{'client'};
$detail->{'StartDate'} = $parms->{'start'};
$detail->{'EndDate'} = $parms->{'end'};
$detail->{'BalanceBroughtForward'} = $parms->{'balance-brought-forward'};
my $res = soapCall($OUT,"Clients","getClientGLAccountEntries",$detail);
if ($res->{'Result'} == RES_OK) {
......
......@@ -52,7 +52,7 @@ our $pluginInfo = {
MenuItem => "Show",
Regex => "show",
Desc => "Show an account",
Help => 'show account="<account number>"',
Help => 'show account="<account number>" [start="<start date>"] [end="<end date>"] [balance-brought-forward="<y|n>"]',
Function => \&show,
},
{
......@@ -187,6 +187,9 @@ sub show
}
my $detail;
$detail->{'AccountNumber'} = $parms->{'account'};
$detail->{'StartDate'} = $parms->{'start'};
$detail->{'EndDate'} = $parms->{'end'};
$detail->{'BalanceBroughtForward'} = $parms->{'balance-brought-forward'};
my $res = soapCall($OUT,"GL","getGLAccountEntries",$detail);
if ($res->{'Result'} == RES_OK) {
......
......@@ -91,7 +91,7 @@ our $pluginInfo = {
MenuItem => "ShowGL",
Regex => "showgl",
Desc => "Show GL account entries",
Help => 'showGL supplier="<supplier code>"',
Help => 'showGL supplier="<supplier code>" [start="<start date>"] [end="<end date>"] [balance-brought-forward="<y|n>"]',
Function => \&showGLAccountEntries,
},
],
......@@ -373,6 +373,9 @@ sub showGLAccountEntries
}
my $detail;
$detail->{'Code'} = $parms->{'supplier'};
$detail->{'StartDate'} = $parms->{'start'};
$detail->{'EndDate'} = $parms->{'end'};
$detail->{'BalanceBroughtForward'} = $parms->{'balance-brought-forward'};
my $res = soapCall($OUT,"Suppliers","getSupplierGLAccountEntries",$detail);
if ($res->{'Result'} == RES_OK) {
......
......@@ -908,9 +908,16 @@ sub removeClient
## @fn getGLAccountEntries($detail)
# Function to return a clients GL account entries
# Parameters:
# Code
#
# @param detail Parameter hash ref
# @li Code Client code
# @li StartDate Optional start date
# @li EndDate Optional end date
# @li BalanceBroughtForward Optional balance brought forward
#
# @returns GL account entries, @see wiaflos::server::GL::getGLAccountEntries
sub getGLAccountEntries
{
my ($detail) = @_;
......@@ -934,6 +941,9 @@ sub getGLAccountEntries
# Build our request
$tmp = undef;
$tmp->{'AccountID'} = $client->{'GLAccountID'};
$tmp->{'StartDate'} = $detail->{'StartDate'};
$tmp->{'EndDate'} = $detail->{'EndDate'};
$tmp->{'BalanceBroughtForward'} = $detail->{'BalanceBroughtForward'};
# Get results
my $res = wiaflos::server::GL::getGLAccountEntries($tmp);
......
......@@ -136,9 +136,9 @@ sub GLAccountCodeExists
# If we have a parent use it
if (defined($parentID) && $parentID ne "") {
$extra_sql .= " AND ParentGLAccountID = ".DBQuote($parentID);
$extra_sql .= " AND ParentGLAccountID = ".DBQuote($parentID);
} else {
$extra_sql .= " AND ParentGLAccountID IS NULL";
$extra_sql .= " AND ParentGLAccountID IS NULL";
}
# Select account count
......@@ -978,11 +978,23 @@ sub getGLTransactionEntries
}
## @fn getGLAccountEntries($data)
# Return an array account entries
# Optional params:
# AccountNumber - Account number
# AccountID - Account id
# StartDate - Start date
#
# @param data Parameter hash ref
# @li AccountID Optional account ID
# @li AccountNumber Optional account number
# @li StartDate Optional start date
# @li EndDate Optional end date
# @li BalanceBroughtForward Optional flag to indicate if we must generate a balance brought forward entry
#
# @returns Array ref of hash refs
# @li ID GL entry ID
# @li TransactionID GL transaction ID
# @li Reference GL entry reference
# @li Amount Amount
# @li TransactionDate Transaction date
# @li TransactionReference Transaction reference
sub getGLAccountEntries
{
my ($data) = @_;
......@@ -1014,47 +1026,60 @@ sub getGLAccountEntries
return ERR_PARAM;
}
# Extra SQL we may need
my $extraSQL = "";
# Check if we must use the start date
if (defined($data->{'StartDate'}) && $data->{'StartDate'} ne "") {
# Return list of transaction entries before the start date, these we add-up and generate a BBF (balance brought forward)
my $sth = DBSelect("
SELECT
gl_entries.Amount
FROM
gl_entries, gl_transactions
WHERE
gl_entries.GLAccountID = ".DBQuote($GLAccID)."
AND gl_transactions.ID = gl_entries.GLTransactionID
AND gl_transactions.Posted = '1'
AND gl_transactions.TransactionDate < ".DBQuote($data->{'StartDate'})."
");
if (!$sth) {
setError(wiaflos::server::dblayer::Error());
return ERR_DB;
}
# Generate balance brought forward amount
my $bbfAmount = Math::BigFloat->new();
$bbfAmount->precision(-2);
while (my $row = $sth->fetchrow_hashref()) {
$bbfAmount->badd($row->{'Amount'});
}
# Check if we need to generate a BBF
if (defined($data->{'BalanceBroughtForward'}) && (
$data->{'BalanceBroughtForward'} =~ /^y(?:es)?$/i || $data->{'BalanceBroughtForward'} eq "1"
)
) {
# Return list of transaction entries before the start date, these we add-up and generate a BBF (balance brought forward)
my $sth = DBSelect("
SELECT
gl_entries.Amount
FROM
gl_entries, gl_transactions
WHERE
gl_entries.GLAccountID = ".DBQuote($GLAccID)."
AND gl_transactions.ID = gl_entries.GLTransactionID
AND gl_transactions.Posted = '1'
AND gl_transactions.TransactionDate < ".DBQuote($data->{'StartDate'})."
");
if (!$sth) {
setError(wiaflos::server::dblayer::Error());
return ERR_DB;
}
DBFreeRes($sth);
# Generate balance brought forward amount
my $bbfAmount = Math::BigFloat->new();
$bbfAmount->precision(-2);
while (my $row = $sth->fetchrow_hashref()) {
$bbfAmount->badd($row->{'Amount'});
}
DBFreeRes($sth);
# Generate entry
my $entry;
$entry->{'ID'} = -99;
$entry->{'TransactionID'} = -99;
$entry->{'Reference'} = "* Balance Brought Forward *";
$entry->{'Amount'} = $bbfAmount->bstr();
$entry->{'TransactionDate'} = $data->{'StartDate'};
# Generate entry
my $entry;
$entry->{'ID'} = -99;
$entry->{'TransactionID'} = -99;
$entry->{'Reference'} = "* Balance Brought Forward *";
$entry->{'Amount'} = $bbfAmount->bstr();
$entry->{'TransactionDate'} = $data->{'StartDate'};
push(@entries,$entry);
push(@entries,$entry);
}
$extraSQL .= " AND gl_transactions.TransactionDate >= ".DBQuote($data->{'StartDate'});
}
$extraSQL = "AND gl_transactions.TransactionDate >= ".DBQuote($data->{'StartDate'});
# Check if we must use an end date
if (defined($data->{'EndDate'}) && $data->{'EndDate'} ne "") {
$extraSQL .= " AND gl_transactions.TransactionDate <= ".DBQuote($data->{'EndDate'});
}
# Return list of transaction entries
......
......@@ -66,10 +66,21 @@ sub Error
}
# Return an array account entries
# Parameters:
# ClientCode - Client code
# StartDate - Start date
## @fn getStatement
# Function to return a client account statement
#
# @param detail Parameter hash ref
# @li ClientCode Client code
# @li StartDate Optional statement start date
# @li EndDate Optional statement end date
#
# @returns Hash ref of account transactions
# @li ID Entry ID
# @li GLTransactionID GL account transaction ID
# @li Reference Entry reference
# @li Amount Amount
# @li TransactionDate Transaction date
# @li TransactionReference Transaction reference
sub getStatement
{
my ($detail) = @_;
......@@ -94,6 +105,8 @@ sub getStatement
$tmp = undef;
$tmp->{'AccountID'} = $client->{'GLAccountID'};
$tmp->{'StartDate'} = $detail->{'StartDate'};
$tmp->{'EndDate'} = $detail->{'EndDate'};
$tmp->{'BalanceBroughtForward'} = 1;
my $res = wiaflos::server::GL::getGLAccountEntries($tmp);
# Fetch items
......
......@@ -954,9 +954,16 @@ sub removeSupplier
## @fn getGLAccountEntries($detail)
# Function to return a suppliers GL account entries
# Parameters:
# Code
#
# @param detail Parameter hash ref
# @li Code Supplier code
# @li StartDate Optional start date
# @li EndDate Optional end date
# @li BalanceBroughtForward Optional balance brought forward
#
# @returns GL account entries, @see wiaflos::server::GL::getGLAccountEntries
sub getGLAccountEntries
{
my ($detail) = @_;
......@@ -980,6 +987,9 @@ sub getGLAccountEntries
# Build our request
$tmp = undef;
$tmp->{'AccountID'} = $supplier->{'GLAccountID'};
$tmp->{'StartDate'} = $detail->{'StartDate'};
$tmp->{'EndDate'} = $detail->{'EndDate'};
$tmp->{'BalanceBroughtForward'} = $detail->{'BalanceBroughtForward'};
# Get results
my $res = wiaflos::server::GL::getGLAccountEntries($tmp);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment