From c63688a48eae649c0ba3dca2c211dbc190362073 Mon Sep 17 00:00:00 2001
From: Alex Buckley <alexbuckley@catalyst.net.nz>
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.

* 2 new sysprefs:

- DefaultToCreatingSerialIssuesOnReceival - Disabled by
default. When enabled it sets the 'Create an item record when
receiving this serial' to be ticked.

- PopulateNewItemDateAccessionedOnPageLoad - Disabled by default. When
enabled it populates the 952$d Date Acquired field in the item addition
page without the cataloguer having to click in the field.

Test plan:

1. Enter mysql terminal:
sudo koha-mysql <instancename>

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 <instancename>

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' and there is a new
syspref in the 'Cataloging' system preferences named -
PopulateNewItemDateAccessionedOnPageLoad

Notice both are 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$g - Cost
952$v - Replacement price

17. Go back to Administration > Global System Preferences and set the
'DefaultToCreatingSerialIssuesOnReceival' and
'PopulateNewItemDateAccessionedOnPageLoad' 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. After creating the subscription repeat step 7 and now receive the
serial and notice that the 952d Date Acquired is set automatically to
todays date in the format: YYYY-MM-DD (i.e.
you don't have to click in the field).

20. Try clicking in the 952d and notice no second date is appended

21. Sign off :)

Sponsored-By: Brimbank Library, Australia
---
 C4/Items.pm                                        | 58 +++++++++++++++++++++-
 C4/Serials.pm                                      |  8 +--
 Koha/Schema/Result/Subscription.pm                 | 12 ++++-
 ...ultToCreatingSerialIssuesOnReceival_syspref.sql |  1 +
 ...ateNewItemDateAccessionedOnPageLoad_syspref.sql |  1 +
 ...52-add_ccode_column_to_subscriptions_table.perl |  7 +++
 installer/data/mysql/kohastructure.sql             |  1 +
 installer/data/mysql/sysprefs.sql                  |  2 +
 .../en/modules/admin/preferences/cataloguing.pref  |  7 ++-
 .../prog/en/modules/admin/preferences/serials.pref |  6 +++
 .../prog/en/modules/serials/subscription-add.tt    | 27 +++++++++-
 .../prog/en/modules/serials/subscription-detail.tt | 11 ++--
 serials/subscription-add.pl                        |  9 +++-
 13 files changed, 133 insertions(+), 17 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug_23352-add_DefaultToCreatingSerialIssuesOnReceival_syspref.sql
 create mode 100644 installer/data/mysql/atomicupdate/bug_23352-add_PopulateNewItemDateAccessionedOnPageLoad_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 94808084ac..ec47f29c95 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -56,6 +56,8 @@ use Koha::DateUtils;
 use MARC::Record;
 use C4::ClassSource;
 use C4::Log;
+use C4::Serials;
+use C4::Acquisition;
 use List::MoreUtils qw(any);
 use YAML qw(Load);
 use DateTime::Format::MySQL;
