File Coverage

blib/lib/Business/cXML/Message/PunchOutOrder.pm
Criterion Covered Total %
statement 57 57 100.0
branch 20 20 100.0
condition n/a
subroutine 16 16 100.0
pod 4 4 100.0
total 97 97 100.0


line stmt bran cond sub pod time code
1             =encoding utf-8
2              
3             =head1 NAME
4              
5             Business::cXML::Message::PunchOutOrder - cXML punch-out order
6              
7             =head1 SYNOPSIS
8              
9             use Business::cXML;
10             my $cxml = new Business::cXML;
11             my $poom = $cxml->new_message('PunchOutOrder');
12              
13             =head1 DESCRIPTION
14              
15             Object representation of a cXML punch-out order.
16              
17             =head1 METHODS
18              
19             See L<Business::cXML::Object/COMMON METHODS>.
20              
21             =head1 PROPERTY METHODS
22              
23             See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate.
24              
25             =over
26              
27             =cut
28              
29 2     2   813 use 5.014;
  2         6  
30 2     2   10 use strict;
  2         3  
  2         69  
31              
32             use base qw(Business::cXML::Object);
33 2     2   10  
  2         4  
  2         145  
34             use constant {
35             CXML_POOM_STATUS_PENDING => 1,
36 2         188 CXML_POOM_STATUS_FINAL => 2,
37             };
38 2     2   11  
  2         4  
39             use constant NODENAME => 'PunchOutOrderMessage';
40 2     2   12 use constant PROPERTIES => (
  2         5  
  2         127  
41 2         148 buyer_cookie => ' ',
42             highest_operation => 'create',
43             status => undef,
44             total => undef,
45             shipto => undef,
46             shipping => undef,
47             tax => undef,
48             items => [],
49             id => undef,
50             );
51 2     2   11 use constant OBJ_PROPERTIES => (
  2         4  
52 2         303 total => [ 'Business::cXML::Amount', 'Total' ],
53             shipto => 'Business::cXML::ShipTo',
54             shipping => [ 'Business::cXML::Amount', 'Shipping' ],
55             tax => [ 'Business::cXML::Amount', 'Tax' ],
56             items => 'Business::cXML::ItemIn',
57             );
58 2     2   17  
  2         5  
59             use Business::cXML::Amount;
60 2     2   449 use Business::cXML::ItemIn;
  2         6  
  2         54  
61 2     2   378 use Business::cXML::ShipTo;
  2         5  
  2         41  
62 2     2   353 use XML::LibXML::Ferry;
  2         5  
  2         79  
63 2     2   13  
  2         10  
  2         772  
64             my ($self, $val) = @_;
65             return CXML_POOM_STATUS_FINAL if $val eq 'final';
66 2     2   58 return CXML_POOM_STATUS_PENDING;
67 2 100       10 }
68 1         3  
69             my ($self, $el) = @_;
70              
71             $el->ferry($self, {
72 8     8 1 17 BuyerCookie => 'buyer_cookie',
73             PunchOutOrderMessageHeader => {
74 8         128 operationAllowed => 'highest_operation',
75             quoteStatus => [ 'status', \&_from_status ],
76             SourcingStatus => '__UNIMPLEMENTED',
77             Total => [ 'total', 'Business::cXML::Amount' ],
78             ShipTo => [ 'shipto', 'Business::cXML::ShipTo' ],
79             Shipping => [ 'shipping', 'Business::cXML::Amount' ],
80             Tax => [ 'tax', 'Business::cXML::Amount' ],
81             SupplierOrderInfo => {
82             orderID => 'id',
83             orderDate => '__UNIMPLEMENTED',
84             },
85             },
86             ItemIn => [ 'items', 'Business::cXML::ItemIn' ],
87             }
88             );
89             }
90              
91             my ($self, $doc) = @_;
92             my $node = $doc->create($self->{_nodeName});
93              
94             $node->add('BuyerCookie', $self->{buyer_cookie});
95 11     11 1 20  
96 11         29 my $head = $node->add('PunchOutOrderMessageHeader', undef,
97             operationAllowed => $self->{highest_operation},
98 11         138 );
99             $head->{quoteStatus} = ($self->is_final ? 'final' : 'pending') if defined $self->{status};
100              
101             # UNIMPLEMENTED: SourcingStatus
102 11         360 $self->total({}) unless defined $self->{total};
103 11 100       482 $head->add($self->{total}->to_node($node));
    100          
