Skip to content

Commit

Permalink
Merge remote-tracking branch 'vanga/master' into feature-patient-visits
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Niles committed Jan 8, 2017
2 parents 82b299d + cc57877 commit db88375
Show file tree
Hide file tree
Showing 88 changed files with 1,427 additions and 3,201 deletions.
10 changes: 10 additions & 0 deletions client/src/css/structure.css
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,13 @@ growl-notification.fading.ng-leave.ng-leave-active {
.ui-select-bootstrap > .ui-select-choices.ui-grid-ui-select {
width: initial;
}

/* fix weird whitespace at the top of grids. */
.ui-grid-canvas {
padding-top : 0;
}

/* fix weird double-line on grid footers */
.ui-grid-footer-panel {
border-bottom: none;
}
9 changes: 6 additions & 3 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@
"UPDATE" : "Update a creditor group",
"FAILURE_DELETE" : "Failure of the deletion of the creditor group"
},
"DB": {
"ER_ROW_IS_REFERENCED_2" : "Cannot delete entry since it has been used in a transaction."
},
"DEBTOR_GROUP": {
"BACK" : "Back to Debtor Groups",
"CREATE" : "Create Debtor Group",
Expand Down Expand Up @@ -208,6 +205,11 @@
"LOADING" : "Fetching Debtor Group",
"SUBSCRIPTIONS" : "Subscriptions"
},
"DOWNLOADS" : {
"JSON" : "Download as JSON",
"PDF" : "Download as PDF",
"CSV" : "Download as CSV"
},
"DEPOT": {
"ADD_DEPOT" : "Add a Depot",
"ALL_DEPOTS" : "All Depots",
Expand Down Expand Up @@ -653,6 +655,7 @@
"TRANSACTION" : "Transaction",
"TRANSFER_ACCOUNT" : "Transfer Account",
"TRANSFER_TYPE" : "Transfer Type",
"TRANSACTION_TYPE" : "Transaction Type",
"TYPE" : "Type",
"UNCONFIGURED" : "Unconfigured",
"UNDEFINED" : "Undefined",
Expand Down
3 changes: 3 additions & 0 deletions client/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ function constantConfig() {
AGED_DEBTOR : 'AGED_DEBTOR',
CASHFLOW : 'CASHFLOW',
INCOME_EXPENSE : 'INCOME_EXPENSE'
},
precision: {
MAX_DECIMAL_PRECISION : 4
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/js/components/bhPDFPrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ angular.module('bhima.components')
options : '<'
},
transclude : true,
template :
template :
'<a href ng-click="$ctrl.print()">' +
'<span ng-if="!$ctrl.$loading"><i class="fa fa-print"></i> {{ $ctrl.buttonText | translate }}</span>' +
'<span ng-if="$ctrl.$loading"><i class="fa fa-spin fa-circle-o-notch"></i> {{ "FORM.INFO.LOADING" | translate }}</span>' +
Expand Down Expand Up @@ -76,6 +76,7 @@ function bhPDFPrintController($window, $http, $sce, $timeout, Languages) {
renderer : 'pdf',
lang : Languages.key
};

var responseType = 'arraybuffer';
var pdfType = 'application/pdf';

Expand Down Expand Up @@ -142,7 +143,6 @@ function bhPDFPrintController($window, $http, $sce, $timeout, Languages) {
component.$loading = !component.$loading;
}


// ensure that the template/ iframe element is available
// both the $onInit and $postLink methods are fired before guaranteeing the
// id has been dynamically set
Expand Down
70 changes: 70 additions & 0 deletions client/src/js/components/bhRendererDropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
angular.module('bhima.components')
.component('bhRendererDropdown', {
bindings : {
reportUrl : '@',
reportOptions : '<'
},
templateUrl : 'partials/templates/bhRendererDropdown.tmpl.html',
controller : bhRendererController
});

bhRendererController.$inject = [ 'appcache', '$http', '$timeout', '$sce', '$window' ];

function bhRendererController(AppCache, $http, $timeout, $sce, $window) {
var $ctrl = this;

var cache = new AppCache('bhRendererComponent');

// delay between GET request completion and loading indication, this is used
// to compensate for the delay in browsers opening the print dialog
var loadingIndicatorDelay = 1000;

$ctrl.$onInit = function () {
$ctrl.options = [
{ icon : 'file-code-o', key : 'DOWNLOADS.JSON', parameters : { renderer: 'json'}, type : 'application/json' },
{ icon : 'file-excel-o', key : 'DOWNLOADS.CSV', parameters : { renderer: 'csv'}, type : 'application/csv' },
{ icon : 'file-pdf-o', key : 'DOWNLOADS.PDF', parameters : { renderer: 'pdf'}, type : 'application/pdf' }
];

$ctrl.selection = cache.selection || $ctrl.options[0];

$ctrl.reportOptions = $ctrl.reportOptions || {};

$ctrl.$loading = false;
};

$ctrl.select = function (option) {
$ctrl.selection = cache.selection = option;
};

$ctrl.execute = function () {
var url = $ctrl.reportUrl;

var parameters = {};
angular.extend(parameters, $ctrl.reportOptions, $ctrl.selection.parameters);

$http.get(url, { params : parameters, responseType : 'arraybuffer' })
.then(function (response) {
var blob = new Blob([response.data], { type: $ctrl.selection.type });
var objectUrl = $sce.trustAsResourceUrl(URL.createObjectURL(blob));
$window.open(objectUrl);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
$timeout(toggleLoading, loadingIndicatorDelay);
});
};

/**
* @method toggleLoading
*
* @description
* This method is responsible for updating the loading state for the controllers
* HTTP requests.
*/
function toggleLoading() {
$ctrl.$loading = !$ctrl.$loading;
}
}
2 changes: 1 addition & 1 deletion client/src/js/services/DebtorGroupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function DebtorGroupService($http, Modal, util, SessionService) {
function invoices(uuid, parameters) {
var url = baseUrl.concat(uuid, '/invoices');
return $http.get(url, { params : parameters })
.then(util.unwrapHttpResponse);
.then(util.unwrapHttpResponse);
}

return service;
Expand Down
3 changes: 0 additions & 3 deletions client/src/js/services/PatientInvoiceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ PatientInvoiceFormService.$inject = [
* with the Patient PatientInvoiceForm module. You must specify a cacheKey to enable the
* class to be instantiated correctly.
*
* @todo (required) discuss if all subsidies/billings services are all
* percentages. If so, the logic can be simplified.
* @todo (required) only the maximum of the bill should be subsidised
* @todo (required) billing services and subsidies should be ignored for
* specific debtors.
Expand Down Expand Up @@ -104,7 +102,6 @@ function PatientInvoiceFormService(Patients, PriceLists, Inventory, AppCache, St

// the invoice details
this.details = {
is_distributable : 1,
date : new Date(),
cost : 0,
description : null
Expand Down
1 change: 0 additions & 1 deletion client/src/js/services/PatientInvoiceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function PatientInvoiceService(Modal, util, Session, Api) {
*/
function formatFilterParameters(params) {
var columns = [
{ field: 'is_distributable', displayName: 'FORM.LABELS.DISTRIBUTABLE' },
{ field: 'service_id', displayName: 'FORM.LABELS.SERVICE' },
{ field: 'user_id', displayName: 'FORM.LABELS.USER' },
{ field: 'reference', displayName: 'FORM.LABELS.REFERENCE' },
Expand Down
2 changes: 0 additions & 2 deletions client/src/js/services/TransactionTypeStoreService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ TransactionTypeStoreService.$inject = ['$q', 'TransactionTypeService', 'Store'];
* Transaction Type Store Controller
*/
function TransactionTypeStoreService($q, TransactionType, Store) {
'use strict';

var service = this;
var data = new Store();
var initialLoad = true;
Expand Down
40 changes: 38 additions & 2 deletions client/src/js/services/VoucherService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ angular.module('bhima.services')
.service('VoucherService', VoucherService);

VoucherService.$inject = [
'PrototypeApiService', '$http', 'util',
'TransactionTypeStoreService'
'PrototypeApiService', '$http', 'util', 'TransactionTypeStoreService'
];

/**
Expand All @@ -24,10 +23,47 @@ function VoucherService(Api, $http, util, TransactionTypeStore) {
service.reverse = reverse;
service.transactionType = transactionType;

// returns true if the key starts with an underscore
function isInternalKey(key) {
return key[0] === '_' || key[0] === '$';
}

// strips internal keys from object
function stripInternalObjectKeys(object) {

var o = {};

angular.forEach(object, function (value, key) {
if (!isInternalKey(key)) {
o[key] = value;
}
});

return o;
}

/**
* Wraps the prototype create method.
*/
function create(voucher) {

var v = angular.copy(voucher);

// format items for posting, removing validation keys and unlinking old objects
v.items = v.items.map(function (item) {
var escapedItem = stripInternalObjectKeys(item);

if (escapedItem.entity) {
escapedItem.entity_uuid = escapedItem.entity.uuid;
}

if (escapedItem.reference) {
escapedItem.reference_uuid = escapedItem.reference.uuid;
}

return escapedItem;
});

return Api.create.call(service, { voucher : voucher });
}

Expand Down
102 changes: 102 additions & 0 deletions client/src/js/services/grid/GridAggregator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
angular.module('bhima.services')
.factory('GridAggregatorService', GridAggregatorService);

GridAggregatorService.$inject = [
'uiGridGroupingConstants', '$filter', 'SessionService'
];

/**
* Grid Aggregator Service
*
* This service contains all aggregators used in bhima, keyed on the column ID. These should
* provide enough detail, along with the aggregation detail.
*
* @todo - finish aggregation for footers
*/
function GridAggregatorService(uiGridGroupingConstants, $filter, Session) {

// cache the enterprise currency id for easy lookup
var enterpriseCurrencyId= Session.enterprise.currency_id;

// cache the currency filter for later lookup
var $currency = $filter('currency');
var $date = $filter('date');

// alias copy
var extend = angular.extend;

/**
* @const TREE_DEFAULTS
*
* @description
* These are to be used with ui-grid-tree-view or ui-grid-grouping. Otherwise, they are not
* hooked up. This is separate from regular aggregators embedded on ui-grid (by setting
* aggregationType on the columnDef). Those do not allow you to set a custom label.
*/
var TREE_DEFAULTS = {

// used to render amounts in the aggregate columns
cost : {
customTreeAggregationFinalizerFn : function (aggregation) {
aggregation.rendered = $currency(aggregation.value, enterpriseCurrencyId);
},

treeAggregationType : uiGridGroupingConstants.aggregation.SUM,
hideAggregationLabel : true
},

quanity : {
treeAggregationType : uiGridGroupingConstants.aggregation.SUM,
},

single : {
treeAggregationType: uiGridGroupingConstants.aggregation.MAX,
customTreeAggregationFinalizerFn: function (aggregation) {
aggregation.rendered = aggregation.value;
},
hideAggregationLabel : true
},

date : {
treeAggregationType: uiGridGroupingConstants.aggregation.AVG,
customTreeAggregationFinalizerFn: function (aggregation) {
aggregation.rendered = $date(aggregation.value);
},
hideAggregationLabel : true
}
};

// list of aggregators to be returned
var aggregators = {
tree : {
debit : extend({}, TREE_DEFAULTS.cost),
credit : extend({}, TREE_DEFAULTS.cost),
debit_equiv : extend({}, TREE_DEFAULTS.cost),
credit_equiv : extend({}, TREE_DEFAULTS.cost),
date : extend({}, TREE_DEFAULTS.date),
trans_date : extend({}, TREE_DEFAULTS.date),
description : extend({}, TREE_DEFAULTS.single)
},
};


/**
* @function extendColumnWithAggregator
*
* @param {Object} column - the grid column to be extended
* @param {Object} aggregator - an aggregator to attach to the column.
*
* @description
* This function provides an easy way to attache an aggregation function
* from the controller.
*/
function extendColumnWithAggregator(column, aggregator) {
extend(column, aggregator);
}

// return the aggregators and methods
return {
aggregators : aggregators,
extendColumnWithAggregator : extendColumnWithAggregator
};
}
Loading

0 comments on commit db88375

Please sign in to comment.