Skip to content

Commit

Permalink
Merge #5096 #5102 #5130
Browse files Browse the repository at this point in the history
5096: Feat: add multiple account report link to account references r=jniles a=jniles

This PR implements a link from "account references" to the multiple account statement, auto-populating the data in the multiple account select input.  We can use this mechanism to auto-populate other reports as well (such as stock).  Here is what it looks like in action:

![rQM9i2kLQM](https://user-images.githubusercontent.com/896472/98641537-38002980-232c-11eb-8d6d-a3a1e6046922.gif)


We also need something like this to filter our balance sheet, though that is probably best left for a totally different report (#5094).

5102: refactor(stock): entry from purchase r=jniles a=jniles

This commit refactors the entry from purchase modal to use the standard receipt renderer and clarify the status code.

5130: 4834 - Fix calculation and status about expired and at risk lots r=jniles a=mbayopanda

This PR fixes the report "Stock Expiration Report" by : 

- Adding new columns: CMM and quantity_at_risk
- Fix the way of fetching risky lots
- Fix calculation of the values of lots at risk
- Correctly display expired and risky lots in the table
- Adding the date of the day in the report 

![image](https://user-images.githubusercontent.com/5445251/99654270-5c5db380-2a5a-11eb-89e1-1ae86e8509a6.png)



Co-authored-by: Jonathan Niles <jonathanwniles@gmail.com>
Co-authored-by: mbayopanda <mbayopanda@gmail.com>
  • Loading branch information
3 people authored Nov 22, 2020
4 parents c8bbc19 + e7bdcd4 + 02d2c36 + 6a1fbd3 commit 7602017
Show file tree
Hide file tree
Showing 26 changed files with 166 additions and 124 deletions.
7 changes: 0 additions & 7 deletions client/src/i18n/en/section_bilan.json

This file was deleted.

7 changes: 0 additions & 7 deletions client/src/i18n/en/section_resultat.json

This file was deleted.

2 changes: 2 additions & 0 deletions client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@
"LEGEND" : "Legend",
"LIFETIME" : "Lifetime",
"LOT_LIFETIME" : "Lifetime By Lot",
"CURRENT_QUANTITY" : "Current Quantity",
"RISK" : "Risk",
"RISK_QUANTITY" : "Risk Quantity",
"RISK_VALUE" : "Risk Value",
"CMM" : "CMM",
"MSD" : "MSD",
"LOSS" : "Stock Loss",
Expand Down
2 changes: 0 additions & 2 deletions client/src/i18n/en/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
"ROLE_MANAGEMENT" : "Role Management",
"ROOT" : "Root",
"RUBRIC_MANAGEMENT" : "Rubrics Management",
"SECTION_BILAN" : "Bilan section",
"SECTION_RESULTAT" : "Result Section",
"SERVICE" : "Services",
"SIMPLE_VOUCHER" : "Simple Voucher",
"STAFFING_INDICES_MANAGEMENT" : "Staffing indices management",
Expand Down
7 changes: 0 additions & 7 deletions client/src/i18n/fr/section_bilan.json

This file was deleted.

7 changes: 0 additions & 7 deletions client/src/i18n/fr/section_resultat.json

This file was deleted.

2 changes: 2 additions & 0 deletions client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
"LIFETIME" : "Durée de vie",
"LOT_LIFETIME" : "Durée par lot",
"RISK" : "Risque",
"CURRENT_QUANTITY" : "Quantité actuelle",
"RISK_QUANTITY" : "Quantité à risque",
"RISK_VALUE" : "Valeur à risque",
"CMM" : "CMM",
"MSD" : "MSD",
"LOSS" : "Perte de stock",
Expand Down
2 changes: 0 additions & 2 deletions client/src/i18n/fr/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@
"ROOT":"Racine",
"RUBRIC_MANAGEMENT":"Gestion Rubriques",
"INVOICES":"Facturation",
"SECTION_BILAN":"Section du bilan",
"SECTION_RESULTAT":"Section des Résultats",
"SERVICE":"Services",
"SIMPLE_VOUCHER":"Bordereau de transfert",
"STOCK":"Stock",
Expand Down
20 changes: 17 additions & 3 deletions client/src/modules/account_reference/account_reference.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ angular.module('bhima.controllers')
.controller('AccountReferenceController', AccountReferenceController);

AccountReferenceController.$inject = [
'$state', 'AccountReferenceService', 'NotifyService', 'uiGridConstants', '$translate',
'$state', 'AccountReferenceService', 'NotifyService', 'uiGridConstants', '$translate', 'bhConstants',
];

/**
* AccountReference Controller
* This module is responsible for handling the CRUD operation on the account references
*/
function AccountReferenceController($state, AccountReferences, Notify, uiGridConstants, $translate) {
function AccountReferenceController($state, AccountReferences, Notify, uiGridConstants, $translate, bhConstants) {
const vm = this;
vm.gridApi = {};
vm.filterEnabled = false;
vm.toggleFilter = toggleFilter;
vm.search = search;
vm.onRemoveFilter = onRemoveFilter;
vm.viewInAccountStatement = viewInAccountStatement;

// options for the UI grid
vm.gridOptions = {
Expand Down Expand Up @@ -91,7 +92,6 @@ function AccountReferenceController($state, AccountReferences, Notify, uiGridCon
return loadGrid(AccountReferences.filters.formatHTTP(true));
}


// bind methods
vm.edit = edit;
vm.remove = remove;
Expand Down Expand Up @@ -157,5 +157,19 @@ function AccountReferenceController($state, AccountReferences, Notify, uiGridCon
vm.loading = !vm.loading;
}

const isNotTitleAccount = account => account.account_type_id !== bhConstants.accounts.TITLE;

function viewInAccountStatement(abbr) {
return AccountReferences.getAccountsForReference(abbr)
.then(list => {
const accountIds = list
.filter(account => (isNotTitleAccount(account) && !account.hidden))
.map(account => account.account_id);

return $state.go('reportsBase.account_report_multiple', { data : { accountIds } });
})
.catch(Notify.handleError);
}

loadGrid();
}
11 changes: 11 additions & 0 deletions client/src/modules/account_reference/account_reference.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ function AccountReferenceService(Api, Filters, $uibModal, AppCache) {
service.filters = referencesFilters;
service.openSearchModal = openSearchModal;

/**
* @method getAccountsForReference
*
* @description
* Returns the list of accounts associated with a reference.
*/
service.getAccountsForReference = function getAccountsForReference(abbr) {
return service.$http.get(`/accounts/references/${abbr}/accounts`)
.then(service.util.unwrapHttpResponse);
};

referencesFilters.registerCustomFilters([
{ key : 'abbr', label : 'ACCOUNT.REFERENCE.REFERENCE' },
{ key : 'number', label : 'FORM.LABELS.ACCOUNT' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
<i class="fa fa-edit"></i> <span translate>FORM.BUTTONS.EDIT</span>
</a>
</li>
<li class="divider"></li>

<li>
<a data-method="view-account-statement" ng-click="grid.appScope.viewInAccountStatement(row.entity.abbr)" href>
<i class="fa fa-list"></i> <span translate>REPORT.VIEW_ACCOUNT_STATEMENT</span>
</a>
</li>

<li class="divider"></li>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ function AccountReportMultipleConfigController(
accountIds : [],
};

function handleStateParameters() {
const { data } = reportData.params;

if (data && data.accountIds) {
vm.reportDetails.accountIds = data.accountIds;
}
}

vm.dateInterval = 1;

checkCachedConfiguration();
Expand Down Expand Up @@ -102,4 +110,6 @@ function AccountReportMultipleConfigController(
vm.reportDetails = angular.copy(cache.reportDetails);
}
}

handleStateParameters();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ BalanceReportConfigController.$inject = [
'$sce', 'NotifyService', 'BaseReportService', 'AppCache', 'reportData', '$state',
];

/**
* @function BalanceReportConfigController
*
* @description
* This function renders the balance report.
*/
function BalanceReportConfigController($sce, Notify, SavedReports, AppCache, reportData, $state) {
const vm = this;
const cache = new AppCache('BalanceReport');
Expand All @@ -25,6 +31,7 @@ function BalanceReportConfigController($sce, Notify, SavedReports, AppCache, rep
vm.previewGenerated = false;
vm.previewResult = null;
};

vm.onChangeLayout = (bool) => {
vm.reportDetails.useSeparateDebitsAndCredits = bool;
};
Expand Down
9 changes: 5 additions & 4 deletions client/src/modules/reports/reports.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ angular.module('bhima.routes')
const reportKey = $stateParams.key;
return SavedReports.requestKey(reportKey)
.then((results) => {
return results[0];
const data = results[0];
data.params = { ...$stateParams };
return data;
});

}

// make sure that the state's transitions refresh the abstract state
Expand Down Expand Up @@ -95,8 +96,8 @@ angular.module('bhima.routes')
$stateProvider.state('reportsBase.'.concat(key), {
url : '/'.concat(key),
controller : key.concat('Controller as ReportConfigCtrl'),
templateUrl : '/modules/reports/generate/'.concat(key, '/', key, '.html'),
params : { key },
templateUrl : `/modules/reports/generate/${key}/${key}.html`,
params : { key, data : { value : null } },
resolve : {
reportData : ['$stateParams', 'BaseReportService', resolveReportData],
},
Expand Down
45 changes: 21 additions & 24 deletions client/src/modules/stock/entry/modals/findPurchase.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,71 @@ angular.module('bhima.controllers')

StockFindPurchaseModalController.$inject = [
'$uibModalInstance', 'PurchaseOrderService', 'NotifyService',
'uiGridConstants', 'GridFilteringService', 'ReceiptModal',
'bhConstants',
'uiGridConstants', 'GridFilteringService', 'bhConstants', 'SessionService',
];

function StockFindPurchaseModalController(
Instance, Purchase, Notify,
uiGridConstants, Filtering, Receipts, bhConstants,
Instance, Purchase, Notify, uiGridConstants, Filtering, bhConstants, Session,
) {
const vm = this;

// global
vm.selectedRow = {};

const {
CONFIRMED,
PARTIALLY_RECEIVED,
} = bhConstants.purchaseStatus;

/* ======================= Grid configurations ============================ */
vm.filterEnabled = false;
vm.gridOptions = { appScopeProvider : vm };

const filtering = new Filtering(vm.gridOptions);

const purchaseReferenceCellTemplate = `
<div class="ui-grid-cell-contents">
<bh-receipt value="row.entity.uuid" display-value="row.entity.reference" type="purchase">
</div>
`;
const columns = [
{
field : 'reference',
displayName : 'TABLE.COLUMNS.REFERENCE',
headerCellFilter : 'translate',
cellTemplate : 'modules/stock/entry/modals/templates/purchase_reference.tmpl.html',
},

{
// cellTemplate : 'modules/stock/entry/modals/templates/purchase_reference.tmpl.html',
cellTemplate : purchaseReferenceCellTemplate,
}, {
field : 'date',
cellFilter : 'date:"'.concat(bhConstants.dates.format, '"'),
cellFilter : `date:"${bhConstants.dates.format}"`,
filter : { condition : filtering.filterByDate },
displayName : 'TABLE.COLUMNS.DATE',
headerCellFilter : 'translate',
sort : { priority : 0, direction : 'desc' },
},

{
}, {
field : 'supplier',
displayName : 'FORM.LABELS.SUPPLIER',
headerCellFilter : 'translate',
},

{
}, {
field : 'cost',
displayName : 'STOCK.AMOUNT',
headerCellFilter : 'translate',
cellFilter : 'currency: grid.appScope.enterprise.currency_id',
cellFilter : `currency:${Session.enterprise.currency_id}`,
cellClass : 'text-right',
},

{ field : 'author', displayName : 'TABLE.COLUMNS.BY', headerCellFilter : 'translate' },
];

vm.gridOptions.columnDefs = columns;
vm.gridOptions.multiSelect = false;
vm.gridOptions.enableColumnMenus = false;
vm.gridOptions.enableFiltering = vm.filterEnabled;
vm.gridOptions.onRegisterApi = onRegisterApi;
vm.toggleFilter = toggleFilter;

// bind methods
vm.submit = submit;
vm.cancel = cancel;
vm.showReceipt = showReceipt;

function onRegisterApi(gridApi) {
vm.gridApi = gridApi;
Expand All @@ -83,15 +85,10 @@ function StockFindPurchaseModalController(
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
}

/** get purchase document */
function showReceipt(uuid) {
Receipts.purchase(uuid);
}

/* ======================= End Grid ======================================== */
function load() {
vm.loading = true;
Purchase.search({ detailed : 1, status_id : [2, 4] })
Purchase.search({ status_id : [CONFIRMED, PARTIALLY_RECEIVED] })
.then(purchases => {
vm.gridOptions.data = purchases;
})
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ exports.configure = function configure(app) {
app.post('/accounts/references', accounts.references.create);
app.put('/accounts/references/:id', accounts.references.update);
app.delete('/accounts/references/:id', accounts.references.remove);
app.get('/accounts/references/:id/accounts', accounts.references.getAccountsForReferenceHTTP);

// API for account importation
app.get('/accounts/template', accounts.importing.downloadTemplate);
Expand Down
9 changes: 6 additions & 3 deletions server/controllers/finance/accounts/references.compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ function getAccountsForReference(abbr, isAmoDep = 0) {
* @link http://www.mysqltutorial.org/mysql-minus/
*/
const queryAccounts = `
SELECT includeTable.account_id, includeTable.account_number FROM (
SELECT includeTable.account_id, includeTable.account_number, includeTable.account_type_id,
includeTable.hidden, includeTable.locked FROM (
SELECT DISTINCT
account.id AS account_id, account.number AS account_number FROM account
account.id AS account_id, account.number AS account_number, account.type_id AS account_type_id,
hidden, locked FROM account
JOIN (
SELECT a.id, a.number FROM account a
JOIN account_reference_item ari ON ari.account_id = a.id
Expand All @@ -168,7 +170,8 @@ function getAccountsForReference(abbr, isAmoDep = 0) {
) AS includeTable
LEFT JOIN (
SELECT DISTINCT
account.id AS account_id, account.number AS account_number FROM account
account.id AS account_id, account.number AS account_number, account.type_id as account_type_id,
hidden, locked FROM account
JOIN (
SELECT a.id, a.number FROM account a
JOIN account_reference_item ari ON ari.account_id = a.id
Expand Down
Loading

0 comments on commit 7602017

Please sign in to comment.