Westpac/PaymentsPlus/Australian/Payment/Import/Invoice.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 50.0% 1 / 2 totaltotal 97.3% 36 / 37 CC 2 SCAR 2.2
CC
2
Cov
100%
to_csv
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Westpac/Types.pm ↑ Summary Westpac/PaymentsPlus/Australian/Payment/Import/Payment.pm »
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 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 with 'Business::Westpac::Role::CSV';
33 2 ▶no warnings qw/ experimental::signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 2 ▶use Business::Westpac::Types qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
36 add_max_string_attribute
37 2 /;
38  
39 4 ▶sub record_type { 'I' }
Subroutine record_type: called CC=1 SCAR=0.0
Pod undocumented
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 2 foreach my $str_attr (
70 'PayersInvoiceNumber[20]',
71 'RecipientInvoiceNumber[20]',
72 'InvoiceDescription[80]',
73 'DeductionDescription[80]',
74 ) {
75 8 __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 2 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 2 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 5 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
123 2 );
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 2 __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 ▶sub to_csv ( $self ) {
Subroutine to_csv: called CC=2 SCAR=6.9
Pod documented
145  
146 4 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 ▶ if ( $self->_has_pass_through_data ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_pass_through_data) 1 3 4
163 1 push( @csv_str, $self->values_to_csv(
164 "IP",$self->pass_through_data
165 ) );
166 }
167  
168 4 return @csv_str;
169 }
170  
171 =head1 SEE ALSO
172  
173 L<Business::Westpac::Types>
174  
175 =cut
176  
177 2 __PACKAGE__->meta->make_immutable;
« Westpac/Types.pm ↑ Summary Westpac/PaymentsPlus/Australian/Payment/Import/Payment.pm »