Feat: add rumus prepaid and postpaid

This commit is contained in:
mfadiln2018 2022-05-24 20:24:42 +07:00
parent cb7d6833aa
commit 1050ca4c85

View File

@ -321,7 +321,7 @@ export class ProductService {
);
}
const baseQuery = this.productRepository
const baseQuery = await this.productRepository
.createQueryBuilder('product')
.leftJoin('product.sub_categories', 'sub_categories')
.leftJoinAndSelect(
@ -343,12 +343,16 @@ export class ProductService {
.addSelect([
'product.name',
'product.code',
'product.type',
'sub_categories.name',
'current_price.admin_price as admin_price',
'current_price.mark_up_price as markup_price',
'current_price.partner_fee as partner_fee',
'current_price.price as price',
])
.addSelect(
'(current_price.price + current_price.mark_up_price) as price',
);
// .addSelect(
// '(current_price.price + current_price.mark_up_price) as price',
// );
// if (
// subCategories != 'null' &&
@ -360,17 +364,39 @@ export class ProductService {
// });
// }
if (subCategories && filterSubCategories.length > 0) {
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
subCategoryId: filterSubCategories,
});
}
const newData = []
const data = await baseQuery
.offset(page * pageSize)
.limit(pageSize)
.getRawMany();
data.map((dataa) => {
let actualPrice = 0
if (dataa.product_type === 'prepaid') {
actualPrice = Number(dataa['price']) + Number(dataa['markup_price'])
}
if (dataa.product_type === 'postpaid') {
actualPrice = Number(dataa['admin_price'])- (Number(dataa['partner_fee']) + Number(dataa['markup_price']))
}
dataa.price = actualPrice
newData.push({
...dataa
})
})
const totalData = await baseQuery.getCount();
return {