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

(-)a/C4/RotatingCollections.pm (-59 lines)
Lines 48-115 BEGIN { Link Here
48
    require Exporter;
48
    require Exporter;
49
    @ISA    = qw( Exporter );
49
    @ISA    = qw( Exporter );
50
    @EXPORT = qw(
50
    @EXPORT = qw(
51
      TransferCollection
52
    );
51
    );
53
}
52
}
54
53
55
=head2 TransferCollection
56
57
 ( $success, $errorcode, $errormessage ) = TransferCollection( $colId, $colBranchcode );
58
59
Transfers a collection to another branch
60
61
 Input:
62
   $colId: id of the collection to be updated
63
   $colBranchcode: branch where collection is moving to
64
65
 Output:
66
   $success: 1 if all database operations were successful, 0 otherwise
67
   $errorCode: Code for reason of failure, good for translating errors in templates
68
   $errorMessage: English description of error
69
70
=cut
71
72
sub TransferCollection {
73
    my ( $colId, $colBranchcode ) = @_;
74
75
    ## Check for all necessary parameters
76
    if ( !$colId ) {
77
        return ( 0, 1, "NO_ID" );
78
    }
79
    if ( !$colBranchcode ) {
80
        return ( 0, 2, "NO_BRANCHCODE" );
81
    }
82
83
    my $dbh = C4::Context->dbh;
84
85
    my $sth;
86
    $sth = $dbh->prepare(
87
        "UPDATE collections
88
                        SET 
89
                        colBranchcode = ? 
90
                        WHERE colId = ?"
91
    );
92
    $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
93
94
    $sth = $dbh->prepare(q{
95
        SELECT items.itemnumber, items.barcode FROM collections_tracking
96
        LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber
97
        LEFT JOIN issues ON items.itemnumber = issues.itemnumber
98
        WHERE issues.borrowernumber IS NULL
99
          AND collections_tracking.colId = ?
100
    });
101
    $sth->execute($colId) or return ( 0, 4, $sth->errstr );
102
    my @results;
103
    while ( my $item = $sth->fetchrow_hashref ) {
104
        my ($status) = CheckReserves( $item->{itemnumber} );
105
        my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} );
106
        C4::Circulation::transferbook( $colBranchcode, $item->{barcode}, my $ignore_reserves = 1 ) unless ( $status eq 'Waiting' || @transfers );
107
    }
108
109
    return 1;
110
111
}
112
113
=head2 isItemInThisCollection
54
=head2 isItemInThisCollection
114
55
115
  $inCollection = isItemInThisCollection( $itemnumber, $colId );
56
  $inCollection = isItemInThisCollection( $itemnumber, $colId );
(-)a/Koha/RotatingCollection.pm (-1 / +47 lines)
Lines 1-6 Link Here
1
package Koha::RotatingCollection;
1
package Koha::RotatingCollection;
2
2
3
# Copyright Josef Moravec 2016
3
# Copyright Josef Moravec 2017
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
Lines 22-28 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils;
25
use Koha::Exceptions;
26
use Koha::Exceptions;
27
use Koha::Holds;
26
use Koha::Items;
28
use Koha::Items;
27
use Koha::RotatingCollection::Trackings;
29
use Koha::RotatingCollection::Trackings;
28
30
Lines 115-120 sub remove_item { Link Here
115
    return $collection_tracking->delete;
117
    return $collection_tracking->delete;
116
}
118
}
117
119
120
=head3 transfer
121
122
$collection->transfer( $library_object )
123
124
throws
125
    Koha::Exceptions::MissingParameter
126
    Koha::Exceptions::ObjectNotFound
