use MARC::File::XML;
+ my $dbh = C4::Context->dbh;
+
sub find_value {
my ($tagfield,$insubfield,$record) = @_;
my $result;
}
}
+ # NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code
+ # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
+ sub _increment_barcode {
+ my ($record, $frameworkcode) = @_;
+ my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
+ unless ($record->field($tagfield)->subfield($tagsubfield)) {
+ my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
+ $sth_barcode->execute;
+ my ($newbarcode) = $sth_barcode->fetchrow;
+ $newbarcode++;
+ # OK, we have the new barcode, now create the entry in MARC record
+ my $fieldItem = $record->field($tagfield);
+ $record->delete_field($fieldItem);
+ $fieldItem->add_subfields($tagsubfield => $newbarcode);
+ $record->insert_fields_ordered($fieldItem);
+ }
+ return $record;
+ }
+
+
my $input = new CGI;
- my $dbh = C4::Context->dbh;
my $error = $input->param('error');
my $biblionumber = $input->param('biblionumber');
my $itemnumber = $input->param('itemnumber');
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
my $number_of_copies = $input->param('number_of_copies');
- # if autoBarcode is set to 'incremental', calculate barcode...
- # NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
- # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
if (C4::Context->preference('autoBarcode') eq 'incremental') {
- my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
- unless ($record->field($tagfield)->subfield($tagsubfield)) {
- my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
- $sth_barcode->execute;
- my ($newbarcode) = $sth_barcode->fetchrow;
- $newbarcode++;
- # OK, we have the new barcode, now create the entry in MARC record
- my $fieldItem = $record->field($tagfield);
- $record->delete_field($fieldItem);
- $fieldItem->add_subfields($tagsubfield => $newbarcode);
- $record->insert_fields_ordered($fieldItem);
- }
+ $record = _increment_barcode($record, $frameworkcode);
}
my $addedolditem = TransformMarcToKoha($dbh,$record);
# If we have to add & duplicate
if ($add_duplicate_submit) {
-
- # We try to get the next barcode
- use C4::Barcodes;
- my $barcodeobj = C4::Barcodes->new;
- my $barcodevalue = $barcodeobj->next_value($addedolditem->{'barcode'}) if $barcodeobj;
- my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
- if ($record->field($tagfield)->subfield($tagsubfield)) {
- # If we got the next codebar value, we put it in the record
- if ($barcodevalue) {
- $record->field($tagfield)->update($tagsubfield => $barcodevalue);
- # If not, we delete the recently inserted barcode from the record (so the user can input a barcode himself)
- } else {
- $record->field($tagfield)->update($tagsubfield => '');
- }
- }
$itemrecord = $record;
+ if (C4::Context->preference('autoBarcode') eq 'incremental') {
+ $itemrecord = _increment_barcode($itemrecord, $frameworkcode);
+ }
+ else {
+ # we have to clear the barcode field in the duplicate item record to make way for the new one generated by the javascript plugin
+ my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
+ my $fieldItem = $itemrecord->field($tagfield);
+ $itemrecord->delete_field($fieldItem);
+ $fieldItem->delete_subfields($tagsubfield);
+ $itemrecord->insert_fields_ordered($fieldItem);
+ }
}
# If we have to add multiple copies
foreach my $thisbranch (@$branches) {
push @authorised_values, $thisbranch->{value};
$authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
- # $value = $thisbranch->{value} if $thisbranch->{selected};
+ # in edit item this is set to the data value otherwise use default
+ if ($op ne 'edititem' && $thisbranch->{selected} ) {
+ $value = $thisbranch->{value};
+ }
}
}
elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {