add: create supplier
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
forwardRef,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { COA } from './entities/coa.entity';
|
||||
@@ -10,24 +16,40 @@ export class CoaService {
|
||||
constructor(
|
||||
@InjectRepository(COA)
|
||||
private coaRepository: Repository<COA>,
|
||||
@Inject(forwardRef(() => UsersService))
|
||||
@Inject(
|
||||
forwardRef(() => {
|
||||
return UsersService;
|
||||
}),
|
||||
)
|
||||
private userService: UsersService,
|
||||
) {}
|
||||
|
||||
async create(inputCoaDto: InputCoaDto) {
|
||||
const user = inputCoaDto.user
|
||||
let coaData = new COA();
|
||||
coaData.user = user.id;
|
||||
coaData.name = coaType[inputCoaDto.type] + '-' + user.username;
|
||||
const coaData = new COA();
|
||||
let name = '';
|
||||
if (inputCoaDto.user) {
|
||||
coaData.user = inputCoaDto.user.id;
|
||||
name = inputCoaDto.user.username;
|
||||
}
|
||||
|
||||
if (inputCoaDto.supplier) {
|
||||
coaData.supplier = inputCoaDto.supplier.id;
|
||||
name = inputCoaDto.supplier.code;
|
||||
}
|
||||
|
||||
coaData.name = `${coaType[inputCoaDto.type]}-${name}`;
|
||||
coaData.balanceType = inputCoaDto.balanceType;
|
||||
coaData.type = inputCoaDto.type;
|
||||
coaData.amount = 0;
|
||||
|
||||
const result = await inputCoaDto.coaEntityManager.insert(COA,coaData);
|
||||
const result = await inputCoaDto.coaEntityManager.insert(COA, coaData);
|
||||
|
||||
if(inputCoaDto.type == coaType.ACCOUNT_RECEIVABLE || inputCoaDto.type == coaType.ACCOUNT_PAYABLE){
|
||||
if (
|
||||
inputCoaDto.type == coaType.ACCOUNT_RECEIVABLE ||
|
||||
inputCoaDto.type == coaType.ACCOUNT_PAYABLE
|
||||
) {
|
||||
coaData.relatedUser = inputCoaDto.relatedUserId;
|
||||
await inputCoaDto.coaEntityManager.save(coaData)
|
||||
await inputCoaDto.coaEntityManager.save(coaData);
|
||||
}
|
||||
|
||||
return coaData;
|
||||
@@ -35,7 +57,10 @@ export class CoaService {
|
||||
|
||||
async findByUser(id: string, typeOfCoa: coaType) {
|
||||
try {
|
||||
return await this.coaRepository.findOneOrFail({ user: id, type: typeOfCoa });
|
||||
return await this.coaRepository.findOneOrFail({
|
||||
user: id,
|
||||
type: typeOfCoa,
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
@@ -51,9 +76,17 @@ export class CoaService {
|
||||
}
|
||||
}
|
||||
|
||||
async findByUserWithRelated(id: string, relatedId: string, typeOfCoa: coaType) {
|
||||
async findByUserWithRelated(
|
||||
id: string,
|
||||
relatedId: string,
|
||||
typeOfCoa: coaType,
|
||||
) {
|
||||
try {
|
||||
return await this.coaRepository.findOneOrFail({ user: id, type: typeOfCoa, relatedUser:relatedId });
|
||||
return await this.coaRepository.findOneOrFail({
|
||||
user: id,
|
||||
type: typeOfCoa,
|
||||
relatedUser: relatedId,
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
|
||||
@@ -2,6 +2,7 @@ import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
import { balanceType, coaType } from 'src/helper/enum-list';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { EntityManager } from 'typeorm';
|
||||
import { Supplier } from '../../users/entities/supplier.entity';
|
||||
|
||||
export class InputCoaDto {
|
||||
@IsUUID()
|
||||
@@ -16,6 +17,9 @@ export class InputCoaDto {
|
||||
@IsUUID()
|
||||
relatedUserId: string;
|
||||
|
||||
@IsUUID()
|
||||
supplier: Supplier;
|
||||
|
||||
@IsNotEmpty()
|
||||
coaEntityManager: EntityManager;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
} from 'typeorm';
|
||||
import { Entity, Column } from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { coaType, balanceType } from '../../helper/enum-list';
|
||||
|
||||
@@ -19,11 +16,18 @@ export class COA extends BaseModel {
|
||||
@Column()
|
||||
amount: number;
|
||||
|
||||
@Column()
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
user: string;
|
||||
|
||||
@Column({
|
||||
nullable:true
|
||||
nullable: true,
|
||||
})
|
||||
relatedUser: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
supplier: string;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { COA } from './coa.entity';
|
||||
import { Transactions } from './transactions.entity';
|
||||
import { TransactionType } from './transaction-type.entity';
|
||||
import { balanceType } from '../../helper/enum-list';
|
||||
|
||||
@Entity()
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
} from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
|
||||
@Entity()
|
||||
export class TransactionType extends BaseModel {
|
||||
@Column()
|
||||
name: string;
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import { TransactionController } from './transaction.controller';
|
||||
import { PpobCallbackController } from './ppob_callback.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { COA } from './entities/coa.entity';
|
||||
import { TransactionType } from './entities/transaction-type.entity';
|
||||
import { TransactionJournal } from './entities/transaction-journal.entity';
|
||||
import { Transactions } from './entities/transactions.entity';
|
||||
import { CoaService } from './coa.service';
|
||||
@@ -13,17 +12,12 @@ import { UsersModule } from 'src/users/users.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
TransactionType,
|
||||
COA,
|
||||
TransactionJournal,
|
||||
Transactions,
|
||||
]),
|
||||
TypeOrmModule.forFeature([COA, TransactionJournal, Transactions]),
|
||||
ProductModule,
|
||||
forwardRef(() => UsersModule),
|
||||
],
|
||||
controllers: [TransactionController, PpobCallbackController],
|
||||
providers: [TransactionService, CoaService],
|
||||
exports:[CoaService]
|
||||
exports: [CoaService],
|
||||
})
|
||||
export class TransactionModule {}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Transactions } from './entities/transactions.entity';
|
||||
import { Connection, EntityManager, Repository } from 'typeorm';
|
||||
import { COA } from './entities/coa.entity';
|
||||
import { TransactionType } from './entities/transaction-type.entity';
|
||||
import { TransactionJournal } from './entities/transaction-journal.entity';
|
||||
import { CoaService } from './coa.service';
|
||||
import * as uuid from 'uuid';
|
||||
@@ -34,8 +33,6 @@ export class TransactionService {
|
||||
constructor(
|
||||
@InjectRepository(Transactions)
|
||||
private transactionRepository: Repository<Transactions>,
|
||||
@InjectRepository(TransactionType)
|
||||
private transactionTypeRepository: Repository<TransactionType>,
|
||||
@InjectRepository(TransactionJournal)
|
||||
private transactionJournalRepository: Repository<TransactionJournal>,
|
||||
@InjectRepository(COA)
|
||||
|
||||
Reference in New Issue
Block a user