I've got Subscription Tools running on our web site now (with a few mods), and it's working great. I wanted a way to load the Receipts table with data from the users that were already on the site so it would send out expiration notices. I know I can use manual Add Receipt but that's a pain with a lot of users already paid up before I install Subscription Tools. So that meant digging into SQL a bit. Figured this might save some of you some time, so here it is. PLEASE study the script before you use it. As always you are responsible for taking a backup of your database and for whatever happens if you use this!
--INSERT INTO dbo.DnnForge_SubscriptionTools_Receipt SELECT r.PortalID, u.UserID, -- u.UserName, GETDATE() as [DateCreated], ur.EffectiveDate as [DateStart], ur.ExpiryDate as [DateEnd], 'Complete' as [Status], -- r.Rolename as [Name], (CASE r.RoleName WHEN 'Family Member' THEN 'Family Membership' WHEN 'Junior Member' THEN 'Junior Membership' WHEN 'Senior Member' THEN 'Senior Membership' ELSE 'Unknown RoleName' END) AS [Name], r.ServiceFee, --NOTE: Manual Frequency and Period values... 5 as [BillingFrequency], /* Yearly */ 1 as [BillingPeriod], /* 1 (year) */ 'Manual2' as [Processor], '' as [ProcessorTxID], 508 as [ModuleID], r.RoleName as [Description], 'USD' as Currency FROM dbo.Users AS u INNER JOIN dbo.UserRoles AS ur ON u.UserID = ur.UserID INNER JOIN dbo.Roles AS r ON ur.RoleID = r.RoleID AND (r.RoleName = N'Family Member' OR r.RoleName = N'Junior Member' OR r.RoleName = N'Senior Member') -- AND DATEDIFF(day, GETDATE(), ur.ExpiryDate) <= 30 LEFT JOIN dbo.DnnForge_SubscriptionTools_Receipt AS sr ON u.UserID = sr.UserID WHERE sr.UserID IS NULL
You will note that the first line is commented. Run the script this way FIRST to see what it is going to do. Uncomment line 5 to see the UserName field while testing. Uncomment line 33 to limit the range of Roles to those which will expire in the next 30 days.
All of our memberships are for 1 year, so I hard coded the Frequency and Period values. Subscription Tools uses number for the Frequency (really it's a type) but DNN uses a letter, so doing this "right" would have been more work than it was worth.
WHEN you are sure the resulting table is what you want, then comment out line 5 again and uncomment line 1.
GOOD LUCK!
William Phelps Meier-Phelps Consulting |