NAME
App::WHMCSUtils - CLI utilities related to WHMCS
VERSION
This document describes version 0.012 of App::WHMCSUtils (from Perl distribution App-WHMCSUtils), released on 2021-11-30.
FUNCTIONS
calc_deferred_revenue
Usage:
calc_deferred_revenue(%args) -> [$status_code, $reason, $payload, \%result_meta]
Deferring revenue is the process of recognizing revenue as you earn it, in contrast to as you receive the cash. This is the principle of accrual accounting, as opposed to cash-based accounting.
For example, suppose on Nov 1, 2019 you receive an amount of $12 for 12 months of hosting (up until Oct 31, 2020). In cash-based accounting, you immediately recognize the $12 as revenue on Nov 1, 2019. In accrual accounting, you recognize $1 revenue for each month you are performing the hosting obligation, for 12 times, from Nov 2019 to Oct 2020.
As another example, suppose you have three invoices:
invoice num type amount note
----------- ------ ------ ----
1001 domain registration 10.5 example.com, from 2019-11-11 to 2020-11-10
1002 hosting 9.0 example.com, from 2019-11-11 to 2020-02-10 (3 months)
1003 hosting 12.0 example.com, from 2019-11-01 to 2020-04-30 (6 months)
The first invoice is not deferred, since we have earned (or performed the obligation of domain registration) immediately. The second and third invoices are deferred. This is how the deferment will go:
invoice \ period 2019-11 2019-12 2020-01 2020-02 2020-03 2020-04
---------------- ------- ------- ------- ------- ------- -------
1001 10.5
1002 3.0 3.0 3.0
1003 2.0 2.0 2.0 2.0 2.0 2.0
TOTAL 15.5 5.0 5.0 2.0 2.0 2.0
This utility collects invoice items from paid invoices, filters eligible ones, then defers the revenue to separate months for items that should be deferred (determined using some heuristic and additionally configurable options), and finally sums the amounts to calculate total monthly deferred revenues.
This utility can also be instructed (via setting the full
option to true) to output the full CSV report (each items with their categorizations and deferred revenues).
Recognizes English and Indonesian description text.
Categorization heuristics:
Fund deposits are not recognized as revenues.
Hosting revenues are deferred, but when the description indicates starting and ending dates and the dates are not too old.
Domain and addon revenues are not deferred, they are recognized immediately.
Other items will be assumed as immediate revenues.
Extra rules (applied first) can be specified via the extra_rules
option.
To use this utility, install the Perl CPAN distribution App::WHMCSUtils. Then, create a configuration file ~/whmcs-calc-deferred-revenue.conf
containing something like:
db_name=YOURDBNAME
db_host=YOURDBHOST
db_user=YOURDBUSER
db_pass=YOURDBPASS
db_host
defaults to localhost
. db_user
and db_pass
can be omitted if you have /etc/my.cnf
or ~/.my.cnf
. This utility can search for username/password from those files.
You can also add other configuration like extra_rules
, e.g.:
extra_rules=[{"type": "^$", "description": "^(?^i)sewa\\b.*ruang", "category": "rent"}]
You can then run the utility for the desired, e.g.:
% whmcs-calc-deferred-revenue --date-start 2013-01-01 --date-end 2017-10-31 \
--date-old-limit 2013-01-01 --full --output-file ~/output.csv
Wait for a while and check the output at ~/output.csv
.
This function is not exported.
Arguments ('*' denotes required arguments):
date_end => date
End at this date (based on invoice payment date).
date_old_limit => date
Set what date will be considered too old to recognize item as revenue.
Default is 2008-01-01.
date_start => date
Start from this date (based on invoice payment date).
db_host => str (default: "localhost")
db_name* => str
db_pass => str
db_port => net::port (default: 3306)
db_user => str
extra_rules => array[hash]
Example (in JSON):
[ { "type": "^$", "description": "^SEWA", "category": "rent" } ]
full => true
output_file => filename
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
restore_whmcs_client
Usage:
restore_whmcs_client(%args) -> [$status_code, $reason, $payload, \%result_meta]
Restore a missing client from SQL database backup.
This function is not exported.
This function supports dry-run operation.
Arguments ('*' denotes required arguments):
client_email => str
client_id => posint
restore_domains => bool (default: 1)
restore_hostings => bool (default: 1)
restore_invoices => bool (default: 1)
sql_backup_dir => dirname
Directory containing per-table SQL files.
sql_backup_file => filename
Can accept either
.sql
or.sql.gz
.Will be converted first to a directory where the SQL file will be extracted to separate files on a per-table basis.
Special arguments:
-dry_run => bool
Pass -dry_run=>1 to enable simulation mode.
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
send_verification_emails
Usage:
send_verification_emails(%args) -> [$status_code, $reason, $payload, \%result_meta]
Send verification emails for clients who have not had their email verified.
WHMCS does not yet provide an API for this, so we do this via a headless browser.
This function is not exported.
This function supports dry-run operation.
Arguments ('*' denotes required arguments):
action => str (default: "send-verification-emails")
The default action is to send verification emails. You can also just list the clients who haven't got their email verified yet.
admin_password* => str
admin_username* => str
db_host => str (default: "localhost")
db_name* => str
db_pass => str
db_port => net::port (default: 3306)
db_user => str
hook_set_sender_email => str|code
Hook to set sender email for every email.
Hook will receive these arguments:
($client_rec, $orig_sender_email)
$client_rec
is a hash containing client record fields, e.g.id
,email
,firstname
,lastname
, etc.$orig_sender_email
is the original sender email setting (Email
setting in the configuration table).Hook is expected to return the sender email.
include_active => bool (default: 1)
Whether to include active clients.
include_client_ids => array[uint]
include_client_ids_from => filename
include_inactive => bool (default: 0)
Whether to include inactive clients.
limit => uint
Only process this many clients then stop.
mech_user_agent => str
random => bool (default: 1)
url* => url
It should be without
/admin
part, e.g.:https://client.mycompany.com/
Special arguments:
-dry_run => bool
Pass -dry_run=>1 to enable simulation mode.
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-WHMCSUtils.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-WHMCSUtils.
SEE ALSO
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTOR
Steven Haryanto (on pc-office) <steven@masterweb.com>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2021, 2019, 2018, 2017 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-WHMCSUtils
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.