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

(-)a/admin/branch_transfer_limits.pl (-35 / +20 lines)
Lines 37-99 my ($template, $loggedinuser, $cookie) Link Here
37
			     debug => 1,
37
			     debug => 1,
38
			     });
38
			     });
39
39
40
my $dbh = C4::Context->dbh;
40
my $fromBranch;
41
my $branchcode;
41
if((!defined($input->param('fromBranch'))) && C4::Context::mybranch() ne '')
42
if((!defined($input->param('branchcode'))) & C4::Context::mybranch() ne '')
43
{
42
{
44
    $branchcode = C4::Context::mybranch();
43
    $fromBranch = Koha::Libraries->find(C4::Context::mybranch());
45
}
44
}
46
else
45
else
47
{
46
{
48
	$branchcode = $input->param('branchcode');
47
    $fromBranch = Koha::Libraries->find($input->param('fromBranch'));
49
}
48
}
50
49
51
# Set the template language for the correct limit type using $limitType
50
# Set the template language for the correct limit type using $limitType
52
my $limitType = C4::Context->preference("BranchTransferLimitsType") || "ccode";
51
my $limitType = C4::Context->preference("BranchTransferLimitsType") || "ccode";
53
52
53
my @branches = Koha::Libraries->search({});
54
my @codes;
54
my @codes;
55
my @branchcodes;
56
55
57
my $sth;
58
if ( $limitType eq 'ccode' ) {
56
if ( $limitType eq 'ccode' ) {
59
	$sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
57
    @codes = map {$_->authorised_value} Koha::AuthorisedValues->search({category => 'CCODE'}, {columns => ['authorised_value']});
60
} elsif ( $limitType eq 'itemtype' ) {
61
	$sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
62
}
58
}
63
$sth->execute();
59
elsif ( $limitType eq 'itemtype' ) {
64
while ( my $row = $sth->fetchrow_hashref ) {
60
    @codes = map {$_->itemtype} Koha::ItemTypes->search({}, {columns => ['itemtype']});
65
	push( @codes, $row->{ $limitType } );
66
}
67
68
$sth = $dbh->prepare("SELECT branchcode FROM branches");
69
$sth->execute();
70
while ( my $row = $sth->fetchrow_hashref ) {
71
	push( @branchcodes, $row->{'branchcode'} );
72
}
61
}
73
62
74
## If Form Data Passed, Update the Database
63
## If Form Data Passed, Update the Database
75
if ( $input->param('updateLimits') ) {
64
if ( $input->param('updateLimits') ) {
76
    DeleteBranchTransferLimits($branchcode);
65
    DeleteBranchTransferLimits($fromBranch->branchcode);
77
78
66
79
	foreach my $code ( @codes ) {
67
	foreach my $code ( @codes ) {
80
		foreach my $toBranch ( @branchcodes ) {
68
		foreach my $toBranch ( @branches ) {
81
			my $isSet = not $input->param( $code . "_" . $toBranch);
69
			my $isSet = not $input->param( $code . "_" . $toBranch->branchcode);
82
			if ( $isSet ) {
70
			if ( $isSet ) {
83
			    CreateBranchTransferLimit( $toBranch, $branchcode, $code );
71
			    CreateBranchTransferLimit( $toBranch->branchcode, $fromBranch->branchcode, $code );
84
			}
72
			}
85
		}
73
		}
86
	}
74
	}
87
}
75
}
88
76
89
## Build branchcode loop
77
## Caclulate the selected branch here, this is to avoid calling Branches.all(selected...) in the Template Toolkit since we already need all the branches here.
90
my @branchcode_loop;
78
foreach my $branch ( @branches ) {
91
foreach my $branchcode ( @branchcodes ) {
79
    $branch->selected(1) if $branch->branchcode eq $fromBranch->branchcode;
92
	my %row_data;
93
	$row_data{ branchcode } = $branchcode;
94
	push ( @branchcode_loop, \%row_data );
95
}
80
}
96
my $branchcount = scalar(@branchcode_loop);
81
my $branchcount = scalar(@branches);
97
82
98
## Build the default data
83
## Build the default data
99
my @codes_loop;
84
my @codes_loop;
Lines 102-110 foreach my $code ( @codes ) { Link Here
102
	my %row_data;
87
	my %row_data;
103
	$row_data{ code } = $code;
88
	$row_data{ code } = $code;
104
	$row_data{ to_branch_loop } = \@to_branch_loop;
89
	$row_data{ to_branch_loop } = \@to_branch_loop;
105
	foreach my $toBranch ( @branchcodes ) {
90
	foreach my $toBranch ( @branches ) {
106
		my %row_data;
91
		my %row_data;
107
                my $isChecked = IsBranchTransferAllowed( $toBranch, $branchcode, $code );
92
                my $isChecked = IsBranchTransferAllowed( $toBranch->branchcode, $fromBranch->branchcode, $code );
108
		$row_data{ code }         = $code;
93
		$row_data{ code }         = $code;
109
		$row_data{ toBranch }     = $toBranch;
94
		$row_data{ toBranch }     = $toBranch;
110
		$row_data{ isChecked }    = $isChecked;	
95
		$row_data{ isChecked }    = $isChecked;	
Lines 118-125 foreach my $code ( @codes ) { Link Here
118
$template->param(
103
$template->param(
119
		branchcount => $branchcount,
104
		branchcount => $branchcount,
120
		codes_loop => \@codes_loop,
105
		codes_loop => \@codes_loop,
121
		branchcode_loop => \@branchcode_loop,
106
		branches => \@branches,
122
		branchcode => $branchcode,
107
		fromBranch => $fromBranch,
123
        limitType => $limitType,
108
        limitType => $limitType,
124
		);
109
		);
125
110
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt (-9 / +14 lines)
Lines 19-34 Link Here
19
        <div class="col-sm-10 col-sm-push-2">
19
        <div class="col-sm-10 col-sm-push-2">
20
            <main>
20
            <main>
21
21
22
<h1>Library [% branchcode | html %] - [% Branches.GetName( branchcode ) | html %] Checkin and transfer policy</h1>
22
<h1>Library [% fromBranch.branchcode | html %] - [% fromBranch.branchname | html %] Checkin and transfer policy</h1>
23
    <form method="get" action="/cgi-bin/koha/admin/branch_transfer_limits.pl" id="selectlibrary">
23
    <form method="get" action="/cgi-bin/koha/admin/branch_transfer_limits.pl" id="selectlibrary">
24
        <label for="branchselect">Select a library :</label>
24
        <label for="branchselect">Select a library :</label>
25
        <select name="branchcode" id="branchselect">
25
        <select name="fromBranch" id="branchselect">
26
            [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1 ) %]
26
            [% PROCESS options_for_libraries libraries => branches %]
27
        </select>
27
        </select>
28
    </form>
28
    </form>
29
29
30
<p class="help">Check the boxes for the libraries you accept to checkin items from.</p>
30
<p class="help">Check the boxes for the libraries you accept to checkin items from.</p>
31
<fieldset>[% IF ( limitType == 'ccode' ) %]<strong>For all collection codes: </strong>[% ELSE %]<strong>For all item types: </strong>[% END %]<a id="CheckAll" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="UncheckAll" href="#"><i class="fa fa-remove"></i> Clear all</a></fieldset>
31
<fieldset>
32
  [% IF ( limitType == 'ccode' ) %]
33
    <strong>For all collection codes: </strong>
34
  [% ELSIF ( limitType == 'itype' ) %]
35
    <strong>For all item types: </strong>
36
  [% END %]
37
    <a id="CheckAll" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="UncheckAll" href="#"><i class="fa fa-remove"></i> Clear all</a></fieldset>
32
38
33
39
34
  <div id="transferlimit_tabs" class="toptabs">
40
  <div id="transferlimit_tabs" class="toptabs">
Lines 54-65 Link Here
54
            <tbody>
60
            <tbody>
55
                    [% FOREACH to_branch_loo IN codes_loo.to_branch_loop %]
61
                    [% FOREACH to_branch_loo IN codes_loo.to_branch_loop %]
56
                        <tr>
62
                        <tr>
57
                            <td><label style="min-width:400px;" for="[% to_branch_loo.code | html %][% to_branch_loo.toBranch | html %]row">[% to_branch_loo.toBranch | html %] - [% Branches.GetName( to_branch_loo.toBranch ) | html %]</label></td>
63
                            <td><label style="min-width:400px;" for="[% to_branch_loo.code | html %][% to_branch_loo.toBranch.branchcode | html %]row">[% to_branch_loo.toBranch.branchcode | html %] - [% to_branch_loo.toBranch.branchname | html %]</label></td>
58
                            <td>
64
                            <td>
59
                            [% IF ( to_branch_loo.isChecked ) %]
65
                            [% IF ( to_branch_loo.isChecked ) %]
60
                                <input type="checkbox" id="[% to_branch_loo.code | html %][% to_branch_loo.toBranch | html %]row" name="[% to_branch_loo.code | html %]_[% to_branch_loo.toBranch | html %]" checked="checked" />
66
                                <input type="checkbox" id="[% to_branch_loo.code | html %][% to_branch_loo.toBranch.branchcode | html %]row" name="[% to_branch_loo.code | html %]_[% to_branch_loo.toBranch.branchcode | html %]" checked="checked" />
61
                            [% ELSE %]
67
                            [% ELSE %]
62
                                <input type="checkbox" id="[% to_branch_loo.code | html %][% to_branch_loo.toBranch | html %]row" name="[% to_branch_loo.code | html %]_[% to_branch_loo.toBranch | html %]" />
68
                                <input type="checkbox" id="[% to_branch_loo.code | html %][% to_branch_loo.toBranch.branchcode | html %]row" name="[% to_branch_loo.code | html %]_[% to_branch_loo.toBranch.branchcode | html %]" />
63
                            [% END %]
69
                            [% END %]
64
                            </td>
70
                            </td>
65
                        </tr>
71
                        </tr>
Lines 71-77 Link Here
71
77
72
        <fieldset class="action">
78
        <fieldset class="action">
73
            <input type="hidden" name="updateLimits" value="1" />
79
            <input type="hidden" name="updateLimits" value="1" />
74
            <input type="hidden" name="branchcode" value="[% branchcode | html %]" />
80
            <input type="hidden" name="fromBranch" value="[% fromBranch.branchcode | html %]" />
75
            <input type="submit" value="Save" />
81
            <input type="submit" value="Save" />
76
            <a class="cancel" href="/cgi-bin/koha/admin/admin-home.pl">Cancel</a>
82
            <a class="cancel" href="/cgi-bin/koha/admin/admin-home.pl">Cancel</a>
77
        </fieldset>
83
        </fieldset>
78
- 

Return to bug 23342