From 469a5ef24eec0380fb114f871512af04ed1308ae Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 9 Mar 2012 12:09:24 +0100 Subject: [PATCH 1/2] Bug 5342: Adds a claims_count field in the serial table This patch adds 1 column in the serial table : - claims_count : number of claims for an orders You can add a tag around your item fields, like this : -- Begin example <> <> The following issues are in late: <>, <> (<>) -- End example For more explication, see the discussion on the Bug 5347 --- C4/Serials.pm | 26 ++++-- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 ++ .../prog/en/modules/serials/claims.tt | 94 ++++++++++--------- serials/claims.pl | 15 +++- 5 files changed, 86 insertions(+), 57 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index ba0397c..8468650 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -88,10 +88,12 @@ sub GetSuppliersWithLateIssues { my $dbh = C4::Context->dbh; my $query = qq| SELECT DISTINCT id, name - FROM subscription - LEFT JOIN serial ON serial.subscriptionid=subscription.subscriptionid - LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id - WHERE id > 0 AND ((planneddate < now() AND serial.status=1) OR serial.STATUS = 3 OR serial.STATUS = 4) ORDER BY name|; + FROM subscription + LEFT JOIN serial ON serial.subscriptionid=subscription.subscriptionid + LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id + WHERE id > 0 AND ((planneddate < now() AND serial.status=1) OR serial.STATUS = 3 OR serial.STATUS = 4 OR serial.STATUS = 7) + ORDER BY name + |; return $dbh->selectall_arrayref($query, { Slice => {} }); } @@ -284,8 +286,12 @@ sub UpdateClaimdateIssues { my $dbh = C4::Context->dbh; $date = strftime( "%Y-%m-%d", localtime ) unless ($date); my $query = " - UPDATE serial SET claimdate = ?, status = 7 - WHERE serialid in (" . join( ",", map { '?' } @$serialids ) . ")"; + UPDATE serial + SET claimdate = ?, + status = 7, + claims_count = claims_count + 1 + WHERE serialid in (" . join( ",", map { '?' } @$serialids ) . ") + "; my $rq = $dbh->prepare($query); $rq->execute($date, @$serialids); return $rq->rows; @@ -1755,7 +1761,7 @@ sub GetLateOrMissingIssues { "SELECT serialid, aqbooksellerid, name, biblio.title, planneddate, serialseq, - serial.status, serial.subscriptionid, claimdate, + serial.status, serial.subscriptionid, claimdate, claims_count, subscription.branchcode FROM serial LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid @@ -1772,7 +1778,7 @@ sub GetLateOrMissingIssues { "SELECT serialid, aqbooksellerid, name, biblio.title, planneddate, serialseq, - serial.status, serial.subscriptionid, claimdate, + serial.status, serial.subscriptionid, claimdate, claims_count, subscription.branchcode FROM serial LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid @@ -1852,7 +1858,9 @@ sub updateClaim { my ($serialid) = @_; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( - "UPDATE serial SET claimdate = now() + "UPDATE serial + SET claimdate = now(), + claims_count = claims_count + 1 WHERE serialid = ? " ); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 14f6122..0a969bd 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1699,6 +1699,7 @@ CREATE TABLE `serial` ( `publisheddate` date default NULL, `itemnumber` text default NULL, `claimdate` date default NULL, + claims_count int(11) default 0, `routingnotes` text, PRIMARY KEY (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 5b635cc..595c344 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4775,6 +4775,13 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.07.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE serial ADD COLUMN claims_count INT(11) DEFAULT 0"); + print "Upgrade to $DBversion done (Add claims_count field in serial table)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt index ceb1570..5b66937 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt @@ -164,6 +164,17 @@

Claims

+ [% IF error_claim %] + [% IF ( error_claim == "no_email" ) %] +
This vendor has no email
+ [% ELSE %] +
[% error_claim %]
+ [% END %] + [% END %] + [% IF info_claim %] +
Email has been sent.
+ [% END %] + [% IF ( letter ) %][% UNLESS ( missingissues ) %][% IF ( supplierid ) %]
No missing issues found.
[% ELSE %]
Please choose a vendor.
[% END %][% END %][% END %] [% IF ( SHOWCONFIRMATION ) %] @@ -263,41 +274,37 @@
-
- - - - [% IF ( letter ) %] - - [% END %] - - - - - - - - - + + +
VendorBranchTitleIssue numberStatusSinceClaim DateBegin Claim
+ + + [% IF ( letter ) %] + + [% END %] + + + + + + + + + + [% FOREACH missingissue IN missingissues %] [% IF ( letter ) %] [% END %] - - + + - + - - - + + + [% END %]
VendorBranchTitleIssue numberStatusSinceClaims countClaim date
- + - [% missingissue.name %] - - [% missingissue.branchcode %] - [% missingissue.name %][% missingissue.branchcode %] [% missingissue.title |html %] - [% missingissue.serialseq %] - [% missingissue.serialseq %] [% IF ( missingissue.status1 ) %]Expected[% END %] [% IF ( missingissue.status2 ) %]Arrived[% END %] @@ -305,28 +312,25 @@ [% IF ( missingissue.status4 ) %]Missing[% END %] [% IF ( missingissue.status7 ) %]Claimed[% END %] - [% missingissue.planneddate %] - - [% missingissue.claimdate %] - - Export item data - [% missingissue.planneddate %][% missingissue.claims_count %][% missingissue.claimdate %]
-

- -[% IF ( letter ) %] -
- -
+

+ + [% IF ( letter ) %] +
+ + + + +
[% END %]
diff --git a/serials/claims.pl b/serials/claims.pl index e51148c..de1c1ef 100755 --- a/serials/claims.pl +++ b/serials/claims.pl @@ -80,9 +80,18 @@ if($op && $op eq 'preview'){ } else { my @serialnums=$input->param('serialid'); if (@serialnums) { # i.e. they have been flagged to generate claims - SendAlerts('claimissues',\@serialnums,$input->param("letter_code")); - my $cntupdate=UpdateClaimdateIssues(\@serialnums); - ### $cntupdate SHOULD be equal to scalar(@$serialnums) + my $err; + eval { + SendAlerts('claimissues',\@serialnums,$input->param("letter_code")); + UpdateClaimdateIssues(\@serialnums); + }; + if ( $@ ) { + $template->param(error_claim => $@); + } elsif ( defined $err->{error} and $err->{error} eq "no_email" ) { + $template->{VARS}->{'error_claim'} = "no_email"; + } else { + $template->{VARS}->{'info_claim'} = 1; + } } } $template->param('letters'=>\@letters,'letter'=>$letter); -- 1.7.7.3