Suppliers.pm 5.64 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Author: Nigel Kukard  <nkukard@lbsd.net>
# Date: 14/02/2007
# Desc: Supplier functions
# License: GPL



package ias::client::cmdline::Suppliers;

use strict;

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


use ias::client::misc;
use ias::client::soap;
use ias::client::reportwriter;


# 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");
38
39
40
+========+===========+===============================================+=====================+================+=================+
| @||||| | @|||||||| | @|||||||||||||||||||||||||||||||||||||||||||| | @|||||||||||||||||| | @||||||||||||| | @|||||||||||||| |
+========+===========+===============================================+=====================+================+=================+
41
42
END
		foreach my $item (@{$res}) {
43
			print swrite(<<'END', $item->{'ID'}, $item->{'Ref'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAccRef'});
44
| @<<<<< | @<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<< | @<<<<<<<<<<<<<< |
45
46
47
END
			}
		print swrite(<<'END');
48
+========+===========+===============================================+=====================+================+=================+
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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;
	}

75
	if (!defined($parms->{'acc'})) {
76
77
78
79
80
81
82
		return -202;
	}


	my $detail;
	$detail->{'Ref'} = $parms->{'ref'};
	$detail->{'Name'} = $parms->{'name'};
83
	$detail->{'GLAccRef'} = $parms->{'acc'};
84
85
	$detail->{'RegNumber'} = $parms->{'reg'};
	$detail->{'TaxReference'} = $parms->{'taxref'};
86
	$detail->{'CreateSubAcc'} = $parms->{'createsubacc'};
87
88
89
90
91
92
93
94
95
	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) {
96
		print($OUT " => Account is not a LIABILITY account\n");
97
98
99
100
101
102
103
104
105
106
107
108
109
110
	}

	return $res;
}


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

111
	if (!defined($parms->{'supplier'})) {
112
113
114
115
116
117
118
119
120
121
122
123
		return -202;
	}

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

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

	my $detail;
124
	$detail->{'SupplierRef'} = $parms->{'supplier'};
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
	$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);

149
	if (!defined($parms->{'supplier'})) {
150
151
152
153
154
155
156
157
158
159
160
161
162
		return -202;
	}

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

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


	my $detail;
163
	$detail->{'SupplierRef'} = $parms->{'supplier'};
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
	$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
181
182
183
184
185
186
187
# Show supplier
sub show
{
	my ($OUT,@args) = @_;

	my $parms = parseArgs(@args);

188
	if (!defined($parms->{'supplier'})) {
Nigel Kukard's avatar
Nigel Kukard committed
189
190
191
192
		return -202;
	}

	my $detail;
193
	$detail->{'SupplierRef'} = $parms->{'supplier'};
Nigel Kukard's avatar
Nigel Kukard committed
194
195
196
197

	use Data::Dumper;

	my $supplier = soapCall($OUT,"Suppliers","getSupplier",$detail);
198
	return -1 if (ref $supplier ne "HASH");
Nigel Kukard's avatar
Nigel Kukard committed
199
200
	
	my $addies = soapCall($OUT,"Suppliers","getAddresses",$detail);
201
	return -1 if (ref $addies ne "ARRAY");
Nigel Kukard's avatar
Nigel Kukard committed
202
203

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

206
207
208
	my $emailAddies = soapCall($OUT,"Suppliers","getEmailAddresses",$detail);
	return -1 if (ref $addies ne "ARRAY");

Nigel Kukard's avatar
Nigel Kukard committed
209
	print("
210
211
212
213
214
215
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230

");

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

foreach my $item (@{$phones}) {
	print("
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
231
232
233
234
235
236
237
}

foreach my $item (@{$emailAddies}) {
	print("
Email Address: ".$item->{'Type'}."
".$item->{'Address'}."
");
Nigel Kukard's avatar
Nigel Kukard committed
238
239
240
241
242
243
}

	return 0;
}


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# 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;
}


272
273
274
275
276
277




1;
# vim: ts=4