Skip to content

Commit

Permalink
feat(journal): allow users to edit transaction type (#1616)
Browse files Browse the repository at this point in the history
This commit allows a user to edit the transaction type in the Posting Journal.  Editing the Transaction Type is important to make proper reports.  Editing is supported via a dropdown on the Posting Journal page.
  • Loading branch information
mbayopanda authored and jniles committed May 9, 2017
1 parent 0856853 commit 6bc89ba
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/posting_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"COLUMNS":"Columns"},
"ERRORS":{"DATE_IN_WRONG_PERIOD":"Dates in wrong period",
"MISSING_DESCRIPTION":"Descriptions omitted",
"VARIOUS_TRANSACTION_TYPE":"Various transaction type for a transaction",
"LOCKED_ACCOUNT":"Locked account(s)",
"TRANSACTION_DIFF_DATES" : "Transactions with different dates",
"UNBALANCED_TRANSACTIONS":"Unbalanced Transaction(s)",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/posting_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"COLUMNS":"Colonnes"},
"ERRORS":{"DATE_IN_WRONG_PERIOD":"Dates dans la mauvaise periode",
"MISSING_DESCRIPTION":"Descriptions omises",
"VARIOUS_TRANSACTION_TYPE":"Type de transaction different pour une meme transaction",
"TRANSACTION_DIFF_DATES" : "Transactions avec des dates differentes",
"LOCKED_ACCOUNT":"Compte(s) verrouille(s)",
"UNBALANCED_TRANSACTIONS":"Transaction(s) non balancee(s)",
Expand Down
17 changes: 14 additions & 3 deletions client/src/js/services/grid/TransactionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ function TransactionService($timeout, util, uiGridConstants, bhConstants, Notify
ERR_TRANSACTION_DIFF_DATES = 'POSTING_JOURNAL.ERRORS.TRANSACTION_DIFF_DATES',
ERR_UNBALANCED_TRANSACTIONS = 'POSTING_JOURNAL.ERRORS.UNBALANCED_TRANSACTIONS',
ERR_DEB_CRED_NOT_NULL = 'POSTING_JOURNAL.ERRORS.DEB_CRED_NOT_NULL',
ERR_CREDITED_DEBITED = 'POSTING_JOURNAL.ERRORS.CREDITED_DEBITED';
ERR_CREDITED_DEBITED = 'POSTING_JOURNAL.ERRORS.CREDITED_DEBITED',
ERR_VARIOUS_TRANSACTION_TYPE='POSTING_JOURNAL.ERRORS.VARIOUS_TRANSACTION_TYPE';

// If the transaction has 0 line
if (numberOfLine === 0) {
Expand All @@ -365,17 +366,22 @@ function TransactionService($timeout, util, uiGridConstants, bhConstants, Notify
var debit = 0,
credit = 0,
initialDate,
baseTransactionType,
accountNull = false,
dateNull = false,
dateDifferent = false,
dateWrongPeriod = false,
debitCreditNull = false,
debitedCreditedNull = false;
debitedCreditedNull = false,
variousTransactionType = false;

if (transaction[0].trans_date) {
initialDate = transaction[0].trans_date;
}

// base transaction type
baseTransactionType = transaction[0].origin_id;


transaction.forEach(function (row) {
debit += Number(row.debit_equiv);
Expand All @@ -388,7 +394,7 @@ function TransactionService($timeout, util, uiGridConstants, bhConstants, Notify
dateNull = !row.trans_date;

// Check if they are different Date
dateDifferent = Dates.util.str(row.trans_date) !== Dates.util.str(initialDate);
dateDifferent = (Dates.util.str(row.trans_date) !== Dates.util.str(initialDate)) || dateDifferent;

// Check if debit and credit are Null
debitCreditNull = (!Number(row.debit_equiv) && !Number(row.credit_equiv));
Expand All @@ -400,6 +406,9 @@ function TransactionService($timeout, util, uiGridConstants, bhConstants, Notify
if (new Date(row.trans_date) < new Date(row.period_start) || new Date(row.trans_date) > new Date(row.period_end)) {
dateWrongPeriod = true;
}

// check if transaction type (origin_id) are differenct
variousTransactionType = (row.origin_id !== baseTransactionType) || variousTransactionType;
});

/**
Expand All @@ -425,6 +434,8 @@ function TransactionService($timeout, util, uiGridConstants, bhConstants, Notify
error = ERR_DEB_CRED_NOT_NULL;
} else if (debitedCreditedNull) {
error = ERR_CREDITED_DEBITED;
} else if (variousTransactionType) {
error = ERR_VARIOUS_TRANSACTION_TYPE;
} else {
// later in validateTransaction()
if (debit !== credit) {
Expand Down
46 changes: 43 additions & 3 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'
'FilterService', '$rootScope', '$filter', 'TransactionTypeService', '$translate',
];

/**
Expand All @@ -33,7 +33,8 @@ JournalController.$inject = [
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) {
uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope, $filter,
TransactionType, $translate) {

// Journal utilities
var sorting;
Expand Down Expand Up @@ -248,6 +249,13 @@ function JournalController(Journal, Sorting, Grouping,
headerCellFilter : 'translate',
visible : true },

{ field : 'origin_id',
displayName : 'FORM.LABELS.TRANSACTION_TYPE',
headerCellFilter : 'translate',
cellTemplate : '/modules/journal/templates/transaction_type.html',
editableCellTemplate : '/modules/journal/templates/transaction_type.edit.html',
visible : false },

{ field : 'display_name',
displayName : 'TABLE.COLUMNS.RESPONSIBLE',
headerCellFilter : 'translate',
Expand Down Expand Up @@ -466,6 +474,7 @@ function JournalController(Journal, Sorting, Grouping,
function startup() {
load(Journal.filters.formatHTTP(true));
vm.latestViewFilters = Journal.filters.formatView();
loadTransactionType();
}

// ===================== edit entity ===============================
Expand Down Expand Up @@ -493,7 +502,38 @@ function JournalController(Journal, Sorting, Grouping,
delete row.entity_uuid;
delete row.hrEntity;
}

// ===================== end edit entity ===========================

// ===================== transaction type ==========================
vm.editTransactionType = editTransactionType;
vm.removeTransactionType = removeTransactionType;

// edit transaction type
function editTransactionType(row) {
var id = row.origin_id;
transactions.editCell(row, 'origin_id', id);
}

// remove transaction type
function removeTransactionType(row) {
transactions.editCell(row, 'origin_id', null);
}

// load transaction types
function loadTransactionType() {
TransactionType.read()
.then(function (list) {
vm.mapOrigins = {};

vm.typeList = list.map(function (item) {
item.hrText = $translate.instant(item.text);
vm.mapOrigins[item.id] = item.hrText;
return item;
});
})
.catch(Notify.handleError);
}
// ===================== end transaction type ======================

startup();
}
32 changes: 32 additions & 0 deletions client/src/modules/journal/templates/transaction_type.edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="ui-grid-cell-contents">
<div ng-show="grid.appScope.transactions.isEditing()">
<!--remove the transaction type-->
<a ng-click="grid.appScope.removeTransactionType(row.entity)" class="text-danger pull-right" href="">
<i class="fa fa-trash"></i>
</a>

<!--select transaction type-->
<ui-select
style="width: 90%;"
name="type_id"
ng-model="row.entity.origin_id"
ng-change="grid.appScope.editTransactionType(row.entity)"
append-to-body="true">

<ui-select-match placeholder="{{ 'FORM.SELECT.TRANSFER_TYPE' | translate }}">
<span translate>{{$select.selected.text}}</span>
</ui-select-match>

<ui-select-choices
ui-select-focus-patch
repeat="item.id as item in grid.appScope.typeList | filter:{ 'hrText' : $select.search }"
group-by="'type'">
<div ng-bind-html="item.hrText | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
</div>

<div ng-hide="grid.appScope.transactions.isEditing()">
{{ grid.appScope.mapOrigins[row.entity.origin_id] }}
</div>
</div>
3 changes: 3 additions & 0 deletions client/src/modules/journal/templates/transaction_type.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="ui-grid-cell-contents">
{{ grid.appScope.mapOrigins[row.entity.origin_id] }}
</div>

0 comments on commit 6bc89ba

Please sign in to comment.