
IF EXISTS (SELECT * FROM sysobjects
Where name = 'sp_GetInvoiceNoSales')
BEGIN

DROP PROCEDURE [dbo].[sp_GetInvoiceNoSales]

END

IF EXISTS (SELECT * FROM sysobjects
Where name = 'sp_GetNextSequenceSales')
BEGIN

DROP PROCEDURE [dbo].[sp_GetNextSequenceSales]

END

IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[pal_Sales]')
 AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
 BEGIN

CREATE TABLE [dbo].[pal_Sales](
	[recId] [int] IDENTITY(1,1) NOT NULL,
	[surfaceItemId] [int] NULL,
	[name] [varchar](150) NULL,
	[surname] [varchar](150) NULL,
	[title] [varchar](10) NULL,
	[initials] [varchar](10) NULL,
	[dateOfService] [datetime] NULL,
	[dateOfCapture] [datetime] NULL,
	[itemCode] [varchar](150) NULL,
	[itemDescription] [varchar](5000) NULL,
	[itemType] [varchar](5) NULL,
	[reference] [varchar](300) NULL,
	[comments] [varchar](300) NULL,
	[qty] [decimal](18, 2) NULL,
	[unitFee] [decimal](18, 2) NULL,
	[amount] [decimal](18, 2) NULL,
	[allocated] [decimal](18, 2) NULL,
	[allocatedReference] [varchar](150) NULL,
	[isVisible] [bit] NULL,
	[invoiceNo] [int] NULL,
	[receiptNo] [int] NULL,
	[runningBal] [decimal](18, 2) NULL,
	[userId] [int] NULL,
	[vatRate] [decimal](18, 2) NULL,
	[postalAddress] [varchar](300) NULL,
	[email] [varchar](300) NULL,
	[sequence] [int] NULL,
 CONSTRAINT [PK_pal_Sales] PRIMARY KEY CLUSTERED 
(
	[recId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


END


IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[pal_SalesItem]')
 AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
 BEGIN


CREATE TABLE [dbo].[pal_SalesItem](
	[recId] [int] IDENTITY(1,1) NOT NULL,
	[code] [varchar](50) NULL,
	[description] [varchar](350) NULL,
	[itemType] [int] NULL,
	[unitMeasure] [varchar](50) NULL,
	[SellPriceExcl] [decimal](18, 2) NULL,
	[SellPriceIncl] [decimal](18, 2) NULL,
	[BuyPriceExcl] [decimal](18, 2) NULL,
	[comments] [varchar](350) NULL,
	[notes] [text] NULL,
 CONSTRAINT [PK_pal_SalesItem] PRIMARY KEY CLUSTERED 
(
	[recId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

END


Truncate Table  [dbo].[pal_Module]

SET IDENTITY_INSERT [dbo].[pal_Module] ON 

GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (1, N'Content', 1, N'Admin_Content.aspx', N'module/content.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (3, N'Users', 3, N'Admin_Users.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, 1)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (4, N'Products', 4, N'Admin_Products.aspx', N'module/featuredProducts.ascx', 0, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (5, N'Product Categories', 5, N'Admin_ProductCategories.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (6, N'Product Brands', 6, N'Admin_ProductBrands.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (7, N'Banners', 7, N'Admin_Banners.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (8, N'Templates', 8, N'Admin_Templates.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (9, N'Gallery', 9, N'Admin_Gallery.aspx', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (10, N'Surface', 10, N'Admin_Surface.aspx', N'surface/surface.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (11, N'Canvas', 11, N'Admin_Canvas.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (12, N'Practices', 12, N'Debtors_Practices.aspx', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (13, N'Doctors', 13, N'Debtors_Doctors.aspx', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (14, N'Tariffs', 14, N'Debtors_Tariffs.aspx', N'debtors/tariffs.ascx', 1, 1, 1, N'oTariffPlan', N'name', N'code', NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (15, N'Procedures', 15, N'Debtors_Procedures.aspx', N'debtors/procedures.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (16, N'Medical Schemes', 16, N'Debtors_Schemes.aspx', N'debtors/schemes.ascx', 1, 1, 1, N'oMedicalScheme', N'name', N'code', NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (17, N'Notes', 17, N'', NULL, 0, 0, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (18, N'Debtors Reports', 18, N'', N'module/debtorsReports.ascx', 0, 1, 0, N'', N'', N'', NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (19, N'Tasks', 19, N'Admin_Tasks.aspx', N'module/task.ascx', 1, 0, 0, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (20, N'FAQ', 20, N'Admin_FAQ.aspx', N'module/faq.ascx', 0, 1, 0, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (21, N'Medical Administrators', 21, N'Debtors_MedAdmins.aspx', NULL, 1, 0, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (22, N'Calendar', 22, N'Admin_Calendar.aspx', NULL, 0, 1, 0, NULL, NULL, NULL, 0)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (23, N'ICD10', 23, N'Debtors_ICD10.aspx', N'debtors/icd10.ascx', 1, 0, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (24, N'Enquiry', 24, N'', N'module/enquiry.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (25, N'Promotions', 25, N'Admin_Promotions.aspx', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (26, N'Sales', 26, N'', N'module/sales.ascx', 1, 1, NULL, NULL, NULL, NULL, NULL)
GO
INSERT [dbo].[pal_Module] ([recId], [module], [sequence], [path], [control], [isActive], [isCanvas], [isPicklist], [objectName], [displayField], [valueField], [isCalendar]) VALUES (27, N'Products and Services', 27, N'Sales_SalesItems.aspx', N'sales/items.ascx', 1, 1, 0, NULL, NULL, NULL, NULL)
GO
SET IDENTITY_INSERT [dbo].[pal_Module] OFF
GO




Truncate Table pal_TemplateType


SET IDENTITY_INSERT [dbo].[pal_TemplateType] ON 

GO
INSERT [dbo].[pal_TemplateType] ([recId], [templateType], [isActive], [sequence]) VALUES (1, N'Canvas', 1, 1)
GO
INSERT [dbo].[pal_TemplateType] ([recId], [templateType], [isActive], [sequence]) VALUES (2, N'Content', 1, 2)
GO
INSERT [dbo].[pal_TemplateType] ([recId], [templateType], [isActive], [sequence]) VALUES (3, N'Campaign', 1, 3)
GO
INSERT [dbo].[pal_TemplateType] ([recId], [templateType], [isActive], [sequence]) VALUES (4, N'Outbound Response', 1, 4)
GO
INSERT [dbo].[pal_TemplateType] ([recId], [templateType], [isActive], [sequence]) VALUES (5, N'Internal Response', 1, 5)
GO
INSERT [dbo].[pal_TemplateType] ([recId], [templateType], [isActive], [sequence]) VALUES (6, N'Debtors', 1, 6)
GO
INSERT [dbo].[pal_TemplateType] ([recId], [templateType], [isActive], [sequence]) VALUES (7, N'Sales', 1, 7)
GO
SET IDENTITY_INSERT [dbo].[pal_TemplateType] OFF
GO
