[wiaflos-devel] COMMIT - r280 - in trunk: database wiaflos/client/cmdline wiaflos/server
svn at linuxrulz.org
svn at linuxrulz.org
Fri May 15 08:41:21 GMT 2009
Author: nkukard
Date: 2009-05-15 08:41:21 +0000 (Fri, 15 May 2009)
New Revision: 280
Modified:
trunk/database/schema.tsql
trunk/wiaflos/client/cmdline/GL.pm
trunk/wiaflos/server/GL.pm
Log:
* Added support for transaction types
Modified: trunk/database/schema.tsql
===================================================================
--- trunk/database/schema.tsql 2009-02-16 16:21:24 UTC (rev 279)
+++ trunk/database/schema.tsql 2009-05-15 08:41:21 UTC (rev 280)
@@ -249,6 +249,8 @@
Reference VARCHAR(255) NOT NULL,
+ Type BIGINT NOT NULL DEFAULT '1', /* 1 - default visible, 2 - year end */
+
Posted SMALLINT NOT NULL DEFAULT '0'
Modified: trunk/wiaflos/client/cmdline/GL.pm
===================================================================
--- trunk/wiaflos/client/cmdline/GL.pm 2009-02-16 16:21:24 UTC (rev 279)
+++ trunk/wiaflos/client/cmdline/GL.pm 2009-05-15 08:41:21 UTC (rev 280)
@@ -52,7 +52,7 @@
MenuItem => "Show",
Regex => "show",
Desc => "Show an account",
- Help => 'show account="<account number>" [start="<start date>"] [end="<end date>"] [balance-brought-forward="<y|n>"]',
+ Help => 'show account="<account number>" [start="<start date>"] [end="<end date>"] [balance-brought-forward="<y|n>"] [type="transaction type bitmask"]',
Function => \&show,
},
{
@@ -71,7 +71,7 @@
MenuItem => "Create",
Regex => "create",
Desc => "Create transaction",
- Help => 'create date="<YYYY-MM-DD>" reference="<reference>"',
+ Help => 'create date="<YYYY-MM-DD>" reference="<reference>" type="<type>"',
Function => \&createTransaction,
},
{
@@ -190,13 +190,14 @@
$detail->{'StartDate'} = $parms->{'start'};
$detail->{'EndDate'} = $parms->{'end'};
$detail->{'BalanceBroughtForward'} = $parms->{'balance-brought-forward'};
+ $detail->{'Type'} = $parms->{'type'};
my $res = soapCall($OUT,"GL","getGLAccountEntries",$detail);
if ($res->{'Result'} == RES_OK) {
- print $OUT swrite(<<'END', "ID", "Date", "Ref", "Amount", "Balance");
-+===========+============+================================================================================+==============+================+
-| @|||||||| | @||||||||| | @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||||||||| | @||||||||||||| |
-+===========+============+================================================================================+==============+================+
+ print $OUT swrite(<<'END', "ID", "Date", "Ref", "Type", "Amount", "Balance");
++===========+============+================================================================================+=========+==============+================+
+| @|||||||| | @||||||||| | @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @|||||| | @||||||||||| | @||||||||||||| |
++===========+============+================================================================================+=========+==============+================+
END
# Sort data
my @sorted = sort {$a->{'TransactionDate'} cmp $b->{'TransactionDate'}} @{$res->{'Data'}};
@@ -205,12 +206,12 @@
foreach my $entry (@sorted) {
$balance->badd($entry->{'Amount'});
- print $OUT swrite(<<'END', $entry->{'TransactionID'}, $entry->{'TransactionDate'}, $entry->{'Reference'} ? $entry->{'Reference'} : $entry->{'TransactionReference'}, sprintf('%8.2f',$entry->{'Amount'}),sprintf('%8.2f',$balance));
-| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>>>> | @>>>>>>>>>>>>> |
+ print $OUT swrite(<<'END', $entry->{'TransactionID'}, $entry->{'TransactionDate'}, $entry->{'Reference'} ? $entry->{'Reference'} : $entry->{'TransactionReference'}, $entry->{'Type'}, sprintf('%8.2f',$entry->{'Amount'}),sprintf('%8.2f',$balance));
+| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @|||||| | @>>>>>>>>>>> | @>>>>>>>>>>>>> |
END
}
print $OUT swrite(<<'END');
-+===========+============+================================================================================+==============+================+
++===========+============+================================================================================+=========+==============+================+
END
} else {
soapDebug($OUT,$res);
@@ -240,6 +241,7 @@
my $detail;
$detail->{'Date'} = $parms->{'date'};
$detail->{'Reference'} = $parms->{'reference'};
+ $detail->{'Type'} = $parms->{'type'};
my $res = soapCall($OUT,"GL","createGLTransaction",$detail);
if ($res->{'Result'} == RES_OK) {
# Save this ID
@@ -414,18 +416,18 @@
my $res = soapCall($OUT,"GL","getGLTransactions");
if ($res->{'Result'} == RES_OK) {
- print $OUT swrite(<<'END', "ID", "TransDate", "Ref", "Posted");
-+===========+============+=======================================================================================================+========+
-| @|||||||| | @||||||||| | @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||| |
-+===========+============+=======================================================================================================+========+
+ print $OUT swrite(<<'END', "ID", "TransDate", "Ref", "Type", "Posted");
++===========+============+==============================================================================================+========+========+
+| @|||||||| | @||||||||| | @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||| | @||||| |
++===========+============+==============================================================================================+========+========+
END
foreach my $tran (@{$res->{'Data'}}) {
print $OUT swrite(<<'END', $tran->{'ID'}, $tran->{'TransactionDate'}, $tran->{'Reference'}, $tran->{'Posted'});
-| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<< |
+| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @||||| | @<<<<< |
END
}
print $OUT swrite(<<'END');
-+===========+============+=======================================================================================================+========+
++===========+============+==============================================================================================+========+========+
END
} else {
soapDebug($OUT,$res);
Modified: trunk/wiaflos/server/GL.pm
===================================================================
--- trunk/wiaflos/server/GL.pm 2009-02-16 16:21:24 UTC (rev 279)
+++ trunk/wiaflos/server/GL.pm 2009-05-15 08:41:21 UTC (rev 280)
@@ -32,7 +32,12 @@
use Math::BigFloat;
+use constant {
+ GL_TRANSTYPE_NORMAL => 1,
+ GL_TRANSTYPE_YEAREND => 2
+};
+
# Our current error message
my $error = "";
@@ -96,6 +101,7 @@
$item->{'ID'} = $rawData->{'ID'};
$item->{'TransactionDate'} = $rawData->{'TransactionDate'};
$item->{'Reference'} = $rawData->{'Reference'};
+ $item->{'Type'} = $rawData->{'Type'};
$item->{'Posted'} = $rawData->{'Posted'};
return $item;
@@ -641,6 +647,7 @@
# @li AccountID Limit transactions to those relating to this account
# @li StartDate Optional start date
# @li EndDate Optional end date
+# @li Type Optional transaction type
#
# @returns Array ref of hash refs
# @li ID GL entry ID
@@ -676,6 +683,12 @@
$extraSQL .= "AND gl_transactions.TransactionDate <= ".DBQuote($data->{'EndDate'})." ";
}
+ # Check if we're filtering on type
+ my $typeFilter = 1;
+ if (defined($data->{'Type'}) && $data->{'Type'} ne "") {
+ $typeFilter = $data->{'Type'};
+ }
+
# Return list of GL transactions
my $sth = DBSelect("
SELECT
@@ -695,6 +708,11 @@
# Fetch rows
while (my $row = $sth->fetchrow_hashref()) {
+ # Check filter, if this is not one of our items, continue
+ if ( ($typeFilter & $row->{'Type'}) != $row->{'Type'} ) {
+ next;
+ }
+
my $transaction = sanitizeRawGLTransactionItem($row);
push(@transactions,$transaction);
@@ -749,15 +767,24 @@
}
+## @fn createGLTransaction($data)
# Create GL transaction
-# Parameters:
-# Date - Transaction date
-# Reference - Transaction reference
+#
+# @param data Parameter hash ref
+# @li Date Date of transaction
+# @li Reference Reference of transaction
+# @li Type Optional transaction type
+#
+# @returns Transaction ID
sub createGLTransaction
{
my ($detail) = @_;
+ # Extra SQL we may need
+ my $extraColumns = "";
+ my $extraValues = "";
+
# Verify date
if (!defined($detail->{'Date'}) || $detail->{'Date'} eq "") {
setError("No date provided for GL transaction");
@@ -770,14 +797,21 @@
return ERR_PARAM;
}
+ # Verify type
+ if (defined($detail->{'Type'}) && $detail->{'Type'} ne "") {
+ $extraColumns .= ",Type";
+ $extraValues .= ",".DBQuote($detail->{'Type'});
+ }
+
# Create GL transaction
my $sth = DBDo("
INSERT INTO gl_transactions
- (TransactionDate,Reference)
+ (TransactionDate,Reference$extraColumns)
VALUES
(
".DBQuote($detail->{'Date'}).",
".DBQuote($detail->{'Reference'})."
+ $extraValues
)
");
if (!$sth) {
@@ -1113,6 +1147,7 @@
# @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, 'y[es]|1'
+# @li Type Optional transaction type
#
# @returns Array ref of hash refs
# @li ID GL entry ID
@@ -1152,6 +1187,12 @@
return ERR_PARAM;
}
+ # Check if we're filtering on type
+ my $typeFilter = 1;
+ if (defined($data->{'Type'}) && $data->{'Type'} ne "") {
+ $typeFilter = $data->{'Type'};
+ }
+
# Extra SQL we may need
my $extraSQL = "";
@@ -1165,7 +1206,7 @@
# 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
+ gl_entries.Amount, gl_transactions.Type
FROM
gl_entries, gl_transactions
WHERE
@@ -1184,6 +1225,10 @@
my $bbfAmount = Math::BigFloat->new();
$bbfAmount->precision(-2);
while (my $row = $sth->fetchrow_hashref()) {
+ # Check filter, if this is not one of our items, continue
+ if ( ($typeFilter & $row->{'Type'}) != $row->{'Type'} ) {
+ next;
+ }
$bbfAmount->badd($row->{'Amount'});
}
@@ -1196,6 +1241,7 @@
$entry->{'Reference'} = "* Balance Brought Forward *";
$entry->{'Amount'} = $bbfAmount->bstr();
$entry->{'TransactionDate'} = $data->{'StartDate'};
+ $entry->{'TransactionType'} = GL_TRANSTYPE_NORMAL;
push(@entries,$entry);
}
@@ -1212,7 +1258,7 @@
my $sth = DBSelect("
SELECT
gl_entries.ID, gl_entries.GLTransactionID, gl_entries.Amount, gl_entries.Reference,
- gl_transactions.TransactionDate, gl_transactions.Reference AS TransRef
+ gl_transactions.TransactionDate, gl_transactions.Reference AS TransRef, gl_transactions.Type AS TransactionType
FROM
gl_entries, gl_transactions
WHERE
@@ -1228,8 +1274,12 @@
# Fetch rows
while (my $row = $sth->fetchrow_hashref()) {
+ # Check filter, if this is not one of our items, continue
+ if ( ($typeFilter & $row->{'TransactionType'}) != $row->{'TransactionType'} ) {
+ next;
+ }
+
my $entry;
-
$entry->{'ID'} = $row->{'ID'};
$entry->{'TransactionID'} = $row->{'GLTransactionID'};
$entry->{'Reference'} = $row->{'Reference'};
@@ -1241,6 +1291,7 @@
$entry->{'TransactionDate'} = $row->{'TransactionDate'};
$entry->{'TransactionReference'} = $row->{'TransRef'};
+ $entry->{'TransactionType'} = $row->{'TransactionType'};
push(@entries,$entry);
}
@@ -1260,6 +1311,7 @@
# @li StartDate - Optional start date
# @li EndDate - Optional end date
# @li EndDateExcl - Exclude end date from search, 'y[es]|1'
+# @li Type Optional transaction type
#
# @returns Hash of account balances
# @li CreditBalance - Credit balance
@@ -1293,6 +1345,13 @@
setError("No (or invalid) account number or ID provided");
return ERR_PARAM;
}
+
+ # Check if we're filtering on type
+ my $typeFilter = 1;
+ if (defined($data->{'Type'}) && $data->{'Type'} ne "") {
+ $typeFilter = $data->{'Type'};
+ }
+
# Extra SQL we may need
my $extraSQL = "";
@@ -1313,7 +1372,7 @@
# Return list of transaction entries
my $sth = DBSelect("
SELECT
- gl_entries.Amount
+ gl_entries.Amount, gl_transactions.Type
FROM
gl_entries, gl_transactions
WHERE
@@ -1337,6 +1396,11 @@
# Add the balances up
while (my $row = $sth->fetchrow_hashref()) {
+ # Check filter, if this is not one of our items, continue
+ if ( ($typeFilter & $row->{'Type'}) != $row->{'Type'} ) {
+ next;
+ }
+
$balance->bzero()->badd($row->{'Amount'});
# Check if its credit or debit
More information about the wiaflos-devel
mailing list