]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIP/ILS/Koha.pm
Got CheckOutItem going
[working/NCIPServer.git] / lib / NCIP / ILS / Koha.pm
1 #
2 #===============================================================================
3 #
4 #         FILE: Koha.pm
5 #
6 #  DESCRIPTION:
7 #
8 #        FILES: ---
9 #         BUGS: ---
10 #        NOTES: ---
11 #       AUTHOR: Chris Cormack (rangi), chrisc@catalyst.net.nz
12 # ORGANIZATION: Koha Development Team
13 #      VERSION: 1.0
14 #      CREATED: 05/11/13 11:14:09
15 #     REVISION: ---
16 #===============================================================================
17 package NCIP::ILS::Koha;
18
19 use Modern::Perl;
20 use Object::Tiny qw{ name };
21
22 use C4::Members qw{ GetMemberDetails };
23 use C4::Circulation qw { AddReturn CanBookBeIssued AddIssue };
24 use C4::Context;
25
26 sub itemdata {
27     my $self = shift;
28     return ( { barcode => '123', title => 'fish' }, undef );
29 }
30
31 sub userdata {
32     my $self     = shift;
33     my $userid   = shift;
34     my $userdata = GetMemberDetails( undef, $userid );
35     return $userdata;
36 }
37
38 sub checkin {
39     my $self       = shift;
40     my $barcode    = shift;
41     my $branch     = shift;
42     my $exemptfine = undef;
43     my $dropbox    = undef;
44     my ( $success, $messages, $issue, $borrower ) =
45       AddReturn( $barcode, $branch, $exemptfine, $dropbox );
46     my $result = {
47         success         => $success,
48         messages        => $messages,
49         iteminformation => $issue,
50         borrower        => $borrower
51     };
52     return $result;
53 }
54
55 sub checkout {
56     my $self     = shift;
57     my $userid   = shift;
58     my $barcode  = shift;
59     my $borrower = GetMemberDetails( undef, $userid );
60     my $error;
61     my $confirm;
62      my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter, $persona)= @_;
63     my @USERENV = (
64     1,
65     'test',
66     'MASTERTEST',
67     'Test',
68     'Test',
69     'AS', #branchcode need to set this properly
70     'Auckland',
71     0,
72     );
73
74 C4::Context->_new_userenv ('DUMMY_SESSION_ID');
75 C4::Context->set_userenv ( @USERENV );
76
77
78    if ($borrower) {
79
80         ( $error, $confirm ) = CanBookBeIssued( $borrower, $barcode );
81
82   #( $issuingimpossible, $needsconfirmation ) =  CanBookBeIssued( $borrower,
83   #                      $barcode, $duedatespec, $inprocess, $ignore_reserves );
84         if (%$error) {
85
86             # Can't issue item, return error hash
87             return ( 1, $error );
88         }
89         elsif (%$confirm) {
90             return ( 1, $confirm );
91         }
92         else {
93             my $datedue = AddIssue( $borrower, $barcode );
94             return (0, undef, $datedue);    #successfully issued
95         }
96     }
97     else {
98         $error->{'badborrower'} = 1;
99         return ( 1, $error );
100     }
101 }
102
103 1;