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.

Non-taxable add-ons for quotes, sales orders, and sales invoices (#586)

Brad Barbin91495ee1c5ba
diff --git a/apps/erp/app/modules/invoicing/invoicing.models.ts b/apps/erp/app/modules/invoicing/invoicing.models.ts
index c449169b4f..fa6e6ed7aa 100644
--- a/apps/erp/app/modules/invoicing/invoicing.models.ts
+++ b/apps/erp/app/modules/invoicing/invoicing.models.ts
@@ -228,6 +228,7 @@ export const salesInvoiceLineValidator = z
accountNumber: zfd.text(z.string().optional()),
assetId: zfd.text(z.string().optional()),
addOnCost: zfd.numeric(z.number().optional().default(0)),
+ nonTaxableAddOnCost: zfd.numeric(z.number().optional().default(0)),
description: zfd.text(z.string().optional()),
quantity: zfd.numeric(z.number().optional()),
unitOfMeasureCode: z
diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceExplorer.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceExplorer.tsx
index abecb36ac7..7882ebdd9d 100644
--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceExplorer.tsx
+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceExplorer.tsx
@@ -62,6 +62,7 @@ export default function SalesInvoiceExplorer() {
unitPrice: 0,
shippingCost: 0,
addOnCost: 0,
+ nonTaxableAddOnCost: 0,
taxAmount: 0,
exchangeRate: salesInvoiceData?.salesInvoice?.exchangeRate ?? 1
};
diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
index c073a50b88..ad05fcdd96 100644
--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx
@@ -7,7 +7,10 @@ import {
cn,
FormControl,
FormLabel,
+ HStack,
+ IconButton,
Input,
+ Label,
ModalCard,
ModalCardBody,
ModalCardContent,
@@ -17,11 +20,12 @@ import {
ModalCardProvider,
ModalCardTitle,
toast,
+ useDisclosure,
VStack
} from "@carbon/react";
import { getItemReadableId } from "@carbon/utils";
import { useEffect, useState } from "react";
-import { LuCircleAlert } from "react-icons/lu";
+import { LuChevronRight, LuCircleAlert, LuPlus, LuTruck } from "react-icons/lu";
import { useParams } from "react-router";
import type { z } from "zod";
import { MethodIcon } from "~/components";
@@ -131,6 +135,7 @@ const SalesInvoiceLineForm = ({
itemData.taxPercent
]);
+ const costsDisclosure = useDisclosure();
const isEditing = initialValues.id !== undefined;
const hasInvalidMethodType =
itemData.methodType === "Make" && !isSalesOrderLine;
@@ -309,9 +314,7 @@ const SalesInvoiceLineForm = ({
</Badge>
<Badge variant="green">
{currencyFormatter.format(
- (initialValues?.unitPrice ?? 0) +
- (initialValues?.addOnCost ?? 0) +
- (initialValues?.shippingCost ?? 0)
+ initialValues?.unitPrice ?? 0
)}{" "}
{initialValues?.unitOfMeasureCode}
</Badge>
@@ -436,58 +439,6 @@ const SalesInvoiceLineForm = ({
}))
}
/>
- <NumberControlled
- name="shippingCost"
- label="Shipping"
- value={itemData.shippingCost}
- minValue={0}
- formatOptions={{
- style: "currency",
- currency:
- routeData?.salesInvoice?.currencyCode ??
- company.baseCurrencyCode
- }}
- onChange={(value) =>
- setItemData((d) => ({
- ...d,
- shippingCost: value
- }))
- }
- />
-
- <Number
- name="addOnCost"
- label="Add On Cost"
- formatOptions={{
- style: "currency",
- currency:
- routeData?.salesInvoice?.currencyCode ??
- company.baseCurrencyCode
- }}
- />
-
- <NumberControlled
- name="taxAmount"
- label="Tax"
- value={itemData.taxAmount}
- formatOptions={{
- style: "currency",
- currency:
- routeData?.salesInvoice?.currencyCode ??
- company.baseCurrencyCode
- }}
- onChange={(value) => {
- const subtotal =
- itemData.unitPrice * itemData.quantity +
- itemData.shippingCost;
- setItemData((d) => ({
- ...d,
- taxAmount: value,
- taxPercent: subtotal > 0 ? value / subtotal : 0
- }));
- }}
- />
-
<Location
name="locationId"
label="Location"
@@ -510,31 +461,168 @@ const SalesInvoiceLineForm = ({
/>
</>
)}
- <NumberControlled
- name="taxPercent"
- label="Tax Percent"
- value={itemData.taxPercent}
- minValue={0}
- maxValue={1}
- step={0.0001}
- formatOptions={{
- style: "percent",
- minimumFractionDigits: 0,
- maximumFractionDigits: 2
- }}
- onChange={(value) => {
- const subtotal =
- itemData.unitPrice * itemData.quantity +
- itemData.shippingCost;
- setItemData((d) => ({
- ...d,
- taxPercent: value,
- taxAmount: subtotal * value
- }));
- }}
- />
<CustomFormFields table="salesInvoiceLine" />
</div>
+
+ {["Item", "Part", "Material", "Tool", "Consumable"].includes(
+ itemType
+ ) && (
+ <div className="w-full">
+ <div className="w-full border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 mt-4">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={costsDisclosure.onToggle}
+ >
+ <Label>Tax &amp; Additional Costs</Label>
+ <HStack>
+ {(itemData.taxPercent ?? 0) > 0 && (
+ <Badge variant="red">
+ {percentFormatter.format(
+ itemData.taxPercent ?? 0
+ )}{" "}
+ Tax
+ </Badge>
+ )}
+ {(itemData.shippingCost ?? 0) > 0 && (
+ <Badge
+ variant="secondary"
+ className="flex items-center gap-1"
+ >
+ <LuTruck />
+ <span>
+ {currencyFormatter.format(
+ itemData.shippingCost ?? 0
+ )}
+ </span>
+ </Badge>
+ )}
+ {(initialValues?.addOnCost ?? 0) > 0 ||
+ ((initialValues?.nonTaxableAddOnCost ?? 0) > 0 && (
+ <Badge
+ variant="secondary"
+ className="flex items-center gap-1"
+ >
+ <LuPlus />
+ <span>
+ {currencyFormatter.format(
+ (initialValues?.addOnCost ?? 0) +
+ (initialValues?.nonTaxableAddOnCost ?? 0)
+ )}{" "}
+ Add-On
+ </span>
+ </Badge>
+ ))}
+
+ <IconButton
+ icon={<LuChevronRight />}
+ aria-label={
+ costsDisclosure.isOpen
+ ? "Collapse Costs"
+ : "Expand Costs"
+ }
+ variant="ghost"
+ size="md"
+ onClick={(e) => {
+ e.stopPropagation();
+ costsDisclosure.onToggle();
+ }}
+ className={`transition-transform ${
+ costsDisclosure.isOpen ? "rotate-90" : ""
+ }`}
+ />
+ </HStack>
+ </HStack>
+ <div
+ className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
+ costsDisclosure.isOpen ? "" : "hidden"
+ }`}
+ >
+ <NumberControlled
+ name="taxPercent"
+ label="Tax Percent"
+ value={itemData.taxPercent}
+ minValue={0}
+ maxValue={1}
+ step={0.0001}
+ formatOptions={{
+ style: "percent",
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 2
+ }}
+ onChange={(value) => {
+ const subtotal =
+ itemData.unitPrice * itemData.quantity +
+ itemData.shippingCost;
+ setItemData((d) => ({
+ ...d,
+ taxPercent: value,
+ taxAmount: subtotal * value
+ }));
+ }}
+ />
+ <NumberControlled
+ name="taxAmount"
+ label="Tax Amount"
+ value={itemData.taxAmount}
+ formatOptions={{
+ style: "currency",
+ currency:
+ routeData?.salesInvoice?.currencyCode ??
+ company.baseCurrencyCode
+ }}
+ onChange={(value) => {
+ const subtotal =
+ itemData.unitPrice * itemData.quantity +
+ itemData.shippingCost;
+ setItemData((d) => ({
+ ...d,
+ taxAmount: value,
+ taxPercent: subtotal > 0 ? value / subtotal : 0
+ }));
+ }}
+ />
+ <NumberControlled
+ name="shippingCost"
+ label="Shipping Cost"
+ value={itemData.shippingCost}
+ minValue={0}
+ formatOptions={{
+ style: "currency",
+ currency:
+ routeData?.salesInvoice?.currencyCode ??
+ company.baseCurrencyCode
+ }}
+ onChange={(value) =>
+ setItemData((d) => ({
+ ...d,
+ shippingCost: value
+ }))
+ }
+ />
+ <Number
+ name="addOnCost"
+ label="Add-On Cost"
+ formatOptions={{
+ style: "currency",
+ currency:
+ routeData?.salesInvoice?.currencyCode ??
+ company.baseCurrencyCode
+ }}
+ />
+ <Number
+ name="nonTaxableAddOnCost"
+ label="Non-Taxable Add-On Cost"
+ formatOptions={{
+ style: "currency",
+ currency:
+ routeData?.salesInvoice?.currencyCode ??
+ company.baseCurrencyCode
+ }}
+ />
+ </div>
+ </div>
+ </div>
+ )}
</VStack>
</ModalCardBody>
<ModalCardFooter>
diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsx
index f05305fe30..e4e62e1a52 100644
--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsx
+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsx
@@ -77,12 +77,14 @@ const LineItems = ({
(line.convertedUnitPrice ?? 0) * (line.quantity ?? 0);
const total =
(lineSubtotal + (line.addOnCost ?? 0) + (line.shippingCost ?? 0)) *
- (1 + (line.taxPercent ?? 0));
+ (1 + (line.taxPercent ?? 0)) +
+ (line.nonTaxableAddOnCost ?? 0);
const customerTotal =
(customerSubtotal +
(line.convertedAddOnCost ?? 0) +
(line.convertedShippingCost ?? 0)) *
- (1 + (line.taxPercent ?? 0));
+ (1 + (line.taxPercent ?? 0)) +
+ (line.convertedNonTaxableAddOnCost ?? 0);
const lineTaxAmount =
(line.taxPercent ?? 0) *
@@ -357,7 +359,8 @@ const SalesInvoiceSummary = ({
const lineSubtotal =
(line.unitPrice ?? 0) * (line.quantity ?? 0) +
(line.shippingCost ?? 0) +
- (line.addOnCost ?? 0);
+ (line.addOnCost ?? 0) +
+ (line.nonTaxableAddOnCost ?? 0);
return acc + lineSubtotal;
}, 0) ?? 0;
@@ -366,7 +369,8 @@ const SalesInvoiceSummary = ({
const lineSubtotal =
(line.convertedUnitPrice ?? 0) * (line.quantity ?? 0) +
(line.convertedShippingCost ?? 0) +
- (line.convertedAddOnCost ?? 0);
+ (line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0);
return acc + lineSubtotal;
}, 0) ?? 0;
diff --git a/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchProperties.tsx b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchProperties.tsx
index eb553247ec..c1313b33a4 100644
--- a/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchProperties.tsx
+++ b/apps/erp/app/modules/resources/ui/Maintenance/MaintenanceDispatchProperties.tsx
@@ -70,8 +70,6 @@ const MaintenanceDispatchProperties = () => {
? optimisticAssignment
: (routeData?.dispatch?.assignee?.id ?? null);
- console.log({ optimisticAssignment, routeData: routeData?.dispatch });
-
const fetcher = useFetcher<{ error?: { message: string } }>();
const eventFetcher = useFetcher<{ error?: { message: string } }>();
diff --git a/apps/erp/app/modules/sales/sales.models.ts b/apps/erp/app/modules/sales/sales.models.ts
index 8e6aaeccb9..5169106c68 100644
--- a/apps/erp/app/modules/sales/sales.models.ts
+++ b/apps/erp/app/modules/sales/sales.models.ts
@@ -188,7 +188,8 @@ export const quoteValidator = z.object({
export const quoteLineAdditionalChargesValidator = z.record(
z.object({
description: z.string(),
- amounts: z.record(z.number())
+ amounts: z.record(z.number()),
+ taxable: z.boolean().default(true)
})
);
@@ -640,6 +641,7 @@ export const salesOrderLineValidator = z
accountNumber: zfd.text(z.string().optional()),
shippingCost: zfd.numeric(z.number().optional()),
addOnCost: zfd.numeric(z.number().optional()),
+ nonTaxableAddOnCost: zfd.numeric(z.number().optional()),
assetId: zfd.text(z.string().optional()),
description: zfd.text(z.string().optional()),
itemId: zfd.text(z.string().optional()),
@@ -775,6 +777,8 @@ export const salesRfqLineValidator = z.object({
export const selectedLineSchema = z.object({
addOn: z.number().optional(),
convertedAddOn: z.number().optional(),
+ taxableAddOn: z.number().optional(),
+ convertedTaxableAddOn: z.number().optional(),
convertedNetUnitPrice: z.number(),
convertedShippingCost: z.number(),
leadTime: z.number(),
diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.ts
index e709a64919..37ea263d62 100644
--- a/apps/erp/app/modules/sales/sales.service.ts
+++ b/apps/erp/app/modules/sales/sales.service.ts
@@ -9,6 +9,7 @@ import type {
} from "@supabase/supabase-js";
import { FunctionRegion } from "@supabase/supabase-js";
import type { z } from "zod";
+import { getSupplierPriceBreaksForItems } from "~/modules/items/items.service";
import { getEmployeeJob } from "~/modules/people";
import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
@@ -19,7 +20,10 @@ import type {
operationStepValidator,
operationToolValidator
} from "../shared";
-import { upsertExternalLink } from "../shared/shared.service";
+import {
+ lookupBuyPriceFromMap,
+ upsertExternalLink
+} from "../shared/shared.service";
import type {
customerAccountingValidator,
customerContactValidator,
@@ -48,6 +52,7 @@ import type {
salesRfqValidator,
selectedLinesValidator
} from "./sales.models";
+import { costCategoryKeys } from "./sales.models";
import type { Quotation, SalesOrder, SalesRFQ } from "./types";
export async function closeSalesOrder(
@@ -2310,23 +2315,18 @@ export async function upsertQuoteLinePrices(
};
});
- return client
- .from("quoteLinePrice")
- .insert(pricesWithExistingDiscountsAndLeadTimes);
+ return (
+ client
+ .from("quoteLinePrice")
+ // @ts-expect-error - categoryMarkups is a Json object
+ .insert(pricesWithExistingDiscountsAndLeadTimes)
+ );
}
async function buildCostEffects(
client: SupabaseClient<Database>,
quoteLineId: string
) {
- const { getSupplierPriceBreaksForItems } = await import(
- "~/modules/items/items.service"
- );
- const { lookupBuyPriceFromMap } = await import(
- "~/modules/shared/shared.service"
- );
- const { costCategoryKeys } = await import("~/modules/sales/sales.models");
-
const operationsResult = await client
.from("quoteOperation")
.select("*")
@@ -2601,8 +2601,6 @@ export async function calculatePricesForQuantities(
) {
if (!quantities.length) return;
- const { costCategoryKeys } = await import("~/modules/sales/sales.models");
-
// 1. Fetch quote (with companyId) and line in parallel
const [quoteResult, lineResult] = await Promise.all([
client
@@ -2683,8 +2681,6 @@ export async function recalculateQuoteLinePrices(
quoteLineId: string,
userId: string
) {
- const { costCategoryKeys } = await import("~/modules/sales/sales.models");
-
// 1. Fetch existing price rows
const existingPrices = await client
.from("quoteLinePrice")
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
index 0eafe2e3cc..5c4ca8ffa1 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
@@ -17,6 +17,7 @@ import {
Input,
NumberField,
NumberInput,
+ Switch,
Table,
Tbody,
Td,
@@ -195,6 +196,13 @@ const QuoteLinePricing = ({
return charges;
});
+ const taxableAdditionalChargesByQuantity = quantities.map((quantity) => {
+ return Object.values(additionalCharges).reduce((acc, charge) => {
+ if (charge.taxable === false) return acc;
+ return acc + (charge.amounts?.[quantity] ?? 0);
+ }, 0);
+ });
+
const onUpdateChargeDescription = useCallback(
async (chargeId: string, description: string) => {
const updatedCharges = {
@@ -260,6 +268,34 @@ const QuoteLinePricing = ({
[additionalCharges, carbon, lineId]
);
+ const onUpdateChargeTaxable = useCallback(
+ async (chargeId: string, taxable: boolean) => {
+ const updatedCharges = {
+ ...additionalCharges,
+ [chargeId]: {
+ ...additionalCharges[chargeId],
+ taxable
+ }
+ };
+
+ setEditableFields((prev) => ({
+ ...prev,
+ additionalCharges: updatedCharges
+ }));
+
+ const costUpdate = await carbon
+ ?.from("quoteLine")
+ .update({ additionalCharges: updatedCharges })
+ .eq("id", lineId);
+
+ if (costUpdate?.error) {
+ console.error(costUpdate.error);
+ toast.error("Failed to update quote line");
+ }
+ },
+ [additionalCharges, lineId, carbon]
+ );
+
const costsByQuantity = quantities.map((quantity) => {
const costs = getLineCosts(quantity);
return {
@@ -1055,7 +1091,23 @@ const QuoteLinePricing = ({
}
}}
/>
- <HStack spacing={1}>
+ <HStack spacing={1} className="items-center pr-1">
+ <Tooltip>
+ <TooltipTrigger>
+ <Switch
+ variant="small"
+ checked={charge.taxable !== false}
+ disabled={!isEditable}
+ onCheckedChange={(checked) =>
+ onUpdateChargeTaxable(
+ chargeId,
+ checked === true
+ )
+ }
+ />
+ </TooltipTrigger>
+ <TooltipContent>Taxable</TooltipContent>
+ </Tooltip>
<fetcher.Form
method="post"
action={path.to.deleteQuoteLineCost(
@@ -1230,7 +1282,11 @@ const QuoteLinePricing = ({
(netPricesByQuantity[index] ?? 0) * quantity +
(editableFields.prices[quantity]?.shippingCost ?? 0) +
(additionalChargesByQuantity[index] ?? 0);
- const tax = subtotal * editableFields.taxPercent;
+ const taxableSubtotal =
+ (netPricesByQuantity[index] ?? 0) * quantity +
+ (editableFields.prices[quantity]?.shippingCost ?? 0) +
+ (taxableAdditionalChargesByQuantity[index] ?? 0);
+ const tax = taxableSubtotal * editableFields.taxPercent;
const price = subtotal + tax;
return (
<Td key={index} className="group-hover:bg-muted/50">
@@ -1272,7 +1328,11 @@ const QuoteLinePricing = ({
(netPricesByQuantity[index] ?? 0) * quantity +
(editableFields.prices[quantity]?.shippingCost ?? 0) +
(additionalChargesByQuantity[index] ?? 0);
- const tax = subtotal * editableFields.taxPercent;
+ const taxableSubtotal =
+ (netPricesByQuantity[index] ?? 0) * quantity +
+ (editableFields.prices[quantity]?.shippingCost ?? 0) +
+ (taxableAdditionalChargesByQuantity[index] ?? 0);
+ const tax = taxableSubtotal * editableFields.taxPercent;
const price = subtotal + tax;
const exchangeRate =
editableFields.prices[quantity]?.exchangeRate;
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteSummary.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteSummary.tsx
index c11f9f3a23..d36a8eba08 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteSummary.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteSummary.tsx
@@ -43,6 +43,8 @@ type SelectedLine = {
convertedNetUnitPrice: number;
addOn: number;
convertedAddOn: number;
+ taxableAddOn: number;
+ convertedTaxableAddOn: number;
leadTime: number;
shippingCost: number;
convertedShippingCost: number;
@@ -55,6 +57,8 @@ type SelectedLine = {
const deselectedLine: SelectedLine = {
addOn: 0,
convertedAddOn: 0,
+ taxableAddOn: 0,
+ convertedTaxableAddOn: 0,
netUnitPrice: 0,
convertedNetUnitPrice: 0,
quantity: 0,
@@ -184,11 +188,15 @@ const LineItems = ({
<MotionNumber
className="font-bold text-xl"
value={
+ (selectedLine.convertedNetUnitPrice ?? 0) *
+ (selectedLine.quantity ?? 0) +
+ (selectedLine.convertedAddOn ?? 0) +
+ (selectedLine.convertedShippingCost ?? 0) +
((selectedLine.convertedNetUnitPrice ?? 0) *
(selectedLine.quantity ?? 0) +
- (selectedLine.convertedAddOn ?? 0) +
+ (selectedLine.convertedTaxableAddOn ?? 0) +
(selectedLine.convertedShippingCost ?? 0)) *
- (1 + (selectedLine.taxPercent ?? 0))
+ (selectedLine.taxPercent ?? 0)
}
format={{
style: "currency",
@@ -303,6 +311,33 @@ const LinePricingOptions = ({
{ 0: 0 }
);
+ const taxableAdditionalChargesByQuantity =
+ line.quantity?.reduce(
+ (acc, quantity) => {
+ const charges = Object.values(line.additionalCharges ?? {}).reduce(
+ (chargeAcc, charge) => {
+ if (charge.taxable === false) return chargeAcc;
+ const amount = charge.amounts?.[quantity];
+ return chargeAcc + amount;
+ },
+ 0
+ );
+ acc[quantity] = charges;
+ return acc;
+ },
+ { 0: 0 } as Record<number, number>
+ ) ?? {};
+
+ const convertedTaxableAdditionalChargesByQuantity = Object.entries(
+ taxableAdditionalChargesByQuantity
+ ).reduce<Record<number, number>>(
+ (acc, [quantity, amount]) => {
+ acc[Number(quantity)] = amount * quoteExchangeRate;
+ return acc;
+ },
+ { 0: 0 }
+ );
+
const additionalCharges: { name: string; amount: number }[] = [];
if (selectedLine.convertedShippingCost) {
additionalCharges.push({
@@ -352,6 +387,13 @@ const LinePricingOptions = ({
convertedAdditionalChargesByQuantity[
selectedOption.quantity
] || 0,
+ taxableAddOn:
+ taxableAdditionalChargesByQuantity[selectedOption.quantity] ||
+ 0,
+ convertedTaxableAddOn:
+ convertedTaxableAdditionalChargesByQuantity[
+ selectedOption.quantity
+ ] || 0,
leadTime: selectedOption.leadTime,
shippingCost: selectedOption.shippingCost ?? 0,
convertedShippingCost:
@@ -550,7 +592,7 @@ const LinePricingOptions = ({
value={
((selectedLine.convertedNetUnitPrice ?? 0) *
selectedLine.quantity +
- (selectedLine.convertedAddOn ?? 0) +
+ (selectedLine.convertedTaxableAddOn ?? 0) +
(selectedLine.convertedShippingCost ?? 0)) *
(selectedLine.taxPercent ?? 0)
}
@@ -568,11 +610,15 @@ const LinePricingOptions = ({
<Td className="text-right">
<MotionNumber
value={
+ (selectedLine.convertedNetUnitPrice ?? 0) *
+ selectedLine.quantity +
+ (selectedLine.convertedAddOn ?? 0) +
+ (selectedLine.convertedShippingCost ?? 0) +
((selectedLine.convertedNetUnitPrice ?? 0) *
selectedLine.quantity +
- (selectedLine.convertedAddOn ?? 0) +
+ (selectedLine.convertedTaxableAddOn ?? 0) +
(selectedLine.convertedShippingCost ?? 0)) *
- (1 + (selectedLine.taxPercent ?? 0))
+ (selectedLine.taxPercent ?? 0)
}
format={{
style: "currency",
@@ -682,6 +728,34 @@ const QuoteSummary = ({
{} as Record<number, number>
) ?? {};
+ const taxableAdditionalChargesByQuantity =
+ line.quantity?.reduce(
+ (acc, quantity) => {
+ const charges = Object.values(
+ line.additionalCharges ?? {}
+ ).reduce((chargeAcc, charge) => {
+ if (charge.taxable === false) return chargeAcc;
+ const amount = charge.amounts?.[quantity];
+ return chargeAcc + amount;
+ }, 0);
+ acc[quantity] = charges;
+ return acc;
+ },
+ {} as Record<number, number>
+ ) ?? {};
+
+ const convertedTaxableAdditionalChargesByQuantity =
+ Object.entries(taxableAdditionalChargesByQuantity).reduce<
+ Record<number, number>
+ >(
+ (acc, [quantity, amount]) => {
+ acc[Number(quantity)] =
+ amount * (routeData?.quote.exchangeRate ?? 1);
+ return acc;
+ },
+ {} as Record<number, number>
+ ) ?? {};
+
acc[line.id] = {
quantity: price.quantity ?? 0,
netUnitPrice: price.netUnitPrice ?? 0,
@@ -689,6 +763,9 @@ const QuoteSummary = ({
addOn: additionalChargesByQuantity[price.quantity] || 0,
convertedAddOn:
convertedAdditionalChargesByQuantity[price.quantity] || 0,
+ taxableAddOn: taxableAdditionalChargesByQuantity[price.quantity] || 0,
+ convertedTaxableAddOn:
+ convertedTaxableAdditionalChargesByQuantity[price.quantity] || 0,
leadTime: price.leadTime,
shippingCost: price.shippingCost ?? 0,
convertedShippingCost: price.convertedShippingCost ?? 0,
@@ -722,7 +799,7 @@ const QuoteSummary = ({
return (
acc +
((line.convertedNetUnitPrice ?? 0) * line.quantity +
- (line.convertedAddOn ?? 0) +
+ (line.convertedTaxableAddOn ?? 0) +
(line.convertedShippingCost ?? 0)) *
(line.taxPercent ?? 0)
);
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx
index dc47191a84..ca6d402b2e 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx
@@ -532,6 +532,30 @@ const LinePricingOptions = ({
return acc;
}, {});
+ const taxableAdditionalChargesByQuantity =
+ line.quantity?.reduce(
+ (acc, quantity) => {
+ const charges = Object.values(line.additionalCharges ?? {}).reduce(
+ (chargeAcc, charge) => {
+ if (charge.taxable === false) return chargeAcc;
+ const amount = charge.amounts?.[quantity];
+ return chargeAcc + amount;
+ },
+ 0
+ );
+ acc[quantity] = charges;
+ return acc;
+ },
+ {} as Record<number, number>
+ ) ?? {};
+
+ const convertedTaxableAdditionalChargesByQuantity = Object.entries(
+ taxableAdditionalChargesByQuantity
+ ).reduce<Record<number, number>>((acc, [quantity, amount]) => {
+ acc[Number(quantity)] = amount * quoteExchangeRate;
+ return acc;
+ }, {});
+
// Sort options by quantity from least to greatest
const sortedOptions = [...options].sort((a, b) => a.quantity - b.quantity);
@@ -560,6 +584,13 @@ const LinePricingOptions = ({
convertedAdditionalChargesByQuantity[
selectedOption.quantity
] || 0,
+ taxableAddOn:
+ taxableAdditionalChargesByQuantity[selectedOption.quantity] ||
+ 0,
+ convertedTaxableAddOn:
+ convertedTaxableAdditionalChargesByQuantity[
+ selectedOption.quantity
+ ] || 0,
shippingCost: selectedOption.shippingCost ?? 0,
convertedShippingCost:
selectedOption.convertedShippingCost ?? 0,
diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderExplorer.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderExplorer.tsx
index d6b742ed8f..9649579f83 100644
--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderExplorer.tsx
+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderExplorer.tsx
@@ -133,6 +133,7 @@ export default function SalesOrderExplorer() {
saleQuantity: 1,
unitPrice: 0,
addOnCost: 0,
+ nonTaxableAddOnCost: 0,
locationId:
salesOrderData?.salesOrder?.locationId ?? defaults.locationId ?? "",
taxPercent: salesOrderData?.customer?.taxPercent ?? 0,
diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx
index 089c1d5040..7a53f3051d 100644
--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx
+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx
@@ -12,6 +12,7 @@ import {
DropdownMenuTrigger,
HStack,
IconButton,
+ Label,
ModalCard,
ModalCardBody,
ModalCardContent,
@@ -26,7 +27,7 @@ import {
import { getItemReadableId } from "@carbon/utils";
import { useState } from "react";
import { BsThreeDotsVertical } from "react-icons/bs";
-import { LuTrash } from "react-icons/lu";
+import { LuChevronRight, LuPlus, LuTrash, LuTruck } from "react-icons/lu";
import { useParams } from "react-router";
import type { z } from "zod";
import { MethodIcon } from "~/components";
@@ -191,6 +192,7 @@ const SalesOrderLineForm = ({
}));
};
+ const costsDisclosure = useDisclosure();
const deleteDisclosure = useDisclosure();
const [items] = useItems();
@@ -243,9 +245,7 @@ const SalesOrderLineForm = ({
</Badge>
<Badge variant="green">
{currencyFormatter.format(
- (initialValues?.unitPrice ?? 0) +
- (initialValues?.addOnCost ?? 0) +
- (initialValues?.shippingCost ?? 0)
+ initialValues?.unitPrice ?? 0
)}{" "}
{initialValues?.unitOfMeasureCode}
</Badge>
@@ -377,37 +377,6 @@ const SalesOrderLineForm = ({
}))
}
/>
- <Number
- name="shippingCost"
- label="Shipping Cost"
- minValue={0}
- formatOptions={{
- style: "currency",
- currency: baseCurrency
- }}
- />
- <Number
- name="addOnCost"
- label="Add-On Cost"
- formatOptions={{
- style: "currency",
- currency: baseCurrency
- }}
- />
-
- <Number
- name="taxPercent"
- label="Tax Percent"
- minValue={0}
- maxValue={1}
- step={0.0001}
- formatOptions={{
- style: "percent",
- minimumFractionDigits: 0,
- maximumFractionDigits: 2
- }}
- />
-
<DatePicker name="promisedDate" label="Promised Date" />
{[
"Part",
@@ -449,6 +418,121 @@ const SalesOrderLineForm = ({
)}
<CustomFormFields table="salesOrderLine" />
</div>
+
+ {lineType !== "Comment" && (
+ <div className="w-full">
+ <div className="w-full border border-border rounded-md shadow-sm p-4 flex flex-col gap-4 mt-4">
+ <HStack
+ className="w-full justify-between cursor-pointer"
+ onClick={costsDisclosure.onToggle}
+ >
+ <Label>Tax &amp; Additional Costs</Label>
+ <HStack>
+ {(initialValues?.taxPercent ?? 0) > 0 && (
+ <Badge variant="red">
+ {percentFormatter.format(
+ initialValues?.taxPercent ?? 0
+ )}{" "}
+ Tax
+ </Badge>
+ )}
+ {(initialValues?.shippingCost ?? 0) > 0 && (
+ <Badge
+ variant="secondary"
+ className="flex items-center gap-1"
+ >
+ <LuTruck />
+ <span>
+ {currencyFormatter.format(
+ initialValues?.shippingCost ?? 0
+ )}
+ </span>
+ </Badge>
+ )}
+ {(initialValues?.addOnCost ?? 0) > 0 ||
+ ((initialValues?.nonTaxableAddOnCost ?? 0) >
+ 0 && (
+ <Badge
+ variant="secondary"
+ className="flex items-center gap-1"
+ >
+ <LuPlus />
+ <span>
+ {currencyFormatter.format(
+ (initialValues?.addOnCost ?? 0) +
+ (initialValues?.nonTaxableAddOnCost ??
+ 0)
+ )}{" "}
+ Add-On
+ </span>
+ </Badge>
+ ))}
+
+ <IconButton
+ icon={<LuChevronRight />}
+ aria-label={
+ costsDisclosure.isOpen
+ ? "Collapse Costs"
+ : "Expand Costs"
+ }
+ variant="ghost"
+ size="md"
+ onClick={(e) => {
+ e.stopPropagation();
+ costsDisclosure.onToggle();
+ }}
+ className={`transition-transform ${
+ costsDisclosure.isOpen ? "rotate-90" : ""
+ }`}
+ />
+ </HStack>
+ </HStack>
+ <div
+ className={`grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3 pb-4 ${
+ costsDisclosure.isOpen ? "" : "hidden"
+ }`}
+ >
+ <Number
+ name="taxPercent"
+ label="Tax Percent"
+ minValue={0}
+ maxValue={1}
+ step={0.0001}
+ formatOptions={{
+ style: "percent",
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 2
+ }}
+ />
+ <Number
+ name="shippingCost"
+ label="Shipping Cost"
+ minValue={0}
+ formatOptions={{
+ style: "currency",
+ currency: baseCurrency
+ }}
+ />
+ <Number
+ name="addOnCost"
+ label="Add-On Cost"
+ formatOptions={{
+ style: "currency",
+ currency: baseCurrency
+ }}
+ />
+ <Number
+ name="nonTaxableAddOnCost"
+ label="Non-Taxable Add-On Cost"
+ formatOptions={{
+ style: "currency",
+ currency: baseCurrency
+ }}
+ />
+ </div>
+ </div>
+ </div>
+ )}
</VStack>
</ModalCardBody>
<ModalCardFooter>
diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx
index f9e034424c..8bf0521bf4 100644
--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx
+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx
@@ -89,7 +89,9 @@ const SalesOrderSummary = ({
const lineTotal =
(line.convertedUnitPrice ?? 0) * (line.saleQuantity ?? 0);
const addOns =
- (line.convertedAddOnCost ?? 0) + (line.convertedShippingCost ?? 0);
+ (line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0) +
+ (line.convertedShippingCost ?? 0);
return acc + lineTotal + addOns;
}, 0) ?? 0;
@@ -97,9 +99,9 @@ const SalesOrderSummary = ({
routeData?.lines?.reduce((acc, line) => {
const lineTotal =
(line.convertedUnitPrice ?? 0) * (line.saleQuantity ?? 0);
- const addOns =
+ const taxableAddOns =
(line.convertedAddOnCost ?? 0) + (line.convertedShippingCost ?? 0);
- return acc + (lineTotal + addOns) * (line.taxPercent ?? 0);
+ return acc + (lineTotal + taxableAddOns) * (line.taxPercent ?? 0);
}, 0) ?? 0;
const convertedShippingCost =
@@ -366,7 +368,8 @@ function LineItems({
(line?.saleQuantity ?? 0) +
(line?.convertedAddOnCost ?? 0) +
(line?.convertedShippingCost ?? 0)) *
- (1 + (line?.taxPercent ?? 0))
+ (1 + (line?.taxPercent ?? 0)) +
+ (line?.convertedNonTaxableAddOnCost ?? 0)
}
format={{
style: "currency",
@@ -392,11 +395,7 @@ function LineItems({
<MethodIcon type={line.methodType ?? "Pick"} />
</Badge>
<Badge variant="green">
- {formatter.format(
- (line.unitPrice ?? 0) +
- (line.addOnCost ?? 0) +
- (line.shippingCost ?? 0)
- )}{" "}
+ {formatter.format(line.unitPrice ?? 0)}{" "}
{line.unitOfMeasureCode}
</Badge>
{(line.taxPercent ?? 0) > 0 ? (
@@ -524,6 +523,22 @@ function LineItems({
</Tr>
)}
+ {Number(line.nonTaxableAddOnCost ?? 0) > 0 && (
+ <Tr>
+ <Td>Non-Taxable Charges</Td>
+ <Td className="text-right">
+ <MotionNumber
+ value={line.nonTaxableAddOnCost ?? 0}
+ format={{
+ style: "currency",
+ currency: currencyCode
+ }}
+ locales={locale}
+ />
+ </Td>
+ </Tr>
+ )}
+
<Tr key="subtotal">
<Td>Subtotal</Td>
<Td className="text-right">
@@ -532,6 +547,7 @@ function LineItems({
(line.convertedUnitPrice ?? 0) *
(line.saleQuantity ?? 0) +
(line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0) +
(line.convertedShippingCost ?? 0)
}
format={{
@@ -574,7 +590,8 @@ function LineItems({
(line.saleQuantity ?? 0) +
(line.convertedAddOnCost ?? 0) +
(line.convertedShippingCost ?? 0)) *
- (1 + (line.taxPercent ?? 0))
+ (1 + (line.taxPercent ?? 0)) +
+ (line.convertedNonTaxableAddOnCost ?? 0)
}
format={{
style: "currency",
diff --git a/apps/erp/app/routes/share+/quote.$id.tsx b/apps/erp/app/routes/share+/quote.$id.tsx
index 2fb8bcb23f..98bb76b277 100644
--- a/apps/erp/app/routes/share+/quote.$id.tsx
+++ b/apps/erp/app/routes/share+/quote.$id.tsx
@@ -420,6 +420,8 @@ type SelectedLine = {
convertedNetUnitPrice: number;
addOn: number;
convertedAddOn: number;
+ taxableAddOn: number;
+ convertedTaxableAddOn: number;
leadTime: number;
shippingCost: number;
convertedShippingCost: number;
@@ -432,6 +434,8 @@ type SelectedLine = {
const deselectedLine: SelectedLine = {
addOn: 0,
convertedAddOn: 0,
+ taxableAddOn: 0,
+ convertedTaxableAddOn: 0,
netUnitPrice: 0,
convertedNetUnitPrice: 0,
quantity: 0,
@@ -543,12 +547,20 @@ const LineItems = ({
<MotionNumber
className="font-bold text-xl"
value={
+ (selectedLines[line.id!]?.convertedNetUnitPrice ??
+ 0) *
+ (selectedLines[line.id!]?.quantity ?? 0) +
+ (selectedLines[line.id!]?.convertedAddOn ?? 0) +
+ (selectedLines[line.id!]?.convertedShippingCost ??
+ 0) +
((selectedLines[line.id!]?.convertedNetUnitPrice ??
0) *
(selectedLines[line.id!]?.quantity ?? 0) +
- (selectedLines[line.id!]?.convertedAddOn ?? 0) +
- selectedLines[line.id!]?.convertedShippingCost) *
- (1 + selectedLines[line.id!]?.taxPercent)
+ (selectedLines[line.id!]?.convertedTaxableAddOn ??
+ 0) +
+ (selectedLines[line.id!]?.convertedShippingCost ??
+ 0)) *
+ (selectedLines[line.id!]?.taxPercent ?? 0)
}
format={{
style: "currency",
@@ -671,6 +683,33 @@ const LinePricingOptions = ({
{ 0: 0 }
);
+ const taxableAdditionalChargesByQuantity =
+ line.quantity?.reduce(
+ (acc, quantity) => {
+ const charges = Object.values(line.additionalCharges ?? {}).reduce(
+ (chargeAcc, charge) => {
+ if (charge.taxable === false) return chargeAcc;
+ const amount = charge.amounts?.[quantity];
+ return chargeAcc + amount;
+ },
+ 0
+ );
+ acc[quantity] = charges;
+ return acc;
+ },
+ { 0: 0 } as Record<number, number>
+ ) ?? {};
+
+ const convertedTaxableAdditionalChargesByQuantity = Object.entries(
+ taxableAdditionalChargesByQuantity
+ ).reduce<Record<number, number>>(
+ (acc, [quantity, amount]) => {
+ acc[Number(quantity)] = amount * quoteExchangeRate;
+ return acc;
+ },
+ { 0: 0 }
+ );
+
const additionalCharges: { name: string; amount: number }[] = [];
if (selectedLine.convertedShippingCost) {
additionalCharges.push({
@@ -731,6 +770,13 @@ const LinePricingOptions = ({
convertedAdditionalChargesByQuantity[
selectedOption.quantity
] || 0,
+ taxableAddOn:
+ taxableAdditionalChargesByQuantity[selectedOption.quantity] ||
+ 0,
+ convertedTaxableAddOn:
+ convertedTaxableAdditionalChargesByQuantity[
+ selectedOption.quantity
+ ] || 0,
leadTime: selectedOption.leadTime,
shippingCost: selectedOption.shippingCost ?? 0,
convertedShippingCost:
@@ -939,7 +985,7 @@ const LinePricingOptions = ({
value={
((selectedLine.convertedNetUnitPrice ?? 0) *
selectedLine.quantity +
- selectedLine.convertedAddOn +
+ (selectedLine.convertedTaxableAddOn ?? 0) +
selectedLine.convertedShippingCost) *
selectedLine.taxPercent
}
@@ -957,11 +1003,15 @@ const LinePricingOptions = ({
<Td className="text-right">
<MotionNumber
value={
+ (selectedLine.convertedNetUnitPrice ?? 0) *
+ selectedLine.quantity +
+ selectedLine.convertedAddOn +
+ selectedLine.convertedShippingCost +
((selectedLine.convertedNetUnitPrice ?? 0) *
selectedLine.quantity +
- selectedLine.convertedAddOn +
+ (selectedLine.convertedTaxableAddOn ?? 0) +
selectedLine.convertedShippingCost) *
- (1 + selectedLine.taxPercent)
+ selectedLine.taxPercent
}
format={{
style: "currency",
@@ -1121,6 +1171,33 @@ const Quote = ({
{} as Record<number, number>
) ?? {};
+ const taxableAdditionalChargesByQuantity =
+ line.quantity?.reduce(
+ (acc, quantity) => {
+ const charges = Object.values(
+ line.additionalCharges ?? {}
+ ).reduce((chargeAcc, charge) => {
+ if (charge.taxable === false) return chargeAcc;
+ const amount = charge.amounts?.[quantity];
+ return chargeAcc + amount;
+ }, 0);
+ acc[quantity] = charges;
+ return acc;
+ },
+ {} as Record<number, number>
+ ) ?? {};
+
+ const convertedTaxableAdditionalChargesByQuantity =
+ Object.entries(taxableAdditionalChargesByQuantity).reduce<
+ Record<number, number>
+ >(
+ (acc, [quantity, amount]) => {
+ acc[Number(quantity)] = amount * (quote.exchangeRate ?? 1);
+ return acc;
+ },
+ {} as Record<number, number>
+ ) ?? {};
+
acc[line.id] = {
quantity: price.quantity ?? 0,
netUnitPrice: price.netUnitPrice ?? 0,
@@ -1128,6 +1205,9 @@ const Quote = ({
addOn: additionalChargesByQuantity[price.quantity] || 0,
convertedAddOn:
convertedAdditionalChargesByQuantity[price.quantity] || 0,
+ taxableAddOn: taxableAdditionalChargesByQuantity[price.quantity] || 0,
+ convertedTaxableAddOn:
+ convertedTaxableAdditionalChargesByQuantity[price.quantity] || 0,
leadTime: price.leadTime,
shippingCost: price.shippingCost ?? 0,
convertedShippingCost: price.convertedShippingCost ?? 0,
@@ -1161,7 +1241,7 @@ const Quote = ({
return (
acc +
(line.convertedNetUnitPrice * line.quantity +
- line.convertedAddOn +
+ (line.convertedTaxableAddOn ?? 0) +
line.convertedShippingCost) *
(line.taxPercent ?? 0)
);
diff --git a/apps/erp/app/routes/x+/job+/update.tsx b/apps/erp/app/routes/x+/job+/update.tsx
index 349a0f6a22..63585c7740 100644
--- a/apps/erp/app/routes/x+/job+/update.tsx
+++ b/apps/erp/app/routes/x+/job+/update.tsx
@@ -21,8 +21,6 @@ export async function action({ request }: ActionFunctionArgs) {
const field = formData.get("field");
const value = formData.get("value");
- console.log({ ids, field, value });
-
if (typeof field !== "string") {
return { error: { message: "Invalid form data" }, data: null };
}
diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.cost.new.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.cost.new.tsx
index d0d95c3064..4f173b9e7f 100644
--- a/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.cost.new.tsx
+++ b/apps/erp/app/routes/x+/quote+/$quoteId.$lineId.cost.new.tsx
@@ -46,7 +46,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
...parsedCharges.data,
[id]: {
description: "Additional Charges",
- amounts: {}
+ amounts: {},
+ taxable: true
}
},
updatedBy: userId
diff --git a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx
index 827ea7f43c..78ddf3a3f6 100644
--- a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx
+++ b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx
@@ -155,6 +155,7 @@ export default function EditSalesInvoiceLineRoute() {
itemId: salesInvoiceLine?.itemId ?? "",
accountNumber: salesInvoiceLine?.accountNumber ?? "",
addOnCost: salesInvoiceLine?.addOnCost ?? 0,
+ nonTaxableAddOnCost: salesInvoiceLine?.nonTaxableAddOnCost ?? 0,
assetId: salesInvoiceLine?.assetId ?? "",
description: salesInvoiceLine?.description ?? "",
quantity: salesInvoiceLine?.quantity ?? 1,
diff --git a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.new.tsx b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.new.tsx
index f09c014cf9..721a588aa2 100644
--- a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.new.tsx
+++ b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.new.tsx
@@ -104,6 +104,7 @@ export default function NewSalesInvoiceLineRoute() {
unitPrice: 0,
shippingCost: 0,
addOnCost: 0,
+ nonTaxableAddOnCost: 0,
taxPercent: 0,
exchangeRate: salesInvoiceData?.salesInvoice?.exchangeRate ?? 1
};
diff --git a/apps/erp/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx b/apps/erp/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx
index 3fe70cb317..2250add290 100644
--- a/apps/erp/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx
+++ b/apps/erp/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx
@@ -184,6 +184,7 @@ export default function EditSalesOrderLineRoute() {
description: line?.description ?? "",
locationId: line?.locationId ?? "",
methodType: line?.methodType ?? "Make",
+ nonTaxableAddOnCost: line?.nonTaxableAddOnCost ?? 0,
promisedDate: line?.promisedDate ?? undefined,
saleQuantity: line?.saleQuantity ?? 1,
setupPrice: line?.setupPrice ?? 0,
diff --git a/apps/erp/app/routes/x+/sales-order+/$orderId.new.tsx b/apps/erp/app/routes/x+/sales-order+/$orderId.new.tsx
index e251681f89..8f69f4f9a6 100644
--- a/apps/erp/app/routes/x+/sales-order+/$orderId.new.tsx
+++ b/apps/erp/app/routes/x+/sales-order+/$orderId.new.tsx
@@ -88,6 +88,8 @@ export default function NewSalesOrderLineRoute() {
shelfId: "",
unitOfMeasureCode: "",
unitPrice: 0,
+ addOnCost: 0,
+ nonTaxableAddOnCost: 0,
locationId:
salesOrderData?.salesOrder?.locationId ?? defaults.locationId ?? "",
taxPercent: salesOrderData?.customer?.taxPercent ?? 0,
diff --git a/apps/mes/app/routes/x+/operation.$operationId.tsx b/apps/mes/app/routes/x+/operation.$operationId.tsx
index e1332e9038..3dd020fb4c 100644
--- a/apps/mes/app/routes/x+/operation.$operationId.tsx
+++ b/apps/mes/app/routes/x+/operation.$operationId.tsx
@@ -152,12 +152,9 @@ export default function OperationRoute() {
thumbnailPath,
trackedEntities,
workCenter,
- nonConformanceActions,
- bomIdMap
+ nonConformanceActions
} = useLoaderData<typeof loader>();
- console.log({ bomIdMap });
-
return (
<JobOperation
key={`job-operation-${operationId}`}
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 99d0ebb48b..78ef0027c8 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -49116,6 +49116,12 @@ export default {
{
$ref: "#/parameters/rowFilter.salesOrderLine.sentDate",
},
+ {
+ $ref: "#/parameters/rowFilter.salesOrderLine.nonTaxableAddOnCost",
+ },
+ {
+ $ref: "#/parameters/rowFilter.salesOrderLine.convertedNonTaxableAddOnCost",
+ },
{
$ref: "#/parameters/select",
},
@@ -49295,6 +49301,12 @@ export default {
{
$ref: "#/parameters/rowFilter.salesOrderLine.sentDate",
},
+ {
+ $ref: "#/parameters/rowFilter.salesOrderLine.nonTaxableAddOnCost",
+ },
+ {
+ $ref: "#/parameters/rowFilter.salesOrderLine.convertedNonTaxableAddOnCost",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -49428,6 +49440,12 @@ export default {
{
$ref: "#/parameters/rowFilter.salesOrderLine.sentDate",
},
+ {
+ $ref: "#/parameters/rowFilter.salesOrderLine.nonTaxableAddOnCost",
+ },
+ {
+ $ref: "#/parameters/rowFilter.salesOrderLine.convertedNonTaxableAddOnCost",
+ },
{
$ref: "#/parameters/body.salesOrderLine",
},
@@ -62091,6 +62109,12 @@ export default {
{
$ref: "#/parameters/rowFilter.salesInvoiceLine.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.salesInvoiceLine.nonTaxableAddOnCost",
+ },
+ {
+ $ref: "#/parameters/rowFilter.salesInvoiceLine.convertedNonTaxableAddOnCost",
+ },
{
$ref: "#/parameters/select",
},
@@ -62252,6 +62276,12 @@ export default {
{
$ref: "#/parameters/rowFilter.salesInvoiceLine.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.salesInvoiceLine.nonTaxableAddOnCost",
+ },
+ {
+ $ref: "#/parameters/rowFilter.salesInvoiceLine.convertedNonTaxableAddOnCost",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -62367,6 +62397,12 @@ export default {
{
$ref: "#/parameters/rowFilter.salesInvoiceLine.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.salesInvoiceLine.nonTaxableAddOnCost",
+ },
+ {
+ $ref: "#/parameters/rowFilter.salesInvoiceLine.convertedNonTaxableAddOnCost",
+ },
{
$ref: "#/parameters/body.salesInvoiceLine",
},
@@ -73254,7 +73290,7 @@ export default {
properties: {
id: {
description:
- "Note:\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
+ "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
format: "text",
type: "string",
},
@@ -73303,7 +73339,7 @@ export default {
},
supplierLocationId: {
description:
- "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
+ "Note:\nThis is a Foreign Key to `supplierLocation.id`.<fk table='supplierLocation' column='id'/>",
format: "text",
type: "string",
},
@@ -92459,6 +92495,7 @@ export default {
"methodType",
"shippingCost",
"taxPercent",
+ "nonTaxableAddOnCost",
],
properties: {
id: {
@@ -92655,6 +92692,15 @@ export default {
format: "date",
type: "string",
},
+ nonTaxableAddOnCost: {
+ default: 0,
+ format: "numeric",
+ type: "number",
+ },
+ convertedNonTaxableAddOnCost: {
+ format: "numeric",
+ type: "number",
+ },
},
type: "object",
},
@@ -98825,6 +98871,7 @@ export default {
"companyId",
"createdAt",
"createdBy",
+ "nonTaxableAddOnCost",
],
properties: {
id: {
@@ -99004,6 +99051,15 @@ export default {
format: "text",
type: "string",
},
+ nonTaxableAddOnCost: {
+ default: 0,
+ format: "numeric",
+ type: "number",
+ },
+ convertedNonTaxableAddOnCost: {
+ format: "numeric",
+ type: "number",
+ },
},
type: "object",
},
@@ -126149,6 +126205,18 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.salesOrderLine.nonTaxableAddOnCost": {
+ name: "nonTaxableAddOnCost",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.salesOrderLine.convertedNonTaxableAddOnCost": {
+ name: "convertedNonTaxableAddOnCost",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.purchaseOrderFavorite": {
name: "purchaseOrderFavorite",
description: "purchaseOrderFavorite",
@@ -133304,6 +133372,18 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.salesInvoiceLine.nonTaxableAddOnCost": {
+ name: "nonTaxableAddOnCost",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.salesInvoiceLine.convertedNonTaxableAddOnCost": {
+ name: "convertedNonTaxableAddOnCost",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.customFieldTables": {
name: "customFieldTables",
description: "customFieldTables",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index df0b81377c..8c9ff8ac20 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -30810,6 +30810,7 @@ export type Database = {
assetId: string | null
companyId: string
convertedAddOnCost: number | null
+ convertedNonTaxableAddOnCost: number | null
convertedSetupPrice: number | null
convertedShippingCost: number | null
convertedUnitPrice: number | null
@@ -30827,6 +30828,7 @@ export type Database = {
locationId: string | null
methodType: Database["public"]["Enums"]["methodType"]
modelUploadId: string | null
+ nonTaxableAddOnCost: number
opportunityId: string | null
quantity: number
salesOrderId: string | null
@@ -30846,6 +30848,7 @@ export type Database = {
assetId?: string | null
companyId: string
convertedAddOnCost?: number | null
+ convertedNonTaxableAddOnCost?: number | null
convertedSetupPrice?: number | null
convertedShippingCost?: number | null
convertedUnitPrice?: number | null
@@ -30863,6 +30866,7 @@ export type Database = {
locationId?: string | null
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
+ nonTaxableAddOnCost?: number
opportunityId?: string | null
quantity?: number
salesOrderId?: string | null
@@ -30882,6 +30886,7 @@ export type Database = {
assetId?: string | null
companyId?: string
convertedAddOnCost?: number | null
+ convertedNonTaxableAddOnCost?: number | null
convertedSetupPrice?: number | null
convertedShippingCost?: number | null
convertedUnitPrice?: number | null
@@ -30899,6 +30904,7 @@ export type Database = {
locationId?: string | null
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
+ nonTaxableAddOnCost?: number
opportunityId?: string | null
quantity?: number
salesOrderId?: string | null
@@ -31743,6 +31749,7 @@ export type Database = {
assetId: string | null
companyId: string
convertedAddOnCost: number | null
+ convertedNonTaxableAddOnCost: number | null
convertedShippingCost: number | null
convertedUnitPrice: number | null
createdAt: string
@@ -31758,6 +31765,7 @@ export type Database = {
locationId: string | null
methodType: Database["public"]["Enums"]["methodType"]
modelUploadId: string | null
+ nonTaxableAddOnCost: number
promisedDate: string | null
quantityInvoiced: number | null
quantitySent: number | null
@@ -31785,6 +31793,7 @@ export type Database = {
assetId?: string | null
companyId: string
convertedAddOnCost?: number | null
+ convertedNonTaxableAddOnCost?: number | null
convertedShippingCost?: number | null
convertedUnitPrice?: number | null
createdAt?: string
@@ -31800,6 +31809,7 @@ export type Database = {
locationId?: string | null
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
+ nonTaxableAddOnCost?: number
promisedDate?: string | null
quantityInvoiced?: number | null
quantitySent?: number | null
@@ -31827,6 +31837,7 @@ export type Database = {
assetId?: string | null
companyId?: string
convertedAddOnCost?: number | null
+ convertedNonTaxableAddOnCost?: number | null
convertedShippingCost?: number | null
convertedUnitPrice?: number | null
createdAt?: string
@@ -31842,6 +31853,7 @@ export type Database = {
locationId?: string | null
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
+ nonTaxableAddOnCost?: number
promisedDate?: string | null
quantityInvoiced?: number | null
quantitySent?: number | null
@@ -33326,6 +33338,48 @@ export type Database = {
},
]
}
+ searchIndex_7gYaboCg4bgSHUXebP88ah: {
+ Row: {
+ createdAt: string
+ description: string | null
+ entityId: string
+ entityType: string
+ id: number
+ link: string
+ metadata: Json | null
+ searchVector: unknown
+ tags: string[] | null
+ title: string
+ updatedAt: string | null
+ }
+ Insert: {
+ createdAt?: string
+ description?: string | null
+ entityId: string
+ entityType: string
+ id?: number
+ link: string
+ metadata?: Json | null
+ searchVector?: unknown
+ tags?: string[] | null
+ title: string
+ updatedAt?: string | null
+ }
+ Update: {
+ createdAt?: string
+ description?: string | null
+ entityId?: string
+ entityType?: string
+ id?: number
+ link?: string
+ metadata?: Json | null
+ searchVector?: unknown
+ tags?: string[] | null
+ title?: string
+ updatedAt?: string | null
+ }
+ Relationships: []
+ }
searchIndexRegistry: {
Row: {
companyId: string
@@ -47714,14 +47768,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -49118,14 +49172,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -51928,6 +51982,7 @@ export type Database = {
assetId: string | null
companyId: string | null
convertedAddOnCost: number | null
+ convertedNonTaxableAddOnCost: number | null
convertedSetupPrice: number | null
convertedShippingCost: number | null
convertedUnitPrice: number | null
@@ -51951,6 +52006,7 @@ export type Database = {
locationId: string | null
methodType: Database["public"]["Enums"]["methodType"] | null
modelUploadId: string | null
+ nonTaxableAddOnCost: number | null
opportunityId: string | null
quantity: number | null
salesOrderId: string | null
@@ -52259,7 +52315,7 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["shipmentCountryCode"]
+ columns: ["invoiceCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -52273,7 +52329,7 @@ export type Database = {
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["invoiceCountryCode"]
+ columns: ["shipmentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -52558,6 +52614,7 @@ export type Database = {
autodeskUrn: string | null
companyId: string | null
convertedAddOnCost: number | null
+ convertedNonTaxableAddOnCost: number | null
convertedShippingCost: number | null
convertedUnitPrice: number | null
createdAt: string | null
@@ -52581,6 +52638,7 @@ export type Database = {
modelPath: string | null
modelSize: number | null
modelUploadId: string | null
+ nonTaxableAddOnCost: number | null
orderDate: string | null
promisedDate: string | null
quantityInvoiced: number | null
@@ -52816,14 +52874,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.ts
index 90a09a4bdb..d04f32f927 100644
--- a/packages/database/supabase/functions/convert/index.ts
+++ b/packages/database/supabase/functions/convert/index.ts
@@ -44,6 +44,8 @@ const payloadValidator = z.discriminatedUnion("type", [
convertedNetUnitPrice: z.number(),
addOn: z.number(),
convertedAddOn: z.number(),
+ taxableAddOn: z.number().optional(),
+ convertedTaxableAddOn: z.number().optional(),
shippingCost: z.number(),
convertedShippingCost: z.number(),
leadTime: z.number(),
@@ -496,7 +498,8 @@ serve(async (req: Request) => {
id: line.id,
salesOrderId: insertedSalesOrderId,
salesOrderLineType: line.itemType as "Part",
- addOnCost: selectedLines![line.id!].addOn,
+ addOnCost: selectedLines![line.id!].taxableAddOn ?? selectedLines![line.id!].addOn,
+ nonTaxableAddOnCost: (selectedLines![line.id!].addOn ?? 0) - (selectedLines![line.id!].taxableAddOn ?? selectedLines![line.id!].addOn ?? 0),
description: line.description,
itemId: line.itemId,
locationId: line.locationId ?? quote.data.locationId,
@@ -731,6 +734,7 @@ serve(async (req: Request) => {
quantity: line.quantityToInvoice,
unitPrice: line.unitPrice ?? 0,
addOnCost: line.addOnCost ?? 0,
+ nonTaxableAddOnCost: line.nonTaxableAddOnCost ?? 0,
shippingCost: line.shippingCost ?? 0,
taxPercent: line.taxPercent ?? 0,
unitOfMeasureCode: line.unitOfMeasureCode ?? "EA",
@@ -1291,6 +1295,7 @@ serve(async (req: Request) => {
quantity: line.quantityToInvoice,
unitPrice: line.unitPrice ?? 0,
addOnCost: line.addOnCost ?? 0,
+ nonTaxableAddOnCost: line.nonTaxableAddOnCost ?? 0,
shippingCost: line.shippingCost ?? 0,
taxPercent: line.taxPercent ?? 0,
unitOfMeasureCode: line.unitOfMeasureCode ?? "EA",
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index df0b81377c..8c9ff8ac20 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -30810,6 +30810,7 @@ export type Database = {
assetId: string | null
companyId: string
convertedAddOnCost: number | null
+ convertedNonTaxableAddOnCost: number | null
convertedSetupPrice: number | null
convertedShippingCost: number | null
convertedUnitPrice: number | null
@@ -30827,6 +30828,7 @@ export type Database = {
locationId: string | null
methodType: Database["public"]["Enums"]["methodType"]
modelUploadId: string | null
+ nonTaxableAddOnCost: number
opportunityId: string | null
quantity: number
salesOrderId: string | null
@@ -30846,6 +30848,7 @@ export type Database = {
assetId?: string | null
companyId: string
convertedAddOnCost?: number | null
+ convertedNonTaxableAddOnCost?: number | null
convertedSetupPrice?: number | null
convertedShippingCost?: number | null
convertedUnitPrice?: number | null
@@ -30863,6 +30866,7 @@ export type Database = {
locationId?: string | null
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
+ nonTaxableAddOnCost?: number
opportunityId?: string | null
quantity?: number
salesOrderId?: string | null
@@ -30882,6 +30886,7 @@ export type Database = {
assetId?: string | null
companyId?: string
convertedAddOnCost?: number | null
+ convertedNonTaxableAddOnCost?: number | null
convertedSetupPrice?: number | null
convertedShippingCost?: number | null
convertedUnitPrice?: number | null
@@ -30899,6 +30904,7 @@ export type Database = {
locationId?: string | null
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
+ nonTaxableAddOnCost?: number
opportunityId?: string | null
quantity?: number
salesOrderId?: string | null
@@ -31743,6 +31749,7 @@ export type Database = {
assetId: string | null
companyId: string
convertedAddOnCost: number | null
+ convertedNonTaxableAddOnCost: number | null
convertedShippingCost: number | null
convertedUnitPrice: number | null
createdAt: string
@@ -31758,6 +31765,7 @@ export type Database = {
locationId: string | null
methodType: Database["public"]["Enums"]["methodType"]
modelUploadId: string | null
+ nonTaxableAddOnCost: number
promisedDate: string | null
quantityInvoiced: number | null
quantitySent: number | null
@@ -31785,6 +31793,7 @@ export type Database = {
assetId?: string | null
companyId: string
convertedAddOnCost?: number | null
+ convertedNonTaxableAddOnCost?: number | null
convertedShippingCost?: number | null
convertedUnitPrice?: number | null
createdAt?: string
@@ -31800,6 +31809,7 @@ export type Database = {
locationId?: string | null
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
+ nonTaxableAddOnCost?: number
promisedDate?: string | null
quantityInvoiced?: number | null
quantitySent?: number | null
@@ -31827,6 +31837,7 @@ export type Database = {
assetId?: string | null
companyId?: string
convertedAddOnCost?: number | null
+ convertedNonTaxableAddOnCost?: number | null
convertedShippingCost?: number | null
convertedUnitPrice?: number | null
createdAt?: string
@@ -31842,6 +31853,7 @@ export type Database = {
locationId?: string | null
methodType?: Database["public"]["Enums"]["methodType"]
modelUploadId?: string | null
+ nonTaxableAddOnCost?: number
promisedDate?: string | null
quantityInvoiced?: number | null
quantitySent?: number | null
@@ -33326,6 +33338,48 @@ export type Database = {
},
]
}
+ searchIndex_7gYaboCg4bgSHUXebP88ah: {
+ Row: {
+ createdAt: string
+ description: string | null
+ entityId: string
+ entityType: string
+ id: number
+ link: string
+ metadata: Json | null
+ searchVector: unknown
+ tags: string[] | null
+ title: string
+ updatedAt: string | null
+ }
+ Insert: {
+ createdAt?: string
+ description?: string | null
+ entityId: string
+ entityType: string
+ id?: number
+ link: string
+ metadata?: Json | null
+ searchVector?: unknown
+ tags?: string[] | null
+ title: string
+ updatedAt?: string | null
+ }
+ Update: {
+ createdAt?: string
+ description?: string | null
+ entityId?: string
+ entityType?: string
+ id?: number
+ link?: string
+ metadata?: Json | null
+ searchVector?: unknown
+ tags?: string[] | null
+ title?: string
+ updatedAt?: string | null
+ }
+ Relationships: []
+ }
searchIndexRegistry: {
Row: {
companyId: string
@@ -47714,14 +47768,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -49118,14 +49172,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -51928,6 +51982,7 @@ export type Database = {
assetId: string | null
companyId: string | null
convertedAddOnCost: number | null
+ convertedNonTaxableAddOnCost: number | null
convertedSetupPrice: number | null
convertedShippingCost: number | null
convertedUnitPrice: number | null
@@ -51951,6 +52006,7 @@ export type Database = {
locationId: string | null
methodType: Database["public"]["Enums"]["methodType"] | null
modelUploadId: string | null
+ nonTaxableAddOnCost: number | null
opportunityId: string | null
quantity: number | null
salesOrderId: string | null
@@ -52259,7 +52315,7 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["shipmentCountryCode"]
+ columns: ["invoiceCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -52273,7 +52329,7 @@ export type Database = {
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["invoiceCountryCode"]
+ columns: ["shipmentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -52558,6 +52614,7 @@ export type Database = {
autodeskUrn: string | null
companyId: string | null
convertedAddOnCost: number | null
+ convertedNonTaxableAddOnCost: number | null
convertedShippingCost: number | null
convertedUnitPrice: number | null
createdAt: string | null
@@ -52581,6 +52638,7 @@ export type Database = {
modelPath: string | null
modelSize: number | null
modelUploadId: string | null
+ nonTaxableAddOnCost: number | null
orderDate: string | null
promisedDate: string | null
quantityInvoiced: number | null
@@ -52816,14 +52874,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/migrations/20260321120000_non-taxable-addon-cost.sql b/packages/database/supabase/migrations/20260321120000_non-taxable-addon-cost.sql
new file mode 100644
index 0000000000..3fbcb9b1f4
--- /dev/null
+++ b/packages/database/supabase/migrations/20260321120000_non-taxable-addon-cost.sql
@@ -0,0 +1,186 @@
+-- Add nonTaxableAddOnCost to salesOrderLine
+ALTER TABLE "salesOrderLine"
+ ADD COLUMN "nonTaxableAddOnCost" NUMERIC NOT NULL DEFAULT 0;
+ALTER TABLE "salesOrderLine"
+ ADD COLUMN "convertedNonTaxableAddOnCost" NUMERIC GENERATED ALWAYS AS ("nonTaxableAddOnCost" * "exchangeRate") STORED;
+
+-- Add nonTaxableAddOnCost to salesInvoiceLine
+ALTER TABLE "salesInvoiceLine"
+ ADD COLUMN "nonTaxableAddOnCost" NUMERIC NOT NULL DEFAULT 0;
+ALTER TABLE "salesInvoiceLine"
+ ADD COLUMN "convertedNonTaxableAddOnCost" NUMERIC GENERATED ALWAYS AS ("nonTaxableAddOnCost" * "exchangeRate") STORED;
+
+-- Redefine salesOrderLines view so sl.* picks up the new columns
+DROP VIEW IF EXISTS "salesOrderLines";
+CREATE OR REPLACE VIEW "salesOrderLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ sl.*,
+ i."readableIdWithRevision" as "itemReadableId",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ COALESCE(mu.id, imu.id) as "modelId",
+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",
+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",
+ COALESCE(mu."name", imu."name") as "modelName",
+ COALESCE(mu."size", imu."size") as "modelSize",
+ ic."unitCost" as "unitCost",
+ cp."customerPartId",
+ cp."customerPartRevision",
+ so."orderDate",
+ so."customerId",
+ so."salesOrderId" as "salesOrderReadableId"
+ FROM "salesOrderLine" sl
+ INNER JOIN "salesOrder" so ON so.id = sl."salesOrderId"
+ LEFT JOIN "modelUpload" mu ON sl."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = sl."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+ LEFT JOIN "customerPartToItem" cp ON cp."customerId" = so."customerId" AND cp."itemId" = i.id
+);
+
+-- Redefine salesInvoiceLines view so sl.* picks up the new columns
+DROP VIEW IF EXISTS "salesInvoiceLines";
+CREATE OR REPLACE VIEW "salesInvoiceLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ sl.*,
+ i."readableIdWithRevision" as "itemReadableId",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ i.name as "itemName",
+ i.description as "itemDescription",
+ ic."unitCost" as "unitCost",
+ (SELECT cp."customerPartId"
+ FROM "customerPartToItem" cp
+ WHERE cp."customerId" = si."customerId" AND cp."itemId" = i.id
+ LIMIT 1) as "customerPartId"
+ FROM "salesInvoiceLine" sl
+ INNER JOIN "salesInvoice" si ON si.id = sl."invoiceId"
+ LEFT JOIN "modelUpload" mu ON sl."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = sl."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+);
+
+-- Update salesOrders view to include nonTaxableAddOnCost in orderTotal
+DROP VIEW IF EXISTS "salesOrders";
+CREATE OR REPLACE VIEW "salesOrders" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ s.*,
+ sl."thumbnailPath",
+ sl."itemType",
+ sl."orderTotal" + COALESCE(ss."shippingCost", 0) AS "orderTotal",
+ sl."jobs",
+ sl."lines",
+ st."name" AS "shippingTermName",
+ sp."paymentTermId",
+ ss."shippingMethodId",
+ ss."receiptRequestedDate",
+ ss."receiptPromisedDate",
+ ss."dropShipment",
+ ss."shippingCost",
+ (
+ SELECT COALESCE(
+ jsonb_object_agg(
+ eim."integration",
+ CASE
+ WHEN eim."metadata" IS NOT NULL THEN eim."metadata"
+ ELSE to_jsonb(eim."externalId")
+ END
+ ) FILTER (WHERE eim."externalId" IS NOT NULL OR eim."metadata" IS NOT NULL),
+ '{}'::jsonb
+ )
+ FROM "externalIntegrationMapping" eim
+ WHERE eim."entityType" = 'salesOrder' AND eim."entityId" = s.id
+ ) AS "externalId"
+ FROM "salesOrder" s
+ LEFT JOIN (
+ SELECT
+ sol."salesOrderId",
+ MIN(CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END) AS "thumbnailPath",
+ SUM(
+ DISTINCT (1+COALESCE(sol."taxPercent", 0))*(COALESCE(sol."saleQuantity", 0)*(COALESCE(sol."unitPrice", 0)) + COALESCE(sol."shippingCost", 0) + COALESCE(sol."addOnCost", 0)) + COALESCE(sol."nonTaxableAddOnCost", 0)
+ ) AS "orderTotal",
+ MIN(i."type") AS "itemType",
+ ARRAY_AGG(
+ CASE
+ WHEN j.id IS NOT NULL THEN json_build_object(
+ 'id', j.id,
+ 'jobId', j."jobId",
+ 'status', j."status",
+ 'dueDate', j."dueDate",
+ 'productionQuantity', j."productionQuantity",
+ 'quantityComplete', j."quantityComplete",
+ 'quantityShipped', j."quantityShipped",
+ 'quantity', j."quantity",
+ 'scrapQuantity', j."scrapQuantity",
+ 'salesOrderLineId', sol.id,
+ 'assignee', j."assignee"
+ )
+ ELSE NULL
+ END
+ ) FILTER (WHERE j.id IS NOT NULL) AS "jobs",
+ ARRAY_AGG(
+ json_build_object(
+ 'id', sol.id,
+ 'methodType', sol."methodType",
+ 'saleQuantity', sol."saleQuantity"
+ )
+ ) AS "lines"
+ FROM "salesOrderLine" sol
+ LEFT JOIN "item" i
+ ON i."id" = sol."itemId"
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ LEFT JOIN "job" j ON j."salesOrderId" = sol."salesOrderId" AND j."salesOrderLineId" = sol."id"
+ GROUP BY sol."salesOrderId"
+ ) sl ON sl."salesOrderId" = s."id"
+ LEFT JOIN "salesOrderShipment" ss ON ss."id" = s."id"
+ LEFT JOIN "shippingTerm" st ON st."id" = ss."shippingTermId"
+ LEFT JOIN "salesOrderPayment" sp ON sp."id" = s."id";
+
+-- Update salesInvoices view to include nonTaxableAddOnCost in invoiceTotal
+DROP VIEW IF EXISTS "salesInvoices";
+CREATE OR REPLACE VIEW "salesInvoices" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ si.*,
+ sil."thumbnailPath",
+ sil."itemType",
+ sil."invoiceTotal" + COALESCE(ss."shippingCost", 0) AS "invoiceTotal",
+ sil."lines"
+ FROM "salesInvoice" si
+ LEFT JOIN (
+ SELECT
+ sil."invoiceId",
+ MIN(CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END) AS "thumbnailPath",
+ SUM(
+ DISTINCT (1+COALESCE(sil."taxPercent", 0))*(COALESCE(sil."quantity", 0)*(COALESCE(sil."unitPrice", 0)) + COALESCE(sil."shippingCost", 0) + COALESCE(sil."addOnCost", 0)) + COALESCE(sil."nonTaxableAddOnCost", 0)
+ ) AS "invoiceTotal",
+ SUM(COALESCE(sil."shippingCost", 0)) AS "shippingCost",
+ MIN(i."type") AS "itemType",
+ ARRAY_AGG(
+ json_build_object(
+ 'id', sil.id,
+ 'invoiceLineType', sil."invoiceLineType",
+ 'quantity', sil."quantity",
+ 'unitPrice', sil."unitPrice",
+ 'itemId', sil."itemId"
+ )
+ ) AS "lines"
+ FROM "salesInvoiceLine" sil
+ LEFT JOIN "item" i
+ ON i."id" = sil."itemId"
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ GROUP BY sil."invoiceId"
+ ) sil ON sil."invoiceId" = si."id"
+ JOIN "salesInvoiceShipment" ss ON ss."id" = si."id";
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index 861728992e..a9f0176879 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -171,15 +171,19 @@ const QuotePDF = ({
const netExtendedPrice = price?.convertedNetExtendedPrice ?? 0;
const additionalCharges = line.additionalCharges ?? {};
const quantity = line.quantity[0];
- const fees = Object.values(additionalCharges).reduce((acc, charge) => {
- let amount = charge.amounts?.[quantity] ?? 0;
- if (shouldConvertCurrency) {
- amount *= exchangeRate;
- }
- return acc + amount;
- }, 0);
+ const taxableFees = Object.values(additionalCharges).reduce(
+ (acc, charge) => {
+ if (charge.taxable === false) return acc;
+ let amount = charge.amounts?.[quantity] ?? 0;
+ if (shouldConvertCurrency) {
+ amount *= exchangeRate;
+ }
+ return acc + amount;
+ },
+ 0
+ );
const lineShipping = price?.convertedShippingCost ?? 0;
- const taxableAmount = netExtendedPrice + fees + lineShipping;
+ const taxableAmount = netExtendedPrice + taxableFees + lineShipping;
return total + taxableAmount * (line.taxPercent ?? 0);
}, 0);
};
@@ -353,11 +357,21 @@ const QuotePDF = ({
}
return acc + amount;
}, 0);
+ const taxableAdditionalCharge = Object.values(
+ additionalCharges
+ ).reduce((acc, charge) => {
+ if (charge.taxable === false) return acc;
+ let amount = charge.amounts?.[quantity] ?? 0;
+ if (shouldConvertCurrency) {
+ amount *= exchangeRate;
+ }
+ return acc + amount;
+ }, 0);
const shippingCost = price?.convertedShippingCost ?? 0;
const taxPercent = line.taxPercent ?? 0;
- const totalBeforeTax =
- netExtendedPrice + additionalCharge + shippingCost;
- const taxAmount = totalBeforeTax * taxPercent;
+ const taxableBeforeTax =
+ netExtendedPrice + taxableAdditionalCharge + shippingCost;
+ const taxAmount = taxableBeforeTax * taxPercent;
const totalTaxAndFees =
additionalCharge + shippingCost + taxAmount;
const totalPrice = netExtendedPrice + totalTaxAndFees;
diff --git a/packages/documents/src/pdf/SalesInvoicePDF.tsx b/packages/documents/src/pdf/SalesInvoicePDF.tsx
index 9689135d59..e5e95d3f08 100644
--- a/packages/documents/src/pdf/SalesInvoicePDF.tsx
+++ b/packages/documents/src/pdf/SalesInvoicePDF.tsx
@@ -7,7 +7,7 @@ import type { AccountsReceivableBillingAddress, PDF } from "../types";
import {
getLineDescription,
getLineDescriptionDetails,
- getLineSubtotal,
+ getLineTaxableSubtotal,
getLineTotal,
getTotal
} from "../utils/sales-invoice";
@@ -95,7 +95,7 @@ const SalesInvoicePDF = ({
} = salesInvoiceLocations;
const currencyCode = salesInvoice.currencyCode ?? company.baseCurrencyCode;
- const formatter = getCurrencyFormatter(currencyCode, locale);
+ const formatter = getCurrencyFormatter(currencyCode ?? "USD", locale);
const paymentTerm = paymentTerms?.find(
(term) => term.id === salesInvoice?.paymentTermId
@@ -240,6 +240,18 @@ const SalesInvoicePDF = ({
const isEven = rowIndex % 2 === 0;
rowIndex++;
+ const lineAddOnCost = line.convertedAddOnCost ?? 0;
+ const lineNonTaxableAddOnCost =
+ line.convertedNonTaxableAddOnCost ?? 0;
+ const lineShippingCost = line.convertedShippingCost ?? 0;
+ const lineTaxPercent = line.taxPercent ?? 0;
+ const lineTaxAmount = getLineTaxableSubtotal(line) * lineTaxPercent;
+ const totalTaxAndFees =
+ lineAddOnCost +
+ lineNonTaxableAddOnCost +
+ lineShippingCost +
+ lineTaxAmount;
+
return (
<View
key={line.id}
@@ -257,14 +269,17 @@ const SalesInvoicePDF = ({
<Text style={tw("text-[8px] text-gray-400 mt-0.5")}>
{getLineDescriptionDetails(line)}
</Text>
- {thumbnails && line.id in thumbnails && thumbnails[line.id] && (
- <View style={tw("mt-1 w-16")}>
- <Image
- src={thumbnails[line.id]!}
- style={tw("w-full h-auto")}
- />
- </View>
- )}
+ {thumbnails &&
+ line.id &&
+ line.id in thumbnails &&
+ thumbnails[line.id] && (
+ <View style={tw("mt-1 w-16")}>
+ <Image
+ src={thumbnails[line.id]!}
+ style={tw("w-full h-auto")}
+ />
+ </View>
+ )}
{Object.keys(line.externalNotes ?? {}).length > 0 && (
<View style={tw("mt-1")}>
<Note
@@ -273,6 +288,33 @@ const SalesInvoicePDF = ({
/>
</View>
)}
+ {line.invoiceLineType !== "Comment" && totalTaxAndFees > 0 && (
+ <View style={tw("mt-1")}>
+ <Text style={tw("text-[8px] text-gray-400 font-bold")}>
+ Tax & Fees
+ </Text>
+ {lineShippingCost > 0 && (
+ <Text style={tw("text-[8px] text-gray-400")}>
+ - Shipping
+ </Text>
+ )}
+ {lineAddOnCost > 0 && (
+ <Text style={tw("text-[8px] text-gray-400")}>
+ - Add-On
+ </Text>
+ )}
+ {lineNonTaxableAddOnCost > 0 && (
+ <Text style={tw("text-[8px] text-gray-400")}>
+ - Non-Taxable Add-On
+ </Text>
+ )}
+ {lineTaxPercent > 0 && (
+ <Text style={tw("text-[8px] text-gray-400")}>
+ - Tax ({(lineTaxPercent * 100).toFixed(0)}%)
+ </Text>
+ )}
+ </View>
+ )}
</View>
<Text style={tw("w-1/6 text-right text-gray-600")}>
{line.invoiceLineType === "Comment"
@@ -295,23 +337,57 @@ const SalesInvoicePDF = ({
{/* Summary */}
<View>
- {/* Subtotal - before tax */}
+ {/* Subtotal - extended price only */}
<View style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>
<View style={tw("w-4/6")} />
<Text style={tw("w-1/6 text-right text-gray-600")}>Subtotal</Text>
<Text style={tw("w-1/6 text-right text-gray-800")}>
{formatter.format(
salesInvoiceLines.reduce(
- (sum, line) => sum + getLineSubtotal(line),
+ (sum, line) =>
+ sum + (line.quantity ?? 0) * (line.convertedUnitPrice ?? 0),
0
)
)}
</Text>
</View>
+ {/* Add-Ons */}
+ {salesInvoiceLines.some(
+ (line) =>
+ (line.convertedAddOnCost ?? 0) > 0 ||
+ (line.convertedNonTaxableAddOnCost ?? 0) > 0
+ ) && (
+ <View
+ style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}
+ >
+ <View style={tw("w-4/6")} />
+ <Text style={tw("w-1/6 text-right text-gray-600")}>Add-Ons</Text>
+ <Text style={tw("w-1/6 text-right text-gray-800")}>
+ {formatter.format(
+ salesInvoiceLines.reduce(
+ (sum, line) =>
+ sum +
+ (line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0),
+ 0
+ )
+ )}
+ </Text>
+ </View>
+ )}
+
{/* Shipping */}
- {salesInvoiceShipment?.shippingCost &&
- salesInvoiceShipment.shippingCost > 0 && (
+ {(() => {
+ const lineShipping = salesInvoiceLines.reduce(
+ (sum, line) => sum + (line.convertedShippingCost ?? 0),
+ 0
+ );
+ const invoiceShipping =
+ (salesInvoiceShipment?.shippingCost ?? 0) *
+ (salesInvoice.exchangeRate ?? 1);
+ const totalShipping = lineShipping + invoiceShipping;
+ return totalShipping > 0 ? (
<View
style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}
>
@@ -320,13 +396,11 @@ const SalesInvoicePDF = ({
Shipping
</Text>
<Text style={tw("w-1/6 text-right text-gray-800")}>
- {formatter.format(
- (salesInvoiceShipment.shippingCost ?? 0) *
- (salesInvoice.exchangeRate ?? 1)
- )}
+ {formatter.format(totalShipping)}
</Text>
</View>
- )}
+ ) : null;
+ })()}
{/* Taxes */}
{salesInvoiceLines.some((line) => (line.taxPercent ?? 0) > 0) && (
@@ -339,7 +413,7 @@ const SalesInvoicePDF = ({
{formatter.format(
salesInvoiceLines.reduce((sum, line) => {
const taxPercent = line.taxPercent ?? 0;
- return sum + getLineSubtotal(line) * taxPercent;
+ return sum + getLineTaxableSubtotal(line) * taxPercent;
}, 0)
)}
</Text>
diff --git a/packages/documents/src/pdf/SalesOrderPDF.tsx b/packages/documents/src/pdf/SalesOrderPDF.tsx
index 55c0e55494..ec8bb41749 100644
--- a/packages/documents/src/pdf/SalesOrderPDF.tsx
+++ b/packages/documents/src/pdf/SalesOrderPDF.tsx
@@ -7,7 +7,7 @@ import type { AccountsReceivableBillingAddress, PDF } from "../types";
import {
getLineDescription,
getLineDescriptionDetails,
- getLineSubtotal,
+ getLineTaxableSubtotal,
getLineTotal,
getTotal
} from "../utils/sales-order";
@@ -86,7 +86,7 @@ const SalesOrderPDF = ({
} = salesOrderLocations;
const currencyCode = salesOrder.currencyCode ?? company.baseCurrencyCode;
- const formatter = getCurrencyFormatter(currencyCode, locale);
+ const formatter = getCurrencyFormatter(currencyCode ?? "USD", locale);
const paymentTerm = paymentTerms?.find(
(term) => term.id === salesOrder?.paymentTermId
@@ -236,6 +236,18 @@ const SalesOrderPDF = ({
const isEven = rowIndex % 2 === 0;
rowIndex++;
+ const lineAddOnCost = line.convertedAddOnCost ?? 0;
+ const lineNonTaxableAddOnCost =
+ line.convertedNonTaxableAddOnCost ?? 0;
+ const lineShippingCost = line.convertedShippingCost ?? 0;
+ const lineTaxPercent = line.taxPercent ?? 0;
+ const lineTaxAmount = getLineTaxableSubtotal(line) * lineTaxPercent;
+ const totalTaxAndFees =
+ lineAddOnCost +
+ lineNonTaxableAddOnCost +
+ lineShippingCost +
+ lineTaxAmount;
+
return (
<View
key={line.id}
@@ -253,14 +265,17 @@ const SalesOrderPDF = ({
<Text style={tw("text-[8px] text-gray-400 mt-0.5")}>
{getLineDescriptionDetails(line)}
</Text>
- {thumbnails && line.id in thumbnails && thumbnails[line.id] && (
- <View style={tw("mt-1 w-16")}>
- <Image
- src={thumbnails[line.id]!}
- style={tw("w-full h-auto")}
- />
- </View>
- )}
+ {thumbnails &&
+ line.id &&
+ line.id in thumbnails &&
+ thumbnails[line.id] && (
+ <View style={tw("mt-1 w-16")}>
+ <Image
+ src={thumbnails[line.id]!}
+ style={tw("w-full h-auto")}
+ />
+ </View>
+ )}
{Object.keys(line.externalNotes ?? {}).length > 0 && (
<View style={tw("mt-1")}>
<Note
@@ -269,6 +284,34 @@ const SalesOrderPDF = ({
/>
</View>
)}
+ {line.salesOrderLineType !== "Comment" &&
+ totalTaxAndFees > 0 && (
+ <View style={tw("mt-1")}>
+ <Text style={tw("text-[8px] text-gray-400 font-bold")}>
+ Tax & Fees
+ </Text>
+ {lineShippingCost > 0 && (
+ <Text style={tw("text-[8px] text-gray-400")}>
+ - Shipping
+ </Text>
+ )}
+ {lineAddOnCost > 0 && (
+ <Text style={tw("text-[8px] text-gray-400")}>
+ - Add-On
+ </Text>
+ )}
+ {lineNonTaxableAddOnCost > 0 && (
+ <Text style={tw("text-[8px] text-gray-400")}>
+ - Non-Taxable Add-On
+ </Text>
+ )}
+ {lineTaxPercent > 0 && (
+ <Text style={tw("text-[8px] text-gray-400")}>
+ - Tax ({(lineTaxPercent * 100).toFixed(0)}%)
+ </Text>
+ )}
+ </View>
+ )}
</View>
<Text style={tw("w-1/6 text-right text-gray-600")}>
{line.salesOrderLineType === "Comment"
@@ -291,36 +334,71 @@ const SalesOrderPDF = ({
{/* Summary */}
<View>
- {/* Subtotal - before tax */}
+ {/* Subtotal - extended price only */}
<View style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}>
<View style={tw("w-4/6")} />
<Text style={tw("w-1/6 text-right text-gray-600")}>Subtotal</Text>
<Text style={tw("w-1/6 text-right text-gray-800")}>
{formatter.format(
salesOrderLines.reduce(
- (sum, line) => sum + getLineSubtotal(line),
+ (sum, line) =>
+ sum +
+ (line.saleQuantity ?? 0) * (line.convertedUnitPrice ?? 0),
0
)
)}
</Text>
</View>
- {/* Shipping */}
- {salesOrder.shippingCost && salesOrder.shippingCost > 0 && (
+ {/* Add-Ons */}
+ {salesOrderLines.some(
+ (line) =>
+ (line.convertedAddOnCost ?? 0) > 0 ||
+ (line.convertedNonTaxableAddOnCost ?? 0) > 0
+ ) && (
<View
style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}
>
<View style={tw("w-4/6")} />
- <Text style={tw("w-1/6 text-right text-gray-600")}>Shipping</Text>
+ <Text style={tw("w-1/6 text-right text-gray-600")}>Add-Ons</Text>
<Text style={tw("w-1/6 text-right text-gray-800")}>
{formatter.format(
- (salesOrder.shippingCost ?? 0) *
- (salesOrder.exchangeRate ?? 1)
+ salesOrderLines.reduce(
+ (sum, line) =>
+ sum +
+ (line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0),
+ 0
+ )
)}
</Text>
</View>
)}
+ {/* Shipping */}
+ {(() => {
+ const lineShipping = salesOrderLines.reduce(
+ (sum, line) => sum + (line.convertedShippingCost ?? 0),
+ 0
+ );
+ const orderShipping =
+ (salesOrder.shippingCost ?? 0) * (salesOrder.exchangeRate ?? 1);
+ const totalShipping = lineShipping + orderShipping;
+ return totalShipping > 0 ? (
+ <View
+ style={tw("flex flex-row py-1.5 px-3 bg-gray-50 text-[10px]")}
+ >
+ <View style={tw("w-4/6")} />
+ <Text style={tw("w-1/6 text-right text-gray-600")}>
+ Shipping
+ </Text>
+ <Text style={tw("w-1/6 text-right text-gray-800")}>
+ {formatter.format(totalShipping)}
+ </Text>
+ </View>
+ ) : null;
+ })()}
+
{/* Taxes */}
{salesOrderLines.some((line) => (line.taxPercent ?? 0) > 0) && (
<View
@@ -332,7 +410,7 @@ const SalesOrderPDF = ({
{formatter.format(
salesOrderLines.reduce((sum, line) => {
const taxPercent = line.taxPercent ?? 0;
- return sum + getLineSubtotal(line) * taxPercent;
+ return sum + getLineTaxableSubtotal(line) * taxPercent;
}, 0)
)}
</Text>
diff --git a/packages/documents/src/utils/sales-invoice.ts b/packages/documents/src/utils/sales-invoice.ts
index 2183d9c033..f62f7749d0 100644
--- a/packages/documents/src/utils/sales-invoice.ts
+++ b/packages/documents/src/utils/sales-invoice.ts
@@ -27,6 +27,20 @@ export function getLineDescriptionDetails(
export function getLineSubtotal(
line: Database["public"]["Views"]["salesInvoiceLines"]["Row"]
+) {
+ if (line?.quantity && line?.convertedUnitPrice) {
+ return (
+ line.quantity * line.convertedUnitPrice +
+ (line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0) +
+ (line.convertedShippingCost ?? 0)
+ );
+ }
+ return 0;
+}
+
+export function getLineTaxableSubtotal(
+ line: Database["public"]["Views"]["salesInvoiceLines"]["Row"]
) {
if (line?.quantity && line?.convertedUnitPrice) {
return (
@@ -42,9 +56,11 @@ export function getLineTaxesAndFees(
line: Database["public"]["Views"]["salesInvoiceLines"]["Row"]
) {
const taxPercent = line.taxPercent ?? 0;
- const tax = getLineSubtotal(line) * taxPercent;
+ const tax = getLineTaxableSubtotal(line) * taxPercent;
const fees =
- (line.convertedAddOnCost ?? 0) + (line.convertedShippingCost ?? 0);
+ (line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0) +
+ (line.convertedShippingCost ?? 0);
return tax + fees;
}
@@ -52,7 +68,7 @@ export function getLineTotal(
line: Database["public"]["Views"]["salesInvoiceLines"]["Row"]
) {
const taxPercent = line.taxPercent ?? 0;
- const tax = getLineSubtotal(line) * taxPercent;
+ const tax = getLineTaxableSubtotal(line) * taxPercent;
return getLineSubtotal(line) + tax;
}
diff --git a/packages/documents/src/utils/sales-order.ts b/packages/documents/src/utils/sales-order.ts
index 6d3de0827c..b01472279a 100644
--- a/packages/documents/src/utils/sales-order.ts
+++ b/packages/documents/src/utils/sales-order.ts
@@ -38,6 +38,20 @@ export function getLineDescriptionDetails(
export function getLineSubtotal(
line: Database["public"]["Views"]["salesOrderLines"]["Row"]
+) {
+ if (line?.saleQuantity && line?.convertedUnitPrice) {
+ return (
+ line.saleQuantity * line.convertedUnitPrice +
+ (line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0) +
+ (line.convertedShippingCost ?? 0)
+ );
+ }
+ return 0;
+}
+
+export function getLineTaxableSubtotal(
+ line: Database["public"]["Views"]["salesOrderLines"]["Row"]
) {
if (line?.saleQuantity && line?.convertedUnitPrice) {
return (
@@ -53,9 +67,11 @@ export function getLineTaxesAndFees(
line: Database["public"]["Views"]["salesOrderLines"]["Row"]
) {
const taxPercent = line.taxPercent ?? 0;
- const tax = getLineSubtotal(line) * taxPercent;
+ const tax = getLineTaxableSubtotal(line) * taxPercent;
const fees =
- (line.convertedAddOnCost ?? 0) + (line.convertedShippingCost ?? 0);
+ (line.convertedAddOnCost ?? 0) +
+ (line.convertedNonTaxableAddOnCost ?? 0) +
+ (line.convertedShippingCost ?? 0);
return tax + fees;
}
@@ -63,7 +79,7 @@ export function getLineTotal(
line: Database["public"]["Views"]["salesOrderLines"]["Row"]
) {
const taxPercent = line.taxPercent ?? 0;
- const tax = getLineSubtotal(line) * taxPercent;
+ const tax = getLineTaxableSubtotal(line) * taxPercent;
return getLineSubtotal(line) + tax;
}