Remaining days calculation in MySql – Multiple maturities

I have the following problem when calculating the remaining days. I need the first period to expire before computing the days of the next period. In this example, even though 2 periods of 30 days were started on the same day, the duration is 60 days and therefore, as of today there are 38 days remaining, and not 16 as my formula gives.
Let’s imagine it as a subscription model in which a user is charged two payments for 30 days.
This is my solution so far.

How to auto send email when publishing a custom post type?

I’d like to have an email automatically sent out to my website’s subscribers when I publish a post for a specific custom post type. I’ve found a few plugins that will do this but only for regular posts (or for any post type that gets published, not allowing you to specify a particular post type). Any suggestions would be greatly appreciated! Thanks.