Suppliers.pm 7.41 KB
Newer Older
1
2
3
4
5
6
7
# Author: Nigel Kukard  <nkukard@lbsd.net>
# Date: 14/02/2007
# Desc: Supplier functions
# License: GPL



Nigel Kukard's avatar
Nigel Kukard committed
8
package wiaflos::client::cmdline::Suppliers;
9
10
11
12
13
14
15
16
17
18
19

use strict;

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


Nigel Kukard's avatar
Nigel Kukard committed
20
21
22
use wiaflos::client::misc;
use wiaflos::client::soap;
use wiaflos::client::reportwriter;
23

Nigel Kukard's avatar
Nigel Kukard committed
24
25
26
27
28
29
30
31
32
33
# Plugin info
our $pluginInfo = {
	Name 	=> "Suppliers",
	Menu 	=> [ 
		# Suppliers main menu option	
		{
			MenuItem 	=> "Suppliers",
			Children 	=> [
				{
					MenuItem 	=> "Create",
34
					Regex		=> "create ",
Nigel Kukard's avatar
Nigel Kukard committed
35
36
37
38
39
40
					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",
41
					Regex		=> "linkaddr ",
Nigel Kukard's avatar
Nigel Kukard committed
42
43
44
45
46
47
					Desc		=> "Link in an address",
					Help		=> 'linkaddr supplier="<supplier ref>" type="<billing or shipping>" address="<address>"',
					Function	=> \&linkAddress,
				},
				{
					MenuItem 	=> "LinkEmail",
48
					Regex		=> "linkemail ",
Nigel Kukard's avatar
Nigel Kukard committed
49
50
51
52
53
54
					Desc		=> "Link in an email address",
					Help		=> 'linkemail(?:addr)? supplier="<supplier ref>" type="<accounts or general>" address="<address>"',
					Function	=> \&linkEmailAddress,
				},
				{
					MenuItem 	=> "LinkPhNum",
55
					Regex		=> "linkphnum ",
Nigel Kukard's avatar
Nigel Kukard committed
56
57
58
59
60
61
					Desc		=> "Link in a phone number",
					Help		=> 'linkphnum supplier="<supplier ref>" type="<phone or fax>" phnumber="<phone number>" [name="<name>"]',
					Function	=> \&linkPhoneNumber,
				},
				{
					MenuItem 	=> "Remove",
62
					Regex		=> "remove ",
Nigel Kukard's avatar
Nigel Kukard committed
63
64
65
66
67
68
					Desc		=> "Remove supplier",
					Help		=> 'remove supplier="<supplier ref>"',
					Function	=> \&remove,
				},
				{
					MenuItem 	=> "List",
69
					Regex		=> "list\$",
Nigel Kukard's avatar
Nigel Kukard committed
70
71
72
73
74
75
					Desc		=> "Display list of suppliers",
					Help		=> 'list',
					Function	=> \&list,
				},
				{
					MenuItem 	=> "Show",
76
					Regex		=> "show ",
Nigel Kukard's avatar
Nigel Kukard committed
77
78
79
80
81
82
83
84
85
86
					Desc		=> "Show supplier",
					Help		=> 'show supplier="<client ref>"',
					Function	=> \&show,
				},
			],
		},
	],
};


87
88
89
90
91
92
93
94
95
96
97
98
99
100

# 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");
101
102
103
+========+===========+===============================================+=====================+================+=================+
| @||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||||||||| | @||||||||||||| | @|||||||||||||| |
+========+===========+===============================================+=====================+================+=================+
104
105
END
		foreach my $item (@{$res}) {
106
			print swrite(<<'END', $item->{'ID'}, $item->{'Ref'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAccRef'});
107
| @<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<< | @<<<<<<<<<<<<<< |
108
109
110
END
			}
		print swrite(<<'END');
111
+========+===========+===============================================+=====================+================+=================+
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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;
	}

138
	if (!defined($parms->{'acc'})) {
139
140
141
142
143
144
145
		return -202;
	}


	my $detail;
	$detail->{'Ref'} = $parms->{'ref'};
	$detail->{'Name'} = $parms->{'name'};
146
	$detail->{'GLAccRef'} = $parms->{'acc'};
147
148
	$detail->{'RegNumber'} = $parms->{'reg'};
	$detail->{'TaxReference'} = $parms->{'taxref'};
149
	$detail->{'CreateSubAcc'} = $parms->{'createsubacc'};
150
151
152
153
154
155
156
157
158
	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) {
159
		print($OUT " => Account is not a LIABILITY account\n");
160
161
162
163
164
165
166
167
168
169
170
171
172
173
	}

	return $res;
}


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

174
	if (!defined($parms->{'supplier'})) {
175
176
177
178
179
180
181
182
183
184
185
186
		return -202;
	}

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

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

	my $detail;
187
	$detail->{'SupplierRef'} = $parms->{'supplier'};
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
	$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);

212
	if (!defined($parms->{'supplier'})) {
213
214
215
216
217
218
219
220
221
222
223
224
225
		return -202;
	}

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

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


	my $detail;
226
	$detail->{'SupplierRef'} = $parms->{'supplier'};
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
	$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
244
245
246
247
248
249
250
# Show supplier
sub show
{
	my ($OUT,@args) = @_;

	my $parms = parseArgs(@args);

251
	if (!defined($parms->{'supplier'})) {
Nigel Kukard's avatar
Nigel Kukard committed
252
253
254
255
		return -202;
	}

	my $detail;
256
	$detail->{'SupplierRef'} = $parms->{'supplier'};
Nigel Kukard's avatar
Nigel Kukard committed
257
258
259
260

	use Data::Dumper;

	my $supplier = soapCall($OUT,"Suppliers","getSupplier",$detail);
261
	return -1 if (ref $supplier ne "HASH");
Nigel Kukard's avatar
Nigel Kukard committed
262
263
	
	my $addies = soapCall($OUT,"Suppliers","getAddresses",$detail);
264
	return -1 if (ref $addies ne "ARRAY");
Nigel Kukard's avatar
Nigel Kukard committed
265
266

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

269
270
271
	my $emailAddies = soapCall($OUT,"Suppliers","getEmailAddresses",$detail);
	return -1 if (ref $addies ne "ARRAY");

Nigel Kukard's avatar
Nigel Kukard committed
272
	print("
273
274
275
276
277
278
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

");

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

foreach my $item (@{$phones}) {
	print("
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
294
295
296
297
298
299
300
}

foreach my $item (@{$emailAddies}) {
	print("
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
Nigel Kukard's avatar
Nigel Kukard committed
301
302
303
304
305
306
}

	return 0;
}


307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# 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;
}


335
336
337
338
339
340




1;
# vim: ts=4