|
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 |
|