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

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

Return to bug 14576