Merge branch 'devops-staging' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend
This commit is contained in:
commit
a9d09a40ff
|
@ -66,7 +66,10 @@ export class PpobCallbackController {
|
||||||
);
|
);
|
||||||
//
|
//
|
||||||
} else {
|
} else {
|
||||||
|
console.log('statusapani', response['status']);
|
||||||
|
console.log('statusapani2', response.toString());
|
||||||
if (response['status'].toString() != '20') {
|
if (response['status'].toString() != '20') {
|
||||||
|
console.log("masukkesiniga", "msk")
|
||||||
//TODO: UPDATE GAGAL
|
//TODO: UPDATE GAGAL
|
||||||
const updateTransaction =
|
const updateTransaction =
|
||||||
await this.transactionService.callbackOrderFailed(
|
await this.transactionService.callbackOrderFailed(
|
||||||
|
@ -79,16 +82,22 @@ export class PpobCallbackController {
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
message: 'failed to proccess',
|
message: 'failed to proccess',
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//TODO: UPDATE BERHASIL
|
||||||
|
const updateTransaction =
|
||||||
|
await this.transactionService.callbackOrderSuccess(
|
||||||
|
response['refid'],
|
||||||
|
response,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
updateTransaction,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: UPDATE BERHASIL
|
|
||||||
const updateTransaction =
|
|
||||||
await this.transactionService.callbackOrderSuccess(
|
|
||||||
response['refid'],
|
|
||||||
response,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log({
|
this.logger.log({
|
||||||
requestQuery: request.query,
|
requestQuery: request.query,
|
||||||
});
|
});
|
||||||
|
|
|
@ -299,184 +299,216 @@ export class TransactionService {
|
||||||
orderTransactionDto: OrderTransactionDto,
|
orderTransactionDto: OrderTransactionDto,
|
||||||
currentUser: any,
|
currentUser: any,
|
||||||
) {
|
) {
|
||||||
const trxId = Array(6)
|
|
||||||
.fill(null)
|
|
||||||
.map(() => {
|
|
||||||
return Math.round(Math.random() * 16).toString(16);
|
|
||||||
})
|
|
||||||
.join('');
|
|
||||||
|
|
||||||
//GET USER
|
const productData = await this.productService.findOne(
|
||||||
const userData = await this.userService.findByUsername(
|
orderTransactionDto.productCode,
|
||||||
currentUser.username,
|
'prepaid',
|
||||||
);
|
);
|
||||||
|
|
||||||
//GET PRODUCT
|
if (productData.status == 'NOT ACTIVE') {
|
||||||
const product = await this.productService.findOne(
|
|
||||||
orderTransactionDto.productCode,
|
|
||||||
'prepaid'
|
|
||||||
);
|
|
||||||
|
|
||||||
const product_price = await this.productHistoryPriceService.findOne(
|
|
||||||
product.id,
|
|
||||||
userData.partner?.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
let supervisorData = [];
|
|
||||||
let profit = product_price.mark_up_price;
|
|
||||||
|
|
||||||
//GET COA
|
|
||||||
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`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const coaExpense = await this.coaService.findByName(
|
|
||||||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!userData.partner) {
|
|
||||||
//GET SALES
|
|
||||||
supervisorData = await this.calculateCommission(
|
|
||||||
supervisorData,
|
|
||||||
profit,
|
|
||||||
userData,
|
|
||||||
);
|
|
||||||
profit = supervisorData
|
|
||||||
.map((item) => {
|
|
||||||
return item.credit;
|
|
||||||
})
|
|
||||||
.reduce((prev, curr) => {
|
|
||||||
return prev + curr;
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
supervisorData = supervisorData.concat([
|
|
||||||
{
|
|
||||||
coa_id: coaExpense.id,
|
|
||||||
debit: profit,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
try {
|
const trxId = Array(6)
|
||||||
await this.connection.transaction(async (manager) => {
|
.fill(null)
|
||||||
const transactionData = new Transactions();
|
.map(() => {
|
||||||
|
return Math.round(Math.random() * 16).toString(16);
|
||||||
|
})
|
||||||
|
.join('');
|
||||||
|
|
||||||
transactionData.id = uuid.v4();
|
//GET USER
|
||||||
transactionData.amount =
|
const userData = await this.userService.findByUsername(
|
||||||
product_price.mark_up_price + product_price.price;
|
currentUser.username,
|
||||||
transactionData.user = userData.id;
|
);
|
||||||
transactionData.status = statusTransaction.SUCCESS;
|
|
||||||
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;
|
|
||||||
await manager.insert(Transactions, transactionData);
|
|
||||||
|
|
||||||
await this.accountingTransaction({
|
//GET PRODUCT
|
||||||
createTransaction: false,
|
const product = await this.productService.findOne(
|
||||||
transactionalEntityManager: manager,
|
orderTransactionDto.productCode,
|
||||||
transaction: transactionData,
|
'prepaid'
|
||||||
amount: transactionData.amount,
|
);
|
||||||
journals: [
|
|
||||||
|
const product_price = await this.productHistoryPriceService.findOne(
|
||||||
|
product.id,
|
||||||
|
userData.partner?.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
let supervisorData = [];
|
||||||
|
let profit = product_price.mark_up_price;
|
||||||
|
|
||||||
|
//GET COA
|
||||||
|
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`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const coaExpense = await this.coaService.findByName(
|
||||||
|
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!userData.partner) {
|
||||||
|
//GET SALES
|
||||||
|
supervisorData = await this.calculateCommission(
|
||||||
|
supervisorData,
|
||||||
|
profit,
|
||||||
|
userData,
|
||||||
|
);
|
||||||
|
profit = supervisorData
|
||||||
|
.map((item) => {
|
||||||
|
return item.credit;
|
||||||
|
})
|
||||||
|
.reduce((prev, curr) => {
|
||||||
|
return prev + curr;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
supervisorData = supervisorData.concat([
|
||||||
|
{
|
||||||
|
coa_id: coaExpense.id,
|
||||||
|
debit: profit,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coaAccount.amount < product_price.mark_up_price + product_price.price) {
|
||||||
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
coa_id: coaInventory.id,
|
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
credit: product_price.price,
|
error: `Transaction Failed because saldo not enough`,
|
||||||
},
|
},
|
||||||
{
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
coa_id: coaCostOfSales.id,
|
);
|
||||||
debit: product_price.price,
|
}
|
||||||
},
|
|
||||||
{
|
try {
|
||||||
coa_id: coaAccount.id,
|
await this.connection.transaction(async (manager) => {
|
||||||
debit: product_price.mark_up_price + product_price.price,
|
const transactionData = new Transactions();
|
||||||
},
|
|
||||||
{
|
transactionData.id = uuid.v4();
|
||||||
// eslint-disable-next-line camelcase
|
transactionData.amount =
|
||||||
coa_id: coaSales.id,
|
product_price.mark_up_price + product_price.price;
|
||||||
credit: product_price.mark_up_price + product_price.price,
|
transactionData.user = userData.id;
|
||||||
},
|
transactionData.status = statusTransaction.SUCCESS;
|
||||||
].concat(supervisorData),
|
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;
|
||||||
|
await manager.insert(Transactions, transactionData);
|
||||||
|
|
||||||
|
await this.accountingTransaction({
|
||||||
|
createTransaction: false,
|
||||||
|
transactionalEntityManager: manager,
|
||||||
|
transaction: transactionData,
|
||||||
|
amount: transactionData.amount,
|
||||||
|
journals: [
|
||||||
|
{
|
||||||
|
coa_id: coaInventory.id,
|
||||||
|
credit: product_price.price,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
coa_id: coaCostOfSales.id,
|
||||||
|
debit: product_price.price,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
coa_id: coaAccount.id,
|
||||||
|
debit: product_price.mark_up_price + product_price.price,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
coa_id: coaSales.id,
|
||||||
|
credit: product_price.mark_up_price + product_price.price,
|
||||||
|
},
|
||||||
|
].concat(supervisorData),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} catch (e) {
|
||||||
} catch (e) {
|
throw e;
|
||||||
throw e;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
trx_id: trxId,
|
trx_id: trxId,
|
||||||
client_trx_id: orderTransactionDto.trx_id,
|
client_trx_id: orderTransactionDto.trx_id,
|
||||||
product: orderTransactionDto.productCode,
|
product: orderTransactionDto.productCode,
|
||||||
amount: product_price.mark_up_price + product_price.price,
|
amount: product_price.mark_up_price + product_price.price,
|
||||||
status: statusTransaction[statusTransaction.SUCCESS],
|
status: statusTransaction[statusTransaction.SUCCESS],
|
||||||
};
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async orderTransactionProd(
|
async orderTransactionProd(
|
||||||
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) {
|
||||||
|
@ -490,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;
|
||||||
|
@ -504,42 +536,41 @@ 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;
|
||||||
|
|
||||||
if (supplier.code != 'IRS') {
|
if (supplier.code != 'IRS') {
|
||||||
const parsingResponse = hitSupplier.split(' ');
|
const parsingResponse = hitSupplier.split(' ');
|
||||||
console.log
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -559,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);
|
||||||
|
|
||||||
|
@ -588,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;
|
||||||
|
@ -602,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;
|
||||||
|
@ -653,6 +684,7 @@ export class TransactionService {
|
||||||
status: status,
|
status: status,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async orderTransactionBillProd(
|
async orderTransactionBillProd(
|
||||||
orderTransactionDto: OrderTransactionDto,
|
orderTransactionDto: OrderTransactionDto,
|
||||||
|
@ -1169,12 +1201,12 @@ export class TransactionService {
|
||||||
relations: ['product_price'],
|
relations: ['product_price'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const dataMsg = callback.msg;
|
// const dataMsg = callback.msg;
|
||||||
const failedReason = dataMsg.split('.');
|
// const failedReason = dataMsg.split('.');
|
||||||
|
|
||||||
dataTransaction.status = statusTransaction.FAILED;
|
// dataTransaction.status = statusTransaction.FAILED;
|
||||||
dataTransaction.callback_json = callback;
|
// dataTransaction.callback_json = callback;
|
||||||
dataTransaction.failed_reason = `${failedReason[0]}, ${failedReason[1]}`;
|
// dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
||||||
|
|
||||||
const userData = await this.userService.findExist(dataTransaction.user);
|
const userData = await this.userService.findExist(dataTransaction.user);
|
||||||
|
|
||||||
|
@ -1186,6 +1218,13 @@ export class TransactionService {
|
||||||
product_price.product.id,
|
product_price.product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
dataTransaction.status = statusTransaction.FAILED;
|
||||||
|
dataTransaction.callback_json = callback;
|
||||||
|
dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
||||||
|
if (callback['price'] != dataTransaction.product_price.price) {
|
||||||
|
dataTransaction.product_price.price = callback['price']
|
||||||
|
}
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
|
@ -1271,6 +1310,10 @@ export class TransactionService {
|
||||||
}
|
}
|
||||||
dataTransaction.callback_json = callback;
|
dataTransaction.callback_json = callback;
|
||||||
|
|
||||||
|
if (callback['price'] != dataTransaction.product_price.price) {
|
||||||
|
dataTransaction.product_price.price = callback['price']
|
||||||
|
}
|
||||||
|
|
||||||
const userData = await this.userService.findExist(dataTransaction.user);
|
const userData = await this.userService.findExist(dataTransaction.user);
|
||||||
|
|
||||||
let supervisorData = [];
|
let supervisorData = [];
|
||||||
|
@ -1570,7 +1613,8 @@ export class TransactionService {
|
||||||
)
|
)
|
||||||
.leftJoin('transaction.product_price', 'product_price')
|
.leftJoin('transaction.product_price', 'product_price')
|
||||||
.leftJoin('product_price.product', 'product')
|
.leftJoin('product_price.product', 'product')
|
||||||
.addSelect('transaction.amount', 'price')
|
.leftJoin('product.supplier', 'supplier')
|
||||||
|
.addSelect('transaction.amount', 'price')
|
||||||
.addSelect('transaction.destination')
|
.addSelect('transaction.destination')
|
||||||
.addSelect('transaction.seri_number', 'seri_number')
|
.addSelect('transaction.seri_number', 'seri_number')
|
||||||
.addSelect('transaction.supplier_trx_id', 'transaction_code')
|
.addSelect('transaction.supplier_trx_id', 'transaction_code')
|
||||||
|
@ -1579,8 +1623,10 @@ export class TransactionService {
|
||||||
.addSelect('transaction.failed_reason', 'failed_reason')
|
.addSelect('transaction.failed_reason', 'failed_reason')
|
||||||
.addSelect('userData.name', 'buyer')
|
.addSelect('userData.name', 'buyer')
|
||||||
.addSelect('product.name', 'name')
|
.addSelect('product.name', 'name')
|
||||||
.addSelect('product.id', 'product_id')
|
.addSelect('product_price.price', 'product_price')
|
||||||
.orderBy('transaction.created_at', 'DESC');
|
.addSelect('product.name', 'supplier_name')
|
||||||
|
.addSelect('supplier.name', 'supplier_name')
|
||||||
|
.orderBy('transaction.created_at', 'DESC');
|
||||||
|
|
||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
baseQuery.andWhere(
|
baseQuery.andWhere(
|
||||||
|
@ -1881,16 +1927,27 @@ export class TransactionService {
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = await baseQuery
|
const data = await baseQuery
|
||||||
.select('SUM(transactions.amount) as total_amount')
|
.select('SUM(transactions.amount) as total_amount')
|
||||||
.addSelect('SUM(product_price.price) as total_modal')
|
.addSelect('SUM(product_price.price) as total_modal')
|
||||||
.addSelect('SUM(product_price.mark_up_price) as total_profit')
|
.addSelect('SUM(product_price.mark_up_price) as total_profit')
|
||||||
.addSelect('COUNT(transactions.id) as total_transaction')
|
.addSelect('COUNT(transactions.id) as total_transaction')
|
||||||
.getRawOne();
|
.getRawOne();
|
||||||
|
|
||||||
|
// const dataCoa = this.coaRepository
|
||||||
|
// .createQueryBuilder('coa')
|
||||||
|
// .innerJoin('user', 'user', 'coa.user = user.id')
|
||||||
|
// .where(
|
||||||
|
// `coa.type = '0' and user.partner_id is not NULL and user.is_active = true and is_rejected = false`
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// const coa = await dataCoa
|
||||||
|
// .select('SUM(coa.amount) as total_modal')
|
||||||
|
// .getRawOne();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
total_modal: parseInt(data.total_modal),
|
||||||
total_amount: parseInt(data.total_amount),
|
total_amount: parseInt(data.total_amount),
|
||||||
total_transaction: parseInt(data.total_transaction),
|
total_transaction: parseInt(data.total_transaction),
|
||||||
total_modal: parseInt(data.total_modal),
|
|
||||||
total_profit: parseInt(data.total_profit),
|
total_profit: parseInt(data.total_profit),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user