Message => Encode::encode( "utf8", "" . $letter->{content} ),
'Content-Type' => 'text/plain; charset="utf8"',
);
+
$mail{'Reply-to'} = C4::Context->preference('ReplytoDefault')
if C4::Context->preference('ReplytoDefault');
$mail{'Sender'} = C4::Context->preference('ReturnpathDefault')
if C4::Context->preference('ReturnpathDefault');
- sendmail(%mail) or carp $Mail::Sendmail::error;
+ unless ( sendmail(%mail) ) {
+ carp $Mail::Sendmail::error;
+ return { error => $Mail::Sendmail::error };
+ }
logaction(
"ACQUISITION",
sub GetSuppliersWithLateIssues {
my $dbh = C4::Context->dbh;
my $query = qq|
- SELECT DISTINCT id, name
+ 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 IN (3, 4, 41, 42, 43, 44)
+ OR serial.STATUS IN (3, 4, 41, 42, 43, 44, 7)
)
AND subscription.closed = 0
ORDER BY name|;
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;
"SELECT
serialid, aqbooksellerid, name,
biblio.title, biblioitems.issn, 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
+ FROM serial
+ LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber
LEFT JOIN biblioitems ON subscription.biblionumber=biblioitems.biblionumber
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
- WHERE subscription.subscriptionid = serial.subscriptionid
+ WHERE subscription.subscriptionid = serial.subscriptionid
AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
AND subscription.aqbooksellerid=$supplierid
$byserial
);
} else {
$sth = $dbh->prepare(
- "SELECT
+ "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
+ FROM serial
+ LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid
LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
- WHERE subscription.subscriptionid = serial.subscriptionid
+ WHERE subscription.subscriptionid = serial.subscriptionid
AND (serial.STATUS IN (4, 41, 42, 43, 44) OR ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3 OR serial.STATUS = 7))
$byserial
ORDER BY $order"
sub updateClaim {
my ($serialid) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare(
- "UPDATE serial SET claimdate = now()
- WHERE serialid = ?
- "
- );
- $sth->execute($serialid);
+ $dbh->do(q|
+ UPDATE serial
+ SET claimdate = NOW(),
+ claims_count = claims_count + 1
+ WHERE serialid = ?
+ |, {}, $serialid );
return;
}
`notes` text,
`publisheddate` date default NULL,
`claimdate` date default NULL,
+ claims_count int(11) default 0,
`routingnotes` text,
PRIMARY KEY (`serialid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SetVersion($DBversion);
}
+$DBversion = "3.17.00.XXX";
+if ( CheckVersion($DBversion) ) {
+ $dbh->do(q|
+ ALTER TABLE serial ADD COLUMN claims_count INT(11) DEFAULT 0 after claimdate
+ |);
+ $dbh->do(q|
+ UPDATE serial
+ SET claims_count = 1
+ WHERE claimdate IS NOT NULL
+ |);
+ print "Upgrade to $DBversion done (Bug 5342: Add claims_count field in serial table)\n";
+ SetVersion($DBversion);
+}
+
=head1 FUNCTIONS
=head2 TableExists($table)
var sTable = $("#claimst").dataTable($.extend(true, {}, dataTablesDefaults, {
"sDom": 't',
"aoColumnDefs": [
- [% IF ( letter ) %]
- { "aTargets": [ 0,1 ], "bSortable": false, "bSearchable": false },
- [% ELSE %]
- { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
- [% END %]
+ { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
{ 'sType': "anti-the", 'aTargets' : [ 'anti-the'] },
{ 'sType': "title-string", 'aTargets' : [ 'title-string'] }
],
$("#claimst tr:visible :checkbox").attr('checked', $("#CheckAll").is(':checked'));
});
- // Generates a dynamic link for exporting the selection's data as CSV
+ // Generates a dynamic link for exporting the selections data as CSV
$("#ExportSelected").click(function() {
// We need to use "input[name=serialid]:checked" instead of "input:checked". Otherwise, the "check all" box will pass the value of "on" as a serialid, which produces a SQL error.
var selected = $("input[name=serialid]:checked");
<h1>Claims</h1>
+ [% IF error_claim %]
+ [% IF error_claim == 'no_vendor_email' %]
+ <div class="error">This vendor has no email defined for late issues.</div>
+ [% ELSIF error_claim == 'no_loggedin_user_email' %]
+ <div class="error">No email is configured for your user.</div>
+ [% ELSE %]
+ <div class="error">[% error_claim %]</div>
+ [% END %]
+ [% END %]
+ [% IF info_claim %]
+ <div class="dialog message">Email has been sent.</div>
+ [% END %]
+
[% IF letters %][% UNLESS ( missingissues ) %][% IF ( supplierid ) %] <div class="dialog alert">No missing issues found.</div>[% ELSE %]<div class="dialog message">Please choose a vendor.</div>[% END %][% END %][% END %]
[% IF ( SHOWCONFIRMATION ) %]
</form>
<fieldset>
- <form action="claims.pl" method="post" class="checkboxed" onsubmit="return checkForm()">
- <input type="hidden" name="order" value="[% order %]" />
- <table id="claimst">
- <thead><tr>
- <th><input type="checkbox" id="CheckAll"></th>
- <th>Vendor</th>
- <th>Library</th>
- <th class="anti-the">Title</th>
- <th>ISSN</th>
- <th>Issue number</th>
- <th>Status</th>
- <th class="title-string">Since</th>
- <th class="title-string">Claim date</th>
- </tr></thead>
+ <form action="claims.pl" method="post" class="checkboxed" onsubmit="return checkForm()">
+ <table id="claimst">
+ <thead>
+ <tr>
+ <th><input type="checkbox" id="CheckAll"></th>
+ <th>Vendor</th>
+ <th>Library</th>
+ <th class="anti-the">Title</th>
+ <th>Issue number</th>
+ <th>Status</th>
+ <th class="title-string">Since</th>
+ <th>Claims count</th>
+ <th class="title-string">Claim date</th>
+ </tr>
+ </thead>
<tbody>[% FOREACH missingissue IN missingissues %]
<tr>
<td>
<input type="checkbox" name="serialid" value="[% missingissue.serialid %]" />
</td>
- <td>
- [% missingissue.name %]
- </td>
+ <td>[% missingissue.name %]</td>
<td>
<span class="branch-[% missingissue.branchcode %]">[% Branches.GetName( missingissue.branchcode ) %]</span>
</td>
<td>
<a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% missingissue.subscriptionid %]">[% missingissue.title |html %]</a>
</td>
- <td>
- [% missingissue.issn %]
- </td>
- <td>
- [% missingissue.serialseq %]
- </td>
+ <td>[% missingissue.serialseq %]</td>
<td>
[% IF ( missingissue.status1 ) %]<span class="status-expected">Expected</span>[% END %]
[% IF ( missingissue.status3 ) %]<span class="status-late">Late</span>[% END %]
<span title="0000-00-00"></span>
[% END %]
</td>
+ <td>[% missingissue.claims_count %]</td>
<td>
[% IF ( missingissue.claimdate ) %]
<span title="[% missingissue.claimdateISO %]">[% missingissue.claimdate %]</span>
[% END %]</tbody>
</table>
- [% IF csv_profiles %]
- <fieldset class="action">
- <label for="csv_code">Select CSV profile:</label>
- <select id="csv_profile_for_export">
- [% FOR csv IN csv_profiles %]
- <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
- [% END %]
- </select>
- <span class="exportSelected"><a id="ExportSelected" href="/cgi-bin/koha/serials/claims.pl">Download selected claims</a></span>
- [% END %]
+ [% IF csv_profiles %]
+ <fieldset class="action">
+ <label for="csv_code">Select CSV profile:</label>
+ <select id="csv_profile_for_export">
+ [% FOR csv IN csv_profiles %]
+ <option value="[% csv.export_format_id %]">[% csv.profile %]</option>
+ [% END %]
+ </select>
+ <span class="exportSelected"><a id="ExportSelected" href="/cgi-bin/koha/serials/claims.pl">Download selected claims</a></span>
+ [% END %]
-[% IF ( letters ) %]
- <fieldset class="action"> <label for="letter_code">Select notice:</label>
- <select name="letter_code" id="letter_code">
- [% FOREACH letter IN letters %]
- <option value="[% letter.code %]">[% letter.name %]</option>
- [% END %]
- </select>
- <input type="hidden" name="op" value="send_alert" /><input type="submit" name="submit" class="button" value="Send notification" /></fieldset>
+ [% IF letters %]
+ <fieldset class="action">
+ <label for="letter_code">Select notice:</label>
+ <select name="letter_code" id="letter_code">
+ [% FOREACH letter IN letters %]
+ <option value="[% letter.code %]">[% letter.name %]</option>
+ [% END %]
+ </select>
+ <input type="hidden" name="op" value="send_alert" />
+ <input type="hidden" name="supplierid" value="[% supplierid %]" />
+ <input type="submit" name="submit" class="button" value="Send notification" />
+ </fieldset>
[% END %]
</form>
</fieldset>
my $claimletter = $input->param('claimletter');
my $supplierid = $input->param('supplierid');
my $suppliername = $input->param('suppliername');
-my $order = $input->param('order');
# open template first (security & userenv set here)
my ($template, $loggedinuser, $cookie)
# supplierlist is returned in name order
my $supplierlist = GetSuppliersWithLateIssues();
for my $s (@{$supplierlist} ) {
- $s->{count} = scalar GetLateOrMissingIssues($s->{id}, q{}, $order);
+ $s->{count} = scalar GetLateOrMissingIssues($s->{id});
if ($supplierid && $s->{id} == $supplierid) {
$s->{selected} = 1;
}
}
-my $letters = GetLetters({ module => 'claimissues' });
-
-my @missingissues;
-my @supplierinfo;
-if ($supplierid) {
- @missingissues = GetLateOrMissingIssues($supplierid,$serialid,$order);
- @supplierinfo=GetBookSeller($supplierid);
-}
-
my $branchloop = GetBranchesLoop();
my $preview=0;
} 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 {
+ $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
+ if ( not ref $err or not exists $err->{error} ) {
+ UpdateClaimdateIssues(\@serialnums);
+ }
+ };
+ if ( $@ ) {
+ $template->param(error_claim => $@);
+ } elsif ( ref $err and exists $err->{error} ) {
+ if ( $err->{error} eq "no_email" ) {
+ $template->param( error_claim => 'no_vendor_email' );
+ } elsif ( $err->{error} =~ m|Bad or missing From address| ) {
+ $template->param( error_claim => 'no_loggedin_user_email' );
+ }
+ } else {
+ $template->param( info_claim => 1 );
+ }
}
}
+my $letters = GetLetters({ module => 'claimissues' });
+
+my @missingissues;
+my @supplierinfo;
+if ($supplierid) {
+ @missingissues = GetLateOrMissingIssues($supplierid);
+ @supplierinfo=GetBookSeller($supplierid);
+}
+
$template->param(
- order =>$order,
suploop => $supplierlist,
phone => $supplierinfo[0]->{phone},
booksellerfax => $supplierinfo[0]->{booksellerfax},
use Modern::Perl;
-use Test::More tests => 13;
+use Test::More tests => 12;
use Data::Dumper;
use_ok('C4::Acquisition');
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
-my $supplierlist=eval{GetSuppliersWithLateIssues()};
-ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
-
my $booksellerid = C4::Bookseller::AddBookseller(
{
name => "my vendor",
--- /dev/null
+use Modern::Perl;
+use Test::More tests => 13;
+
+use C4::Acquisition;
+use C4::Budgets;
+use_ok('C4::Serials');
+
+use Koha::DateUtils qw( dt_from_string output_pref );
+
+my $dbh = C4::Context->dbh;
+$dbh->{AutoCommit} = 0;
+$dbh->{RaiseError} = 1;
+
+my $branchcode = 'CPL';
+my $bpid = AddBudgetPeriod({
+ budget_period_startdate => '2015-01-01',
+ budget_period_enddate => '2015-12-31',
+ budget_period_description => "budget desc"
+});
+
+my $budget_id = AddBudget({
+ budget_code => "ABCD",
+ budget_amount => "123.132",
+ budget_name => "Périodiques",
+ budget_notes => "This is a note",
+ budget_period_id => $bpid
+});
+
+my $record = MARC::Record->new();
+my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
+
+my $sample_supplier1 = {
+ name => 'Name1',
+ address1 => 'address1_1',
+ address2 => 'address1-2',
+ address3 => 'address1_2',
+ address4 => 'address1_2',
+ postal => 'postal1',
+ phone => 'phone1',
+ accountnumber => 'accountnumber1',
+ fax => 'fax1',
+ url => 'url1',
+ active => 1,
+ gstreg => 1,
+ listincgst => 1,
+ invoiceincgst => 1,
+ gstrate => '1.0000',
+ discount => '1.0000',
+ notes => 'notes1',
+ deliverytime => undef
+};
+my $sample_supplier2 = {
+ name => 'Name2',
+ address1 => 'address1_2',
+ address2 => 'address2-2',
+ address3 => 'address3_2',
+ address4 => 'address4_2',
+ postal => 'postal2',
+ phone => 'phone2',
+ accountnumber => 'accountnumber2',
+ fax => 'fax2',
+ url => 'url2',
+ active => 1,
+ gstreg => 1,
+ listincgst => 1,
+ invoiceincgst => 1,
+ gstrate => '2.0000',
+ discount => '2.0000',
+ notes => 'notes2',
+ deliverytime => 2
+};
+
+my $supplier_id1 = C4::Bookseller::AddBookseller($sample_supplier1);
+my $supplier_id2 = C4::Bookseller::AddBookseller($sample_supplier2);
+
+my $supplierlist = eval { GetSuppliersWithLateIssues() };
+is( length($@), 0, "No SQL problem in GetSuppliersWithLateIssues" );
+is ( scalar(@$supplierlist), 0, 'There is no late issues yet');
+
+my $subscriptionid_not_late = NewSubscription(
+ undef, $branchcode, $supplier_id1, undef, $budget_id, $biblionumber,
+ '2013-01-01', undef, undef, undef, undef,
+ undef, undef, undef, undef, undef, undef,
+ 1, "notes",undef, '9999-01-01', undef, undef,
+ undef, undef, 0, "intnotes", 0,
+ undef, undef, 0, undef, '2013-12-31', 0
+);
+$supplierlist = GetSuppliersWithLateIssues();
+is ( scalar(@$supplierlist), 0, 'There is still no late issues yet');
+
+my $subscriptionid_inlate1 = NewSubscription(
+ undef, $branchcode, $supplier_id1, undef, $budget_id, $biblionumber,
+ '2013-01-01', undef, undef, undef, undef,
+ undef, undef, undef, undef, undef, undef,
+ 1, "notes",undef, '2013-01-01', undef, undef,
+ undef, undef, 0, "intnotes", 0,
+ undef, undef, 0, undef, '2013-12-31', 0
+);
+
+my $subscriptionid_inlate2 = NewSubscription(
+ undef, $branchcode, $supplier_id2, undef, $budget_id, $biblionumber,
+ '2013-01-01', undef, undef, undef, undef,
+ undef, undef, undef, undef, undef, undef,
+ 1, "notes",undef, '2013-01-01', undef, undef,
+ undef, undef, 0, "intnotes", 0,
+ undef, undef, 0, undef, '2013-12-31', 0
+);
+
+my $subscriptionid_inlate3 = NewSubscription(
+ undef, $branchcode, $supplier_id2, undef, $budget_id, $biblionumber,
+ '2013-01-02', undef, undef, undef, undef,
+ undef, undef, undef, undef, undef, undef,
+ 1, "notes",undef, '2013-01-02', undef, undef,
+ undef, undef, 0, "intnotes", 0,
+ undef, undef, 0, undef, '2013-12-31', 0
+);
+
+
+$supplierlist = GetSuppliersWithLateIssues();
+is ( scalar(@$supplierlist), 2, '2 suppliers should have issues in late');
+
+is( GetLateOrMissingIssues(), undef, 'GetLateOrMissingIssues should return undef without parameter' );
+
+my @late_or_missing_issues = GetLateOrMissingIssues( $supplier_id1 );
+is( scalar(@late_or_missing_issues), 1, 'supplier 1 should have 1 issue in late' );
+
+@late_or_missing_issues = GetLateOrMissingIssues( $supplier_id2);
+is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late' );
+
+is( exists $late_or_missing_issues[0]->{claimdate}, 1, 'GetLateOrMissingIssues returns claimdate' );
+is( exists $late_or_missing_issues[0]->{claims_count}, 1, 'GetLateOrMissingIssues returns claims_count' );
+is( $late_or_missing_issues[0]->{claims_count}, 0, 'The issues should not habe been claimed yet' );
+
+my $serialid_to_claim = $late_or_missing_issues[0]->{serialid};
+updateClaim( $serialid_to_claim );
+
+@late_or_missing_issues = GetLateOrMissingIssues( $supplier_id2);
+is( scalar(@late_or_missing_issues), 2, 'supplier 2 should have 2 issues in late (already claimed issues are returns)' );
+
+my ( $serial_claimed ) = grep { ($_->{serialid} == $serialid_to_claim) ? $_ : () } @late_or_missing_issues;
+is( $serial_claimed->{claims_count}, 1, 'The serial should have been claimed' );
+
+my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
+# FIXME: This test should pass. The GetLateOrMissingIssues should not deal with date format!
+#is( $serial_claimed->{claimdate}, $today, 'The serial should have been claimed today' );
#!/usr/bin/perl
use Modern::Perl;
-use Test::More tests => 37;
+use Test::More tests => 36;
use MARC::Record;
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
-
-my $supplierlist=eval{GetSuppliersWithLateIssues()};
-ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
-
my $record = MARC::Record->new();
$record->append_fields(
MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )