Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 74 customer pricelist #78

Merged
merged 9 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/api/src/app/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MenuContent1612983991735 } from './migrations/1612983991735-MenuContent
import { EnhanceCustomer1615749063579 } from './migrations/1615749063579-EnhanceCustomer';
import { MenuSettings1615961288134 } from './migrations/1615961288134-MenuSettings';
import { UoM1616228731111 } from './migrations/1616228731111-UoM';
import { CustomerPriceList1618661208366 } from './migrations/1618661208366-CustomerPriceList';

export const migrations = [
CreateDB1595508635320,
Expand All @@ -20,4 +21,5 @@ export const migrations = [
EnhanceCustomer1615749063579,
MenuSettings1615961288134,
UoM1616228731111,
CustomerPriceList1618661208366,
];
2 changes: 1 addition & 1 deletion apps/api/src/app/migrations/1595508635320-CreateDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class CreateDB1595508635320 implements MigrationInterface {
`ALTER TABLE "public"."customer" ADD CONSTRAINT "FK_2c1aeb39925d1e1ace946ca2f21" FOREIGN KEY ("addressId") REFERENCES "public"."address"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`CREATE TABLE IF NOT EXISTS "public"."unit_of_measurement_conversion" ("id" SERIAL NOT NULL, "updtTs" TIMESTAMP NOT NULL DEFAULT now(), "isActive" boolean NOT NULL DEFAULT true, "isCurrent" boolean NOT NULL DEFAULT true, "currencyMultiplyingRate" double precision NOT NULL, "end" date NOT NULL, "start" date NOT NULL, "updtOpId" integer NOT NULL, "fromId" integer, "toId" integer, CONSTRAINT "PK_f8796ed806b216628b252bb3b4c" PRIMARY KEY ("id"))`,
`CREATE TABLE IF NOT EXISTS "public"."unit_of_measurement_conversion" ("id" SERIAL NOT NULL, "updtTs" TIMESTAMP NOT NULL DEFAULT now(), "isActive" boolean NOT NULL DEFAULT true, "isCurrent" boolean NOT NULL DEFAULT true, "currencyMultiplyingRate" double precision NOT NULL, "updtOpId" integer NOT NULL, "fromId" integer, "toId" integer, CONSTRAINT "PK_f8796ed806b216628b252bb3b4c" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE IF NOT EXISTS "public"."unit_of_measurement" ("id" SERIAL NOT NULL, "updtTs" TIMESTAMP NOT NULL DEFAULT now(), "isActive" boolean NOT NULL DEFAULT true, "isCurrent" boolean NOT NULL DEFAULT true, "displayName" character varying NOT NULL, "updtOpId" integer NOT NULL, CONSTRAINT "PK_f64cb86b321fc095bde6961d6da" PRIMARY KEY ("id"))`,
Expand Down
83 changes: 83 additions & 0 deletions apps/api/src/app/migrations/1618661208366-CustomerPriceList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CustomerPriceList1618661208366 implements MigrationInterface {
name = 'CustomerPriceList1618661208366';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "public"."customerProductPrice" ("id" SERIAL NOT NULL, "sellingPrice" numeric(12,2) NOT NULL, "productId" integer NOT NULL, "customerPriceListId" integer NOT NULL, CONSTRAINT "PK_41712b48577a11adfdbb81efdf9" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "public"."customerPriceList" ("id" SERIAL NOT NULL, "displayName" character varying NOT NULL, "validFrom" TIMESTAMP, "validTo" TIMESTAMP, "customerGroupId" integer NOT NULL, CONSTRAINT "PK_3a410c80620c92c128634387f20" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_customerPriceList_displayName" ON "public"."customerPriceList" ("displayName") `,
);
await queryRunner.query(
`CREATE TABLE "public"."customerGroup" ("id" SERIAL NOT NULL, "updtTs" TIMESTAMP NOT NULL DEFAULT now(), "isActive" boolean NOT NULL DEFAULT true, "isCurrent" boolean NOT NULL DEFAULT true, "displayName" character varying NOT NULL, "updtOpId" integer NOT NULL, CONSTRAINT "PK_2f921748bb8e683b3d7007182ca" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_customerGroup_displayName" ON "public"."customerGroup" ("displayName") `,
);
await queryRunner.query(
`ALTER TABLE "public"."unit_of_measurement_conversion" DROP COLUMN IF EXISTS "end"`,
);
await queryRunner.query(
`ALTER TABLE "public"."unit_of_measurement_conversion" DROP COLUMN IF EXISTS "start"`,
);
await queryRunner.query(
`ALTER TABLE "public"."customer" ADD "customerGroupId" integer`,
);
await queryRunner.query(
`ALTER TABLE "public"."user" ALTER COLUMN "updtOpId" SET DEFAULT 0`,
);
await queryRunner.query(
`ALTER TABLE "public"."customerProductPrice" ADD CONSTRAINT "FK_51fd886ac463154b1fb68ad944a" FOREIGN KEY ("productId") REFERENCES "public"."product"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "public"."customerProductPrice" ADD CONSTRAINT "FK_5fad018dfcf766b9fab575e5ea1" FOREIGN KEY ("customerPriceListId") REFERENCES "public"."customerPriceList"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "public"."customerPriceList" ADD CONSTRAINT "FK_635c71f6ed02473cca6603a3079" FOREIGN KEY ("customerGroupId") REFERENCES "public"."customerGroup"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "public"."customerGroup" ADD CONSTRAINT "FK_6622e70e814cce558a98043c611" FOREIGN KEY ("updtOpId") REFERENCES "public"."user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "public"."customer" ADD CONSTRAINT "FK_07b06500ab5d46137b7f87cc53c" FOREIGN KEY ("customerGroupId") REFERENCES "public"."customerGroup"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "public"."customer" DROP CONSTRAINT "FK_07b06500ab5d46137b7f87cc53c"`,
);
await queryRunner.query(
`ALTER TABLE "public"."customerGroup" DROP CONSTRAINT "FK_6622e70e814cce558a98043c611"`,
);
await queryRunner.query(
`ALTER TABLE "public"."customerPriceList" DROP CONSTRAINT "FK_635c71f6ed02473cca6603a3079"`,
);
await queryRunner.query(
`ALTER TABLE "public"."customerProductPrice" DROP CONSTRAINT "FK_5fad018dfcf766b9fab575e5ea1"`,
);
await queryRunner.query(
`ALTER TABLE "public"."customerProductPrice" DROP CONSTRAINT "FK_51fd886ac463154b1fb68ad944a"`,
);
await queryRunner.query(
`ALTER TABLE "public"."user" ALTER COLUMN "updtOpId" SET DEFAULT '0'`,
);
await queryRunner.query(
`ALTER TABLE "public"."customer" DROP COLUMN "customerGroupId"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_customerGroup_displayName"`,
);
await queryRunner.query(`DROP TABLE "public"."customerGroup"`);
await queryRunner.query(
`DROP INDEX "public"."IDX_customerPriceList_displayName"`,
);
await queryRunner.query(`DROP TABLE "public"."customerPriceList"`);
await queryRunner.query(`DROP TABLE "public"."customerProductPrice"`);
}
}
6 changes: 6 additions & 0 deletions apps/api/src/app/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { CurrencyResolver } from './resolvers/currency.resolver';
import { CountryResolver } from './resolvers/country.resolver';
import { BankResolver } from './resolvers/bank.resolver';
import { AccountingSchemeResolver } from './resolvers/accounting.scheme.resolver';
import { CustomerGroupResolver } from './resolvers/customer.group.resolver';
import { CustomerPriceListResolver } from './resolvers/customer.price.list.resolver';
import { CustomerProductPriceResolver } from './resolvers/customer.product.price.resolver';

