Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Commit

Permalink
Correct order counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Jan 27, 2016
1 parent ed7da34 commit 91a8f2e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 58 deletions.
6 changes: 4 additions & 2 deletions client/views/growers/orders.js
Expand Up @@ -3,7 +3,9 @@ import Nav from './nav'

export default ({canEdit, grower, mediumImage, path, products}) => {
const {name} = grower
const total = products.reduce((sum, {cost}) => sum + +cost, 0).toFixed(2)
const total = products.reduce((sum, {cost, reserved}) => {
return sum + +cost * reserved
}, 0).toFixed(2)

return <div className='row'>
<div className='col-md-3 text-center'>
Expand Down Expand Up @@ -31,7 +33,7 @@ export default ({canEdit, grower, mediumImage, path, products}) => {
<a href={`/products/${id}`}>{name}</a>
</td>
<td>{reserved}</td>
<td>${(+cost).toFixed(2)}</td>
<td>${(+cost * reserved).toFixed(2)}</td>
</tr>
})}
</tbody>
Expand Down
7 changes: 0 additions & 7 deletions routes/growers.js
Expand Up @@ -96,14 +96,7 @@ router.post('/:grower_id/products', (req, res) => {
router.get('/:grower_id/orders', (req, res) => {
if (!req.canEdit) return res.status(401).render('401')

const total = `(
select sum(quantity * cost) from product_orders
inner join orders on orders.id = product_orders.order_id
where product_id = products.id and orders.status = 'open'
) as total`

db.Product
.select('*', total)
.where({grower_id: req.grower.id})
.where('reserved > 0')
.all().then((products) => {
Expand Down
49 changes: 0 additions & 49 deletions views/growers/orders.ejs

This file was deleted.

0 comments on commit 91a8f2e

Please sign in to comment.