add: product price

This commit is contained in:
ilham 2021-12-08 09:16:43 +07:00
parent 426c2ccec8
commit 2e52ae494e
9 changed files with 72 additions and 33 deletions

View File

@ -15,7 +15,7 @@ export enum productType {
} }
export enum coaType { export enum coaType {
SYSTEM_BANk, WALLET,
INCOME, INCOME,
} }

View File

@ -13,6 +13,9 @@ export class CreateProductDto {
@IsNotEmpty() @IsNotEmpty()
price: number; price: number;
@IsNotEmpty()
markUpPrice: number;
@IsUUID() @IsUUID()
subCategoriesId: string; subCategoriesId: string;
} }

View File

@ -0,0 +1,17 @@
import { IsNotEmpty } from 'class-validator';
import { productType } from '../../../helper/enum-list';
export class UpdatePriceProductDto {
@IsNotEmpty()
price: number;
@IsNotEmpty()
markUpPrice: number;
@IsNotEmpty()
type: productType;
startDate: Date;
endDate: Date;
}

View File

@ -1,4 +1,6 @@
import { PartialType } from '@nestjs/mapped-types'; import { OmitType, PartialType } from '@nestjs/mapped-types';
import { CreateProductDto } from './create-product.dto'; import { CreateProductDto } from './create-product.dto';
export class UpdateProductDto extends PartialType(CreateProductDto) {} export class UpdateProductDto extends PartialType(
OmitType(CreateProductDto, ['price'] as const),
) {}

View File

