-
-
-
-
- {{ 'FORM.LABELS.TRANSACTION' | translate }}s
-
-
+
+
- {{ 'VOUCHERS.COMPLEX.ADD_ITEMS' | translate }}
+ class="btn btn-default"
+ id="recover"
+ ng-class="{ 'btn-primary' : ComplexVoucherCtrl.Voucher.hasCacheAvailable() }"
+ ng-click="ComplexVoucherCtrl.Voucher.readCache()"
+ ng-disabled="!ComplexVoucherCtrl.Voucher.hasCacheAvailable() || ComplexVoucherCtrl.Voucher.hasRecoveredCache || ComplexVoucherForm.$submitted">
+ {{ "FORM.BUTTONS.RECOVER_ITEMS" | translate }}
-
-
+
+
+
+
+ {{ "FORM.BUTTONS.ADD" | translate }}
+
+
+
+
+
-
-
-
-
-
- {{ ComplexVoucherCtrl.notifyMessage.label | translate }}
-
-
+
+
+
-
- {{ "FORM.BUTTONS.SUBMIT" | translate }}
-
-
+
+
+
+ {{ ComplexVoucherCtrl.Voucher._error | translate }}
+
+
+
+
+
+ {{ "FORM.BUTTONS.CLEAR" | translate }}
+
+
+
+ {{ "FORM.BUTTONS.SUBMIT" | translate }}
+
diff --git a/client/src/partials/vouchers/complex.js b/client/src/partials/vouchers/complex.js
index 1633208ad8..dae5702f33 100644
--- a/client/src/partials/vouchers/complex.js
+++ b/client/src/partials/vouchers/complex.js
@@ -1,11 +1,11 @@
angular.module('bhima.controllers')
-.controller('ComplexJournalVoucherController', ComplexJournalVoucherController);
+ .controller('ComplexJournalVoucherController', ComplexJournalVoucherController);
ComplexJournalVoucherController.$inject = [
- 'VoucherService', '$translate', 'AccountService', 'CurrencyService',
- 'SessionService', 'FindEntityService', 'FindReferenceService',
- 'NotifyService', 'CashboxService', 'VoucherToolkitService', 'ReceiptModal',
- 'bhConstants', 'GridAggregatorService', 'uiGridConstants'
+ 'VoucherService', '$translate', 'CurrencyService', 'SessionService',
+ 'FindEntityService', 'FindReferenceService', 'NotifyService',
+ 'VoucherToolkitService', 'ReceiptModal', 'bhConstants', 'GridAggregatorService',
+ 'uiGridConstants', 'VoucherForm'
];
/**
@@ -17,14 +17,30 @@ ComplexJournalVoucherController.$inject = [
* @constructor
*
* @todo - Implement caching mechanism for incomplete forms (via AppCache)
- * @todo - Implement Patient Invoices data and Cash Payment data for modal
- * @todo - Implement a mean to categorise transactions for cashflow reports
* @todo/@fixme - this error notification system needs serious refactor.
*/
-function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currencies, Session, FindEntity, FindReference, Notify, Cashbox, Toolkit, Receipts, bhConstants, GridAggregators, uiGridConstants) {
+function ComplexJournalVoucherController(Vouchers, $translate, Currencies, Session, FindEntity, FindReference, Notify, Toolkit, Receipts, bhConstants, GridAggregators, uiGridConstants, VoucherForm) {
var vm = this;
+ // bind constants
vm.bhConstants = bhConstants;
+ vm.enterprise = Session.enterprise;
+ vm.itemIncrement = 1;
+ vm.timestamp = new Date();
+
+ // bind the complex voucher form
+ vm.Voucher = new VoucherForm('ComplexVouchers');
+
+ // fired to clear the grid
+ vm.clear = function clear() {
+ vm.Voucher.clear();
+ };
+
+ // fired on changes
+ vm.onChanges = function onChanges() {
+ vm.Voucher.onChanges();
+ vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.EDIT);
+ };
// bread crumb paths
vm.paths = [{
@@ -40,14 +56,11 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
option: Toolkit.options
}];
- // global variables
- var MIN_DECIMAL_VALUE= bhConstants.lengths.minDecimalValue;
- var MIN_PRECISION_VALUE = getDecimalPrecision(MIN_DECIMAL_VALUE);
-
// ui-grid options
vm.gridOptions = {
appScopeProvider : vm,
- fastWatch : true,
+ //fastWatch : true,
+ flatEntityAccess : true,
enableSorting : false,
enableColumnMenus : false,
showColumnFooter : true,
@@ -74,11 +87,9 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
vm.rows = result.rows;
vm.rows.forEach(function (item) {
- checkRowValidity(item.index);
});
- vm.gridOptions.data = vm.rows;
- refreshState();
+ // vm.gridOptions.data = vm.rows;
conventionPaymentDetails(result.convention);
});
}
@@ -86,34 +97,24 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
// set convention payment details
function conventionPaymentDetails(convention) {
vm.financialTransaction = true;
+
var conventionType = vm.incomes.filter(function (item) {
return item.id === 3;
})[0];
+
vm.voucher.type_id = JSON.stringify(conventionType);
vm.voucher.description = convention.name;
vm.defaultIncomeTypeId = 3;
- buildDescription();
}
/** ======================== end voucher tools ======================= */
-
// bind the startup method as a reset method
vm.submit = submit;
vm.currencySymbol = currencySymbol;
- vm.addVoucherItem = addVoucherItem;
- vm.removeVoucherItem = removeVoucherItem;
- vm.checkRowValidity = checkRowValidity;
vm.openEntityModal = openEntityModal;
vm.openReferenceModal = openReferenceModal;
- // load the list of accounts
- Accounts.read()
- .then(function (accounts) {
- vm.accounts = accounts;
- })
- .catch(Notify.handleError);
-
// load the available currencies
Currencies.read()
.then(function (currencies) {
@@ -146,208 +147,9 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
return Currencies.symbol(currency_id);
}
- /** Add transaction row */
- function addVoucherItem() {
- vm.rows.push(generateRow());
- refreshState();
- }
-
- /** remove transaction row */
- function removeVoucherItem(index) {
- vm.rows.splice(index, 1);
- refreshState();
- }
-
- /** generate row element */
- function generateRow() {
- var index = vm.rows.length || 0;
- return {
- index : index,
- account_id : undefined,
- debit : 0,
- credit : 0,
- document_uuid : undefined,
- entity_uuid : undefined
- };
- }
-
- /** clean and generate voucher correct data */
- function handleVoucher() {
-
- buildDescription();
-
- var voucher;
- var voucherTypeId = vm.voucher.type_id ? JSON.parse(vm.voucher.type_id).id : null;
- var voucherDescription = vm.descriptionPrefix.concat('/', vm.voucher.description);
-
- if (vm.sumCredit === vm.sumDebit) {
- voucher = {
- project_id : Session.project.id,
- date : vm.voucher.date,
- description : voucherDescription,
- currency_id : vm.voucher.currency_id,
- amount : vm.sumDebit,
- user_id : Session.user.id,
- type_id : voucherTypeId
- };
- }
-
- return voucher;
- }
-
- /** clean and generate voucher items data */
- function handleVoucherItems() {
- var voucherItems;
- var account_id;
- var entity_uuid;
- var document_uuid;
-
- voucherItems = vm.rows.map(function (row) {
-
- account_id = row.account && row.account.id ? row.account.id : '';
- entity_uuid = row.entity && row.entity.uuid ? row.entity.uuid : '';
- document_uuid = row.reference && row.reference.uuid ? row.reference.uuid : '';
-
- return {
- account_id : account_id,
- debit : row.debit,
- credit : row.credit,
- document_uuid : document_uuid,
- entity_uuid : entity_uuid
- };
-
- });
-
- return voucherItems;
- }
-
- /** validation function */
- function validRowsInput() {
-
- // validate amount
- var allValidAmount = vm.rows.every(function (row) {
-
- // must have a one non-zero value
- var validAmount =
- ((row.debit > 0 && !row.credit) || (!row.debit && row.credit > 0)) &&
- (angular.isDefined(row.debit) && angular.isDefined(row.credit));
-
- return validAmount;
- });
-
- // validate account
- var allValidAccount = vm.rows.every(function (row) {
-
- // must have an account defined
- return row.account && row.account.id;
- });
-
- var allValidPrecision = vm.rows.every(function (row) {
- return (
- getDecimalPrecision(row.debit) <= MIN_PRECISION_VALUE &&
- getDecimalPrecision(row.credit) <= MIN_PRECISION_VALUE
- );
- });
-
- // validate that the transaction balances
- var totals = vm.rows.reduce(function (aggregate, row) {
- aggregate.debit += row.debit;
- aggregate.credit += row.credit;
- return aggregate;
- }, { debit : 0, credit : 0 });
-
- var validTotals = totals.debit === totals.credit;
-
- // use multiple validation
- return {
- validAmount : allValidAmount,
- validAccount : allValidAccount,
- validTotals : validTotals,
- validPrecision : allValidPrecision
- };
- }
-
- /** check validity and refresh all bonding data */
- function refreshState() {
- vm.posted = false;
- vm.financialTransaction = false;
- vm.rowsInput = validRowsInput();
-
- vm.validInput = (
- vm.rowsInput.validAmount && vm.rowsInput.validAccount &&
- vm.rowsInput.validPrecision && vm.rowsInput.validTotals &&
- vm.rows.length > 1
- );
-
- vm.notifyMessage =
- !vm.rowsInput.validAmount ? { icon : 'glyphicon glyphicon-alert', label : 'VOUCHERS.COMPLEX.ERROR_AMOUNT' } :
- !vm.rowsInput.validAccount ? { icon : 'glyphicon glyphicon-alert', label : 'VOUCHERS.COMPLEX.ERROR_ACCOUNT' } :
- !vm.rowsInput.validTotals ? { icon : 'glyphicon glyphicon-alert', label : 'VOUCHERS.COMPLEX.ERROR_TOTALS' } :
- !vm.rowsInput.validPrecision ? { icon : 'glyphicon glyphicon-alert', label : 'VOUCHERS.COMPLEX.ERROR_PRECISION' } :
- vm.rowsInput.validTotals && vm.validInput ? { icon : 'glyphicon glyphicon-ok-sign', label : 'VOUCHERS.COMPLEX.VALID_TOTALS' } :
- { icon : '', label : '' };
-
- summation();
- }
-
- // get the length of the portion after the decimal point.
- function getDecimalPrecision(value) {
- var valueString = String(value);
- var decimalPart = valueString.split('.')[1] || [];
- return decimalPart.length;
- }
-
- /** checking validity of a row */
- function checkRowValidity(index) {
- if (angular.isUndefined(index)) { return; }
-
- var row = vm.rows[index];
-
- /** validity of the amount */
- var hasValidAmount =
- ((!row.credit && row.debit >= MIN_DECIMAL_VALUE) || (!row.debit && row.credit >= MIN_DECIMAL_VALUE)) &&
- (angular.isDefined(row.debit) && angular.isDefined(row.credit));
-
- /** must have an account defined */
- var hasValidAccount = (row.account && row.account.id);
-
- // the amounts recorded in each line should have the correct number of
- // digits after the decimal point
- var hasValidPrecision = (
- getDecimalPrecision(row.debit) <= MIN_PRECISION_VALUE &&
- getDecimalPrecision(row.credit) <= MIN_PRECISION_VALUE
- );
-
- /** validity of the row */
- row.isValid = hasValidAccount && hasValidAmount && hasValidPrecision;
- row.hasAccount = hasValidAccount;
-
- /**
- * refresh the ui to the real state
- * This function does a lot of process but it useful for informing the user
- * it notify about :
- * -- the validity of all amount given
- * -- the validity of totals (balanced or not)
- * -- the validity of accounts
- * -- the validity of missing values
- */
- refreshState();
-
- /**
- * Check financial account
- */
- isFinancial();
- }
/** summation */
function summation() {
- vm.sumDebit = 0;
- vm.sumCredit = 0;
- vm.rows.forEach(function (row) {
- vm.sumDebit += row.debit;
- vm.sumCredit += row.credit;
- });
-
// if the gridApi is available call the datachange function to recompute footer totals
if (vm.gridApi) {
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.EDIT);
@@ -356,75 +158,17 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
/** run the module on startup and refresh */
function startup() {
- // init posted variable
- vm.posted = false;
-
- // current timestamp to limit date
- vm.timestamp = new Date();
-
- // set up default voucher values
- vm.voucher = {};
- vm.voucher.date = new Date();
-
- // setup the enterprise currency as default
- vm.voucher.currency_id = Session.enterprise.currency_id;
-
- // init voucher items with two rows
- vm.rows = [];
- vm.rows.push(generateRow());
- vm.rows.push(generateRow());
- vm.gridOptions.data = vm.rows;
-
- // init sum debit and credit
- vm.sumDebit = 0;
- vm.sumCredit = 0;
-
- // init financial accounts
- vm.financialAccount = [];
-
- Cashbox.read(null, { detailed: 1 })
- .then(function (list) {
-
- list.forEach(function (item) {
-
- if (vm.financialAccount.indexOf(item.account_id) === -1) {
- vm.financialAccount.push(item.account_id);
- }
-
- if (vm.financialAccount.indexOf(item.transfer_account_id) === -1) {
- vm.financialAccount.push(item.transfer_account_id);
- }
-
- });
- })
- .catch(Notify.handleError);
+ vm.gridOptions.data = vm.Voucher.store.data;
}
- /** check use of financial accounts */
- function isFinancial() {
+ /* ============================= Transaction Type ============================= */
- vm.financialTransaction = false;
- for (var i = 0; i < vm.rows.length; i++) {
- if (vm.rows[i].account && vm.financialAccount.indexOf(vm.rows[i].account.id) !== -1) {
- vm.financialTransaction = true;
- break;
- }
- }
-
- // prevent persistent value
- vm.voucher.type_id = vm.financialTransaction ? vm.voucher.type_id : null;
-
- }
-
- /* ============================= Transfer Type ============================= */
Vouchers.transactionType()
.then(function (list) {
groupType(list.data);
})
.catch(Notify.handleError);
- vm.buildDescription = buildDescription;
-
function groupType(array) {
vm.incomes = array.filter(function (item) {
return item.type === 'income';
@@ -434,29 +178,6 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
});
}
- function buildDescription() {
- var type = vm.voucher.type_id,
- current = new Date(),
- description = String(Session.project.abbr).concat('/VOUCHER');
-
- if (type) {
-
- type = JSON.parse(type);
-
- vm.type = type.type;
-
- vm.descriptionPrefix = description
- .concat('/', type.prefix)
- .concat('/', current.toDateString());
-
- } else {
-
- vm.descriptionPrefix = description.concat('/', current.toDateString());
-
- }
-
- }
- /* ============================= End Transfer Type ========================= */
/* ============================= Grid ====================================== */
@@ -466,23 +187,33 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
field : 'isValid',
displayName : '...',
cellTemplate: 'partials/vouchers/templates/status.grid.tmpl.html',
+ aggregationType: uiGridConstants.aggregationTypes.count,
+ aggregationHideLabel : true,
+ footerCellClass : 'text-center',
width: 40
}, {
field : 'account',
displayName : 'FORM.LABELS.ACCOUNT',
headerCellFilter: 'translate',
- cellTemplate: 'partials/vouchers/templates/account.grid.tmpl.html'
+ cellTemplate: 'partials/vouchers/templates/account.grid.tmpl.html',
+ width: '35%'
}, {
field : 'debit',
displayName : 'FORM.LABELS.DEBIT',
headerCellFilter: 'translate',
cellTemplate: 'partials/vouchers/templates/debit.grid.tmpl.html',
+ aggregationType: uiGridConstants.aggregationTypes.sum,
+ aggregationHideLabel : true,
+ footerCellFilter: 'currency:' + Session.enterprise.currency_id,
footerCellClass : 'text-right'
}, {
field : 'credit',
displayName : 'FORM.LABELS.CREDIT',
headerCellFilter: 'translate',
cellTemplate: 'partials/vouchers/templates/credit.grid.tmpl.html',
+ aggregationType: uiGridConstants.aggregationTypes.sum,
+ aggregationHideLabel : true,
+ footerCellFilter: 'currency:' + Session.enterprise.currency_id,
footerCellClass : 'text-right'
}, {
field : 'entity',
@@ -500,10 +231,6 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
cellTemplate: 'partials/vouchers/templates/remove.grid.tmpl.html',
}];
- // set up the debit/credit aggregators
- GridAggregators.extendColumnWithAggregator(vm.gridOptions.columnDefs[2], GridAggregators.aggregators.tree.debit);
- GridAggregators.extendColumnWithAggregator(vm.gridOptions.columnDefs[3], GridAggregators.aggregators.tree.credit);
-
/* ============================= End Grid ================================== */
/** submit data */
@@ -515,24 +242,20 @@ function ComplexJournalVoucherController(Vouchers, $translate, Accounts, Currenc
return;
}
- // get the updated state of the module with all checks made
- refreshState();
-
- var voucherItems = handleVoucherItems();
- var voucher = handleVoucher();
+ var valid = vm.Voucher.validate();
- if (voucherItems.length > 0) {
- voucher.items = voucherItems;
+ if (!valid) {
+ Notify.danger(vm.Voucher._error);
+ return;
}
+ var voucher = vm.Voucher.details;
+ voucher.items = vm.Voucher.store.data;
+
return Vouchers.create(voucher)
.then(function (result) {
- form.$setPristine();
- startup();
- refreshState();
- vm.posted = true;
-
Receipts.voucher(result.uuid, true);
+ vm.Voucher.clear();
})
.catch(Notify.handleError);
}
diff --git a/client/src/partials/vouchers/templates/account.grid.tmpl.html b/client/src/partials/vouchers/templates/account.grid.tmpl.html
index 74a9904af8..889920f8ac 100644
--- a/client/src/partials/vouchers/templates/account.grid.tmpl.html
+++ b/client/src/partials/vouchers/templates/account.grid.tmpl.html
@@ -1,9 +1,8 @@
@@ -12,9 +11,8 @@
+ repeat="account.id as account in grid.appScope.Voucher.accounts | filter: { 'hrlabel' : $select.search } track by account.id">
diff --git a/client/src/partials/vouchers/templates/credit.grid.tmpl.html b/client/src/partials/vouchers/templates/credit.grid.tmpl.html
index baaf76b358..e3567c589d 100644
--- a/client/src/partials/vouchers/templates/credit.grid.tmpl.html
+++ b/client/src/partials/vouchers/templates/credit.grid.tmpl.html
@@ -1,8 +1,8 @@
diff --git a/client/src/partials/vouchers/templates/debit.grid.tmpl.html b/client/src/partials/vouchers/templates/debit.grid.tmpl.html
index 96c79c546e..1e2c53b85f 100644
--- a/client/src/partials/vouchers/templates/debit.grid.tmpl.html
+++ b/client/src/partials/vouchers/templates/debit.grid.tmpl.html
@@ -1,8 +1,8 @@
diff --git a/client/src/partials/vouchers/templates/remove.grid.tmpl.html b/client/src/partials/vouchers/templates/remove.grid.tmpl.html
index 72424282bd..67323256f2 100644
--- a/client/src/partials/vouchers/templates/remove.grid.tmpl.html
+++ b/client/src/partials/vouchers/templates/remove.grid.tmpl.html
@@ -1,7 +1,7 @@
diff --git a/client/src/partials/vouchers/templates/status.grid.tmpl.html b/client/src/partials/vouchers/templates/status.grid.tmpl.html
index e05f65344d..faf31f02e1 100644
--- a/client/src/partials/vouchers/templates/status.grid.tmpl.html
+++ b/client/src/partials/vouchers/templates/status.grid.tmpl.html
@@ -1,29 +1,19 @@
-
-
-
-
+
-
+
-
+
-
diff --git a/server/controllers/finance/reports/cashflow/index.js b/server/controllers/finance/reports/cashflow/index.js
index 121dc4fa0b..51da9984c5 100644
--- a/server/controllers/finance/reports/cashflow/index.js
+++ b/server/controllers/finance/reports/cashflow/index.js
@@ -41,10 +41,10 @@ function report(req, res, next) {
let params = req.query;
processingCashflowReport(params)
- .then(result => {
- res.status(200).json(result);
- })
- .catch(next);
+ .then(result => {
+ res.status(200).json(result);
+ })
+ .catch(next);
}
/** processingCashflowReport */
@@ -541,9 +541,11 @@ function document(req, res, next) {
tempExpense[item.origin_id] = typeof tempExpense[item.origin_id] !== 'undefined' ? false : true;
if (tempExpense[item.origin_id] === true) {
+
var value = expenses.reduce(function (a, b) {
return b.origin_id === item.origin_id ? b.credit_equiv + a : a;
}, 0);
+
session.summationExpense[period].push({
'transfer_type' : item.transactionType,
'currency_id' : item.currency_id,
diff --git a/server/controllers/finance/reports/cashflow/report.handlebars b/server/controllers/finance/reports/cashflow/report.handlebars
index 880968630d..6817b28098 100644
--- a/server/controllers/finance/reports/cashflow/report.handlebars
+++ b/server/controllers/finance/reports/cashflow/report.handlebars
@@ -207,12 +207,8 @@
{{/each}}
-
-
-
-
diff --git a/server/models/procedures.sql b/server/models/procedures.sql
index 0496511f05..c1a1d30bcd 100644
--- a/server/models/procedures.sql
+++ b/server/models/procedures.sql
@@ -183,16 +183,16 @@ BEGIN
-- populate core set-up values
CALL PostingSetupUtil(date, enterprise_id, project_id, currency_id, current_fiscal_year_id, current_period_id, current_exchange_rate, enterprise_currency_id, transaction_id, gain_account_id, loss_account_id);
- -- Check that all invoice items have sales accounts - if they do not the transaction will be imbalanced
- SELECT COUNT(invoice_item.uuid)
+ -- Check that all invoice items have sales accounts - if they do not the transaction will be imbalanced
+ SELECT COUNT(invoice_item.uuid)
INTO verify_invalid_accounts
FROM invoice JOIN invoice_item JOIN inventory JOIN inventory_group
- ON invoice.uuid = invoice_item.invoice_uuid
- AND invoice_item.inventory_uuid = inventory.uuid
+ ON invoice.uuid = invoice_item.invoice_uuid
+ AND invoice_item.inventory_uuid = inventory.uuid
AND inventory.group_uuid = inventory_group.uuid
WHERE invoice.uuid = uuid
AND inventory_group.sales_account IS NULL;
-
+
IF verify_invalid_accounts > 0 THEN
SIGNAL InvalidSalesAccounts
SET MESSAGE_TEXT = 'A NULL sales account has been found for an inventory item in this invoice.';
@@ -660,16 +660,16 @@ BEGIN
the difference to the debtor and credit the difference as a gain to the gain_account
- The debtor entity an invoice reference are not included on the gain
- account transaction. In this case the debtor covered MORE than the
- invoiced amount and so referencing them on the enterprise gain will
- actually debit them the additional amount.
+ account transaction. In this case the debtor covered MORE than the
+ invoiced amount and so referencing them on the enterprise gain will
+ actually debit them the additional amount.
*/
IF (remainder > 0) THEN
-
- -- The debtor is not debited in this transaction. They have already
- -- balanced the invoice and their debt according to the invoice (the
+
+ -- The debtor is not debited in this transaction. They have already
+ -- balanced the invoice and their debt according to the invoice (the
-- exact amount). The additional payment can just be put in a gain account.
-
+
-- credit the rounding account
INSERT INTO posting_journal (
uuid, project_id, fiscal_year_id, period_id, trans_id, trans_date,
@@ -687,9 +687,9 @@ BEGIN
A negative remainder means that the debtor underpaid slightly and we should credit
the difference to the debtor and debit the difference as a loss to the loss_account
- - The debtor and invoice are referenced on the loss account transaction
- make up for the amount that is loss. In this case the debtor has not
- actually paid enough money to cover the amount of the invoice. If this
+ - The debtor and invoice are referenced on the loss account transaction
+ make up for the amount that is loss. In this case the debtor has not
+ actually paid enough money to cover the amount of the invoice. If this
is not referenced his balance will not be zero.
*/
ELSE