crater-invoice / crater

Open Source Invoicing Solution for Individuals & Businesses
https://craterapp.com
GNU Affero General Public License v3.0
7.71k stars 1.6k forks source link

Recurring Invoices are not created on defined date #912

Closed Pazekal90 closed 2 years ago

Pazekal90 commented 2 years ago

Describe the bug Recurring Invoices are not created on defined date when using the regex pattern. It should have created this invoice on 09 April 22. But it didn't. I rely on this function properly working :/ Now i have to look on those dates every week or so :/

Screenshots

Bildschirmfoto 2022-04-30 um 23 16 15

Please complete the following information:

rihards-simanovics commented 2 years ago

Hi @Pazekal90, in order for the application to create an invoice every x amount of time you need to setup a scheduled task in crontabs. please refer to these docs to create one: https://docs.craterapp.com/guide/recurring-invoices.html

In your case I would suggest using the following expression (will run - every minute, but don't worry if there is no tasks scheduled it will be ignored by the crater app): * * * * * user_owning_crater_dir /path/to/php/bin_ver/if/not/set/globally/php /path/to/root/folder/artisan schedule:run e.g. * * * * * crater_app php7.4 /var/www/vhosts/crater.root.folder/artisan schedule:run

Pazekal90 commented 2 years ago

Hi @Pazekal90, in order for the application to create an invoice every x amount of time you need to setup a scheduled task in crontabs. please refer to these docs to create one: https://docs.craterapp.com/guide/recurring-invoices.html

In your case I would suggest using the following expression (will run - every minute, but don't worry if there is no tasks scheduled it will be ignored by the crater app): * * * * * user_owning_crater_dir /path/to/php/bin_ver/if/not/set/globally/php /path/to/root/folder/artisan schedule:run e.g. * * * * * crater_app php7.4 /var/www/vhosts/crater.root.folder/artisan schedule:run

Oh ok. Sorry i didn't know that. Is there a way of running this schedule script via API or via web hook? I ask because i have no dedicated server environment and "only" a hosted environment with no access to shell.

rihards-simanovics commented 2 years ago

Hi @Pazekal90, I see, don't worry. Most hosting providers have a way to create scheduled tasks; otherwise, WordPress wouldn't work anywhere 🤣.

However, I must warn you, doing it with me would be slower as I don't have access to their control panel, so perhaps you should contact your host's support team first and tell them that you need to set up a scheduled task (crontab) for your app. I'm sure they will be happy to help. Another way will be to look through their FAQ if they have it.

When you have time, can you tell me who is your hosting provider and what subscription or plan you have? This will give me some idea of what functionality access you may have.

enoversum commented 2 years ago

Hi @Pazekal90, I see, don't worry. Most hosting providers have a way to create scheduled tasks; otherwise, WordPress wouldn't work anywhere 🤣.

Well, WordPress often triggers its scheduling simply by someone visiting the front end of a website, and also on WordPress some plugins that need to follow a fixed schedule require you to set up cronjobs. You can watch that when a point release update is coming in and WordPress sends out a notification that your website has been updated—on low-traffic websites, that can take a few days to happen.

NicoHood commented 2 years ago

I ran into the same issue, as it was not mentioned in the installation guide. Could you please add it there as well?

https://docs.craterapp.com/installation.html

rihards-simanovics commented 2 years ago

Hi @mohitpanjwani, I think it might be good to add a reference to the recurring invoice in the introduction. Certain people will have trouble with this, especially if they have never worked with laravel before, also because it is an essential part of the software to work fully.

I can't find any projects under crater-invoice that would allow updating the docs through the Github PR, so I assume it's not made public.

Pazekal90 commented 2 years ago

Hi @Pazekal90, I see, don't worry. Most hosting providers have a way to create scheduled tasks; otherwise, WordPress wouldn't work anywhere 🤣.

Well, WordPress often triggers its scheduling simply by someone visiting the front end of a website, and also on WordPress some plugins that need to follow a fixed schedule require you to set up cronjobs. You can watch that when a point release update is coming in and WordPress sends out a notification that your website has been updated—on low-traffic websites, that can take a few days to happen.

I fully agree here. They use the views to start those processes in the background. Is there a way of using a web cron provider that triggers a specific url with credentials to start the process of recurring invoice generation?

I checked twice and my hosting provider does not provide any option to create tasks. Not via SSH and not in their control panel.

rihards-simanovics commented 2 years ago

@Pazekal90 Wow, sorry to hear that. In that case, my initial suggestion would be to go to another hosting provider or get a VPS with your current one. I use IONOS, and their VPSs are very cheap compared to some others I used and are very reliable.

However, if that is not an option for you and you got a contract, you may need to go about it creatively. I think what you can do is create a PHP file that can be in a root dir, and it would then trigger the artisan schedule:run. This way, you can then create a web cron. I haven't done that before, so I don't know if you can trigger PHP-CLI like this, but I will do some research and get back.

Edit 1: ok, after some research, it appears that you can use https://www.php.net/manual/en/function.exec.php. I will need to try it, but not today. I will let you know tomorrow what I can come up with. Until then, getting the VPS would be the quicker & cheaper option.

Pazekal90 commented 2 years ago

@Pazekal90 Wow, sorry to hear that. In that case, my initial suggestion would be to go to another hosting provider or get a VPS with your current one. I use IONOS, and their VPSs are very cheap compared to some others I used and are very reliable.

However, if that is not an option for you and you got a contract, you may need to go about it creatively. I think what you can do is create a PHP file that can be in a root dir, and it would then trigger the artisan schedule:run. This way, you can then create a web cron. I haven't done that before, so I don't know if you can trigger PHP-CLI like this, but I will do some research and get back.

Edit 1: ok, after some research, it appears that you can use https://www.php.net/manual/en/function.exec.php. I will need to try it, but not today. I will let you know tomorrow what I can come up with. Until then, getting the VPS would be the quicker & cheaper option.

Did you try it out? Something new on this?

rihards-simanovics commented 2 years ago

Hi, sorry, not yet. I've been busy at work and completely forgot. I don't know if I will have time this week but feel free to try it yourself in the meantime.

rihards-simanovics commented 2 years ago

Hi again @Pazekal90, so it worked for me, but I don't know how well it will work for you as this may be blocked by your hosting provider, in other words, no guarantees. in the ./public/ dir (assuming it is your root dir), create a file with obscured name, something like cron-tasks-jib4ksjc8.php and place the following code into it:

<?php
// DEBUG START: Comment the below code when running in production.
echo "Running the Scheduled tasks:<br>"; // Just a title in case you want to "see" the result
// DEBUG END

exec( "./../artisan schedule:run", $o ); // Command will begin in ./public move back to root and execute artisan schedule command

// DEBUG START: Comment the below code when running in production.
echo "<pre>";
print_r($o);
echo "</pre>";
// DEBUG END
?>

When you visit the https://your-hostname/cron-tasks-jib4ksjc8.php, you should see the following output:

Running the Scheduled tasks:
Array
(
    [0] => No scheduled commands are ready to run.
)

After this, you can create a web cron and target that URL every minute.

rihards-simanovics commented 2 years ago

If this fixes your specific issue, please don't forget to close this issue.

PS: I forgot to mention, but there might be a potential issue with updates. Not sure if public folder content gets removed, so you may want to add a .gitignore and make a backup of the file if the update removes it.

Pazekal90 commented 2 years ago

Hi again @Pazekal90, so it worked for me, but I don't know how well it will work for you as this may be blocked by your hosting provider, in other words, no guarantees. in the ./public/ dir (assuming it is your root dir), create a file with obscured name, something like cron-tasks-jib4ksjc8.php and place the following code into it:

<?php
// DEBUG START: Comment the below code when running in production.
echo "Running the Scheduled tasks:<br>"; // Just a title in case you want to "see" the result
// DEBUG END

exec( "./../artisan schedule:run", $o ); // Command will begin in ./public move back to root and execute artisan schedule command

// DEBUG START: Comment the below code when running in production.
echo "<pre>";
print_r($o);
echo "</pre>";
// DEBUG END
?>

When you visit the https://your-hostname/cron-tasks-jib4ksjc8.php, you should see the following output:

Running the Scheduled tasks:
Array
(
    [0] => No scheduled commands are ready to run.
)

After this, you can create a web cron and target that URL every minute.

Nice. thanks. Already tried but unfortunately there is no output in debug mode. Also changed one of my recurring invoices to today but it did not launch. Do you know why?

image image
Pazekal90 commented 2 years ago

Seems like the exec command is not even triggered.

rihards-simanovics commented 2 years ago

Yeah, it looks like PHP-CLI is either disabled or blocked (presumably for security reasons). However, let's debug this real quick because this could also mean you were executing the script from the wrong location (blank response, I had that during debugging).

So let's change the the exec command to see if it even works, where it says exec( "./../artisan schedule:run", $o ); change that to exec( "ls", $o ); for Linux or exec( "dir", $o ); for Windows. send your output here.

Pazekal90 commented 2 years ago

@rihards-simanovics That works.

image
rihards-simanovics commented 2 years ago

Interesting, can you confirm that the file artisan exists one level up from the public folder (in root dir), also is it Windows or Linux you are running? you may need to change forward-slash / to backslash \ if in Windows. I've just re-checked if everything still works on my end and the relative path seems to work fine, try ../artisan schedule:run.

Pazekal90 commented 2 years ago

@rihards-simanovics: Running on linux.. But i found out what the problem was. I needed to change the permissions on the file so the owner can execute. It now has 740 and it is working. Nice... Thanks for your help.

I would like to reward you for your help. Do you accept sponsors?

Pazekal90 commented 2 years ago

Maybe that method is worth to mention in the docs @mohitpanjwani for users like me with a hosting environment without ssh ?

rihards-simanovics commented 2 years ago

Hi @Pazekal90, I see. I forgot about that; yes, that would make sense. As for the reward, don't worry. I'm just glad I could help. Though if you really feel strongly about it I will check if there is a way to do it on Github.

Pazekal90 commented 2 years ago

Hi @Pazekal90, I see. I forgot about that; yes, that would make sense. As for the reward, don't worry. I'm just glad I could help. Though if you really feel strongly about it I will check if there is a way to do it on Github.

Thank you. Next time you help we will do that here on GitHub with sponsors.

CountOlaf87 commented 1 year ago

I'm trying to make this work with a docker install, for me the documentation is not very clear on that, do I still need to run something?

JanLlamaman commented 1 year ago

Hi again @Pazekal90, so it worked for me, but I don't know how well it will work for you as this may be blocked by your hosting provider, in other words, no guarantees. in the ./public/ dir (assuming it is your root dir), create a file with obscured name, something like cron-tasks-jib4ksjc8.php and place the following code into it:

<?php
// DEBUG START: Comment the below code when running in production.
echo "Running the Scheduled tasks:<br>"; // Just a title in case you want to "see" the result
// DEBUG END

exec( "./../artisan schedule:run", $o ); // Command will begin in ./public move back to root and execute artisan schedule command

// DEBUG START: Comment the below code when running in production.
echo "<pre>";
print_r($o);
echo "</pre>";
// DEBUG END
?>

When you visit the https://your-hostname/cron-tasks-jib4ksjc8.php, you should see the following output:

Running the Scheduled tasks:
Array
(
    [0] => No scheduled commands are ready to run.
)

After this, you can create a web cron and target that URL every minute.

I tried to use this method for my hosting provider as well but got the error that my php version too old even though that it shows PHP Version 8.1.16 if I check with phpinfo in the same file.

Running the Scheduled tasks: Array ( [0] => [1] => Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.4.0". You are running 7.2.34-nmm7. in /www/htdocs/wb23456/invoice.domain.nz/vendor/composer/platform_check.php on line 24 )

any idea why?

rihards-simanovics commented 1 year ago

Hey @JanLlamaman what kind of hosting you use, shared, VPS, or dedicated server?

It's likely that the PHP version bundled with the OS is the one that is being used to execute the file, check your Nginx/Apache configs to ensure it uses the version of PHP you need.

Lastly you could try updating the composer dependencies. Otherwise need more info, i.e. nginx/Apache logs, Laravel logs, etc.

JanLlamaman commented 1 year ago

hey @rihards-simanovics, I got it sorted.

I needed to explicit change the version for the php-cli as it's using php 7.2 by default.

exec("php81 ./../artisan schedule:run", $o );

JanLlamaman commented 1 year ago

@rihards-simanovics My cron is being executed but the Invoices are still not being created on the date

Running the Scheduled tasks: Array ( [0] => No scheduled commands are ready to run. )