feat: enhance transaction read service to include total sales calculation and item ID in quantity query
parent
47d45cb65c
commit
01fb358875
|
@ -41,17 +41,29 @@ export class TransactionReadService extends BaseReadService<TransactionEntity> {
|
|||
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(
|
||||
|
|
Loading…
Reference in New Issue