Suppliers.pm 8.64 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

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

	if (@args > 0) {
Nigel Kukard's avatar
Nigel Kukard committed
102
103
		print($OUT "  => ERROR: Too many arguments provided\n");
		return ERR_C_PARAM;
104
105
106
107
	}

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

Nigel Kukard's avatar
Nigel Kukard committed
108
	if ($res->{'Result'} == RES_OK) {
109
		print $OUT swrite(<<'END', "ID", "Code", "Name", "RegNumber", "TaxRef", "GLAccount");
110
111
112
+========+===========+===============================================+=====================+================+=================+
| @||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||||||||| | @||||||||||||| | @|||||||||||||| |
+========+===========+===============================================+=====================+================+=================+
113
END
Nigel Kukard's avatar
Nigel Kukard committed
114
		foreach my $item (@{$res->{'Data'}}) {
115
			print $OUT swrite(<<'END', $item->{'ID'}, $item->{'Code'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAccountNumber'});
116
| @<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<< | @<<<<<<<<<<<<<< |
117
118
END
			}
119
			print $OUT swrite(<<'END');
120
+========+===========+===============================================+=====================+================+=================+
121
122
END
	} else {
Nigel Kukard's avatar
Nigel Kukard committed
123
		soapDebug($OUT,$res);
124
125
	}

Nigel Kukard's avatar
Nigel Kukard committed
126
	return $res->{'Result'};
127
128
129
130
131
132
133
134
135
136
137
}


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

138
	if (!defined($parms->{'code'})) {
Nigel Kukard's avatar
Nigel Kukard committed
139
		print($OUT "  => ERROR: Parameter 'code' not defined\n");
140
		return ERR_C_PARAM;
141
142
143
	}

	if (!defined($parms->{'name'})) {
Nigel Kukard's avatar
Nigel Kukard committed
144
		print($OUT "  => ERROR: Parameter 'name' not defined\n");
145
		return ERR_C_PARAM;
146
147
	}

148
	if (!defined($parms->{'account'})) {
Nigel Kukard's avatar
Nigel Kukard committed
149
		print($OUT "  => ERROR: Parameter 'account' not defined\n");
150
		return ERR_C_PARAM;
151
152
153
154
	}


	my $detail;
155
	$detail->{'Code'} = $parms->{'code'};
156
	$detail->{'Name'} = $parms->{'name'};
157
	$detail->{'GLAccountNumber'} = $parms->{'account'};
158
159
	$detail->{'RegNumber'} = $parms->{'reg'};
	$detail->{'TaxReference'} = $parms->{'taxref'};
Nigel Kukard's avatar
Nigel Kukard committed
160
	$detail->{'CreateSubAccount'} = $parms->{'createsubaccount'};
161
	my $res = soapCall($OUT,"Suppliers","createSupplier",$detail);
Nigel Kukard's avatar
Nigel Kukard committed
162
163
164
165
166
	
	if ($res->{'Result'} != RES_OK) {
		soapDebug($OUT,$res);
		return $res->{'Result'};
	}
167

Nigel Kukard's avatar
Nigel Kukard committed
168
	return $res->{'Data'};
169
170
171
172
173
174
175
176
177
178
179
}


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

180
	if (!defined($parms->{'supplier'})) {
Nigel Kukard's avatar
Nigel Kukard committed
181
		print($OUT "  => ERROR: Parameter 'supplier' not defined\n");
182
		return ERR_C_PARAM;
183
184
185
	}

	if (!defined($parms->{'type'})) {
Nigel Kukard's avatar
Nigel Kukard committed
186
		print($OUT "  => ERROR: Parameter 'type' not defined\n");
187
		return ERR_C_PARAM;
188
189
190
	}

	if (!defined($parms->{'address'})) {
Nigel Kukard's avatar
Nigel Kukard committed
191
		print($OUT "  => ERROR: Parameter 'address' not defined\n");
192
		return ERR_C_PARAM;
193
194
195
	}

	my $detail;
196
	$detail->{'Code'} = $parms->{'supplier'};
197
198
	$detail->{'Type'} = $parms->{'type'};
	$detail->{'Address'} = $parms->{'address'};
199
	my $res = soapCall($OUT,"Suppliers","linkSupplierAddress",$detail);
Nigel Kukard's avatar
Nigel Kukard committed
200
201
202
203
204
	
	if ($res->{'Result'} != RES_OK) {
		soapDebug($OUT,$res);
		return $res->{'Result'};
	}
205

Nigel Kukard's avatar
Nigel Kukard committed
206
	return $res->{'Data'};
207
208
209
210
211
212
213
214
215
216
217
}


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

218
	if (!defined($parms->{'supplier'})) {
Nigel Kukard's avatar
Nigel Kukard committed
219
		print($OUT "  => ERROR: Parameter 'supplier' not defined\n");
220
		return ERR_C_PARAM;
221
222
223
	}

	if (!defined($parms->{'type'})) {
Nigel Kukard's avatar
Nigel Kukard committed
224
		print($OUT "  => ERROR: Parameter 'type' not defined\n");
225
		return ERR_C_PARAM;
226
227
	}

228
	if (!defined($parms->{'number'})) {
Nigel Kukard's avatar
Nigel Kukard committed
229
		print($OUT "  => ERROR: Parameter 'number' not defined\n");
230
		return ERR_C_PARAM;
231
232
233
234
	}


	my $detail;