@@ -665,6 +667,7 @@ sub GetItemsInfo {
            borrowers.surname,
            borrowers.firstname,
            borrowers.branchcode as bcode,
+           serial.serialid,
            serial.serialseq,
            serial.publisheddate,
            itemtypes.description,
@@ -1363,7 +1366,7 @@ sub _SearchItems_build_where_fragment {
 
     my ($items, $total) = SearchItems($filter, $params);
 
-Perform a search among items
+Perform ubscriptionCurrentlyOnOrder search among items
 
 $filter is a reference to a hash which can be a filter, or a combination of filters.
 
@@ -1542,6 +1545,20 @@ sub PrepareItemrecordDisplay {
     }
     my @loop_data;
 
+    #Get the default items.price and items.replacementprice from the aqorder that the serial has been ordered in.
+    my $unitprice;
+    my $replacementprice;
+    my $subscriptionid = $defaultvalues->{'subscriptionid'};
+    my $lastOrder;
+
+    #If the subscription is on order (i.e. aqorders.datereceived is NULL then call GetLastOrderNotReceviedFromSubscription() which
+    #retrieves the last order for the subscriptionid with a datereceived also equalling NULL
+    if ( subscriptionCurrentlyOnOrder($subscriptionid) ) {
+        $lastOrder = GetLastOrderNotReceivedFromSubscriptionid( $subscriptionid );
+    } else { #Otherwise the subscription has already arrived so retrieve the last order for the subscriptionid where datereceived is not null
+        $lastOrder = GetLastOrderReceivedFromSubscriptionid( $subscriptionid );
+    }
+
     my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
     my $query = qq{
         SELECT authorised_value,lib FROM authorised_values
@@ -1613,7 +1630,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) ) {
@@ -1632,6 +1650,20 @@ sub PrepareItemrecordDisplay {
                         $defaultvalue = $defaultvalues->{location};
                     }
                 }
+                #Set the default items.price from the aqorders.unitprice
+                if ( $lastOrder->{unitprice} && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.price' ) {
+                    $defaultvalue = $lastOrder->{unitprice};
+                }
+                #Set the default items.replacementprice from the aqorders.replacementprice
+                if ( $lastOrder->{replacementprice} && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.replacementprice' ) {
+                    $defaultvalue = $lastOrder->{replacementprice};
+                }
+                #Set dateaccessioned to current date automatically so the librarian doesnt have to click in the input form to load dateaccessioned
+                if ( C4::Context->preference('PopulateNewItemDateAccessionedOnPageLoad') && $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;
@@ -1694,6 +1726,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(
@@ -1707,6 +1759,7 @@ sub PrepareItemrecordDisplay {
                             $authorised_lib{$value} = $lib;
                         }
                     }
+
                     $subfield_data{marc_value} = {
                         type    => 'select',
                         values  => \@authorised_values,
@@ -1725,6 +1778,7 @@ sub PrepareItemrecordDisplay {
                     if ( $itemrecord and my $field = $itemrecord->field($tag) ) {
                         $defaultvalue = $field->subfield($subfield) || q{};
                     }
+
                     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 f56309e98c..ae1e8fc140 100644
--- a/C4/Serials.pm
+++ b/C4/Serials.pm
@@ -1302,7 +1302,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 $subscription = Koha::Subscriptions->find($subscriptionid);
@@ -1345,6 +1345,7 @@ sub ModSubscription {
             itemtype          => $itemtype,
             previousitemtype  => $previousitemtype,
             mana_id           => $mana_id,
+            ccode             => $ccode,
         }
     )->store;
 
@@ -1362,7 +1363,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.
 
@@ -1379,7 +1380,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;
 
@@ -1422,6 +1423,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 88b43251c1..0264eeef5a 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 0000000000..d7cd80bc02
--- /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_PopulateNewItemDateAccessionedOnPageLoad_syspref.sql b/installer/data/mysql/atomicupdate/bug_23352-add_PopulateNewItemDateAccessionedOnPageLoad_syspref.sql
new file mode 100644
index 0000000000..902d6225ad
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_23352-add_PopulateNewItemDateAccessionedOnPageLoad_syspref.sql
@@ -0,0 +1 @@
+INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('PopulateNewItemDateAccessionedOnPageLoad', 0, NULL, "If enabled the 952$d Date Acquired will be populate on page load rather than requiring the user to click in the input field", "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 0000000000..36a0cc9ef6
--- /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 a7126a56ec..4c408bbbb4 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1998,6 +1998,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 01ec32d118..6a56f5717a 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -153,6 +153,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 using the "standard" option. If empty Koha will default to "surname,firstname,othernames,cardnumber,userid". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page.','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'),
@@ -499,6 +500,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('PayPalSandboxMode',  '1', NULL ,  'If enabled, the system will use PayPal''s sandbox server for testing, rather than the production server.',  'YesNo'),
 ('PayPalSignature',  '', NULL ,  'Your PayPal API signature',  'Free'),
 ('PayPalUser',  '', NULL ,  'Your PayPal API username ( email address )',  'Free'),
+('PopulateNewItemDateAccessionedOnPageLoad', 0, NULL, "If enabled the 952$d Date Acquired will be populate on page load rather than requiring the user to click in the input field", "YesNo"),
 ('PrefillItem','0','','When a new item is added, should it be prefilled with last created item values?','YesNo'),
 ('PreserveSerialNotes','1','','When a new "Expected" issue is generated, should it be prefilled with last created issue notes?','YesNo'),
 ('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
index 20587fa310..dd81f31020 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
@@ -27,6 +27,12 @@ Cataloging:
             - the advanced cataloging editor.
             - "<br/> NOTE:"
             - Currently does not include support for UNIMARC or NORMARC fixed fields.
+        -
+            - pref: PopulateNewItemDateAccessionedOnPageLoad
+              choices:
+                  yes: "Enable"
+                  no: "Disable"
+            - If enabled the 952$d Date Acquired will be populate on page load rather than requiring the user to click in the input field
     Spine Labels:
         -
             - When using the quick spine label printer,
@@ -46,7 +52,6 @@ Cataloging:
                   yes: Display
                   no:  "Don't display"
             - buttons on the bib details page to print item spine labels.
-        -
     Record Structure:
         -
             - Fill in the default language for field 008 Range 35-37 of MARC21 records (e.g. eng, nor, ger, see <a href="http://www.loc.gov/marc/languages/language_code.html">MARC Code List for Languages</a>)
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 d7fa40f61f..52cd023e6e 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
@@ -62,3 +62,9 @@ Serials:
             yes: Do
             no: Do not
         - prefill the notes from the last 'Arrived' serial when generating the next 'Expected' issue.
+    -
+        - 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 c2b3af0a59..6df45750bd 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; }
                                         <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1" checked="checked" /><label class="widelabel" for="serialsadditems-yes"> Create an item record when receiving this serial</label></p>
                                         <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" /><label class="widelabel" for="serialsadditems-no"> Do not create an item record when receiving this serial </label></p>
                                     [% ELSE %]
-                                        <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1"/><label class="widelabel" for="serialsadditems-yes"> Create an item record when receiving this serial</label></p>
-                                        <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" checked="checked" /><label class="widelabel" for="serialsadditems-no"> Do not create an item record when receiving this serial</label></p>
+                                        [% IF Koha.Preference('DefaultToCreatingSerialIssuesOnReceival') %]
+                                            <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1" checked="checked"/><label class="widelabel" for="serialsadditems-yes"> Create an item record when receiving this serial</label></p>
+                                            <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" /><label class="widelabel" for="serialsadditems-no"> Do not create an item record when receiving this serial</label></p>
+                                        [% ELSE %]
+                                            <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1"/><label class="widelabel" for="serialsadditems-yes"> Create an item record when receiving this serial</label></p>
+                                            <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" checked="checked" /><label class="widelabel" for="serialsadditems-no"> Do not create an item record when receiving this serial</label></p>
+                                        [% END %]
                                     [% END %]
                                 </li>
                                 <li class="radio">
@@ -319,6 +324,24 @@ fieldset.rows table { clear: none; margin: 0; }
                                         </select>
                                         <span class="required">Required</span>
                                     </li>
+                                    <ul>
+                                        <li>
+                                            <label for="ccode" class="required">Serial issue Collection code:</label>
+                                            <select name="ccode" id="ccode">
+                                                [% FOREACH ccode_value IN ccode_loop %]
+                                                   [% IF (ccode_value.selected) %]
+                                                        <option value="[% ccode_value.authorised_value | html %]" selected="selected">
+                                                    [% ELSE %]
+                                                        <option value="[% ccode_value.authorised_value | html %]">
+                                                    [% END %]
+                                                        [% ccode_value.lib | html %]
+                                                        </option>
+                                                [% END %]
+                                            </select>
+                                            <span class="required">Required</span>
+                                        </li>
+
+                                    </ul>
                                     <li>
                                         <label for="locale">Locale:</label>
                                         <select id="locale" name="locale">
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt
index 03a7bc9592..ce123fd648 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt
@@ -77,11 +77,7 @@
                         <li><a href="#subscription_planning">Planning</a></li>
                         <li><a href="#subscription_issues">Issues</a></li>
                         <li><a href="#subscription_summary">Summary</a></li>
-                        [% IF orders_grouped.size %]
-                            <li>
-                                <a href="#acquisition_details">Acquisition details</a>
-                            </li>
-                        [% END %]
+                        <li><a href="#acquisition_details">Acquisition details</a></li>
                     </ul>
 
                     <div id="subscription_info">
@@ -478,6 +474,11 @@
                                 </tbody>
                             </table> <!-- /#orders -->
                         </div> <!-- /#acquisition_details -->
+                    [% ELSE %]
+                        <div id="acquisition_details">
+                            <h2>Acquisition details</h2>
+                            Create an order for the new subscription: <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions Home Page</a>
+                        </div>
                     [% END # IF orders_grouped.size %]
                 </div> <!-- /#subscription_description -->
             </main>
diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl
index ebc19a05e9..bbd337e826 100755
--- a/serials/subscription-add.pl
+++ b/serials/subscription-add.pl
@@ -139,9 +139,12 @@ if ($op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription') {
 
 my $locations_loop = GetAuthorisedValues("LOC");
 
+my $ccode_loop = GetAuthorisedValues("CCODE");
+
 $template->param(
     branchcode => $subs->{branchcode},
     locations_loop=>$locations_loop,
+    ccode_loop => $ccode_loop,
 );
 
 my @additional_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
@@ -349,6 +352,7 @@ sub redirect_add_subscription {
     my $itemtype          = $query->param('itemtype');
     my $previousitemtype  = $query->param('previousitemtype');
     my $skip_serialseq    = $query->param('skip_serialseq');
+    my $ccode             = $query->param('ccode');
 
     my $mana_id;
     if ( $query->param('mana_id') ne "" ) {
@@ -375,7 +379,7 @@ sub redirect_add_subscription {
         join(";",@irregularity), $numberpattern, $locale, $callnumber,
         $manualhistory, $internalnotes, $serialsadditems,
         $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
-        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
+        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
     );
     if ( (C4::Context->preference('Mana') == 1) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
         my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription');
@@ -463,6 +467,7 @@ sub redirect_mod_subscription {
     my $itemtype          = $query->param('itemtype');
     my $previousitemtype  = $query->param('previousitemtype');
     my $skip_serialseq    = $query->param('skip_serialseq');
+    my $ccode             = $query->param('ccode');
 
     my $mana_id;
     if ( $query->param('mana_id') ne "" ) {
@@ -498,7 +503,7 @@ sub redirect_mod_subscription {
         $status, $biblionumber, $callnumber, $notes, $letter,
         $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
         $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
-        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
+        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
     );
 
     my @additional_fields;
-- 
2.11.0