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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import { error, notFound } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { redirect } from "@carbon/utils";
import type { LoaderFunctionArgs } from "react-router";
import { useLoaderData } from "react-router";
import {
getAccount,
getAccountLedgerPage
} from "~/modules/accounting/accounting.service";
import { AccountLedgerDrawer } from "~/modules/accounting/ui/Reports";
import { path } from "~/utils/path";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client, companyId, companyGroupId } = await requirePermissions(
request,
{
view: "accounting",
role: "employee"
}
);
const { accountId } = params;
if (!accountId) throw notFound("accountId not found");
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
const companiesParam = searchParams.get("companies");
const startDate = searchParams.get("startDate") || null;
const endDate = searchParams.get("endDate") || null;
const isConsolidated = companiesParam === "all";
const selectedCompanyId = isConsolidated
? null
: (companiesParam ?? companyId);
const [account, ledger] = await Promise.all([
getAccount(client, accountId),
// A later page (`?after=`) is read for its lines only.
getAccountLedgerPage(client, {
accountId,
companyGroupId,
companyId: selectedCompanyId,
consolidated: isConsolidated,
startDate,
endDate,
after: searchParams.get("after")
})
]);
if (account.error || !account.data) {
throw redirect(
path.to.trialBalance,
await flash(request, error(account.error, "Failed to load account"))
);
}
return {
account: account.data,
...ledger,
startDate,
endDate
};
}
export default function TrialBalanceLedgerRoute() {
const { account, lines, count, nextCursor, summary, startDate, endDate } =
useLoaderData<typeof loader>();
return (
<AccountLedgerDrawer
account={account}
lines={lines}
count={count}
summary={summary}
startDate={startDate}
endDate={endDate}
nextCursor={nextCursor}
backTo={path.to.trialBalance}
/>
);
}