+=head2 IssueSlip
+
+ IssueSlip($branchcode, $borrowernumber, $quickslip)
+
+ Returns letter hash ( see C4::Letters::GetPreparedLetter )
+
+ $quickslip is boolean, to indicate whether we want a quick slip
+
+=cut
+
+sub IssueSlip {
+ my ($branch, $borrowernumber, $quickslip) = @_;
+
+# return unless ( C4::Context->boolean_preference('printcirculationslips') );
+
+ my $now = POSIX::strftime("%Y-%m-%d", localtime);
+
+ my $issueslist = GetPendingIssues($borrowernumber);
+ foreach my $it (@$issueslist){
+ if ((substr $it->{'issuedate'}, 0, 10) eq $now) {
+ $it->{'now'} = 1;
+ }
+ elsif ((substr $it->{'date_due'}, 0, 10) le $now) {
+ $it->{'overdue'} = 1;
+ }
+
+ $it->{'date_due'}=format_date($it->{'date_due'});
+ }
+ my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
+
+ my ($letter_code, %repeat);
+ if ( $quickslip ) {
+ $letter_code = 'ISSUEQSLIP';
+ %repeat = (
+ 'checkedout' => [ map {
+ 'biblio' => $_,
+ 'items' => $_,
+ 'issues' => $_,
+ }, grep { $_->{'now'} } @issues ],
+ );
+ }
+ else {
+ $letter_code = 'ISSUESLIP';
+ %repeat = (
+ 'checkedout' => [ map {
+ 'biblio' => $_,
+ 'items' => $_,
+ 'issues' => $_,
+ }, grep { !$_->{'overdue'} } @issues ],
+
+ 'overdue' => [ map {
+ 'biblio' => $_,
+ 'items' => $_,
+ 'issues' => $_,
+ }, grep { $_->{'overdue'} } @issues ],
+
+ 'news' => [ map {
+ $_->{'timestamp'} = $_->{'newdate'};
+ { opac_news => $_ }
+ } @{ GetNewsToDisplay("slip") } ],
+ );
+ }
+
+ return C4::Letters::GetPreparedLetter (
+ module => 'circulation',
+ letter_code => $letter_code,
+ branchcode => $branch,
+ tables => {
+ 'branches' => $branch,
+ 'borrowers' => $borrowernumber,
+ },
+ repeat => \%repeat,
+ );
+}
+
+=head2 GetBorrowersWithEmail
+
+ ([$borrnum,$userid], ...) = GetBorrowersWithEmail('me@example.com');
+
+This gets a list of users and their basic details from their email address.
+As it's possible for multiple user to have the same email address, it provides
+you with all of them. If there is no userid for the user, there will be an
+C<undef> there. An empty list will be returned if there are no matches.
+
+=cut
+
+sub GetBorrowersWithEmail {
+ my $email = shift;
+
+ my $dbh = C4::Context->dbh;
+
+ my $query = "SELECT borrowernumber, userid FROM borrowers WHERE email=?";
+ my $sth=$dbh->prepare($query);
+ $sth->execute($email);
+ my @result = ();
+ while (my $ref = $sth->fetch) {
+ push @result, $ref;
+ }
+ die "Failure searching for borrowers by email address: $sth->errstr" if $sth->err;
+ return @result;
+}
+
+