Merge branch 'master' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-production
This commit is contained in:
commit
c5f54c8663
|
@ -10,6 +10,9 @@ export class Transactions extends BaseModel {
|
|||
@Column()
|
||||
amount: number;
|
||||
|
||||
@Column()
|
||||
balance_remaining: number;
|
||||
|
||||
@Column()
|
||||
status: statusTransaction;
|
||||
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
import { Controller, Get, HttpStatus, Logger, Req } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Logger,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { TransactionService } from './transaction.service';
|
||||
import { FastifyRequest } from 'fastify';
|
||||
import { Public } from '../auth/public.decorator';
|
||||
import { EntityNotFoundError } from 'typeorm';
|
||||
|
||||
@Controller({
|
||||
path: 'ppob_callback',
|
||||
|
@ -24,7 +32,6 @@ export class PpobCallbackController {
|
|||
response,
|
||||
);
|
||||
} else {
|
||||
|
||||
//TODO: UPDATE BERHASIL
|
||||
await this.transactionService.checkCallbackOrderSuccess(
|
||||
response['clientid'],
|
||||
|
@ -36,6 +43,7 @@ export class PpobCallbackController {
|
|||
@Public()
|
||||
@Get('/metro')
|
||||
async getMetro(@Req() request: FastifyRequest) {
|
||||
try {
|
||||
const response = request.query;
|
||||
|
||||
if (response['message'].toLowerCase().includes('cek tagihan')) {
|
||||
|
@ -56,6 +64,7 @@ export class PpobCallbackController {
|
|||
}
|
||||
|
||||
const splitMessage = response['message'].split('"');
|
||||
|
||||
//TODO: UPDATE BERHASIL
|
||||
await this.transactionService.updateBill(
|
||||
response['refid'],
|
||||
|
@ -68,8 +77,8 @@ export class PpobCallbackController {
|
|||
} else {
|
||||
console.log('statusapani', response['status']);
|
||||
console.log('statusapani2', response.toString());
|
||||
|
||||
if (response['status'].toString() != '20') {
|
||||
console.log("masukkesiniga", "msk")
|
||||
//TODO: UPDATE GAGAL
|
||||
const updateTransaction =
|
||||
await this.transactionService.callbackOrderFailed(
|
||||
|
@ -98,6 +107,7 @@ export class PpobCallbackController {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.log({
|
||||
requestQuery: request.query,
|
||||
});
|
||||
|
@ -106,5 +116,19 @@ export class PpobCallbackController {
|
|||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Error callback',
|
||||
message: e
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import { UsersModule } from 'src/users/users.module';
|
|||
import { ConfigurableModule } from '../configurable/configurable.module';
|
||||
import { CheckBillHistory } from './entities/check-bill-history.entity';
|
||||
import { CallbackPartner } from './entities/callback-partner.entity';
|
||||
import {ProductHistoryPrice} from "../product/entities/product-history-price.entity";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -21,6 +22,7 @@ import { CallbackPartner } from './entities/callback-partner.entity';
|
|||
Transactions,
|
||||
CheckBillHistory,
|
||||
CallbackPartner,
|
||||
ProductHistoryPrice,
|
||||
]),
|
||||
ProductModule,
|
||||
ConfigurableModule,
|
||||
|
|
|
@ -35,6 +35,8 @@ export class TransactionService {
|
|||
private transactionRepository: Repository<Transactions>,
|
||||
@InjectRepository(TransactionJournal)
|
||||
private transactionJournalRepository: Repository<TransactionJournal>,
|
||||
@InjectRepository(ProductHistoryPrice)
|
||||
private productPriceRepository: Repository<ProductHistoryPrice>,
|
||||
@InjectRepository(COA)
|
||||
private coaRepository: Repository<COA>,
|
||||
@InjectRepository(CheckBillHistory)
|
||||
|
@ -627,6 +629,7 @@ export class TransactionService {
|
|||
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;
|
||||
|
@ -1201,6 +1204,12 @@ export class TransactionService {
|
|||
relations: ['product_price'],
|
||||
});
|
||||
|
||||
const dataProductHistoryPrice = await this.productPriceRepository.findOne({
|
||||
where: {
|
||||
id: dataTransaction.product_price.id,
|
||||
},
|
||||
});
|
||||
|
||||
// const dataMsg = callback.msg;
|
||||
// const failedReason = dataMsg.split('.');
|
||||
|
||||
|
@ -1222,10 +1231,13 @@ export class TransactionService {
|
|||
dataTransaction.callback_json = callback;
|
||||
dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
||||
|
||||
console.log("inipricetable", dataTransaction.product_price.price)
|
||||
console.log("inipricecallback", callback['price'])
|
||||
if(callback['message']) {
|
||||
if (callback['message'].includes('METRO')) {
|
||||
if (callback['price'] != dataTransaction.product_price.price) {
|
||||
dataTransaction.product_price.price = callback['price']
|
||||
console.log("mskupdt", "msk")
|
||||
dataTransaction.product_price.price = parseInt(callback['price'])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1236,6 +1248,11 @@ export class TransactionService {
|
|||
coaType.WALLET,
|
||||
);
|
||||
|
||||
dataTransaction.status = statusTransaction.FAILED;
|
||||
dataTransaction.callback_json = callback;
|
||||
dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
||||
dataTransaction.balance_remaining = coaAccount.amount + product_price.mark_up_price + product_price.price;
|
||||
|
||||
const coaInventory = await this.coaService.findByName(
|
||||
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
||||
);
|
||||
|
@ -1251,6 +1268,7 @@ export class TransactionService {
|
|||
try {
|
||||
await this.connection.transaction(async (manager) => {
|
||||
await manager.save(dataTransaction);
|
||||
await manager.save(dataProductHistoryPrice);
|
||||
|
||||
await this.accountingTransaction({
|
||||
createTransaction: false,
|
||||
|
@ -1304,6 +1322,12 @@ export class TransactionService {
|
|||
relations: ['product_price'],
|
||||
});
|
||||
|
||||
const dataProductHistoryPrice = await this.productPriceRepository.findOne({
|
||||
where: {
|
||||
id: dataTransaction.product_price.id,
|
||||
},
|
||||
});
|
||||
|
||||
dataTransaction.status = statusTransaction.SUCCESS;
|
||||
if(callback['sn']){
|
||||
dataTransaction.seri_number = callback['sn'];
|
||||
|
@ -1318,7 +1342,7 @@ export class TransactionService {
|
|||
if(callback['message']) {
|
||||
if (callback['message'].includes('METRO')) {
|
||||
if (callback['price'] != dataTransaction.product_price.price) {
|
||||
dataTransaction.product_price.price = callback['price']
|
||||
dataProductHistoryPrice.price = parseInt(callback['price'])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1342,6 +1366,8 @@ export class TransactionService {
|
|||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||
);
|
||||
|
||||
// dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||
|
||||
if (userData.partner == null) {
|
||||
//GET SALES
|
||||
supervisorData = await this.calculateCommission(
|
||||
|
@ -1368,6 +1394,7 @@ export class TransactionService {
|
|||
try {
|
||||
await this.connection.transaction(async (manager) => {
|
||||
await manager.save(dataTransaction);
|
||||
await manager.save(dataProductHistoryPrice)
|
||||
|
||||
await this.accountingTransaction({
|
||||
createTransaction: false,
|
||||
|
@ -1461,14 +1488,26 @@ export class TransactionService {
|
|||
coaType.WALLET,
|
||||
);
|
||||
|
||||
if (!partnerData.callback_url) {
|
||||
this.logger.error(`Call to partner failed, reason: no callback url`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const url = `${partnerData.callback_url}?status=${status}&memberID=${partnerData.code}&trxid=${trxId}&harga=${harga}&product=${productCode}&dest=${destination}&seriNumber=${seriNumber}&message=${message}&saldo=${coaAccount.amount}`;
|
||||
const result = await this.callbackPartnerRepository.insert({
|
||||
partner_trx_id: partnerId,
|
||||
trx_id: trxId,
|
||||
url: url,
|
||||
});
|
||||
|
||||
try {
|
||||
const res = await axios.get(url);
|
||||
|
||||
return res;
|
||||
} catch (e) {
|
||||
this.logger.error(`Call to partner failed, reason: ${e.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async rollbackJurnal(trxId: string[]) {
|
||||
|
@ -1625,6 +1664,7 @@ export class TransactionService {
|
|||
.leftJoin('product.supplier', 'supplier')
|
||||
.addSelect('transaction.amount', 'price')
|
||||
.addSelect('transaction.destination')
|
||||
.addSelect('transaction.balance_remaining', 'balance_remaining')
|
||||
.addSelect('transaction.seri_number', 'seri_number')
|
||||
.addSelect('transaction.supplier_trx_id', 'transaction_code')
|
||||
.addSelect('transaction.status', 'status')
|
||||
|
@ -1633,6 +1673,7 @@ export class TransactionService {
|
|||
.addSelect('userData.name', 'buyer')
|
||||
.addSelect('product.name', 'name')
|
||||
.addSelect('product_price.price', 'product_price')
|
||||
.addSelect('product_price.mark_up_price', 'mark_up_price')
|
||||
.addSelect('product.name', 'supplier_name')
|
||||
.addSelect('supplier.name', 'supplier_name')
|
||||
.orderBy('transaction.created_at', 'DESC');
|
||||
|
|
Loading…
Reference in New Issue
Block a user