From fa28afba180f0a10db7378edda7d06d542ccb18f Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Fri, 25 Jul 2008 09:04:07 -0500 Subject: [PATCH] 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 --- acqui/finishreceive.pl | 37 ++++++++++++------- acqui/parcel.pl | 16 ++++++++ .../prog/en/css/staff-global.css | 5 +++ koha-tmpl/intranet-tmpl/prog/en/js/additem.js | 16 ++++++++ .../prog/en/modules/acqui/orderreceive.tmpl | 2 +- .../prog/en/modules/acqui/parcel.tmpl | 12 +++++- 6 files changed, 71 insertions(+), 17 deletions(-) diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index df3bc5e654..c43d858ad8 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -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"); + diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 5823554857..e6fa893ecb 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index a64226a64a..c2636f2e05 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js b/koha-tmpl/intranet-tmpl/prog/en/js/additem.js index ee93450703..6d67451fea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/additem.js @@ -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 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; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl index 432a808eb9..cae52116c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl @@ -124,7 +124,7 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl index 645e1d7031..6db1616438 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tmpl @@ -8,7 +8,7 @@ -