From 844a66971a3f1dd9d5ec4b7682403b44c012c2a6 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Sun, 21 Jul 2019 22:35:28 +0000 Subject: [PATCH] Bug 23352: Default setting of item price, replacement price, ccode, dateaccesioned in serials-edit.pl This patch contains: * Database and DBIx changes * Setting 952g (items.price) and 952v (items.replacementprice) from Acquisitions module order unitprice and replacment cost respectively * Default setting of the 952d (items.dateaccessioned) on page load * New input in serials/subscription-add.pl for librarian to select default collection code for serial issues. * New syspref: DefaultToCreatingSerialIssuesOnReceival - disabled by default. When enabled it sets the 'Create an item record when receiving this serial' to be ticked. Test plan: 1. Enter mysql terminal: sudo koha-mysql 2. Run the query: describe subscription; 3. Notice there is no 'ccode' column after the 'mana_id' column 4. In the staff client go to Serials > New subscription 5. Notice the 'Do not create an item record when receiving this serial' radiobutton is ticked by default. Click the 'Create an item record when receiving this serial' radiobutton 6. Fill out all the required serial fields, set the library branch to a branch different to the library branch you are currently logged in as and click 'Save subscription' 7. Now go to the Acquisitions module. Add a new basket to a vendor Add to the basket and select 'From a subscription' Search for the subscription you created in steps 5-6 Set a quantity, vendor price of 2 and replacement cost of 3 Save the order 8. Go back to Serials and recieve an item for the subscription and notice that the item creation form that is loaded when you change the status from 'Expected' to 'Arrived' does not set defaults for: 952$8 - Collection code 952$d - Date accessioned - You must click in the input box to load a default value for this 952$g - Cost 952$v - Replacement price Also note the 952$a and 952$b are set the library you set in the subscription and not the branch you are currently logged in as 9. Exit mysql terminal and apply patch 10. Navigate to the installer/data/mysql directory 11. Enter koha-shell: sudo koha-shell 12. Run: ./updatedatabase.pl 13. Notice 2 atomicupdates run without errors 14. Exit koha-shell and re-enter mysql terminal and confirm the 'ccode' column is in the subscription table now after mana_id column Exit the MySQL terminal. 15. In the Koha staff client > Administration > Global System Preferences and notice there is a new syspref in the 'Serials' system preferences named 'DefaultToCreatingSerialIssuesOnReceival' Notice it is disabled by default. 16. Repeat steps 4-8. Notice there is now a new input in the subscription-add.pl page 2: 'Serial issue Collection' which populates with the contents of the ccode authorised value Notice upon receiving the item the following fields do have a default value now: 952$8 - Collection code 952$d - Date accessioned - Default value in this field on page load 952$g - Cost 952$v - Replacement price 17. Go back to Administration > Global System Preferences and set the 'DefaultToCreatingSerialIssuesOnReceival' syspref to 'enabled' 18. Go back to Serials > New subscription and observe the 'Create an item record when receiving this serial' radiobutton is now checked by default 19. Sign off :) Sponsored-By: Brimbank Library, Australia --- C4/Items.pm | 45 +++++++++++++++++++++- C4/Serials.pm | 11 +++--- Koha/Schema/Result/Subscription.pm | 12 +++++- ...ultToCreatingSerialIssuesOnReceival_syspref.sql | 1 + ...52-add_ccode_column_to_subscriptions_table.perl | 7 ++++ installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/serials.pref | 6 +++ .../prog/en/modules/serials/subscription-add.tt | 27 ++++++++++++- .../prog/en/modules/serials/subscription-detail.tt | 12 +++--- serials/subscription-add.pl | 9 ++++- 11 files changed, 113 insertions(+), 19 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_23352-add_DefaultToCreatingSerialIssuesOnReceival_syspref.sql create mode 100644 installer/data/mysql/atomicupdate/bug_23352-add_ccode_column_to_subscriptions_table.perl diff --git a/C4/Items.pm b/C4/Items.pm index 797bda6..e587f9c 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -2335,7 +2335,6 @@ The $frameworkcode returns the item for the given frameworkcode, ONLY if bibnum sub PrepareItemrecordDisplay { my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode ) = @_; - my $dbh = C4::Context->dbh; $frameworkcode = C4::Biblio::GetFrameworkCode($bibnum) if $bibnum; my ( $itemtagfield, $itemtagsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" ); @@ -2353,6 +2352,14 @@ sub PrepareItemrecordDisplay { } my @loop_data; + my $unitprice; + my $replacementprice; + my @orders = C4::Acquisition::GetOrdersByBiblionumber($bibnum); + foreach my $order (@orders) { + $unitprice = $order->{'unitprice'}; + $replacementprice = $order->{'replacementprice'}; + } + my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; my $query = qq{ SELECT authorised_value,lib FROM authorised_values @@ -2422,7 +2429,8 @@ sub PrepareItemrecordDisplay { $defaultvalue = $defaultvalues->{callnumber}; } } - if ( ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' ) + + if ( ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' ) && $defaultvalues && $defaultvalues->{'branchcode'} ) { if ( $itemrecord and $defaultvalues and not $itemrecord->subfield($tag,$subfield) ) { @@ -2441,6 +2449,17 @@ sub PrepareItemrecordDisplay { $defaultvalue = $defaultvalues->{location}; } } + if ( $unitprice && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.price' ) { + $defaultvalue = $unitprice; + } + if ( $replacementprice && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.replacementprice' ) { + $defaultvalue = $replacementprice; + } + if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.dateaccessioned' ) { + my $date = DateTime->now; + $date = $date->ymd; + $defaultvalue = $date; + } if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) { my @authorised_values; my %authorised_lib; @@ -2503,6 +2522,26 @@ sub PrepareItemrecordDisplay { $defaultvalue = $default_source; + #---- collection code CCODE + } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "CCODE") { + $authorised_values_sth->execute( + $tagslib->{$tag}->{$subfield}->{authorised_value}, + $branch_limit ? $branch_limit : () + ); + push @authorised_values, "" + unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); + while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { + push @authorised_values, $value; + $authorised_lib{$value} = $lib; + } + + # Set the default CCODE to what was set in subscription.ccode + if ($itemrecord and $defaultvalues) { + $defaultvalue = $defaultvalues->{'ccode'}; + } elsif (!$itemrecord and $defaultvalues) { + $defaultvalue = $defaultvalues->{'ccode'}; + } + #---- "true" authorised value } else { $authorised_values_sth->execute( @@ -2516,6 +2555,7 @@ sub PrepareItemrecordDisplay { $authorised_lib{$value} = $lib; } } + $subfield_data{marc_value} = { type => 'select', values => \@authorised_values, @@ -2534,6 +2574,7 @@ sub PrepareItemrecordDisplay { if ( $itemrecord and my $field = $itemrecord->field($tag) ) { $defaultvalue = $field->subfield($subfield); } + if( !$plugin->errstr ) { #TODO Move html to template; see report 12176/13397 my $tab= $plugin->noclick? '-1': ''; diff --git a/C4/Serials.pm b/C4/Serials.pm index f2290f4..3cf09cd 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1301,7 +1301,7 @@ sub ModSubscription { $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id + $itemtype, $previousitemtype, $mana_id, $ccode ) = @_; my $dbh = C4::Context->dbh; @@ -1314,7 +1314,7 @@ sub ModSubscription { callnumber=?, notes=?, letter=?, manualhistory=?, internalnotes=?, serialsadditems=?, staffdisplaycount=?, opacdisplaycount=?, graceperiod=?, location = ?, enddate=?, - skip_serialseq=?, itemtype=?, previousitemtype=?, mana_id=? + skip_serialseq=?, itemtype=?, previousitemtype=?, mana_id=?, ccode=? WHERE subscriptionid = ?"; my $sth = $dbh->prepare($query); @@ -1328,7 +1328,7 @@ sub ModSubscription { $letter, ($manualhistory ? $manualhistory : 0), $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id, + $itemtype, $previousitemtype, $mana_id, $ccode, $subscriptionid ); my $rows = $sth->rows; @@ -1345,7 +1345,7 @@ $subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbu $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, - $skip_serialseq, $itemtype, $previousitemtype); + $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode); Create a new subscription with value given on input args. @@ -1362,7 +1362,7 @@ sub NewSubscription { $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, - $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id + $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode ) = @_; my $dbh = C4::Context->dbh; @@ -1405,6 +1405,7 @@ sub NewSubscription { itemtype => $itemtype, previousitemtype => $previousitemtype, mana_id => $mana_id, + ccode => $ccode, } )->store; $subscription->discard_changes; diff --git a/Koha/Schema/Result/Subscription.pm b/Koha/Schema/Result/Subscription.pm index 88b4325..0264eee 100644 --- a/Koha/Schema/Result/Subscription.pm +++ b/Koha/Schema/Result/Subscription.pm @@ -276,6 +276,12 @@ __PACKAGE__->table("subscription"); data_type: 'integer' is_nullable: 1 +=head2 ccode + + data_type: 'varchar' + is_nullable: 1 + size: 80 + =cut __PACKAGE__->add_columns( @@ -365,6 +371,8 @@ __PACKAGE__->add_columns( { data_type => "varchar", is_nullable => 1, size => 10 }, "mana_id", { data_type => "integer", is_nullable => 1 }, + "ccode", + { data_type => "varchar", is_nullable => 1, size => 80 }, ); =head1 PRIMARY KEY @@ -452,8 +460,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-01-23 12:56:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dTb/JOO3KQ3NZGypFbRiEw +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2019-07-21 22:34:06 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TS3fIO7Y11bAkj73Ak8ouA __PACKAGE__->has_many( "additional_field_values", diff --git a/installer/data/mysql/atomicupdate/bug_23352-add_DefaultToCreatingSerialIssuesOnReceival_syspref.sql b/installer/data/mysql/atomicupdate/bug_23352-add_DefaultToCreatingSerialIssuesOnReceival_syspref.sql new file mode 100644 index 0000000..d7cd80b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_23352-add_DefaultToCreatingSerialIssuesOnReceival_syspref.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('DefaultToCreatingSerialIssuesOnReceival', 0, NULL, "If enabled the 'Create an item record when receiving this serial' checkbox will be checked by default", "YesNo"); diff --git a/installer/data/mysql/atomicupdate/bug_23352-add_ccode_column_to_subscriptions_table.perl b/installer/data/mysql/atomicupdate/bug_23352-add_ccode_column_to_subscriptions_table.perl new file mode 100644 index 0000000..36a0cc9 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_23352-add_ccode_column_to_subscriptions_table.perl @@ -0,0 +1,7 @@ + +unless ( column_exists('subscription', 'ccode')) { + $dbh->do(q{ + ALTER TABLE `subscription` + ADD `ccode` varchar (80) default NULL AFTER `mana_id` + }); +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 62effe9..f8d0a12 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2021,6 +2021,7 @@ CREATE TABLE `subscription` ( -- information related to the subscription `itemtype` VARCHAR( 10 ) NULL, `previousitemtype` VARCHAR( 10 ) NULL, `mana_id` int(11) NULL DEFAULT NULL, + `ccode` varchar(80) DEFAULT NULL, -- authorized value for the collection code associated with this item (MARC21 952$8) PRIMARY KEY (`subscriptionid`), KEY `by_biblionumber` (`biblionumber`), CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE, diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index a0d1132..e2ca8a5 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -143,6 +143,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('DefaultPatronSearchFields', 'surname,firstname,othernames,cardnumber,userid',NULL,'Comma separated list defining the default fields to be used during a patron search','free'), ('defaultSortField','relevance','relevance|popularity|call_number|pubdate|acqdate|title|author','Specify the default field used for sorting','Choice'), ('defaultSortOrder','dsc','asc|dsc|az|za','Specify the default sort order','Choice'), +('DefaultToCreatingSerialIssuesOnReceival', 0, NULL, "If enabled the 'Create an item record when receiving this serial' checkbox will be checked by default", "YesNo"), ('DefaultToLoggedInLibraryCircRules', '0', NULL , 'If enabled, circ rules editor will default to the logged in library''s rules, rather than the ''all libraries'' rules.', 'YesNo'), ('DefaultToLoggedInLibraryNoticesSlips', '0', NULL , 'If enabled,slips and notices editor will default to the logged in library''s rules, rather than the ''all libraries'' rules.', 'YesNo'), ('DefaultToLoggedInLibraryOverdueTriggers', '0', NULL , 'If enabled, overdue status triggers editor will default to the logged in library''s rules, rather than the ''default'' rules.', 'YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref index c64abdd..12a0dbb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref @@ -56,3 +56,9 @@ Serials: yes: Make no: Do not make - previous serial automatically available when receiving a new serial issue. The previous issue can also be set to another item type when receiving a new one. Please note that the item-level_itypes syspref must be set to specific item. + - + - pref: DefaultToCreatingSerialIssuesOnReceival + choices: + yes: Enable + no: Disable + - If enabled the 'Create an item record when receiving this serial' checkbox in serials/subscription-add.pl will be ticked by default diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index eff55ae..18c9802 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -78,8 +78,13 @@ fieldset.rows table { clear: none; margin: 0; }

[% ELSE %] -

-

+ [% IF Koha.Preference('DefaultToCreatingSerialIssuesOnReceival') %] +

+

+ [% ELSE %] +

+

+ [% END %] [% END %]
  • @@ -319,6 +324,24 @@ fieldset.rows table { clear: none; margin: 0; } Required
  • +
      +
    • + + + Required +
    • + +