From bc043c86c357028aad91471f9a2af47ebf4a1a24 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 4 Dec 2014 11:15:36 +0100 Subject: [PATCH] Bug 13392: Add suggestions.ordereddate and suggestions.orderedby Those fields are updated when suggestion status is changed to 'ORDERED' and are displayed on suggestion/suggestion.pl page Signed-off-by: Beroud --- C4/Suggestions.pm | 7 +++++++ installer/data/mysql/kohastructure.sql | 5 +++++ installer/data/mysql/updatedatabase.pl | 14 ++++++++++++++ .../prog/en/modules/suggestion/suggestion.tt | 5 +++++ suggestion/suggestion.pl | 2 +- 5 files changed, 32 insertions(+), 1 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 1d9edbb..ffe5642 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -482,6 +482,13 @@ sub ModSuggestion { or $suggestion->{$field} eq '' ); } + if ($suggestion->{STATUS} and $suggestion->{STATUS} eq 'ORDERED') { + $suggestion->{ordereddate} = dt_from_string; + if (C4::Context->userenv) { + $suggestion->{orderedby} = C4::Context->userenv->{number}; + } + } + my $rs = Koha::Database->new->schema->resultset('Suggestion')->find($suggestion->{suggestionid}); my $status_update_table = 1; eval { diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 4ffbbf2..aace3cc 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2187,6 +2187,8 @@ CREATE TABLE `suggestions` ( -- purchase suggestions accepteddate date default NULL, -- date the suggestion was marked as accepted rejectedby INT(11) default NULL, -- borrowernumber for the librarian who rejected the suggestion, foreign key linking to the borrowers table rejecteddate date default NULL, -- date the suggestion was marked as rejected + orderedby INT(11) NULL DEFAULT NULL, -- borrowernumber for the librarian who ordered the suggestion + ordereddate DATE NULL DEFAULT NULL, -- date the suggestion was marked as ordered `STATUS` varchar(10) NOT NULL default '', -- suggestion status (ASKED, CHECKED, ACCEPTED, or REJECTED) `note` mediumtext, -- note entered on the suggestion `author` varchar(80) default NULL, -- author of the suggested item @@ -2213,6 +2215,9 @@ CREATE TABLE `suggestions` ( -- purchase suggestions PRIMARY KEY (`suggestionid`), KEY `suggestedby` (`suggestedby`), KEY `managedby` (`managedby`) + CONSTRAINT suggestions_orderedby_fk + FOREIGN KEY (orderedby) REFERENCES borrowers (borrowernumber) + ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index cf17e0b..f1d0ff1 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -9585,6 +9585,20 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = 'XXX'; +if ( CheckVersion($DBversion) ) { + $dbh->do(q| + ALTER TABLE suggestions + ADD COLUMN orderedby INT(11) NULL DEFAULT NULL AFTER rejecteddate, + ADD COLUMN ordereddate DATE NULL DEFAULT NULL AFTER orderedby, + ADD CONSTRAINT suggestions_orderedby_fk + FOREIGN KEY (orderedby) REFERENCES borrowers (borrowernumber) + ON DELETE SET NULL ON UPDATE CASCADE + |); + print "Upgrade to $DBversion done (Bug 13392: Add suggestions.orderedby and suggestions.ordereddate)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index bfe0198..7884869 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -276,6 +276,11 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o [% accepteddate | $KohaDates %] [% IF ( acceptedby_borrowernumber ) %][% acceptedby_surname %], [% acceptedby_firstname %] [% Branches.GetName( acceptedby_branchcode ) %] ([% acceptedby_description %])[% END %] + + Suggestion ordered + [% ordereddate | $KohaDates %] + [% IF ( orderedby_borrowernumber ) %][% orderedby_surname %], [% orderedby_firstname %] [% Branches.GetName( orderedby_branchcode ) %] ([% orderedby_description %])[% END %] + diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index b146aad..2df0433 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -271,7 +271,7 @@ if ($op=~/else/) { ); } -foreach my $element ( qw(managedby suggestedby acceptedby) ) { +foreach my $element ( qw(managedby suggestedby acceptedby orderedby) ) { # $debug || warn $$suggestion_ref{$element}; if ($$suggestion_ref{$element}){ my $member=GetMember(borrowernumber=>$$suggestion_ref{$element}); -- 1.7.2.5