USE [LegitimateKZN_QA_SO]
GO

/****** Object:  Table [App].[ReceiptDetails]    Script Date: 2025/11/29 10:43:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [App].[ReceiptDetails](
	[ReceiptDetailID] [bigint] IDENTITY(1,1) NOT NULL,
	[ReceiptBatchID] [bigint] NULL,
	[PaymentTypeID] [smallint] NOT NULL,
	[ReceiptNumber]  AS ('RCT'+[System].[Fn_PadLeft]('0',(7),[ReceiptDetailID])),
	[TotalCost] [money] NOT NULL,
	[CreatedById] [bigint] NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[UpdatedById] [bigint] NOT NULL,
	[UpdatedDate] [datetime] NOT NULL,
	[IsCancelled] [bit] NOT NULL,
	[ApplicantData] [varchar](2000) NULL,
	[ReceiptItems] [varchar](max) NULL,
	[HasBulkVehicleApplications] [bit] NOT NULL,
	[ApplicationRequestDetailID] [bigint] NULL,
 CONSTRAINT [PK__ReceiptD__CC08C40052AF0DCA] PRIMARY KEY CLUSTERED 
(
	[ReceiptDetailID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [App].[ReceiptDetails] ADD  CONSTRAINT [DF_ReceiptDetails_PaymentTypeID]  DEFAULT ((1)) FOR [PaymentTypeID]
GO

ALTER TABLE [App].[ReceiptDetails] ADD  CONSTRAINT [DF__ReceiptDe__Creat__5497563C]  DEFAULT (getdate()) FOR [CreatedDate]
GO

ALTER TABLE [App].[ReceiptDetails] ADD  CONSTRAINT [DF__ReceiptDe__Updat__558B7A75]  DEFAULT (getdate()) FOR [UpdatedDate]
GO

ALTER TABLE [App].[ReceiptDetails] ADD  CONSTRAINT [DF__ReceiptDe__IsCan__567F9EAE]  DEFAULT ((0)) FOR [IsCancelled]
GO

ALTER TABLE [App].[ReceiptDetails] ADD  DEFAULT ((0)) FOR [HasBulkVehicleApplications]
GO

ALTER TABLE [App].[ReceiptDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ReceiptDetails_ApplicationRequestDetails] FOREIGN KEY([ApplicationRequestDetailID])
REFERENCES [App].[ApplicationRequestDetails] ([ApplicationRequestDetailID])
GO

ALTER TABLE [App].[ReceiptDetails] CHECK CONSTRAINT [FK_ReceiptDetails_ApplicationRequestDetails]
GO

ALTER TABLE [App].[ReceiptDetails]  WITH CHECK ADD  CONSTRAINT [FK_ReceiptDetails_PaymentTypes] FOREIGN KEY([PaymentTypeID])
REFERENCES [Md].[PaymentTypes] ([PaymentTypeID])
GO

ALTER TABLE [App].[ReceiptDetails] CHECK CONSTRAINT [FK_ReceiptDetails_PaymentTypes]
GO

ALTER TABLE [App].[ReceiptDetails]  WITH CHECK ADD  CONSTRAINT [FK_ReceiptDetails_ReceiptBatches] FOREIGN KEY([ReceiptBatchID])
REFERENCES [App].[ReceiptBatches] ([ReceiptBatchID])
GO

ALTER TABLE [App].[ReceiptDetails] CHECK CONSTRAINT [FK_ReceiptDetails_ReceiptBatches]
GO


