How to execute script

We found that they are some scripts useful - email_expire_services_to_representatives.php

Can we can use it in scheduled jobs?

Hello,

I see no reason why you could not.

Regards,
Marc

Hello Marc.

Is it possible to be more specific ā€œstep by stepā€ how to add scheduled job for script email_expire_services_to_customers.php ?

Thanks in advance,
George

Hi Georges,

This will depend on your environment. Under linux (preferred), you will add a task in the crontab, something like :
0 8 * * * apache /home/dolibarr/scripts/contracts/email_expire_services_to_customers.php test contacts

Replace the ā€˜/home/dolibarrā€™ with the path to your installation and apache by the user that runs php in your website. Then, look at the script for proper options (you probably want to replace test by confirm and specify dates). And look at cron manual for adequate perodicity. The example above will run everyday at 8am.

On windows, you have to define a scheduled task, I am not familiar with that but it would work the same way.

Hope this helps,
Kind regards,
Marc

Hello Marc.
Still I canā€™t make it work.

I have a hosting on PLESK panel (under Linux).
I have added crontab https://prntscr.com/1qevxj0 to run every 5 minutes. Also replaced the ā€˜/home/dolibarrā€™ with the path of my installation(/var/www/vhosts/scripts/contracts/email_expire_services_to_customers.php) and apache by the user (/opt/plesk/php/7.4/bin/php)

Command

/opt/plesk/php/7.4/bin/php /var/www/vhosts/scripts/contracts/email_expire_services_to_customers.php

I donā€™t understand the third part to look at the script for proper options ā€œyou probably want to replace test by confirm and specify datesā€ .

Iā€™m sorry if Iā€™m hard to understand. Iā€™m completely newbie to Dolibarr.

Thanks in advance.
George

Hi Georges,

On top of the script, you find these drivers :

    print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
	print "\n";
	print "Send an email to customers to remind all contracts services to expire or expired.\n";
	print "If you choose 'test' mode, no emails are sent.\n";
	print "If you add param delay (nb of days), only services with expired date < today + delay are i
ncluded.\n";
	print "If you add param after (nb of days), only services with expired date >= today + delay are 
included.\n";

This may help adjust the command line parameters.
Could you be more explicit on ā€œit daesā€™nt workā€ => error messages, screenshots, logfile excerpts, whatever may helpā€¦
Regards,
Marc

Hi Marc.

Well, I feel like something is missing in the whole process.
I have Dolibarr ver. 14.0.0 and the installation is in httpdocs folder. The ā€œscriptsā€ folder is outside of it.
I have not specified anywhere in Dolibarr where is located ā€œscriptsā€ folder.
How is it referenced to the data?

When I said, ā€œStill I canā€™t make it work.ā€ I meant that cronjob that I specify returned me an error(Screenshot by Lightshot) .

I thought it would be almost the same process as setting up Scheduled Jobs from Admins Tools with a URL that check and launch qualified cron jobs from a browser.

Thanks.
Regards,
George

Looks like you havenā€™t specified 2 mandatory arguments, that is

  1. test or confirm
  2. thirdparties or contacts

Regards
Marc

1 Like

Hi Marc.
I really appreciate your help. Thank you.

I just fixed it with the below command:

/opt/plesk/php/7.4/bin/php /var/www/vhosts/scripts/domain/contracts/email_expire_services_to_customers.php confirm thirdparties

and Ī™ also had error on file ā€œemail_expire_services_to_customers.phpā€ line 55 on required path.

require $path."ā€¦/ā€¦/htdocs/master.inc.php";

I would like to ask you if is there a possibility to send notification emails 30, 15, 7 and 2 days before the end of the service as well as if there is a possibility to record it on event reports.

Thanks in advance.
Regards,
George

Hello @simicar

Is it possible, when the script(contracts/email_expire_services_to_customers.php) is executing, to record it on agenda event reports in order to display it on Third party notifications tab (List of all automatic email notifications sent)?

Thanks in advance

Regards
George

Hi George,

For this you will have to extend the script to add the action event definitions, as is done in htdocs/core/actions_sendmails.inc.php, and call the trigger CONTRACT_SENTBYMAIL that should do the job.

Regards,
Marc