Suppliers.pm 8.08 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
24
25
26
27
28
29
30
31
32

use strict;

# Exporter stuff
require Exporter;
our (@ISA,@EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
);


Nigel Kukard's avatar
Nigel Kukard committed
33
34
35
use wiaflos::client::misc;
use wiaflos::client::soap;
use wiaflos::client::reportwriter;
36

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


100
101
102
103
104
105
106
107
108
109
110
111
112
113

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

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

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

	if (ref $res eq "ARRAY") {
		print swrite(<<'END', "ID", "Ref", "Name", "RegNumber", "TaxRef", "GLAcc");
114
115
116
+========+===========+===============================================+=====================+================+=================+
| @||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||||||||| | @||||||||||||| | @|||||||||||||| |
+========+===========+===============================================+=====================+================+=================+
117
118
END
		foreach my $item (@{$res}) {
119
			print swrite(<<'END', $item->{'ID'}, $item->{'Ref'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAccRef'});
120
| @<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<< | @<<<<<<<<<<<<<< |
121
122
123
END
			}
		print swrite(<<'END');
124
+========+===========+===============================================+=====================+================+=================+
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
END
	} else {
		print($OUT " => ERROR(suppliers:getsuppliers): Error $res while executing command\n");
		return -1;
	}

	return 0;
}


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

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

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

151
	if (!defined($parms->{'acc'})) {
152
153
154
155
156
157
158
		return -202;
	}


	my $detail;
	$detail->{'Ref'} = $parms->{'ref'};
	$detail->{'Name'} = $parms->{'name'};
159
	$detail->{'GLAccRef'} = $parms->{'acc'};
160
161
	$detail->{'RegNumber'} = $parms->{'reg'};
	$detail->{'TaxReference'} = $parms->{'taxref'};
162
	$detail->{'CreateSubAcc'} = $parms->{'createsubacc'};
163
164
165
166
167
168
169
170
171
	my $res = soapCall($OUT,"Suppliers","createSupplier",$detail);

	if ($res == -2) {
		print($OUT " => Database error\n");
	} elsif ($res == -3) {
		print($OUT " => Parameter problem\n");
	} elsif ($res == -4) {
		print($OUT " => Cannot find GL account\n");
	} elsif ($res == -5) {
172
		print($OUT " => Account is not a LIABILITY account\n");
173
174
175
176
177
178
179
180
181
182
183
184
185
186
	}

	return $res;
}


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

187
	if (!defined($parms->{'supplier'})) {
188
189
190
191
192
193
194
195
196
197
198
199
		return -202;
	}

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

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

	my $detail;
200
	$detail->{'SupplierRef'} = $parms->{'supplier'};
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
	$detail->{'Type'} = $parms->{'type'};
	$detail->{'Address'} = $parms->{'address'};
	my $res = soapCall($OUT,"Suppliers","linkAddress",$detail);

	if ($res == -2) {
		print($OUT " => Database error\n");
	} elsif ($res == -3) {
		print($OUT " => Parameter problem\n");
	} elsif ($res == -4) {
		print($OUT " => Supplier not found\n");
	}

	return $res;
}


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

225
	if (!defined($parms->{'supplier'})) {
226
227
228
229
230
231
232
233
234
235
236
237
238
		return -202;
	}

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

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


	my $detail;
239
	$detail->{'SupplierRef'} = $parms->{'supplier'};
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
	$detail->{'Type'} = $parms->{'type'};
	$detail->{'PhNumber'} = $parms->{'phnumber'};
	$detail->{'Name'} = $parms->{'name'};
	my $res = soapCall($OUT,"Suppliers","linkPhoneNumber",$detail);

	if ($res == -2) {
		print($OUT " => Database error\n");
	} elsif ($res == -3) {
		print($OUT " => Parameter problem\n");
	} elsif ($res == -4) {
		print($OUT " => Supplier not found\n");
	}

	return $res;
}


Nigel Kukard's avatar
Nigel Kukard committed
257
258
259
260
261
262
263
# Show supplier
sub show
{
	my ($OUT,@args) = @_;

	my $parms = parseArgs(@args);

264
	if (!defined($parms->{'supplier'})) {
Nigel Kukard's avatar
Nigel Kukard committed
265
266
267
268
		return -202;
	}

	my $detail;
269
	$detail->{'SupplierRef'} = $parms->{'supplier'};
Nigel Kukard's avatar
Nigel Kukard committed
270
271
272
273

	use Data::Dumper;

	my $supplier = soapCall($OUT,"Suppliers","getSupplier",$detail);
274
	return -1 if (ref $supplier ne "HASH");
Nigel Kukard's avatar
Nigel Kukard committed
275
276
	
	my $addies = soapCall($OUT,"Suppliers","getAddresses",$detail);
277
	return -1 if (ref $addies ne "ARRAY");
Nigel Kukard's avatar
Nigel Kukard committed
278
279

	my $phones = soapCall($OUT,"Suppliers","getPhoneNumbers",$detail);
280
	return -1 if (ref $phones ne "ARRAY");
Nigel Kukard's avatar
Nigel Kukard committed
281

282
283
284
	my $emailAddies = soapCall($OUT,"Suppliers","getEmailAddresses",$detail);
	return -1 if (ref $addies ne "ARRAY");

Nigel Kukard's avatar
Nigel Kukard committed
285
	print("
286
287
288
289
290
291
ID.....: ".$supplier->{'ID'}."
Ref....: ".$supplier->{'Ref'}."
Name...: ".$supplier->{'Name'}."
Reg....: ".(defined($supplier->{'RegNumber'}) ? $supplier->{'RegNumber'} : "-")."
TaxRef.: ".(defined($supplier->{'TaxReference'}) ? $supplier->{'TaxReference'} : "-")."
GLAcc..: ".$supplier->{'GLAccRef'}."
Nigel Kukard's avatar
Nigel Kukard committed
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

");

foreach my $item (@{$addies}) {
	print("
Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
}

foreach my $item (@{$phones}) {
	print("
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
307
308
309
310
311
312
313
}

foreach my $item (@{$emailAddies}) {
	print("
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
Nigel Kukard's avatar
Nigel Kukard committed
314
315
316
317
318
319
}

	return 0;
}


320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# Remove supplier
sub remove
{
	my ($OUT,@args) = @_;
	
	
	my $parms = parseArgs(@args);

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

	my $detail;
	$detail->{'SupplierRef'} = $parms->{'supplier'};
	my $res = soapCall($OUT,"Suppliers","removeSupplier",$detail);

	if ($res == -2) {
		print($OUT " => Database error\n");
	} elsif ($res == -3) {
		print($OUT " => Parameter problem\n");
	} elsif ($res == -4) {
		print($OUT " => Supplier not found\n");
	}

	return $res;
}


348
349
350
351
352
353




1;
# vim: ts=4