Antaram commited on
Commit
0eb59ad
·
verified ·
1 Parent(s): 1f8a7cb

Upload 29 files

Browse files
Files changed (1) hide show
  1. src/routes/patti.js +8 -7
src/routes/patti.js CHANGED
@@ -159,17 +159,18 @@ router.get('/lots/active', async (req, res) => {
159
  }
160
  });
161
 
162
- // GET patti available lots by mirchi type (active lots for dropdown)
163
  router.get('/lots/available/:mirchiTypeId', async (req, res) => {
164
  try {
165
  const { mirchiTypeId } = req.params;
166
  const result = await pool.query(
167
- `SELECT *,
168
- FLOOR(remaining_quantity / 50) as poti_count
169
- FROM patti_lots
170
- WHERE mirchi_type_id = $1
171
- AND status = 'active'
172
- ORDER BY purchase_date DESC`,
 
173
  [mirchiTypeId]
174
  );
175
  res.json(result.rows);
 
159
  }
160
  });
161
 
162
+ // GET patti available lots by mirchi type (all lots for dropdown)
163
  router.get('/lots/available/:mirchiTypeId', async (req, res) => {
164
  try {
165
  const { mirchiTypeId } = req.params;
166
  const result = await pool.query(
167
+ `SELECT pl.*,
168
+ COALESCE(SUM(pti.poti_count), 0) as poti_count
169
+ FROM patti_lots pl
170
+ LEFT JOIN patti_transaction_items pti ON pl.id = pti.lot_id
171
+ WHERE pl.mirchi_type_id = $1
172
+ GROUP BY pl.id
173
+ ORDER BY pl.purchase_date DESC`,
174
  [mirchiTypeId]
175
  );
176
  res.json(result.rows);