export const resolvers = [
AppResolver,
Expand All @@ -21,4 +24,7 @@ export const resolvers = [
CountryResolver,
BankResolver,
AccountingSchemeResolver,
CustomerGroupResolver,
CustomerPriceListResolver,
CustomerProductPriceResolver,
];
3 changes: 1 addition & 2 deletions apps/api/src/app/resolvers/bank.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export class BankResolver {

@Query(() => Bank)
async bank(@Args('id', { type: () => Int }) id: number) {
const result = await this.bankService.loadEntityById(getManager(), id);
return result;
return await this.bankService.loadEntityById(getManager(), id);
}

@Mutation(() => Bank)
Expand Down
38 changes: 38 additions & 0 deletions apps/api/src/app/resolvers/customer.group.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Args, Int, Mutation, Query, Resolver } from '@nestjs/graphql';
import { Inject, UseGuards } from '@nestjs/common';
import { CurrentUser, GqlAuthGuard } from '../../auth';
import { CustomerGroup } from '../../model/generated/entities/CustomerGroup';
import {
CustomerGroupModel,
CustomerGroupService,
CustomerGroupServiceKey,
} from '../../model';
import { getManager } from 'typeorm';
import { CustomerGroupSaveArgs } from '../saveArgs/customerGroup.save.args';

@Resolver(() => CustomerGroup)
@UseGuards(GqlAuthGuard)
export class CustomerGroupResolver {
constructor(
@Inject(CustomerGroupServiceKey)
protected readonly customerGroupService: CustomerGroupService,
) {}

@Query(() => [CustomerGroup])
async customerGroups() {
return await this.customerGroupService.loadEntities(getManager());
}

@Query(() => CustomerGroup)
async customerGroup(@Args('id', { type: () => Int }) id: number) {
return await this.customerGroupService.loadEntityById(getManager(), id);
}

@Mutation(() => CustomerGroup)
async saveCustomerGroup(
@Args('args') objData: CustomerGroupSaveArgs,
@CurrentUser() user,
): Promise<CustomerGroupModel> {
return await this.customerGroupService.save(getManager(), objData, user);
}
}
42 changes: 42 additions & 0 deletions apps/api/src/app/resolvers/customer.price.list.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Args, Int, Mutation, Query, Resolver } from '@nestjs/graphql';
import { Inject, UseGuards } from '@nestjs/common';
import { CurrentUser, GqlAuthGuard } from '../../auth';
import { CustomerPriceList } from '../../model/generated/entities/CustomerPriceList';
import {
CustomerPriceListModel,
CustomerPriceListService,
CustomerPriceListServiceKey,
} from '../../model';
import { getManager } from 'typeorm';
import { CustomerPriceListSaveArgs } from '../saveArgs/customerPriceList.save.args';

