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

Completed tax refactor and fixed user profile postal address. #146

Merged
merged 1 commit into from
Apr 20, 2024
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
6 changes: 4 additions & 2 deletions backend/src/Faktur.Contracts/Receipts/ReceiptTax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
ReceiptId = table.Column<int>(type: "integer", nullable: false),
Code = table.Column<string>(type: "character varying(4)", maxLength: 4, nullable: false),
Flags = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
Rate = table.Column<double>(type: "double precision", nullable: false),
TaxableAmount = table.Column<decimal>(type: "money", nullable: false),
Amount = table.Column<decimal>(type: "money", nullable: false)
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<decimal>("Amount")
.HasColumnType("money");

b.Property<string>("Flags")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("character varying(10)");

b.Property<double>("Rate")
.HasColumnType("double precision");

Expand All @@ -607,6 +612,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("Code");

b.HasIndex("Flags");

b.HasIndex("Rate");

b.HasIndex("TaxableAmount");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,10 +14,12 @@ public void Configure(EntityTypeBuilder<ReceiptTaxEntity> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -28,6 +29,7 @@ private ReceiptTaxEntity()

public void Update(ReceiptTaxUnit tax)
{
Flags = tax.Flags.Value;
Rate = tax.Rate;
TaxableAmount = tax.TaxableAmount;
Amount = tax.Amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
ReceiptId = table.Column<int>(type: "int", nullable: false),
Code = table.Column<string>(type: "nvarchar(4)", maxLength: 4, nullable: false),
Flags = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
Rate = table.Column<double>(type: "float", nullable: false),
TaxableAmount = table.Column<decimal>(type: "money", nullable: false),
Amount = table.Column<decimal>(type: "money", nullable: false)
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<decimal>("Amount")
.HasColumnType("money");

b.Property<string>("Flags")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");

b.Property<double>("Rate")
.HasColumnType("float");

Expand All @@ -609,6 +614,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("Code");

b.HasIndex("Flags");

b.HasIndex("Rate");

b.HasIndex("TaxableAmount");
Expand Down
10 changes: 2 additions & 8 deletions frontend/src/components/receipts/ReceiptCategorization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -24,7 +23,6 @@ const props = withDefaults(
defineProps<{
processing?: boolean;
receipt: Receipt;
taxes: Tax[]; // TODO(fpion): should be included in receipt.taxes
}>(),
{
processing: false,
Expand All @@ -47,11 +45,7 @@ const groupedItems = computed<ItemGroup[]>(() => {
});
const taxFlags = computed<Map<string, string>>(() => {
const taxFlags = new Map<string, string>();
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;
});

Expand All @@ -68,7 +62,7 @@ const noCategoryClass = computed<string>(() => {
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) => {
Expand Down
51 changes: 28 additions & 23 deletions frontend/src/components/users/ContactInformation.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { TarButton } from "logitar-vue3-ui";
import { computed, ref, watchEffect } from "vue";
import { computed, ref, watch } from "vue";
import { useForm } from "vee-validate";
import { useI18n } from "vue-i18n";

Expand Down Expand Up @@ -87,27 +87,30 @@ function clearAddress(): void {
country.value = undefined;
}

watchEffect(() => {
const user: UserProfile = props.user;
address.value = {
street: user.address?.street ?? "",
locality: user.address?.locality ?? "",
postalCode: user.address?.postalCode ?? "",
region: user.address?.region ?? "",
country: user.address?.country ?? "",
isVerified: false,
};
country.value = address.value.country ? countries.find(({ code }) => code === address.value.country) : undefined;
email.value = {
address: user.email?.address ?? "",
isVerified: false,
};
phone.value = {
number: user.phone?.number ?? "",
extension: user.phone?.extension ?? "",
isVerified: false,
};
});
watch(
props.user,
(user) => {
address.value = {
street: user.address?.street ?? "",
locality: user.address?.locality ?? "",
postalCode: user.address?.postalCode ?? "",
region: user.address?.region ?? "",
country: user.address?.country ?? "",
isVerified: false,
};
country.value = address.value.country ? countries.find(({ code }) => code === address.value.country) : undefined;
email.value = {
address: user.email?.address ?? "",
isVerified: false,
};
phone.value = {
number: user.phone?.number ?? "",
extension: user.phone?.extension ?? "",
isVerified: false,
};
},
{ deep: true, immediate: true },
);
</script>

<template>
Expand All @@ -130,6 +133,8 @@ watchEffect(() => {
<AddressCountrySelect class="col-lg-6" :required="isAddressRequired" v-model="address.country" @selected="country = $event" />
<AddressRegionSelect class="col-lg-6" :country="country" :required="Boolean(country?.regions?.length)" v-model="address.region" />
</div>
<TarButton :disabled="!isAddressRequired" icon="fas fa-times" :text="t('actions.clear')" variant="warning" @click="clearAddress" />
<div class="mb-3">
<TarButton :disabled="!isAddressRequired" icon="fas fa-times" :text="t('actions.clear')" variant="warning" @click="clearAddress" />
</div>
</form>
</template>
2 changes: 2 additions & 0 deletions frontend/src/stores/__tests__/categories.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/receipts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type ReceiptSortOption = SortOption & {

export type ReceiptTax = {
code: string;
flags: string;
rate: number;
taxableAmount: number;
amount: number;
Expand Down
24 changes: 1 addition & 23 deletions frontend/src/views/receipts/ReceiptEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -39,7 +37,6 @@ const issuedOn = ref<Date>();
const itemEditRef = ref<InstanceType<typeof ReceiptItemEdit> | null>();
const number = ref<string>("");
const receipt = ref<Receipt>();
const taxes = ref<Tax[]>([]);

const displayName = computed<string>(() => (receipt.value ? formatReceipt(receipt.value) : ""));
const hasChanges = computed<boolean>(() =>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -190,14 +175,7 @@ onMounted(async () => {
</div>
<TarTabs>
<TarTab active id="items" :title="`${t('receipts.items.title')} (${receipt.itemCount})`">
<ReceiptCategorization
:processing="isProcessing"
:receipt="receipt"
ref="categorization"
:taxes="taxes"
@categorized="onCategorized"
@edit="onEdit"
/>
<ReceiptCategorization :processing="isProcessing" :receipt="receipt" ref="categorization" @categorized="onCategorized" @edit="onEdit" />
<ReceiptStatus :receipt="receipt" />
<ReceiptItemEdit ref="itemEditRef" @error="handleError" @saved="onItemSaved" />
</TarTab>
Expand Down