use C4::Dates qw(format_date format_date_in_iso);
use MARC::Record;
use C4::Suggestions;
+use C4::Biblio;
use C4::Debug;
use C4::SQLHelper qw(InsertInTable);
@ISA = qw(Exporter);
@EXPORT = qw(
&GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket
+ &GetBasketAsCSV
&GetBasketsByBookseller &GetBasketsByBasketgroup
&ModBasketHeader
#------------------------------------------------------------#
+=head3 GetBasketAsCSV
+
+=over 4
+
+&GetBasketAsCSV($basketno);
+
+Export a basket as CSV
+
+=back
+
+=cut
+sub GetBasketAsCSV {
+ my ($basketno) = @_;
+ my $basket = GetBasket($basketno);
+ my @orders = GetOrders($basketno);
+ my $contract = GetContract($basket->{'contractnumber'});
+ my $csv = Text::CSV->new();
+ my $output;
+
+ # TODO: Translate headers
+ my @headers = qw(contractname ordernumber line entrydate isbn author title publishercode collectiontitle notes quantity rrp);
+
+ $csv->combine(@headers);
+ $output = $csv->string() . "\n";
+
+ my @rows;
+ foreach my $order (@orders) {
+ my @cols;
+ my $bd = GetBiblioData($order->{'biblionumber'});
+ push(@cols,
+ $contract->{'contractname'},
+ $order->{'ordernumber'},
+ $order->{'entrydate'},
+ $order->{'isbn'},
+ $bd->{'author'},
+ $bd->{'title'},
+ $bd->{'publishercode'},
+ $bd->{'collectiontitle'},
+ $order->{'notes'},
+ $order->{'quantity'},
+ $order->{'rrp'},
+ );
+ push (@rows, \@cols);
+ }
+
+ # Sort by publishercode
+ # TODO: Sort by publishercode then by title
+ @rows = sort { @$a[7] cmp @$b[7] } @rows;
+
+ foreach my $row (@rows) {
+ $csv->combine(@$row);
+ $output .= $csv->string() . "\n";
+
+ }
+
+ return $output;
+
+}
+
+
=head3 CloseBasketgroup
=over 4
} elsif ($op eq 'attachbasket' && $template->{'param_map'}->{'CAN_user_acquisition_group_manage'} == 1) {
print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?basketno=' . $basket->{'basketno'} . '&op=attachbasket&booksellerid=' . $booksellerid);
# check if we have to "close" a basket before building page
+} elsif ($op eq 'export') {
+ print $query->header(
+ -type => 'text/csv',
+ -attachment => 'basket' . $basket->{'basketno'} . '.csv',
+ );
+ print GetBasketAsCSV($query->param('basketno'));
+ exit;
} elsif ($op eq 'close') {
my $confirm = $query->param('confirm');
if ($confirm) {
};
$basketgroupid = NewBasketgroup($basketgroup);
}
-
- print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid);
+
+ my $url = '/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid;
+ $url .= "&closed=1" if ($input->param("closed"));
+ print $input->redirect($url);
}else{
my $basketgroups = &GetBasketgroups($booksellerid);
displaybasketgroups($basketgroups, $bookseller, $baskets);
}
+$template->param(closed => $input->param("closed"));
#prolly won't use all these, maybe just use print, the rest can be done inside validate
output_html_with_http_headers $input, $cookie, $template->output;
new YAHOO.widget.Button("closebutton");
<!-- /TMPL_IF -->
new YAHOO.widget.Button("basketheadbutton");
+ new YAHOO.widget.Button("exportbutton");
new YAHOO.widget.Button("delbasketbutton");
}
//]]>
<!-- TMPL_ELSE -->
<li><a href="<!-- TMPL_VAR name="script_name" -->?op=close&basketno=<!-- TMPL_VAR name="basketno" -->&booksellerid=<!-- TMPL_VAR name="booksellerid" -->" class="button" id="closebutton">Close this basket</a></li>
<!-- /TMPL_IF -->
+ <li><a href="<!-- TMPL_VAR name="script_name" -->?op=export&basketno=<!-- TMPL_VAR name="basketno" -->&booksellerid=<!-- TMPL_VAR name="booksellerid" -->" class="button" id="exportbutton">Export this basket as CSV</a></li>
</ul>
</div>
<!-- TMPL_ELSE -->
YAHOO.util.Event.onDOMReady(DDApp.init, DDApp, true);
var tabView = new YAHOO.widget.TabView('bgtabs');
//]]>
+
+
+function submitForm(form) {
+ if (form.close.checked == true) {
+ var input = document.createElement("input");
+ input.setAttribute("type", "hidden");
+ input.setAttribute("name", "closed");
+ input.setAttribute("value", "1");
+ form.appendChild(input);
+ }
+}
+
</script>
</head>
<body>
</div>
<!-- TMPL_IF NAME="grouping" -->
<div id="bd">
- <div class="yui-gc">
- <div class="yui-u first">
+ <div class="yui-g">
+ <div class="yui-u grouping">
<form action="<!-- TMPL_VAR name="scriptname" -->" method="post" name="basketgroups" id="basketgroups">
<div id="groups">
</div>
- <div class="yui-u grouping">
- <form action="" method="post">
+ <div class="yui-u first">
+ <form action="" method="post" id="groupingform" onsubmit="return submitForm(this)">
<fieldset id="various" class='various' >
<h3><label for="basketgroupname">Basketgroup Name:</label></h3>
<input type="text" name="basketgroupname" id="basketgroupname" value="<!-- TMPL_VAR NAME="name" -->" />
<div class="yui-g">
<div id="bgtabs" class="yui-navset">
<ul class="yui-nav">
- <li class="selected"><a href="#opened"><em>Opened</em></a></li>
- <li><a href="#closed"><em>Closed</em></a></li>
+ <li<!-- TMPL_UNLESS NAME="closed" --> class="selected"<!-- /TMPL_UNLESS -->><a href="#opened"><em>Opened</em></a></li>
+ <li<!-- TMPL_IF NAME="closed" --> class="selected"<!-- /TMPL_IF -->><a href="#closed"><em>Closed</em></a></li>
</ul>
<div class="yui-content">
<div id="opened">