- handle when product is not active cannot hit api transaction order prod
This commit is contained in:
parent
c184fdddc5
commit
245e876144
|
@ -456,44 +456,59 @@ export class TransactionService {
|
||||||
orderTransactionDto: OrderTransactionDto,
|
orderTransactionDto: OrderTransactionDto,
|
||||||
currentUser: any,
|
currentUser: any,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
const productData = await this.productService.findOne(
|
||||||
|
orderTransactionDto.productCode,
|
||||||
|
'prepaid',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (productData.status == 'NOT ACTIVE') {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
error: `Transaction Failed because product is not active`,
|
||||||
|
},
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
let status;
|
let status;
|
||||||
const amount = 0;
|
const amount = 0;
|
||||||
//GET USER DATA
|
//GET USER DATA
|
||||||
const userData = await this.userService.findByUsername(
|
const userData = await this.userService.findByUsername(
|
||||||
currentUser.username,
|
currentUser.username,
|
||||||
);
|
);
|
||||||
|
|
||||||
//GET PRODUCT AND PRICE
|
//GET PRODUCT AND PRICE
|
||||||
const product = await this.productService.findOne(
|
const product = await this.productService.findOne(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
'prepaid',
|
'prepaid',
|
||||||
);
|
);
|
||||||
|
|
||||||
const supplier = await this.supplierService.findByCode(
|
const supplier = await this.supplierService.findByCode(
|
||||||
product.supplier.code,
|
product.supplier.code,
|
||||||
);
|
);
|
||||||
|
|
||||||
let product_price = await this.productHistoryPriceService.findOne(
|
let product_price = await this.productHistoryPriceService.findOne(
|
||||||
product.id,
|
product.id,
|
||||||
userData.partner?.id,
|
userData.partner?.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
);
|
);
|
||||||
|
|
||||||
const coaInventory = await this.coaService.findByName(
|
const coaInventory = await this.coaService.findByName(
|
||||||
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const coaCostOfSales = await this.coaService.findByName(
|
const coaCostOfSales = await this.coaService.findByName(
|
||||||
`${coaType[coaType.COST_OF_SALES]}-${product.supplier.code}`,
|
`${coaType[coaType.COST_OF_SALES]}-${product.supplier.code}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const coaSales = await this.coaService.findByName(
|
const coaSales = await this.coaService.findByName(
|
||||||
`${coaType[coaType.SALES]}-SYSTEM`,
|
`${coaType[coaType.SALES]}-SYSTEM`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (orderTransactionDto.bill_trx_id) {
|
if (orderTransactionDto.bill_trx_id) {
|
||||||
|
@ -507,11 +522,11 @@ export class TransactionService {
|
||||||
} 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: 'Bill not found',
|
error: 'Bill not found',
|
||||||
},
|
},
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -521,27 +536,27 @@ export class TransactionService {
|
||||||
|
|
||||||
if (coaAccount.amount < product_price.mark_up_price + product_price.price) {
|
if (coaAccount.amount < product_price.mark_up_price + product_price.price) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
error: `Transaction Failed because saldo not enough`,
|
error: `Transaction Failed because saldo not enough`,
|
||||||
},
|
},
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//HIT API SUPPLIER
|
//HIT API SUPPLIER
|
||||||
const trxId = Array(6)
|
const trxId = Array(6)
|
||||||
.fill(null)
|
.fill(null)
|
||||||
.map(() => {
|
.map(() => {
|
||||||
return Math.round(Math.random() * 16).toString(16);
|
return Math.round(Math.random() * 16).toString(16);
|
||||||
})
|
})
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
let hitSupplier = await doTransaction(
|
let hitSupplier = await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
trxId,
|
trxId,
|
||||||
supplier,
|
supplier,
|
||||||
);
|
);
|
||||||
// let hitSupplier;
|
// let hitSupplier;
|
||||||
|
|
||||||
|
@ -550,12 +565,12 @@ export class TransactionService {
|
||||||
const newHitSupplier = {
|
const newHitSupplier = {
|
||||||
success: hitSupplier.includes('diproses'),
|
success: hitSupplier.includes('diproses'),
|
||||||
harga: parseInt(
|
harga: parseInt(
|
||||||
parsingResponse[parsingResponse.length - 2].replace(/\./g,' '),
|
parsingResponse[parsingResponse.length - 2].replace(/\./g, ' '),
|
||||||
),
|
),
|
||||||
msg: hitSupplier,
|
msg: hitSupplier,
|
||||||
};
|
};
|
||||||
hitSupplier = newHitSupplier;
|
hitSupplier = newHitSupplier;
|
||||||
if(orderTransactionDto.bill_trx_id !== null){
|
if (orderTransactionDto.bill_trx_id !== null) {
|
||||||
hitSupplier.harga = product_price.price;
|
hitSupplier.harga = product_price.price;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -575,9 +590,9 @@ export class TransactionService {
|
||||||
product_price.endDate = new Date();
|
product_price.endDate = new Date();
|
||||||
costInventory = hitSupplier.harga;
|
costInventory = hitSupplier.harga;
|
||||||
const listActivePrice =
|
const listActivePrice =
|
||||||
await this.productHistoryPriceService.getAllActivePriceByProduct(
|
await this.productHistoryPriceService.getAllActivePriceByProduct(
|
||||||
product.id,
|
product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
await this.productHistoryPriceService.updateEndDate(product.id);
|
await this.productHistoryPriceService.updateEndDate(product.id);
|
||||||
|
|
||||||
|
@ -604,7 +619,7 @@ export class TransactionService {
|
||||||
|
|
||||||
transactionData.id = uuid.v4();
|
transactionData.id = uuid.v4();
|
||||||
transactionData.amount =
|
transactionData.amount =
|
||||||
product_price.mark_up_price + product_price.price;
|
product_price.mark_up_price + product_price.price;
|
||||||
transactionData.user = userData.id;
|
transactionData.user = userData.id;
|
||||||
transactionData.type = typeTransaction.ORDER;
|
transactionData.type = typeTransaction.ORDER;
|
||||||
transactionData.product_price = product_price;
|
transactionData.product_price = product_price;
|
||||||
|
@ -618,11 +633,11 @@ export class TransactionService {
|
||||||
status = statusTransaction[transactionData.status];
|
status = statusTransaction[transactionData.status];
|
||||||
await this.transactionRepository.insert(transactionData);
|
await this.transactionRepository.insert(transactionData);
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
error: hitSupplier.msg,
|
error: hitSupplier.msg,
|
||||||
},
|
},
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
transactionData.status = statusTransaction.PENDING;
|
transactionData.status = statusTransaction.PENDING;
|
||||||
|
@ -669,6 +684,7 @@ export class TransactionService {
|
||||||
status: status,
|
status: status,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async orderTransactionBillProd(
|
async orderTransactionBillProd(
|
||||||
orderTransactionDto: OrderTransactionDto,
|
orderTransactionDto: OrderTransactionDto,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user