Commit b27d8689 authored by Petter Goksøyr Åsen's avatar Petter Goksøyr Åsen
Browse files

plukkliste: add onlyex key to item-level holds

parent e0b1853b
...@@ -114,20 +114,15 @@ sub compute { ...@@ -114,20 +114,15 @@ sub compute {
my $loc = $pick->{loc} or die Dumper($pick)."..."; my $loc = $pick->{loc} or die Dumper($pick)."...";
my $i = { my $i = {
itemnumber => $pick->{itemnumber}, itemnumber => $pick->{itemnumber},
onlyex => $pick->{onlyex},
barcode => $pick->{barcode}, barcode => $pick->{barcode},
location => $pick->{location}, location => $pick->{location},
itemcallnumber => $pick->{itemcallnumber}, itemcallnumber => $pick->{itemcallnumber},
ccode => $pick->{ccode}, ccode => $pick->{ccode},
category => category(%meta, location => $pick->{location}), category => category(%meta, location => $pick->{location}),
}; };
if (exists $pick->{found} or $pick->{transfer_to} or ($pick->{homebranch} ne $pick->{holdingbranch}) ) { if (not $pick->{onloan}) {
my $b = $out->{enroute}//=[];
$i->{reserve} = $pick->{reserve} if $pick->{reserve};
$i->{transfer_to} = $pick->{transfer_to} if $pick->{transfer_to};
push @$b, $i;
} else {
$out->{pick}//={}; $out->{pick}//={};
$i->{plukk} = 1;
my $b = $out->{pick}->{$pick->{loc}}//=[]; my $b = $out->{pick}->{$pick->{loc}}//=[];
push @$b, $i; push @$b, $i;
} }
...@@ -147,9 +142,7 @@ sub compute { ...@@ -147,9 +142,7 @@ sub compute {
sub _compute { sub _compute {
my ($bib, $items, $holds) = @_; my ($bib, $items, $holds) = @_;
my %orig;
my %available; my %available;
my %all;
my %pick; my %pick;
my %bybranch; my %bybranch;
...@@ -176,13 +169,9 @@ sub _compute { ...@@ -176,13 +169,9 @@ sub _compute {
$item->{shelf} = $branch; $item->{shelf} = $branch;
} }
$orig{$item->{itemnumber}} = $item;
next if $item->{notforloan} or $item->{damaged} or $item->{itemlost}; next if $item->{notforloan} or $item->{damaged} or $item->{itemlost};
next if $item->{itype} and $item->{itype} =~ m{^(DAGSLAAN|UKESLAAN|10DLAAN|TOUKESLAAN|SETT)$}; next if $item->{itype} and $item->{itype} =~ m{^(DAGSLAAN|UKESLAAN|10DLAAN|TOUKESLAAN|SETT)$};
$all{$item->{itemnumber}} = $item;
my $b = $bybranch->($branch); my $b = $bybranch->($branch);
$b->{items}++; $b->{items}++;
...@@ -192,41 +181,34 @@ sub _compute { ...@@ -192,41 +181,34 @@ sub _compute {
$b->{available}++; $b->{available}++;
} }
} }
for my $hold (sort { $a->{priority} <=> $b->{priority} } @$holds) { for my $hold (sort { $a->{priority} <=> $b->{priority} } @$holds) {
my $rid = $hold->{reserve_id};
if (my $i = $hold->{itemnumber}) { # item number is locked if (my $i = $hold->{itemnumber}) { # item number is locked
my $item = $orig{$i} or do { next if $hold->{found};
warn "Can't find item $i"; my $item = $available{$i} or next;
next; $item->{reserve} = $hold->{reserve_id};
};
$item->{reserve} = $rid;
$item->{found} = $hold->{found}; $item->{found} = $hold->{found};
$item->{onlyex} = $item->{copynumber};
$pick{$i} = $item; $pick{$i} = $item;
#print "; FIXED $rid $to <= $i $item->{loc}\n"; $bybranch->($item->{loc})->{available}-- if $item->{loc};
$bybranch->($item->{loc})->{available}-- if $item and $item->{loc};
delete $available{$i}; delete $available{$i};
} }
} }
for my $hold (sort { $a->{priority} <=> $b->{priority} } @$holds) { for my $hold (sort { $a->{priority} <=> $b->{priority} } @$holds) {
my $rid = $hold->{reserve_id}; if (my $i = $hold->{itemnumber}) { # item number is locked, handeled in above for loop
next;
}
next if $hold->{found};
my $to = $hold->{branchcode}; my $to = $hold->{branchcode};
my $age = eval { no warnings; str2time($hold->{reservedate}) } // 0; my $age = eval { no warnings; str2time($hold->{reservedate}) } // 0;
$age = int( (time()-$age)/86400) if $age; $age = int( (time()-$age)/86400) if $age;
$hold->{age} = $age; $hold->{age} = $age;
next if $age < 0; # not active yet (TODO, maybe start working on it 2 days before?) next if $age < 0; # not active yet (TODO, maybe start working on it 2 days before?)
if (my $i = $hold->{itemnumber}) { # item number is locked
next;
}
#next if $hold->{found}//'' eq 'W'; # should we check the transfers?
next if $hold->{found};
#if ($age>10) { # if there is a hold for 10 days, than all the books should be picked up
# print "ALL\n";
# return values %all;
#}
my $b = $bybranch->($to); my $b = $bybranch->($to);
#print Dumper([branch => $b]); #print Dumper([branch => $b]);
if ($b->{available}) { if ($b->{available}) {
...@@ -237,21 +219,19 @@ sub _compute { ...@@ -237,21 +219,19 @@ sub _compute {
else { else {
$pick{$_->{itemnumber}} = $_ for @list; $pick{$_->{itemnumber}} = $_ for @list;
my $first = $list[0]; my $first = $list[0];
delete $all{$first->{itemnumber}};
$bybranch->($first->{loc})->{available}--; $bybranch->($first->{loc})->{available}--;
#print "; $first->{barcode} for $rid ($to)\n";
next; next;
} }
} }
# no good items found, mark everything for pick # no good items found, mark everything for pick
return values %available; #return values %available;
} }
return values %pick; return values %pick;
} }
my %bnums; my %bnums;
TX { TX {
SELECT "distinct biblionumber FROM reserves WHERE reservedate < NOW() and found IS NULL ORDER BY biblionumber" => [] => sub { $bnums{$_{biblionumber}}++; }; SELECT "DISTINCT biblionumber FROM reserves WHERE reservedate < NOW() AND found IS NULL ORDER BY biblionumber" => [] => sub { $bnums{$_{biblionumber}}++; };
}; };
#print "got ".scalar(keys %bnums)." distinct bibnums\n"; #print "got ".scalar(keys %bnums)." distinct bibnums\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment