From fb88aba99733cc9e4c4ad0b6e1ff42bb14f15258 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Jan 2013 11:06:29 +0100 Subject: [PATCH] Bug 8007: Discharge management At the intranet, it is now possible to generate a discharge for a patron. At the opac, a patron can request a discharge and download discharges already generated. Requirements: aptitude install python-pisa New sysprefs: - useDischarge: Allows librarians to discharge borrowers and borrowers to request a discharge - dischargePath: Sets the upload path for the generated discharges - dischargeWebPath: Sets the upload path starting from documentroot for the generated discharges New letter with a letter_code DISCHARGE. Test plan: - Switch on the syspref useDischarge. - Fill the syspref dischargePath (e.g. /home/koha/src/koha-tmpl/discharges) - Fill the syspref dischargeWebPath (e.g. /discharges) - For a security reason create a .htaccess in your dischargePath with the following content: Options -Indexes and change the rights: sudo chown www-data:www-data /home/koha/src/koha-tmpl/discharges - Check that a new tab appears in the patron page (intranet and opac) - Check that the discharge cannot be generated if the patron has issues. - Check that the patron can request a discharge from it's opac area. - The request is a mail sent via the sendmail command - Generate the discharge from the intranet - Try to download it (from the opac and the intranet) Sponsored-by: SCD Limoges --- C4/Auth.pm | 2 + C4/Discharges.pm | 100 +++++++++++ C4/Letters.pm | 20 ++- C4/Members.pm | 10 +- .../data/mysql/de-DE/mandatory/sample_notices.sql | 3 +- .../data/mysql/en/mandatory/sample_notices.sql | 3 +- .../data/mysql/es-ES/mandatory/sample_notices.sql | 3 +- .../mysql/fr-FR/1-Obligatoire/sample_notices.sql | 3 +- installer/data/mysql/it-IT/necessari/notices.sql | 3 +- .../mysql/nb-NO/1-Obligatorisk/sample_notices.sql | 3 +- .../data/mysql/pl-PL/mandatory/sample_notices.sql | 3 +- .../data/mysql/ru-RU/mandatory/sample_notices.sql | 3 +- installer/data/mysql/sysprefs.sql | 3 + .../data/mysql/uk-UA/mandatory/sample_notices.sql | 3 +- installer/data/mysql/updatedatabase.pl | 12 ++ .../intranet-tmpl/prog/en/includes/circ-menu.inc | 3 + .../intranet-tmpl/prog/en/includes/circ-menu.tt | 4 + .../prog/en/includes/members-menu.inc | 3 + .../prog/en/modules/admin/preferences/patrons.pref | 14 ++ .../prog/en/modules/members/discharge.tt | 53 ++++++ koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc | 3 + .../opac-tmpl/prog/en/modules/opac-discharge.tt | 54 ++++++ members/discharge.pl | 173 ++++++++++++++++++++ misc/cronjobs/gather_print_notices.pl | 22 ++- opac/opac-discharge.pl | 81 +++++++++ 25 files changed, 556 insertions(+), 28 deletions(-) create mode 100644 C4/Discharges.pm create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-discharge.tt create mode 100755 members/discharge.pl create mode 100755 opac/opac-discharge.pl diff --git a/C4/Auth.pm b/C4/Auth.pm index ca061b5..f5a7adc 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -368,6 +368,7 @@ sub get_template_and_user { AllowMultipleCovers => C4::Context->preference('AllowMultipleCovers'), EnableBorrowerFiles => C4::Context->preference('EnableBorrowerFiles'), UseKohaPlugins => C4::Context->preference('UseKohaPlugins'), + useDischarge => C4::Context->preference('useDischarge'), ); } else { @@ -471,6 +472,7 @@ sub get_template_and_user { OPACLocalCoverImages => C4::Context->preference("OPACLocalCoverImages"), PatronSelfRegistration => C4::Context->preference("PatronSelfRegistration"), PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"), + useDischarge => C4::Context->preference('useDischarge'), ); $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic")); diff --git a/C4/Discharges.pm b/C4/Discharges.pm new file mode 100644 index 0000000..8656c06 --- /dev/null +++ b/C4/Discharges.pm @@ -0,0 +1,100 @@ +package C4::Discharges; + +# Copyright 2013 BibLibre +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 NAME + +C4::Discharges - functions for discharges + +=head1 DESCRIPTION + +This modules allows to retrieve informations about generated discharges + +=cut + +use Modern::Perl; +use File::Basename; + +our $debug; +use vars qw(@ISA @EXPORT); +BEGIN { + $debug = $ENV{DEBUG} || 0; + require Exporter; + @ISA = qw( Exporter ); + + push @EXPORT, qw( + &GetDischarges + &removeUnprocessedDischarges + ); + + +} + + +=head1 METHODS + +=head2 GetDischarges($borrowernumber) + + my @list = GetDischarges($borrowernumber); + + returns the discharges list for a given borrower. + +=cut + +sub GetDischarges { + my $borrowernumber = shift; + return unless $borrowernumber; + + my $dischargePath = C4::Context->preference('dischargePath'); + my $dischargeWebPath = C4::Context->preference('dischargeWebPath'); + my @return; + + my $pdf_path = qq{$dischargePath/$borrowernumber/*.pdf}; + my @files = <$pdf_path>; + foreach (@files) { + my ($file, $dir, $ext) = fileparse("$_"); + push @return, $file; + } + + return @return; +} + +=head2 removeUnprocessedDischarges($borrowernumber) + + removeUnprocessedDischarges($borrowernumber); + + Removes all discharges with a pending status, because if the process had been complete, the status would be 'sent' + +=cut + +sub removeUnprocessedDischarges { + my $borrowernumber = shift; + return unless $borrowernumber; + + my $dbh = C4::Context->dbh; + my $query = q{ + DELETE FROM message_queue + WHERE borrowernumber=? + AND letter_code='DISCHARGE' + AND status='pending' + }; + my $sth = $dbh->prepare($query); + return $sth->execute($borrowernumber); +} + +1; diff --git a/C4/Letters.pm b/C4/Letters.pm index fdbb473..7e78059 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -768,7 +768,7 @@ sub GetRSSMessages { =head2 GetPrintMessages - my $message_list = GetPrintMessages( { borrowernumber => $borrowernumber } ) + my $message_list = GetPrintMessages( { borrowernumber => $borrowernumber [, letter_code => $letter_code] } ) Returns a arrayref of all queued print messages (optionally, for a particular person). @@ -777,10 +777,14 @@ person). sub GetPrintMessages { my $params = shift || {}; - - return _get_unsent_messages( { message_transport_type => 'print', - borrowernumber => $params->{'borrowernumber'}, - } ); + + return _get_unsent_messages( + { + message_transport_type => 'print', + borrowernumber => $params->{borrowernumber}, + letter_code => $params->{letter_code}, + } + ); } =head2 GetQueuedMessages ([$hashref]) @@ -888,9 +892,13 @@ ENDSQL push @query_params, $params->{'message_transport_type'}; } if ( $params->{'borrowernumber'} ) { - $statement .= ' AND borrowernumber = ? '; + $statement .= ' AND b.borrowernumber = ? '; push @query_params, $params->{'borrowernumber'}; } + if ( $params->{letter_code} ) { + $statement .= ' AND letter_code = ? '; + push @query_params, $params->{letter_code}; + } if ( $params->{'limit'} ) { $statement .= ' limit ? '; push @query_params, $params->{'limit'}; diff --git a/C4/Members.pm b/C4/Members.pm index 6a30c44..5b6496b 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -2216,7 +2216,7 @@ sub GetBorrowersNamesAndLatestIssue { =head2 DebarMember -my $success = DebarMember( $borrowernumber, $todate ); +my $success = DebarMember( $borrowernumber, $todate, $comment ); marks a Member as debarred, and therefore unable to checkout any more items. @@ -2227,15 +2227,15 @@ true on success, false on failure =cut sub DebarMember { - my $borrowernumber = shift; - my $todate = shift; + my ( $borrowernumber, $todate, $comment ) = @_; return unless defined $borrowernumber; return unless $borrowernumber =~ /^\d+$/; return ModMember( - borrowernumber => $borrowernumber, - debarred => $todate + borrowernumber => $borrowernumber, + debarred => $todate, + debarredcomment => $comment, ); } diff --git a/installer/data/mysql/de-DE/mandatory/sample_notices.sql b/installer/data/mysql/de-DE/mandatory/sample_notices.sql index df927a6..31986df 100644 --- a/installer/data/mysql/de-DE/mandatory/sample_notices.sql +++ b/installer/data/mysql/de-DE/mandatory/sample_notices.sql @@ -15,7 +15,8 @@ VALUES ('circulation','ODUE','Mahnung','Mahnung','Liebe/r < ('suggestions','ACCEPTED','Anschaffungsvorschlag wurde angenommen', 'Ihr Anschaffungsvorschlag wurde angenommen','Liebe(r) <> <>,\n\nSie haben der Bibliothek folgendes Medium zur Anschaffung vorgeschlagen: <> by <>.\n\nDie Bibliothek hat diesen Titel heute recherchiert und wird Ihn sobald wie möglich im Buchhandel bestellen. Sie erhalten Nachricht, sobald die Bestellung abgeschlossen ist und sobald der Titel in der Bibliotek verfügbar ist.\n\nWenn Sie Fragen haben, richten Sie Ihre Mail bitte an: <>.\n\nVielen Dank,\n\n<>'), ('suggestions','AVAILABLE','Vorgeschlagenes Medium verfügbar', 'Das vorgeschlagene Medium ist jetzt verfügbar','Liebe(r) <> <>,\n\nSie haben der Bibliothek folgendes Medium zur Anschaffung vorgeschlagen: <> von <>.\n\nWir freuen uns Ihnen mitteilen zu können, dass dieser Titel jetzt im Bestand der Bibliothek verfügbar ist.\n\nWenn Sie Fragen haben, richten Sie Ihre Mail bitte an: <>.\n\nVielen Dank,\n\n<>'), ('suggestions','ORDERED','Vorgeschlagenes Medium bestellt', 'Das vorgeschlagene Medium wurde im Buchhandel bestellt','Liebe(r) <> <>,\n\nSie haben der Bibliothek folgendes Medium zur Anschaffung vorgeschlaten: <> von <>.\n\nWir freuen uns Ihnen mitteilen zu können, dass dieser Titel jetzt im Buchhandel bestellt wurde. Nach Eintreffen wird er in unseren Bestand eingearbeitet.\n\nSie erhalten Nachricht, sobald das Medium verfügbar ist.\n\nBei Nachfragen erreichen Sie uns unter der Emailadresse <>.\n\nVielen Dank,\n\n<>'), -('suggestions','REJECTED','Anschaffungsvorschlag nicht angenommen', 'Ihr Anschaffungsvorschlag wurde nicht angenommen','Liebe(r) <> <>,\n\nSie haven der Bibliothek folgendes Medium zur Anschaffung vorgeschlagen: <> von <>.\n\nDie Bibliothek hat diesen Titel heute recherchiert und sich gegen eine Anschaffung entschieden.\n\nBegründung: <>\n\nWenn Sie Fragen haben, richten Sie Ihre Mail bitte an: <>.\n\nVielen Dank,\n\n<>'); +('suggestions','REJECTED','Anschaffungsvorschlag nicht angenommen', 'Ihr Anschaffungsvorschlag wurde nicht angenommen','Liebe(r) <> <>,\n\nSie haven der Bibliothek folgendes Medium zur Anschaffung vorgeschlagen: <> von <>.\n\nDie Bibliothek hat diesen Titel heute recherchiert und sich gegen eine Anschaffung entschieden.\n\nBegründung: <>\n\nWenn Sie Fragen haben, richten Sie Ihre Mail bitte an: <>.\n\nVielen Dank,\n\n<>'), +('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>'); INSERT INTO `letter` (module, code, name, title, content, is_html) VALUES ('circulation','ISSUESLIP','Ausleihquittung (Quittungsdruck)','Ausleihquittung (Quittungsdruck)', '

<>

diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql index 2d09971..45a6e9a 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ b/installer/data/mysql/en/mandatory/sample_notices.sql @@ -16,7 +16,8 @@ VALUES ('circulation','ODUE','Overdue Notice','Item Overdue','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your suggestion today. The item will be ordered as soon as possible. You will be notified by mail when the order is completed, and again when the item arrives at the library.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','AVAILABLE','Suggestion available', 'Suggested purchase available','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested is now part of the collection.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','ORDERED','Suggestion ordered', 'Suggested item ordered','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested has now been ordered. It should arrive soon, at which time it will be processed for addition into the collection.\n\nYou will be notified again when the book is available.\n\nIf you have any questions, please email us at <>\n\nThank you,\n\n<>'), -('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'); +('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), +('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>'); INSERT INTO `letter` (module, code, name, title, content, is_html) VALUES ('circulation','ISSUESLIP','Issue Slip','Issue Slip', '

<>

Checked out to <> <> <> <>
diff --git a/installer/data/mysql/es-ES/mandatory/sample_notices.sql b/installer/data/mysql/es-ES/mandatory/sample_notices.sql index 346133f..c4a1f6e 100644 --- a/installer/data/mysql/es-ES/mandatory/sample_notices.sql +++ b/installer/data/mysql/es-ES/mandatory/sample_notices.sql @@ -15,5 +15,6 @@ VALUES ('circulation','ODUE','Overdue Notice','Item Overdue','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your suggestion today. The item will be ordered as soon as possible. You will be notified by mail when the order is completed, and again when the item arrives at the library.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','AVAILABLE','Suggestion available', 'Suggested purchase available','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested is now part of the collection.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','ORDERED','Suggestion ordered', 'Suggested item ordered','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested has now been ordered. It should arrive soon, at which time it will be processed for addition into the collection.\n\nYou will be notified again when the book is available.\n\nIf you have any questions, please email us at <>\n\nThank you,\n\n<>'), -('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'); +('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), +('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>'); INSERT INTO `letter` (module, code, name, title, content) VALUES ('circulation','RENEWAL','Item Renewal','Renewals','The following items have been renew:\r\n----\r\n<>\r\n----\r\nThank you for visiting <>.'); diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql index 4b786b6..36c15fc 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql @@ -17,5 +17,6 @@ VALUES ('suggestions','ACCEPTED','Suggestion accceptée', 'Suggestion acceptée','Cher(e) <> <>,\n\nVous avez crée une suggestion d\'achat au sujet du document <> de <>.\n\nLa Bibliothèque a reçu votre demande ce jour. Nous donnerons suite à votre demande aussi vite que possible. Vous serez averti par courriel dès que la commande sera envoyée,et quand les documents seront arrivés à la Bibliothèque.\n\nSi vous avez des questions, merci de nous contacter à l\'adresse suivante <>.\n\nMerci,\n\n<>'), ('suggestions','AVAILABLE','Suggestion disponible', 'Suggestion d\'achat disponible','cher(e) <> <>,\n\nVous avez effectué une suggestion d\'achat pour le docuement <> de <>.\n\nNous sommes heureux de vous informer que le document que vous aviez demandé est maintenant disponible dans nos collections.\n\nSi vous avez des questions, merci de nous contacter par courriel à l\'adresse <>.\n\nMerci,\n\n<>'), ('suggestions','ORDERED','Suggestion commandée', 'Suggestion commandée','Cher(e) <> <>,\n\nVous avez effectué une demande de suggestion d\'achat sur le docuement <> de <>.\n\nNous sommes heureux de vous informer que le document que vous avez demandé est maintenant en commande. Le document devrait arriver rapidement dans nos collections.\n\nVous serez averti quand le docuement sera disponible.\n\nSi vous avez des questions, merci de nous contacter à l\'adresse <>\n\nMerci,\n\n<>'), -('suggestions','REJECTED','Suggestion rejetée', 'Suggestion d\'achat rejeté','Cher(e) <> <>,\n\nVous avez fait la demande du document <> de <>.\n\nla Bibliothèque a examiné votre demande ce jour, et a décidé de ne pas retenir la suggestion pour l\'instant.\n\nLa raison est la suivante: <>\n\nSi vous avez des questions, merci de nous contacter à l\'adresse <>.\n\nMerci,\n\n<>'); +('suggestions','REJECTED','Suggestion rejetée', 'Suggestion d\'achat rejeté','Cher(e) <> <>,\n\nVous avez fait la demande du document <> de <>.\n\nla Bibliothèque a examiné votre demande ce jour, et a décidé de ne pas retenir la suggestion pour l\'instant.\n\nLa raison est la suivante: <>\n\nSi vous avez des questions, merci de nous contacter à l\'adresse <>.\n\nMerci,\n\n<>'), +('members', 'DISCHARGE', 'Quitus', 'Quitus pour <> <>', '

Quitus

\r\n\r\nLa librairie <> certifies que lecteur suivant :\r\n\r\n <> <>\r\n Numéro de carte : <>\r\n\r\na bien retourné tous ses documents.\r\n\r\n<>'); INSERT INTO `letter` (module, code, name, title, content) VALUES ('circulation','RENEWAL','Item Renewal','Renewals','Les documents suivants ont été renouvelés\r\n----\r\n<>\r\n----\r\nMerci, <>.'); diff --git a/installer/data/mysql/it-IT/necessari/notices.sql b/installer/data/mysql/it-IT/necessari/notices.sql index afdae5d..73ab8d4 100644 --- a/installer/data/mysql/it-IT/necessari/notices.sql +++ b/installer/data/mysql/it-IT/necessari/notices.sql @@ -15,7 +15,8 @@ VALUES ('circulation','ODUE','Overdue Notice','Item Overdue','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your suggestion today. The item will be ordered as soon as possible. You will be notified by mail when the order is completed, and again when the item arrives at the library.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','AVAILABLE','Suggestion available', 'Suggested purchase available','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested is now part of the collection.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','ORDERED','Suggestion ordered', 'Suggested item ordered','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested has now been ordered. It should arrive soon, at which time it will be processed for addition into the collection.\n\nYou will be notified again when the book is available.\n\nIf you have any questions, please email us at <>\n\nThank you,\n\n<>'), -('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'); +('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), +('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>'); INSERT INTO letter (module, code, name, title, content, is_html) VALUES ('circulation','ISSUESLIP','Issue Slip','Issue Slip', '

<>

Checked out to <> <> <> <>
diff --git a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql b/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql index bb26665..541e8a4 100644 --- a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql +++ b/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql @@ -36,5 +36,6 @@ VALUES ('circulation','ODUE','Purring','Purring på dokument','<> <>,\n\nDu har foreslått at biblioteket kjøper inn <> av <>.\n\nBiblioteket har vurdert forslaget i dag. Dokumentet vil bli bestilt så fort det lar seg gjøre. Du vil få en ny melding når bestillingen er gjort, og når dokumentet ankommer biblioteket.\n\nEr det noe du lurer på, vennligst kontakt oss på <>.\n\nVennlig hilsen,\n\n<>'), ('suggestions','AVAILABLE','Foreslått dokument tilgjengelig', 'Foreslått dokument tilgjengelig','<> <>,\n\nDu har foreslått at biblioteket kjøper inn <> av <>.\n\nVi har gleden av å informere deg om at dokumentet nå er innlemmet i samlingen.\n\nEr det noe du lurer på, vennligst kontakt oss på <>.\n\nVennlig hilsen,\n\n<>'), ('suggestions','ORDERED','Innkjøpsforslag i bestilling', 'Innkjøpsforslag i bestilling','Dear <> <>,\n\nDu har foreslått at biblioteket kjøper inn <> av <>.\n\nVi har gleden av å informere deg om at dokumentet du foreslo nå er i bestilling.\n\nDu vil få en ny melding når dokumentet er tilgjengelig.\n\nEr det noe du lurer på, vennligst kontakt oss på <>.\n\nVennlig hilsen,\n\n<>'), -('suggestions','REJECTED','Innkjøpsforslag avslått', 'Innkjøpsforslag avslått','<> <>,\n\nDu har foreslått at biblioteket kjøper inn <> av <>.\n\nBiblioteket har vurdert innkjøpsforslaget ditt i dag, og bestemt seg for å ikke ta det til følge.\n\nBegrunnelse: <>\n\nEr det noe du lurer på, vennligst kontakt oss på <>.\n\nVennlig hilsen,\n\n<>'); +('suggestions','REJECTED','Innkjøpsforslag avslått', 'Innkjøpsforslag avslått','<> <>,\n\nDu har foreslått at biblioteket kjøper inn <> av <>.\n\nBiblioteket har vurdert innkjøpsforslaget ditt i dag, og bestemt seg for å ikke ta det til følge.\n\nBegrunnelse: <>\n\nEr det noe du lurer på, vennligst kontakt oss på <>.\n\nVennlig hilsen,\n\n<>'), +('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>'); INSERT INTO `letter` (module, code, name, title, content) VALUES ('circulation','RENEWAL','Item Renewal','Renewals','The following items have been renew:\r\n----\r\n<>\r\n----\r\nThank you for visiting <>.'); diff --git a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql b/installer/data/mysql/pl-PL/mandatory/sample_notices.sql index cd487d4..93a969e 100644 --- a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql +++ b/installer/data/mysql/pl-PL/mandatory/sample_notices.sql @@ -17,5 +17,6 @@ VALUES ('suggestions','ACCEPTED','Suggestion accepted', 'Purchase suggestion accepted','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your suggestion today. The item will be ordered as soon as possible. You will be notified by mail when the order is completed, and again when the item arrives at the library.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','AVAILABLE','Suggestion available', 'Suggested purchase available','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested is now part of the collection.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','ORDERED','Suggestion ordered', 'Suggested item ordered','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested has now been ordered. It should arrive soon, at which time it will be processed for addition into the collection.\n\nYou will be notified again when the book is available.\n\nIf you have any questions, please email us at <>\n\nThank you,\n\n<>'), -('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'); +('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), +('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>'); INSERT INTO `letter` (module, code, name, title, content) VALUES ('circulation','RENEWAL','Item Renewal','Renewals','The following items have been renew:\r\n----\r\n<>\r\n----\r\nThank you for visiting <>.'); diff --git a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql b/installer/data/mysql/ru-RU/mandatory/sample_notices.sql index 9c1f259..3dff59a 100644 --- a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql +++ b/installer/data/mysql/ru-RU/mandatory/sample_notices.sql @@ -15,5 +15,6 @@ VALUES ('circulation','ODUE','Overdue Notice','Item Overdue','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your suggestion today. The item will be ordered as soon as possible. You will be notified by mail when the order is completed, and again when the item arrives at the library.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','AVAILABLE','Suggestion available', 'Suggested purchase available','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested is now part of the collection.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','ORDERED','Suggestion ordered', 'Suggested item ordered','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested has now been ordered. It should arrive soon, at which time it will be processed for addition into the collection.\n\nYou will be notified again when the book is available.\n\nIf you have any questions, please email us at <>\n\nThank you,\n\n<>'), -('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'); +('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), +('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>'); INSERT INTO `letter` (module, code, name, title, content) VALUES ('circulation','RENEWAL','Item Renewal','Renewals','The following items have been renew:\r\n----\r\n<>\r\n----\r\nThank you for visiting <>.'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 5d536c5..da97d18 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -423,3 +423,6 @@ INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ( INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('DisplayIconsXSLT', '1', '', 'If ON, displays the format, audience, and material type icons in XSLT MARC21 results and detail pages.', 'YesNo'); INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('HighlightOwnItemsOnOPAC','0','','If on, and a patron is logged into the OPAC, items from his or her home library will be emphasized and shown first in search results and item details.','YesNo'); INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('HighlightOwnItemsOnOPACWhich','PatronBranch','PatronBranch|OpacURLBranch','Decides which branch''s items to emphasize. If PatronBranch, emphasize the logged in user''s library''s items. If OpacURLBranch, highlight the items of the Apache var BRANCHCODE defined in Koha''s Apache configuration file.','Choice') +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('useDischarge','','Allows librarians to discharge borrowers and borrowers to request a discharge','','YesNo'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('dischargePath','','Sets the upload path for the generated discharges','',''); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('dischargeWebPath','','Set the upload path starting from document root for the generated discharges','',''); diff --git a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql b/installer/data/mysql/uk-UA/mandatory/sample_notices.sql index 8b61186..f1b7eac 100644 --- a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql +++ b/installer/data/mysql/uk-UA/mandatory/sample_notices.sql @@ -14,5 +14,6 @@ VALUES ('circulation','ODUE','Overdue Notice','Item Overdue','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your suggestion today. The item will be ordered as soon as possible. You will be notified by mail when the order is completed, and again when the item arrives at the library.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','AVAILABLE','Suggestion available', 'Suggested purchase available','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested is now part of the collection.\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), ('suggestions','ORDERED','Suggestion ordered', 'Suggested item ordered','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nWe are pleased to inform you that the item you requested has now been ordered. It should arrive soon, at which time it will be processed for addition into the collection.\n\nYou will be notified again when the book is available.\n\nIf you have any questions, please email us at <>\n\nThank you,\n\n<>'), -('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'); +('suggestions','REJECTED','Suggestion rejected', 'Purchase suggestion declined','Dear <> <>,\n\nYou have suggested that the library acquire <> by <>.\n\nThe library has reviewed your request today, and has decided not to accept the suggestion at this time.\n\nThe reason given is: <>\n\nIf you have any questions, please email us at <>.\n\nThank you,\n\n<>'), +('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>'); INSERT INTO `letter` (module, code, name, title, content) VALUES ('circulation','RENEWAL','Item Renewal','Renewals','The following items have been renew:\r\n----\r\n<>\r\n----\r\nThank you for visiting <>.'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 1aee659..84e42d9 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6749,6 +6749,18 @@ if ( CheckVersion($DBversion) ) { } + + +$DBversion = "3.11.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('useDischarge','','Allows librarians to discharge borrowers and borrowers to request a discharge','','YesNo');"); + $dbh->do("INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('dischargePath','','Sets the upload path for the generated discharges','','');"); + $dbh->do("INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('dischargeWebPath','','Sets the upload path starting from documentroot for the generated discharges','','');"); + $dbh->do("INSERT INTO `letter` (module, code, name, title, content) VALUES('members', 'DISCHARGE', 'Discharge', 'Discharge for <> <>', '

Discharge

\r\n\r\nThe library <> certifies that the following borrower :\r\n\r\n <> <>\r\n Cardnumber : <>\r\n\r\nreturned all his documents.\r\n\r\n<>');"); + print "Upgrade to $DBversion done (Add System Preferences useDischarge, dischargePath, dischargeWebpath and discharge notice)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc index f2cd877..f7df526 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -83,6 +83,9 @@ [% IF EnableBorrowerFiles %] [% IF ( borrower_files ) %]
  • [% ELSE %]
  • [% END %]Files
  • [% END %] + [% IF CAN_user_borrowers && useDischarge %] + [% IF dischargeview %]
  • [% ELSE %]
  • [% END %]Discharge
  • + [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.tt b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.tt index ced2858..d02b093 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.tt @@ -78,6 +78,10 @@ in the global namespace %] [% END %] [% IF ( sentnotices ) %]
  • [% ELSE %]
  • [% END %]Notices
  • [% IF ( statisticsview ) %]
  • [% ELSE %]
  • [% END %]Statistics
  • + [% IF CAN_user_borrowers && useDischarge %] + [% IF dischargeview %]
  • [% ELSE %]
  • [% END %]Discharge
  • + [% END %] + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/members-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/members-menu.inc index 9bd5285..e7e8772 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-menu.inc @@ -19,6 +19,9 @@ [% IF EnableBorrowerFiles %] [% IF ( borrower_files ) %]
  • [% ELSE %]
  • [% END %]Files
  • [% END %] + [% IF CAN_user_borrowers && useDischarge %] + [% IF dischargeview %]
  • [% ELSE %]
  • [% END %]Discharge
  • + [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 74d14af..f4728b7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -139,3 +139,17 @@ Patrons: yes: Do no: "Don't" - enable the ability to upload and attach arbitrary files to a borrower record. + - + - pref: useDischarge + choices: + yes: Allows + no: "Don't allow" + - librarians to discharge borrowers and borrowers to request a discharge + - + - pref: dischargePath + class: multi + - Sets the upload path for the generated discharges + - + - pref: dischargeWebPath + class: multi + - Sets the upload path starting from documentroot for the generated discharges diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt new file mode 100644 index 0000000..2eb236f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt @@ -0,0 +1,53 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Patrons › [% IF (unknowuser) %]Patron does not exist[% ELSE %]Discharge for [% firstname %] [% surname %] ([% cardnumber %])[% END %] +[% INCLUDE 'doc-head-close.inc' %] + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'patron-search.inc' %] + + + +
    +
    +
    +
    +
    +

    Discharge

    +[% IF path_missing %]

    The system preferences dischargePath and dischargeWebPath have to be filled.

    [% END %] +[% IF (error) %]

    An error has occured while generating the discharge. Please retry later or contact your administrator.

    [% END %] +[% IF (hasissues) %] +

    Cannot edit discharge: borrower has issues.

    +[% ELSE %] + [% IF (hasreserves) %] +

    Borrower has reserves: they will be canceled if the discharge is generated.

    + [% END %] + [% UNLESS path_missing %] +
    + + +
    + [% END %] +[% END %] +[% IF (dischargeloop) %] +

    Generated discharges

    + +[% END %] +
    + + +
    +
    +
    +[% INCLUDE 'circ-menu.inc' %] +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc b/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc index 5a07d95..53509ca 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc @@ -32,6 +32,9 @@ [% IF ( virtualshelves ) %] [% IF ( listsview ) %]
  • [% ELSE %]
  • [% END %]my lists
  • [% END %] + [% IF useDischarge %] + [% IF dischargeview %]
  • [% ELSE %]
  • [% END %]Discharge
  • + [% END %]
    diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-discharge.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-discharge.tt new file mode 100644 index 0000000..f059fde --- /dev/null +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-discharge.tt @@ -0,0 +1,54 @@ +[% INCLUDE 'doc-head-open.inc' %] +[% IF (LibraryNameTitle) %][% LibraryNameTitle %][% ELSE %]Koha Online[% END %] Catalog +[% INCLUDE 'doc-head-close.inc' %] + + +[% IF OpacNav or loggedinusername %] +
    +[% ELSE %] +
    +[% END %] +
    +[% INCLUDE 'masthead.inc' %] + +
    +
    +
    +
    +

    Discharge

    + [% IF generated %] + [% IF success %] +

    Your discharge request has been sent. Your discharge will be available on this page within a few days.

    + [% ELSE %] +

    Your discharge request could not be sent. Please retry later or contact an administrator.

    + [% END %] + [% ELSE %] +

    What is a discharge?

    +

    This document certifies that you have returned all borrowed items. It is sometimes asked during a file transfer from a school to another. The discharge is sent by us to your school. You will also find it available on your reader account.

    +

    Warning: This request is only valid if you are in good standing with the library. Once the application is made, you can not borrow library materials.

    + Ask for a discharge + [% END %] + [% IF dischargeloop %] +

    Generated discharges

    + + [% END %] +
    +
    +
    +
    + +[% IF ( OpacNav || loggedinusername ) %] +
    +
    + [% INCLUDE 'navigation.inc' %] + [% INCLUDE 'usermenu.inc' %] +
    +
    +[% END %] +
    +[% INCLUDE 'opac-bottom.inc' %] + diff --git a/members/discharge.pl b/members/discharge.pl new file mode 100755 index 0000000..ef6cdb8 --- /dev/null +++ b/members/discharge.pl @@ -0,0 +1,173 @@ +#!/usr/bin/perl + +# Copyright 2013 BibLibre SARL +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 NAME + +discharge.pl + +=head1 DESCRIPTION + +Allows librarian to edit and/or manage borrowers' discharges + +=cut + +use Modern::Perl; + +use CGI; +use C4::Auth; +use C4::Output; +use C4::Members; +use C4::Reserves; +use C4::Letters; +use C4::Discharges; + +use Koha::DateUtils; + +my $input = new CGI; +my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( { + template_name => 'members/discharge.tmpl', + query => $input, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { 'borrowers' => '*' }, + debug => 1, +} ); + +my $dischargePath = C4::Context->preference('dischargePath'); +my $dischargeWebPath = C4::Context->preference('dischargeWebPath'); + +my $borrowernumber; +my $data; +if ( $input->param('borrowernumber') ) { + $borrowernumber = $input->param('borrowernumber'); + + # Getting member data + $data = GetMember( borrowernumber => $borrowernumber ); + + # Getting pending issues + my $issues = GetPendingIssues($borrowernumber); + my $hasissues = scalar(@$issues); + + # Getting reserves + my @reserves = GetReservesFromBorrowernumber($borrowernumber); + my $hasreserves = scalar(@reserves); + + # Generating discharge if needed + if ($input->param('generatedischarge')) { + # If borrower has pending reserves, we cancel them + foreach (@reserves) { + CancelReserve($_->{'reservenumber'}); + } + $hasreserves = 0; + + # Debarring member + # Getting librarian's name + my $librarian = GetMember('borrowernumber' => $loggedinuser); + my $librarianname = $librarian->{'firstname'} . " " . $librarian->{'surname'}; + + # Getting today's date + my $date = C4::Dates->new()->output(); + # (this is quite ugly, but this is how borrowers seems to be permanently debarred) + # FIXME: Perl strings are not translatable atm, so comment is written in english + C4::Members::DebarMember($borrowernumber, '9999-12-31', "Discharge generated by $librarianname on $date"); + + # Creating message + my $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => 'DISCHARGE', + tables => { + borrowers => $borrowernumber, + branches => $data->{branchcode}, + }, + ); + my $today = output_pref(dt_from_string()); + $letter->{'title'} =~ s/<>/$today/g; + $letter->{'content'} =~ s/<>/$today/g; + + C4::Letters::EnqueueLetter( + { letter => $letter, + borrowernumber => $borrowernumber, + message_transport_type => 'print', + } + ); + + # Calling gather_print_notices.pl with borrowernumber and css to create html from letter + # We place the generated html in a per-user directory + # We create the per-user directory if it doesn't exist + mkdir "$dischargePath/$borrowernumber" unless -d "$dischargePath/$borrowernumber"; + qx{../misc/cronjobs/gather_print_notices.pl -f discharge -l DISCHARGE -b $borrowernumber $dischargePath/$borrowernumber}; + + # Calling printoverdues.pl in this same user directory + qx{../misc/cronjobs/printoverdues.sh $dischargePath/$borrowernumber}; + + # Error handling: + # Check if we really got our discharge as a pdf file + my $todayiso = output_pref(dt_from_string(), 'iso', 1); + # If we don't, then + unless (-e "$dischargePath/$borrowernumber/discharge-$todayiso.pdf") { + # Show an error message to the librarian + $template->param(error => 1); + + # Remove the possibly generated html file + unlink "$dischargePath/$borrowernumber/discharge-$todayiso.html"; + + # Remove the unprocessed message from message_queue + removeUnprocessedDischarges($borrowernumber); + + } + + } + + # Getting already generated discharges + my @list = GetDischarges($borrowernumber); + my @loop = map {{ url => $dischargeWebPath . "/" . $borrowernumber . "/" . $_, filename => $_ }} @list; + $template->param("dischargeloop" => \@loop) if (@list); + + + $template->param( + borrowernumber => $borrowernumber, + biblionumber => $data->{'biblionumber'}, + title => $data->{'title'}, + initials => $data->{'initials'}, + surname => $data->{'surname'}, + borrowernumber => $borrowernumber, + firstname => $data->{'firstname'}, + cardnumber => $data->{'cardnumber'}, + categorycode => $data->{'categorycode'}, + category_type => $data->{'category_type'}, + categoryname => $data->{'description'}, + address => $data->{'address'}, + address2 => $data->{'address2'}, + city => $data->{'city'}, + zipcode => $data->{'zipcode'}, + country => $data->{'country'}, + phone => $data->{'phone'}, + email => $data->{'email'}, + branchcode => $data->{'branchcode'}, + hasissues => $hasissues, + hasreserves => $hasreserves, + ); + +} +# Send parameters to template +$template->param( + dischargeview => 1, + path_missing => ( $dischargePath and $dischargeWebPath ) ? 0 : 1, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl index 286b035..fe7e940 100755 --- a/misc/cronjobs/gather_print_notices.pl +++ b/misc/cronjobs/gather_print_notices.pl @@ -39,7 +39,7 @@ use Getopt::Long; sub usage { print STDERR < \$help, 's|split' => \$split, + 'b:i' => \$borrowernumber, + 'l:s' => \$letter_code, + 'f:s' => \$filename, ) || usage(1); usage(0) if ($help); @@ -65,8 +68,11 @@ if ( !$output_directory || !-d $output_directory ) { usage(1); } +my $params = {}; +$params->{'borrowernumber'} = $borrowernumber if ($borrowernumber); +$params->{'letter_code'} = $letter_code if ($letter_code); my $today = C4::Dates->new(); -my @all_messages = @{ GetPrintMessages() }; +my @all_messages = @{ GetPrintMessages( $params ) }; exit unless (@all_messages); my $OUTPUT; @@ -104,9 +110,9 @@ if ($split) { } } else { - open $OUTPUT, '>', - File::Spec->catdir( $output_directory, - "holdnotices-" . $today->output('iso') . ".html" ); + my $fn = $filename || "holdnotices"; + my $file=File::Spec->catdir( $output_directory, $fn . "-" . $today->output('iso') . ".html"); + open my $fh, '>', $file or die "Can't open file $file : $!"; my $template = C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet', @@ -118,13 +124,13 @@ else { messages => \@all_messages, ); - print $OUTPUT $template->output; + print $fh $template->output; foreach my $message (@all_messages) { C4::Letters::_set_message_status( { message_id => $message->{'message_id'}, status => 'sent' } ); } - close $OUTPUT; + close $fh; } diff --git a/opac/opac-discharge.pl b/opac/opac-discharge.pl new file mode 100755 index 0000000..ce4473a --- /dev/null +++ b/opac/opac-discharge.pl @@ -0,0 +1,81 @@ +#!/usr/bin/perl + +# Copyright 2013 BibLibre SARL +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use C4::Auth qw(:DEFAULT get_session); +use CGI; +use C4::Context; +use C4::Output; +use C4::Log; +use C4::Debug; +use C4::Branch; +use C4::Members; +use C4::Discharges; +use Mail::Sendmail; + +my $cgi = new CGI; + +my $dischargePath = C4::Context->preference('dischargePath'); +my $dischargeWebPath = C4::Context->preference('dischargeWebPath'); + +# Getting the template and auth +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "opac-discharge.tmpl", + query => $cgi, + type => "opac", + debug => 1, + } +); + +# Getting already generated discharges +my @list = GetDischarges($loggedinuser); +my @loop = map {{ url => $dischargeWebPath . "/" . $loggedinuser . "/" . $_, filename => $_ }} @list; +$template->param("dischargeloop" => \@loop) if (@list); + +my $generate = $cgi->param('generate'); +# Sending an email to the librarian if user requested a discharge +if ($generate) { + my $title = "Discharge request"; + my $member = GetMember('borrowernumber' => $loggedinuser); + my $membername = $member->{firstname} . " " . $member->{surname} . " (" . $member->{cardnumber} . ")"; + my $content = "Discharge request from $membername"; + my $branch = GetBranchDetail($member->{'branchcode'}); + my $sender_email_address = GetFirstValidEmailAddress($loggedinuser); + $sender_email_address = $branch->{branchemail} unless ($sender_email_address); + + # Note : perhaps we should use C4::Messages here? + my %mail = ( + To => $branch->{branchemail}, + From => $sender_email_address, + Subject => "Discharge request", + Message => $content, + 'Content-Type' => 'text/plain; charset="utf8"', + ); + + my $result = sendmail(%mail); + $template->param( + success => $result, + generated => 1, + ); +} + +$template->param( dischargeview => 1 ); + +output_html_with_http_headers $cgi, $cookie, $template->output; -- 1.7.10.4