Skip to content

Commit

Permalink
Merge pull request #339 from jniles/chore-improve-cashboxes
Browse files Browse the repository at this point in the history
chore(journal): improve posting core with issue fixes
  • Loading branch information
sfount committed Apr 21, 2016
2 parents 7109154 + 9b5042e commit 7f9ae02
Show file tree
Hide file tree
Showing 24 changed files with 467 additions and 557 deletions.
33 changes: 6 additions & 27 deletions client/src/js/services/AccountService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ function AccountService($http, util, sessionService) {
service.read = read;
service.label = label;

/** @deprecated */
service.list = list;

service.getBalance = getBalance;
service.getChildren = getChildren;

Expand Down Expand Up @@ -56,24 +53,6 @@ function AccountService($http, util, sessionService) {
});
}

// return a list of accounts
function list() {
return $http.get('/accounts?full=1') // TODO - this should only be /accounts
.then(util.unwrapHttpResponse)
.then(function (accounts) {

// hack to make sure accounts are properly rendered on cashboxes page
// FIXME - make /accounts return the account type w/o query string
// and preformat the numberLabel elsewhere
accounts.forEach(function (account) {
account.hrlabel = label(account);
});

return accounts;
})
.then(order);
}

function getBalance(account_id, opt){
var url = baseUrl + account_id + '/balance';
return $http.get(url, opt)
Expand Down Expand Up @@ -140,11 +119,11 @@ function AccountService($http, util, sessionService) {
}

/**
*@helper
*@helper
* This Method Creat an account
**/
function create(account) {
var classAccount = String(account.number).charAt(0),
var classAccount = String(account.number).charAt(0),
accountClean = {
enterprise_id : sessionService.enterprise.id,
type_id : account.type.id,
Expand All @@ -154,7 +133,7 @@ function AccountService($http, util, sessionService) {
locked : account.locked,
cc_id : account.cc_id,
pc_id : account.pc_id,
classe : classAccount,
classe : classAccount,
is_asset : account.is_asset,
reference_id : account.reference_id,
is_brut_link : account.is_brut_link,
Expand All @@ -168,8 +147,8 @@ function AccountService($http, util, sessionService) {

/**
* @desc It updates an account
* @param {Integer} id, account id to update
* @param {object} account, account to update
* @param {Integer} id, account id to update
* @param {object} account, account to update
* @example
* service.update(id, account)
* .then(function (res){
Expand All @@ -184,7 +163,7 @@ function AccountService($http, util, sessionService) {
parent : account.parent,
locked : account.locked,
cc_id : account.cc_id,
pc_id : account.pc_id,
pc_id : account.pc_id,
is_asset : account.is_asset,
reference_id : account.reference_id,
is_brut_link : account.is_brut_link,
Expand Down
44 changes: 24 additions & 20 deletions client/src/js/services/CashBoxService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,78 @@ CashboxService.$inject = [ '$http', 'util' ];
/**
* Cashbox Service
*
* @todo documenation updates to use JSDoc standards
* This service communicates with both the backend cashboxes API and the cashbox
* currency API for manipulating cashboxes. Cashbox-currency methods are
* exposed behind the service.currencies.* functions.
*/
function CashboxService($http, util) {
var service = {};
var service = this;
var baseUrl = '/cashboxes/';

// expose service methods to the client for consumption
service.read = read;
service.create = create;
service.update = update;
service.delete = del;

// cashbox-currency methods
service.currencies = {};
service.currencies.read = readCurrencies;
service.currencies.create = createCurrencies;
service.currencies.update = updateCurrencies;


/* ------------------------------------------------------------------------ */



function read(id, opt) {
var url = (id) ? '/cashboxes/' + id : '/cashboxes';
return $http.get(url, opt)
function read(id, params) {
var url = baseUrl.concat(id || '');
return $http.get(url, { params: params })
.then(util.unwrapHttpResponse);
}

function create(box) {
return $http.post('/cashboxes', { cashbox: box })
delete box.currencies;
delete box.type;
return $http.post(baseUrl, { cashbox: box })
.then(util.unwrapHttpResponse);
}

// update a cashbox in the database
function update(id, box) {

// remove box props that shouldn't be submitted to the server
delete box.id;
delete box.type;
delete box.currencies;

return $http.put('/cashboxes/' + id, box)
return $http.put(baseUrl.concat(id), box)
.then(util.unwrapHttpResponse);

}

// DELETE a cashbox in the database
function del(id) {
return $http.delete('/cashboxes/' + id)
return $http.delete(baseUrl.concat(id))
.then(util.unwrapHttpResponse);
}

// this will read either all cashbox currency accounts or a specific
// cashbox currency account.
function readCurrencies(id, currencyId) {
var url = '/cashboxes/' + id + '/currencies';
var url = baseUrl + id + '/currencies/';

// attache the currencyId if it exists
if (currencyId) { url += '/' + currencyId; }
// attach the currencyId if it exists
url = url.concat(currencyId || '');

return $http.get(url)
.then(util.unwrapHttpResponse);
}

function createCurrencies(id, data) {
var url = '/cashboxes/' + id + '/currencies';
var url = baseUrl + id + '/currencies';
return $http.post(url, data)
.then(util.unwrapHttpResponse);
}

function updateCurrencies(cashboxId, data) {
var currencyId = data.currency_id;
var url = '/cashboxes/' + cashboxId + '/currencies/' + currencyId;
var url = baseUrl + cashboxId + '/currencies/' + currencyId;

// delete potentially duplicate data entries
delete data.currency_id;
Expand Down
28 changes: 14 additions & 14 deletions client/src/partials/accounts/accounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO Handle HTTP exception errors (displayed contextually on form)
angular.module('bhima.controllers')
.controller('AccountsController', AccountsController);

Expand Down Expand Up @@ -56,9 +55,9 @@ function AccountsController(accountService, costCenterService, profitCenterServi
function cancel() {
vm.view = 'default';
}
//This function cancels the information that should not exist
//in the event of one or another type of accounts (balance or income/expense)

//This function cancels the information that should not exist
//in the event of one or another type of accounts (balance or income/expense)
function dataByTypes(){
if(vm.account.type.type === 'balance'){
vm.account.is_charge = null;
Expand All @@ -69,8 +68,8 @@ function AccountsController(accountService, costCenterService, profitCenterServi
}
}

//This function first looks up the name type of account with the ID
//and then cancels the information that should not exist in the event of one
//This function first looks up the name type of account with the ID
//and then cancels the information that should not exist in the event of one
//or another type of accounts (balance or operating account)
function typeAccount(typeId, accountTypes){
vm.account.type = accountTypeService.getTypeText(typeId, accountTypes);
Expand All @@ -94,11 +93,11 @@ function AccountsController(accountService, costCenterService, profitCenterServi

function create() {
vm.view = 'create';
vm.account = {
vm.account = {
is_title : 0,
parent : 0,
locked : 0
};
locked : 0
};
}

// switch to update mode
Expand All @@ -109,10 +108,11 @@ function AccountsController(accountService, costCenterService, profitCenterServi
vm.account = data;
}


// refresh the displayed Accounts
function refreshAccounts() {
return accountService.list().then(function (data) {
return accountService.read(null, { detailed : 1 })
.then(function (data) {
vm.accounts = data;
vm.loading = false;
});
Expand All @@ -128,7 +128,7 @@ function AccountsController(accountService, costCenterService, profitCenterServi
var creation = (vm.view === 'create');

var account = angular.copy(vm.account);

promise = (creation) ?
accountService.create(account) :
accountService.update(account.id, account);
Expand All @@ -139,9 +139,9 @@ function AccountsController(accountService, costCenterService, profitCenterServi
})
.then(function () {
vm.view = creation ? 'create_success' : 'update_success';
})
})
.catch(handler);
}

startup();
startup();
}
43 changes: 4 additions & 39 deletions client/src/partials/bhima/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,17 @@ function ApplicationController($timeout, AppCache, appstate, connect, util, Sess
function loadState() {
var currencies, exchangeRate, fiscalYear;

exchangeRate = {
'tables' : {
'exchange_rate' : {'columns' : ['id', 'enterprise_id', 'currency_id', 'rate', 'date'] },
'enterprise' : {'columns' : ['id', 'currency_id::enterprise_currency_id']}
},
join : ['exchange_rate.enterprise_id=enterprise.id']
};

fiscalYear = {
'tables' : {
'period' : { 'columns' : ['id', 'period_start', 'period_stop', 'fiscal_year_id'] },
'fiscal_year' : { 'columns': ['fiscal_year_txt', 'start_month', 'start_year', 'previous_fiscal_year', 'enterprise_id'] }
'period' : { 'columns' : ['id', 'start_date', 'end_date', 'fiscal_year_id'] },
'fiscal_year' : { 'columns': ['label', 'start_date', 'previous_fiscal_year_id', 'enterprise_id'] }
},
join : ['period.fiscal_year_id=fiscal_year.id'],
where : ['period.period_start<=' + util.sqlDate(), 'AND', 'period.period_stop>=' + util.sqlDate()]
};

currencies = {
'tables' : {
'currency' : {
'columns' : ['id', 'name', 'symbol', 'min_monentary_unit']
}
}
where : ['period.start_date<=' + util.sqlDate(), 'AND', 'period.end_date>=' + util.sqlDate()]
};

// set appstate variables
// TODO : Loading exchange rates should be moved into a service
// where only the pages needing exchange rates load them.
setEnvironmentVariable('fiscalYears', fiscalYear);
setEnvironmentVariable('currencies', currencies);
setEnvironmentVariable('exchange_rate', exchangeRate);

// FIXME hack to make sure that appstate has user,
// project, and enterprise defined
$timeout(function () {

// FIXME hack to make receipts work with locations
var project = Session.project;
project.location_id = Session.enterprise.location_id;

appstate.set('enterprise', Session.enterprise);
appstate.set('project', Session.project);
appstate.set('user', Session.user);

// TODO Position this to gaurantee the project is populated
vm.projectName = Session.project.name;
});

// FIXME
// set DEPRECATED appstate variables until we can change them
Expand All @@ -107,6 +71,7 @@ function ApplicationController($timeout, AppCache, appstate, connect, util, Sess

// Optionally expand sidebar
// vm.sidebarExpanded = true;
vm.projectName = Session.project.name;
}

// utility function to set appstate() variables
Expand Down
27 changes: 17 additions & 10 deletions client/src/partials/cash/cashboxes/cashboxes.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
<div class="row">

<div class="col-md-6">
<table class="table table-striped table-bordered table-condensed" style="max-height:600px; overflow:auto;">
<table class="table table-striped table-bordered table-condensed" style="max-height:80vh; overflow:auto;">
<thead>
<tr>
<th colspan="2">{{ "TABLE.COLUMNS.NAME" | translate }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="box in CashCtrl.cashboxes track by box.id">
<td>{{ box.text }}</td>
<td>{{ box.label}}</td>
<td class="text-right">
<a class="btn btn-xs btn-default" ng-click="CashCtrl.update(box.id)"><i class="glyphicon glyphicon-pencil"></i> {{ "FORM.BUTTONS.EDIT" | translate }}</a>
<a class="btn btn-xs btn-default" ng-click="CashCtrl.update(box.id)">
<i class="glyphicon glyphicon-pencil"></i> {{ "FORM.BUTTONS.EDIT" | translate }}
</a>
</td>
</tr>
</tbody>
Expand All @@ -55,8 +57,8 @@ <h4>{{ "CASHBOX.TITLE" | translate }}</h4>
<label class="control-label">
{{ "FORM.LABELS.NAME" | translate }}
</label>
<input class="form-control" name="text" ng-model="CashCtrl.box.text" required>
<div class="help-block" ng-messages="CreateForm.text.$error" ng-show="CreateForm.$submitted">
<input class="form-control" name="label" ng-model="CashCtrl.box.label" required>
<div class="help-block" ng-messages="CreateForm.label.$error" ng-show="CreateForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
Expand All @@ -72,7 +74,7 @@ <h4>{{ "CASHBOX.TITLE" | translate }}</h4>

<div class="radio">
<label>
<input type="radio" name="type" ng-model="CashCtrl.box.type" value="auxillary" required>
<input type="radio" name="type" ng-model="CashCtrl.box.type" value="auxiliary" required>
{{ "FORM.LABELS.AUXILIARY" | translate }}
</label>
</div>
Expand All @@ -85,7 +87,12 @@ <h4>{{ "CASHBOX.TITLE" | translate }}</h4>
<label class="control-label">
{{ "FORM.LABELS.PROJECT" | translate }}
</label>
<select class="form-control" name="project" ng-model="CashCtrl.box.project_id" ng-options="project.id as project.name for project in CashCtrl.projects" required>
<select
class="form-control"
name="project"
ng-model="CashCtrl.box.project_id"
ng-options="project.id as project.name for project in CashCtrl.projects track by project.id"
required>
<option value="" disabled>{{ "FORM.SELECTS.SELECT_PROJECT" | translate }}</option>
</select>
<div class="help-block" ng-messages="CreateForm.project.$error" ng-show="CreateForm.$submitted">
Expand Down Expand Up @@ -115,8 +122,8 @@ <h4>{{ "CASHBOX.TITLE" | translate }}</h4>
<label class="control-label">
{{ "FORM.LABELS.NAME" | translate }}
</label>
<input class="form-control" name="text" ng-model="CashCtrl.box.text" required>
<div class="help-block" ng-messages="UpdateForm.text.$error" ng-show="UpdateForm.$submitted">
<input class="form-control" name="label" ng-model="CashCtrl.box.label" required>
<div class="help-block" ng-messages="UpdateForm.label.$error" ng-show="UpdateForm.$submitted">
<div ng-messages-include="partials/templates/messages.tmpl.html"></div>
</div>
</div>
Expand Down Expand Up @@ -164,7 +171,7 @@ <h4>{{ "CASHBOX.TITLE" | translate }}</h4>
class="form-control"
name="project"
ng-model="CashCtrl.box.project_id"
ng-options="project.id as project.name for project in CashCtrl.projects track by project.id"
ng-options="project.id as project.name for project in CashCtrl.projects"
required>
<option value="" disabled>{{ "FORM.SELECTS.SELECT_PROJECT" | translate }}</option>
</select>
Expand Down
Loading

0 comments on commit 7f9ae02

Please sign in to comment.