From 829ba7e747cee5cbd6464dd727e317f28a3a77cd Mon Sep 17 00:00:00 2001 From: dhinesh-m24 Date: Wed, 25 Feb 2026 12:49:12 +0530 Subject: [PATCH] fix: Update Invoice schema, queries, mutations and remove ShiftDayCompletion related files --- .../connector/invoice/mutations.gql | 40 ++ .../dataconnect/connector/invoice/queries.gql | 12 + .../shiftDayCompletion/mutations.gql | 129 ------ .../connector/shiftDayCompletion/queries.gql | 417 ------------------ backend/dataconnect/schema/invoice.gql | 3 + .../dataconnect/schema/shiftDayCompletion.gql | 45 -- 6 files changed, 55 insertions(+), 591 deletions(-) delete mode 100644 backend/dataconnect/connector/shiftDayCompletion/mutations.gql delete mode 100644 backend/dataconnect/connector/shiftDayCompletion/queries.gql delete mode 100644 backend/dataconnect/schema/shiftDayCompletion.gql diff --git a/backend/dataconnect/connector/invoice/mutations.gql b/backend/dataconnect/connector/invoice/mutations.gql index 53af2552..4b415587 100644 --- a/backend/dataconnect/connector/invoice/mutations.gql +++ b/backend/dataconnect/connector/invoice/mutations.gql @@ -5,6 +5,7 @@ mutation createInvoice( $vendorId: UUID! $businessId: UUID! $orderId: UUID! + $shiftId: UUID $paymentTerms: InovicePaymentTerms $invoiceNumber: String! @@ -31,6 +32,7 @@ mutation createInvoice( vendorId: $vendorId businessId: $businessId orderId: $orderId + shiftId: $shiftId paymentTerms: $paymentTerms invoiceNumber: $invoiceNumber @@ -61,6 +63,7 @@ mutation updateInvoice( $vendorId: UUID $businessId: UUID $orderId: UUID + $shiftId: UUID $paymentTerms: InovicePaymentTerms $invoiceNumber: String @@ -92,6 +95,7 @@ mutation updateInvoice( vendorId: $vendorId businessId: $businessId orderId: $orderId + shiftId: $shiftId paymentTerms: $paymentTerms invoiceNumber: $invoiceNumber @@ -121,3 +125,39 @@ mutation updateInvoice( mutation deleteInvoice($id: UUID!) @auth(level: USER) { invoice_delete(id: $id) } + +# ------------------------------------------------------------ +# APPROVE INVOICE +# Called by the client to approve a shift-day completion record. +# Sets status to APPROVED, triggering the invoice-ready state. +# ------------------------------------------------------------ +mutation approveInvoice($id: UUID!) @auth(level: USER) { + invoice_update( + id: $id + data: { + status: APPROVED + } + ) +} + +# ------------------------------------------------------------ +# DISPUTE INVOICE +# Called by the client to dispute a shift-day completion record. +# Sets status to DISPUTED and stores the dispute details. +# ------------------------------------------------------------ +mutation disputeInvoice( + $id: UUID! + $disputedItems: Any + $disputeReason: String! + $disputeDetails: String +) @auth(level: USER) { + invoice_update( + id: $id + data: { + status: DISPUTED + disputedItems: $disputedItems + disputeReason: $disputeReason + disputeDetails: $disputeDetails + } + ) +} diff --git a/backend/dataconnect/connector/invoice/queries.gql b/backend/dataconnect/connector/invoice/queries.gql index 53c33a15..9ee1df24 100644 --- a/backend/dataconnect/connector/invoice/queries.gql +++ b/backend/dataconnect/connector/invoice/queries.gql @@ -13,6 +13,7 @@ query listInvoices( vendorId businessId orderId + shiftId paymentTerms invoiceNumber @@ -74,6 +75,7 @@ query getInvoiceById($id: UUID!) @auth(level: USER) { vendorId businessId orderId + shiftId paymentTerms invoiceNumber @@ -144,6 +146,7 @@ query listInvoicesByVendorId( vendorId businessId orderId + shiftId paymentTerms invoiceNumber @@ -214,6 +217,7 @@ query listInvoicesByBusinessId( vendorId businessId orderId + shiftId paymentTerms invoiceNumber @@ -284,6 +288,7 @@ query listInvoicesByOrderId( vendorId businessId orderId + shiftId paymentTerms invoiceNumber @@ -354,6 +359,7 @@ query listInvoicesByStatus( vendorId businessId orderId + shiftId paymentTerms invoiceNumber @@ -407,11 +413,14 @@ query listInvoicesByStatus( # ------------------------------------------------------------ # FILTER INVOICES (multi filters) # NOTE: Timestamp filters use ge/le (NOT gte/lte) +# Supports shiftId filter — use with status: PENDING_REVIEW to list +# shift-day completion records awaiting client approval. # ------------------------------------------------------------ query filterInvoices( $vendorId: UUID $businessId: UUID $orderId: UUID + $shiftId: UUID $status: InvoiceStatus $issueDateFrom: Timestamp @@ -428,6 +437,7 @@ query filterInvoices( vendorId: { eq: $vendorId } businessId: { eq: $businessId } orderId: { eq: $orderId } + shiftId: { eq: $shiftId } status: { eq: $status } issueDate: { ge: $issueDateFrom, le: $issueDateTo } @@ -443,6 +453,7 @@ query filterInvoices( vendorId businessId orderId + shiftId paymentTerms invoiceNumber @@ -517,6 +528,7 @@ query listOverdueInvoices( vendorId businessId orderId + shiftId paymentTerms invoiceNumber diff --git a/backend/dataconnect/connector/shiftDayCompletion/mutations.gql b/backend/dataconnect/connector/shiftDayCompletion/mutations.gql deleted file mode 100644 index edaa5b92..00000000 --- a/backend/dataconnect/connector/shiftDayCompletion/mutations.gql +++ /dev/null @@ -1,129 +0,0 @@ - -# ------------------------------------------------------------ -# CREATE — called automatically at the end of each shift day -# ------------------------------------------------------------ -mutation createShiftDayCompletion( - $shiftId: UUID! - $orderId: UUID! - $businessId: UUID! - $vendorId: UUID! - $dayDate: Timestamp! - $dayNumber: Int! - $hours: Float - $cost: Float - $staffSummary: Any - $createdBy: String -) @auth(level: USER) { - shiftDayCompletion_insert( - data: { - shiftId: $shiftId - orderId: $orderId - businessId: $businessId - vendorId: $vendorId - dayDate: $dayDate - dayNumber: $dayNumber - status: PENDING_REVIEW - hours: $hours - cost: $cost - staffSummary: $staffSummary - createdBy: $createdBy - } - ) -} - -# ------------------------------------------------------------ -# APPROVE — client approves a daily completion record -# ------------------------------------------------------------ -mutation approveShiftDayCompletion( - $id: UUID! - $reviewedBy: String! - $reviewedAt: Timestamp! -) @auth(level: USER) { - shiftDayCompletion_update( - id: $id - data: { - status: APPROVED - reviewedBy: $reviewedBy - reviewedAt: $reviewedAt - } - ) -} - -# ------------------------------------------------------------ -# DISPUTE — client disputes a daily completion record -# ------------------------------------------------------------ -mutation disputeShiftDayCompletion( - $id: UUID! - $reviewedBy: String! - $reviewedAt: Timestamp! - $disputeReason: String! - $disputeDetails: String - $disputedItems: Any -) @auth(level: USER) { - shiftDayCompletion_update( - id: $id - data: { - status: DISPUTED - reviewedBy: $reviewedBy - reviewedAt: $reviewedAt - disputeReason: $disputeReason - disputeDetails: $disputeDetails - disputedItems: $disputedItems - } - ) -} - -# ------------------------------------------------------------ -# LINK INVOICE — set once invoice is generated after full approval -# ------------------------------------------------------------ -mutation linkInvoiceToShiftDayCompletion( - $id: UUID! - $invoiceId: UUID! -) @auth(level: USER) { - shiftDayCompletion_update( - id: $id - data: { - invoiceId: $invoiceId - } - ) -} - -# ------------------------------------------------------------ -# UPDATE — general-purpose update (admin use) -# ------------------------------------------------------------ -mutation updateShiftDayCompletion( - $id: UUID! - $status: ShiftDayCompletionStatus - $hours: Float - $cost: Float - $staffSummary: Any - $disputeReason: String - $disputeDetails: String - $disputedItems: Any - $reviewedBy: String - $reviewedAt: Timestamp - $invoiceId: UUID -) @auth(level: USER) { - shiftDayCompletion_update( - id: $id - data: { - status: $status - hours: $hours - cost: $cost - staffSummary: $staffSummary - disputeReason: $disputeReason - disputeDetails: $disputeDetails - disputedItems: $disputedItems - reviewedBy: $reviewedBy - reviewedAt: $reviewedAt - invoiceId: $invoiceId - } - ) -} - -# ------------------------------------------------------------ -# DELETE -# ------------------------------------------------------------ -mutation deleteShiftDayCompletion($id: UUID!) @auth(level: USER) { - shiftDayCompletion_delete(id: $id) -} diff --git a/backend/dataconnect/connector/shiftDayCompletion/queries.gql b/backend/dataconnect/connector/shiftDayCompletion/queries.gql deleted file mode 100644 index 3532c03a..00000000 --- a/backend/dataconnect/connector/shiftDayCompletion/queries.gql +++ /dev/null @@ -1,417 +0,0 @@ - -# ------------------------------------------------------------ -# GET BY ID -# ------------------------------------------------------------ -query getShiftDayCompletionById($id: UUID!) @auth(level: USER) { - shiftDayCompletion(id: $id) { - id - shiftId - orderId - businessId - vendorId - dayDate - dayNumber - status - hours - cost - staffSummary - disputeReason - disputeDetails - disputedItems - reviewedBy - reviewedAt - invoiceId - createdAt - updatedAt - createdBy - - shift { - id - title - date - startTime - endTime - hours - durationDays - status - } - - order { - id - eventName - orderType - poReference - teamHub { - hubName - address - } - } - - business { - id - businessName - email - contactName - } - - vendor { - id - companyName - email - } - - invoice { - id - invoiceNumber - status - issueDate - dueDate - amount - } - } -} - -# ------------------------------------------------------------ -# LIST ALL COMPLETION RECORDS FOR A SHIFT -# ------------------------------------------------------------ -query listShiftDayCompletionsByShift( - $shiftId: UUID! - $offset: Int - $limit: Int -) @auth(level: USER) { - shiftDayCompletions( - where: { shiftId: { eq: $shiftId } } - orderBy: { dayNumber: ASC } - offset: $offset - limit: $limit - ) { - id - shiftId - orderId - businessId - vendorId - dayDate - dayNumber - status - hours - cost - staffSummary - disputeReason - disputeDetails - disputedItems - reviewedBy - reviewedAt - invoiceId - createdAt - updatedAt - - shift { - id - title - date - startTime - endTime - durationDays - status - } - - invoice { - id - invoiceNumber - status - amount - } - } -} - -# ------------------------------------------------------------ -# LIST ALL COMPLETION RECORDS FOR AN ORDER -# ------------------------------------------------------------ -query listShiftDayCompletionsByOrder( - $orderId: UUID! - $offset: Int - $limit: Int -) @auth(level: USER) { - shiftDayCompletions( - where: { orderId: { eq: $orderId } } - orderBy: { dayDate: ASC } - offset: $offset - limit: $limit - ) { - id - shiftId - orderId - businessId - vendorId - dayDate - dayNumber - status - hours - cost - staffSummary - disputeReason - disputeDetails - disputedItems - reviewedBy - reviewedAt - invoiceId - createdAt - updatedAt - - shift { - id - title - date - startTime - endTime - durationDays - status - } - - invoice { - id - invoiceNumber - status - amount - } - } -} - -# ------------------------------------------------------------ -# LIST PENDING REVIEW RECORDS FOR A BUSINESS (client view) -# ------------------------------------------------------------ -query listPendingShiftDayCompletionsByBusiness( - $businessId: UUID! - $offset: Int - $limit: Int -) @auth(level: USER) { - shiftDayCompletions( - where: { - businessId: { eq: $businessId } - status: { eq: PENDING_REVIEW } - } - orderBy: { dayDate: ASC } - offset: $offset - limit: $limit - ) { - id - shiftId - orderId - businessId - vendorId - dayDate - dayNumber - status - hours - cost - staffSummary - createdAt - updatedAt - - shift { - id - title - date - startTime - endTime - durationDays - status - location - locationAddress - } - - order { - id - eventName - orderType - poReference - teamHub { - hubName - address - } - } - - vendor { - id - companyName - } - } -} - -# ------------------------------------------------------------ -# LIST ALL RECORDS FOR A BUSINESS FILTERED BY STATUS -# ------------------------------------------------------------ -query listShiftDayCompletionsByBusinessAndStatus( - $businessId: UUID! - $status: ShiftDayCompletionStatus! - $offset: Int - $limit: Int -) @auth(level: USER) { - shiftDayCompletions( - where: { - businessId: { eq: $businessId } - status: { eq: $status } - } - orderBy: { dayDate: DESC } - offset: $offset - limit: $limit - ) { - id - shiftId - orderId - businessId - vendorId - dayDate - dayNumber - status - hours - cost - staffSummary - disputeReason - disputeDetails - disputedItems - reviewedBy - reviewedAt - invoiceId - createdAt - updatedAt - - shift { - id - title - date - startTime - endTime - durationDays - status - } - - order { - id - eventName - orderType - poReference - } - - invoice { - id - invoiceNumber - status - amount - } - } -} - -# ------------------------------------------------------------ -# LIST ALL APPROVED RECORDS FOR A SHIFT (invoice trigger check) -# ------------------------------------------------------------ -query listApprovedShiftDayCompletionsByShift( - $shiftId: UUID! -) @auth(level: USER) { - shiftDayCompletions( - where: { - shiftId: { eq: $shiftId } - status: { eq: APPROVED } - } - orderBy: { dayNumber: ASC } - ) { - id - shiftId - orderId - businessId - vendorId - dayDate - dayNumber - status - hours - cost - staffSummary - reviewedBy - reviewedAt - invoiceId - createdAt - updatedAt - - shift { - id - title - durationDays - hours - cost - status - order { - id - eventName - businessId - vendorId - poReference - teamHub { - hubName - address - } - } - } - } -} - -# ------------------------------------------------------------ -# LIST ALL RECORDS BY VENDOR FILTERED BY STATUS -# ------------------------------------------------------------ -query listShiftDayCompletionsByVendorAndStatus( - $vendorId: UUID! - $status: ShiftDayCompletionStatus! - $offset: Int - $limit: Int -) @auth(level: USER) { - shiftDayCompletions( - where: { - vendorId: { eq: $vendorId } - status: { eq: $status } - } - orderBy: { dayDate: DESC } - offset: $offset - limit: $limit - ) { - id - shiftId - orderId - businessId - vendorId - dayDate - dayNumber - status - hours - cost - staffSummary - disputeReason - disputeDetails - reviewedBy - reviewedAt - invoiceId - createdAt - updatedAt - - shift { - id - title - date - startTime - endTime - durationDays - status - } - - business { - id - businessName - email - } - - invoice { - id - invoiceNumber - status - amount - } - } -} diff --git a/backend/dataconnect/schema/invoice.gql b/backend/dataconnect/schema/invoice.gql index 89306cab..586c7753 100644 --- a/backend/dataconnect/schema/invoice.gql +++ b/backend/dataconnect/schema/invoice.gql @@ -31,6 +31,9 @@ type Invoice @table(name: "invoices") { orderId: UUID! order: Order! @ref(fields: "orderId", references: "id") + shiftId: UUID + shift: Shift @ref(fields: "shiftId", references: "id") + #web paymentTerms: InovicePaymentTerms invoiceNumber: String! diff --git a/backend/dataconnect/schema/shiftDayCompletion.gql b/backend/dataconnect/schema/shiftDayCompletion.gql deleted file mode 100644 index a990edb7..00000000 --- a/backend/dataconnect/schema/shiftDayCompletion.gql +++ /dev/null @@ -1,45 +0,0 @@ -enum ShiftDayCompletionStatus { - PENDING_REVIEW - APPROVED - DISPUTED -} - -type ShiftDayCompletion @table(name: "shift_day_completions", key: ["id"]) { - id: UUID! @default(expr: "uuidV4()") - - shiftId: UUID! - shift: Shift! @ref(fields: "shiftId", references: "id") - - orderId: UUID! - order: Order! @ref(fields: "orderId", references: "id") - - businessId: UUID! - business: Business! @ref(fields: "businessId", references: "id") - - vendorId: UUID! - vendor: Vendor! @ref(fields: "vendorId", references: "id") - - dayDate: Timestamp! - dayNumber: Int! - - status: ShiftDayCompletionStatus! @default(expr: "'PENDING_REVIEW'") - - hours: Float - cost: Float - - staffSummary: Any @col(dataType: "jsonb") - - disputeReason: String - disputeDetails: String - disputedItems: Any @col(dataType: "jsonb") - - reviewedBy: String - reviewedAt: Timestamp - - invoiceId: UUID - invoice: Invoice @ref(fields: "invoiceId", references: "id") - - createdAt: Timestamp @default(expr: "request.time") - updatedAt: Timestamp @default(expr: "request.time") - createdBy: String -}