Merge branch 'devops-staging' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend
This commit is contained in:
commit
4e9d4e48f9
|
@ -3,7 +3,7 @@ import {
|
||||||
Get,
|
Get,
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Logger,
|
Logger, Post,
|
||||||
Req,
|
Req,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { TransactionService } from './transaction.service';
|
import { TransactionService } from './transaction.service';
|
||||||
|
@ -131,4 +131,25 @@ export class PpobCallbackController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public()
|
||||||
|
@Post('/hemat')
|
||||||
|
async getHemat(@Req() request: FastifyRequest) {
|
||||||
|
const response = request.body;
|
||||||
|
console.log('responsehemat', response);
|
||||||
|
console.log('responsehemat2', request.body);
|
||||||
|
if (response['msg'] != 'Transaksi Sukses') {
|
||||||
|
//TODO: UPDATE GAGAL
|
||||||
|
await this.transactionService.checkCallbackOrderFailed(
|
||||||
|
response['data']['idtransaction'],
|
||||||
|
response,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
//TODO: UPDATE BERHASIL
|
||||||
|
await this.transactionService.checkCallbackOrderSuccess(
|
||||||
|
response['data']['idtransaction'],
|
||||||
|
response,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -523,267 +523,267 @@ export class TransactionService {
|
||||||
);
|
);
|
||||||
|
|
||||||
const statusProduct = await this.productHistoryStatusService.findOneActive(
|
const statusProduct = await this.productHistoryStatusService.findOneActive(
|
||||||
product.id,
|
product.id,
|
||||||
userData.partner == null ? null : userData.partner.id,
|
userData.partner == null ? null : userData.partner.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (statusProduct.status == 'NOT ACTIVE') {
|
if (statusProduct.status == 'NOT ACTIVE') {
|
||||||
throw new HttpException(
|
|
||||||
{
|
|
||||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
error: `Transaction Failed because product is not active`,
|
|
||||||
},
|
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.log('userdatapartnerid', userData.partner?.id);
|
|
||||||
|
|
||||||
let product_price = await this.productHistoryPriceService.findOne(
|
|
||||||
product.id,
|
|
||||||
userData.partner?.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
//GET COA
|
|
||||||
console.log('coamsk5', product_price.id);
|
|
||||||
|
|
||||||
const coaAccount = await this.coaService.findByUser(
|
|
||||||
userData.id,
|
|
||||||
coaType.WALLET,
|
|
||||||
);
|
|
||||||
|
|
||||||
const coaInventory = await this.coaService.findByName(
|
|
||||||
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const coaCostOfSales = await this.coaService.findByName(
|
|
||||||
`${coaType[coaType.COST_OF_SALES]}-${product.supplier.code}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const coaSales = await this.coaService.findByName(
|
|
||||||
`${coaType[coaType.SALES]}-SYSTEM`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (orderTransactionDto.bill_trx_id) {
|
|
||||||
try {
|
|
||||||
const billId = await this.checkBillHistoryRepository.findOneOrFail({
|
|
||||||
where: {
|
|
||||||
trx_id: orderTransactionDto.bill_trx_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
product_price.price = billId.amount;
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof EntityNotFoundError) {
|
|
||||||
throw new HttpException(
|
|
||||||
{
|
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
|
||||||
error: 'Bill not found',
|
|
||||||
},
|
|
||||||
HttpStatus.NOT_FOUND,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 product is not active`,
|
||||||
},
|
},
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
|
console.log('userdatapartnerid', userData.partner?.id);
|
||||||
|
|
||||||
//HIT API SUPPLIER
|
let product_price = await this.productHistoryPriceService.findOne(
|
||||||
const trxId = Array(6)
|
product.id,
|
||||||
.fill(null)
|
userData.partner?.id,
|
||||||
.map(() => {
|
);
|
||||||
return Math.round(Math.random() * 16).toString(16);
|
|
||||||
})
|
|
||||||
.join('');
|
|
||||||
|
|
||||||
let hitLoginHemat;
|
//GET COA
|
||||||
|
console.log('coamsk5', product_price.id);
|
||||||
|
|
||||||
if (supplier.code == 'Hemat') {
|
const coaAccount = await this.coaService.findByUser(
|
||||||
hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier);
|
userData.id,
|
||||||
}
|
coaType.WALLET,
|
||||||
|
);
|
||||||
|
|
||||||
let hitSupplier = supplier.code == 'Hemat' ?
|
const coaInventory = await this.coaService.findByName(
|
||||||
await doTransaction(
|
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
||||||
orderTransactionDto.productCode,
|
);
|
||||||
orderTransactionDto.destination,
|
|
||||||
trxId,
|
|
||||||
supplier,
|
|
||||||
hitLoginHemat.data,
|
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
|
||||||
) : await doTransaction(
|
|
||||||
orderTransactionDto.productCode,
|
|
||||||
orderTransactionDto.destination,
|
|
||||||
trxId,
|
|
||||||
supplier,
|
|
||||||
"",
|
|
||||||
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
|
||||||
);
|
|
||||||
|
|
||||||
// let hitSupplier;
|
const coaCostOfSales = await this.coaService.findByName(
|
||||||
|
`${coaType[coaType.COST_OF_SALES]}-${product.supplier.code}`,
|
||||||
|
);
|
||||||
|
|
||||||
console.log('iniresponsupplierharga', hitSupplier)
|
const coaSales = await this.coaService.findByName(
|
||||||
console.log('iniresponsupplier', hitSupplier.harga)
|
`${coaType[coaType.SALES]}-SYSTEM`,
|
||||||
console.log(supplier.code, 'sdkfjsd');
|
);
|
||||||
console.log(product_price, 'price');
|
|
||||||
|
|
||||||
|
if (orderTransactionDto.bill_trx_id) {
|
||||||
|
try {
|
||||||
|
const billId = await this.checkBillHistoryRepository.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
trx_id: orderTransactionDto.bill_trx_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (supplier.code == 'metro') {
|
product_price.price = billId.amount;
|
||||||
const parsingResponse = hitSupplier.split(' ');
|
} catch (e) {
|
||||||
console.log('parsingResponse', parsingResponse)
|
if (e instanceof EntityNotFoundError) {
|
||||||
const newHitSupplier = {
|
throw new HttpException(
|
||||||
success: hitSupplier.includes('diproses'),
|
{
|
||||||
harga: parseInt(
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
parsingResponse[parsingResponse.length - 2].replace(/\./g, ' '),
|
error: 'Bill not found',
|
||||||
),
|
},
|
||||||
msg: hitSupplier,
|
HttpStatus.NOT_FOUND,
|
||||||
};
|
|
||||||
|
|
||||||
hitSupplier = newHitSupplier;
|
|
||||||
|
|
||||||
if (orderTransactionDto.bill_trx_id !== null) {
|
|
||||||
hitSupplier.harga = product_price.price;
|
|
||||||
}
|
|
||||||
} else if (supplier.code == 'Hemat') {
|
|
||||||
const newHitSupplier = {
|
|
||||||
success: hitSupplier.success,
|
|
||||||
harga: product_price.price,
|
|
||||||
msg: hitSupplier.msg,
|
|
||||||
};
|
|
||||||
|
|
||||||
hitSupplier = newHitSupplier;
|
|
||||||
|
|
||||||
if (orderTransactionDto.bill_trx_id !== null) {
|
|
||||||
hitSupplier.harga = product_price.price;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(hitSupplier, 'newhitSupplier');
|
|
||||||
|
|
||||||
// const hitSupplier = {
|
|
||||||
// harga: 2000,
|
|
||||||
// success: true,
|
|
||||||
// msg: 'Berhasil',
|
|
||||||
// };
|
|
||||||
|
|
||||||
this.logger.log({
|
|
||||||
responseAPISupplier: hitSupplier,
|
|
||||||
});
|
|
||||||
|
|
||||||
let costInventory = product_price.price;
|
|
||||||
|
|
||||||
if (hitSupplier.harga != undefined) {
|
|
||||||
if (hitSupplier.harga != product_price.price) {
|
|
||||||
console.log('priceupdate1supplier', hitSupplier.harga);
|
|
||||||
console.log('priceupdate1normal', product_price.price);
|
|
||||||
product_price.endDate = new Date();
|
|
||||||
costInventory = hitSupplier.harga;
|
|
||||||
|
|
||||||
const listActivePrice =
|
|
||||||
await this.productHistoryPriceService.getAllActivePriceByProduct(
|
|
||||||
product.id,
|
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
await this.productHistoryPriceService.updateEndDate(product.id);
|
throw e;
|
||||||
|
}
|
||||||
listActivePrice.map(async (x) => {
|
|
||||||
const newProductPrice = new ProductHistoryPrice();
|
|
||||||
|
|
||||||
newProductPrice.id = uuid.v4();
|
|
||||||
newProductPrice.type = x.type;
|
|
||||||
newProductPrice.price = hitSupplier.harga;
|
|
||||||
newProductPrice.mark_up_price = x.mark_up_price;
|
|
||||||
newProductPrice.startDate = new Date();
|
|
||||||
newProductPrice.product = product;
|
|
||||||
newProductPrice.partner = x.partner;
|
|
||||||
await this.productHistoryPriceService.create(newProductPrice);
|
|
||||||
|
|
||||||
product_price = newProductPrice;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
//TRANSACTION DATA
|
|
||||||
await this.connection.transaction(async (manager) => {
|
|
||||||
const transactionData = new Transactions();
|
|
||||||
|
|
||||||
transactionData.id = uuid.v4();
|
|
||||||
transactionData.amount =
|
|
||||||
product_price.mark_up_price + product_price.price;
|
|
||||||
transactionData.user = userData.id;
|
|
||||||
transactionData.type = typeTransaction.ORDER;
|
|
||||||
transactionData.product_price = product_price;
|
|
||||||
transactionData.destination = orderTransactionDto.destination;
|
|
||||||
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
|
||||||
transactionData.supplier_trx_id = trxId;
|
|
||||||
transactionData.check_bill = orderTransactionDto.bill_trx_id;
|
|
||||||
transactionData.balance_remaining =
|
|
||||||
coaAccount.amount - product_price.mark_up_price - costInventory;
|
|
||||||
|
|
||||||
if (!hitSupplier.success) {
|
|
||||||
transactionData.status = statusTransaction.FAILED;
|
|
||||||
status = statusTransaction[transactionData.status];
|
|
||||||
await this.transactionRepository.insert(transactionData);
|
|
||||||
throw new HttpException(
|
|
||||||
{
|
|
||||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
error: hitSupplier.msg,
|
|
||||||
},
|
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
transactionData.status = statusTransaction.PENDING;
|
|
||||||
status = statusTransaction[transactionData.status];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await manager.insert(Transactions, transactionData);
|
if (coaAccount.amount < product_price.mark_up_price + product_price.price) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
error: `Transaction Failed because saldo not enough`,
|
||||||
|
},
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await this.accountingTransaction({
|
//HIT API SUPPLIER
|
||||||
createTransaction: false,
|
const trxId = Array(6)
|
||||||
transactionalEntityManager: manager,
|
.fill(null)
|
||||||
transaction: transactionData,
|
.map(() => {
|
||||||
amount: transactionData.amount,
|
return Math.round(Math.random() * 16).toString(16);
|
||||||
journals: [
|
})
|
||||||
{
|
.join('');
|
||||||
coa_id: coaInventory.id,
|
|
||||||
credit: costInventory,
|
let hitLoginHemat;
|
||||||
},
|
|
||||||
{
|
if (supplier.code == 'Hemat') {
|
||||||
coa_id: coaCostOfSales.id,
|
hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier);
|
||||||
debit: costInventory,
|
}
|
||||||
},
|
|
||||||
{
|
let hitSupplier = supplier.code == 'Hemat' ?
|
||||||
coa_id: coaAccount.id,
|
await doTransaction(
|
||||||
debit: product_price.mark_up_price + costInventory,
|
orderTransactionDto.productCode,
|
||||||
},
|
orderTransactionDto.destination,
|
||||||
{
|
trxId,
|
||||||
// eslint-disable-next-line camelcase
|
supplier,
|
||||||
coa_id: coaSales.id,
|
hitLoginHemat.data,
|
||||||
credit: product_price.mark_up_price + costInventory,
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
},
|
) : await doTransaction(
|
||||||
],
|
orderTransactionDto.productCode,
|
||||||
});
|
orderTransactionDto.destination,
|
||||||
|
trxId,
|
||||||
|
supplier,
|
||||||
|
"",
|
||||||
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
|
);
|
||||||
|
|
||||||
|
// let hitSupplier;
|
||||||
|
|
||||||
|
console.log('iniresponsupplierharga', hitSupplier)
|
||||||
|
console.log('iniresponsupplier', hitSupplier.harga)
|
||||||
|
console.log(supplier.code, 'sdkfjsd');
|
||||||
|
console.log(product_price, 'price');
|
||||||
|
|
||||||
|
|
||||||
|
if (supplier.code == 'metro') {
|
||||||
|
const parsingResponse = hitSupplier.split(' ');
|
||||||
|
console.log('parsingResponse', parsingResponse)
|
||||||
|
const newHitSupplier = {
|
||||||
|
success: hitSupplier.includes('diproses'),
|
||||||
|
harga: parseInt(
|
||||||
|
parsingResponse[parsingResponse.length - 2].replace(/\./g, ' '),
|
||||||
|
),
|
||||||
|
msg: hitSupplier,
|
||||||
|
};
|
||||||
|
|
||||||
|
hitSupplier = newHitSupplier;
|
||||||
|
|
||||||
|
if (orderTransactionDto.bill_trx_id !== null) {
|
||||||
|
hitSupplier.harga = product_price.price;
|
||||||
|
}
|
||||||
|
} else if (supplier.code == 'Hemat') {
|
||||||
|
const newHitSupplier = {
|
||||||
|
success: hitSupplier.success,
|
||||||
|
harga: product_price.price,
|
||||||
|
msg: hitSupplier.msg,
|
||||||
|
};
|
||||||
|
|
||||||
|
hitSupplier = newHitSupplier;
|
||||||
|
|
||||||
|
if (orderTransactionDto.bill_trx_id !== null) {
|
||||||
|
hitSupplier.harga = product_price.price;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(hitSupplier, 'newhitSupplier');
|
||||||
|
|
||||||
|
// const hitSupplier = {
|
||||||
|
// harga: 2000,
|
||||||
|
// success: true,
|
||||||
|
// msg: 'Berhasil',
|
||||||
|
// };
|
||||||
|
|
||||||
|
this.logger.log({
|
||||||
|
responseAPISupplier: hitSupplier,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
let costInventory = product_price.price;
|
||||||
trx_id: trxId,
|
|
||||||
client_trx_id: orderTransactionDto.trx_id,
|
if (hitSupplier.harga != undefined) {
|
||||||
product: orderTransactionDto.productCode,
|
if (hitSupplier.harga != product_price.price) {
|
||||||
amount: product_price.mark_up_price + product_price.price,
|
console.log('priceupdate1supplier', hitSupplier.harga);
|
||||||
status: status,
|
console.log('priceupdate1normal', product_price.price);
|
||||||
};
|
product_price.endDate = new Date();
|
||||||
|
costInventory = hitSupplier.harga;
|
||||||
|
|
||||||
|
const listActivePrice =
|
||||||
|
await this.productHistoryPriceService.getAllActivePriceByProduct(
|
||||||
|
product.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.productHistoryPriceService.updateEndDate(product.id);
|
||||||
|
|
||||||
|
listActivePrice.map(async (x) => {
|
||||||
|
const newProductPrice = new ProductHistoryPrice();
|
||||||
|
|
||||||
|
newProductPrice.id = uuid.v4();
|
||||||
|
newProductPrice.type = x.type;
|
||||||
|
newProductPrice.price = hitSupplier.harga;
|
||||||
|
newProductPrice.mark_up_price = x.mark_up_price;
|
||||||
|
newProductPrice.startDate = new Date();
|
||||||
|
newProductPrice.product = product;
|
||||||
|
newProductPrice.partner = x.partner;
|
||||||
|
await this.productHistoryPriceService.create(newProductPrice);
|
||||||
|
|
||||||
|
product_price = newProductPrice;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
//TRANSACTION DATA
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
const transactionData = new Transactions();
|
||||||
|
|
||||||
|
transactionData.id = uuid.v4();
|
||||||
|
transactionData.amount =
|
||||||
|
product_price.mark_up_price + product_price.price;
|
||||||
|
transactionData.user = userData.id;
|
||||||
|
transactionData.type = typeTransaction.ORDER;
|
||||||
|
transactionData.product_price = product_price;
|
||||||
|
transactionData.destination = orderTransactionDto.destination;
|
||||||
|
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
||||||
|
transactionData.supplier_trx_id = trxId;
|
||||||
|
transactionData.check_bill = orderTransactionDto.bill_trx_id;
|
||||||
|
transactionData.balance_remaining =
|
||||||
|
coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||||
|
|
||||||
|
if (!hitSupplier.success) {
|
||||||
|
transactionData.status = statusTransaction.FAILED;
|
||||||
|
status = statusTransaction[transactionData.status];
|
||||||
|
await this.transactionRepository.insert(transactionData);
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
error: hitSupplier.msg,
|
||||||
|
},
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
transactionData.status = statusTransaction.PENDING;
|
||||||
|
status = statusTransaction[transactionData.status];
|
||||||
|
}
|
||||||
|
|
||||||
|
await manager.insert(Transactions, transactionData);
|
||||||
|
|
||||||
|
await this.accountingTransaction({
|
||||||
|
createTransaction: false,
|
||||||
|
transactionalEntityManager: manager,
|
||||||
|
transaction: transactionData,
|
||||||
|
amount: transactionData.amount,
|
||||||
|
journals: [
|
||||||
|
{
|
||||||
|
coa_id: coaInventory.id,
|
||||||
|
credit: costInventory,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
coa_id: coaCostOfSales.id,
|
||||||
|
debit: costInventory,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
coa_id: coaAccount.id,
|
||||||
|
debit: product_price.mark_up_price + costInventory,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
coa_id: coaSales.id,
|
||||||
|
credit: product_price.mark_up_price + costInventory,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
trx_id: trxId,
|
||||||
|
client_trx_id: orderTransactionDto.trx_id,
|
||||||
|
product: orderTransactionDto.productCode,
|
||||||
|
amount: product_price.mark_up_price + product_price.price,
|
||||||
|
status: status,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1011,7 +1011,7 @@ export class TransactionService {
|
||||||
let hitLoginHemat;
|
let hitLoginHemat;
|
||||||
|
|
||||||
if (supplier.code == 'Hemat') {
|
if (supplier.code == 'Hemat') {
|
||||||
hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier);
|
hitLoginHemat = await doAuthorizeHemat(supplier.irs_user, supplier.irs_pass, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hitSupplier = supplier.code == 'Hemat' ? await doTransaction(
|
let hitSupplier = supplier.code == 'Hemat' ? await doTransaction(
|
||||||
|
@ -1257,19 +1257,19 @@ export class TransactionService {
|
||||||
// } else {
|
// } else {
|
||||||
|
|
||||||
|
|
||||||
const updateTransaction = await this.callbackOrderFailed(
|
const updateTransaction = await this.callbackOrderFailed(
|
||||||
supplier_trx_id,
|
supplier_trx_id,
|
||||||
callback,
|
callback,
|
||||||
);
|
);
|
||||||
|
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
updateTransaction,
|
updateTransaction,
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
error: 'updated transaction to failed',
|
error: 'updated transaction to failed',
|
||||||
},
|
},
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
);
|
);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1295,19 +1295,19 @@ export class TransactionService {
|
||||||
// HttpStatus.BAD_REQUEST,
|
// HttpStatus.BAD_REQUEST,
|
||||||
// );
|
// );
|
||||||
// } else {
|
// } else {
|
||||||
const updateTransaction = await this.callbackOrderSuccess(
|
const updateTransaction = await this.callbackOrderSuccess(
|
||||||
supplier_trx_id,
|
supplier_trx_id,
|
||||||
callback,
|
callback,
|
||||||
);
|
);
|
||||||
|
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
updateTransaction,
|
updateTransaction,
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
error: 'success',
|
error: 'success',
|
||||||
},
|
},
|
||||||
HttpStatus.OK,
|
HttpStatus.OK,
|
||||||
);
|
);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1361,13 +1361,9 @@ export class TransactionService {
|
||||||
product_price.product.id,
|
product_price.product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('inipricetable', dataTransaction.product_price.price);
|
|
||||||
console.log('inipricecallback', callback['price']);
|
|
||||||
|
|
||||||
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) {
|
||||||
console.log('mskupdt', 'msk');
|
|
||||||
dataTransaction.product_price.price = parseInt(callback['price']);
|
dataTransaction.product_price.price = parseInt(callback['price']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1463,37 +1459,6 @@ export class TransactionService {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
dataTransaction.status = statusTransaction.SUCCESS;
|
|
||||||
|
|
||||||
if (callback['sn']) {
|
|
||||||
dataTransaction.seri_number = callback['sn'];
|
|
||||||
console.log('msksn1', dataTransaction.seri_number);
|
|
||||||
} else {
|
|
||||||
const response = callback['message'];
|
|
||||||
const responseBaru = response.split(' ');
|
|
||||||
|
|
||||||
dataTransaction.seri_number =
|
|
||||||
responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9];
|
|
||||||
|
|
||||||
if (dataTransaction.seri_number == 'SN:') {
|
|
||||||
dataTransaction.seri_number = responseBaru[11];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dataTransaction.callback_json = callback;
|
|
||||||
|
|
||||||
if (callback['message']) {
|
|
||||||
if (callback['message'].includes('METRO')) {
|
|
||||||
if (callback['price'] != dataTransaction.product_price.price) {
|
|
||||||
dataProductHistoryPrice.price = parseInt(callback['price']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const userData = await this.userService.findExist(dataTransaction.user);
|
|
||||||
|
|
||||||
let supervisorData = [];
|
|
||||||
|
|
||||||
const product_price = await this.productHistoryPriceService.findById(
|
const product_price = await this.productHistoryPriceService.findById(
|
||||||
dataTransaction.product_price.id,
|
dataTransaction.product_price.id,
|
||||||
);
|
);
|
||||||
|
@ -1502,6 +1467,46 @@ export class TransactionService {
|
||||||
product_price.product.id,
|
product_price.product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const supplier = await this.supplierService.findByCode(
|
||||||
|
product.supplier.code,
|
||||||
|
);
|
||||||
|
|
||||||
|
dataTransaction.status = statusTransaction.SUCCESS;
|
||||||
|
|
||||||
|
if (supplier.code == 'Hemat') {
|
||||||
|
dataTransaction.seri_number = callback['data']['serial_number'];
|
||||||
|
dataProductHistoryPrice.price = parseInt(callback['data']['additional']['harga']);
|
||||||
|
} else {
|
||||||
|
if (callback['sn']) {
|
||||||
|
dataTransaction.seri_number = callback['sn'];
|
||||||
|
console.log('msksn1', dataTransaction.seri_number);
|
||||||
|
} else {
|
||||||
|
const response = callback['message'];
|
||||||
|
const responseBaru = response.split(' ');
|
||||||
|
|
||||||
|
dataTransaction.seri_number =
|
||||||
|
responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9];
|
||||||
|
|
||||||
|
if (dataTransaction.seri_number == 'SN:') {
|
||||||
|
dataTransaction.seri_number = responseBaru[11];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dataTransaction.callback_json = callback;
|
||||||
|
|
||||||
|
if (callback['message']) {
|
||||||
|
if (callback['message'].includes('METRO')) {
|
||||||
|
if (callback['price'] != dataTransaction.product_price.price) {
|
||||||
|
dataProductHistoryPrice.price = parseInt(callback['price']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const userData = await this.userService.findExist(dataTransaction.user);
|
||||||
|
|
||||||
|
let supervisorData = [];
|
||||||
|
|
||||||
let profit = product_price.mark_up_price;
|
let profit = product_price.mark_up_price;
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
|
@ -2121,7 +2126,7 @@ export class TransactionService {
|
||||||
total_transaction: parseInt(data.total_transaction),
|
total_transaction: parseInt(data.total_transaction),
|
||||||
total_modal: parseInt(data.total_modal),
|
total_modal: parseInt(data.total_modal),
|
||||||
total_profit: parseInt(data.total_profit),
|
total_profit: parseInt(data.total_profit),
|
||||||
total_commission: parseInt(total_expense) - parseInt(data.total_profit),
|
total_commission: parseInt(data.total_profit) - parseInt(total_expense),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user