MT2408 : UI Changes / CSV Export
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Tue, 22 Dec 2009 13:06:56 +0000 (14:06 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Thu, 28 Jan 2010 14:11:48 +0000 (15:11 +0100)
C4/Acquisition.pm
acqui/basket.pl
acqui/basketgroup.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tmpl

index 0ad03e9..f26e243 100644 (file)
@@ -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
index 492417a..9687b88 100755 (executable)
@@ -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) {
index 7e407b3..e8273a9 100755 (executable)
@@ -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;
index 5124441..561ce9a 100644 (file)
@@ -74,6 +74,7 @@
                                 new YAHOO.widget.Button("closebutton");
                             <!-- /TMPL_IF -->
                             new YAHOO.widget.Button("basketheadbutton");
+                            new YAHOO.widget.Button("exportbutton");
                             new YAHOO.widget.Button("delbasketbutton");
                         }
                         //]]>
@@ -87,6 +88,7 @@
                     <!-- TMPL_ELSE -->
                         <li><a href="<!-- TMPL_VAR name="script_name" -->?op=close&amp;basketno=<!-- TMPL_VAR name="basketno" -->&amp;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&amp;basketno=<!-- TMPL_VAR name="basketno" -->&amp;booksellerid=<!-- TMPL_VAR name="booksellerid" -->" class="button" id="exportbutton">Export this basket as CSV</a></li>
                     </ul>
                 </div>
             <!-- TMPL_ELSE -->
index baca750..e0245c3 100755 (executable)
@@ -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);
+    }
+}
+
 </script>
 </head>
 <body>
@@ -172,8 +184,8 @@ fieldset.various li {
                </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">
@@ -202,8 +214,8 @@ fieldset.various li {
 
                        </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" -->" />
@@ -257,8 +269,8 @@ fieldset.various li {
        <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">