Bug 7600: Return a single-pixel GIF when no local cover image exists
[koha_gimpoz] / C4 / Circulation.pm
index d8a6794..999f617 100644 (file)
@@ -99,6 +99,7 @@ BEGIN {
                 &IsBranchTransferAllowed
                 &CreateBranchTransferLimit
                 &DeleteBranchTransferLimits
+        &TransferSlip
        );
 
     # subs to deal with offline circulation
@@ -2676,11 +2677,18 @@ sub SendCirculationAlert {
         borrowernumber => $borrower->{borrowernumber},
         message_name   => $message_name{$type},
     });
-    my $letter = C4::Letters::getletter('circulation', $type);
-    C4::Letters::parseletter($letter, 'biblio',      $item->{biblionumber});
-    C4::Letters::parseletter($letter, 'biblioitems', $item->{biblionumber});
-    C4::Letters::parseletter($letter, 'borrowers',   $borrower->{borrowernumber});
-    C4::Letters::parseletter($letter, 'branches',    $branch);
+    my $letter =  C4::Letters::GetPreparedLetter (
+        module => 'circulation',
+        letter_code => $type,
+        branchcode => $branch,
+        tables => {
+            'biblio'      => $item->{biblionumber},
+            'biblioitems' => $item->{biblionumber},
+            'borrowers'   => $borrower,
+            'branches'    => $branch,
+        }
+    ) or return;
+
     my @transports = @{ $borrower_preferences->{transports} };
     # warn "no transports" unless @transports;
     for (@transports) {
@@ -2695,7 +2703,8 @@ sub SendCirculationAlert {
             $message->update;
         }
     }
-    $letter;
+
+    return $letter;
 }
 
 =head2 updateWrongTransfer
@@ -3037,51 +3046,50 @@ sub LostItem{
 }
 
 sub GetOfflineOperations {
-       my $dbh = C4::Context->dbh;
-       my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE branchcode=? ORDER BY timestamp");
-       $sth->execute(C4::Context->userenv->{'branch'});
-       my $results = $sth->fetchall_arrayref({});
-       $sth->finish;
-       return $results;
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE branchcode=? ORDER BY timestamp");
+    $sth->execute(C4::Context->userenv->{'branch'});
+    my $results = $sth->fetchall_arrayref({});
+    $sth->finish;
+    return $results;
 }
 
 sub GetOfflineOperation {
-       my $dbh = C4::Context->dbh;
-       my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE operationid=?");
-       $sth->execute( shift );
-       my $result = $sth->fetchrow_hashref;
-       $sth->finish;
-       return $result;
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE operationid=?");
+    $sth->execute( shift );
+    my $result = $sth->fetchrow_hashref;
+    $sth->finish;
+    return $result;
 }
 
 sub AddOfflineOperation {
-       my $dbh = C4::Context->dbh;
-       warn Data::Dumper::Dumper(@_);
-       my $sth = $dbh->prepare("INSERT INTO pending_offline_operations VALUES('',?,?,?,?,?,?)");
-       $sth->execute( @_ );
-       return "Added.";
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare("INSERT INTO pending_offline_operations (userid, branchcode, timestamp, action, barcode, cardnumber) VALUES(?,?,?,?,?,?)");
+    $sth->execute( @_ );
+    return "Added.";
 }
 
 sub DeleteOfflineOperation {
-       my $dbh = C4::Context->dbh;
-       my $sth = $dbh->prepare("DELETE FROM pending_offline_operations WHERE operationid=?");
-       $sth->execute( shift );
-       return "Deleted.";
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare("DELETE FROM pending_offline_operations WHERE operationid=?");
+    $sth->execute( shift );
+    return "Deleted.";
 }
 
 sub ProcessOfflineOperation {
-       my $operation = shift;
+    my $operation = shift;
 
     my $report;
-       if ( $operation->{action} eq 'return' ) {
+    if ( $operation->{action} eq 'return' ) {
         $report = ProcessOfflineReturn( $operation );
-       } elsif ( $operation->{action} eq 'issue' ) {
-           $report = ProcessOfflineIssue( $operation );
-       }
+    } elsif ( $operation->{action} eq 'issue' ) {
+        $report = ProcessOfflineIssue( $operation );
+    }
 
-       DeleteOfflineOperation( $operation->{operationid} ) if $operation->{operationid};
+    DeleteOfflineOperation( $operation->{operationid} ) if $operation->{operationid};
 
-       return $report;
+    return $report;
 }
 
 sub ProcessOfflineReturn {
@@ -3120,7 +3128,7 @@ sub ProcessOfflineIssue {
     if ( $borrower->{borrowernumber} ) {
         my $itemnumber = C4::Items::GetItemnumberFromBarcode( $operation->{barcode} );
         unless ($itemnumber) {
-            return "barcode not found";
+            return "Barcode not found.";
         }
         my $issue = GetOpenIssue( $itemnumber );
 
@@ -3148,6 +3156,35 @@ sub ProcessOfflineIssue {
 
 
 
+=head2 TransferSlip
+
+  TransferSlip($user_branch, $itemnumber, $to_branch)
+
+  Returns letter hash ( see C4::Letters::GetPreparedLetter ) or undef
+
+=cut
+
+sub TransferSlip {
+    my ($branch, $itemnumber, $to_branch) = @_;
+
+    my $item =  GetItem( $itemnumber )
+      or return;
+
+    my $pulldate = C4::Dates->new();
+
+    return C4::Letters::GetPreparedLetter (
+        module => 'circulation',
+        letter_code => 'TRANSFERSLIP',
+        branchcode => $branch,
+        tables => {
+            'branches'    => $to_branch,
+            'biblio'      => $item->{biblionumber},
+            'items'       => $item,
+        },
+    );
+}
+
+
 1;
 
 __END__