From b57088868ee53bce1ee6dff95cf18d8005b4b34d Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 25 Apr 2017 13:27:00 -0400 Subject: [PATCH] Bug 6758: Add new patron column for date of renewal Test Plan: 1) Apply this patch 2) Run updatedatabase 3) Create a new patron 4) Note the new column date_renewed is NULL 5) Renew the patron 6) Note the date in the column date_renewed is today's date Signed-off-by: Katrin Fischer Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- Koha/Patron.pm | 4 +++- .../data/mysql/atomicupdate/bug_6758.perl | 24 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 3 +++ t/db_dependent/Koha/Patrons.t | 9 +++++-- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_6758.perl diff --git a/Koha/Patron.pm b/Koha/Patron.pm index f7970eacf9..daa972c85b 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -366,7 +366,9 @@ sub renew_account { } my $expiry_date = $self->category->get_expiry_date($date); - $self->dateexpiry($expiry_date)->store; + $self->dateexpiry($expiry_date); + $self->date_renewed( dt_from_string() ); + $self->store(); $self->add_enrolment_fee_if_needed; diff --git a/installer/data/mysql/atomicupdate/bug_6758.perl b/installer/data/mysql/atomicupdate/bug_6758.perl new file mode 100644 index 0000000000..c7bf74b48b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_6758.perl @@ -0,0 +1,24 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + unless ( column_exists( 'borrowers', 'date_renewed' ) ) { + $dbh->do(q{ + ALTER TABLE borrowers ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry; + }); + } + + unless ( column_exists( 'deletedborrowers', 'date_renewed' ) ) { + $dbh->do(q{ + ALTER TABLE deletedborrowers ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry; + }); + } + + unless ( column_exists( 'borrower_modifications', 'date_renewed' ) ) { + $dbh->do(q{ + ALTER TABLE borrower_modifications ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry; + }); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 6758 - Capture membership renewal date for reporting purposes)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index bb222ef90d..2edd37117e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -601,6 +601,7 @@ CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD) `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD) + `date_renewed` date default NULL, -- date the patron/borrower's card was last renewed `gonenoaddress` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having an unconfirmed address `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYYY-MM-DD) @@ -1638,6 +1639,7 @@ CREATE TABLE `borrowers` ( -- this table includes information about your patrons `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD) `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD) + `date_renewed` date default NULL, -- date the patron/borrower's card was last renewed `gonenoaddress` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having an unconfirmed address `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYYY-MM-DD) @@ -3419,6 +3421,7 @@ CREATE TABLE IF NOT EXISTS `borrower_modifications` ( `categorycode` varchar(10) DEFAULT NULL, `dateenrolled` date DEFAULT NULL, `dateexpiry` date DEFAULT NULL, + `date_renewed` date default NULL, `gonenoaddress` tinyint(1) DEFAULT NULL, `lost` tinyint(1) DEFAULT NULL, `debarred` date DEFAULT NULL, diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 96a833e4bf..7a9b9a52ab 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -244,7 +244,7 @@ subtest 'is_going_to_expire' => sub { subtest 'renew_account' => sub { - plan tests => 30; + plan tests => 36; for my $date ( '2016-03-31', '2016-11-30', dt_from_string() ) { my $dt = dt_from_string( $date, 'iso' ); @@ -267,6 +267,7 @@ subtest 'renew_account' => sub { value => { dateexpiry => $a_month_ago, categorycode => $patron_category->{categorycode}, + date_renewed => undef, # Force builder to not popular the column for new patron } } ); @@ -290,6 +291,8 @@ subtest 'renew_account' => sub { my $retrieved_patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} ); my $retrieved_patron_3 = Koha::Patrons->find( $patron_3->{borrowernumber} ); + is( $retrieved_patron->date_renewed, undef, "Date renewed is not set for patrons that have never been renewed" ); + t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' ); t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); my $expiry_date = $retrieved_patron->renew_account; @@ -303,7 +306,9 @@ subtest 'renew_account' => sub { t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); $expiry_date = $retrieved_patron->renew_account; is( $expiry_date, $a_year_later, "today + 12 months must be $a_year_later" ); - $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; + $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); + ok( $retrieved_patron->date_renewed, "Date renewed is set when calling renew_account" ); + $retrieved_expiry_date = $retrieved_patron->dateexpiry; is( dt_from_string($retrieved_expiry_date), $a_year_later, "today + 12 months must be $a_year_later" ); $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' ); -- 2.39.5