@Resolver(() => CustomerPriceList)
@UseGuards(GqlAuthGuard)
export class CustomerPriceListResolver {
constructor(
@Inject(CustomerPriceListServiceKey)
protected readonly customerPriceListService: CustomerPriceListService,
) {}

@Query(() => [CustomerPriceList])
async customerPriceLists() {
return await this.customerPriceListService.loadEntities(getManager());
}

@Query(() => CustomerPriceList)
async customerPriceList(@Args('id', { type: () => Int }) id: number) {
return await this.customerPriceListService.loadEntityById(getManager(), id);
}

@Mutation(() => CustomerPriceList)
async saveCustomerPriceList(
@Args('args') objData: CustomerPriceListSaveArgs,
@CurrentUser() user,
): Promise<CustomerPriceListModel> {
return await this.customerPriceListService.save(
getManager(),
objData,
user,
);
}
}
45 changes: 45 additions & 0 deletions apps/api/src/app/resolvers/customer.product.price.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Args, Int, Mutation, Query, Resolver } from '@nestjs/graphql';
import { Inject, UseGuards } from '@nestjs/common';
import { CurrentUser, GqlAuthGuard } from '../../auth';
import { CustomerProductPrice } from '../../model/generated/entities/CustomerProductPrice';
import {
CustomerProductPriceModel,
CustomerProductPriceService,
CustomerProductPriceServiceKey,
} from '../../model';
import { getManager } from 'typeorm';
import { CustomerProductPriceSaveArgs } from '../saveArgs/customer.product.price.save.args';

