From e57699066ae71738025241fedfdcf1ebe8cae3aa Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Sat, 21 Aug 2021 09:44:52 +0700 Subject: [PATCH] add margin gross --- src/services/postgres/GeneralService.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/services/postgres/GeneralService.js b/src/services/postgres/GeneralService.js index 9f7144b..226280c 100644 --- a/src/services/postgres/GeneralService.js +++ b/src/services/postgres/GeneralService.js @@ -22,6 +22,14 @@ class GeneralService { `SELECT COUNT(id) as purchase_count FROM purchases WHERE office_id = (SELECT id FROM offices WHERE company_id = '${companyId}' LIMIT 1) AND date::DATE = CURRENT_DATE - 1`, ); + const totalSales = await this._pool.query(` + SELECT SUM(amount) as sale_total FROM sales WHERE office_id = (SELECT id FROM offices WHERE company_id = '${companyId}' LIMIT 1) + `); + + const totalPurchases = await this._pool.query(` + SELECT SUM(amount) as purchase_total FROM purchases WHERE office_id = (SELECT id FROM offices WHERE company_id = '${companyId}' LIMIT 1) + `); + const graphSale = await this._pool.query( `SELECT COUNT(date), date::DATE FROM sales @@ -51,6 +59,8 @@ class GeneralService { grownPurchase, graphSale: graphSale.rows, graphPurchase: graphPurchase.rows, + totalSales: totalSales.rows[0].sale_total, + totalPurchases: totalPurchases.rows[0].purchase_total, }; } }