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