Bug 6614: Remove newlines from order notes when exporting to CSV
[koha_gimpoz] / C4 / Acquisition.pm
index 95a0ad5..738fe16 100644 (file)
@@ -233,7 +233,7 @@ sub GetBasketAsCSV {
     my $output; 
 
     # TODO: Translate headers
-    my @headers = qw(contractname ordernumber line entrydate isbn author title publishercode collectiontitle notes quantity rrp);
+    my @headers = qw(contractname ordernumber entrydate isbn author title publishercode collectiontitle notes quantity rrp);
 
     $csv->combine(@headers);                                                                                                        
     $output = $csv->string() . "\n";   
@@ -241,16 +241,17 @@ sub GetBasketAsCSV {
     my @rows;
     foreach my $order (@orders) {
        my @cols;
-       my $bd = GetBiblioData($order->{'biblionumber'});
+       # newlines are not valid characters for Text::CSV combine()
+        $order->{'notes'} =~ s/[\r\n]+//g;
        push(@cols,
                $contract->{'contractname'},
                $order->{'ordernumber'},
                $order->{'entrydate'}, 
                $order->{'isbn'},
-               $bd->{'author'},
-               $bd->{'title'},
-               $bd->{'publishercode'},
-               $bd->{'collectiontitle'},
+               $order->{'author'},
+               $order->{'title'},
+               $order->{'publishercode'},
+               $order->{'collectiontitle'},
                $order->{'notes'},
                $order->{'quantity'},
                $order->{'rrp'},
@@ -258,10 +259,6 @@ sub GetBasketAsCSV {
        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";    
@@ -568,7 +565,7 @@ sub ModBasketgroup {
     my $dbh = C4::Context->dbh;
     my $query = "UPDATE aqbasketgroups SET ";
     my @params;
-    foreach my $field (qw(name billingplace deliveryplace deliverycomment closed)) {
+    foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) {
         if ( defined $basketgroupinfo->{$field} ) {
             $query .= "$field=?, ";
             push(@params, $basketgroupinfo->{$field});
@@ -658,7 +655,7 @@ Returns a reference to the array of all the basketgroups of bookseller $booksell
 sub GetBasketgroups {
     my $booksellerid = shift;
     die "bookseller id is required to edit a basketgroup" unless $booksellerid;
-    my $query = "SELECT * FROM aqbasketgroups WHERE booksellerid=?";
+    my $query = "SELECT * FROM aqbasketgroups WHERE booksellerid=? ORDER BY `id` DESC";
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare($query);
     $sth->execute($booksellerid);
@@ -961,6 +958,10 @@ sub ModOrder {
 
     my $dbh = C4::Context->dbh;
     my @params;
+
+    # update uncertainprice to an integer, just in case (under FF, checked boxes have the value "ON" by default)
+    $orderinfo->{uncertainprice}=1 if $orderinfo->{uncertainprice};
+
 #    delete($orderinfo->{'branchcode'});
     # the hash contains a lot of entries not in aqorders, so get the columns ...
     my $sth = $dbh->prepare("SELECT * FROM aqorders LIMIT 1;");
@@ -1348,8 +1349,9 @@ sub GetParcels {
                 sum(quantity) AS itemsexpected,
                 sum(quantityreceived) AS itemsreceived
         FROM   aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno
-        WHERE aqbasket.booksellerid = $bookseller and datereceived IS NOT NULL
+        WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL
     ";
+    push @query_params, $bookseller;
 
     if ( defined $code ) {
         $strsth .= ' and aqorders.booksellerinvoicenumber like ? ';
@@ -1430,6 +1432,7 @@ sub GetLateOrders {
             OR datereceived IS NULL
             OR aqorders.quantityreceived < aqorders.quantity
         )
+        AND (aqorders.datecancellationprinted IS NULL OR aqorders.datecancellationprinted='0000-00-00')
     ";
     my $having = "";
     if ($dbdriver eq "mysql") {