Bug 24865: Customize the Accountlines Description
authorKyle Hall <kyle@bywatersolutions.com>
Thu, 17 Feb 2022 14:23:28 +0000 (09:23 -0500)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 5 Jul 2022 14:37:35 +0000 (11:37 -0300)
It would be great if we could customize what information was added to the "Description of charges" field when a fine was made so data could be stored even when the item is deleted.

Test Plan:
1) Create an overdue checkout that will get a fine
2) Run fines.pl
3) Note the description for the fine
4) Delete the fine from the database
5) Apply this patch
6) Run updatedatabase.pl
7) Restart all the things!
8) Run fines.pl
9) Note the description of the fine is unchanged
10) Delete the fine again
11) Browse to Slips & Notices
12) Edit the new notice OVERDUE_FINE_DESC
    You will have access to the objects checkout, item, and borrower
13) Run fines.pl
14) Note your new description was used

Signed-off-by: Christopher Brannon <cbrannon@cdalibrary.org>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Overdues.pm
installer/data/mysql/atomicupdate/bug_24865.pl [new file with mode: 0755]
installer/data/mysql/en/mandatory/sample_notices.yml
tools/letter.pl

index a31d2b4..c277c6c 100644 (file)
@@ -27,13 +27,14 @@ use POSIX qw( ceil floor );
 use Locale::Currency::Format 1.28 qw( currency_format FMT_SYMBOL );
 use Carp qw( carp );
 
-use C4::Context;
 use C4::Accounts;
-use Koha::Logger;
+use C4::Context;
 use Koha::Account::Lines;
 use Koha::Account::Offsets;
 use Koha::Libraries;
 use Koha::Recalls;
+use Koha::Logger;
+use Koha::Patrons;
 
 our (@ISA, @EXPORT_OK);
 BEGIN {
@@ -597,12 +598,18 @@ sub UpdateFine {
         }
     } else {
         if ( $amount ) { # Don't add new fines with an amount of 0
-            my $sth4 = $dbh->prepare(
-                "SELECT title FROM biblio LEFT JOIN items ON biblio.biblionumber=items.biblionumber WHERE items.itemnumber=?"
-            );
-            $sth4->execute($itemnum);
-            my $title = $sth4->fetchrow;
-            my $desc = "$title $due";
+            my $patron = Koha::Patrons->find( $borrowernumber );
+            my $desc = C4::Letters::GetPreparedLetter(
+                module                 => 'circulation',
+                letter_code            => 'OVERDUE_FINE_DESC',
+                message_transport_type => 'print',
+                lang                   => $patron->lang,
+                tables                 => {
+                    issues    => $itemnum,
+                    borrowers => $borrowernumber,
+                    items     => $itemnum,
+                },
+            )->{content};
 
             my $account = Koha::Account->new({ patron_id => $borrowernumber });
             $accountline = $account->add_debit(
diff --git a/installer/data/mysql/atomicupdate/bug_24865.pl b/installer/data/mysql/atomicupdate/bug_24865.pl
new file mode 100755 (executable)
index 0000000..764a8ca
--- /dev/null
@@ -0,0 +1,15 @@
+use Modern::Perl;
+
+return {
+    bug_number => "24865",
+    description => "Customize the Accountlines Description",
+    up => sub {
+        my ($args) = @_;
+        my ($dbh, $out) = @$args{qw(dbh out)};
+        $dbh->do(q{
+            INSERT IGNORE INTO letter
+            (module,code,branchcode,name,is_html,title,content,message_transport_type,lang)
+            VALUES ('circulation','OVERDUE_FINE_DESC','','Overdue Item Fine Description',0,'Overdue Item Fine Description','[% item.biblio.title %] [% checkout.date_due | $KohaDates %]','print','default')
+        });
+    },
+};
index 4da53c2..34ffab8 100644 (file)
@@ -1566,6 +1566,17 @@ tables:
             - "[% END %]"
 
         - module: circulation
+          code: OVERDUE_FINE_DESC
+          branchcode: ""
+          name: "Overdue Item Fine Description"
+          is_html: 0
+          title: "Overdue Item Fine Description"
+          message_transport_type: print
+          lang: default
+          content:
+            - "[% item.biblio.title %] [% checkout.date_due | $KohaDates %]"
+
+        - module: circulation
           code: AUTO_RENEWALS_DGST
           branchcode: ""
           name: "Notification on auto renewals"
index 4276e46..9751b70 100755 (executable)
@@ -56,7 +56,10 @@ use Koha::Patron::Attribute::Types;
 sub protected_letters {
     my $dbh = C4::Context->dbh;
     my $codes = $dbh->selectall_arrayref(q{SELECT DISTINCT letter_code FROM message_transports});
-    return { map { $_->[0] => 1 } @{$codes} };
+    return {
+        OVERDUE_FINE_DESC => 1,
+        map { $_->[0] => 1 } @{$codes}
+    };
 }
 
 our $input       = CGI->new;