Merge branch 'devops-staging' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend
This commit is contained in:
commit
d1be6fcef6
|
@ -66,7 +66,7 @@ export class ProductService {
|
||||||
let productStatusPartner;
|
let productStatusPartner;
|
||||||
|
|
||||||
const subCategories =
|
const subCategories =
|
||||||
await this.productSubCategoriesService.findOneForCSVParser(it[2]);
|
await this.productSubCategoriesService.findOneForCSVParser(it[2]);
|
||||||
|
|
||||||
if (!subCategories) {
|
if (!subCategories) {
|
||||||
return;
|
return;
|
||||||
|
@ -123,6 +123,7 @@ export class ProductService {
|
||||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dataHistoryPrice = await this.productHistoryPrice.findOne({
|
dataHistoryPrice = await this.productHistoryPrice.findOne({
|
||||||
product: productData,
|
product: productData,
|
||||||
partner: IsNull(),
|
partner: IsNull(),
|
||||||
|
@ -223,12 +224,12 @@ export class ProductService {
|
||||||
'current_price',
|
'current_price',
|
||||||
'current_price.end_date is NULL',
|
'current_price.end_date is NULL',
|
||||||
)
|
)
|
||||||
.innerJoinAndMapOne(
|
.innerJoinAndMapOne(
|
||||||
'product.currentStatus',
|
'product.currentStatus',
|
||||||
'product.statusHistory',
|
'product.statusHistory',
|
||||||
'history_status',
|
'history_status',
|
||||||
'history_status.deleted_at is NULL'
|
'history_status.deleted_at is NULL',
|
||||||
)
|
)
|
||||||
.select(['product.id'])
|
.select(['product.id'])
|
||||||
.addSelect([
|
.addSelect([
|
||||||
'product.name',
|
'product.name',
|
||||||
|
@ -237,7 +238,7 @@ export class ProductService {
|
||||||
'supplier.name',
|
'supplier.name',
|
||||||
'category.name',
|
'category.name',
|
||||||
])
|
])
|
||||||
.addSelect('history_status.status', 'status')
|
.addSelect('history_status.status', 'status')
|
||||||
.addSelect('current_price.price', 'price')
|
.addSelect('current_price.price', 'price')
|
||||||
.addSelect('current_price.partner_fee', 'partner_fee')
|
.addSelect('current_price.partner_fee', 'partner_fee')
|
||||||
.addSelect('current_price.admin_price', 'admin_price')
|
.addSelect('current_price.admin_price', 'admin_price')
|
||||||
|
@ -245,7 +246,7 @@ export class ProductService {
|
||||||
'(current_price.price + current_price.mark_up_price) as mark_up_price',
|
'(current_price.price + current_price.mark_up_price) as mark_up_price',
|
||||||
)
|
)
|
||||||
.orderBy('product.code')
|
.orderBy('product.code')
|
||||||
.distinct();
|
.distinct();
|
||||||
|
|
||||||
if (subCategories && filterSubCategories.length > 0) {
|
if (subCategories && filterSubCategories.length > 0) {
|
||||||
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||||
|
@ -312,7 +313,7 @@ export class ProductService {
|
||||||
.createQueryBuilder('product')
|
.createQueryBuilder('product')
|
||||||
.leftJoin('product.sub_categories', 'sub_categories')
|
.leftJoin('product.sub_categories', 'sub_categories')
|
||||||
|
|
||||||
.leftJoin('product.statusHistory', 'status_history')
|
.leftJoin('product.statusHistory', 'status_history')
|
||||||
|
|
||||||
.leftJoinAndMapOne(
|
.leftJoinAndMapOne(
|
||||||
'product.currentPrice',
|
'product.currentPrice',
|
||||||
|
@ -330,7 +331,7 @@ export class ProductService {
|
||||||
.addSelect(['product.name', 'product.code', 'sub_categories.name'])
|
.addSelect(['product.name', 'product.code', 'sub_categories.name'])
|
||||||
.addSelect('(current_price.price + current_price.mark_up_price) as price')
|
.addSelect('(current_price.price + current_price.mark_up_price) as price')
|
||||||
.orderBy('price', 'ASC')
|
.orderBy('price', 'ASC')
|
||||||
.distinct()
|
.distinct();
|
||||||
|
|
||||||
if (subCategories != 'null' && subCategories) {
|
if (subCategories != 'null' && subCategories) {
|
||||||
baseQuery.andWhere('product.sub_categories_id = :id', {
|
baseQuery.andWhere('product.sub_categories_id = :id', {
|
||||||
|
@ -393,18 +394,22 @@ export class ProductService {
|
||||||
id_partner: user.partner.id,
|
id_partner: user.partner.id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.innerJoinAndMapOne(
|
.innerJoinAndMapOne(
|
||||||
'product.currentStatus',
|
'product.currentStatus',
|
||||||
'product.statusHistory',
|
'product.statusHistory',
|
||||||
'history_status',
|
'history_status',
|
||||||
'history_status.deleted_at is NULL'
|
'history_status.partner_id = :id_partner and history_status.deleted_at is NULL',
|
||||||
)
|
{
|
||||||
.where(`history_status.partner_id = :id_partner and history_status.status = 'ACTIVE'`,
|
id_partner: user.partner.id,
|
||||||
{
|
},
|
||||||
id_partner: user.partner.id,
|
)
|
||||||
},
|
// .where(`history_status.partner_id = :id_partner`, {
|
||||||
)
|
// partner: user.partner.id,
|
||||||
.select(['product.id'])
|
// })
|
||||||
|
.where(`history_status.status = 'ACTIVE'`, {
|
||||||
|
status: 'ACTIVE',
|
||||||
|
})
|
||||||
|
.select(['product.id'])
|
||||||
.addSelect([
|
.addSelect([
|
||||||
'product.name',
|
'product.name',
|
||||||
'product.code',
|
'product.code',
|
||||||
|
@ -415,11 +420,11 @@ export class ProductService {
|
||||||
'current_price.partner_fee as partner_fee',
|
'current_price.partner_fee as partner_fee',
|
||||||
'current_price.price as price',
|
'current_price.price as price',
|
||||||
])
|
])
|
||||||
.addSelect('history_status.status', 'status')
|
.addSelect('history_status.status', 'status')
|
||||||
.distinct()
|
.distinct();
|
||||||
// .addSelect(
|
// .addSelect(
|
||||||
// '(current_price.price + current_price.mark_up_price) as price',
|
// '(current_price.price + current_price.mark_up_price) as price',
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// if (
|
// if (
|
||||||
// subCategories != 'null' &&
|
// subCategories != 'null' &&
|
||||||
|
@ -431,14 +436,15 @@ export class ProductService {
|
||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if (subCategories && filterSubCategories.length > 0) {
|
||||||
if (subCategories && filterSubCategories.length > 0) {
|
baseQuery
|
||||||
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||||
subCategoryId: filterSubCategories,
|
subCategoryId: filterSubCategories,
|
||||||
}).andWhere(`history_status.status = 'ACTIVE'`)
|
})
|
||||||
|
.andWhere(`history_status.status = 'ACTIVE'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newData = []
|
const newData = [];
|
||||||
|
|
||||||
const data = await baseQuery
|
const data = await baseQuery
|
||||||
.offset(page * pageSize)
|
.offset(page * pageSize)
|
||||||
|
@ -446,23 +452,24 @@ export class ProductService {
|
||||||
.getRawMany();
|
.getRawMany();
|
||||||
|
|
||||||
data.map((dataa) => {
|
data.map((dataa) => {
|
||||||
let actualPrice = 0
|
let actualPrice = 0;
|
||||||
|
|
||||||
if (dataa.product_type === 'prepaid') {
|
if (dataa.product_type === 'prepaid') {
|
||||||
actualPrice = Number(dataa['price']) + Number(dataa['markup_price'])
|
actualPrice = Number(dataa['price']) + Number(dataa['markup_price']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataa.product_type === 'postpaid') {
|
if (dataa.product_type === 'postpaid') {
|
||||||
actualPrice = Number(dataa['admin_price'])- (Number(dataa['partner_fee']) + Number(dataa['markup_price']))
|
actualPrice =
|
||||||
}
|
Number(dataa['admin_price']) -
|
||||||
|
(Number(dataa['partner_fee']) + Number(dataa['markup_price']));
|
||||||
|
}
|
||||||
|
|
||||||
dataa.price = actualPrice
|
dataa.price = actualPrice;
|
||||||
|
|
||||||
newData.push({
|
newData.push({
|
||||||
...dataa
|
...dataa,
|
||||||
})
|
});
|
||||||
|
});
|
||||||
})
|
|
||||||
|
|
||||||
const totalData = await baseQuery.getCount();
|
const totalData = await baseQuery.getCount();
|
||||||
|
|
||||||
|
@ -495,32 +502,35 @@ export class ProductService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOneActive(code: string, type: string, roles: string, supplierId: string) {
|
async findOneActive(
|
||||||
if (roles == "Retail") {
|
code: string,
|
||||||
|
type: string,
|
||||||
|
roles: string,
|
||||||
|
supplierId: string,
|
||||||
|
) {
|
||||||
|
if (roles == 'Retail') {
|
||||||
try {
|
try {
|
||||||
return await this.productRepository.findOneOrFail({
|
return await this.productRepository.findOneOrFail({
|
||||||
relations: ['supplier'],
|
relations: ['supplier'],
|
||||||
where: {
|
where: {
|
||||||
code: code,
|
code: code,
|
||||||
supplier: supplierId
|
supplier: supplierId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
error: 'Product not found',
|
error: 'Product not found',
|
||||||
},
|
},
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.productRepository.findOneOrFail({
|
return await this.productRepository.findOneOrFail({
|
||||||
relations: ['supplier'],
|
relations: ['supplier'],
|
||||||
|
@ -531,17 +541,16 @@ export class ProductService {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
error: 'Product not found',
|
error: 'Product not found',
|
||||||
},
|
},
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,6 +607,7 @@ export class ProductService {
|
||||||
await this.productHistoryStatus.update(dataStatus.id, {
|
await this.productHistoryStatus.update(dataStatus.id, {
|
||||||
status: updateProductDto.status,
|
status: updateProductDto.status,
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await this.productRepository.update(id, {
|
const result = await this.productRepository.update(id, {
|
||||||
name: updateProductDto.name,
|
name: updateProductDto.name,
|
||||||
code: updateProductDto.code,
|
code: updateProductDto.code,
|
||||||
|
|
|
@ -1111,23 +1111,23 @@ export class TransactionService {
|
||||||
supplier_trx_id
|
supplier_trx_id
|
||||||
);
|
);
|
||||||
|
|
||||||
if (transactionData.status == statusTransaction.FAILED) {
|
// if (transactionData.status == statusTransaction.FAILED) {
|
||||||
throw new HttpException(
|
// throw new HttpException(
|
||||||
{
|
// {
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
// statusCode: HttpStatus.BAD_REQUEST,
|
||||||
error: 'failed to update, the transaction already failed',
|
// error: 'failed to update, the transaction already failed',
|
||||||
},
|
// },
|
||||||
HttpStatus.BAD_REQUEST,
|
// HttpStatus.BAD_REQUEST,
|
||||||
);
|
// );
|
||||||
} else if (transactionData.status == statusTransaction.SUCCESS) {
|
// } else if (transactionData.status == statusTransaction.SUCCESS) {
|
||||||
throw new HttpException(
|
// throw new HttpException(
|
||||||
{
|
// {
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
// statusCode: HttpStatus.BAD_REQUEST,
|
||||||
error: 'failed to update, the transaction already success',
|
// error: 'failed to update, the transaction already success',
|
||||||
},
|
// },
|
||||||
HttpStatus.BAD_REQUEST,
|
// HttpStatus.BAD_REQUEST,
|
||||||
);
|
// );
|
||||||
} else {
|
// } else {
|
||||||
const updateTransaction = await this.callbackOrderFailed(
|
const updateTransaction = await this.callbackOrderFailed(
|
||||||
supplier_trx_id,
|
supplier_trx_id,
|
||||||
callback,
|
callback,
|
||||||
|
@ -1142,7 +1142,7 @@ export class TransactionService {
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1337,14 +1337,14 @@ export class TransactionService {
|
||||||
});
|
});
|
||||||
|
|
||||||
dataTransaction.status = statusTransaction.SUCCESS;
|
dataTransaction.status = statusTransaction.SUCCESS;
|
||||||
if(callback['sn']){
|
if (callback['sn']) {
|
||||||
dataTransaction.seri_number = callback['sn'];
|
dataTransaction.seri_number = callback['sn'];
|
||||||
console.log("msksn1", dataTransaction.seri_number)
|
console.log("msksn1", dataTransaction.seri_number)
|
||||||
} else {
|
} else {
|
||||||
const response = callback['message'];
|
const response = callback['message'];
|
||||||
const responseBaru = response.split(' ');
|
const responseBaru = response.split(' ');
|
||||||
dataTransaction.seri_number =
|
dataTransaction.seri_number =
|
||||||
responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9];
|
responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9];
|
||||||
|
|
||||||
if (dataTransaction.seri_number == 'SN:') {
|
if (dataTransaction.seri_number == 'SN:') {
|
||||||
dataTransaction.seri_number = responseBaru[11]
|
dataTransaction.seri_number = responseBaru[11]
|
||||||
|
@ -1352,7 +1352,7 @@ export class TransactionService {
|
||||||
}
|
}
|
||||||
dataTransaction.callback_json = callback;
|
dataTransaction.callback_json = callback;
|
||||||
|
|
||||||
if(callback['message']) {
|
if (callback['message']) {
|
||||||
if (callback['message'].includes('METRO')) {
|
if (callback['message'].includes('METRO')) {
|
||||||
if (callback['price'] != dataTransaction.product_price.price) {
|
if (callback['price'] != dataTransaction.product_price.price) {
|
||||||
dataProductHistoryPrice.price = parseInt(callback['price'])
|
dataProductHistoryPrice.price = parseInt(callback['price'])
|
||||||
|
@ -1365,18 +1365,18 @@ export class TransactionService {
|
||||||
let supervisorData = [];
|
let supervisorData = [];
|
||||||
|
|
||||||
const product_price = await this.productHistoryPriceService.findById(
|
const product_price = await this.productHistoryPriceService.findById(
|
||||||
dataTransaction.product_price.id,
|
dataTransaction.product_price.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
const product = await this.productService.findOneById(
|
const product = await this.productService.findOneById(
|
||||||
product_price.product.id,
|
product_price.product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let profit = product_price.mark_up_price;
|
let profit = product_price.mark_up_price;
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
const coaExpense = await this.coaService.findByName(
|
const coaExpense = await this.coaService.findByName(
|
||||||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
|
// dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||||
|
@ -1384,17 +1384,17 @@ export class TransactionService {
|
||||||
if (userData.partner == null) {
|
if (userData.partner == null) {
|
||||||
//GET SALES
|
//GET SALES
|
||||||
supervisorData = await this.calculateCommission(
|
supervisorData = await this.calculateCommission(
|
||||||
supervisorData,
|
supervisorData,
|
||||||
profit,
|
profit,
|
||||||
userData,
|
userData,
|
||||||
);
|
);
|
||||||
profit = supervisorData
|
profit = supervisorData
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
return item.credit;
|
return item.credit;
|
||||||
})
|
})
|
||||||
.reduce((prev, curr) => {
|
.reduce((prev, curr) => {
|
||||||
return prev + curr;
|
return prev + curr;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
supervisorData = supervisorData.concat([
|
supervisorData = supervisorData.concat([
|
||||||
{
|
{
|
||||||
|
@ -1420,21 +1420,22 @@ export class TransactionService {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
if (userData.partner != null) {
|
||||||
if (userData.partner) {
|
if (userData.partner) {
|
||||||
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
|
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
|
||||||
this.callbackToPartner(
|
this.callbackToPartner(
|
||||||
userData.partner.id,
|
userData.partner.id,
|
||||||
message,
|
message,
|
||||||
dataTransaction.partner_trx_id,
|
dataTransaction.partner_trx_id,
|
||||||
dataTransaction.amount,
|
dataTransaction.amount,
|
||||||
product.code,
|
product.code,
|
||||||
dataTransaction.destination,
|
dataTransaction.destination,
|
||||||
dataTransaction.seri_number,
|
dataTransaction.seri_number,
|
||||||
'berhasil',
|
'berhasil',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async resendOrderToPartner(supplier_trx_id: string, status: boolean){
|
async resendOrderToPartner(supplier_trx_id: string, status: boolean){
|
||||||
const dataTransaction = await this.transactionRepository.findOne({
|
const dataTransaction = await this.transactionRepository.findOne({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user