Suppliers.pm 4.95 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
43
END
		foreach my $item (@{$res}) {
			print swrite(<<'END', $item->{'ID'}, $item->{'Ref'}, $item->{'Name'}, defined($item->{'RegNumber'}) ? $item->{'RegNumber'} : '-', defined($item->{'TaxReference'}) ? $item->{'TaxReference'} : '-', $item->{'GLAcc'});
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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;
	}

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


	my $detail;
	$detail->{'Ref'} = $parms->{'ref'};
	$detail->{'Name'} = $parms->{'name'};
	$detail->{'GLAccID'} = $parms->{'accid'};
	$detail->{'RegNumber'} = $parms->{'reg'};
	$detail->{'TaxReference'} = $parms->{'taxref'};
	my $res = soapCall($OUT,"Suppliers","createSupplier",$detail);

	if ($res == -2) {
		print($OUT " => Database error\n");
		return undef;
	} elsif ($res == -3) {
		print($OUT " => Parameter problem\n");
		return undef;
	} elsif ($res == -4) {
		print($OUT " => Cannot find GL account\n");
		return undef;
	} elsif ($res == -5) {
98
		print($OUT " => Account is not a LIABILITY account\n");
99
100
101
102
103
104
105
106
107
108
109
110
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
		return undef;
	}

	return $res;
}


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

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

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

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


	my $detail;
	$detail->{'SupplierID'} = $parms->{'supplierid'};
	$detail->{'Type'} = $parms->{'type'};
	$detail->{'Address'} = $parms->{'address'};
	my $res = soapCall($OUT,"Suppliers","linkAddress",$detail);

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

	return $res;
}


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

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

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

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


	my $detail;
	$detail->{'SupplierID'} = $parms->{'supplierid'};
	$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");
		return undef;
	} elsif ($res == -3) {
		print($OUT " => Parameter problem\n");
		return undef;
	} elsif ($res == -4) {
		print($OUT " => Supplier not found\n");
		return undef;
	}

	return $res;
}


Nigel Kukard's avatar
Nigel Kukard committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# Show supplier
sub show
{
	my ($OUT,@args) = @_;

	my $parms = parseArgs(@args);

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

	my $detail;
	$detail->{'SupplierID'} = $parms->{'supplierid'};

	use Data::Dumper;

	my $supplier = soapCall($OUT,"Suppliers","getSupplier",$detail);

#return -1 if ($supplier ne "HASH");
	
	my $addies = soapCall($OUT,"Suppliers","getAddresses",$detail);
#	return -1 if ($addies ne "ARRAY");

	my $phones = soapCall($OUT,"Suppliers","getPhoneNumbers",$detail);
#	return -1 if ($phones ne "ARRAY");

	print("
ID.....:".$supplier->{'ID'}."
Ref....:".$supplier->{'Ref'}."
Name...:".$supplier->{'Name'}."
Reg....:".$supplier->{'RegNumber'}."
TaxRef.:".$supplier->{'TaxReference'}."
GLAcc..: ".$supplier->{'GLAcc'}."

");

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

foreach my $item (@{$phones}) {
	print("
Phone Number: ".$item->{'Type'}."
".$item->{'PhNumber'}."
");
}

	return 0;
}


245
246
247
248
249
250




1;
# vim: ts=4