|
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 3043-3048
sub LostItem{
Link Here
|
| 3043 |
} |
3052 |
} |
| 3044 |
} |
3053 |
} |
| 3045 |
|
3054 |
|
|
|
3055 |
sub GetOfflineOperations { |
| 3056 |
my $dbh = C4::Context->dbh; |
| 3057 |
my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE branchcode=? ORDER BY timestamp"); |
| 3058 |
$sth->execute(C4::Context->userenv->{'branch'}); |
| 3059 |
my $results = $sth->fetchall_arrayref({}); |
| 3060 |
$sth->finish; |
| 3061 |
return $results; |
| 3062 |
} |
| 3063 |
|
| 3064 |
sub GetOfflineOperation { |
| 3065 |
my $dbh = C4::Context->dbh; |
| 3066 |
my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE operationid=?"); |
| 3067 |
$sth->execute( shift ); |
| 3068 |
my $result = $sth->fetchrow_hashref; |
| 3069 |
$sth->finish; |
| 3070 |
return $result; |
| 3071 |
} |
| 3072 |
|
| 3073 |
sub AddOfflineOperation { |
| 3074 |
my $dbh = C4::Context->dbh; |
| 3075 |
warn Data::Dumper::Dumper(@_); |
| 3076 |
my $sth = $dbh->prepare("INSERT INTO pending_offline_operations VALUES('',?,?,?,?,?,?)"); |
| 3077 |
$sth->execute( @_ ); |
| 3078 |
return "Added."; |
| 3079 |
} |
| 3080 |
|
| 3081 |
sub DeleteOfflineOperation { |
| 3082 |
my $dbh = C4::Context->dbh; |
| 3083 |
my $sth = $dbh->prepare("DELETE FROM pending_offline_operations WHERE operationid=?"); |
| 3084 |
$sth->execute( shift ); |
| 3085 |
return "Deleted."; |
| 3086 |
} |
| 3087 |
|
| 3088 |
sub ProcessOfflineOperation { |
| 3089 |
my $operation = shift; |
| 3090 |
|
| 3091 |
my $report; |
| 3092 |
if ( $operation->{action} eq 'return' ) { |
| 3093 |
$report = ProcessOfflineReturn( $operation ); |
| 3094 |
} elsif ( $operation->{action} eq 'issue' ) { |
| 3095 |
$report = ProcessOfflineIssue( $operation ); |
| 3096 |
} |
| 3097 |
|
| 3098 |
DeleteOfflineOperation( $operation->{operationid} ) if $operation->{operationid}; |
| 3099 |
|
| 3100 |
return $report; |
| 3101 |
} |
| 3102 |
|
| 3103 |
sub ProcessOfflineReturn { |
| 3104 |
my $operation = shift; |
| 3105 |
|
| 3106 |
my $itemnumber = C4::Items::GetItemnumberFromBarcode( $operation->{barcode} ); |
| 3107 |
|
| 3108 |
if ( $itemnumber ) { |
| 3109 |
my $issue = GetOpenIssue( $itemnumber ); |
| 3110 |
if ( $issue ) { |
| 3111 |
MarkIssueReturned( |
| 3112 |
$issue->{borrowernumber}, |
| 3113 |
$itemnumber, |
| 3114 |
undef, |
| 3115 |
$operation->{timestamp}, |
| 3116 |
); |
| 3117 |
ModItem( |
| 3118 |
{ renewals => 0, onloan => undef }, |
| 3119 |
$issue->{'biblionumber'}, |
| 3120 |
$itemnumber |
| 3121 |
); |
| 3122 |
return "Success."; |
| 3123 |
} else { |
| 3124 |
return "Item not issued."; |
| 3125 |
} |
| 3126 |
} else { |
| 3127 |
return "Item not found."; |
| 3128 |
} |
| 3129 |
} |
| 3130 |
|
| 3131 |
sub ProcessOfflineIssue { |
| 3132 |
my $operation = shift; |
| 3133 |
|
| 3134 |
my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber |
| 3135 |
|
| 3136 |
if ( $borrower->{borrowernumber} ) { |
| 3137 |
my $itemnumber = C4::Items::GetItemnumberFromBarcode( $operation->{barcode} ); |
| 3138 |
unless ($itemnumber) { |
| 3139 |
return "barcode not found"; |
| 3140 |
} |
| 3141 |
my $issue = GetOpenIssue( $itemnumber ); |
| 3142 |
|
| 3143 |
if ( $issue and ( $issue->{borrowernumber} ne $borrower->{borrowernumber} ) ) { # Item already issued to another borrower, mark it returned |
| 3144 |
MarkIssueReturned( |
| 3145 |
$issue->{borrowernumber}, |
| 3146 |
$itemnumber, |
| 3147 |
undef, |
| 3148 |
$operation->{timestamp}, |
| 3149 |
); |
| 3150 |
} |
| 3151 |
AddIssue( |
| 3152 |
$borrower, |
| 3153 |
$operation->{'barcode'}, |
| 3154 |
undef, |
| 3155 |
1, |
| 3156 |
$operation->{timestamp}, |
| 3157 |
undef, |
| 3158 |
); |
| 3159 |
return "Success."; |
| 3160 |
} else { |
| 3161 |
return "Borrower not found."; |
| 3162 |
} |
| 3163 |
} |
| 3046 |
|
3164 |
|
| 3047 |
1; |
3165 |
1; |
| 3048 |
|
3166 |
|