File Coverage

blib/lib/Business/Westpac/PaymentsPlus/Australian/Payment/Import/Invoice.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 1 2 50.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             package Business::Westpac::PaymentsPlus::Australian::Payment::Import::Invoice;
2              
3             =head1 NAME
4              
5             Business::Westpac::PaymentsPlus::Australian::Payment::Import::Invoice
6              
7             =head1 SYNOPSIS
8              
9             use Business::Westpac::PaymentsPlus::Australian::Payment::Import::Invoice;
10              
11             my $Invoice = Business::Westpac::PaymentsPlus::Australian::Payment::Import::Invoice->new(
12             payers_invoice_number => '1000000001',
13             recipient_invoice_number => '1000000001',
14             issued_date => '26082016',
15             due_date => '01092016',
16             invoice_amount => '36.04',
17             invoice_amount_paid => '36.04',
18             invoice_description => 'Desc 1',
19             deduction_description => 'Ded Desc 1',
20             pass_through_data => 'Some pass through data',
21             );
22              
23             =head1 DESCRIPTION
24              
25             Class for modeling Invoice details in the context of Westpac CSV files.
26              
27             =cut
28              
29 2     2   480319 use feature qw/ signatures /;
  2         5  
  2         326  
30              
31 2     2   470 use Moose;
  2         637239  
  2         19  
32             with 'Business::Westpac::Role::CSV';
33 2     2   16476 no warnings qw/ experimental::signatures /;
  2         7  
  2         118  
34              
35 2         1030 use Business::Westpac::Types qw/
36             add_max_string_attribute
37 2     2   661 /;
  2         10  
38              
39 4     4 0 13 sub record_type { 'I' }
40              
41             =head1 ATTRIBUTES
42              
43             All attributes are optional, except were stated, and are read only
44              
45             =over
46              
47             =item payers_invoice_number (Str, max 20 chars)
48              
49             =item recipient_invoice_number (Str, max 20 chars)
50              
51             =item invoice_description (Str, max 80 chars)
52              
53             =item deduction_description (Str, max 80 chars)
54              
55             =item issued_date (WestpacDate)
56              
57             =item due_date (WestpacDate)
58              
59             =item invoice_amount (Num)
60              
61             =item invoice_amount_paid (Num)
62              
63             =item deduction_amount (Num)
64              
65             =back
66              
67             =cut
68              
69             foreach my $str_attr (
70             'PayersInvoiceNumber[20]',
71             'RecipientInvoiceNumber[20]',
72             'InvoiceDescription[80]',
73             'DeductionDescription[80]',
74             ) {
75             __PACKAGE__->add_max_string_attribute(
76             $str_attr,
77             is => 'ro',
78             required => 0,
79             );
80             }
81              
82             =head1 METHODS
83              
84             =head2 issued_csv_date
85              
86             Returns the issued_date to a string suitable for the CSV
87              
88             =head2 due_csv_date
89              
90             Returns the due_date to a string suitable for the CSV
91              
92             =cut
93              
94             has 'issued_date' => (
95             is => 'ro',
96             isa => 'WestpacDate',
97             required => 0,
98             coerce => 1,
99             handles => {
100             issued_csv_date => [ strftime => '%d%m%C%y' ],
101             },
102             );
103              
104             has 'due_date' => (
105             is => 'ro',
106             isa => 'WestpacDate',
107             required => 0,
108             coerce => 1,
109             handles => {
110             due_csv_date => [ strftime => '%d%m%C%y' ],
111             },
112             );
113              
114             has [ qw/
115             invoice_amount
116             invoice_amount_paid
117             deduction_amount
118             / ] => (
119             is => 'ro',
120             isa => 'Num',
121             required => 0,
122             default => sub { 0 },
123             );
124              
125             # Pass through data appears on a distinct "Invoice Pass-through record"
126             # (IP) however it can only appear after a Invoice record (I), i.e. this
127             # class. Given the IP line currently *only* contains a single field, the
128             # pass through data, it seems overkill to have an entire distinct class for
129             # it. So for now it's just an attribute on *this* class.
130             __PACKAGE__->add_max_string_attribute(
131             'PassThroughData[120]',
132             is => 'ro',
133             required => 0,
134             );
135              
136             =head2 to_csv
137              
138             Convert the attributes to CSV line(s):
139              
140             my @csv = $Invoice->to_csv;
141              
142             =cut
143              
144 4     4 1 9 sub to_csv ( $self ) {
  4         10  
  4         7  
145              
146 4         62 my @csv_str = $self->attributes_to_csv(
147             qw/
148             record_type
149             payers_invoice_number
150             recipient_invoice_number
151             issued_csv_date
152             due_csv_date
153             invoice_amount
154             invoice_amount_paid
155             invoice_description
156             deduction_amount
157             deduction_description
158             /
159             );
160              
161             # add the "Invoice Pass-through record" if present
162 4 100       64 if ( $self->_has_pass_through_data ) {
163 1         8 push( @csv_str, $self->values_to_csv(
164             "IP",$self->pass_through_data
165             ) );
166             }
167              
168 4         55 return @csv_str;
169             }
170              
171             =head1 SEE ALSO
172              
173             L<Business::Westpac::Types>
174              
175             =cut
176              
177             __PACKAGE__->meta->make_immutable;