fix: distribute saldo partner from admin
This commit is contained in:
parent
ed5ca6556d
commit
78470a0e3f
|
@ -6,4 +6,7 @@ export class DistributeTransactionDto {
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
destination: string;
|
destination: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
supplier: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,15 @@ export class TransactionJournal extends BaseModel {
|
||||||
@Column()
|
@Column()
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|
||||||
@OneToOne(
|
@ManyToOne(
|
||||||
() => {
|
() => {
|
||||||
return Transactions;
|
return Transactions;
|
||||||
},
|
},
|
||||||
(trans) => {
|
(transaction) => {
|
||||||
return trans.id;
|
return transaction.id;
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
transaction: Transactions;
|
transaction_head: Transactions;
|
||||||
|
|
||||||
@ManyToOne(
|
@ManyToOne(
|
||||||
() => {
|
() => {
|
||||||
|
|
|
@ -116,6 +116,25 @@ export class TransactionService {
|
||||||
distributeTransactionDto: DistributeTransactionDto,
|
distributeTransactionDto: DistributeTransactionDto,
|
||||||
currentUser: any,
|
currentUser: any,
|
||||||
) {
|
) {
|
||||||
|
//GET USER
|
||||||
|
const userData = await this.userService.findByUsername(
|
||||||
|
currentUser.username,
|
||||||
|
);
|
||||||
|
if (userData.roles.name != 'Admin') {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||||
|
error: 'Roles Not Admin',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_ACCEPTABLE,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//GET Supplier
|
||||||
|
const supplier = await this.supplierService.findByCode(
|
||||||
|
distributeTransactionDto.supplier,
|
||||||
|
);
|
||||||
|
|
||||||
// GET COA
|
// GET COA
|
||||||
const coaAR = await this.coaService.findByUser(
|
const coaAR = await this.coaService.findByUser(
|
||||||
distributeTransactionDto.destination,
|
distributeTransactionDto.destination,
|
||||||
|
@ -125,10 +144,12 @@ export class TransactionService {
|
||||||
distributeTransactionDto.destination,
|
distributeTransactionDto.destination,
|
||||||
coaType.WALLET,
|
coaType.WALLET,
|
||||||
);
|
);
|
||||||
|
const coaBudget = await this.coaService.findByName(
|
||||||
|
`${coaType[coaType.BUDGET]}-${supplier.code}`,
|
||||||
|
);
|
||||||
|
|
||||||
//GET USER
|
const coaContraBudget = await this.coaService.findByName(
|
||||||
const userData = await this.userService.findByUsername(
|
`${coaType[coaType.CONTRA_BUDGET]}-${supplier.code}`,
|
||||||
currentUser.username,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
|
@ -157,6 +178,14 @@ export class TransactionService {
|
||||||
coa_id: coaWallet.id,
|
coa_id: coaWallet.id,
|
||||||
credit: transactionData.amount,
|
credit: transactionData.amount,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
coa_id: coaBudget.id,
|
||||||
|
credit: transactionData.amount,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
coa_id: coaContraBudget.id,
|
||||||
|
debit: transactionData.amount,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -412,9 +441,9 @@ export class TransactionService {
|
||||||
? 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 = transaction;
|
journalEntry.transaction_head = transaction;
|
||||||
|
|
||||||
return this.transactionJournalRepository.save(journalEntry);
|
return createJournalDto.transactionalEntityManager.save(journalEntry);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,10 @@ export class UsersService {
|
||||||
async findByUsername(username: string) {
|
async findByUsername(username: string) {
|
||||||
try {
|
try {
|
||||||
return await this.usersRepository.findOneOrFail({
|
return await this.usersRepository.findOneOrFail({
|
||||||
|
where: {
|
||||||
username: username,
|
username: username,
|
||||||
|
},
|
||||||
|
relations: ['roles'],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user