Merge branch 'master' of https://gitlab.com/empatnusabangsa/ppob/ppob-backend into devops-production
This commit is contained in:
		| @@ -11,25 +11,49 @@ export const doTransaction = async ( | ||||
|     destination, | ||||
|     idtrx, | ||||
|     supplier, | ||||
|     authorization, | ||||
|     typePaid, | ||||
| ) => { | ||||
|   try { | ||||
|     if(supplier.code == 'IRS'){ | ||||
|     if (supplier.code == 'IRS') { | ||||
|       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}`, | ||||
|       ); | ||||
|  | ||||
|       return res.data; | ||||
|     } else if (supplier.code == 'NIRS') { | ||||
|       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}`, | ||||
|       ); | ||||
|  | ||||
|       return res.data; | ||||
|     } else { | ||||
|     } else if (supplier.code == 'Hemat') { | ||||
|       if (authorization != "") { | ||||
|         console.log("initoken", authorization) | ||||
|         const options = { | ||||
|           headers: {'Content-Type': 'application/json', | ||||
|             'Authorization': 'Bearer ' + authorization} | ||||
|         }; | ||||
|         const data = { | ||||
|           idtransaction: idtrx, | ||||
|           destination: `${destination}`, | ||||
|           code: `${productCode}`, | ||||
|           type: `${typePaid}`, | ||||
|         }; | ||||
|         const res = await axios.post(`${supplier.url}/v1/transaction/request`, data, options); | ||||
|  | ||||
|         return res.data; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     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}`, | ||||
|     ); | ||||
|  | ||||
|     return res.data; | ||||
|     } | ||||
|     console.log('restranshemat', res) | ||||
|   } catch (err) { | ||||
|     console.log('errtranshemat', err.response.data); | ||||
|     throw err; | ||||
|   } | ||||
| }; | ||||
|   | ||||
							
								
								
									
										16
									
								
								src/helper/sihemat-authorization.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/helper/sihemat-authorization.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| 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}/authenticate`, data); | ||||
|  | ||||
|         return res.data; | ||||
|     } catch (err) { | ||||
|         console.log('errauthhemat', 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 { | ||||
|       return await this.productRepository.findOneOrFail({ | ||||
|         relations: ['supplier'], | ||||
|         where: { | ||||
|           code: code, | ||||
|           id: productId | ||||
|         }, | ||||
|       }); | ||||
|     } catch (e) { | ||||
| @@ -635,16 +636,16 @@ export class ProductService { | ||||
|       code: string, | ||||
|       updatePriceProductDto: UpdatePriceProductDto, | ||||
|   ) { | ||||
|     const product = await this.findOne(code, updatePriceProductDto.productType); | ||||
|     // const product = await this.findOne(code, updatePriceProductDto.productType); | ||||
|  | ||||
|     await this.productHistoryPrice.insert({ | ||||
|       product: product, | ||||
|       type: updatePriceProductDto.type, | ||||
|       price: updatePriceProductDto.price, | ||||
|       mark_up_price: updatePriceProductDto.markUpPrice, | ||||
|       startDate: updatePriceProductDto.startDate, | ||||
|       endDate: updatePriceProductDto.endDate, | ||||
|     }); | ||||
|     // await this.productHistoryPrice.insert({ | ||||
|     //   product: product, | ||||
|     //   type: updatePriceProductDto.type, | ||||
|     //   price: updatePriceProductDto.price, | ||||
|     //   mark_up_price: updatePriceProductDto.markUpPrice, | ||||
|     //   startDate: updatePriceProductDto.startDate, | ||||
|     //   endDate: updatePriceProductDto.endDate, | ||||
|     // }); | ||||
|  | ||||
|     return true; | ||||
|   } | ||||
|   | ||||
| @@ -1,30 +1,42 @@ | ||||
| import {HttpException, HttpStatus, Injectable, Logger} from '@nestjs/common'; | ||||
| import {DistributeTransactionDto} from './dto/distribute-transaction.dto'; | ||||
| import {OrderTransactionDto} from './dto/order-transaction.dto'; | ||||
| import {InjectRepository} from '@nestjs/typeorm'; | ||||
| import {Transactions} from './entities/transactions.entity'; | ||||
| import {Between, Connection, EntityNotFoundError, In, Repository} from 'typeorm'; | ||||
| import {COA} from './entities/coa.entity'; | ||||
| import {TransactionJournal} from './entities/transaction-journal.entity'; | ||||
| import {CoaService} from './coa.service'; | ||||
| import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'; | ||||
| import { DistributeTransactionDto } from './dto/distribute-transaction.dto'; | ||||
| import { OrderTransactionDto } from './dto/order-transaction.dto'; | ||||
| import { InjectRepository } from '@nestjs/typeorm'; | ||||
| import { Transactions } from './entities/transactions.entity'; | ||||
| import { | ||||
|   Between, | ||||
|   Connection, | ||||
|   EntityNotFoundError, | ||||
|   In, | ||||
|   Repository, | ||||
| } from 'typeorm'; | ||||
| import { COA } from './entities/coa.entity'; | ||||
| import { TransactionJournal } from './entities/transaction-journal.entity'; | ||||
| import { CoaService } from './coa.service'; | ||||
| import * as uuid from 'uuid'; | ||||
| import {uniq} from 'lodash'; | ||||
| import {Decimal} from 'decimal.js'; | ||||
| import {balanceType, coaType, statusTransaction, typeTransaction,} from '../helper/enum-list'; | ||||
| import {ProductService} from '../product/product.service'; | ||||
| import {CreateJournalDto} from './dto/create-journal.dto'; | ||||
| import {UsersService} from 'src/users/users.service'; | ||||
| import {AddSaldoSupplier} from './dto/add-saldo-supplier.dto'; | ||||
| import {SupplierService} from '../users/supplier/supplier.service'; | ||||
| import {ProductHistoryPriceService} from '../product/history-price/history-price.service'; | ||||
| import {CommissionService} from '../configurable/commission.service'; | ||||
| import {DepositReturnDto} from './dto/deposit_return.dto'; | ||||
| import {UserDetail} from '../users/entities/user_detail.entity'; | ||||
| import {doTransaction} from '../helper/irs-api'; | ||||
| import {ProductHistoryPrice} from '../product/entities/product-history-price.entity'; | ||||
| import { uniq } from 'lodash'; | ||||
| import { Decimal } from 'decimal.js'; | ||||
| import { | ||||
|   balanceType, | ||||
|   coaType, | ||||
|   statusTransaction, | ||||
|   typeTransaction, | ||||
| } from '../helper/enum-list'; | ||||
| import { ProductService } from '../product/product.service'; | ||||
| import { CreateJournalDto } from './dto/create-journal.dto'; | ||||
| import { UsersService } from 'src/users/users.service'; | ||||
| import { AddSaldoSupplier } from './dto/add-saldo-supplier.dto'; | ||||
| import { SupplierService } from '../users/supplier/supplier.service'; | ||||
| import { ProductHistoryPriceService } from '../product/history-price/history-price.service'; | ||||
| import { CommissionService } from '../configurable/commission.service'; | ||||
| import { DepositReturnDto } from './dto/deposit_return.dto'; | ||||
| import { UserDetail } from '../users/entities/user_detail.entity'; | ||||
| import { doTransaction } from '../helper/irs-api'; | ||||
| import { ProductHistoryPrice } from '../product/entities/product-history-price.entity'; | ||||
| import axios from 'axios'; | ||||
| import {CheckBillHistory} from './entities/check-bill-history.entity'; | ||||
| import {CallbackPartner} from './entities/callback-partner.entity'; | ||||
| import { CheckBillHistory } from './entities/check-bill-history.entity'; | ||||
| import { CallbackPartner } from './entities/callback-partner.entity'; | ||||
| import { doAuthorizeHemat } from '../helper/sihemat-authorization'; | ||||
|  | ||||
| @Injectable() | ||||
| export class TransactionService { | ||||
| @@ -165,7 +177,9 @@ export class TransactionService { | ||||
|           currentUser.userId, | ||||
|           coaType.ACCOUNT_RECEIVABLE, | ||||
|       ); | ||||
|       console.log('coamsk1', 'coa') | ||||
|  | ||||
|       console.log('coamsk1', 'coa'); | ||||
|  | ||||
|       const coaWallet = await this.coaService.findByUser( | ||||
|           distributeTransactionDto.destination, | ||||
|           coaType.WALLET, | ||||
| @@ -227,7 +241,8 @@ export class TransactionService { | ||||
|     ); | ||||
|  | ||||
|     // GET COA | ||||
|     console.log('coamsk2', 'coa') | ||||
|     console.log('coamsk2', 'coa'); | ||||
|  | ||||
|     const coaSenderWallet = await this.coaService.findByUser( | ||||
|         userData.id, | ||||
|         coaType.WALLET, | ||||
| @@ -239,7 +254,8 @@ export class TransactionService { | ||||
|         coaType.ACCOUNT_PAYABLE, | ||||
|     ); | ||||
|  | ||||
|     console.log('coamsk3', 'coa') | ||||
|     console.log('coamsk3', 'coa'); | ||||
|  | ||||
|     const coaReceiverWallet = await this.coaService.findByUser( | ||||
|         distributeTransactionDto.destination, | ||||
|         coaType.WALLET, | ||||
| @@ -307,10 +323,10 @@ export class TransactionService { | ||||
|       orderTransactionDto: OrderTransactionDto, | ||||
|       currentUser: any, | ||||
|   ) { | ||||
|  | ||||
|     const productData = await this.productService.findOne( | ||||
|         orderTransactionDto.productCode, | ||||
|         'prepaid', | ||||
|         orderTransactionDto.productId | ||||
|     ); | ||||
|  | ||||
|     // if (!productData.statusHistory.status.includes('ACTIVE')) { | ||||
| @@ -341,7 +357,7 @@ export class TransactionService { | ||||
|     const product = await this.productService.findOneActive( | ||||
|         orderTransactionDto.productCode, | ||||
|         'prepaid', | ||||
|         orderTransactionDto.productId | ||||
|         orderTransactionDto.productId, | ||||
|     ); | ||||
|  | ||||
|     const product_price = await this.productHistoryPriceService.findOne( | ||||
| @@ -353,7 +369,8 @@ export class TransactionService { | ||||
|     let profit = product_price.mark_up_price; | ||||
|  | ||||
|     //GET COA | ||||
|       console.log('coamsk4', 'coa') | ||||
|     console.log('coamsk4', 'coa'); | ||||
|  | ||||
|     const coaAccount = await this.coaService.findByUser( | ||||
|         userData.id, | ||||
|         coaType.WALLET, | ||||
| @@ -468,10 +485,10 @@ export class TransactionService { | ||||
|       orderTransactionDto: OrderTransactionDto, | ||||
|       currentUser: any, | ||||
|   ) { | ||||
|  | ||||
|     const productData = await this.productService.findOne( | ||||
|         orderTransactionDto.productCode, | ||||
|         'prepaid', | ||||
|         orderTransactionDto.productId | ||||
|     ); | ||||
|  | ||||
|     // if (!productData.statusHistory.status.includes('ACTIVE')) { | ||||
| @@ -496,21 +513,23 @@ export class TransactionService { | ||||
|     const product = await this.productService.findOneActive( | ||||
|         orderTransactionDto.productCode, | ||||
|         'prepaid', | ||||
|         orderTransactionDto.productId | ||||
|         orderTransactionDto.productId, | ||||
|     ); | ||||
|  | ||||
|     const supplier = await this.supplierService.findByCode( | ||||
|         product.supplier.code, | ||||
|     ); | ||||
|  | ||||
|     console.log('userdatapartnerid', userData.partner?.id) | ||||
|     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) | ||||
|     console.log('coamsk5', product_price.id); | ||||
|  | ||||
|     const coaAccount = await this.coaService.findByUser( | ||||
|         userData.id, | ||||
|         coaType.WALLET, | ||||
| @@ -532,9 +551,10 @@ export class TransactionService { | ||||
|       try { | ||||
|         const billId = await this.checkBillHistoryRepository.findOneOrFail({ | ||||
|           where: { | ||||
|             trx_id: orderTransactionDto.bill_trx_id | ||||
|             trx_id: orderTransactionDto.bill_trx_id, | ||||
|           }, | ||||
|         }); | ||||
|  | ||||
|         product_price.price = billId.amount; | ||||
|       } catch (e) { | ||||
|         if (e instanceof EntityNotFoundError) { | ||||
| @@ -569,16 +589,40 @@ export class TransactionService { | ||||
|         }) | ||||
|         .join(''); | ||||
|  | ||||
|     let hitSupplier = await doTransaction( | ||||
|     let hitLoginHemat; | ||||
|  | ||||
|     if (supplier.code == 'Hemat') { | ||||
|       hitLoginHemat =  await doAuthorizeHemat('wndpt001', '3NHESIJ5', supplier); | ||||
|     } | ||||
|  | ||||
|     let hitSupplier = supplier.code == 'Hemat' ? | ||||
|         await doTransaction( | ||||
|             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; | ||||
|  | ||||
|     if (supplier.code != 'IRS') { | ||||
|     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( | ||||
| @@ -586,11 +630,28 @@ export class TransactionService { | ||||
|         ), | ||||
|         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, | ||||
| @@ -605,10 +666,11 @@ export class TransactionService { | ||||
|  | ||||
|     if (hitSupplier.harga != undefined) { | ||||
|       if (hitSupplier.harga != product_price.price) { | ||||
|           console.log("priceupdate1supplier", hitSupplier.harga) | ||||
|           console.log("priceupdate1normal", 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, | ||||
| @@ -632,6 +694,7 @@ export class TransactionService { | ||||
|         }); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     try { | ||||
|       //TRANSACTION DATA | ||||
|       await this.connection.transaction(async (manager) => { | ||||
| @@ -647,7 +710,8 @@ 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; | ||||
|         transactionData.balance_remaining = | ||||
|             coaAccount.amount - product_price.mark_up_price - costInventory; | ||||
|  | ||||
|         if (!hitSupplier.success) { | ||||
|           transactionData.status = statusTransaction.FAILED; | ||||
| @@ -722,19 +786,21 @@ export class TransactionService { | ||||
|     const product = await this.productService.findOne( | ||||
|         orderTransactionDto.productCode, | ||||
|         'postpaid', | ||||
|         orderTransactionDto.productId | ||||
|     ); | ||||
|  | ||||
|     const supplier = await this.supplierService.findByCode( | ||||
|         product.supplier.code, | ||||
|     ); | ||||
|  | ||||
|     let product_price = await this.productHistoryPriceService.findOne( | ||||
|     const product_price = await this.productHistoryPriceService.findOne( | ||||
|         product.id, | ||||
|         userData.partner?.id, | ||||
|     ); | ||||
|  | ||||
|     //GET COA | ||||
|     console.log('coamsk6', 'coa') | ||||
|     console.log('coamsk6', 'coa'); | ||||
|  | ||||
|     const coaAccount = await this.coaService.findByUser( | ||||
|         userData.id, | ||||
|         coaType.WALLET, | ||||
| @@ -770,15 +836,32 @@ export class TransactionService { | ||||
|         }) | ||||
|         .join(''); | ||||
|  | ||||
|     let hitSupplier = await doTransaction( | ||||
|     let hitLoginHemat; | ||||
|  | ||||
|     if (supplier.code == 'Hemat') { | ||||
|       hitLoginHemat =  await doAuthorizeHemat('wndpt001', '3NHESIJ5', supplier); | ||||
|     } | ||||
|  | ||||
|     let hitSupplier = supplier.code == 'Hemat' ? | ||||
|         await doTransaction( | ||||
|             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', | ||||
|         ); | ||||
|  | ||||
|     if (supplier.code != 'IRS') { | ||||
|       const parsingResponse = hitSupplier.split(' '); | ||||
|  | ||||
|       hitSupplier = { | ||||
|         success: hitSupplier.includes('diproses'), | ||||
|         harga: parseInt( | ||||
| @@ -886,13 +969,14 @@ export class TransactionService { | ||||
|     const product = await this.productService.findOne( | ||||
|         orderTransactionDto.productCode, | ||||
|         'postpaid', | ||||
|         orderTransactionDto.productId | ||||
|     ); | ||||
|  | ||||
|     const supplier = await this.supplierService.findByCode( | ||||
|         product.supplier.code, | ||||
|     ); | ||||
|  | ||||
|     let product_price = await this.productHistoryPriceService.findOne( | ||||
|     const product_price = await this.productHistoryPriceService.findOne( | ||||
|         product.id, | ||||
|         userData.partner?.id, | ||||
|     ); | ||||
| @@ -907,18 +991,43 @@ export class TransactionService { | ||||
|     let status; | ||||
|  | ||||
|     try { | ||||
|       let hitSupplier = await doTransaction( | ||||
|         'CEK' + orderTransactionDto.productCode.slice(3), | ||||
|  | ||||
|       let hitLoginHemat; | ||||
|  | ||||
|       if (supplier.code == 'Hemat') { | ||||
|        hitLoginHemat =  await doAuthorizeHemat('wndpt001', '3NHESIJ5', supplier); | ||||
|       } | ||||
|  | ||||
|       let hitSupplier = supplier.code == 'Hemat' ? await doTransaction( | ||||
|           orderTransactionDto.productCode, | ||||
|           orderTransactionDto.destination, | ||||
|           trxId, | ||||
|           supplier, | ||||
|           hitLoginHemat.data, | ||||
|           'INQUIRY' | ||||
|       ) : await doTransaction( | ||||
|           `CEK${orderTransactionDto.productCode.slice(3)}`, | ||||
|           orderTransactionDto.destination, | ||||
|           trxId, | ||||
|           supplier, | ||||
|           "", | ||||
|           'INQUIRY' | ||||
|       ); | ||||
|       const parsingResponse = hitSupplier.split(' '); | ||||
|       // const parsingResponse = hitSupplier.split(' '); | ||||
|  | ||||
|       if (supplier.code == 'Hemat') { | ||||
|         hitSupplier = { | ||||
|           success: hitSupplier.success == true, | ||||
|           msg: hitSupplier.msg, | ||||
|         }; | ||||
|       } else { | ||||
|         hitSupplier = { | ||||
|           success: hitSupplier.includes('diproses'), | ||||
|           msg: hitSupplier, | ||||
|         }; | ||||
|  | ||||
|       } | ||||
|       console.log('inidatacheckbill', hitSupplier) | ||||
|       console.log('statushitsupplier', hitSupplier.success) | ||||
|       if (!hitSupplier.success) { | ||||
|         status = statusTransaction[statusTransaction.FAILED]; | ||||
|         throw new HttpException( | ||||
| @@ -1077,9 +1186,9 @@ export class TransactionService { | ||||
|     try { | ||||
|       await this.connection.transaction(async (manager) => { | ||||
|         transactionData.status = | ||||
|           statusApproval === 'Accept' | ||||
|             ? statusTransaction.APPROVED | ||||
|             : statusTransaction.REJECTED; | ||||
|             statusApproval === 'Accept' ? | ||||
|                 statusTransaction.APPROVED : | ||||
|                 statusTransaction.REJECTED; | ||||
|         await manager.save(transactionData); | ||||
|  | ||||
|         await this.accountingTransaction({ | ||||
| @@ -1109,28 +1218,29 @@ export class TransactionService { | ||||
|   } | ||||
|  | ||||
|   async checkCallbackOrderFailed(supplier_trx_id: string, callback: any) { | ||||
|  | ||||
|     const transactionData = await this.findDataTransactionBySupplierTrxId( | ||||
|       supplier_trx_id | ||||
|         supplier_trx_id, | ||||
|     ); | ||||
|  | ||||
|     if (transactionData.status == statusTransaction.FAILED) { | ||||
|       throw new HttpException( | ||||
|           { | ||||
|             statusCode: HttpStatus.BAD_REQUEST, | ||||
|             error: 'failed to update, the transaction already failed', | ||||
|           }, | ||||
|           HttpStatus.BAD_REQUEST, | ||||
|       ); | ||||
|     } else if (transactionData.status == statusTransaction.SUCCESS) { | ||||
|       throw new HttpException( | ||||
|           { | ||||
|             statusCode: HttpStatus.BAD_REQUEST, | ||||
|             error: 'failed to update, the transaction already success', | ||||
|           }, | ||||
|           HttpStatus.BAD_REQUEST, | ||||
|       ); | ||||
|     } else { | ||||
|     // if (transactionData.status == statusTransaction.FAILED) { | ||||
|     //   throw new HttpException( | ||||
|     //       { | ||||
|     //         statusCode: HttpStatus.BAD_REQUEST, | ||||
|     //         error: 'failed to update, the transaction already failed', | ||||
|     //       }, | ||||
|     //       HttpStatus.BAD_REQUEST, | ||||
|     //   ); | ||||
|     // } else if (transactionData.status == statusTransaction.SUCCESS) { | ||||
|     //   throw new HttpException( | ||||
|     //       { | ||||
|     //         statusCode: HttpStatus.BAD_REQUEST, | ||||
|     //         error: 'failed to update, the transaction already success', | ||||
|     //       }, | ||||
|     //       HttpStatus.BAD_REQUEST, | ||||
|     //   ); | ||||
|     // } else { | ||||
|  | ||||
|  | ||||
|       const updateTransaction = await this.callbackOrderFailed( | ||||
|           supplier_trx_id, | ||||
|           callback, | ||||
| @@ -1144,37 +1254,32 @@ export class TransactionService { | ||||
|           }, | ||||
|           HttpStatus.BAD_REQUEST, | ||||
|       ); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     // } | ||||
|   } | ||||
|  | ||||
|   async checkCallbackOrderSuccess(supplier_trx_id: string, callback: any) { | ||||
|  | ||||
|     const transactionData = await this.findDataTransactionBySupplierTrxId( | ||||
|         supplier_trx_id | ||||
|         supplier_trx_id, | ||||
|     ); | ||||
|  | ||||
|     if (transactionData.status == statusTransaction.FAILED) { | ||||
|       throw new HttpException( | ||||
|           { | ||||
|             statusCode: HttpStatus.BAD_REQUEST, | ||||
|             error: 'failed to update, the transaction already failed', | ||||
|           }, | ||||
|           HttpStatus.BAD_REQUEST, | ||||
|       ); | ||||
|     } else if (transactionData.status == statusTransaction.SUCCESS) { | ||||
|       throw new HttpException( | ||||
|           { | ||||
|             statusCode: HttpStatus.BAD_REQUEST, | ||||
|             error: 'failed to update, the transaction already success', | ||||
|           }, | ||||
|           HttpStatus.BAD_REQUEST, | ||||
|       ); | ||||
|     } else { | ||||
|  | ||||
|       const updateTransaction = | ||||
|           await this.callbackOrderSuccess( | ||||
|     // if (transactionData.status == statusTransaction.FAILED) { | ||||
|     //   throw new HttpException( | ||||
|     //       { | ||||
|     //         statusCode: HttpStatus.BAD_REQUEST, | ||||
|     //         error: 'failed to update, the transaction already failed', | ||||
|     //       }, | ||||
|     //       HttpStatus.BAD_REQUEST, | ||||
|     //   ); | ||||
|     // } else if (transactionData.status == statusTransaction.SUCCESS) { | ||||
|     //   throw new HttpException( | ||||
|     //       { | ||||
|     //         statusCode: HttpStatus.BAD_REQUEST, | ||||
|     //         error: 'failed to update, the transaction already success', | ||||
|     //       }, | ||||
|     //       HttpStatus.BAD_REQUEST, | ||||
|     //   ); | ||||
|     // } else { | ||||
|       const updateTransaction = await this.callbackOrderSuccess( | ||||
|           supplier_trx_id, | ||||
|           callback, | ||||
|       ); | ||||
| @@ -1187,9 +1292,7 @@ export class TransactionService { | ||||
|           }, | ||||
|           HttpStatus.OK, | ||||
|       ); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     // } | ||||
|   } | ||||
|  | ||||
|   async findDataTransactionBySupplierTrxId(supplier_trx_id: string) { | ||||
| @@ -1242,19 +1345,21 @@ export class TransactionService { | ||||
|         product_price.product.id, | ||||
|     ); | ||||
|  | ||||
|     console.log("inipricetable", dataTransaction.product_price.price) | ||||
|     console.log("inipricecallback", callback['price']) | ||||
|     if(callback['message']) { | ||||
|     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) { | ||||
|           console.log("mskupdt", "msk") | ||||
|           dataTransaction.product_price.price = parseInt(callback['price']) | ||||
|           console.log('mskupdt', 'msk'); | ||||
|           dataTransaction.product_price.price = parseInt(callback['price']); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     //GET COA | ||||
|     console.log('coamsk7', 'coa') | ||||
|     console.log('coamsk7', 'coa'); | ||||
|  | ||||
|     const coaAccount = await this.coaService.findByUser( | ||||
|         userData.id, | ||||
|         coaType.WALLET, | ||||
| @@ -1263,7 +1368,8 @@ export class TransactionService { | ||||
|     dataTransaction.status = statusTransaction.FAILED; | ||||
|     dataTransaction.callback_json = callback; | ||||
|     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( | ||||
|         `${coaType[coaType.INVENTORY]}-${product.supplier.code}`, | ||||
| @@ -1313,6 +1419,7 @@ export class TransactionService { | ||||
|  | ||||
|     if (userData.partner) { | ||||
|       const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`; | ||||
|  | ||||
|       this.callbackToPartner( | ||||
|           userData.partner.id, | ||||
|           message, | ||||
| @@ -1341,25 +1448,28 @@ export class TransactionService { | ||||
|     }); | ||||
|  | ||||
|     dataTransaction.status = statusTransaction.SUCCESS; | ||||
|  | ||||
|     if (callback['sn']) { | ||||
|       dataTransaction.seri_number = callback['sn']; | ||||
|       console.log("msksn1", dataTransaction.seri_number) | ||||
|       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.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']) | ||||
|           dataProductHistoryPrice.price = parseInt(callback['price']); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
| @@ -1386,7 +1496,7 @@ export class TransactionService { | ||||
|     // dataTransaction.balance_remaining = coaAccount.amount - product_price.mark_up_price - costInventory; | ||||
|  | ||||
|     if (userData.partner == null) { | ||||
|       console.log('partnernull', 'masuk') | ||||
|       console.log('partnernull', 'masuk'); | ||||
|       //GET SALES | ||||
|       supervisorData = await this.calculateCommission( | ||||
|           supervisorData, | ||||
| @@ -1412,7 +1522,7 @@ export class TransactionService { | ||||
|     try { | ||||
|       await this.connection.transaction(async (manager) => { | ||||
|         await manager.save(dataTransaction); | ||||
|         await manager.save(dataProductHistoryPrice) | ||||
|         await manager.save(dataProductHistoryPrice); | ||||
|  | ||||
|         await this.accountingTransaction({ | ||||
|           createTransaction: false, | ||||
| @@ -1425,10 +1535,13 @@ export class TransactionService { | ||||
|     } catch (e) { | ||||
|       throw e; | ||||
|     } | ||||
|  | ||||
|     if (userData.partner != null) { | ||||
|       if (userData.partner) { | ||||
|       console.log('partnernotnull', 'masuk') | ||||
|         console.log('partnernotnull', 'masuk'); | ||||
|  | ||||
|         const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`; | ||||
|  | ||||
|         this.callbackToPartner( | ||||
|             userData.partner.id, | ||||
|             message, | ||||
| @@ -1443,7 +1556,7 @@ export class TransactionService { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async resendOrderToPartner(supplier_trx_id: string, status: boolean){ | ||||
|   async resendOrderToPartner(supplier_trx_id: string, status: boolean) { | ||||
|     const dataTransaction = await this.transactionRepository.findOne({ | ||||
|       where: { | ||||
|         supplier_trx_id: supplier_trx_id, | ||||
| @@ -1463,6 +1576,7 @@ export class TransactionService { | ||||
|  | ||||
|     if (status) { | ||||
|       const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah berhasil.`; | ||||
|  | ||||
|       await this.callbackToPartner( | ||||
|           userData.partner.id, | ||||
|           message, | ||||
| @@ -1475,6 +1589,7 @@ export class TransactionService { | ||||
|       ); | ||||
|     } else { | ||||
|       const message = `Transaksi ${product.code} dengan tujuan ${dataTransaction.destination} telah gagal.`; | ||||
|  | ||||
|       this.callbackToPartner( | ||||
|           userData.partner.id, | ||||
|           message, | ||||
| @@ -1486,8 +1601,6 @@ export class TransactionService { | ||||
|           'gagal', | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|  | ||||
|   } | ||||
|  | ||||
|   async callbackToPartner( | ||||
| @@ -1503,7 +1616,8 @@ export class TransactionService { | ||||
|     const partnerData = await this.userService.findPartner(partnerId); | ||||
|     const userData = await this.userService.findOneByPartner(partnerId); | ||||
|  | ||||
|     console.log('coamsk8', 'coa') | ||||
|     console.log('coamsk8', 'coa'); | ||||
|  | ||||
|     const coaAccount = await this.coaService.findByUser( | ||||
|         userData.id, | ||||
|         coaType.WALLET, | ||||
| @@ -1511,6 +1625,7 @@ export class TransactionService { | ||||
|  | ||||
|     if (!partnerData.callback_url) { | ||||
|       this.logger.error(`Call to partner failed, reason: no callback url`); | ||||
|  | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
| @@ -1527,6 +1642,7 @@ export class TransactionService { | ||||
|       return res; | ||||
|     } catch (e) { | ||||
|       this.logger.error(`Call to partner failed, reason: ${e.message}`); | ||||
|  | ||||
|       return false; | ||||
|     } | ||||
|   } | ||||
| @@ -1540,7 +1656,7 @@ export class TransactionService { | ||||
|     // }); | ||||
|  | ||||
|     if (trxId.length % 2 != 0) { | ||||
|       throw Error("Not Balance") | ||||
|       throw Error('Not Balance'); | ||||
|     } | ||||
|  | ||||
|     const dataTransactionJurnal = await this.transactionJournalRepository.find({ | ||||
| @@ -1550,10 +1666,10 @@ export class TransactionService { | ||||
|       relations: ['coa'], | ||||
|     }); | ||||
|  | ||||
|     let dataRollbackJurnal = []; | ||||
|     const dataRollbackJurnal = []; | ||||
|  | ||||
|     dataTransactionJurnal.map((it) => { | ||||
|       let data = { | ||||
|       const data = { | ||||
|         coa_id: it.coa.id, | ||||
|       }; | ||||
|  | ||||
| @@ -1586,7 +1702,8 @@ export class TransactionService { | ||||
|   async withdrawBenefit(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 coaBank = await this.coaService.findByName( | ||||
| @@ -1762,7 +1879,7 @@ export class TransactionService { | ||||
|         take: pageSize || 10, | ||||
|         order: { | ||||
|           createdAt: 'DESC', | ||||
|         } | ||||
|         }, | ||||
|       }); | ||||
|     } catch (e) { | ||||
|       throw new HttpException( | ||||
| @@ -2062,7 +2179,8 @@ export class TransactionService { | ||||
|         ), | ||||
|     ); | ||||
|  | ||||
|     console.log('coamsk10', 'coa') | ||||
|     console.log('coamsk10', 'coa'); | ||||
|  | ||||
|     return Promise.all( | ||||
|         supervisorData.map(async (it) => { | ||||
|           const coaAccount = await this.coaService.findByUser( | ||||
| @@ -2129,9 +2247,9 @@ export class TransactionService { | ||||
|           const journalEntry = new TransactionJournal(); | ||||
|  | ||||
|           journalEntry.coa = coa; | ||||
|         journalEntry.type = journal.debit | ||||
|           ? balanceType.DEBIT | ||||
|           : balanceType.CREDIT; | ||||
|           journalEntry.type = journal.debit ? | ||||
|               balanceType.DEBIT : | ||||
|               balanceType.CREDIT; | ||||
|           journalEntry.amount = journal.debit ? journal.debit : journal.credit; | ||||
|           journalEntry.transaction_head = transaction; | ||||
|  | ||||
| @@ -2204,7 +2322,9 @@ export class TransactionService { | ||||
|       message: string, | ||||
|   ) { | ||||
|     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 product_price = await this.productHistoryPriceService.findById( | ||||
| @@ -2216,12 +2336,12 @@ export class TransactionService { | ||||
|           trx_id: trxId, | ||||
|         }, | ||||
|         { | ||||
|         amount: status | ||||
|           ? amount - | ||||
|           amount: status ? | ||||
|               amount - | ||||
|               admin + | ||||
|               product_price.partner_fee + | ||||
|             product_price.mark_up_price | ||||
|           : 0, | ||||
|               product_price.mark_up_price : | ||||
|               0, | ||||
|           admin_price: admin, | ||||
|           status: status ? 'SUCCESS' : 'FAILED', | ||||
|           callback_json: JSON.stringify(message), | ||||
| @@ -2229,12 +2349,13 @@ export class TransactionService { | ||||
|     ); | ||||
|  | ||||
|     if (userData.partner) { | ||||
|       const message = status | ||||
|         ? `Bill dari ${billData.destination} adalah ${ | ||||
|       const message = status ? | ||||
|           `Bill dari ${billData.destination} adalah ${ | ||||
|               amount + product_price.partner_fee + product_price.mark_up_price | ||||
|           }.` | ||||
|         : ''; | ||||
|           }.` : | ||||
|           ''; | ||||
|       const statusResponse = status ? 'berhasil' : 'gagal'; | ||||
|  | ||||
|       this.callbackToPartner( | ||||
|           userData.id, | ||||
|           message, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user