Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: default accounts redesign

Brad Barbin6f5c4fdc2c6a
diff --git a/apps/erp/app/modules/accounting/accounting.models.ts b/apps/erp/app/modules/accounting/accounting.models.ts
index ac5cef14fc..70e780cfb1 100644
--- a/apps/erp/app/modules/accounting/accounting.models.ts
+++ b/apps/erp/app/modules/accounting/accounting.models.ts
@@ -306,6 +306,9 @@ export const defaultIncomeAcountValidator = z.object({
})
});
+export const defaultAccountValidator =
+ defaultBalanceSheetAccountValidator.merge(defaultIncomeAcountValidator);
+
export const paymentTermsCalculationMethod = [
"Net",
"End of Month",
diff --git a/apps/erp/app/modules/accounting/ui/AccountDefaults/AccountDefaultsForm.tsx b/apps/erp/app/modules/accounting/ui/AccountDefaults/AccountDefaultsForm.tsx
index dadc4c9374..b830ca2bd9 100644
--- a/apps/erp/app/modules/accounting/ui/AccountDefaults/AccountDefaultsForm.tsx
+++ b/apps/erp/app/modules/accounting/ui/AccountDefaults/AccountDefaultsForm.tsx
@@ -1,37 +1,403 @@
import { ValidatedForm } from "@carbon/form";
-import {
- Button,
- Card,
- CardContent,
- CardDescription,
- CardHeader,
- CardTitle,
- HStack,
- Tabs,
- TabsContent,
- TabsList,
- TabsTrigger
-} from "@carbon/react";
+import { Badge, Button, HStack } from "@carbon/react";
+import type { ReactNode } from "react";
+import { useMemo } from "react";
import { useNavigate } from "react-router";
-import { z } from "zod";
-import { Hidden, Select, Submit } from "~/components/Form";
+import { Combobox, Hidden, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
import { path } from "~/utils/path";
-import {
- defaultBalanceSheetAccountValidator,
- defaultIncomeAcountValidator
-} from "../../accounting.models";
+import { defaultAccountValidator } from "../../accounting.models";
import type { AccountListItem } from "../../types";
-const defaultUnion = z.union([
- defaultBalanceSheetAccountValidator,
- defaultIncomeAcountValidator
-]);
+type AccountType = "income" | "balance";
+
+type BadgeType = "Asset" | "Liability" | "Equity" | "Revenue" | "Expense";
+
+type AccountDefaultField = {
+ name: string;
+ label: string;
+ description: string;
+ accountType: AccountType;
+ badgeType: BadgeType;
+};
+
+type CategoryGroup = {
+ id: string;
+ title: string;
+ description: string;
+ fields: AccountDefaultField[];
+};
+
+const badgeColors: Record<BadgeType, string> = {
+ Asset: "green",
+ Liability: "red",
+ Equity: "blue",
+ Revenue: "yellow",
+ Expense: "orange"
+};
+
+const categoryGroups: CategoryGroup[] = [
+ // --- Assets ---
+ {
+ id: "cash-banking",
+ title: "Cash & Banking",
+ description: "Configure default accounts for cash and bank transactions",
+ fields: [
+ {
+ name: "bankCashAccount",
+ label: "Bank - Cash",
+ description: "Primary cash account for bank transactions",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "bankLocalCurrencyAccount",
+ label: "Bank - Local Currency",
+ description: "Bank account denominated in the local currency",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "bankForeignCurrencyAccount",
+ label: "Bank - Foreign Currency",
+ description: "Bank account denominated in a foreign currency",
+ accountType: "balance",
+ badgeType: "Asset"
+ }
+ ]
+ },
+ {
+ id: "receivables",
+ title: "Accounts Receivable",
+ description: "Default accounts for customer transactions and receivables",
+ fields: [
+ {
+ name: "receivablesAccount",
+ label: "Receivables",
+ description: "Accounts receivable for amounts owed by customers",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "prepaymentAccount",
+ label: "Prepayments",
+ description:
+ "Account for advance payments made before goods or services are received",
+ accountType: "balance",
+ badgeType: "Asset"
+ }
+ ]
+ },
+ {
+ id: "inventory",
+ title: "Inventory",
+ description: "Configure default accounts for inventory management",
+ fields: [
+ {
+ name: "inventoryAccount",
+ label: "Inventory",
+ description: "Primary account for on-hand inventory valuation",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "inventoryInterimAccrualAccount",
+ label: "Inventory Interim Accrual",
+ description:
+ "Interim accrual for inventory received but not yet invoiced",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "workInProgressAccount",
+ label: "Work in Progress (WIP)",
+ description: "Account for production orders not yet completed",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "inventoryInvoicedNotReceivedAccount",
+ label: "Inventory Invoiced Not Received",
+ description:
+ "Accrual for inventory invoiced but not yet physically received",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "inventoryShippedNotInvoicedAccount",
+ label: "Inventory Shipped Not Invoiced",
+ description:
+ "Accrual for inventory shipped but not yet invoiced to customer",
+ accountType: "balance",
+ badgeType: "Asset"
+ }
+ ]
+ },
+ {
+ id: "fixed-assets",
+ title: "Fixed Assets",
+ description: "Default accounts for long-term assets and depreciation",
+ fields: [
+ {
+ name: "assetAquisitionCostAccount",
+ label: "Asset Acquisition Cost",
+ description: "Account for the purchase cost of fixed assets",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "assetAquisitionCostOnDisposalAccount",
+ label: "Asset Cost on Disposal",
+ description: "Account for the cost of fixed assets when disposed",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "accumulatedDepreciationAccount",
+ label: "Accumulated Depreciation",
+ description:
+ "Contra-asset account for total depreciation of fixed assets",
+ accountType: "balance",
+ badgeType: "Asset"
+ },
+ {
+ name: "accumulatedDepreciationOnDisposalAccount",
+ label: "Accumulated Depreciation on Disposal",
+ description: "Depreciation reversal when a fixed asset is disposed",
+ accountType: "balance",
+ badgeType: "Asset"
+ }
+ ]
+ },
+ // --- Liabilities ---
+ {
+ id: "payables",
+ title: "Accounts Payable",
+ description:
+ "Configure default accounts for vendor and supplier transactions",
+ fields: [
+ {
+ name: "payablesAccount",
+ label: "Payables",
+ description: "Accounts payable for amounts owed to suppliers",
+ accountType: "balance",
+ badgeType: "Liability"
+ },
+ {
+ name: "inventoryReceivedNotInvoicedAccount",
+ label: "Inventory Received Not Invoiced",
+ description: "Accrual for inventory received but not yet invoiced",
+ accountType: "balance",
+ badgeType: "Liability"
+ }
+ ]
+ },
+ {
+ id: "taxes",
+ title: "Taxes",
+ description: "Default accounts for tax-related transactions",
+ fields: [
+ {
+ name: "salesTaxPayableAccount",
+ label: "Sales Tax Payable",
+ description: "Liability account for sales tax collected from customers",
+ accountType: "balance",
+ badgeType: "Liability"
+ },
+ {
+ name: "purchaseTaxPayableAccount",
+ label: "Purchase Tax Payable",
+ description: "Liability account for tax paid on purchases",
+ accountType: "balance",
+ badgeType: "Liability"
+ },
+ {
+ name: "reverseChargeSalesTaxPayableAccount",
+ label: "Reverse Charge Sales Tax",
+ description: "Tax liability for reverse-charge transactions",
+ accountType: "balance",
+ badgeType: "Liability"
+ }
+ ]
+ },
+ // --- Equity ---
+ {
+ id: "equity",
+ title: "Equity",
+ description: "Configure default equity and retained earnings accounts",
+ fields: [
+ {
+ name: "retainedEarningsAccount",
+ label: "Retained Earnings",
+ description: "Equity account for accumulated profits or losses",
+ accountType: "balance",
+ badgeType: "Equity"
+ }
+ ]
+ },
+ // --- Revenue ---
+ {
+ id: "revenue",
+ title: "Sales & Revenue",
+ description: "Default accounts for sales and income",
+ fields: [
+ {
+ name: "salesAccount",
+ label: "Sales",
+ description: "Default account for posting sales revenue from invoices",
+ accountType: "income",
+ badgeType: "Revenue"
+ },
+ {
+ name: "salesDiscountAccount",
+ label: "Sales Discounts",
+ description: "Contra-revenue account for discounts given on sales",
+ accountType: "income",
+ badgeType: "Revenue"
+ }
+ ]
+ },
+ // --- Expenses ---
+ {
+ id: "cogs",
+ title: "Purchasing & Cost of Goods",
+ description: "Configure default accounts for purchasing and COGS",
+ fields: [
+ {
+ name: "costOfGoodsSoldAccount",
+ label: "Cost of Goods Sold",
+ description: "Expense account for the cost of items sold",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "purchaseAccount",
+ label: "Purchases",
+ description:
+ "Account for recording raw material and inventory purchases",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "directCostAppliedAccount",
+ label: "Direct Cost Applied",
+ description: "Account for direct costs applied to production orders",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "overheadCostAppliedAccount",
+ label: "Overhead Cost Applied",
+ description: "Account for overhead costs applied to production orders",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "purchaseVarianceAccount",
+ label: "Purchase Variance",
+ description: "Variance between expected and actual purchase costs",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "inventoryAdjustmentVarianceAccount",
+ label: "Inventory Adjustment Variance",
+ description: "Variance from physical inventory count adjustments",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "materialVarianceAccount",
+ label: "Material Variance",
+ description: "Variance between standard and actual material costs",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "capacityVarianceAccount",
+ label: "Capacity Variance",
+ description: "Variance between standard and actual capacity costs",
+ accountType: "income",
+ badgeType: "Expense"
+ }
+ ]
+ },
+ {
+ id: "expenses",
+ title: "Operating Expenses",
+ description: "Default accounts for business expenses",
+ fields: [
+ {
+ name: "overheadAccount",
+ label: "Overhead",
+ description: "General overhead expense account for indirect costs",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "maintenanceAccount",
+ label: "Maintenance Expense",
+ description: "Expense account for equipment and facility maintenance",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "assetDepreciationExpenseAccount",
+ label: "Depreciation Expense",
+ description: "Periodic depreciation expense for fixed assets",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "assetGainsAndLossesAccount",
+ label: "Gains and Losses",
+ description: "Gains or losses recognized on disposal of fixed assets",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "serviceChargeAccount",
+ label: "Service Charges",
+ description: "Bank and financial service charge expenses",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "interestAccount",
+ label: "Interest",
+ description: "Interest income or expense from banking activities",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "supplierPaymentDiscountAccount",
+ label: "Supplier Payment Discounts",
+ description: "Discounts earned for early payment to suppliers",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "customerPaymentDiscountAccount",
+ label: "Customer Payment Discounts",
+ description: "Discounts given to customers for early payment",
+ accountType: "income",
+ badgeType: "Expense"
+ },
+ {
+ name: "roundingAccount",
+ label: "Rounding Account",
+ description: "Account for small rounding differences in transactions",
+ accountType: "income",
+ badgeType: "Expense"
+ }
+ ]
+ }
+];
type AccountDefaultsFormProps = {
balanceSheetAccounts: AccountListItem[];
incomeStatementAccounts: AccountListItem[];
- initialValues: z.infer<typeof defaultUnion>;
+ initialValues: Record<string, string>;
};
const AccountDefaultsForm = ({
@@ -45,280 +411,111 @@ const AccountDefaultsForm = ({
const isDisabled = !permissions.can("update", "accounting");
- const incomeStatementAccountOptions = incomeStatementAccounts.map((c) => ({
- value: c.number,
- label: `${c.number} - ${c.name}`
- }));
-
- const balanceSheetAccountOptions = balanceSheetAccounts.map((c) => ({
- value: c.number,
- label: `${c.number} - ${c.name}`
- }));
-
- const initialIncomeStatementValues =
- defaultIncomeAcountValidator.safeParse(initialValues);
- const initialBalanceSheetValues =
- defaultBalanceSheetAccountValidator.safeParse(initialValues);
+ const accountOptions: Record<
+ AccountType,
+ { value: string; label: ReactNode }[]
+ > = useMemo(
+ () => ({
+ income: incomeStatementAccounts.map((c) => ({
+ value: c.number,
+ label: (
+ <div className="flex items-center gap-2">
+ <span className="text-xs font-mono text-muted-foreground">
+ {c.number}
+ </span>
+ <span className="text-xs text-foreground truncate">{c.name}</span>
+ </div>
+ )
+ })),
+ balance: balanceSheetAccounts.map((c) => ({
+ value: c.number,
+ label: (
+ <div className="flex items-center gap-2">
+ <span className="text-xs font-mono text-muted-foreground">
+ {c.number}
+ </span>
+ <span className="text-xs text-foreground truncate">{c.name}</span>
+ </div>
+ )
+ }))
+ }),
+ [incomeStatementAccounts, balanceSheetAccounts]
+ );
return (
- <Card>
- <CardHeader>
- <CardTitle>Default Accounts</CardTitle>
- <CardDescription>
- These accounts are used in the absence of a more specific account from
- a posting group
- </CardDescription>
- </CardHeader>
- <CardContent>
- <Tabs defaultValue="income">
- <TabsList>
- <TabsTrigger value="income">Income Statement</TabsTrigger>
- <TabsTrigger value="balance">Balance Sheet</TabsTrigger>
- </TabsList>
-
- <TabsContent value="income" className="py-6">
- <ValidatedForm
- validator={defaultIncomeAcountValidator}
- method="post"
- action={path.to.accountingDefaults}
- defaultValues={initialIncomeStatementValues.data}
- className="w-full flex flex-col space-y-4"
- >
- <Hidden name="intent" value="income" />
- <div className="grid gap-y-4 gap-x-8 grid-cols-1 md:grid-cols-2">
- <Select
- name="salesAccount"
- label="Sales"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="salesDiscountAccount"
- label="Sales Discounts"
- options={incomeStatementAccountOptions}
- />
-
- <Select
- name="costOfGoodsSoldAccount"
- label="Cost of Goods Sold"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="purchaseAccount"
- label="Purchases"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="directCostAppliedAccount"
- label="Direct Cost Applied"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="overheadCostAppliedAccount"
- label="Overhead Cost Applied"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="purchaseVarianceAccount"
- label="Purchase Variance"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="inventoryAdjustmentVarianceAccount"
- label="Inventory Adjustment"
- options={incomeStatementAccountOptions}
- />
-
- <Select
- name="materialVarianceAccount"
- label="Material Variance"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="capacityVarianceAccount"
- label="Capacity Variance"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="overheadAccount"
- label="Overhead"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="maintenanceAccount"
- label="Maintenance Expense"
- options={incomeStatementAccountOptions}
- />
-
- <Select
- name="assetDepreciationExpenseAccount"
- label="Depreciation Expense"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="assetGainsAndLossesAccount"
- label="Gains and Losses"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="serviceChargeAccount"
- label="Service Charges"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="interestAccount"
- label="Interest"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="supplierPaymentDiscountAccount"
- label="Supplier Payment Discounts"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="customerPaymentDiscountAccount"
- label="Customer Payment Discounts"
- options={incomeStatementAccountOptions}
- />
- <Select
- name="roundingAccount"
- label="Rounding Account"
- options={incomeStatementAccountOptions}
- />
+ <ValidatedForm
+ validator={defaultAccountValidator}
+ method="post"
+ action={path.to.accountingDefaults}
+ defaultValues={initialValues}
+ className="w-full"
+ >
+ <Hidden name="intent" value="all" />
+ <div className="rounded-lg border border-border bg-card">
+ <div className="flex items-center justify-between border-b border-border p-6">
+ <div>
+ <h1 className="text-xl font-semibold text-foreground">
+ Default Accounts
+ </h1>
+ <p className="text-sm text-muted-foreground">
+ Configure the default accounts used for various transaction types
+ across your system
+ </p>
+ </div>
+ <HStack>
+ <Submit isDisabled={isDisabled}>Save</Submit>
+ <Button size="md" variant="solid" onClick={onClose}>
+ Cancel
+ </Button>
+ </HStack>
+ </div>
+ <div className="flex flex-col gap-8 p-6">
+ {categoryGroups.map((group) => (
+ <div key={group.id} className="border border-border rounded-lg">
+ <div className="py-6 px-4 border-b border-border">
+ <h2 className="text-base font-semibold text-foreground">
+ {group.title}
+ </h2>
+ <p className="text-xs text-muted-foreground">
+ {group.description}
+ </p>
</div>
- <HStack>
- <Submit isDisabled={isDisabled}>Save</Submit>
- <Button size="md" variant="solid" onClick={onClose}>
- Cancel
- </Button>
- </HStack>
- </ValidatedForm>
- </TabsContent>
- <TabsContent value="balance" className="py-6">
- <ValidatedForm
- validator={defaultBalanceSheetAccountValidator}
- method="post"
- action={path.to.accountingDefaults}
- defaultValues={initialBalanceSheetValues.data}
- className="w-full flex flex-col space-y-4"
- >
- <Hidden name="intent" value="balance" />
- <div className="grid gap-y-4 gap-x-8 grid-cols-1 md:grid-cols-2">
- <Select
- name="inventoryAccount"
- label="Inventory"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="inventoryInterimAccrualAccount"
- label="Inventory Interim Accrual"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="workInProgressAccount"
- label="Work in Progress (WIP)"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="receivablesAccount"
- label="Receivables"
- options={balanceSheetAccountOptions}
- />
-
- <Select
- name="inventoryInvoicedNotReceivedAccount"
- label="Inventory Invoiced Not Received"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="bankCashAccount"
- label="Bank - Cash"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="bankLocalCurrencyAccount"
- label="Bank - Local Currency"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="bankForeignCurrencyAccount"
- label="Bank - Foreign Currency"
- options={balanceSheetAccountOptions}
- />
-
- <Select
- name="assetAquisitionCostAccount"
- label="Asset Aquisition Cost"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="assetAquisitionCostOnDisposalAccount"
- label="Asset Cost on Disposal"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="accumulatedDepreciationAccount"
- label="Accumulated Depreciation"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="accumulatedDepreciationOnDisposalAccount"
- label="Accumulated Depreciation on Disposal"
- options={balanceSheetAccountOptions}
- />
-
- <Select
- name="prepaymentAccount"
- label="Prepayments"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="payablesAccount"
- label="Payables"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="inventoryReceivedNotInvoicedAccount"
- label="Inventory Received Not Invoiced"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="inventoryShippedNotInvoicedAccount"
- label="Inventory Shipped Not Invoiced"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="salesTaxPayableAccount"
- label="Sales Tax Payable"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="purchaseTaxPayableAccount"
- label="Purchase Tax Payable"
- options={balanceSheetAccountOptions}
- />
- <Select
- name="reverseChargeSalesTaxPayableAccount"
- label="Reverse Charge Sales Tax"
- options={balanceSheetAccountOptions}
- />
-
- <Select
- name="retainedEarningsAccount"
- label="Retained Earnings"
- options={balanceSheetAccountOptions}
- />
+ <div className="flex flex-col gap-3 p-4">
+ {group.fields.map((field) => (
+ <div
+ key={field.name}
+ className="group rounded-lg border border-border p-4 transition-all hover:border-muted-foreground/30"
+ >
+ <div className="flex items-start justify-between gap-4">
+ <div className="flex-1 min-w-0">
+ <div className="flex items-center gap-2 mb-1">
+ <h3 className="text-sm font-medium text-foreground">
+ {field.label}
+ </h3>
+ <Badge variant={badgeColors[field.badgeType]}>
+ {field.badgeType}
+ </Badge>
+ </div>
+ <p className="text-xs text-muted-foreground">
+ {field.description}
+ </p>
+ </div>
+ <div className="flex-shrink-0 w-64">
+ <Combobox
+ name={field.name}
+ options={accountOptions[field.accountType]}
+ size="sm"
+ />
+ </div>
+ </div>
+ </div>
+ ))}
</div>
- <HStack>
- <Submit isDisabled={isDisabled}>Save</Submit>
- <Button size="md" variant="solid" onClick={onClose}>
- Cancel
- </Button>
- </HStack>
- </ValidatedForm>
- </TabsContent>
- </Tabs>
- </CardContent>
- </Card>
+ </div>
+ ))}
+ </div>
+ </div>
+ </ValidatedForm>
);
};
diff --git a/apps/erp/app/modules/accounting/ui/useAccountingSubmodules.tsx b/apps/erp/app/modules/accounting/ui/useAccountingSubmodules.tsx
index 6526344f59..61834d14cc 100644
--- a/apps/erp/app/modules/accounting/ui/useAccountingSubmodules.tsx
+++ b/apps/erp/app/modules/accounting/ui/useAccountingSubmodules.tsx
@@ -1,4 +1,4 @@
-import { LuDollarSign, LuList } from "react-icons/lu";
+import { LuDollarSign, LuList, LuTarget } from "react-icons/lu";
import { usePermissions } from "~/hooks";
import type { AuthenticatedRouteGroup } from "~/types";
import { path } from "~/utils/path";
@@ -63,11 +63,12 @@ const accountingRoutes: AuthenticatedRouteGroup[] = [
role: "employee",
icon: <LuDollarSign />
},
- // {
- // name: "Default Accounts",
- // to: path.to.accountingDefaults,
- // role: "employee",
- // },
+ {
+ name: "Default Accounts",
+ to: path.to.accountingDefaults,
+ icon: <LuTarget />,
+ role: "employee"
+ },
// {
// name: "Fiscal Year",
// to: path.to.fiscalYears,
diff --git a/apps/erp/app/routes/x+/accounting+/_layout.tsx b/apps/erp/app/routes/x+/accounting+/_layout.tsx
index 70f25735c1..2f1de5239d 100644
--- a/apps/erp/app/routes/x+/accounting+/_layout.tsx
+++ b/apps/erp/app/routes/x+/accounting+/_layout.tsx
@@ -54,7 +54,7 @@ export default function AccountingRoute() {
return (
<CollapsibleSidebarProvider>
- <div className="grid grid-cols-[auto_1fr] w-full h-full">
+ <div className="grid grid-cols-[auto_1fr] w-full h-full bg-card">
<GroupedContentSidebar groups={groups} />
<VStack spacing={0} className="h-full">
<Outlet />
diff --git a/apps/erp/app/routes/x+/accounting+/defaults.tsx b/apps/erp/app/routes/x+/accounting+/defaults.tsx
index 7a25aca795..13c35da5ae 100644
--- a/apps/erp/app/routes/x+/accounting+/defaults.tsx
+++ b/apps/erp/app/routes/x+/accounting+/defaults.tsx
@@ -2,12 +2,13 @@ import { assertIsPost, error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
-import { VStack } from "@carbon/react";
+import { ScrollArea, VStack } from "@carbon/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
import { data, redirect, useLoaderData } from "react-router";
import { useRouteData } from "~/hooks";
import type { AccountListItem } from "~/modules/accounting";
import {
+ defaultAccountValidator,
defaultBalanceSheetAccountValidator,
defaultIncomeAcountValidator,
getDefaultAccounts,
@@ -56,8 +57,8 @@ export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData();
const intent = formData.get("intent") as string;
- if (intent === "income") {
- const validation = await validator(defaultIncomeAcountValidator).validate(
+ if (intent === "all") {
+ const validation = await validator(defaultAccountValidator).validate(
formData
);
@@ -65,52 +66,46 @@ export async function action({ request }: ActionFunctionArgs) {
return validationError(validation.error);
}
- const updateDefaults = await updateDefaultIncomeAccounts(client, {
- ...validation.data,
- companyId,
- updatedBy: userId
- });
- if (updateDefaults.error) {
- return data(
- {},
- await flash(
- request,
- error(updateDefaults.error, "Failed to update default accounts")
- )
- );
- }
-
- throw redirect(
- path.to.accountingDefaults,
- await flash(request, success("Updated income statement accounts"))
+ const incomeValidation = defaultIncomeAcountValidator.safeParse(
+ validation.data
+ );
+ const balanceValidation = defaultBalanceSheetAccountValidator.safeParse(
+ validation.data
);
- } else if (intent === "balance") {
- const validation = await validator(
- defaultBalanceSheetAccountValidator
- ).validate(formData);
- if (validation.error) {
- return validationError(validation.error);
+ if (!incomeValidation.success || !balanceValidation.success) {
+ throw new Error("Failed to parse default accounts");
}
- const updateDefaults = await updateDefaultBalanceSheetAccounts(client, {
- ...validation.data,
- companyId,
- updatedBy: userId
- });
- if (updateDefaults.error) {
+ const [updateIncome, updateBalance] = await Promise.all([
+ updateDefaultIncomeAccounts(client, {
+ ...incomeValidation.data,
+ companyId,
+ updatedBy: userId
+ }),
+ updateDefaultBalanceSheetAccounts(client, {
+ ...balanceValidation.data,
+ companyId,
+ updatedBy: userId
+ })
+ ]);
+
+ if (updateIncome.error || updateBalance.error) {
return data(
{},
await flash(
request,
- error(updateDefaults.error, "Failed to update default accounts")
+ error(
+ updateIncome.error || updateBalance.error,
+ "Failed to update default accounts"
+ )
)
);
}
throw redirect(
path.to.accountingDefaults,
- await flash(request, success("Updated balance sheet accounts"))
+ await flash(request, success("Updated default accounts"))
);
}
@@ -125,12 +120,17 @@ export default function AccountDefaultsRoute() {
}>(path.to.accounting);
return (
- <VStack className="h-full p-4 overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
- <AccountDefaultsForm
- balanceSheetAccounts={routeData?.balanceSheetAccounts ?? []}
- incomeStatementAccounts={routeData?.incomeStatementAccounts ?? []}
- initialValues={defaultAccounts}
- />
- </VStack>
+ <ScrollArea className="w-full h-[calc(100dvh-49px)]">
+ <VStack
+ spacing={4}
+ className="py-12 px-4 max-w-[60rem] h-full mx-auto gap-4"
+ >
+ <AccountDefaultsForm
+ balanceSheetAccounts={routeData?.balanceSheetAccounts ?? []}
+ incomeStatementAccounts={routeData?.incomeStatementAccounts ?? []}
+ initialValues={defaultAccounts}
+ />
+ </VStack>
+ </ScrollArea>
);
}
diff --git a/packages/react/src/Badge.tsx b/packages/react/src/Badge.tsx
index 89aff49813..e5fe464646 100644
--- a/packages/react/src/Badge.tsx
+++ b/packages/react/src/Badge.tsx
@@ -11,7 +11,7 @@ import { LuX } from "react-icons/lu";
import { cn } from "./utils/cn";
const badgeVariants = cva(
- "inline-flex items-center rounded-md px-2 min-h-[1.25rem] font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 uppercase font-bold text-[11px] truncate tracking-tight whitespace-nowrap",
+ "inline-flex items-center rounded-md px-2 min-h-[1.25rem] font-medium transition-colors border focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 font-bold text-[11px] truncate tracking-tight whitespace-nowrap",
{
variants: {
variant: {
@@ -23,16 +23,16 @@ const badgeVariants = cva(
"bg-destructive text-destructive-foreground shadow:sm dark:shadow hover:bg-destructive/80",
outline: "text-foreground border border-border",
green:
- "bg-emerald-100 text-emerald-800 dark:bg-emerald-900/50 dark:text-emerald-400",
+ "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-400 border-emerald-500/20",
yellow:
- "bg-yellow-100 text-yellow-800 dark:bg-yellow-900/50 dark:text-yellow-300",
+ "bg-yellow-100 text-yellow-800 dark:bg-yellow-500/15 dark:text-yellow-400 border-yellow-500/20",
orange:
- "bg-orange-100 text-orange-800 dark:bg-orange-900/50 dark:text-orange-300",
- red: "bg-red-100 text-red-800 dark:bg-red-900/50 dark:text-red-400",
- blue: "bg-blue-100 text-blue-800 dark:bg-blue-900/50 dark:text-blue-400",
- gray: "bg-[#e3e2e080] text-[#32302c] dark:bg-[#373737] dark:text-white hover:bg-[#e3e2e0] dark:hover:bg-[#5a5a5a]",
+ "bg-orange-100 text-orange-800 dark:bg-orange-500/15 dark:text-orange-400 border-orange-500/20",
+ red: "bg-red-100 text-red-800 dark:bg-red-500/15 dark:text-red-400 border-red-500/20",
+ blue: "bg-blue-100 text-blue-800 dark:bg-blue-500/15 dark:text-blue-400 border-blue-500/20",
+ gray: "bg-[#e3e2e080] text-[#32302c] dark:bg-[#373737] dark:text-white hover:bg-[#e3e2e0] dark:hover:bg-[#5a5a5a] ",
purple:
- "bg-violet-100 text-violet-800 dark:bg-violet-900/50 dark:text-violet-400"
+ "bg-violet-100 text-violet-800 dark:bg-violet-500/15 dark:text-violet-400"
}
},
defaultVariants: {