diff --git a/src/transaction/entities/transactions.entity.ts b/src/transaction/entities/transactions.entity.ts index 4c146b7..fb1aed7 100644 --- a/src/transaction/entities/transactions.entity.ts +++ b/src/transaction/entities/transactions.entity.ts @@ -16,6 +16,11 @@ export class Transactions extends BaseModel { @Column() type: typeTransaction; + @Column({ + nullable: true, + }) + check_bill: string; + @Column({ type: 'uuid', nullable: true, diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 0fb35cf..63b34fd 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -50,7 +50,7 @@ export class TransactionService { private commissionService: CommissionService, private supplierService: SupplierService, private connection: Connection, - ) {} + ) { } async addSupplierSaldo(addSaldoSupplier: AddSaldoSupplier, currentUser: any) { const supplier = await this.supplierService.findByCode( @@ -481,7 +481,29 @@ export class TransactionService { `${coaType[coaType.SALES]}-SYSTEM`, ); + if (orderTransactionDto.bill_trx_id !== null) { + try { + const billId = await this.checkBillHistoryRepository.findOneOrFail({ + where: { + id: orderTransactionDto.bill_trx_id + }, + }); + product_price.price = billId.amount + } catch (e) { + if (e instanceof EntityNotFoundError) { + throw new HttpException( + { + statusCode: HttpStatus.NOT_FOUND, + error: 'Build not found', + }, + HttpStatus.NOT_FOUND, + ); + } else { + throw e; + } + } + } if (coaAccount.amount < product_price.mark_up_price + product_price.price) { throw new HttpException( @@ -570,6 +592,7 @@ export class TransactionService { transactionData.destination = orderTransactionDto.destination; transactionData.partner_trx_id = orderTransactionDto.trx_id; transactionData.supplier_trx_id = trxId; + transactionData.check_bill = orderTransactionDto.bill_trx_id; if (!hitSupplier.success) { transactionData.status = statusTransaction.FAILED;