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 (+23 lines)
Lines 110-115 sub remove_item { Link Here
110
    return $collection_tracking->delete;
110
    return $collection_tracking->delete;
111
}
111
}
112
112
113
=head3 transfer
114
115
$collection->transfer( $branchcode)
116
117
throws
118
    Koha::Exceptions::MissingParameter
119
120
=cut
121
122
sub transfer {
123
    my ( $self, $branchcode ) = @_;
124
125
    Koha::Exceptions::MissingParameter->throw if not defined $branchcode;
126
127
    $self->colBranchcode( $branchcode )->store;
128
129
    for ( my $item = $self->items ) {
130
        my ( $status ) = C4::Reserves::CheckReserves( $item->itemnumber );
131
        my @transfers = C4::Circulation::GetTransfers( $item->itemnumber );
132
        C4::Circulation::transferbook( $branchcode, $item->barcode, my $ignore_reserves = 1 ) unless ( $status eq 'Waiting' || @transfers );
133
    }
134
}
135
113
=head3 type
136
=head3 type
114
137
115
=cut
138
=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 / +7 lines)
Lines 21-27 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
26
use Koha::RotatingCollections;
25
use Koha::RotatingCollections;
27
26
Lines 32-37 my $query = new CGI; Link Here
32
my $colId    = $query->param('colId');
31
my $colId    = $query->param('colId');
33
my $toBranch = $query->param('toBranch');
32
my $toBranch = $query->param('toBranch');
34
33
34
my $collection = Koha::RotatingCollections->find( $colId );
35
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {
37
    {
37
        template_name   => "rotating_collections/transferCollection.tt",
38
        template_name   => "rotating_collections/transferCollection.tt",
Lines 44-74 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
44
);
45
);
45
46
46
## Transfer collection
47
## Transfer collection
47
my ( $success, $errorCode, $errorMessage );
48
if ($toBranch) {
48
if ($toBranch) {
49
    ( $success, $errorCode, $errorMessage ) =
49
    my $transferred = eval ( $collection->transfer( $toBranch ) );
50
      TransferCollection( $colId, $toBranch );
51
50
52
    if ($success) {
51
    if ( $@ and not $transferred ) {
52
        $template->param( transferFailure => 1 );
53
    } else {
53
        $template->param( transferSuccess => 1 );
54
        $template->param( transferSuccess => 1 );
54
    }
55
    }
55
    else {
56
        $template->param(
57
            transferFailure => 1,
58
            errorCode       => $errorCode,
59
            errorMessage    => $errorMessage
60
        );
61
    }
62
}
56
}
63
57
64
## Get data about collection
65
my $collection = Koha::RotatingCollections->find($colId);
66
67
$template->param(
58
$template->param(
68
    colId            => $collection->colId,
59
    collection => $collection,
69
    colTitle         => $collection->colTitle,
70
    colDesc          => $collection->colDesc,
71
    colBranchcode    => $collection->colBranchcode,
72
);
60
);
73
61
74
output_html_with_http_headers $query, $cookie, $template->output;
62
output_html_with_http_headers $query, $cookie, $template->output;
75
- 

Return to bug 18606