Merge pull request '4363-refactor(item_waste): refactor table and add totals in table_head' (#1053) from 4363-item_waste_refactor into dev
gitea/salix/pipeline/head This commit is unstable
Details
gitea/salix/pipeline/head This commit is unstable
Details
Reviewed-on: #1053 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
f9f09440ec
|
@ -30,11 +30,24 @@ module.exports = Self => {
|
||||||
sum(ws.saleWaste) AS dwindle
|
sum(ws.saleWaste) AS dwindle
|
||||||
FROM bs.waste ws
|
FROM bs.waste ws
|
||||||
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1, ?))
|
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1, ?))
|
||||||
AND week = WEEK(TIMESTAMPADD(WEEK,-1, ?), 1)
|
AND week = WEEK(TIMESTAMPADD(WEEK,-1, ?), 1)
|
||||||
GROUP BY buyer, family
|
GROUP BY buyer, family
|
||||||
) sub
|
) sub
|
||||||
ORDER BY percentage DESC`, [date, date], myOptions);
|
ORDER BY percentage DESC`, [date, date], myOptions);
|
||||||
|
|
||||||
|
const wastesTotal = await Self.rawSql(`
|
||||||
|
SELECT *, 100 * dwindle / total AS percentage
|
||||||
|
FROM (
|
||||||
|
SELECT buyer,
|
||||||
|
sum(ws.saleTotal) AS total,
|
||||||
|
sum(ws.saleWaste) AS dwindle
|
||||||
|
FROM bs.waste ws
|
||||||
|
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1, ?))
|
||||||
|
AND week = WEEK(TIMESTAMPADD(WEEK,-1, ?), 1)
|
||||||
|
GROUP BY buyer
|
||||||
|
) sub
|
||||||
|
ORDER BY percentage DESC`, [date, date], myOptions);
|
||||||
|
|
||||||
const details = [];
|
const details = [];
|
||||||
|
|
||||||
for (let waste of wastes) {
|
for (let waste of wastes) {
|
||||||
|
@ -55,6 +68,14 @@ module.exports = Self => {
|
||||||
buyerDetail.lines.push(waste);
|
buyerDetail.lines.push(waste);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let waste of details) {
|
||||||
|
let buyerTotal = wastesTotal.find(totals => {
|
||||||
|
return waste.buyer == totals.buyer;
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.assign(waste, buyerTotal);
|
||||||
|
}
|
||||||
|
|
||||||
return details;
|
return details;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,6 +12,7 @@ describe('Item getWasteByWorker()', () => {
|
||||||
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
|
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
|
||||||
|
|
||||||
expect(anyResult.buyer).toMatch(/(CharlesXavier|HankPym|DavidCharlesHaller)/);
|
expect(anyResult.buyer).toMatch(/(CharlesXavier|HankPym|DavidCharlesHaller)/);
|
||||||
|
expect(anyResult.total).toBeGreaterThanOrEqual(1000);
|
||||||
expect(anyResult.lines.length).toBeGreaterThanOrEqual(3);
|
expect(anyResult.lines.length).toBeGreaterThanOrEqual(3);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
|
@ -4,39 +4,46 @@
|
||||||
data="details">
|
data="details">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<vn-data-viewer model="model">
|
<vn-data-viewer model="model">
|
||||||
<section ng-repeat="detail in details" class="vn-pa-md">
|
<vn-card>
|
||||||
<vn-horizontal class="header">
|
<vn-table>
|
||||||
<h5><span translate>{{detail.buyer}}</span></h5>
|
<vn-thead>
|
||||||
<vn-none>
|
<vn-tr class="header">
|
||||||
<vn-icon
|
<vn-th class="waste-family">Buyer</vn-th>
|
||||||
ng-class="{'hidden': !$ctrl.wasteConfig[detail.buyer].hidden}"
|
<vn-th class="waste-family">Family</vn-th>
|
||||||
class="arrow pointer"
|
<vn-th number>Percentage</vn-th>
|
||||||
icon="keyboard_arrow_up"
|
<vn-th number>Dwindle</vn-th>
|
||||||
vn-tooltip="Minimize/Maximize"
|
<vn-th number>Total</vn-th>
|
||||||
ng-click="$ctrl.toggleHidePanel(detail)">
|
<vn-th shrink></vn-th>
|
||||||
</vn-icon>
|
</vn-tr>
|
||||||
</vn-none>
|
</vn-thead>
|
||||||
</vn-horizontal>
|
<vn-tbody ng-repeat="detail in details" class="vn-mb-md">
|
||||||
<vn-card ng-class="{'hidden': !$ctrl.wasteConfig[detail.buyer].hidden}">
|
<vn-tr class="header">
|
||||||
<vn-table>
|
<vn-td>{{::detail.buyer}}</vn-td>
|
||||||
<vn-thead>
|
<vn-td>{{::detail.family}}</vn-td>
|
||||||
<vn-tr>
|
<vn-td number>{{::(detail.percentage / 100) | percentage: 2}}</vn-td>
|
||||||
<vn-th class="waste-family">Family</vn-th>
|
<vn-td number>{{::detail.dwindle | currency: 'EUR'}}</vn-td>
|
||||||
<vn-th number>Percentage</vn-th>
|
<vn-td number>{{::detail.total | currency: 'EUR'}}</vn-td>
|
||||||
<vn-th number>Dwindle</vn-th>
|
<vn-td shrink>
|
||||||
<vn-th number>Total</vn-th>
|
<vn-icon-button
|
||||||
</vn-tr>
|
ng-class="{'hidden': !$ctrl.wasteConfig[detail.buyer].hidden}"
|
||||||
</vn-thead>
|
class="arrow pointer"
|
||||||
<vn-tbody>
|
icon="keyboard_arrow_up"
|
||||||
<a ng-repeat="waste in detail.lines" class="clickable vn-tr"
|
vn-tooltip="Minimize/Maximize"
|
||||||
ui-sref="item.waste.detail({buyer: waste.buyer, family: waste.family})">
|
ng-click="$ctrl.toggleHidePanel(detail)">
|
||||||
<vn-td class="waste-family">{{::waste.family}}</vn-td>
|
</vn-icon-button>
|
||||||
<vn-td number>{{::(waste.percentage / 100) | percentage: 2}}</vn-td>
|
</vn-td>
|
||||||
<vn-td number>{{::waste.dwindle | currency: 'EUR'}}</vn-td>
|
</vn-tr>
|
||||||
<vn-td number>{{::waste.total | currency: 'EUR'}}</vn-td>
|
<vn-tr ng-repeat="waste in detail.lines" class="clickable vn-tr"
|
||||||
</vn-tr>
|
ui-sref="item.waste.detail({buyer: waste.buyer, family: waste.family})"
|
||||||
</vn-tbody>
|
ng-class="{'hidden': !$ctrl.wasteConfig[detail.buyer].hidden}">
|
||||||
</vn-table>
|
<vn-td></vn-td>
|
||||||
</vn-card>
|
<vn-td>{{::waste.family}}</vn-td>
|
||||||
</section>
|
<vn-td number>{{::(waste.percentage / 100) | percentage: 2}}</vn-td>
|
||||||
|
<vn-td number>{{::waste.dwindle | currency: 'EUR'}}</vn-td>
|
||||||
|
<vn-td number>{{::waste.total | currency: 'EUR'}}</vn-td>
|
||||||
|
<vn-td shrink></vn-td>
|
||||||
|
</vn-tr>
|
||||||
|
</vn-tbody>
|
||||||
|
</vn-table>
|
||||||
|
</vn-card>
|
||||||
</vn-data-viewer>
|
</vn-data-viewer>
|
|
@ -5,20 +5,9 @@ vn-item-waste-index,
|
||||||
vn-item-waste-detail {
|
vn-item-waste-detail {
|
||||||
.header {
|
.header {
|
||||||
padding: 12px 0 5px 0;
|
padding: 12px 0 5px 0;
|
||||||
color: gray;
|
background-color: $color-bg;
|
||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
border-bottom: $border;
|
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
|
||||||
& > vn-none > vn-icon {
|
|
||||||
@extend %clickable-light;
|
|
||||||
color: $color-button;
|
|
||||||
font-size: 1.4rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
vn-none > .arrow {
|
|
||||||
transition: transform 200ms;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vn-table vn-th.waste-family,
|
vn-table vn-th.waste-family,
|
||||||
|
@ -26,11 +15,12 @@ vn-item-waste-detail {
|
||||||
max-width: 64px;
|
max-width: 64px;
|
||||||
width: 64px
|
width: 64px
|
||||||
}
|
}
|
||||||
|
|
||||||
.hidden {
|
.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
||||||
}
|
}
|
||||||
.header > vn-none > .arrow.hidden {
|
|
||||||
|
.arrow.hidden {
|
||||||
display: block;
|
display: block;
|
||||||
transform: rotate(180deg);
|
transform: rotate(180deg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue