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

(-)a/C4/Circulation.pm (-25 / +18 lines)
Lines 58-63 use Koha::RefundLostItemFeeRules; Link Here
58
use Koha::Account::Lines;
58
use Koha::Account::Lines;
59
use Koha::Account::Offsets;
59
use Koha::Account::Offsets;
60
use Koha::Config::SysPrefs;
60
use Koha::Config::SysPrefs;
61
use Koha::Util::SystemPreferences;
61
use Carp;
62
use Carp;
62
use List::MoreUtils qw( uniq any );
63
use List::MoreUtils qw( uniq any );
63
use Scalar::Util qw( looks_like_number );
64
use Scalar::Util qw( looks_like_number );
Lines 1839-1870 sub AddReturn { Link Here
1839
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
1840
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
1840
    my $patron_unblessed = $patron ? $patron->unblessed : {};
1841
    my $patron_unblessed = $patron ? $patron->unblessed : {};
1841
1842
1842
    my $yaml_loc = C4::Context->preference('UpdateItemLocationOnCheckin');
1843
    my $update_loc_rules = get_yaml_pref_hash('UpdateItemLocationOnCheckin');
1843
    if ($yaml_loc) {
1844
    map { $update_loc_rules->{$_} = $update_loc_rules->{$_}[0] } keys %$update_loc_rules; #We can only move to one location so we flatten the arrays
1844
        $yaml_loc = "$yaml_loc\n\n";  # YAML is strict on ending \n. Surplus does not hurt
1845
    if ($update_loc_rules) {
1845
        my $rules;
1846
        if (defined $update_loc_rules->{_ALL_}) {
1846
        eval { $rules = YAML::Load($yaml_loc); };
1847
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $item->{permanent_location}; }
1847
        if ($@) {
1848
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
1848
            warn "Unable to parse UpdateItemLocationOnCheckin syspref : $@";
1849
            if ( $item->{location} ne $update_loc_rules->{_ALL_}) {
1850
                $messages->{'ItemLocationUpdated'} = { from => $item->{location}, to => $update_loc_rules->{_ALL_} };
1851
                ModItem( { location => $update_loc_rules->{_ALL_} }, undef, $itemnumber );
1852
            }
1849
        }
1853
        }
1850
        else {
1854
        else {
1851
            if (defined $rules->{_ALL_}) {
1855
            foreach my $key ( keys %$update_loc_rules ) {
1852
                if ($rules->{_ALL_} eq '_PERM_') { $rules->{_ALL_} = $item->{permanent_location}; }
1856
                if ( $update_loc_rules->{$key} eq '_PERM_' ) { $update_loc_rules->{$key} = $item->{permanent_location}; }
1853
                if ($rules->{_ALL_} eq '_BLANK_') { $rules->{_ALL_} = ''; }
1857
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
1854
                if ( $item->{location} ne $rules->{_ALL_}) {
1858
                if ( ($item->{location} eq $key && $item->{location} ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->{location} eq '' && $update_loc_rules->{$key} ne '') ) {
1855
                    $messages->{'ItemLocationUpdated'} = { from => $item->{location}, to => $rules->{_ALL_} };
1859
                    $messages->{'ItemLocationUpdated'} = { from => $item->{location}, to => $update_loc_rules->{$key} };
1856
                    ModItem( { location => $rules->{_ALL_} }, undef, $itemnumber );
1860
                    ModItem( { location => $update_loc_rules->{$key} }, undef, $itemnumber );
1857
                }
1861
                    last;
1858
            }
1859
            else {
1860
                foreach my $key ( keys %$rules ) {
1861
                    if ( $rules->{$key} eq '_PERM_' ) { $rules->{$key} = $item->{permanent_location}; }
1862
                    if ( $rules->{$key} eq '_BLANK_') { $rules->{$key} = '' ;}
1863
                    if ( ($item->{location} eq $key && $item->{location} ne $rules->{$key}) || ($key eq '_BLANK_' && $item->{location} eq '' && $rules->{$key} ne '') ) {
1864
                        $messages->{'ItemLocationUpdated'} = { from => $item->{location}, to => $rules->{$key} };
1865
                        ModItem( { location => $rules->{$key} }, undef, $itemnumber );
1866
                        last;
1867
                    }
1868
                }
1862
                }
1869
            }
1863
            }
1870
        }
1864
        }
1871
- 

Return to bug 14576