Statements.pm 4.25 KB
Newer Older
1
# Statement functions
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
19
# 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.

20
21
22
23
24
25



package wiaflos::client::cmdline::Statements;

use strict;
26
use warnings;
27
28


29
use wiaflos::constants;
30
31
32
33
34
35
36
37
38
39
40
use wiaflos::client::misc;
use wiaflos::client::soap;
use wiaflos::client::reportwriter;

use Math::BigFloat;
Math::BigFloat::precision(-2);


# Plugin info
our $pluginInfo = {
	Name 	=> "Statements",
41
	Menu 	=> [
42
43
44
45
46
47
		# Clients Menu
		{
			MenuItem 	=> "Clients",
			Children 	=> [
				{
					MenuItem 	=> "Statements",
48
					Regex		=> "state(?:ments)?",
49
50
51
					Children	=> [
						{
							MenuItem 	=> "Show",
52
							Regex		=> "show",
53
							Desc		=> "Display statement",
54
							Help		=> 'show client="<client code>" [start="<start date>"] [end="yyyy-mm-dd"]',
55
56
57
58
							Function	=> \&show,
						},
						{
							MenuItem 	=> "Send",
59
							Regex		=> "send",
60
							Desc		=> "Send statement",
61
							Help		=> 'send client="<client code>" [start="<yyyy-mm-dd>"] [end="yyyy-mm-dd"] [subject="<subject>"] sendto="<email[:addy1,addy2...] or file:filename>"',
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
							Function	=> \&send,
						},
					],
				},
			],
		},
	],
};



# Show client statement
sub show
{
	my ($OUT,@args) = @_;


	my $parms = parseArgs(@args);

	if (!defined($parms->{'client'})) {
82
83
		print($OUT "  => ERROR: Parameter 'client' not defined\n");
		return ERR_C_PARAM;
84
85
86
	}

	my $detail;
87
	$detail->{'ClientCode'} = $parms->{'client'};
88
	$detail->{'StartDate'} = $parms->{'start'};
89
	$detail->{'EndDate'} = $parms->{'end'};
90
	my $res = soapCall($OUT,"wiaflos/server/api/Statements","getStatement",$detail);
91

92
	if ($res->{'Result'} == RES_OK) {
93
94
95
96
97
98
99
100
		print swrite(<<'END', "ID", "Date", "Ref", "Amount", "Balance");
+===========+============+================================================================================+==============+================+
| @|||||||| | @||||||||| | @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | @||||||||||| | @||||||||||||| |
+===========+============+================================================================================+==============+================+
END
		# Sort data
		my $balance = Math::BigFloat->new(0);

101
		foreach my $entry (@{$res->{'Data'}}) {
102
			$balance->badd($entry->{'Amount'});
Nigel Kukard's avatar
Nigel Kukard committed
103
			print swrite(<<'END', $entry->{'ID'}, $entry->{'TransactionDate'}, $entry->{'Reference'} ? $entry->{'Reference'} : $entry->{'TransactionReference'}, sprintf('%.2f',$entry->{'Amount'}),sprintf('%.2f',$balance));
104
105
106
107
108
109
110
| @<<<<<<<< | @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>>>> | @>>>>>>>>>>>>> |
END
		}
		print swrite(<<'END');
+===========+============+================================================================================+==============+================+
END
	} else {
111
		soapDebug($OUT,$res);
112
113
	}

114
	return $res->{'Result'};
115
116
117
118
119
120
121
122
123
124
125
126
}


# Send statement
sub send
{
	my ($OUT,@args) = @_;


	my $parms = parseArgs(@args);

	if (!defined($parms->{'client'})) {
127
128
		print($OUT "  => ERROR: Parameter 'client' not defined\n");
		return ERR_C_PARAM;
129
130
131
	}

	if (!defined($parms->{'sendto'})) {
132
133
		print($OUT "  => ERROR: Parameter 'sendto' not defined\n");
		return ERR_C_PARAM;
134
135
136
137
	}


	my $detail;
138
	$detail->{'ClientCode'} = $parms->{'client'};
139
	$detail->{'StartDate'} = $parms->{'start'};
140
	$detail->{'EndDate'} = $parms->{'end'};
141
	$detail->{'SendTo'} = $parms->{'sendto'};
142
	$detail->{'Subject'} = $parms->{'subject'};
143
	my $res = soapCall($OUT,"wiaflos/server/api/Statements","sendStatement",$detail);
144
145
146
147
148
	if ($res->{'Result'} != RES_OK) {
		soapDebug($OUT,$res);
	}

	return $res->{'Result'};
149
150
151
152
153
154
155
}




1;
# vim: ts=4