Functional Weave
Code in Rust

legal.disbursements-vat@1.0.0

impl/typescript.ts

1,417 bytes · the TypeScript implementation · view raw

import { type DisbursementFacts, type DisbursementTreatment } from "./legal_disbursements_vat_types.ts";

/** HMRC VAT Notice 700 section 25.1.1, in HMRC's order. All must be met. */
const CONDITIONS: readonly (keyof DisbursementFacts)[] = [
  "actedAsAgent",
  "clientReceivedAndUsed",
  "clientResponsibleToPay",
  "clientAuthorisedPayment",
  "clientKnewThirdParty",
  "separatelyItemised",
  "exactAmountRecovered",
  "additionalToOwnSupply",
];

/** Disbursement (outside the scope of your VAT) or recharge (VAT due), and why. */
export function disbursementVat(facts: DisbursementFacts): DisbursementTreatment {
  const failed: string[] = [];
  for (const name of CONDITIONS) {
    const value = facts[name];
    if (typeof value !== "boolean") {
      throw new TypeError(`${name} must be true or false, received ${value}`);
    }
    if (!value) failed.push(name);
  }
  if (failed.length === 0) {
    return {
      treatment: "disbursement",
      failedConditions: [],
      reason: "all eight conditions of VAT Notice 700 section 25.1.1 are met: pass the cost on at the exact amount, outside the value of your supply, with no VAT added",
    };
  }
  return {
    treatment: "recharge",
    failedConditions: failed,
    reason: `not a disbursement for VAT purposes (${failed.join(", ")} not met): include the cost in the value of your supply and charge VAT on it at the rate of your main supply`,
  };
}