add: withdraw
This commit is contained in:
parent
7b0056f2ae
commit
c5e1df20b8
|
@ -11,6 +11,7 @@ export enum typeTransaction {
|
||||||
ORDER,
|
ORDER,
|
||||||
DEPOSIT_SUPPLIER,
|
DEPOSIT_SUPPLIER,
|
||||||
DEPOSIT_RETURN,
|
DEPOSIT_RETURN,
|
||||||
|
WITHDRAW,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum productType {
|
export enum productType {
|
||||||
|
@ -31,6 +32,7 @@ export enum coaType {
|
||||||
BUDGET,
|
BUDGET,
|
||||||
CONTRA_BUDGET,
|
CONTRA_BUDGET,
|
||||||
PROFIT,
|
PROFIT,
|
||||||
|
WITHDRAW,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum balanceType {
|
export enum balanceType {
|
||||||
|
|
|
@ -211,4 +211,13 @@ export class TransactionController {
|
||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put('withdraw/:id')
|
||||||
|
async withdrawProfit(@Param('id', ParseUUIDPipe) id: string, @Request() req) {
|
||||||
|
return {
|
||||||
|
data: await this.transactionService.withdrawBenefit(id),
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ import { SupplierService } from '../users/supplier/supplier.service';
|
||||||
import { ProductHistoryPriceService } from '../product/history-price/history-price.service';
|
import { ProductHistoryPriceService } from '../product/history-price/history-price.service';
|
||||||
import { CommissionService } from '../configurable/commission.service';
|
import { CommissionService } from '../configurable/commission.service';
|
||||||
import { DepositReturnDto } from './dto/deposit_return.dto';
|
import { DepositReturnDto } from './dto/deposit_return.dto';
|
||||||
import { User } from '../users/entities/user.entity';
|
|
||||||
import { UserDetail } from '../users/entities/user_detail.entity';
|
import { UserDetail } from '../users/entities/user_detail.entity';
|
||||||
|
|
||||||
interface JournalEntry {
|
interface JournalEntry {
|
||||||
|
@ -719,6 +718,51 @@ export class TransactionService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async withdrawBenefit(user) {
|
||||||
|
const userData = await this.userService.findExist(user);
|
||||||
|
|
||||||
|
const coaProfit = await this.coaService.findByUser(user, coaType.PROFIT);
|
||||||
|
|
||||||
|
const coaBank = await this.coaService.findByName(
|
||||||
|
`${coaType[coaType.BANK]}-SYSTEM`,
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const transactionData = new Transactions();
|
||||||
|
|
||||||
|
transactionData.id = uuid.v4();
|
||||||
|
transactionData.amount = coaProfit.amount;
|
||||||
|
transactionData.user = userData.id;
|
||||||
|
transactionData.status = statusTransaction.APPROVED;
|
||||||
|
transactionData.type = typeTransaction.WITHDRAW;
|
||||||
|
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
await manager.insert(Transactions, transactionData);
|
||||||
|
|
||||||
|
await this.accountingTransaction({
|
||||||
|
createTransaction: false,
|
||||||
|
transactionalEntityManager: manager,
|
||||||
|
transaction: transactionData,
|
||||||
|
amount: transactionData.amount,
|
||||||
|
journals: [
|
||||||
|
{
|
||||||
|
coa_id: coaBank.id,
|
||||||
|
credit: transactionData.amount,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
coa_id: coaProfit.id,
|
||||||
|
debit: transactionData.amount,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return transactionData;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async calculateCommission(data, totalPrice, userData) {
|
async calculateCommission(data, totalPrice, userData) {
|
||||||
const supervisorData = [];
|
const supervisorData = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user