BUG 2351 : Add duplicate barcode check prior to receiving multiple items. This patch adds a javascript form check for duplicates in-form, and returns an error if there are duplicates in the catalog.
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
parent
4998eeed4a
commit
fa28afba18
6 changed files with 71 additions and 17 deletions
|
@ -54,15 +54,12 @@ my @ccode=$input->param('ccode');
|
|||
my @itemtype=$input->param('itemtype');
|
||||
my @location=$input->param('location');
|
||||
my @enumchron=$input->param('volinf');
|
||||
my $cnt = 0;
|
||||
my $cnt=0;
|
||||
my $error_url_str;
|
||||
|
||||
if ($quantityrec > $origquantityrec ) {
|
||||
# save the quantity recieved.
|
||||
$datereceived = ModReceiveOrder($biblionumber,$ordnum,$quantityrec,$user,$cost,$invoiceno,$freight,$replacement,undef,$datereceived);
|
||||
# create items if the user has entered barcodes
|
||||
# my @barcodes=split(/\,| |\|/,$barcode);
|
||||
# foreach barcode provided, build the item MARC::Record and create the item
|
||||
foreach my $bc (@barcode) {
|
||||
my @items_err ;
|
||||
foreach my $bc (@barcode) {
|
||||
my $itemRecord = TransformKohaToMarc({
|
||||
"items.replacementprice" => $replacement,
|
||||
"items.price" => $cost,
|
||||
|
@ -75,13 +72,25 @@ if ($quantityrec > $origquantityrec ) {
|
|||
"items.location" => $location[$cnt],
|
||||
"items.enumchron" => $enumchron[$cnt], # FIXME : No integration here with serials module.
|
||||
"items.loan" => 0, });
|
||||
AddItemFromMarc($itemRecord,$biblionumber);
|
||||
$cnt++;
|
||||
my $item_hash = TransformMarcToKoha(undef,$itemRecord,'','items');
|
||||
# FIXME: possible race condition here. duplicate barcode check should happen in AddItem, but for now we have to do it here.
|
||||
my %err = CheckItemPreSave($item_hash);
|
||||
if(%err) {
|
||||
push @items_err, \%err;
|
||||
for my $err_cnd (keys %err) {
|
||||
$error_url_str .= "&error=" . $err_cnd . "&error_param=" . $err{$err_cnd};
|
||||
}
|
||||
$quantityrec--;
|
||||
} else {
|
||||
AddItemFromMarc($itemRecord,$biblionumber);
|
||||
}
|
||||
}
|
||||
|
||||
# save the quantity received.
|
||||
if( $quantityrec > 0 ) {
|
||||
$datereceived = ModReceiveOrder($biblionumber,$ordnum, $quantityrec ,$user,$cost,$invoiceno,$freight,$replacement,undef,$datereceived);
|
||||
}
|
||||
}
|
||||
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived");
|
||||
#} else {
|
||||
# print $input->header;
|
||||
# #delorder($biblionumber,$ordnum);
|
||||
# print $input->redirect("/acquisitions/");
|
||||
#}
|
||||
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str");
|
||||
|
||||
|
|
|
@ -75,6 +75,8 @@ my $datereceived = ($input->param('op') eq 'new') ? C4::Dates->new($input->para
|
|||
: C4::Dates->new($input->param('datereceived'), 'iso') ;
|
||||
$datereceived = C4::Dates->new() unless $datereceived;
|
||||
my $code=$input->param('code');
|
||||
my @rcv_err = $input->param('error');
|
||||
my @rcv_err_barcode = $input->param('error_bc');
|
||||
|
||||
my ($template, $loggedinuser, $cookie)
|
||||
= get_template_and_user({template_name => "acqui/parcel.tmpl",
|
||||
|
@ -84,6 +86,20 @@ my ($template, $loggedinuser, $cookie)
|
|||
flagsrequired => {acquisition => 1},
|
||||
debug => 1,
|
||||
});
|
||||
|
||||
# If receiving error, report the error (coming from finishrecieve.pl(sic)).
|
||||
if( scalar(@rcv_err) ) {
|
||||
my $cnt=0;
|
||||
my $error_loop;
|
||||
for my $err (@rcv_err) {
|
||||
push @$error_loop, { "error_$err" => 1 , barcode => $rcv_err_barcode[$cnt] };
|
||||
$cnt++;
|
||||
}
|
||||
$template->param( receive_error => 1 ,
|
||||
error_loop => $error_loop,
|
||||
);
|
||||
}
|
||||
|
||||
my $cfstr = "%.2f"; # currency format string -- could get this from currency table.
|
||||
my @parcelitems=GetParcel($supplierid,$invoice,$datereceived->output('iso'));
|
||||
my $countlines = scalar @parcelitems;
|
||||
|
|
|
@ -860,6 +860,11 @@ fieldset.rows .inputnote {
|
|||
padding-left : 15px;
|
||||
}
|
||||
|
||||
.error {
|
||||
background-color : #FFFF99;
|
||||
color: red;
|
||||
}
|
||||
|
||||
div.error {
|
||||
border : 2px dashed #990000;
|
||||
background-color : #FFFF99;
|
||||
|
|
|
@ -35,3 +35,19 @@ function cloneItemBlock(index) {
|
|||
original.parentNode.insertBefore(clone,original.nextSibling);
|
||||
countItemBlocks();
|
||||
}
|
||||
function check_additem() {
|
||||
var barcodes = document.getElementsByName('barcode');
|
||||
var success = true;
|
||||
for(i=0;i<barcodes.length;i++){
|
||||
for(j=0;j<barcodes.length;j++){
|
||||
if( (i > j) && (barcodes[i].value == barcodes[j].value) ) {
|
||||
barcodes[i].className='error';
|
||||
barcodes[j].className='error';
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO : Add AJAX function to test against barcodes already in the database, not just
|
||||
// duplicates within the form.
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@
|
|||
|
||||
</div>
|
||||
</div><div class="yui-g"><fieldset class="action"><!-- TMPL_IF name="catview" -->
|
||||
<input type="submit" name="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/acqui/parcel.pl?supplierid=<!-- TMPL_VAR NAME="supplierid" -->&invoice=<!-- TMPL_VAR NAME="invoice" -->&gst=<!-- TMPL_VAR NAME="gst" -->&freight=<!-- TMPL_VAR NAME="freight" -->">Cancel</a>
|
||||
<input type="button" value="Save" onclick="javascript:if(check_additem()) { this.form.submit(); } else { alert( _('Duplicate barcodes detected. Please correct the errors and resubmit.') ); return false };" /> <a class="cancel" href="/cgi-bin/koha/acqui/parcel.pl?supplierid=<!-- TMPL_VAR NAME="supplierid" -->&invoice=<!-- TMPL_VAR NAME="invoice" -->&gst=<!-- TMPL_VAR NAME="gst" -->&freight=<!-- TMPL_VAR NAME="freight" -->">Cancel</a>
|
||||
<!-- TMPL_ELSE -->
|
||||
<a href="/cgi-bin/koha/acqui/neworderempty.pl?ordnum=<!-- TMPL_VAR NAME="ordernumber" -->&id=<!-- TMPL_VAR NAME="booksellerid" -->">Edit</a>
|
||||
<!-- /TMPL_IF --></fieldset></div> </form>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<!-- TMPL_INCLUDE NAME="header.inc" -->
|
||||
<!-- TMPL_INCLUDE NAME="acquisitions-search.inc" -->
|
||||
|
||||
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> › <!-- TMPL_IF name="date" -->
|
||||
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> › <!-- TMPL_IF name="datereceived" -->
|
||||
Receipt Summary for <i><!-- TMPL_VAR NAME="name" --></i> <!--TMPL_IF Name="invoice"--><i>[ <!-- TMPL_VAR NAME="invoice" --> ]</i><!--/TMPL_IF --> on <i><!-- TMPL_VAR NAME="formatteddatereceived" --></i>
|
||||
<!-- TMPL_ELSE -->
|
||||
Receive orders from <!-- TMPL_VAR NAME="name" -->
|
||||
|
@ -19,7 +19,15 @@
|
|||
<div id="bd">
|
||||
<div id="yui-main">
|
||||
<div class="yui-b">
|
||||
|
||||
<!-- TMPL_IF NAME="receive_error" -->
|
||||
<div id="page_error" class="error">
|
||||
<h3>Error adding items:</h3>
|
||||
<ul>
|
||||
<!-- TMPL_LOOP NAME="error_loop" -->
|
||||
<li><!-- TMPL_VAR NAME="error_param" --> : <!-- TMPL_IF NAME="error_duplicate_barcode" -->Duplicate Barcode<!-- /TMPL_IF --> <!-- todo: other error conditions come here. --></li>
|
||||
<!-- /TMPL_LOOP -->
|
||||
</div>
|
||||
<!-- /TMPL_IF -->
|
||||
<h1>
|
||||
<!-- TMPL_IF name="datereceived" -->
|
||||
Receipt Summary for <i><!-- TMPL_VAR NAME="name" --></i> <!--TMPL_IF Name="invoice"--> <i> [ <!-- TMPL_VAR NAME="invoice" --> ] </i><!--/TMPL_IF --> on <i><!-- TMPL_VAR NAME="formatteddatereceived" --></i>
|
||||
|
|
Loading…
Reference in a new issue