|
Lines 99-104
BEGIN {
Link Here
|
| 99 |
&CreateBranchTransferLimit |
99 |
&CreateBranchTransferLimit |
| 100 |
&DeleteBranchTransferLimits |
100 |
&DeleteBranchTransferLimits |
| 101 |
); |
101 |
); |
|
|
102 |
|
| 103 |
# subs to deal with offline circulation |
| 104 |
push @EXPORT, qw( |
| 105 |
&GetOfflineOperations |
| 106 |
&GetOfflineOperation |
| 107 |
&AddOfflineOperation |
| 108 |
&DeleteOfflineOperation |
| 109 |
&ProcessOfflineOperation |
| 110 |
); |
| 102 |
} |
111 |
} |
| 103 |
|
112 |
|
| 104 |
=head1 NAME |
113 |
=head1 NAME |
|
Lines 2942-2947
sub DeleteBranchTransferLimits {
Link Here
|
| 2942 |
$sth->execute(); |
2951 |
$sth->execute(); |
| 2943 |
} |
2952 |
} |
| 2944 |
|
2953 |
|
|
|
2954 |
sub GetOfflineOperations { |
| 2955 |
my $dbh = C4::Context->dbh; |
| 2956 |
my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE branchcode=? ORDER BY timestamp"); |
| 2957 |
$sth->execute(C4::Context->userenv->{'branch'}); |
| 2958 |
my $results = $sth->fetchall_arrayref({}); |
| 2959 |
$sth->finish; |
| 2960 |
return $results; |
| 2961 |
} |
| 2962 |
|
| 2963 |
sub GetOfflineOperation { |
| 2964 |
my $dbh = C4::Context->dbh; |
| 2965 |
my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE operationid=?"); |
| 2966 |
$sth->execute( shift ); |
| 2967 |
my $result = $sth->fetchrow_hashref; |
| 2968 |
$sth->finish; |
| 2969 |
return $result; |
| 2970 |
} |
| 2971 |
|
| 2972 |
sub AddOfflineOperation { |
| 2973 |
my $dbh = C4::Context->dbh; |
| 2974 |
warn Data::Dumper::Dumper(@_); |
| 2975 |
my $sth = $dbh->prepare("INSERT INTO pending_offline_operations VALUES('',?,?,?,?,?,?)"); |
| 2976 |
$sth->execute( @_ ); |
| 2977 |
return "Added."; |
| 2978 |
} |
| 2979 |
|
| 2980 |
sub DeleteOfflineOperation { |
| 2981 |
my $dbh = C4::Context->dbh; |
| 2982 |
my $sth = $dbh->prepare("DELETE FROM pending_offline_operations WHERE operationid=?"); |
| 2983 |
$sth->execute( shift ); |
| 2984 |
return "Deleted."; |
| 2985 |
} |
| 2986 |
|
| 2987 |
sub ProcessOfflineOperation { |
| 2988 |
my $operation = shift; |
| 2989 |
|
| 2990 |
my $report; |
| 2991 |
if ( $operation->{action} eq 'return' ) { |
| 2992 |
$report = ProcessOfflineReturn( $operation ); |
| 2993 |
} elsif ( $operation->{action} eq 'issue' ) { |
| 2994 |
$report = ProcessOfflineIssue( $operation ); |
| 2995 |
} |
| 2996 |
|
| 2997 |
DeleteOfflineOperation( $operation->{operationid} ) if $operation->{operationid}; |
| 2998 |
|
| 2999 |
return $report; |
| 3000 |
} |
| 3001 |
|
| 3002 |
sub ProcessOfflineReturn { |
| 3003 |
my $operation = shift; |
| 3004 |
|
| 3005 |
my $itemnumber = C4::Items::GetItemnumberFromBarcode( $operation->{barcode} ); |
| 3006 |
|
| 3007 |
if ( $itemnumber ) { |
| 3008 |
my $issue = GetOpenIssue( $itemnumber ); |
| 3009 |
if ( $issue ) { |
| 3010 |
MarkIssueReturned( |
| 3011 |
$issue->{borrowernumber}, |
| 3012 |
$itemnumber, |
| 3013 |
undef, |
| 3014 |
$operation->{timestamp}, |
| 3015 |
); |
| 3016 |
ModItem( |
| 3017 |
{ renewals => 0, onloan => undef }, |
| 3018 |
$issue->{'biblionumber'}, |
| 3019 |
$itemnumber |
| 3020 |
); |
| 3021 |
return "Success."; |
| 3022 |
} else { |
| 3023 |
return "Item not issued."; |
| 3024 |
} |
| 3025 |
} else { |
| 3026 |
return "Item not found."; |
| 3027 |
} |
| 3028 |
} |
| 3029 |
|
| 3030 |
sub ProcessOfflineIssue { |
| 3031 |
my $operation = shift; |
| 3032 |
|
| 3033 |
my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber |
| 3034 |
|
| 3035 |
if ( $borrower->{borrowernumber} ) { |
| 3036 |
my $itemnumber = C4::Items::GetItemnumberFromBarcode( $operation->{barcode} ); |
| 3037 |
my $issue = GetOpenIssue( $itemnumber ); |
| 3038 |
|
| 3039 |
if ( $issue and ( $issue->{borrowernumber} ne $borrower->{borrowernumber} ) ) { # Item already issued to another borrower, mark it returned |
| 3040 |
MarkIssueReturned( |
| 3041 |
$issue->{borrowernumber}, |
| 3042 |
$itemnumber, |
| 3043 |
undef, |
| 3044 |
$operation->{timestamp}, |
| 3045 |
); |
| 3046 |
} |
| 3047 |
AddIssue( |
| 3048 |
$borrower, |
| 3049 |
$operation->{'barcode'}, |
| 3050 |
undef, |
| 3051 |
1, |
| 3052 |
$operation->{timestamp}, |
| 3053 |
undef, |
| 3054 |
); |
| 3055 |
return "Success."; |
| 3056 |
} else { |
| 3057 |
return "Borrower not found."; |
| 3058 |
} |
| 3059 |
} |
| 3060 |
|
| 3061 |
|
| 2945 |
|
3062 |
|
| 2946 |
1; |
3063 |
1; |
| 2947 |
|
3064 |
|