Bugzilla – Attachment 16464 Details for
Bug 7294
status "in order"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7294: Adds acquisition informations in marc record
Bug-7294-Adds-acquisition-informations-in-marc-rec.patch (text/plain), 20.81 KB, created by
Matthias Meusburger
on 2013-03-20 09:59:24 UTC
(
hide
)
Description:
Bug 7294: Adds acquisition informations in marc record
Filename:
MIME Type:
Creator:
Matthias Meusburger
Created:
2013-03-20 09:59:24 UTC
Size:
20.81 KB
patch
obsolete
>From 3c4c7cb6df911aec2d3da0e57eb7bc5e77b85b60 Mon Sep 17 00:00:00 2001 >From: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Mon, 20 Feb 2012 14:06:36 +0100 >Subject: [PATCH] Bug 7294: Adds acquisition informations in marc record > >"View status 'in order' to the OPAC and staff interface. Specific >fields from aqorders can be mapped to marc fields (using ACQ bibliographic >framework): >aqorders.branchcode >aqorders.quantity >aqorders.listprice >aqorders.uncertainprice >aqorders.rrp >aqorders.ecost >aqorders.notes >aqorders.supplierreference >aqorders.ordernumber > >This way, you can keep track on what is currently on order >at biblio level until you receive everything. Once all items have been >received, the marc field is deleted. > >Please note that mapping the ordernumber is mandatory for this feature to work > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > C4/Acquisition.pm | 106 +++++++++++++- > acqui/addorder.pl | 147 +++++++++++++++----- > admin/koha2marclinks.pl | 8 +- > admin/marc_subfields_structure.pl | 6 + > installer/data/mysql/kohastructure.sql | 1 + > installer/data/mysql/updatedatabase.pl | 7 + > .../prog/en/modules/acqui/neworderempty.tt | 22 +++ > 7 files changed, 250 insertions(+), 47 deletions(-) > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 4a9eae6..76723f1 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -1306,6 +1306,8 @@ sub ModReceiveOrder { > $sth->finish(); > > my $new_ordernumber = $ordernumber; >+ >+ # If there are still items to be received > if ( $order->{quantity} > $quantrec ) { > # Split order line in two parts: the first is the original order line > # without received items (the quantity is decreased), >@@ -1337,6 +1339,59 @@ sub ModReceiveOrder { > ModItemOrder($itemnumber, $new_ordernumber); > } > } >+ >+ # create a new order for the remaining items, and set its bookfund. >+ foreach my $orderkey ( "linenumber", "allocation" ) { >+ delete($order->{'$orderkey'}); >+ } >+ $order->{'quantity'} -= $quantrec; >+ $order->{'quantityreceived'} = 0; >+ >+ my ($newOrder, $newordernumber) = NewOrder($order); >+ # Change ordernumber in aqorders_items for items not received >+ my @orderitems = GetItemnumbersFromOrder( $order->{'ordernumber'} ); >+ my $count = scalar @orderitems; >+ >+ for (my $i=0; $i<$count; $i++){ >+ foreach (@$received_items){ >+ splice (@orderitems, $i, 1) if ($orderitems[$i] == $_); >+ } >+ } >+ foreach (@orderitems) { >+ ModItemOrder($_, $newOrder); >+ } >+ >+ # Do we have to update order informations from the marc record? >+ my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ'); >+ >+ # Updating MARC order field if exists >+ if ($ordertag and $ordersubtag) { >+ $debug and warn "updating MARC"; >+ # Getting record >+ my $record = GetMarcBiblio($biblionumber); >+ if ($record) { >+ $debug and warn "updating Record"; >+ foreach ($record->field($ordertag)) { >+ if ($_->subfield($ordersubtag) eq $ordernumber) { >+ # Updating ordernumber >+ $debug and warn "updating ordernumber $ordernumber => $newordernumber"; >+ $_->update($ordersubtag => $newordernumber); >+ >+ # Updating quantity >+ my ($quantitytag, $quantitysubtag) = GetMarcFromKohaField('aqorders.quantity', 'ACQ'); >+ if ($quantitysubtag) { >+ $debug and warn "updating quantity " . $order->{quantity}; >+ $_->update($quantitysubtag => $order->{quantity}); >+ } >+ } >+ } >+ >+ # Applying changes >+ ModBiblio($record, $biblionumber, 'ACQ'); >+ } >+ } >+ >+ > } else { > $sth=$dbh->prepare("update aqorders > set quantityreceived=?,datereceived=?,invoiceid=?, >@@ -1344,6 +1399,9 @@ sub ModReceiveOrder { > where biblionumber=? and ordernumber=?"); > $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber); > $sth->finish; >+ >+ # Removing MARC order field if exists >+ DelMarcOrder($biblionumber, $ordernumber); > } > return ($datereceived, $new_ordernumber); > } >@@ -1563,11 +1621,49 @@ sub DelOrder { > my $sth = $dbh->prepare($query); > $sth->execute( $bibnum, $ordernumber ); > $sth->finish; >+ >+ # Removing MARC order field if exists >+ DelMarcOrder($bibnum, $ordernumber); >+ > my @itemnumbers = GetItemnumbersFromOrder( $ordernumber ); > foreach my $itemnumber (@itemnumbers){ >- C4::Items::DelItem( $dbh, $bibnum, $itemnumber ); >+ C4::Items::DelItem( $dbh, $bibnum, $itemnumber ); >+ } >+ >+} >+ >+=head3 DelMarcOrder >+ >+ &DelMarcOrder($biblionumber, $ordernumber); >+ >+Delete the order field from the MARC record. aqorders.ordernumber needs >+to be linked to a MARC field/subfield. The field is deleted if the value of >+the subfield containing the ordernumber matches the ordernumber given >+in parameter >+ >+=cut >+ >+sub DelMarcOrder { >+ my ($biblionumber, $ordernumber) = @_; >+ >+ # Do we have to remove order informations from the marc record? >+ my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ'); >+ >+ # Removing MARC order field if exists >+ if ($ordertag and $ordersubtag) { >+ # Getting record >+ my $record = GetMarcBiblio($biblionumber); >+ if ($record) { >+ # Looking for the right field >+ foreach ($record->field($ordertag)) { >+ if ($_->subfield($ordersubtag) eq $ordernumber) { >+ $record->delete_field($_); >+ } >+ } >+ # Applying changes >+ ModBiblio($record, $biblionumber, 'ACQ'); >+ } > } >- > } > > =head2 FUNCTIONS ABOUT PARCELS >@@ -1871,7 +1967,7 @@ sub GetLateOrders { > > Retreives some acquisition history information > >-params: >+params: > title > author > name >@@ -1928,7 +2024,7 @@ sub GetHistory { > SELECT > biblio.title, > biblio.author, >- biblioitems.isbn, >+ biblioitems.isbn, > biblioitems.ean, > aqorders.basketno, > aqbasket.basketname, >@@ -1948,7 +2044,7 @@ sub GetHistory { > LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno > LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id > LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id >- LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber >+ LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber > LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber > LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid"; > >diff --git a/acqui/addorder.pl b/acqui/addorder.pl >index 3fa7620..2a8f829 100755 >--- a/acqui/addorder.pl >+++ b/acqui/addorder.pl >@@ -122,10 +122,11 @@ if it is an order from an existing suggestion : the id of this suggestion. > use strict; > use warnings; > use CGI; >-use C4::Auth; # get_template_and_user >-use C4::Acquisition; # NewOrder DelOrder ModOrder >-use C4::Suggestions; # ModStatus >-use C4::Biblio; # AddBiblio TransformKohaToMarc >+use C4::Auth; # get_template_and_user >+use C4::Acquisition; # NewOrder DelOrder ModOrder >+use C4::Suggestions; # ModStatus >+use C4::Biblio; # AddBiblio TransformKohaToMarc >+use C4::Bookseller qw/GetBookSellerFromId/; > use C4::Items; > use C4::Output; > >@@ -150,7 +151,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > ); > > # get CGI parameters >-my $orderinfo = $input->Vars; >+my $orderinfo = $input->Vars; > $orderinfo->{'list_price'} ||= 0; > $orderinfo->{'uncertainprice'} ||= 0; > >@@ -163,52 +164,126 @@ my $user = $input->remote_user; > # delete biblio if delbiblio has been set to 1 by the librarian > my $bibitemnum; > if ( $orderinfo->{quantity} ne '0' ) { >+ >+ # Getting bookseller's name >+ if ($orderinfo->{booksellerid}) { >+ my $bookseller = GetBookSellerFromId($orderinfo->{booksellerid}); >+ $orderinfo->{supplierreference} = $bookseller->{name}; >+ } >+ >+ # Do we have to add order informations to the marc record? >+ my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ'); >+ my $record; >+ my $existingbiblio; # Was the order made on an existing biblio? >+ my $ordermodif; # Is this an order modification? >+ > #TODO:check to see if biblio exists >- unless ( $$orderinfo{biblionumber} ) { >+ unless ( $orderinfo->{biblionumber} ) { > #if it doesnt create it >- my $record = TransformKohaToMarc( >- { >- "biblio.title" => "$$orderinfo{title}", >- "biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "", >- "biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "", >- "biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "", >- "biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "", >- "biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "", >- "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", >- "biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", >- "biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", >- "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "", >- "aqorders.branchcode" => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "", >- "aqorders.quantity" => $$orderinfo{quantity} ? $$orderinfo{quantity} : "", >- "aqorders.listprice" => $$orderinfo{listprice} ? $$orderinfo{listprice} : "", >- "aqorders.uncertainprice" => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "", >- "aqorders.rrp" => $$orderinfo{rrp} ? $$orderinfo{rrp} : "", >- "aqorders.ecost" => $$orderinfo{ecost} ? $$orderinfo{ecost} : "", >- "aqorders.discount" => $$orderinfo{discount} ? $$orderinfo{discount} : "", >- }); >+ my $tmprecord = TransformKohaToMarc( >+ { "biblio.title" => "$$orderinfo{title}", >+ "biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "", >+ "biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "", >+ "biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "", >+ "biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "", >+ "biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "", >+ "biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "", >+ "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "", >+ "biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", >+ "biblioitems.editionstatement"=> $$orderinfo{editionstatement}? $$orderinfo{editionstatement}: "", >+ "aqorders.branchcode" => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "", >+ "aqorders.quantity" => $$orderinfo{quantity} ? $$orderinfo{quantity} : "", >+ "aqorders.listprice" => $$orderinfo{listprice} ? $$orderinfo{listprice} : "", >+ "aqorders.uncertainprice" => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "", >+ "aqorders.rrp" => $$orderinfo{rrp} ? $$orderinfo{rrp} : "", >+ "aqorders.ecost" => $$orderinfo{ecost} ? $$orderinfo{ecost} : "", >+ "aqorders.discount" => $$orderinfo{discount} ? $$orderinfo{discount} : "", >+ "aqorders.notes" => $$orderinfo{notes} ? $$orderinfo{notes} : "", >+ "aqorders.supplierreference" => $$orderinfo{supplierreference}?$$orderinfo{supplierreference}:"", >+ "aqorders.sort1" => $$orderinfo{sort1} ? $$orderinfo{sort1} : "", >+ "aqorders.sort2" => $$orderinfo{sort2} ? $$orderinfo{sort2} : "" >+ } >+ ); > > # create the record in catalogue, with framework '' >- my ($biblionumber,$bibitemnum) = AddBiblio($record,''); >+ my ( $biblionumber, $bibitemnum ) = AddBiblio( $tmprecord, '' ); >+ > # change suggestion status if applicable > if ($$orderinfo{suggestionid}) { > ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} ); > } >- $orderinfo->{biblioitemnumber}=$bibitemnum; >- $orderinfo->{biblionumber}=$biblionumber; >+ $orderinfo->{biblioitemnumber} = $bibitemnum; >+ $orderinfo->{biblionumber} = $biblionumber; >+ } else { >+ $existingbiblio = 1; > } > > $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq ''; > >- # if we already have $ordernumber, then it's an ordermodif >- if ($$orderinfo{ordernumber}) { >- ModOrder( $orderinfo); >- } >- else { # else, it's a new line >+ # Getting record >+ $record = GetMarcBiblio($orderinfo->{biblionumber}); >+ >+ >+ >+ # if we already have $ordernumber, then it's an ordermodif >+ if ( $orderinfo->{ordernumber} ) { >+ ModOrder($orderinfo); >+ $ordermodif = 1; >+ >+ } else { # else, it's a new line > @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo); >+ >+ # We have to add the ordernumber in the designated subfield >+ if ($ordertag && $record && !$ordermodif) { >+ >+ # If it's a new line, but we don't have any $ordertag field yet, >+ if (!$record->field($ordertag)) { >+ # We add a new $ordertag field, with the ordernumber as subfield (other fields will be populated later) >+ $record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $orderinfo->{ordernumber})) if (!$record->field($ordertag)); >+ } else { >+ # Else, it's a new line, and we already have a $ordertag field >+ foreach ($record->field($ordertag)) { >+ # If there's a $ordertag field without ordernumber, we create it >+ if (!$_->subfield($ordersubtag)) { >+ $_->update($ordersubtag, $orderinfo->{ordernumber}); >+ } >+ } >+ } >+ ModBiblio($record, $orderinfo->{biblionumber}, 'ACQ'); >+ } >+ >+ > } > >- # now, add items if applicable >- if (C4::Context->preference('AcqCreateItem') eq 'ordering') { >+ if ($record) { >+ >+ # If we have to add order infos to the marc record >+ if ($ordertag) { >+ >+ # If the order was made on an existing biblio and it is not a modification, we add the field >+ $record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$ordermodif && $existingbiblio); >+ >+ foreach ($record->field($ordertag)) { >+ # Looking for the matching one >+ if ($_->subfield($ordersubtag) eq $orderinfo->{ordernumber}) { >+ >+ # Replacing or creating subfields >+ my ($t, $st); >+ for my $tablefield (qw/branchcode quantity listprice uncertainprice rrp ecost notes supplierreference sort1 sort2/) { >+ ($t, $st) = GetMarcFromKohaField("aqorders.$tablefield", 'ACQ'); >+ $_->update($st, $orderinfo->{$tablefield}) if ($orderinfo->{$tablefield} and $st); >+ } >+ ModBiblio($record, $orderinfo->{biblionumber}, 'ACQ'); >+ } >+ } >+ >+ } >+ >+ } >+ >+ >+ # now, add items if applicable >+ if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { > > my @tags = $input->param('tag'); > my @subfields = $input->param('subfield'); >diff --git a/admin/koha2marclinks.pl b/admin/koha2marclinks.pl >index fc320ad..30123a2 100755 >--- a/admin/koha2marclinks.pl >+++ b/admin/koha2marclinks.pl >@@ -157,12 +157,8 @@ q|select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structur > $template->param( > loop => \@loop_data, > tablename => CGI::scrolling_list( >- -name => 'tablename', >- -values => [ >- 'biblio', >- 'biblioitems', >- 'items', >- ], >+ -name => 'tablename', >+ -values => [ 'biblio', 'biblioitems', 'items', 'aqorders'], > -default => $tablename, > -size => 1, > -multiple => 0 >diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl >index 615fbcf..45e8773 100755 >--- a/admin/marc_subfields_structure.pl >+++ b/admin/marc_subfields_structure.pl >@@ -122,6 +122,12 @@ if ( $op eq 'add_form' ) { > while ( ( my $field ) = $sth2->fetchrow_array ) { > push @kohafields, "items." . $field; > } >+ $sth2 = $dbh->prepare("SHOW COLUMNS from aqorders"); >+ $sth2->execute; >+ while ( ( my $field ) = $sth2->fetchrow_array ) { >+ push @kohafields, "aqorders." . $field; >+ } >+ > > # build authorised value list > $sth2->finish; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 4872a1f..bf26b61 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -2792,6 +2792,7 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items > `claims_count` int(11) default 0, -- count of claim letters generated > `claimed_date` date default NULL, -- last date a claim was generated > parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent >+ `branchcode` varchar(10) default NULL, > PRIMARY KEY (`ordernumber`), > KEY `basketno` (`basketno`), > KEY `biblionumber` (`biblionumber`), >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index dbb3faa..5587594 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -6557,6 +6557,13 @@ if ( CheckVersion($DBversion) ) { > SetVersion($DBversion); > } > >+$DBversion = "3.11.00.XXX"; >+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { >+ $dbh->do("ALTER TABLE `aqorders` ADD `branchcode` VARCHAR( 10 ) NULL"); >+ print "Upgrade to $DBversion done (Adding branchcode in aqorders)\n"; >+ SetVersion($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >index 536d439..62fc9bb 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt >@@ -349,6 +349,28 @@ $(document).ready(function() > </ol> > </fieldset> > >+ <!-- Acquisition details --> >+ <fieldset class="rows"> >+ <legend>Acquisition details</legend> >+ <ol> >+ <li> >+ <label for="branchcode">Branch: </label> >+ <select name="branchcode" id="branchcode"> >+ <option value=""></option> >+ [% FOREACH branch_loo IN branchloop %] >+ [% IF (branch_loo.selected) %] >+ <option value="[% branch_loo.value %]" selected="selected">[% branch_loo.branchname %]</option> >+ [% ELSE %] >+ <option value="[% branch_loo.value %]">[% branch_loo.branchname %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ </li> >+ </ol> >+ </fieldset> >+ >+ >+ > [% IF ( suggestionid ) %] > <fieldset class="rows"> > <legend>Suggestion</legend> >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7294
:
7773
|
7834
|
8084
|
8345
|
8916
|
8922
|
9980
|
10121
|
10745
|
11661
|
12301
|
12302
|
12303
|
12332
|
14072
|
14076
|
14918
|
16017
|
16247
| 16464 |
17313