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.

fix: income statement balance sheet calculations

Brad Barbine45e7925f991
diff --git a/apps/carbon/app/components/CreateableCombobox.tsx b/apps/carbon/app/components/CreateableCombobox.tsx
index c1633a6156..2afd41c8be 100644
--- a/apps/carbon/app/components/CreateableCombobox.tsx
+++ b/apps/carbon/app/components/CreateableCombobox.tsx
@@ -51,16 +51,17 @@ const CreatableCombobox = forwardRef<HTMLButtonElement, CreatableComboboxProps>(
},
ref
) => {
+ const [open, setOpen] = useState(false);
const [search, setSearch] = useState("");
const isExactMatch = options.some((option) =>
- [option.value.toLowerCase(), option.helper?.toLowerCase()].includes(
+ [option.label.toLowerCase(), option.helper?.toLowerCase()].includes(
search.toLowerCase()
)
);
return (
<HStack spacing={1}>
- <Popover>
+ <Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<CommandTrigger
size={size}
@@ -68,6 +69,7 @@ const CreatableCombobox = forwardRef<HTMLButtonElement, CreatableComboboxProps>(
className={cn("min-w-[160px]", !value && "text-muted-foreground")}
ref={ref}
{...props}
+ onClick={() => setOpen(true)}
>
{value
? options.find((option) => option.value === value)?.label
@@ -95,6 +97,7 @@ const CreatableCombobox = forwardRef<HTMLButtonElement, CreatableComboboxProps>(
key={option.value}
onSelect={() => {
if (!isSelected) onChange?.(option.value);
+ setOpen(false);
}}
>
{option.helper ? (
diff --git a/apps/carbon/app/components/Layout/Navigation/DetailSidebar.tsx b/apps/carbon/app/components/Layout/Navigation/DetailSidebar.tsx
index 59a90b5ae2..9356288ea9 100644
--- a/apps/carbon/app/components/Layout/Navigation/DetailSidebar.tsx
+++ b/apps/carbon/app/components/Layout/Navigation/DetailSidebar.tsx
@@ -1,5 +1,15 @@
-import { Button, Count, VStack } from "@carbon/react";
-import { Link, useMatches } from "@remix-run/react";
+import {
+ Button,
+ Count,
+ HStack,
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+ VStack,
+ useKeyboardShortcuts,
+} from "@carbon/react";
+import { Link, useMatches, useNavigate } from "@remix-run/react";
import type { IconType } from "react-icons";
type DetailSidebarProps = {
@@ -8,39 +18,60 @@ type DetailSidebarProps = {
to: string;
icon?: IconType;
count?: number;
+ shortcut?: string;
}[];
};
const DetailSidebar = ({ links }: DetailSidebarProps) => {
const matches = useMatches();
+ const navigate = useNavigate();
+
+ useKeyboardShortcuts(
+ links.reduce<Record<string, () => void>>((acc, link) => {
+ if (link.shortcut) {
+ acc[link.shortcut] = () => navigate(link.to);
+ }
+ return acc;
+ }, {})
+ );
return (
- <VStack className="overflow-y-auto h-full" spacing={1}>
- {links.map((route) => {
- const isActive = matches.some(
- (match) =>
- (match.pathname.includes(route.to) && route.to !== "") ||
- (match.id.includes(".index") && route.to === "")
- );
+ <TooltipProvider>
+ <VStack className="overflow-y-auto h-full" spacing={1}>
+ {links.map((route) => {
+ const isActive = matches.some(
+ (match) =>
+ (match.pathname.includes(route.to) && route.to !== "") ||
+ (match.id.includes(".index") && route.to === "")
+ );
- return (
- <Button
- key={route.name}
- asChild
- variant={isActive ? "primary" : "ghost"}
- className="w-full justify-start"
- >
- <Link to={route.to}>
- {route.icon && <route.icon className="mr-2" />}
- <span>{route.name}</span>
- {route.count !== undefined && (
- <Count count={route.count} className="ml-auto" />
+ return (
+ <Tooltip key={route.name}>
+ <TooltipTrigger className="w-full">
+ <Button
+ asChild
+ variant={isActive ? "primary" : "ghost"}
+ className="w-full justify-start"
+ >
+ <Link to={route.to}>
+ {route.icon && <route.icon className="mr-2" />}
+ <span>{route.name}</span>
+ {route.count !== undefined && (
+ <Count count={route.count} className="ml-auto" />
+ )}
+ </Link>
+ </Button>
+ </TooltipTrigger>
+ {route.shortcut && (
+ <TooltipContent side="right">
+ <HStack>{route.shortcut}</HStack>
+ </TooltipContent>
)}
- </Link>
- </Button>
- );
- })}
- </VStack>
+ </Tooltip>
+ );
+ })}
+ </VStack>
+ </TooltipProvider>
);
};
diff --git a/apps/carbon/app/modules/accounting/accounting.models.ts b/apps/carbon/app/modules/accounting/accounting.models.ts
index 6f60cfa56d..ce8451d27b 100644
--- a/apps/carbon/app/modules/accounting/accounting.models.ts
+++ b/apps/carbon/app/modules/accounting/accounting.models.ts
@@ -5,8 +5,8 @@ import { months } from "~/modules/shared";
export const accountTypes = [
"Posting",
- "Heading",
- // "Total",
+ // "Heading",
+ "Total",
"Begin Total",
"End Total",
] as const;
@@ -130,7 +130,7 @@ export const accountValidator = withZod(
)
.refine(
(data) => {
- if (!["Heading", "Begin Total", "End Total"].includes(data.type)) {
+ if (!["Total", "Begin Total", "End Total"].includes(data.type)) {
return !!data.accountCategoryId;
}
return true;
diff --git a/apps/carbon/app/modules/accounting/accounting.service.ts b/apps/carbon/app/modules/accounting/accounting.service.ts
index 7b543128f2..0a1d88adaf 100644
--- a/apps/carbon/app/modules/accounting/accounting.service.ts
+++ b/apps/carbon/app/modules/accounting/accounting.service.ts
@@ -29,7 +29,7 @@ function addLevelsAndTotalsToAccounts(
let hasHeading = false;
accounts.forEach((account) => {
- if (account.type === "End Total") {
+ if (["End Total", "Total"].includes(account.type)) {
endTotalAccounts.push(account.number);
}
@@ -42,14 +42,9 @@ function addLevelsAndTotalsToAccounts(
beginTotalAccounts.push(account.number);
}
- if (account.type === "Heading") {
- level = 0;
- hasHeading = true;
- }
-
let totaling = "";
- if (account.type === "End Total") {
+ if (["End Total", "Total"].includes(account.type)) {
let startAccount = beginTotalAccounts.pop();
let endAccount = endTotalAccounts.pop();
@@ -272,11 +267,30 @@ function getAccountTotal(
const [start, end] = account.totaling.split("..");
if (!start || !end) throw new Error("Invalid totaling");
- accounts.forEach((account) => {
- if (account.number >= start && account.number <= end) {
- total += transactionsByAccount[account.number]?.[type] ?? 0;
- }
- });
+ // for End Total -- we just do a simple sum of all accounts between start and end
+ if (account.type === "End Total") {
+ accounts.forEach((account) => {
+ if (account.number >= start && account.number <= end) {
+ total += transactionsByAccount[account.number]?.[type] ?? 0;
+ }
+ });
+ }
+
+ // for Total -- we use accounting equation to calculate the total
+ if (account.type === "Total") {
+ accounts.forEach((account) => {
+ if (account.number >= start && account.number <= end) {
+ if (["Asset", "Revenue"].includes(account.class as string)) {
+ total += transactionsByAccount[account.number]?.[type] ?? 0;
+ }
+ if (
+ ["Liability", "Equity", "Expense"].includes(account.class as string)
+ ) {
+ total -= transactionsByAccount[account.number]?.[type] ?? 0;
+ }
+ }
+ });
+ }
return total;
}
diff --git a/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountsTable.tsx b/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountsTable.tsx
index 3d3d938ad5..93bfd33a6c 100644
--- a/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountsTable.tsx
+++ b/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountsTable.tsx
@@ -69,7 +69,9 @@ const ChartOfAccountsTable = memo(({ data }: ChartOfAccountsTableProps) => {
accessorKey: "netChange",
header: "Net Change",
cell: ({ row }) => {
- const hasValue = ["Posting", "End Total"].includes(row.original.type);
+ const hasValue = ["Posting", "End Total", "Total"].includes(
+ row.original.type
+ );
return hasValue ? (row.original.netChange ?? 0).toFixed(2) : null;
},
},
@@ -77,7 +79,9 @@ const ChartOfAccountsTable = memo(({ data }: ChartOfAccountsTableProps) => {
accessorKey: "balanceAtDate",
header: "Balance at Date",
cell: ({ row }) => {
- const hasValue = ["Posting", "End Total"].includes(row.original.type);
+ const hasValue = ["Posting", "End Total", "Total"].includes(
+ row.original.type
+ );
return hasValue ? (row.original.balanceAtDate ?? 0).toFixed(2) : null;
},
},
@@ -85,7 +89,9 @@ const ChartOfAccountsTable = memo(({ data }: ChartOfAccountsTableProps) => {
accessorKey: "balance",
header: "Balance",
cell: ({ row }) => {
- const hasValue = ["Posting", "End Total"].includes(row.original.type);
+ const hasValue = ["Posting", "End Total", "Total"].includes(
+ row.original.type
+ );
return hasValue ? (row.original.balance ?? 0).toFixed(2) : null;
},
},
diff --git a/apps/carbon/app/modules/invoicing/invoicing.service.ts b/apps/carbon/app/modules/invoicing/invoicing.service.ts
index adc748fcf9..c38bfddaf3 100644
--- a/apps/carbon/app/modules/invoicing/invoicing.service.ts
+++ b/apps/carbon/app/modules/invoicing/invoicing.service.ts
@@ -80,7 +80,8 @@ export async function getPurchaseInvoiceLines(
return client
.from("purchaseInvoiceLine")
.select("*")
- .eq("invoiceId", purchaseInvoiceId);
+ .eq("invoiceId", purchaseInvoiceId)
+ .order("createdAt", { ascending: true });
}
export async function getPurchaseInvoiceLine(
diff --git a/apps/carbon/app/modules/purchasing/purchasing.service.ts b/apps/carbon/app/modules/purchasing/purchasing.service.ts
index 46414acddf..73b7b24d9a 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.service.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.service.ts
@@ -200,7 +200,8 @@ export async function getPurchaseOrderLines(
return client
.from("purchaseOrderLines")
.select("*")
- .eq("purchaseOrderId", purchaseOrderId);
+ .eq("purchaseOrderId", purchaseOrderId)
+ .order("createdAt", { ascending: true });
}
export async function getPurchaseOrderLine(
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderSidebar/usePurchaseOrderSidebar.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderSidebar/usePurchaseOrderSidebar.tsx
index 4ea49491e3..58936c1bc2 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderSidebar/usePurchaseOrderSidebar.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderSidebar/usePurchaseOrderSidebar.tsx
@@ -28,24 +28,28 @@ export function usePurchaseOrderSidebar({
name: "Summary",
to: path.to.purchaseOrderDetails(orderId),
icon: BsBank,
+ shortcut: "Command+Shift+s",
},
{
name: "Lines",
to: path.to.purchaseOrderLines(orderId),
count: lines,
icon: BsListCheck,
+ shortcut: "Command+Shift+l",
},
{
name: "Delivery",
to: path.to.purchaseOrderDelivery(orderId),
role: ["employee", "supplier"],
icon: BsTruck,
+ shortcut: "Command+Shift+d",
},
{
name: "Payment",
to: path.to.purchaseOrderPayment(orderId),
role: ["employee"],
icon: BsCreditCard,
+ shortcut: "Command+Shift+p",
},
{
name: "Internal Documents",
@@ -53,6 +57,7 @@ export function usePurchaseOrderSidebar({
role: ["employee"],
count: internalDocuments,
icon: HiOutlineDocumentArrowDown,
+ shortcut: "Command+Shift+i",
},
{
name: "External Documents",
@@ -60,6 +65,7 @@ export function usePurchaseOrderSidebar({
role: ["employee", "supplier"],
count: externalDocuments,
icon: HiOutlineDocumentArrowUp,
+ shortcut: "Command+Shift+e",
},
].filter(
(item) =>
diff --git a/apps/carbon/app/routes/onboarding+/company.tsx b/apps/carbon/app/routes/onboarding+/company.tsx
index 6b3b931321..83cae41c8a 100644
--- a/apps/carbon/app/routes/onboarding+/company.tsx
+++ b/apps/carbon/app/routes/onboarding+/company.tsx
@@ -144,7 +144,7 @@ export default function OnboardingCompany() {
<CardContent>
<Hidden name="next" value={next} />
<VStack spacing={4}>
- <Input name="name" label="Company Name" />
+ <Input autoFocus name="name" label="Company Name" />
<Input name="addressLine1" label="Address" />
<Input name="city" label="City" />
<Input name="state" label="State" />
diff --git a/apps/carbon/app/routes/onboarding+/user.tsx b/apps/carbon/app/routes/onboarding+/user.tsx
index 62ff009666..c05aa7d472 100644
--- a/apps/carbon/app/routes/onboarding+/user.tsx
+++ b/apps/carbon/app/routes/onboarding+/user.tsx
@@ -113,7 +113,7 @@ export default function OnboardingUser() {
<CardContent>
<Hidden name="next" value={next} />
<VStack spacing={4}>
- <Input name="firstName" label="First Name" />
+ <Input autoFocus name="firstName" label="First Name" />
<Input name="lastName" label="Last Name" />
<Input autoComplete="off" name="email" label="Email" />
<Password autoComplete="off" name="password" label="Password" />
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 58a8928195..2265b59fba 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -13016,7 +13016,7 @@ export type Database = {
| "Other Income"
| "Other Expense"
glAccountClass: "Asset" | "Liability" | "Equity" | "Revenue" | "Expense"
- glAccountType: "Posting" | "Heading" | "Begin Total" | "End Total"
+ glAccountType: "Posting" | "Total" | "Begin Total" | "End Total"
glConsolidatedRate: "Average" | "Current" | "Historical"
glIncomeBalance: "Balance Sheet" | "Income Statement"
journalLineDocumentType:
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 58a8928195..2265b59fba 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -13016,7 +13016,7 @@ export type Database = {
| "Other Income"
| "Other Expense"
glAccountClass: "Asset" | "Liability" | "Equity" | "Revenue" | "Expense"
- glAccountType: "Posting" | "Heading" | "Begin Total" | "End Total"
+ glAccountType: "Posting" | "Total" | "Begin Total" | "End Total"
glConsolidatedRate: "Average" | "Current" | "Historical"
glIncomeBalance: "Balance Sheet" | "Income Statement"
journalLineDocumentType:
diff --git a/packages/database/supabase/migrations/20230330024715_accounts.sql b/packages/database/supabase/migrations/20230330024715_accounts.sql
index b05e774b28..ea3001b5b1 100644
--- a/packages/database/supabase/migrations/20230330024715_accounts.sql
+++ b/packages/database/supabase/migrations/20230330024715_accounts.sql
@@ -84,8 +84,7 @@ CREATE TYPE "glIncomeBalance" AS ENUM (
CREATE TYPE "glAccountType" AS ENUM (
'Posting',
- 'Heading',
- -- 'Total',
+ 'Total',
'Begin Total',
'End Total'
);
diff --git a/packages/database/supabase/seed.sql b/packages/database/supabase/seed.sql
index e589977292..ecb6d803a4 100644
--- a/packages/database/supabase/seed.sql
+++ b/packages/database/supabase/seed.sql
@@ -245,7 +245,7 @@ VALUES
('51120', 'Customer Payment Discounts', 'Posting', 'cjgo71si60lg1aoj5pcg', NULL, 'Income Statement', 'Expense', 'Average', true, true, 'system'),
('51235', 'Rounding Account', 'Posting', 'cjgo71si60lg1aoj5pcg', NULL, 'Income Statement', 'Expense', 'Average', true, true, 'system'),
('51999', 'Interest, Total', 'End Total', 'cjgo71si60lg1aoj5pcg', NULL, 'Income Statement', 'Expense', 'Average', false, true, 'system'),
- ('79999', 'Income Statement, Total', 'End Total', 'cjgo71si60lg1aoj5pag', NULL, 'Income Statement', null, 'Average', true, true, 'system'),
+ ('79999', 'Income Statement, Total', 'Total', 'cjgo71si60lg1aoj5pag', NULL, 'Income Statement', null, 'Average', true, true, 'system'),
('80000', 'Balance Sheet', 'Begin Total', NULL, NULL, 'Balance Sheet', null, 'Average', false, true, 'system'),
('80001', 'Assets', 'Begin Total', NULL, NULL, 'Balance Sheet', 'Asset', 'Average', false, true, 'system'),
('81000', 'Fixed Assets', 'Begin Total', NULL, NULL, 'Balance Sheet', 'Asset', 'Average', false, true, 'system'),
@@ -278,7 +278,7 @@ VALUES
('95010', 'Retained Earnings', 'Posting', 'cjgo71si60lg1aoj5pa0', NULL, 'Balance Sheet', 'Equity', 'Average', false, true, 'system'),
('96010', 'Owner Equity', 'Posting', 'cjgo71si60lg1aoj5p90', NULL, 'Balance Sheet', 'Equity', 'Average', true, true, 'system'),
('96999', 'Equity, Total', 'End Total', NULL, NULL, 'Balance Sheet', 'Equity', 'Average', false, true, 'system'),
- ('99999', 'Balance Sheet, Total', 'End Total', NULL, NULL, 'Balance Sheet', null, 'Average', false, true, 'system');
+ ('99999', 'Balance Sheet, Total', 'Total', NULL, NULL, 'Balance Sheet', null, 'Average', false, true, 'system');
INSERT INTO public."accountDefault" (
"id",