104             $head->add($self->{shipto}->to_node($node)) if defined $self->{shipto};
105             $head->add($self->{shipping}->to_node($node)) if defined $self->{shipping};
106 11 100       139 $head->add($self->{tax}->to_node($node)) if defined $self->{tax};
107 11         41 $head->add('SupplierOrderInfo', undef, orderID => $self->{id}) if defined $self->{id};
108 11 100       226  
109 11 100       116 $node->add($_->to_node($node)) foreach (@{ $self->{items} });
110 11 100       37  
111 11 100       51 return $node;
112             }
113 11         78  
  11         46  
114             =item C<B<is_pending>( [I<$bool>] )>
115 11         274  
116             =item C<B<is_final>( [I<$bool>] )>
117              
118             Respectively gets or sets whether the order is in pending or final status.
119             There is no status at all by default.
120              
121             =cut
122              
123             my ($self, $bool) = @_;
124             $self->{status} = CXML_POOM_STATUS_PENDING if $bool;
125             return $self->{status} == CXML_POOM_STATUS_PENDING;
126             }
127              
128 3     3 1 7 my ($self, $bool) = @_;
129 3 100       6 $self->{status} = CXML_POOM_STATUS_FINAL if $bool;
130 3         10 return $self->{status} == CXML_POOM_STATUS_FINAL;
131             }
132              
133             =item C<B<buyer_cookie>>
134 5     5 1 10  
135 5 100       12 Mandatory, cookie from original punch-out setup request
136 5         21  
137             =item C<B<highest_operation>>
138              
139             Mandatory, highest operation that we allow on this order. One of: C<create>
140             (default), C<inspect>, C<edit>
141              
142             =item C<B<total>>
143              
144             Mandatory, L<Business::cXML::Amount> object of type C<Total>
145              
146             =item C<B<shipto>>
147              
148             Optional, L<Business::cXML::ShipTo> object
149              
150             =item C<B<shipping>>
151              
152             Optional, L<Business::cXML::Amount> object of C<Shipping> type (includes
153             tracking information)
154              
155             =item B<tax>
156              
157             Optional, L<Business::cXML::Amount> object of type C<Tax>
158              
159             =item C<B<items>[]>
160              
161             Optional, L<Business::cXML::ItemIn> objects
162              
163             =item C<B<id>>
164              
165             Optional, supplier sales order ID for this order, if one was created. The
166             buyer can later cancel the sales order by sending an C<OrderRequest> of type
167             C<delete> that refers to this ID.
168              
169             =back
170              
171             =head1 AUTHOR
172              
173             Stéphane Lavergne L<https://github.com/vphantom>
174              
175             =head1 ACKNOWLEDGEMENTS
176              
177             Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
178              
179             =head1 COPYRIGHT & LICENSE
180              
181             Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
182              
183             Permission is hereby granted, free of charge, to any person obtaining a copy
184             of this software and associated documentation files (the "Software"), to deal
185             in the Software without restriction, including without limitation the rights
186             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
187             copies of the Software, and to permit persons to whom the Software is
188             furnished to do so, subject to the following conditions:
189              
190             The above copyright notice and this permission notice shall be included in all
191             copies or substantial portions of the Software.
192              
193             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
194             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
195             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
196             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
198             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
199             SOFTWARE.
200              
201             =cut
202              
203             1;
204