Skip to content

Commit

Permalink
fix(creditNote): reverse all rows in a reversal
Browse files Browse the repository at this point in the history
This commit changes the `ReverseTransaction()` method to using UNION
ALL instead of a simple UNION to avoid only reversing unique rows.  This
has resulted in multiple unbalanced credit notes in production.
  • Loading branch information
Jonathan Niles authored and sfount committed Feb 8, 2017
1 parent 6797e4f commit 5107b53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion client/src/js/services/VoucherService.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ function VoucherService(Api, $http, util, TransactionTypeStore) {
* This method facilitate annulling a transaction,
* bhima should automatically be able to reverse
* any transaction in the posting_journal by creating a
* new transaction that is an exact duplicate of the original transaction with sign minous.
* new transaction that is an exact duplicate of the original transaction with the
* debits and credits switched.
*/
function reverse(creditNote) {
return $http.post(baseUrl.concat(creditNote.uuid, '/reverse'), creditNote)
Expand Down
16 changes: 8 additions & 8 deletions server/controllers/finance/journal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function find(options) {
* journalEntryList
* Allows you to select which transactions to print
*/
function journalEntryList(options) {
function journalEntryList(options) {
let uuids = options.uuids.map(function(uuid) {
return db.bid(uuid);
});
Expand Down Expand Up @@ -293,7 +293,7 @@ function getTransaction (req, res, next) {
*
* @description
* This is a generic wrapper for reversing any transaction in the posting
* journal or general ledger.
* journal or general ledger.
*
* POST /journal/:uuid/reverse
*/
Expand All @@ -303,20 +303,20 @@ function reverse(req, res, next) {
const recordUuid = db.bid(req.params.uuid);
const params = [ recordUuid, req.session.user.id, req.body.description, db.bid(voucherUuid) ];

/**
* Check already cancelled
/**
* Check already cancelled
* Transaction type for cancelled operation is 10
*/
const CANCELLED_ID = 10;
const query =
`SELECT uuid FROM voucher
const query =
`SELECT uuid FROM voucher
WHERE voucher.type_id = ${CANCELLED_ID} AND voucher.reference_uuid = ?`;

// create and execute a transaction if necessary
// create and execute a transaction if necessary
db.exec(query, [recordUuid])
.then(rows => {
if (rows.length > 0) {
// transaction already cancelled
// transaction already cancelled
throw new BadRequest('The transaction has been already cancelled', 'POSTING_JOURNAL.ERRORS.MULTIPLE_CANCELLING');
}
return db.exec('CALL ReverseTransaction(?, ?, ?, ?);', params);
Expand Down
6 changes: 3 additions & 3 deletions server/models/procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ BEGIN

DECLARE cashPaymentOriginId SMALLINT(5);

-- set origin to the CASH_PAYMENT transaction type
-- set origin to the CASH_PAYMENT transaction type
SET cashPaymentOriginId = 2;

-- copy cash payment values into working variables
Expand Down Expand Up @@ -1128,7 +1128,7 @@ BEGIN
SELECT voucher_uuid, NOW(), zz.project_id, enterprise.currency_id, 0, CONCAT_WS(' ', '[REVERSAL]', description, ' -- ', zz.description), user_id, 10, uuid
FROM (
SELECT pj.project_id, pj.description FROM posting_journal AS pj WHERE pj.record_uuid = uuid
UNION
UNION ALL
SELECT gl.project_id, gl.description FROM general_ledger AS gl WHERE gl.record_uuid = uuid
) AS zz
JOIN project ON zz.project_id = project.id
Expand All @@ -1141,7 +1141,7 @@ BEGIN
FROM (
SELECT pj.account_id, pj.credit_equiv, pj.debit_equiv, pj.reference_uuid, pj.entity_uuid
FROM posting_journal AS pj WHERE pj.record_uuid = uuid
UNION
UNION ALL
SELECT gl.account_id, gl.credit_equiv, gl.debit_equiv, gl.reference_uuid, gl.entity_uuid
FROM general_ledger AS gl WHERE gl.record_uuid = uuid
) AS zz;
Expand Down

0 comments on commit 5107b53

Please sign in to comment.