[wiaflos-devel] COMMIT - r286 - in trunk: database soap wiaflos/client wiaflos/client/cmdline wiaflos/server
svn at linuxrulz.org
svn at linuxrulz.org
Sat May 16 14:30:07 GMT 2009
Author: nkukard
Date: 2009-05-16 14:30:07 +0000 (Sat, 16 May 2009)
New Revision: 286
Added:
trunk/wiaflos/client/cmdline/YearEnd.pm
trunk/wiaflos/server/YearEnd.pm
Modified:
trunk/database/schema.tsql
trunk/soap/wiaflos.conf
trunk/wiaflos/client/cmdline.pm
Log:
* Added YearEnd capabilities
Modified: trunk/database/schema.tsql
===================================================================
--- trunk/database/schema.tsql 2009-05-16 14:28:21 UTC (rev 285)
+++ trunk/database/schema.tsql 2009-05-16 14:30:07 UTC (rev 286)
@@ -144,6 +144,8 @@
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Reporting/IncomeStatement/Send');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Reporting/TrialBalance/Show');
INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'Reporting/TrialBalance/Send');
+/* Year End */
+INSERT INTO soap_caps (GroupID,Capability) VALUES (1,'YearEnd/Perform');
Modified: trunk/soap/wiaflos.conf
===================================================================
--- trunk/soap/wiaflos.conf 2009-05-16 14:28:21 UTC (rev 285)
+++ trunk/soap/wiaflos.conf 2009-05-16 14:30:07 UTC (rev 286)
@@ -32,9 +32,9 @@
[soap]
plugins=<<EOT
Engine
-SOAPTest
-Clients
-GL
+SOAPTest
+Clients
+GL
Inventory
Tax
Suppliers
@@ -46,6 +46,7 @@
SupplierCreditNotes
SupplierReceipting
Reporting
+YearEnd
EOT
Added: trunk/wiaflos/client/cmdline/YearEnd.pm
===================================================================
--- trunk/wiaflos/client/cmdline/YearEnd.pm (rev 0)
+++ trunk/wiaflos/client/cmdline/YearEnd.pm 2009-05-16 14:30:07 UTC (rev 286)
@@ -0,0 +1,98 @@
+# Year end procedures
+# Copyright (C) 2009, AllWorldIT
+# Copyright (C) 2008, LinuxRulz
+# Copyright (C) 2007 Nigel Kukard <nkukard at lbsd.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+
+
+package wiaflos::client::cmdline::YearEnd;
+
+use strict;
+use warnings;
+
+
+use wiaflos::constants;
+use wiaflos::client::misc;
+use wiaflos::client::soap;
+use wiaflos::client::reportwriter;
+
+
+# Plugin info
+our $pluginInfo = {
+ Name => "YearEnd",
+ Menu => [
+ # Reporting Menu
+ {
+ MenuItem => "YearEnd",
+ Regex => "year(?:end)?",
+ Children => [
+ {
+ MenuItem => "Create",
+ Regex => "create",
+ Desc => "Create year end",
+ Help => 'send start="<yyyy-mm-dd>" end="<yyyy-mm-dd>" account="<account number>"',
+ Function => \&performYearEnd,
+ },
+ ],
+ },
+ ],
+};
+
+
+
+
+# Perform year end
+sub performYearEnd
+{
+ my ($OUT, at args) = @_;
+
+
+ my $parms = parseArgs(@args);
+
+ if (!defined($parms->{'start'})) {
+ print($OUT " => ERROR: Parameter 'start' not defined\n");
+ return ERR_C_PARAM;
+ }
+
+ if (!defined($parms->{'end'})) {
+ print($OUT " => ERROR: Parameter 'end' not defined\n");
+ return ERR_C_PARAM;
+ }
+
+ if (!defined($parms->{'account'})) {
+ print($OUT " => ERROR: Parameter 'account' not defined\n");
+ return ERR_C_PARAM;
+ }
+
+
+ my $detail;
+ $detail->{'StartDate'} = $parms->{'start'};
+ $detail->{'EndDate'} = $parms->{'end'};
+ $detail->{'REAccountNumber'} = $parms->{'account'};
+ my $res = soapCall($OUT,"YearEnd","performYearEnd",$detail);
+ if ($res->{'Result'} != RES_OK) {
+ soapDebug($OUT,$res);
+ }
+
+ return $res->{'Result'};
+}
+
+
+
+1;
+# vim: ts=4
Modified: trunk/wiaflos/client/cmdline.pm
===================================================================
--- trunk/wiaflos/client/cmdline.pm 2009-05-16 14:28:21 UTC (rev 285)
+++ trunk/wiaflos/client/cmdline.pm 2009-05-16 14:30:07 UTC (rev 286)
@@ -58,6 +58,7 @@
SupplierCreditNotes
SupplierReceipting
Reporting
+ YearEnd
);
my @plugins;
Added: trunk/wiaflos/server/YearEnd.pm
===================================================================
--- trunk/wiaflos/server/YearEnd.pm (rev 0)
+++ trunk/wiaflos/server/YearEnd.pm 2009-05-16 14:30:07 UTC (rev 286)
@@ -0,0 +1,209 @@
+# Year end support
+# Copyright (C) 2009, AllWorldIT
+# Copyright (C) 2008, LinuxRulz
+# Copyright (C) 2007 Nigel Kukard <nkukard at lbsd.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+
+package wiaflos::server::YearEnd;
+
+use strict;
+use warnings;
+
+
+use wiaflos::constants;
+use wiaflos::server::dblayer;
+use wiaflos::server::GL;
+
+use Math::BigFloat;
+
+
+
+# Our current error message
+my $error = "";
+
+# Set current error message
+# Args: error_message
+sub setError
+{
+ my $err = shift;
+ my ($package,$filename,$line) = caller;
+ my (undef,undef,undef,$subroutine) = caller(1);
+
+ # Set error
+ $error = "$subroutine($line): $err";
+}
+
+# Return current error message
+# Args: none
+sub Error
+{
+ my $err = $error;
+
+ # Reset error
+ $error = "";
+
+ # Return error
+ return $err;
+}
+
+
+## @fn performYearEnd
+# Function to perform a yearend on the set of books
+#
+# @param detail Parameter hash ref
+# @li StartDate - Yearend start date
+# @li EndDate - Yearend end date
+# @li REAccountNumber - Retained earnings account number
+sub performYearEnd
+{
+ my $detail = shift;
+
+
+ # Verify dates
+ if (!defined($detail->{'StartDate'}) || $detail->{'StartDate'} eq "") {
+ setError("No start date provided for year end");
+ return ERR_PARAM;
+ }
+ if (!defined($detail->{'EndDate'}) || $detail->{'EndDate'} eq "") {
+ setError("No end date provided for year end");
+ return ERR_PARAM;
+ }
+ if (!defined($detail->{'REAccountNumber'}) || $detail->{'REAccountNumber'} eq "") {
+ setError("No retained earnings account number provided for year end");
+ return ERR_PARAM;
+ }
+
+ # Get our account tree
+ my $accounts = wiaflos::server::GL::getGLAccounts();
+ if (ref($accounts) ne "ARRAY") {
+ setError(wiaflos::server::GL::Error());
+ return $accounts;
+ }
+
+ # List of transactions to create, hashed by account ID
+ my %entryList = ();
+
+ # GL search criteria
+ my $search;
+ $search->{'StartDate'} = $detail->{'StartDate'};
+ $search->{'EndDate'} = $detail->{'EndDate'};
+
+ # Transaction balance
+ my $transActBalance = Math::BigFloat->new();
+ $transActBalance->precision(-2);
+
+ # Pick out expense accounts and generate transaction list
+ foreach my $account(@{$accounts}) {
+ # If its not expense or income, ignore it
+ if ($account->{'FinCatCode'} ne "E01" && $account->{'FinCatCode'} ne "D01") {
+ next;
+ }
+
+ # Set account ID
+ $search->{'AccountID'} = $account->{'ID'};
+
+ # Get account balance
+ my $glBalance = wiaflos::server::GL::getGLAccountBalance($search);
+ if (ref($glBalance) ne "HASH") {
+ setError(wiaflos::server::GL::Error());
+ return $glBalance;
+ }
+
+ # These are our balances
+ my $creditBalance = Math::BigFloat->new($glBalance->{'CreditBalance'});
+ my $debitBalance = Math::BigFloat->new($glBalance->{'DebitBalance'});
+ $creditBalance->precision(-2);
+ $debitBalance->precision(-2);
+
+ # Generate overall balance
+ my $balance = $debitBalance->copy()->bsub($creditBalance);
+
+ # Get opposite side of the transaction
+ $balance->bmul(-1);
+
+ # Record the balance for this account
+ $entryList{$account->{'ID'}} = $balance->bstr();
+
+ # Add up balance
+ $transActBalance->bsub($balance);
+ }
+
+
+ DBBegin();
+
+ my $data;
+
+ # Transaction details
+ $data->{'Date'} = $detail->{'EndDate'};
+ $data->{'Reference'} = "Year End: ".$detail->{'StartDate'}." to ".$detail->{'EndDate'};
+ $data->{'Type'} = 2;
+ # Create transaction
+ my $GLTransActID = wiaflos::server::GL::createGLTransaction($data);
+ if ($GLTransActID < 1) {
+ setError(wiaflos::server::GL::Error());
+ DBRollback();
+ return $GLTransActID;
+ }
+
+ # Set defaults for the transaction entries
+ $data = undef;
+ $data->{'ID'} = $GLTransActID;
+ # Loop with transaction entry list
+ foreach my $accountID (keys %entryList) {
+ # Set the details specific to this entry
+ $data->{'GLAccountID'} = $accountID;
+ $data->{'Amount'} = $entryList{$accountID};
+ # Create entry
+ if ((my $res = wiaflos::server::GL::linkGLTransaction($data)) < 1) {
+ setError(wiaflos::server::GL::Error());
+ DBRollback();
+ return $res;
+ }
+ }
+
+ # Setup data for the retained earnings entry
+ $data = undef;
+ $data->{'ID'} = $GLTransActID;
+ $data->{'GLAccountNumber'} = $detail->{'REAccountNumber'};
+ $data->{'Amount'} = $transActBalance->bstr();
+ # Create entry
+ if ((my $res = wiaflos::server::GL::linkGLTransactionByAccountNumber($data)) < 1) {
+ setError(wiaflos::server::GL::Error());
+ DBRollback();
+ return $res;
+ }
+
+ # Post transaction
+ $data = undef;
+ $data->{'ID'} = $GLTransActID;
+ if ((my $res = wiaflos::server::GL::postGLTransaction($data)) != 0) {
+ setError(wiaflos::server::GL::Error());
+ DBRollback();
+ return $res;
+ }
+
+ DBCommit();
+
+ return RES_OK;
+}
+
+
+
+
+1;
+# vim: ts=4
More information about the wiaflos-devel
mailing list