Skip to content

Commit

Permalink
feat(stock): red negative values in stock sheet
Browse files Browse the repository at this point in the history
Colors the negative values in the stock sheet report in red.

Partially addresses #5415.
  • Loading branch information
jniles committed Mar 4, 2021
1 parent 6efcc68 commit 8fb36f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions server/controllers/stock/reports/stock/stock_sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const {
* @method stockSheetReport
*
* @description
* This method builds the stock inventory report as either a JSON, PDF, or HTML
* This method builds the stock sheet report as either a JSON, PDF, or HTML
* file to be sent to the client.
*
* GET /reports/stock/inventory
* GET /reports/stock/sheet
*/
async function stockSheetReport(req, res, next) {
const optionReport = _.extend(req.query, {
Expand Down Expand Up @@ -41,6 +41,11 @@ async function stockSheetReport(req, res, next) {
data.rows = rows.movements;
}

// mark rows if they contain negative balances
data.rows.forEach(row => {
row.hasNegativeValues = row.stock.quantity < 0;
});

data.totals = rows.totals;
data.result = rows.result;
data.dateFrom = options.dateFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</thead>
<tbody>
{{#each rows}}
<tr>
<tr {{#if hasNegativeValues}}class="bg-danger text-danger"{{/if}}>
<td style="border-left: 1px solid #000;">{{reference}}</td>
<td style="border-right: 1px solid #000;">{{timestamp date}}</td>
{{#unless ../depot.text}}
Expand All @@ -77,9 +77,9 @@
<td class="text-right" style="border-right: 1px solid #000;">{{#if exit.value}}{{currency exit.value ../metadata.enterprise.currency_id}}{{/if}}</td>

{{!-- stock --}}
<td class="text-right" style="background-color:#efefef;">{{stock.quantity}}</td>
<td class="text-right" style="background-color:#efefef;">{{precision stock.unit_cost 4}}</td>
<td class="text-right" style="background-color:#efefef;border-right: 1px solid #000;">{{currency stock.value ../metadata.enterprise.currency_id}}</td>
<td class="text-right" {{#unless hasNegativeValues}}style="background-color:#efefef;"{{/unless}}>{{stock.quantity}}</td>
<td class="text-right" {{#unless hasNegativeValues}}style="background-color:#efefef;"{{/unless}}>{{precision stock.unit_cost 4}}</td>
<td class="text-right" {{#unless hasNegativeValues}}style="background-color:#efefef;border-right: 1px solid #000;"{{/unless}}>{{currency stock.value ../metadata.enterprise.currency_id}}</td>
</tr>
{{/each}}
</tbody>
Expand Down

0 comments on commit 8fb36f7

Please sign in to comment.