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.

feat: allow more decimal places in numeric fields

Brad Barbin340b44536c21
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 5ba2470857..652900154b 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -4753,10 +4753,10 @@ export default {
$ref: "#/parameters/rowFilter.methodMaterial.scrapQuantity",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",
+ $ref: "#/parameters/rowFilter.methodMaterial.tags",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.tags",
+ $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",
},
{
$ref: "#/parameters/select",
@@ -4872,10 +4872,10 @@ export default {
$ref: "#/parameters/rowFilter.methodMaterial.scrapQuantity",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",
+ $ref: "#/parameters/rowFilter.methodMaterial.tags",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.tags",
+ $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",
},
{
$ref: "#/parameters/preferReturn",
@@ -4945,10 +4945,10 @@ export default {
$ref: "#/parameters/rowFilter.methodMaterial.scrapQuantity",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",
+ $ref: "#/parameters/rowFilter.methodMaterial.tags",
},
{
- $ref: "#/parameters/rowFilter.methodMaterial.tags",
+ $ref: "#/parameters/rowFilter.methodMaterial.productionQuantity",
},
{
$ref: "#/parameters/body.methodMaterial",
@@ -5299,10 +5299,10 @@ export default {
$ref: "#/parameters/rowFilter.quoteMaterial.scrapQuantity",
},
{
- $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",
+ $ref: "#/parameters/rowFilter.quoteMaterial.tags",
},
{
- $ref: "#/parameters/rowFilter.quoteMaterial.tags",
+ $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",
},
{
$ref: "#/parameters/select",
@@ -5427,10 +5427,10 @@ export default {
$ref: "#/parameters/rowFilter.quoteMaterial.scrapQuantity",
},
{
- $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",
+ $ref: "#/parameters/rowFilter.quoteMaterial.tags",
},
{
- $ref: "#/parameters/rowFilter.quoteMaterial.tags",
+ $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",
},
{
$ref: "#/parameters/preferReturn",
@@ -5509,10 +5509,10 @@ export default {
$ref: "#/parameters/rowFilter.quoteMaterial.scrapQuantity",
},
{
- $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",
+ $ref: "#/parameters/rowFilter.quoteMaterial.tags",
},
{
- $ref: "#/parameters/rowFilter.quoteMaterial.tags",
+ $ref: "#/parameters/rowFilter.quoteMaterial.productionQuantity",
},
{
$ref: "#/parameters/body.quoteMaterial",
@@ -18915,9 +18915,6 @@ export default {
{
$ref: "#/parameters/rowFilter.salesOrders.jobs",
},
- {
- $ref: "#/parameters/rowFilter.salesOrders.lines",
- },
{
$ref: "#/parameters/rowFilter.salesOrders.shippingTermName",
},
@@ -18939,6 +18936,9 @@ export default {
{
$ref: "#/parameters/rowFilter.salesOrders.shippingCost",
},
+ {
+ $ref: "#/parameters/rowFilter.salesOrders.locationName",
+ },
{
$ref: "#/parameters/select",
},
@@ -36300,6 +36300,15 @@ export default {
{
$ref: "#/parameters/rowFilter.quoteMaterialWithMakeMethodId.quoteOperationId",
},
+ {
+ $ref: "#/parameters/rowFilter.quoteMaterialWithMakeMethodId.scrapQuantity",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteMaterialWithMakeMethodId.tags",
+ },
+ {
+ $ref: "#/parameters/rowFilter.quoteMaterialWithMakeMethodId.productionQuantity",
+ },
{
$ref: "#/parameters/rowFilter.quoteMaterialWithMakeMethodId.quoteMaterialMakeMethodId",
},
@@ -36571,7 +36580,7 @@ export default {
$ref: "#/parameters/rowFilter.purchaseOrders.locationId",
},
{
- $ref: "#/parameters/rowFilter.purchaseOrders.supplierShippingCost",
+ $ref: "#/parameters/rowFilter.purchaseOrders.locationName",
},
{
$ref: "#/parameters/select",
@@ -38259,6 +38268,18 @@ export default {
{
$ref: "#/parameters/rowFilter.jobMaterialWithMakeMethodId.estimatedQuantity",
},
+ {
+ $ref: "#/parameters/rowFilter.jobMaterialWithMakeMethodId.defaultShelf",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobMaterialWithMakeMethodId.shelfId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobMaterialWithMakeMethodId.quantityIssued",
+ },
+ {
+ $ref: "#/parameters/rowFilter.jobMaterialWithMakeMethodId.quantityToIssue",
+ },
{
$ref: "#/parameters/rowFilter.jobMaterialWithMakeMethodId.jobMaterialMakeMethodId",
},
@@ -46314,10 +46335,6 @@ export default {
format: "numeric",
type: "number",
},
- productionQuantity: {
- format: "numeric",
- type: "number",
- },
tags: {
format: "text[]",
items: {
@@ -46325,6 +46342,10 @@ export default {
},
type: "array",
},
+ productionQuantity: {
+ format: "numeric",
+ type: "number",
+ },
},
type: "object",
},
@@ -46612,10 +46633,6 @@ export default {
format: "numeric",
type: "number",
},
- productionQuantity: {
- format: "numeric",
- type: "number",
- },
tags: {
format: "text[]",
items: {
@@ -46623,6 +46640,10 @@ export default {
},
type: "array",
},
+ productionQuantity: {
+ format: "numeric",
+ type: "number",
+ },
},
type: "object",
},
@@ -53311,11 +53332,6 @@ export default {
items: {},
type: "array",
},
- lines: {
- format: "json[]",
- items: {},
- type: "array",
- },
shippingTermName: {
format: "text",
type: "string",
@@ -53348,6 +53364,10 @@ export default {
format: "numeric",
type: "number",
},
+ locationName: {
+ format: "text",
+ type: "string",
+ },
},
type: "object",
},
@@ -60967,6 +60987,21 @@ export default {
format: "text",
type: "string",
},
+ scrapQuantity: {
+ format: "numeric",
+ type: "number",
+ },
+ tags: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
+ productionQuantity: {
+ format: "numeric",
+ type: "number",
+ },
quoteMaterialMakeMethodId: {
description: "Note:\nThis is a Primary Key.<pk/>",
format: "text",
@@ -61286,14 +61321,13 @@ export default {
type: "string",
},
locationId: {
- description:
- "Note:\nThis is a Foreign Key to `location.id`.<fk table='location' column='id'/>",
+ description: "Note:\nThis is a Primary Key.<pk/>",
format: "text",
type: "string",
},
- supplierShippingCost: {
- format: "numeric",
- type: "number",
+ locationName: {
+ format: "text",
+ type: "string",
},
},
type: "object",
@@ -62107,6 +62141,24 @@ export default {
format: "numeric",
type: "number",
},
+ defaultShelf: {
+ format: "boolean",
+ type: "boolean",
+ },
+ shelfId: {
+ description:
+ "Note:\nThis is a Foreign Key to `shelf.id`.<fk table='shelf' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ quantityIssued: {
+ format: "numeric",
+ type: "number",
+ },
+ quantityToIssue: {
+ format: "numeric",
+ type: "number",
+ },
jobMaterialMakeMethodId: {
description: "Note:\nThis is a Primary Key.<pk/>",
format: "text",
@@ -65801,17 +65853,17 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.methodMaterial.productionQuantity": {
- name: "productionQuantity",
+ "rowFilter.methodMaterial.tags": {
+ name: "tags",
required: false,
- format: "numeric",
+ format: "text[]",
in: "query",
type: "string",
},
- "rowFilter.methodMaterial.tags": {
- name: "tags",
+ "rowFilter.methodMaterial.productionQuantity": {
+ name: "productionQuantity",
required: false,
- format: "text[]",
+ format: "numeric",
in: "query",
type: "string",
},
@@ -66150,17 +66202,17 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.quoteMaterial.productionQuantity": {
- name: "productionQuantity",
+ "rowFilter.quoteMaterial.tags": {
+ name: "tags",
required: false,
- format: "numeric",
+ format: "text[]",
in: "query",
type: "string",
},
- "rowFilter.quoteMaterial.tags": {
- name: "tags",
+ "rowFilter.quoteMaterial.productionQuantity": {
+ name: "productionQuantity",
required: false,
- format: "text[]",
+ format: "numeric",
in: "query",
type: "string",
},
@@ -74980,13 +75032,6 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.salesOrders.lines": {
- name: "lines",
- required: false,
- format: "json[]",
- in: "query",
- type: "string",
- },
"rowFilter.salesOrders.shippingTermName": {
name: "shippingTermName",
required: false,
@@ -75036,6 +75081,13 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.salesOrders.locationName": {
+ name: "locationName",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.supplier": {
name: "supplier",
description: "supplier",
@@ -84894,6 +84946,27 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.quoteMaterialWithMakeMethodId.scrapQuantity": {
+ name: "scrapQuantity",
+ required: false,
+ format: "numeric",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.quoteMaterialWithMakeMethodId.tags": {
+ name: "tags",
+ required: false,
+ format: "text[]",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.quoteMaterialWithMakeMethodId.productionQuantity": {
+ name: "productionQuantity",
+ required: false,
+ format: "numeric",
+ in: "query",
+ type: "string",
+ },
"rowFilter.quoteMaterialWithMakeMethodId.quoteMaterialMakeMethodId": {
name: "quoteMaterialMakeMethodId",
required: false,
@@ -85346,10 +85419,10 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.purchaseOrders.supplierShippingCost": {
- name: "supplierShippingCost",
+ "rowFilter.purchaseOrders.locationName": {
+ name: "locationName",
required: false,
- format: "numeric",
+ format: "text",
in: "query",
type: "string",
},
@@ -86400,6 +86473,34 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.jobMaterialWithMakeMethodId.defaultShelf": {
+ name: "defaultShelf",
+ required: false,
+ format: "boolean",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.jobMaterialWithMakeMethodId.shelfId": {
+ name: "shelfId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.jobMaterialWithMakeMethodId.quantityIssued": {
+ name: "quantityIssued",
+ required: false,
+ format: "numeric",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.jobMaterialWithMakeMethodId.quantityToIssue": {
+ name: "quantityToIssue",
+ required: false,
+ format: "numeric",
+ in: "query",
+ type: "string",
+ },
"rowFilter.jobMaterialWithMakeMethodId.jobMaterialMakeMethodId": {
name: "jobMaterialMakeMethodId",
required: false,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index ef9d777c4e..a81efbe94e 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -5428,6 +5428,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "employeeJob_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "employeeJob_managerId_fkey"
columns: ["managerId"]
@@ -6933,6 +6940,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "itemInventory_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "itemInventory_shelfId_fkey"
columns: ["shelfId"]
@@ -7073,6 +7087,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "itemLedger_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "itemLedger_serialNumber_fkey"
columns: ["serialNumber", "itemId"]
@@ -7268,6 +7289,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "itemPlanning_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "itemPlanning_updatedBy_fkey"
columns: ["updatedBy"]
@@ -8078,6 +8106,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "job_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "job_quoteId_fkey"
columns: ["quoteId"]
@@ -12485,6 +12520,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "pickMethod_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "pickMethod_shelfId_fkey"
columns: ["defaultShelfId"]
@@ -12734,6 +12776,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "postingGroupInventory_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "postingGroupInventory_materialVarianceAccount_fkey"
columns: ["materialVarianceAccount", "companyId"]
@@ -13997,6 +14046,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoice_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoice_paymentTermId_fkey"
columns: ["paymentTermId"]
@@ -14139,6 +14195,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoiceDelivery_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoiceDelivery_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -14456,6 +14519,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoiceLines_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoiceLines_purchaseOrderId_fkey"
columns: ["purchaseOrderId"]
@@ -15149,6 +15219,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseOrderDelivery_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseOrderDelivery_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -16344,6 +16421,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quote_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quote_salesPersonId_fkey"
columns: ["salesPersonId"]
@@ -16695,6 +16779,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quoteLine_quoteId_fkey"
columns: ["quoteId"]
@@ -18060,6 +18151,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteShipment_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quoteShipment_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -18296,6 +18394,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "receipt_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "receipt_postedBy_fkey"
columns: ["postedBy"]
@@ -18527,6 +18632,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "receiptLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "receiptLine_receiptId_fkey"
columns: ["receiptId"]
@@ -18987,6 +19099,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesOrder_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesOrder_updatedBy_fkey"
columns: ["updatedBy"]
@@ -19677,6 +19796,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesOrderShipment_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesOrderShipment_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -20145,6 +20271,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesRfq_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesRfq_noQuoteReasonId_fkey"
columns: ["noQuoteReasonId"]
@@ -21125,6 +21258,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "shelf_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "shelf_updatedBy_fkey"
columns: ["updatedBy"]
@@ -21307,6 +21447,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "shifts_updatedBy_fkey"
columns: ["updatedBy"]
@@ -25392,6 +25539,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "warehouse_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "warehouse_updatedBy_fkey"
columns: ["updatedBy"]
@@ -25672,6 +25826,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "workCenter_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "workCenter_requiredAbilityId_fkey"
columns: ["requiredAbilityId"]
@@ -27397,6 +27558,7 @@ export type Database = {
createdAt: string | null
createdBy: string | null
customFields: Json | null
+ defaultShelf: boolean | null
description: string | null
estimatedQuantity: number | null
id: string | null
@@ -27410,7 +27572,10 @@ export type Database = {
methodType: Database["public"]["Enums"]["methodType"] | null
order: number | null
quantity: number | null
+ quantityIssued: number | null
+ quantityToIssue: number | null
scrapQuantity: number | null
+ shelfId: string | null
unitCost: number | null
unitOfMeasureCode: string | null
updatedAt: string | null
@@ -27529,6 +27694,13 @@ export type Database = {
referencedRelation: "jobOperationsWithMakeMethods"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "jobMaterial_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "jobMaterial_unitOfMeasureCode_fkey"
columns: ["unitOfMeasureCode", "companyId"]
@@ -27994,6 +28166,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "job_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "job_quoteId_fkey"
columns: ["quoteId"]
@@ -28422,14 +28601,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"]
@@ -28996,6 +29175,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoiceLines_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoiceLines_purchaseOrderId_fkey"
columns: ["purchaseOrderId"]
@@ -29289,6 +29475,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoice_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoice_paymentTermId_fkey"
columns: ["paymentTermId"]
@@ -29668,6 +29861,7 @@ export type Database = {
internalNotes: Json | null
itemType: Database["public"]["Enums"]["itemType"] | null
locationId: string | null
+ locationName: string | null
orderDate: string | null
orderTotal: number | null
paymentTermId: string | null
@@ -29683,7 +29877,6 @@ export type Database = {
supplierInteractionId: string | null
supplierLocationId: string | null
supplierReference: string | null
- supplierShippingCost: number | null
tags: string[] | null
thumbnailPath: string | null
updatedAt: string | null
@@ -29921,13 +30114,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "purchaseOrderDelivery_locationId_fkey"
- columns: ["locationId"]
- isOneToOne: false
- referencedRelation: "location"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "purchaseOrderDelivery_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -30164,6 +30350,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quoteLine_quoteId_fkey"
columns: ["quoteId"]
@@ -30242,12 +30435,15 @@ export type Database = {
itemType: string | null
methodType: Database["public"]["Enums"]["methodType"] | null
order: number | null
+ productionQuantity: number | null
quantity: number | null
quoteId: string | null
quoteLineId: string | null
quoteMakeMethodId: string | null
quoteMaterialMakeMethodId: string | null
quoteOperationId: string | null
+ scrapQuantity: number | null
+ tags: string[] | null
unitCost: number | null
unitOfMeasureCode: string | null
updatedAt: string | null
@@ -30925,6 +31121,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quote_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quote_salesPersonId_fkey"
columns: ["salesPersonId"]
@@ -31240,14 +31443,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"]
@@ -31276,8 +31479,8 @@ export type Database = {
internalNotes: Json | null
itemType: Database["public"]["Enums"]["itemType"] | null
jobs: Json[] | null
- lines: Json[] | null
locationId: string | null
+ locationName: string | null
orderDate: string | null
orderTotal: number | null
paymentTermId: string | null
@@ -31470,6 +31673,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesOrder_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesOrder_updatedBy_fkey"
columns: ["updatedBy"]
@@ -31936,6 +32146,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesRfq_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesRfq_updatedBy_fkey"
columns: ["updatedBy"]
@@ -32067,6 +32284,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "shifts_updatedBy_fkey"
columns: ["updatedBy"]
@@ -33107,6 +33331,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "employeeJob_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "location_companyId_fkey"
columns: ["companyId"]
@@ -33229,6 +33460,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "workCenter_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "workCenter_requiredAbilityId_fkey"
columns: ["requiredAbilityId"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index ef9d777c4e..a81efbe94e 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -5428,6 +5428,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "employeeJob_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "employeeJob_managerId_fkey"
columns: ["managerId"]
@@ -6933,6 +6940,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "itemInventory_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "itemInventory_shelfId_fkey"
columns: ["shelfId"]
@@ -7073,6 +7087,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "itemLedger_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "itemLedger_serialNumber_fkey"
columns: ["serialNumber", "itemId"]
@@ -7268,6 +7289,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "itemPlanning_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "itemPlanning_updatedBy_fkey"
columns: ["updatedBy"]
@@ -8078,6 +8106,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "job_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "job_quoteId_fkey"
columns: ["quoteId"]
@@ -12485,6 +12520,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "pickMethod_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "pickMethod_shelfId_fkey"
columns: ["defaultShelfId"]
@@ -12734,6 +12776,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "postingGroupInventory_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "postingGroupInventory_materialVarianceAccount_fkey"
columns: ["materialVarianceAccount", "companyId"]
@@ -13997,6 +14046,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoice_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoice_paymentTermId_fkey"
columns: ["paymentTermId"]
@@ -14139,6 +14195,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoiceDelivery_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoiceDelivery_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -14456,6 +14519,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoiceLines_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoiceLines_purchaseOrderId_fkey"
columns: ["purchaseOrderId"]
@@ -15149,6 +15219,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseOrderDelivery_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseOrderDelivery_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -16344,6 +16421,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quote_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quote_salesPersonId_fkey"
columns: ["salesPersonId"]
@@ -16695,6 +16779,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quoteLine_quoteId_fkey"
columns: ["quoteId"]
@@ -18060,6 +18151,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteShipment_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quoteShipment_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -18296,6 +18394,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "receipt_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "receipt_postedBy_fkey"
columns: ["postedBy"]
@@ -18527,6 +18632,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "receiptLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "receiptLine_receiptId_fkey"
columns: ["receiptId"]
@@ -18987,6 +19099,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesOrder_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesOrder_updatedBy_fkey"
columns: ["updatedBy"]
@@ -19677,6 +19796,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesOrderShipment_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesOrderShipment_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -20145,6 +20271,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesRfq_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesRfq_noQuoteReasonId_fkey"
columns: ["noQuoteReasonId"]
@@ -21125,6 +21258,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "shelf_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "shelf_updatedBy_fkey"
columns: ["updatedBy"]
@@ -21307,6 +21447,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "shifts_updatedBy_fkey"
columns: ["updatedBy"]
@@ -25392,6 +25539,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "warehouse_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "warehouse_updatedBy_fkey"
columns: ["updatedBy"]
@@ -25672,6 +25826,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "workCenter_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "workCenter_requiredAbilityId_fkey"
columns: ["requiredAbilityId"]
@@ -27397,6 +27558,7 @@ export type Database = {
createdAt: string | null
createdBy: string | null
customFields: Json | null
+ defaultShelf: boolean | null
description: string | null
estimatedQuantity: number | null
id: string | null
@@ -27410,7 +27572,10 @@ export type Database = {
methodType: Database["public"]["Enums"]["methodType"] | null
order: number | null
quantity: number | null
+ quantityIssued: number | null
+ quantityToIssue: number | null
scrapQuantity: number | null
+ shelfId: string | null
unitCost: number | null
unitOfMeasureCode: string | null
updatedAt: string | null
@@ -27529,6 +27694,13 @@ export type Database = {
referencedRelation: "jobOperationsWithMakeMethods"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "jobMaterial_shelfId_fkey"
+ columns: ["shelfId"]
+ isOneToOne: false
+ referencedRelation: "shelf"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "jobMaterial_unitOfMeasureCode_fkey"
columns: ["unitOfMeasureCode", "companyId"]
@@ -27994,6 +28166,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "job_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "job_quoteId_fkey"
columns: ["quoteId"]
@@ -28422,14 +28601,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"]
@@ -28996,6 +29175,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoiceLines_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoiceLines_purchaseOrderId_fkey"
columns: ["purchaseOrderId"]
@@ -29289,6 +29475,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "purchaseInvoice_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "purchaseInvoice_paymentTermId_fkey"
columns: ["paymentTermId"]
@@ -29668,6 +29861,7 @@ export type Database = {
internalNotes: Json | null
itemType: Database["public"]["Enums"]["itemType"] | null
locationId: string | null
+ locationName: string | null
orderDate: string | null
orderTotal: number | null
paymentTermId: string | null
@@ -29683,7 +29877,6 @@ export type Database = {
supplierInteractionId: string | null
supplierLocationId: string | null
supplierReference: string | null
- supplierShippingCost: number | null
tags: string[] | null
thumbnailPath: string | null
updatedAt: string | null
@@ -29921,13 +30114,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "purchaseOrderDelivery_locationId_fkey"
- columns: ["locationId"]
- isOneToOne: false
- referencedRelation: "location"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "purchaseOrderDelivery_shippingMethodId_fkey"
columns: ["shippingMethodId"]
@@ -30164,6 +30350,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quoteLine_quoteId_fkey"
columns: ["quoteId"]
@@ -30242,12 +30435,15 @@ export type Database = {
itemType: string | null
methodType: Database["public"]["Enums"]["methodType"] | null
order: number | null
+ productionQuantity: number | null
quantity: number | null
quoteId: string | null
quoteLineId: string | null
quoteMakeMethodId: string | null
quoteMaterialMakeMethodId: string | null
quoteOperationId: string | null
+ scrapQuantity: number | null
+ tags: string[] | null
unitCost: number | null
unitOfMeasureCode: string | null
updatedAt: string | null
@@ -30925,6 +31121,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quote_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quote_salesPersonId_fkey"
columns: ["salesPersonId"]
@@ -31240,14 +31443,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"]
@@ -31276,8 +31479,8 @@ export type Database = {
internalNotes: Json | null
itemType: Database["public"]["Enums"]["itemType"] | null
jobs: Json[] | null
- lines: Json[] | null
locationId: string | null
+ locationName: string | null
orderDate: string | null
orderTotal: number | null
paymentTermId: string | null
@@ -31470,6 +31673,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesOrder_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesOrder_updatedBy_fkey"
columns: ["updatedBy"]
@@ -31936,6 +32146,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "salesRfq_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "salesRfq_updatedBy_fkey"
columns: ["updatedBy"]
@@ -32067,6 +32284,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "shifts_updatedBy_fkey"
columns: ["updatedBy"]
@@ -33107,6 +33331,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "employeeJob_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "location_companyId_fkey"
columns: ["companyId"]
@@ -33229,6 +33460,13 @@ export type Database = {
referencedRelation: "location"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "workCenter_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "workCenter_requiredAbilityId_fkey"
columns: ["requiredAbilityId"]
diff --git a/packages/database/supabase/migrations/20250204164256_numeric-increase-2.sql b/packages/database/supabase/migrations/20250204164256_numeric-increase-2.sql
new file mode 100644
index 0000000000..81f1be98b2
--- /dev/null
+++ b/packages/database/supabase/migrations/20250204164256_numeric-increase-2.sql
@@ -0,0 +1,1932 @@
+BEGIN;
+
+DROP VIEW IF EXISTS "quoteLines";
+DROP VIEW IF EXISTS "supplierQuoteLines";
+
+DROP VIEW IF EXISTS "quoteMaterialWithMakeMethodId";
+DROP VIEW IF EXISTS "jobMaterialWithMakeMethodId";
+
+
+ALTER TABLE "methodMaterial" DROP COLUMN "productionQuantity";
+ALTER TABLE "methodMaterial"
+ ALTER COLUMN "quantity" TYPE NUMERIC,
+ ALTER COLUMN "scrapQuantity" TYPE NUMERIC;
+ALTER TABLE "methodMaterial" ADD COLUMN "productionQuantity" NUMERIC GENERATED ALWAYS AS ("quantity" + "scrapQuantity") STORED;
+
+ALTER TABLE "quoteMaterial" DROP COLUMN "productionQuantity";
+ALTER TABLE "quoteMaterial"
+ ALTER COLUMN "quantity" TYPE NUMERIC,
+ ALTER COLUMN "unitCost" TYPE NUMERIC,
+ ALTER COLUMN "scrapQuantity" TYPE NUMERIC;
+ALTER TABLE "quoteMaterial" ADD COLUMN "productionQuantity" NUMERIC GENERATED ALWAYS AS ("quantity" + "scrapQuantity") STORED;
+
+
+ALTER TABLE "jobMaterial" DROP COLUMN "quantityToIssue";
+
+ALTER TABLE "jobMaterial"
+ ALTER COLUMN "quantity" TYPE NUMERIC,
+ ALTER COLUMN "unitCost" TYPE NUMERIC,
+ ALTER COLUMN "scrapQuantity" TYPE NUMERIC,
+ ALTER COLUMN "quantityIssued" TYPE NUMERIC,
+ ALTER COLUMN "estimatedQuantity" TYPE NUMERIC;
+
+ALTER TABLE "jobMaterial"
+ ADD COLUMN "quantityToIssue" NUMERIC GENERATED ALWAYS AS (GREATEST(("estimatedQuantity" - "quantityIssued"), 0)) STORED;
+
+CREATE OR REPLACE VIEW "quoteMaterialWithMakeMethodId" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ qm.*,
+ qmm."id" AS "quoteMaterialMakeMethodId"
+ FROM "quoteMaterial" qm
+ LEFT JOIN "quoteMakeMethod" qmm
+ ON qmm."parentMaterialId" = qm."id";
+
+CREATE OR REPLACE VIEW "jobMaterialWithMakeMethodId" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ jm.*,
+ jmm."id" AS "jobMaterialMakeMethodId"
+ FROM "jobMaterial" jm
+ LEFT JOIN "jobMakeMethod" jmm
+ ON jmm."parentMaterialId" = jm."id";
+
+ALTER TABLE "quoteLinePrice"
+ DROP COLUMN IF EXISTS "convertedUnitPrice",
+ DROP COLUMN IF EXISTS "convertedNetUnitPrice",
+ DROP COLUMN IF EXISTS "convertedNetExtendedPrice",
+ DROP COLUMN IF EXISTS "convertedShippingCost",
+ DROP COLUMN IF EXISTS "netUnitPrice",
+ DROP COLUMN IF EXISTS "netExtendedPrice",
+ ALTER COLUMN "unitPrice" TYPE NUMERIC,
+ ALTER COLUMN "shippingCost" TYPE NUMERIC,
+ ADD COLUMN "convertedUnitPrice" NUMERIC GENERATED ALWAYS AS ("unitPrice" * "exchangeRate") STORED,
+ ADD COLUMN "netUnitPrice" NUMERIC GENERATED ALWAYS AS ("unitPrice" * (1 - "discountPercent")) STORED,
+ ADD COLUMN "netExtendedPrice" NUMERIC GENERATED ALWAYS AS ("unitPrice" * (1 - "discountPercent") * "quantity") STORED,
+ ADD COLUMN "convertedNetUnitPrice" NUMERIC GENERATED ALWAYS AS ("unitPrice" * "exchangeRate" * (1 - "discountPercent")) STORED,
+ ADD COLUMN "convertedNetExtendedPrice" NUMERIC GENERATED ALWAYS AS ("unitPrice" * "exchangeRate" * (1 - "discountPercent") * "quantity") STORED,
+ ADD COLUMN "convertedShippingCost" NUMERIC GENERATED ALWAYS AS ("shippingCost" * "exchangeRate") STORED;
+
+-- Drop dependent views first
+DROP VIEW IF EXISTS "salesOrderLines";
+DROP VIEW IF EXISTS "salesOrders";
+
+-- Update salesOrderLine columns
+ALTER TABLE "salesOrderLine"
+ DROP COLUMN IF EXISTS "convertedAddOnCost",
+ DROP COLUMN IF EXISTS "convertedShippingCost",
+ DROP COLUMN IF EXISTS "convertedUnitPrice",
+ ALTER COLUMN "unitPrice" TYPE NUMERIC,
+ ALTER COLUMN "setupPrice" TYPE NUMERIC,
+ ALTER COLUMN "addOnCost" TYPE NUMERIC,
+ ALTER COLUMN "shippingCost" TYPE NUMERIC,
+ ADD COLUMN "convertedAddOnCost" NUMERIC GENERATED ALWAYS AS ("addOnCost" * "exchangeRate") STORED,
+ ADD COLUMN "convertedShippingCost" NUMERIC GENERATED ALWAYS AS ("shippingCost" * "exchangeRate") STORED,
+ ADD COLUMN "convertedUnitPrice" NUMERIC GENERATED ALWAYS AS ("unitPrice" * "exchangeRate") STORED;
+
+
+
+DROP VIEW IF EXISTS "purchaseOrderLines";
+DROP VIEW IF EXISTS "purchaseOrders";
+
+-- Update purchaseOrderLine columns
+ALTER TABLE "purchaseOrderLine" DROP COLUMN IF EXISTS "unitPrice";
+ALTER TABLE "purchaseOrderLine" DROP COLUMN IF EXISTS "extendedPrice";
+ALTER TABLE "purchaseOrderLine" DROP COLUMN IF EXISTS "shippingCost";
+ALTER TABLE "purchaseOrderLine" DROP COLUMN IF EXISTS "taxAmount";
+ALTER TABLE "purchaseOrderLine" DROP COLUMN IF EXISTS "supplierExtendedPrice";
+ALTER TABLE "purchaseOrderLine" DROP COLUMN IF EXISTS "taxPercent";
+
+ALTER TABLE "purchaseOrderLine" ALTER COLUMN "supplierUnitPrice" TYPE NUMERIC;
+ALTER TABLE "purchaseOrderLine" ALTER COLUMN "supplierShippingCost" TYPE NUMERIC;
+ALTER TABLE "purchaseOrderLine" ALTER COLUMN "supplierTaxAmount" TYPE NUMERIC;
+
+ALTER TABLE "purchaseOrderLine" ADD COLUMN "unitPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "purchaseOrderLine" ADD COLUMN "supplierExtendedPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "purchaseQuantity"
+) STORED;
+
+ALTER TABLE "purchaseOrderLine" ADD COLUMN "extendedPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "exchangeRate" * "purchaseQuantity"
+) STORED;
+
+ALTER TABLE "purchaseOrderLine" ADD COLUMN "shippingCost" NUMERIC GENERATED ALWAYS AS (
+ "supplierShippingCost" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "purchaseOrderLine" ADD COLUMN "taxAmount" NUMERIC GENERATED ALWAYS AS (
+ "supplierTaxAmount" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "purchaseOrderLine" ADD COLUMN IF NOT EXISTS "taxPercent" NUMERIC GENERATED ALWAYS AS (
+ CASE
+ WHEN (("supplierUnitPrice" + "supplierShippingCost") * "purchaseQuantity") = 0 THEN 0
+ ELSE "supplierTaxAmount" / (("supplierUnitPrice" + "supplierShippingCost") * "purchaseQuantity")
+ END
+) STORED;
+
+
+
+DROP VIEW IF EXISTS "purchaseInvoiceLines";
+DROP VIEW IF EXISTS "purchaseInvoices";
+
+
+-- Update itemUnitSalePrice columns
+ALTER TABLE "itemUnitSalePrice"
+ ALTER COLUMN "unitSalePrice" TYPE NUMERIC;
+
+-- Update itemCost columns
+ALTER TABLE "itemCost"
+ ALTER COLUMN "unitCost" TYPE NUMERIC;
+
+
+
+-- Update purchaseInvoiceLine columns
+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN IF EXISTS "totalAmount";
+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN IF EXISTS "unitPrice";
+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN IF EXISTS "extendedPrice";
+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN IF EXISTS "shippingCost";
+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN IF EXISTS "taxAmount";
+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN IF EXISTS "supplierExtendedPrice";
+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN IF EXISTS "taxPercent";
+ALTER TABLE "purchaseInvoiceLine" ALTER COLUMN "supplierUnitPrice" TYPE NUMERIC;
+ALTER TABLE "purchaseInvoiceLine" ALTER COLUMN "supplierShippingCost" TYPE NUMERIC;
+ALTER TABLE "purchaseInvoiceLine" ALTER COLUMN "supplierTaxAmount" TYPE NUMERIC;
+
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN "supplierExtendedPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "quantity"
+) STORED;
+
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN "unitPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN "extendedPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "exchangeRate" * "quantity"
+) STORED;
+
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN "shippingCost" NUMERIC GENERATED ALWAYS AS (
+ "supplierShippingCost" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN "taxAmount" NUMERIC GENERATED ALWAYS AS (
+ "supplierTaxAmount" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN IF NOT EXISTS "taxPercent" NUMERIC GENERATED ALWAYS AS (
+ CASE
+ WHEN (("supplierUnitPrice" + "supplierShippingCost") * "quantity") = 0 THEN 0
+ ELSE "supplierTaxAmount" / (("supplierUnitPrice" + "supplierShippingCost") * "quantity")
+ END
+) STORED;
+
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN "totalAmount" NUMERIC GENERATED ALWAYS AS (
+ ("supplierUnitPrice" * "quantity" * "exchangeRate") +
+ ("supplierShippingCost" * "exchangeRate") +
+ ("supplierTaxAmount" * "exchangeRate")
+) STORED;
+
+
+
+-- Update supplierQuoteLinePrice columns
+-- First drop the generated columns that depend on the columns we want to modify
+ALTER TABLE "supplierQuoteLinePrice" DROP COLUMN IF EXISTS "unitPrice";
+ALTER TABLE "supplierQuoteLinePrice" DROP COLUMN IF EXISTS "supplierExtendedPrice";
+ALTER TABLE "supplierQuoteLinePrice" DROP COLUMN IF EXISTS "extendedPrice";
+ALTER TABLE "supplierQuoteLinePrice" DROP COLUMN IF EXISTS "shippingCost";
+ALTER TABLE "supplierQuoteLinePrice" DROP COLUMN IF EXISTS "taxAmount";
+ALTER TABLE "supplierQuoteLinePrice" DROP COLUMN IF EXISTS "taxPercent";
+
+-- Now we can modify the base columns
+ALTER TABLE "supplierQuoteLinePrice"
+ ALTER COLUMN "supplierUnitPrice" TYPE NUMERIC,
+ ALTER COLUMN "supplierShippingCost" TYPE NUMERIC,
+ ALTER COLUMN "supplierTaxAmount" TYPE NUMERIC,
+ ALTER COLUMN "quantity" TYPE NUMERIC;
+
+-- Finally recreate the generated columns
+ALTER TABLE "supplierQuoteLinePrice" ADD COLUMN "unitPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "supplierQuoteLinePrice" ADD COLUMN "supplierExtendedPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "quantity"
+) STORED;
+
+ALTER TABLE "supplierQuoteLinePrice" ADD COLUMN "extendedPrice" NUMERIC GENERATED ALWAYS AS (
+ "supplierUnitPrice" * "exchangeRate" * "quantity"
+) STORED;
+
+ALTER TABLE "supplierQuoteLinePrice" ADD COLUMN "shippingCost" NUMERIC GENERATED ALWAYS AS (
+ "supplierShippingCost" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "supplierQuoteLinePrice" ADD COLUMN "taxAmount" NUMERIC GENERATED ALWAYS AS (
+ "supplierTaxAmount" * "exchangeRate"
+) STORED;
+
+ALTER TABLE "supplierQuoteLinePrice" ADD COLUMN "taxPercent" NUMERIC GENERATED ALWAYS AS (
+ CASE
+ WHEN ("supplierUnitPrice" + "supplierShippingCost") * "quantity" = 0 THEN 0
+ ELSE "supplierTaxAmount" / (("supplierUnitPrice" + "supplierShippingCost") * "quantity")
+ END
+) STORED;
+
+
+DROP VIEW IF EXISTS "salesOrders";
+CREATE OR REPLACE VIEW "salesOrders" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ s.*,
+ sl."thumbnailPath",
+ sl."itemType",
+ sl."orderTotal",
+ sl."jobs",
+ st."name" AS "shippingTermName",
+ sp."paymentTermId",
+ ss."shippingMethodId",
+ ss."receiptRequestedDate",
+ ss."receiptPromisedDate",
+ ss."dropShipment",
+ ss."shippingCost",
+ l."name" AS "locationName"
+ 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((1+COALESCE(sol."taxPercent", 0))*(COALESCE(sol."saleQuantity", 0)*(COALESCE(sol."unitPrice", 0)) + COALESCE(sol."shippingCost", 0) + COALESCE(sol."addOnCost", 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")
+ ELSE NULL
+ END
+ ) FILTER (WHERE j.id IS NOT NULL) AS "jobs"
+ 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"
+ LEFT JOIN "location" l ON l."id" = ss."locationId";
+
+
+DROP VIEW IF EXISTS "salesOrderLines";
+CREATE OR REPLACE VIEW "salesOrderLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ sl.*,
+ 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"
+ 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
+);
+
+DROP VIEW IF EXISTS "purchaseOrders";
+CREATE OR REPLACE VIEW "purchaseOrders" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ p.*,
+ pl."thumbnailPath",
+ pl."itemType",
+ pl."orderTotal",
+ pd."shippingMethodId",
+ pd."shippingTermId",
+ pd."receiptRequestedDate",
+ pd."receiptPromisedDate",
+ pd."deliveryDate",
+ pd."dropShipment",
+ pp."paymentTermId",
+ l."id" AS "locationId",
+ l."name" AS "locationName"
+ FROM "purchaseOrder" p
+ LEFT JOIN (
+ SELECT
+ pol."purchaseOrderId",
+ MIN(CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END) AS "thumbnailPath",
+ SUM(COALESCE(pol."purchaseQuantity", 0)*(COALESCE(pol."unitPrice", 0)) + COALESCE(pol."shippingCost", 0) + COALESCE(pol."taxAmount", 0)) AS "orderTotal",
+ MIN(i."type") AS "itemType"
+ FROM "purchaseOrderLine" pol
+ LEFT JOIN "item" i
+ ON i."id" = pol."itemId"
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ GROUP BY pol."purchaseOrderId"
+ ) pl ON pl."purchaseOrderId" = p."id"
+ LEFT JOIN "purchaseOrderDelivery" pd ON pd."id" = p."id"
+ LEFT JOIN "shippingTerm" st ON st."id" = pd."shippingTermId"
+ LEFT JOIN "purchaseOrderPayment" pp ON pp."id" = p."id"
+ LEFT JOIN "location" l ON l."id" = pd."locationId";
+
+
+DROP VIEW IF EXISTS "purchaseOrderLines";
+CREATE OR REPLACE VIEW "purchaseOrderLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ pl.*,
+ 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",
+ 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",
+ sp."supplierPartId"
+ FROM "purchaseOrderLine" pl
+ INNER JOIN "purchaseOrder" so ON so.id = pl."purchaseOrderId"
+ LEFT JOIN "modelUpload" mu ON pl."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = pl."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+ LEFT JOIN "supplierPart" sp ON sp."supplierId" = so."supplierId" AND sp."itemId" = i.id
+);
+
+DROP VIEW IF EXISTS "purchaseInvoices";
+CREATE OR REPLACE VIEW "purchaseInvoices" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ pi."id",
+ pi."invoiceId",
+ pi."supplierId",
+ pi."invoiceSupplierId",
+ pi."supplierInteractionId",
+ pi."supplierReference",
+ pi."invoiceSupplierContactId",
+ pi."invoiceSupplierLocationId",
+ pi."locationId",
+ pi."postingDate",
+ pi."dateIssued",
+ pi."dateDue",
+ pi."datePaid",
+ pi."paymentTermId",
+ pi."currencyCode",
+ pi."exchangeRate",
+ pi."exchangeRateUpdatedAt",
+ pi."subtotal",
+ pi."totalDiscount",
+ pi."totalAmount",
+ pi."totalTax",
+ pi."balance",
+ pi."assignee",
+ pi."createdBy",
+ pi."createdAt",
+ pi."updatedBy",
+ pi."updatedAt",
+ pi."internalNotes",
+ pi."customFields",
+ pi."companyId",
+ pl."thumbnailPath",
+ pl."itemType",
+ pl."orderTotal",
+ CASE
+ WHEN pi."dateDue" < CURRENT_DATE AND pi."status" = 'Submitted' THEN 'Overdue'
+ ELSE pi."status"
+ END AS status,
+ pt."name" AS "paymentTermName"
+ FROM "purchaseInvoice" pi
+ LEFT JOIN (
+ SELECT
+ pol."invoiceId",
+ MIN(CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END) AS "thumbnailPath",
+ SUM(COALESCE(pol."quantity", 0)*(COALESCE(pol."unitPrice", 0)) + COALESCE(pol."shippingCost", 0) + COALESCE(pol."taxAmount", 0)) AS "orderTotal",
+ MIN(i."type") AS "itemType"
+ FROM "purchaseInvoiceLine" pol
+ LEFT JOIN "item" i
+ ON i."id" = pol."itemId"
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ GROUP BY pol."invoiceId"
+ ) pl ON pl."invoiceId" = pi."id"
+ LEFT JOIN "paymentTerm" pt ON pt."id" = pi."paymentTermId";
+
+DROP VIEW IF EXISTS "purchaseInvoiceLines";
+CREATE OR REPLACE VIEW "purchaseInvoiceLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ pl.*,
+ 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",
+ sp."supplierPartId"
+ FROM "purchaseInvoiceLine" pl
+ INNER JOIN "purchaseInvoice" pi ON pi.id = pl."invoiceId"
+ LEFT JOIN "modelUpload" mu ON pl."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = pl."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+ LEFT JOIN "supplierPart" sp ON sp."supplierId" = pi."supplierId" AND sp."itemId" = i.id
+);
+
+DROP VIEW IF EXISTS "quoteLines";
+CREATE OR REPLACE VIEW "quoteLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ ql.*,
+ 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"
+ FROM "quoteLine" ql
+ LEFT JOIN "modelUpload" mu ON ql."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = ql."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+);
+
+DROP VIEW IF EXISTS "supplierQuoteLines";
+CREATE OR REPLACE VIEW "supplierQuoteLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ ql.*,
+ i."type" as "itemType",
+ COALESCE(i."thumbnailPath", mu."thumbnailPath") as "thumbnailPath",
+ ic."unitCost" as "unitCost"
+ FROM "supplierQuoteLine" ql
+ INNER JOIN "item" i ON i.id = ql."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+);
+
+-- Drop existing functions first
+DROP FUNCTION IF EXISTS get_job_method(TEXT);
+DROP FUNCTION IF EXISTS get_job_methods_by_method_id(TEXT);
+DROP FUNCTION IF EXISTS get_quote_methods(TEXT);
+DROP FUNCTION IF EXISTS get_quote_methods_by_method_id(TEXT);
+
+-- short circuit tree if it's not a make method:
+CREATE OR REPLACE FUNCTION get_job_method(jid TEXT)
+RETURNS TABLE (
+ "jobId" TEXT,
+ "methodMaterialId" TEXT,
+ "jobMakeMethodId" TEXT,
+ "jobMaterialMakeMethodId" TEXT,
+ "itemId" TEXT,
+ "itemReadableId" TEXT,
+ "description" TEXT,
+ "itemType" TEXT,
+ "quantity" NUMERIC,
+ "unitCost" NUMERIC,
+ "methodType" "methodType",
+ "parentMaterialId" TEXT,
+ "order" DOUBLE PRECISION,
+ "isRoot" BOOLEAN
+) AS $$
+WITH RECURSIVE material AS (
+ SELECT
+ "jobId",
+ "id",
+ "id" AS "jobMakeMethodId",
+ 'Make'::"methodType" AS "methodType",
+ "id" AS "jobMaterialMakeMethodId",
+ "itemId",
+ 'Part' AS "itemType",
+ 1::NUMERIC AS "quantity",
+ 0::NUMERIC AS "unitCost",
+ "parentMaterialId",
+ CAST(1 AS DOUBLE PRECISION) AS "order",
+ TRUE AS "isRoot"
+ FROM
+ "jobMakeMethod"
+ WHERE
+ "jobId" = jid
+ AND "parentMaterialId" IS NULL
+ UNION
+ SELECT
+ child."jobId",
+ child."id",
+ child."jobMakeMethodId",
+ child."methodType",
+ child."jobMaterialMakeMethodId",
+ child."itemId",
+ child."itemType",
+ child."quantity",
+ child."unitCost",
+ parent."id" AS "parentMaterialId",
+ child."order",
+ FALSE AS "isRoot"
+ FROM
+ "jobMaterialWithMakeMethodId" child
+ INNER JOIN material parent ON parent."jobMaterialMakeMethodId" = child."jobMakeMethodId"
+ WHERE parent."methodType" = 'Make'
+)
+SELECT
+ material."jobId",
+ material.id as "methodMaterialId",
+ material."jobMakeMethodId",
+ material."jobMaterialMakeMethodId",
+ material."itemId",
+ item."readableId" AS "itemReadableId",
+ item."name" AS "description",
+ material."itemType",
+ material."quantity",
+ material."unitCost",
+ material."methodType",
+ material."parentMaterialId",
+ material."order",
+ material."isRoot"
+FROM material
+INNER JOIN item ON material."itemId" = item.id
+WHERE material."jobId" = jid
+ORDER BY "order"
+$$ LANGUAGE sql STABLE;
+
+CREATE OR REPLACE FUNCTION get_job_methods_by_method_id(mid TEXT)
+RETURNS TABLE (
+ "jobId" TEXT,
+ "methodMaterialId" TEXT,
+ "jobMakeMethodId" TEXT,
+ "jobMaterialMakeMethodId" TEXT,
+ "itemId" TEXT,
+ "itemReadableId" TEXT,
+ "description" TEXT,
+ "unitOfMeasureCode" TEXT,
+ "itemType" TEXT,
+ "quantity" NUMERIC,
+ "unitCost" NUMERIC,
+ "methodType" "methodType",
+ "parentMaterialId" TEXT,
+ "order" DOUBLE PRECISION,
+ "isRoot" BOOLEAN
+) AS $$
+WITH RECURSIVE material AS (
+ SELECT
+ "jobId",
+ "id",
+ "id" AS "jobMakeMethodId",
+ 'Make'::"methodType" AS "methodType",
+ "id" AS "jobMaterialMakeMethodId",
+ "itemId",
+ 'Part' AS "itemType",
+ 1::NUMERIC AS "quantity",
+ 0::NUMERIC AS "unitCost",
+ "parentMaterialId",
+ CAST(1 AS DOUBLE PRECISION) AS "order",
+ TRUE AS "isRoot"
+ FROM
+ "jobMakeMethod"
+ WHERE
+ "id" = mid
+ UNION
+ SELECT
+ child."jobId",
+ child."id",
+ child."jobMakeMethodId",
+ child."methodType",
+ child."jobMaterialMakeMethodId",
+ child."itemId",
+ child."itemType",
+ child."quantity",
+ child."unitCost",
+ parent."id" AS "parentMaterialId",
+ child."order",
+ FALSE AS "isRoot"
+ FROM
+ "jobMaterialWithMakeMethodId" child
+ INNER JOIN material parent ON parent."jobMaterialMakeMethodId" = child."jobMakeMethodId"
+ WHERE parent."methodType" = 'Make'
+)
+SELECT
+ material."jobId",
+ material.id as "methodMaterialId",
+ material."jobMakeMethodId",
+ material."jobMaterialMakeMethodId",
+ material."itemId",
+ item."readableId" AS "itemReadableId",
+ item."name" AS "description",
+ item."unitOfMeasureCode",
+ material."itemType",
+ material."quantity",
+ material."unitCost",
+ material."methodType",
+ material."parentMaterialId",
+ material."order",
+ material."isRoot"
+FROM material
+INNER JOIN item ON material."itemId" = item.id
+ORDER BY "order"
+$$ LANGUAGE sql STABLE;
+
+CREATE OR REPLACE FUNCTION get_quote_methods(qid TEXT)
+RETURNS TABLE (
+ "quoteId" TEXT,
+ "quoteLineId" TEXT,
+ "methodMaterialId" TEXT,
+ "quoteMakeMethodId" TEXT,
+ "quoteMaterialMakeMethodId" TEXT,
+ "itemId" TEXT,
+ "itemReadableId" TEXT,
+ "description" TEXT,
+ "itemType" TEXT,
+ "quantity" NUMERIC,
+ "unitCost" NUMERIC,
+ "methodType" "methodType",
+ "parentMaterialId" TEXT,
+ "order" DOUBLE PRECISION,
+ "isRoot" BOOLEAN
+) AS $$
+WITH RECURSIVE material AS (
+ SELECT
+ "quoteId",
+ "quoteLineId",
+ "id",
+ "id" AS "quoteMakeMethodId",
+ 'Make'::"methodType" AS "methodType",
+ "id" AS "quoteMaterialMakeMethodId",
+ "itemId",
+ 'Part' AS "itemType",
+ 1::NUMERIC AS "quantity",
+ 0::NUMERIC AS "unitCost",
+ "parentMaterialId",
+ CAST(1 AS DOUBLE PRECISION) AS "order",
+ TRUE AS "isRoot"
+ FROM
+ "quoteMakeMethod"
+ WHERE
+ "quoteId" = qid
+ AND "parentMaterialId" IS NULL
+ UNION
+ SELECT
+ child."quoteId",
+ child."quoteLineId",
+ child."id",
+ child."quoteMakeMethodId",
+ child."methodType",
+ child."quoteMaterialMakeMethodId",
+ child."itemId",
+ child."itemType",
+ child."quantity",
+ child."unitCost",
+ parent."id" AS "parentMaterialId",
+ child."order",
+ FALSE AS "isRoot"
+ FROM
+ "quoteMaterialWithMakeMethodId" child
+ INNER JOIN material parent ON parent."quoteMaterialMakeMethodId" = child."quoteMakeMethodId"
+)
+SELECT
+ material."quoteId",
+ material."quoteLineId",
+ material.id as "methodMaterialId",
+ material."quoteMakeMethodId",
+ material."quoteMaterialMakeMethodId",
+ material."itemId",
+ item."readableId" AS "itemReadableId",
+ item."name" AS "description",
+ material."itemType",
+ material."quantity",
+ material."unitCost",
+ material."methodType",
+ material."parentMaterialId",
+ material."order",
+ material."isRoot"
+FROM material
+INNER JOIN item ON material."itemId" = item.id
+WHERE material."quoteId" = qid
+ORDER BY "order"
+$$ LANGUAGE sql STABLE;
+
+CREATE OR REPLACE FUNCTION get_quote_methods_by_method_id(mid TEXT)
+RETURNS TABLE (
+ "quoteId" TEXT,
+ "quoteLineId" TEXT,
+ "methodMaterialId" TEXT,
+ "quoteMakeMethodId" TEXT,
+ "quoteMaterialMakeMethodId" TEXT,
+ "itemId" TEXT,
+ "itemReadableId" TEXT,
+ "description" TEXT,
+ "unitOfMeasureCode" TEXT,
+ "itemType" TEXT,
+ "quantity" NUMERIC,
+ "unitCost" NUMERIC,
+ "methodType" "methodType",
+ "parentMaterialId" TEXT,
+ "order" DOUBLE PRECISION,
+ "isRoot" BOOLEAN
+) AS $$
+WITH RECURSIVE material AS (
+ SELECT
+ "quoteId",
+ "quoteLineId",
+ "id",
+ "id" AS "quoteMakeMethodId",
+ 'Make'::"methodType" AS "methodType",
+ "id" AS "quoteMaterialMakeMethodId",
+ "itemId",
+ 'Part' AS "itemType",
+ 1::NUMERIC AS "quantity",
+ 0::NUMERIC AS "unitCost",
+ "parentMaterialId",
+ CAST(1 AS DOUBLE PRECISION) AS "order",
+ TRUE AS "isRoot"
+ FROM
+ "quoteMakeMethod"
+ WHERE
+ "id" = mid
+ UNION
+ SELECT
+ child."quoteId",
+ child."quoteLineId",
+ child."id",
+ child."quoteMakeMethodId",
+ child."methodType",
+ child."quoteMaterialMakeMethodId",
+ child."itemId",
+ child."itemType",
+ child."quantity",
+ child."unitCost",
+ parent."id" AS "parentMaterialId",
+ child."order",
+ FALSE AS "isRoot"
+ FROM
+ "quoteMaterialWithMakeMethodId" child
+ INNER JOIN material parent ON parent."quoteMaterialMakeMethodId" = child."quoteMakeMethodId"
+ WHERE parent."methodType" = 'Make'
+)
+SELECT
+ material."quoteId",
+ material."quoteLineId",
+ material.id as "methodMaterialId",
+ material."quoteMakeMethodId",
+ material."quoteMaterialMakeMethodId",
+ material."itemId",
+ item."readableId" AS "itemReadableId",
+ item."name" AS "description",
+ item."unitOfMeasureCode",
+ material."itemType",
+ material."quantity",
+ material."unitCost",
+ material."methodType",
+ material."parentMaterialId",
+ material."order",
+ material."isRoot"
+FROM material
+INNER JOIN item ON material."itemId" = item.id
+ORDER BY "order"
+$$ LANGUAGE sql STABLE;
+
+
+DROP FUNCTION IF EXISTS get_active_job_operations_by_location;
+CREATE OR REPLACE FUNCTION get_active_job_operations_by_location(
+ location_id TEXT,
+ work_center_ids TEXT[]
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "priority" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobMakeMethodId" TEXT,
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH relevant_jobs AS (
+ SELECT
+ j."id",
+ j."jobId",
+ j."status",
+ j."dueDate",
+ j."deadlineType",
+ j."customerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ mu."thumbnailPath"
+ FROM "job" j
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "modelUpload" mu ON mu.id = j."modelUploadId"
+ WHERE j."locationId" = location_id
+ AND (j."status" = 'Ready' OR j."status" = 'In Progress' OR j."status" = 'Paused')
+ )
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."priority",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ jo."jobMakeMethodId",
+ rj."jobId" AS "jobReadableId",
+ rj."status" AS "jobStatus",
+ rj."dueDate" AS "jobDueDate",
+ rj."deadlineType" AS "jobDeadlineType",
+ rj."customerId" AS "jobCustomerId",
+ rj."salesOrderReadableId",
+ rj."salesOrderId",
+ rj."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ CASE
+ WHEN rj."status" = 'Paused' THEN 'Paused'
+ ELSE jo."status"
+ END AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(rj."thumbnailPath", mu."thumbnailPath")
+ ELSE mu."thumbnailPath"
+ END as "thumbnailPath"
+ FROM "jobOperation" jo
+ JOIN relevant_jobs rj ON rj.id = jo."jobId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ WHERE CASE
+ WHEN array_length(work_center_ids, 1) > 0 THEN
+ jo."workCenterId" = ANY(work_center_ids) AND jo."status" != 'Done' AND jo."status" != 'Canceled'
+ ELSE jo."status" != 'Done' AND jo."status" != 'Canceled'
+ END
+ ORDER BY jo."priority";
+END;
+$$ LANGUAGE plpgsql;
+
+
+DROP FUNCTION IF EXISTS get_active_job_operations_by_location;
+CREATE OR REPLACE FUNCTION get_active_job_operations_by_location(
+ location_id TEXT,
+ work_center_ids TEXT[]
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "priority" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobMakeMethodId" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[],
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH relevant_jobs AS (
+ SELECT
+ j."id",
+ j."jobId",
+ j."status",
+ j."dueDate",
+ j."deadlineType",
+ j."customerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ mu."thumbnailPath"
+ FROM "job" j
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "modelUpload" mu ON mu.id = j."modelUploadId"
+ WHERE j."locationId" = location_id
+ AND (j."status" = 'Ready' OR j."status" = 'In Progress' OR j."status" = 'Paused')
+ )
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."priority",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ jo."jobMakeMethodId",
+ jo."assignee",
+ jo."tags",
+ rj."jobId" AS "jobReadableId",
+ rj."status" AS "jobStatus",
+ rj."dueDate" AS "jobDueDate",
+ rj."deadlineType" AS "jobDeadlineType",
+ rj."customerId" AS "jobCustomerId",
+ rj."salesOrderReadableId",
+ rj."salesOrderId",
+ rj."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ CASE
+ WHEN rj."status" = 'Paused' THEN 'Paused'
+ ELSE jo."status"
+ END AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(rj."thumbnailPath", mu."thumbnailPath")
+ ELSE mu."thumbnailPath"
+ END as "thumbnailPath"
+ FROM "jobOperation" jo
+ JOIN relevant_jobs rj ON rj.id = jo."jobId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ WHERE CASE
+ WHEN array_length(work_center_ids, 1) > 0 THEN
+ jo."workCenterId" = ANY(work_center_ids) AND jo."status" != 'Done' AND jo."status" != 'Canceled'
+ ELSE jo."status" != 'Done' AND jo."status" != 'Canceled'
+ END
+ ORDER BY jo."priority";
+END;
+$$ LANGUAGE plpgsql;
+
+DROP FUNCTION IF EXISTS get_recent_job_operations_by_employee;
+CREATE OR REPLACE FUNCTION get_recent_job_operations_by_employee(
+ employee_id TEXT,
+ company_id TEXT
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[]
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH recent_production_events AS (
+ SELECT "jobOperationId", MAX("endTime") as "endTime"
+ FROM "productionEvent"
+ WHERE "employeeId" = employee_id AND "companyId" = company_id
+ GROUP BY "jobOperationId"
+ )
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ j."jobId" AS "jobReadableId",
+ j."status" AS "jobStatus",
+ j."dueDate" AS "jobDueDate",
+ j."deadlineType" AS "jobDeadlineType",
+ j."customerId" AS "jobCustomerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ jo."status" AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(j_mu."thumbnailPath", i_mu."thumbnailPath")
+ ELSE COALESCE(i."thumbnailPath", i_mu."thumbnailPath")
+ END as "thumbnailPath",
+ jo."assignee",
+ jo."tags"
+ FROM recent_production_events rpe
+ JOIN "jobOperation" jo ON jo.id = rpe."jobOperationId"
+ JOIN "job" j ON j.id = jo."jobId"
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" j_mu ON j_mu.id = j."modelUploadId"
+ LEFT JOIN "modelUpload" i_mu ON i_mu.id = i."modelUploadId"
+ ORDER BY rpe."endTime" DESC
+ LIMIT 20;
+END;
+$$ LANGUAGE plpgsql;
+
+
+DROP FUNCTION IF EXISTS get_active_job_operations_by_employee;
+CREATE OR REPLACE FUNCTION get_active_job_operations_by_employee(
+ employee_id TEXT,
+ company_id TEXT
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[]
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH active_production_events AS (
+ SELECT DISTINCT "jobOperationId"
+ FROM "productionEvent"
+ WHERE "employeeId" = employee_id AND "endTime" IS NULL AND "companyId" = company_id
+ )
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ j."jobId" AS "jobReadableId",
+ j."status" AS "jobStatus",
+ j."dueDate" AS "jobDueDate",
+ j."deadlineType" AS "jobDeadlineType",
+ j."customerId" AS "jobCustomerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ jo."status" AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(j_mu."thumbnailPath", i_mu."thumbnailPath")
+ ELSE COALESCE(i."thumbnailPath", i_mu."thumbnailPath")
+ END as "thumbnailPath",
+ jo."assignee",
+ jo."tags"
+ FROM "jobOperation" jo
+ JOIN "job" j ON j.id = jo."jobId"
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" j_mu ON j_mu.id = j."modelUploadId"
+ LEFT JOIN "modelUpload" i_mu ON i_mu.id = i."modelUploadId"
+ JOIN active_production_events ape ON ape."jobOperationId" = jo.id;
+END;
+$$ LANGUAGE plpgsql;
+
+
+DROP FUNCTION IF EXISTS get_active_job_operations_by_location;
+CREATE OR REPLACE FUNCTION get_active_job_operations_by_location(
+ location_id TEXT,
+ work_center_ids TEXT[]
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "priority" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobMakeMethodId" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[],
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH relevant_jobs AS (
+ SELECT
+ j."id",
+ j."jobId",
+ j."status",
+ j."dueDate",
+ j."deadlineType",
+ j."customerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ mu."thumbnailPath"
+ FROM "job" j
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "modelUpload" mu ON mu.id = j."modelUploadId"
+ WHERE j."locationId" = location_id
+ AND (j."status" = 'Ready' OR j."status" = 'In Progress' OR j."status" = 'Paused')
+ )
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."priority",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ jo."jobMakeMethodId",
+ jo."assignee",
+ jo."tags",
+ rj."jobId" AS "jobReadableId",
+ rj."status" AS "jobStatus",
+ rj."dueDate" AS "jobDueDate",
+ rj."deadlineType" AS "jobDeadlineType",
+ rj."customerId" AS "jobCustomerId",
+ rj."salesOrderReadableId",
+ rj."salesOrderId",
+ rj."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ CASE
+ WHEN rj."status" = 'Paused' THEN 'Paused'
+ ELSE jo."status"
+ END AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(rj."thumbnailPath", mu."thumbnailPath")
+ ELSE COALESCE(i."thumbnailPath", mu."thumbnailPath")
+ END as "thumbnailPath"
+ FROM "jobOperation" jo
+ JOIN relevant_jobs rj ON rj.id = jo."jobId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ WHERE CASE
+ WHEN array_length(work_center_ids, 1) > 0 THEN
+ jo."workCenterId" = ANY(work_center_ids) AND jo."status" != 'Done' AND jo."status" != 'Canceled'
+ ELSE jo."status" != 'Done' AND jo."status" != 'Canceled'
+ END
+ ORDER BY jo."priority";
+END;
+$$ LANGUAGE plpgsql;
+
+DROP FUNCTION IF EXISTS get_assigned_job_operations;
+CREATE OR REPLACE FUNCTION get_assigned_job_operations(
+ user_id TEXT,
+ company_id TEXT
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[]
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ j."jobId" AS "jobReadableId",
+ j."status" AS "jobStatus",
+ j."dueDate" AS "jobDueDate",
+ j."deadlineType" AS "jobDeadlineType",
+ j."customerId" AS "jobCustomerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ CASE
+ WHEN j."status" = 'Paused' THEN 'Paused'
+ ELSE jo."status"
+ END AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(j_mu."thumbnailPath", i_mu."thumbnailPath")
+ ELSE COALESCE(i."thumbnailPath", i_mu."thumbnailPath")
+ END as "thumbnailPath",
+ jo."assignee",
+ jo."tags"
+ FROM "jobOperation" jo
+ JOIN "job" j ON j.id = jo."jobId"
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" j_mu ON j_mu.id = j."modelUploadId"
+ LEFT JOIN "modelUpload" i_mu ON i_mu.id = i."modelUploadId"
+ WHERE jo."assignee" = user_id
+ AND jo."status" IN ('Todo', 'Ready', 'Waiting', 'In Progress', 'Paused')
+ AND j."status" IN ('Ready', 'In Progress', 'Paused')
+ AND j."companyId" = company_id
+ ORDER BY jo."priority";
+END;
+$$ LANGUAGE plpgsql;
+
+DROP FUNCTION IF EXISTS get_assigned_job_operations;
+CREATE OR REPLACE FUNCTION get_assigned_job_operations(
+ user_id TEXT,
+ company_id TEXT
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[]
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ j."jobId" AS "jobReadableId",
+ j."status" AS "jobStatus",
+ j."dueDate" AS "jobDueDate",
+ j."deadlineType" AS "jobDeadlineType",
+ j."customerId" AS "jobCustomerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ CASE
+ WHEN j."status" = 'Paused' THEN 'Paused'
+ ELSE jo."status"
+ END AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(i."thumbnailPath", j_mu."thumbnailPath", i_mu."thumbnailPath")
+ ELSE COALESCE(i."thumbnailPath", i_mu."thumbnailPath")
+ END as "thumbnailPath",
+ jo."assignee",
+ jo."tags"
+ FROM "jobOperation" jo
+ JOIN "job" j ON j.id = jo."jobId"
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" j_mu ON j_mu.id = j."modelUploadId"
+ LEFT JOIN "modelUpload" i_mu ON i_mu.id = i."modelUploadId"
+ WHERE jo."assignee" = user_id
+ AND jo."status" IN ('Todo', 'Ready', 'Waiting', 'In Progress', 'Paused')
+ AND j."status" IN ('Ready', 'In Progress', 'Paused')
+ AND j."companyId" = company_id
+ ORDER BY jo."priority";
+END;
+$$ LANGUAGE plpgsql;
+
+DROP FUNCTION IF EXISTS get_recent_job_operations_by_employee;
+CREATE OR REPLACE FUNCTION get_recent_job_operations_by_employee(
+ employee_id TEXT,
+ company_id TEXT
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[]
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH recent_production_events AS (
+ SELECT "jobOperationId", MAX("endTime") as "endTime"
+ FROM "productionEvent"
+ WHERE "employeeId" = employee_id AND "companyId" = company_id
+ GROUP BY "jobOperationId"
+ )
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ j."jobId" AS "jobReadableId",
+ j."status" AS "jobStatus",
+ j."dueDate" AS "jobDueDate",
+ j."deadlineType" AS "jobDeadlineType",
+ j."customerId" AS "jobCustomerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ jo."status" AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(i."thumbnailPath", j_mu."thumbnailPath", i_mu."thumbnailPath")
+ ELSE COALESCE(i."thumbnailPath", i_mu."thumbnailPath")
+ END as "thumbnailPath",
+ jo."assignee",
+ jo."tags"
+ FROM recent_production_events rpe
+ JOIN "jobOperation" jo ON jo.id = rpe."jobOperationId"
+ JOIN "job" j ON j.id = jo."jobId"
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" j_mu ON j_mu.id = j."modelUploadId"
+ LEFT JOIN "modelUpload" i_mu ON i_mu.id = i."modelUploadId"
+ ORDER BY rpe."endTime" DESC
+ LIMIT 20;
+END;
+$$ LANGUAGE plpgsql;
+
+
+DROP FUNCTION IF EXISTS get_active_job_operations_by_employee;
+CREATE OR REPLACE FUNCTION get_active_job_operations_by_employee(
+ employee_id TEXT,
+ company_id TEXT
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[]
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH active_production_events AS (
+ SELECT DISTINCT "jobOperationId"
+ FROM "productionEvent"
+ WHERE "employeeId" = employee_id AND "endTime" IS NULL AND "companyId" = company_id
+ )
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ j."jobId" AS "jobReadableId",
+ j."status" AS "jobStatus",
+ j."dueDate" AS "jobDueDate",
+ j."deadlineType" AS "jobDeadlineType",
+ j."customerId" AS "jobCustomerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ jo."status" AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(i."thumbnailPath", j_mu."thumbnailPath", i_mu."thumbnailPath")
+ ELSE COALESCE(i."thumbnailPath", i_mu."thumbnailPath")
+ END as "thumbnailPath",
+ jo."assignee",
+ jo."tags"
+ FROM "jobOperation" jo
+ JOIN "job" j ON j.id = jo."jobId"
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" j_mu ON j_mu.id = j."modelUploadId"
+ LEFT JOIN "modelUpload" i_mu ON i_mu.id = i."modelUploadId"
+ JOIN active_production_events ape ON ape."jobOperationId" = jo.id;
+END;
+$$ LANGUAGE plpgsql;
+
+
+DROP FUNCTION IF EXISTS get_active_job_operations_by_location;
+CREATE OR REPLACE FUNCTION get_active_job_operations_by_location(
+ location_id TEXT,
+ work_center_ids TEXT[]
+)
+RETURNS TABLE (
+ "id" TEXT,
+ "jobId" TEXT,
+ "operationOrder" DOUBLE PRECISION,
+ "priority" DOUBLE PRECISION,
+ "processId" TEXT,
+ "workCenterId" TEXT,
+ "description" TEXT,
+ "setupTime" NUMERIC,
+ "setupUnit" factor,
+ "laborTime" NUMERIC,
+ "laborUnit" factor,
+ "machineTime" NUMERIC,
+ "machineUnit" factor,
+ "operationOrderType" "methodOperationOrder",
+ "jobMakeMethodId" TEXT,
+ "assignee" TEXT,
+ "tags" TEXT[],
+ "jobReadableId" TEXT,
+ "jobStatus" "jobStatus",
+ "jobDueDate" DATE,
+ "jobDeadlineType" "deadlineType",
+ "jobCustomerId" TEXT,
+ "salesOrderReadableId" TEXT,
+ "salesOrderId" TEXT,
+ "salesOrderLineId" TEXT,
+ "parentMaterialId" TEXT,
+ "itemReadableId" TEXT,
+ "itemDescription" TEXT,
+ "operationStatus" "jobOperationStatus",
+ "operationQuantity" NUMERIC,
+ "quantityComplete" NUMERIC,
+ "quantityScrapped" NUMERIC,
+ "thumbnailPath" TEXT
+)
+SECURITY INVOKER
+AS $$
+BEGIN
+ RETURN QUERY
+ WITH relevant_jobs AS (
+ SELECT
+ j."id",
+ j."jobId",
+ j."status",
+ j."dueDate",
+ j."deadlineType",
+ j."customerId",
+ so."salesOrderId" AS "salesOrderReadableId",
+ so."id" AS "salesOrderId",
+ j."salesOrderLineId",
+ mu."thumbnailPath"
+ FROM "job" j
+ LEFT JOIN "salesOrderLine" sol ON sol."id" = j."salesOrderLineId"
+ LEFT JOIN "salesOrder" so ON so."id" = sol."salesOrderId"
+ LEFT JOIN "modelUpload" mu ON mu.id = j."modelUploadId"
+ WHERE j."locationId" = location_id
+ AND (j."status" = 'Ready' OR j."status" = 'In Progress' OR j."status" = 'Paused')
+ )
+ SELECT
+ jo."id",
+ jo."jobId",
+ jo."order" AS "operationOrder",
+ jo."priority",
+ jo."processId",
+ jo."workCenterId",
+ jo."description",
+ jo."setupTime",
+ jo."setupUnit",
+ jo."laborTime",
+ jo."laborUnit",
+ jo."machineTime",
+ jo."machineUnit",
+ jo."operationOrder" AS "operationOrderType",
+ jo."jobMakeMethodId",
+ jo."assignee",
+ jo."tags",
+ rj."jobId" AS "jobReadableId",
+ rj."status" AS "jobStatus",
+ rj."dueDate" AS "jobDueDate",
+ rj."deadlineType" AS "jobDeadlineType",
+ rj."customerId" AS "jobCustomerId",
+ rj."salesOrderReadableId",
+ rj."salesOrderId",
+ rj."salesOrderLineId",
+ jmm."parentMaterialId",
+ i."readableId" as "itemReadableId",
+ i."name" as "itemDescription",
+ CASE
+ WHEN rj."status" = 'Paused' THEN 'Paused'
+ ELSE jo."status"
+ END AS "operationStatus",
+ jo."operationQuantity",
+ jo."quantityComplete",
+ jo."quantityScrapped",
+ CASE
+ WHEN jmm."parentMaterialId" IS NULL THEN COALESCE(i."thumbnailPath", rj."thumbnailPath", mu."thumbnailPath")
+ ELSE COALESCE(i."thumbnailPath", mu."thumbnailPath")
+ END as "thumbnailPath"
+ FROM "jobOperation" jo
+ JOIN relevant_jobs rj ON rj.id = jo."jobId"
+ LEFT JOIN "jobMakeMethod" jmm ON jo."jobMakeMethodId" = jmm.id
+ LEFT JOIN "item" i ON jmm."itemId" = i.id
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ WHERE CASE
+ WHEN array_length(work_center_ids, 1) > 0 THEN
+ jo."workCenterId" = ANY(work_center_ids) AND jo."status" != 'Done' AND jo."status" != 'Canceled'
+ ELSE jo."status" != 'Done' AND jo."status" != 'Canceled'
+ END
+ ORDER BY jo."priority";
+END;
+$$ LANGUAGE plpgsql;
+
+-- Update quantity columns to NUMERIC
+ALTER TABLE "receiptLineTracking" ALTER COLUMN "quantity" TYPE NUMERIC;
+ALTER TABLE "jobProductionTracking" ALTER COLUMN "quantity" TYPE NUMERIC;
+ALTER TABLE "jobMaterialTracking" ALTER COLUMN "quantity" TYPE NUMERIC;
+
+
+DROP VIEW IF EXISTS "purchaseOrderLines";
+ALTER TABLE "purchaseOrderLine" DROP COLUMN "taxPercent";
+
+DROP VIEW IF EXISTS "purchaseInvoiceLines";
+ALTER TABLE "purchaseInvoiceLine" DROP COLUMN "taxPercent";
+
+ALTER TABLE "purchaseOrderLine" ADD COLUMN "taxPercent" NUMERIC GENERATED ALWAYS AS (
+ CASE
+ WHEN ("supplierUnitPrice" * "purchaseQuantity" + "supplierShippingCost") = 0 THEN 0
+ ELSE "supplierTaxAmount" / ("supplierUnitPrice" * "purchaseQuantity" + "supplierShippingCost")
+ END
+) STORED;
+
+DROP VIEW IF EXISTS "purchaseOrderLines";
+CREATE OR REPLACE VIEW "purchaseOrderLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ pl.*,
+ 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",
+ 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",
+ sp."supplierPartId"
+ FROM "purchaseOrderLine" pl
+ INNER JOIN "purchaseOrder" so ON so.id = pl."purchaseOrderId"
+ LEFT JOIN "modelUpload" mu ON pl."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = pl."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+ LEFT JOIN "supplierPart" sp ON sp."supplierId" = so."supplierId" AND sp."itemId" = i.id
+);
+
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN "taxPercent" NUMERIC GENERATED ALWAYS AS (
+ CASE
+ WHEN ("supplierUnitPrice" * "quantity" + "supplierShippingCost") = 0 THEN 0
+ ELSE "supplierTaxAmount" / ("supplierUnitPrice" * "quantity" + "supplierShippingCost")
+ END
+) STORED;
+
+DROP VIEW IF EXISTS "purchaseInvoiceLines";
+CREATE OR REPLACE VIEW "purchaseInvoiceLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ pl.*,
+ 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",
+ sp."supplierPartId"
+ FROM "purchaseInvoiceLine" pl
+ INNER JOIN "purchaseInvoice" pi ON pi.id = pl."invoiceId"
+ LEFT JOIN "modelUpload" mu ON pl."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = pl."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+ LEFT JOIN "supplierPart" sp ON sp."supplierId" = pi."supplierId" AND sp."itemId" = i.id
+);
+
+ALTER TABLE "supplierQuoteLinePrice" DROP COLUMN "taxPercent";
+ALTER TABLE "supplierQuoteLinePrice" ADD COLUMN "taxPercent" NUMERIC GENERATED ALWAYS AS (
+ CASE
+ WHEN ("supplierUnitPrice" * "quantity" + "supplierShippingCost") = 0 THEN 0
+ ELSE "supplierTaxAmount" / ("supplierUnitPrice" * "quantity" + "supplierShippingCost")
+ END
+) STORED;
+
+COMMIT;
\ No newline at end of file
diff --git a/packages/form/src/components/Number.tsx b/packages/form/src/components/Number.tsx
index 07b9e97b75..2cd1b4d5eb 100644
--- a/packages/form/src/components/Number.tsx
+++ b/packages/form/src/components/Number.tsx
@@ -40,6 +40,12 @@ const Number = forwardRef<HTMLInputElement, FormNumberProps>(
ref
) => {
const { getInputProps, error } = useField(name);
+ const formatOptions =
+ rest.formatOptions ??
+ ({
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 10,
+ } satisfies Intl.NumberFormatOptions);
return (
<FormControl isInvalid={!!error} isRequired={isRequired}>
@@ -57,6 +63,7 @@ const Number = forwardRef<HTMLInputElement, FormNumberProps>(
id: name,
...rest,
})}
+ formatOptions={formatOptions}
>
<NumberInputGroup className="relative">
<NumberInput isReadOnly={isReadOnly} ref={ref} />