-- can item float to checkin lib? aka the shelving location is not full and has less than dups_threshold duplicate titles?
- opcode := 'floated';
+ opcode := 'shelf';
SELECT INTO send_lib,open_space,duplicates o.clib,o.open,d.numdups from smart_float.openings(copy_rec.location) as o join smart_float.dups(copy_rec.barcode) as d on d.clib=o.clib where o.clib=chkin_org and o.open>0 and (d.numdups<o.dups_threshold or d.numdups=0);
IF NOT FOUND THEN
- -- can item bounce to another lib?
- opcode := 'bounced';
+ -- another lib with shelf space and under dups_threshold?
+ opcode := 'most_space';
SELECT INTO send_lib,open_space,duplicates o.clib,o.open,d.numdups from smart_float.openings(copy_rec.location) as o join smart_float.dups(copy_rec.barcode) as d on d.clib=o.clib where o.open>0 and (d.numdups<o.dups_threshold or d.numdups=0) AND evergreen.can_float(copy_rec.floating,copy_rec.circ_lib,o.clib) is TRUE order by o.open desc limit 1;
IF NOT FOUND THEN
- -- can item float here or bounce elsewhere regardless of dups?
- opcode := 'open_only_bounced';
- SELECT INTO send_lib,open_space clib,open from smart_float.openings(copy_rec.location) where open>0 AND evergreen.can_float(copy_rec.floating,copy_rec.circ_lib,clib) is TRUE order by open desc limit 1;
+ -- lib with least dups, most open space
+ opcode := 'least_dups';
+ SELECT INTO send_lib,open_space,duplicates o.clib,o.open,d.numdups from smart_float.openings(copy_rec.location) as o join smart_float.dups(copy_rec.barcode) as d on d.clib=o.clib where o.open>0 AND evergreen.can_float(copy_rec.floating,copy_rec.circ_lib,o.clib) is TRUE order by d.numdups,o.open desc limit 1;
IF NOT FOUND THEN
-- otherwise no sense in transiting item
-- floating to checkin lib because it can't go anywhere else
- opcode := 'nogo_floated';
+ opcode := 'nogo_shelf';
send_lib := chkin_org;
END IF;
END IF;