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