2025-05-14 21:45:16 +02:00

36 lines
1.3 KiB
TypeScript

import { ApolloContext } from '@lib/seed/interfaces/context';
import { OrderEngineDBInterfaceSchema } from '../schemas/order.schema';
export async function getTotalPrice(order: OrderEngineDBInterfaceSchema, ctx: ApolloContext): Promise<number> {
let price = 0;
if (order.lines && order.lines.length > 0) {
for (let index = 0; index < order.lines.length; index++) {
const line = order.lines[index];
price += (await line.getLinePrice(ctx)) + (await line.getLineVatPrice(ctx));
}
}
return price;
}
export async function getVatPrice(order: OrderEngineDBInterfaceSchema, ctx: ApolloContext): Promise<number> {
let price = 0;
if (order.lines && order.lines.length > 0) {
for (let index = 0; index < order.lines.length; index++) {
const line = order.lines[index];
price += await line.getLineVatPrice(ctx);
}
}
return price;
}
export async function getSubTotalPrice(order: OrderEngineDBInterfaceSchema, ctx: ApolloContext): Promise<number> {
let price = 0;
if (order.lines && order.lines.length > 0) {
for (let index = 0; index < order.lines.length; index++) {
const line = order.lines[index];
price += await line.getLinePrice(ctx);
}
}
return price;
}