diff options
Diffstat (limited to 'lib/procurement-select')
| -rw-r--r-- | lib/procurement-select/service.ts | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/procurement-select/service.ts b/lib/procurement-select/service.ts new file mode 100644 index 00000000..14fe54d7 --- /dev/null +++ b/lib/procurement-select/service.ts @@ -0,0 +1,85 @@ +'use server' + +import db from "@/db/db" +import { + incoterms, placeOfShipping, paymentTerms +} from "@/db/schema" +import { eq } from "drizzle-orm" + +export async function getIncotermsForSelection() { + try { + const data = await db + .select({ + code: incoterms.code, + description: incoterms.description, + }) + .from(incoterms) + .where(eq(incoterms.isActive, true)) + .orderBy(incoterms.code) + + return data + + } catch (error) { + console.error("Error fetching incoterms:", error) + throw new Error("Failed to fetch incoterms") + } +} + + +export async function getPaymentTermsForSelection() { + try { + const data = await db + .select({ + code: paymentTerms.code, + description: paymentTerms.description, + }) + .from(paymentTerms) + .where(eq(paymentTerms.isActive, true)) + .orderBy(paymentTerms.code) + + return data + + } catch (error) { + console.error("Error fetching paymentTerms:", error) + throw new Error("Failed to fetch paymentTerms") + } +} + + +export async function getPlaceOfShippingForSelection() { + try { + const data = await db + .select({ + code: placeOfShipping.code, + description: placeOfShipping.description, + }) + .from(placeOfShipping) + .where(eq(placeOfShipping.isActive, true)) + .orderBy(placeOfShipping.code) + + return data + + } catch (error) { + console.error("Error fetching placeOfShipping:", error) + throw new Error("Failed to fetch placeOfShipping") + } +} + +export async function getPlaceOfDestinationForSelection() { + try { + const data = await db + .select({ + code: placeOfShipping.code, + description: placeOfShipping.description, + }) + .from(placeOfShipping) + .where(eq(placeOfShipping.isActive, true)) + .orderBy(placeOfShipping.code) + + return data + + } catch (error) { + console.error("Error fetching placeOfShipping:", error) + throw new Error("Failed to fetch placeOfShipping") + } +}
\ No newline at end of file |
