Suppliers.pm 8.02 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
44
45
46
47
48
					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",
49
					Regex		=> "linkaddr ",
Nigel Kukard's avatar
Nigel Kukard committed
50
51
52
53
54
55
					Desc		=> "Link in an address",
					Help		=> 'linkaddr supplier="<supplier ref>" type="<billing or shipping>" address="<address>"',
					Function	=> \&linkAddress,
				},
				{
					MenuItem 	=> "LinkEmail",
56
					Regex		=> "linkemail ",
Nigel Kukard's avatar
Nigel Kukard committed
57
58
59
60
61
62
					Desc		=> "Link in an email address",
					Help		=> 'linkemail(?:addr)? supplier="<supplier ref>" type="<accounts or general>" address="<address>"',
					Function	=> \&linkEmailAddress,
				},
				{
					MenuItem 	=> "LinkPhNum",
63
					Regex		=> "linkphnum ",
Nigel Kukard's avatar
Nigel Kukard committed
64
65
66
67
68
69
					Desc		=> "Link in a phone number",
					Help		=> 'linkphnum supplier="<supplier ref>" type="<phone or fax>" phnumber="<phone number>" [name="<name>"]',
					Function	=> \&linkPhoneNumber,
				},
				{
					MenuItem 	=> "Remove",
70
					Regex		=> "remove ",
Nigel Kukard's avatar
Nigel Kukard committed
71
72
73
74
75
76
					Desc		=> "Remove supplier",
					Help		=> 'remove supplier="<supplier ref>"',
					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
86
87
88
89
90
91
92
93
94
					Desc		=> "Show supplier",
					Help		=> 'show supplier="<client ref>"',
					Function	=> \&show,
				},
			],
		},
	],
};


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

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

146
	if (!defined($parms->{'acc'})) {
147
148
149
150
151
152
153
		return -202;
	}


	my $detail;
	$detail->{'Ref'} = $parms->{'ref'};
	$detail->{'Name'} = $parms->{'name'};
154
	$detail->{'GLAccRef'} = $parms->{'acc'};
155
156
	$detail->{'RegNumber'} = $parms->{'reg'};
	$detail->{'TaxReference'} = $parms->{'taxref'};
157
	$detail->{'CreateSubAcc'} = $parms->{'createsubacc'};
158
159
160
161
162
163
164
165
166
	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) {
167
		print($OUT " => Account is not a LIABILITY account\n");
168
169
170
171
172
173
174
175
176
177
178
179
180
181
	}

	return $res;
}


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

182
	if (!defined($parms->{'supplier'})) {
183
184
185
186
187
188
189
190
191
192
193
194
		return -202;
	}

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

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

	my $detail;
195
	$detail->{'SupplierRef'} = $parms->{'supplier'};
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
	$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);

220
	if (!defined($parms->{'supplier'})) {
221
222
223
224
225
226
227
228
229
230
231
232
233
		return -202;
	}

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

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


	my $detail;
234
	$detail->{'SupplierRef'} = $parms->{'supplier'};
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
	$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
252
253
254
255
256
257
258
# Show supplier
sub show
{
	my ($OUT,@args) = @_;

	my $parms = parseArgs(@args);

259
	if (!defined($parms->{'supplier'})) {
Nigel Kukard's avatar
Nigel Kukard committed
260
261
262
263
		return -202;
	}

	my $detail;
264
	$detail->{'SupplierRef'} = $parms->{'supplier'};
Nigel Kukard's avatar
Nigel Kukard committed
265
266
267
268

	use Data::Dumper;

	my $supplier = soapCall($OUT,"Suppliers","getSupplier",$detail);
269
	return -1 if (ref $supplier ne "HASH");
Nigel Kukard's avatar
Nigel Kukard committed
270
271
	
	my $addies = soapCall($OUT,"Suppliers","getAddresses",$detail);
272
	return -1 if (ref $addies ne "ARRAY");
Nigel Kukard's avatar
Nigel Kukard committed
273
274

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

277
278
279
	my $emailAddies = soapCall($OUT,"Suppliers","getEmailAddresses",$detail);
	return -1 if (ref $addies ne "ARRAY");

Nigel Kukard's avatar
Nigel Kukard committed
280
	print("
281
282
283
284
285
286
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

");

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

foreach my $item (@{$phones}) {
	print("
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
302
303
304
305
306
307
308
}

foreach my $item (@{$emailAddies}) {
	print("
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
Nigel Kukard's avatar
Nigel Kukard committed
309
310
311
312
313
314
}

	return 0;
}


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# 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;
}


343
344
345
346
347
348




1;
# vim: ts=4