Lines 27-32
use Modern::Perl;
Link Here
|
27 |
use C4::Context; |
27 |
use C4::Context; |
28 |
use C4::Circulation; |
28 |
use C4::Circulation; |
29 |
use C4::Reserves qw(GetReserveStatus); |
29 |
use C4::Reserves qw(GetReserveStatus); |
|
|
30 |
use C4::Biblio; |
31 |
use C4::Branch; |
32 |
use C4::Items; |
33 |
use C4::Reserves; |
30 |
|
34 |
|
31 |
use DBI; |
35 |
use DBI; |
32 |
|
36 |
|
Lines 56-68
BEGIN {
Link Here
|
56 |
GetItemsInCollection |
60 |
GetItemsInCollection |
57 |
|
61 |
|
58 |
GetCollection |
62 |
GetCollection |
|
|
63 |
GetCollectionByTitle |
59 |
GetCollections |
64 |
GetCollections |
60 |
|
65 |
|
61 |
AddItemToCollection |
66 |
AddItemToCollection |
62 |
RemoveItemFromCollection |
67 |
RemoveItemFromCollection |
63 |
TransferCollection |
68 |
TransferCollection |
|
|
69 |
TransferCollectionItem |
70 |
ReturnCollectionItemToOrigin |
71 |
ReturnCollectionToOrigin |
64 |
|
72 |
|
65 |
GetCollectionItemBranches |
73 |
GetCollectionItemBranches |
|
|
74 |
|
75 |
GetItemOriginBranch |
76 |
GetItemsCollection |
77 |
|
78 |
isItemInAnyCollection |
66 |
); |
79 |
); |
67 |
} |
80 |
} |
68 |
|
81 |
|
Lines 82-95
BEGIN {
Link Here
|
82 |
=cut |
95 |
=cut |
83 |
|
96 |
|
84 |
sub CreateCollection { |
97 |
sub CreateCollection { |
85 |
my ( $title, $description ) = @_; |
98 |
my ( $title, $description, $owningbranch ) = @_; |
86 |
|
99 |
|
87 |
## Check for all neccessary parameters |
100 |
## Check for all neccessary parameters |
88 |
if ( !$title ) { |
101 |
if ( !$title ) { |
89 |
return ( 0, 1, "No Title Given" ); |
102 |
return ( 0, 1, "No title given" ); |
90 |
} |
103 |
} |
91 |
if ( !$description ) { |
104 |
if ( !$description ) { |
92 |
return ( 0, 2, "No Description Given" ); |
105 |
return ( 0, 2, "No description given" ); |
|
|
106 |
} |
107 |
|
108 |
if ( !$owningbranch ) { |
109 |
return ( 0, 3, "No owning branch given" ); |
110 |
} |
111 |
|
112 |
# Check whether a collection with the given title already exists |
113 |
my $collections = GetCollections(); |
114 |
for my $col (@$collections) { |
115 |
if ($col->{'colTitle'} eq $title) { |
116 |
return (0, 4, "A collection with the title '" . $title . "' already exists"); |
117 |
} |
93 |
} |
118 |
} |
94 |
|
119 |
|
95 |
my $success = 1; |
120 |
my $success = 1; |
Lines 98-107
sub CreateCollection {
Link Here
|
98 |
|
123 |
|
99 |
my $sth; |
124 |
my $sth; |
100 |
$sth = $dbh->prepare( |
125 |
$sth = $dbh->prepare( |
101 |
"INSERT INTO collections ( colId, colTitle, colDesc ) |
126 |
"INSERT INTO collections ( colId, colTitle, colDesc, owningBranchcode ) |
102 |
VALUES ( NULL, ?, ? )" |
127 |
VALUES ( NULL, ?, ?, ? )" |
103 |
); |
128 |
); |
104 |
$sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() ); |
129 |
$sth->execute( $title, $description, $owningbranch ) or return ( 0, 5, $sth->errstr() ); |
105 |
|
130 |
|
106 |
return 1; |
131 |
return 1; |
107 |
|
132 |
|
Lines 139-144
sub UpdateCollection {
Link Here
|
139 |
return ( 0, 3, "No Description Given" ); |
164 |
return ( 0, 3, "No Description Given" ); |
140 |
} |
165 |
} |
141 |
|
166 |
|
|
|
167 |
# Check whether a collection with the given title already exists |
168 |
my $collections = GetCollections(); |
169 |
for my $col (@$collections) { |
170 |
if ($col->{'colTitle'} eq $title) { |
171 |
return (0, 4, "A collection with the title '" . $title . "' already exists"); |
172 |
} |
173 |
} |
174 |
|
142 |
my $dbh = C4::Context->dbh; |
175 |
my $dbh = C4::Context->dbh; |
143 |
|
176 |
|
144 |
my $sth; |
177 |
my $sth; |
Lines 178-183
sub DeleteCollection {
Link Here
|
178 |
return ( 0, 1, "No Collection Id Given" ); |
211 |
return ( 0, 1, "No Collection Id Given" ); |
179 |
} |
212 |
} |
180 |
|
213 |
|
|
|
214 |
my $collectionItems = GetItemsInCollection($colId); |
215 |
# KD-139: Actually remove all items from the collection before removing the collection itself. |
216 |
for my $item (@$collectionItems) { |
217 |
my $itembiblio = GetBiblioFromItemNumber(undef, $item->{'barcode'}); |
218 |
my $itemnumber = $itembiblio->{'itemnumber'}; |
219 |
RemoveItemFromCollection($colId, $itemnumber); |
220 |
} |
221 |
|
181 |
my $dbh = C4::Context->dbh; |
222 |
my $dbh = C4::Context->dbh; |
182 |
|
223 |
|
183 |
my $sth; |
224 |
my $sth; |
Lines 205-216
sub DeleteCollection {
Link Here
|
205 |
sub GetCollections { |
246 |
sub GetCollections { |
206 |
|
247 |
|
207 |
my $dbh = C4::Context->dbh; |
248 |
my $dbh = C4::Context->dbh; |
|
|
249 |
my $query = ' |
250 |
SELECT * |
251 |
FROM collections |
252 |
LEFT JOIN branches ON owningBranchcode = branches.branchcode |
253 |
'; |
208 |
|
254 |
|
209 |
my $sth = $dbh->prepare("SELECT * FROM collections"); |
255 |
my $sth = $dbh->prepare($query); |
210 |
$sth->execute() or return ( 1, $sth->errstr() ); |
256 |
$sth->execute() or return ( 1, $sth->errstr() ); |
211 |
|
257 |
|
212 |
my @results; |
258 |
my @results; |
213 |
while ( my $row = $sth->fetchrow_hashref ) { |
259 |
while ( my $row = $sth->fetchrow_hashref ) { |
|
|
260 |
my $colItemCount = GetCollectionItemCount($row->{'colId'}); |
261 |
my $itemsTransferred = GetTransferredItemCount($row->{'colId'}); |
262 |
$row->{'colItemsCount'} = $colItemCount; |
263 |
$row->{'itemsTransferred'} = $itemsTransferred; |
214 |
push( @results, $row ); |
264 |
push( @results, $row ); |
215 |
} |
265 |
} |
216 |
|
266 |
|
Lines 246-264
sub GetItemsInCollection {
Link Here
|
246 |
|
296 |
|
247 |
my $sth = $dbh->prepare( |
297 |
my $sth = $dbh->prepare( |
248 |
"SELECT |
298 |
"SELECT |
249 |
biblio.title, |
299 |
biblio.title, |
250 |
items.itemcallnumber, |
300 |
biblio.biblionumber, |
251 |
items.barcode |
301 |
items.itemcallnumber, |
252 |
FROM collections, collections_tracking, items, biblio |
302 |
items.barcode, |
253 |
WHERE collections.colId = collections_tracking.colId |
303 |
items.itemnumber, |
|
|
304 |
items.holdingbranch, |
305 |
items.homebranch, |
306 |
branches.branchname, |
307 |
collections_tracking.* |
308 |
FROM collections, collections_tracking, items, biblio, branches |
309 |
WHERE items.homebranch = branches.branchcode |
310 |
AND collections.colId = collections_tracking.colId |
254 |
AND collections_tracking.itemnumber = items.itemnumber |
311 |
AND collections_tracking.itemnumber = items.itemnumber |
255 |
AND items.biblionumber = biblio.biblionumber |
312 |
AND items.biblionumber = biblio.biblionumber |
256 |
AND collections.colId = ? ORDER BY biblio.title" |
313 |
AND collections.colId = ? |
|
|
314 |
ORDER BY biblio.title" |
257 |
); |
315 |
); |
258 |
$sth->execute($colId) or return ( 0, 0, 2, $sth->errstr() ); |
316 |
$sth->execute($colId) or return ( 0, 0, 2, $sth->errstr() ); |
259 |
|
317 |
|
260 |
my @results; |
318 |
my @results; |
261 |
while ( my $row = $sth->fetchrow_hashref ) { |
319 |
while ( my $row = $sth->fetchrow_hashref ) { |
|
|
320 |
my $originbranchname = GetBranchName($row->{'origin_branchcode'}); |
321 |
my $holdingbranchname = GetBranchName($row->{'holdingbranch'}); |
322 |
$row->{'holdingbranchname'} = $holdingbranchname; |
323 |
$row->{'origin_branchname'} = $originbranchname; |
324 |
$row->{'intransit'} = GetTransfers($row->{'itemnumber'}); |
262 |
push( @results, $row ); |
325 |
push( @results, $row ); |
263 |
} |
326 |
} |
264 |
|
327 |
|
Lines 296-301
sub GetCollection {
Link Here
|
296 |
|
359 |
|
297 |
} |
360 |
} |
298 |
|
361 |
|
|
|
362 |
=head2 GetCollectionByTitle |
363 |
|
364 |
($colId, $colTitle, $colDesc, $colBranchcode) = GetCollectionByTitle($colTitle); |
365 |
|
366 |
Returns information about a collection |
367 |
|
368 |
Input: |
369 |
$colTitle: Title of the collection |
370 |
Output: |
371 |
$colId, $colTitle, $colDesc, $colBranchcode |
372 |
|
373 |
=cut |
374 |
|
375 |
sub GetCollectionByTitle { |
376 |
my ($colId) = @_; |
377 |
|
378 |
my $dbh = C4::Context->dbh; |
379 |
|
380 |
my ( $sth, @results ); |
381 |
$sth = $dbh->prepare("SELECT * FROM collections WHERE colTitle = ?"); |
382 |
$sth->execute($colId) or return 0; |
383 |
|
384 |
my $row = $sth->fetchrow_hashref; |
385 |
|
386 |
return ( |
387 |
$$row{'colId'}, $$row{'colTitle'}, |
388 |
$$row{'colDesc'}, $$row{'colBranchcode'} |
389 |
); |
390 |
|
391 |
} |
392 |
|
393 |
=head2 GetItemsCollection |
394 |
|
395 |
$itemsCollection = GetItemsCollection($itemnumber) |
396 |
|
397 |
Returns an item's collection if it exists |
398 |
|
399 |
Input: |
400 |
$itemnumber: itemnumber of the item |
401 |
Output: |
402 |
$colId of the item's collection or 0 if the item is not in a collection |
403 |
|
404 |
=cut |
405 |
|
406 |
sub GetItemsCollection { |
407 |
my $itemnumber = shift; |
408 |
|
409 |
if (!isItemInAnyCollection($itemnumber)) { |
410 |
return 0; |
411 |
} |
412 |
|
413 |
my $dbh = C4::Context->dbh; |
414 |
my $sth = $dbh->prepare("SELECT * FROM collections_tracking WHERE itemnumber = ?"); |
415 |
$sth->execute($itemnumber) or return 0; |
416 |
|
417 |
my $colItem = $sth->fetchrow_hashref; |
418 |
if ($colItem) { |
419 |
return $colItem->{'colId'}; |
420 |
} |
421 |
return 0; |
422 |
} |
423 |
|
299 |
=head2 AddItemToCollection |
424 |
=head2 AddItemToCollection |
300 |
|
425 |
|
301 |
( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber ); |
426 |
( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber ); |
Lines 322-334
sub AddItemToCollection {
Link Here
|
322 |
if ( !$itemnumber ) { |
447 |
if ( !$itemnumber ) { |
323 |
return ( 0, 2, "No Itemnumber Given" ); |
448 |
return ( 0, 2, "No Itemnumber Given" ); |
324 |
} |
449 |
} |
325 |
|
|
|
326 |
if ( isItemInThisCollection( $itemnumber, $colId ) ) { |
450 |
if ( isItemInThisCollection( $itemnumber, $colId ) ) { |
327 |
return ( 0, 2, "Item is already in the collection!" ); |
451 |
return ( 0, 2, "Item is already in the collection!" ); |
328 |
} |
452 |
} |
329 |
elsif ( isItemInAnyCollection($itemnumber) ) { |
453 |
elsif ( isItemInAnyCollection($itemnumber) ) { |
330 |
return ( 0, 3, "Item is already in a different collection!" ); |
454 |
return ( 0, 3, "Item is already in a different collection!" ); |
331 |
} |
455 |
} |
|
|
456 |
# Check item's reserve status |
457 |
my ($reservedate, $borrowernumber, $branchcode, $reserve_id, $waitingdate) = GetReservesFromItemnumber($itemnumber); |
458 |
return (0, 4, "The item is waiting for pickup and cannot be added to a collection!") if ($waitingdate); |
459 |
|
460 |
my $itembiblio = GetBiblioFromItemNumber($itemnumber, undef); |
461 |
my $originbranchcode = $itembiblio->{'homebranch'}; |
462 |
my $transferred = 0; |
332 |
|
463 |
|
333 |
my $dbh = C4::Context->dbh; |
464 |
my $dbh = C4::Context->dbh; |
334 |
|
465 |
|
Lines 336-345
sub AddItemToCollection {
Link Here
|
336 |
$sth = $dbh->prepare(" |
467 |
$sth = $dbh->prepare(" |
337 |
INSERT INTO collections_tracking ( |
468 |
INSERT INTO collections_tracking ( |
338 |
colId, |
469 |
colId, |
339 |
itemnumber |
470 |
itemnumber, |
340 |
) VALUES ( ?, ? ) |
471 |
origin_branchcode |
|
|
472 |
) VALUES (?, ?, ?) |
341 |
"); |
473 |
"); |
342 |
$sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() ); |
474 |
$sth->execute($colId, $itemnumber, $originbranchcode) or return ( 0, 3, $sth->errstr() ); |
343 |
|
475 |
|
344 |
return 1; |
476 |
return 1; |
345 |
|
477 |
|
Lines 374-381
sub RemoveItemFromCollection {
Link Here
|
374 |
return ( 0, 2, "Item is not in the collection!" ); |
506 |
return ( 0, 2, "Item is not in the collection!" ); |
375 |
} |
507 |
} |
376 |
|
508 |
|
377 |
my $dbh = C4::Context->dbh; |
509 |
# KD-139: Attempt to transfer the item being removed if it has its origin branch |
|
|
510 |
# set up. |
511 |
my $itembiblio = GetBiblioFromItemNumber($itemnumber, undef); |
512 |
my $currenthomebranchcode = $itembiblio->{'homebranch'}; |
513 |
my $originbranchcode = GetItemOriginBranch($itemnumber); |
514 |
my $barcode = $itembiblio->{'barcode'}; |
515 |
my ($dotransfer, $messages, $iteminformation); |
516 |
|
517 |
if ($originbranchcode && $barcode) { |
518 |
if (GetTransfers($itemnumber)) { |
519 |
DeleteTransfer($itemnumber) |
520 |
} |
521 |
($dotransfer, $messages, $iteminformation) = transferbook($originbranchcode, $barcode, 1); |
522 |
} |
378 |
|
523 |
|
|
|
524 |
my $dbh = C4::Context->dbh; |
379 |
my $sth; |
525 |
my $sth; |
380 |
$sth = $dbh->prepare( |
526 |
$sth = $dbh->prepare( |
381 |
"DELETE FROM collections_tracking |
527 |
"DELETE FROM collections_tracking |
Lines 383-388
sub RemoveItemFromCollection {
Link Here
|
383 |
); |
529 |
); |
384 |
$sth->execute($itemnumber) or return ( 0, 3, $sth->errstr() ); |
530 |
$sth->execute($itemnumber) or return ( 0, 3, $sth->errstr() ); |
385 |
|
531 |
|
|
|
532 |
# Transfer was not done - not considered an error here |
533 |
if (!$dotransfer) { |
534 |
return (1, 4, $messages); |
535 |
} |
536 |
|
537 |
# Change the item's homebranch back to its pre-transfer status |
538 |
ModItem({ homebranch => $originbranchcode }, undef, $itemnumber); |
539 |
|
540 |
return 1; |
541 |
} |
542 |
|
543 |
=head2 ReturnCollectionToOrigin |
544 |
|
545 |
($success, $errorcode, $errormessage) = ReturnCollectionToOrigin($colId); |
546 |
|
547 |
Marks a collection to be returned to their origin branch, e.g. the branch that was |
548 |
the item's home branch when it was first added to the collection |
549 |
|
550 |
Input: |
551 |
$colId: Collection the returned item belongs to |
552 |
|
553 |
Output: |
554 |
$success: 1 if all database operations were successful, 0 otherwise |
555 |
$errorcode: Code for reason of failure, good for translating errors in templates |
556 |
$errormessages: English description of any errors with return operations |
557 |
=cut |
558 |
|
559 |
sub ReturnCollectionToOrigin { |
560 |
my $colId = shift; |
561 |
|
562 |
if (!$colId) { |
563 |
return (0, 1, "No collection id given"); |
564 |
} |
565 |
|
566 |
my $collectionItems = GetItemsInCollection($colId); |
567 |
my $collectionItemsCount = scalar(@$collectionItems); |
568 |
my ($colSuccess, $errorcode, @errormessages); |
569 |
|
570 |
for my $item (@$collectionItems) { |
571 |
my $itemOriginBranch = GetItemOriginBranch($item->{'itemnumber'}); |
572 |
my ($success, $errocode, $errormessage); |
573 |
if ($itemOriginBranch) { |
574 |
($success, $errorcode, $errormessage) = |
575 |
ReturnCollectionItemToOrigin($colId, $item->{'itemnumber'}); |
576 |
if (!$success) { |
577 |
push(@errormessages, $errormessage); |
578 |
} |
579 |
} |
580 |
} |
581 |
my $errorCount = scalar(@errormessages); |
582 |
if ($errorCount == $collectionItemsCount) { |
583 |
return (0, 2, "No items in collection transferred"); |
584 |
} |
585 |
else { |
586 |
# Some items were succesfully returned - return info about failed transfers for template usage |
587 |
return (1, 0, \@errormessages); |
588 |
} |
589 |
} |
590 |
|
591 |
|
592 |
|
593 |
=head2 ReturnCollectionItemToOrigin |
594 |
|
595 |
($success, $errorcode, $errormessage) = ReturnCollectionItemToOrigin($colId, $itemnumber); |
596 |
|
597 |
Marks a collection item to be returned to their origin branch, e.g. the branch that was |
598 |
the item's home branch when it was first added to the collection |
599 |
|
600 |
Input: |
601 |
$colId: Collection the returned item belongs to |
602 |
$itemnumber: Item in the collection to be returned to their origin branch |
603 |
|
604 |
Output: |
605 |
$success: 1 if all database operations were successful, 0 otherwise |
606 |
$errorCode: Code for reason of failure, good for translating errors in templates |
607 |
$errorMessage: English description of error |
608 |
|
609 |
=cut |
610 |
|
611 |
sub ReturnCollectionItemToOrigin { |
612 |
my ($colId, $itemnumber) = @_; |
613 |
my $originBranch = GetItemOriginBranch($itemnumber); |
614 |
|
615 |
## Check for all neccessary parameters |
616 |
if (!$colId) { |
617 |
return (0, 1, "No collection id given"); |
618 |
} |
619 |
if (!$itemnumber) { |
620 |
return (0, 2, "No itemnumber given"); |
621 |
} |
622 |
|
623 |
if (!$originBranch) { |
624 |
return (0, 3, "Item has no origin branch set"); |
625 |
} |
626 |
|
627 |
if (!isItemTransferred($itemnumber)) { |
628 |
return (0, 4, "Cannot return an item that is not transferred"); |
629 |
} |
630 |
|
631 |
my $dbh = C4::Context->dbh; |
632 |
my $sth = $dbh->prepare(q{ |
633 |
SELECT items.itemnumber, items.barcode, items.homebranch, items.holdingbranch FROM collections_tracking |
634 |
LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber |
635 |
LEFT JOIN issues ON items.itemnumber = issues.itemnumber |
636 |
WHERE issues.borrowernumber IS NULL |
637 |
AND collections_tracking.colId = ? AND collections_tracking.itemnumber = ? |
638 |
}); |
639 |
|
640 |
$sth->execute($colId, $itemnumber) or return (0, 5, $sth->errstr); |
641 |
my ($dotransfer, $messages, $iteminformation); |
642 |
if (my $item = $sth->fetchrow_hashref) { |
643 |
unless (GetReserveStatus($item->{itemnumber}) eq "Waiting") { |
644 |
($dotransfer, $messages, $iteminformation) |
645 |
= transferbook($originBranch, $item->{barcode}, 1); |
646 |
} |
647 |
} |
648 |
# Push all issues with the transfer into a list for template usage. |
649 |
if (!$dotransfer) { |
650 |
my @errorlist; |
651 |
for my $message (keys %$messages) { |
652 |
push(@errorlist, $message); |
653 |
} |
654 |
return (0, 6, \@errorlist); |
655 |
} |
656 |
|
657 |
$sth = $dbh->prepare(q{ |
658 |
UPDATE collections_tracking |
659 |
SET |
660 |
transfer_branch = NULL |
661 |
WHERE itemnumber = ? |
662 |
}); |
663 |
$sth->execute($itemnumber) or return (0, 7, $sth->errstr); |
664 |
ModItem({ homebranch => $originBranch }, undef, $itemnumber); |
665 |
|
386 |
return 1; |
666 |
return 1; |
387 |
} |
667 |
} |
388 |
|
668 |
|
Lines 404-449
Transfers a collection to another branch
Link Here
|
404 |
=cut |
684 |
=cut |
405 |
|
685 |
|
406 |
sub TransferCollection { |
686 |
sub TransferCollection { |
407 |
my ( $colId, $colBranchcode ) = @_; |
687 |
my ($colId, $colBranchcode) = @_; |
408 |
|
688 |
|
409 |
## Check for all neccessary parameters |
689 |
## Check for all neccessary parameters |
410 |
if ( !$colId ) { |
690 |
if (!$colId) { |
411 |
return ( 0, 1, "No Id Given" ); |
691 |
return (0, 1, "No id given"); |
412 |
} |
692 |
} |
413 |
if ( !$colBranchcode ) { |
693 |
if (!$colBranchcode) { |
414 |
return ( 0, 2, "No Branchcode Given" ); |
694 |
return (0, 2, "No branchcode given"); |
415 |
} |
695 |
} |
416 |
|
696 |
|
417 |
my $dbh = C4::Context->dbh; |
697 |
my $colItems = GetItemsInCollection($colId); |
|
|
698 |
my $colItemsCount = scalar(@$colItems); |
699 |
my ($transfersuccess, $error, @errorlist); |
700 |
my $problemItemCount = 0; |
701 |
|
702 |
for my $item (@$colItems) { |
703 |
my $itemOriginBranch = GetItemOriginBranch($item->{'itemnumber'}); |
704 |
my $itemCurHomeBranch = $item->{'homebranch'}; |
705 |
my ($dotransfer, $errorcode, $errormessage) = TransferCollectionItem($colId, $item->{'itemnumber'}, $colBranchcode); |
706 |
if (!$dotransfer) { |
707 |
$problemItemCount++; |
708 |
push(@errorlist, $item->{'title'} . ":"); |
709 |
if (ref $errormessage eq "ARRAY") { |
710 |
for my $message (@$errormessage) { |
711 |
push(@errorlist, $message); |
712 |
} |
713 |
} |
714 |
else { |
715 |
push (@errorlist, $errormessage); |
716 |
} |
717 |
} |
718 |
} |
418 |
|
719 |
|
419 |
my $sth; |
720 |
if ($problemItemCount == $colItemsCount) { |
420 |
$sth = $dbh->prepare( |
721 |
return (0, 3, \@errorlist); |
421 |
"UPDATE collections |
722 |
} |
422 |
SET |
723 |
elsif ($problemItemCount < $colItemsCount) { |
423 |
colBranchcode = ? |
724 |
return (1, 0, \@errorlist); |
424 |
WHERE colId = ?" |
725 |
} |
425 |
); |
726 |
else { |
426 |
$sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() ); |
727 |
return 1; |
|
|
728 |
} |
729 |
} |
427 |
|
730 |
|
428 |
$sth = $dbh->prepare(q{ |
731 |
=head2 TransferItem |
429 |
SELECT items.itemnumber, items.barcode FROM collections_tracking |
732 |
|
|
|
733 |
($success, $errorcode, $errormessage) = TransferCollection($colId, $itemnumber, $transferBranch); |
734 |
|
735 |
Transfers an item to another branch |
736 |
|
737 |
Input: |
738 |
$colId: id of the collection to be updated |
739 |
$itemnumber: the itemnumber of the item in the collection being transferred |
740 |
$transferBranch: branch where item is moving to |
741 |
|
742 |
Output: |
743 |
$success: 1 if all database operations were successful, 0 otherwise |
744 |
$errorCode: Code for reason of failure, good for translating errors in templates |
745 |
$errorMessage: English description of error |
746 |
|
747 |
=cut |
748 |
|
749 |
sub TransferCollectionItem { |
750 |
my ($colId, $itemnumber, $transferBranch) = @_; |
751 |
|
752 |
if (!$colId) { |
753 |
return (0, 1, "No collection id given"); |
754 |
} |
755 |
|
756 |
if (!$itemnumber) { |
757 |
return (0, 2, "No itemnumber given"); |
758 |
} |
759 |
|
760 |
if (!$transferBranch) { |
761 |
return (0, 3, "No transfer branch given"); |
762 |
} |
763 |
|
764 |
if (isItemTransferred($itemnumber)) { |
765 |
return (0, 4, "Item is already transferred"); |
766 |
} |
767 |
|
768 |
my $dbh = C4::Context->dbh; |
769 |
my $sth = $dbh->prepare(q{ |
770 |
SELECT items.itemnumber, items.barcode, items.homebranch FROM collections_tracking |
430 |
LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber |
771 |
LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber |
431 |
LEFT JOIN issues ON items.itemnumber = issues.itemnumber |
772 |
LEFT JOIN issues ON items.itemnumber = issues.itemnumber |
432 |
WHERE issues.borrowernumber IS NULL |
773 |
WHERE issues.borrowernumber IS NULL |
433 |
AND collections_tracking.colId = ? |
774 |
AND collections_tracking.colId = ? AND collections_tracking.itemnumber = ? |
434 |
}); |
775 |
}); |
435 |
$sth->execute($colId) or return ( 0, 4, $sth->errstr ); |
776 |
|
436 |
my @results; |
777 |
$sth->execute($colId, $itemnumber) or return ( 0, 5, $sth->errstr ); |
437 |
while ( my $item = $sth->fetchrow_hashref ) { |
778 |
my ($dotransfer, $messages, $iteminformation); |
438 |
transferbook( $colBranchcode, $item->{barcode}, |
779 |
if (my $item = $sth->fetchrow_hashref) { |
439 |
my $ignore_reserves = 1 ) |
780 |
unless (GetReserveStatus($item->{itemnumber}) eq "Waiting") { |
440 |
unless ( GetReserveStatus( $item->{itemnumber} ) eq "Waiting" ); |
781 |
($dotransfer, $messages, $iteminformation) |
|
|
782 |
= transferbook($transferBranch, $item->{barcode}, 1); |
783 |
} |
441 |
} |
784 |
} |
442 |
|
785 |
|
443 |
return 1; |
786 |
# Push all issues with the transfer into a list for template usage. |
|
|
787 |
if (!$dotransfer) { |
788 |
my @errorlist; |
789 |
for my $message (keys %$messages) { |
790 |
push(@errorlist, $message); |
791 |
} |
792 |
return (0, 6, \@errorlist); |
793 |
} |
794 |
my $transferred = 1; |
444 |
|
795 |
|
|
|
796 |
$sth = $dbh->prepare(q{ |
797 |
UPDATE collections_tracking |
798 |
SET |
799 |
transfer_branch = ?, |
800 |
transferred = ? |
801 |
WHERE itemnumber = ? |
802 |
}); |
803 |
$sth->execute($transferBranch, $transferred, $itemnumber) or return (0, 7, $sth->errstr); |
804 |
ModItem({ homebranch => $transferBranch }, undef, $itemnumber); |
805 |
|
806 |
return 1; |
445 |
} |
807 |
} |
446 |
|
808 |
|
|
|
809 |
|
447 |
=head2 GetCollectionItemBranches |
810 |
=head2 GetCollectionItemBranches |
448 |
|
811 |
|
449 |
my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber ); |
812 |
my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber ); |
Lines 461-467
sub GetCollectionItemBranches {
Link Here
|
461 |
|
824 |
|
462 |
my ( $sth, @results ); |
825 |
my ( $sth, @results ); |
463 |
$sth = $dbh->prepare( |
826 |
$sth = $dbh->prepare( |
464 |
"SELECT holdingbranch, colBranchcode FROM items, collections, collections_tracking |
827 |
"SELECT holdingbranch, transfer_branch FROM items, collections, collections_tracking |
465 |
WHERE items.itemnumber = collections_tracking.itemnumber |
828 |
WHERE items.itemnumber = collections_tracking.itemnumber |
466 |
AND collections.colId = collections_tracking.colId |
829 |
AND collections.colId = collections_tracking.colId |
467 |
AND items.itemnumber = ?" |
830 |
AND items.itemnumber = ?" |
Lines 470-476
sub GetCollectionItemBranches {
Link Here
|
470 |
|
833 |
|
471 |
my $row = $sth->fetchrow_hashref; |
834 |
my $row = $sth->fetchrow_hashref; |
472 |
|
835 |
|
473 |
return ( $$row{'holdingbranch'}, $$row{'colBranchcode'}, ); |
836 |
return ( $$row{'holdingbranch'}, $$row{'transfer_branch'}, ); |
|
|
837 |
} |
838 |
|
839 |
=head2 GetTransferredItemCount |
840 |
|
841 |
$transferredCount = GetTransferredItemCount($colId); |
842 |
|
843 |
=cut |
844 |
|
845 |
sub GetTransferredItemCount { |
846 |
my $colId = shift; |
847 |
|
848 |
my $dbh = C4::Context->dbh; |
849 |
my $query = "SELECT COUNT(*) |
850 |
FROM collections_tracking |
851 |
WHERE colId = ? AND transferred = 1 |
852 |
"; |
853 |
my $sth = $dbh->prepare($query); |
854 |
$sth->execute($colId) or die $sth->errstr(); |
855 |
|
856 |
my $result = $sth->fetchrow(); |
857 |
return $result; |
858 |
} |
859 |
|
860 |
=head2 GetCollectionItemCount |
861 |
|
862 |
$colItemCount = GetCollectionItemCount($colId); |
863 |
|
864 |
=cut |
865 |
|
866 |
sub GetCollectionItemCount { |
867 |
my $colId = shift; |
868 |
|
869 |
my $dbh = C4::Context->dbh; |
870 |
my $query = "SELECT COUNT(colId) |
871 |
FROM collections_tracking |
872 |
WHERE colId = ? |
873 |
"; |
874 |
my $sth = $dbh->prepare($query); |
875 |
$sth->execute($colId) or die $sth->errstr(); |
876 |
|
877 |
my $result = $sth->fetchrow(); |
878 |
return $result; |
474 |
} |
879 |
} |
475 |
|
880 |
|
476 |
=head2 isItemInThisCollection |
881 |
=head2 isItemInThisCollection |
Lines 520-525
sub isItemInAnyCollection {
Link Here
|
520 |
} |
925 |
} |
521 |
} |
926 |
} |
522 |
|
927 |
|
|
|
928 |
=head2 isItemTramsferred |
929 |
|
930 |
($transferred, $errorcode, $errormessage) = isItemTransferred($itemnumber); |
931 |
|
932 |
=cut |
933 |
|
934 |
sub isItemTransferred { |
935 |
my $itemnumber = shift; |
936 |
|
937 |
my $dbh = C4::Context->dbh; |
938 |
my $sth; |
939 |
|
940 |
my $query = ' |
941 |
Select * FROM collections_tracking |
942 |
WHERE itemnumber = ? |
943 |
'; |
944 |
|
945 |
$sth = $dbh->prepare($query); |
946 |
$sth->execute($itemnumber) or return (0, 1, $sth->errstr); |
947 |
my $resultrow = $sth->fetchrow_hashref; |
948 |
if (!$resultrow) { |
949 |
return (0, 2, "Item is not in a collection"); |
950 |
} |
951 |
|
952 |
if ($resultrow->{'transferred'}) { |
953 |
return 1; |
954 |
} |
955 |
else { |
956 |
return 0; |
957 |
} |
958 |
|
959 |
} |
960 |
|
961 |
|
962 |
|
963 |
=head2 GetItemOriginBranch |
964 |
|
965 |
$originBranch = GetItemOriginBranch($itemnumber); |
966 |
|
967 |
Kd-139: Returns the given item's origin branch, e.g. the home branch at the time it was |
968 |
being added to a collection or 0 the item has no origin |
969 |
|
970 |
=cut |
971 |
|
972 |
sub GetItemOriginBranch { |
973 |
my $itemnumber = shift; |
974 |
|
975 |
my $dbh = C4::Context->dbh; |
976 |
my $sth; |
977 |
|
978 |
my $query = ' |
979 |
SELECT * |
980 |
FROM collections_tracking |
981 |
WHERE itemnumber = ? |
982 |
'; |
983 |
$sth = $dbh->prepare($query); |
984 |
$sth->execute($itemnumber); |
985 |
my $resultrow = $sth->fetchrow_hashref; |
986 |
|
987 |
if (!$resultrow) { |
988 |
return 0; |
989 |
} |
990 |
|
991 |
my $originBranchCode = $resultrow->{'origin_branchcode'}; |
992 |
if ($originBranchCode) { |
993 |
return $originBranchCode; |
994 |
} |
995 |
else { |
996 |
return 0; |
997 |
} |
998 |
} |
999 |
|
523 |
1; |
1000 |
1; |
524 |
|
1001 |
|
525 |
__END__ |
1002 |
__END__ |