Commit b3bb74c9 authored by Nigel Kukard's avatar Nigel Kukard

* Fixed up templating system

- Added more documentation
- Added support for the yearend transactions in reporting
parent 186fc608
......@@ -183,3 +183,147 @@ DIRECTIVE SUMMARY
[%# placing the '#' immediately inside the directive
tag comments out the entire directive
%]
VARIABLE FUNCTIONS:
api_variable_new($name,$type)
$name - variable name
$type - variable type, ONLY 'float' is currently supported!
api_variable_add($name,$value)
Add $value to variable named with $name
api_variable_subtract($name,$value)
Add $value to variable named with $name
api_variable_get($name)
Return the value of the variable
'float' - formatted %.2f , 2 decimal places
api_variable_getraw($name)
Return raw value of the variable
api_bitwise_and($var1,$var2,$var3... $varN)
Bitwise all arguments
CONSTANTS:
WiaflosString
Generated by Wiaflos string
StartDate
Start date of report, or "-" if there is no start date
EndDate
End date of report, or "CURRENT" if there is no end date
FLAGS:
API_RPT_BALANCE_BF
Bitwise constant, this is a flag and will signify the backend to return a balance brought forward psuedo transaction
API_RPT_INCLUDE_YEAREND
Include yearend transactions , this is a flag and will signify the backend to return the hidden yearend transactions
FUNCTIONS:
api_account_balances
Return a complex account balance structure
{'AccountBalances}{[ACCOUNT_NUMBER]} => hash of hashes {
Number - Account Number
Name - Account Name
DebitBalance - Debit balance for entire period
CreditBalance - Credit balance or entire period
Balance - Debit & credit or entire period
CreditAmount - Total of all credits for period
DebitAmount - Total of all debits for period
ReportWriterCategoryCode - Report writer category code
Children - Link to children accounts
If REPORT_BALANCE_BF is specified:
OpeningDebitBalance
OpeningCreditBalance
OpeningBalance
ClosingBalance
}
{'ReportWriterCategoryToAccounts'}{CATEGORY_CODE} => array of accounts above
api_gl_transactions
Return list of transactions
{'Transactions'} = array of hashes {
ID
TransactionDate
Reference
Entries = array of hashes {
ID
GLAccountID
GLAccountName
GLAccountNumber
Amount
Reference
}
}
api_account_entries
Return account entries
{'Account'} = hash {
ID
Number
ParentGLAccountID
Name
FinCatCode
FinCatDescription
RwCatCode
RwCatDescription
}
{'Entries'} = array (
ID
GLTransactionID
Reference
Amount
Balance
TransactionDate
TransactionReference
)
api_inventory_stock_balances
Return stock balances.
{'StockItemBalances'}->{[ITEM_CODE]}->{[ITEM_SERIAL]} = {
TotalQuantity - Total quantity of all items with this serial
TotalValue - Total value of all items with this serial
}
{'StockBalances'}->{[ITEM_CODE]} = {
TotalQuantity - Quantity of all items with this stock code
TotalValue - Value of all items with this stock code
}
{'TotalValue'} = Total floating point stock value
api_format_amount($amount,$options)
Format $amount according to the $options below:
API_FMT_REVERSE - bitwise option, reverse the amount before formatting (ie. multiply by -1)
API_FMT_NEGBRACKET - bitwise option, put negatives in brackets
api_dump($variable)
Dump to server console
......@@ -8,7 +8,7 @@
<body>
[% # Pull account balances from backend
SET data = api_account_balances(API_RPT_BALANCE_BF)
SET data = api_account_balances( api_bitwise_and(API_RPT_BALANCE_BF,API_RPT_INCLUDE_YEAREND) )
%]
<table id="page" width="100%">
......
......@@ -42,12 +42,14 @@ our (@ISA,@EXPORT,@EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT = qw(
REPORT_BALANCE_BF
REPORT_INCLUDE_YEAREND
);
@EXPORT_OK = ();
use constant {
REPORT_BALANCE_BF => 1,
REPORT_INCLUDE_YEAREND => 2,
};
......@@ -87,12 +89,12 @@ sub Error
#
# @param flags Flags of what we returned, options are below, use || (OR)
# @li REPORT_BALANCE_BF - Return balance brought forward for each account
# @li REPORT_INCLUDE_YEAREND - Get balances and include yearend transactions
#
# @param data Parameter hash ref
# @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
......@@ -125,6 +127,12 @@ sub getAccountBalances
$search->{'StartDate'} = $data->{'StartDate'};
$search->{'EndDate'} = $data->{'EndDate'};
$search->{'Levels'} = $data->{'Levels'};
$search->{'Type'} = 1;
# Check if we must include yearend transactions
if (($flags & REPORT_INCLUDE_YEAREND) == REPORT_INCLUDE_YEAREND) {
$search->{'Type'} |= 2;
}
# Loop with the parent accounts, remember they're top level
foreach my $account (@{$res}) {
......@@ -166,6 +174,7 @@ sub getAccountBalances
my $info;
$info->{'StartDate'} = $search->{'StartDate'};
$info->{'EndDate'} = $search->{'EndDate'};
$info->{'Type'} = $search->{'Type'};
$info->{'AccountID'} = $paccount->{'ID'};
# Get our own account balance
my $res = wiaflos::server::GL::getGLAccountBalance($info);
......@@ -189,6 +198,7 @@ sub getAccountBalances
my $bfinfo;
$bfinfo->{'EndDate'} = $search->{'StartDate'};
$bfinfo->{'EndDateExcl'} = 1;
$bfinfo->{'Type'} = $search->{'Type'};
$bfinfo->{'AccountID'} = $paccount->{'ID'};
# Pull in balance brought forward
$res = wiaflos::server::GL::getGLAccountBalance($bfinfo);
......@@ -520,7 +530,7 @@ sub sendReport
# Generate closing balance entry
my $entry;
$entry->{'ID'} = -99;
$entry->{'TransactionID'} = -99;
$entry->{'GLTransactionID'} = -99;
$entry->{'Reference'} = "* Closing Balance *";
$entry->{'Balance'} = sprintf('%.2f',$closingBalance->bstr());
$entry->{'TransactionDate'} = $detail->{'EndDate'};
......@@ -696,6 +706,21 @@ sub sendReport
}
# Reporting API function to logical AND all variables
sub api_bitwise_and
{
my @vars = @_;
# AND up all the values
my $res = 0;
foreach my $val (@vars) {
$res |= $val;
}
return $res;
}
# Dump contents of parameters on server
sub api_format_amount
{
......@@ -758,6 +783,7 @@ sub sendReport
# API
'api_account_balances' => \&api_account_balances,
'API_RPT_BALANCE_BF' => REPORT_BALANCE_BF,
'API_RPT_INCLUDE_YEAREND' => REPORT_INCLUDE_YEAREND,
'api_account_entries' => \&api_account_entries,
......@@ -769,6 +795,8 @@ sub sendReport
'api_variable_subtract' => \&api_variable_subtract,
'api_variable_get' => \&api_variable_get,
'api_variable_getraw' => \&api_variable_getraw,
'api_bitwise_and' => \&api_bitwise_and,
'api_format_amount' => \&api_format_amount,
'API_FMT_REVERSE' => API_FMT_REVERSE,
......
Markdown is supported
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