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.

2.3 KB
Raw Blame
// 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 { requirePermissions } from "@carbon/auth/auth.server";
import { getCutoverInventoryValuation } from "@carbon/database/accounting-cutover-reads";
import { msg } from "@lingui/core/macro";
import { Trans } from "@lingui/react/macro";
import type { LoaderFunctionArgs } from "react-router";
import { useLoaderData } from "react-router";
import { SetupBody, SetupSection } from "~/components/Setup";
import { getActivationCutover } from "~/modules/accounting/accounting.service";
import {
  ActivationFooter,
  InventoryCostTable
} from "~/modules/accounting/ui/Activation";
import { getDatabaseClient } from "~/services/database.server";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";

export const handle: Handle = {
  breadcrumb: msg`Inventory`,
  to: path.to.accountingActivationStep("inventory")
};

export async function loader({ request }: LoaderFunctionArgs) {
  const { client, companyId } = await requirePermissions(request, {
    view: "accounting"
  });
  const { cutoverDate } = await getActivationCutover(
    client,
    companyId,
    request
  );
  const inventory = await getCutoverInventoryValuation(getDatabaseClient(), {
    companyId,
    cutoverDate
  });
  return { cutoverDate, inventory };
}

/** Step 2: the stock the enable opens with, and the cost of each item. */
export default function AccountingActivationInventoryRoute() {
  const { cutoverDate, inventory } = useLoaderData<typeof loader>();

  return (
    <>
      <SetupBody>
        <SetupSection
          title={<Trans>Inventory</Trans>}
          description={
            <Trans>
              The enable resets each item's stock to its on-hand quantity at the
              cutover date, at the unit cost below. Review the cost of every
              Average item.
            </Trans>
          }
        >
          <InventoryCostTable
            items={inventory.items}
            accounts={inventory.accounts}
            total={inventory.total}
          />
        </SetupSection>
      </SetupBody>
      <ActivationFooter step="inventory" cutoverDate={cutoverDate} />
    </>
  );
}