Skip to content

2. Setting up cronjobs

Bohdan Zemlianskyi edited this page Jul 25, 2019 · 8 revisions

Add the following command to your cronjobs:

# run invoice generator at 01:00 on the first day of each month
0 0 1 * *    /usr/bin/php -q {WHMCS}/modules/servers/onappusers/cronjobs/generate-invoices.php

{WHMCS} is the full path to your WHMCS directory.

DO NOT SETUP INVOICE GENERATOR BEFORE TESTING (SEE BELOW)!

Advanced usage

#####Invoice generator By default it generates customers invoices relying on collected statistics for the previous month.
As usual it should be run once a month when you want generate invoices.

You can force generator to generate invoices for the certain period by passing desired starting and ending dates in format 'YYYY-MM-DD HH:MM' as a parameters:

/usr/bin/php -q {WHMCS}/modules/servers/onappusers/cronjobs/generate-invoices.php --since='2016-08-15 00:00' --till='2016-09-15 23:00'

for the proper calculation all dates should be entered in the server's timezone

Auto apply money from the credit to the invoices when generated:

/usr/bin/php -q {WHMCS}/modules/servers/onappusers/cronjobs/generate-invoices.php --autoapplycredit

Testing invoice generator

We strongly recommend to test invoice generator before using in production to be sure that it works properly.
For testing you should setup statistics collector (or run it from console) and run tester:

# test invoices for previous month
/usr/bin/php -q {WHMCS}/modules/servers/onappusers/cronjobs/test.php -l

# test invoices for current month
/usr/bin/php -q {WHMCS}/modules/servers/onappusers/cronjobs/test.php -l --since='2016-10-01 00:00'

# test invoices for certain WHMCS user (WHMCS user id = 1234)
/usr/bin/php -q {WHMCS}/modules/servers/onappusers/cronjobs/test.php -l --since='2016-10-01 00:00' --whmcsuserid=1234

Tester functionally is the same as generator itself, but it writes processed data to the file for review instead of generating real invoices.

Prepay usage

You can enable hourly billing in product settings, and generate invoices by next command:

/usr/bin/php -q {WHMCS}/modules/servers/onappusers/cronjobs/hourly.php -l

Clone this wiki locally