Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cost center): uniquely show auxiliary cost centers in columns #5982

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
<hr>
<div class="radio">
<p><strong translate>COST_CENTER.STEP_DOWN_COST_ALLOCATION</strong></p>
<label class="control-label" style="vertical-align: middle;" translate>ALLOCATION_METHOD</label>:
<label class="control-label" style="vertical-align: middle; padding-left:0" translate>ALLOCATION_METHOD</label>:
<label class="radio-inline" ng-repeat="choice in CostCenterModalCtrl.allocationMethodOptions">
<input
type="radio"
Expand Down
17 changes: 15 additions & 2 deletions server/controllers/finance/cost_center_allocation_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,36 @@ async function fetch(session, params) {
}
return item;
});

const data = stepdown.compute(formattedCostCenters);
const cumulatedAllocatedCosts = data.map((item, index, array) => (item.principal ? 0 : array[index].toDist[index]));

const cumulatedAllocatedCosts = data
.map((item, index, array) => (item.principal ? 'principal' : array[index].toDist[index]))
.filter(item => item !== 'principal');

const auxiliaryIndexes = data.map((item, i) => (item.auxiliary ? i : null)).filter(item => !!item);
const services = data.map(item => {
item.distribution = item.toDist.map((value, i) => {
const ratio = item.ratio ? item.ratio[i] : undefined;
return { value, ratio };
});

item.auxiliaryDistribution = item.distribution.map((value, i) => {
return auxiliaryIndexes.includes(i) ? value : null;
}).filter(value => !!value);

return item;
});

const directCostTotal = services.reduce((prev, curr) => { return curr.directCost + prev; }, 0);

// horizontal view
const hView = [];
let totalAfterAllocation = 0;

// heck to get the correct number of colums
const numAuxiliaryCenters = data.filter(value => !value.is_principal).length;

for (let i = 0; i < data.length; i++) {
const ei = data[i];
const row = {
Expand All @@ -63,7 +74,8 @@ async function fetch(session, params) {
values : [],
total : 0,
};
for (let z = 0; z < data.length; z++) {

for (let z = 0; z < numAuxiliaryCenters; z++) {
const value = data[z].toDist[i];
const ratio = data[z].ratio ? data[z].ratio[i] : 0;
const selfCenter = !!(i === z);
Expand All @@ -76,6 +88,7 @@ async function fetch(session, params) {
selfCenterValue,
});
}

// the total is the direct cost plus all allocations
row.total += ei.directCost;
// auxiliary cost center distribute all of their value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
<th>{{translate 'FORM.LABELS.SERVICE'}}</th>
<th>{{translate 'COST_CENTER.DIRECT_COST'}}</th>
{{#each data as | service |}}
{{#unless service.is_principal}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

<th>{{ service.cost_center_label }}</th>
<th style="width: 3em;">%</th>
{{/unless}}
{{/each}}
<th>{{translate 'TABLE.COLUMNS.TOTAL'}}</th>
</tr>
Expand Down Expand Up @@ -99,4 +101,4 @@
</div>
</div>
</body>
</html>
</html>
19 changes: 9 additions & 10 deletions server/models/procedures/cost_centers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ RETURNS MEDIUMINT(8) DETERMINISTIC
BEGIN
RETURN (
SELECT GetCostCenterByServiceUuid(i.service_uuid)
FROM invoice i
WHERE i.uuid = invoice_uuid
FROM invoice i
WHERE i.uuid = invoice_uuid
);
END $$

Expand All @@ -97,17 +97,16 @@ BEGIN
SELECT @full_error AS error_message;
END;


DROP TEMPORARY TABLE IF EXISTS cost_center_costs_with_indexes;
CREATE TEMPORARY TABLE cost_center_costs_with_indexes AS
SELECT
z.id, z.label AS cost_center_label,
z.allocation_basis_id,
z.is_principal,
z.step_order,
z.`value` AS direct_cost,
ccb.name AS cost_center_allocation_basis_label,
ccbv.quantity AS cost_center_allocation_basis_value
z.id, z.label AS cost_center_label,
z.allocation_basis_id,
z.is_principal,
z.step_order,
z.`value` AS direct_cost,
ccb.name AS cost_center_allocation_basis_label,
ccbv.quantity AS cost_center_allocation_basis_value
FROM
(
(
Expand Down