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