From 5d94b3796b19e5fafd7ef34a73b0e7abb905a413 Mon Sep 17 00:00:00 2001 From: Francis Pion Date: Sat, 20 Apr 2024 15:34:00 -0400 Subject: [PATCH] Completed tax refactor and fixed user profile postal address. --- .../Faktur.Contracts/Receipts/ReceiptTax.cs | 6 ++- ... 20240420185953_Release_2_0_0.Designer.cs} | 9 +++- ...0_0.cs => 20240420185953_Release_2_0_0.cs} | 6 +++ .../Migrations/FakturContextModelSnapshot.cs | 7 +++ .../Configurations/ReceiptTaxConfiguration.cs | 5 +- .../Entities/ReceiptTaxEntity.cs | 2 + .../Mapper.cs | 2 +- ... 20240420185826_Release_2_0_0.Designer.cs} | 9 +++- ...0_0.cs => 20240420185826_Release_2_0_0.cs} | 6 +++ .../Migrations/FakturContextModelSnapshot.cs | 7 +++ .../receipts/ReceiptCategorization.vue | 10 +--- .../components/users/ContactInformation.vue | 51 ++++++++++--------- .../src/stores/__tests__/categories.spec.ts | 2 + frontend/src/types/receipts.ts | 1 + frontend/src/views/receipts/ReceiptEdit.vue | 24 +-------- 15 files changed, 87 insertions(+), 60 deletions(-) rename backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/{20240409152500_Release_2_0_0.Designer.cs => 20240420185953_Release_2_0_0.Designer.cs} (99%) rename backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/{20240409152500_Release_2_0_0.cs => 20240420185953_Release_2_0_0.cs} (99%) rename backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/{20240409151915_Release_2_0_0.Designer.cs => 20240420185826_Release_2_0_0.Designer.cs} (99%) rename backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/{20240409151915_Release_2_0_0.cs => 20240420185826_Release_2_0_0.cs} (99%) diff --git a/backend/src/Faktur.Contracts/Receipts/ReceiptTax.cs b/backend/src/Faktur.Contracts/Receipts/ReceiptTax.cs index a8d4632e..8d73cae7 100644 --- a/backend/src/Faktur.Contracts/Receipts/ReceiptTax.cs +++ b/backend/src/Faktur.Contracts/Receipts/ReceiptTax.cs @@ -3,16 +3,18 @@ public record ReceiptTax { public string Code { get; set; } + public string Flags { get; set; } public double Rate { get; set; } public decimal TaxableAmount { get; set; } public decimal Amount { get; set; } - public ReceiptTax() : this(string.Empty) + public ReceiptTax() : this(string.Empty, string.Empty) { } - public ReceiptTax(string code) + public ReceiptTax(string code, string flags) { Code = code; + Flags = flags; } } diff --git a/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240409152500_Release_2_0_0.Designer.cs b/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240420185953_Release_2_0_0.Designer.cs similarity index 99% rename from backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240409152500_Release_2_0_0.Designer.cs rename to backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240420185953_Release_2_0_0.Designer.cs index 755c412c..ffc264b8 100644 --- a/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240409152500_Release_2_0_0.Designer.cs +++ b/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240420185953_Release_2_0_0.Designer.cs @@ -11,7 +11,7 @@ namespace Faktur.EntityFrameworkCore.PostgreSQL.Migrations { [DbContext(typeof(FakturContext))] - [Migration("20240409152500_Release_2_0_0")] + [Migration("20240420185953_Release_2_0_0")] partial class Release_2_0_0 { /// @@ -598,6 +598,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Amount") .HasColumnType("money"); + b.Property("Flags") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + b.Property("Rate") .HasColumnType("double precision"); @@ -610,6 +615,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("Code"); + b.HasIndex("Flags"); + b.HasIndex("Rate"); b.HasIndex("TaxableAmount"); diff --git a/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240409152500_Release_2_0_0.cs b/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240420185953_Release_2_0_0.cs similarity index 99% rename from backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240409152500_Release_2_0_0.cs rename to backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240420185953_Release_2_0_0.cs index 16008a5b..424bfcbc 100644 --- a/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240409152500_Release_2_0_0.cs +++ b/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/20240420185953_Release_2_0_0.cs @@ -254,6 +254,7 @@ protected override void Up(MigrationBuilder migrationBuilder) { ReceiptId = table.Column(type: "integer", nullable: false), Code = table.Column(type: "character varying(4)", maxLength: 4, nullable: false), + Flags = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), Rate = table.Column(type: "double precision", nullable: false), TaxableAmount = table.Column(type: "money", nullable: false), Amount = table.Column(type: "money", nullable: false) @@ -709,6 +710,11 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "ReceiptTaxes", column: "Code"); + migrationBuilder.CreateIndex( + name: "IX_ReceiptTaxes_Flags", + table: "ReceiptTaxes", + column: "Flags"); + migrationBuilder.CreateIndex( name: "IX_ReceiptTaxes_Rate", table: "ReceiptTaxes", diff --git a/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/FakturContextModelSnapshot.cs b/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/FakturContextModelSnapshot.cs index e6e4fbb5..2ff87103 100644 --- a/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/FakturContextModelSnapshot.cs +++ b/backend/src/Faktur.EntityFrameworkCore.PostgreSQL/Migrations/FakturContextModelSnapshot.cs @@ -595,6 +595,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Amount") .HasColumnType("money"); + b.Property("Flags") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + b.Property("Rate") .HasColumnType("double precision"); @@ -607,6 +612,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("Code"); + b.HasIndex("Flags"); + b.HasIndex("Rate"); b.HasIndex("TaxableAmount"); diff --git a/backend/src/Faktur.EntityFrameworkCore.Relational/Configurations/ReceiptTaxConfiguration.cs b/backend/src/Faktur.EntityFrameworkCore.Relational/Configurations/ReceiptTaxConfiguration.cs index d783f67f..b176f53d 100644 --- a/backend/src/Faktur.EntityFrameworkCore.Relational/Configurations/ReceiptTaxConfiguration.cs +++ b/backend/src/Faktur.EntityFrameworkCore.Relational/Configurations/ReceiptTaxConfiguration.cs @@ -1,4 +1,5 @@ -using Faktur.Domain.Taxes; +using Faktur.Domain.Products; +using Faktur.Domain.Taxes; using Faktur.EntityFrameworkCore.Relational.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -13,10 +14,12 @@ public void Configure(EntityTypeBuilder builder) builder.HasKey(x => new { x.ReceiptId, x.Code }); builder.HasIndex(x => x.Code); + builder.HasIndex(x => x.Flags); builder.HasIndex(x => x.Rate); builder.HasIndex(x => x.TaxableAmount); builder.HasIndex(x => x.Amount); + builder.Property(x => x.Flags).HasMaxLength(FlagsUnit.MaximumLength); builder.Property(x => x.Code).HasMaxLength(TaxCodeUnit.MaximumLength); builder.Property(x => x.TaxableAmount).HasColumnType("money"); builder.Property(x => x.Amount).HasColumnType("money"); diff --git a/backend/src/Faktur.EntityFrameworkCore.Relational/Entities/ReceiptTaxEntity.cs b/backend/src/Faktur.EntityFrameworkCore.Relational/Entities/ReceiptTaxEntity.cs index a78558a0..c8fc581d 100644 --- a/backend/src/Faktur.EntityFrameworkCore.Relational/Entities/ReceiptTaxEntity.cs +++ b/backend/src/Faktur.EntityFrameworkCore.Relational/Entities/ReceiptTaxEntity.cs @@ -8,6 +8,7 @@ internal class ReceiptTaxEntity public int ReceiptId { get; private set; } public string Code { get; private set; } = string.Empty; + public string Flags { get; private set; } = string.Empty; public double Rate { get; private set; } public decimal TaxableAmount { get; private set; } public decimal Amount { get; private set; } @@ -28,6 +29,7 @@ private ReceiptTaxEntity() public void Update(ReceiptTaxUnit tax) { + Flags = tax.Flags.Value; Rate = tax.Rate; TaxableAmount = tax.TaxableAmount; Amount = tax.Amount; diff --git a/backend/src/Faktur.EntityFrameworkCore.Relational/Mapper.cs b/backend/src/Faktur.EntityFrameworkCore.Relational/Mapper.cs index a80b4004..76b62c2a 100644 --- a/backend/src/Faktur.EntityFrameworkCore.Relational/Mapper.cs +++ b/backend/src/Faktur.EntityFrameworkCore.Relational/Mapper.cs @@ -141,7 +141,7 @@ public Receipt ToReceipt(ReceiptEntity source, bool includeItems) foreach (ReceiptTaxEntity tax in source.Taxes) { - destination.Taxes.Add(new ReceiptTax(tax.Code) + destination.Taxes.Add(new ReceiptTax(tax.Code, tax.Flags) { Rate = tax.Rate, TaxableAmount = tax.TaxableAmount, diff --git a/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240409151915_Release_2_0_0.Designer.cs b/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240420185826_Release_2_0_0.Designer.cs similarity index 99% rename from backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240409151915_Release_2_0_0.Designer.cs rename to backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240420185826_Release_2_0_0.Designer.cs index 615290f5..3eadf0e9 100644 --- a/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240409151915_Release_2_0_0.Designer.cs +++ b/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240420185826_Release_2_0_0.Designer.cs @@ -11,7 +11,7 @@ namespace Faktur.EntityFrameworkCore.SqlServer.Migrations { [DbContext(typeof(FakturContext))] - [Migration("20240409151915_Release_2_0_0")] + [Migration("20240420185826_Release_2_0_0")] partial class Release_2_0_0 { /// @@ -600,6 +600,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Amount") .HasColumnType("money"); + b.Property("Flags") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + b.Property("Rate") .HasColumnType("float"); @@ -612,6 +617,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("Code"); + b.HasIndex("Flags"); + b.HasIndex("Rate"); b.HasIndex("TaxableAmount"); diff --git a/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240409151915_Release_2_0_0.cs b/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240420185826_Release_2_0_0.cs similarity index 99% rename from backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240409151915_Release_2_0_0.cs rename to backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240420185826_Release_2_0_0.cs index e12fc050..59e64add 100644 --- a/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240409151915_Release_2_0_0.cs +++ b/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/20240420185826_Release_2_0_0.cs @@ -253,6 +253,7 @@ protected override void Up(MigrationBuilder migrationBuilder) { ReceiptId = table.Column(type: "int", nullable: false), Code = table.Column(type: "nvarchar(4)", maxLength: 4, nullable: false), + Flags = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), Rate = table.Column(type: "float", nullable: false), TaxableAmount = table.Column(type: "money", nullable: false), Amount = table.Column(type: "money", nullable: false) @@ -710,6 +711,11 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "ReceiptTaxes", column: "Code"); + migrationBuilder.CreateIndex( + name: "IX_ReceiptTaxes_Flags", + table: "ReceiptTaxes", + column: "Flags"); + migrationBuilder.CreateIndex( name: "IX_ReceiptTaxes_Rate", table: "ReceiptTaxes", diff --git a/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/FakturContextModelSnapshot.cs b/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/FakturContextModelSnapshot.cs index 0bc53cfe..a2f10a50 100644 --- a/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/FakturContextModelSnapshot.cs +++ b/backend/src/Faktur.EntityFrameworkCore.SqlServer/Migrations/FakturContextModelSnapshot.cs @@ -597,6 +597,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Amount") .HasColumnType("money"); + b.Property("Flags") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + b.Property("Rate") .HasColumnType("float"); @@ -609,6 +614,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("Code"); + b.HasIndex("Flags"); + b.HasIndex("Rate"); b.HasIndex("TaxableAmount"); diff --git a/frontend/src/components/receipts/ReceiptCategorization.vue b/frontend/src/components/receipts/ReceiptCategorization.vue index 3fe16ef8..6b02f486 100644 --- a/frontend/src/components/receipts/ReceiptCategorization.vue +++ b/frontend/src/components/receipts/ReceiptCategorization.vue @@ -7,7 +7,6 @@ import AppBackButton from "@/components/shared/AppBackButton.vue"; import ReceiptItemCard from "./ReceiptItemCard.vue"; import ReceiptTotal from "./ReceiptTotal.vue"; import type { Receipt, ReceiptItem, ReceiptTotal as TReceiptTotal } from "@/types/receipts"; -import type { Tax } from "@/types/taxes"; import { isTaxable } from "@/helpers/taxUtils"; import { orderBy } from "@/helpers/arrayUtils"; import { useCategoryStore } from "@/stores/categories"; @@ -24,7 +23,6 @@ const props = withDefaults( defineProps<{ processing?: boolean; receipt: Receipt; - taxes: Tax[]; // TODO(fpion): should be included in receipt.taxes }>(), { processing: false, @@ -47,11 +45,7 @@ const groupedItems = computed(() => { }); const taxFlags = computed>(() => { const taxFlags = new Map(); - props.taxes.forEach((tax) => { - if (tax.flags) { - taxFlags.set(tax.code, tax.flags); - } - }); + props.receipt.taxes.forEach((tax) => taxFlags.set(tax.code, tax.flags)); return taxFlags; }); @@ -68,7 +62,7 @@ const noCategoryClass = computed(() => { function calculateTotal(category?: string): TReceiptTotal { const total: TReceiptTotal = { subTotal: 0, - taxes: props.receipt.taxes.map(({ code, rate }) => ({ code, taxableAmount: 0, rate, amount: 0 })), + taxes: props.receipt.taxes.map(({ code, flags, rate }) => ({ code, flags, rate, taxableAmount: 0, amount: 0 })), total: 0, }; props.receipt.items.forEach((item) => { diff --git a/frontend/src/components/users/ContactInformation.vue b/frontend/src/components/users/ContactInformation.vue index 941a0a2e..9ab7a5f5 100644 --- a/frontend/src/components/users/ContactInformation.vue +++ b/frontend/src/components/users/ContactInformation.vue @@ -1,6 +1,6 @@ diff --git a/frontend/src/stores/__tests__/categories.spec.ts b/frontend/src/stores/__tests__/categories.spec.ts index b52cd27b..209e853e 100644 --- a/frontend/src/stores/__tests__/categories.spec.ts +++ b/frontend/src/stores/__tests__/categories.spec.ts @@ -53,12 +53,14 @@ const receipt: Receipt = { taxes: [ { code: "GST", + flags: "F", rate: 0.05, taxableAmount: 9.99, amount: 0.5, }, { code: "QST", + flags: "P", rate: 0.09975, taxableAmount: 9.99, amount: 1.0, diff --git a/frontend/src/types/receipts.ts b/frontend/src/types/receipts.ts index 2be64f4a..a0521bfd 100644 --- a/frontend/src/types/receipts.ts +++ b/frontend/src/types/receipts.ts @@ -81,6 +81,7 @@ export type ReceiptSortOption = SortOption & { export type ReceiptTax = { code: string; + flags: string; rate: number; taxableAmount: number; amount: number; diff --git a/frontend/src/views/receipts/ReceiptEdit.vue b/frontend/src/views/receipts/ReceiptEdit.vue index 02dec2bf..5d74e241 100644 --- a/frontend/src/views/receipts/ReceiptEdit.vue +++ b/frontend/src/views/receipts/ReceiptEdit.vue @@ -17,11 +17,9 @@ import ReceiptStatus from "@/components/receipts/ReceiptStatus.vue"; import StatusDetail from "@/components/shared/StatusDetail.vue"; import type { ApiError } from "@/types/api"; import type { CategorySavedEvent, Receipt, ReceiptItem } from "@/types/receipts"; -import type { Tax } from "@/types/taxes"; import { categorizeReceipt, deleteReceipt, readReceipt, replaceReceipt } from "@/api/receipts"; import { formatReceipt } from "@/helpers/displayUtils"; import { handleErrorKey } from "@/inject/App"; -import { searchTaxes } from "@/api/taxes"; import { useCategoryStore } from "@/stores/categories"; import { useToastStore } from "@/stores/toast"; @@ -39,7 +37,6 @@ const issuedOn = ref(); const itemEditRef = ref | null>(); const number = ref(""); const receipt = ref(); -const taxes = ref([]); const displayName = computed(() => (receipt.value ? formatReceipt(receipt.value) : "")); const hasChanges = computed(() => @@ -146,18 +143,6 @@ onMounted(async () => { const receipt = await readReceipt(id); setModel(receipt); } - taxes.value = ( - await searchTaxes({ - ids: [], - search: { - terms: [], - operator: "And", - }, - sort: [], - skip: 0, - limit: 0, - }) - ).items; } catch (e: unknown) { const { status } = e as ApiError; if (status === 404) { @@ -190,14 +175,7 @@ onMounted(async () => { - +