Skip to content

Commit

Permalink
Merge #5340
Browse files Browse the repository at this point in the history
5340: Link to purchase order analysis from purchase registry r=jmcameron a=jniles

Adds a link from the purchase order registry to the purchase order analysis report.

Closes #5333.

Co-authored-by: Jonathan Niles <jonathanwniles@gmail.com>
  • Loading branch information
bors[bot] and jniles authored Feb 3, 2021
2 parents f9cbae5 + 0715461 commit db55809
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 25 deletions.
3 changes: 1 addition & 2 deletions client/src/modules/general-ledger/general-ledger.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ function GeneralLedgerService(Api, $httpParamSerializer, Languages, Session) {
service.aggregates = (params) => service.read.call({ url : service.url.concat('aggregates') }, null, params);

// GET /general_ledger/transactions
service.transactions = (params) =>
service.read.call({ url : service.url.concat('transactions') }, null, params);
service.transactions = (params) => service.read.call({ url : service.url.concat('transactions') }, null, params);

return service;
}
6 changes: 6 additions & 0 deletions client/src/modules/purchases/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ function PurchaseListController(
// barcode scanner
vm.openBarcodeScanner = openBarcodeScanner;

vm.openPurchaseOrderAnalysisReport = (uuid) => {
const params = PurchaseOrder.openPurchaseOrderAnalysisReport(uuid);
const link = `/reports/purchase_order_analysis?${params}`;
return link;
};

vm.editStatus = editStatus;

vm.FLUX_FROM_PURCHASE = bhConstants.flux.FROM_PURCHASE;
Expand Down
18 changes: 16 additions & 2 deletions client/src/modules/purchases/purchases.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('bhima.services')
PurchaseOrderService.$inject = [
'$uibModal', 'FilterService', 'appcache', 'PeriodService',
'PrototypeApiService', '$httpParamSerializer', 'LanguageService',
'bhConstants',
'bhConstants', 'SessionService',
];

/**
Expand All @@ -16,7 +16,7 @@ PurchaseOrderService.$inject = [
*/
function PurchaseOrderService(
$uibModal, Filters, AppCache, Periods, Api, $httpParamSerializer,
Languages, bhConstants,
Languages, bhConstants, Session,
) {
const baseUrl = '/purchases/';
const service = new Api(baseUrl);
Expand All @@ -36,6 +36,8 @@ function PurchaseOrderService(
service.stockBalance = stockBalance;
service.purchaseState = purchaseState;

service.openPurchaseOrderAnalysisReport = openPurchaseOrderAnalysisReport;

purchaseFilters.registerDefaultFilters(bhConstants.defaultFilters);

purchaseFilters.registerCustomFilters([
Expand Down Expand Up @@ -144,6 +146,18 @@ function PurchaseOrderService(
}).result;
}

function openPurchaseOrderAnalysisReport(row) {
const opts = {
lang : Languages.key,
currency_id : Session.enterprise.currency_id,
purchase_uuid : row.uuid,
shouldShowDetails : 1,
renderer : 'pdf',
};

return $httpParamSerializer(opts);
}

function download(type) {
const filterOpts = purchaseFilters.formatHTTP();
const defaultOpts = { renderer : type, lang : Languages.key };
Expand Down
10 changes: 10 additions & 0 deletions client/src/modules/purchases/templates/action.cell.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@

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

<li>
<a ng-href="{{ grid.appScope.openPurchaseOrderAnalysisReport(row.entity) }}" target="_blank">
<span class="fa fa-file-pdf-o"></span> <span translate>REPORT.PURCHASE_ORDER_ANALYSIS.TITLE</span>
</a>
</li>

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

<li ng-if="row.entity.hasStockMovement">
<a href
data-method="view-stock-movements"
Expand All @@ -29,6 +37,8 @@
</a>
</li>



<li ng-if="row.entity.hasStockMovement">
<a data-method="view-stock-lot" href
ui-sref="stockInventories({ filters : [
Expand Down
2 changes: 0 additions & 2 deletions server/controllers/finance/generalLedger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* @requires lib/util
*/


// module dependencies
const Tree = require('@ima-worldhealth/tree');

Expand Down Expand Up @@ -104,7 +103,6 @@ function getAggregates(req, res, next) {
.done();
}


/**
* @function getAccountTotalsMatrix
*
Expand Down
1 change: 0 additions & 1 deletion server/controllers/finance/reports/purchases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const REPORT_TEMPLATE = './server/controllers/finance/reports/purchases/report.h

exports.report = report;


/**
* @function report
*
Expand Down
44 changes: 26 additions & 18 deletions server/controllers/stock/reports/purchase_order_analysis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async function report(req, res, next) {
canceled : {
color : '#d9534f',
icon : 'X',
text : 'FORM.LABELS.CANCELED',
},
exessive : {
color : '#d9534f',
Expand All @@ -71,23 +72,23 @@ async function report(req, res, next) {
// This request makes it possible to obtain the quantities of the ordered products
const sqlInventoriesOrdered = `
SELECT BUID(p.uuid) AS purchase_uuid, BUID(iv.uuid) AS inventory_uuid, iv.code,
iv.text AS inventory_text, pi.quantity AS quantity_ordered
iv.text AS inventory_text, pi.quantity AS quantity_ordered
FROM purchase AS p
JOIN purchase_item AS pi ON pi.purchase_uuid = p.uuid
JOIN inventory AS iv ON iv.uuid = pi.inventory_uuid
JOIN purchase_item AS pi ON pi.purchase_uuid = p.uuid
JOIN inventory AS iv ON iv.uuid = pi.inventory_uuid
WHERE p.uuid = ?
ORDER BY iv.text ASC;
`;

// This query is used to get the quantities in stock for a purchase order
const sqlInventoriesInStock = `
SELECT BUID(p.uuid) AS purchase_uuid, BUID(iv.uuid) AS inventory_uuid,
iv.text AS inventoryText, l.label AS lotLabel, p.project_id,
p.reference, p.user_id, l.uuid AS lotUuid, SUM(l.quantity) AS quantity_inStock,
l.expiration_date, MAX(l.entry_date) AS entry_date, iv.code
iv.text AS inventoryText, l.label AS lotLabel, p.project_id,
p.reference, p.user_id, l.uuid AS lotUuid, SUM(l.quantity) AS quantity_inStock,
l.expiration_date, MAX(l.entry_date) AS entry_date, iv.code
FROM purchase AS p
JOIN lot AS l ON l.origin_uuid = p.uuid
JOIN inventory AS iv ON iv.uuid = l.inventory_uuid
JOIN lot AS l ON l.origin_uuid = p.uuid
JOIN inventory AS iv ON iv.uuid = l.inventory_uuid
WHERE p.uuid = ?
GROUP BY iv.uuid
ORDER BY iv.text ASC;
Expand All @@ -96,15 +97,15 @@ async function report(req, res, next) {
// This request tracks the entries in stock of a purchase order, by date, by deposit but also by product
const sqlInventoriesInStockDetailled = `
SELECT BUID(p.uuid) AS purchase_uuid, BUID(iv.uuid) AS inventory_uuid, iv.text AS inventoryText,
l.label AS lotLabel, p.project_id, p.reference, p.user_id, l.uuid AS lotUuid, l.quantity,
l.expiration_date, l.entry_date, iv.code,
d.text AS depotText, BUID(sm.uuid) AS stock_movement_uuid, dm1.text AS stock_movement_reference
l.label AS lotLabel, p.project_id, p.reference, p.user_id, l.uuid AS lotUuid, l.quantity,
l.expiration_date, l.entry_date, iv.code,
d.text AS depotText, BUID(sm.uuid) AS stock_movement_uuid, dm1.text AS stock_movement_reference
FROM purchase AS p
JOIN lot AS l ON l.origin_uuid = p.uuid
JOIN inventory AS iv ON iv.uuid = l.inventory_uuid
JOIN stock_movement AS sm ON sm.lot_uuid = l.uuid
JOIN depot AS d ON d.uuid = sm.depot_uuid
JOIN document_map AS dm1 ON dm1.uuid = sm.document_uuid
JOIN lot AS l ON l.origin_uuid = p.uuid
JOIN inventory AS iv ON iv.uuid = l.inventory_uuid
JOIN stock_movement AS sm ON sm.lot_uuid = l.uuid
JOIN depot AS d ON d.uuid = sm.depot_uuid
JOIN document_map AS dm1 ON dm1.uuid = sm.document_uuid
WHERE p.uuid = ? AND sm.is_exit = 0 AND sm.flux_id = ?
ORDER BY iv.text ASC, l.entry_date ASC
`;
Expand All @@ -113,7 +114,7 @@ async function report(req, res, next) {
const PURCHASE_FLUX_ID = 1;

const [
purchase, inventoriesOrdered, inventoriesInStock, inventoriesInStockDetailled,
[purchase], inventoriesOrdered, inventoriesInStock, inventoriesInStockDetailled,
] = await Promise.all([
Purchases.find({ uuid : params.purchase_uuid }),
db.exec(sqlInventoriesOrdered, uidPurchase),
Expand Down Expand Up @@ -146,6 +147,13 @@ async function report(req, res, next) {
} else if (ordered.quantity_difference > 0 && ordered.quantity_difference < ordered.quantity_ordered) {
ordered.status = statusDisplay.partial;
}

// if the purchase order is canceled, it should display canceled for all
// items
if (purchase.status_id === 5) {
ordered.status = statusDisplay.canceled;
}

});

inventoriesOrdered.forEach(ordered => {
Expand All @@ -159,7 +167,7 @@ async function report(req, res, next) {

data.inventoriesOrdered = inventoriesOrdered;

[data.purchase] = purchase;
data.purchase = purchase;

if (data.purchase.status_id === 1) {
data.purchase.statusDisplay = statusDisplay.waiting;
Expand Down

0 comments on commit db55809

Please sign in to comment.