Skip to content

Commit

Permalink
fix(purchase): implement feedback on PR
Browse files Browse the repository at this point in the history
This commit implements the feedback from @sfount.
 1. bhConstants is used to set the grid height at the initial module
 load.
 2. The `purchases/new` path has been renamed to `purchases/create`.
 3. The relevant `ui-grid` cells leverage `ui-grid-cell-contents` to
 ensure proper overflows, padding, and centering on small screens.
 4. Resolved mixed aliases for `this` in services.
 5. Ensure that the `currency_id` is set on the server, not the client.
  • Loading branch information
jniles committed Jun 29, 2016
1 parent da01118 commit b30eb6e
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 51 deletions.
5 changes: 4 additions & 1 deletion client/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function bhimaConfig($stateProvider, $urlRouterProvider, $urlMatcherFactoryProvi


.state('purchasesCreate', {
url : '/purchases/new',
url : '/purchases/create',
controller : 'PurchaseOrderController as PurchaseCtrl',
templateUrl : 'partials/purchases/create/create.html'
})
Expand Down Expand Up @@ -566,6 +566,9 @@ function constantConfig() {
accounts : {
ROOT : 0,
TITLE : 4
},
purchase : {
GRID_HEIGHT: 200
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/js/services/AccountService.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function AccountService($http, util, Session) {
* @returns {Array} - the flattened array
*/
function flatten(tree, depth) {
var depth = isNaN(depth) ? -1 : depth;
depth = isNaN(depth) ? -1 : depth;
depth += 1;

return tree.reduce(function (array, node) {
Expand Down
3 changes: 0 additions & 3 deletions client/src/js/services/PurchaseOrderService.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ function PurchaseOrderService(Api, Session) {
return item;
});

// automatically set the currency_id to the enterprise currency
data.currency_id = Session.enterprise.currency_id;

return Api.create.call(service, data);
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/partials/accounts/AccountGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function AccountGridService(AccountStore, Accounts, Store, Notify) {

AccountGrid.prototype.insertDifference = function insertDifference(account, index) {
this.data.splice(index, 0, account);
}
};

return AccountGrid;
}
38 changes: 19 additions & 19 deletions client/src/partials/accounts/accounts.routes.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@

angular.module('bhima.routes')
.config(['$stateProvider', function ($stateProvider) {
.config(['$stateProvider', function ($stateProvider) {

$stateProvider
.state('accounts', {
abstract : true,
url : '/accounts',
controller: 'AccountsController as AccountsCtrl',
templateUrl: 'partials/accounts/accounts.html'
})

.state('accounts.create', {
url : '/create',
params : {
parentId : { squash : true, value : null }
},
onEnter :['$state', '$uibModal', accountsModal]
onEnter :['$state', '$uibModal', accountsModal]
})
.state('accounts.list', {
url : '/:id',
params : {
params : {
id : { squash : true, value : null }
}
})
.state('accounts.edit', {

.state('accounts.edit', {
url : '/:id/edit',
params : {
params : {
id : { squash : true, value : null }
},
onEnter :['$state', '$uibModal', accountsModal]
})
});
}]);

function accountsModal($state, $modal) {
function accountsModal($state, $modal) {
var instance = $modal.open({
keyboard : false,
backdrop : 'static',
templateUrl: 'partials/accounts/edit/accounts.edit.modal.html',
controller: 'AccountEditController as AccountEditCtrl'
})
instance.result.then(function (result) {
// clean up action
});
keyboard : false,
backdrop : 'static',
templateUrl: 'partials/accounts/edit/accounts.edit.modal.html',
controller: 'AccountEditController as AccountEditCtrl'
});

instance.result.then(function (result) {
// clean up action
});
}
20 changes: 10 additions & 10 deletions client/src/partials/patients/record/patient_record.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ PatientRecordController.$inject = ['$stateParams', 'PatientService', 'NotifyServ
function PatientRecordController($stateParams, Patients, Notify, moment, Upload, $timeout) {
var vm = this;
var patientID = $stateParams.patientID;

vm.loading = true;
vm.uploadFiles = uploadFiles;
vm.uploadButtonText = 'PATIENT_RECORDS.UPLOAD_PICTURE';

function uploadFiles(file, invalidFiles) {
if(invalidFiles.length){
Notify.danger('FORM.WARNNINGS.BAD_FILE_TYPE');
return
Notify.danger('FORM.WARNNINGS.BAD_FILE_TYPE');
return;
}

if (file) {
var imageCheck = file.type.search("image/");
var imageCheck = file.type.search('image/');
if(imageCheck !== -1){
file.upload = Upload.upload({
url: '/patients/' + patientID + '/pictures',
url: '/patients/' + patientID + '/pictures',
data: {pictures: file}
});

Expand All @@ -37,7 +37,7 @@ function PatientRecordController($stateParams, Patients, Notify, moment, Upload,
} else {
Notify.danger('FORM.INFOS.UPLOAD_PICTURE_FAILED');
}
}
}
}

/** @fixme if no uuid is provided this will download all the patients through the base url '/' */
Expand All @@ -50,12 +50,12 @@ function PatientRecordController($stateParams, Patients, Notify, moment, Upload,
vm.uploadButtonText = 'PATIENT_RECORDS.UPDATE_PICTURE';
}

/** @todo move to service or mysql query */
/** @todo move to service or mysql query */
vm.patient.name = [vm.patient.first_name, vm.patient.middle_name, vm.patient.last_name].join(' ');
vm.patient.age = moment().diff(vm.patient.dob, 'years');
})
.catch(function (error) {
vm.loading = false;
Notify.handleError(error);
});
}
});
}
6 changes: 3 additions & 3 deletions client/src/partials/purchases/create/PurchaseOrderForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ function PurchaseOrderFormService(Inventory, AppCache, Store, Pool, PurchaseOrde
*/
PurchaseOrderForm.prototype.digest = function digest() {
var order = this;
var totals = this.totals;
var totals = order.totals;

// loop through the items summing them into a total
totals.rows = this.store.data.reduce(function (value, unit) {
totals.rows = order.store.data.reduce(function (value, unit) {

// compute validation
unit.validate();
Expand All @@ -164,7 +164,7 @@ function PurchaseOrderFormService(Inventory, AppCache, Store, Pool, PurchaseOrde
var order = this;

// copy the data so that forEach() doesn't get confused.
var cp = angular.copy(this.store.data);
var cp = angular.copy(order.store.data);

// remove each item from the store
cp.forEach(function (item) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/partials/purchases/create/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
</div>
</div>

<div id="purchase-order-grid" ui-grid="PurchaseCtrl.gridOptions" style="height : 230px; width : 100%;" ui-grid-auto-resize ui-grid-cellNav>
<div id="purchase-order-grid" ui-grid="PurchaseCtrl.gridOptions" style="height : {{ ::PurchaseCtrl.bhConstants.GRID_HEIGHT }}px; width : 100%;" ui-grid-auto-resize ui-grid-cellNav>
</div>

<div class="row" ng-if="PurchaseCtrl.supplier">
Expand Down
5 changes: 3 additions & 2 deletions client/src/partials/purchases/create/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ angular.module('bhima.controllers')

PurchaseOrderController.$inject = [
'PurchaseOrderService', 'PurchaseOrderForm', 'SupplierService', 'NotifyService',
'SessionService', 'util', 'ReceiptModal'
'SessionService', 'util', 'ReceiptModal', 'bhConstants'
];


function PurchaseOrderController(Purchases, PurchaseOrder, Suppliers, Notify, Session, util, Receipts) {
function PurchaseOrderController(Purchases, PurchaseOrder, Suppliers, Notify, Session, util, Receipts, bhConstants) {
var vm = this;

// create a new purchase order form
vm.order = new PurchaseOrder('PurchaseOrder');
vm.bhConstants = bhConstants;

vm.itemIncrement = 1;
vm.enterprise = Session.enterprise;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div style="padding : 5px;" class="text-center">
<div class="ui-grid-cell-contents text-center">
<a href="" ng-click="grid.appScope.order.removeItem(row.entity)" tabindex="-1"><i class="fa fa-trash-o text-danger"></i></a>
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div style="padding : 5px; text-align : right;">
<div class="ui-grid-cell-contents" style="text-align:right;">
{{ row.entity.quantity * row.entity.unit_price | currency:grid.appScope.enterprise.currency_id }}
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-hide="row.entity._valid" class="text-center"
<div ng-hide="row.entity._valid" class="ui-grid-cell-contents text-center"
ng-class="{
'bg-warning text-warning' : !row.entity._initialised,
'bg-danger text-danger' : row.entity._initialised
Expand All @@ -12,7 +12,7 @@
<span ng-show="row.entity._initialised" class="fa fa-times-circle"></span>
</div>

<div ng-show="row.entity._valid" class="bg-success text-center" style="padding: 5px;">
<div ng-show="row.entity._valid" class="ui-grid-cell-contents bg-success text-center">
<!-- success state: valid and initialised -->
<span class="text-success fa fa-check-circle"></span>
</div>
4 changes: 1 addition & 3 deletions client/src/partials/templates/modals/reports.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,5 @@ function ReportsModalController(Receipts, Instance, $sce, $window, Data) {
$window.print();
}
Instance.close();
}


};
}
2 changes: 1 addition & 1 deletion client/src/partials/vouchers/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function SimpleJournalVoucherController(AppCache, Vouchers, Accounts, Session, u
vm.descriptionPrefix = String(Session.project.abbr)
.concat('/', selected.prefix, '/')
.concat(current.toDateString());
};
}

startup();
}
2 changes: 1 addition & 1 deletion client/test/e2e/purchases/purchases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const components = require('../shared/components');
describe('Purchase Orders', function () {
'use strict';

const path = '#/purchases/new';
const path = '#/purchases/create';

// navigate to the patient invoice page
beforeEach(() => helpers.navigate(path));
Expand Down
1 change: 1 addition & 0 deletions server/controllers/finance/purchases.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function create(req, res, next) {

data.user_id = req.session.user.id;
data.project_id = req.session.project.id;
data.currency_id = req.session.enterprise.currency_id;

const sql =
'INSERT INTO purchase SET ?';
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 @@ -46,7 +46,7 @@ INSERT INTO unit VALUES
(138, 'Inventory Module', 'TREE.INVENTORY', 'Inventory management module', 0, '/partials/inventory/index', '/inventory'),
(139, 'Inventory List', 'TREE.INVENTORY_LIST', 'Inventory list module', 138, '/partials/inventory/list', '/inventory/list'),
(140, 'Inventory Configurations', 'TREE.INVENTORY_CONFIGURATION', 'Inventory configuration module', 138, '/partials/inventory/configuration', '/inventory/configuration'),
(141, 'Purchase Orders', 'TREE.PURCHASING', 'This module is responsible for creating purchase orders', 138, '/partials/purchases/create', '/purchases/new');
(141, 'Purchase Orders', 'TREE.PURCHASING', 'This module is responsible for creating purchase orders', 138, '/partials/purchases/create', '/purchases/create');

INSERT INTO `account_type` VALUES

Expand Down

0 comments on commit b30eb6e

Please sign in to comment.