@ -19,6 +19,9 @@ export class ProductHistoryPrice extends BaseModel {
@Column() @Column()
price: number; price: number;
@Column()
markUpPrice: number;
@Column({ type: 'date' }) @Column({ type: 'date' })
startDate: Date; startDate: Date;

View File

@ -7,6 +7,7 @@ import { ProductSubCategoriesService } from './product-sub-categories.service';
import { UpdateProductDto } from './dto/product/update-product.dto'; import { UpdateProductDto } from './dto/product/update-product.dto';
import { ProductHistoryPrice } from './entities/product-history-price.entity'; import { ProductHistoryPrice } from './entities/product-history-price.entity';
import { productType } from '../helper/enum-list'; import { productType } from '../helper/enum-list';
import { UpdatePriceProductDto } from './dto/product/update-price-product.dto';
export class ProductService { export class ProductService {
constructor( constructor(
@ -33,6 +34,8 @@ export class ProductService {
await this.productHistoryPrice.insert({ await this.productHistoryPrice.insert({
product: result.identifiers[0], product: result.identifiers[0],
type: productType.NORMAL, type: productType.NORMAL,
price: createProductDto.price,
markUpPrice: createProductDto.markUpPrice,
startDate: new Date(), startDate: new Date(),
endDate: null, endDate: null,
}); });
@ -84,6 +87,7 @@ export class ProductService {
throw e; throw e;
} }
} }
const subCategories = await this.productSubCategoriesService.findOne( const subCategories = await this.productSubCategoriesService.findOne(
updateProductDto.subCategoriesId, updateProductDto.subCategoriesId,
); );
@ -93,12 +97,29 @@ export class ProductService {
code: updateProductDto.code, code: updateProductDto.code,
status: updateProductDto.status, status: updateProductDto.status,
subCategories: subCategories, subCategories: subCategories,
price: updateProductDto.price,
}); });
return this.productRepository.findOneOrFail(id); return this.productRepository.findOneOrFail(id);
} }
async updatePrice(
code: string,
updatePriceProductDto: UpdatePriceProductDto,
) {
const product = await this.findOne(code);
await this.productHistoryPrice.insert({
product: product,
type: updatePriceProductDto.type,
price: updatePriceProductDto.price,
markUpPrice: updatePriceProductDto.markUpPrice,
startDate: updatePriceProductDto.startDate,
endDate: updatePriceProductDto.endDate,
});
return
}
async remove(id: string) { async remove(id: string) {
try { try {
await this.productRepository.findOneOrFail(id); await this.productRepository.findOneOrFail(id);

View File

@ -10,9 +10,9 @@ export class CoaService {
private coaRepository: Repository<COA>, private coaRepository: Repository<COA>,
) {} ) {}
async findByUser(id: string, type: coaType) { async findByUser(id: string, typeOfCoa: coaType) {
try { try {
return await this.coaRepository.findOneOrFail({ user: id, type: type }); return await this.coaRepository.findOneOrFail({ user: id, type: typeOfCoa });
} catch (e) { } catch (e) {
if (e instanceof EntityNotFoundError) { if (e instanceof EntityNotFoundError) {
throw new HttpException( throw new HttpException(

View File

@ -28,22 +28,4 @@ export class TransactionController {
orderTransaction(@Body() orderTransactionDto: OrderTransactionDto) { orderTransaction(@Body() orderTransactionDto: OrderTransactionDto) {
return this.transactionService.orderTransaction(orderTransactionDto); return this.transactionService.orderTransaction(orderTransactionDto);
} }
@Get(':id')
findOne(@Param('id') id: string) {
return this.transactionService.findOne(+id);
}
@Patch(':id')
update(
@Param('id') id: string,
@Body() updateTransactionDto: UpdateTransactionDto,
) {
return this.transactionService.update(+id, updateTransactionDto);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.transactionService.remove(+id);
}
} }

View File

@ -1,18 +1,21 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { DistributeTransactionDto } from './dto/distribute-transaction.dto'; import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
import { OrderTransactionDto } from './dto/order-transaction.dto'; import { OrderTransactionDto } from './dto/order-transaction.dto';
import { UpdateTransactionDto } from './dto/update-transaction.dto';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Transactions } from './entities/transactions.entity'; import { Transactions } from './entities/transactions.entity';
import { Connection, EntityNotFoundError, Repository } from 'typeorm'; import { Connection, Repository } from 'typeorm';
import { COA } from './entities/coa.entity'; import { COA } from './entities/coa.entity';
import { TransactionType } from './entities/transaction-type.entity'; import { TransactionType } from './entities/transaction-type.entity';
import { TransactionJournal } from './entities/transaction-journal.entity'; import { TransactionJournal } from './entities/transaction-journal.entity';
import { CoaService } from './coa.service'; import { CoaService } from './coa.service';
import { statusTransaction } from '../helper/enum-list'; import {
balanceType,
coaType,
statusTransaction,
typeTransaction,
} from '../helper/enum-list';
import { ProductService } from '../product/product.service'; import { ProductService } from '../product/product.service';
import * as irsService from '../helper/irs-service'; import * as irsService from '../helper/irs-service';
import { balanceType, typeTransaction } from '../helper/enum-list';
@Injectable() @Injectable()
export class TransactionService { export class TransactionService {
@ -32,8 +35,14 @@ export class TransactionService {
async distributeDeposit(distributeTransactionDto: DistributeTransactionDto) { async distributeDeposit(distributeTransactionDto: DistributeTransactionDto) {
// GET COA // GET COA
const coaSender = await this.coaService.findByUser('id_user'); const coaSender = await this.coaService.findByUser(
const coaReciever = await this.coaService.findByUser('id_user'); 'id_user',
coaType.WALLET,
);
const coaReciever = await this.coaService.findByUser(
'id_user',
coaType.WALLET,
);
await this.connection.transaction(async (manager) => { await this.connection.transaction(async (manager) => {
//INSERT TRANSACTION //INSERT TRANSACTION
@ -73,7 +82,10 @@ export class TransactionService {
} }
async orderTransaction(orderTransactionDto: OrderTransactionDto) { async orderTransaction(orderTransactionDto: OrderTransactionDto) {
const coaAccount = await this.coaService.findByUser('id_user'); const coaAccount = await this.coaService.findByUser(
'id_user',
coaType.WALLET,
);
//GET PRODUCT //GET PRODUCT
const product = await this.productService.findOne( const product = await this.productService.findOne(
@ -90,7 +102,6 @@ export class TransactionService {
); );
} }
try { try {
const orderIRS = await irsService.createTransaction( const orderIRS = await irsService.createTransaction(
orderTransactionDto.productCode, orderTransactionDto.productCode,