diff --git a/README.md b/README.md
index 1ad239f..9a3763a 100644
--- a/README.md
+++ b/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.
\ No newline at end of file
+more information.
diff --git a/modules/addons/accounting/hooks.php b/modules/addons/accounting/hooks.php
index 9e86cb4..bad2325 100644
--- a/modules/addons/accounting/hooks.php
+++ b/modules/addons/accounting/hooks.php
@@ -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 = '';
+
// Add the drop-down field to the invoice item.
echo '';
+
+ // Select the account that was previously selected for the invoice
+ // item.
+ echo '';
}
} 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());
}
});
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
deleted file mode 100644
index 6148c8e..0000000
--- a/phpunit.xml.dist
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
- ./tests/
-
-
-