Statements.pm 3.66 KB
Newer Older
1
# SOAP interface to Statements module
2
# Copyright (C) 2009-2020, AllWorldIT
Nigel Kukard's avatar
Nigel Kukard committed
3
# Copyright (C) 2008, LinuxRulz
Nigel Kukard's avatar
Nigel Kukard committed
4
# Copyright (C) 2007 Nigel Kukard  <nkukard@lbsd.net>
5
#
6
7
8
9
# 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.
10
#
11
12
13
14
# 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.
15
#
16
17
18
# 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.
19
20


21
package wiaflos::server::api::Statements;
22
23

use strict;
24
25
use warnings;

26
use wiaflos::server::api::auth;
27

28
29
use wiaflos::constants;
use wiaflos::soap;
30
use wiaflos::server::core::Statements;
31
32
33
34
35


# Plugin info
our $pluginInfo = {
	Name => "Statements",
36
	Init => \&init,
37
38
39
};


40
41
42
43
44
# Initialize module
sub init {
	my $server = shift;


45
46
	wiaflos::server::api::auth::aclAdd('wiaflos/server/api/Statements','getStatement','Statements/Show');
	wiaflos::server::api::auth::aclAdd('wiaflos/server/api/Statements','sendStatement','Statements/Send');
47
48
49
}


50
51
52
53


# Return list of statement entries
# Parameters:
54
#		ClientCode		- Client code
55
#		StartDate	- Start date
56
#		EndDate	- End date
57
58
59
60
sub getStatement {
	my (undef,$data) = @_;


61
62
	if (!defined($data->{'ClientCode'}) || $data->{'ClientCode'} eq "") {
		return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ClientCode' invalid");
63
64
	}

65
	my $authInfo = wiaflos::server::api::auth::sessionGetData();
66
67
68

	# Grab and sanitize data
	my $detail;
69
	$detail->{'ClientCode'} = $data->{'ClientCode'};
70
	$detail->{'StartDate'} = $data->{'StartDate'};
71
	$detail->{'EndDate'} = $data->{'EndDate'};
72
	my $rawData = wiaflos::server::core::Statements::getStatement($detail);
73
	if (ref $rawData ne "ARRAY") {
74
		return SOAPResponse(RES_ERROR,$rawData,wiaflos::server::core::Statements::Error());
75
76
77
78
79
	}

	# Build result
	my @data;
	foreach my $item (@{$rawData}) {
Nigel Kukard's avatar
Nigel Kukard committed
80
		my $tmpItem;
81
82

		$tmpItem->{'ID'} = $item->{'ID'};
83
84
85
		$tmpItem->{'GLTransactionID'} = $item->{'GLTransactionID'};
		$tmpItem->{'Reference'} = $item->{'Reference'};
		$tmpItem->{'TransactionDate'} = $item->{'TransactionDate'};
86
		$tmpItem->{'Amount'} = $item->{'Amount'};
87
		$tmpItem->{'TransactionReference'} = $item->{'TransactionReference'};
88

Nigel Kukard's avatar
Nigel Kukard committed
89
		push(@data,$tmpItem);
90
91
	}

92
	return SOAPResponse(RES_OK,\@data);
93
94
95
96
97
}


# Build client statement
# Parameters:
98
#		ClientCode	- Client ref
99
100
#		SendTo		- Send statement to here
# Optional:
101
#		StartDate	- Start date
102
#		EndDate		- End date
103
#		Subject		- Statement subject
104
105
106
107
108
sub sendStatement {
	my (undef,$data) = @_;


	# Check params
109
110
	if (!defined($data->{'ClientCode'}) || $data->{'ClientCode'} eq "") {
		return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'ClientCode' invalid");
111
112
113
	}

	if (!defined($data->{'SendTo'}) || $data->{'SendTo'} eq "") {
114
		return SOAPResponse(RES_ERROR,ERR_S_PARAM,"Parameter 'SendTo' invalid");
115
116
	}

117
	my $authInfo = wiaflos::server::api::auth::sessionGetData();
118
119
120

	# Do transaction
	my $detail;
121
	$detail->{'ClientCode'} = $data->{'ClientCode'};
122
	$detail->{'SendTo'} = $data->{'SendTo'};
123
	$detail->{'StartDate'} = $data->{'StartDate'};
124
	$detail->{'EndDate'} = $data->{'EndDate'};
125
	$detail->{'Subject'} = $data->{'Subject'};
126
	my $res = wiaflos::server::core::Statements::sendStatement($detail);
Nigel Kukard's avatar
Nigel Kukard committed
127

128
	if ($res < 0) {
129
		return SOAPResponse(RES_ERROR,$res,wiaflos::server::core::Statements::Error());
130
	}
131

132
	return SOAPResponse(RES_OK,$res);
133
134
135
136
137
138
}



1;
# vim: ts=4