c75112590798db1197c636ece044b72fc2f3482b
[koha.git] / C4 / SIP / ILS / Transaction.pm
1 #
2 # Transaction: Superclass of all the transactional status objects
3 #
4
5 package C4::SIP::ILS::Transaction;
6
7 use Carp;
8 use strict;
9 use warnings;
10 use C4::Context;
11 use C4::Circulation qw( GetItemIssue );
12 use Koha::DateUtils;
13
14 my %fields = (
15         ok            => 0,
16         patron        => undef,
17         item          => undef,
18         desensitize   => 0,
19         alert         => '',
20         transaction_id=> undef,
21         sip_fee_type  => '01', # Other/Unknown
22         fee_amount    => undef,
23         sip_currency  => 'USD', # FIXME: why hardcoded?
24         screen_msg    => '',
25         print_line    => '',
26     fee_ack       => 'N',
27 );
28
29 our $AUTOLOAD;
30
31 sub new {
32         my $class = shift;
33         my $self = {
34                 _permitted => \%fields,
35                 %fields,
36         };
37         return bless $self, $class;
38 }
39
40 sub duedatefromissue {
41     my ($self, $iss, $itemnum) = @_;
42     my $due_dt;
43     if (defined $iss ) {
44         $due_dt = dt_from_string( $iss->date_due() );
45     } # renew from AddIssue ??
46     else {
47         # need to reread the issue to get due date
48         $iss = GetItemIssue($itemnum);
49         if ($iss && $iss->{date_due} ) {
50             $due_dt = dt_from_string( $iss->{date_due} );
51         }
52     }
53     return $due_dt;
54 }
55
56
57
58 sub DESTROY {
59     # be cool
60 }
61
62 sub AUTOLOAD {
63     my $self = shift;
64     my $class = ref($self) or croak "$self is not an object";
65     my $name = $AUTOLOAD;
66
67     $name =~ s/.*://;
68
69     unless (exists $self->{_permitted}->{$name}) {
70                 croak "Can't access '$name' field of class '$class'";
71     }
72
73         if (@_) {
74                 return $self->{$name} = shift;
75         } else {
76                 return $self->{$name};
77         }
78 }
79
80 1;
81 __END__
82