A new crontab based perl script to send membership expiry reminders. A system
preference controls the number of days in advance of membership expiry that the
notices will be sent on.
---
 C4/Letters.pm                                      |    4 +
 C4/Members.pm                                      |   22 +++++
 .../data/mysql/de-DE/mandatory/sample_notices.sql  |    1 +
 .../data/mysql/en/mandatory/sample_notices.sql     |    1 +
 .../data/mysql/es-ES/mandatory/sample_notices.sql  |    1 +
 .../mysql/fr-FR/1-Obligatoire/sample_notices.sql   |    1 +
 installer/data/mysql/it-IT/necessari/notices.sql   |    1 +
 .../mysql/nb-NO/1-Obligatorisk/sample_notices.sql  |    1 +
 .../data/mysql/pl-PL/mandatory/sample_notices.sql  |    3 +-
 .../data/mysql/ru-RU/mandatory/sample_notices.sql  |    1 +
 installer/data/mysql/sysprefs.sql                  |    1 +
 .../data/mysql/uk-UA/mandatory/sample_notices.sql  |    1 +
 installer/data/mysql/updatedatabase.pl             |    9 ++
 .../prog/en/modules/admin/preferences/patrons.pref |    5 +
 misc/cronjobs/membership_expiry.pl                 |  100 ++++++++++++++++++++
 15 files changed, 151 insertions(+), 1 deletions(-)
 create mode 100755 misc/cronjobs/membership_expiry.pl

diff --git a/C4/Letters.pm b/C4/Letters.pm
index 6846a00..961fa00 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -525,6 +525,10 @@ sub parseletter {
     }
 
     my $values = $sth->fetchrow_hashref;
+
+    if ($table eq 'borrowers' && $values->{'dateexpiry'}){
+                my @dateexpiry = split /-/, $values->{'dateexpiry'};
+                $values->{'dateexpiry'} = 
C4::Dates->new(sprintf('%04d-%02d-%02d', Add_Delta_Days( @dateexpiry,0)),'iso' 
)->output(); }
     
     # TEMPORARY hack until the expirationdate column is added to reserves
     if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
