[Koha-bugs] [Bug 15239] Add multiple items fail on barcode

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue Aug 22 22:23:28 CEST 2017


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

--- Comment #9 from Ruben Norori <kachomanic at gmail.com> ---
I have the definitive solution:
First we must add two new procedures, functions, methods, which consult in the
database the registry homebranch.

#Original function
sub get_item_from_barcode {
    my ($barcode)=@_;
    my $dbh=C4::Context->dbh;
    my $result;
    my $rq=$dbh->prepare("SELECT itemnumber from items where items.barcode=?");
    $rq->execute($barcode);
    ($result)=$rq->fetchrow;
    return($result);
}

#New function
sub get_home_from_barcode {
    my ($barcode)=@_;
    my $dbh=C4::Context->dbh;
    my $result;
    my $rq=$dbh->prepare("SELECT homebranch from items where items.barcode=?");
    $rq->execute($barcode);
    ($result)=$rq->fetchrow;
    return($result);
}

#New function
sub get_home_from_item {
    my ($barcode)=@_;
    my $dbh=C4::Context->dbh;
    my $result;
    my $rq=$dbh->prepare("SELECT homebranch from items where
items.itemnumber=?");
    $rq->execute($barcode);
    ($result)=$rq->fetchrow;
    return($result);
}

Then call the functions and save the result in a variable that we concate at
the final result, also add an "if" to use one function in the first iteration
and the other function executes it in the "else".

for (my $i = 0; $i < $number_of_copies;) {
                # If there is a barcode
                if ($barcodevalue) {
                    # Getting a new barcode (if it is not the first iteration
or the barcode we tried already exists)
                    # For execute only in the first iteration
                    if($i<1){
                    # Call new function
                    my $newv = get_home_from_item($exist_itemnumber);
                    $barcodevalue = $newv.$barcodeobj->next_value($oldbarcode)
if ($i > 0 || $exist_itemnumber);
                    }else{
                    # Call new function 
                    my $exin = get_home_from_barcode($barcodevalue);
                    $barcodevalue = $exin.$barcodeobj->next_value($oldbarcode)
if ($i > 0 || $exist_itemnumber);
                    }
                    # Putting it into the record
                    if ($barcodevalue) {
                        $record->field($tagfield)->update($tagsubfield =>
$barcodevalue);
                    }

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list