More work on hooks.php
More content for README
This commit is contained in:
parent
0a435d2ae3
commit
23b960da54
3 changed files with 44 additions and 29 deletions
21
README.md
21
README.md
|
@ -2,11 +2,14 @@
|
|||
|
||||
## Summary
|
||||
|
||||
This module allows you to select the account that you want a specific invoice item to be assigned to in accounting.
|
||||
This module allows you to select the account that you want a specific invoice
|
||||
item to be assigned to in accounting.
|
||||
|
||||
This was a specific requirement for a client, but the concept of displaying a dynamic list of values for a custom invoice item field may be useful to others.
|
||||
This was a specific requirement for a client, but the concept of displaying a
|
||||
dynamic list of values for a custom invoice item field may be useful to others.
|
||||
|
||||
This addon is a fork of the [WHMCS Sample Addon Module](https://github.com/WHMCS/sample-addon-module) and, as such, is licensed under the MIT License.
|
||||
This addon is a fork of the [WHMCS Sample Addon Module](https://github.com/WHMCS/sample-addon-module)
|
||||
and, as such, is licensed under the MIT License.
|
||||
|
||||
## Minimum Requirements
|
||||
|
||||
|
@ -16,7 +19,17 @@ http://docs.whmcs.com/System_Requirements
|
|||
We recommend your module follows the same minimum requirements wherever
|
||||
possible.
|
||||
|
||||
## Installation
|
||||
|
||||
Simply download the repository as a zip file, extract the contents and upload
|
||||
the `modules/addons/accounting` directory to the same location within your
|
||||
WHMCS installation.
|
||||
|
||||
Alternatively, you can clone the repository to a location outside of your
|
||||
WHMCS installation and create a symbolic link to the `modules/addons/accounting`
|
||||
directory.
|
||||
|
||||
## License
|
||||
|
||||
This module is licensed under the MIT License. Please see the LICENSE file for
|
||||
more information.
|
||||
more information.
|
||||
|
|
|
@ -21,12 +21,26 @@ add_hook('InvoiceEdit', 1, function(array $params) {
|
|||
try {
|
||||
// Get the invoice ID from the parameters.
|
||||
$invoiceId = $params['invoiceid'];
|
||||
|
||||
// When the invoice is saved, update the invoice items with the
|
||||
// selected account.
|
||||
if (isset($_POST['accountSelector'])) {
|
||||
foreach ($_POST['accountSelector'] as $invoiceItemId => $account) {
|
||||
Capsule::table('mod_accounting')
|
||||
->where('invoice', $invoiceId)
|
||||
->where('item', $invoiceItemId)
|
||||
->update(['account' => $account]);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the invoice items from the database.
|
||||
$invoiceItems = Capsule::table('tblinvoiceitems')
|
||||
->where('invoiceid', $invoiceId)
|
||||
$invoiceItems = Capsule::table('mod_accounting')
|
||||
->where('invoice', $invoiceId)
|
||||
->get();
|
||||
|
||||
// Get the available accounts from the module configuration.
|
||||
$availableAccounts = explode("\n", $params['Available Accounts']);
|
||||
|
||||
// Create the drop-down field for each invoice item.
|
||||
foreach ($invoiceItems as $invoiceItem) {
|
||||
$accountSelector = '<select name="accountSelector[' . $invoiceItem->id . ']">';
|
||||
|
@ -34,23 +48,24 @@ add_hook('InvoiceEdit', 1, function(array $params) {
|
|||
$accountSelector .= '<option value="' . $availableAccount . '">' . $availableAccount . '</option>';
|
||||
}
|
||||
$accountSelector .= '</select>';
|
||||
|
||||
// Add the drop-down field to the invoice item.
|
||||
echo '<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("input[name=\'description[' . $invoiceItem->id . ']\']").before("' . $accountSelector . '");
|
||||
});
|
||||
</script>';
|
||||
|
||||
// Select the account that was previously selected for the invoice
|
||||
// item.
|
||||
echo '<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("select[name=\'accountSelector[' . $invoiceItem->id . ']\']").val("' . $invoiceItem->account . '");
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Consider logging or reporting the error.
|
||||
}
|
||||
});
|
||||
|
||||
add_hook('ClientEdit', 1, function(array $params) {
|
||||
try {
|
||||
// Call the service's function, using the values provided by WHMCS in
|
||||
// `$params`.
|
||||
} catch (Exception $e) {
|
||||
// Consider logging or reporting the error.
|
||||
// Log the error
|
||||
logActivity('Accounting Error: ' . $e->getMessage());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.6/phpunit.xsd"
|
||||
bootstrap="tests/_bootstrap.php"
|
||||
cacheTokens="false"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="WHMCS Sample Addon Module Tests">
|
||||
<directory suffix=".php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
Loading…
Reference in a new issue