Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Journal tool) marking transactions as comment #2060

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/i18n/en/table.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"CHARGE": "Charge",
"CLIENT": "Client",
"CODE": "Code",
"COMMENT" :"Commentaire",
"COST": "Cost",
"COST_CENTER": "Cost Center",
"COUNTRY": "Country",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/table.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"CHARGE": "Charge",
"CLIENT": "Client",
"CODE": "Code",
"COMMENT" :"Comment",
"COST": "Coût",
"COST_CENTER": "Centre de cout",
"COUNTRY": "Pays",
Expand Down
12 changes: 9 additions & 3 deletions client/src/modules/journal/journal.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@
</div>
</div>

<div class="toolbar-item">
<button data-method="comment" class="btn btn-default" ng-disabled="!JournalCtrl.selectedRows.length" ng-click="JournalCtrl.commentRows()">
<i class="fa fa-sticky-note-o"></i> <span class="visible-lg-inline" translate>FORM.LABELS.COMMENT</span>
</button>
</div>

<div class="toolbar-item">
<button data-method="search" class="btn btn-default" ng-click="JournalCtrl.openSearchModal()">
<i class="fa fa-search"></i> <span class="visible-lg-inline" translate>FORM.BUTTONS.SEARCH</span>
</button>
</div>
<div class="toolbar-item">
<button
ng-class="{ 'btn-success' : JournalCtrl.selection.selected.groups.length === 1 }"
<button
ng-class="{ 'btn-success' : JournalCtrl.selection.selected.groups.length === 1 }"
ng-disabled="JournalCtrl.selection.selected.groups.length === 0"
ng-click="JournalCtrl.editTransactionModal()"
class="btn btn-default" data-method="edit">
<i class="fa fa-pencil-square-o"></i>
<i class="fa fa-pencil-square-o"></i>
<span ng-if="JournalCtrl.selection.selected.groups.length === 1">({{JournalCtrl.selection.selected.groups[0]}})</span>
<span ng-if="JournalCtrl.selection.selected.groups.length > 1">(...)</span>
</button>
Expand Down
35 changes: 34 additions & 1 deletion client/src/modules/journal/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function JournalController(Journal, Sorting, Grouping,
var cache = AppCache(cacheKey.concat('-module'));
var vm = this;

vm.selectedRows = [];

// number of all of the transactions in the system
Journal.count()
.then(function (data) {
Expand All @@ -77,9 +79,37 @@ function JournalController(Journal, Sorting, Grouping,
flatEntityAccess : true,
enableGroupHeaderSelection : true,
enableRowHeaderSelection : true,
onRegisterApi : function (api) { vm.gridApi = api; }
onRegisterApi : function onRegisterApi(api) {
vm.gridApi = api;
vm.gridApi.selection.on.rowSelectionChanged(null, rowSelectionChanged);
vm.gridApi.selection.on.rowSelectionChangedBatch(null, rowSelectionChanged);
},

};

// row selection changed
function rowSelectionChanged() {
vm.selectedRows = vm.gridApi.selection.getSelectedGridRows();
}

// comment selected rows
vm.commentRows = function commentRows() {
Journal.openCommentModal({ rows : vm.selectedRows })
.then(function (comment) {
if (!comment) { return; }
updateGridComment(vm.selectedRows, comment);
Notify.success('ACCOUNT_STATEMENT.SUCCESSFULLY_COMMENTED');
})
.catch(Notify.handleError);
};

// update local rows
function updateGridComment(rows, comment) {
rows.forEach(function (row) {
row.entity.comment = comment;
});
}

vm.grouped = angular.isDefined(cache.grouped) ? cache.grouped : false;

// Initialise each of the journal utilities, providing them access to the journal
Expand Down Expand Up @@ -265,6 +295,9 @@ function JournalController(Journal, Sorting, Grouping,
displayName : 'TABLE.COLUMNS.RESPONSIBLE',
headerCellFilter : 'translate',
visible : false },
{ field : 'comment',
displayName : 'TABLE.COLUMNS.COMMENT',
headerCellFilter : 'translate' },
];
vm.gridOptions.columnDefs = columns;

Expand Down
33 changes: 31 additions & 2 deletions client/src/modules/journal/journal.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ angular.module('bhima.services')
.service('JournalService', JournalService);

// Dependencies injection
JournalService.$inject = ['PrototypeApiService', 'AppCache', 'FilterService', 'PeriodService', '$uibModal'];
JournalService.$inject = [ 'PrototypeApiService', 'AppCache', 'FilterService', 'PeriodService', '$uibModal', 'util'];

/**
* Journal Service
* This service is responsible of all process with the posting journal
*/
function JournalService(Api, AppCache, Filters, Periods, Modal) {
function JournalService(Api, AppCache, Filters, Periods, Modal, util) {
var URL = '/journal/';
var service = new Api(URL);

service.grid = grid;
service.saveChanges = saveChanges;
service.openSearchModal = openSearchModal;
service.openCommentModal = openCommentModal;
service.openTransactionEditModal = openTransactionEditModal;
service.mapTransactionIdsToRecordUuids = mapTransactionIdsToRecordUuids;
service.commentPostingJournal = commentPostingJournal;

/**
* Standard API read method, as this will be used to drive the journal grids
Expand Down Expand Up @@ -165,6 +167,26 @@ function JournalService(Api, AppCache, Filters, Periods, Modal) {
}).result;
}

/**
* @method openCommentModal
* @param {object} request
*/
function openCommentModal(request) {
var params = {
templateUrl : 'modules/journal/modals/comment.modal.html',
controller : 'CommentJournalController',
controllerAs : '$ctrl',
size : 'md',
backdrop : 'static',
resolve : {
modalParameters : function dataProvider() { return request; },
},
};
var instance = Modal.open(params);
return instance.result;
}


// @TODO(sfount) move this to a service that can easily be accessed by any module that will show a transactions details
function openTransactionEditModal(transactionUuid, readOnly) {
return Modal.open({
Expand All @@ -180,5 +202,12 @@ function JournalService(Api, AppCache, Filters, Periods, Modal) {
}).result;
}

// updating the posting journal by adding comments in transactions
function commentPostingJournal(params) {
return service.$http.put(URL.concat('comments'), { 'params' : params })
.then(util.unwrapHttpResponse);
}


return service;
}
33 changes: 33 additions & 0 deletions client/src/modules/journal/modals/comment.modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<form name="ModalForm"
ng-submit="$ctrl.submit(ModalForm)"
novalidate>

<div class="modal-header" translate>
ACCOUNT_STATEMENT.COMMENT
</div>

<div class="modal-body">
<div class="form-group">
{{ $ctrl.rows.length || 0 }}
<label translate>ACCOUNT_STATEMENT.SELECTED_ROWS</label>
</div>

<div class="form-group"
ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.comment.$invalid }">
<input type="text" class="form-control" name="comment" ng-model="$ctrl.comment" required>

<div class="help-block" ng-messages="ModalForm.comment.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="$ctrl.cancel()" translate>
FORM.BUTTONS.CLOSE
</button>
<bh-loading-button loading-state="$ctrl.$loading">
<span translate>FORM.BUTTONS.SUBMIT</span>
</bh-loading-button>
</div>
</form>
41 changes: 41 additions & 0 deletions client/src/modules/journal/modals/comment.modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
angular.module('bhima.controllers')
.controller('CommentJournalController', CommentJournalController);

// DI
CommentJournalController.$inject = [
'$uibModalInstance', 'modalParameters', 'JournalService', 'NotifyService',
];

// Comment Account Statement Controller
function CommentJournalController(Instance, ModalParameters, Journal, Notify) {
var vm = this;

vm.cancel = Instance.dismiss;
vm.submit = submit;
vm.rows = ModalParameters.rows;

// submit the comment
function submit(form) {
if (form.$invalid) { return; }

var params = {
uuids : getRowsUuid(vm.rows),
comment : vm.comment,
};

Journal.commentPostingJournal(params)
.then(function (res) {
if (!res) { return; }
Instance.close(vm.comment);
})
.catch(Notify.handleError)
.finally(Instance.close);
}

// get rows uuid
function getRowsUuid(rows) {
return rows.map(function (row) {
return row.entity.uuid;
});
}
}
1 change: 1 addition & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ exports.configure = function configure(app) {
app.get('/journal/:record_uuid', journal.getTransaction);
app.post('/journal/:record_uuid/edit', journal.editTransaction);
app.post('/journal/:uuid/reverse', journal.reverse);
app.put('/journal/comments', journal.commentPostingJournal);

// API for general ledger
app.get('/general_ledger', generalLedger.list);
Expand Down
25 changes: 24 additions & 1 deletion server/controllers/finance/journal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports.journalEntryList = journalEntryList;

exports.editTransaction = editTransaction;
exports.count = count;

exports.commentPostingJournal = commentPostingJournal;

/**
* Looks up a transaction by record_uuid.
Expand Down Expand Up @@ -514,3 +514,26 @@ function count(req, res, next) {
})
.catch(next);
}


/**
* PUT /journal/comments
* @param {object} params - { uuids: [...], comment: '' }
*/
function commentPostingJournal(req, res, next) {
const params = req.body.params;
const uuids = params.uuids.map((uuid) => {
return db.bid(uuid);
});

const sql = 'UPDATE posting_journal SET comment = ? WHERE uuid IN ?';
db.exec(sql, [params.comment, [uuids]])
.then((rows) => {
if (!rows.affectedRows || rows.affectedRows !== uuids.length) {
throw new BadRequest('Error on update general ledger comment');
}
res.sendStatus(200);
})
.catch(next)
.done();
}