View | Details | Raw Unified | Return to bug 6758
Collapse All | Expand All

(-)a/Koha/Patron.pm (-1 / +3 lines)
Lines 359-365 sub renew_account { Link Here
359
    }
359
    }
360
    my $expiry_date = $self->category->get_expiry_date($date);
360
    my $expiry_date = $self->category->get_expiry_date($date);
361
361
362
    $self->dateexpiry($expiry_date)->store;
362
    $self->dateexpiry($expiry_date);
363
    $self->date_renewed( dt_from_string() );
364
    $self->store();
363
365
364
    $self->add_enrolment_fee_if_needed;
366
    $self->add_enrolment_fee_if_needed;
365
367
(-)a/installer/data/mysql/atomicupdate/bug_6758.perl (+24 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
4
    unless ( column_exists( 'borrowers', 'date_renewed' ) ) {
5
        $dbh->do(q{
6
            ALTER TABLE borrowers ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry;
7
        });
8
    }
9
10
    unless ( column_exists( 'deletedborrowers', 'date_renewed' ) ) {
11
        $dbh->do(q{
12
            ALTER TABLE deletedborrowers ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry;
13
        });
14
    }
15
16
    unless ( column_exists( 'borrower_modifications', 'date_renewed' ) ) {
17
        $dbh->do(q{
18
            ALTER TABLE borrower_modifications ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry;
19
        });
20
    }
21
22
    SetVersion( $DBversion );
23
    print "Upgrade to $DBversion done (Bug 6758 - Capture membership renewal date for reporting purposes)\n";
24
}
(-)a/installer/data/mysql/kohastructure.sql (+3 lines)
Lines 598-603 CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower Link Here
598
  `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category
598
  `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category
599
  `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD)
599
  `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD)
600
  `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
600
  `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
601
  `date_renewed` date default NULL, -- date the patron/borrower's card was last renewed
601
  `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
602
  `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
602
  `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
603
  `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
603
  `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 (YYY-MM-DD)
604
  `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 (YYY-MM-DD)
Lines 1629-1634 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
1629
  `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category
1630
  `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category
1630
  `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD)
1631
  `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD)
1631
  `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
1632
  `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
1633
  `date_renewed` date default NULL, -- date the patron/borrower's card was last renewed
1632
  `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
1634
  `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
1633
  `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
1635
  `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
1634
  `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 (YYY-MM-DD)
1636
  `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 (YYY-MM-DD)
Lines 3403-3408 CREATE TABLE IF NOT EXISTS `borrower_modifications` ( Link Here
3403
  `categorycode` varchar(10) DEFAULT NULL,
3405
  `categorycode` varchar(10) DEFAULT NULL,
3404
  `dateenrolled` date DEFAULT NULL,
3406
  `dateenrolled` date DEFAULT NULL,
3405
  `dateexpiry` date DEFAULT NULL,
3407
  `dateexpiry` date DEFAULT NULL,
3408
  `date_renewed` date default NULL,
3406
  `gonenoaddress` tinyint(1) DEFAULT NULL,
3409
  `gonenoaddress` tinyint(1) DEFAULT NULL,
3407
  `lost` tinyint(1) DEFAULT NULL,
3410
  `lost` tinyint(1) DEFAULT NULL,
3408
  `debarred` date DEFAULT NULL,
3411
  `debarred` date DEFAULT NULL,
(-)a/t/db_dependent/Koha/Patrons.t (-3 / +8 lines)
Lines 242-248 subtest 'is_going_to_expire' => sub { Link Here
242
242
243
243
244
subtest 'renew_account' => sub {
244
subtest 'renew_account' => sub {
245
    plan tests => 10;
245
    plan tests => 12;
246
    my $a_month_ago                = dt_from_string->add( months => -1 )->truncate( to => 'day' );
246
    my $a_month_ago                = dt_from_string->add( months => -1 )->truncate( to => 'day' );
247
    my $a_year_later               = dt_from_string->add( months => 12 )->truncate( to => 'day' );
247
    my $a_year_later               = dt_from_string->add( months => 12 )->truncate( to => 'day' );
248
    my $a_year_later_minus_a_month = dt_from_string->add( months => 11 )->truncate( to => 'day' );
248
    my $a_year_later_minus_a_month = dt_from_string->add( months => 11 )->truncate( to => 'day' );
Lines 261-266 subtest 'renew_account' => sub { Link Here
261
            value  => {
261
            value  => {
262
                dateexpiry   => $a_month_ago,
262
                dateexpiry   => $a_month_ago,
263
                categorycode => $patron_category->{categorycode},
263
                categorycode => $patron_category->{categorycode},
264
                date_renewed => undef, # Force builder to not popular the column for new patron
264
            }
265
            }
265
        }
266
        }
266
    );
267
    );
Lines 284-289 subtest 'renew_account' => sub { Link Here
284
    my $retrieved_patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
285
    my $retrieved_patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
285
    my $retrieved_patron_3 = Koha::Patrons->find( $patron_3->{borrowernumber} );
286
    my $retrieved_patron_3 = Koha::Patrons->find( $patron_3->{borrowernumber} );
286
287
288
    is( $retrieved_patron->date_renewed, undef, "Date renewed is not set for patrons that have never been renewed" );
289
287
    t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' );
290
    t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' );
288
    t::lib::Mocks::mock_preference( 'BorrowersLog',              1 );
291
    t::lib::Mocks::mock_preference( 'BorrowersLog',              1 );
289
    my $expiry_date = $retrieved_patron->renew_account;
292
    my $expiry_date = $retrieved_patron->renew_account;
Lines 297-303 subtest 'renew_account' => sub { Link Here
297
    t::lib::Mocks::mock_preference( 'BorrowersLog',              0 );
300
    t::lib::Mocks::mock_preference( 'BorrowersLog',              0 );
298
    $expiry_date = $retrieved_patron->renew_account;
301
    $expiry_date = $retrieved_patron->renew_account;
299
    is( $expiry_date, $a_year_later, );
302
    is( $expiry_date, $a_year_later, );
300
    $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry;
303
304
    $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} );
305
    ok( $retrieved_patron->date_renewed, "Date renewed is set when calling renew_account" );
306
    $retrieved_expiry_date = $retrieved_patron->dateexpiry;
301
    is( dt_from_string($retrieved_expiry_date), $a_year_later );
307
    is( dt_from_string($retrieved_expiry_date), $a_year_later );
302
    $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
308
    $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
303
    is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' );
309
    is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' );
304
- 

Return to bug 6758