Skip to content

Commit

Permalink
fix(purchase): ui glitches in purchase orders
Browse files Browse the repository at this point in the history
This commit fixes the following issues:
 1. Payment defaults to "on purchase" instead of "on delivery"
 2. The button to fetch the cache has been removed.

Closes #1842.
  • Loading branch information
jniles committed Jan 9, 2018
1 parent 9b3d24f commit c7ef425
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 74 deletions.
7 changes: 3 additions & 4 deletions client/src/modules/purchases/create/PurchaseOrderForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function PurchaseOrderFormService(Inventory, AppCache, Store, Pool, PurchaseOrde

// the order details
this.details = {
payment_method: 'FORM.LABELS.ON_DELIVERY',
payment_method: 'FORM.LABELS.ON_PURCHASE',
date: new Date(),
cost: 0,
};
Expand Down Expand Up @@ -226,12 +226,11 @@ function PurchaseOrderFormService(Inventory, AppCache, Store, Pool, PurchaseOrde
* @param {Object} item - the item/row to be configured
*/
PurchaseOrderForm.prototype.configureItem = function configureItem(item) {

// remove the item from the pool
var inventoryItem = this.inventory.use(item.inventory_uuid);

/**
* FIX ME or NEED Discussion, The Purchase Order must Used Purchase Price and not
/**
* FIX ME or NEED Discussion, The Purchase Order must Used Purchase Price and not
* Used Inventory Selling price
*/
inventoryItem.price = 0;
Expand Down
36 changes: 12 additions & 24 deletions client/src/modules/purchases/create/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- top note panel for the purchase order details inspired by the patient invoice page's ergonomics -->
<form
name="PurchaseOrderForm"
autocomplete="off"
autocomplete="off"
autocapitalize="off"
autocorrect="off"
ng-submit="PurchaseCtrl.submit(PurchaseOrderForm)"
Expand All @@ -22,7 +22,7 @@
<div class="col-xs-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="col-md-6">
<div class="col-md-6">
<bh-supplier-select
supplier-uuid="PurchaseCtrl.order.details.supplier_uuid"
required="true"
Expand Down Expand Up @@ -57,7 +57,7 @@
<div class="radio">
<label>
<input type="radio" name="paymentMethod" id="other" value="FORM.LABELS.OTHER" ng-model="PurchaseCtrl.order.details.payment_method" required>
<span translate>FORM.LABELS.OTHER</span>
<span translate>FORM.LABELS.OTHER</span>
</label>
</div>

Expand Down Expand Up @@ -108,27 +108,15 @@
ng-click="PurchaseCtrl.optimalPurchase()"
id="optimal_purchase"
ng-disabled="!PurchaseCtrl.supplier">
<i class="fa fa-shopping-cart"></i>
<span translate>FORM.BUTTONS.OPTIMAL_PURCHASE_ORDER </span>
</button>
</div>

<!-- "Recover Items" button -->
<div class="btn-group pull-right" role="group">
<button
class="btn btn-default"
ng-class="{'btn-primary' : PurchaseCtrl.order.hasCacheAvailable() && PurchaseCtrl.order.details.supplier_uuid }"
ng-click="PurchaseCtrl.order.readCache()"
ng-disabled="!PurchaseCtrl.order.hasCacheAvailable() || !PurchaseCtrl.supplier">
<span class="fa fa-recycle"></span>
<span translate>FORM.BUTTONS.RECOVER_ITEMS</span>
<i class="fa fa-shopping-cart"></i>
<span translate>FORM.BUTTONS.OPTIMAL_PURCHASE_ORDER </span>
</button>
</div>

<!-- "Add number of grid rows" input-group -->
<bh-add-item
disable = "PurchaseCtrl.supplier && !PurchaseCtrl.optimalPO"
callback = "PurchaseCtrl.addItems(numItem)">
disable="PurchaseCtrl.supplier && !PurchaseCtrl.optimalPO"
callback="PurchaseCtrl.addItems(numItem)">
</bh-add-item>

<!-- @todo - hacky check for inventory to prevent local variables -->
Expand All @@ -137,28 +125,28 @@
class="text-warning"
ng-show="PurchaseCtrl.order.inventory.size() > 0 && PurchaseCtrl.order.inventory.available.data.length === 0">
<span class="fa fa-info-circle"></span>
<span translate>FORM.INFO.ITEMS_FULL</span>
<span translate>FORM.INFO.ITEMS_FULL</span>
</p>

<p
style="padding-top : 10px;"
class="text-info"
ng-show="!PurchaseCtrl.supplier">
<span class="fa fa-info-circle"></span>
<span translate>FORM.INFO.NO_SUPPLIER</span>
<span translate>FORM.INFO.NO_SUPPLIER</span>
</p>
</div>
</div>

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

<div class="row" ng-if="PurchaseCtrl.supplier">
<h4 class="text-right" style="margin-right: 25px;">
<span translate>FORM.LABELS.TOTAL</span>
<span translate>FORM.LABELS.TOTAL</span>
{{ PurchaseCtrl.order.totals.rows | currency:PurchaseCtrl.enterprise.currency_id }}
</h4>
</div>
Expand All @@ -183,7 +171,7 @@ <h4 class="text-right" style="margin-right: 25px;">
class="text-danger"
ng-show="PurchaseCtrl.order._invalid && PurchaseOrderForm.$submitted">
<span class="fa fa-exclamation-circle"></span>
<span translate>FORM.ERRORS.INVALID</span>
<span translate>FORM.ERRORS.INVALID</span>
</p>
</div>
</div>
Expand Down
78 changes: 38 additions & 40 deletions client/src/modules/purchases/create/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('bhima.controllers')
.controller('PurchaseOrderController', PurchaseOrderController);
.controller('PurchaseOrderController', PurchaseOrderController);

PurchaseOrderController.$inject = [
'PurchaseOrderService', 'PurchaseOrderForm', 'NotifyService',
Expand All @@ -14,7 +14,6 @@ function PurchaseOrderController(Purchases, PurchaseOrder, Notify, Session, util
vm.order = new PurchaseOrder('PurchaseOrder');
vm.bhConstants = bhConstants;

vm.itemIncrement = 1;
vm.enterprise = Session.enterprise;
vm.maxLength = util.maxLength;
vm.maxDate = new Date();
Expand All @@ -23,7 +22,7 @@ function PurchaseOrderController(Purchases, PurchaseOrder, Notify, Session, util
vm.optimalPurchase = optimalPurchase;
vm.optimalPO = false;

function setSupplier (supplier) {
function setSupplier(supplier) {
vm.supplier = supplier;
vm.order.setSupplier(supplier);
}
Expand All @@ -34,17 +33,17 @@ function PurchaseOrderController(Purchases, PurchaseOrder, Notify, Session, util
enableSorting : false,
enableColumnMenus : false,
columnDefs : [
{ field: 'status', width: 25, displayName : '', cellTemplate: 'modules/purchases/create/templates/status.tmpl.html' },
{ field: 'code', width: 150, displayName: 'TABLE.COLUMNS.CODE', headerCellFilter: 'translate', cellTemplate: 'modules/purchases/create/templates/code.tmpl.html' },
{ field: 'description', displayName: 'TABLE.COLUMNS.DESCRIPTION', headerCellFilter: 'translate' },
{ field: 'unit', width:100, displayName: 'TABLE.COLUMNS.UNIT', headerCellFilter: 'translate' },
{ field: 'quantity', width:100, displayName: 'TABLE.COLUMNS.QUANTITY', headerCellFilter: 'translate', cellTemplate: 'modules/purchases/create/templates/quantity.tmpl.html' },
{ field: 'unit_price', width: 100, displayName: 'TABLE.COLUMNS.PURCHASE_PRICE', headerCellFilter: 'translate', cellTemplate: 'modules/purchases/create/templates/price.tmpl.html' },
{ field: 'amount', width:100, displayName: 'TABLE.COLUMNS.AMOUNT', headerCellFilter: 'translate', cellTemplate: 'modules/purchases/create/templates/amount.tmpl.html' },
{ field: 'actions', width: 25, cellTemplate: 'modules/purchases/create/templates/actions.tmpl.html' }
{ field : 'status', width : 25, displayName : '', cellTemplate : 'modules/purchases/create/templates/status.tmpl.html' },
{ field : 'code', width : 150, displayName : 'TABLE.COLUMNS.CODE', headerCellFilter : 'translate', cellTemplate : 'modules/purchases/create/templates/code.tmpl.html' },
{ field : 'description', displayName : 'TABLE.COLUMNS.DESCRIPTION', headerCellFilter : 'translate' },
{ field : 'unit', width :100, displayName : 'TABLE.COLUMNS.UNIT', headerCellFilter : 'translate' },
{ field : 'quantity', width :100, displayName : 'TABLE.COLUMNS.QUANTITY', headerCellFilter : 'translate', cellTemplate : 'modules/purchases/create/templates/quantity.tmpl.html' },
{ field : 'unit_price', width : 100, displayName : 'TABLE.COLUMNS.PURCHASE_PRICE', headerCellFilter : 'translate', cellTemplate : 'modules/purchases/create/templates/price.tmpl.html' },
{ field : 'amount', width :100, displayName : 'TABLE.COLUMNS.AMOUNT', headerCellFilter : 'translate', cellTemplate : 'modules/purchases/create/templates/amount.tmpl.html' },
{ field : 'actions', width : 25, cellTemplate : 'modules/purchases/create/templates/actions.tmpl.html' }
],
onRegisterApi : onRegisterApi,
data : vm.order.store.data
data : vm.order.store.data,
};

// this function will be called whenever items change in the grid.
Expand All @@ -64,7 +63,6 @@ function PurchaseOrderController(Purchases, PurchaseOrder, Notify, Session, util

// submits the form
function submit(form) {

// make sure form validation is triggered
form.$setSubmitted();

Expand Down Expand Up @@ -112,7 +110,7 @@ function PurchaseOrderController(Purchases, PurchaseOrder, Notify, Session, util
}

// clears the module, resetting it
//TODO : Choose a better name for a starting method
// TODO : Choose a better name for a starting method
function clear(form) {
// remove the data
delete vm.supplier;
Expand All @@ -127,35 +125,35 @@ function PurchaseOrderController(Purchases, PurchaseOrder, Notify, Session, util
}
}

function optimalPurchase () {
function optimalPurchase() {
vm.optimalPO = true;

Stock.inventories.read(null, {require_po : 1})
.then(function (rows) {
if (!rows.length) {
return Notify.warn('FORM.INFO.NO_INVENTORY_PO');
}

// adding items.length line in the Order store, which will be reflected to the grid
if (rows.length > 1) {
vm.order.addItem(rows.length);
}

vm.order.store.data.forEach(function (item, index) {
item.code = rows[index].code;
item.inventory_uuid = rows[index].inventory_uuid;
item.description = rows[index].text;
item.quantity = rows[index].S_Q;
item.unit_price = 0;
item.unit = rows[index].unit_type;
item._initialised = true;
});
Stock.inventories.read(null, { require_po : 1 })
.then(function (rows) {
if (!rows.length) {
return Notify.warn('FORM.INFO.NO_INVENTORY_PO');
}

// adding items.length line in the Order store, which will be reflected to the grid
if (rows.length > 1) {
vm.order.addItem(rows.length);
}

vm.order.store.data.forEach(function (item, index) {
item.code = rows[index].code;
item.inventory_uuid = rows[index].inventory_uuid;
item.description = rows[index].text;
item.quantity = rows[index].S_Q;
item.unit_price = 0;
item.unit = rows[index].unit_type;
item._initialised = true;
});

})
.catch(Notify.handleError)
.finally(function () {
vm.loadingState = false;
});
})
.catch(Notify.handleError)
.finally(function () {
vm.loadingState = false;
});
}

// bind methods
Expand Down
10 changes: 4 additions & 6 deletions client/src/modules/purchases/list/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<a class="btn btn-default" uib-dropdown-toggle>
<span class="fa fa-bars"></span> <span class="hidden-xs" translate>FORM.LABELS.MENU</span> <span class="caret"></span>
</a>

<ul uib-dropdown-menu role="menu" class="dropdown-menu-right">
<li role="menuitem">
<a href data-method="configure" ng-click="PurchaseListCtrl.openColumnConfiguration()">
<i class="fa fa-columns"></i> <span translate>FORM.LABELS.COLUMNS</span>
</a>
</li>
</li>

<li role="separator" class="divider"></li>
<li role="separator" class="divider"></li>
<li role="menuitem">
<a href data-method="save-state" ng-click="PurchaseListCtrl.saveGridState()">
<i class="fa fa-save"></i> <span translate>FORM.BUTTONS.SAVE_GRID_CONFIGURATION</span>
Expand All @@ -44,12 +44,10 @@
<span class="fa fa-file-excel-o"></span> <span translate>DOWNLOADS.CSV</span>
</a>
</li>

</ul>

</div>
</div>

<div class="toolbar-item">
<button
ng-click="PurchaseListCtrl.search()"
Expand Down

0 comments on commit c7ef425

Please sign in to comment.