Register   Login
     
  Latest Posts  
RE: RSS Character Limitation
by greenflash on 3/18/2010 6:45 AM
RE: Order by dropbox ?
by smcculloch on 3/18/2010 6:31 AM
RE: Order by dropbox ?
by smcculloch on 3/18/2010 6:31 AM
RE: Tags and Filtering
by smcculloch on 3/18/2010 6:31 AM
RE: Tags and Related Articles
by smcculloch on 3/18/2010 6:30 AM
RE: Is there a way to add image, based on x of DATE
by smcculloch on 3/18/2010 6:29 AM
RE: Images/Lightbox on Listing template
by smcculloch on 3/18/2010 6:29 AM
RE: thumbnails and W3C validation
by smcculloch on 3/18/2010 6:28 AM
RE: Multiple images in RSS feed
by smcculloch on 3/18/2010 6:27 AM
RE: NA Latest - Template question
by smcculloch on 3/18/2010 6:26 AM
  Forums  
Subject: SQL to load Receipts table from user roles
Prev Next
You are not authorized to post a reply.

Author Messages
WilliamUser is Offline
Gold Membership
Ventrian Super Newbie
Ventrian Super Newbie
Posts:22

10/20/2009 12:34 PM  

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

Scott McCullochUser is Offline
Administrators
Ventrian Master
Ventrian Master
Posts:17204


10/21/2009 7:22 AM  
Thanks William, i've pinned the thread and sent you an email.

Scott McCulloch
Site Administrator
You are not authorized to post a reply.
Forums > Modules > Subscription Tools > SQL to load Receipts table from user roles



ActiveForums 3.7