line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Xero::Item; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1263
|
use 5.006; |
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
35
|
|
5
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
41
|
|
6
|
2
|
|
|
2
|
|
7
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
111
|
|
7
|
2
|
|
|
2
|
|
9
|
use Data::Dumper; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1302
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
WebService::Xero::Item - Object encapulates Item data returned by API |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.11 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @PARAMS = qw/Name ItemID Code Description UpdatedDateUTC IsTrackedAsInventory InventoryAssetAccountCode TotalCostPool QuantityOnHand IsSold IsPurchased/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @ARRAY_PARAMS = qw//; ## TODO: implement |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Object to describe an Item record as specified by Xero API and the associated DTD at |
29
|
|
|
|
|
|
|
L. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Mostly a wrapper for Xero Item data structure. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use WebService::Xero::Item; |
35
|
|
|
|
|
|
|
my $foo = WebService::Xero::Item->new(); |
36
|
|
|
|
|
|
|
... |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 new() |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new |
47
|
|
|
|
|
|
|
{ |
48
|
2
|
|
|
2
|
1
|
5
|
my ( $class, %params ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $self = bless |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
API_URL => 'https://api.xero.com/api.xro/2.0/Items', |
53
|
|
|
|
|
|
|
debug => $params{debug}, |
54
|
2
|
|
|
|
|
10
|
PurchaseDetails => { UnitPrice => 0, AccountCode=> '', COGSAccountCode=> '', TaxType=> '', }, |
55
|
|
|
|
|
|
|
SalesDetails => { UnitPrice => 0, AccountCode => '', TaxType=> '', }, |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
}, $class; |
58
|
2
|
50
|
|
|
|
5
|
foreach my $key (@PARAMS) { $self->{$key} = defined $params{$key} ? $params{$key} : ''; } |
|
22
|
|
|
|
|
41
|
|
59
|
|
|
|
|
|
|
|
60
|
2
|
50
|
|
|
|
24
|
$self->{PurchaseDetails}{UnitPrice} = $params{PurchaseDetails}{UnitPrice} if defined $params{PurchaseDetails}{UnitPrice}; |
61
|
2
|
50
|
|
|
|
6
|
$self->{PurchaseDetails}{COGSAccountCode} = $params{PurchaseDetails}{COGSAccountCode} if defined $params{PurchaseDetails}{COGSAccountCode}; |
62
|
2
|
50
|
|
|
|
3
|
$self->{PurchaseDetails}{AccountCode} = $params{PurchaseDetails}{AccountCode} if defined $params{PurchaseDetails}{AccountCode}; |
63
|
2
|
50
|
|
|
|
4
|
$self->{PurchaseDetails}{TaxType} = $params{PurchaseDetails}{TaxType} if defined $params{PurchaseDetails}{TaxType}; |
64
|
|
|
|
|
|
|
|
65
|
2
|
50
|
|
|
|
5
|
$self->{PurchaseDetails}{UnitPrice} = $params{PurchaseDetails}{UnitPrice} if defined $params{PurchaseDetails}{UnitPrice}; |
66
|
2
|
50
|
|
|
|
5
|
$self->{PurchaseDetails}{AccountCode} = $params{PurchaseDetails}{AccountCode} if defined $params{PurchaseDetails}{AccountCode}; |
67
|
2
|
50
|
|
|
|
3
|
$self->{PurchaseDetails}{TaxType} = $params{PurchaseDetails}{TaxType} if defined $params{PurchaseDetails}{TaxType}; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
10
|
return $self; #->_validate_agent(); ## derived classes will validate this |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 create_new_through_agent() |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
not ready to use yet. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub create_new_through_agent |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %params ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
0
|
croak('need a valid agent parameter') unless ( ref( $params{agent} ) =~ /Agent/m ); ## |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
my $new = WebService::Xero::Item->new( %params ); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
## TODO: Create |
89
|
0
|
|
|
|
|
0
|
return $new; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 new_from_api_data() |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
creates a new instance from the data provided by querying the API organisation end point |
96
|
|
|
|
|
|
|
( typically handled by WebService::Xero::Agent->do_xero_api_call() ) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Example Contact Queries using Xero Agent that return Data consumable by this method: |
99
|
|
|
|
|
|
|
https://api.xero.com/api.xro/2.0/Items |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns undef, a single object instance or an array of object instances depending on the data input provided. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub new_from_api_data |
107
|
|
|
|
|
|
|
{ |
108
|
1
|
|
|
1
|
1
|
2
|
my ( $self, $data ) = @_; |
109
|
1
|
50
|
33
|
|
|
8
|
return WebService::Xero::Item->new( %{$data->{Items}[0]} ) if ( ref($data->{Items}) eq 'ARRAY' and scalar(@{$data->{Items}})==1 ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
110
|
1
|
50
|
33
|
|
|
3
|
if ( ref($data->{Items}) eq 'ARRAY' and scalar(@{$data->{Items}})>1 ) |
|
0
|
|
|
|
|
0
|
|
111
|
|
|
|
|
|
|
{ |
112
|
0
|
|
|
|
|
0
|
my $Items = []; |
113
|
0
|
|
|
|
|
0
|
foreach my $Item_struct ( @{$data->{Items}} ) |
|
0
|
|
|
|
|
0
|
|
114
|
|
|
|
|
|
|
{ |
115
|
0
|
|
|
|
|
0
|
push @$Items, WebService::Xero::Item->new( %{$Item_struct} ); |
|
0
|
|
|
|
|
0
|
|
116
|
|
|
|
|
|
|
} |
117
|
0
|
|
|
|
|
0
|
return $Items; |
118
|
|
|
|
|
|
|
} |
119
|
1
|
|
|
|
|
3
|
return WebService::Xero::Item->new( debug=> $data ); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 as_text() |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub as_text |
133
|
|
|
|
|
|
|
{ |
134
|
1
|
|
|
1
|
1
|
3
|
my ( $self ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
2
|
my $ret = "Item:\n" . join("\n", map { "$_ : $self->{$_}" } @PARAMS); |
|
11
|
|
|
|
|
20
|
|
137
|
1
|
|
|
|
|
4
|
$ret .= " PurchaseDetails::UnitPrice $self->{PurchaseDetails}{UnitPrice}\n"; |
138
|
1
|
|
|
|
|
2
|
$ret .= " PurchaseDetails::UnitPrice $self->{PurchaseDetails}{UnitPrice}\n"; |
139
|
|
|
|
|
|
|
|
140
|
1
|
|
|
|
|
6
|
return $ret; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Peter Scott, C<< >> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 REFERENCE |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 BUGS |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
155
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
156
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 API LIMITATIONS |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Emailing Items - FROM Xero Developer Docs ( https://developer.xero.com/documentation/api/Items/ ) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
It is not possible to email an Item through the Xero application using the Xero accounting API. |
164
|
|
|
|
|
|
|
To track progress on this feature request, or to add your support to it, please vote here. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 SUPPORT |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
perldoc WebService::Xero::Item |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
You can also look for information at: |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over 4 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * Xero Developer API Docs |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 TODO |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Copyright 2016 Peter Scott. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
198
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
199
|
|
|
|
|
|
|
copy of the full license at: |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
204
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
205
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
206
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
209
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
210
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
213
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
216
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
217
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
218
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
219
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
220
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
221
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
222
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
225
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
226
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
227
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
228
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
229
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
230
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
231
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; # End of WebService::Xero |