diff --git a/src/modules/transaction/transaction/data/services/transaction-read.service.ts b/src/modules/transaction/transaction/data/services/transaction-read.service.ts index 47aec59..eefa87a 100644 --- a/src/modules/transaction/transaction/data/services/transaction-read.service.ts +++ b/src/modules/transaction/transaction/data/services/transaction-read.service.ts @@ -41,17 +41,29 @@ export class TransactionReadService extends BaseReadService { group by payment_type_counter, payment_type_method_name;`; const transactions = await this.repo.query(query); - const qtyQuery = `select ti.item_name, sum(ti.qty) total_qty, count(ti.item_name), sum(ti.qty), string_agg(distinct ti.item_price::text, '') price, + const qtyQuery = `select ti.item_id, ti.item_name, sum(ti.qty) total_qty, count(ti.item_name), sum(ti.qty), string_agg(distinct ti.item_price::text, '') price, sum(payment_total) payment_total, sum(payment_total_pay) payment_total_pay from transactions t inner join transaction_items ti on t.id = ti.transaction_id where t.creator_counter_no IN (${posId}) and invoice_date = '${startDate}' and t.status = 'settled' - group by ti.item_name`; + group by ti.item_name, ti.item_id`; const qtyTransactions = await this.repo.query(qtyQuery); - return { payment: transactions, qty: qtyTransactions }; + const totalSalesQuery = `select sum(payment_total) payment_total + from transactions t + where 1=1 + and t.creator_counter_no IN (${posId}) + and invoice_date = '${startDate}' + and status = 'settled'`; + const totalSales = await this.repo.query(totalSalesQuery); + + return { + payment: transactions, + qty: qtyTransactions, + totalSales: totalSales?.[0]?.payment_total ?? 0, + }; } async getLastTransactionByPos(