|
Lines 141-172
sub batch_add {
Link Here
|
| 141 |
@to_branches = @library_ids unless $params->{to_library_id}; |
141 |
@to_branches = @library_ids unless $params->{to_library_id}; |
| 142 |
} |
142 |
} |
| 143 |
|
143 |
|
|
|
144 |
my $dbic_params = Koha::Item::Transfer::Limits->new->attributes_from_api($params); |
| 145 |
my %existing_limits = |
| 146 |
map { sprintf( "%s:%s:%s:%s", $_->fromBranch, $_->toBranch, $_->itemtype, $_->ccode ) => 1 } |
| 147 |
Koha::Item::Transfer::Limits->search($dbic_params)->as_list; |
| 148 |
|
| 144 |
my @results; |
149 |
my @results; |
| 145 |
foreach my $from ( @from_branches ) { |
150 |
foreach my $from (@from_branches) { |
| 146 |
foreach my $to ( @to_branches ) { |
151 |
foreach my $to (@to_branches) { |
| 147 |
my $limit_params = { %$params }; |
152 |
my $limit_params = {%$params}; |
| 148 |
|
153 |
|
| 149 |
$limit_params->{from_library_id} = $from; |
154 |
$limit_params->{from_library_id} = $from; |
| 150 |
$limit_params->{to_library_id} = $to; |
155 |
$limit_params->{to_library_id} = $to; |
| 151 |
|
156 |
|
| 152 |
next if $to eq $from; |
157 |
next if $to eq $from; |
| 153 |
|
158 |
|
| 154 |
my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api( $limit_params ); |
159 |
my $key = sprintf( |
| 155 |
my $exists = Koha::Item::Transfer::Limits->search( $transfer_limit->unblessed )->count; |
160 |
"%s:%s:%s:%s", $limit_params->{from_branch_id} || q{}, |
| 156 |
unless ( $exists ) { |
161 |
$limit_params->{to_branch_id} || q{}, $limit_params->{item_type} || q{}, |
| 157 |
$transfer_limit->store; |
162 |
$limit_params->{collection_code} || q{} |
| 158 |
push( @results, $transfer_limit->to_api()); |
163 |
); |
| 159 |
} |
164 |
next if exists $existing_limits{$key}; |
|
|
165 |
|
| 166 |
my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api($limit_params); |
| 167 |
$transfer_limit->store; |
| 168 |
push( @results, $transfer_limit->to_api() ); |
| 160 |
} |
169 |
} |
| 161 |
} |
170 |
} |
| 162 |
my $transfer_limit = Koha::Item::Transfer::Limit->new_from_api( $params ); |
|
|
| 163 |
|
171 |
|
| 164 |
return $c->render( |
172 |
return $c->render( |
| 165 |
status => 201, |
173 |
status => 201, |
| 166 |
openapi => \@results |
174 |
openapi => \@results |
| 167 |
); |
175 |
); |
| 168 |
} |
176 |
} catch { |
| 169 |
catch { |
|
|
| 170 |
$c->unhandled_exception($_); |
177 |
$c->unhandled_exception($_); |
| 171 |
}; |
178 |
}; |
| 172 |
} |
179 |
} |
| 173 |
- |
|
|