| 1 | package WebService::Xero::Invoice; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 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 | 2 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | our @PARAMS = qw/Date DueDate Status LineAmountTypes SubTotal TotalTax Total UpdatedDateUTC CurrencyCode Type InvoiceID InvoiceNumber AmountDue AmountPaid AmountCredited CurrencyRate/; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 2 | 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<https://github.com/XeroAPI/XeroAPI-Schemas/blob/master/src/main/resources/XeroSchemas/v2.00/Invoice.xsd>. | ||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 47 | 3 | my ( $class, %params ) = @_; | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | my $self = bless | ||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||
| 51 | debug => $params{debug}, | ||||||||||||||||||||||||||||||||
| 52 | 3 | API_URL => 'https://api.xero.com/api.xro/2.0/Invoices' | |||||||||||||||||||||||||||||||
| 53 | }, $class; | ||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | foreach my $key (@PARAMS) { $self->{$key} = defined $params{$key} ? $params{$key} : ''; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 3 | 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
create_new_through_agent: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 67 | 0 | my ( $self, %params ) = @_; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | croak('need a valid agent parameter') unless ( ref( $params{agent} ) =~ /Agent/m ); ## | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 0 | my $new = WebService::Xero::Invoice->new( %params ); | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | ## TODO: Create | ||||||||||||||||||||||||||||||||
| 74 | 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 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new_from_api_data: called CC=6 SCAR=29.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 93 | 2 | my ( $self, $data ) = @_; | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( ref($data->{Invoices}) eq 'ARRAY' and scalar(@{$data->{Invoices}})==1 ) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $data->{"Invoices"} eq "ARRAY" and scalar @{$data->{"Invoices"};} == 1
MC/DC0%0/2
ref $data->{"Invoices"} eq "ARRAY" and scalar @{$data->{"Invoices"};} == 1
ref $data->{"Invoices"} eq "ARRAY"
scalar @{$data->{"Invoices"};} == 1
Truth table33%1/3
A and B
A= ref $data->{"Invoices"} eq "ARRAY"B= scalar @{$data->{"Invoices"};} == 1
| |||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||
| 97 | 0 | return WebService::Xero::Invoice->new( %{$data->{Invoices}[0]} ) | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | elsif ( ref($data->{Invoices}) eq 'ARRAY' and scalar(@{$data->{Invoices}})>1 ) | ||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $data->{"Invoices"} eq "ARRAY" and scalar @{$data->{"Invoices"};} > 1
MC/DC0%0/2
ref $data->{"Invoices"} eq "ARRAY" and scalar @{$data->{"Invoices"};} > 1
ref $data->{"Invoices"} eq "ARRAY"
scalar @{$data->{"Invoices"};} > 1
Truth table33%1/3
A and B
A= ref $data->{"Invoices"} eq "ARRAY"B= scalar @{$data->{"Invoices"};} > 1
| |||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||
| 101 | 0 | my $invoices = []; | |||||||||||||||||||||||||||||||
| 102 | 0 | foreach my $invoice_struct ( @{$data->{Invoices}} ) | |||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||
| 104 | 0 | push @$invoices, WebService::Xero::Invoice->new( %{$invoice_struct} ); | |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | 0 | return $invoices; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | 2 | 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 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
as_text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 120 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 121 | 1 | return "Invoice:\n" . join("\n", map { "$_ : $self->{$_}" } @PARAMS); | |||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
get_pdf: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 137 | 0 | 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<< <peter at computerpros.com.au> >> | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | =head1 REFERENCE | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | =head1 BUGS | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | Please report any bugs or feature requests to C<bug-webservice-xero at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||
| 156 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-Xero>. 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<https://developer.xero.com/documentation/api/contacts/> | ||||||||||||||||||||||||||||||||
| 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<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||||||
| 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 | 2 | 1; # End of WebService::Xero | |||||||||||||||||||||||||||||||