add all request for si hemat :
- Login - Request Transaction PrePaid - Request Inquiry / Check Bill PostPaid - Request Payment PostPaid
This commit is contained in:
parent
a5683666aa
commit
9b14685a92
|
@ -11,24 +11,42 @@ export const doTransaction = async (
|
||||||
destination,
|
destination,
|
||||||
idtrx,
|
idtrx,
|
||||||
supplier,
|
supplier,
|
||||||
|
authorization,
|
||||||
|
typePaid,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
if (supplier.code == 'IRS') {
|
if (supplier.code == 'IRS') {
|
||||||
const res = await axios.get(
|
const res = await axios.get(
|
||||||
`${irs_url}?id=${irs_id}&pin=${irs_pin}&user=${irs_user}&pass=${irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
`${irs_url}?id=${irs_id}&pin=${irs_pin}&user=${irs_user}&pass=${irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
} else if (supplier.code == 'NIRS') {
|
} else if (supplier.code == 'NIRS') {
|
||||||
const res = await axios.get(
|
const res = await axios.get(
|
||||||
`${supplier.url}?id=${supplier.irs_id}&pin=${supplier.irs_pin}&user=${supplier.irs_user}&pass=${supplier.irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
`${supplier.url}?id=${supplier.irs_id}&pin=${supplier.irs_pin}&user=${supplier.irs_user}&pass=${supplier.irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
} else {
|
} else if (supplier.code == 'Hemat') {
|
||||||
|
const options = {
|
||||||
|
headers: { Authorization: `${authorization}` },
|
||||||
|
};
|
||||||
|
const data = {
|
||||||
|
idtransaction: idtrx,
|
||||||
|
destination: `${destination}`,
|
||||||
|
code: `${productCode}`,
|
||||||
|
type: `${typePaid}`,
|
||||||
|
};
|
||||||
|
const res = await axios.post(`${supplier.url}`, data, options);
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await axios.get(
|
const res = await axios.get(
|
||||||
`${supplier.url}?memberID=${supplier.irs_id}&pin=${supplier.irs_pin}&password=${supplier.irs_pass}&product=${productCode}&dest=${destination}&counter=1&refID=${idtrx}`,
|
`${supplier.url}?memberID=${supplier.irs_id}&pin=${supplier.irs_pin}&password=${supplier.irs_pass}&product=${productCode}&dest=${destination}&counter=1&refID=${idtrx}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
15
src/helper/sihemat-authorization.ts
Normal file
15
src/helper/sihemat-authorization.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export const doAuthorizeHemat = async (user, pass, supplier) => {
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
username: `${user}`,
|
||||||
|
password: `${pass}`,
|
||||||
|
};
|
||||||
|
const res = await axios.post(`${supplier.url}`, data);
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
|
@ -515,12 +515,13 @@ export class ProductService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(code: string, type: string) {
|
async findOne(code: string, type: string, productId: string) {
|
||||||
try {
|
try {
|
||||||
return await this.productRepository.findOneOrFail({
|
return await this.productRepository.findOneOrFail({
|
||||||
relations: ['supplier'],
|
relations: ['supplier'],
|
||||||
where: {
|
where: {
|
||||||
code: code,
|
code: code,
|
||||||
|
id: productId
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -635,16 +636,16 @@ export class ProductService {
|
||||||
code: string,
|
code: string,
|
||||||
updatePriceProductDto: UpdatePriceProductDto,
|
updatePriceProductDto: UpdatePriceProductDto,
|
||||||
) {
|
) {
|
||||||
const product = await this.findOne(code, updatePriceProductDto.productType);
|
// const product = await this.findOne(code, updatePriceProductDto.productType);
|
||||||
|
|
||||||
await this.productHistoryPrice.insert({
|
// await this.productHistoryPrice.insert({
|
||||||
product: product,
|
// product: product,
|
||||||
type: updatePriceProductDto.type,
|
// type: updatePriceProductDto.type,
|
||||||
price: updatePriceProductDto.price,
|
// price: updatePriceProductDto.price,
|
||||||
mark_up_price: updatePriceProductDto.markUpPrice,
|
// mark_up_price: updatePriceProductDto.markUpPrice,
|
||||||
startDate: updatePriceProductDto.startDate,
|
// startDate: updatePriceProductDto.startDate,
|
||||||
endDate: updatePriceProductDto.endDate,
|
// endDate: updatePriceProductDto.endDate,
|
||||||
});
|
// });
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,25 @@ 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, In, 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';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { uniq } from 'lodash';
|
import { uniq } from 'lodash';
|
||||||
import { Decimal } from 'decimal.js';
|
import { Decimal } from 'decimal.js';
|
||||||
import {balanceType, coaType, statusTransaction, typeTransaction,} from '../helper/enum-list';
|
import {
|
||||||
|
balanceType,
|
||||||
|
coaType,
|
||||||
|
statusTransaction,
|
||||||
|
typeTransaction,
|
||||||
|
} from '../helper/enum-list';
|
||||||
import { ProductService } from '../product/product.service';
|
import { ProductService } from '../product/product.service';
|
||||||
import { CreateJournalDto } from './dto/create-journal.dto';
|
import { CreateJournalDto } from './dto/create-journal.dto';
|
||||||
import { UsersService } from 'src/users/users.service';
|
import { UsersService } from 'src/users/users.service';
|
||||||
|
@ -25,6 +36,7 @@ import {ProductHistoryPrice} from '../product/entities/product-history-price.ent
|
||||||
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';
|
import { CallbackPartner } from './entities/callback-partner.entity';
|
||||||
|
import { doAuthorizeHemat } from '../helper/sihemat-authorization';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionService {
|
export class TransactionService {
|
||||||
|
@ -165,7 +177,9 @@ export class TransactionService {
|
||||||
currentUser.userId,
|
currentUser.userId,
|
||||||
coaType.ACCOUNT_RECEIVABLE,
|
coaType.ACCOUNT_RECEIVABLE,
|
||||||
);
|
);
|
||||||
console.log('coamsk1', 'coa')
|
|
||||||
|
console.log('coamsk1', 'coa');
|
||||||
|
|
||||||
const coaWallet = await this.coaService.findByUser(
|
const coaWallet = await this.coaService.findByUser(
|
||||||
distributeTransactionDto.destination,
|
distributeTransactionDto.destination,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
|
@ -227,7 +241,8 @@ export class TransactionService {
|
||||||
);
|
);
|
||||||
|
|
||||||
// GET COA
|
// GET COA
|
||||||
console.log('coamsk2', 'coa')
|
console.log('coamsk2', 'coa');
|
||||||
|
|
||||||
const coaSenderWallet = await this.coaService.findByUser(
|
const coaSenderWallet = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
|
@ -239,7 +254,8 @@ export class TransactionService {
|
||||||
coaType.ACCOUNT_PAYABLE,
|
coaType.ACCOUNT_PAYABLE,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('coamsk3', 'coa')
|
console.log('coamsk3', 'coa');
|
||||||
|
|
||||||
const coaReceiverWallet = await this.coaService.findByUser(
|
const coaReceiverWallet = await this.coaService.findByUser(
|
||||||
distributeTransactionDto.destination,
|
distributeTransactionDto.destination,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
|
@ -307,10 +323,10 @@ export class TransactionService {
|
||||||
orderTransactionDto: OrderTransactionDto,
|
orderTransactionDto: OrderTransactionDto,
|
||||||
currentUser: any,
|
currentUser: any,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const productData = await this.productService.findOne(
|
const productData = await this.productService.findOne(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
'prepaid',
|
'prepaid',
|
||||||
|
orderTransactionDto.productId
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (!productData.statusHistory.status.includes('ACTIVE')) {
|
// if (!productData.statusHistory.status.includes('ACTIVE')) {
|
||||||
|
@ -341,7 +357,7 @@ export class TransactionService {
|
||||||
const product = await this.productService.findOneActive(
|
const product = await this.productService.findOneActive(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
'prepaid',
|
'prepaid',
|
||||||
orderTransactionDto.productId
|
orderTransactionDto.productId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const product_price = await this.productHistoryPriceService.findOne(
|
const product_price = await this.productHistoryPriceService.findOne(
|
||||||
|
@ -353,7 +369,8 @@ export class TransactionService {
|
||||||
let profit = product_price.mark_up_price;
|
let profit = product_price.mark_up_price;
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
console.log('coamsk4', 'coa')
|
console.log('coamsk4', 'coa');
|
||||||
|
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
|
@ -468,10 +485,10 @@ export class TransactionService {
|
||||||
orderTransactionDto: OrderTransactionDto,
|
orderTransactionDto: OrderTransactionDto,
|
||||||
currentUser: any,
|
currentUser: any,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const productData = await this.productService.findOne(
|
const productData = await this.productService.findOne(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
'prepaid',
|
'prepaid',
|
||||||
|
orderTransactionDto.productId
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (!productData.statusHistory.status.includes('ACTIVE')) {
|
// if (!productData.statusHistory.status.includes('ACTIVE')) {
|
||||||
|
@ -496,21 +513,23 @@ export class TransactionService {
|
||||||
const product = await this.productService.findOneActive(
|
const product = await this.productService.findOneActive(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
'prepaid',
|
'prepaid',
|
||||||
orderTransactionDto.productId
|
orderTransactionDto.productId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const supplier = await this.supplierService.findByCode(
|
const supplier = await this.supplierService.findByCode(
|
||||||
product.supplier.code,
|
product.supplier.code,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('userdatapartnerid', userData.partner?.id)
|
console.log('userdatapartnerid', userData.partner?.id);
|
||||||
|
|
||||||
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
|
||||||
console.log('coamsk5', product_price.id)
|
console.log('coamsk5', product_price.id);
|
||||||
|
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
|
@ -532,9 +551,10 @@ export class TransactionService {
|
||||||
try {
|
try {
|
||||||
const billId = await this.checkBillHistoryRepository.findOneOrFail({
|
const billId = await this.checkBillHistoryRepository.findOneOrFail({
|
||||||
where: {
|
where: {
|
||||||
trx_id: orderTransactionDto.bill_trx_id
|
trx_id: orderTransactionDto.bill_trx_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
product_price.price = billId.amount;
|
product_price.price = billId.amount;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
@ -569,11 +589,18 @@ export class TransactionService {
|
||||||
})
|
})
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
|
const hitLoginHemat =
|
||||||
|
supplier.code == 'Hemat' ?
|
||||||
|
await doAuthorizeHemat('wndpt001', '3NHESIJ5', supplier) :
|
||||||
|
'';
|
||||||
|
|
||||||
let hitSupplier = await doTransaction(
|
let hitSupplier = await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
trxId,
|
trxId,
|
||||||
supplier,
|
supplier,
|
||||||
|
hitLoginHemat.data,
|
||||||
|
product.type == 'prepaid' ? 'PURCHASE' : 'PAYMENT',
|
||||||
);
|
);
|
||||||
// let hitSupplier;
|
// let hitSupplier;
|
||||||
|
|
||||||
|
@ -586,7 +613,9 @@ export class TransactionService {
|
||||||
),
|
),
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -605,10 +634,11 @@ export class TransactionService {
|
||||||
|
|
||||||
if (hitSupplier.harga != undefined) {
|
if (hitSupplier.harga != undefined) {
|
||||||
if (hitSupplier.harga != product_price.price) {
|
if (hitSupplier.harga != product_price.price) {
|
||||||
console.log("priceupdate1supplier", hitSupplier.harga)
|
console.log('priceupdate1supplier', hitSupplier.harga);
|
||||||
console.log("priceupdate1normal", product_price.price)
|
console.log('priceupdate1normal', product_price.price);
|
||||||
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,
|
||||||
|
@ -632,6 +662,7 @@ export class TransactionService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//TRANSACTION DATA
|
//TRANSACTION DATA
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
|
@ -647,7 +678,8 @@ export class TransactionService {
|
||||||
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
transactionData.partner_trx_id = orderTransactionDto.trx_id;
|
||||||
transactionData.supplier_trx_id = trxId;
|
transactionData.supplier_trx_id = trxId;
|
||||||
transactionData.check_bill = orderTransactionDto.bill_trx_id;
|
transactionData.check_bill = orderTransactionDto.bill_trx_id;
|
||||||
transactionData.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
|
transactionData.balance_remaining =
|
||||||
|
coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||||
|
|
||||||
if (!hitSupplier.success) {
|
if (!hitSupplier.success) {
|
||||||
transactionData.status = statusTransaction.FAILED;
|
transactionData.status = statusTransaction.FAILED;
|
||||||
|
@ -722,19 +754,21 @@ export class TransactionService {
|
||||||
const product = await this.productService.findOne(
|
const product = await this.productService.findOne(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
'postpaid',
|
'postpaid',
|
||||||
|
orderTransactionDto.productId
|
||||||
);
|
);
|
||||||
|
|
||||||
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(
|
const product_price = await this.productHistoryPriceService.findOne(
|
||||||
product.id,
|
product.id,
|
||||||
userData.partner?.id,
|
userData.partner?.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
console.log('coamsk6', 'coa')
|
console.log('coamsk6', 'coa');
|
||||||
|
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
|
@ -770,15 +804,23 @@ export class TransactionService {
|
||||||
})
|
})
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
|
const hitLoginHemat =
|
||||||
|
supplier.code == 'Hemat' ?
|
||||||
|
await doAuthorizeHemat('wndpt001', '3NHESIJ5', supplier) :
|
||||||
|
'';
|
||||||
|
|
||||||
let hitSupplier = await doTransaction(
|
let hitSupplier = await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
trxId,
|
trxId,
|
||||||
supplier,
|
supplier,
|
||||||
|
hitLoginHemat.data,
|
||||||
|
product
|
||||||
);
|
);
|
||||||
|
|
||||||
if (supplier.code != 'IRS') {
|
if (supplier.code != 'IRS') {
|
||||||
const parsingResponse = hitSupplier.split(' ');
|
const parsingResponse = hitSupplier.split(' ');
|
||||||
|
|
||||||
hitSupplier = {
|
hitSupplier = {
|
||||||
success: hitSupplier.includes('diproses'),
|
success: hitSupplier.includes('diproses'),
|
||||||
harga: parseInt(
|
harga: parseInt(
|
||||||
|
@ -886,13 +928,14 @@ export class TransactionService {
|
||||||
const product = await this.productService.findOne(
|
const product = await this.productService.findOne(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
'postpaid',
|
'postpaid',
|
||||||
|
orderTransactionDto.productId
|
||||||
);
|
);
|
||||||
|
|
||||||
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(
|
const product_price = await this.productHistoryPriceService.findOne(
|
||||||
product.id,
|
product.id,
|
||||||
userData.partner?.id,
|
userData.partner?.id,
|
||||||
);
|
);
|
||||||
|
@ -907,13 +950,21 @@ export class TransactionService {
|
||||||
let status;
|
let status;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const hitLoginHemat =
|
||||||
|
supplier.code == 'Hemat' ?
|
||||||
|
await doAuthorizeHemat('wndpt001', '3NHESIJ5', supplier) :
|
||||||
|
'';
|
||||||
|
|
||||||
let hitSupplier = await doTransaction(
|
let hitSupplier = await doTransaction(
|
||||||
'CEK' + orderTransactionDto.productCode.slice(3),
|
`CEK${orderTransactionDto.productCode.slice(3)}`,
|
||||||
orderTransactionDto.destination,
|
orderTransactionDto.destination,
|
||||||
trxId,
|
trxId,
|
||||||
supplier,
|
supplier,
|
||||||
|
hitLoginHemat.data,
|
||||||
|
'INQUIRY'
|
||||||
);
|
);
|
||||||
const parsingResponse = hitSupplier.split(' ');
|
const parsingResponse = hitSupplier.split(' ');
|
||||||
|
|
||||||
hitSupplier = {
|
hitSupplier = {
|
||||||
success: hitSupplier.includes('diproses'),
|
success: hitSupplier.includes('diproses'),
|
||||||
msg: hitSupplier,
|
msg: hitSupplier,
|
||||||
|
@ -1077,9 +1128,9 @@ export class TransactionService {
|
||||||
try {
|
try {
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
transactionData.status =
|
transactionData.status =
|
||||||
statusApproval === 'Accept'
|
statusApproval === 'Accept' ?
|
||||||
? statusTransaction.APPROVED
|
statusTransaction.APPROVED :
|
||||||
: statusTransaction.REJECTED;
|
statusTransaction.REJECTED;
|
||||||
await manager.save(transactionData);
|
await manager.save(transactionData);
|
||||||
|
|
||||||
await this.accountingTransaction({
|
await this.accountingTransaction({
|
||||||
|
@ -1109,9 +1160,8 @@ export class TransactionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkCallbackOrderFailed(supplier_trx_id: string, callback: any) {
|
async checkCallbackOrderFailed(supplier_trx_id: string, callback: any) {
|
||||||
|
|
||||||
const transactionData = await this.findDataTransactionBySupplierTrxId(
|
const transactionData = await this.findDataTransactionBySupplierTrxId(
|
||||||
supplier_trx_id
|
supplier_trx_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (transactionData.status == statusTransaction.FAILED) {
|
if (transactionData.status == statusTransaction.FAILED) {
|
||||||
|
@ -1144,15 +1194,12 @@ export class TransactionService {
|
||||||
},
|
},
|
||||||
HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkCallbackOrderSuccess(supplier_trx_id: string, callback: any) {
|
async checkCallbackOrderSuccess(supplier_trx_id: string, callback: any) {
|
||||||
|
|
||||||
const transactionData = await this.findDataTransactionBySupplierTrxId(
|
const transactionData = await this.findDataTransactionBySupplierTrxId(
|
||||||
supplier_trx_id
|
supplier_trx_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (transactionData.status == statusTransaction.FAILED) {
|
if (transactionData.status == statusTransaction.FAILED) {
|
||||||
|
@ -1172,9 +1219,7 @@ 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,
|
||||||
);
|
);
|
||||||
|
@ -1187,9 +1232,7 @@ export class TransactionService {
|
||||||
},
|
},
|
||||||
HttpStatus.OK,
|
HttpStatus.OK,
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async findDataTransactionBySupplierTrxId(supplier_trx_id: string) {
|
async findDataTransactionBySupplierTrxId(supplier_trx_id: string) {
|
||||||
|
@ -1242,19 +1285,21 @@ export class TransactionService {
|
||||||
product_price.product.id,
|
product_price.product.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("inipricetable", dataTransaction.product_price.price)
|
console.log('inipricetable', dataTransaction.product_price.price);
|
||||||
console.log("inipricecallback", callback['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")
|
console.log('mskupdt', 'msk');
|
||||||
dataTransaction.product_price.price = parseInt(callback['price'])
|
dataTransaction.product_price.price = parseInt(callback['price']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//GET COA
|
//GET COA
|
||||||
console.log('coamsk7', 'coa')
|
console.log('coamsk7', 'coa');
|
||||||
|
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
|
@ -1263,7 +1308,8 @@ export class TransactionService {
|
||||||
dataTransaction.status = statusTransaction.FAILED;
|
dataTransaction.status = statusTransaction.FAILED;
|
||||||
dataTransaction.callback_json = callback;
|
dataTransaction.callback_json = callback;
|
||||||
dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
dataTransaction.failed_reason = `Trx ${product.code} ke ${dataTransaction.destination} gagal`;
|
||||||
dataTransaction.balance_remaining = coaAccount.amount + dataTransaction.amount;
|
dataTransaction.balance_remaining =
|
||||||
|
coaAccount.amount + dataTransaction.amount;
|
||||||
|
|
||||||
const coaInventory = await this.coaService.findByName(
|
const coaInventory = await this.coaService.findByName(
|
||||||
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
`${coaType[coaType.INVENTORY]}-${product.supplier.code}`,
|
||||||
|
@ -1313,6 +1359,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.partner.id,
|
userData.partner.id,
|
||||||
message,
|
message,
|
||||||
|
@ -1341,25 +1388,28 @@ export class TransactionService {
|
||||||
});
|
});
|
||||||
|
|
||||||
dataTransaction.status = statusTransaction.SUCCESS;
|
dataTransaction.status = statusTransaction.SUCCESS;
|
||||||
|
|
||||||
if (callback['sn']) {
|
if (callback['sn']) {
|
||||||
dataTransaction.seri_number = callback['sn'];
|
dataTransaction.seri_number = callback['sn'];
|
||||||
console.log("msksn1", dataTransaction.seri_number)
|
console.log('msksn1', dataTransaction.seri_number);
|
||||||
} else {
|
} else {
|
||||||
const response = callback['message'];
|
const response = callback['message'];
|
||||||
const responseBaru = response.split(' ');
|
const responseBaru = response.split(' ');
|
||||||
|
|
||||||
dataTransaction.seri_number =
|
dataTransaction.seri_number =
|
||||||
responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9];
|
responseBaru[10].length > 1 ? responseBaru[10] : responseBaru[9];
|
||||||
|
|
||||||
if (dataTransaction.seri_number == 'SN:') {
|
if (dataTransaction.seri_number == 'SN:') {
|
||||||
dataTransaction.seri_number = responseBaru[11]
|
dataTransaction.seri_number = responseBaru[11];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dataTransaction.callback_json = callback;
|
dataTransaction.callback_json = callback;
|
||||||
|
|
||||||
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) {
|
||||||
dataProductHistoryPrice.price = parseInt(callback['price'])
|
dataProductHistoryPrice.price = parseInt(callback['price']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1386,7 +1436,7 @@ export class TransactionService {
|
||||||
// dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
|
// dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory;
|
||||||
|
|
||||||
if (userData.partner == null) {
|
if (userData.partner == null) {
|
||||||
console.log('partnernull', 'masuk')
|
console.log('partnernull', 'masuk');
|
||||||
//GET SALES
|
//GET SALES
|
||||||
supervisorData = await this.calculateCommission(
|
supervisorData = await this.calculateCommission(
|
||||||
supervisorData,
|
supervisorData,
|
||||||
|
@ -1412,7 +1462,7 @@ export class TransactionService {
|
||||||
try {
|
try {
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
await manager.save(dataTransaction);
|
await manager.save(dataTransaction);
|
||||||
await manager.save(dataProductHistoryPrice)
|
await manager.save(dataProductHistoryPrice);
|
||||||
|
|
||||||
await this.accountingTransaction({
|
await this.accountingTransaction({
|
||||||
createTransaction: false,
|
createTransaction: false,
|
||||||
|
@ -1425,10 +1475,13 @@ export class TransactionService {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userData.partner != null) {
|
if (userData.partner != null) {
|
||||||
if (userData.partner) {
|
if (userData.partner) {
|
||||||
console.log('partnernotnull', 'masuk')
|
console.log('partnernotnull', 'masuk');
|
||||||
|
|
||||||
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.partner.id,
|
userData.partner.id,
|
||||||
message,
|
message,
|
||||||
|
@ -1463,6 +1516,7 @@ export class TransactionService {
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
|
const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`;
|
||||||
|
|
||||||
await this.callbackToPartner(
|
await this.callbackToPartner(
|
||||||
userData.partner.id,
|
userData.partner.id,
|
||||||
message,
|
message,
|
||||||
|
@ -1475,6 +1529,7 @@ export class TransactionService {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
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.partner.id,
|
userData.partner.id,
|
||||||
message,
|
message,
|
||||||
|
@ -1486,8 +1541,6 @@ export class TransactionService {
|
||||||
'gagal',
|
'gagal',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async callbackToPartner(
|
async callbackToPartner(
|
||||||
|
@ -1503,7 +1556,8 @@ export class TransactionService {
|
||||||
const partnerData = await this.userService.findPartner(partnerId);
|
const partnerData = await this.userService.findPartner(partnerId);
|
||||||
const userData = await this.userService.findOneByPartner(partnerId);
|
const userData = await this.userService.findOneByPartner(partnerId);
|
||||||
|
|
||||||
console.log('coamsk8', 'coa')
|
console.log('coamsk8', 'coa');
|
||||||
|
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
userData.id,
|
userData.id,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
|
@ -1511,6 +1565,7 @@ export class TransactionService {
|
||||||
|
|
||||||
if (!partnerData.callback_url) {
|
if (!partnerData.callback_url) {
|
||||||
this.logger.error(`Call to partner failed, reason: no callback url`);
|
this.logger.error(`Call to partner failed, reason: no callback url`);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1527,6 +1582,7 @@ export class TransactionService {
|
||||||
return res;
|
return res;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`Call to partner failed, reason: ${e.message}`);
|
this.logger.error(`Call to partner failed, reason: ${e.message}`);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1540,7 +1596,7 @@ export class TransactionService {
|
||||||
// });
|
// });
|
||||||
|
|
||||||
if (trxId.length % 2 != 0) {
|
if (trxId.length % 2 != 0) {
|
||||||
throw Error("Not Balance")
|
throw Error('Not Balance');
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataTransactionJurnal = await this.transactionJournalRepository.find({
|
const dataTransactionJurnal = await this.transactionJournalRepository.find({
|
||||||
|
@ -1550,10 +1606,10 @@ export class TransactionService {
|
||||||
relations: ['coa'],
|
relations: ['coa'],
|
||||||
});
|
});
|
||||||
|
|
||||||
let dataRollbackJurnal = [];
|
const dataRollbackJurnal = [];
|
||||||
|
|
||||||
dataTransactionJurnal.map((it) => {
|
dataTransactionJurnal.map((it) => {
|
||||||
let data = {
|
const data = {
|
||||||
coa_id: it.coa.id,
|
coa_id: it.coa.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1586,7 +1642,8 @@ export class TransactionService {
|
||||||
async withdrawBenefit(user) {
|
async withdrawBenefit(user) {
|
||||||
const userData = await this.userService.findExist(user);
|
const userData = await this.userService.findExist(user);
|
||||||
|
|
||||||
console.log('coamsk9', 'coa')
|
console.log('coamsk9', 'coa');
|
||||||
|
|
||||||
const coaProfit = await this.coaService.findByUser(user, coaType.PROFIT);
|
const coaProfit = await this.coaService.findByUser(user, coaType.PROFIT);
|
||||||
|
|
||||||
const coaBank = await this.coaService.findByName(
|
const coaBank = await this.coaService.findByName(
|
||||||
|
@ -1762,7 +1819,7 @@ export class TransactionService {
|
||||||
take: pageSize || 10,
|
take: pageSize || 10,
|
||||||
order: {
|
order: {
|
||||||
createdAt: 'DESC',
|
createdAt: 'DESC',
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
|
@ -2062,7 +2119,8 @@ export class TransactionService {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('coamsk10', 'coa')
|
console.log('coamsk10', 'coa');
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
supervisorData.map(async (it) => {
|
supervisorData.map(async (it) => {
|
||||||
const coaAccount = await this.coaService.findByUser(
|
const coaAccount = await this.coaService.findByUser(
|
||||||
|
@ -2129,9 +2187,9 @@ export class TransactionService {
|
||||||
const journalEntry = new TransactionJournal();
|
const journalEntry = new TransactionJournal();
|
||||||
|
|
||||||
journalEntry.coa = coa;
|
journalEntry.coa = coa;
|
||||||
journalEntry.type = journal.debit
|
journalEntry.type = journal.debit ?
|
||||||
? balanceType.DEBIT
|
balanceType.DEBIT :
|
||||||
: balanceType.CREDIT;
|
balanceType.CREDIT;
|
||||||
journalEntry.amount = journal.debit ? journal.debit : journal.credit;
|
journalEntry.amount = journal.debit ? journal.debit : journal.credit;
|
||||||
journalEntry.transaction_head = transaction;
|
journalEntry.transaction_head = transaction;
|
||||||
|
|
||||||
|
@ -2204,7 +2262,9 @@ export class TransactionService {
|
||||||
message: string,
|
message: string,
|
||||||
) {
|
) {
|
||||||
const billData = await this.findOneBillById(trxId);
|
const billData = await this.findOneBillById(trxId);
|
||||||
console.log(billData,"ini dia")
|
|
||||||
|
console.log(billData, 'ini dia');
|
||||||
|
|
||||||
const userData = await this.userService.findExist(billData.user);
|
const userData = await this.userService.findExist(billData.user);
|
||||||
|
|
||||||
const product_price = await this.productHistoryPriceService.findById(
|
const product_price = await this.productHistoryPriceService.findById(
|
||||||
|
@ -2216,12 +2276,12 @@ export class TransactionService {
|
||||||
trx_id: trxId,
|
trx_id: trxId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
amount: status
|
amount: status ?
|
||||||
? amount -
|
amount -
|
||||||
admin +
|
admin +
|
||||||
product_price.partner_fee +
|
product_price.partner_fee +
|
||||||
product_price.mark_up_price
|
product_price.mark_up_price :
|
||||||
: 0,
|
0,
|
||||||
admin_price: admin,
|
admin_price: admin,
|
||||||
status: status ? 'SUCCESS' : 'FAILED',
|
status: status ? 'SUCCESS' : 'FAILED',
|
||||||
callback_json: JSON.stringify(message),
|
callback_json: JSON.stringify(message),
|
||||||
|
@ -2229,12 +2289,13 @@ export class TransactionService {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (userData.partner) {
|
if (userData.partner) {
|
||||||
const message = status
|
const message = status ?
|
||||||
? `Bill dari ${billData.destination} adalah ${
|
`Bill dari ${billData.destination} adalah ${
|
||||||
amount + product_price.partner_fee + product_price.mark_up_price
|
amount + product_price.partner_fee + product_price.mark_up_price
|
||||||
}.`
|
}.` :
|
||||||
: '';
|
'';
|
||||||
const statusResponse = status ? 'berhasil' : 'gagal';
|
const statusResponse = status ? 'berhasil' : 'gagal';
|
||||||
|
|
||||||
this.callbackToPartner(
|
this.callbackToPartner(
|
||||||
userData.id,
|
userData.id,
|
||||||
message,
|
message,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user