https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19442

Rudy Hinojosa <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]
                   |                            |utions

--- Comment #2 from Rudy Hinojosa <[email protected]> ---
This already works on version 26.05.02, if you replace the entire routine of
get_borrower_attributes() codeblock in /usr/share/koha/lib/C4/patroncard/Lib.pm
with the following get_borrower_attributes() below:

sub get_borrower_attributes {
    my ( $borrower_number, @fields ) = @_;

    my $get_branch = 0;
    $get_branch = 1 if grep { $_ eq 'branchcode' } @fields;

    # Get normal borrower table fields
    my $dbh = C4::Context->dbh;

    my @borrower_fields = ();
    my @attribute_fields = ();

    # Get the actual columns in borrowers
    my $sth_columns = $dbh->prepare("SHOW COLUMNS FROM borrowers");
    $sth_columns->execute();

    my %borrower_columns;
    while ( my $row = $sth_columns->fetchrow_hashref ) {
        $borrower_columns{ $row->{'Field'} } = 1;
    }

    # Separate normal borrower fields from patron attributes
    foreach my $field (@fields) {
        if ( $borrower_columns{$field} ) {
            push @borrower_fields, $field;
        } else {
            push @attribute_fields, $field;
        }
    }

    my $borrower_attributes = {};

    # Get normal borrower fields
    if (@borrower_fields) {
        my $query = "SELECT " . join( ', ', @borrower_fields )
            . " FROM borrowers WHERE borrowernumber = ?";

        my $sth = $dbh->prepare($query);
        $sth->execute($borrower_number);

        if ( $sth->err ) {
            warn sprintf(
                'Database returned the following error: %s',
                $sth->errstr
            );
            return 1;
        }

        $borrower_attributes = $sth->fetchrow_hashref() || {};
    }

    # Get patron attributes such as SID
    if (@attribute_fields) {
        my $placeholders = join( ',', ('?') x @attribute_fields );

        my $query = "
            SELECT code, attribute
            FROM borrower_attributes
            WHERE borrowernumber = ?
              AND code IN ($placeholders)
        ";

        my $sth = $dbh->prepare($query);
        $sth->execute( $borrower_number, @attribute_fields );

        while ( my $row = $sth->fetchrow_hashref ) {
            $borrower_attributes->{ $row->{'code'} } = $row->{'attribute'};
        }
    }

    # Convert branchcode to branch name as before
    if ($get_branch) {
        $sth_columns = $dbh->prepare(
            "SELECT branchname FROM branches WHERE branchcode = ?"
        );
        $sth_columns->execute( $borrower_attributes->{'branchcode'} );

        if ( $sth_columns->err ) {
            warn sprintf(
                'Database returned the following error: %s',
                $sth_columns->errstr
            );
            return 1;
        }

        my $branch = $sth_columns->fetchrow_hashref();
        $borrower_attributes->{'branchcode'} = $branch->{'branchname'}
            if $branch;
    }

    return $borrower_attributes;
}

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to