add: top up saldo supplier
This commit is contained in:
parent
14a00988d9
commit
ed5ca6556d
|
@ -1,12 +1,16 @@
|
|||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
import { balanceType, coaType, statusTransaction, typeTransaction } from 'src/helper/enum-list';
|
||||
import {
|
||||
balanceType,
|
||||
coaType,
|
||||
statusTransaction,
|
||||
typeTransaction,
|
||||
} from 'src/helper/enum-list';
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
|
||||
export class AddSaldoSupplier {
|
||||
@IsNotEmpty()
|
||||
supplier?: string;
|
||||
@IsNotEmpty()
|
||||
supplier: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
amount?: number;
|
||||
@IsNotEmpty()
|
||||
amount: number;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ export class TransactionController {
|
|||
@Request() req,
|
||||
) {
|
||||
return {
|
||||
data: await this.transactionService.addIRSWallet(
|
||||
data: await this.transactionService.addPartnerSaldo(
|
||||
addSaldoSupplier,
|
||||
req.user,
|
||||
),
|
||||
|
|
|
@ -21,6 +21,7 @@ import * as irsService from '../helper/irs-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.service';
|
||||
|
||||
interface JournalEntry {
|
||||
coa_id: string;
|
||||
|
@ -40,17 +41,29 @@ export class TransactionService {
|
|||
private coaService: CoaService,
|
||||
private productService: ProductService,
|
||||
private userService: UsersService,
|
||||
private supplierService: SupplierService,
|
||||
private connection: Connection,
|
||||
) {}
|
||||
|
||||
async addIRSWallet(addSaldoSupplier: AddSaldoSupplier, currentUser: any) {
|
||||
async addPartnerSaldo(addSaldoSupplier: AddSaldoSupplier, currentUser: any) {
|
||||
const supplier = await this.supplierService.findByCode(
|
||||
addSaldoSupplier.supplier,
|
||||
);
|
||||
// GET COA
|
||||
const coaBank = await this.coaService.findByName(
|
||||
`${coaType[coaType.BANK]}-SYSTEM`,
|
||||
);
|
||||
|
||||
const coaInventory = await this.coaService.findByName(
|
||||
`${coaType[coaType.INVENTORY]}-${addSaldoSupplier.supplier}`,
|
||||
`${coaType[coaType.INVENTORY]}-${supplier.code}`,
|
||||
);
|
||||
|
||||
const coaBudget = await this.coaService.findByName(
|
||||
`${coaType[coaType.BUDGET]}-${supplier.code}`,
|
||||
);
|
||||
|
||||
const coaContraBudget = await this.coaService.findByName(
|
||||
`${coaType[coaType.CONTRA_BUDGET]}-${supplier.code}`,
|
||||
);
|
||||
|
||||
//GET USER
|
||||
|
@ -78,10 +91,18 @@ export class TransactionService {
|
|||
journals: [
|
||||
{
|
||||
coa_id: coaBank.id,
|
||||
debit: transactionData.amount,
|
||||
credit: transactionData.amount,
|
||||
},
|
||||
{
|
||||
coa_id: coaInventory.id,
|
||||
debit: transactionData.amount,
|
||||
},
|
||||
{
|
||||
coa_id: coaBudget.id,
|
||||
debit: transactionData.amount,
|
||||
},
|
||||
{
|
||||
coa_id: coaContraBudget.id,
|
||||
credit: transactionData.amount,
|
||||
},
|
||||
],
|
||||
|
@ -429,15 +450,12 @@ export class TransactionService {
|
|||
);
|
||||
|
||||
let balance = new Decimal(coa.amount);
|
||||
|
||||
if (coa.balanceType === balanceType.DEBIT) {
|
||||
if (coa.balanceType == balanceType.DEBIT) {
|
||||
balance = balance.plus(debitSum.minus(creditSum));
|
||||
} else if (coa.balanceType === balanceType.CREDIT) {
|
||||
} else if (coa.balanceType == balanceType.CREDIT) {
|
||||
balance = balance.plus(creditSum.minus(debitSum));
|
||||
}
|
||||
|
||||
const diff = balance.minus(new Decimal(coa.amount));
|
||||
|
||||
return createJournalDto.transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
.update(COA)
|
||||
|
|
|
@ -94,9 +94,11 @@ export class SupplierService {
|
|||
});
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
async findByCode(code: string) {
|
||||
try {
|
||||
return await this.supplierRepository.findOneOrFail(id);
|
||||
return await this.supplierRepository.findOneOrFail({
|
||||
code: code,
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
|
|
|
@ -16,6 +16,6 @@ import { Supplier } from './entities/supplier.entity';
|
|||
],
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService, SupplierService],
|
||||
exports: [UsersService],
|
||||
exports: [UsersService, SupplierService],
|
||||
})
|
||||
export class UsersModule {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user