Suppliers.pm 7.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Supplier functions
# Copyright (C) 2007 Nigel Kukard  <nkukard@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.

18
19
20



Nigel Kukard's avatar
Nigel Kukard committed
21
package wiaflos::client::cmdline::Suppliers;
22
23

use strict;
24
use warnings;
25
26


27
use wiaflos::constants;
Nigel Kukard's avatar
Nigel Kukard committed
28
29
30
use wiaflos::client::misc;
use wiaflos::client::soap;
use wiaflos::client::reportwriter;
31

Nigel Kukard's avatar
Nigel Kukard committed
32
33
34
35
36
37
38
39
40
41
# Plugin info
our $pluginInfo = {
	Name 	=> "Suppliers",
	Menu 	=> [ 
		# Suppliers main menu option	
		{
			MenuItem 	=> "Suppliers",
			Children 	=> [
				{
					MenuItem 	=> "Create",
42
					Regex		=> "create ",
Nigel Kukard's avatar
Nigel Kukard committed
43
					Desc		=> "Create a supplier",
44
					Help		=> 'create code="<supplier code>" name="<supplier name>" [reg="<registration num>"] [taxref="<tax reference number>"] account="<GL account>" [contactperson="<contact person name>"] [createsubaccount="<y to create sub account>"]',
Nigel Kukard's avatar
Nigel Kukard committed
45
46
47
48
					Function	=> \&create,
				},
				{
					MenuItem 	=> "LinkAddr",
49
					Regex		=> "linkaddr ",
Nigel Kukard's avatar
Nigel Kukard committed
50
					Desc		=> "Link in an address",
51
					Help		=> 'linkaddr supplier="<supplier code>" type="<billing or shipping>" address="<address>"',
Nigel Kukard's avatar
Nigel Kukard committed
52
53
54
55
					Function	=> \&linkAddress,
				},
				{
					MenuItem 	=> "LinkEmail",
56
					Regex		=> "linkemail ",
Nigel Kukard's avatar
Nigel Kukard committed
57
					Desc		=> "Link in an email address",
58
					Help		=> 'linkemail(?:addr)? supplier="<supplier code>" type="<accounts or general>" address="<address>"',
Nigel Kukard's avatar
Nigel Kukard committed
59
60
61
62
					Function	=> \&linkEmailAddress,
				},
				{
					MenuItem 	=> "LinkPhNum",
63
					Regex		=> "linkphnum ",
Nigel Kukard's avatar
Nigel Kukard committed
64
					Desc		=> "Link in a phone number",
65
					Help		=> 'linkphnum supplier="<supplier code>" type="<phone or fax>" number="<phone number>" [name="<name>"]',
Nigel Kukard's avatar
Nigel Kukard committed
66
67
68
69
					Function	=> \&linkPhoneNumber,
				},
				{
					MenuItem 	=> "Remove",
70
					Regex		=> "remove ",
Nigel Kukard's avatar
Nigel Kukard committed
71
					Desc		=> "Remove supplier",
72
					Help		=> 'remove supplier="<supplier code>"',
Nigel Kukard's avatar
Nigel Kukard committed
73
74
75
76
					Function	=> \&remove,
				},
				{
					MenuItem 	=> "List",
77
					Regex		=> "list\$",
Nigel Kukard's avatar
Nigel Kukard committed
78
79
80
81
82
83
					Desc		=> "Display list of suppliers",
					Help		=> 'list',
					Function	=> \&list,
				},
				{
					MenuItem 	=> "Show",
84
					Regex		=> "show ",
Nigel Kukard's avatar
Nigel Kukard committed
85
					Desc		=> "Show supplier",
86
					Help		=> 'show supplier="<supplier code>"',
Nigel Kukard's avatar
Nigel Kukard committed
87
88
89
90
91
92
93
94
					Function	=> \&show,
				},
			],
		},
	],
};


95
96
97
98
99
100
101
102
103
104
105
106
107

