Merge branch 'development' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into development
Conflicts: src/transaction/transaction.service.ts
This commit is contained in:
commit
5c50d1d53a
18
src/transaction/entities/callback-partner.entity.ts
Normal file
18
src/transaction/entities/callback-partner.entity.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||||
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
import { statusTransaction, typeTransaction } from '../../helper/enum-list';
|
||||||
|
import { ProductHistoryPrice } from '../../product/entities/product-history-price.entity';
|
||||||
|
import { UserDetail } from '../../users/entities/user_detail.entity';
|
||||||
|
import { TransactionJournal } from './transaction-journal.entity';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class CallbackPartner extends BaseModel {
|
||||||
|
@Column()
|
||||||
|
trx_id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
partner_trx_id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
url: string;
|
||||||
|
}
|
|
@ -132,6 +132,40 @@ export class TransactionController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('rollback-jurnal')
|
||||||
|
async rollbackJurnal(@Body() request, @Request() req) {
|
||||||
|
const data = await this.transactionService.rollbackJurnal(request.trxId);
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('resend-partner/success/:code')
|
||||||
|
async resendSuccess(@Request() req, @Param('code') code: string) {
|
||||||
|
const data = await this.transactionService.resendOrderToPartner(code, true);
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('resend-partner/failed/:code')
|
||||||
|
async resendFailed(@Request() req, @Param('code') code: string) {
|
||||||
|
const data = await this.transactionService.resendOrderToPartner(
|
||||||
|
code,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Get('history')
|
@Get('history')
|
||||||
async getHistoryTransactionUser(
|
async getHistoryTransactionUser(
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { ProductModule } from '../product/product.module';
|
||||||
import { UsersModule } from 'src/users/users.module';
|
import { UsersModule } from 'src/users/users.module';
|
||||||
import { ConfigurableModule } from '../configurable/configurable.module';
|
import { ConfigurableModule } from '../configurable/configurable.module';
|
||||||
import { CheckBillHistory } from './entities/check-bill-history.entity';
|
import { CheckBillHistory } from './entities/check-bill-history.entity';
|
||||||
|
import { CallbackPartner } from './entities/callback-partner.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -19,6 +20,7 @@ import { CheckBillHistory } from './entities/check-bill-history.entity';
|
||||||
TransactionJournal,
|
TransactionJournal,
|
||||||
Transactions,
|
Transactions,
|
||||||
CheckBillHistory,
|
CheckBillHistory,
|
||||||
|
CallbackPartner,
|
||||||
]),
|
]),
|
||||||
ProductModule,
|
ProductModule,
|
||||||
ConfigurableModule,
|
ConfigurableModule,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
||||||
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Transactions } from './entities/transactions.entity';
|
import { Transactions } from './entities/transactions.entity';
|
||||||
import { Between, Connection, EntityNotFoundError, Repository } from 'typeorm';
|
import { Between, Connection, EntityNotFoundError, In, Repository } from 'typeorm';
|
||||||
import { COA } from './entities/coa.entity';
|
import { COA } from './entities/coa.entity';
|
||||||
import { TransactionJournal } from './entities/transaction-journal.entity';
|
import { TransactionJournal } from './entities/transaction-journal.entity';
|
||||||
import { CoaService } from './coa.service';
|
import { CoaService } from './coa.service';
|
||||||
|
@ -29,6 +29,7 @@ import { doTransaction } from '../helper/irs-api';
|
||||||
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
|
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { CheckBillHistory } from './entities/check-bill-history.entity';
|
import { CheckBillHistory } from './entities/check-bill-history.entity';
|
||||||
|
import { CallbackPartner } from './entities/callback-partner.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionService {
|
export class TransactionService {
|
||||||
|
@ -43,6 +44,8 @@ export class TransactionService {
|
||||||
private coaRepository: Repository<COA>,
|
private coaRepository: Repository<COA>,
|
||||||
@InjectRepository(CheckBillHistory)
|
@InjectRepository(CheckBillHistory)
|
||||||
private checkBillHistoryRepository: Repository<CheckBillHistory>,
|
private checkBillHistoryRepository: Repository<CheckBillHistory>,
|
||||||
|
@InjectRepository(CallbackPartner)
|
||||||
|
private callbackPartnerRepository: Repository<CallbackPartner>,
|
||||||
private coaService: CoaService,
|
private coaService: CoaService,
|
||||||
private productService: ProductService,
|
private productService: ProductService,
|
||||||
private productHistoryPriceService: ProductHistoryPriceService,
|
private productHistoryPriceService: ProductHistoryPriceService,
|
||||||
|
@ -1064,17 +1067,6 @@ export class TransactionService {
|
||||||
relations: ['product_price'],
|
relations: ['product_price'],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dataTransaction.status == statusTransaction.FAILED) {
|
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
|
||||||
message: 'failed to update, the transaction already failed',
|
|
||||||
};
|
|
||||||
} else if (dataTransaction.status == statusTransaction.SUCCESS) {
|
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
|
||||||
message: 'failed to update, the transaction already success',
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const dataMsg = callback.msg;
|
const dataMsg = callback.msg;
|
||||||
const failedReason = dataMsg.split('.');
|
const failedReason = dataMsg.split('.');
|
||||||
|
|
||||||
|
@ -1146,7 +1138,7 @@ export class TransactionService {
|
||||||
if (userData.partner) {
|
if (userData.partner) {
|
||||||
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`;
|
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`;
|
||||||
this.callbackToPartner(
|
this.callbackToPartner(
|
||||||
userData.id,
|
userData.partner.id,
|
||||||
message,
|
message,
|
||||||
dataTransaction.partner_trx_id,
|
dataTransaction.partner_trx_id,
|
||||||
dataTransaction.amount,
|
dataTransaction.amount,
|
||||||
|
@ -1155,13 +1147,6 @@ export class TransactionService {
|
||||||
'-',
|
'-',
|
||||||
'gagal',
|
'gagal',
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
|
||||||
message: 'failed to proccess',
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1173,21 +1158,15 @@ export class TransactionService {
|
||||||
relations: ['product_price'],
|
relations: ['product_price'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (dataTransaction.status == statusTransaction.FAILED) {
|
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
|
||||||
message: 'failed to update, the transaction already failed',
|
|
||||||
};
|
|
||||||
} else if (dataTransaction.status == statusTransaction.SUCCESS) {
|
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.BAD_REQUEST,
|
|
||||||
message: 'failed to update, the transaction already success',
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
|
|
||||||
dataTransaction.status = statusTransaction.SUCCESS;
|
dataTransaction.status = statusTransaction.SUCCESS;
|
||||||
|
if(callback['sn']){
|
||||||
dataTransaction.seri_number = callback['sn'];
|
dataTransaction.seri_number = callback['sn'];
|
||||||
|
} else {
|
||||||
|
const response = callback['message'];
|
||||||
|
const responseBaru = response.split(' ');
|
||||||
|
dataTransaction.seri_number =
|
||||||
|
responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9];
|
||||||
|
}
|
||||||
dataTransaction.callback_json = callback;
|
dataTransaction.callback_json = callback;
|
||||||
|
|
||||||
const userData = await this.userService.findExist(dataTransaction.user);
|
const userData = await this.userService.findExist(dataTransaction.user);
|
||||||
|
@ -1208,7 +1187,8 @@ export class TransactionService {
|
||||||
const coaExpense = await this.coaService.findByName(
|
const coaExpense = await this.coaService.findByName(
|
||||||
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
`${coaType[coaType.EXPENSE]}-SYSTEM`,
|
||||||
);
|
);
|
||||||
if (userData.partner != null) {
|
|
||||||
|
if (userData.partner == null) {
|
||||||
//GET SALES
|
//GET SALES
|
||||||
supervisorData = await this.calculateCommission(
|
supervisorData = await this.calculateCommission(
|
||||||
supervisorData,
|
supervisorData,
|
||||||
|
@ -1250,7 +1230,7 @@ export class TransactionService {
|
||||||
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.id,
|
userData.partner.id,
|
||||||
message,
|
message,
|
||||||
dataTransaction.partner_trx_id,
|
dataTransaction.partner_trx_id,
|
||||||
dataTransaction.amount,
|
dataTransaction.amount,
|
||||||
|
@ -1260,11 +1240,53 @@ export class TransactionService {
|
||||||
'berhasil',
|
'berhasil',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
message: 'success',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async resendOrderToPartner(supplier_trx_id: string, status: boolean){
|
||||||
|
const dataTransaction = await this.transactionRepository.findOne({
|
||||||
|
where: {
|
||||||
|
supplier_trx_id: supplier_trx_id,
|
||||||
|
},
|
||||||
|
relations: ['product_price'],
|
||||||
|
});
|
||||||
|
|
||||||
|
const userData = await this.userService.findExist(dataTransaction.user);
|
||||||
|
|
||||||
|
const product_price = await this.productHistoryPriceService.findById(
|
||||||
|
dataTransaction.product_price.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
const product = await this.productService.findOneById(
|
||||||
|
product_price.product.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
|
||||||
|
await this.callbackToPartner(
|
||||||
|
userData.partner.id,
|
||||||
|
message,
|
||||||
|
dataTransaction.partner_trx_id,
|
||||||
|
dataTransaction.amount,
|
||||||
|
product.code,
|
||||||
|
dataTransaction.destination,
|
||||||
|
dataTransaction.seri_number,
|
||||||
|
'berhasil',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`;
|
||||||
|
this.callbackToPartner(
|
||||||
|
userData.partner.id,
|
||||||
|
message,
|
||||||
|
dataTransaction.partner_trx_id,
|
||||||
|
dataTransaction.amount,
|
||||||
|
product.code,
|
||||||
|
dataTransaction.destination,
|
||||||
|
'-',
|
||||||
|
'gagal',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async callbackToPartner(
|
async callbackToPartner(
|
||||||
|
@ -1278,9 +1300,73 @@ export class TransactionService {
|
||||||
status: string,
|
status: string,
|
||||||
) {
|
) {
|
||||||
const partnerData = await this.userService.findPartner(partnerId);
|
const partnerData = await this.userService.findPartner(partnerId);
|
||||||
const res = await axios.get(
|
const userData = await this.userService.findOneByPartner(partnerId);
|
||||||
`${partnerData.callback_url}?status=${status}&memberID=${partnerData.code}&trxid=${trxId}&harga=${harga}&product=${productCode}&dest=${destination}&seriNumber=${seriNumber}&message=${message}`,
|
|
||||||
|
const coaAccount = await this.coaService.findByUser(
|
||||||
|
userData.id,
|
||||||
|
coaType.WALLET,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
const res = await axios.get(url);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async rollbackJurnal(trxId: string[]) {
|
||||||
|
// const dataTransaction = await this.transactionRepository.findOne({
|
||||||
|
// where: {
|
||||||
|
// id: trxId,
|
||||||
|
// },
|
||||||
|
// relations: ['product_price'],
|
||||||
|
// });
|
||||||
|
|
||||||
|
if (trxId.length % 2 != 0) {
|
||||||
|
throw Error("Not Balance")
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataTransactionJurnal = await this.transactionJournalRepository.find({
|
||||||
|
where: {
|
||||||
|
id: In(trxId),
|
||||||
|
},
|
||||||
|
relations: ['coa'],
|
||||||
|
});
|
||||||
|
|
||||||
|
let dataRollbackJurnal = [];
|
||||||
|
|
||||||
|
dataTransactionJurnal.map((it) => {
|
||||||
|
let data = {
|
||||||
|
coa_id: it.coa.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (it.type == 0) {
|
||||||
|
data['credit'] = it.amount;
|
||||||
|
} else {
|
||||||
|
data['debit'] = it.amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
dataRollbackJurnal.push(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
const dataTransaction = new Transactions();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
await this.accountingTransaction({
|
||||||
|
createTransaction: false,
|
||||||
|
transactionalEntityManager: manager,
|
||||||
|
transaction: dataTransaction,
|
||||||
|
amount: dataTransaction.amount,
|
||||||
|
journals: dataRollbackJurnal,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async withdrawBenefit(user) {
|
async withdrawBenefit(user) {
|
||||||
|
|
|
@ -366,7 +366,7 @@ export class UsersService {
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
relations: ['superior', 'roles'],
|
relations: ['superior', 'roles', 'partner'],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user