fix: companies
This commit is contained in:
@@ -1,13 +1,4 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
UseInterceptors,
|
||||
} from "@nestjs/common";
|
||||
import { Body, Controller, Delete, Get, Param, Post, Query, UseInterceptors } from "@nestjs/common";
|
||||
import { ApiOperation } from "@nestjs/swagger";
|
||||
|
||||
import { BillsService } from "./bills.service";
|
||||
|
||||
@@ -8,11 +8,7 @@ import { BusinessesModule } from "../businesses/businesses.module";
|
||||
import { CompaniesModule } from "../companies/companies.module";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MikroOrmModule.forFeature([Bill]),
|
||||
CompaniesModule,
|
||||
BusinessesModule,
|
||||
],
|
||||
imports: [MikroOrmModule.forFeature([Bill]), CompaniesModule, BusinessesModule],
|
||||
controllers: [BillsController],
|
||||
providers: [BillsService],
|
||||
})
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import dayjs from 'dayjs';
|
||||
import Decimal from 'decimal.js';
|
||||
import { EntityManager } from "@mikro-orm/postgresql";
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import dayjs from "dayjs";
|
||||
import Decimal from "decimal.js";
|
||||
|
||||
import { BillListQueryDto } from './dto/bill-list-query.dto';
|
||||
import { CreateChargeBillDto } from './dto/create-charge-bill.dto';
|
||||
import { CreateWaterBillDto } from './dto/create-water-bill.dto';
|
||||
import { Bill } from './entities/bill.entity';
|
||||
import { BillType } from './enums/bill-type.enum';
|
||||
import { BillsRepository } from './repositories/bill.repository';
|
||||
import { CompanyMessage } from '../../common/enums/message.enum';
|
||||
import { Business } from '../businesses/entities/business.entity';
|
||||
import { Company } from '../companies/entities/company.entity';
|
||||
import { CompaniesService } from '../companies/services/companies.service';
|
||||
import { InvoiceItem } from '../invoices/entities/invoice-item.entity';
|
||||
import { Invoice } from '../invoices/entities/invoice.entity';
|
||||
import { BillListQueryDto } from "./dto/bill-list-query.dto";
|
||||
import { CreateChargeBillDto } from "./dto/create-charge-bill.dto";
|
||||
import { CreateWaterBillDto } from "./dto/create-water-bill.dto";
|
||||
import { Bill } from "./entities/bill.entity";
|
||||
import { BillType } from "./enums/bill-type.enum";
|
||||
import { BillsRepository } from "./repositories/bill.repository";
|
||||
import { CompanyMessage } from "../../common/enums/message.enum";
|
||||
import { Business } from "../businesses/entities/business.entity";
|
||||
import { Company } from "../companies/entities/company.entity";
|
||||
import { CompaniesService } from "../companies/services/companies.service";
|
||||
import { InvoiceItem } from "../invoices/entities/invoice-item.entity";
|
||||
import { Invoice } from "../invoices/entities/invoice.entity";
|
||||
|
||||
@Injectable()
|
||||
export class BillsService {
|
||||
@@ -33,7 +33,7 @@ export class BillsService {
|
||||
|
||||
const bill = em.create(Bill, { type: BillType.WATER_BILL, business });
|
||||
em.persist(bill);
|
||||
const dueDate = dayjs().add(dueDays, 'day').toDate();
|
||||
const dueDate = dayjs().add(dueDays, "day").toDate();
|
||||
|
||||
const uniqueCompanyIds = [...new Set(values.map((v) => v.companyId))];
|
||||
const companies = await this.companiesService.findByIds(uniqueCompanyIds, em);
|
||||
@@ -59,7 +59,7 @@ export class BillsService {
|
||||
});
|
||||
|
||||
const invoiceItem = em.create(InvoiceItem, {
|
||||
name: 'قبض آب',
|
||||
name: "قبض آب",
|
||||
count: value.waterUsage,
|
||||
unitPrice: new Decimal(waterRate),
|
||||
discount: new Decimal(0),
|
||||
@@ -90,7 +90,7 @@ export class BillsService {
|
||||
|
||||
const bill = em.create(Bill, { type: BillType.MONTHLY_CHARGE, business });
|
||||
em.persist(bill);
|
||||
const dueDate = dayjs().add(dueDays, 'day').toDate();
|
||||
const dueDate = dayjs().add(dueDays, "day").toDate();
|
||||
|
||||
const companies = await this.companiesService.findAllBybusinessId(business.id, em);
|
||||
|
||||
@@ -110,7 +110,7 @@ export class BillsService {
|
||||
});
|
||||
|
||||
const invoiceItem = em.create(InvoiceItem, {
|
||||
name: 'قبض شارژ',
|
||||
name: "قبض شارژ",
|
||||
count: 1,
|
||||
unitPrice: subtotal,
|
||||
discount: new Decimal(0),
|
||||
@@ -142,10 +142,7 @@ export class BillsService {
|
||||
}
|
||||
|
||||
async findOne(id: string, businessId: string) {
|
||||
const bill = await this.billRepository.findOne(
|
||||
{ id, business: { id: businessId } },
|
||||
{ populate: ["invoices"] },
|
||||
);
|
||||
const bill = await this.billRepository.findOne({ id, business: { id: businessId } }, { populate: ["invoices"] });
|
||||
if (!bill) {
|
||||
throw new BadRequestException("Bill not found");
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsInt } from "class-validator";
|
||||
|
||||
export class CreateChargeBillDto {
|
||||
@ApiProperty()
|
||||
@IsInt()
|
||||
chargeRate: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsInt()
|
||||
dueDays:number;
|
||||
@ApiProperty()
|
||||
@IsInt()
|
||||
chargeRate: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsInt()
|
||||
dueDays: number;
|
||||
}
|
||||
|
||||
@@ -3,30 +3,31 @@ import { Type } from "class-transformer";
|
||||
import { ArrayMinSize, IsArray, IsInt, IsNotEmpty, IsUUID, ValidateNested } from "class-validator";
|
||||
|
||||
export class ValueDto {
|
||||
@IsNotEmpty({ message: ' BillMessage.COMPANY_ID_REQUIRED' })
|
||||
@ApiProperty({ description: "شناسه شرکت", })
|
||||
@IsUUID("7")
|
||||
companyId: string;
|
||||
@IsNotEmpty({ message: " BillMessage.COMPANY_ID_REQUIRED" })
|
||||
@ApiProperty({ description: "شناسه شرکت" })
|
||||
@IsUUID("7")
|
||||
companyId: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNotEmpty({ message: 'BillMessage.WATER_USAGE_REQUIRED' })
|
||||
@IsInt()
|
||||
@ApiProperty({ description: "مصرف آب", example: 100 })
|
||||
waterUsage: number;
|
||||
@ApiProperty()
|
||||
@IsNotEmpty({ message: "BillMessage.WATER_USAGE_REQUIRED" })
|
||||
@IsInt()
|
||||
@ApiProperty({ description: "مصرف آب", example: 100 })
|
||||
waterUsage: number;
|
||||
}
|
||||
|
||||
export class CreateWaterBillDto {
|
||||
@ApiProperty()
|
||||
@IsInt()
|
||||
waterRate:number;
|
||||
@ApiProperty()
|
||||
@IsInt()
|
||||
waterRate: number;
|
||||
|
||||
@ApiProperty()
|
||||
@IsInt()
|
||||
dueDays:number;
|
||||
@ApiProperty()
|
||||
@IsInt()
|
||||
dueDays: number;
|
||||
|
||||
@Type(() => ValueDto)
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@ValidateNested({ each: true })
|
||||
values: ValueDto[];
|
||||
@ApiProperty({ example: [{ companyId: "", waterUsage: 100 }] })
|
||||
@Type(() => ValueDto)
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@ValidateNested({ each: true })
|
||||
values: ValueDto[];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { PartialType } from "@nestjs/swagger";
|
||||
|
||||
import { CreateWaterBillDto } from './create-water-bill.dto';
|
||||
import { CreateWaterBillDto } from "./create-water-bill.dto";
|
||||
|
||||
export class UpdateBillDto extends PartialType(CreateWaterBillDto) {}
|
||||
|
||||
@@ -8,15 +8,14 @@ import { BillsRepository } from "../repositories/bill.repository";
|
||||
|
||||
@Entity({ repository: () => BillsRepository })
|
||||
export class Bill extends BaseEntity {
|
||||
@Enum({ items: () => BillType })
|
||||
type: BillType;
|
||||
|
||||
@Enum({ items: () => BillType })
|
||||
type: BillType;
|
||||
@ManyToOne(() => Business, { nullable: false, deleteRule: "cascade" })
|
||||
business!: Business;
|
||||
|
||||
@ManyToOne(() => Business, { nullable: false, deleteRule: "cascade" })
|
||||
business!: Business;
|
||||
@OneToMany(() => Invoice, (invoice) => invoice.bill, { cascade: [Cascade.PERSIST, Cascade.REMOVE], orphanRemoval: true })
|
||||
invoices = new Collection<Invoice>(this);
|
||||
|
||||
@OneToMany(() => Invoice, (invoice) => invoice.bill, { cascade: [Cascade.PERSIST, Cascade.REMOVE], orphanRemoval: true })
|
||||
invoices = new Collection<Invoice>(this);
|
||||
|
||||
[EntityRepositoryType]?: BillsRepository;
|
||||
[EntityRepositoryType]?: BillsRepository;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user