Jump to content
  • 0

Stop invoices from sending on the weekend.


Jason

Question

I am looking for a way to limit invoices to sending during weekdays. In older versions of Blesta I added a line or two of php to cron.php to check if the day of the week was Saturday or Sunday and if it was to simply skip creating the invoice.

if ((date('N') >= 6) .....

Since I upgraded a while back my code no longer works. I added it where I thought it should be, but it hasn't kept the system from sending invoices. So I am either adding it in the wrong spot, or Blesta no longer uses the cron.php file to determine if an invoice is sent. Any ideas how I could accomplish this?

Thanks,
--Jason

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
14 hours ago, Jason said:

I am looking for a way to limit invoices to sending during weekdays. In older versions of Blesta I added a line or two of php to cron.php to check if the day of the week was Saturday or Sunday and if it was to simply skip creating the invoice.


if ((date('N') >= 6) .....

Since I upgraded a while back my code no longer works. I added it where I thought it should be, but it hasn't kept the system from sending invoices. So I am either adding it in the wrong spot, or Blesta no longer uses the cron.php file to determine if an invoice is sent. Any ideas how I could accomplish this?

Thanks,
--Jason

What version of Blesta did you do that with? Are you trying to prevent the generation of invoice, or only email delivery? You edited the /app/controllers/cron.php file? Can you provide a snipped from the file showing your change and a few lines above/below?

Out of curiosity, why no weekends?

Link to comment
Share on other sites

  • 0

I am trying to keep it from generating the invoices and sending out emails on the weekend, but then complete those tasks on Monday.
I don't remember what version of Blesta is was, but it worked for several versions. I may have had to move where the line of code was located, but I was able to successful utilize the code through a couple of different releases/version. I believe the workaround was in place somewhere from around 2016 till 2018 or 2019 before it stopped working.

I grabbed some of the code from a backup file I have from a previous version where I had used the code...

	private function createRenewingServiceInvoices() {
		
if (date('N') >= 6) { $output = ""; } else {
	
		$this->uses(array("ClientGroups", "Coupons", "Invoices", "Services", "PackageOptions"));

and of course I closed the if statement lower on down after the function was finished. It isn't pretty but it worked as expected.

I also extended it to include Christmas as a day not to send invoices.

$month = date('n');
$day = date('j');
if ((date('N') >= 6) || (strtotime(date('Y-12-25')) == strtotime(date('Y-m-d'))) ) { $output = ""; } else {

The idea was to simply have it skip creating the invoice on those days, the following day it would see the invoices had not been created and voila it would create it as it was supposed to.

As for why ... I observe Sunday as a day of rest for religious reasons, and didn't want the billing system sending out bills to my clients on that day. I am also primarily a web designer, so while I do host websites, having them only billed Monday through Friday lowers the amount of potential questions and emails on the weekend :-).

Link to comment
Share on other sites

  • 0
44 minutes ago, Jason said:

I am trying to keep it from generating the invoices and sending out emails on the weekend, but then complete those tasks on Monday.
I don't remember what version of Blesta is was, but it worked for several versions. I may have had to move where the line of code was located, but I was able to successful utilize the code through a couple of different releases/version. I believe the workaround was in place somewhere from around 2016 till 2018 or 2019 before it stopped working.

I grabbed some of the code from a backup file I have from a previous version where I had used the code...


	private function createRenewingServiceInvoices() {
		
if (date('N') >= 6) { $output = ""; } else {
	
		$this->uses(array("ClientGroups", "Coupons", "Invoices", "Services", "PackageOptions"));

and of course I closed the if statement lower on down after the function was finished. It isn't pretty but it worked as expected.

I also extended it to include Christmas as a day not to send invoices.


$month = date('n');
$day = date('j');
if ((date('N') >= 6) || (strtotime(date('Y-12-25')) == strtotime(date('Y-m-d'))) ) { $output = ""; } else {

The idea was to simply have it skip creating the invoice on those days, the following day it would see the invoices had not been created and voila it would create it as it was supposed to.

As for why ... I observe Sunday as a day of rest for religious reasons, and didn't want the billing system sending out bills to my clients on that day. I am also primarily a web designer, so while I do host websites, having them only billed Monday through Friday lowers the amount of potential questions and emails on the weekend :-).

I don't see a problem necessarily with your code, it's just checking if it's Saturday or Sunday (6 or 7), and not executing the code to generate invoices. Personally I would have made Sunday 1 and not Monday as Sunday is actually the first day of the week, but I digress. Maybe @Jono has something to add.

Link to comment
Share on other sites

  • 0
2 hours ago, Jono said:

That private method no longer exists in the current version of Blesta.  Cron tasks have been moved to their own classes.  See core/Automation/Tasks/Task/CreateInvoices.php  Specifically see the run() and isTimeToRun() and createRenewingServiceInvoices() methods

Thanks! I will check that out and see if I can figure out a solution.
I really appreciate the help! Will post back here if I am able to get it working.
--Jason

Link to comment
Share on other sites

  • 0

Wanted to follow up with the solution I used.

Thanks so much for pointing me in the right direction @Jono!  I moved a variation of my the code to the CreateInvoices.php page (core/Automation/Tasks/Task/CreateInvoices.php) and that has worked perfectly (so far).

In case anyone else was curious what I did ... I added an if statement after "private function process() {" that blocked the creation of the invoices on weekends. The invoice for the service is still created, but pushed until a later day. It didn't alter the service renewal dates, it simply altered when the invoice was created/sent.

No guarantee it will work for anyone else, or that it won't have unintended consequences, but it seems to work perfectly for what I needed.
Thanks again @Jono and @Paul for the help!

  private function process()
    {
		
		//  Don't process renewal invoices if it is Saturday, Sunday or Christmas 
		if ((date('N') >= 6) || (strtotime(date('Y-12-25')) == strtotime(date('Y-m-d'))) ) { $output = ""; } else {
			

            // Create invoices for renewing services
            $this->createRenewingServiceInvoices();

            // Create recurring invoices
            $this->createRecurringInvoices();

		}
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...