@Resolver(() => CustomerProductPrice)
@UseGuards(GqlAuthGuard)
export class CustomerProductPriceResolver {
constructor(
@Inject(CustomerProductPriceServiceKey)
protected readonly customerProductPriceService: CustomerProductPriceService,
) {}

@Query(() => [CustomerProductPrice])
async customerProductPrices() {
return await this.customerProductPriceService.loadEntities(getManager());
}

@Query(() => CustomerProductPrice)
async customerProductPrice(@Args('id', { type: () => Int }) id: number) {
return await this.customerProductPriceService.loadEntityById(
getManager(),
id,
);
}

@Mutation(() => CustomerProductPrice)
async saveCustomerProductPrice(
@Args('args') objData: CustomerProductPriceSaveArgs,
@CurrentUser() user,
): Promise<CustomerProductPriceModel> {
return await this.customerProductPriceService.save(
getManager(),
objData,
user,
);
}
}
14 changes: 14 additions & 0 deletions apps/api/src/app/saveArgs/customer.product.price.save.args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BaseSaveArgs } from './base.save.args';
import { CustomerProductPriceSaveArgsModel } from '../../model';
import { Field, InputType } from '@nestjs/graphql';

@InputType()
export class CustomerProductPriceSaveArgs extends BaseSaveArgs
implements CustomerProductPriceSaveArgsModel {
@Field()
customerPriceListDisplayName: string;
@Field()
productSKU: string;
@Field()
sellingPrice: number;
}
10 changes: 10 additions & 0 deletions apps/api/src/app/saveArgs/customerGroup.save.args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BaseSaveArgs } from './base.save.args';
import { CustomerGroupSaveArgsModel } from '../../model';
import { Field, InputType } from '@nestjs/graphql';

@InputType()
export class CustomerGroupSaveArgs extends BaseSaveArgs
implements CustomerGroupSaveArgsModel {
@Field()
displayName: string;
}
26 changes: 26 additions & 0 deletions apps/api/src/app/saveArgs/customerPriceList.save.args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BaseSaveArgs } from './base.save.args';
import { CustomerPriceListSaveArgsModel, ProductPrice } from '../../model';
import { Field, InputType } from '@nestjs/graphql';

@InputType()
export class ProductPriceSaveArgs implements ProductPrice {
@Field()
productSKU: string;
@Field()
sellingPrice: number;
}

@InputType()
export class CustomerPriceListSaveArgs extends BaseSaveArgs
implements CustomerPriceListSaveArgsModel {
@Field()
customerGroupDisplayName: string;
@Field()
displayName: string;
@Field(() => [ProductPriceSaveArgs])
productPrices: Array<ProductPrice>;
@Field()
validFrom: Date;
@Field()
validTo: Date;
}
13 changes: 12 additions & 1 deletion apps/api/src/model/generated/entities/Customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import { SalesInvoiceModel } from '../../lib/sales.invoice.model';
import { User } from './User';
import { UserModel } from '../../lib/user.model';
import { DateTimeScalarType } from '../../../app/support/date.scalar';
import { CustomerGroup } from './CustomerGroup';
import { CustomerGroupModel } from '../../lib/customer.group.model';
import { CustomerModel } from '../../lib/customer.model';

@Index('IDX_df529c45726940beb548906481', ['displayName'], { unique: true })
@Index('IDX_71b54ec7502c83c7f503f57c64', ['legalName'], { unique: true })
@Index('IDX_a843215c5e375894bcd5bdf24a', ['vatNumber'], { unique: true })
@Entity('customer', { schema: 'public' })
@ObjectType()
export class Customer {
export class Customer implements CustomerModel {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
@Field()
id: number;
Expand Down Expand Up @@ -98,4 +101,12 @@ export class Customer {
@JoinColumn([{ name: 'addressId', referencedColumnName: 'id' }])
@Field(() => Address, { nullable: true })
address: AddressModel;

@Field(() => CustomerGroup)
@ManyToOne(
() => CustomerGroup,
customerGroup => customerGroup.customers,
{ nullable: true, eager: true },
)
customerGroup?: CustomerGroupModel;
}
Loading