Bug 21621: Remove incorrect GROUP BY from tools/letter.pl
[koha_ffzg] / tools / letter.pl
index d0c52c2..caaeb0e 100755 (executable)
 # TODO This script drives the CRUD operations on the letter table
 # The DB interaction should be handled by calls to C4/Letters.pm
 
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Context;
 use C4::Output;
 use C4::Letters;
-use C4::Members::Attributes;
+
+use Koha::Patron::Attribute::Types;
 
 # $protected_letters = protected_letters()
 # - return a hashref of letter_codes representing letters that should never be deleted
@@ -230,15 +230,7 @@ sub add_form {
         push @{$field_selection}, add_fields('aqbooksellers', 'aqbasket', 'aqorders', 'biblio', 'biblioitems');
     }
     elsif ($module eq 'claimissues') {
-        push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription');
-        push @{$field_selection},
-        {
-            value => q{},
-            text => '---BIBLIO---'
-        };
-        foreach(qw(title author serial)) {
-            push @{$field_selection}, {value => "biblio.$_", text => ucfirst $_ };
-        }
+        push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription', 'biblio', 'biblioitems');
     }
     elsif ($module eq 'serial') {
         push @{$field_selection}, add_fields('branches', 'biblio', 'biblioitems', 'borrowers', 'subscription', 'serial');
@@ -268,10 +260,14 @@ sub add_form {
         }
     }
 
+    my $preview_is_available = grep {/^$code$/} qw(
+        CHECKIN CHECKOUT HOLD_SLIP
+    );
     $template->param(
         module     => $module,
         SQLfieldnames => $field_selection,
         branchcode => $branchcode,
+        preview_is_available => $preview_is_available,
     );
     return;
 }
@@ -309,11 +305,11 @@ sub add_validate {
                 q{
                     UPDATE letter
                     SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ?, lang = ?
-                    WHERE branchcode = ? AND module = ? AND code = ? AND message_transport_type = ?
+                    WHERE branchcode = ? AND module = ? AND code = ? AND message_transport_type = ? AND lang = ?
                 },
                 undef,
                 $branchcode || '', $module, $name, $is_html || 0, $title, $content, $lang,
-                $branchcode, $oldmodule, $code, $mtt
+                $branchcode, $oldmodule, $code, $mtt, $lang
             );
         } else {
             $dbh->do(
@@ -381,7 +377,6 @@ sub retrieve_letters {
     }
 
     $sql .= " WHERE ".join(" AND ", @where) if @where;
-    $sql .= " GROUP BY branchcode,module,code";
     $sql .= " ORDER BY module, code, branchcode";
 
     return $dbh->selectall_arrayref($sql, { Slice => {} }, @args);
@@ -463,12 +458,14 @@ sub get_columns_for {
         }
     }
     if ($table eq 'borrowers') {
-        if ( my $attributes = C4::Members::Attributes::GetAttributes() ) {
-            foreach (@$attributes) {
-                push @fields, {
-                    value => "borrower-attribute:$_",
-                    text  => "attribute:$_",
-                }
+        my $attribute_types = Koha::Patron::Attribute::Types->search(
+            {},
+            { order_by => 'code' },
+        );
+        while ( my $at = $attribute_types->next ) {
+            push @fields, {
+                value => "borrower-attribute:" . $at->code,
+                text  => "attribute:" . $at->code,
             }
         }
     }