# List suppliers
sub list
{
	my ($OUT,@args) = @_;

	if (@args > 0) {
		return -202;
	}

	my $res = soapCall($OUT,"Suppliers","getSuppliers");

	if (ref $res eq "ARRAY") {
108
		print $OUT swrite(<<'END', "ID", "Code", "Name", "RegNumber", "TaxRef", "GLAccount");
109
110
111
+========+===========+===============================================+=====================+================+=================+
| @||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||||||||| | @||||||||||||| | @|||||||||||||| |
+========+===========+===============================================+=====================+================+=================+
112
113
END
		foreach my $item (@{$res}) {
114
			print $OUT swrite(<<'END', $item->{'ID'}, $item->{'Code'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAccountNumber'});
115
| @<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<< | @<<<<<<<<<<<<<< |
116
117
END
			}
118
			print $OUT swrite(<<'END');
119
+========+===========+===============================================+=====================+================+=================+
120
121
END
	} else {
122
		return $res;
123
124
125
126
127
128
129
130
131
132
133
134
135
136
	}

	return 0;
}


# Create supplier
sub create
{
	my ($OUT,@args) = @_;
	
	
	my $parms = parseArgs(@args);

137
138
	if (!defined($parms->{'code'})) {
		return ERR_C_PARAM;
139
140
141
	}

	if (!defined($parms->{'name'})) {
142
		return ERR_C_PARAM;
143
144
	}

145
146
	if (!defined($parms->{'account'})) {
		return ERR_C_PARAM;
147
148
149
150
	}


	my $detail;
151
	$detail->{'Code'} = $parms->{'code'};
152
	$detail->{'Name'} = $parms->{'name'};
153
	$detail->{'GLAccountNumber'} = $parms->{'account'};
154
155
	$detail->{'RegNumber'} = $parms->{'reg'};
	$detail->{'TaxReference'} = $parms->{'taxref'};
156
	$detail->{'CreateSubAccout'} = $parms->{'createsubaccount'};
157
158
159
160
161
162
163
164
165
166
167
168
169
170
	my $res = soapCall($OUT,"Suppliers","createSupplier",$detail);

	return $res;
}


# Link address 
sub linkAddress
{
	my ($OUT,@args) = @_;
	
	
	my $parms = parseArgs(@args);

171
	if (!defined($parms->{'supplier'})) {
172
		return ERR_C_PARAM;
173
174
175
	}

	if (!defined($parms->{'type'})) {
176
		return ERR_C_PARAM;
177
178
179
	}

	if (!defined($parms->{'address'})) {
180
		return ERR_C_PARAM;
181
182
183
	}

	my $detail;
184
	$detail->{'Code'} = $parms->{'supplier'};
185
186
	$detail->{'Type'} = $parms->{'type'};
	$detail->{'Address'} = $parms->{'address'};
187
	my $res = soapCall($OUT,"Suppliers","linkSupplierAddress",$detail);
188
189
190
191
192
193
194
195
196
197
198
199
200

	return $res;
}


# Link phone number 
sub linkPhoneNumber
{
	my ($OUT,@args) = @_;
	
	
	my $parms = parseArgs(@args);

201
	if (!defined($parms->{'supplier'})) {
202
		return ERR_C_PARAM;
203
204
205
	}

	if (!defined($parms->{'type'})) {
206
		return ERR_C_PARAM;
207
208
	}

209
210
	if (!defined($parms->{'number'})) {
		return ERR_C_PARAM;
211
212
213
214
	}


	my $detail;
215
	$detail->{'Code'} = $parms->{'supplier'};
216
	$detail->{'Type'} = $parms->{'type'};
217
	$detail->{'Number'} = $parms->{'number'};
218
	$detail->{'Name'} = $parms->{'name'};
219
	my $res = soapCall($OUT,"Suppliers","linkSupplierPhoneNumber",$detail);
220
221
222
223
224

	return $res;
}


Nigel Kukard's avatar
Nigel Kukard committed
225
226
227
228
229
230
231
# Show supplier
sub show
{
	my ($OUT,@args) = @_;

	my $parms = parseArgs(@args);

232
	if (!defined($parms->{'supplier'})) {
233
		return ERR_C_PARAM;
Nigel Kukard's avatar
Nigel Kukard committed
234
235
236
	}

	my $detail;
237
	$detail->{'Code'} = $parms->{'supplier'};
Nigel Kukard's avatar
Nigel Kukard committed
238
239

	my $supplier = soapCall($OUT,"Suppliers","getSupplier",$detail);
240
	return $supplier if (ref $supplier ne "HASH");
Nigel Kukard's avatar
Nigel Kukard committed
241
	
242
243
	my $addies = soapCall($OUT,"Suppliers","getSupplierAddresses",$detail);
	return $addies if (ref $addies ne "ARRAY");
Nigel Kukard's avatar
Nigel Kukard committed
244

245
246
	my $phones = soapCall($OUT,"Suppliers","getSupplierPhoneNumbers",$detail);
	return $phones if (ref $phones ne "ARRAY");
Nigel Kukard's avatar
Nigel Kukard committed
247

248
249
	my $emailAddies = soapCall($OUT,"Suppliers","getSupplierEmailAddresses",$detail);
	return $emailAddies if (ref $addies ne "ARRAY");
250

251
	print($OUT "
252
ID.....: ".$supplier->{'ID'}."
253
Code...: ".$supplier->{'Code'}."
254
255
256
Name...: ".$supplier->{'Name'}."
Reg....: ".(defined($supplier->{'RegNumber'}) ? $supplier->{'RegNumber'} : "-")."
TaxRef.: ".(defined($supplier->{'TaxReference'}) ? $supplier->{'TaxReference'} : "-")."
257
GLAcc..: ".$supplier->{'GLAccountNumber'}."
Nigel Kukard's avatar
Nigel Kukard committed
258
259
260
261

");

foreach my $item (@{$addies}) {
262
	print($OUT "
Nigel Kukard's avatar
Nigel Kukard committed
263
264
265
266
267
268
Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
}

foreach my $item (@{$phones}) {
269
	print($OUT "
Nigel Kukard's avatar
Nigel Kukard committed
270
271
272
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
273
274
275
}

foreach my $item (@{$emailAddies}) {
276
	print($OUT "
277
278
279
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
Nigel Kukard's avatar
Nigel Kukard committed
280
281
282
283
284
285
}

	return 0;
}


286
287
288
289
290
291
292
293
294
295
296
297
298
# Remove supplier
sub remove
{
	my ($OUT,@args) = @_;
	
	
	my $parms = parseArgs(@args);

	if (!defined($parms->{'supplier'})) {
		return -202;
	}

	my $detail;
299
	$detail->{'Code'} = $parms->{'supplier'};
300
301
302
303
304
305
	my $res = soapCall($OUT,"Suppliers","removeSupplier",$detail);

	return $res;
}


306
307
308
309
310
311




1;
# vim: ts=4