235
	$detail->{'Code'} = $parms->{'supplier'};
236
	$detail->{'Type'} = $parms->{'type'};
237
	$detail->{'Number'} = $parms->{'number'};
238
	$detail->{'Name'} = $parms->{'name'};
239
	my $res = soapCall($OUT,"Suppliers","linkSupplierPhoneNumber",$detail);
240

Nigel Kukard's avatar
Nigel Kukard committed
241
242
243
244
245
246
	if ($res->{'Result'} != RES_OK) {
		soapDebug($OUT,$res);
		return $res->{'Result'};
	}

	return $res->{'Data'};
247
248
249
}


Nigel Kukard's avatar
Nigel Kukard committed
250
251
252
253
254
255
256
# Show supplier
sub show
{
	my ($OUT,@args) = @_;

	my $parms = parseArgs(@args);

257
	if (!defined($parms->{'supplier'})) {
258
		return ERR_C_PARAM;
Nigel Kukard's avatar
Nigel Kukard committed
259
260
261
	}

	my $detail;
262
	$detail->{'Code'} = $parms->{'supplier'};
Nigel Kukard's avatar
Nigel Kukard committed
263

Nigel Kukard's avatar
Nigel Kukard committed
264
265
266
267
268
269
270
271
	my $res;

	$res = soapCall($OUT,"Suppliers","getSupplier",$detail);
	if ($res->{'Result'} != RES_OK) {
		soapDebug($OUT,$res);
		return $res->{'Result'};
	}
	my $supplier = $res->{'Data'};
Nigel Kukard's avatar
Nigel Kukard committed
272
	
Nigel Kukard's avatar
Nigel Kukard committed
273
274
275
276
277
278
	$res = soapCall($OUT,"Suppliers","getSupplierAddresses",$detail);
	if ($res->{'Result'} != RES_OK) {
		soapDebug($OUT,$res);
		return $res->{'Result'};
	}
	my $addies = $res->{'Data'};
Nigel Kukard's avatar
Nigel Kukard committed
279

Nigel Kukard's avatar
Nigel Kukard committed
280
281
282
283
284
285
	$res = soapCall($OUT,"Suppliers","getSupplierPhoneNumbers",$detail);
	if ($res->{'Result'} != RES_OK) {
		soapDebug($OUT,$res);
		return $res->{'Result'};
	}
	my $phones = $res->{'Data'};
Nigel Kukard's avatar
Nigel Kukard committed
286

Nigel Kukard's avatar
Nigel Kukard committed
287
288
289
290
291
292
	$res = soapCall($OUT,"Suppliers","getSupplierEmailAddresses",$detail);
	if ($res->{'Result'} != RES_OK) {
		soapDebug($OUT,$res);
		return $res->{'Result'};
	}
	my $emailAddies = $res->{'Data'};
293

294
	print($OUT "
295
ID.....: ".$supplier->{'ID'}."
296
Code...: ".$supplier->{'Code'}."
297
298
299
Name...: ".$supplier->{'Name'}."
Reg....: ".(defined($supplier->{'RegNumber'}) ? $supplier->{'RegNumber'} : "-")."
TaxRef.: ".(defined($supplier->{'TaxReference'}) ? $supplier->{'TaxReference'} : "-")."
300
GLAcc..: ".$supplier->{'GLAccountNumber'}."
Nigel Kukard's avatar
Nigel Kukard committed
301
302
303
304

");

foreach my $item (@{$addies}) {
305
	print($OUT "
Nigel Kukard's avatar
Nigel Kukard committed
306
307
308
309
310
311
Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
}

foreach my $item (@{$phones}) {
312
	print($OUT "
Nigel Kukard's avatar
Nigel Kukard committed
313
Phone Number: ".$item->{'Type'}."
Nigel Kukard's avatar
Nigel Kukard committed
314
".$item->{'Number'}."
Nigel Kukard's avatar
Nigel Kukard committed
315
");
316
317
318
}

foreach my $item (@{$emailAddies}) {
319
	print($OUT "
320
321
322
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
Nigel Kukard's avatar
Nigel Kukard committed
323
324
}

Nigel Kukard's avatar
Nigel Kukard committed
325
	return RES_OK;
Nigel Kukard's avatar
Nigel Kukard committed
326
327
328
}


329
330
331
332
333
334
335
336
337
# Remove supplier
sub remove
{
	my ($OUT,@args) = @_;
	
	
	my $parms = parseArgs(@args);

	if (!defined($parms->{'supplier'})) {
Nigel Kukard's avatar
Nigel Kukard committed
338
339
		print($OUT "  => ERROR: Parameter 'supplier' not defined\n");
		return ERR_C_PARAM;
340
341
342
	}

	my $detail;
343
	$detail->{'Code'} = $parms->{'supplier'};
344
	my $res = soapCall($OUT,"Suppliers","removeSupplier",$detail);
Nigel Kukard's avatar
Nigel Kukard committed
345
	if ($res->{'Result'} != RES_OK) {
Nigel Kukard's avatar
Nigel Kukard committed
346
		soapDebug($OUT,$res);
Nigel Kukard's avatar
Nigel Kukard committed
347
348
349
	}

	return $res->{'Result'};
350
351
352
}


353
354
355
356
357
358




1;
# vim: ts=4