cXML/Amount.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 24 / 24 Conditioncond 100% 12 / 12 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 105 / 105 CC 20 SCAR 26.5
CC
20
Cov
100%
to_node
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 14.1
« cXML/Message/PunchOutOrder.pm ↑ Summary cXML/Address/Postal.pm »
1 =encoding utf-8
2  
3 =head1 NAME
4  
5 Business::cXML::Amount - cXML amounts
6  
7 =head1 SYNOPSIS
8  
9 use Business::cXML::Amount;
10 my $charge = new Business::cXML::Amount 'Charge' {
11 currency => 'CAD',
12 amount => '17.99',
13 };
14  
15 =head1 DESCRIPTION
16  
17 Object representation of the common cXML amounts:
18  
19 =over
20  
21 C<AdditionalCost>
22 C<AvailablePrice>
23 C<Charge>
24 C<DeductedPrice>
25 C<DeductionAmount>
26 C<DepositAmount>
27 C<DiscountAmount>
28 C<DiscountBasis>
29 C<DueAmount>
30 C<ExactAmount>
31 C<ExpectedLimit>
32 C<Fee>
33 C<FeeAmount>
34 C<FixedAmount>
35 C<GoodsAndServiceAmount>
36 C<GrossAmount>
37 C<GrossProgressPaymentAmount>
38 C<InformationalAmount>
39 C<InformationalPrice>
40 C<InformationalPriceExclTax>
41 C<MaxAmount>
42 C<MaxReleaseAmount>
43 C<MinAmount>
44 C<MinReleaseAMount>
45 C<NetAmount>
46 C<OriginalPrice>
47 C<OverallLimit>
48 C<PartialAmount>
49 C<Penalty>
50 C<Shipping>
51 C<ShippingAmount>
52 C<SpecialHandlingAmount>
53 C<SubtotalAmount>
54 C<Tax>
55 C<TaxableAmount>
56 C<TaxAdjustment>
57 C<TaxAdjustmentDetail>
58 C<TaxAmount>
59 C<TotalAllowances>
60 C<TotalAmountInBillingCurrency>
61 C<TotalAmountInPostedCurrency>
62 C<TotalAmountWithoutTax>
63 C<TotalCharges>
64 C<TotalRetailAmount>
65 C<TotalReturnableItemsDepositAmount>
66 C<UnitGrossPrice>
67 C<UnitNetPriceCorrection>
68  
69 =back
70  
71 Not all variations allow the same attributes, but since they overwhelmingly
72 share the same basic function and structure, they were grouped into a single
73 object.
74  
75 Specifically B<NOT> implemented are:
76  
77 =over
78  
79 =item * C<Distribution> sub-section
80  
81 =item * C<Modifications> sub-section
82  
83 =item * C<PriceBasisQuantity> sub-section
84  
85 =item * C<AdditionalCost> with a C<Percentage> sub-section (only its C<Money> is implemented)
86  
87 =back
88  
89 =head1 METHODS
90  
91 See L<Business::cXML::Object/COMMON METHODS>.
92  
93 =head1 PROPERTY METHODS
94  
95 See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate.
96  
97 =over
98  
99 =cut
100  
101 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
103  
104 package Business::cXML::Amount;
105 2 ▶use base qw(Business::cXML::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
106  
107 2 ▶use Business::cXML::Amount::TaxDetail;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 2 ▶use XML::LibXML::Ferry;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 2 ▶use constant NODENAME => 'Amount';
Subroutine BEGIN: called CC=1 SCAR=0.0
111 2 ▶use constant PROPERTIES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
112 currency => 'USD',
113 amount => '0.00',
114 description => undef,
115 type => undef,
116 fees => [],
117 tracking_domain => undef,
118 tracking_id => undef,
119 tax_details => [],
120 taxadj_details => [],
121 category => '',
122 region => undef,
123 2 );
124 2 ▶use constant OBJ_PROPERTIES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
125 fees => [ 'Business::cXML::Amount', 'Fee' ],
126 tax_details => 'Business::cXML::Amount::TaxDetail',
127 taxadj_details => [ 'Business::cXML::Amount', 'TaxAdjustmentDetail' ],
128 description => 'Business::cXML::Description',
129 2 );
130  
131 14 ▶sub from_node {
Subroutine from_node: called CC=1 SCAR=0.0
Pod documented
132 14 my ($self, $el) = @_;
133  
134 14 $el->ferry($self, {
135 trackingDomain => 'tracking_domain',
136 trackingId => 'tracking_id',
137 tracking => '__OBSOLETE',
138 Money => { __text => 'amount' },
139 Fee => [ 'fees', 'Business::cXML::Amount'],
140 Percentage => '__UNIMPLEMENTED',
141 PriceBasisQuantity => '__UNIMPLEMENTED',
142 TaxDetail => [ 'tax_details', 'Business::cXML::Amount::TaxDetail' ],
143 TaxAdjustmentDetail => [ 'taxadj_details', 'Business::cXML::Amount' ],
144 Description => [ 'description', 'Business::cXML::Description' ],
145 Distribution => '__UNIMPLEMENTED',
146 Modifications => '__UNIMPLEMENTED',
147 });
148 }
149  
150 16 ▶sub to_node {
Subroutine to_node: called CC=20 SCAR=30.0
Pod documented
151 16 my ($self, $doc) = @_;
152 16 my $node = $doc->create($self->{_nodeName});
153  
154 16 ▶ $self->{type} = 'other' if $self->{_nodeName} eq 'AvailablePrice' && !defined $self->{type};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_nodeName"} eq "AvailablePrice" and not defined $self->{"type"} 1 15 16
Condition100%3/3
$self->{"_nodeName"} eq "AvailablePrice" and not defined $self->{"type"}
!ll&&!rl&&r
1411
MC/DC100%2/2
$self->{"_nodeName"} eq "AvailablePrice" and not defined $self->{"type"}
$self->{"_nodeName"} eq "AvailablePrice" not defined $self->{"type"}
Truth table100%3/3
A and not(B)
A= $self->{"_nodeName"} eq "AvailablePrice"B= not defined $self->{"type"}
ABresult
0X0
100
111
155 16 ▶ $node->{type} = $self->{type} if defined $self->{type} && $self->{_nodeName} =~ /^(AvailablePrice|Fee|OriginalPrice)$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"type"} and $self->{"_nodeName"} =~ /^(AvailablePrice|Fee|OriginalPrice)$/u 2 14 16
Condition100%3/3
defined $self->{"type"} and $self->{"_nodeName"} =~ /^(AvailablePrice|Fee|OriginalPrice)$/u
!ll&&!rl&&r
1312
MC/DC100%2/2
defined $self->{"type"} and $self->{"_nodeName"} =~ /^(AvailablePrice|Fee|OriginalPrice)$/u
defined $self->{"type"} $self->{"_nodeName"} =~ /^(AvailablePrice|Fee|OriginalPrice)$/u
Truth table100%3/3
A and B
A= defined $self->{"type"}B= $self->{"_nodeName"} =~ /^(AvailablePrice|Fee|OriginalPrice)$/u
ABresult
0X0
100
111
156 16 ▶ if ($self->{_nodeName} eq 'TaxAdjustmentDetail') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_nodeName"} eq "TaxAdjustmentDetail") 2 14 16
157 2 $node->{category} = $self->{category};
158 2 ▶ $node->{region} = $self->{region} if defined $self->{region};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"region"} 1 1 2
159 };
160  
161 16 ▶ if ($self->{_nodeName} eq 'Shipping') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_nodeName"} eq "Shipping") 2 14 16
162 2 ▶ $node->{trackingDomain} = $self->{tracking_domain} if defined $self->{tracking_domain};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"tracking_domain"} 1 1 2
163 2 ▶ $node->{trackingId} = $self->{tracking_id} if defined $self->{tracking_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"tracking_id"} 1 1 2
164 };
165  
166 16 $node->add('Money', $self->{amount}, currency => $self->{currency});
167  
168 16 ▶ if ($self->{_nodeName} eq 'FeeAmount') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_nodeName"} eq "FeeAmount") 1 15 16
169 1 $node->add($_->to_node($node)) foreach (@{ $self->{fees} });
170 };
171  
172 16 ▶ $self->description({}) if !defined($self->{description}) && $self->{_nodeName} =~ /^(Penalty|Shipping|Tax)$/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self->{"description"} and $self->{"_nodeName"} =~ /^(Penalty|Shipping|Tax)$/u 1 15 16
Condition100%3/3
not defined $self->{"description"} and $self->{"_nodeName"} =~ /^(Penalty|Shipping|Tax)$/u
!ll&&!rl&&r
781
MC/DC100%2/2
not defined $self->{"description"} and $self->{"_nodeName"} =~ /^(Penalty|Shipping|Tax)$/u
not defined $self->{"description"} $self->{"_nodeName"} =~ /^(Penalty|Shipping|Tax)$/u
Truth table100%3/3
not(A) and B
A= not defined $self->{"description"}B= $self->{"_nodeName"} =~ /^(Penalty|Shipping|Tax)$/u
ABresult
0X0
100
111
173 $node->add($self->{description}->to_node($node))
174 if defined $self->{description}
175 16 ▶ && $self->{_nodeName} =~ /^(AvailablePrice|Penalty|Shipping|SpecialHandlingAmount|Tax)$/
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"description"} and $self->{"_nodeName"} =~ /^(AvailablePrice|Penalty|Shipping|SpecialHandlingAmount|Tax)$/u 7 9 16
Condition100%3/3
defined $self->{"description"} and $self->{"_nodeName"} =~ /^(AvailablePrice|Penalty|Shipping|SpecialHandlingAmount|Tax)$/u
!ll&&!rl&&r
817
MC/DC100%2/2
defined $self->{"description"} and $self->{"_nodeName"} =~ /^(AvailablePrice|Penalty|Shipping|SpecialHandlingAmount|Tax)$/u
defined $self->{"description"} $self->{"_nodeName"} =~ /^(AvailablePrice|Penalty|Shipping|SpecialHandlingAmount|Tax)$/u
Truth table100%3/3
A and B
A= defined $self->{"description"}B= $self->{"_nodeName"} =~ /^(AvailablePrice|Penalty|Shipping|SpecialHandlingAmount|Tax)$/u
ABresult
0X0
100
111
176 ;
177  
178 16 ▶ if ($self->{_nodeName} eq 'Tax') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_nodeName"} eq "Tax") 3 13 16
179 3 $node->add($_->to_node($node)) foreach (@{ $self->{tax_details} });
180 };
181 16 ▶ if ($self->{_nodeName} eq 'TaxAdjustment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_nodeName"} eq "TaxAdjustment") 2 14 16
182 2 $node->add($_->to_node($node)) foreach (@{ $self->{taxadj_details} });
183 };
184  
185 16 return $node;
186 }
187  
188 =item C<B<currency>>
189  
190 Mandatory, i.e. C<USD> (default)
191  
192 =item C<B<amount>>
193  
194 Mandatory, i.e C<0.0> (default). Use a string if you want control over formatting.
195  
196 =back
197  
198 =head3 C<AvailablePrice>, C<Penalty>, C<Shipping>, C<SpecialHandlingAmount>, C<Tax> add:
199  
200 =over
201  
202 =item C<B<description>>
203  
204 Optional, L<Business::cXML::Description> object
205  
206 =back
207  
208 =head3 C<AvailablePrice>, C<Fee>, C<OriginalPrice> add:
209  
210 =over
211  
212 =item C<B<type>>
213  
214 Optional. For C<AvailablePrice>, it is expected to be one of: C<lowest>,
215 C<lowestCompliant>, C<highestCompliant>, C<highest>, C<other> (default)
216  
217 =back
218  
219 =head3 C<FeeAmount> adds:
220  
221 =over
222  
223 =item C<B<fees>[]>
224  
225 Optional, L<Business::cXML::Amount> objects of C<Fee> type
226  
227 =back
228  
229 =head3 C<Shipping> adds:
230  
231 =over
232  
233 =item C<B<tracking_domain>>
234  
235 Optional, logistics supplier, i.e. C<FedEx>, C<UPS>
236  
237 =item C<B<tracking_id>>
238  
239 Optional, logistics supplier tracking number
240  
241 =back
242  
243 =head3 C<Tax> adds:
244  
245 =over
246  
247 =item C<B<tax_details>[]>
248  
249 Optional, L</Business::cXML::Amount::TaxDetail> objects
250  
251 =back
252  
253 =head3 C<TaxAdjustment> adds:
254  
255 =over
256  
257 =item C<B<taxadj_details>[]>
258  
259 Optional, L<Business::cXML::Amount> objects named C<TaxAdjustmentDetail>
260  
261 =back
262  
263 =head3 C<TaxAdjustmentDetail> adds:
264  
265 =over
266  
267 =item C<B<category>>
268  
269 Mandatory
270  
271 =item C<B<region>>
272  
273 Optional
274  
275 =back
276  
277 =head1 AUTHOR
278  
279 Stéphane Lavergne L<https://github.com/vphantom>
280  
281 =head1 ACKNOWLEDGEMENTS
282  
283 Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
284  
285 =head1 COPYRIGHT & LICENSE
286  
287 Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
288  
289 Permission is hereby granted, free of charge, to any person obtaining a copy
290 of this software and associated documentation files (the "Software"), to deal
291 in the Software without restriction, including without limitation the rights
292 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
293 copies of the Software, and to permit persons to whom the Software is
294 furnished to do so, subject to the following conditions:
295  
296 The above copyright notice and this permission notice shall be included in all
297 copies or substantial portions of the Software.
298  
299 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
300 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
301 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
302 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
303 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
304 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
305 SOFTWARE.
306  
307 =cut
308  
309 2 1;
« cXML/Message/PunchOutOrder.pm ↑ Summary cXML/Address/Postal.pm »