127
128
=cut
129
130
sub transfer {
131
    my ( $self, $library ) = @_;
132
133
    Koha::Exceptions::MissingParameter->throw if not defined $library;
134
135
    Koha::Exceptions::ObjectNotFound->throw if ref($library) ne 'Koha::Library';
136
137
    $self->colBranchcode( $library->branchcode )->store;
138
139
    my $from = C4::Context->userenv->{'branch'} if C4::Context->userenv;
140
141
    my $items = $self->items;
142
    while ( my $item = $items->next ) {
143
        my $holds = Koha::Holds->search( {
144
            itemnumber => $item->itemnumber,
145
            found      => 'W',
146
        } );
147
148
149
        # If no user context is defined the default from library for transfer will be the 'holding' one
150
        $from = $item->holdingbranch if not defined $from;
151
        unless ($holds->count || $item->get_transfer) {
152
            my $transfer = Koha::Item::Transfer->new( {
153
                frombranch => $from,
154
                tobranch => $library->branchcode,
155
                itemnumber => $item->itemnumber,
156
                datesent => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
157
                comments => $self->colTitle,
158
            } )->store;
159
            $item->holdingbranch( $library->branchcode )->store;
160
        }
161
    }
162
}
163
118
=head3 type
164
=head3 type
119
165
120
=cut
166
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tt (-3 / +3 lines)
Lines 7-20 Link Here
7
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'header.inc' %]
8
[% INCLUDE 'cat-search.inc' %]
8
[% INCLUDE 'cat-search.inc' %]
9
9
10
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a> &rsaquo; <a href="/cgi-bin/koha/rotating_collections/addItems.pl?colId=[% colId %]">Collection <i>[% colTitle %]</i></a> &rsaquo; Transfer collection</div>
10
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a> &rsaquo; <a href="/cgi-bin/koha/rotating_collections/addItems.pl?colId=[% collection.colId %]">Collection <i>[% collection.colTitle %]</i></a> &rsaquo; Transfer collection</div>
11
11
12
<div id="doc3" class="yui-t2">
12
<div id="doc3" class="yui-t2">
13
    <div id="bd">
13
    <div id="bd">
14
        <div id="yui-main">
14
        <div id="yui-main">
15
            <div class="yui-b">
15
            <div class="yui-b">
16
16
17
                <h1>Transfer collection <i>[% colTitle %]</i></h1>
17
                <h1>Transfer collection <i>[% collection.colTitle %]</i></h1>
18
18
19
                [% IF ( transferSuccess ) %]
19
                [% IF ( transferSuccess ) %]
20
                    <div class="dialog message">
20
                    <div class="dialog message">
Lines 32-38 Link Here
32
                [% ELSE %]
32
                [% ELSE %]
33
                    <div>
33
                    <div>
34
                        <form action="transferCollection.pl" method="post">
34
                        <form action="transferCollection.pl" method="post">
35
                            <input type="hidden" name="colId" value="[% colId %]" />
35
                            <input type="hidden" name="colId" value="[% collection.colId %]" />
36
                            <fieldset class="rows">
36
                            <fieldset class="rows">
37
                                <ol>
37
                                <ol>
38
                                    <li>
38
                                    <li>
(-)a/rotating_collections/transferCollection.pl (-20 / +10 lines)
Lines 21-28 use Modern::Perl; Link Here
21
use C4::Output;
21
use C4::Output;
22
use C4::Auth;
22
use C4::Auth;
23
use C4::Context;
23
use C4::Context;
24
use C4::RotatingCollections;
25
24
25
use Koha::Libraries;
26
use Koha::RotatingCollections;
26
use Koha::RotatingCollections;
27
27
28
use CGI qw ( -utf8 );
28
use CGI qw ( -utf8 );
Lines 32-37 my $query = new CGI; Link Here
32
my $colId    = $query->param('colId');
32
my $colId    = $query->param('colId');
33
my $toBranch = $query->param('toBranch');
33
my $toBranch = $query->param('toBranch');
34
34
35
my $collection = Koha::RotatingCollections->find( $colId );
36
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {
38
    {
37
        template_name   => "rotating_collections/transferCollection.tt",
39
        template_name   => "rotating_collections/transferCollection.tt",
Lines 44-74 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
44
);
46
);
45
47
46
## Transfer collection
48
## Transfer collection
47
my ( $success, $errorCode, $errorMessage );
48
if ($toBranch) {
49
if ($toBranch) {
49
    ( $success, $errorCode, $errorMessage ) =
50
    my $branch = Koha::Libraries->find( $toBranch );
50
      TransferCollection( $colId, $toBranch );
51
52
    my $transferred = eval ( $collection->transfer( $branch ) );
51
53
52
    if ($success) {
54
    if ( $@ and not $transferred ) {
55
        $template->param( transferFailure => 1 );
56
    } else {
53
        $template->param( transferSuccess => 1 );
57
        $template->param( transferSuccess => 1 );
54
    }
58
    }
55
    else {
56
        $template->param(
57
            transferFailure => 1,
58
            errorCode       => $errorCode,
59
            errorMessage    => $errorMessage
60
        );
61
    }
62
}
59
}
63
60
64
## Get data about collection
65
my $collection = Koha::RotatingCollections->find($colId);
66
67
$template->param(
61
$template->param(
68
    colId            => $collection->colId,
62
    collection => $collection,
69
    colTitle         => $collection->colTitle,
70
    colDesc          => $collection->colDesc,
71
    colBranchcode    => $collection->colBranchcode,
72
);
63
);
73
64
74
output_html_with_http_headers $query, $cookie, $template->output;
65
output_html_with_http_headers $query, $cookie, $template->output;
75
- 

Return to bug 18606