summaryrefslogtreecommitdiff
path: root/lib/procurement-select/service.ts
blob: 14fe54d7cdd7ea5b63e183888f02ed0b61b50258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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")
    }
}