From 5f61beed724e55195a1cd6ed843585d6a73f4dee Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Tue, 22 Dec 2009 14:06:56 +0100 Subject: [PATCH] MT2408 : UI Changes / CSV Export --- C4/Acquisition.pm | 62 +++++++++++++++++++ acqui/basket.pl | 7 +++ acqui/basketgroup.pl | 7 ++- .../prog/en/modules/acqui/basket.tmpl | 2 + .../prog/en/modules/acqui/basketgroup.tmpl | 24 +++++-- 5 files changed, 94 insertions(+), 8 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 0ad03e9819..f26e243250 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -25,6 +25,7 @@ use C4::Debug; 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); @@ -40,6 +41,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket + &GetBasketAsCSV &GetBasketsByBookseller &GetBasketsByBasketgroup &ModBasketHeader @@ -222,6 +224,66 @@ sub CloseBasket { #------------------------------------------------------------# +=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 diff --git a/acqui/basket.pl b/acqui/basket.pl index 492417abb7..9687b88f83 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -135,6 +135,13 @@ if ( $op eq 'delete_confirm' ) { } 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) { diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 7e407b3aa2..e8273a92d2 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -437,8 +437,10 @@ if ( $op eq "add" ) { }; $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); @@ -447,5 +449,6 @@ if ( $op eq "add" ) { 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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl index 5124441710..561ce9a9de 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl @@ -74,6 +74,7 @@ new YAHOO.widget.Button("closebutton"); new YAHOO.widget.Button("basketheadbutton"); + new YAHOO.widget.Button("exportbutton"); new YAHOO.widget.Button("delbasketbutton"); } //]]> @@ -87,6 +88,7 @@
  • ?op=close&basketno=&booksellerid=" class="button" id="closebutton">Close this basket
  • +
  • ?op=export&basketno=&booksellerid=" class="button" id="exportbutton">Export this basket as CSV
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl index baca7505af..e0245c3a7c 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl @@ -114,6 +114,18 @@ fieldset.various li { 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); + } +} + @@ -172,8 +184,8 @@ fieldset.various li {
    -
    -
    +
    +
    " method="post" name="basketgroups" id="basketgroups">
    @@ -202,8 +214,8 @@ fieldset.various li {
    -
    - +
    +

    " /> @@ -257,8 +269,8 @@ fieldset.various li {
    -- 2.20.1