View | Details | Raw Unified | Return to bug 12518
Collapse All | Expand All

(-)a/C4/Letters.pm (-1 / +1 lines)
Lines 893-899 sub _get_unsent_messages { Link Here
893
893
894
    my $dbh = C4::Context->dbh();
894
    my $dbh = C4::Context->dbh();
895
    my $statement = << 'ENDSQL';
895
    my $statement = << 'ENDSQL';
896
SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, b.branchcode
896
SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, mq.letter_code, b.branchcode
897
  FROM message_queue mq
897
  FROM message_queue mq
898
  LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber
898
  LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber
899
 WHERE status = ?
899
 WHERE status = ?
(-)a/misc/cronjobs/gather_print_notices.pl (-3 / +43 lines)
Lines 34-39 use C4::Dates; Link Here
34
use C4::Debug;
34
use C4::Debug;
35
use C4::Letters;
35
use C4::Letters;
36
use C4::Templates;
36
use C4::Templates;
37
use C4::Items;
38
use C4::Reserves;
37
use File::Spec;
39
use File::Spec;
38
use Getopt::Long;
40
use Getopt::Long;
39
41
Lines 44-58 Usage: $0 OUTPUT_DIRECTORY Link Here
44
  OUTPUT_DIRECTORY/notices-CURRENT_DATE.html .
46
  OUTPUT_DIRECTORY/notices-CURRENT_DATE.html .
45
47
46
  -s --split  Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html
48
  -s --split  Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html
49
  
50
  --holdbarcode  If you want to separate HOLD-letters based on the reserve's pickup branch instead of the borrowers homebranch
51
                 Define this regexp to find the Item barcodes from the HOLD-letters. Items need to be found so the reservation
52
                 information can be found. Regexp could be like 'Item: (\\S+)<br />' or 'Barcode (\\S+)<br />'. Remember that
53
                 these letters are htmlized, so lines end/start with <br />! You must define a capture group between
54
                 parenthesis () to catch the barcode.
47
USAGE
55
USAGE
48
    exit $_[0];
56
    exit $_[0];
49
}
57
}
50
58
51
my ( $stylesheet, $help, $split );
59
my ( $stylesheet, $help, $split, $HOLDbarcodeParsingRegexp );
52
60
53
GetOptions(
61
GetOptions(
54
    'h|help'  => \$help,
62
    'h|help'  => \$help,
55
    's|split' => \$split,
63
    's|split' => \$split,
64
    'holdbarcode=s' => \$HOLDbarcodeParsingRegexp,
56
) || usage(1);
65
) || usage(1);
57
66
58
usage(0) if ($help);
67
usage(0) if ($help);
Lines 80-88 foreach my $message (@all_messages) { Link Here
80
my $OUTPUT;
89
my $OUTPUT;
81
90
82
if ($split) {
91
if ($split) {
92
    
83
    my %messages_by_branch;
93
    my %messages_by_branch;
84
    foreach my $message (@all_messages) {
94
    foreach my $message (@all_messages) {
85
        push( @{ $messages_by_branch{ $message->{'branchcode'} } }, $message );
95
        my $defaultBranch = $message->{'branchcode'};
96
        
97
        #Catch HOLD print letters so we can direct them to branches which actually have the items waiting for pickup.
98
        if (defined $HOLDbarcodeParsingRegexp && $message->{letter_code} eq 'HOLD') {
99
            fetchPickupLocations( $defaultBranch, $message, \%messages_by_branch );
100
        }
101
        else {
102
            push( @{ $messages_by_branch{ $defaultBranch } }, $message );
103
        }       
86
    }
104
    }
87
105
88
    foreach my $branchcode ( keys %messages_by_branch ) {
106
    foreach my $branchcode ( keys %messages_by_branch ) {
Lines 139-141 else { Link Here
139
    close $OUTPUT;
157
    close $OUTPUT;
140
158
141
}
159
}
142
- 
160
161
#Finds the barcodes using a regexp and then gets the reservations attached to them.
162
#Sends the same letter to the branches from which there are Items' pickup locations inside this one letter.
163
sub fetchPickupLocations {
164
    my ($defaultBranch, $message, $messages_by_branch) = @_;
165
    #Find out the barcodes
166
    my @barcodes = $message->{content} =~ /$HOLDbarcodeParsingRegexp/mg;
167
    my %targetBranches; #The same letter can have Items from multiple pickup locations so we need to send this letter to each separate pickup branch.
168
    foreach my $barcode (@barcodes) {
169
        my $itemnumber = C4::Items::GetItemnumberFromBarcode( $barcode );
170
        my ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $waitingdate ) = GetReservesFromItemnumber($itemnumber);
171
        $targetBranches{ $branchcode } = 1 if $branchcode; #Set the branches which receives this print notification.
172
    }
173
    
174
    if (%targetBranches) { #Send the same message to each branch from which there are pickup locations.
175
        foreach my $branchcode (keys %targetBranches) {
176
            push( @{ $messages_by_branch->{ $branchcode } }, $message );
177
        }
178
    }
179
    else { #Or default to the default!
180
        push( @{ $messages_by_branch->{  $defaultBranch  } }, $message );
181
    }
182
}

Return to bug 12518