More work on patron card generation feature

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Chris Nighswonger 2008-03-26 06:01:35 -04:00 committed by Joshua Ferraro
parent 028f4f24fb
commit dd80cb4f2a
8 changed files with 70 additions and 44 deletions

View file

@ -312,11 +312,10 @@ sub get_highest_batch {
}
#FIXME: Needs to be ported to receive $batch_type
sub get_batches {
my ($batch_type) = @_;
my ( $batch_type ) = @_;
my $dbh = C4::Context->dbh;
my $q = "select batch_id, count(*) as num from $batch_type group by batch_id";
my $q = "SELECT batch_id, COUNT(*) AS num FROM $batch_type GROUP BY batch_id";
my $sth = $dbh->prepare($q);
$sth->execute();
my @resultsloop;
@ -841,39 +840,41 @@ sub GetPatronCardItems {
}
sub deduplicate_batch {
my $batch_id = shift or return undef;
my ( $batch_id, $batch_type ) = @_;
my $query = "
SELECT DISTINCT
batch_id,itemnumber,
count(labelid) as count
FROM labels
WHERE batch_id = ?
GROUP BY itemnumber,batch_id
HAVING count > 1
batch_id," . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . ",
count(". (($batch_type eq 'labels') ? 'labelid' : 'cardid') . ") as count
FROM $batch_type
WHERE batch_id = ?
GROUP BY " . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . ",batch_id
HAVING count > 1
ORDER BY batch_id,
count DESC ";
count DESC ";
my $sth = C4::Context->dbh->prepare($query);
$sth->execute($batch_id);
$sth->rows or return undef;
warn $sth->errstr if $sth->errstr;
$sth->rows or return undef, $sth->errstr;
my $del_query = qq(
my $del_query = "
DELETE
FROM labels
FROM $batch_type
WHERE batch_id = ?
AND itemnumber = ?
AND " . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . " = ?
ORDER BY timestamp ASC
);
";
my $killed = 0;
while (my $data = $sth->fetchrow_hashref()) {
my $itemnumber = $data->{itemnumber} or next;
my $itemnumber = $data->{(($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber')} or next;
my $limit = $data->{count} - 1 or next;
my $sth2 = C4::Context->dbh->prepare("$del_query LIMIT $limit");
# die sprintf "$del_query LIMIT %s\n (%s, %s)", $limit, $batch_id, $itemnumber;
# $sth2->execute($batch_id, C4::Context->dbh->quote($data->{itemnumber}), $data->{count} - 1)
$sth2->execute($batch_id, $itemnumber) and
$killed += ($data->{count} - 1);
warn $sth2->errstr if $sth2->errstr;
}
return $killed;
return $killed, undef;
}
sub DrawSpineText {

View file

@ -3,6 +3,6 @@
<table>
<tr><th>Layout:</th><td><!-- TMPL_IF NAME="active_layout_name" --><!-- TMPL_VAR NAME="active_layout_name" --><!-- TMPL_ELSE --><span class="error">No Layout Specified: <a href="/cgi-bin/koha/labels/label-home.pl">Select a Label Layout</a></span><!-- /TMPL_IF --> </td></tr>
<tr><th>Template: </th><td><!-- TMPL_IF NAME="active_template_name" --><!-- TMPL_VAR NAME="active_template_name" --><!-- TMPL_ELSE --><span class="error">No Template Specified: <a href="/cgi-bin/koha/labels/label-templates.pl">Select a Label Template</a></span><!-- /TMPL_IF --> </td></tr>
<tr><th>Batch: </th><td><!-- TMPL_IF NAME="batch_id" --><!-- TMPL_VAR NAME="batch_id" --><!-- TMPL_ELSE --><span class="error">No Batch Specified: <a href="/cgi-bin/koha/labels/label-manager.pl?op=add_batch">Select items to print</a></span><!-- /TMPL_IF --> </td></tr>
<tr><th>Batch: </th><td><!-- TMPL_IF NAME="batch_id" --><!-- TMPL_VAR NAME="batch_id" --><!-- TMPL_ELSE --><span class="error"><a href="/cgi-bin/koha/labels/label-manager.pl?op=add_batch&amp;type=<!-- TMPL_VAR NAME="type" -->">Create a new batch</a></span><!-- /TMPL_IF --> </td></tr>
</table>
</div>
</div>

View file

@ -2,6 +2,6 @@
<li><a href="/cgi-bin/koha/labels/label-home.pl">Layouts</a></li>
<li><a href="/cgi-bin/koha/labels/label-templates.pl">Templates</a></li>
<li><a href="/cgi-bin/koha/labels/label-profiles.pl">Printer Profiles</a></li>
<li><a href="/cgi-bin/koha/labels/label-manager.pl?type=labels">Create or Print Label Batches</a></li>
<li><a href="/cgi-bin/koha/labels/label-manager.pl?type=patroncards">Create or Print Patron Card Batches</a></li>
<li><a href="/cgi-bin/koha/labels/label-manager.pl?type=labels">Manage Label Batches</a></li>
<li><a href="/cgi-bin/koha/labels/label-manager.pl?type=patroncards">Manage Patron Card Batches</a></li>
</ul>

View file

@ -3,8 +3,8 @@
<script type="text/javascript">
//<![CDATA[
function Plugin(batch_id) {
window.open("label-item-search.pl?batch_id="+batch_id+"",'FindABibIndex','width=640,height=400,toolbar=no,scrollbars=yes');
function Plugin(batch_id, batch_type) {
window.open("label-item-search.pl?batch_id="+batch_id+"&amp;type="+batch_type+"",'FindABibIndex','width=640,height=400,toolbar=no,scrollbars=yes');
}
// prepare DOM for YUI Toolbar
@ -22,7 +22,7 @@
type: "button",
label: "Add item(s) to batch",
container: "additemsc",
onclick: {fn:function(){Plugin(<!-- TMPL_VAR NAME="batch_id" -->)}}
onclick: {fn:function(){Plugin(<!-- TMPL_VAR NAME="batch_id" -->,"<!-- TMPL_VAR NAME="type" -->")}}
});
new YAHOO.widget.Button("deletebatch");
new YAHOO.widget.Button("dedup");
@ -32,11 +32,11 @@
//]]>
</script>
<ul class="toolbar">
<li id="additemsc"><a id="additems" href="#" onclick="Plugin(<!-- TMPL_VAR NAME="batch_id" -->); return false;">Add item(s) to batch</a></li>
<li><a id="deletebatch" href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Delete current batch</a></li>
<li id="additemsc"><a id="additems" href="#" onclick="Plugin(<!-- TMPL_VAR NAME="batch_id" -->, "<!-- TMPL_VAR NAME="type" -->"); return false;">Add item(s) to batch</a></li>
<li><a id="deletebatch" href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->">Delete current batch</a></li>
<!-- FIXME: should use POST to change server state, not GET -->
<li><a id="dedup" href="/cgi-bin/koha/labels/label-manager.pl?op=deduplicate&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Remove duplicate barcodes</a></li>
<li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Generate PDF for Batch</a></li>
<li><a id="dedup" href="/cgi-bin/koha/labels/label-manager.pl?op=deduplicate&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->">Remove duplicate barcodes</a></li>
<li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->">Generate PDF for Batch</a></li>
</ul></div>
<!-- TMPL_ELSIF EXPR="(type eq 'patroncards')" -->
<div id="toolbar">
@ -74,9 +74,9 @@
</script>
<ul class="toolbar">
<li id="addpatronsc"><a id="addpatrons" href="#" onclick="Plugin(<!-- TMPL_VAR NAME="batch_id" -->,"<!-- TMPL_VAR NAME="type" -->"); return false;">Add item(s) to batch</a></li>
<li><a id="deletebatch" href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Delete current batch</a></li>
<li><a id="deletebatch" href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->">Delete current batch</a></li>
<!-- FIXME: should use POST to change server state, not GET -->
<li><a id="dedup" href="/cgi-bin/koha/labels/label-manager.pl?op=deduplicate&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Remove duplicate barcodes</a></li>
<li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Generate PDF for Batch</a></li>
<li><a id="dedup" href="/cgi-bin/koha/labels/label-manager.pl?op=deduplicate&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->">Remove duplicate patrons</a></li>
<li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->">Generate PDF for Batch</a></li>
</ul></div>
<!-- /TMPL_IF -->

View file

@ -20,6 +20,8 @@
<!-- TMPL_IF NAME="batch_id" -->
<!-- TMPL_INCLUDE NAME="tools-labels-batches-toolbar.inc" -->
<!-- TMPL_IF EXPR="(type eq 'labels')" -->
<div class="yui-g">
<div class="yui-u first">
<h2>Items to be Printed for Batch <!-- TMPL_VAR NAME="batch_id" --> (<!-- TMPL_VAR NAME="batch_count" --> items)</h2>
<table>
<tr>
@ -40,7 +42,10 @@
</tr>
<!-- /TMPL_LOOP -->
</table>
</div>
<!-- TMPL_ELSIF EXPR="(type eq 'patroncards')" -->
<div class="yui-g">
<div class="yui-u first">
<h2>Patron Cards to be Printed for Batch <!-- TMPL_VAR NAME="batch_id" --> (<!-- TMPL_VAR NAME="batch_count" --> items)</h2>
<table>
<tr>
@ -61,7 +66,12 @@
</tr>
<!-- /TMPL_LOOP -->
</table>
</div>
<!-- /TMPL_IF --><!-- /type -->
<div class="yui-u">
<!-- TMPL_INCLUDE NAME="label-status.inc" -->
</div>
</div>
<!-- TMPL_ELSE -->
<!-- TMPL_INCLUDE NAME="tools-labels-toolbar.inc" -->
<!-- TMPL_IF EXPR="(type eq 'labels')" -->
@ -95,7 +105,12 @@
<!-- TMPL_ELSE -->
<div class="yui-g">
<div class="yui-u first">
<h2>No Label Batches Currently Defined</h2>
<fieldset class="brief">
<legend>No Label Batches Currently Defined</legend>
<div class="hint">
Select "New Label Batch" to create a Label batch.
</div>
</fieldset>
</div>
<div class="yui-u">
<!-- TMPL_INCLUDE NAME="label-status.inc" -->
@ -133,7 +148,12 @@
<!-- TMPL_ELSE -->
<div class="yui-g">
<div class="yui-u first">
<h2>No Patron Card Batches Currently Defined</h2>
<fieldset class="brief">
<legend>No Patron Card Batches Currently Defined</legend>
<div class="hint">
Select "New Patron Card Batch" to create a Label batch.
</div>
</fieldset>
</div>
<div class="yui-u">
<!-- TMPL_INCLUDE NAME="label-status.inc" -->

View file

@ -13,7 +13,7 @@ $(document).ready(function(){
return false;
});
});
function add_item(itemnum,batch_id){
function add_item(itemnum,batch_id,type_id){
var getstr='';
if (itemnum == 'checked') {
itms= new Array;
@ -24,11 +24,13 @@ function add_item(itemnum,batch_id){
}
}
getstr = itms.join("&");
} else {
getstr = "itemnumber="+document.resultform.itemnumber.value;
}
} else {
getstr = "itemnumber="+itemnum;
}
var myurl = "label-manager.pl?op=add&batch_id="+batch_id+"&"+getstr;
var myurl = "label-manager.pl?op=add&batch_id="+batch_id+"&type="+type_id+"&"+getstr;
window.opener.location.href = myurl;
}
function add_item3(itemnumber){
@ -68,7 +70,7 @@ function add_item3(itemnumber){
</p>
</div>
<div id="breadcrumbs"><a href="/cgi-bin/koha/labels/label-item-search.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Search for Items for Batch <!-- TMPL_VAR NAME="batch_id" --></a> &rsaquo; Search results</div>
<form name="resultform" class="checkboxed"><div style="float: right; margin-top: .5em;"><input type="submit" class="icon addchecked" value="Add checked" onclick="add_item('checked',<!-- TMPL_VAR NAME="batch_id" -->); return false" /> <input type="button" class="close" value="Done" /></div><div style="line-height: 2em; margin-left: .7em;"><a id="CheckAll" href="/cgi-bin/koha/labels/label-item-search.pl">Select All</a></span><span class="clearall"><a id="CheckNone" href="/cgi-bin/koha/labels/label-item-search.pl">Clear All</a></div>
<form name="resultform" class="checkboxed"><div style="float: right; margin-top: .5em;"><input type="submit" class="icon addchecked" value="Add checked" onclick="add_item('checked',<!-- TMPL_VAR NAME="batch_id" -->,'<!-- TMPL_VAR NAME="type" -->'); return false" /> <input type="button" class="close" value="Done" /></div><div style="line-height: 2em; margin-left: .7em;"><a id="CheckAll" href="/cgi-bin/koha/labels/label-item-search.pl">Select All</a></span><span class="clearall"><a id="CheckNone" href="/cgi-bin/koha/labels/label-item-search.pl">Clear All</a></div>
<table style="float: left; margin: .5em 0;">
<!-- TMPL_LOOP name="result" -->
@ -95,7 +97,7 @@ function add_item3(itemnumber){
<!-- TMPL_IF name="barcode" --> <!-- TMPL_VAR name="barcode" --> <!-- /TMPL_IF -->
</td>
<td>
<a onclick="add_item('<!-- TMPL_VAR NAME="itemnumber" -->',<!-- TMPL_VAR NAME="batch_id" -->); return false" href="/cgi-bin/koha/barcodes/label-manager.pl?itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->&amp;batch_id=<!-- TMPL_VAR name="batch_id" -->&amp;op=add">Add</a>
<a onclick="add_item('<!-- TMPL_VAR NAME="itemnumber" -->',<!-- TMPL_VAR NAME="batch_id" -->, '<!-- TMPL_VAR NAME="type" -->'); return false" href="/cgi-bin/koha/barcodes/label-manager.pl?itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->&amp;batch_id=<!-- TMPL_VAR name="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->&amp;op=add">Add</a>
<!-- /NEW -->
</td>

View file

@ -197,6 +197,7 @@ if ( $show_results ) {
to => $to,
numbers => \@numbers,
batch_id => $batch_id,
type => $type,
);
}
@ -229,7 +230,8 @@ else {
}
$template->param(
itemtypeloop =>\@itemtypeloop,
batch_id => $batch_id,
batch_id => $batch_id,
type => $type,
);
}

View file

@ -40,8 +40,8 @@ my $startlabel = $query->param('startlabel');
my $printingtype = $query->param('printingtype');
my $guidebox = $query->param('guidebox');
my $fontsize = $query->param('fontsize');
my @itemnumber = $query->param('itemnumber') if ($query->param('type') eq 'labels');
my @itemnumber = $query->param('borrowernumber') if ($query->param('type') eq 'patroncards');
my @itemnumber;
($query->param('type') eq 'labels') ? (@itemnumber = $query->param('itemnumber')) : (@itemnumber = $query->param('borrowernumber'));
my $batch_type = $query->param('type');
# little block for displaying active layout/template/batch in templates
@ -137,7 +137,7 @@ elsif ( $op eq 'delete' ) {
}
elsif ( $op eq 'delete_batch' ) {
delete_batch($batch_id, $batch_type);
print $query->redirect("label-manager.pl");
print $query->redirect("label-manager.pl?type=$batch_type");
exit;
}
elsif ( $op eq 'add_batch' ) {
@ -149,8 +149,9 @@ elsif ( $op eq 'set_active_layout' ) {
exit;
}
elsif ( $op eq 'deduplicate' ) {
my $return = deduplicate_batch($batch_id);
my $msg = (($return) ? "Removed $return" : "Error revoving") . " duplicate items from Batch $batch_id";
warn "\$batch_id=$batch_id and \$batch_type=$batch_type";
my ($return, $dberror) = deduplicate_batch($batch_id, $batch_type);
my $msg = (($return) ? "Removed $return" : "Error removing") . " duplicate items from Batch $batch_id." . (($dberror) ? " Database returned: $dberror" : "");
push @messages, $msg;
}