diff --git a/C4/Members.pm b/C4/Members.pm
index dcc168b..3031acc 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -86,6 +86,7 @@ BEGIN {
                &GetBorrowersWithIssuesHistoryOlderThan
 
                &GetExpiryDate
+               &GetUpcomingMembershipExpires
 
                &AddMessage
                &DeleteMessage
@@ -2260,6 +2261,27 @@ sub GetMessagesCount {
     return $count;
 }
 
+=head2 GetUpcomingMembershipExpires
+
+  my $upcoming_mem_expires = GetUpcomingMembershipExpires();
+
+=cut
+
+sub GetUpcomingMembershipExpires {
+    my $dbh = C4::Context->dbh;
+    my $days = C4::Context->preference("MemExpDaysNotice");
+    my $query = "
+      SELECT borrowers.* , categories.description,
+branches.branchname FROM borrowers
+      LEFT JOIN branches on borrowers.branchcode = branches.branchcode
+      LEFT JOIN categories on borrowers.categorycode = categories.categorycode
+      WHERE dateexpiry = DATE_ADD(CURDATE(),INTERVAL $days DAY);
+    ";
+    my $sth = $dbh->prepare($query);
+    $sth->execute;
+    my $results = $sth->fetchall_arrayref({});
+    return $results;
+}
 
 
 =head2 DeleteMessage
diff --git a/installer/data/mysql/de-DE/mandatory/sample_notices.sql 
b/installer/data/mysql/de-DE/mandatory/sample_notices.sql
index 166c36d..deb6eae 100644
--- a/installer/data/mysql/de-DE/mandatory/sample_notices.sql
+++ b/installer/data/mysql/de-DE/mandatory/sample_notices.sql
@@ -3,6 +3,7 @@ VALUES ('circulation','ODUE','Mahnung','Mahnung','Liebe/r 
<<borrowers.firstname>
 ('claimacquisition','ACQCLAIM','Reklamation (Erwerbung)','Titel nicht 
eingetroffen','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nOrdernumber
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> bestellt) 
(je $<<aqorders.listprice>> €) sind nicht eingetroffen.'),
 ('serial','RLIST','Umlaufliste','Zeitschrift ist jetzt 
verfügbar','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nDas folgende 
Heft ist jetzt verfügbar:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nBitte holen Sie es sobald möglich ab.'),
 ('members','ACCTDETAILS','Kontoinformationen - Standard','Ihr neues 
Benutzerkonto','Liebe/r <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nDie Daten Ihres neuen Benutzerkontos 
sind:\r\n\r\nBenutzer:  <<borrowers.userid>>\r\nPasswort: 
<<borrowers.password>>\r\n\r\nWenn Sie Probleme in Hinsicht auf Ihr 
Benutzerkonto haben, wenden Sie sich bitte an die Bibliothek.\r\n\r\nVielen 
Dank,\r\nIhr Bibliotheksteam'), 
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 
('circulation','DUE','Fälligkeitsbenachrichtigung','Fälligkeitsbenachrichtigung','Liebe/r
 <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nDie folgenden Medien 
sind ab heute fällig:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)'), 
 ('circulation','DUEDGST','Fälligkeitsbenachrichtigung 
(Zusammenfassung)','Fälligkeitsbenachrichtigung','Sie haben <<count>> 
überfällige Medien.'), 
 
('circulation','PREDUE','Erinnerungsbenachrichtigung','Erinnerungsbenachrichtigung','Liebe/r
 <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nFolgende Ausleihe wird 
bald fällig:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql 
b/installer/data/mysql/en/mandatory/sample_notices.sql
index 689fa0f..b7d4fe8 100644
--- a/installer/data/mysql/en/mandatory/sample_notices.sql
+++ b/installer/data/mysql/en/mandatory/sample_notices.sql
@@ -3,6 +3,7 @@ VALUES ('circulation','ODUE','Overdue Notice','Item 
Overdue','Dear <<borrowers.f
 ('claimacquisition','ACQCLAIM','Acquisition Claim','Item Not 
Received','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nOrdernumber
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) 
($<<aqorders.listprice>> each) has not been received.'),
 ('serial','RLIST','Routing List','Serial is now 
available','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
issue is now available:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nPlease pick it up at your convenience.'),
 ('members','ACCTDETAILS','Account Details Template - DEFAULT','Your new Koha 
account details.','Hello <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nYour new Koha account details are:\r\n\r\nUser:  
<<borrowers.userid>>\r\nPassword: <<borrowers.password>>\r\n\r\nIf you have any 
problems or questions regarding your account, please contact your Koha 
Administrator.\r\n\r\nThank you,\r\nKoha 
Administrator\r\[email protected]'), 
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 ('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear 
<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now 
due:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You 
have <<count>> items due'), 
 ('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item 
Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
item will be due soon:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)'), 
diff --git a/installer/data/mysql/es-ES/mandatory/sample_notices.sql 
b/installer/data/mysql/es-ES/mandatory/sample_notices.sql
index 689fa0f..b7d4fe8 100644
--- a/installer/data/mysql/es-ES/mandatory/sample_notices.sql
+++ b/installer/data/mysql/es-ES/mandatory/sample_notices.sql
@@ -3,6 +3,7 @@ VALUES ('circulation','ODUE','Overdue Notice','Item 
Overdue','Dear <<borrowers.f
 ('claimacquisition','ACQCLAIM','Acquisition Claim','Item Not 
Received','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nOrdernumber
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) 
($<<aqorders.listprice>> each) has not been received.'),
 ('serial','RLIST','Routing List','Serial is now 
available','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
issue is now available:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nPlease pick it up at your convenience.'),
 ('members','ACCTDETAILS','Account Details Template - DEFAULT','Your new Koha 
account details.','Hello <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nYour new Koha account details are:\r\n\r\nUser:  
<<borrowers.userid>>\r\nPassword: <<borrowers.password>>\r\n\r\nIf you have any 
problems or questions regarding your account, please contact your Koha 
Administrator.\r\n\r\nThank you,\r\nKoha 
Administrator\r\[email protected]'), 
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 ('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear 
<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now 
due:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You 
have <<count>> items due'), 
 ('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item 
Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
item will be due soon:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)'), 
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 977e59d..d4307f1 100644
--- a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql
+++ b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql
@@ -5,6 +5,7 @@ VALUES
 ('claimacquisition','ACQCLAIM','Acquisition Claim','Item Not 
Received','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nOrdernumber
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) 
($<<aqorders.listprice>> each) has not been received.'),
 ('serial','RLIST','Routing List','Serial is now 
available','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
issue is now available:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nPlease pick it up at your convenience.'),
 ('members','ACCTDETAILS','Account Details Template - DEFAULT','Your new Koha 
account details.','Hello <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nYour new Koha account details are:\r\n\r\nUser:  
<<borrowers.userid>>\r\nPassword: <<borrowers.password>>\r\n\r\nIf you have any 
problems or questions regarding your account, please contact your Koha 
Administrator.\r\n\r\nThank you,\r\nKoha 
Administrator\r\[email protected]'),
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 ('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear 
<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now 
due:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'),
 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You 
have <<count>> items due'),
 ('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item 
Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
item will be due soon:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)'),
diff --git a/installer/data/mysql/it-IT/necessari/notices.sql 
b/installer/data/mysql/it-IT/necessari/notices.sql
index 689fa0f..b7d4fe8 100644
--- a/installer/data/mysql/it-IT/necessari/notices.sql
+++ b/installer/data/mysql/it-IT/necessari/notices.sql
@@ -3,6 +3,7 @@ VALUES ('circulation','ODUE','Overdue Notice','Item 
Overdue','Dear <<borrowers.f
 ('claimacquisition','ACQCLAIM','Acquisition Claim','Item Not 
Received','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nOrdernumber
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) 
($<<aqorders.listprice>> each) has not been received.'),
 ('serial','RLIST','Routing List','Serial is now 
available','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
issue is now available:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nPlease pick it up at your convenience.'),
 ('members','ACCTDETAILS','Account Details Template - DEFAULT','Your new Koha 
account details.','Hello <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nYour new Koha account details are:\r\n\r\nUser:  
<<borrowers.userid>>\r\nPassword: <<borrowers.password>>\r\n\r\nIf you have any 
problems or questions regarding your account, please contact your Koha 
Administrator.\r\n\r\nThank you,\r\nKoha 
Administrator\r\[email protected]'), 
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 ('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear 
<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now 
due:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You 
have <<count>> items due'), 
 ('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item 
Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
item will be due soon:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)'), 
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 cdb5529..29d86ac 100644
--- a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql
+++ b/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql
@@ -24,6 +24,7 @@ VALUES ('circulation','ODUE','Purring','Purring på 
dokument','<<borrowers.first
 ('claimacquisition','ACQCLAIM','Periodikapurring','Eksemplar ikke 
mottatt','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nBestillingsnummer
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) 
($<<aqorders.listprice>> each) har ikke blitt mottatt.'),
 ('serial','RLIST','Sirkulasjon','Et dokument er nå 
tilgjengelig','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nDette 
dokumentet er tilgjengelig:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nVennligst kom og hent det når det passer.'),
 ('members','ACCTDETAILS','Mal for kontodetaljer - STANDARD','Dine nye 
kontodetaljer i Koha.','Hei <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nDine nye detaljer er:\r\n\r\nBruker:  
<<borrowers.userid>>\r\nPassord: <<borrowers.password>>\r\n\r\nDersom det 
oppstår problemer, vennligst kontakt biblioteket.\r\n\r\nVennlig 
hilsen,\r\nBiblioteket\r\[email protected]'), 
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 
('circulation','DUE','Innleveringspåminnelse','Innleveringspåminnelse','<<borrowers.firstname>>
 <<borrowers.surname>>,\r\n\r\nDette dokumentet må nå 
leveres:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
 ('circulation','DUEDGST','Innleveringspåminnelse 
(sammendrag)','Innleveringspåminnelse','Du har <<count>> dokumenter som skulle 
vært levert.'), 
 
('circulation','PREDUE','Forhåndspåminnelse','Forhåndspåminnelse','<<borrowers.firstname>>
 <<borrowers.surname>>,\r\n\r\nDette dokumentet må snart 
leveres:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
diff --git a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql 
b/installer/data/mysql/pl-PL/mandatory/sample_notices.sql
index 6be2eb8..1491625 100644
--- a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql
+++ b/installer/data/mysql/pl-PL/mandatory/sample_notices.sql
@@ -4,7 +4,8 @@ VALUES
 'Item Overdue','Dear <<borrowers.firstname>> 
<<borrowers.surname>>,\n\nAccording to our current records, you have items that 
are overdue.Your library does not charge late fines, but please return or renew 
them at the branch below as soon as 
possible.\n\n<<branches.branchname>>\n<<branches.branchaddress1>>\n<<branches.branchaddress2>>
 <<branches.branchaddress3>>\nPhone: <<branches.branchphone>>\nFax: 
<<branches.branchfax>>\nEmail: <<branches.branchemail>>\n\nIf you have 
registered a password with the library, and you have a renewal available, you 
may renew online. If an item becomes more than 30 days overdue, you will be 
unable to use your library card until the item is returned.\n\nThe following 
item(s) is/are currently overdue:\n\n<item>"<<biblio.title>>" by 
<<biblio.author>>, <<items.itemcallnumber>>, Barcode: <<items.barcode>> Fine: 
<fine>GBP</fine></item>\n\nThank-you for your prompt attention to this 
matter.\n\n<<branches.branchname>> Staff\n'),
 ('claimacquisition','ACQCLAIM','Acquisition Claim','Item Not 
Received','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nOrdernumber
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) 
($<<aqorders.listprice>> each) has not been received.'),
 ('serial','RLIST','Routing List','Serial is now 
available','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
issue is now available:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nPlease pick it up at your convenience.'),
-('members','ACCTDETAILS','Account Details Template - DEFAULT','Your new Koha 
account details.','Hello <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nYour new Koha account details are:\r\n\r\nUser:  
<<borrowers.userid>>\r\nPassword: <<borrowers.password>>\r\n\r\nIf you have any 
problems or questions regarding your account, please contact your Koha 
Administrator.\r\n\r\nThank you,\r\nKoha 
Administrator\r\[email protected]'), 
+('members','ACCTDETAILS','Account Details Template - DEFAULT','Your new Koha 
account details.','Hello <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nYour new Koha account details are:\r\n\r\nUser:  
<<borrowers.userid>>\r\nPassword: <<borrowers.password>>\r\n\r\nIf you have any 
problems or questions regarding your account, please contact your Koha 
Administrator.\r\n\r\nThank you,\r\nKoha 
Administrator\r\[email protected]'),
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 ('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear 
<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now 
due:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You 
have <<count>> items due'), 
 ('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item 
Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
item will be due soon:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)'), 
diff --git a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql 
b/installer/data/mysql/ru-RU/mandatory/sample_notices.sql
index 689fa0f..b7d4fe8 100644
--- a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql
+++ b/installer/data/mysql/ru-RU/mandatory/sample_notices.sql
@@ -3,6 +3,7 @@ VALUES ('circulation','ODUE','Overdue Notice','Item 
Overdue','Dear <<borrowers.f
 ('claimacquisition','ACQCLAIM','Acquisition Claim','Item Not 
Received','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nOrdernumber
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) 
($<<aqorders.listprice>> each) has not been received.'),
 ('serial','RLIST','Routing List','Serial is now 
available','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
issue is now available:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nPlease pick it up at your convenience.'),
 ('members','ACCTDETAILS','Account Details Template - DEFAULT','Your new Koha 
account details.','Hello <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nYour new Koha account details are:\r\n\r\nUser:  
<<borrowers.userid>>\r\nPassword: <<borrowers.password>>\r\n\r\nIf you have any 
problems or questions regarding your account, please contact your Koha 
Administrator.\r\n\r\nThank you,\r\nKoha 
Administrator\r\[email protected]'), 
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 ('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear 
<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now 
due:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You 
have <<count>> items due'), 
 ('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item 
Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
item will be due soon:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)'), 
diff --git a/installer/data/mysql/sysprefs.sql 
b/installer/data/mysql/sysprefs.sql
index 8407505..6bb78f9 100755
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -317,3 +317,4 @@ INSERT INTO systempreferences 
(variable,value,explanation,options,type) VALUES (
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) 
VALUES ('BasketConfirmations', '1', 'When closing or reopening a basket,', 
'always ask for confirmation.|do not ask for confirmation.', 'Choice');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) 
VALUES ('MARCAuthorityControlField008', '|| aca||aabn           | a|a     d', 
NULL, NULL, 'Textarea');
 INSERT INTO systempreferences (variable,value,explanation,options,type) 
VALUES('OpenLibraryCovers',0,'If ON Openlibrary book covers will be 
show',NULL,'YesNo');
+INSERT INTO `systempreferences`(variable,value,explanation,options,type) 
VALUES('MemExpDaysNotice',14,'Send a membership expiry notice that a patron is 
about to expire after',NULL,'free');
diff --git a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql 
b/installer/data/mysql/uk-UA/mandatory/sample_notices.sql
index 358205b..631481d 100644
--- a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql
+++ b/installer/data/mysql/uk-UA/mandatory/sample_notices.sql
@@ -3,6 +3,7 @@ VALUES ('circulation','ODUE','Overdue Notice','Item 
Overdue','Dear <<borrowers.f
 ('claimacquisition','ACQCLAIM','Acquisition Claim','Item Not 
Received','<<aqbooksellers.name>>\r\n<<aqbooksellers.address1>>\r\n<<aqbooksellers.address2>>\r\n<<aqbooksellers.address3>>\r\n<<aqbooksellers.address4>>\r\n<<aqbooksellers.phone>>\r\n\r\nOrdernumber
 <<aqorders.ordernumber>> (<<aqorders.title>>) (<<aqorders.quantity>> ordered) 
($<<aqorders.listprice>> each) has not been received.'),
 ('serial','RLIST','Routing List','Serial is now 
available','<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
issue is now available:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)\r\n\r\nPlease pick it up at your convenience.'),
 ('members','ACCTDETAILS','Account Details Template - DEFAULT','Your new Koha 
account details.','Hello <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>.\r\n\r\nYour new Koha account details are:\r\n\r\nUser:  
<<borrowers.userid>>\r\nPassword: <<borrowers.password>>\r\n\r\nIf you have any 
problems or questions regarding your account, please contact your Koha 
Administrator.\r\n\r\nThank you,\r\nKoha 
Administrator\r\[email protected]'), 
+('members','MEMEXP','Membership Expiry Notice','Membership Expiry 
Notice','Dear <<borrowers.title>> <<borrowers.firstname>> 
<<borrowers.surname>>,.\r\n\r\nYour membership expires soon 
on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>'),
 ('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear 
<<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now 
due:\r\n\r\n<<biblio.title>>, <<biblio.author>> (<<items.barcode>>)'), 
 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You 
have <<count>> items due'), 
 ('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item 
Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following 
item will be due soon:\r\n\r\n<<biblio.title>>, <<biblio.author>> 
(<<items.barcode>>)'), 
diff --git a/installer/data/mysql/updatedatabase.pl 
b/installer/data/mysql/updatedatabase.pl
index bdfc9ac..0a782d6 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4439,6 +4439,15 @@ if (C4::Context->preference("Version") < 
TransformToNum($DBversion)) {
     SetVersion($DBversion);
 }
 
+$DBversion = "3.05.00.XXX";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+$dbh->do(q{INSERT INTO `letter` (`module`, `code`, `name`, `title`,`content`) 
VALUES('members','MEMEXP','Membership Expiry','Your Membership Expires','Dear 
<<borrowers.title>> <<borrowers.firstname>> <<borrowers.surname>>,.\r\n\r\nYour 
membership expires soon on:\r\n\r\n<<borrowers.dateexpiry>>\r\n\r\nThank 
you,\r\n\r\n<<branches.branchname>>');
+    });
+    $dbh->do("INSERT INTO `systempreferences` 
(variable,value,explanation,options,type) VALUES('MemExpDaysNotice',14,'Send a 
membership expiry notice that a patron is about to expire after',NULL,'free')");
+    print "Upgrade to $DBversion done (Add letter and syspref for Membership 
expiry notifications)\n";
+    SetVersion ($DBversion);
+}
+
 
 =head1 FUNCTIONS
 
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 ac3e1d2..327246d 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
@@ -82,6 +82,11 @@ Patrons:
            class: integer
          - characters long.
      -
+         - Send a membership expiry notice that a patron is about to expire 
after
+         - pref: MemExpDaysNotice
+           class: integer
+         - days.
+     -
          - Show a notice that a patron is about to expire
          - pref: NotifyBorrowerDeparture
            class: integer
diff --git a/misc/cronjobs/membership_expiry.pl 
b/misc/cronjobs/membership_expiry.pl
new file mode 100755
index 0000000..a50176d
--- /dev/null
+++ b/misc/cronjobs/membership_expiry.pl
@@ -0,0 +1,100 @@
+#!/usr/bin/perl
+
+# Copyright 2011 Nucsoft Osslabs.
+#
+# 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
+
+membership_expires.pl - cron script to put item due reminders into message 
queue
+
+=head1 SYNOPSIS
+
+./membership_expires.pl
+
+or, in crontab:
+0 1 * * * membership_expires.pl
+
+=cut
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Data::Dumper;
+BEGIN {
+    # find Koha's Perl modules
+    # test carefully before changing this
+    use FindBin;
+    eval { require "$FindBin::Bin/../kohalib.pl" };
+}
+
+use C4::Context;
+use C4::Letters;
+use C4::Dates qw/format_date/;
+
+# These are defaults for command line options.
+my $nomail;                                                         # -n: No 
mail. Will not send any emails.
+my $fromaddress = C4::Context->preference('KohaAdminEmailAddress'); # -f: From 
address for the emails
+my $verbose     = 0;                                                # -v: 
verbose
+
+GetOptions( 'n'              => \$nomail,
+            'v'              => \$verbose,
+       );
+
+warn 'getting upcoming membership expires' if $verbose;
+my $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires();
+warn 'found ' . scalar( @$upcoming_mem_expires ) . ' issues' if $verbose;
+
+UPCOMINGMEMEXP: foreach my $recent ( @$upcoming_mem_expires ) {
+
+   my $letter_type = 'MEMEXP';
+   my $letter = C4::Letters::getletter( 'members', $letter_type );
+            die "no letter of type '$letter_type' found. Please see 
sample_notices.sql" unless $letter;
+
+   $letter = parse_letter( {        letter    => $letter,
+                                    borrowernumber => 
$recent->{'borrowernumber'},
+                                    categorycode  => $recent->{'categorycode'},
+                                    branchcode => $recent->{'branchcode'},
+                                     
+                                  });        
+    if ($letter) {
+                    C4::Letters::EnqueueLetter( {   letter                 => 
$letter,
+                                                    borrowernumber        =>  
$recent->{'borrowernumber'},
+                                                    message_transport_type => 
'email' } );
+                }
+               
+
+       }
+
+=head1 METHODS
+
+=head2 parse_letter
+
+=cut
+
+sub parse_letter {
+    my $params = shift;
+    foreach my $required ( qw( letter borrowernumber ) ) {
+               return unless exists $params->{$required};
+    }
+    C4::Letters::parseletter( $params->{'letter'}, 'borrowers',   
$params->{'borrowernumber'} );
+    C4::Letters::parseletter( $params->{'letter'}, 'branches',   
$params->{'branchcode'} );   
+    return $params->{'letter'};
+}
+
+1;
+
+__END__
-- 
1.6.4.2

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to