fix for 565 : item barcode not checked unique

This commit is contained in:
tipaul 2003-09-04 13:04:12 +00:00
parent 8bc5e4ab66
commit 0ee4bfe070
4 changed files with 30 additions and 2 deletions

View file

@ -27,6 +27,7 @@ use C4::Interface::CGI::Output;
use C4::Biblio;
use C4::Context;
use C4::Koha; # XXX subfield_is_koha_internal_p
use C4::Search;
use HTML::Template;
use MARC::File::USMARC;
@ -58,6 +59,7 @@ my $tagslib = &MARCgettagslib($dbh,1);
my $record = MARCgetbiblio($dbh,$bibid);
my $itemrecord;
my $nextop="additem";
my @errors; # store errors found while checking data BEFORE saving item.
#------------------------------------------------------------------------------------------------------------------------------
if ($op eq "additem") {
#------------------------------------------------------------------------------------------------------------------------------
@ -73,9 +75,20 @@ if ($op eq "additem") {
$indicators{$ind_tag[$i]} = $indicator[$i];
}
my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
# check for item barcode # being unique
my $oldbibid = MARCmarc2koha($dbh,$record);
my $exists = itemdata($oldbibid->{'barcode'});
push @errors,"barcode_not_unique" if($exists);
# MARC::Record builded => now, record in DB
my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid);
$nextop = "additem";
# if barcode exists, don't create, but report The problem.
my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid) unless ($exists);
if ($exists) {
$nextop = "additem";
$itemrecord = $record;
warn "==>".$record->as_formatted;
} else {
$nextop = "additem";
}
#------------------------------------------------------------------------------------------------------------------------------
} elsif ($op eq "edititem") {
#------------------------------------------------------------------------------------------------------------------------------
@ -253,4 +266,7 @@ $template->param(item_loop => \@item_value_loop,
itemtagsubfield =>$itemtagsubfield,
op => $nextop,
opisadd => ($nextop eq "saveitem")?0:1);
foreach my $error (@errors) {
$template->param($error => 1);
}
output_html_with_http_headers $input, $cookie, $template->output;

View file

@ -24,6 +24,7 @@
</table>
<br />
<center>
<DIV name="10XX" id="10XX">
<table border=1 cellspacing=0 cellpadding=5 width=80%>
<tr background="<TMPL_VAR name="themelang">/images/background-mem.gif">
@ -43,6 +44,7 @@
</table>
</DIV>
<br /><br />
<table border=1 cellspacing=0 cellpadding=5 width=80%>
<tr background="<TMPL_VAR name="themelang">/images/background-mem.gif">
<th>New Item</th>
@ -63,6 +65,9 @@
</tmpl_loop>
</table>
<input type="hidden" name="itemnum" value="<TMPL_VAR name="itemnum">">
<TMPL_IF name="barcode_not_unique">
<div id="problem"><b>ERROR : Barcode already exists !<b></div>
</TMPL_IF>
<TMPL_IF name="opisadd">
<input type="button" value="Add item" onClick='Check(this.form)' accesskey="w">
<TMPL_ELSE>

View file

@ -13,6 +13,10 @@
background-image:url("/intranet-tmpl/default/en/images/background-mem.gif");
}
#problem {
color: red;
font-weight:bold;
}
#menubar {
border-top:1px solid #666666;
font: 1.2em sans-serif;

View file

@ -63,6 +63,9 @@
</tmpl_loop>
</table>
<input type="hidden" name="itemnum" value="<TMPL_VAR name="itemnum">">
<TMPL_IF name="barcode_not_unique">
<div id="problem"><b>ERROR : Barcode already exists !<b></div>
</TMPL_IF>
<TMPL_IF name="opisadd">
<input type="button" value="Enregistrer" onClick='Check(this.form)' accesskey="w">
<TMPL_ELSE>