Skip to content

Commit

Permalink
feat(journal): propagate changes in shared properties to whole transa…
Browse files Browse the repository at this point in the history
…ction

This commit implements a feature that propagates changes made while editing a transactions to all lines of the transaction for certain shared columns such as date, origin_id, and others.
  • Loading branch information
lomamech authored and jniles committed May 11, 2017
1 parent 2bcb301 commit 89a3272
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
33 changes: 31 additions & 2 deletions client/src/modules/journal/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ JournalController.$inject = [
'SessionService', 'NotifyService', 'TransactionService', 'GridEditorService',
'bhConstants', '$state', 'uiGridConstants', 'ModalService', 'LanguageService',
'AppCache', 'Store', 'uiGridGroupingConstants', 'ExportService', 'FindEntityService',
'FilterService', '$rootScope', '$filter', 'TransactionTypeService', '$translate',
'FilterService', '$rootScope', '$filter', 'TransactionTypeService', '$translate', '$scope',
];

/**
Expand All @@ -34,7 +34,7 @@ function JournalController(Journal, Sorting, Grouping,
Filtering, Columns, Config, Session, Notify, Transactions, Editors,
bhConstants, $state, uiGridConstants, Modal, Languages, AppCache, Store,
uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope, $filter,
TransactionType, $translate) {
TransactionType, $translate, $scope) {

// Journal utilities
var sorting;
Expand Down Expand Up @@ -277,6 +277,32 @@ function JournalController(Journal, Sorting, Grouping,
// API register function
function onRegisterApi(gridApi) {
vm.gridApi = gridApi;

vm.gridApi.edit.on.afterCellEdit($scope, function(rowEntity, colDef, newValue, oldValue){
if(newValue != oldValue) {
propagate(colDef.field,newValue);
}
});
}

function updateSharedPropertyOnRow(rows, column, value){
rows.forEach(function (row) {
transactions.editCell(row, column, value, row[column]);
row[column] = (column === 'trans_date') ? new Date(value) : value;
});

}

function propagate(column, value){
var propagateColumn = ['trans_date', 'entity_uuid', 'origin_id'];
//Check if the column updated must be propragated in all transaction
var hasSharedProperty = propagateColumn.indexOf(column) !== -1;

if (hasSharedProperty) {
// pass updates on to both the original rows and the new (pending) rows
updateSharedPropertyOnRow(vm.transactions._entity.data.data, column, value);
updateSharedPropertyOnRow(vm.transactions._entity.newRows.data, column, value);
}
}

// This function opens a modal through column service to let the user show or Hide columns
Expand Down Expand Up @@ -512,6 +538,9 @@ function JournalController(Journal, Sorting, Grouping,
function editTransactionType(row) {
var id = row.origin_id;
transactions.editCell(row, 'origin_id', id);

// Propagate the changement in all origin Id for transaction
propagate('origin_id', id);
}

// remove transaction type
Expand Down
2 changes: 1 addition & 1 deletion server/models/test/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ INSERT INTO `posting_journal` VALUES
(HUID(UUID()),1,1,16,'TRANS3','2016-01-09 17:04:27',@first_voucher,'description x',3628,0.0000,100.0000,0.0000,100.0000,2,NULL,NULL,'Sample voucher data one',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS4','2016-01-09 17:04:27',@second_voucher,'description x',3627,200.0000,0.0000,200.0000,0.0000,2,NULL,NULL,'Sample voucher data two',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS4','2016-01-09 17:04:27',@second_voucher,'description x',3628,0.0000,200.0000,0.0000,200.0000,2,NULL,NULL,'Sample voucher data two',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS5','2016-01-08 17:04:27',@third_voucher,'description x',3627,300.0000,0.0000,300.0000,0.0000,2,NULL,NULL,'Sample voucher data three',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS5','2016-02-08 17:04:27',@third_voucher,'description x',3627,300.0000,0.0000,300.0000,0.0000,2,NULL,NULL,'Sample voucher data three',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS5','2016-02-08 17:04:27',@third_voucher,'unique',3628,0.0000,300.0000,0.0000,300.0000,2,NULL,NULL,'Sample voucher data three',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS6','2017-04-07 09:18:00',@fourth_voucher, 'description x',3641,1000.0000,0.0000,1000.0000,0.0000,2,NULL,NULL,NULL,1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS6','2017-04-07 09:18:00',@fourth_voucher,'description x',3643,0.0000,1000.0000,0.0000,1000.0000,2,NULL,NULL,NULL,1,2,1,NULL);
Expand Down

0 comments on commit 89a3272

Please sign in to comment.