SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspViewAccountUsersLogOnHistory]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 17/Sep/2007
-- Description: To view the log history of Account uesrs
-- =============================================
CREATE PROCEDURE [dbo].[UspViewAccountUsersLogOnHistory] --1,null,''ad'',''2/28/2008'',''2/28/2008''
@AccountId INT,
@ProfileId INT,
@Name VARCHAR(50) = NULL,
@FromDate datetime = Null,
@ToDate datetime = Null
AS
BEGIN
SET NOCOUNT ON;
Declare @Query1 as VARCHAR(2000)
Declare @Query2 as VARCHAR(2000)
Declare @Condition1 as VARCHAR(1000)
Declare @Condition2 as VARCHAR(1000)
IF @AccountId <> ''''
BEGIN
Select @Condition1 = '' AND ac.AccountId='' + Cast(@AccountId as varchar(10))
END
IF @ProfileId <> ''''
IF @Condition1 <> ''''
BEGIN
Select @Condition1 = @Condition1 + '' AND pr.profileid='' + Cast(@ProfileId as varchar(10))
END
ELSE
BEGIN
Select @Condition1 ='' AND pr.profileid='' + Cast(@ProfileId as varchar(10))
END
IF @Name <> ''''
BEGIN
SELECT @Condition2 = '' WHERE p.FirstName like ''''%'' + @Name + ''%'''' ''
END
IF @FromDate<>'''' AND @ToDate<>''''
BEGIN
DECLARE @DateFrom datetime
DECLARE @DateTo datetime
SET @DateFrom=Convert(varchar,@FromDate,101)
SET @DateTo=Convert(varchar,@ToDate,101)
IF @Condition1 <> ''''
BEGIN
SELECT @condition1 = @Condition1 + '' AND ((datepart(day,logindatetime) between datepart(day,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(day,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(month,logindatetime) between datepart(month,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(month,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(year,logindatetime) between datepart(year,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(year,'''''' + convert(varchar,@DateTo,106) + '''''' )))''
END
ELSE
BEGIN
SELECT @condition1 = '' AND ((datepart(day,logindatetime) between datepart(day,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(day,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(month,logindatetime) between datepart(month,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(month,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(year,logindatetime) between datepart(year,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(year,'''''' + convert(varchar,@DateTo,106) + '''''' )))''
END
END
ELSE IF @ToDate<>''''
BEGIN
SET @DateTo=Convert(varchar,@ToDate,101)
IF @condition1 <> ''''
BEGIN
SELECT @condition1 = @condition1 + '' AND convert(varchar,logindatetime,106) <= '''''' + convert(varchar,@DateTo,106) +''''''''
END
ELSE
BEGIN
SELECT @condition1 = '' AND convert(varchar,logindatetime,106) <='''''' + convert(varchar,@DateTo,106) +''''''''
END
END
SELECT @Query1=''SELECT a.AccountId,a.Name as AccountName,p.personid,p.email, url,
rs.profilename,rs.logindate,rs.logintime,rs.logoutdate,rs.logouttime,
rs.logindatetime,p.FirstName AS Name
FROM tblperson p
INNER JOIN tblaccount a
ON
p.accountid=a.accountid
INNER JOIN (SELECT personid,ac.Name,logindatetime, Convert(varchar(17),logindatetime,113) as logindate,
Convert(varchar,logindatetime,108) as logintime,
ISNULL(Convert(varchar(40),(Convert(varchar(17),logoutdatetime,113))),''''Not Available'''') as logoutdate,
Convert(varchar,logoutdatetime,108) as logouttime ,profilename
FROM tblaccountlog ac, tblprofile pr
WHERE ac.profileid=pr.profileid ''
SELECT @Query2='') rs
ON
p.personid=rs.personid ''
IF @Condition1 <> ''''
BEGIN
SELECT @Query1 = @Query1 + @Condition1
END
IF @Condition2 <> ''''
BEGIN
SELECT @Query2 = @Query2 + @Condition2
END
DECLARE @Query AS VARCHAR(2000)
SELECT @Query = @Query1 + @Query2 + '' order by rs.logindatetime desc''
--print(@Condition2)
--print(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblAccountSelectAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 14/9/2005
-- Modified Date: 20/9/2007
-- Description: For Login Process
-- =============================================
CREATE PROCEDURE [dbo].[USPTblAccountSelectAll] --''1'','''','''','''',''''
-- Add the parameters for the stored procedure here
@ProfileId int,
@Name varchar(100) = NULL,
@MaximumAgency int = NULL,
@LastActivity datetime = NULL,
@CurrencyId int=NULL
AS
DECLARE
@query varchar(1000),
@condition varchar(200)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT @condition = '' WHERE a.Deleted=0 ''
IF(@Name<>'''')
BEGIN
SELECT @condition = '' AND (a.Name like ''''%'' + @Name + ''%'''')''
END
IF(@MaximumAgency<>'''')
BEGIN
SELECT @condition = @condition + '' AND a.MaximumAgency >= '' + cast(@MaximumAgency as varchar(10))
END
IF(@CurrencyId<>'''')
BEGIN
SELECT @condition = @condition + '' AND c.CurrencyId = '' + cast(@CurrencyId as varchar(20))
END
IF(@LastActivity<>'''')
BEGIN
SELECT @condition = @condition + '' AND p.LastLogin >= '''''' + cast(@LastActivity as varchar(30)) + ''''''''
END
-- IF(@LastActive<>'''')
-- BEGIN
-- SELECT @condition = '' a.url like ''''%'' + @LastActive + ''%'''' ''
-- END
SELECT @query= ''SELECT
a.AccountID, p.PersonId, p.Email, api.CountryId, p.LastLogin, a.Name,
a.MaximumAgency, c.CurrencyName, CONVERT(VARCHAR,a.ActivationDate,106) AS ActivationDate, a.Deleted, CONVERT(VARCHAR, a.ExpiryDate,106) AS ExpiryDate,
CASE a.Deleted
WHEN ''''true'''' THEN ''''InActive''''
ELSE ''''Active''''
END as Status
FROM tblAccount AS a
LEFT JOIN tblCurrency AS c
ON c.CurrencyId=a.CurrencyId AND c.Deleted=0
INNER JOIN tblPerson as p
ON p.AccountID=a.AccountID AND p.Deleted=0
INNER JOIN tblAccountuserPersonalInfo AS api ON
api.AccountId=a.AccountID AND api.PersonId=p.personId
INNER JOIN tblMapPersonProfile as pp ON pp.PersonId = p.PersonID''
SELECT @query= @query + '' AND pp.ProfileId=''
SELECT @query= @query + cast(@ProfileId as varchar(20))
SELECT @query= @query + '' ''
/*IF(@condition<>'''')
BEGIN*/
SELECT @query= @query + @condition + '' order by a.DateModified desc ''
/*END
ELSE
BEGIN
SELECT @query= @query + '' order by a.DateModified desc ''
END*/
EXEC(@query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblGstCodesSelectByGstCodesID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2005
--Modified date: 22/10/2007
-- Description: FILL DDL Rate Type
-- =============================================
CREATE procedure [dbo].[USPTblGstCodesSelectByGstCodesID]
(
@GstCodeId int
)
AS
SELECT Rate, Date, TaxCodeId FROM tblGST
WHERE Deleted=''0'' AND GstCodeId=@GstCodeId
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsplTblMaintainanceInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 10-sep-2007
-- Description:
CREATE PROCEDURE [dbo].[UsplTblMaintainanceInsert]
-- Add the parameters for the stored procedure here
@MaintenanceTable varchar(50),
@Action varchar(100),
@Detail varchar(1000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Insert into tblMaintenance(MaintenanceTable,
[Action],
[Detail])
values
(
@MaintenanceTable ,
@Action ,
@Detail
)
-- Insert statements for procedure here
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSelectAgencyGST]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 8/Nov/2007
-- Modified By: Jatin (10/12/2007)
-- Description: Select GST of Agency
-- Modified By: Jagsir Singh (19/Feb/2008) -- Insert @Query and @Date Comparison
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSelectAgencyGST] --1,''19 Feb 2008''
-- Add the parameters for the stored procedure here
@AgencyId INT,
@Date DATETIME = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Query VARCHAR(500)
SET @Query=''SELECT a.AgencyId,a.AgencyName,convert(varchar, g.Date,106) AS Date,
CASE WHEN g.Registered=''''False'''' THEN ''''No'''' ELSE ''''Yes'''' END AS Status,g.Registered
FROM tblAgencyRegisterGST g
INNER JOIN tblAgency a
ON a.AgencyId=g.AgencyId
AND a.AgencyId=''+ CAST(@AgencyId AS VARCHAR(10)) +
'' AND a.Deleted=''''false''''
WHERE g.Deleted=''''False'''' ''
IF @Date is not null
BEGIN
SET @Query=@Query+'' AND convert(varchar, g.Date,106) = '''''' + Convert(Varchar,@Date,106) + ''''''''
END
SET @Query=@Query+'' ORDER BY Date DESC''
--Print(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTaxCodeSelectById]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
-- Description: Rate Type Insert
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTaxCodeSelectById]
-- Add the parameters for the stored procedure here
--@RateTypeId int,
@TaxCodeId int,
@TaxCode VARCHAR(3) OUTPUT
AS
BEGIN
SET @TaxCode= (SELECT TaxCode from tblTaxCode where TaxCodeId=@TaxCodeId)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSelectTalentGST]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin Kumar
-- Create date: 10/12/2007
-- Description: Select GST of Talent
-- Modified By: Jagsir Singh (20/Feb/2008) -- Insert @Query and @Date Comparison
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSelectTalentGST] --2,''18 Dec 2007''
-- Add the parameters for the stored procedure here
@TalentId INT,
@GSTDate DATETIME = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Query VARCHAR(500)
SET @Query = ''SELECT t.TalentId,t.TalentName,convert(varchar, g.Date,106) AS Date,
CASE WHEN g.Registered=''''False'''' THEN ''''No'''' ELSE ''''Yes'''' END AS Status,g.Registered
FROM tblTalentRegisterGST g
INNER JOIN tblTalent t
ON t.TalentId=g.TalentId
AND t.TalentId='' + Cast(@TalentId AS VARCHAR(10)) +
'' AND t.Deleted=''''false''''
WHERE g.Deleted=''''False''''''
IF @GSTDate is not null
BEGIN
SET @Query=@Query+'' AND convert(varchar, g.Date,106) = '''''' + Convert(Varchar,@GSTDate,106) + ''''''''
END
SET @Query=@Query+'' ORDER BY Date DESC''
--Print(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAgencyFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 27/9/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblAgencyFillDdl] --''1'','''','''','''','''' --''33'', ''12'',''23'',''32''
-- Add the parameters for the stored procedure here
@AccountId int,
@CompanyId int=NULL,
@TalentId int=NULL,
@ProductionId int=NULL,
@PersonId int=NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE
@qry varchar(2000),
@cond varchar(500)
--SELECT @cond = '' WHERE agy.Deleted=''''False'''' AND agy.Status=''''False''''''
SELECT @cond = '' WHERE agy.Deleted=''''False'''' AND agy.AccountId='' + cast(@AccountId as varchar(20))
IF(@CompanyID>0 OR @ProductionId>0 OR @TalentId>0)
BEGIN
SELECT @qry= ''SELECT DISTINCT agy.AgencyId, agy.Agencyname
from tblAgency agy
LEFT JOIN tblcountry cntry on
agy.countryid=cntry.countryid
INNER JOIN tblProduction as prod ON
prod.Deleted=''''0'''' AND prod.AgencyId=agy.AgencyId''
IF(@CompanyID>0)
BEGIN
SELECT @cond = @cond + '' AND prod.CompanyId = '' + cast(@CompanyId as varchar(20))
END
IF(@ProductionId>0)
BEGIN
SELECT @cond = @cond + '' AND prod.ProductionId = '' + cast(@ProductionId as varchar(20))
--SELECT @cond = @cond + '' AND prod.AgencyId=agy.AgencyId''
END
IF(@TalentId>0)
BEGIN
SELECT @qry = @qry + '' INNER JOIN tblJob AS j ON
j.ProductionID=prod.ProductionID AND
j.TalentId=''+ cast(@TalentID as varchar(20))
END
IF(@PersonId>0)
BEGIN
SELECT @qry = @qry + '' INNER JOIN tblAgencyAccess AS aa ON
aa.AgencyId=agy.AgencyId AND
aa.PersonId=''+ cast(@PersonId as varchar(20))
END
END
ELSE
BEGIN
SELECT @qry= ''SELECT DISTINCT agy.AgencyId, agy.Agencyname
from tblAgency agy
LEFT JOIN tblcountry cntry on
agy.countryid=cntry.countryid''
IF(@PersonId>0)
BEGIN
SELECT @qry = @qry + '' INNER JOIN tblAgencyAccess AS aa ON
aa.AgencyId=agy.AgencyId AND
aa.PersonId=''+ cast(@PersonId as varchar(20))
END
-- INNER JOIN tblProduction as prod ON
-- prod.Deleted=''''0'''' AND prod.AgencyId=agy.AgencyId''
END
SELECT @qry = @qry + @cond
EXEC(@qry)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblCompanyFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 27/9/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblCompanyFillDdl] --''1'',''1'','''','''',''''
-- Add the parameters for the stored procedure here
@AccountId int,
@AgencyID int=NULL,
@TalentId int=NULL,
@ProductionId int=NULL,
@ProfileId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE
@qry varchar(2000),
@cond varchar(500)
SELECT @cond = '' WHERE comp.Deleted = ''''0''''''
IF(@AgencyID>0 OR @ProductionId>0 OR @TalentId>0)
BEGIN
SELECT @qry= ''SELECT DISTINCT comp.CompanyId, comp.Companyname
FROM tblcompany comp
INNER JOIN tblcountry cntry on
comp.countryid=cntry.countryid
--AND comp.AccountId=@AccountId
INNER JOIN
tblPerson as p ON p.AccountID='' + cast(@AccountId as varchar(20))
SELECT @qry = @qry + '' AND
p.Deleted=0
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId='' + cast(@ProfileId as varchar(20))
SELECT @qry = @qry + '' AND
pp.PersonId = p.PersonID
INNER JOIN
tblCompanyAcess AS a ON p.PersonID=a.PersonID AND
comp.CompanyId=a.CompanyId
INNER JOIN tblProduction as prod ON
prod.Deleted=''''0'''' AND prod.CompanyId=comp.CompanyId''
IF(@AgencyID>0)
BEGIN
SELECT @cond = @cond + '' AND prod.AgencyID = '' + cast(@AgencyID as varchar(20))
END
IF(@ProductionId>0)
BEGIN
SELECT @cond = @cond + '' AND prod.ProductionId = '' + cast(@ProductionId as varchar(20))
END
IF(@TalentId>0)
BEGIN
SELECT @qry= @qry + '' INNER JOIN tblJob AS j ON
j.ProductionID=prod.ProductionID AND
j.TalentId=''+ cast(@TalentID as varchar(20))
END
END
ELSE
BEGIN
SELECT @qry= ''SELECT DISTINCT comp.CompanyId, comp.Companyname
FROM tblcompany comp
INNER JOIN tblcountry cntry on
comp.countryid=cntry.countryid
--AND comp.AccountId=@AccountId
INNER JOIN
tblPerson as p ON p.AccountID='' + cast(@AccountId as varchar(20))
SELECT @qry = @qry + '' AND
p.Deleted=0
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId='' + cast(@ProfileId as varchar(20))
SELECT @qry = @qry + '' AND
pp.PersonId = p.PersonID
INNER JOIN
tblCompanyAcess AS a ON p.PersonID=a.PersonID AND
comp.CompanyId=a.CompanyId''
-- INNER JOIN tblProduction as prod ON
-- prod.Deleted=''''0'''' AND prod.CompanyId=comp.CompanyId''
END
SELECT @qry = @qry + @cond
EXEC(@qry)
PRINT(@qry)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileSelectById]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 27/Sep/2007
-- Description: Select selected profile detail on basis of profile id
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileSelectById]
-- Add the parameters for the stored procedure here
@ProfileId INT
As
--Declare @MaintenanceTable varchar(50)
--Declare @Action varchar(100)
--Declare @Detail varchar(1000)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT ProfileName, InActive , parentProfileId
FROM tblProfile
WHERE profileId=@ProfileId and deleted=''false''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblRequestDetail]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select request details
-- =============================================
CREATE PROCEDURE [dbo].[UspTblRequestDetail] --1
-- Add the parameters for the stored procedure here
@JobPaymentId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT PaymentTypeId,TalentAccountId,Value
FROM tblJobPayment
WHERE JobPaymentId=@JobPaymentId
AND
Deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsplTblMaintainanceInsert_new]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 10-sep-2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsplTblMaintainanceInsert_new]
-- Add the parameters for the stored procedure here
@MaintenanceTable VARCHAR(50),
@Action VARCHAR(50),
@Detail VARCHAR(1000),
@DateModified DATETIME,
@ModifiedBy INT,
@ModifiedID INT,
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO tblMaintenance(MaintenanceTable,Action,Detail,DateModified,ModifiedBy,ModifiedId,AccountId)
VALUES(@MaintenanceTable,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId,@AccountId)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResetIdentityValue]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- =============================================
-- Author: Harendra Singh
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[ResetIdentityValue]
-- Add the parameters for the stored procedure here
@Tablename as varchar(200),
@Value as Int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @cmd as varchar(1000)
-- Insert statements for procedure here
If (EXISTS(SELECT name FROM syscolumns WHERE status = 0x80 AND
OBJECT_NAME(id)=@Tablename ))
begin
print ''IsIdentity''
SET @Cmd = ''DBCC CHECKIDENT ('''''' + @TableName + '''''', RESEED,''+ cast (@Value as varchar)+ '')''
EXEC (@Cmd)
--EXEC sp_executesql @Cmd
--exec ''use talent_test DBCC CHECIDENT (@Tablename , RESEED, 1)''
end
else
begin
print ''No IsIdentity''
end
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentAccounts]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select payment types
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTalentAccounts] --35
-- Add the parameters for the stored procedure here
@TalentId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT TalentAccountId,AccountNumber+'': ''+AccountName as TalentAccount
FROM tblTalentAccount
WHERE TalentId=@TalentId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblAccountSelectProfile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 19/9/2005
-- Description: Account Select by AccountID by Admin
-- =============================================
CREATE procedure [dbo].[USPTblAccountSelectProfile]
(
-- Add the parameters for the stored procedure here
@AccountID int,
@ProfileId int
)
as
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
a.AccountID, p.PersonName, a.Name, a.url, a.Email, a.Phone,
a.Fax, a.PostalAddress, a.BusinessAddress, a.ExpiryDate,
a.MaximumAgency, a.ActivationDate, a.ExpiryDate,
datediff(dd, getdate(), a.ExpiryDate) as ValidDays, a.Deleted
FROM
tblAccount AS a
INNER JOIN
tblPerson as p ON p.AccountID=a.AccountID AND p.Deleted=''0''
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId=@ProfileId AND
pp.PersonId = p.PersonID
WHERE
a.AccountID=@AccountID
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblPersonProfileSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14/Sep/2007
-- Description: To select the profiles of the person who is logged in
-- =============================================
CREATE PROCEDURE [dbo].[UspTblPersonProfileSelect]
-- Add the parameters for the stored procedure here
@PersonId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT ProfileId,ProfileName
FROM tblProfile
WHERE ProfileId IN (SELECT ProfileId
FROM tblMapPersonProfile
WHERE PersonId=@PersonId
)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblNavigationSelect]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT NavigationId,[Name],Description,Parent,Sequence
FROM tblNavigation
WHERE deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionsByAgency]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 191007
-- Description: Select Productions on basis of agencies
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProductionsByAgency] --1,5
-- Add the parameters for the stored procedure here
@AccountId INT,
@AgencyId INT=null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF @AgencyId <> 0
BEGIN
SELECT ProductionId,Description
FROM tblProduction
WHERE
AgencyId=@AgencyId
AND
AccountId=@AccountId
END
ELSE
BEGIN
SELECT ProductionId,Description
FROM tblProduction
WHERE
AccountId=@AccountId
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationGroup]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <11/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblNavigationGroup]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select distinct NavigationId, Name, Description
from tblNavigation where parent is null and deleted=''0''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspViewBatchProduction]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 27/Nov/2007
-- Description: Select all Productions for AgencyId
-- =============================================
CREATE PROCEDURE [dbo].[UspViewBatchProduction] --15,1,1,1,1
-- Add the parameters for the stored procedure here
@BatchId INT,
@AccountId INT,
@AgencyId INT,
@ProductionId INT,
@CompanyId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Query VARCHAR(2000)
SET @Query=''SELECT p.ProductionId,p.ProductionTitle,b.BatchId,ag.AgencyName,cmp.CompanyName,
CASE WHEN
(SELECT ProductionId FROM tblBatchProduction AS bp WHERE bp.Deleted=''''0'''' AND bp.ProductionId=p.ProductionId and bp.BatchId=b.BatchId)>0
THEN
''''True''''
ELSE
''''False''''
END AS IsChecked
FROM tblproduction p
INNER JOIN tblAgency ag
INNER JOIN tblBatch b
ON ag.AgencyId=b.AgencyId
ON p.AgencyId=ag.AgencyId
AND ag.deleted=''''False''''
INNER JOIN tblCompany cmp
ON p.CompanyId=cmp.CompanyId''
IF @CompanyId<>0
BEGIN
SET @Query = @Query + '' AND cmp.CompanyId='' + CAST(@CompanyId as varchar(10))
END
SET @Query = @Query + '' AND cmp.Deleted=''''False''''
INNER JOIN tblAccount ac
ON p.AccountId=ac.AccountId
AND ac.Deleted=''''False''''
WHERE b.BatchId='' + CAST(@BatchId as varchar(10)) +
'' AND
ag.AgencyId='' + CAST(@AgencyId as varchar(10)) +
'' AND
ac.AccountId='' + CAST(@AccountId as varchar(10))
IF @ProductionId<>0
BEGIN
SET @Query=@Query+ '' AND p.ProductionId = '' + CAST(@ProductionId as varchar(10))
END
--Print(@Query)
Exec(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblCompanyContactSelectByContactId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 13/9/2005
-- Description: View All Contacts of an Agency
-- =============================================
CREATE procedure [dbo].[USPTblCompanyContactSelectByContactId]
-- Add the parameters for the stored procedure here
@ContactId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT [CompanyId]
,[ContactId]
,[CompanyName]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
,[Deleted]
,[DateModified]
,[ModifiedBy] from tblCompanycontact Where ContactId=@ContactId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblRateTypeSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: For Rate Type
-- =============================================
CREATE procedure [dbo].[USPTblRateTypeSelect] --'''', ''1'', ''1''
@RateTypeName varchar(100) = NULL,
@CategoryID int = NULL,
@AccountId int
AS
DECLARE
@query varchar(500),
@condition varchar(200)
SELECT @condition = '' WHERE r.Deleted=0 AND r.AccountId='' + cast(@AccountId as varchar(10))
SELECT @query= ''SELECT r.*, c.CategoryName FROM tblRateType as r
INNER JOIN tblCategory AS c
ON c.CategoryId=r.CategoryId''
IF(@RateTypeName<>'''')
BEGIN
SELECT @condition = '' AND (r.RateTypeName like ''''%'' + @RateTypeName + ''%'''')''
END
IF(@CategoryID<>'''')
BEGIN
SELECT @condition = @condition + '' AND r.CategoryID = '' + cast(@CategoryID as varchar(10))
END
SELECT @query= @query + @condition + '' Order by datemodified desc''
EXEC(@query)
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblFetchAgencyAccountForReciept]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <13/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblFetchAgencyAccountForReciept] --7 ,8
-- Add the parameters for the stored procedure here
@AccountId int,
@ProductionId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT dbo.tblAgencyAccount.CurrencyId as CurrencyId, dbo.tblAgencyAccount.AccountNumber as AccountNumber
FROM dbo.tblProduction INNER JOIN
dbo.tblAgency ON dbo.tblProduction.AgencyId = dbo.tblAgency.AgencyId INNER JOIN
dbo.tblAgencyAccount ON dbo.tblAgency.AgencyId = dbo.tblAgencyAccount.AgencyId
WHERE dbo.tblProduction.ProductionID=@ProductionId and dbo.tblAgency.AccountId=@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 14/9/2005
-- Description: For Login Process
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountUpdate]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@Name varchar(100),
@Description varchar(2000),
@Phone varchar(20),
@Fax varchar(20),
@PostalAddress varchar(500),
@BusinessAddress varchar(500),
@DateModified datetime,
@ModifiedBy int
--@Result INT OUTPUT
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
BEGIN TRAN
UPDATE tblAccount
SET
Name = @Name,
Description=@Description,
Phone = @Phone,
Fax=@Fax,
PostalAddress=@PostalAddress,
BusinessAddress=@BusinessAddress,
DateModified = @DateModified,
ModifiedBy=@ModifiedBy
WHERE
AccountId=@AccountId AND
EXISTS (SELECT COUNT(*) FROM
tblMapPersonProfile as pp, tblPerson AS p
WHERE pp.ProfileId=@ProfileId AND pp.PersonId = p.PersonID
AND p.AccountId=@AccountId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralNavigationSelectNew]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
-- =============================================
--Modified By: Jagsir Singh (29/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblCentralNavigationSelectNew]
-- Add the parameters for the stored procedure here
@ProfileId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF(@ProfileId = 1)
BEGIN
SELECT CentralNavigationId,Name,Description,Parent,Sequence
FROM tblCentralNavigation
WHERE deleted=''False''
END
ELSE
BEGIN
SELECT CentralNavigationId,Name,Description,Parent,Sequence
FROM tblCentralNavigation
WHERE deleted=''False''
AND CentralNavigationId <> 12
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCurrencySelectBySearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/9/2007
-- Description: Select a particular Currency
--Modified By: Harendra Singh
--Modified Date: 17/12/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCurrencySelectBySearch] --1,''''
@CurrencyId INT,
@CurrencyName Varchar(50) = null
AS
SET NOCOUNT ON
DECLARE @Query VARCHAR(1000)
DECLARE @Condition VARCHAR(1000)
IF @CurrencyId <> ''''
BEGIN
SELECT @Condition = '' AND CurrencyId = '' + CAST(@CurrencyId AS VARCHAR(10))
END
IF @CurrencyName <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND CurrencyName like ''''%'' + @CurrencyName + ''%'''' ''
END
ELSE
BEGIN
SELECT @Condition = '' AND CurrencyName like ''''%'' + @CurrencyName + ''%'''' ''
END
END
SELECT @Query =''SELECT CurrencyID,CurrencyName,Description,BaseCurrency ,FXRate
FROM tblCurrency
WHERE
Deleted=''''False'''' ''
IF @Condition <> ''''
BEGIN
SELECT @Query = @Query + @Condition
END
SET @Query=@Query+'' Order by datemodified desc''
EXEC(@Query)
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAgencyFeeIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 01/11/2007
-- Description: For AgencyFee Deletion
-- =============================================
CREATE procedure [dbo].[UspTblAgencyFeeIsDeletedUpdate]
(
-- Add the parameters for the stored procedure here
@AgencyFeeID int,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
UPDATE tblAgencyFee
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
AgencyFeeID=@AgencyFeeID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
ELSE
BEGIN
SET @Result=1
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblTalentSelectByProductionID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet
-- Create date: 01/11/2007
-- Description: For Disbursement
-- =============================================
Create PROCEDURE [dbo].[USPTblTalentSelectByProductionID]--''4''
-- Add the parameters for the stored procedure here
@Productionid int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
select tbljob.Talentid,Talentname from tbljob inner join tbltalent on tbljob.talentid=tbltalent.talentid where Productionid=@Productionid and tbljob.Deleted=0
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCountrySelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 11/9/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCountrySelect]
AS
SET NOCOUNT ON
SELECT CountryId,CountryName,a.CurrencyId,CurrencyName,LabelGST,
Status=CASE a.deleted When ''False'' then ''Active''
Else
''InActive''
END
from tblCountry a inner join tblcurrency c on
a.currencyid=c.currencyid
where a.deleted = ''False''
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountLogout]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Sep/2007
-- Description: This make the entry for logout in tblLog
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountLogout]
-- Add the parameters for the stored procedure here
@AccountLogId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblAccountLog
SET LogoutDateTime=getdate()
WHERE AccountLogId=@AccountLogId
IF (@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralMaintenanceInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir
-- Create date: 12/Sep/2007
-- Description: Insert values into central maintenance table
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralMaintenanceInsert]
-- Add the parameters for the stored procedure here
@MaintenanceTable VARCHAR(50),
@Action VARCHAR(50),
@Detail VARCHAR(1000),
@DateModified DATETIME,
@ModifiedBy INT,
@ModifiedID INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO tblCentralMaintenance(MaintenanceTable,Action,Detail,DateModified,ModifiedBy,ModifiedId)
VALUES(@MaintenanceTable,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralSelectedUsers]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13/Sep/2007
-- Description: Select All Central Users
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralSelectedUsers] --null,null,null
@CentralProfileId INT,
@UserName VARCHAR(50),
@Deleted INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE
@query varchar(1000),
@condition varchar(200)
IF(@CentralProfileId<>'''')
BEGIN
SELECT @condition=''A.CentralProfileId='' + Cast(@CentralProfileId as varchar(10))
END
IF(@UserName<>'''')
BEGIN
IF(@condition<>'''')
BEGIN
SELECT @condition = @condition + '' AND t.UserName like ''''%'' + @UserName + ''%'''' ''
END
ELSE
BEGIN
SELECT @condition = ''t.UserName like ''''%'' + @UserName + ''%'''' ''
END
END
IF(@Deleted = 0 Or @Deleted = 1)
BEGIN
IF(@condition<>'''')
BEGIN
SELECT @condition = @condition + '' AND A.deleted='' + Cast(@Deleted as VARCHAR(5))
END
ELSE
BEGIN
SELECT @condition = ''A.deleted='' + Cast(@Deleted as VARCHAR(5))
END
END
ELSE
BEGIN
IF(@condition<>'''')
BEGIN
SELECT @condition = @condition + '' AND A.deleted=0''
END
ELSE
BEGIN
SELECT @condition = ''A.deleted=0''
END
END
IF(@condition<>'''')
BEGIN
SELECT @condition = '' WHERE '' + @condition
END
SELECT @query= ''SELECT A.UserId,t.UserName,Email,
Status=CASE a.deleted When ''''False'''' then ''''Active''''
Else
''''InActive''''
END
,PasswordCreationDate,P.CentralProfileName,P.CentralProfileId
FROM tblCentralAdmin A inner join
tblCentralProfile P on
A.CentralProfileId=P.CentralProfileId
inner join
(select AA.UserId,FirstName+'''' ''''+LastName as UserName
from tblCentralAdmin AA
inner join tblCentralUserPersonalInfo uu on
AA.userid=uu.userid ) t on A.UserId=t.UserId''
IF(@condition<>'''')
BEGIN
SELECT @query= @query + @condition
END
SELECT @query = @query + '' order by A.datemodified desc''
exec(@query)
--print(@query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGetNoOfAgencies]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 5Jan2008
-- Description: Returns Max no. of agencies
-- =============================================
CREATE PROCEDURE [dbo].[UspTblGetNoOfAgencies] --null
-- Add the parameters for the stored procedure here
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT @Result = AgencyMax FROM tblSite WHERE [Default]=''True'' AND Deleted=''False''
--print @Result
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralNavigationSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralNavigationSelect]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT CentralNavigationId,Name,Description,Parent,Sequence
FROM tblCentralNavigation
WHERE deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralNavigationGroup]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <19/12/2007>
-- Description:
CREATE PROCEDURE [dbo].[UspTblCentralNavigationGroup]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select distinct CentralNavigationId, Name, Description
from tblCentralNavigation where parent is null and deleted=''0''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCountrySelectBySearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/9/2007
-- Description: Select a particular Country
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCountrySelectBySearch] --null,null
@CountryId INT,
@CountryName Varchar(50) = null
AS
SET NOCOUNT ON
DECLARE @Query VARCHAR(1000)
DECLARE @Condition VARCHAR(1000)
IF @CountryId <> ''''
BEGIN
SELECT @Condition = '' AND CountryId = '' + CAST(@CountryId AS VARCHAR(10))
END
IF @CountryName <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND CountryName like ''''%'' + @CountryName + ''%'''' ''
END
ELSE
BEGIN
SELECT @Condition = '' AND CountryName like ''''%'' + @CountryName + ''%'''' ''
END
END
SELECT @Query =''SELECT CountryId,CountryName,a.CurrencyId,CurrencyName,LabelGST,
Status=CASE a.deleted When ''''False'''' then ''''Active''''
Else
''''InActive''''
END
from tblCountry a inner join tblcurrency c on
a.currencyid=c.currencyid
where a.deleted = ''''False''''''
IF @Condition <> ''''
BEGIN
SELECT @Query = @Query + @Condition
END
SET @Query=@Query+'' order by a.datemodified desc''
EXEC(@Query)
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblJobSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 17/10/2005
-- Modified Date: 02/11/2007
-- Description: For Job Select
-- =============================================
CREATE PROCEDURE [dbo].[USPTblJobSelect] --''1'', ''10'', 29
-- Add the parameters for the stored procedure here
@AccountId int,
@ProductionId int=Null,
@AgencyID int=NULL,
@CompanyID int=NULL,
@TalentID int=NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE
@query varchar(2000),
@condition varchar(500)
SELECT @condition = '' WHERE j.Deleted=''''0''''''
IF(@AgencyID>0)
BEGIN
SELECT @condition = @condition + '' AND a.AgencyID = '' + cast(@AgencyID as varchar(10))
END
IF(@ProductionId>0)
BEGIN
SELECT @condition = @condition + '' AND p.ProductionId = '' + cast(@ProductionId as varchar(10))
END
IF(@CompanyID>0)
BEGIN
SELECT @condition = @condition + '' AND c.CompanyID = '' + cast(@CompanyID as varchar(10))
END
IF(@TalentId>0)
BEGIN
SELECT @condition = @condition + '' AND t.TalentId = '' + cast(@TalentId as varchar(10))
END
SELECT @query= ''SELECT
j.JobId, p.ProductionId, p.ProductionTitle, pt.Name as ProductionTypeName, a.AgencyName, a.AgencyId,
c.CompanyName, c.CompanyId,
t.TalentId, t.TalentName,
''''test'''' as IsEmployee
FROM tblJob as j
INNER JOIN
tblProduction as p ON
p.ProductionId=j.ProductionId AND p.Deleted=''''0'''' AND p.AccountId='' + cast(@AccountID as varchar(20))
SELECT @query = @query + '' INNER JOIN
tblAgency as a ON
a.AgencyId=p.AgencyId AND a.Deleted=''''0''''
INNER JOIN
tblCompany as c ON
c.CompanyId=p.CompanyId AND c.Deleted=''''0''''
INNER JOIN tblTalent AS t ON
t.TalentId=j.TalentId AND t.Deleted=''''0''''
LEFT JOIN
tblProductionType AS pt ON
pt.ProductionTypeId=p.ProductionTypeId AND pt.Deleted=''''0''''''
SELECT @query= @query + @condition + '' order by j.datemodified desc ''
EXEC(@query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralProfilePermission]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: < 20/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralProfilePermission]
@ProfileId int,
@FormName varchar(100)
AS
/* SET NOCOUNT ON */
Declare @@NavigationId as int
set @@NavigationId = (select distinct isnull(CentralNavigationId,0) from tblCentralNavigation
Where FormName=@FormName)
IF @@NavigationId <>0
Begin
select [select], [insert], [update],[delete] from tblCentralmenu
where CentralProfileId=@ProfileId and CentralNavigationId=@@NavigationId
End
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblProductionsByAgencyId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 8/Jan/2008
-- Description: Fill dropdown with productions
-- =============================================
CREATE PROCEDURE [dbo].[USPTblProductionsByAgencyId]
-- Add the parameters for the stored procedure here
@AgencyId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT ProductionId,ProductionTitle
FROM tblProduction
WHERE AgencyId=@AgencyId
AND Deleted=''False''AND Completed=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountLogInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Sep/2007
-- Description: Insert log when any account user logs on
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountLogInsert]
-- Add the parameters for the stored procedure here
@AccountId INT,
@PersonId INT,
@ProfileId INT,
@AccountLogId INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRAN
INSERT INTO tblAccountLog(AccountId,PersonId,ProfileId,LoginDateTime)
VALUES(@AccountId,@PersonId,@ProfileId,getdate())
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
ELSE
BEGIN
SET @AccountLogId =(SELECT ISNULL(MAX(AccountLogId),0)
FROM tblAccountLog)
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblViewInvs]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Nov/2007
-- Description: View all Invoices according BatchId
-- =============================================
CREATE PROCEDURE [dbo].[UsptblViewInvs] --201,null
-- Add the parameters for the stored procedure here
@BatchId INT,
@Printed BIT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(500)
DECLARE @Cond VARCHAR(100)
SET @Query = ''SELECT InvoiceId,AgencyName,TalentName,CompanyName,InvoicDate,
Status=CASE Printed When ''''False'''' then ''''UnPrinted''''
Else
''''Printed''''
END
FROM vwInvoiceFormat
WHERE BatchId=''+Cast(@BatchId as VARCHAR(10))
IF (@Printed=0 Or @Printed=1)
BEGIN
SET @Cond = '' AND Printed='' + Cast(@Printed as VARCHAR(5))
END
IF @Cond<>''''
BEGIN
SET @Query = @Query+@Cond
END
EXEC(@Query)
--Print(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblTalentFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/10/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblTalentFillDdl] --''1'',''12'','''','''',''1''
-- Add the parameters for the stored procedure here
(
@AccountId int,
@CompanyId int=NULL,
@AgencyId int=NULL,
@ProductionId int=NULL,
@DDLforProduction bit=NULL -- TRUE for ManageJob page only for rest pages it is FALSE
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE
@qry varchar(2000),
@cond varchar(500)
SELECT @cond = '' WHERE t.Deleted=''''0''''''
-- IF(@CompanyID>0 OR @ProductionId>0 OR @AgencyId>0 OR @DDLforProduction=''1'')
-- BEGIN
-- IF(@CompanyID>0)
-- BEGIN
-- SELECT @cond = @cond + '' AND prod.CompanyId = '' + cast(@CompanyId as varchar(20))
-- END
--
-- IF(@AgencyId>0)
-- BEGIN
-- SELECT @cond = @cond + '' AND prod.AgencyId = '' + cast(@AgencyId as varchar(20))
-- END
--
-- IF(@ProductionId>0)
-- BEGIN
-- SELECT @cond = @cond + '' AND prod.ProductionId = '' + cast(@ProductionId as varchar(20))
-- SELECT @cond = @cond + '' AND prod.AgencyId=agy.AgencyId''
-- END
--
-- SELECT @qry= ''Select distinct t.TalentId, t.TalentName
-- from tblTalent t
-- INNER JOIN
-- tblPerson as p ON
-- p.AccountID= '' + cast(@AccountId as varchar(20))
-- SELECT @qry = @qry + '' AND p.Deleted=0
-- INNER JOIN
-- tblMapPersonProfile as pp ON
-- pp.PersonId = p.PersonID
-- AND pp.Deleted=''''0''''
-- INNER JOIN
-- tblTalentAccess AS a ON
-- p.PersonID=a.PersonID AND
-- t.TalentId=a.TalentId
-- AND a.Deleted=''''0''''
-- INNER JOIN tblProduction as prod ON
-- prod.Deleted=''''0''''
-- INNER JOIN
-- tblAgency as agy ON
-- agy.AgencyId=prod.AgencyId AND agy.Deleted=''''0''''
-- INNER JOIN tblJob AS j ON
-- j.ProductionID=prod.ProductionID AND j.TalentId=t.TalentId''
-- END
-- ELSE
BEGIN
SELECT @qry= ''Select distinct t.TalentId, t.TalentName
from tblTalent t
INNER JOIN
tblPerson as p ON
p.AccountID='' + cast(@AccountId as varchar(20))
SELECT @qry = @qry + '' AND p.Deleted=0
INNER JOIN
tblMapPersonProfile as pp ON
pp.PersonId = p.PersonID
AND pp.Deleted=''''0''''
INNER JOIN
tblTalentAccess AS a ON
p.PersonID=a.PersonID AND
t.TalentId=a.TalentId
AND a.Deleted=''''0''''
INNER JOIN tblProduction as prod ON
prod.Deleted=''''0''''''
END
SELECT @qry = @qry + @cond
EXEC(@qry)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralLogInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Sep/2007
-- Description: Insert log when any account user logs on
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralLogInsert]
-- Add the parameters for the stored procedure here
@UserId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO tblCentralLog(UserId,LoginDateTime)
VALUES(@UserId,getdate())
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralLogout]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Sep/2007
-- Description: This make the entry for logout in tblLog
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralLogout]
-- Add the parameters for the stored procedure here
@CentralLogId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblCentralLog
SET LogOutDateTime=getdate()
WHERE CentralLogId=@CentralLogId
IF (@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblUpdateStatus]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet
-- Create date: 23/10/2007
--Modified date: 20/9/2007
-- Description: For Login Process
-- =============================================
CREATE procedure [dbo].[USPTblUpdateStatus]
(
-- Add the parameters for the stored procedure here
@Id int,
@ContactId int,
@Profile varchar(50),
@Result int Output
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Begin tran
if @Profile=''Agency''
Begin
Update tblAgencycontact set [Default]=''true'' where AgencyId=@Id
and ContactId=@ContactId
Update tblAgencycontact set [Default]=''false'' where AgencyId=@Id and
ContactId <> @ContactId
End
Else If @Profile=''Company''
Begin
Update tblCompanycontact set [Default]=''true'' where CompanyId=@Id
and ContactId=@ContactId
Update tblCompanycontact set [Default]=''false'' where CompanyId=@Id and
ContactId <> @ContactId
End
Else If @Profile=''Talent''
Begin
Update tblTalentcontact set [Default]=''true'' where TalentId=@Id
and ContactId=@ContactId
Update tblTalentcontact set [Default]=''false'' where TalentId=@Id and
ContactId <> @ContactId
End
if @@Error<>0
Begin
Rollback tran
set @Result=0
End
else
Begin
Commit tran
set @Result=1
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCurrencySelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 11/9/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCurrencySelect]
AS
SET NOCOUNT ON
SELECT CurrencyId,CurrencyName,BaseCurrency,
Status=CASE deleted When ''False'' then ''Active''
Else
''InActive''
End
from tblCurrency
Where deleted=''False''
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblCentralUserFullName]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Oct/2007
-- Description: Retruns FullNAme of the user who logged On
-- =============================================
CREATE PROCEDURE [dbo].[UsptblCentralUserFullName]
-- Add the parameters for the stored procedure here
@UserId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT FirstName + '' '' + LastName AS FullName
FROM tblCentralUserPersonalInfo
WHERE
UserId=@UserId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSearchTalentByDynaAttributes]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14/Jan/2008
-- Description: Search Talents by Dynamic Attributes
-- Modified By: Jatin
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSearchTalentByDynaAttributes] --8,''Like'',''red'',null,null,null,null,null,null,1
-- Add the parameters for the stored procedure here
@Param1 INT,
@Op1 VARCHAR(10),
@Value1 VARCHAR(100),
@Param2 INT,
@Op2 VARCHAR(10),
@Value2 VARCHAR(100),
@Param3 INT,
@Op3 VARCHAR(10),
@Value3 VARCHAR(100),
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(2000)
DECLARE @Condition VARCHAR(1000)
DECLARE @joinQry VARCHAR(2000)
IF @Op1=''Like'' OR @Op1=''Not Like''
SET @Value1='' ''''%'' + @Value1 + ''%''''''
IF @Op2=''Like'' OR @Op2=''Not Like''
SET @Value2='' ''''%'' + @Value2 + ''%''''''
IF @Op3=''Like'' OR @Op3=''Not Like''
SET @Value3='' ''''%'' + @Value3 + ''%''''''
SET @Query=''SELECT t.talentId,t.TalentName,CountryName FROM tblTalent AS t
INNER JOIN tblTalentAccess ta
INNER JOIN tblPerson p
ON ta.PersonId=p.PersonId
AND p.AccountId='' + Cast(@AccountId as varchar(30)) +
'' ON t.TalentId=ta.TalentId
INNER JOIN tblCountry c
ON t.Country=c.CountryId''
SET @Condition = '' WHERE t.Deleted=''''False''''''
SET @joinQry = '' ''
IF (@Param1 <> '''' AND @Op1 <> '''' AND @Value1 <> '''')
BEGIN
IF @Op1=''Like'' OR @Op1=''Not Like''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t1 ON
t1.attributeId='' + Cast(@Param1 as varchar(10)) +
'' and t1.value ''+ Cast(@Op1 as varchar(10)) + Cast(@Value1 as varchar(110)) + '' AND t1.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t1 ON
t1.attributeId='' + Cast(@Param1 as varchar(10)) +
'' and CAST(t1.value AS FLOAT) ''+ Cast(@Op1 as varchar(10)) + Cast(@Value1 as varchar(110)) + '' AND t1.TalentId=t.TalentId ''
END
END
IF (@Param2 <> '''' AND @Op2 <> '''' AND @Value2 <> '''')
BEGIN
IF @Op2=''Like'' OR @Op2=''Not Like''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t2 ON
t2.attributeId='' + Cast(@Param2 as varchar(10)) +
'' and t2.value ''+ Cast(@Op2 as varchar(10)) + Cast(@Value2 as varchar(110)) + '' AND t2.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t2 ON
t2.attributeId='' + Cast(@Param2 as varchar(10)) +
'' and CAST(t2.value AS FLOAT) ''+ Cast(@Op2 as varchar(10)) + Cast(@Value2 as varchar(110)) + '' AND t2.TalentId=t.TalentId ''
END
END
IF (@Param3 <> '''' AND @Op3 <> '''' AND @Value3 <> '''')
BEGIN
IF @Op3=''Like'' OR @Op3=''Not Like''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t3 ON
t3.attributeId='' + Cast(@Param3 as varchar(10)) +
'' and t3.value ''+ Cast(@Op3 as varchar(10)) + Cast(@Value3 as varchar(110)) + '' AND t3.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t3 ON
t3.attributeId='' + Cast(@Param3 as varchar(10)) +
'' and CAST(t3.value AS FLOAT) ''+ Cast(@Op3 as varchar(10)) + Cast(@Value3 as varchar(110)) + '' AND t3.TalentId=t.TalentId ''
END
END
IF @joinQry <> ''''
BEGIN
SET @Query = @Query + @joinQry + @Condition
END
ELSE
BEGIN
SET @Query = @Query + @Condition
END
--PRINT(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblPersonSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir
-- Create date: 4/9/2005
-- Description: For Login Process
-- =============================================
CREATE PROCEDURE [dbo].[UspTblPersonSelect]
-- Add the parameters for the stored procedure here
@UserName varchar(50) = 0,
@Password varchar(100) = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT PersonId
FROM tblPerson
WHERE PersonName=@UserName
AND
Password=@Password
And
Deleted=0
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountProfilesBySearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Oct/2007
-- Description: Selected Profiles on seach
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountProfilesBySearch] --null,null
-- Add the parameters for the stored procedure here
@ProfileName VARCHAR(50),
@InActive INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @Query as VARCHAR(1000)
Declare @Condition as VARCHAR(1000)
IF @ProfileName <> ''''
BEGIN
Select @Condition = ''AND ProfileName like ''''%'' + @ProfileName + ''%'''' ''
END
IF(@InActive = 0 Or @InActive = 1)
BEGIN
IF(@Condition<>'''')
BEGIN
SELECT @Condition = @Condition + '' AND InActive='' + Cast(@InActive as VARCHAR(5))
END
ELSE
BEGIN
SELECT @Condition = '' AND InActive='' + Cast(@InActive as VARCHAR(5))
END
END
SELECT @Query = ''SELECT p.ProfileId ,p.ProfileName,
--Convert(VARCHAR,p.DateModified,106) as DateModified,
Status=CASE p.InActive When ''''False'''' then ''''Active''''
Else
''''InActive''''
END
--,c.UserName as ModifiedBy
FROM tblProfile p
inner join
(Select ca.userid,FirstName+'''' ''''+LastName as UserName
From tblCentralAdmin ca
inner join tblCentralUserPersonalInfo ci
on
ca.userid=ci.userid )c
on p.ModifiedBy = c.UserId
WHERE p.Deleted=''''False''''''
IF @Condition <> ''''
BEGIN
SELECT @Query = @Query + @Condition
END
exec(@Query)
--print(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblReceiptSelectAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin Kumar
-- Create date: 05/12/2007
-- Modified date: 05/02/2008
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[USPTblReceiptSelectAll] --''1'',''4'',''1'',''1''
-- Add the parameters for the stored procedure here
@AccountId INT,
@ProductionId INT=NULL,
@AgencyID INT=NULL,
@CompanyID INT=NULL
AS
BEGIN
DECLARE
@query varchar(2000),
@condition varchar(500)
SELECT @condition = '' WHERE r.Deleted=''''0'''' AND r.AccountId='' + cast(@AccountId as varchar(10))
IF(@AgencyID>0)
BEGIN
SELECT @condition = @condition + '' AND ag.AgencyID = '' + cast(@AgencyID as varchar(10))
END
IF(@ProductionId>0)
BEGIN
SELECT @condition = @condition + '' AND p.ProductionId = '' + cast(@ProductionId as varchar(10))
END
IF(@CompanyID>0)
BEGIN
SELECT @condition = @condition + '' AND c.CompanyID = '' + cast(@CompanyID as varchar(10))
END
SELECT @query= ''SELECT Distinct r.datemodified,r.ReceiptId, p.ProductionTitle, r.Description,
r.Posted, CASE WHEN ((select Count(*) from tblAllocation AS a WHERE a.ReceiptId=r.ReceiptId AND a.Posted=0)>0)
THEN ''''true'''' ELSE ''''false'''' END AS IsAllocation,
CASE WHEN ((select Count(*) from tblLiability AS l WHERE l.ReceiptId=r.ReceiptId)>0)
THEN ''''true'''' ELSE ''''false'''' END AS IsLiability
FROM tblReceipt AS r
INNER JOIN tblProduction AS p ON
p.ProductionId=r.ProductionId AND
p.AccountId='' + cast(@AccountId as varchar(10))
SELECT @query= @query + '' INNER JOIN tblAgency AS ag ON
ag.AgencyId=p.AgencyId
INNER JOIN tblCompany AS c ON
c.CompanyId=p.CompanyId
INNER JOIN tblAllocation AS a ON
a.ReceiptId=r.ReceiptId ''
SELECT @query= @query + @condition + '' order by r.datemodified desc ''
EXEC(@query)
END'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCompanySearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 261007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCompanySearch]
-- Add the parameters for the stored procedure here
@CompanyName varchar(100) ,
@CountryId int ,
@AccountId int,
@Status bit=0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Declare @Query as varchar(2000)
set @Query='' Select comp.CompanyId,comp.Companyname,cc.Telephone,comp.Deleted,Countryname from tblcompany comp left join tblcompanycontact cc on comp.companyid=cc.companyid left join tblcountry cntry on
comp.countryid=cntry.countryid where comp.CompanyId in(Select CompanyId from tblCompanyAcess a inner join tblperson p on
a.PersonId=p.PersonId where AccountId=''+convert(varchar,@AccountId)+''and comp.Deleted=''+ convert(varchar,@Status)+'')'' + ''and cc.[Default]=1''
IF(@CompanyName !='''')
BEGIN
SET @Query=@Query + ''and comp.CompanyName like''''%'' + @CompanyName+''%''''''
END
IF (@CountryId > 0)
BEGIN
SET @Query=@Query + ''and comp.CountryId='' + convert(varchar,@CountryId)
END
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCompanyContactSearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 260907
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCompanyContactSearch]
-- Add the parameters for the stored procedure here
@Title varchar(50) ,
@Mobile varchar(20),
@Telephone varchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Declare @Query as varchar(2000)
SET @Query='' Select [CompanyId]
,[ContactId]
,[CompanyName]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
,[Deleted]
,[DateModified]
,[ModifiedBy] from tblcompanyContact where ContactId is not null ''
IF (@Title !='''')
Begin
set @Query=@Query + ''and Title='''''' + @Title+''''''''
End
IF (@Mobile !='''')
Begin
set @Query=@Query + ''and Mobile='''''' + @Mobile+''''''''
End
IF (@Telephone !='''')
Begin
set @Query=@Query + ''and Telephone='''''' +@Telephone+''''''''
End
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblExceptionLogInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- =============================================
-- Author: Gurnek Singh
-- Create date: 09/08/2007
-- Description: Insert log entry into TbleExceptionLog table.
-- =============================================
CREATE PROCEDURE [dbo].[UspTblExceptionLogInsert]
(
@EventID int,
@Priority int,
@Severity nvarchar(32),
@Title nvarchar(256),
@Timestamp datetime,
@MachineName nvarchar(32),
@AppDomainName nvarchar(512),
@ProcessID nvarchar(256),
@ProcessName nvarchar(512),
@ThreadName nvarchar(512),
@Win32ThreadId nvarchar(128),
@Message nvarchar(1500),
@FormattedMessage ntext,
@LogId int OUTPUT
)
AS
INSERT INTO [tblExceptionLog] (
EventID,
Priority,
Severity,
Title,
[Timestamp],
MachineName,
AppDomainName,
ProcessID,
ProcessName,
ThreadName,
Win32ThreadId,
Message,
FormattedMessage
)
VALUES (
@EventID,
@Priority,
@Severity,
@Title,
@Timestamp,
@MachineName,
@AppDomainName,
@ProcessID,
@ProcessName,
@ThreadName,
@Win32ThreadId,
@Message,
@FormattedMessage)
SET @LogID = @@IDENTITY
RETURN @LogID
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSelectAccountNames]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 15 Oct 2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSelectAccountNames]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT AccountId,Name
FROM tblAccount
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralProfileSelectAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13/Sep/2007
-- Description: Returns all central user profiles
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralProfileSelectAll]
-- Add the parameters for the stored procedure here
@ProfileId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(1000)
DECLARE @Cond VARCHAR(500)
IF @ProfileId>=2
BEGIN
SET @Cond='' AND
CentralProfileId>2''
END
ELSE
BEGIN
IF @ProfileId = 1
BEGIN
SET @Cond='' AND
CentralProfileId>1''
END
END
SET @Query= ''SELECT CentralProfileId,CentralProfileName
FROM tblCentralProfile
WHERE Deleted=''''False''''''
IF @Cond<>''''
BEGIN
SET @Query=@Query+@Cond
END
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSearchTalentByDynaAttributes1]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14/Jan/2008
-- Description: Search Talents by Dynamic Attributes
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSearchTalentByDynaAttributes1] --3,''>'',120,null,null,null,null,null,null,1
-- Add the parameters for the stored procedure here
@Param1 INT,
@Op1 VARCHAR(10),
@Value1 VARCHAR(100),
@Param2 INT,
@Op2 VARCHAR(10),
@Value2 VARCHAR(100),
@Param3 INT,
@Op3 VARCHAR(10),
@Value3 VARCHAR(100),
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(2000)
DECLARE @Condition VARCHAR(1000)
DECLARE @joinQry VARCHAR(2000)
IF @Op1=''Like'' OR @Op1=''Not Like''
SET @Value1='' ''''%'' + @Value1 + ''%''''''
IF @Op2=''Like'' OR @Op2=''Not Like''
SET @Value2='' ''''%'' + @Value2 + ''%''''''
IF @Op3=''Like'' OR @Op3=''Not Like''
SET @Value3='' ''''%'' + @Value3 + ''%''''''
SET @Query=''SELECT t.talentId,t.TalentName,CountryName FROM tblTalent AS t
INNER JOIN tblTalentAccess ta
INNER JOIN tblPerson p
ON ta.PersonId=p.PersonId
AND p.AccountId='' + Cast(@AccountId as varchar(30)) +
'' ON t.TalentId=ta.TalentId
INNER JOIN tblCountry c
ON t.Country=c.CountryId''
SET @Condition = '' WHERE t.Deleted=''''False''''''
IF (@Param1 <> '''' AND @Op1 <> '''' AND @Value1 <> '''')
BEGIN
IF @joinQry<>''''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t1 ON
t1.attributeId='' + Cast(@Param1 as varchar(10)) +
'' and t1.value ''+ Cast(@Op1 as varchar(10)) + Cast(@Value1 as varchar(110)) + '' AND t1.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = '' INNER JOIN tblTalentAttribute AS t1 ON
t1.attributeId='' + Cast(@Param1 as varchar(10)) +
'' and t1.value ''+ Cast(@Op1 as varchar(10)) + Cast(@Value1 as varchar(110)) + '' AND t1.TalentId=t.TalentId ''
END
END
IF (@Param2 <> '''' AND @Op2 <> '''' AND @Value2 <> '''')
BEGIN
IF @joinQry<>''''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t2 ON
t2.attributeId='' + Cast(@Param2 as varchar(10)) +
'' and t2.value ''+ Cast(@Op2 as varchar(10)) + Cast(@Value2 as varchar(110)) + '' AND t2.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = '' INNER JOIN tblTalentAttribute AS t2 ON
t2.attributeId='' + Cast(@Param2 as varchar(10)) +
'' and t2.value ''+ Cast(@Op2 as varchar(10)) + Cast(@Value2 as varchar(110)) + '' AND t2.TalentId=t.TalentId ''
END
END
IF (@Param3 <> '''' AND @Op3 <> '''' AND @Value3 <> '''')
BEGIN
IF @joinQry<>''''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t3 ON
t3.attributeId='' + Cast(@Param3 as varchar(10)) +
'' and t3.value ''+ Cast(@Op3 as varchar(10)) + Cast(@Value3 as varchar(110)) + '' AND t3.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = '' INNER JOIN tblTalentAttribute AS t3 ON
t3.attributeId='' + Cast(@Param3 as varchar(10)) +
'' and t3.value ''+ Cast(@Op3 as varchar(10)) + Cast(@Value3 as varchar(110)) + '' AND t3.TalentId=t.TalentId ''
END
END
IF @joinQry <> ''''
BEGIN
SET @Query = @Query + @joinQry + @Condition
END
ELSE
BEGIN
SET @Query = @Query + @Condition
END
PRINT(@Query)
--EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblAgencyContactSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 170907
-- Description: View All Contacts of an Agency
-- =============================================
CREATE procedure [dbo].[USPTblAgencyContactSelect]
-- Add the parameters for the stored procedure here
@AgencyID int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SELECT [AgencyId]
,[ContactId]
,[AgencyName]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
,[Deleted]
,[DateModified]
,[ModifiedBy] FROM tblAgencycontact WHERE AgencyID=@AgencyID and Deleted=0 order by DateModified desc
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USpMAxAgencyId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET
-- Create date: 160108
-- Description: PICKUP MAXIMUM AGENCYID FROM AGENCY TABLE
-- =============================================
CREATE PROCEDURE [dbo].[USpMAxAgencyId]
-- Add the parameters for the stored procedure here
@Result int Output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Set @Result =(Select max(agencyid) from tblagency)
return @Result
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspAccountLogIn]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: JAGSIR SINGH
-- Create date: 5 sep 2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspAccountLogIn]
@UserName VARCHAR(50),
@Password VARCHAR(100)
AS
SET NOCOUNT ON
DECLARE @CH INT
DECLARE @LogId INT
DECLARE @PersonId INT
SELECT p.PersonId,p.AccountId,PersonName,p.Email,p.FirstName
FROM tblPerson p,tblAccount a
WHERE PersonName=@UserName
AND
Password=@Password
AND
p.Deleted=''False''
AND
p.AccountId=a.AccountId
And
a.Deleted=''False''
SELECT @CH = COUNT(*)
FROM tblPerson
WHERE PersonName=@UserName
AND
Password=@Password
AND
Deleted=''False''
IF(@CH>0)
BEGIN
BEGIN TRAN
SELECT @PersonId=PersonId
FROM tblPerson
WHERE PersonName=@UserName
AND
Password=@Password
AND
Deleted=''False''
UPDATE tblPerson
SET LastLogin=getdate()
WHERE PersonName=@UserName
AND
Password=@Password
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SELECT mp.ProfileId,p.ProfileName
FROM tblMapPersonProfile mp,
tblProfile p
WHERE PersonId=@PersonId
AND
mp.ProfileId=p.ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblUpdateAccountStatus]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet
-- Create date: 23/10/2007
--Modified date: 20/9/2007
-- Description: For Login Process
-- =============================================
CREATE procedure [dbo].[USPTblUpdateAccountStatus]--35,7,''Talent'','''',
(
-- Add the parameters for the stored procedure here
@Id int,
@AccountId int,
@Profile varchar(50),
@Type varchar(30),
@Result int Output
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @Query as varchar(2000)
Begin tran
if @Profile=''Agency''
Begin
Set @Query=''Update tblAgencyAccount set ''+ @Type+''Default=''''true'''' where AgencyId=''+cast(@Id as varchar)
+'' and AgencyAccountId=''+cast(@AccountId as varchar)
exec(@Query)
Set @Query=''Update tblAgencyAccount set ''+ @Type+''Default=''''false'''' where AgencyId=''+cast(@Id as varchar)
+ '' and AgencyAccountId <>'' +cast(@AccountId as varchar)
exec(@Query)
End
Else If @Profile=''Talent''
Begin
Set @Query=''Update tblTalentAccount set [Default]=''''true'''' where TalentId=''+cast(@Id as varchar)
+'' and TalentAccountId=''+cast(@AccountId as varchar)
exec(@Query)
Set @Query=''Update tblTalentAccount set [Default]=''''false'''' where TalentId=''+cast(@Id as varchar)
+'' and TalentAccountId <> ''+cast(@AccountId as varchar)
exec(@Query)
End
if @@Error<>0
Begin
Rollback tran
set @Result=0
End
else
Begin
Commit tran
set @Result=1
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSearchTalentsByAttributes]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 2/Jan/2008
-- Description: Search Talents by Attributes
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSearchTalentsByAttributes] --172,67,''Fair'',''Black'',''White'',''F'',1
-- Add the parameters for the stored procedure here
@Height INT,
@Weight INT,
@Color VARCHAR(50),
@HairColor VARCHAR(50),
@EyeColor VARCHAR(50),
@Sex CHAR(1),
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(2000)
DECLARE @Condition VARCHAR(2000)
IF @Height <> 0
BEGIN
SELECT @Condition='' WHERE ta.Height = '' + CAST(@Height AS VARCHAR(10))
END
IF @Weight <> 0
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.Weight = '' + CAST(@Weight AS VARCHAR(10))
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.Weight = '' + CAST(@Weight AS VARCHAR(10))
END
END
IF @Color <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.Color = '''''' + @Color + ''''''''
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.Color = '''''' + @Color + ''''''''
END
END
IF @HairColor <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.HairColor = '''''' + @HairColor + ''''''''
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.HairColor = '''''' + @HairColor + ''''''''
END
END
IF @EyeColor <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.EyeColor = '''''' + @EyeColor + ''''''''
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.EyeColor = '''''' + @EyeColor + ''''''''
END
END
IF @Sex <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.Sex = '''''' + @Sex + ''''''''
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.Sex = '''''' + @Sex + ''''''''
END
END
IF @Condition <> ''''
BEGIN
SELECT @Query= ''SELECT t.TalentId,TalentName,CountryName
FROM tblTalent t
INNER JOIN tblTalentAccess tac
INNER JOIN tblPerson p
ON tac.PersonId=p.PersonId
AND p.AccountId=''+ CAST(@AccountId AS VARCHAR(10))+
'' AND p.Deleted=''''False''''
ON t.TalentId=tac.TalentId
INNER JOIN tblTalentAttribute ta
ON t.TalentId=ta.TalentId
AND ta.Deleted=''''False''''
INNER JOIN tblCountry c
ON t.Country=c.CountryId'' + @Condition
END
ELSE
BEGIN
SELECT @Query= ''SELECT t.TalentId,TalentName,CountryName
FROM tblTalent t
INNER JOIN tblTalentAccess tac
INNER JOIN tblPerson p
ON tac.PersonId=p.PersonId
AND p.AccountId=''+Cast(@AccountId as varchar(10))+
'' AND p.Deleted=''''False''''
ON t.TalentId=tac.TalentId
INNER JOIN tblCountry c
ON t.Country=c.CountryId''
END
--PRINT(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblTalentSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2005
--Modified date: 20/9/2007
-- Description: For Login Process
-- =============================================
CREATE procedure [dbo].[USPTblTalentSelect]--1,5
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@Country varchar(20) = NULL,
@Name varchar(100) = NULL,
@LastActivity datetime = NULL,
@TalentId int=NULL
)
AS
DECLARE
@query varchar(1000),
@condition varchar(500)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT @condition = '' WHERE t.Deleted=0 ''
IF(@Name<>'''')
BEGIN
SELECT @condition = @condition + '' AND (t.TalentName like ''''%'' + @Name + ''%'''') ''
END
IF(@Country>0)
BEGIN
SELECT @condition = @condition + '' AND t.Country = '' + cast(@Country as varchar(15))
END
IF(@TalentId>0)
BEGIN
SELECT @condition = @condition + '' AND t.TalentId = '' + cast(@TalentId as varchar(15))
END
IF(@LastActivity<>'''')
BEGIN
SELECT @condition = @condition + '' AND p.LastLogin >= '''''' + cast(@LastActivity as varchar(30)) + ''''''''
END
-- IF(@condition<>'''')
-- BEGIN
-- SELECT @condition = '' WHERE '' + @condition, p.PersonName, p.Email, p.LastLogin, tc.Telephone, tc.Mobile,
-- END
SELECT @query= ''SELECT
t.TalentID ,c.CountryName, c.CountryId,
t.TalentName,
CASE t.Deleted
WHEN ''''true'''' THEN ''''InActive''''
ELSE ''''Active''''
END as Status
FROM
tblTalent AS t
INNER JOIN
tblCountry AS c ON
c.CountryID=t.Country
LEFT outer JOIN
tblTalentContact AS tc ON
tc.TalentId=t.TalentId AND TC.[Default]=''''1''''
INNER JOIN
tblPerson AS p ON p.AccountID=''
SELECT @query= @query + cast(@AccountID as varchar(20))
SELECT @query= @query + '' AND p.Deleted=0
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId=''
SELECT @query= @query + cast(@ProfileId as varchar(20))
SELECT @query= @query + '' AND
pp.PersonId = p.PersonID
INNER JOIN
tblTalentAccess AS a ON p.PersonID=a.PersonID AND
t.TalentId=a.TalentId ''
IF(@condition<>'''')
BEGIN
SELECT @query= @query + @condition + '' order by t.DateModified desc ''
END
exec(@query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAccountSelectByUrl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 7-Sep, 2007
-- Description: Retrieve the AccountId if the url exists
-- =============================================
CREATE PROCEDURE [dbo].[UsptblAccountSelectByUrl]
-- Add the parameters for the stored procedure here
@url VARCHAR(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT AccountId,Deleted
FROM tblAccount
WHERE url=@url
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspViewCentralUsersLogOnHistory]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 17/Sep/2007
-- Description: To view the log history of central uesrs
-- =============================================
CREATE PROCEDURE [dbo].[UspViewCentralUsersLogOnHistory] --null,null,''17/Feb/2008'',''20/Feb/2008''
-- Add the parameters for the stored procedure here
@CentralProfileId INT,
@UserName VARCHAR(50),
@FromDate datetime,
@ToDate datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Declare @Query as VARCHAR(2000)
Declare @Condition as VARCHAR(1000)
IF @CentralProfileId <> ''''
BEGIN
Select @Condition = '' WHERE a.CentralProfileId = '' + Cast(@CentralProfileId as varchar(10))
END
IF @UserName <> ''''
IF @Condition<>''''
BEGIN
SELECT @Condition = @Condition + '' AND t.UserName like ''''%'' + @UserName + ''%'''' ''
END
ELSE
BEGIN
SELECT @Condition = '' WHERE t.UserName like ''''%'' + @UserName + ''%'''' ''
END
IF @FromDate<>'''' AND @ToDate<>''''
BEGIN
DECLARE @DateFrom datetime
DECLARE @DateTo datetime
SET @DateFrom=Convert(varchar,@FromDate,101)
SET @DateTo=Convert(varchar,@ToDate,101)
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ((datepart(day,logindatetime) between datepart(day,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(day,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(month,logindatetime) between datepart(month,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(month,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(year,logindatetime) between datepart(year,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(year,'''''' + convert(varchar,@DateTo,106) + '''''' )))''
END
ELSE
BEGIN
SELECT @Condition = '' WHERE ((datepart(day,logindatetime) between datepart(day,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(day,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(month,logindatetime) between datepart(month,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(month,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(year,logindatetime) between datepart(year,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(year,'''''' + convert(varchar,@DateTo,106) + '''''' )))''
END
END
ELSE IF @ToDate<>''''
BEGIN
SET @DateTo=Convert(varchar,@ToDate,101)
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND convert(varchar,logindatetime,106) <= '''''' + convert(varchar,@DateTo,106) +''''''''
END
ELSE
BEGIN
SELECT @Condition = '' WHERE convert(varchar,logindatetime,106) <='''''' + convert(varchar,@DateTo,106) +''''''''
END
END
SELECT @Query=''SELECT a.UserId,t.UserName,Email,CentralProfileName,
Convert(varchar(17),logindatetime,113) as logindate,
Convert(varchar,logindatetime,108) as logintime,
ISNULL(Convert(varchar(40),(Convert(varchar(17),logoutdatetime,113))),''''Not Available'''') as logoutdate,
Convert(varchar,logoutdatetime,108) as logouttime
FROM tblcentraladmin a
INNER JOIN
tblcentralprofile c
ON
a.centralprofileid=c.centralprofileid
INNER JOIN
tblcentrallog l
ON
a.userid=l.userid
INNER JOIN
(SELECT aa.UserId,FirstName+'''' ''''+LastName as UserName
FROM tblCentralAdmin aa
INNER JOIN tblCentralUserPersonalInfo C
ON aa.userid=C.UserId) t
ON
a.UserId=t.UserId''
IF @Condition<>''''
BEGIN
SELECT @Query=@Query+@Condition
END
SELECT @Query=@Query+ '' order by logindatetime desc''
--print (@Query)
exec(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralAdminSelectUserDetail]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13/Sep/2007
-- Description: Get All Details of the user
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralAdminSelectUserDetail] --166
-- Add the parameters for the stored procedure here
@UserId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(500)
SET @Query= ''SELECT Email,a.CentralProfileId,a.Deleted,FirstName,LastName,
Telephone,Mobile,Fax,PostalAddress,BusinessAddress,p.CountryId,pr.CentralProfileName,c.CountryName
FROM tblCentralAdmin a ,tblCentralUserPersonalInfo p
,tblcountry c,tblcentralprofile pr
WHERE p.countryid=c.Countryid
and a.UserID=p.UserId
and a.centralprofileid=pr.centralprofileid
and a.UserId = '' + CAST(@UserId AS VARCHAR(50))
--PRINT(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAgencyByContactId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 120907
-- Description: SELECT AGENCY DETAIL BY CONTACTID
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAgencyByContactId]
@ContactId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT [AgencyId]
,[ContactId]
,[AgencyName]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
,[Deleted]
,[DateModified]
,[ModifiedBy] FROM tblAgencyContact WHERE Contactid=@ContactId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblBatchSelectOld]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- AUTHOR : Harendra
CREATE PROCEDURE [dbo].[UspTblBatchSelectOld] --204,1,30
@BatchId int,
@AccountId int,
@AgencyId int,
@Description VARCHAR(100)
AS
/* SET NOCOUNT ON */
if (@BatchId = 0)
begin
IF (@AgencyID = 0)
BEGIN
SELECT DISTINCT
tblBatch.AgencyId, tblAgency.AgencyName, CONVERT(varchar, tblBatch.BillToDate, 106) AS BillToDate,
tblBatch.BatchId,tblBatch.Description, tblBatch.IncludeJobs,
tblBatch.IncludeAgencyFees, tblBatch.IncludeDisbursements,
case tblBatch.status
when 1 then ''Normal''
when 2 then ''Listed''
when 3 then ''Posted''
else ''Normal''
end as status
FROM tblBatch INNER JOIN
tblAgency ON tblBatch.AgencyId = tblAgency.AgencyId
inner Join tblBatchStatus on tblBatch.status=tblBatchStatus.BatchstatusId
where tblBatch.AccountId=@AccountId
AND tblBatch.Deleted = ''0''
END
ELSE
BEGIN
SELECT DISTINCT
tblBatch.AgencyId, tblAgency.AgencyName, CONVERT(varchar, tblBatch.BillToDate, 106) AS BillToDate,
tblBatch.BatchId,tblBatch.Description, tblBatch.IncludeJobs,
tblBatch.IncludeAgencyFees, tblBatch.IncludeDisbursements,
case tblBatch.status
when 1 then ''Normal''
when 2 then ''Listed''
when 3 then ''Posted''
else ''Normal''
end as status
FROM tblBatch INNER JOIN
tblAgency ON tblBatch.AgencyId = tblAgency.AgencyId
inner Join tblBatchStatus on tblBatch.status=tblBatchStatus.BatchstatusId
where tblBatch.AccountId=@AccountId AND tblBatch.AgencyId=@AgencyId
AND tblBatch.Deleted = ''0''
END
end
else
begin
IF (@AgencyID =0)
BEGIN
SELECT DISTINCT
tblBatch.AgencyId, tblAgency.AgencyName, CONVERT(varchar, tblBatch.BillToDate, 106) AS BillToDate,
tblBatch.BatchId,tblBatch.Description, tblBatch.IncludeJobs,
tblBatch.IncludeAgencyFees, tblBatch.IncludeDisbursements,
case tblBatch.status
when 1 then ''Normal''
when 2 then ''Listed''
when 3 then ''Posted''
else ''Normal''
end as status
FROM tblBatch INNER JOIN
tblAgency ON tblBatch.AgencyId = tblAgency.AgencyId
inner Join tblBatchStatus on tblBatch.status=tblBatchStatus.BatchstatusId
where tblBatch.AccountId=@AccountId
AND tblBatch.Deleted = ''0'' and tblBatch.BatchId=@BatchId
END
ELSE
BEGIN
SELECT DISTINCT
tblBatch.AgencyId, tblAgency.AgencyName, CONVERT(varchar, tblBatch.BillToDate, 106) AS BillToDate,
tblBatch.BatchId,tblBatch.Description, tblBatch.IncludeJobs,
tblBatch.IncludeAgencyFees, tblBatch.IncludeDisbursements,
case tblBatch.status
when 1 then ''Normal''
when 2 then ''Listed''
when 3 then ''Posted''
else ''Normal''
end as status
FROM tblBatch INNER JOIN
tblAgency ON tblBatch.AgencyId = tblAgency.AgencyId
inner Join tblBatchStatus on tblBatch.status=tblBatchStatus.BatchstatusId
where tblBatch.AccountId=@AccountId AND tblBatch.AgencyId=@AgencyId
AND tblBatch.Deleted = ''0'' and tblBatch.BatchId=@BatchId
END
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblBatchStatusSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 26/Nov/2007
-- Description: Select Batch Status
-- =============================================
CREATE PROCEDURE [dbo].[UspTblBatchStatusSelect]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT BatchStatusId,BatchStatus
FROM tblBatchStatus
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblJobIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 26/9/2005
-- Description: For Production Creation
-- =============================================
CREATE procedure [dbo].[UspTblJobIsDeletedUpdate]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@JobID int,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
SET @Result=0
BEGIN TRAN
UPDATE tblJob
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
JobID=@JobID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblJob'',''Delete'',''Job Deleted'',@Date,@ModifiedBy,@JobID,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblUpdatePayReq]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14 Nov 2007
-- Description: Update the request details for payment from talent
-- =============================================
CREATE PROCEDURE [dbo].[UspTblUpdatePayReq] --14,2,7,1222,1,114,null
-- Add the parameters for the stored procedure here
@JobId INT,
@JobPaymentId INT,
@PaymentTypeId INT,
@TalentAccountId INT,
@Value INT,
@ModifiedBy INT,
@AccountId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Check INT
BEGIN TRAN
SET @Check= (SELECT COUNT(*)
FROM tblJobPayment
WHERE JobId=@JobId
AND
AccountID=@AccountId
AND
TalentAccountId=@TalentAccountId
AND
JobPaymentId<>@JobPaymentId
AND
Deleted=''False'')
IF @Check = 0
BEGIN
UPDATE tblJobPayment SET PaymentTypeId=@PaymentTypeId,
TalentAccountId=@TalentAccountId,
Value=@Value,
ModifiedBy=@ModifiedBy,
DateModified=getdate()
WHERE JobPaymentId=@JobPaymentId
AND
AccountId=@AccountId
SET @Result = 1
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblJobPayment'',''Request Updated'',''Payment Request Updated'',@Date,@ModifiedBy,@JobPaymentId,@AccountId
END
ELSE
BEGIN
SET @Result = 2
END
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
SET @Result = 0
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspInvoiceStatus]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <26/11/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspInvoiceStatus]
-- Add the parameters for the stored procedure here
@InvoiceId varchar(10),
@AccountId int,
@status varchar(10),
@ModifiedBy int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Date DATETIME
SET @Date=getdate()
-- Insert statements for procedure here
IF @status=''Print''
BEGIN
Update tblInvoice set printed=''true'' where InvoiceId=@InvoiceId and AccountId=@AccountId
exec UsplTblMaintainanceInsert_new ''tblInvoice'',''Status Updated'',''Staus of Invoice has been updated as Print'',@Date,@ModifiedBy,@InvoiceId,@AccountId
END
IF @status=''Post''
BEGIN
Update tblInvoice set Posted=@Date where InvoiceId=@InvoiceId and AccountId=@AccountId
exec UsplTblMaintainanceInsert_new ''tblInvoice'',''Status Updated'',''Staus of Invoice has been updated as Post'',@Date,@ModifiedBy,@InvoiceId,@AccountId
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblRateTypeUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 5-sep-2007
--Modified date: 21/2/2008
-- Description: -- =============================================
CREATE PROCEDURE [dbo].[UspTblRateTypeUpdate]
-- Add the parameters for the stored procedure here
@RateTypeId int,
@AccountId INT,
@RateTypeName varchar(100),
@Administrator bit,
@CategoryId int,
@GeneralRateGL varchar(20),
@TrustRateGL varchar(20),
@SGCApplies bit,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkType int
SET @Result=0
SET @chkType = (SELECT COUNT(*) FROM tblRateType WHERE RateTypeId<>@RateTypeId AND RateTypeName=@RateTypeName AND AccountId=@AccountId AND Deleted=''false'')
IF @chkType > 0
BEGIN
SET @Result=2
END
Else
BEGIN
BEGIN TRAN
UPDATE tblRateType
SET
RateTypeName=@RateTypeName,
Administrator=@Administrator,
CategoryId=@CategoryId,
GeneralRateGL=@GeneralRateGL,
TrustRateGL=@TrustRateGL,
SGCApplies=@SGCApplies,
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
RateTypeId=@RateTypeId
AND AccountId=@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblRateType'',''Update'',''Rate Type Updated'',@Date, @ModifiedBy,@RateTypeId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblRateTypeIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: To Delete RateType Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblRateTypeIsDeletedUpdate]
(
@RateTypeID int,
@AccountId INT,
@DateModified datetime,
@ModifiedBy int,
@Deleted bit,
@Result INT OUTPUT
)
as
BEGIN
BEGIN TRAN
UPDATE tblRateType
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE RateTypeID=@RateTypeID
AND AccountId=@AccountId
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
--MAINTAINANCE ENTRY
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblRateType'',''Delete'',''Rate Type Deleted'',@Date, @ModifiedBy,@RateTypeId, @AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblRateTypeInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: Rate Type Insert
-- =============================================
CREATE PROCEDURE [dbo].[UspTblRateTypeInsert]
-- Add the parameters for the stored procedure here
--@RateTypeId int,
@RateTypeName varchar(100),
@AccountId int,
@Administrator bit,
@CategoryId int,
@GeneralRateGL varchar(20),
@TrustRateGL varchar(20),
@SGCApplies bit,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkType int
SET @Result=0
SET @chkType = (SELECT COUNT(*) FROM tblRateType WHERE RateTypeName=@RateTypeName AND AccountId=@AccountId AND Deleted=''false'')
IF @chkType > 0
BEGIN
SET @Result=2
END
Else
BEGIN
BEGIN TRAN
INSERT INTO tblRateType
(AccountId, RateTypeName, Administrator, CategoryId, GeneralRateGL,
TrustRateGL, SGCApplies, Deleted, DateModified, ModifiedBy)
VALUES(@AccountId, @RateTypeName, @Administrator, @CategoryId, @GeneralRateGL,
@TrustRateGL, @SGCApplies, @Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @RateTypeId INT
DECLARE @Date DATETIME
SET @Date=getdate()
SET @RateTypeId=(SELECT ISNULL(MAX(RateTypeId),0) FROM tblRateType)
exec UsplTblMaintainanceInsert_new ''tblRateType'',''Insert'',''New Rate Type Inserted'',@Date, @ModifiedBy,@RateTypeId, @AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblInsPayReq]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14 Nov 2007
-- Description: Insert the request for payment from talent
-- =============================================
CREATE PROCEDURE [dbo].[UspTblInsPayReq]
-- Add the parameters for the stored procedure here
@JobId INT,
@PaymentTypeId INT,
@TalentAccountId INT,
@Value INT,
@ModifiedBy INT,
@AccountId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Check INT
BEGIN TRAN
SET @Check= (SELECT COUNT(*)
FROM tblJobPayment
WHERE JobId=@JobId
AND
AccountID=@AccountId
AND
TalentAccountId=@TalentAccountId
AND
Deleted=''False'')
IF @Check = 0
BEGIN
INSERT INTO tblJobPayment(JobId,
PaymentTypeId,
TalentAccountId,
Value,
AccountId,
ModifiedBy)
VALUES(@JobId,
@PaymentTypeId,
@TalentAccountId,
@Value,
@AccountId,
@ModifiedBy)
SET @Result = 1
DECLARE @Date DATETIME
DECLARE @JobPaymentId INT
SET @Date=getdate()
SET @JobPaymentId = (SELECT ISNULL(MAX(JobPaymentId),0) FROM tblJobPayment)
exec UsplTblMaintainanceInsert_new ''tblJobPayment'',''Request'',''Payment Request sent by Talent'',@Date,@ModifiedBy,@JobPaymentId,@AccountId
END
ELSE
BEGIN
SET @Result = 2
END
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
SET @Result = 0
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionTypeUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18-02-2008
-- Description: Production Type update
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProductionTypeUpdate]
-- Add the parameters for the stored procedure here
@ProductionTypeId int,
@Name varchar(100),
@AccountId int,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkType int
SET @Result=0
SET @chkType = (SELECT COUNT(*) FROM tblProductionType WHERE [Name]=@Name AND ProductionTypeId<>@ProductionTypeId AND AccountId=@AccountId AND Deleted=''false'')
IF @chkType > 0
BEGIN
SET @Result=2
END
Else
BEGIN
BEGIN TRAN
UPDATE tblProductionType
SET
Name=@Name,
AccountId=@AccountId,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
ProductionTypeId=@ProductionTypeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblProductionType'',''Update'',''Production Type Updated'',@Date,@ModifiedBy,@ProductionTypeId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionTypeInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/02/2008
-- Description: ProductionType Insert
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProductionTypeInsert]
@Name varchar(100),
@AccountId int,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkType int
SET @Result=0
SET @chkType = (SELECT COUNT(*) FROM tblProductionType WHERE [Name]=@Name AND AccountId=@AccountId AND Deleted=''false'')
IF @chkType > 0
BEGIN
SET @Result=2
END
Else
BEGIN
BEGIN TRAN
INSERT INTO tblProductionType
(Name, AccountId, Deleted, DateModified, ModifiedBy)
VALUES(@Name, @AccountId, @Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @ProductionTypeId INT
DECLARE @Date DATETIME
SET @Date=getdate()
SET @ProductionTypeId=(SELECT ISNULL(MAX(ProductionTypeId),0) FROM tblProductionType)
exec UsplTblMaintainanceInsert_new ''tblProductionType'',''Insert'',''New Production Type Added'',@Date,@ModifiedBy,@ProductionTypeId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionTypeIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/02/2008
-- Description: To Delete Production Type Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProductionTypeIsDeletedUpdate]
(
@ProductionTypeID int,
@AccountId int,
@DateModified datetime,
@ModifiedBy int,
@Deleted bit,
@Result INT OUTPUT
)
as
BEGIN
BEGIN TRAN
UPDATE tblProductionType
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE ProductionTypeID=@ProductionTypeID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
--MAINTAINANCE ENTRY
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblProductionType'',''Deleted'',''Production Type has been deleted'',@Date, @ModifiedBy,@ProductionTypeID, @AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAgencyDeleted]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 170907
-- Description: To Delete Agency
-- =============================================
--ModifiedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblAgencyDeleted]
(
-- Add the parameters for the stored procedure here
@AgencyID int,
@AccountId INT,
@ModifiedBy INT
)
as
BEGIN
DECLARE @MaintenanceTable varchar(50)
DECLARE @Action varchar(100)
DECLARE @Detail varchar(1000)
UPDATE tblAgency SET Deleted=1 WHERE AgencyID=@AgencyID
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblAgency'',''Delete'',''Agency Deleted'',@Date,@ModifiedBy,@AgencyID,@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblLiabilityUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 26/9/2007
-- Description: For Liability Update
-- =============================================
CREATE procedure [dbo].[UspTblLiabilityUpdate]
(
-- Add the parameters for the stored procedure here
@LiabilityID int,
@AccountId int,
@ReceiptId int,
@AllocationId int,
@InvoiceId int,
@LineTypeId int,
@Amount float,
@AmountFX float,
@TaxPAYG float,
@TaxCode varchar(50),
@Posted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
SET @Result=0
BEGIN TRAN
UPDATE tblLiability
SET
ReceiptId=@ReceiptId,
AllocationId=@AllocationId,
InvoiceId=@InvoiceId,
LineTypeId=@LineTypeId,
Amount=@Amount,
AmountFX=@AmountFX,
TaxPAYG=@TaxPAYG,
TaxCode=@TaxCode,
Posted=@Posted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
LiabilityID=@LiabilityID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblLiability'',''Update'',''Liability Updated'',@Date,@ModifiedBy,@LiabilityID,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentUpdateByTalent]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2005
-- Description: To Delete Account Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTalentUpdateByTalent]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@TalentId int,
@TalentName varchar(100),
@Country int,
@ABN varchar(20),
@TFN varchar(20),
@PostalAddress varchar(1000),
@ResidentialAddress varchar(1000),
@Telephone varchar(50),
@Mobile varchar(50),
@TalentSubAccountGL varchar(20),
@SuperannuationRate float,
@DateModified datetime,
@ModifiedBy varchar(50)
)
as
BEGIN
BEGIN TRAN
UPDATE tblTalent
SET
TalentName=@TalentName,
Country=@Country,
ABN=@ABN,
TFN=@TFN,
PostalAddress=@PostalAddress,
ResidentialAddress=@ResidentialAddress,
Telephone=@Telephone,
Mobile=@Mobile,
TalentSubAccountGL=@TalentSubAccountGL,
SuperannuationRate=@SuperannuationRate,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
TalentId=@TalentId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
UPDATE tblPerson
SET
tblPerson.PersonName=@TalentName
WHERE
(SELECT COUNT(*) FROM tblMapPersonProfile WHERE tblMapPersonProfile.ProfileId=@ProfileId AND
tblMapPersonProfile.PersonId = tblPerson.PersonID)>0 AND
AccountID=@AccountID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblTalent'',''Update'',''Talent detail updated'',@Date,@ModifiedBy,@TalentId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblDeletePaymentRequest]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select all payment requests for the job by talent
-- =============================================
CREATE PROCEDURE [dbo].[UspTblDeletePaymentRequest] --null,null
-- Add the parameters for the stored procedure here
@JobPaymentId INT ,
@AccountId INT ,
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblJobPayment
SET Deleted=''True''
WHERE JobPaymentId=@JobPaymentId
AND
AccountId=@AccountId
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblJobPayment'',''Request Deleted'',''Request has been deleted'',@Date,@ModifiedBy,@JobPaymentId,@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAllocationUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <06/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAllocationUpdate]
-- Add the parameters for the stored procedure here
@AccountId int,
@AllocationId int,
@Amount float,
@RateFx float,
@AmountFx float,
@TaxPAYG float,
@ModifiedBy int,
@Result int output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblAllocation
SET [Amount]=@Amount,
[RateFX]=@RateFx,
[AmountFX]=@AmountFx,
[TaxPAYG]=@TaxPAYG,
[ModifiedBy]=@ModifiedBy,
[DateModified]=getdate()
WHERE AllocationId=@AllocationId and AccountId=@AccountId
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblallocation'',''Update'',''Allocation Updated'',@Date,@ModifiedBy,@AllocationId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentAccountDeleted]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 23/10/2007
-- Description: To Delete Talent Account
-- =============================================
-- ModifiedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblTalentAccountDeleted]
(
-- Add the parameters for the stored procedure here
@TalentAccountID int,
@AccountId INT,
@ModifiedBy INT,
@Result int output
)
as
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
set @Result=0
UPDATE tblTalentAccount SET Deleted=1 WHERE TalentAccountID=@TalentAccountID
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblTalentAccount'',''Delete'',''Talent Account Deleted'',@Date,@ModifiedBy,@TalentAccountID,@AccountId
if @@Error<> 0
set @Result=0
else
set @Result=1
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAgencyContactDeleted]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 170907
-- Description: To LOGICALLY DELETION OF AGENCY CONTACT
-- =============================================
--ModifiedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblAgencyContactDeleted]
(
-- Add the parameters for the stored procedure here
@ContactID int,
@AccountId INT,
@ModifiedBy INT,
@Result int output
)
as
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
set @Result=0
UPDATE tblAgencyContact SET Deleted=1 WHERE ContactID=@ContactID
DECLARE @Date Datetime
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblAgencyContact'',''Delete'',''Agency Contact Deleted'',@Date,@ModifiedBy,@ContactID,@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAllocationIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <06/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAllocationIsDeletedUpdate]
-- Add the parameters for the stored procedure here
@AccountId int,
@AllocationId int,
@ModifiedBy int,
@Result int output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE tblAllocation
SET [deleted]=''TRUE'',
[ModifiedBy]=@ModifiedBy,
[DateModified]=getdate()
WHERE AllocationId=@AllocationId and AccountId=@AccountId
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblallocation'',''Delete'',''allocation Deleted'',@Date,@ModifiedBy,@AllocationId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 26/9/2007
-- Description: For Production Deletion
-- =============================================
CREATE procedure [dbo].[UspTblProductionIsDeletedUpdate]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProductionID int,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
SET @Result=0
BEGIN TRAN
UPDATE tblProduction
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
ProductionID=@ProductionID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblProduction'',''Delete'',''Production Deleted'',@Date,@ModifiedBy,@ProductionID,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblShowExps]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 29 Jan 2008
-- Description: Returns all exceptions raised in database
-- =============================================
CREATE PROCEDURE [dbo].[UspTblShowExps]
-- Add the parameters for the stored procedure here
@Date DATETIME
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT CategoryName,Severity,Title,[TimeStamp],[Message]
FROM tblExceptionLog el
INNER JOIN tblExceptionCategoryLog ecl
INNER JOIN tblExceptionCategory ec
ON ecl.CategoryID=ec.CategoryID
ON el.LogID=ecl.LogID
WHERE Convert(VARCHAR,[TimeStamp],106) = CONVERT(VARCHAR,@Date,106)
ORDER BY [TimeStamp] DESC
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGstCodesUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 26/11/2007
-- Description: -- =============================================
CREATE PROCEDURE [dbo].[UspTblGstCodesUpdate]
-- Add the parameters for the stored procedure here
@GstCodeId int,
@TaxCodeId int,
@Date datetime,
@Rate float,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
declare @ChkName varchar(20)
set @ChkName = (select count(*) from tblGST where date=@Date and TaxCodeId=@TaxCodeId and deleted=''false'' and GstCodeId<> @GstCodeId )
if (@ChkName <> 0)
begin
set @result=0
end
else
begin
BEGIN
SET @Result=0
BEGIN TRAN
UPDATE tblGST
SET
TaxCodeId=@TaxCodeId,
Date=@Date,
Rate=@Rate,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
GstCodeId=@GstCodeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @Date1 DATETIME
SET @Date1=getdate()
exec UspTblCentralMaintenanceInsert ''tblGST'',''Update'',''GST Code Updated'',@Date1, @ModifiedBy,@GstCodeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGstCodesInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
-- Description: Rate Type Insert
-- =============================================
CREATE PROCEDURE [dbo].[UspTblGstCodesInsert]
-- Add the parameters for the stored procedure here
@TaxCodeId int,
@Date datetime,
@Rate float,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
declare @ChkName varchar(20)
BEGIN
SET @Result=0
set @ChkName = (select count(*) from tblGST where date=@Date and TaxCodeId=@TaxCodeId and deleted=''false'' )
if (@ChkName <> 0)
begin
set @result=0
end
else
begin
BEGIN TRAN
INSERT INTO tblGST
(TaxCodeId, Date, Rate, Deleted, DateModified, ModifiedBy)
VALUES(@TaxCodeId, @Date, @Rate, @Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @GstCodeId INT
DECLARE @Date1 DATETIME
SET @Date1=getdate()
SET @GstCodeId=(SELECT ISNULL(MAX(GstCodeId),0) FROM tblGST)
exec UspTblCentralMaintenanceInsert ''tblGST'',''Insert'',''New GST Code Inserted'',@Date1, @ModifiedBy,@GstCodeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
end
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCountryAudit]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Sep/2007
-- Description: Audit of country
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCountryAudit]
-- Add the parameters for the stored procedure here
@CountryId INT,
@CurrencyId INT,
@CountryName VARCHAR(50),
@LabelGST VARCHAR(20),
@ModifiedBy INT,
@HostIP VARCHAR(15),
@UserName VARCHAR(50),
@Action VARCHAR(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
BEGIN TRAN
DECLARE @Date DATETIME
SET @Date=getdate()
INSERT INTO tblCountryAudit(CountryId,CurrencyId,CountryName,LabelGST,ModifiedBy,HostIP,UserName,[Action],[DateTime])
VALUES(@CountryId,@CurrencyId,@CountryName,@LabelGST,@ModifiedBy,@HostIP,@UserName,@Action,@Date)
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCurrencyAudit]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 4/jan/2008
-- Description: Add new currency
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCurrencyAudit]
-- Add the parameters for the stored procedure here
@CurrencyID int,
@CurrencyName VARCHAR(3),
@Description VARCHAR(100),
@BaseCurrency TINYINT,
@FXRate float,
@ModifiedBy INT,
@HostIp varchar(15),
@USerName varchar(50),
@Action VARCHAR(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
BEGIN TRAN
DECLARE @Date DATETIME
SET @Date=getdate()
INSERT INTO [Talent].[dbo].[tblCurrencyAudit]
([CurrencyId]
,[CurrencyName]
,[Description]
,[BaseCurrency]
,[DateModified]
,[ModifiedBy]
,[FXRate]
,[HostIP]
,[UserName]
,[Action])
VALUES
(@CurrencyId
,@CurrencyName
,@Description
,@BaseCurrency
,@Date
,@ModifiedBy
,@FXRate
,@HostIP
,@UserName
,@Action)
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralMenuUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 1/Oct/2007
-- Description: Update the menus for the selected profile
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralMenuUpdate]
-- Add the parameters for the stored procedure here
@CentralProfileId INT,
@Navigations VARCHAR(1000),
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DELETE FROM tblCentralMenu WHERE CentralProfileId=@CentralProfileId
DECLARE @NavigationId INT
DECLARE @str VARCHAR(1000)
-- Insert statements for procedure here
WHILE @Navigations <> ''''
BEGIN
SET @NavigationId = CHARINDEX('','', @Navigations)
IF @NavigationId > 0
BEGIN
SET @str = CAST(LEFT(@Navigations, @NavigationId-1) AS INT)
SET @Navigations = RIGHT(@Navigations, LEN(@Navigations)-@NavigationId)
END
ELSE
BEGIN
SET @str = CAST(@Navigations AS INT)
SET @Navigations = ''''
END
INSERT INTO tblCentralMenu(CentralProfileId,CentralNavigationId,ModifiedBy)
VALUES(@CentralProfileId,CONVERT(VARCHAR(100),@str),@ModifiedBy)
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@CentralProfileId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCurrencyUpdateToBase]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Sep/2007
-- Description: Add new currency
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCurrencyUpdateToBase]
-- Add the parameters for the stored procedure here
@CurrencyId INT,
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRAN
UPDATE tblCurrency
SET BaseCurrency = ''True'',
DateModified = getdate(),
ModifiedBy = @ModifiedBy
WHERE
CurrencyId = @CurrencyId
UPDATE tblCurrency
SET BaseCurrency = ''False''
WHERE
CurrencyId <> @CurrencyId
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCurrency'',''Update'',''Currency hase been changed to base currency'',@Date, @ModifiedBy,@CurrencyId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblMenuUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 1/Oct/2007
-- Description: Update the menus for the selected profile
-- =============================================
CREATE PROCEDURE [dbo].[UspTblMenuUpdate]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@Navigations VARCHAR(1000),
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DELETE FROM tblMenu WHERE ProfileId=@ProfileId
DECLARE @NavigationId INT
DECLARE @str VARCHAR(1000)
-- Insert statements for procedure here
WHILE @Navigations <> ''''
BEGIN
SET @NavigationId = CHARINDEX('','', @Navigations)
IF @NavigationId > 0
BEGIN
SET @str = CAST(LEFT(@Navigations, @NavigationId-1) AS INT)
SET @Navigations = RIGHT(@Navigations, LEN(@Navigations)-@NavigationId)
END
ELSE
BEGIN
SET @str = CAST(@Navigations AS INT)
SET @Navigations = ''''
END
INSERT INTO tblMenu(ProfileId,NavigationId,ModifiedBy)
VALUES(@ProfileId,CONVERT(VARCHAR(100),@str),@ModifiedBy)
-- UPDATE tblMenu SET NavigationId=CONVERT(VARCHAR(100),@str)
-- WHERE ProfileId=@ProfileId
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Sep/2007
-- Description: Add new currency
--ModifiedBy - Harendra Singh
--Modified Date- 27/Oct/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileUpdate]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@ProfileName VARCHAR(50),
@InActive BIT,
@ModifiedBy INT,
@SubProfile BIT,
--@ParentProfileId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @ParentprofileIdExist int
SET @Result = (SELECT COUNT(*)
FROM tblProfile
WHERE ProfileName = @ProfileName
AND ProfileId <> @ProfileId)
--set @ParentprofileIdExist=(select isnull(ParentProfileId, -1) from tblprofile
-- where profileid=@ProfileId )
--
----IF PARENT PROFILE ID CHANGED IT WILL DELETE ALL PERMISSION
--IF (@ParentprofileIdExist <> @ParentProfileId)
--BEGIN
-- delete from tblmenu where ProfileId=@ProfileId
--END
IF(@Result=0)
BEGIN
BEGIN TRAN
if (@SubProfile=''True'')
BEGIN
UPDATE tblProfile
SET ProfileName = @ProfileName,--ParentProfileId=@ParentProfileId,
InActive = @InActive,
DateModified = getdate(),
ModifiedBy = @ModifiedBy
WHERE ProfileId = @ProfileId
END
ELSE
BEGIN
UPDATE tblProfile
SET ProfileName = @ProfileName,
InActive = @InActive,
DateModified = getdate(),
ModifiedBy = @ModifiedBy
WHERE ProfileId = @ProfileId
END
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblProfile'',''Update'',''Account profile details have been changed'',@Date, @ModifiedBy,@ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Sep/2007
-- Description: Add new currency
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileInsert]
-- Add the parameters for the stored procedure here
@ProfileName VARCHAR(50),
@ModifiedBy INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Result = (SELECT COUNT(*)
FROM tblProfile
WHERE ProfileName = @ProfileName)
IF(@Result=0)
BEGIN
BEGIN TRAN
INSERT INTO tblProfile(ProfileName,DateModified,ModifiedBy)
VALUES(@ProfileName,getdate(),@ModifiedBy)
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @ProfileId INT
DECLARE @Date DATETIME
SET @Date=getdate()
SET @ProfileId=(SELECT ISNULL(MAX(ProfileId),0) FROM tblProfile)
exec UspTblCentralMaintenanceInsert ''tblProfile'',''New Profile'',''New account profile has been created'',@Date, @ModifiedBy,@ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 27/Sep/2007
-- Description: Select selected profile detail on basis of profile id
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileDelete]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@ModifiedBy INT
As
--Declare @MaintenanceTable varchar(50)
--Declare @Action varchar(100)
--Declare @Detail varchar(1000)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
UPDATE tblProfile
SET Deleted=''True'',
ModifiedBy=@ModifiedBy
WHERE profileId=@ProfileId
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblProfile'',''Delete Profile'',''Account profile has been deleted'',@Date, @ModifiedBy,@ProfileId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGstCodesIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2005
-- Description: To Delete RateType Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblGstCodesIsDeletedUpdate]
(
@GstCodeID int,
@DateModified datetime,
@ModifiedBy int,
@Deleted bit,
@Result INT OUTPUT
)
as
BEGIN
BEGIN TRAN
UPDATE tblGST
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE GstCodeID=@GstCodeID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
--MAINTAINANCE ENTRY
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblGST'',''Delete'',''Gst Code Deleted'',@Date, @ModifiedBy,@GstCodeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTaxCodeDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 23/Nov/2007
-- Description: Select Tax Codes on basis of countryid
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTaxCodeDelete]
-- Add the parameters for the stored procedure here
@TaxCodeId INT,
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE tblTaxCode
SET Deleted=''True'',
ModifiedBy=@ModifiedBy
WHERE TaxCodeId=@TaxCodeId
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblTaxCode'',''Delete'',''Tax Code Deleted'',@Date, @ModifiedBy,@TaxCodeId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTaxCodeInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 23/Nov/2007
-- Description: Select Tax Codes on basis of countryid
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTaxCodeInsert]
-- Add the parameters for the stored procedure here
@CountryId INT,
@TaxCode VARCHAR(3),
@ModifiedBy INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SET @Result=(SELECT COUNT(TaxCode)
FROM tblTaxCode
WHERE CountryId=@CountryId
AND TaxCode LIKE @TaxCode
AND Deleted=''False'')
IF @Result = 0
BEGIN
INSERT INTO tblTaxCode(CountryId,TaxCode,ModifiedBy)
VALUES(@CountryId,@TaxCode,@ModifiedBy)
DECLARE @TaxCodeId INT
SET @TaxCodeId =(SELECT ISNULL(MAX(TaxCodeId),0) FROM tblTaxCode)
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblTaxCode'',''Insert'',''New Tax Code Inserted'',@Date, @ModifiedBy,@TaxCodeId
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralUsersDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13/Sep/2007
-- Description: To delete the central user
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralUsersDelete]
-- Add the parameters for the stored procedure here
@CentralAdminId INT,
@UserId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
BEGIN TRAN
UPDATE tblCentralAdmin
SET Deleted=''True''
WHERE UserId=@UserId
IF(@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralAdmin'',''Deleteion'',''User has been deleted'',@Date,@CentralAdminId,@UserId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileActiveInActive]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 17 Oct 2007
-- Description: Make Profile Active/InActive
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileActiveInActive]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@InActive BIT,
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblProfile
SET InActive = @InActive,
DateModified = getdate(),
ModifiedBy = @ModifiedBy
WHERE ProfileId=@ProfileId
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblProfile'',''Update'',''Account profile details have been changed'',@Date, @ModifiedBy,@ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSubProfileInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[UspTblSubProfileInsert]
-- Add the parameters for the stored procedure here
@ProfileName VARCHAR(50),
@ModifiedBy INT,
@ParentProfileId INT,
@Result INT OUTPUT
AS
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Result = (SELECT COUNT(*)
FROM tblProfile
WHERE ProfileName = @ProfileName)
IF(@Result=0)
BEGIN
BEGIN TRAN
INSERT INTO tblProfile(ProfileName,DateModified,ModifiedBy ,ParentProfileId)
VALUES(@ProfileName,getdate(),@ModifiedBy,@ParentProfileId)
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @ProfileId INT
DECLARE @Date DATETIME
SET @Date=getdate()
SET @ProfileId=(SELECT ISNULL(MAX(ProfileId),0) FROM tblProfile)
exec UspTblCentralMaintenanceInsert ''tblProfile'',''New Profile'',''New account sub profile has been created'',@Date, @ModifiedBy,@ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblProductionTypeSelectByID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/02/2008
-- Description: Details of ProductionType by Id
-- =============================================
CREATE procedure [dbo].[USPTblProductionTypeSelectByID]
(
@ProductionTypeId int,
@AccountId int
)
AS
SELECT * FROM tblProductionType
WHERE Deleted=''0'' AND ProductionTypeId=@ProductionTypeId AND AccountId=@AccountId
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblProductionTypeSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/02/2008
-- Description: For Production Type
-- =============================================
CREATE procedure [dbo].[USPTblProductionTypeSelect]
@Name varchar(100) = NULL,
@AccountId int
AS
IF(@Name<>'''')
BEGIN
EXEC(''SELECT * FROM tblProductionType
WHERE
Deleted=''''0'''' AND AccountId='''''' + @AccountId + '''''' AND Name like ''''%'' + @Name + ''%'''''')
END
ELSE
BEGIN
SELECT * FROM tblProductionType
WHERE Deleted=''0'' AND AccountId=@AccountId
Order by datemodified desc
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblProductionTypeFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 01/10/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblProductionTypeFillDdl]
-- Add the parameters for the stored procedure here
@AccountId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Select ProductionTypeID, Name
from tblProductionType AS pt
WHERE pt.Deleted = ''0'' AND AccountId=@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblRateTypeFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: FILL DDL Rate Type
-- =============================================
CREATE procedure [dbo].[USPTblRateTypeFillDdl]
@AccountId int
AS
SELECT RateTypeId, SUBSTRING(RateTypeName,1,50) as RateTypeName
-- ,CASE LEN(RateTypeName)
-- WHEN (LEN(RateTypeName)>30) THEN SUBSTRING(RateTypeName,1,30)
-- ELSE RateTypeName
-- END AS RateTypeName
FROM tblRateType
WHERE Deleted=''0'' AND AccountId=@AccountId
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblRateTypeSelectByRateTypeID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: FILL DDL Rate Type
-- =============================================
CREATE procedure [dbo].[USPTblRateTypeSelectByRateTypeID]
(
@RateTypeId int,
@AccountId INT
)
AS
SELECT * FROM tblRateType
WHERE Deleted=''0'' AND RateTypeId=@RateTypeId AND AccountId=@AccountId
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblExceptionCategoryLogInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[UspTblExceptionCategoryLogInsert]
@CategoryID INT,
@LogID INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @CatLogID INT
SELECT @CatLogID FROM tblExceptionCategoryLog WHERE CategoryID=@CategoryID and LogID = @LogID
IF @CatLogID IS NULL
BEGIN
INSERT INTO tblExceptionCategoryLog (CategoryID, LogID) VALUES(@CategoryID, @LogID)
RETURN @@IDENTITY
END
ELSE RETURN @CatLogID
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblExceptionClearLogs]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[UspTblExceptionClearLogs]
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM tblExceptionCategoryLog
DELETE FROM [tblExceptionLog]
DELETE FROM tblExceptionCategory
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblPaymentRequest]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select all payment requests for the job by talent
-- =============================================
CREATE PROCEDURE [dbo].[UspTblPaymentRequest] --2,1
-- Add the parameters for the stored procedure here
@JobId INT ,
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT jp.JobPaymentId, jp.PaymentTypeId,pt.PaymentType,jp.TalentAccountId,ta.AccountName+'': '' +ta.AccountNumber as TalentAccount,jp.Value
FROM tblJobPayment jp Inner join
tblPaymentType pt on
jp.PaymentTypeId=pt.PaymentTypeId
inner join tblTalentAccount ta on
jp.TalentAccountId=ta.TalentAccountId
WHERE jp.JobId=@JobId
AND
jp.AccountId=@AccountId
AND
jp.Deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSelectPayTypes]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select payment types
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSelectPayTypes] --1
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT PaymentTypeId,PaymentType
FROM tblPaymentType
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspCentralLogs]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 26/Sep/2007
-- Description: View the log history
-- =============================================
CREATE PROCEDURE [dbo].[UspCentralLogs] --''g'',''10/29/2007''
-- Add the parameters for the stored procedure here
@ModBy VARCHAR(50)= null,
@MDate DATETIME = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @TableName VARCHAR(50)
DECLARE @Action VARCHAR(20)
DECLARE @Detail VARCHAR(100)
DECLARE @Datemodified DATETIME
DECLARE @Date DATETIME
DECLARE @Time DATETIME
DECLARE @ModifiedByName VARCHAR(50)
DECLARE @ModifiedBy INT
DECLARE @ModifiedName VARCHAR(50)
DECLARE @ModifiedId INT
DECLARE @FirstName VARCHAR(50)
DECLARE @LastName VARCHAR(50)
DECLARE @TempTable TABLE
(
TableName VARCHAR(50),
Action VARCHAR(20),
DETAIL VARCHAR(100),
Date1 DATETIME,
Time DATETIME,
ModifiedByName VARCHAR(50),
ModifiedName VARCHAR(50)
)
DECLARE Curser CURSOR FOR
SELECT MaintenanceTable,Action,Detail,DateModified,ModifiedBy,ModifiedId FROM tblcentralmaintenance
OPEN Curser
FETCH Curser INTO @TableName,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId
WHILE @@Fetch_Status = 0
BEGIN
-- PRINT @TableName
-- PRINT @ModifiedId
SET @FirstName = (SELECT FirstName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedBy)
SET @LastName = (SELECT LastName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedBy)
SELECT @ModifiedByName = @FirstName + '' '' + @LastName
IF @TableName = ''tblCentralAdmin''
BEGIN
SET @FirstName = (SELECT FirstName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedId)
SET @LastName = (SELECT LastName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedId)
SELECT @ModifiedName = @FirstName + '' '' + @LastName
END
IF @TableName = ''TblCentralUserPersonalInfo''
BEGIN
SET @FirstName = (SELECT FirstName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedId)
SET @LastName = (SELECT LastName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedId)
SELECT @ModifiedName = @FirstName + '' '' + @LastName
END
IF @TableName = ''tblCountry''
BEGIN
SET @ModifiedName=(SELECT CountryName from tblCountry WHERE CountryId=@ModifiedId)
END
IF @TableName = ''tblProfile''
BEGIN
SET @ModifiedName=(SELECT ProfileName from tblProfile WHERE ProfileId=@ModifiedId)
END
IF @TableName = ''tblMenu''
BEGIN
SET @ModifiedName=(SELECT ProfileName from tblProfile WHERE ProfileId=@ModifiedId)
END
IF @TableName = ''tblCentralMenu''
BEGIN
SET @ModifiedName=(SELECT CentralProfileName from tblCentralProfile WHERE CentralProfileId=@ModifiedId)
END
IF @TableName = ''tblCurrency''
BEGIN
SET @ModifiedName=(SELECT CurrencyName from tblCurrency WHERE CurrencyId=@ModifiedId)
END
IF @TableName = ''tblCentralMenu''
BEGIN
SET @ModifiedName=(SELECT CentralProfileName from tblCentralProfile WHERE CentralProfileId=@ModifiedId)
END
IF @TableName = ''tblRateType''
BEGIN
SET @ModifiedName=(SELECT RateTypeName from tblRateType WHERE RateTypeId=@ModifiedId)
END
IF @TableName = ''tblCategory''
BEGIN
SET @ModifiedName=(SELECT CategoryName from tblCategory WHERE CategoryId=@ModifiedId)
END
IF @TableName = ''tblTaxCode''
BEGIN
SET @ModifiedName=(SELECT TaxCode from tblTaxCode WHERE TaxCodeId=@ModifiedId)
END
IF @TableName = ''tblGST''
BEGIN
SET @ModifiedName=(SELECT Rate from tblGST WHERE GstCodeId=@ModifiedId)
END
IF @TableName = ''tblAttribute''
BEGIN
SET @ModifiedName=(SELECT AttributeName from tblAttribute WHERE AttributeId=@ModifiedId)
END
IF @TableName = ''tblAttributeType''
BEGIN
SET @ModifiedName=(SELECT AttributeType from tblAttributeType WHERE AttributeTypeId=@ModifiedId)
END
IF @TableName = ''tblDocument''
BEGIN
SET @ModifiedName=(SELECT DocumentDescription from tblDocument WHERE DocumentId=@ModifiedId)
END
IF @TableName = ''tblAccount''
BEGIN
SET @ModifiedName=(SELECT Name from tblAccount WHERE AccountId=@ModifiedId)
END
SET @Date = @DateModified
SET @Time = @DateModified
INSERT INTO @TempTable(TableName,Action,Detail,Date1,Time,ModifiedByName,ModifiedName)
VALUES(@TableName,@Action,@Detail,@Date,@Time,@ModifiedByName,@ModifiedName)
FETCH Curser INTO @TableName,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId
END
IF(@MDate<>'''')
BEGIN
IF(@ModBy<>'''')
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedName
FROM @TempTable WHERE ModifiedByName like ''%'' + @ModBy + ''%''
AND convert(varchar,Date1,106) = convert(varchar,@MDate,106)
order by Date1 desc
END
ELSE
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedName
FROM @TempTable WHERE convert(varchar,Date1,106) = convert(varchar,@MDate,106)
order by Date1 desc
END
END
ELSE
IF(@ModBy<>'''')
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedName
FROM @TempTable WHERE ModifiedByName like ''%'' + @ModBy + ''%''
order by Date1 desc
END
ELSE
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedName
FROM @TempTable order by Date1 desc
END
CLOSE Curser
DEALLOCATE Curser
RETURN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigation]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* --Author: Harendra Singh
--Purpose: To Dispaly form listing & permission
--Created date: 17/10/2007
*/
CREATE PROCEDURE [dbo].[UspTblNavigation]
@ProfileId INT
AS
declare @chkparent int
declare @ParentProfileId int
set @chkparent=(select count(*) from tblprofile where ProfileId= @ProfileId and ParentProfileId is not null)
if (@chkparent <> 0 )
begin
set @ParentProfileId =(select ParentProfileId from tblprofile where ProfileId= @ProfileId)
SELECT DISTINCT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') AND (A.ProfileId = @ProfileId)
UNION
SELECT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') AND (A.ProfileId = @ParentProfileId) AND (A.NavigationId NOT IN
(SELECT NavigationId
FROM tblMenu
WHERE (ProfileId = @ProfileId) AND (Deleted = ''false'')))
end
else
begin
SELECT DISTINCT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select],
ISNULL(A.[insert], ''false'') AS [insert], ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') AND (A.ProfileId = @ProfileId)
UNION
SELECT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A CROSS JOIN
tblMenu AS B
WHERE (A.Deleted = ''False'') AND (A.NavigationId NOT IN
(SELECT NavigationId
FROM tblMenu
WHERE (ProfileId = @ProfileId) AND (Deleted = ''false'')))
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationSelectByProfile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
--Modified By:Harendra Singh
--Modified Date: 19/12/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspTblNavigationSelectByProfile]
-- Add the parameters for the stored procedure here
@ProfileId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
-- select n.navigationid, m.Profileid,name,parent, NavigationUrl
-- from tblnavigation as n
-- inner join tblMenu as m on
-- m.Deleted=''false'' and n.navigationid=m.navigationid
-- where n.IsInMenu=''True'' and n.deleted=''False''
select navigationid,name,parent, NavigationUrl
from tblnavigation
where navigationid in (select navigationid from tblmenu where profileid=@ProfileId)
AND
IsInMenu=''True'' and deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationSelectByProfile1]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
--Modified By:Harendra Singh
--Modified Date: 19/12/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspTblNavigationSelectByProfile1]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select n.navigationid, m.Profileid,name,parent, NavigationUrl
from tblnavigation as n
inner join tblMenu as m on
m.Deleted=''false'' and n.navigationid=m.navigationid
where n.IsInMenu=''True'' and n.deleted=''False''
-- select navigationid,name,parent, NavigationUrl
-- from tblnavigation
-- where navigationid in (select navigationid from tblmenu where profileid=@ProfileId)
-- AND
-- IsInMenu=''True'' and deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationNEW]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* --Author: Harendra Singh
--Purpose: To Dispaly form listing & permission
--Created date: 17/10/2007
*/
CREATE PROCEDURE [dbo].[UspTblNavigationNEW] --1 ,6
@ProfileId INT,
@ParentId int
AS
declare @chkparent int
declare @ParentProfileId int
Declare @Count int
set @Count =(select count (*) from tblmenu where profileId=@ProfileId)
IF @Count <>0
BEGIN
select AF.* from
((( SELECT DISTINCT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select],
ISNULL(A.[insert], ''false'') AS [insert], ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') and B.Parent=@ParentId AND (A.ProfileId = @ProfileId)
UNION
SELECT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A Cross JOIN
tblMenu AS B
WHERE (A.Deleted = ''False'') and A.Parent=@ParentId AND (A.NavigationId NOT IN
(SELECT NavigationId
FROM tblMenu
WHERE (ProfileId = @ProfileId) AND (Deleted = ''false'')))
Union
( SELECT DISTINCT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select],
ISNULL(A.[insert], ''false'') AS [insert], ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') AND (A.ProfileId = @ProfileId)
and B.Parent in (select parent from tblNavigation
where Parent in (select navigationId from tblNavigation where parent=@ParentId))
UNION
SELECT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A
where parent in(
select parent from tblNavigation
where Parent in (select navigationId from tblNavigation where parent=@ParentId))
AND (NavigationId NOT IN
(SELECT NavigationId
FROM tblMenu
WHERE (ProfileId = @ProfileId) AND (Deleted = ''false''))) and deleted=''0'')))) AF ,
tblNavigation CN where AF.NavigationId = CN.NavigationId and CN.NavigationURL is not null
END
ELSE
BEGIN
SELECT AF.* from
( SELECT DISTINCT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A
WHERE (A.Deleted = ''False'') and A.Parent=@ParentId
Union
SELECT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A
where parent in(select parent from tblNavigation where Parent in (select navigationId from tblNavigation where parent=@ParentId)))
AF ,
tblNavigation CN where AF.NavigationId = CN.NavigationId and CN.NavigationURL is not null
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblUpdateCentralMenu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* --Author: Harendra Singh
--Purpose: To upadte/add central Navigation & permission
--Created date: 19/12/2007
*/
CREATE PROCEDURE [dbo].[UspTblUpdateCentralMenu] --3 , 6, ''true'',''true'',''true'',''true'' ,1
-- Add the parameters for the stored procedure here
@ProfileId INT,
@NavigationId int,
@select bit,
@insert bit,
@update bit,
@delete bit,
@ModifiedBy INT
AS
declare @IsExist int
declare @date datetime
Declare @ParentId int
declare @rootParent int
Declare @count int
declare @checkRoot int
declare @DelParent int
Declare @DelrootParent int
Declare @countDel int
declare @CountrootDel int
declare @checkRootParent int
declare @AccessPath as varchar(50)
Declare @@AccessAnavigationId int
Declare @@STRAccess as varchar(2)
Declare @CountAccess as int
set @date=getdate()
--Deleting existing Permission and then set new one.
--if (@select=''false'')
--begin
delete from tblcentralMenu where centralprofileId=@ProfileId and centralNavigationId=@NavigationId
--end
-- set @DelParent=(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@NavigationId )
--SET @DelrootParent =(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@DelParent )
-- set @countDel=(select count(*) from tblcentralmenu where
-- centralNavigationId in (select centralnavigationId from tblCentralNavigation
-- where Parent=@DelParent) and centralProfileId=@ProfileId)
--
-- Set @CountrootDel=(select count(*) from tblCentralNavigation where parent=@DelParent and formname is null)
--
-- Set @CountrootDel=(select count(*) from tblcentralmenu where
-- centralNavigationId in (select centralnavigationId from tblCentralNavigation
-- where Parent=@DelrootParent) and centralProfileId=@ProfileId)
-- IF (@countDel=0 and @CountrootDel=0)
-- BEGIN
-- DELETE FROM tblcentralmenu where centralnavigationId=@DelParent and centralProfileId=@ProfileId
-- END
-- ELSE
-- BEGIN
-- --SET @DelrootParent =(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@DelParent )
-- Set @CountrootDel=(select count(*) from tblcentralmenu where
-- centralNavigationId in (select centralnavigationId from tblCentralNavigation
-- where Parent=@DelrootParent) and centralProfileId=@ProfileId)
-- IF @CountrootDel=0
-- BEGIN
-- DELETE FROM tblcentralmenu where centralnavigationId=@DelParent and centralProfileId=@ProfileId
-- DELETE FROM tblcentralmenu where centralnavigationId=@DelrootParent and centralProfileId=@ProfileId
-- END
--
-- END
set @IsExist= (select count(*)from tblcentralmenu where centralProfileId=@ProfileId and centralNavigationId=@NavigationId)
if (@IsExist <> 0)
begin
update tblmenu set [select]=@select , [insert]=@insert , [update]=@update , [delete]=@delete,
DateModified=@date , ModifiedBy=@ModifiedBy
where ProfileId=@ProfileId and NavigationId=@NavigationId
--exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
end
else
begin
if(@select =''1'')
begin
Set @count =(select count(*) from tblcentralmenu where
centralNavigationId in (select Parent from tblCentralNavigation
where CentralNavigationId=@NavigationId) and centralProfileId=@ProfileId)
If (@count=0)
Begin
Set @ParentId=(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@NavigationId )
set @rootParent=(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@ParentId)
if @ParentId<>0
begin
if @rootParent<>0
begin
set @checkRootParent=(select count(*) from tblcentralmenu where
centralNavigationId in (select Parent from tblCentralNavigation
where CentralNavigationId=@rootParent) and centralProfileId=@ProfileId)
if (@checkRootParent=0)
begin
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@rootParent,@select,@insert,@update,@delete,@date,@ModifiedBy)
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@ParentId,@select,@insert,@update,@delete,@date,@ModifiedBy)
end
end
set @checkRoot=(select count(*) from tblcentralmenu where
centralNavigationId in (select Parent from tblCentralNavigation
where CentralNavigationId=@rootParent) and centralProfileId=@ProfileId)
IF @checkRoot=0
BEGIN
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@ParentId,@select,@insert,@update,@delete,@date,@ModifiedBy)
END
END
End
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@NavigationId,@select,@insert,@update,@delete,@date,@ModifiedBy)
set @AccessPath=(select isnull(AccessPath,'''') from tblcentralnavigation where centralnavigationId=@NavigationId)
IF @AccessPath<>''''
BEGIN
WHILE @AccessPath <>''''
BEGIN
SET @@AccessAnavigationId = CHARINDEX('','', @AccessPath)
IF @@AccessAnavigationId >0
BEGIN
SET @@STRAccess = CAST(LEFT(@AccessPath, @@AccessAnavigationId-1) AS Int)
SET @AccessPath = RIGHT(@AccessPath, LEN(@AccessPath)-@@AccessAnavigationId)
END
ELSE
BEGIN
SET @@STRAccess = CAST(@AccessPath AS int)
SET @AccessPath = ''''
END
SET @CountAccess =(select Count(*) from tblcentralmenu where centralnavigationid=@@STRAccess AND centralProfileID=@ProfileId)
IF @CountAccess=0
BEGIN
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@@STRAccess,0,0,0,0,@date,@ModifiedBy)
END
END
END
--exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
end
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblUpdateMenu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* --Author: Harendra Singh
--Purpose: To upadte/add Navigation & permission
--Created date: 16/10/2007
*/
CREATE PROCEDURE [dbo].[UspTblUpdateMenu]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@NavigationId int,
@select bit,
@insert bit,
@update bit,
@delete bit,
@ModifiedBy INT
AS
declare @IsExist int
declare @date datetime
Declare @ParentId int
declare @rootParent int
Declare @count int
declare @checkRoot int
declare @AccessPath as varchar(50)
Declare @@AccessAnavigationId int
Declare @@STRAccess as varchar(2)
Declare @CountAccess as int
set @date=getdate()
--Deleting existing Permission and then set new one.
--if (@select=''false'')
-- begin
delete from tblMenu where profileId=@ProfileId and NavigationId=@NavigationId
set @IsExist= (select count(*)from tblmenu where ProfileId=@ProfileId and NavigationId=@NavigationId)
if (@IsExist <> 0)
begin
update tblmenu set [select]=@select , [insert]=@insert , [update]=@update , [delete]=@delete,
DateModified=@date , ModifiedBy=@ModifiedBy
where ProfileId=@ProfileId and NavigationId=@NavigationId
--exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
end
else
begin
if(@select =''1'')
begin
Set @count =(select count(*) from tblmenu where
NavigationId in (select Parent from tblNavigation where navigationId=@NavigationId) and ProfileId=@ProfileId)
If (@count=0)
Begin
Set @ParentId=(select isnull(Parent,0) from tblNavigation where navigationId=@NavigationId)
set @rootParent=(select isnull(Parent,0) from tblNavigation where navigationId=@ParentId)
if @ParentId<>0
begin
if @rootParent<>0
begin
set @checkRoot=(select count(*) from tblmenu where
NavigationId in (select Parent from tblNavigation
where NavigationId=@ParentId) and ProfileId=@ProfileId)
if (@checkRoot=0)
begin
insert into tblMenu(ProfileId , NavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@rootParent,@select,@insert,@update,@delete,@date,@ModifiedBy)
end
end
insert into tblMenu(ProfileId , NavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@ParentId,@select,@insert,@update,@delete,@date,@ModifiedBy)
end
End
insert into tblMenu(ProfileId , NavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@NavigationId,@select,@insert,@update,@delete,@date,@ModifiedBy)
set @AccessPath=(select isnull(AccessPath,'''') from tblnavigation where navigationId=@NavigationId)
IF @AccessPath<>''''
BEGIN
WHILE @AccessPath <>''''
BEGIN
SET @@AccessAnavigationId = CHARINDEX('','', @AccessPath)
IF @@AccessAnavigationId >0
BEGIN
SET @@STRAccess = CAST(LEFT(@AccessPath, @@AccessAnavigationId-1) AS Int)
SET @AccessPath = RIGHT(@AccessPath, LEN(@AccessPath)-@@AccessAnavigationId)
END
ELSE
BEGIN
SET @@STRAccess = CAST(@AccessPath AS int)
SET @AccessPath = ''''
END
SET @CountAccess =(select Count(*) from tblmenu where navigationid=@@STRAccess AND ProfileID=@ProfileId)
IF @CountAccess=0
BEGIN
Insert into tblMenu(ProfileId , NavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@@STRAccess,0,0,0,0,@date,@ModifiedBy)
END
END
END
--exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
end
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfilePermission]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[UspTblProfilePermission] --1,''ManageAgency.aspx''
@ProfileId int,
@FormName varchar(100)
AS
/* SET NOCOUNT ON */
Declare @@NavigationId as int
set @@NavigationId = (select distinct isnull(NavigationId,0) from tblNavigation
Where FormName=@FormName)
print @@NavigationId
if @@NavigationId <>0
Begin
select [select], [insert], [update],[delete] from tblmenu
where ProfileId=@ProfileId and NavigationId=@@NavigationId
End
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTbldeletetmsProfilePermission]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Harendra Singh
-- Create date: 21/2/08
-- Description: delete all permission before assign new permission
-- =============================================
CREATE PROCEDURE [dbo].[UspTbldeletetmsProfilePermission] --1,0
-- Add the parameters for the stored procedure here
@ProfileId int,
@Result int output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @@NavigationId int
declare @@parent int
declare @@rootparent int
declare @@Count int
declare @@count2 int
Declare @@Countroot int
DECLARE @@NavigationIdlevel2 INT
-- Insert statements for procedure here
--BEGIN TRAN
DECLARE Cursor_Parent CURSOR FOR
select navigationId from tblnavigation
where formname is null order by parent desc
OPEN Cursor_Parent
FETCH Cursor_Parent
INTO @@NavigationId
WHILE @@Fetch_Status = 0
BEGIN
SET @@Count=(SELECT count(distinct M.NavigationId)
FROM dbo.tblMenu M
INNER JOIN
dbo.tblNavigation N
ON M.NavigationId = N.NavigationId where N.Parent=@@NavigationId and M.profileId=@ProfileId)
IF @@Count>0
BEGIN
DECLARE Cursor_Parent_level3 CURSOR FOR
SELECT M.NavigationId
FROM dbo.tblMenu M
INNER JOIN
dbo.tblNavigation N
ON M.NavigationId = N.NavigationId where N.Parent=@@NavigationId and profileId=@ProfileId and N.Formname is null
OPEN Cursor_Parent_level3
FETCH Cursor_Parent_level3
INTO @@NavigationIdlevel2
WHILE @@Fetch_Status = 0
BEGIN
SET @@Count=(SELECT count(distinct M.NavigationId)
FROM dbo.tblMenu M
INNER JOIN
dbo.tblNavigation N
ON M.NavigationId = N.NavigationId where N.Parent=@@NavigationIdlevel2 and profileId=@ProfileId)
IF @@Count=0
BEGIN
delete from tblmenu where navigationId =@@NavigationIdlevel2 and profileId=@ProfileId
END
FETCH NEXT FROM Cursor_Parent_level3 INTO @@NavigationIdlevel2
END
CLOSE Cursor_Parent_level3
DEALLOCATE Cursor_Parent_level3
set @@Countroot=(SELECT count( M.NavigationId)
FROM dbo.tblMenu M
INNER JOIN
dbo.tblNavigation N
ON M.NavigationId = N.NavigationId where N.Parent=@@NavigationId and profileId=@ProfileId)
IF @@Countroot=0
BEGIN
delete from tblmenu where navigationId =@@NavigationId and profileId=@ProfileId
END
END
ELSE
BEGIN
--print ''level1''
--print (@@centralNavigationId)
delete from tblmenu where navigationId =@@NavigationId
and profileId=@ProfileId
END
FETCH NEXT FROM Cursor_Parent INTO @@NavigationId
END
CLOSE Cursor_Parent
DEALLOCATE Cursor_Parent
--IF @@ERROR <> 0
-- BEGIN
-- ROLLBACK TRAN
-- SET @Result=0
-- END
-- ELSE
-- BEGIN
-- COMMIT TRAN
-- SET @Result=1
-- END
END
--delete from tblcentralmenu where centralprofileid=@CentralProfileId
--
-- if @@ERROR <> 0
-- BEGIN
-- ROLLBACK TRAN
-- SET @Result=0
-- END
-- ELSE
-- BEGIN
-- COMMIT TRAN
-- SET @Result=1
-- END
--END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileSelectAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 27/Sep/2007
-- Description: Select All profiles for central admin
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileSelectAll]
-- Add the parameters for the stored procedure here
@ddl INT = 0
As
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF @ddl=0
BEGIN
SELECT p.ProfileId ,p.ProfileName,
Convert(VARCHAR,p.DateModified,106) as DateModified,
Status=CASE p.deleted When ''False'' then ''Active''
Else
''InActive''
END,
c.UserName as ModifiedBy
FROM tblProfile p
inner join
(Select ca.userid,FirstName+'' ''+LastName as UserName
From tblCentralAdmin ca
inner join tblCentralUserPersonalInfo ci
on
ca.userid=ci.userid )c
on p.ModifiedBy = c.UserId
where p.deleted=''false''
END
ELSE
BEGIN
SELECT p.ProfileId ,p.ProfileName
FROM tblProfile p
where p.deleted=''false''
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAdminRecoverPass]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 4/9/2007
-- Description: To recover the password for central admin user
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAdminRecoverPass]
-- Add the parameters for the stored procedure here
@UserName VARCHAR(50),
@EmailId VARCHAR(100) OUTPUT,
@Password Varchar(100),
@UserId INT OUTPUT,
@Name VARCHAR(100) OUTPUT,
@Profile VARCHAR(100) OUTPUT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
DECLARE @CH INT
SET @CH=(SELECT COUNT(*)
FROM tblCentralAdmin
WHERE UserName=@UserName
AND
Deleted=''False'')
IF(@CH=1)
BEGIN
BEGIN TRAN
UPDATE tblCentralAdmin SET Password=@Password,
PasswordCreationDate=getdate(),
PassReset=''True''
WHERE UserName=@UserName
And
Deleted=''False''
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @EmailId=(SELECT Email
FROM tblCentralAdmin
WHERE UserName=@UserName
AND
Deleted=''False''
)
SET @UserId=(SELECT UserId
FROM tblCentralAdmin
WHERE UserName=@UserName
AND
Deleted=''False''
)
SELECT @Name = FirstName + '' '' + LastName
FROM TblCentralUserPersonalInfo
WHERE CentralUserId=@UserId
SET @Profile=(SELECT cp.CentralProfileName
FROM tblCentralProfile cp
INNER JOIN tblCentralAdmin ca
ON ca.CentralProfileId = cp.CentralProfileId
WHERE ca.UserId=@UserId)
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert''tblCentralAdmin'',''Reset password'',''Password has been reset by the user'',@Date,@UserId,@UserId
SET @Result=1
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
ELSE
BEGIN
SET @Result=0
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralUsersNew]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 10-Sep, 2007
-- Description: Create new central Administrator users
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralUsersNew]-- ''hhh'',''hh'',''hh'',33,33,33,''afd'',1,122,''df'',''dsf'',124,null
-- Add the parameters for the stored procedure here
@UserName VARCHAR(50),
@FirstName varchar(50),
@LastName varchar(50),
@Telephone varchar(20),
@Mobile varchar(20),
@Fax varchar(20),
@PostalAddress varchar(1000),
@BusinessAddress varchar(1000),
@CountryId int,
@UserId INT,
@Password VARCHAR(100),
@Email VARCHAR(100),
@CentralProfileId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SET @Result=(SELECT COUNT(*)
FROM tblCentralAdmin
where UserName=@UserName)
IF(@Result=0)
BEGIN
BEGIN TRAN
INSERT INTO tblCentralAdmin(UserName,Password,Email,PasswordCreationDate,CentralProfileId,ModifiedBy,PassReset)
VALUES(@UserName,@Password,@Email,getdate(),@CentralProfileId,@UserId,''True'')
DECLARE @NewUserId INT
SET @NewUserId = (SELECT ISNULL(MAX(UserId),0) FROM tblCentralAdmin)
PRINT(@NewUserId)
Insert into tblCentralUserPersonalInfo(UserId,FirstName,LastName,Telephone,Mobile,CountryId,Fax,PostalAddress,BusinessAddress,ModifiedBy) values
(@NewUserId,@FirstName,@LastName,@Telephone,@Mobile,@CountryId,@Fax,@PostalAddress,@BusinessAddress,@UserId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralAdmin'',''Insertion'',''New Central user has been created'',@Date,@UserId,@NewUserId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralUsersUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14/Sep/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralUsersUpdate]
-- Add the parameters for the stored procedure here
@UserId INT,
@Email VARCHAR(100),
@FirstName VARCHAR(50),
@LastName VARCHAR(50),
@Telephone VARCHAR(20),
@Mobile VARCHAR(20),
@Fax VARCHAR(20),
@PostalAddress VARCHAR(1000),
@BusinessAddress VARCHAR(1000),
@CountryId INT,
@CentralProfileId INT,
@CentralAdminId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Result=(SELECT COUNT(*)
FROM tblCentralAdmin
WHERE UserName=@Email
AND
UserId<>@UserId )
IF(@Result=0)
BEGIN
BEGIN TRAN
DECLARE @No AS INT
SET @No = (SELECT count(*) FROM tblCentralUserPersonalInfo WHERE UserId=@UserId)
IF @No <> ''''
BEGIN
UPDATE tblCentralUserPersonalInfo
SET FirstName=@FirstName,
LastName=@LastName,
Telephone=@Telephone,
Mobile=@Mobile,
Fax=@Fax,
PostalAddress=@PostalAddress,
BusinessAddress=@BusinessAddress,
CountryId=@CountryId,
DateModified=getdate(),
ModifiedBy=@CentralAdminId
WHERE UserId=@UserId
END
ELSE
BEGIN
INSERT INTO tblCentralUserPersonalInfo
(UserId,FirstName,LastName,Telephone,
Mobile,Fax,PostalAddress,BusinessAddress,CountryId,
DateModified,ModifiedBy,Deleted)
VALUES(@UserId,@FirstName,@LastName,@Telephone,
@Mobile,@Fax,@PostalAddress,@BusinessAddress,@CountryId,
getDate(),@CentralAdminId,''False'')
END
UPDATE tblCentralAdmin
SET Email=@Email,
CentralProfileId=@CentralProfileId,
DateModified=getdate(),
ModifiedBy=@CentralAdminId
WHERE UserId=@UserId
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralUserPersonalInfo'',''Updation'',''User detail has been updated'',@Date,@CentralAdminId,@UserId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[uspPhysicalDeletion]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 301207
-- Description: PHYSICAL DELETE ALL THE DELETED RECORD PLACED IN TABLE
-- AFTER A FIX PERIOD OF TIME
-- =============================================
CREATE procedure [dbo].[uspPhysicalDeletion]
AS
BEGIN
DECLARE @AutoDeletemonth as int
Set @AutoDeletemonth=(Select autodeletemonths from tblsite WHERE [Default]=1 and Deleted=0)
DELETE FROM TblCentralUserPersonalInfo WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAccountuserPersonalInfo WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCentralAdmin WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblProduction WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCompany WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalent WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgency WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAllocation WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblBatchLine WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblInvoiceItem WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblJobPayment WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblLiability WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblBatchProduction WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAttribute WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblPaymentItem WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblJob WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyFee WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblGLAccount WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblInvoice WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblGLCategory WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblDisbursement WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblBatch WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCompanyAcess WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCompanyContact WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblPayment WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblLineType WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblSuperFund WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyTalent WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyRegisterGST WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentAccess WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblPerson WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblProductionType WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblSelection WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentAccount WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCentralProfile WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentAttribute WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyContact WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblReceipt WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyAccount WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblInvoiceFrequency WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAdvance WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyAccess WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentRegisterGST WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentContact WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAdminChangePass]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 6/9/2007
-- Description: Change the current password to new password
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAdminChangePass]
-- Add the parameters for the stored procedure here
@OldPassword VARCHAR(100),
@NewPassword VARCHAR(100),
@UserId INT,
@Name VARCHAR(100) OUTPUT,
@Profile VARCHAR(50) OUTPUT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Pass VARCHAR(100)
SELECT @Pass=Password
FROM tblCentralAdmin
WHERE UserId=@UserId
AND
Deleted=''False''
IF(@OldPassword=@Pass)
BEGIN
BEGIN TRAN
UPDATE tblCentralAdmin
SET Password=@NewPassword,
PassReset=''False''
WHERE UserId=@UserId
And
Deleted=''False''
SELECT @Name=FirstName + '' '' + LastName
FROM TblCentralUserPersonalInfo
WHERE CentralUserId=@UserId
SET @Profile=(SELECT cp.CentralProfileName
FROM tblCentralProfile cp
INNER JOIN tblCentralAdmin ca
ON ca.CentralProfileId = cp.CentralProfileId
WHERE ca.UserId=@UserId)
IF(@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralAdmin'',''Password changed'',''Old password has been changed with new one'',@Date, @UserId,@UserId
IF(@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
SET @Result=1
END
ELSE
BEGIN
SET @Result=0
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblAccountSelectByAccountID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/*
Author: Jatin
Create date: 4/9/2007
Description: Account Select by AccountID by Admin
*/
CREATE procedure [dbo].[USPTblAccountSelectByAccountID]
(
-- Add the parameters for the stored procedure here
@AccountID int,
@ProfileId int
)
as
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
a.AccountID, a.Phone, a.Fax, a.CountryId, a.PostalAddress, a.BusinessAddress, p.FirstName, p.PersonName, a.Name,
a.Description, a.url, p.Email, a.MaximumAgency,a.CurrencyId, a.ActivationDate, a.ExpiryDate,
datediff(dd, getdate(), a.ExpiryDate) as ValidDays, a.Deleted
FROM
tblAccount AS a
INNER JOIN
tblPerson as p ON p.AccountID=a.AccountID AND p.Deleted=''0''
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId=@ProfileId AND
pp.PersonId = p.PersonID
INNER JOIN tblAccountuserPersonalInfo AS api ON
api.AccountId=a.AccountID AND api.PersonId=p.personId
WHERE
a.AccountID=@AccountID
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountInsertByAdmin]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2007
-- Description: For Login Process
-- Modified By: Jagsir Singh:- Insertion into Log Table
-- Modified By: Jagsir Singh:- Set Default= true in person table like super admin for account application
-- =============================================
CREATE procedure [dbo].[UspTblAccountInsertByAdmin]
(
-- Add the parameters for the stored procedure here
@PersonName varchar(50),
@Password varchar(100),
@ProfileId int,
@Name varchar(100),
@FirstName varchar(50),
@Description varchar(2000),
@Email varchar(100),
@url varchar(100),
@Phone varchar(20),
@Fax varchar(20),
@MaximumAgency int,
@PostalAddress varchar(500),
@BusinessAddress varchar(500),
@RegistrationDate datetime,
@CurrencyId Int,
@ExpiryDate datetime,
--@SuspensionDate datetime=NULL,
@ActivationDate datetime,
@CountryId int,
--@ReasonForSuspension varchar(1000)=NULL,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
DECLARE
@AccountId int,
@chkUserName int,
@PersonId int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET @Result=0
SET NOCOUNT ON;
SET @chkUserName = (SELECT COUNT(*) FROM tblPerson WHERE PersonName=@PersonName and Deleted=''0'')
IF @chkUserName > 0
BEGIN
SET @Result=-2
END
Else
BEGIN
BEGIN TRAN
set @AccountId = (SELECT ISNULL(MAX(AccountId),0) FROM tblAccount) + 1
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblAccount
(AccountId, Name, Description, Email, url, Phone, Fax, PostalAddress, BusinessAddress, MaximumAgency, RegistrationDate,
CountryId,CurrencyId,ExpiryDate, ActivationDate, Deleted, DateModified, ModifiedBy)
VALUES(@AccountId, @Name, @Description, @Email, @url, @Phone, @Fax, @PostalAddress, @BusinessAddress, @MaximumAgency, @RegistrationDate,
@CountryId,@CurrencyId,@ExpiryDate, @ActivationDate, @Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblPerson
(AccountID, PersonName, FirstName, Password, Email, Deleted,
DateModified, ModifiedBy, [Default],PassReset)
VALUES(@AccountID, @PersonName, @FirstName, @Password, @Email, @Deleted,
@DateModified, @ModifiedBy,''True'',''True'')
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
set @PersonId = (SELECT isnull(max(PersonID),1) from tblPerson)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblAccountuserPersonalInfo
(AccountId, PersonId, FirstName, LastName, PostalAddress,
BuisnessAddress, Telephone, Mobile, Fax, CountryId, Deleted,
DateModified, ModifiedBy)
VALUES
(@AccountId, @PersonId, @FirstName, '''', @PostalAddress,
@BusinessAddress, @Phone, @Phone, @Fax, @CountryId, @Deleted,
@DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblMapPersonProfile
(PersonId, ProfileId, Deleted,
DateModified, ModifiedBy)
VALUES(@PersonId, @ProfileId, @Deleted,
@DateModified, @ModifiedBy)
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblAccount'',''Insert'',''New Account has been Inserted'',@Date, @ModifiedBy,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountUpdateByAdmin]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2005
-- Description: To Delete Account Temporaryly
-- Modified By: Jagsir Singh:- Insertion into Log Table
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountUpdateByAdmin]
(
-- Add the parameters for the stored procedure here
@AccountID int,
@ProfileId int,
@Name varchar(100),
@FirstName varchar(50),
@Description varchar(2000),
@Email varchar(100),
@MaximumAgency int,
@ExpiryDate datetime,
@ActivationDate datetime,
@CurrencyId Int,
@CountryId Int,
@Phone varchar(20),
@Fax varchar(20),
@PostalAddress varchar(500),
@BusinessAddress varchar(500),
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
as
DECLARE
@chkEmail int
BEGIN
SET @Result=0
-- SET @chkEmail =(SELECT Count(*) FROM tblPerson WHERE Email=@Email and Deleted=''0''
-- AND tblPerson.PersonId not in(SELECT pp.PersonId
-- FROM
-- tblMapPersonProfile AS pp
-- INNER JOIN
-- tblPerson as p ON
-- p.PersonId=pp.PersonId AND
-- p.AccountId=@AccountID))
--
-- IF @chkEmail > 0
-- BEGIN
-- SET @Result=-1
-- END
-- Else
-- BEGIN
BEGIN TRAN
UPDATE tblAccount
SET
Name=@Name,
Description=@Description,
MaximumAgency=@MaximumAgency,
ExpiryDate=@ExpiryDate,
Phone = @Phone,
Fax=@Fax,
PostalAddress=@PostalAddress,
BusinessAddress=@BusinessAddress,
CountryId=@CountryId,
CurrencyId=@CurrencyId,
ActivationDate=@ActivationDate,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
AccountID=@AccountID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
UPDATE tblPerson
SET
tblPerson.Email=@Email,
tblPerson.FirstName=@FirstName
WHERE
(SELECT top 1 pp.PersonId
FROM
tblMapPersonProfile AS pp
INNER JOIN
tblPerson as p ON
p.PersonId=pp.PersonId
INNER JOIN
tblAccount AS a ON
a.AccountId=tblPerson.AccountId AND
p.AccountId=a.AccountId
WHERE
pp.ProfileId=@ProfileId)
= tblPerson.PersonId
AND
AccountID=@AccountID
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblAccount'',''Update'',''Account detail has been updated'',@Date, @ModifiedBy,@AccountID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
--END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspAccountLogs]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 26/Sep/2007
-- Description: View the log history
-- =============================================
CREATE PROCEDURE [dbo].[UspAccountLogs]
-- Add the parameters for the stored procedure here
@AccountId INT,
@ModBy VARCHAR(50) = NULL,
@MDate DATETIME = NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @TableName VARCHAR(50)
DECLARE @Action VARCHAR(20)
DECLARE @Detail VARCHAR(100)
DECLARE @Datemodified DATETIME
DECLARE @Date DATETIME
DECLARE @Time DATETIME
DECLARE @ModifiedByName VARCHAR(50)
DECLARE @ModifiedBy INT
DECLARE @ModifiedName VARCHAR(50)
DECLARE @ModifiedId INT
DECLARE @TempTable TABLE
(
TableName VARCHAR(50),
Action VARCHAR(20),
DETAIL VARCHAR(100),
Date1 DATETIME,
Time DATETIME,
ModifiedByName VARCHAR(50),
ModifiedId INT
)
DECLARE Curser CURSOR FOR
SELECT MaintenanceTable,Action,Detail,DateModified,ModifiedBy,ModifiedId FROM tblmaintenance WHERE AccountId=@AccountId
OPEN Curser
FETCH Curser INTO @TableName,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId
WHILE @@Fetch_Status = 0
BEGIN
SET @ModifiedByName = (SELECT FirstName FROM tblPerson WHERE PersonId=@ModifiedBy)
/* IF @TableName = ''tblCentralAdmin''
BEGIN
SET @ModifiedName=(SELECT UserName from tblCentralAdmin WHERE UserId=@ModifiedId)
END
*/
SET @Date = @DateModified
SET @Time = @DateModified
INSERT INTO @TempTable(TableName,Action,Detail,Date1,Time,ModifiedByName,ModifiedId)
VALUES(@TableName,@Action,@Detail,@Date,@Time,@ModifiedByName,@ModifiedId)
FETCH Curser INTO @TableName,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId
END
IF(@MDate<>'''')
BEGIN
IF(@ModBy<>'''')
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedId
FROM @TempTable WHERE ModifiedByName like ''%'' + @ModBy + ''%''
AND convert(varchar,Date1,106) = convert(varchar,@MDate,106)
order by Date1 desc
END
ELSE
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedId
FROM @TempTable WHERE convert(varchar,Date1,106) = convert(varchar,@MDate,106)
order by Date1 desc
END
END
ELSE
IF(@ModBy<>'''')
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedId
FROM @TempTable WHERE ModifiedByName like ''%'' + @ModBy + ''%''
order by Date1 desc
END
ELSE
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedId
FROM @TempTable
order by Date1 desc
END
CLOSE Curser
DEALLOCATE Curser
RETURN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblCompanySelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 170907
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblCompanySelect]--1
-- Add the parameters for the stored procedure here
@AccountId int,
@CompanyId int=null,
@Status bit=0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Select comp.CompanyId,comp.Companyname,compcont.Telephone,comp.Deleted,Countryname from tblcompany comp inner join tblcountry cntry on
-- comp.countryid=cntry.countryid left join tblcompanycontact compcont on comp.companyid=compcont.companyid and [Default]=1 where comp.CompanyId in(Select a.CompanyId from tblCompanyAcess a inner join tblperson p on
--a.PersonId=p.PersonId where AccountId=@AccountId) ,compcont.Telephone
if (@CompanyId>0)
BEGIN
SELECT comp.CompanyId,comp.Companyname,comp.Deleted,Countryname FROM
tblcompany comp
inner join tblcountry cntry on
comp.countryid=cntry.countryid
left join
tblcompanycontact compcont on
comp.companyid=compcont.companyid and [Default]=1 where comp.CompanyId =@CompanyId
and comp.Deleted=@Status order by comp.DateModified desc
End
Else
Begin
Select comp.CompanyId,comp.Companyname,comp.Deleted,Countryname from
tblcompany comp
inner join tblcountry cntry on
comp.countryid=cntry.countryid
left join tblcompanycontact compcont on
comp.companyid=compcont.companyid and [Default]=1 where comp.CompanyId in
(select Companyid from tblcompanyacess a inner join tblperson p on a.personid=p.personid where p.AccountId=@AccountId and p.deleted=0)
and comp.Deleted=@Status order by comp.DateModified desc
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2005
--Modified Date: 27/09/2007
--Modified By: Manpreet
--Jatin 18-12-2007
-- Description: To Delete Account Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTalentUpdate]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@TalentId int,
@Country varchar(20),
@TalentName varchar(100) ,
@Email varchar(100),
@Fax varchar(20),
@Registered bit,
@PostalAddress varchar(1000),
@ResidentialAddress varchar(1000),
@Telephone varchar(20),
@Mobile varchar(20),
@ABN varchar(20),
@TFN varchar(20),
@TalentSubAccountGL varchar(20),
@SuperannuationRate float,
@DateModified datetime,
@ModifiedBy varchar(50)
)
as
BEGIN
BEGIN TRAN
UPDATE tblTalent
SET
TalentName=@TalentName,
Country=@Country,
ABN=@ABN,
TFN=@TFN,
PostalAddress=@PostalAddress,
ResidentialAddress=@ResidentialAddress,
TalentSubAccountGL=@TalentSubAccountGL,
SuperannuationRate=@SuperannuationRate,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
TalentId=@TalentId
UPDATE [Talent].[dbo].[tblTalentContact]
SET [Telephone] =@Telephone
,[Fax] =@Fax
,[Mobile] =@Mobile
,[Email] =@Email
WHERE [Default]=''true'' and TalentId=@TalentId
Update tblperson
set FirstName=@TalentName
where PersonId=(Select PersonId from tbltalentaccess where TalentId=@TalentId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
-- UPDATE [Talent].[dbo].[tblTalentRegisterGST]
-- SET [Date] = getdate()
-- ,[Registered] = @Registered
-- WHERE TalentId=@TalentId
--
-- IF @@ERROR <> 0
-- BEGIN
-- ROLLBACK TRAN
-- END
UPDATE tblPerson
SET
tblPerson.Email=@Email
WHERE
(SELECT top 1 pp.PersonId
FROM tblMapPersonProfile as pp
INNER JOIN
tblTalent AS t ON
t.TalentId=@TalentID
INNER JOIN
tblTalentAccess AS a ON a.TalentId=@TalentID
WHERE
pp.ProfileId=@ProfileId
And
pp.PersonId=a.PersonId)
=tblPerson.PersonId
AND
AccountID=@AccountID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblTalent'',''Update'',''Talent detail updated'',@Date,@ModifiedBy,@TalentId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCompanyDeleted]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 17/9/2007
-- Description: To Delete Company
-- =============================================
--ModifiedBy Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblCompanyDeleted]
(
-- Add the parameters for the stored procedure here
@CompanyID int,
@AccountId INT,
@ModifiedBy INT,
@Result int output
)
as
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
BEGIN TRAN
UPDATE tblCompany SET Deleted=1, ModifiedBy=@ModifiedBy WHERE CompanyID=@CompanyID
UPDATE tblperson SET deleted =1, ModifiedBy=@ModifiedBy WHERE personid=(SELECT Personid FROM
tblcompanyacess WHERE Companyid=@CompanyID)
DECLARE @Date DATETIME
SET @Date=getdate()
EXEC UsplTblMaintainanceInsert_new ''tblCompany'',''Delete'',''Company Deleted'',@Date,@ModifiedBy,@CompanyID,@AccountId
IF @@Error<> 0
BEGIN
SET @Result=0
ROLLBACK TRAN
END
ELSE
BEGIN
SET @Result=1
COMMIT TRAN
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblCompanyUpdateByCompanyId ]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 17/9/2007
-- Description:
-- =============================================
--ModifiedBy Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UsptblCompanyUpdateByCompanyId ]
-- Add the parameters for the stored procedure here
@CompanyId int,
@CountryId int,
@CompanyName varchar(100),
@IsInvoiceByEmail bit,
@PostalAddress varchar(1000),
@BuisnessAddress varchar(1000),
@Telephone varchar(20),
@Fax varchar(20),
@Mobile varchar(20),
@Email varchar(100),
@AccountId INT,
@ModifiedBy INT,
@Result int output
AS
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Set @Result=0
Begin Tran
update tblCompany set CompanyName=@CompanyName,
PostalAddress=@PostalAddress,
IsInvoiceByEmail=@IsInvoiceByEmail,
DateModified=getdate(),
BusinessAddress=@BuisnessAddress ,
CountryId=@CountryId
where CompanyId=@CompanyId
update tblCompanyContact set CompanyName=@CompanyName,
Telephone=@Telephone,
Fax=@Fax,
Mobile=@Mobile,
DateModified=getdate(),
Email=@Email
where CompanyId=@CompanyId and [Default]=1
Update tblPerson
Set FirstName=@CompanyName,
DateModified=getdate()
Where PersonId=(Select PersonId From tblCompanyAcess where CompanyId=@CompanyId )
if @@Error<>0
RollBack tran
else
Commit tran
set @Result=1
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblCompany'',''Update'',''Company Updated'',@Date,@ModifiedBy,@CompanyId,@AccountId
-- Set @MaintenanceTable=''tblCompanycontact''
-- Set @Action=''Update''
-- Set @Detail=''Update''
-- exec UsplTblMaintainanceInsert @MaintenanceTable,@Action, @Detail
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAccountUserUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 17-sep-2007
-- Description: Detail of various person acc to their profile
-- =============================================
--ModifiedBy: Jagsir Singh (7/Nov/2007)
--Modified By: Jagsir Singh (18/Feb/2008) --- insert profileid
CREATE PROCEDURE [dbo].[UsptblAccountUserUpdate]
-- Add the parameters for the stored procedure here
@AccountId int,
@FirstName varchar(50),
@LastName varchar(50),
@ProfileId INT,
@CountryId int,
@PostalAddress varchar(1000),
@BusinessAddress varchar(1000),
@Telephone varchar(20),
@Mobile varchar(20),
@Fax varchar(20),
@Email varchar(100) ,
@PersonId int ,
@ModifiedBy INT,
@Result int Output
AS
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Begin tran
UPDATE [Talent].[dbo].[tblAccountuserPersonalInfo]
SET
[FirstName] = @FirstName
,[LastName] = @LastName
,[PostalAddress] = @PostalAddress
,[BuisnessAddress] = @BusinessAddress
,[Telephone] = @Telephone
,[Mobile] = @Mobile
,[Fax] = @Fax
,[CountryId] = @CountryId
,[DateModified] = getdate()
WHERE AccountId=@AccountId and PersonId=@PersonId
update tblPerson
SET
[FirstName] = @FirstName,
[DateModified] = getdate(),
[Email]=@Email where PersonId=@PersonId
UPDATE tblMapPersonProfile
SET ProfileId=@ProfileId
WHERE PersonId=@PersonId
if @@ERROR <> 0
Begin
Rollback tran
set @Result=0
end
else
Begin
Commit tran
set @Result=1
end
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblAccountuserPersonalInfo'',''Update'',
''User Detail Updated'',@Date,@ModifiedBy,@PersonId,@AccountId
END
--
--select * from tblperson where personid in(select personid from tblmappersonprofile where profileid=3) and deleted=0
--select * from tblperson where personid in (select personid from tblaccountuserpersonalinfo) and deleted=0 and status=1
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspAccountLogIn_NEW]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 5 sep 2007
-- Description:
--Modified by: Harendra Singh
--Modified Date: 18/12/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspAccountLogIn_NEW]
@UserName VARCHAR(50),
@Password VARCHAR(100),
@Result INT OUTPUT
AS
SET NOCOUNT ON
DECLARE @CH INT
DECLARE @LogId INT
DECLARE @PersonId INT
DECLARE @AccountId INT
DECLARE @@Check INT
Declare @@IsActiveProfile BIT
SELECT @Accountid=AccountId FROM tblPerson
WHERE PersonName=@UserName AND Password=@Password
SELECT @@Check = Count(AccountId) FROM tblAccount
WHERE AccountId=@AccountId
AND SuspensionDate < getdate()
IF(@@Check<>0)
BEGIN
SET @Result=1 -- Account Suspended
END
ELSE
BEGIN
SELECT @@Check = Count(AccountId) FROM tblAccount
WHERE AccountId=@AccountId
AND ExpiryDate < getdate()
IF(@@Check<>0)
BEGIN
SET @Result=2 -- Account Expired
END
ELSE
BEGIN
SELECT @@Check = Count(AccountId) FROM tblAccount
WHERE AccountId=@AccountId
AND Deleted=''True''
IF(@@Check<>0)
BEGIN
SET @Result=3 -- Account Deleted
END
ELSE
BEGIN
SELECT @PersonId=PersonId
FROM tblPerson
WHERE PersonName=@UserName
AND
Password=@Password
AND
Deleted=''False''
IF(@PersonId<>0)
BEGIN
----Check that profile is active
Select @@IsActiveProfile =InActive from tblProfile PR
INNER JOIN tblMapPersonProfile MP
ON PR.ProfileId =MP.ProfileId
Where MP.PersonId=@PersonId
IF (@@IsActiveProfile=''False'')
Begin
SELECT p.PersonId,p.AccountId,PersonName,p.Email,p.FirstName,p.[Default],p.PassReset
FROM tblPerson p
INNER JOIN tblAccount a
ON p.AccountId=a.AccountId
WHERE p.PersonId=@PersonId
BEGIN TRAN
UPDATE tblPerson
SET LastLogin=getdate()
WHERE PersonId=@PersonId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SELECT mp.ProfileId,p.ProfileName
FROM tblMapPersonProfile mp,
tblProfile p
WHERE PersonId=@PersonId
AND
mp.ProfileId=p.ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=6
COMMIT TRAN
End
Else
Begin
SET @Result=5 -- Profile is Inactive
End
END
ELSE
BEGIN
SET @Result=4 -- Wrong User Name or Password
END
END
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblPersonDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 011007
-- Description: Delete Selected Person From PersonTable
-- =============================================
CREATE PROCEDURE [dbo].[UsptblPersonDelete]
-- Add the parameters for the stored procedure here
@PersonId int,
@Result int output
AS
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE tblPerson SET Deleted=1 WHERE PersonId=@PersonId
SET @MaintenanceTable=''tblPerson''
SET @Action=''Update''
SET @Detail=''Delete user''
EXEC UsplTblMaintainanceInsert @MaintenanceTable,@Action, @Detail
IF @@Error<> 0
SET @Result=0
ELSE
SET @Result=1
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGetUserAccess]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/Feb/2008
-- Description: Return User Access to Agency
-- =============================================
CREATE PROCEDURE [dbo].[UspTblGetUserAccess] --1,1
-- Add the parameters for the stored procedure here
@AccountId INT,
@AgencyId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT p.PersonId, p.PersonName,
CASE WHEN ((SELECT COUNT(*) FROM tblAgencyAccess AS aa
WHERE aa.AgencyId=@AgencyId AND aa.PersonId=p.PersonId) > 0)
THEN ''true'' ELSE ''false'' END AS IsAccess FROM tblPerson AS p
INNER JOIN tblMapPersonProfile AS mpp ON
mpp.ProfileId<>1 AND mpp.ProfileId=2 AND mpp.PersonId=p.PersonId
WHERE
p.AccountId=@AccountId AND p.Deleted=''false''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspCompanyInfoInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Geeta
-- Create date: 11/9/2007
-- Description: For Login Process
----Modified By: Manpreet Singh
-----Modified Date: 19/9/2007
-- =============================================
-- ModifiedBy Jagsir Singh (30/Nov/2007)
CREATE procedure [dbo].[UspCompanyInfoInsert]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@Password varchar(50),
@ProfileId int,
@CountryId Int,
@IsInvoiceByEmail bit,
@CompanyName varchar(50),
@UserName varchar(50),
@PostalAddress varchar(1000),
@BusinessAddress varchar(1000),
@Telephone varchar(20),
@Mobile varchar(20),
@Fax varchar(20),
@Email varchar(100),
@ModifiedBy INT,
@Result INT OUTPUT
)
AS
DECLARE
@chkUserName int,
@chkEmail int,
@PersonId int,
@CompanyId int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
SET NOCOUNT ON;
SET @Result=0
SET @chkEmail = (SELECT COUNT(*) FROM tblPerson WHERE Email=@Email AND AccountID=@AccountID and Deleted=0)
SET @chkUserName = (SELECT COUNT(*) FROM tblPerson WHERE PersonName=@UserName and Deleted=''0'')
IF @chkUsername > 0
BEGIN
SET @Result=-2
END
Else
BEGIN
BEGIN TRAN
INSERT INTO tblPerson(AccountID, Email, Password, PersonName,Firstname,DateModified,ModifiedBy,PassReset)
VALUES
(@AccountID, @Email, @Password, @UserName,@CompanyName,GetDate(),@ModifiedBy,''True'')
set @PersonId = (SELECT isnull(max(PersonID),1) from tblPerson)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblMapPersonProfile
(PersonId, ProfileId)
VALUES(@PersonId, @ProfileId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblCompany
(
CountryID,
CompanyName,
IsInvoiceByEmail,
PostalAddress,
BusinessAddress
)
VALUES
(
@CountryID,
@CompanyName,
@IsInvoiceByEmail,
@PostalAddress,
@BusinessAddress
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
Select @CompanyId=Max(CompanyId) from tblCompany
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblCompanyAcess
(
PersonId,
CompanyId
)
VALUES
(
@PersonId,
@CompanyId
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
Insert Into tblCompanyContact
(
CompanyId,
CompanyName,
Title,
Telephone,
Fax,
Mobile,
Email,
[Default]
)
Values
(
@CompanyId,
@companyName,
''Main Contact'',
@Telephone,
@fax,
@Mobile,
@Email,
1
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblCompany'',''Insert'',''Company Inserted'',@Date,@ModifiedBy,@CompanyId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
IF @chkEmail > 0
BEGIN
SET @Result=-1
END
Else
BEGIN
SET @Result=1
END
COMMIT TRAN
END
END'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAccountUserSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 17-sep-2007
-- Description: Detail of various person acc. to their profile
-- =============================================
--ModifiedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UsptblAccountUserSelect]--1,0
-- Add the parameters for the stored procedure here
@AccountId int,
@PersonId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF @PersonId > 0
BEGIN
SELECT p.PersonId, ap.FirstName,ap.LastName, ISNULL(convert(varchar,p.LastLogin,106),''Never'') as LastLogin, ap.CountryId,
p.AccountID, pr.ProfileName,p.Email,
ap.Telephone, ap.Mobile, ap.Fax,
ap.PostalAddress,ap.BuisnessAddress,pr.ProfileId
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId LEFT OUTER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId
WHERE p.AccountID = @AccountId AND p.PersonId=@PersonId
AND pr.profileid<3 and p.Deleted=0
END
ELSE
BEGIN
SELECT p.PersonId, p.FirstName, ISNULL(convert(varchar,p.LastLogin,106),''Never'') as LastLogin,
p.AccountID, pr.ProfileName,pr.ProfileId,[Default]
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId LEFT OUTER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblPersonSelectByProfile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 170807
-- Description: Detail of various person acc to their profile
-- =============================================
CREATE PROCEDURE [dbo].[UsptblPersonSelectByProfile]
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT per.PersonId,PersonName,Email,per.Deleted ,Convert(varchar,LastLogin,107)+'' | ''+ Convert(varchar,LastLogin,108) as LastLogin
FROM tblPerson per inner join tblmappersonprofile map on per.personid=map.personid and
map.profileid=@ProfileId
WHERE Accountid=@AccountId and per.Deleted=0 ORDER BY per.DateModified desc
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblUserWiseDdlAgencies]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 4/Nov/2007
-- Description: Select only those Agencies on which the person has permissions to access
-- =============================================
CREATE PROCEDURE [dbo].[UspTblUserWiseDdlAgencies] --1,6
-- Add the parameters for the stored procedure here
@AccountId INT,
@PersonId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @ProfileId INT
SELECT @ProfileId = mp.ProfileId
FROM tblMapPersonProfile mp
INNER JOIN tblPerson p
ON mp.PersonId=p.PersonId
AND p.PersonId=@personId
IF(@ProfileId=2)
BEGIN
SELECT a.AgencyId,a.AgencyName
FROM tblAgency a
INNER JOIN tblAgencyAccess aa
ON a.AgencyId=aa.AgencyId
WHERE aa.PersonId=@PersonId
AND a.AccountId=@AccountId
AND a.Deleted=''False''
END
ELSE
BEGIN
SELECT a.AgencyId,a.AgencyName
FROM tblAgency a
WHERE AccountId=@AccountId
AND a.deleted=''False''
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountChangePassword]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 7/9/2007
-- Description: Change the current password to new password
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountChangePassword]
-- Add the parameters for the stored procedure here
@OldPassword VARCHAR(100),
@NewPassword VARCHAR(100),
@PersonId INT,
@Name VARCHAR(100) OUTPUT,
@Profile VARCHAR(100) OUTPUT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Pass VARCHAR(100)
SELECT @Pass=Password
FROM tblPerson
WHERE PersonId=@PersonId
AND
Deleted=''False''
IF(@OldPassword=@Pass)
BEGIN
BEGIN TRAN
UPDATE tblPerson
SET Password=@NewPassword,
PassReset=''False'',
DateModified=getdate(),
ModifiedBy=@PersonId
WHERE PersonId=@PersonId
AND
Deleted=''False''
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SELECT @Name=FirstName
FROM tblPerson
WHERE PersonId=@PersonId
SET @Profile=(SELECT ProfileName
FROM tblProfile p
INNER JOIN tblMapPersonProfile mp
ON p.ProfileId=mp.ProfileId
WHERE mp.PersonId=@PersonId)
DECLARE @AccountId INT
SELECT @AccountId = AccountId
FROM tblPerson
WHERE PersonId=@PersonId And Deleted=''False''
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblPerson'',''Password changed'',''Old password has been changed with new one'',@Date,@PersonId,@PersonId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
SET @Result=1
END
ELSE
BEGIN
SET @Result=0
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountRecoverPassword]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 7/9/2007
-- Description: To recover the password for Account user
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountRecoverPassword]
-- Add the parameters for the stored procedure here
@UserName VARCHAR(50),
@Password Varchar(100),
@EmailId VARCHAR(100) OUTPUT,
@Name VARCHAR(100) OUTPUT,
@Profile VARCHAR(100) OUTPUT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
DECLARE @CH INT
SET @CH=(SELECT COUNT(*)
FROM tblPerson
WHERE PersonName=@UserName
AND
Deleted=''False'')
IF(@CH=1)
BEGIN
BEGIN TRAN
DECLARE @PersonId INT
SET @PersonId=(SELECT PersonId
FROM tblPerson
WHERE PersonName=@UserName
AND
Deleted=''False'')
SELECT @Name=FirstName
FROM tblPerson
WHERE PersonId=@PersonId
UPDATE tblPerson
SET Password=@Password,
DateModified=getdate(),
ModifiedBy=@PersonId,
PassReset=''True''
WHERE PersonId=@PersonId
SET @Profile=(SELECT ProfileName
FROM tblProfile p
INNER JOIN tblMapPersonProfile mp
ON p.ProfileId=mp.ProfileId
WHERE mp.PersonId=@PersonId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @EmailId=(SELECT Email
FROM tblPerson
WHERE PersonId=@PersonId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @AccountId INT
SELECT @AccountId = AccountId
FROM tblPerson
WHERE PersonId=@PersonId And Deleted=''False''
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblPerson'',''Reset password'',''Password hes been reset by the user'',@Date,@PersonId,@PersonId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
SET @Result=1
END
ELSE
BEGIN
SET @Result=0
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 5-sep-2007
-- Description: ---Modified By :Manpreet
--Jatin 18-12-2007
-- =============================================
-- ModififedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblTalentInsert]
-- Add the parameters for the stored procedure here
@AccountId int,
@PersonName varchar(50),
@Email varchar(100),
@Password varchar(100),
@ProfileId int,
@Country varchar(20),
@TalentName varchar(100),
@PostalAddress varchar(1000),
@ResidentialAddress varchar(1000),
@Telephone varchar(20),
@Registered bit,
@Mobile varchar(20),
@ABN varchar(20),
@TFN varchar(20),
@Fax varchar(20),
@TalentSubAccountGL varchar(20),
@SuperannuationRate float,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkUsername int,
@chkEmail int,
@PersonId int,
@TalentId int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Result=0
SET @chkEmail = (SELECT COUNT(*) FROM tblPerson WHERE Email=@Email and AccountId=@AccountId and Deleted=''0'')
SET @chkUserName = (SELECT COUNT(*) FROM tblPerson WHERE PersonName=@PersonName and Deleted=''0'')
IF @chkUsername > 0
BEGIN
SET @Result=-2
END
Else
BEGIN
BEGIN TRAN
INSERT INTO tblTalent
(Country, TalentName, ABN, TFN,
PostalAddress, ResidentialAddress,
TalentSubAccountGL, SuperannuationRate,
Deleted, DateModified, ModifiedBy)
VALUES(@Country, @TalentName, @ABN, @TFN,
@PostalAddress, @ResidentialAddress,
@TalentSubAccountGL, @SuperannuationRate,
@Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
set @TalentId = (SELECT isnull(max(TalentId),1) from tblTalent)
INSERT INTO [Talent].[dbo].[tblTalentContact]
([TalentId]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
)
VALUES
(@TalentId
,''main contact''
,@Telephone
,@Fax
,@Mobile
,@Email
,''true''
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblPerson
(AccountID, PersonName,FirstName, Email, Password, Deleted,
DateModified, ModifiedBy,PassReset)
VALUES(@AccountID, @PersonName,@TalentName, @Email, @Password, @Deleted,
@DateModified, @ModifiedBy,''True'')
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO [Talent].[dbo].[tblTalentRegisterGST]
([TalentId]
,[Date]
,[Registered]
)
VALUES
(@TalentId
,getdate()
,@Registered
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
set @PersonId = (SELECT isnull(max(PersonID),1) from tblPerson)
INSERT INTO tblMapPersonProfile
(PersonId, ProfileId, Deleted,
DateModified, ModifiedBy)
VALUES(@PersonId, @ProfileId, @Deleted,
@DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblTalentAccess
(PersonId, TalentId, Deleted,
DateModified, ModifiedBy)
VALUES(@PersonId, @TalentId, @Deleted,
@DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblTalent'',''Insert'',''New Talent Added'',@Date,@ModifiedBy,@TalentId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
IF @chkEmail > 0
BEGIN
SET @Result=-1
END
Else
BEGIN
SET @Result=1
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblPersonInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 6-sep-2007
-- Description: Create a new USer !
-- =============================================
--ModifiedBy: Jagsir Singh (7/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblPersonInsert]
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@PersonName varchar(50),
@FirstName varchar(50),
@LastName varchar(50),
@CountryId int,
@PostalAddress varchar(1000),
@BusinessAddress varchar(1000),
@Telephone varchar(20),
@Mobile varchar(20),
@Fax varchar(20),
@Password varchar(100),
@Email varchar(100) ,
@ModifiedBy INT,
@Result int Output
AS
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
Declare @PersonId int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Set @Result=0
-- BEGIN TRAN
insert into TblPerson(AccountID,PersonName,FirstName,Password,Email,DateModified,ModifiedBy,PassReset)
values( @AccountId ,@PersonName,@FirstName,@Password,@Email,GETDATE(),@ModifiedBy,''True'')
select @PersonId=ISnull(max(PersonId),0) from tblperson --Select Latest inserted person id in person table
Insert into TblmapPersonProfile(PersonId,ProfileId) values(@PersonId,@ProfileId)
INSERT INTO [Talent].[dbo].[tblAccountuserPersonalInfo]
([PersonId]
,[AccountId]
,[FirstName]
,[LastName]
,[PostalAddress]
,[BuisnessAddress]
,[Telephone]
,[Mobile]
,[Fax]
,[CountryId]
)
VALUES
(@PersonId,
@AccountId
,@FirstName
,@LastName
,@PostalAddress
,@BusinessAddress
,@Telephone
,@Mobile
,@Fax
,@CountryId
)
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblPerson'',''New User'',''New User has been created'',@Date, @ModifiedBy,@PersonId,@AccountId
-- if @@Error<>0 ---it means some error occur while executing Query then Rollback transaction
-- BEGIN
-- Rollback tran
-- END
-- Commit Tran
set @Result=1
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAccountUserSearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 8-jan-2008
-- Description: Detail of various person acc. to their profile
-- =============================================
CREATE PROCEDURE [dbo].[UsptblAccountUserSearch]--1,''m'',1
-- Add the parameters for the stored procedure here
@AccountId int,
@Firstname varchar(50),
@ProfileId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF @FirstName <>''''
BEGIN
if @Profileid>0
BEGIN
SELECT p.PersonId, ap.FirstName,ap.LastName, ISNULL(convert(varchar,p.LastLogin,106),''Never'')as LastLogin, ap.CountryId,
p.AccountID, pr.ProfileName,p.Email,pr.ProfileId,
ap.Telephone, ap.Mobile, ap.Fax,
ap.PostalAddress,ap.BuisnessAddress
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId and mp.profileid=@ProfileId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId INNER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId and ap.FirstName like ''%''+@Firstname +''%''
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
ELSE
BEGIN
SELECT p.PersonId, ap.FirstName,ap.LastName,ISNULL(convert(varchar,p.LastLogin,106),''Never'')as LastLogin, ap.CountryId,
p.AccountID, pr.ProfileName,p.Email,pr.ProfileId,
ap.Telephone, ap.Mobile, ap.Fax,
ap.PostalAddress,ap.BuisnessAddress
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId INNER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId and ap.FirstName like ''%''+@Firstname +''%''
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
END
Else
BEGIN
if @Profileid>0
BEGIN
SELECT p.PersonId, ap.FirstName,ap.LastName, ISNULL(convert(varchar,p.LastLogin,106),''Never'')as LastLogin, ap.CountryId,
p.AccountID, pr.ProfileName,p.Email,pr.ProfileId,
ap.Telephone, ap.Mobile, ap.Fax,
ap.PostalAddress,ap.BuisnessAddress
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId and mp.profileid=@ProfileId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId INNER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
ELSE
BEGIN
SELECT p.PersonId, p.FirstName, ISNULL(convert(varchar,p.LastLogin,106),''Never'')as LastLogin,
p.AccountID, pr.ProfileName,pr.ProfileId
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId INNER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspPersonLogIn]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 060807
-- Description: CHECK EXISTENCE OF PERSONNAME AND EMAIL IN PERSON TABLE
-- =============================================
CREATE PROCEDURE [dbo].[UspPersonLogIn]
@AccountId int,
@PersonName VARCHAR(50),
@Email varchar(100),
@Result int output
AS
SET NOCOUNT ON
if exists(SELECT PersonId FROM tblPerson WHERE PersonName=@PersonName)
set @Result=1
else
if exists(Select PersonId from tblPerson where Email=@Email and AccountId=@AccountId and Deleted=0)
set @Result=2
else
set @Result=0
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblReceiptInsertUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 211107
-- Description: Add/Update Receipt
--Modifiedby: Harendra Singh
--Modified Date: 291107
-- =============================================
CREATE PROCEDURE [dbo].[UspTblReceiptInsertUpdate]
@AccountId int,
@ReceiptId int=0,
@ProductionId int ,
@BankAccount varchar(20),
@CurrencyId int=0,
@ReceiptDate datetime,
@Amount float,
@Reference varchar(20),
@Description varchar(100),
-- @Posted bit,
@Type varchar(30),
@Result INT OUTPUT
AS
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
Declare @Posted as bit
BEGIN
SET @Posted=''False''
SET @Result=0
BEGIN TRAN
if (@Type=''insert'' )
Begin
INSERT INTO [Talent].[dbo].[tblReceipt]
([ProductionId]
,[AccountId]
,[BankAccount]
,[CurrencyId]
,[ReceiptDate]
,[Amount]
,[Reference]
,[Description]
,[Posted]
)
VALUES
(
@ProductionId
,@AccountId
,@BankAccount
,@CurrencyId
,@ReceiptDate
,@Amount
,@Reference
,@Description
,@Posted
)
End
else if (@Type=''update'' )
Begin
UPDATE [Talent].[dbo].[tblReceipt]
SET [ProductionId] = @ProductionId
,[BankAccount] = @BankAccount
,[CurrencyId]=@CurrencyId
,[ReceiptDate] = @ReceiptDate
,[Amount] = @Amount
,[Reference] = @Reference
,[Description]=@Description
--,[Posted] = @Posted
WHERE ReceiptId= @ReceiptId and AccountId=@AccountId
End
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
if @Type=''insert''
Begin
Set @MaintenanceTable=''tblReceipt''
Set @Action=''Insert''
Set @Detail=''New Document has been inserted''
exec UsplTblMaintainanceInsert @MaintenanceTable,@Action, @Detail
End
if @Type=''update''
Begin
Set @MaintenanceTable=''tbl Receipt''
Set @Action=''update''
Set @Detail=''New Document has been updated''
exec UsplTblMaintainanceInsert @MaintenanceTable,@Action, @Detail
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspRptTalentEarning]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin Kumar
-- Create date: 17/Dec/2007
--Modified date: 21/01/2008, 23/01/2008
-- Description: View Talent Earning to print
-- =============================================
CREATE PROCEDURE [dbo].[UspRptTalentEarning] --1,1,1
-- Add the parameters for the stored procedure here
@TalentId int,
@AgencyId Int,
@AccountId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT DISTINCT dbo.tblTalent.TalentName, dbo.tblProduction.ProductionTitle, dbo.tblAgency.AgencyName, dbo.tblAgencyContact.Email AS AgencyEmail,
dbo.tblAgency.PostalAddress, CONVERT(VARCHAR(15), dbo.tblInvoice.InvoicDate, 106) AS InvoicDate, dbo.tblLineType.LineType, CONVERT(VARCHAR(15), dbo.tblPayment.Date, 106) AS DatePaidToTalent,
dbo.tblPayment.Reference, CONVERT(VARCHAR(15), dbo.tblReceipt.ReceiptDate, 106) AS ReceiptDate, dbo.tblJob.Description AS JobDescription, dbo.tblCompany.CompanyName,
dbo.tblJob.IsEmployee, dbo.tblPaymentItem.Amount, dbo.tblSite.Version
FROM dbo.tblPaymentItem
INNER JOIN
dbo.tblPayment ON dbo.tblPaymentItem.PaymentId = dbo.tblPayment.PaymentID
INNER JOIN
dbo.tblReceipt ON dbo.tblPayment.ReceiptID = dbo.tblReceipt.ReceiptId
INNER JOIN
dbo.tblProduction ON dbo.tblPayment.ProductionId = dbo.tblProduction.ProductionID AND
dbo.tblReceipt.ProductionId = dbo.tblProduction.ProductionID
INNER JOIN
dbo.tblInvoice ON dbo.tblProduction.ProductionID = dbo.tblInvoice.ProductionId
INNER JOIN
dbo.tblJob ON dbo.tblProduction.ProductionID = dbo.tblJob.ProductionId
INNER JOIN
dbo.tblCompany ON dbo.tblProduction.CompanyId = dbo.tblCompany.CompanyId
INNER JOIN
dbo.tblLiability ON dbo.tblPaymentItem.LiabilityId = dbo.tblLiability.LiabilityId AND dbo.tblReceipt.ReceiptId = dbo.tblLiability.ReceiptId AND
dbo.tblInvoice.InvoiceId = dbo.tblLiability.InvoiceId
INNER JOIN
dbo.tblLineType ON dbo.tblLiability.LineTypeId = dbo.tblLineType.LineTypeId
INNER JOIN
dbo.tblAgency ON dbo.tblProduction.AgencyId = dbo.tblAgency.AgencyId AND dbo.tblInvoice.AgencyId = dbo.tblAgency.AgencyId
INNER JOIN
dbo.tblAgencyContact ON dbo.tblAgency.AgencyId = dbo.tblAgencyContact.AgencyId AND dbo.tblAgencyContact.[Default]=''1''
INNER JOIN
dbo.tblTalent ON dbo.tblInvoice.TalentId = dbo.tblTalent.TalentId AND dbo.tblJob.TalentId = dbo.tblTalent.TalentId
INNER JOIN
dbo.tblAccount ON dbo.tblPayment.AccountId = dbo.tblAccount.AccountId AND dbo.tblProduction.AccountId = dbo.tblAccount.AccountId AND
dbo.tblLiability.AccountId = dbo.tblAccount.AccountId
LEFT JOIN
dbo.tblSite ON dbo.tblSite.[Default]=1 AND dbo.tblSite.AccountId = dbo.tblAccount.AccountId
WHERE tblTalent.TalentId=@TalentId AND
dbo.tblAgency.AgencyId=@AgencyId AND
dbo.tblAccount.AccountId=@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCheckRecieptCurrency]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <5/12/2007>
-- Description:
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspViewAccountUsersLogOnHistory]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 17/Sep/2007
-- Description: To view the log history of Account uesrs
-- =============================================
CREATE PROCEDURE [dbo].[UspViewAccountUsersLogOnHistory] --1,null,''ad'',''2/28/2008'',''2/28/2008''
@AccountId INT,
@ProfileId INT,
@Name VARCHAR(50) = NULL,
@FromDate datetime = Null,
@ToDate datetime = Null
AS
BEGIN
SET NOCOUNT ON;
Declare @Query1 as VARCHAR(2000)
Declare @Query2 as VARCHAR(2000)
Declare @Condition1 as VARCHAR(1000)
Declare @Condition2 as VARCHAR(1000)
IF @AccountId <> ''''
BEGIN
Select @Condition1 = '' AND ac.AccountId='' + Cast(@AccountId as varchar(10))
END
IF @ProfileId <> ''''
IF @Condition1 <> ''''
BEGIN
Select @Condition1 = @Condition1 + '' AND pr.profileid='' + Cast(@ProfileId as varchar(10))
END
ELSE
BEGIN
Select @Condition1 ='' AND pr.profileid='' + Cast(@ProfileId as varchar(10))
END
IF @Name <> ''''
BEGIN
SELECT @Condition2 = '' WHERE p.FirstName like ''''%'' + @Name + ''%'''' ''
END
IF @FromDate<>'''' AND @ToDate<>''''
BEGIN
DECLARE @DateFrom datetime
DECLARE @DateTo datetime
SET @DateFrom=Convert(varchar,@FromDate,101)
SET @DateTo=Convert(varchar,@ToDate,101)
IF @Condition1 <> ''''
BEGIN
SELECT @condition1 = @Condition1 + '' AND ((datepart(day,logindatetime) between datepart(day,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(day,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(month,logindatetime) between datepart(month,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(month,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(year,logindatetime) between datepart(year,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(year,'''''' + convert(varchar,@DateTo,106) + '''''' )))''
END
ELSE
BEGIN
SELECT @condition1 = '' AND ((datepart(day,logindatetime) between datepart(day,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(day,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(month,logindatetime) between datepart(month,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(month,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(year,logindatetime) between datepart(year,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(year,'''''' + convert(varchar,@DateTo,106) + '''''' )))''
END
END
ELSE IF @ToDate<>''''
BEGIN
SET @DateTo=Convert(varchar,@ToDate,101)
IF @condition1 <> ''''
BEGIN
SELECT @condition1 = @condition1 + '' AND convert(varchar,logindatetime,106) <= '''''' + convert(varchar,@DateTo,106) +''''''''
END
ELSE
BEGIN
SELECT @condition1 = '' AND convert(varchar,logindatetime,106) <='''''' + convert(varchar,@DateTo,106) +''''''''
END
END
SELECT @Query1=''SELECT a.AccountId,a.Name as AccountName,p.personid,p.email, url,
rs.profilename,rs.logindate,rs.logintime,rs.logoutdate,rs.logouttime,
rs.logindatetime,p.FirstName AS Name
FROM tblperson p
INNER JOIN tblaccount a
ON
p.accountid=a.accountid
INNER JOIN (SELECT personid,ac.Name,logindatetime, Convert(varchar(17),logindatetime,113) as logindate,
Convert(varchar,logindatetime,108) as logintime,
ISNULL(Convert(varchar(40),(Convert(varchar(17),logoutdatetime,113))),''''Not Available'''') as logoutdate,
Convert(varchar,logoutdatetime,108) as logouttime ,profilename
FROM tblaccountlog ac, tblprofile pr
WHERE ac.profileid=pr.profileid ''
SELECT @Query2='') rs
ON
p.personid=rs.personid ''
IF @Condition1 <> ''''
BEGIN
SELECT @Query1 = @Query1 + @Condition1
END
IF @Condition2 <> ''''
BEGIN
SELECT @Query2 = @Query2 + @Condition2
END
DECLARE @Query AS VARCHAR(2000)
SELECT @Query = @Query1 + @Query2 + '' order by rs.logindatetime desc''
--print(@Condition2)
--print(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblAccountSelectAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 14/9/2005
-- Modified Date: 20/9/2007
-- Description: For Login Process
-- =============================================
CREATE PROCEDURE [dbo].[USPTblAccountSelectAll] --''1'','''','''','''',''''
-- Add the parameters for the stored procedure here
@ProfileId int,
@Name varchar(100) = NULL,
@MaximumAgency int = NULL,
@LastActivity datetime = NULL,
@CurrencyId int=NULL
AS
DECLARE
@query varchar(1000),
@condition varchar(200)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT @condition = '' WHERE a.Deleted=0 ''
IF(@Name<>'''')
BEGIN
SELECT @condition = '' AND (a.Name like ''''%'' + @Name + ''%'''')''
END
IF(@MaximumAgency<>'''')
BEGIN
SELECT @condition = @condition + '' AND a.MaximumAgency >= '' + cast(@MaximumAgency as varchar(10))
END
IF(@CurrencyId<>'''')
BEGIN
SELECT @condition = @condition + '' AND c.CurrencyId = '' + cast(@CurrencyId as varchar(20))
END
IF(@LastActivity<>'''')
BEGIN
SELECT @condition = @condition + '' AND p.LastLogin >= '''''' + cast(@LastActivity as varchar(30)) + ''''''''
END
-- IF(@LastActive<>'''')
-- BEGIN
-- SELECT @condition = '' a.url like ''''%'' + @LastActive + ''%'''' ''
-- END
SELECT @query= ''SELECT
a.AccountID, p.PersonId, p.Email, api.CountryId, p.LastLogin, a.Name,
a.MaximumAgency, c.CurrencyName, CONVERT(VARCHAR,a.ActivationDate,106) AS ActivationDate, a.Deleted, CONVERT(VARCHAR, a.ExpiryDate,106) AS ExpiryDate,
CASE a.Deleted
WHEN ''''true'''' THEN ''''InActive''''
ELSE ''''Active''''
END as Status
FROM tblAccount AS a
LEFT JOIN tblCurrency AS c
ON c.CurrencyId=a.CurrencyId AND c.Deleted=0
INNER JOIN tblPerson as p
ON p.AccountID=a.AccountID AND p.Deleted=0
INNER JOIN tblAccountuserPersonalInfo AS api ON
api.AccountId=a.AccountID AND api.PersonId=p.personId
INNER JOIN tblMapPersonProfile as pp ON pp.PersonId = p.PersonID''
SELECT @query= @query + '' AND pp.ProfileId=''
SELECT @query= @query + cast(@ProfileId as varchar(20))
SELECT @query= @query + '' ''
/*IF(@condition<>'''')
BEGIN*/
SELECT @query= @query + @condition + '' order by a.DateModified desc ''
/*END
ELSE
BEGIN
SELECT @query= @query + '' order by a.DateModified desc ''
END*/
EXEC(@query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblGstCodesSelectByGstCodesID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2005
--Modified date: 22/10/2007
-- Description: FILL DDL Rate Type
-- =============================================
CREATE procedure [dbo].[USPTblGstCodesSelectByGstCodesID]
(
@GstCodeId int
)
AS
SELECT Rate, Date, TaxCodeId FROM tblGST
WHERE Deleted=''0'' AND GstCodeId=@GstCodeId
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsplTblMaintainanceInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 10-sep-2007
-- Description:
CREATE PROCEDURE [dbo].[UsplTblMaintainanceInsert]
-- Add the parameters for the stored procedure here
@MaintenanceTable varchar(50),
@Action varchar(100),
@Detail varchar(1000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Insert into tblMaintenance(MaintenanceTable,
[Action],
[Detail])
values
(
@MaintenanceTable ,
@Action ,
@Detail
)
-- Insert statements for procedure here
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSelectAgencyGST]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 8/Nov/2007
-- Modified By: Jatin (10/12/2007)
-- Description: Select GST of Agency
-- Modified By: Jagsir Singh (19/Feb/2008) -- Insert @Query and @Date Comparison
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSelectAgencyGST] --1,''19 Feb 2008''
-- Add the parameters for the stored procedure here
@AgencyId INT,
@Date DATETIME = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Query VARCHAR(500)
SET @Query=''SELECT a.AgencyId,a.AgencyName,convert(varchar, g.Date,106) AS Date,
CASE WHEN g.Registered=''''False'''' THEN ''''No'''' ELSE ''''Yes'''' END AS Status,g.Registered
FROM tblAgencyRegisterGST g
INNER JOIN tblAgency a
ON a.AgencyId=g.AgencyId
AND a.AgencyId=''+ CAST(@AgencyId AS VARCHAR(10)) +
'' AND a.Deleted=''''false''''
WHERE g.Deleted=''''False'''' ''
IF @Date is not null
BEGIN
SET @Query=@Query+'' AND convert(varchar, g.Date,106) = '''''' + Convert(Varchar,@Date,106) + ''''''''
END
SET @Query=@Query+'' ORDER BY Date DESC''
--Print(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTaxCodeSelectById]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
-- Description: Rate Type Insert
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTaxCodeSelectById]
-- Add the parameters for the stored procedure here
--@RateTypeId int,
@TaxCodeId int,
@TaxCode VARCHAR(3) OUTPUT
AS
BEGIN
SET @TaxCode= (SELECT TaxCode from tblTaxCode where TaxCodeId=@TaxCodeId)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSelectTalentGST]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin Kumar
-- Create date: 10/12/2007
-- Description: Select GST of Talent
-- Modified By: Jagsir Singh (20/Feb/2008) -- Insert @Query and @Date Comparison
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSelectTalentGST] --2,''18 Dec 2007''
-- Add the parameters for the stored procedure here
@TalentId INT,
@GSTDate DATETIME = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Query VARCHAR(500)
SET @Query = ''SELECT t.TalentId,t.TalentName,convert(varchar, g.Date,106) AS Date,
CASE WHEN g.Registered=''''False'''' THEN ''''No'''' ELSE ''''Yes'''' END AS Status,g.Registered
FROM tblTalentRegisterGST g
INNER JOIN tblTalent t
ON t.TalentId=g.TalentId
AND t.TalentId='' + Cast(@TalentId AS VARCHAR(10)) +
'' AND t.Deleted=''''false''''
WHERE g.Deleted=''''False''''''
IF @GSTDate is not null
BEGIN
SET @Query=@Query+'' AND convert(varchar, g.Date,106) = '''''' + Convert(Varchar,@GSTDate,106) + ''''''''
END
SET @Query=@Query+'' ORDER BY Date DESC''
--Print(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAgencyFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 27/9/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblAgencyFillDdl] --''1'','''','''','''','''' --''33'', ''12'',''23'',''32''
-- Add the parameters for the stored procedure here
@AccountId int,
@CompanyId int=NULL,
@TalentId int=NULL,
@ProductionId int=NULL,
@PersonId int=NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE
@qry varchar(2000),
@cond varchar(500)
--SELECT @cond = '' WHERE agy.Deleted=''''False'''' AND agy.Status=''''False''''''
SELECT @cond = '' WHERE agy.Deleted=''''False'''' AND agy.AccountId='' + cast(@AccountId as varchar(20))
IF(@CompanyID>0 OR @ProductionId>0 OR @TalentId>0)
BEGIN
SELECT @qry= ''SELECT DISTINCT agy.AgencyId, agy.Agencyname
from tblAgency agy
LEFT JOIN tblcountry cntry on
agy.countryid=cntry.countryid
INNER JOIN tblProduction as prod ON
prod.Deleted=''''0'''' AND prod.AgencyId=agy.AgencyId''
IF(@CompanyID>0)
BEGIN
SELECT @cond = @cond + '' AND prod.CompanyId = '' + cast(@CompanyId as varchar(20))
END
IF(@ProductionId>0)
BEGIN
SELECT @cond = @cond + '' AND prod.ProductionId = '' + cast(@ProductionId as varchar(20))
--SELECT @cond = @cond + '' AND prod.AgencyId=agy.AgencyId''
END
IF(@TalentId>0)
BEGIN
SELECT @qry = @qry + '' INNER JOIN tblJob AS j ON
j.ProductionID=prod.ProductionID AND
j.TalentId=''+ cast(@TalentID as varchar(20))
END
IF(@PersonId>0)
BEGIN
SELECT @qry = @qry + '' INNER JOIN tblAgencyAccess AS aa ON
aa.AgencyId=agy.AgencyId AND
aa.PersonId=''+ cast(@PersonId as varchar(20))
END
END
ELSE
BEGIN
SELECT @qry= ''SELECT DISTINCT agy.AgencyId, agy.Agencyname
from tblAgency agy
LEFT JOIN tblcountry cntry on
agy.countryid=cntry.countryid''
IF(@PersonId>0)
BEGIN
SELECT @qry = @qry + '' INNER JOIN tblAgencyAccess AS aa ON
aa.AgencyId=agy.AgencyId AND
aa.PersonId=''+ cast(@PersonId as varchar(20))
END
-- INNER JOIN tblProduction as prod ON
-- prod.Deleted=''''0'''' AND prod.AgencyId=agy.AgencyId''
END
SELECT @qry = @qry + @cond
EXEC(@qry)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblCompanyFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 27/9/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblCompanyFillDdl] --''1'',''1'','''','''',''''
-- Add the parameters for the stored procedure here
@AccountId int,
@AgencyID int=NULL,
@TalentId int=NULL,
@ProductionId int=NULL,
@ProfileId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE
@qry varchar(2000),
@cond varchar(500)
SELECT @cond = '' WHERE comp.Deleted = ''''0''''''
IF(@AgencyID>0 OR @ProductionId>0 OR @TalentId>0)
BEGIN
SELECT @qry= ''SELECT DISTINCT comp.CompanyId, comp.Companyname
FROM tblcompany comp
INNER JOIN tblcountry cntry on
comp.countryid=cntry.countryid
--AND comp.AccountId=@AccountId
INNER JOIN
tblPerson as p ON p.AccountID='' + cast(@AccountId as varchar(20))
SELECT @qry = @qry + '' AND
p.Deleted=0
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId='' + cast(@ProfileId as varchar(20))
SELECT @qry = @qry + '' AND
pp.PersonId = p.PersonID
INNER JOIN
tblCompanyAcess AS a ON p.PersonID=a.PersonID AND
comp.CompanyId=a.CompanyId
INNER JOIN tblProduction as prod ON
prod.Deleted=''''0'''' AND prod.CompanyId=comp.CompanyId''
IF(@AgencyID>0)
BEGIN
SELECT @cond = @cond + '' AND prod.AgencyID = '' + cast(@AgencyID as varchar(20))
END
IF(@ProductionId>0)
BEGIN
SELECT @cond = @cond + '' AND prod.ProductionId = '' + cast(@ProductionId as varchar(20))
END
IF(@TalentId>0)
BEGIN
SELECT @qry= @qry + '' INNER JOIN tblJob AS j ON
j.ProductionID=prod.ProductionID AND
j.TalentId=''+ cast(@TalentID as varchar(20))
END
END
ELSE
BEGIN
SELECT @qry= ''SELECT DISTINCT comp.CompanyId, comp.Companyname
FROM tblcompany comp
INNER JOIN tblcountry cntry on
comp.countryid=cntry.countryid
--AND comp.AccountId=@AccountId
INNER JOIN
tblPerson as p ON p.AccountID='' + cast(@AccountId as varchar(20))
SELECT @qry = @qry + '' AND
p.Deleted=0
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId='' + cast(@ProfileId as varchar(20))
SELECT @qry = @qry + '' AND
pp.PersonId = p.PersonID
INNER JOIN
tblCompanyAcess AS a ON p.PersonID=a.PersonID AND
comp.CompanyId=a.CompanyId''
-- INNER JOIN tblProduction as prod ON
-- prod.Deleted=''''0'''' AND prod.CompanyId=comp.CompanyId''
END
SELECT @qry = @qry + @cond
EXEC(@qry)
PRINT(@qry)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileSelectById]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 27/Sep/2007
-- Description: Select selected profile detail on basis of profile id
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileSelectById]
-- Add the parameters for the stored procedure here
@ProfileId INT
As
--Declare @MaintenanceTable varchar(50)
--Declare @Action varchar(100)
--Declare @Detail varchar(1000)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT ProfileName, InActive , parentProfileId
FROM tblProfile
WHERE profileId=@ProfileId and deleted=''false''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblRequestDetail]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select request details
-- =============================================
CREATE PROCEDURE [dbo].[UspTblRequestDetail] --1
-- Add the parameters for the stored procedure here
@JobPaymentId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT PaymentTypeId,TalentAccountId,Value
FROM tblJobPayment
WHERE JobPaymentId=@JobPaymentId
AND
Deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsplTblMaintainanceInsert_new]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 10-sep-2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsplTblMaintainanceInsert_new]
-- Add the parameters for the stored procedure here
@MaintenanceTable VARCHAR(50),
@Action VARCHAR(50),
@Detail VARCHAR(1000),
@DateModified DATETIME,
@ModifiedBy INT,
@ModifiedID INT,
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO tblMaintenance(MaintenanceTable,Action,Detail,DateModified,ModifiedBy,ModifiedId,AccountId)
VALUES(@MaintenanceTable,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId,@AccountId)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResetIdentityValue]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- =============================================
-- Author: Harendra Singh
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[ResetIdentityValue]
-- Add the parameters for the stored procedure here
@Tablename as varchar(200),
@Value as Int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @cmd as varchar(1000)
-- Insert statements for procedure here
If (EXISTS(SELECT name FROM syscolumns WHERE status = 0x80 AND
OBJECT_NAME(id)=@Tablename ))
begin
print ''IsIdentity''
SET @Cmd = ''DBCC CHECKIDENT ('''''' + @TableName + '''''', RESEED,''+ cast (@Value as varchar)+ '')''
EXEC (@Cmd)
--EXEC sp_executesql @Cmd
--exec ''use talent_test DBCC CHECIDENT (@Tablename , RESEED, 1)''
end
else
begin
print ''No IsIdentity''
end
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentAccounts]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select payment types
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTalentAccounts] --35
-- Add the parameters for the stored procedure here
@TalentId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT TalentAccountId,AccountNumber+'': ''+AccountName as TalentAccount
FROM tblTalentAccount
WHERE TalentId=@TalentId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblAccountSelectProfile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 19/9/2005
-- Description: Account Select by AccountID by Admin
-- =============================================
CREATE procedure [dbo].[USPTblAccountSelectProfile]
(
-- Add the parameters for the stored procedure here
@AccountID int,
@ProfileId int
)
as
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
a.AccountID, p.PersonName, a.Name, a.url, a.Email, a.Phone,
a.Fax, a.PostalAddress, a.BusinessAddress, a.ExpiryDate,
a.MaximumAgency, a.ActivationDate, a.ExpiryDate,
datediff(dd, getdate(), a.ExpiryDate) as ValidDays, a.Deleted
FROM
tblAccount AS a
INNER JOIN
tblPerson as p ON p.AccountID=a.AccountID AND p.Deleted=''0''
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId=@ProfileId AND
pp.PersonId = p.PersonID
WHERE
a.AccountID=@AccountID
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblPersonProfileSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14/Sep/2007
-- Description: To select the profiles of the person who is logged in
-- =============================================
CREATE PROCEDURE [dbo].[UspTblPersonProfileSelect]
-- Add the parameters for the stored procedure here
@PersonId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT ProfileId,ProfileName
FROM tblProfile
WHERE ProfileId IN (SELECT ProfileId
FROM tblMapPersonProfile
WHERE PersonId=@PersonId
)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblNavigationSelect]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT NavigationId,[Name],Description,Parent,Sequence
FROM tblNavigation
WHERE deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionsByAgency]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 191007
-- Description: Select Productions on basis of agencies
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProductionsByAgency] --1,5
-- Add the parameters for the stored procedure here
@AccountId INT,
@AgencyId INT=null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF @AgencyId <> 0
BEGIN
SELECT ProductionId,Description
FROM tblProduction
WHERE
AgencyId=@AgencyId
AND
AccountId=@AccountId
END
ELSE
BEGIN
SELECT ProductionId,Description
FROM tblProduction
WHERE
AccountId=@AccountId
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationGroup]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <11/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblNavigationGroup]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select distinct NavigationId, Name, Description
from tblNavigation where parent is null and deleted=''0''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspViewBatchProduction]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 27/Nov/2007
-- Description: Select all Productions for AgencyId
-- =============================================
CREATE PROCEDURE [dbo].[UspViewBatchProduction] --15,1,1,1,1
-- Add the parameters for the stored procedure here
@BatchId INT,
@AccountId INT,
@AgencyId INT,
@ProductionId INT,
@CompanyId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Query VARCHAR(2000)
SET @Query=''SELECT p.ProductionId,p.ProductionTitle,b.BatchId,ag.AgencyName,cmp.CompanyName,
CASE WHEN
(SELECT ProductionId FROM tblBatchProduction AS bp WHERE bp.Deleted=''''0'''' AND bp.ProductionId=p.ProductionId and bp.BatchId=b.BatchId)>0
THEN
''''True''''
ELSE
''''False''''
END AS IsChecked
FROM tblproduction p
INNER JOIN tblAgency ag
INNER JOIN tblBatch b
ON ag.AgencyId=b.AgencyId
ON p.AgencyId=ag.AgencyId
AND ag.deleted=''''False''''
INNER JOIN tblCompany cmp
ON p.CompanyId=cmp.CompanyId''
IF @CompanyId<>0
BEGIN
SET @Query = @Query + '' AND cmp.CompanyId='' + CAST(@CompanyId as varchar(10))
END
SET @Query = @Query + '' AND cmp.Deleted=''''False''''
INNER JOIN tblAccount ac
ON p.AccountId=ac.AccountId
AND ac.Deleted=''''False''''
WHERE b.BatchId='' + CAST(@BatchId as varchar(10)) +
'' AND
ag.AgencyId='' + CAST(@AgencyId as varchar(10)) +
'' AND
ac.AccountId='' + CAST(@AccountId as varchar(10))
IF @ProductionId<>0
BEGIN
SET @Query=@Query+ '' AND p.ProductionId = '' + CAST(@ProductionId as varchar(10))
END
--Print(@Query)
Exec(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblCompanyContactSelectByContactId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 13/9/2005
-- Description: View All Contacts of an Agency
-- =============================================
CREATE procedure [dbo].[USPTblCompanyContactSelectByContactId]
-- Add the parameters for the stored procedure here
@ContactId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT [CompanyId]
,[ContactId]
,[CompanyName]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
,[Deleted]
,[DateModified]
,[ModifiedBy] from tblCompanycontact Where ContactId=@ContactId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblRateTypeSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: For Rate Type
-- =============================================
CREATE procedure [dbo].[USPTblRateTypeSelect] --'''', ''1'', ''1''
@RateTypeName varchar(100) = NULL,
@CategoryID int = NULL,
@AccountId int
AS
DECLARE
@query varchar(500),
@condition varchar(200)
SELECT @condition = '' WHERE r.Deleted=0 AND r.AccountId='' + cast(@AccountId as varchar(10))
SELECT @query= ''SELECT r.*, c.CategoryName FROM tblRateType as r
INNER JOIN tblCategory AS c
ON c.CategoryId=r.CategoryId''
IF(@RateTypeName<>'''')
BEGIN
SELECT @condition = '' AND (r.RateTypeName like ''''%'' + @RateTypeName + ''%'''')''
END
IF(@CategoryID<>'''')
BEGIN
SELECT @condition = @condition + '' AND r.CategoryID = '' + cast(@CategoryID as varchar(10))
END
SELECT @query= @query + @condition + '' Order by datemodified desc''
EXEC(@query)
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblFetchAgencyAccountForReciept]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <13/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblFetchAgencyAccountForReciept] --7 ,8
-- Add the parameters for the stored procedure here
@AccountId int,
@ProductionId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT dbo.tblAgencyAccount.CurrencyId as CurrencyId, dbo.tblAgencyAccount.AccountNumber as AccountNumber
FROM dbo.tblProduction INNER JOIN
dbo.tblAgency ON dbo.tblProduction.AgencyId = dbo.tblAgency.AgencyId INNER JOIN
dbo.tblAgencyAccount ON dbo.tblAgency.AgencyId = dbo.tblAgencyAccount.AgencyId
WHERE dbo.tblProduction.ProductionID=@ProductionId and dbo.tblAgency.AccountId=@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 14/9/2005
-- Description: For Login Process
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountUpdate]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@Name varchar(100),
@Description varchar(2000),
@Phone varchar(20),
@Fax varchar(20),
@PostalAddress varchar(500),
@BusinessAddress varchar(500),
@DateModified datetime,
@ModifiedBy int
--@Result INT OUTPUT
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
BEGIN TRAN
UPDATE tblAccount
SET
Name = @Name,
Description=@Description,
Phone = @Phone,
Fax=@Fax,
PostalAddress=@PostalAddress,
BusinessAddress=@BusinessAddress,
DateModified = @DateModified,
ModifiedBy=@ModifiedBy
WHERE
AccountId=@AccountId AND
EXISTS (SELECT COUNT(*) FROM
tblMapPersonProfile as pp, tblPerson AS p
WHERE pp.ProfileId=@ProfileId AND pp.PersonId = p.PersonID
AND p.AccountId=@AccountId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralNavigationSelectNew]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
-- =============================================
--Modified By: Jagsir Singh (29/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblCentralNavigationSelectNew]
-- Add the parameters for the stored procedure here
@ProfileId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF(@ProfileId = 1)
BEGIN
SELECT CentralNavigationId,Name,Description,Parent,Sequence
FROM tblCentralNavigation
WHERE deleted=''False''
END
ELSE
BEGIN
SELECT CentralNavigationId,Name,Description,Parent,Sequence
FROM tblCentralNavigation
WHERE deleted=''False''
AND CentralNavigationId <> 12
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCurrencySelectBySearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/9/2007
-- Description: Select a particular Currency
--Modified By: Harendra Singh
--Modified Date: 17/12/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCurrencySelectBySearch] --1,''''
@CurrencyId INT,
@CurrencyName Varchar(50) = null
AS
SET NOCOUNT ON
DECLARE @Query VARCHAR(1000)
DECLARE @Condition VARCHAR(1000)
IF @CurrencyId <> ''''
BEGIN
SELECT @Condition = '' AND CurrencyId = '' + CAST(@CurrencyId AS VARCHAR(10))
END
IF @CurrencyName <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND CurrencyName like ''''%'' + @CurrencyName + ''%'''' ''
END
ELSE
BEGIN
SELECT @Condition = '' AND CurrencyName like ''''%'' + @CurrencyName + ''%'''' ''
END
END
SELECT @Query =''SELECT CurrencyID,CurrencyName,Description,BaseCurrency ,FXRate
FROM tblCurrency
WHERE
Deleted=''''False'''' ''
IF @Condition <> ''''
BEGIN
SELECT @Query = @Query + @Condition
END
SET @Query=@Query+'' Order by datemodified desc''
EXEC(@Query)
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAgencyFeeIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 01/11/2007
-- Description: For AgencyFee Deletion
-- =============================================
CREATE procedure [dbo].[UspTblAgencyFeeIsDeletedUpdate]
(
-- Add the parameters for the stored procedure here
@AgencyFeeID int,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
UPDATE tblAgencyFee
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
AgencyFeeID=@AgencyFeeID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
ELSE
BEGIN
SET @Result=1
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblTalentSelectByProductionID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet
-- Create date: 01/11/2007
-- Description: For Disbursement
-- =============================================
Create PROCEDURE [dbo].[USPTblTalentSelectByProductionID]--''4''
-- Add the parameters for the stored procedure here
@Productionid int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
select tbljob.Talentid,Talentname from tbljob inner join tbltalent on tbljob.talentid=tbltalent.talentid where Productionid=@Productionid and tbljob.Deleted=0
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCountrySelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 11/9/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCountrySelect]
AS
SET NOCOUNT ON
SELECT CountryId,CountryName,a.CurrencyId,CurrencyName,LabelGST,
Status=CASE a.deleted When ''False'' then ''Active''
Else
''InActive''
END
from tblCountry a inner join tblcurrency c on
a.currencyid=c.currencyid
where a.deleted = ''False''
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountLogout]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Sep/2007
-- Description: This make the entry for logout in tblLog
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountLogout]
-- Add the parameters for the stored procedure here
@AccountLogId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblAccountLog
SET LogoutDateTime=getdate()
WHERE AccountLogId=@AccountLogId
IF (@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralMaintenanceInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir
-- Create date: 12/Sep/2007
-- Description: Insert values into central maintenance table
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralMaintenanceInsert]
-- Add the parameters for the stored procedure here
@MaintenanceTable VARCHAR(50),
@Action VARCHAR(50),
@Detail VARCHAR(1000),
@DateModified DATETIME,
@ModifiedBy INT,
@ModifiedID INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO tblCentralMaintenance(MaintenanceTable,Action,Detail,DateModified,ModifiedBy,ModifiedId)
VALUES(@MaintenanceTable,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralSelectedUsers]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13/Sep/2007
-- Description: Select All Central Users
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralSelectedUsers] --null,null,null
@CentralProfileId INT,
@UserName VARCHAR(50),
@Deleted INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE
@query varchar(1000),
@condition varchar(200)
IF(@CentralProfileId<>'''')
BEGIN
SELECT @condition=''A.CentralProfileId='' + Cast(@CentralProfileId as varchar(10))
END
IF(@UserName<>'''')
BEGIN
IF(@condition<>'''')
BEGIN
SELECT @condition = @condition + '' AND t.UserName like ''''%'' + @UserName + ''%'''' ''
END
ELSE
BEGIN
SELECT @condition = ''t.UserName like ''''%'' + @UserName + ''%'''' ''
END
END
IF(@Deleted = 0 Or @Deleted = 1)
BEGIN
IF(@condition<>'''')
BEGIN
SELECT @condition = @condition + '' AND A.deleted='' + Cast(@Deleted as VARCHAR(5))
END
ELSE
BEGIN
SELECT @condition = ''A.deleted='' + Cast(@Deleted as VARCHAR(5))
END
END
ELSE
BEGIN
IF(@condition<>'''')
BEGIN
SELECT @condition = @condition + '' AND A.deleted=0''
END
ELSE
BEGIN
SELECT @condition = ''A.deleted=0''
END
END
IF(@condition<>'''')
BEGIN
SELECT @condition = '' WHERE '' + @condition
END
SELECT @query= ''SELECT A.UserId,t.UserName,Email,
Status=CASE a.deleted When ''''False'''' then ''''Active''''
Else
''''InActive''''
END
,PasswordCreationDate,P.CentralProfileName,P.CentralProfileId
FROM tblCentralAdmin A inner join
tblCentralProfile P on
A.CentralProfileId=P.CentralProfileId
inner join
(select AA.UserId,FirstName+'''' ''''+LastName as UserName
from tblCentralAdmin AA
inner join tblCentralUserPersonalInfo uu on
AA.userid=uu.userid ) t on A.UserId=t.UserId''
IF(@condition<>'''')
BEGIN
SELECT @query= @query + @condition
END
SELECT @query = @query + '' order by A.datemodified desc''
exec(@query)
--print(@query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGetNoOfAgencies]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 5Jan2008
-- Description: Returns Max no. of agencies
-- =============================================
CREATE PROCEDURE [dbo].[UspTblGetNoOfAgencies] --null
-- Add the parameters for the stored procedure here
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT @Result = AgencyMax FROM tblSite WHERE [Default]=''True'' AND Deleted=''False''
--print @Result
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralNavigationSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralNavigationSelect]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT CentralNavigationId,Name,Description,Parent,Sequence
FROM tblCentralNavigation
WHERE deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralNavigationGroup]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <19/12/2007>
-- Description:
CREATE PROCEDURE [dbo].[UspTblCentralNavigationGroup]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select distinct CentralNavigationId, Name, Description
from tblCentralNavigation where parent is null and deleted=''0''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCountrySelectBySearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/9/2007
-- Description: Select a particular Country
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCountrySelectBySearch] --null,null
@CountryId INT,
@CountryName Varchar(50) = null
AS
SET NOCOUNT ON
DECLARE @Query VARCHAR(1000)
DECLARE @Condition VARCHAR(1000)
IF @CountryId <> ''''
BEGIN
SELECT @Condition = '' AND CountryId = '' + CAST(@CountryId AS VARCHAR(10))
END
IF @CountryName <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND CountryName like ''''%'' + @CountryName + ''%'''' ''
END
ELSE
BEGIN
SELECT @Condition = '' AND CountryName like ''''%'' + @CountryName + ''%'''' ''
END
END
SELECT @Query =''SELECT CountryId,CountryName,a.CurrencyId,CurrencyName,LabelGST,
Status=CASE a.deleted When ''''False'''' then ''''Active''''
Else
''''InActive''''
END
from tblCountry a inner join tblcurrency c on
a.currencyid=c.currencyid
where a.deleted = ''''False''''''
IF @Condition <> ''''
BEGIN
SELECT @Query = @Query + @Condition
END
SET @Query=@Query+'' order by a.datemodified desc''
EXEC(@Query)
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblJobSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 17/10/2005
-- Modified Date: 02/11/2007
-- Description: For Job Select
-- =============================================
CREATE PROCEDURE [dbo].[USPTblJobSelect] --''1'', ''10'', 29
-- Add the parameters for the stored procedure here
@AccountId int,
@ProductionId int=Null,
@AgencyID int=NULL,
@CompanyID int=NULL,
@TalentID int=NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE
@query varchar(2000),
@condition varchar(500)
SELECT @condition = '' WHERE j.Deleted=''''0''''''
IF(@AgencyID>0)
BEGIN
SELECT @condition = @condition + '' AND a.AgencyID = '' + cast(@AgencyID as varchar(10))
END
IF(@ProductionId>0)
BEGIN
SELECT @condition = @condition + '' AND p.ProductionId = '' + cast(@ProductionId as varchar(10))
END
IF(@CompanyID>0)
BEGIN
SELECT @condition = @condition + '' AND c.CompanyID = '' + cast(@CompanyID as varchar(10))
END
IF(@TalentId>0)
BEGIN
SELECT @condition = @condition + '' AND t.TalentId = '' + cast(@TalentId as varchar(10))
END
SELECT @query= ''SELECT
j.JobId, p.ProductionId, p.ProductionTitle, pt.Name as ProductionTypeName, a.AgencyName, a.AgencyId,
c.CompanyName, c.CompanyId,
t.TalentId, t.TalentName,
''''test'''' as IsEmployee
FROM tblJob as j
INNER JOIN
tblProduction as p ON
p.ProductionId=j.ProductionId AND p.Deleted=''''0'''' AND p.AccountId='' + cast(@AccountID as varchar(20))
SELECT @query = @query + '' INNER JOIN
tblAgency as a ON
a.AgencyId=p.AgencyId AND a.Deleted=''''0''''
INNER JOIN
tblCompany as c ON
c.CompanyId=p.CompanyId AND c.Deleted=''''0''''
INNER JOIN tblTalent AS t ON
t.TalentId=j.TalentId AND t.Deleted=''''0''''
LEFT JOIN
tblProductionType AS pt ON
pt.ProductionTypeId=p.ProductionTypeId AND pt.Deleted=''''0''''''
SELECT @query= @query + @condition + '' order by j.datemodified desc ''
EXEC(@query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralProfilePermission]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: < 20/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralProfilePermission]
@ProfileId int,
@FormName varchar(100)
AS
/* SET NOCOUNT ON */
Declare @@NavigationId as int
set @@NavigationId = (select distinct isnull(CentralNavigationId,0) from tblCentralNavigation
Where FormName=@FormName)
IF @@NavigationId <>0
Begin
select [select], [insert], [update],[delete] from tblCentralmenu
where CentralProfileId=@ProfileId and CentralNavigationId=@@NavigationId
End
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblProductionsByAgencyId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 8/Jan/2008
-- Description: Fill dropdown with productions
-- =============================================
CREATE PROCEDURE [dbo].[USPTblProductionsByAgencyId]
-- Add the parameters for the stored procedure here
@AgencyId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT ProductionId,ProductionTitle
FROM tblProduction
WHERE AgencyId=@AgencyId
AND Deleted=''False''AND Completed=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountLogInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Sep/2007
-- Description: Insert log when any account user logs on
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountLogInsert]
-- Add the parameters for the stored procedure here
@AccountId INT,
@PersonId INT,
@ProfileId INT,
@AccountLogId INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRAN
INSERT INTO tblAccountLog(AccountId,PersonId,ProfileId,LoginDateTime)
VALUES(@AccountId,@PersonId,@ProfileId,getdate())
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
ELSE
BEGIN
SET @AccountLogId =(SELECT ISNULL(MAX(AccountLogId),0)
FROM tblAccountLog)
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblViewInvs]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Nov/2007
-- Description: View all Invoices according BatchId
-- =============================================
CREATE PROCEDURE [dbo].[UsptblViewInvs] --201,null
-- Add the parameters for the stored procedure here
@BatchId INT,
@Printed BIT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(500)
DECLARE @Cond VARCHAR(100)
SET @Query = ''SELECT InvoiceId,AgencyName,TalentName,CompanyName,InvoicDate,
Status=CASE Printed When ''''False'''' then ''''UnPrinted''''
Else
''''Printed''''
END
FROM vwInvoiceFormat
WHERE BatchId=''+Cast(@BatchId as VARCHAR(10))
IF (@Printed=0 Or @Printed=1)
BEGIN
SET @Cond = '' AND Printed='' + Cast(@Printed as VARCHAR(5))
END
IF @Cond<>''''
BEGIN
SET @Query = @Query+@Cond
END
EXEC(@Query)
--Print(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblTalentFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/10/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblTalentFillDdl] --''1'',''12'','''','''',''1''
-- Add the parameters for the stored procedure here
(
@AccountId int,
@CompanyId int=NULL,
@AgencyId int=NULL,
@ProductionId int=NULL,
@DDLforProduction bit=NULL -- TRUE for ManageJob page only for rest pages it is FALSE
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE
@qry varchar(2000),
@cond varchar(500)
SELECT @cond = '' WHERE t.Deleted=''''0''''''
-- IF(@CompanyID>0 OR @ProductionId>0 OR @AgencyId>0 OR @DDLforProduction=''1'')
-- BEGIN
-- IF(@CompanyID>0)
-- BEGIN
-- SELECT @cond = @cond + '' AND prod.CompanyId = '' + cast(@CompanyId as varchar(20))
-- END
--
-- IF(@AgencyId>0)
-- BEGIN
-- SELECT @cond = @cond + '' AND prod.AgencyId = '' + cast(@AgencyId as varchar(20))
-- END
--
-- IF(@ProductionId>0)
-- BEGIN
-- SELECT @cond = @cond + '' AND prod.ProductionId = '' + cast(@ProductionId as varchar(20))
-- SELECT @cond = @cond + '' AND prod.AgencyId=agy.AgencyId''
-- END
--
-- SELECT @qry= ''Select distinct t.TalentId, t.TalentName
-- from tblTalent t
-- INNER JOIN
-- tblPerson as p ON
-- p.AccountID= '' + cast(@AccountId as varchar(20))
-- SELECT @qry = @qry + '' AND p.Deleted=0
-- INNER JOIN
-- tblMapPersonProfile as pp ON
-- pp.PersonId = p.PersonID
-- AND pp.Deleted=''''0''''
-- INNER JOIN
-- tblTalentAccess AS a ON
-- p.PersonID=a.PersonID AND
-- t.TalentId=a.TalentId
-- AND a.Deleted=''''0''''
-- INNER JOIN tblProduction as prod ON
-- prod.Deleted=''''0''''
-- INNER JOIN
-- tblAgency as agy ON
-- agy.AgencyId=prod.AgencyId AND agy.Deleted=''''0''''
-- INNER JOIN tblJob AS j ON
-- j.ProductionID=prod.ProductionID AND j.TalentId=t.TalentId''
-- END
-- ELSE
BEGIN
SELECT @qry= ''Select distinct t.TalentId, t.TalentName
from tblTalent t
INNER JOIN
tblPerson as p ON
p.AccountID='' + cast(@AccountId as varchar(20))
SELECT @qry = @qry + '' AND p.Deleted=0
INNER JOIN
tblMapPersonProfile as pp ON
pp.PersonId = p.PersonID
AND pp.Deleted=''''0''''
INNER JOIN
tblTalentAccess AS a ON
p.PersonID=a.PersonID AND
t.TalentId=a.TalentId
AND a.Deleted=''''0''''
INNER JOIN tblProduction as prod ON
prod.Deleted=''''0''''''
END
SELECT @qry = @qry + @cond
EXEC(@qry)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralLogInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Sep/2007
-- Description: Insert log when any account user logs on
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralLogInsert]
-- Add the parameters for the stored procedure here
@UserId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO tblCentralLog(UserId,LoginDateTime)
VALUES(@UserId,getdate())
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralLogout]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Sep/2007
-- Description: This make the entry for logout in tblLog
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralLogout]
-- Add the parameters for the stored procedure here
@CentralLogId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblCentralLog
SET LogOutDateTime=getdate()
WHERE CentralLogId=@CentralLogId
IF (@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblUpdateStatus]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet
-- Create date: 23/10/2007
--Modified date: 20/9/2007
-- Description: For Login Process
-- =============================================
CREATE procedure [dbo].[USPTblUpdateStatus]
(
-- Add the parameters for the stored procedure here
@Id int,
@ContactId int,
@Profile varchar(50),
@Result int Output
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Begin tran
if @Profile=''Agency''
Begin
Update tblAgencycontact set [Default]=''true'' where AgencyId=@Id
and ContactId=@ContactId
Update tblAgencycontact set [Default]=''false'' where AgencyId=@Id and
ContactId <> @ContactId
End
Else If @Profile=''Company''
Begin
Update tblCompanycontact set [Default]=''true'' where CompanyId=@Id
and ContactId=@ContactId
Update tblCompanycontact set [Default]=''false'' where CompanyId=@Id and
ContactId <> @ContactId
End
Else If @Profile=''Talent''
Begin
Update tblTalentcontact set [Default]=''true'' where TalentId=@Id
and ContactId=@ContactId
Update tblTalentcontact set [Default]=''false'' where TalentId=@Id and
ContactId <> @ContactId
End
if @@Error<>0
Begin
Rollback tran
set @Result=0
End
else
Begin
Commit tran
set @Result=1
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCurrencySelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 11/9/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCurrencySelect]
AS
SET NOCOUNT ON
SELECT CurrencyId,CurrencyName,BaseCurrency,
Status=CASE deleted When ''False'' then ''Active''
Else
''InActive''
End
from tblCurrency
Where deleted=''False''
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblCentralUserFullName]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Oct/2007
-- Description: Retruns FullNAme of the user who logged On
-- =============================================
CREATE PROCEDURE [dbo].[UsptblCentralUserFullName]
-- Add the parameters for the stored procedure here
@UserId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT FirstName + '' '' + LastName AS FullName
FROM tblCentralUserPersonalInfo
WHERE
UserId=@UserId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSearchTalentByDynaAttributes]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14/Jan/2008
-- Description: Search Talents by Dynamic Attributes
-- Modified By: Jatin
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSearchTalentByDynaAttributes] --8,''Like'',''red'',null,null,null,null,null,null,1
-- Add the parameters for the stored procedure here
@Param1 INT,
@Op1 VARCHAR(10),
@Value1 VARCHAR(100),
@Param2 INT,
@Op2 VARCHAR(10),
@Value2 VARCHAR(100),
@Param3 INT,
@Op3 VARCHAR(10),
@Value3 VARCHAR(100),
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(2000)
DECLARE @Condition VARCHAR(1000)
DECLARE @joinQry VARCHAR(2000)
IF @Op1=''Like'' OR @Op1=''Not Like''
SET @Value1='' ''''%'' + @Value1 + ''%''''''
IF @Op2=''Like'' OR @Op2=''Not Like''
SET @Value2='' ''''%'' + @Value2 + ''%''''''
IF @Op3=''Like'' OR @Op3=''Not Like''
SET @Value3='' ''''%'' + @Value3 + ''%''''''
SET @Query=''SELECT t.talentId,t.TalentName,CountryName FROM tblTalent AS t
INNER JOIN tblTalentAccess ta
INNER JOIN tblPerson p
ON ta.PersonId=p.PersonId
AND p.AccountId='' + Cast(@AccountId as varchar(30)) +
'' ON t.TalentId=ta.TalentId
INNER JOIN tblCountry c
ON t.Country=c.CountryId''
SET @Condition = '' WHERE t.Deleted=''''False''''''
SET @joinQry = '' ''
IF (@Param1 <> '''' AND @Op1 <> '''' AND @Value1 <> '''')
BEGIN
IF @Op1=''Like'' OR @Op1=''Not Like''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t1 ON
t1.attributeId='' + Cast(@Param1 as varchar(10)) +
'' and t1.value ''+ Cast(@Op1 as varchar(10)) + Cast(@Value1 as varchar(110)) + '' AND t1.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t1 ON
t1.attributeId='' + Cast(@Param1 as varchar(10)) +
'' and CAST(t1.value AS FLOAT) ''+ Cast(@Op1 as varchar(10)) + Cast(@Value1 as varchar(110)) + '' AND t1.TalentId=t.TalentId ''
END
END
IF (@Param2 <> '''' AND @Op2 <> '''' AND @Value2 <> '''')
BEGIN
IF @Op2=''Like'' OR @Op2=''Not Like''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t2 ON
t2.attributeId='' + Cast(@Param2 as varchar(10)) +
'' and t2.value ''+ Cast(@Op2 as varchar(10)) + Cast(@Value2 as varchar(110)) + '' AND t2.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t2 ON
t2.attributeId='' + Cast(@Param2 as varchar(10)) +
'' and CAST(t2.value AS FLOAT) ''+ Cast(@Op2 as varchar(10)) + Cast(@Value2 as varchar(110)) + '' AND t2.TalentId=t.TalentId ''
END
END
IF (@Param3 <> '''' AND @Op3 <> '''' AND @Value3 <> '''')
BEGIN
IF @Op3=''Like'' OR @Op3=''Not Like''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t3 ON
t3.attributeId='' + Cast(@Param3 as varchar(10)) +
'' and t3.value ''+ Cast(@Op3 as varchar(10)) + Cast(@Value3 as varchar(110)) + '' AND t3.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t3 ON
t3.attributeId='' + Cast(@Param3 as varchar(10)) +
'' and CAST(t3.value AS FLOAT) ''+ Cast(@Op3 as varchar(10)) + Cast(@Value3 as varchar(110)) + '' AND t3.TalentId=t.TalentId ''
END
END
IF @joinQry <> ''''
BEGIN
SET @Query = @Query + @joinQry + @Condition
END
ELSE
BEGIN
SET @Query = @Query + @Condition
END
--PRINT(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblPersonSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir
-- Create date: 4/9/2005
-- Description: For Login Process
-- =============================================
CREATE PROCEDURE [dbo].[UspTblPersonSelect]
-- Add the parameters for the stored procedure here
@UserName varchar(50) = 0,
@Password varchar(100) = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT PersonId
FROM tblPerson
WHERE PersonName=@UserName
AND
Password=@Password
And
Deleted=0
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountProfilesBySearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 11/Oct/2007
-- Description: Selected Profiles on seach
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountProfilesBySearch] --null,null
-- Add the parameters for the stored procedure here
@ProfileName VARCHAR(50),
@InActive INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @Query as VARCHAR(1000)
Declare @Condition as VARCHAR(1000)
IF @ProfileName <> ''''
BEGIN
Select @Condition = ''AND ProfileName like ''''%'' + @ProfileName + ''%'''' ''
END
IF(@InActive = 0 Or @InActive = 1)
BEGIN
IF(@Condition<>'''')
BEGIN
SELECT @Condition = @Condition + '' AND InActive='' + Cast(@InActive as VARCHAR(5))
END
ELSE
BEGIN
SELECT @Condition = '' AND InActive='' + Cast(@InActive as VARCHAR(5))
END
END
SELECT @Query = ''SELECT p.ProfileId ,p.ProfileName,
--Convert(VARCHAR,p.DateModified,106) as DateModified,
Status=CASE p.InActive When ''''False'''' then ''''Active''''
Else
''''InActive''''
END
--,c.UserName as ModifiedBy
FROM tblProfile p
inner join
(Select ca.userid,FirstName+'''' ''''+LastName as UserName
From tblCentralAdmin ca
inner join tblCentralUserPersonalInfo ci
on
ca.userid=ci.userid )c
on p.ModifiedBy = c.UserId
WHERE p.Deleted=''''False''''''
IF @Condition <> ''''
BEGIN
SELECT @Query = @Query + @Condition
END
exec(@Query)
--print(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblReceiptSelectAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin Kumar
-- Create date: 05/12/2007
-- Modified date: 05/02/2008
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[USPTblReceiptSelectAll] --''1'',''4'',''1'',''1''
-- Add the parameters for the stored procedure here
@AccountId INT,
@ProductionId INT=NULL,
@AgencyID INT=NULL,
@CompanyID INT=NULL
AS
BEGIN
DECLARE
@query varchar(2000),
@condition varchar(500)
SELECT @condition = '' WHERE r.Deleted=''''0'''' AND r.AccountId='' + cast(@AccountId as varchar(10))
IF(@AgencyID>0)
BEGIN
SELECT @condition = @condition + '' AND ag.AgencyID = '' + cast(@AgencyID as varchar(10))
END
IF(@ProductionId>0)
BEGIN
SELECT @condition = @condition + '' AND p.ProductionId = '' + cast(@ProductionId as varchar(10))
END
IF(@CompanyID>0)
BEGIN
SELECT @condition = @condition + '' AND c.CompanyID = '' + cast(@CompanyID as varchar(10))
END
SELECT @query= ''SELECT Distinct r.datemodified,r.ReceiptId, p.ProductionTitle, r.Description,
r.Posted, CASE WHEN ((select Count(*) from tblAllocation AS a WHERE a.ReceiptId=r.ReceiptId AND a.Posted=0)>0)
THEN ''''true'''' ELSE ''''false'''' END AS IsAllocation,
CASE WHEN ((select Count(*) from tblLiability AS l WHERE l.ReceiptId=r.ReceiptId)>0)
THEN ''''true'''' ELSE ''''false'''' END AS IsLiability
FROM tblReceipt AS r
INNER JOIN tblProduction AS p ON
p.ProductionId=r.ProductionId AND
p.AccountId='' + cast(@AccountId as varchar(10))
SELECT @query= @query + '' INNER JOIN tblAgency AS ag ON
ag.AgencyId=p.AgencyId
INNER JOIN tblCompany AS c ON
c.CompanyId=p.CompanyId
INNER JOIN tblAllocation AS a ON
a.ReceiptId=r.ReceiptId ''
SELECT @query= @query + @condition + '' order by r.datemodified desc ''
EXEC(@query)
END'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCompanySearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 261007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCompanySearch]
-- Add the parameters for the stored procedure here
@CompanyName varchar(100) ,
@CountryId int ,
@AccountId int,
@Status bit=0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Declare @Query as varchar(2000)
set @Query='' Select comp.CompanyId,comp.Companyname,cc.Telephone,comp.Deleted,Countryname from tblcompany comp left join tblcompanycontact cc on comp.companyid=cc.companyid left join tblcountry cntry on
comp.countryid=cntry.countryid where comp.CompanyId in(Select CompanyId from tblCompanyAcess a inner join tblperson p on
a.PersonId=p.PersonId where AccountId=''+convert(varchar,@AccountId)+''and comp.Deleted=''+ convert(varchar,@Status)+'')'' + ''and cc.[Default]=1''
IF(@CompanyName !='''')
BEGIN
SET @Query=@Query + ''and comp.CompanyName like''''%'' + @CompanyName+''%''''''
END
IF (@CountryId > 0)
BEGIN
SET @Query=@Query + ''and comp.CountryId='' + convert(varchar,@CountryId)
END
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCompanyContactSearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 260907
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCompanyContactSearch]
-- Add the parameters for the stored procedure here
@Title varchar(50) ,
@Mobile varchar(20),
@Telephone varchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Declare @Query as varchar(2000)
SET @Query='' Select [CompanyId]
,[ContactId]
,[CompanyName]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
,[Deleted]
,[DateModified]
,[ModifiedBy] from tblcompanyContact where ContactId is not null ''
IF (@Title !='''')
Begin
set @Query=@Query + ''and Title='''''' + @Title+''''''''
End
IF (@Mobile !='''')
Begin
set @Query=@Query + ''and Mobile='''''' + @Mobile+''''''''
End
IF (@Telephone !='''')
Begin
set @Query=@Query + ''and Telephone='''''' +@Telephone+''''''''
End
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblExceptionLogInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- =============================================
-- Author: Gurnek Singh
-- Create date: 09/08/2007
-- Description: Insert log entry into TbleExceptionLog table.
-- =============================================
CREATE PROCEDURE [dbo].[UspTblExceptionLogInsert]
(
@EventID int,
@Priority int,
@Severity nvarchar(32),
@Title nvarchar(256),
@Timestamp datetime,
@MachineName nvarchar(32),
@AppDomainName nvarchar(512),
@ProcessID nvarchar(256),
@ProcessName nvarchar(512),
@ThreadName nvarchar(512),
@Win32ThreadId nvarchar(128),
@Message nvarchar(1500),
@FormattedMessage ntext,
@LogId int OUTPUT
)
AS
INSERT INTO [tblExceptionLog] (
EventID,
Priority,
Severity,
Title,
[Timestamp],
MachineName,
AppDomainName,
ProcessID,
ProcessName,
ThreadName,
Win32ThreadId,
Message,
FormattedMessage
)
VALUES (
@EventID,
@Priority,
@Severity,
@Title,
@Timestamp,
@MachineName,
@AppDomainName,
@ProcessID,
@ProcessName,
@ThreadName,
@Win32ThreadId,
@Message,
@FormattedMessage)
SET @LogID = @@IDENTITY
RETURN @LogID
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSelectAccountNames]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 15 Oct 2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSelectAccountNames]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT AccountId,Name
FROM tblAccount
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralProfileSelectAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13/Sep/2007
-- Description: Returns all central user profiles
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralProfileSelectAll]
-- Add the parameters for the stored procedure here
@ProfileId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(1000)
DECLARE @Cond VARCHAR(500)
IF @ProfileId>=2
BEGIN
SET @Cond='' AND
CentralProfileId>2''
END
ELSE
BEGIN
IF @ProfileId = 1
BEGIN
SET @Cond='' AND
CentralProfileId>1''
END
END
SET @Query= ''SELECT CentralProfileId,CentralProfileName
FROM tblCentralProfile
WHERE Deleted=''''False''''''
IF @Cond<>''''
BEGIN
SET @Query=@Query+@Cond
END
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSearchTalentByDynaAttributes1]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14/Jan/2008
-- Description: Search Talents by Dynamic Attributes
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSearchTalentByDynaAttributes1] --3,''>'',120,null,null,null,null,null,null,1
-- Add the parameters for the stored procedure here
@Param1 INT,
@Op1 VARCHAR(10),
@Value1 VARCHAR(100),
@Param2 INT,
@Op2 VARCHAR(10),
@Value2 VARCHAR(100),
@Param3 INT,
@Op3 VARCHAR(10),
@Value3 VARCHAR(100),
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(2000)
DECLARE @Condition VARCHAR(1000)
DECLARE @joinQry VARCHAR(2000)
IF @Op1=''Like'' OR @Op1=''Not Like''
SET @Value1='' ''''%'' + @Value1 + ''%''''''
IF @Op2=''Like'' OR @Op2=''Not Like''
SET @Value2='' ''''%'' + @Value2 + ''%''''''
IF @Op3=''Like'' OR @Op3=''Not Like''
SET @Value3='' ''''%'' + @Value3 + ''%''''''
SET @Query=''SELECT t.talentId,t.TalentName,CountryName FROM tblTalent AS t
INNER JOIN tblTalentAccess ta
INNER JOIN tblPerson p
ON ta.PersonId=p.PersonId
AND p.AccountId='' + Cast(@AccountId as varchar(30)) +
'' ON t.TalentId=ta.TalentId
INNER JOIN tblCountry c
ON t.Country=c.CountryId''
SET @Condition = '' WHERE t.Deleted=''''False''''''
IF (@Param1 <> '''' AND @Op1 <> '''' AND @Value1 <> '''')
BEGIN
IF @joinQry<>''''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t1 ON
t1.attributeId='' + Cast(@Param1 as varchar(10)) +
'' and t1.value ''+ Cast(@Op1 as varchar(10)) + Cast(@Value1 as varchar(110)) + '' AND t1.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = '' INNER JOIN tblTalentAttribute AS t1 ON
t1.attributeId='' + Cast(@Param1 as varchar(10)) +
'' and t1.value ''+ Cast(@Op1 as varchar(10)) + Cast(@Value1 as varchar(110)) + '' AND t1.TalentId=t.TalentId ''
END
END
IF (@Param2 <> '''' AND @Op2 <> '''' AND @Value2 <> '''')
BEGIN
IF @joinQry<>''''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t2 ON
t2.attributeId='' + Cast(@Param2 as varchar(10)) +
'' and t2.value ''+ Cast(@Op2 as varchar(10)) + Cast(@Value2 as varchar(110)) + '' AND t2.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = '' INNER JOIN tblTalentAttribute AS t2 ON
t2.attributeId='' + Cast(@Param2 as varchar(10)) +
'' and t2.value ''+ Cast(@Op2 as varchar(10)) + Cast(@Value2 as varchar(110)) + '' AND t2.TalentId=t.TalentId ''
END
END
IF (@Param3 <> '''' AND @Op3 <> '''' AND @Value3 <> '''')
BEGIN
IF @joinQry<>''''
BEGIN
SET @joinQry = @joinQry + '' INNER JOIN tblTalentAttribute AS t3 ON
t3.attributeId='' + Cast(@Param3 as varchar(10)) +
'' and t3.value ''+ Cast(@Op3 as varchar(10)) + Cast(@Value3 as varchar(110)) + '' AND t3.TalentId=t.TalentId ''
END
ELSE
BEGIN
SET @joinQry = '' INNER JOIN tblTalentAttribute AS t3 ON
t3.attributeId='' + Cast(@Param3 as varchar(10)) +
'' and t3.value ''+ Cast(@Op3 as varchar(10)) + Cast(@Value3 as varchar(110)) + '' AND t3.TalentId=t.TalentId ''
END
END
IF @joinQry <> ''''
BEGIN
SET @Query = @Query + @joinQry + @Condition
END
ELSE
BEGIN
SET @Query = @Query + @Condition
END
PRINT(@Query)
--EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblAgencyContactSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 170907
-- Description: View All Contacts of an Agency
-- =============================================
CREATE procedure [dbo].[USPTblAgencyContactSelect]
-- Add the parameters for the stored procedure here
@AgencyID int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SELECT [AgencyId]
,[ContactId]
,[AgencyName]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
,[Deleted]
,[DateModified]
,[ModifiedBy] FROM tblAgencycontact WHERE AgencyID=@AgencyID and Deleted=0 order by DateModified desc
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USpMAxAgencyId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET
-- Create date: 160108
-- Description: PICKUP MAXIMUM AGENCYID FROM AGENCY TABLE
-- =============================================
CREATE PROCEDURE [dbo].[USpMAxAgencyId]
-- Add the parameters for the stored procedure here
@Result int Output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Set @Result =(Select max(agencyid) from tblagency)
return @Result
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspAccountLogIn]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: JAGSIR SINGH
-- Create date: 5 sep 2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspAccountLogIn]
@UserName VARCHAR(50),
@Password VARCHAR(100)
AS
SET NOCOUNT ON
DECLARE @CH INT
DECLARE @LogId INT
DECLARE @PersonId INT
SELECT p.PersonId,p.AccountId,PersonName,p.Email,p.FirstName
FROM tblPerson p,tblAccount a
WHERE PersonName=@UserName
AND
Password=@Password
AND
p.Deleted=''False''
AND
p.AccountId=a.AccountId
And
a.Deleted=''False''
SELECT @CH = COUNT(*)
FROM tblPerson
WHERE PersonName=@UserName
AND
Password=@Password
AND
Deleted=''False''
IF(@CH>0)
BEGIN
BEGIN TRAN
SELECT @PersonId=PersonId
FROM tblPerson
WHERE PersonName=@UserName
AND
Password=@Password
AND
Deleted=''False''
UPDATE tblPerson
SET LastLogin=getdate()
WHERE PersonName=@UserName
AND
Password=@Password
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SELECT mp.ProfileId,p.ProfileName
FROM tblMapPersonProfile mp,
tblProfile p
WHERE PersonId=@PersonId
AND
mp.ProfileId=p.ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblUpdateAccountStatus]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet
-- Create date: 23/10/2007
--Modified date: 20/9/2007
-- Description: For Login Process
-- =============================================
CREATE procedure [dbo].[USPTblUpdateAccountStatus]--35,7,''Talent'','''',
(
-- Add the parameters for the stored procedure here
@Id int,
@AccountId int,
@Profile varchar(50),
@Type varchar(30),
@Result int Output
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @Query as varchar(2000)
Begin tran
if @Profile=''Agency''
Begin
Set @Query=''Update tblAgencyAccount set ''+ @Type+''Default=''''true'''' where AgencyId=''+cast(@Id as varchar)
+'' and AgencyAccountId=''+cast(@AccountId as varchar)
exec(@Query)
Set @Query=''Update tblAgencyAccount set ''+ @Type+''Default=''''false'''' where AgencyId=''+cast(@Id as varchar)
+ '' and AgencyAccountId <>'' +cast(@AccountId as varchar)
exec(@Query)
End
Else If @Profile=''Talent''
Begin
Set @Query=''Update tblTalentAccount set [Default]=''''true'''' where TalentId=''+cast(@Id as varchar)
+'' and TalentAccountId=''+cast(@AccountId as varchar)
exec(@Query)
Set @Query=''Update tblTalentAccount set [Default]=''''false'''' where TalentId=''+cast(@Id as varchar)
+'' and TalentAccountId <> ''+cast(@AccountId as varchar)
exec(@Query)
End
if @@Error<>0
Begin
Rollback tran
set @Result=0
End
else
Begin
Commit tran
set @Result=1
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSearchTalentsByAttributes]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 2/Jan/2008
-- Description: Search Talents by Attributes
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSearchTalentsByAttributes] --172,67,''Fair'',''Black'',''White'',''F'',1
-- Add the parameters for the stored procedure here
@Height INT,
@Weight INT,
@Color VARCHAR(50),
@HairColor VARCHAR(50),
@EyeColor VARCHAR(50),
@Sex CHAR(1),
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(2000)
DECLARE @Condition VARCHAR(2000)
IF @Height <> 0
BEGIN
SELECT @Condition='' WHERE ta.Height = '' + CAST(@Height AS VARCHAR(10))
END
IF @Weight <> 0
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.Weight = '' + CAST(@Weight AS VARCHAR(10))
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.Weight = '' + CAST(@Weight AS VARCHAR(10))
END
END
IF @Color <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.Color = '''''' + @Color + ''''''''
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.Color = '''''' + @Color + ''''''''
END
END
IF @HairColor <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.HairColor = '''''' + @HairColor + ''''''''
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.HairColor = '''''' + @HairColor + ''''''''
END
END
IF @EyeColor <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.EyeColor = '''''' + @EyeColor + ''''''''
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.EyeColor = '''''' + @EyeColor + ''''''''
END
END
IF @Sex <> ''''
BEGIN
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ta.Sex = '''''' + @Sex + ''''''''
END
ELSE
BEGIN
SELECT @Condition='' WHERE ta.Sex = '''''' + @Sex + ''''''''
END
END
IF @Condition <> ''''
BEGIN
SELECT @Query= ''SELECT t.TalentId,TalentName,CountryName
FROM tblTalent t
INNER JOIN tblTalentAccess tac
INNER JOIN tblPerson p
ON tac.PersonId=p.PersonId
AND p.AccountId=''+ CAST(@AccountId AS VARCHAR(10))+
'' AND p.Deleted=''''False''''
ON t.TalentId=tac.TalentId
INNER JOIN tblTalentAttribute ta
ON t.TalentId=ta.TalentId
AND ta.Deleted=''''False''''
INNER JOIN tblCountry c
ON t.Country=c.CountryId'' + @Condition
END
ELSE
BEGIN
SELECT @Query= ''SELECT t.TalentId,TalentName,CountryName
FROM tblTalent t
INNER JOIN tblTalentAccess tac
INNER JOIN tblPerson p
ON tac.PersonId=p.PersonId
AND p.AccountId=''+Cast(@AccountId as varchar(10))+
'' AND p.Deleted=''''False''''
ON t.TalentId=tac.TalentId
INNER JOIN tblCountry c
ON t.Country=c.CountryId''
END
--PRINT(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblTalentSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2005
--Modified date: 20/9/2007
-- Description: For Login Process
-- =============================================
CREATE procedure [dbo].[USPTblTalentSelect]--1,5
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@Country varchar(20) = NULL,
@Name varchar(100) = NULL,
@LastActivity datetime = NULL,
@TalentId int=NULL
)
AS
DECLARE
@query varchar(1000),
@condition varchar(500)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT @condition = '' WHERE t.Deleted=0 ''
IF(@Name<>'''')
BEGIN
SELECT @condition = @condition + '' AND (t.TalentName like ''''%'' + @Name + ''%'''') ''
END
IF(@Country>0)
BEGIN
SELECT @condition = @condition + '' AND t.Country = '' + cast(@Country as varchar(15))
END
IF(@TalentId>0)
BEGIN
SELECT @condition = @condition + '' AND t.TalentId = '' + cast(@TalentId as varchar(15))
END
IF(@LastActivity<>'''')
BEGIN
SELECT @condition = @condition + '' AND p.LastLogin >= '''''' + cast(@LastActivity as varchar(30)) + ''''''''
END
-- IF(@condition<>'''')
-- BEGIN
-- SELECT @condition = '' WHERE '' + @condition, p.PersonName, p.Email, p.LastLogin, tc.Telephone, tc.Mobile,
-- END
SELECT @query= ''SELECT
t.TalentID ,c.CountryName, c.CountryId,
t.TalentName,
CASE t.Deleted
WHEN ''''true'''' THEN ''''InActive''''
ELSE ''''Active''''
END as Status
FROM
tblTalent AS t
INNER JOIN
tblCountry AS c ON
c.CountryID=t.Country
LEFT outer JOIN
tblTalentContact AS tc ON
tc.TalentId=t.TalentId AND TC.[Default]=''''1''''
INNER JOIN
tblPerson AS p ON p.AccountID=''
SELECT @query= @query + cast(@AccountID as varchar(20))
SELECT @query= @query + '' AND p.Deleted=0
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId=''
SELECT @query= @query + cast(@ProfileId as varchar(20))
SELECT @query= @query + '' AND
pp.PersonId = p.PersonID
INNER JOIN
tblTalentAccess AS a ON p.PersonID=a.PersonID AND
t.TalentId=a.TalentId ''
IF(@condition<>'''')
BEGIN
SELECT @query= @query + @condition + '' order by t.DateModified desc ''
END
exec(@query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAccountSelectByUrl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 7-Sep, 2007
-- Description: Retrieve the AccountId if the url exists
-- =============================================
CREATE PROCEDURE [dbo].[UsptblAccountSelectByUrl]
-- Add the parameters for the stored procedure here
@url VARCHAR(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT AccountId,Deleted
FROM tblAccount
WHERE url=@url
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspViewCentralUsersLogOnHistory]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 17/Sep/2007
-- Description: To view the log history of central uesrs
-- =============================================
CREATE PROCEDURE [dbo].[UspViewCentralUsersLogOnHistory] --null,null,''17/Feb/2008'',''20/Feb/2008''
-- Add the parameters for the stored procedure here
@CentralProfileId INT,
@UserName VARCHAR(50),
@FromDate datetime,
@ToDate datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Declare @Query as VARCHAR(2000)
Declare @Condition as VARCHAR(1000)
IF @CentralProfileId <> ''''
BEGIN
Select @Condition = '' WHERE a.CentralProfileId = '' + Cast(@CentralProfileId as varchar(10))
END
IF @UserName <> ''''
IF @Condition<>''''
BEGIN
SELECT @Condition = @Condition + '' AND t.UserName like ''''%'' + @UserName + ''%'''' ''
END
ELSE
BEGIN
SELECT @Condition = '' WHERE t.UserName like ''''%'' + @UserName + ''%'''' ''
END
IF @FromDate<>'''' AND @ToDate<>''''
BEGIN
DECLARE @DateFrom datetime
DECLARE @DateTo datetime
SET @DateFrom=Convert(varchar,@FromDate,101)
SET @DateTo=Convert(varchar,@ToDate,101)
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND ((datepart(day,logindatetime) between datepart(day,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(day,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(month,logindatetime) between datepart(month,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(month,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(year,logindatetime) between datepart(year,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(year,'''''' + convert(varchar,@DateTo,106) + '''''' )))''
END
ELSE
BEGIN
SELECT @Condition = '' WHERE ((datepart(day,logindatetime) between datepart(day,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(day,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(month,logindatetime) between datepart(month,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(month,'''''' + convert(varchar,@DateTo,106) + '''''' ))
AND (datepart(year,logindatetime) between datepart(year,'''''' + convert(varchar,@DateFrom,106) + '''''') AND datepart(year,'''''' + convert(varchar,@DateTo,106) + '''''' )))''
END
END
ELSE IF @ToDate<>''''
BEGIN
SET @DateTo=Convert(varchar,@ToDate,101)
IF @Condition <> ''''
BEGIN
SELECT @Condition = @Condition + '' AND convert(varchar,logindatetime,106) <= '''''' + convert(varchar,@DateTo,106) +''''''''
END
ELSE
BEGIN
SELECT @Condition = '' WHERE convert(varchar,logindatetime,106) <='''''' + convert(varchar,@DateTo,106) +''''''''
END
END
SELECT @Query=''SELECT a.UserId,t.UserName,Email,CentralProfileName,
Convert(varchar(17),logindatetime,113) as logindate,
Convert(varchar,logindatetime,108) as logintime,
ISNULL(Convert(varchar(40),(Convert(varchar(17),logoutdatetime,113))),''''Not Available'''') as logoutdate,
Convert(varchar,logoutdatetime,108) as logouttime
FROM tblcentraladmin a
INNER JOIN
tblcentralprofile c
ON
a.centralprofileid=c.centralprofileid
INNER JOIN
tblcentrallog l
ON
a.userid=l.userid
INNER JOIN
(SELECT aa.UserId,FirstName+'''' ''''+LastName as UserName
FROM tblCentralAdmin aa
INNER JOIN tblCentralUserPersonalInfo C
ON aa.userid=C.UserId) t
ON
a.UserId=t.UserId''
IF @Condition<>''''
BEGIN
SELECT @Query=@Query+@Condition
END
SELECT @Query=@Query+ '' order by logindatetime desc''
--print (@Query)
exec(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralAdminSelectUserDetail]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13/Sep/2007
-- Description: Get All Details of the user
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralAdminSelectUserDetail] --166
-- Add the parameters for the stored procedure here
@UserId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Query VARCHAR(500)
SET @Query= ''SELECT Email,a.CentralProfileId,a.Deleted,FirstName,LastName,
Telephone,Mobile,Fax,PostalAddress,BusinessAddress,p.CountryId,pr.CentralProfileName,c.CountryName
FROM tblCentralAdmin a ,tblCentralUserPersonalInfo p
,tblcountry c,tblcentralprofile pr
WHERE p.countryid=c.Countryid
and a.UserID=p.UserId
and a.centralprofileid=pr.centralprofileid
and a.UserId = '' + CAST(@UserId AS VARCHAR(50))
--PRINT(@Query)
EXEC(@Query)
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAgencyByContactId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 120907
-- Description: SELECT AGENCY DETAIL BY CONTACTID
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAgencyByContactId]
@ContactId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT [AgencyId]
,[ContactId]
,[AgencyName]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
,[Deleted]
,[DateModified]
,[ModifiedBy] FROM tblAgencyContact WHERE Contactid=@ContactId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblBatchSelectOld]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- AUTHOR : Harendra
CREATE PROCEDURE [dbo].[UspTblBatchSelectOld] --204,1,30
@BatchId int,
@AccountId int,
@AgencyId int,
@Description VARCHAR(100)
AS
/* SET NOCOUNT ON */
if (@BatchId = 0)
begin
IF (@AgencyID = 0)
BEGIN
SELECT DISTINCT
tblBatch.AgencyId, tblAgency.AgencyName, CONVERT(varchar, tblBatch.BillToDate, 106) AS BillToDate,
tblBatch.BatchId,tblBatch.Description, tblBatch.IncludeJobs,
tblBatch.IncludeAgencyFees, tblBatch.IncludeDisbursements,
case tblBatch.status
when 1 then ''Normal''
when 2 then ''Listed''
when 3 then ''Posted''
else ''Normal''
end as status
FROM tblBatch INNER JOIN
tblAgency ON tblBatch.AgencyId = tblAgency.AgencyId
inner Join tblBatchStatus on tblBatch.status=tblBatchStatus.BatchstatusId
where tblBatch.AccountId=@AccountId
AND tblBatch.Deleted = ''0''
END
ELSE
BEGIN
SELECT DISTINCT
tblBatch.AgencyId, tblAgency.AgencyName, CONVERT(varchar, tblBatch.BillToDate, 106) AS BillToDate,
tblBatch.BatchId,tblBatch.Description, tblBatch.IncludeJobs,
tblBatch.IncludeAgencyFees, tblBatch.IncludeDisbursements,
case tblBatch.status
when 1 then ''Normal''
when 2 then ''Listed''
when 3 then ''Posted''
else ''Normal''
end as status
FROM tblBatch INNER JOIN
tblAgency ON tblBatch.AgencyId = tblAgency.AgencyId
inner Join tblBatchStatus on tblBatch.status=tblBatchStatus.BatchstatusId
where tblBatch.AccountId=@AccountId AND tblBatch.AgencyId=@AgencyId
AND tblBatch.Deleted = ''0''
END
end
else
begin
IF (@AgencyID =0)
BEGIN
SELECT DISTINCT
tblBatch.AgencyId, tblAgency.AgencyName, CONVERT(varchar, tblBatch.BillToDate, 106) AS BillToDate,
tblBatch.BatchId,tblBatch.Description, tblBatch.IncludeJobs,
tblBatch.IncludeAgencyFees, tblBatch.IncludeDisbursements,
case tblBatch.status
when 1 then ''Normal''
when 2 then ''Listed''
when 3 then ''Posted''
else ''Normal''
end as status
FROM tblBatch INNER JOIN
tblAgency ON tblBatch.AgencyId = tblAgency.AgencyId
inner Join tblBatchStatus on tblBatch.status=tblBatchStatus.BatchstatusId
where tblBatch.AccountId=@AccountId
AND tblBatch.Deleted = ''0'' and tblBatch.BatchId=@BatchId
END
ELSE
BEGIN
SELECT DISTINCT
tblBatch.AgencyId, tblAgency.AgencyName, CONVERT(varchar, tblBatch.BillToDate, 106) AS BillToDate,
tblBatch.BatchId,tblBatch.Description, tblBatch.IncludeJobs,
tblBatch.IncludeAgencyFees, tblBatch.IncludeDisbursements,
case tblBatch.status
when 1 then ''Normal''
when 2 then ''Listed''
when 3 then ''Posted''
else ''Normal''
end as status
FROM tblBatch INNER JOIN
tblAgency ON tblBatch.AgencyId = tblAgency.AgencyId
inner Join tblBatchStatus on tblBatch.status=tblBatchStatus.BatchstatusId
where tblBatch.AccountId=@AccountId AND tblBatch.AgencyId=@AgencyId
AND tblBatch.Deleted = ''0'' and tblBatch.BatchId=@BatchId
END
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblBatchStatusSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 26/Nov/2007
-- Description: Select Batch Status
-- =============================================
CREATE PROCEDURE [dbo].[UspTblBatchStatusSelect]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT BatchStatusId,BatchStatus
FROM tblBatchStatus
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblJobIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 26/9/2005
-- Description: For Production Creation
-- =============================================
CREATE procedure [dbo].[UspTblJobIsDeletedUpdate]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@JobID int,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
SET @Result=0
BEGIN TRAN
UPDATE tblJob
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
JobID=@JobID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblJob'',''Delete'',''Job Deleted'',@Date,@ModifiedBy,@JobID,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblUpdatePayReq]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14 Nov 2007
-- Description: Update the request details for payment from talent
-- =============================================
CREATE PROCEDURE [dbo].[UspTblUpdatePayReq] --14,2,7,1222,1,114,null
-- Add the parameters for the stored procedure here
@JobId INT,
@JobPaymentId INT,
@PaymentTypeId INT,
@TalentAccountId INT,
@Value INT,
@ModifiedBy INT,
@AccountId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Check INT
BEGIN TRAN
SET @Check= (SELECT COUNT(*)
FROM tblJobPayment
WHERE JobId=@JobId
AND
AccountID=@AccountId
AND
TalentAccountId=@TalentAccountId
AND
JobPaymentId<>@JobPaymentId
AND
Deleted=''False'')
IF @Check = 0
BEGIN
UPDATE tblJobPayment SET PaymentTypeId=@PaymentTypeId,
TalentAccountId=@TalentAccountId,
Value=@Value,
ModifiedBy=@ModifiedBy,
DateModified=getdate()
WHERE JobPaymentId=@JobPaymentId
AND
AccountId=@AccountId
SET @Result = 1
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblJobPayment'',''Request Updated'',''Payment Request Updated'',@Date,@ModifiedBy,@JobPaymentId,@AccountId
END
ELSE
BEGIN
SET @Result = 2
END
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
SET @Result = 0
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspInvoiceStatus]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <26/11/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspInvoiceStatus]
-- Add the parameters for the stored procedure here
@InvoiceId varchar(10),
@AccountId int,
@status varchar(10),
@ModifiedBy int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Date DATETIME
SET @Date=getdate()
-- Insert statements for procedure here
IF @status=''Print''
BEGIN
Update tblInvoice set printed=''true'' where InvoiceId=@InvoiceId and AccountId=@AccountId
exec UsplTblMaintainanceInsert_new ''tblInvoice'',''Status Updated'',''Staus of Invoice has been updated as Print'',@Date,@ModifiedBy,@InvoiceId,@AccountId
END
IF @status=''Post''
BEGIN
Update tblInvoice set Posted=@Date where InvoiceId=@InvoiceId and AccountId=@AccountId
exec UsplTblMaintainanceInsert_new ''tblInvoice'',''Status Updated'',''Staus of Invoice has been updated as Post'',@Date,@ModifiedBy,@InvoiceId,@AccountId
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblRateTypeUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 5-sep-2007
--Modified date: 21/2/2008
-- Description:
CREATE PROCEDURE [dbo].[UspTblRateTypeUpdate]
-- Add the parameters for the stored procedure here
@RateTypeId int,
@AccountId INT,
@RateTypeName varchar(100),
@Administrator bit,
@CategoryId int,
@GeneralRateGL varchar(20),
@TrustRateGL varchar(20),
@SGCApplies bit,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkType int
SET @Result=0
SET @chkType = (SELECT COUNT(*) FROM tblRateType WHERE RateTypeId<>@RateTypeId AND RateTypeName=@RateTypeName AND AccountId=@AccountId AND Deleted=''false'')
IF @chkType > 0
BEGIN
SET @Result=2
END
Else
BEGIN
BEGIN TRAN
UPDATE tblRateType
SET
RateTypeName=@RateTypeName,
Administrator=@Administrator,
CategoryId=@CategoryId,
GeneralRateGL=@GeneralRateGL,
TrustRateGL=@TrustRateGL,
SGCApplies=@SGCApplies,
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
RateTypeId=@RateTypeId
AND AccountId=@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblRateType'',''Update'',''Rate Type Updated'',@Date, @ModifiedBy,@RateTypeId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblRateTypeIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: To Delete RateType Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblRateTypeIsDeletedUpdate]
(
@RateTypeID int,
@AccountId INT,
@DateModified datetime,
@ModifiedBy int,
@Deleted bit,
@Result INT OUTPUT
)
as
BEGIN
BEGIN TRAN
UPDATE tblRateType
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE RateTypeID=@RateTypeID
AND AccountId=@AccountId
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
--MAINTAINANCE ENTRY
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblRateType'',''Delete'',''Rate Type Deleted'',@Date, @ModifiedBy,@RateTypeId, @AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblRateTypeInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: Rate Type Insert
-- =============================================
CREATE PROCEDURE [dbo].[UspTblRateTypeInsert]
-- Add the parameters for the stored procedure here
--@RateTypeId int,
@RateTypeName varchar(100),
@AccountId int,
@Administrator bit,
@CategoryId int,
@GeneralRateGL varchar(20),
@TrustRateGL varchar(20),
@SGCApplies bit,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkType int
SET @Result=0
SET @chkType = (SELECT COUNT(*) FROM tblRateType WHERE RateTypeName=@RateTypeName AND AccountId=@AccountId AND Deleted=''false'')
IF @chkType > 0
BEGIN
SET @Result=2
END
Else
BEGIN
BEGIN TRAN
INSERT INTO tblRateType
(AccountId, RateTypeName, Administrator, CategoryId, GeneralRateGL,
TrustRateGL, SGCApplies, Deleted, DateModified, ModifiedBy)
VALUES(@AccountId, @RateTypeName, @Administrator, @CategoryId, @GeneralRateGL,
@TrustRateGL, @SGCApplies, @Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @RateTypeId INT
DECLARE @Date DATETIME
SET @Date=getdate()
SET @RateTypeId=(SELECT ISNULL(MAX(RateTypeId),0) FROM tblRateType)
exec UsplTblMaintainanceInsert_new ''tblRateType'',''Insert'',''New Rate Type Inserted'',@Date, @ModifiedBy,@RateTypeId, @AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblInsPayReq]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14 Nov 2007
-- Description: Insert the request for payment from talent
-- =============================================
CREATE PROCEDURE [dbo].[UspTblInsPayReq]
-- Add the parameters for the stored procedure here
@JobId INT,
@PaymentTypeId INT,
@TalentAccountId INT,
@Value INT,
@ModifiedBy INT,
@AccountId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Check INT
BEGIN TRAN
SET @Check= (SELECT COUNT(*)
FROM tblJobPayment
WHERE JobId=@JobId
AND
AccountID=@AccountId
AND
TalentAccountId=@TalentAccountId
AND
Deleted=''False'')
IF @Check = 0
BEGIN
INSERT INTO tblJobPayment(JobId,
PaymentTypeId,
TalentAccountId,
Value,
AccountId,
ModifiedBy)
VALUES(@JobId,
@PaymentTypeId,
@TalentAccountId,
@Value,
@AccountId,
@ModifiedBy)
SET @Result = 1
DECLARE @Date DATETIME
DECLARE @JobPaymentId INT
SET @Date=getdate()
SET @JobPaymentId = (SELECT ISNULL(MAX(JobPaymentId),0) FROM tblJobPayment)
exec UsplTblMaintainanceInsert_new ''tblJobPayment'',''Request'',''Payment Request sent by Talent'',@Date,@ModifiedBy,@JobPaymentId,@AccountId
END
ELSE
BEGIN
SET @Result = 2
END
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
SET @Result = 0
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionTypeUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18-02-2008
-- Description: Production Type update
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProductionTypeUpdate]
-- Add the parameters for the stored procedure here
@ProductionTypeId int,
@Name varchar(100),
@AccountId int,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkType int
SET @Result=0
SET @chkType = (SELECT COUNT(*) FROM tblProductionType WHERE [Name]=@Name AND ProductionTypeId<>@ProductionTypeId AND AccountId=@AccountId AND Deleted=''false'')
IF @chkType > 0
BEGIN
SET @Result=2
END
Else
BEGIN
BEGIN TRAN
UPDATE tblProductionType
SET
Name=@Name,
AccountId=@AccountId,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
ProductionTypeId=@ProductionTypeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblProductionType'',''Update'',''Production Type Updated'',@Date,@ModifiedBy,@ProductionTypeId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionTypeInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/02/2008
-- Description: ProductionType Insert
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProductionTypeInsert]
@Name varchar(100),
@AccountId int,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkType int
SET @Result=0
SET @chkType = (SELECT COUNT(*) FROM tblProductionType WHERE [Name]=@Name AND AccountId=@AccountId AND Deleted=''false'')
IF @chkType > 0
BEGIN
SET @Result=2
END
Else
BEGIN
BEGIN TRAN
INSERT INTO tblProductionType
(Name, AccountId, Deleted, DateModified, ModifiedBy)
VALUES(@Name, @AccountId, @Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @ProductionTypeId INT
DECLARE @Date DATETIME
SET @Date=getdate()
SET @ProductionTypeId=(SELECT ISNULL(MAX(ProductionTypeId),0) FROM tblProductionType)
exec UsplTblMaintainanceInsert_new ''tblProductionType'',''Insert'',''New Production Type Added'',@Date,@ModifiedBy,@ProductionTypeId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionTypeIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/02/2008
-- Description: To Delete Production Type Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProductionTypeIsDeletedUpdate]
(
@ProductionTypeID int,
@AccountId int,
@DateModified datetime,
@ModifiedBy int,
@Deleted bit,
@Result INT OUTPUT
)
as
BEGIN
BEGIN TRAN
UPDATE tblProductionType
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE ProductionTypeID=@ProductionTypeID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
--MAINTAINANCE ENTRY
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblProductionType'',''Deleted'',''Production Type has been deleted'',@Date, @ModifiedBy,@ProductionTypeID, @AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAgencyDeleted]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 170907
-- Description: To Delete Agency
-- =============================================
--ModifiedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblAgencyDeleted]
(
-- Add the parameters for the stored procedure here
@AgencyID int,
@AccountId INT,
@ModifiedBy INT
)
as
BEGIN
DECLARE @MaintenanceTable varchar(50)
DECLARE @Action varchar(100)
DECLARE @Detail varchar(1000)
UPDATE tblAgency SET Deleted=1 WHERE AgencyID=@AgencyID
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblAgency'',''Delete'',''Agency Deleted'',@Date,@ModifiedBy,@AgencyID,@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblLiabilityUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 26/9/2007
-- Description: For Liability Update
-- =============================================
CREATE procedure [dbo].[UspTblLiabilityUpdate]
(
-- Add the parameters for the stored procedure here
@LiabilityID int,
@AccountId int,
@ReceiptId int,
@AllocationId int,
@InvoiceId int,
@LineTypeId int,
@Amount float,
@AmountFX float,
@TaxPAYG float,
@TaxCode varchar(50),
@Posted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
SET @Result=0
BEGIN TRAN
UPDATE tblLiability
SET
ReceiptId=@ReceiptId,
AllocationId=@AllocationId,
InvoiceId=@InvoiceId,
LineTypeId=@LineTypeId,
Amount=@Amount,
AmountFX=@AmountFX,
TaxPAYG=@TaxPAYG,
TaxCode=@TaxCode,
Posted=@Posted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
LiabilityID=@LiabilityID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblLiability'',''Update'',''Liability Updated'',@Date,@ModifiedBy,@LiabilityID,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentUpdateByTalent]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2005
-- Description: To Delete Account Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTalentUpdateByTalent]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@TalentId int,
@TalentName varchar(100),
@Country int,
@ABN varchar(20),
@TFN varchar(20),
@PostalAddress varchar(1000),
@ResidentialAddress varchar(1000),
@Telephone varchar(50),
@Mobile varchar(50),
@TalentSubAccountGL varchar(20),
@SuperannuationRate float,
@DateModified datetime,
@ModifiedBy varchar(50)
)
as
BEGIN
BEGIN TRAN
UPDATE tblTalent
SET
TalentName=@TalentName,
Country=@Country,
ABN=@ABN,
TFN=@TFN,
PostalAddress=@PostalAddress,
ResidentialAddress=@ResidentialAddress,
Telephone=@Telephone,
Mobile=@Mobile,
TalentSubAccountGL=@TalentSubAccountGL,
SuperannuationRate=@SuperannuationRate,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
TalentId=@TalentId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
UPDATE tblPerson
SET
tblPerson.PersonName=@TalentName
WHERE
(SELECT COUNT(*) FROM tblMapPersonProfile WHERE tblMapPersonProfile.ProfileId=@ProfileId AND
tblMapPersonProfile.PersonId = tblPerson.PersonID)>0 AND
AccountID=@AccountID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblTalent'',''Update'',''Talent detail updated'',@Date,@ModifiedBy,@TalentId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblDeletePaymentRequest]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select all payment requests for the job by talent
-- =============================================
CREATE PROCEDURE [dbo].[UspTblDeletePaymentRequest] --null,null
-- Add the parameters for the stored procedure here
@JobPaymentId INT ,
@AccountId INT ,
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblJobPayment
SET Deleted=''True''
WHERE JobPaymentId=@JobPaymentId
AND
AccountId=@AccountId
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblJobPayment'',''Request Deleted'',''Request has been deleted'',@Date,@ModifiedBy,@JobPaymentId,@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAllocationUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <06/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAllocationUpdate]
-- Add the parameters for the stored procedure here
@AccountId int,
@AllocationId int,
@Amount float,
@RateFx float,
@AmountFx float,
@TaxPAYG float,
@ModifiedBy int,
@Result int output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblAllocation
SET [Amount]=@Amount,
[RateFX]=@RateFx,
[AmountFX]=@AmountFx,
[TaxPAYG]=@TaxPAYG,
[ModifiedBy]=@ModifiedBy,
[DateModified]=getdate()
WHERE AllocationId=@AllocationId and AccountId=@AccountId
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblallocation'',''Update'',''Allocation Updated'',@Date,@ModifiedBy,@AllocationId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentAccountDeleted]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 23/10/2007
-- Description: To Delete Talent Account
-- =============================================
-- ModifiedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblTalentAccountDeleted]
(
-- Add the parameters for the stored procedure here
@TalentAccountID int,
@AccountId INT,
@ModifiedBy INT,
@Result int output
)
as
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
set @Result=0
UPDATE tblTalentAccount SET Deleted=1 WHERE TalentAccountID=@TalentAccountID
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblTalentAccount'',''Delete'',''Talent Account Deleted'',@Date,@ModifiedBy,@TalentAccountID,@AccountId
if @@Error<> 0
set @Result=0
else
set @Result=1
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAgencyContactDeleted]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 170907
-- Description: To LOGICALLY DELETION OF AGENCY CONTACT
-- =============================================
--ModifiedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblAgencyContactDeleted]
(
-- Add the parameters for the stored procedure here
@ContactID int,
@AccountId INT,
@ModifiedBy INT,
@Result int output
)
as
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
set @Result=0
UPDATE tblAgencyContact SET Deleted=1 WHERE ContactID=@ContactID
DECLARE @Date Datetime
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblAgencyContact'',''Delete'',''Agency Contact Deleted'',@Date,@ModifiedBy,@ContactID,@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAllocationIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <06/12/2007>
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAllocationIsDeletedUpdate]
-- Add the parameters for the stored procedure here
@AccountId int,
@AllocationId int,
@ModifiedBy int,
@Result int output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE tblAllocation
SET [deleted]=''TRUE'',
[ModifiedBy]=@ModifiedBy,
[DateModified]=getdate()
WHERE AllocationId=@AllocationId and AccountId=@AccountId
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblallocation'',''Delete'',''allocation Deleted'',@Date,@ModifiedBy,@AllocationId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProductionIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 26/9/2007
-- Description: For Production Deletion
-- =============================================
CREATE procedure [dbo].[UspTblProductionIsDeletedUpdate]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProductionID int,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
SET @Result=0
BEGIN TRAN
UPDATE tblProduction
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
ProductionID=@ProductionID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblProduction'',''Delete'',''Production Deleted'',@Date,@ModifiedBy,@ProductionID,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblShowExps]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 29 Jan 2008
-- Description: Returns all exceptions raised in database
-- =============================================
CREATE PROCEDURE [dbo].[UspTblShowExps]
-- Add the parameters for the stored procedure here
@Date DATETIME
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT CategoryName,Severity,Title,[TimeStamp],[Message]
FROM tblExceptionLog el
INNER JOIN tblExceptionCategoryLog ecl
INNER JOIN tblExceptionCategory ec
ON ecl.CategoryID=ec.CategoryID
ON el.LogID=ecl.LogID
WHERE Convert(VARCHAR,[TimeStamp],106) = CONVERT(VARCHAR,@Date,106)
ORDER BY [TimeStamp] DESC
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGstCodesUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 26/11/2007
-- Description:
CREATE PROCEDURE [dbo].[UspTblGstCodesUpdate]
-- Add the parameters for the stored procedure here
@GstCodeId int,
@TaxCodeId int,
@Date datetime,
@Rate float,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
declare @ChkName varchar(20)
set @ChkName = (select count(*) from tblGST where date=@Date and TaxCodeId=@TaxCodeId and deleted=''false'' and GstCodeId<> @GstCodeId )
if (@ChkName <> 0)
begin
set @result=0
end
else
begin
BEGIN
SET @Result=0
BEGIN TRAN
UPDATE tblGST
SET
TaxCodeId=@TaxCodeId,
Date=@Date,
Rate=@Rate,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
GstCodeId=@GstCodeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @Date1 DATETIME
SET @Date1=getdate()
exec UspTblCentralMaintenanceInsert ''tblGST'',''Update'',''GST Code Updated'',@Date1, @ModifiedBy,@GstCodeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGstCodesInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
-- Description: Rate Type Insert
-- =============================================
CREATE PROCEDURE [dbo].[UspTblGstCodesInsert]
-- Add the parameters for the stored procedure here
@TaxCodeId int,
@Date datetime,
@Rate float,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
declare @ChkName varchar(20)
BEGIN
SET @Result=0
set @ChkName = (select count(*) from tblGST where date=@Date and TaxCodeId=@TaxCodeId and deleted=''false'' )
if (@ChkName <> 0)
begin
set @result=0
end
else
begin
BEGIN TRAN
INSERT INTO tblGST
(TaxCodeId, Date, Rate, Deleted, DateModified, ModifiedBy)
VALUES(@TaxCodeId, @Date, @Rate, @Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
--MAINTAINANCE ENTRY
DECLARE @GstCodeId INT
DECLARE @Date1 DATETIME
SET @Date1=getdate()
SET @GstCodeId=(SELECT ISNULL(MAX(GstCodeId),0) FROM tblGST)
exec UspTblCentralMaintenanceInsert ''tblGST'',''Insert'',''New GST Code Inserted'',@Date1, @ModifiedBy,@GstCodeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
end
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCountryAudit]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Sep/2007
-- Description: Audit of country
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCountryAudit]
-- Add the parameters for the stored procedure here
@CountryId INT,
@CurrencyId INT,
@CountryName VARCHAR(50),
@LabelGST VARCHAR(20),
@ModifiedBy INT,
@HostIP VARCHAR(15),
@UserName VARCHAR(50),
@Action VARCHAR(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
BEGIN TRAN
DECLARE @Date DATETIME
SET @Date=getdate()
INSERT INTO tblCountryAudit(CountryId,CurrencyId,CountryName,LabelGST,ModifiedBy,HostIP,UserName,[Action],[DateTime])
VALUES(@CountryId,@CurrencyId,@CountryName,@LabelGST,@ModifiedBy,@HostIP,@UserName,@Action,@Date)
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCurrencyAudit]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 4/jan/2008
-- Description: Add new currency
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCurrencyAudit]
-- Add the parameters for the stored procedure here
@CurrencyID int,
@CurrencyName VARCHAR(3),
@Description VARCHAR(100),
@BaseCurrency TINYINT,
@FXRate float,
@ModifiedBy INT,
@HostIp varchar(15),
@USerName varchar(50),
@Action VARCHAR(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
BEGIN TRAN
DECLARE @Date DATETIME
SET @Date=getdate()
INSERT INTO [Talent].[dbo].[tblCurrencyAudit]
([CurrencyId]
,[CurrencyName]
,[Description]
,[BaseCurrency]
,[DateModified]
,[ModifiedBy]
,[FXRate]
,[HostIP]
,[UserName]
,[Action])
VALUES
(@CurrencyId
,@CurrencyName
,@Description
,@BaseCurrency
,@Date
,@ModifiedBy
,@FXRate
,@HostIP
,@UserName
,@Action)
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralMenuUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 1/Oct/2007
-- Description: Update the menus for the selected profile
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralMenuUpdate]
-- Add the parameters for the stored procedure here
@CentralProfileId INT,
@Navigations VARCHAR(1000),
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DELETE FROM tblCentralMenu WHERE CentralProfileId=@CentralProfileId
DECLARE @NavigationId INT
DECLARE @str VARCHAR(1000)
-- Insert statements for procedure here
WHILE @Navigations <> ''''
BEGIN
SET @NavigationId = CHARINDEX('','', @Navigations)
IF @NavigationId > 0
BEGIN
SET @str = CAST(LEFT(@Navigations, @NavigationId-1) AS INT)
SET @Navigations = RIGHT(@Navigations, LEN(@Navigations)-@NavigationId)
END
ELSE
BEGIN
SET @str = CAST(@Navigations AS INT)
SET @Navigations = ''''
END
INSERT INTO tblCentralMenu(CentralProfileId,CentralNavigationId,ModifiedBy)
VALUES(@CentralProfileId,CONVERT(VARCHAR(100),@str),@ModifiedBy)
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@CentralProfileId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCurrencyUpdateToBase]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Sep/2007
-- Description: Add new currency
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCurrencyUpdateToBase]
-- Add the parameters for the stored procedure here
@CurrencyId INT,
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRAN
UPDATE tblCurrency
SET BaseCurrency = ''True'',
DateModified = getdate(),
ModifiedBy = @ModifiedBy
WHERE
CurrencyId = @CurrencyId
UPDATE tblCurrency
SET BaseCurrency = ''False''
WHERE
CurrencyId <> @CurrencyId
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCurrency'',''Update'',''Currency hase been changed to base currency'',@Date, @ModifiedBy,@CurrencyId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblMenuUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 1/Oct/2007
-- Description: Update the menus for the selected profile
-- =============================================
CREATE PROCEDURE [dbo].[UspTblMenuUpdate]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@Navigations VARCHAR(1000),
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DELETE FROM tblMenu WHERE ProfileId=@ProfileId
DECLARE @NavigationId INT
DECLARE @str VARCHAR(1000)
-- Insert statements for procedure here
WHILE @Navigations <> ''''
BEGIN
SET @NavigationId = CHARINDEX('','', @Navigations)
IF @NavigationId > 0
BEGIN
SET @str = CAST(LEFT(@Navigations, @NavigationId-1) AS INT)
SET @Navigations = RIGHT(@Navigations, LEN(@Navigations)-@NavigationId)
END
ELSE
BEGIN
SET @str = CAST(@Navigations AS INT)
SET @Navigations = ''''
END
INSERT INTO tblMenu(ProfileId,NavigationId,ModifiedBy)
VALUES(@ProfileId,CONVERT(VARCHAR(100),@str),@ModifiedBy)
-- UPDATE tblMenu SET NavigationId=CONVERT(VARCHAR(100),@str)
-- WHERE ProfileId=@ProfileId
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Sep/2007
-- Description: Add new currency
--ModifiedBy - Harendra Singh
--Modified Date- 27/Oct/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileUpdate]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@ProfileName VARCHAR(50),
@InActive BIT,
@ModifiedBy INT,
@SubProfile BIT,
--@ParentProfileId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @ParentprofileIdExist int
SET @Result = (SELECT COUNT(*)
FROM tblProfile
WHERE ProfileName = @ProfileName
AND ProfileId <> @ProfileId)
--set @ParentprofileIdExist=(select isnull(ParentProfileId, -1) from tblprofile
-- where profileid=@ProfileId )
--
----IF PARENT PROFILE ID CHANGED IT WILL DELETE ALL PERMISSION
--IF (@ParentprofileIdExist <> @ParentProfileId)
--BEGIN
-- delete from tblmenu where ProfileId=@ProfileId
--END
IF(@Result=0)
BEGIN
BEGIN TRAN
if (@SubProfile=''True'')
BEGIN
UPDATE tblProfile
SET ProfileName = @ProfileName,--ParentProfileId=@ParentProfileId,
InActive = @InActive,
DateModified = getdate(),
ModifiedBy = @ModifiedBy
WHERE ProfileId = @ProfileId
END
ELSE
BEGIN
UPDATE tblProfile
SET ProfileName = @ProfileName,
InActive = @InActive,
DateModified = getdate(),
ModifiedBy = @ModifiedBy
WHERE ProfileId = @ProfileId
END
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblProfile'',''Update'',''Account profile details have been changed'',@Date, @ModifiedBy,@ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 21/Sep/2007
-- Description: Add new currency
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileInsert]
-- Add the parameters for the stored procedure here
@ProfileName VARCHAR(50),
@ModifiedBy INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Result = (SELECT COUNT(*)
FROM tblProfile
WHERE ProfileName = @ProfileName)
IF(@Result=0)
BEGIN
BEGIN TRAN
INSERT INTO tblProfile(ProfileName,DateModified,ModifiedBy)
VALUES(@ProfileName,getdate(),@ModifiedBy)
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @ProfileId INT
DECLARE @Date DATETIME
SET @Date=getdate()
SET @ProfileId=(SELECT ISNULL(MAX(ProfileId),0) FROM tblProfile)
exec UspTblCentralMaintenanceInsert ''tblProfile'',''New Profile'',''New account profile has been created'',@Date, @ModifiedBy,@ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 27/Sep/2007
-- Description: Select selected profile detail on basis of profile id
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileDelete]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@ModifiedBy INT
As
--Declare @MaintenanceTable varchar(50)
--Declare @Action varchar(100)
--Declare @Detail varchar(1000)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
UPDATE tblProfile
SET Deleted=''True'',
ModifiedBy=@ModifiedBy
WHERE profileId=@ProfileId
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblProfile'',''Delete Profile'',''Account profile has been deleted'',@Date, @ModifiedBy,@ProfileId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGstCodesIsDeletedUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2005
-- Description: To Delete RateType Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblGstCodesIsDeletedUpdate]
(
@GstCodeID int,
@DateModified datetime,
@ModifiedBy int,
@Deleted bit,
@Result INT OUTPUT
)
as
BEGIN
BEGIN TRAN
UPDATE tblGST
SET
Deleted=@Deleted,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE GstCodeID=@GstCodeID
IF @@ERROR <> 0
BEGIN
SET @Result=0
END
--MAINTAINANCE ENTRY
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblGST'',''Delete'',''Gst Code Deleted'',@Date, @ModifiedBy,@GstCodeId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTaxCodeDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 23/Nov/2007
-- Description: Select Tax Codes on basis of countryid
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTaxCodeDelete]
-- Add the parameters for the stored procedure here
@TaxCodeId INT,
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE tblTaxCode
SET Deleted=''True'',
ModifiedBy=@ModifiedBy
WHERE TaxCodeId=@TaxCodeId
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblTaxCode'',''Delete'',''Tax Code Deleted'',@Date, @ModifiedBy,@TaxCodeId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTaxCodeInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 23/Nov/2007
-- Description: Select Tax Codes on basis of countryid
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTaxCodeInsert]
-- Add the parameters for the stored procedure here
@CountryId INT,
@TaxCode VARCHAR(3),
@ModifiedBy INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SET @Result=(SELECT COUNT(TaxCode)
FROM tblTaxCode
WHERE CountryId=@CountryId
AND TaxCode LIKE @TaxCode
AND Deleted=''False'')
IF @Result = 0
BEGIN
INSERT INTO tblTaxCode(CountryId,TaxCode,ModifiedBy)
VALUES(@CountryId,@TaxCode,@ModifiedBy)
DECLARE @TaxCodeId INT
SET @TaxCodeId =(SELECT ISNULL(MAX(TaxCodeId),0) FROM tblTaxCode)
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblTaxCode'',''Insert'',''New Tax Code Inserted'',@Date, @ModifiedBy,@TaxCodeId
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralUsersDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13/Sep/2007
-- Description: To delete the central user
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralUsersDelete]
-- Add the parameters for the stored procedure here
@CentralAdminId INT,
@UserId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
BEGIN TRAN
UPDATE tblCentralAdmin
SET Deleted=''True''
WHERE UserId=@UserId
IF(@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralAdmin'',''Deleteion'',''User has been deleted'',@Date,@CentralAdminId,@UserId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileActiveInActive]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 17 Oct 2007
-- Description: Make Profile Active/InActive
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileActiveInActive]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@InActive BIT,
@ModifiedBy INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
BEGIN TRAN
UPDATE tblProfile
SET InActive = @InActive,
DateModified = getdate(),
ModifiedBy = @ModifiedBy
WHERE ProfileId=@ProfileId
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblProfile'',''Update'',''Account profile details have been changed'',@Date, @ModifiedBy,@ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSubProfileInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[UspTblSubProfileInsert]
-- Add the parameters for the stored procedure here
@ProfileName VARCHAR(50),
@ModifiedBy INT,
@ParentProfileId INT,
@Result INT OUTPUT
AS
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Result = (SELECT COUNT(*)
FROM tblProfile
WHERE ProfileName = @ProfileName)
IF(@Result=0)
BEGIN
BEGIN TRAN
INSERT INTO tblProfile(ProfileName,DateModified,ModifiedBy ,ParentProfileId)
VALUES(@ProfileName,getdate(),@ModifiedBy,@ParentProfileId)
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @ProfileId INT
DECLARE @Date DATETIME
SET @Date=getdate()
SET @ProfileId=(SELECT ISNULL(MAX(ProfileId),0) FROM tblProfile)
exec UspTblCentralMaintenanceInsert ''tblProfile'',''New Profile'',''New account sub profile has been created'',@Date, @ModifiedBy,@ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblProductionTypeSelectByID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/02/2008
-- Description: Details of ProductionType by Id
-- =============================================
CREATE procedure [dbo].[USPTblProductionTypeSelectByID]
(
@ProductionTypeId int,
@AccountId int
)
AS
SELECT * FROM tblProductionType
WHERE Deleted=''0'' AND ProductionTypeId=@ProductionTypeId AND AccountId=@AccountId
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblProductionTypeSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/02/2008
-- Description: For Production Type
-- =============================================
CREATE procedure [dbo].[USPTblProductionTypeSelect]
@Name varchar(100) = NULL,
@AccountId int
AS
IF(@Name<>'''')
BEGIN
EXEC(''SELECT * FROM tblProductionType
WHERE
Deleted=''''0'''' AND AccountId='''''' + @AccountId + '''''' AND Name like ''''%'' + @Name + ''%'''''')
END
ELSE
BEGIN
SELECT * FROM tblProductionType
WHERE Deleted=''0'' AND AccountId=@AccountId
Order by datemodified desc
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblProductionTypeFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 01/10/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblProductionTypeFillDdl]
-- Add the parameters for the stored procedure here
@AccountId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Select ProductionTypeID, Name
from tblProductionType AS pt
WHERE pt.Deleted = ''0'' AND AccountId=@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblRateTypeFillDdl]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: FILL DDL Rate Type
-- =============================================
CREATE procedure [dbo].[USPTblRateTypeFillDdl]
@AccountId int
AS
SELECT RateTypeId, SUBSTRING(RateTypeName,1,50) as RateTypeName
-- ,CASE LEN(RateTypeName)
-- WHEN (LEN(RateTypeName)>30) THEN SUBSTRING(RateTypeName,1,30)
-- ELSE RateTypeName
-- END AS RateTypeName
FROM tblRateType
WHERE Deleted=''0'' AND AccountId=@AccountId
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblRateTypeSelectByRateTypeID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 22/10/2007
--Modified date: 21/2/2008
-- Description: FILL DDL Rate Type
-- =============================================
CREATE procedure [dbo].[USPTblRateTypeSelectByRateTypeID]
(
@RateTypeId int,
@AccountId INT
)
AS
SELECT * FROM tblRateType
WHERE Deleted=''0'' AND RateTypeId=@RateTypeId AND AccountId=@AccountId
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblExceptionCategoryLogInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[UspTblExceptionCategoryLogInsert]
@CategoryID INT,
@LogID INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @CatLogID INT
SELECT @CatLogID FROM tblExceptionCategoryLog WHERE CategoryID=@CategoryID and LogID = @LogID
IF @CatLogID IS NULL
BEGIN
INSERT INTO tblExceptionCategoryLog (CategoryID, LogID) VALUES(@CategoryID, @LogID)
RETURN @@IDENTITY
END
ELSE RETURN @CatLogID
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblExceptionClearLogs]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[UspTblExceptionClearLogs]
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM tblExceptionCategoryLog
DELETE FROM [tblExceptionLog]
DELETE FROM tblExceptionCategory
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblPaymentRequest]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select all payment requests for the job by talent
-- =============================================
CREATE PROCEDURE [dbo].[UspTblPaymentRequest] --2,1
-- Add the parameters for the stored procedure here
@JobId INT ,
@AccountId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT jp.JobPaymentId, jp.PaymentTypeId,pt.PaymentType,jp.TalentAccountId,ta.AccountName+'': '' +ta.AccountNumber as TalentAccount,jp.Value
FROM tblJobPayment jp Inner join
tblPaymentType pt on
jp.PaymentTypeId=pt.PaymentTypeId
inner join tblTalentAccount ta on
jp.TalentAccountId=ta.TalentAccountId
WHERE jp.JobId=@JobId
AND
jp.AccountId=@AccountId
AND
jp.Deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblSelectPayTypes]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 13 Nov 2007
-- Description: Select payment types
-- =============================================
CREATE PROCEDURE [dbo].[UspTblSelectPayTypes] --1
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT PaymentTypeId,PaymentType
FROM tblPaymentType
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspCentralLogs]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 26/Sep/2007
-- Description: View the log history
-- =============================================
CREATE PROCEDURE [dbo].[UspCentralLogs] --''g'',''10/29/2007''
-- Add the parameters for the stored procedure here
@ModBy VARCHAR(50)= null,
@MDate DATETIME = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @TableName VARCHAR(50)
DECLARE @Action VARCHAR(20)
DECLARE @Detail VARCHAR(100)
DECLARE @Datemodified DATETIME
DECLARE @Date DATETIME
DECLARE @Time DATETIME
DECLARE @ModifiedByName VARCHAR(50)
DECLARE @ModifiedBy INT
DECLARE @ModifiedName VARCHAR(50)
DECLARE @ModifiedId INT
DECLARE @FirstName VARCHAR(50)
DECLARE @LastName VARCHAR(50)
DECLARE @TempTable TABLE
(
TableName VARCHAR(50),
Action VARCHAR(20),
DETAIL VARCHAR(100),
Date1 DATETIME,
Time DATETIME,
ModifiedByName VARCHAR(50),
ModifiedName VARCHAR(50)
)
DECLARE Curser CURSOR FOR
SELECT MaintenanceTable,Action,Detail,DateModified,ModifiedBy,ModifiedId FROM tblcentralmaintenance
OPEN Curser
FETCH Curser INTO @TableName,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId
WHILE @@Fetch_Status = 0
BEGIN
-- PRINT @TableName
-- PRINT @ModifiedId
SET @FirstName = (SELECT FirstName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedBy)
SET @LastName = (SELECT LastName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedBy)
SELECT @ModifiedByName = @FirstName + '' '' + @LastName
IF @TableName = ''tblCentralAdmin''
BEGIN
SET @FirstName = (SELECT FirstName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedId)
SET @LastName = (SELECT LastName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedId)
SELECT @ModifiedName = @FirstName + '' '' + @LastName
END
IF @TableName = ''TblCentralUserPersonalInfo''
BEGIN
SET @FirstName = (SELECT FirstName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedId)
SET @LastName = (SELECT LastName from tblCentralUserPersonalInfo WHERE UserId=@ModifiedId)
SELECT @ModifiedName = @FirstName + '' '' + @LastName
END
IF @TableName = ''tblCountry''
BEGIN
SET @ModifiedName=(SELECT CountryName from tblCountry WHERE CountryId=@ModifiedId)
END
IF @TableName = ''tblProfile''
BEGIN
SET @ModifiedName=(SELECT ProfileName from tblProfile WHERE ProfileId=@ModifiedId)
END
IF @TableName = ''tblMenu''
BEGIN
SET @ModifiedName=(SELECT ProfileName from tblProfile WHERE ProfileId=@ModifiedId)
END
IF @TableName = ''tblCentralMenu''
BEGIN
SET @ModifiedName=(SELECT CentralProfileName from tblCentralProfile WHERE CentralProfileId=@ModifiedId)
END
IF @TableName = ''tblCurrency''
BEGIN
SET @ModifiedName=(SELECT CurrencyName from tblCurrency WHERE CurrencyId=@ModifiedId)
END
IF @TableName = ''tblCentralMenu''
BEGIN
SET @ModifiedName=(SELECT CentralProfileName from tblCentralProfile WHERE CentralProfileId=@ModifiedId)
END
IF @TableName = ''tblRateType''
BEGIN
SET @ModifiedName=(SELECT RateTypeName from tblRateType WHERE RateTypeId=@ModifiedId)
END
IF @TableName = ''tblCategory''
BEGIN
SET @ModifiedName=(SELECT CategoryName from tblCategory WHERE CategoryId=@ModifiedId)
END
IF @TableName = ''tblTaxCode''
BEGIN
SET @ModifiedName=(SELECT TaxCode from tblTaxCode WHERE TaxCodeId=@ModifiedId)
END
IF @TableName = ''tblGST''
BEGIN
SET @ModifiedName=(SELECT Rate from tblGST WHERE GstCodeId=@ModifiedId)
END
IF @TableName = ''tblAttribute''
BEGIN
SET @ModifiedName=(SELECT AttributeName from tblAttribute WHERE AttributeId=@ModifiedId)
END
IF @TableName = ''tblAttributeType''
BEGIN
SET @ModifiedName=(SELECT AttributeType from tblAttributeType WHERE AttributeTypeId=@ModifiedId)
END
IF @TableName = ''tblDocument''
BEGIN
SET @ModifiedName=(SELECT DocumentDescription from tblDocument WHERE DocumentId=@ModifiedId)
END
IF @TableName = ''tblAccount''
BEGIN
SET @ModifiedName=(SELECT Name from tblAccount WHERE AccountId=@ModifiedId)
END
SET @Date = @DateModified
SET @Time = @DateModified
INSERT INTO @TempTable(TableName,Action,Detail,Date1,Time,ModifiedByName,ModifiedName)
VALUES(@TableName,@Action,@Detail,@Date,@Time,@ModifiedByName,@ModifiedName)
FETCH Curser INTO @TableName,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId
END
IF(@MDate<>'''')
BEGIN
IF(@ModBy<>'''')
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedName
FROM @TempTable WHERE ModifiedByName like ''%'' + @ModBy + ''%''
AND convert(varchar,Date1,106) = convert(varchar,@MDate,106)
order by Date1 desc
END
ELSE
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedName
FROM @TempTable WHERE convert(varchar,Date1,106) = convert(varchar,@MDate,106)
order by Date1 desc
END
END
ELSE
IF(@ModBy<>'''')
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedName
FROM @TempTable WHERE ModifiedByName like ''%'' + @ModBy + ''%''
order by Date1 desc
END
ELSE
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedName
FROM @TempTable order by Date1 desc
END
CLOSE Curser
DEALLOCATE Curser
RETURN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigation]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* --Author: Harendra Singh
--Purpose: To Dispaly form listing & permission
--Created date: 17/10/2007
*/
CREATE PROCEDURE [dbo].[UspTblNavigation]
@ProfileId INT
AS
declare @chkparent int
declare @ParentProfileId int
set @chkparent=(select count(*) from tblprofile where ProfileId= @ProfileId and ParentProfileId is not null)
if (@chkparent <> 0 )
begin
set @ParentProfileId =(select ParentProfileId from tblprofile where ProfileId= @ProfileId)
SELECT DISTINCT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') AND (A.ProfileId = @ProfileId)
UNION
SELECT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') AND (A.ProfileId = @ParentProfileId) AND (A.NavigationId NOT IN
(SELECT NavigationId
FROM tblMenu
WHERE (ProfileId = @ProfileId) AND (Deleted = ''false'')))
end
else
begin
SELECT DISTINCT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select],
ISNULL(A.[insert], ''false'') AS [insert], ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') AND (A.ProfileId = @ProfileId)
UNION
SELECT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A CROSS JOIN
tblMenu AS B
WHERE (A.Deleted = ''False'') AND (A.NavigationId NOT IN
(SELECT NavigationId
FROM tblMenu
WHERE (ProfileId = @ProfileId) AND (Deleted = ''false'')))
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationSelectByProfile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
--Modified By:Harendra Singh
--Modified Date: 19/12/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspTblNavigationSelectByProfile]
-- Add the parameters for the stored procedure here
@ProfileId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
-- select n.navigationid, m.Profileid,name,parent, NavigationUrl
-- from tblnavigation as n
-- inner join tblMenu as m on
-- m.Deleted=''false'' and n.navigationid=m.navigationid
-- where n.IsInMenu=''True'' and n.deleted=''False''
select navigationid,name,parent, NavigationUrl
from tblnavigation
where navigationid in (select navigationid from tblmenu where profileid=@ProfileId)
AND
IsInMenu=''True'' and deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationSelectByProfile1]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date:
-- Description:
--Modified By:Harendra Singh
--Modified Date: 19/12/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspTblNavigationSelectByProfile1]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select n.navigationid, m.Profileid,name,parent, NavigationUrl
from tblnavigation as n
inner join tblMenu as m on
m.Deleted=''false'' and n.navigationid=m.navigationid
where n.IsInMenu=''True'' and n.deleted=''False''
-- select navigationid,name,parent, NavigationUrl
-- from tblnavigation
-- where navigationid in (select navigationid from tblmenu where profileid=@ProfileId)
-- AND
-- IsInMenu=''True'' and deleted=''False''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblNavigationNEW]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* --Author: Harendra Singh
--Purpose: To Dispaly form listing & permission
--Created date: 17/10/2007
*/
CREATE PROCEDURE [dbo].[UspTblNavigationNEW] --1 ,6
@ProfileId INT,
@ParentId int
AS
declare @chkparent int
declare @ParentProfileId int
Declare @Count int
set @Count =(select count (*) from tblmenu where profileId=@ProfileId)
IF @Count <>0
BEGIN
select AF.* from
((( SELECT DISTINCT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select],
ISNULL(A.[insert], ''false'') AS [insert], ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') and B.Parent=@ParentId AND (A.ProfileId = @ProfileId)
UNION
SELECT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A Cross JOIN
tblMenu AS B
WHERE (A.Deleted = ''False'') and A.Parent=@ParentId AND (A.NavigationId NOT IN
(SELECT NavigationId
FROM tblMenu
WHERE (ProfileId = @ProfileId) AND (Deleted = ''false'')))
Union
( SELECT DISTINCT
A.NavigationId, B.Name, B.Description, B.Parent, B.Sequence, ISNULL(A.[select], ''false'') AS [select],
ISNULL(A.[insert], ''false'') AS [insert], ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblMenu AS A INNER JOIN
tblNavigation AS B ON A.NavigationId = B.NavigationId
WHERE (A.Deleted = ''False'') AND (A.ProfileId = @ProfileId)
and B.Parent in (select parent from tblNavigation
where Parent in (select navigationId from tblNavigation where parent=@ParentId))
UNION
SELECT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A
where parent in(
select parent from tblNavigation
where Parent in (select navigationId from tblNavigation where parent=@ParentId))
AND (NavigationId NOT IN
(SELECT NavigationId
FROM tblMenu
WHERE (ProfileId = @ProfileId) AND (Deleted = ''false''))) and deleted=''0'')))) AF ,
tblNavigation CN where AF.NavigationId = CN.NavigationId and CN.NavigationURL is not null
END
ELSE
BEGIN
SELECT AF.* from
( SELECT DISTINCT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A
WHERE (A.Deleted = ''False'') and A.Parent=@ParentId
Union
SELECT A.NavigationId, A.Name, A.Description, A.Parent, A.Sequence, ISNULL(A.[select], ''false'') AS [select], ISNULL(A.[insert], ''false'') AS [insert],
ISNULL(A.[update], ''false'') AS [update], ISNULL(A.[delete], ''false'') AS [delete]
FROM tblNavigation AS A
where parent in(select parent from tblNavigation where Parent in (select navigationId from tblNavigation where parent=@ParentId)))
AF ,
tblNavigation CN where AF.NavigationId = CN.NavigationId and CN.NavigationURL is not null
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblUpdateCentralMenu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* --Author: Harendra Singh
--Purpose: To upadte/add central Navigation & permission
--Created date: 19/12/2007
*/
CREATE PROCEDURE [dbo].[UspTblUpdateCentralMenu] --3 , 6, ''true'',''true'',''true'',''true'' ,1
-- Add the parameters for the stored procedure here
@ProfileId INT,
@NavigationId int,
@select bit,
@insert bit,
@update bit,
@delete bit,
@ModifiedBy INT
AS
declare @IsExist int
declare @date datetime
Declare @ParentId int
declare @rootParent int
Declare @count int
declare @checkRoot int
declare @DelParent int
Declare @DelrootParent int
Declare @countDel int
declare @CountrootDel int
declare @checkRootParent int
declare @AccessPath as varchar(50)
Declare @@AccessAnavigationId int
Declare @@STRAccess as varchar(2)
Declare @CountAccess as int
set @date=getdate()
--Deleting existing Permission and then set new one.
--if (@select=''false'')
--begin
delete from tblcentralMenu where centralprofileId=@ProfileId and centralNavigationId=@NavigationId
--end
-- set @DelParent=(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@NavigationId )
--SET @DelrootParent =(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@DelParent )
-- set @countDel=(select count(*) from tblcentralmenu where
-- centralNavigationId in (select centralnavigationId from tblCentralNavigation
-- where Parent=@DelParent) and centralProfileId=@ProfileId)
--
-- Set @CountrootDel=(select count(*) from tblCentralNavigation where parent=@DelParent and formname is null)
--
-- Set @CountrootDel=(select count(*) from tblcentralmenu where
-- centralNavigationId in (select centralnavigationId from tblCentralNavigation
-- where Parent=@DelrootParent) and centralProfileId=@ProfileId)
-- IF (@countDel=0 and @CountrootDel=0)
-- BEGIN
-- DELETE FROM tblcentralmenu where centralnavigationId=@DelParent and centralProfileId=@ProfileId
-- END
-- ELSE
-- BEGIN
-- --SET @DelrootParent =(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@DelParent )
-- Set @CountrootDel=(select count(*) from tblcentralmenu where
-- centralNavigationId in (select centralnavigationId from tblCentralNavigation
-- where Parent=@DelrootParent) and centralProfileId=@ProfileId)
-- IF @CountrootDel=0
-- BEGIN
-- DELETE FROM tblcentralmenu where centralnavigationId=@DelParent and centralProfileId=@ProfileId
-- DELETE FROM tblcentralmenu where centralnavigationId=@DelrootParent and centralProfileId=@ProfileId
-- END
--
-- END
set @IsExist= (select count(*)from tblcentralmenu where centralProfileId=@ProfileId and centralNavigationId=@NavigationId)
if (@IsExist <> 0)
begin
update tblmenu set [select]=@select , [insert]=@insert , [update]=@update , [delete]=@delete,
DateModified=@date , ModifiedBy=@ModifiedBy
where ProfileId=@ProfileId and NavigationId=@NavigationId
--exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
end
else
begin
if(@select =''1'')
begin
Set @count =(select count(*) from tblcentralmenu where
centralNavigationId in (select Parent from tblCentralNavigation
where CentralNavigationId=@NavigationId) and centralProfileId=@ProfileId)
If (@count=0)
Begin
Set @ParentId=(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@NavigationId )
set @rootParent=(select isnull(Parent,0) from tblCentralNavigation where CentralNavigationId=@ParentId)
if @ParentId<>0
begin
if @rootParent<>0
begin
set @checkRootParent=(select count(*) from tblcentralmenu where
centralNavigationId in (select Parent from tblCentralNavigation
where CentralNavigationId=@rootParent) and centralProfileId=@ProfileId)
if (@checkRootParent=0)
begin
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@rootParent,@select,@insert,@update,@delete,@date,@ModifiedBy)
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@ParentId,@select,@insert,@update,@delete,@date,@ModifiedBy)
end
end
set @checkRoot=(select count(*) from tblcentralmenu where
centralNavigationId in (select Parent from tblCentralNavigation
where CentralNavigationId=@rootParent) and centralProfileId=@ProfileId)
IF @checkRoot=0
BEGIN
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@ParentId,@select,@insert,@update,@delete,@date,@ModifiedBy)
END
END
End
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@NavigationId,@select,@insert,@update,@delete,@date,@ModifiedBy)
set @AccessPath=(select isnull(AccessPath,'''') from tblcentralnavigation where centralnavigationId=@NavigationId)
IF @AccessPath<>''''
BEGIN
WHILE @AccessPath <>''''
BEGIN
SET @@AccessAnavigationId = CHARINDEX('','', @AccessPath)
IF @@AccessAnavigationId >0
BEGIN
SET @@STRAccess = CAST(LEFT(@AccessPath, @@AccessAnavigationId-1) AS Int)
SET @AccessPath = RIGHT(@AccessPath, LEN(@AccessPath)-@@AccessAnavigationId)
END
ELSE
BEGIN
SET @@STRAccess = CAST(@AccessPath AS int)
SET @AccessPath = ''''
END
SET @CountAccess =(select Count(*) from tblcentralmenu where centralnavigationid=@@STRAccess AND centralProfileID=@ProfileId)
IF @CountAccess=0
BEGIN
insert into tblCentralMenu(CentralProfileId , CentralNavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@@STRAccess,0,0,0,0,@date,@ModifiedBy)
END
END
END
--exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
end
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblUpdateMenu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* --Author: Harendra Singh
--Purpose: To upadte/add Navigation & permission
--Created date: 16/10/2007
*/
CREATE PROCEDURE [dbo].[UspTblUpdateMenu]
-- Add the parameters for the stored procedure here
@ProfileId INT,
@NavigationId int,
@select bit,
@insert bit,
@update bit,
@delete bit,
@ModifiedBy INT
AS
declare @IsExist int
declare @date datetime
Declare @ParentId int
declare @rootParent int
Declare @count int
declare @checkRoot int
declare @AccessPath as varchar(50)
Declare @@AccessAnavigationId int
Declare @@STRAccess as varchar(2)
Declare @CountAccess as int
set @date=getdate()
--Deleting existing Permission and then set new one.
--if (@select=''false'')
-- begin
delete from tblMenu where profileId=@ProfileId and NavigationId=@NavigationId
set @IsExist= (select count(*)from tblmenu where ProfileId=@ProfileId and NavigationId=@NavigationId)
if (@IsExist <> 0)
begin
update tblmenu set [select]=@select , [insert]=@insert , [update]=@update , [delete]=@delete,
DateModified=@date , ModifiedBy=@ModifiedBy
where ProfileId=@ProfileId and NavigationId=@NavigationId
--exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
end
else
begin
if(@select =''1'')
begin
Set @count =(select count(*) from tblmenu where
NavigationId in (select Parent from tblNavigation where navigationId=@NavigationId) and ProfileId=@ProfileId)
If (@count=0)
Begin
Set @ParentId=(select isnull(Parent,0) from tblNavigation where navigationId=@NavigationId)
set @rootParent=(select isnull(Parent,0) from tblNavigation where navigationId=@ParentId)
if @ParentId<>0
begin
if @rootParent<>0
begin
set @checkRoot=(select count(*) from tblmenu where
NavigationId in (select Parent from tblNavigation
where NavigationId=@ParentId) and ProfileId=@ProfileId)
if (@checkRoot=0)
begin
insert into tblMenu(ProfileId , NavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@rootParent,@select,@insert,@update,@delete,@date,@ModifiedBy)
end
end
insert into tblMenu(ProfileId , NavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@ParentId,@select,@insert,@update,@delete,@date,@ModifiedBy)
end
End
insert into tblMenu(ProfileId , NavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@NavigationId,@select,@insert,@update,@delete,@date,@ModifiedBy)
set @AccessPath=(select isnull(AccessPath,'''') from tblnavigation where navigationId=@NavigationId)
IF @AccessPath<>''''
BEGIN
WHILE @AccessPath <>''''
BEGIN
SET @@AccessAnavigationId = CHARINDEX('','', @AccessPath)
IF @@AccessAnavigationId >0
BEGIN
SET @@STRAccess = CAST(LEFT(@AccessPath, @@AccessAnavigationId-1) AS Int)
SET @AccessPath = RIGHT(@AccessPath, LEN(@AccessPath)-@@AccessAnavigationId)
END
ELSE
BEGIN
SET @@STRAccess = CAST(@AccessPath AS int)
SET @AccessPath = ''''
END
SET @CountAccess =(select Count(*) from tblmenu where navigationid=@@STRAccess AND ProfileID=@ProfileId)
IF @CountAccess=0
BEGIN
Insert into tblMenu(ProfileId , NavigationID,[select],[insert],[update],[delete], DateModified,ModifiedBy)
values(@ProfileId,@@STRAccess,0,0,0,0,@date,@ModifiedBy)
END
END
END
--exec UspTblCentralMaintenanceInsert ''tblMenu'',''update'',''Permissions for a selected profile has been updated'',@Date, @ModifiedBy,@ProfileId
end
end
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfilePermission]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[UspTblProfilePermission] --1,''ManageAgency.aspx''
@ProfileId int,
@FormName varchar(100)
AS
/* SET NOCOUNT ON */
Declare @@NavigationId as int
set @@NavigationId = (select distinct isnull(NavigationId,0) from tblNavigation
Where FormName=@FormName)
print @@NavigationId
if @@NavigationId <>0
Begin
select [select], [insert], [update],[delete] from tblmenu
where ProfileId=@ProfileId and NavigationId=@@NavigationId
End
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTbldeletetmsProfilePermission]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Harendra Singh
-- Create date: 21/2/08
-- Description: delete all permission before assign new permission
-- =============================================
CREATE PROCEDURE [dbo].[UspTbldeletetmsProfilePermission] --1,0
-- Add the parameters for the stored procedure here
@ProfileId int,
@Result int output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @@NavigationId int
declare @@parent int
declare @@rootparent int
declare @@Count int
declare @@count2 int
Declare @@Countroot int
DECLARE @@NavigationIdlevel2 INT
-- Insert statements for procedure here
--BEGIN TRAN
DECLARE Cursor_Parent CURSOR FOR
select navigationId from tblnavigation
where formname is null order by parent desc
OPEN Cursor_Parent
FETCH Cursor_Parent
INTO @@NavigationId
WHILE @@Fetch_Status = 0
BEGIN
SET @@Count=(SELECT count(distinct M.NavigationId)
FROM dbo.tblMenu M
INNER JOIN
dbo.tblNavigation N
ON M.NavigationId = N.NavigationId where N.Parent=@@NavigationId and M.profileId=@ProfileId)
IF @@Count>0
BEGIN
DECLARE Cursor_Parent_level3 CURSOR FOR
SELECT M.NavigationId
FROM dbo.tblMenu M
INNER JOIN
dbo.tblNavigation N
ON M.NavigationId = N.NavigationId where N.Parent=@@NavigationId and profileId=@ProfileId and N.Formname is null
OPEN Cursor_Parent_level3
FETCH Cursor_Parent_level3
INTO @@NavigationIdlevel2
WHILE @@Fetch_Status = 0
BEGIN
SET @@Count=(SELECT count(distinct M.NavigationId)
FROM dbo.tblMenu M
INNER JOIN
dbo.tblNavigation N
ON M.NavigationId = N.NavigationId where N.Parent=@@NavigationIdlevel2 and profileId=@ProfileId)
IF @@Count=0
BEGIN
delete from tblmenu where navigationId =@@NavigationIdlevel2 and profileId=@ProfileId
END
FETCH NEXT FROM Cursor_Parent_level3 INTO @@NavigationIdlevel2
END
CLOSE Cursor_Parent_level3
DEALLOCATE Cursor_Parent_level3
set @@Countroot=(SELECT count( M.NavigationId)
FROM dbo.tblMenu M
INNER JOIN
dbo.tblNavigation N
ON M.NavigationId = N.NavigationId where N.Parent=@@NavigationId and profileId=@ProfileId)
IF @@Countroot=0
BEGIN
delete from tblmenu where navigationId =@@NavigationId and profileId=@ProfileId
END
END
ELSE
BEGIN
--print ''level1''
--print (@@centralNavigationId)
delete from tblmenu where navigationId =@@NavigationId
and profileId=@ProfileId
END
FETCH NEXT FROM Cursor_Parent INTO @@NavigationId
END
CLOSE Cursor_Parent
DEALLOCATE Cursor_Parent
--IF @@ERROR <> 0
-- BEGIN
-- ROLLBACK TRAN
-- SET @Result=0
-- END
-- ELSE
-- BEGIN
-- COMMIT TRAN
-- SET @Result=1
-- END
END
--delete from tblcentralmenu where centralprofileid=@CentralProfileId
--
-- if @@ERROR <> 0
-- BEGIN
-- ROLLBACK TRAN
-- SET @Result=0
-- END
-- ELSE
-- BEGIN
-- COMMIT TRAN
-- SET @Result=1
-- END
--END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblProfileSelectAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 27/Sep/2007
-- Description: Select All profiles for central admin
-- =============================================
CREATE PROCEDURE [dbo].[UspTblProfileSelectAll]
-- Add the parameters for the stored procedure here
@ddl INT = 0
As
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF @ddl=0
BEGIN
SELECT p.ProfileId ,p.ProfileName,
Convert(VARCHAR,p.DateModified,106) as DateModified,
Status=CASE p.deleted When ''False'' then ''Active''
Else
''InActive''
END,
c.UserName as ModifiedBy
FROM tblProfile p
inner join
(Select ca.userid,FirstName+'' ''+LastName as UserName
From tblCentralAdmin ca
inner join tblCentralUserPersonalInfo ci
on
ca.userid=ci.userid )c
on p.ModifiedBy = c.UserId
where p.deleted=''false''
END
ELSE
BEGIN
SELECT p.ProfileId ,p.ProfileName
FROM tblProfile p
where p.deleted=''false''
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAdminRecoverPass]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 4/9/2007
-- Description: To recover the password for central admin user
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAdminRecoverPass]
-- Add the parameters for the stored procedure here
@UserName VARCHAR(50),
@EmailId VARCHAR(100) OUTPUT,
@Password Varchar(100),
@UserId INT OUTPUT,
@Name VARCHAR(100) OUTPUT,
@Profile VARCHAR(100) OUTPUT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
DECLARE @CH INT
SET @CH=(SELECT COUNT(*)
FROM tblCentralAdmin
WHERE UserName=@UserName
AND
Deleted=''False'')
IF(@CH=1)
BEGIN
BEGIN TRAN
UPDATE tblCentralAdmin SET Password=@Password,
PasswordCreationDate=getdate(),
PassReset=''True''
WHERE UserName=@UserName
And
Deleted=''False''
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @EmailId=(SELECT Email
FROM tblCentralAdmin
WHERE UserName=@UserName
AND
Deleted=''False''
)
SET @UserId=(SELECT UserId
FROM tblCentralAdmin
WHERE UserName=@UserName
AND
Deleted=''False''
)
SELECT @Name = FirstName + '' '' + LastName
FROM TblCentralUserPersonalInfo
WHERE CentralUserId=@UserId
SET @Profile=(SELECT cp.CentralProfileName
FROM tblCentralProfile cp
INNER JOIN tblCentralAdmin ca
ON ca.CentralProfileId = cp.CentralProfileId
WHERE ca.UserId=@UserId)
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert''tblCentralAdmin'',''Reset password'',''Password has been reset by the user'',@Date,@UserId,@UserId
SET @Result=1
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
ELSE
BEGIN
SET @Result=0
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralUsersNew]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 10-Sep, 2007
-- Description: Create new central Administrator users
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralUsersNew]-- ''hhh'',''hh'',''hh'',33,33,33,''afd'',1,122,''df'',''dsf'',124,null
-- Add the parameters for the stored procedure here
@UserName VARCHAR(50),
@FirstName varchar(50),
@LastName varchar(50),
@Telephone varchar(20),
@Mobile varchar(20),
@Fax varchar(20),
@PostalAddress varchar(1000),
@BusinessAddress varchar(1000),
@CountryId int,
@UserId INT,
@Password VARCHAR(100),
@Email VARCHAR(100),
@CentralProfileId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SET @Result=(SELECT COUNT(*)
FROM tblCentralAdmin
where UserName=@UserName)
IF(@Result=0)
BEGIN
BEGIN TRAN
INSERT INTO tblCentralAdmin(UserName,Password,Email,PasswordCreationDate,CentralProfileId,ModifiedBy,PassReset)
VALUES(@UserName,@Password,@Email,getdate(),@CentralProfileId,@UserId,''True'')
DECLARE @NewUserId INT
SET @NewUserId = (SELECT ISNULL(MAX(UserId),0) FROM tblCentralAdmin)
PRINT(@NewUserId)
Insert into tblCentralUserPersonalInfo(UserId,FirstName,LastName,Telephone,Mobile,CountryId,Fax,PostalAddress,BusinessAddress,ModifiedBy) values
(@NewUserId,@FirstName,@LastName,@Telephone,@Mobile,@CountryId,@Fax,@PostalAddress,@BusinessAddress,@UserId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralAdmin'',''Insertion'',''New Central user has been created'',@Date,@UserId,@NewUserId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCentralUsersUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 14/Sep/2007
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UspTblCentralUsersUpdate]
-- Add the parameters for the stored procedure here
@UserId INT,
@Email VARCHAR(100),
@FirstName VARCHAR(50),
@LastName VARCHAR(50),
@Telephone VARCHAR(20),
@Mobile VARCHAR(20),
@Fax VARCHAR(20),
@PostalAddress VARCHAR(1000),
@BusinessAddress VARCHAR(1000),
@CountryId INT,
@CentralProfileId INT,
@CentralAdminId INT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Result=(SELECT COUNT(*)
FROM tblCentralAdmin
WHERE UserName=@Email
AND
UserId<>@UserId )
IF(@Result=0)
BEGIN
BEGIN TRAN
DECLARE @No AS INT
SET @No = (SELECT count(*) FROM tblCentralUserPersonalInfo WHERE UserId=@UserId)
IF @No <> ''''
BEGIN
UPDATE tblCentralUserPersonalInfo
SET FirstName=@FirstName,
LastName=@LastName,
Telephone=@Telephone,
Mobile=@Mobile,
Fax=@Fax,
PostalAddress=@PostalAddress,
BusinessAddress=@BusinessAddress,
CountryId=@CountryId,
DateModified=getdate(),
ModifiedBy=@CentralAdminId
WHERE UserId=@UserId
END
ELSE
BEGIN
INSERT INTO tblCentralUserPersonalInfo
(UserId,FirstName,LastName,Telephone,
Mobile,Fax,PostalAddress,BusinessAddress,CountryId,
DateModified,ModifiedBy,Deleted)
VALUES(@UserId,@FirstName,@LastName,@Telephone,
@Mobile,@Fax,@PostalAddress,@BusinessAddress,@CountryId,
getDate(),@CentralAdminId,''False'')
END
UPDATE tblCentralAdmin
SET Email=@Email,
CentralProfileId=@CentralProfileId,
DateModified=getdate(),
ModifiedBy=@CentralAdminId
WHERE UserId=@UserId
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralUserPersonalInfo'',''Updation'',''User detail has been updated'',@Date,@CentralAdminId,@UserId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[uspPhysicalDeletion]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 301207
-- Description: PHYSICAL DELETE ALL THE DELETED RECORD PLACED IN TABLE
-- AFTER A FIX PERIOD OF TIME
-- =============================================
CREATE procedure [dbo].[uspPhysicalDeletion]
AS
BEGIN
DECLARE @AutoDeletemonth as int
Set @AutoDeletemonth=(Select autodeletemonths from tblsite WHERE [Default]=1 and Deleted=0)
DELETE FROM TblCentralUserPersonalInfo WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAccountuserPersonalInfo WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCentralAdmin WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblProduction WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCompany WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalent WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgency WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAllocation WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblBatchLine WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblInvoiceItem WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblJobPayment WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblLiability WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblBatchProduction WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAttribute WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblPaymentItem WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblJob WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyFee WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblGLAccount WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblInvoice WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblGLCategory WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblDisbursement WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblBatch WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCompanyAcess WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCompanyContact WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblPayment WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblLineType WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblSuperFund WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyTalent WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyRegisterGST WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentAccess WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblPerson WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblProductionType WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblSelection WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentAccount WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblCentralProfile WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentAttribute WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyContact WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblReceipt WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyAccount WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblInvoiceFrequency WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAdvance WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblAgencyAccess WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentRegisterGST WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
DELETE FROM tblTalentContact WHERE deleted=1 and datediff(month,datemodified,getdate())>=@AutoDeletemonth
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAdminChangePass]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 6/9/2007
-- Description: Change the current password to new password
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAdminChangePass]
-- Add the parameters for the stored procedure here
@OldPassword VARCHAR(100),
@NewPassword VARCHAR(100),
@UserId INT,
@Name VARCHAR(100) OUTPUT,
@Profile VARCHAR(50) OUTPUT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Pass VARCHAR(100)
SELECT @Pass=Password
FROM tblCentralAdmin
WHERE UserId=@UserId
AND
Deleted=''False''
IF(@OldPassword=@Pass)
BEGIN
BEGIN TRAN
UPDATE tblCentralAdmin
SET Password=@NewPassword,
PassReset=''False''
WHERE UserId=@UserId
And
Deleted=''False''
SELECT @Name=FirstName + '' '' + LastName
FROM TblCentralUserPersonalInfo
WHERE CentralUserId=@UserId
SET @Profile=(SELECT cp.CentralProfileName
FROM tblCentralProfile cp
INNER JOIN tblCentralAdmin ca
ON ca.CentralProfileId = cp.CentralProfileId
WHERE ca.UserId=@UserId)
IF(@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblCentralAdmin'',''Password changed'',''Old password has been changed with new one'',@Date, @UserId,@UserId
IF(@@ERROR<>0)
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
SET @Result=1
END
ELSE
BEGIN
SET @Result=0
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPTblAccountSelectByAccountID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/*
Author: Jatin
Create date: 4/9/2007
Description: Account Select by AccountID by Admin
*/
CREATE procedure [dbo].[USPTblAccountSelectByAccountID]
(
-- Add the parameters for the stored procedure here
@AccountID int,
@ProfileId int
)
as
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
a.AccountID, a.Phone, a.Fax, a.CountryId, a.PostalAddress, a.BusinessAddress, p.FirstName, p.PersonName, a.Name,
a.Description, a.url, p.Email, a.MaximumAgency,a.CurrencyId, a.ActivationDate, a.ExpiryDate,
datediff(dd, getdate(), a.ExpiryDate) as ValidDays, a.Deleted
FROM
tblAccount AS a
INNER JOIN
tblPerson as p ON p.AccountID=a.AccountID AND p.Deleted=''0''
INNER JOIN
tblMapPersonProfile as pp ON
pp.ProfileId=@ProfileId AND
pp.PersonId = p.PersonID
INNER JOIN tblAccountuserPersonalInfo AS api ON
api.AccountId=a.AccountID AND api.PersonId=p.personId
WHERE
a.AccountID=@AccountID
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountInsertByAdmin]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2007
-- Description: For Login Process
-- Modified By: Jagsir Singh:- Insertion into Log Table
-- Modified By: Jagsir Singh:- Set Default= true in person table like super admin for account application
-- =============================================
CREATE procedure [dbo].[UspTblAccountInsertByAdmin]
(
-- Add the parameters for the stored procedure here
@PersonName varchar(50),
@Password varchar(100),
@ProfileId int,
@Name varchar(100),
@FirstName varchar(50),
@Description varchar(2000),
@Email varchar(100),
@url varchar(100),
@Phone varchar(20),
@Fax varchar(20),
@MaximumAgency int,
@PostalAddress varchar(500),
@BusinessAddress varchar(500),
@RegistrationDate datetime,
@CurrencyId Int,
@ExpiryDate datetime,
--@SuspensionDate datetime=NULL,
@ActivationDate datetime,
@CountryId int,
--@ReasonForSuspension varchar(1000)=NULL,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
AS
DECLARE
@AccountId int,
@chkUserName int,
@PersonId int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET @Result=0
SET NOCOUNT ON;
SET @chkUserName = (SELECT COUNT(*) FROM tblPerson WHERE PersonName=@PersonName and Deleted=''0'')
IF @chkUserName > 0
BEGIN
SET @Result=-2
END
Else
BEGIN
BEGIN TRAN
set @AccountId = (SELECT ISNULL(MAX(AccountId),0) FROM tblAccount) + 1
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblAccount
(AccountId, Name, Description, Email, url, Phone, Fax, PostalAddress, BusinessAddress, MaximumAgency, RegistrationDate,
CountryId,CurrencyId,ExpiryDate, ActivationDate, Deleted, DateModified, ModifiedBy)
VALUES(@AccountId, @Name, @Description, @Email, @url, @Phone, @Fax, @PostalAddress, @BusinessAddress, @MaximumAgency, @RegistrationDate,
@CountryId,@CurrencyId,@ExpiryDate, @ActivationDate, @Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblPerson
(AccountID, PersonName, FirstName, Password, Email, Deleted,
DateModified, ModifiedBy, [Default],PassReset)
VALUES(@AccountID, @PersonName, @FirstName, @Password, @Email, @Deleted,
@DateModified, @ModifiedBy,''True'',''True'')
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
set @PersonId = (SELECT isnull(max(PersonID),1) from tblPerson)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblAccountuserPersonalInfo
(AccountId, PersonId, FirstName, LastName, PostalAddress,
BuisnessAddress, Telephone, Mobile, Fax, CountryId, Deleted,
DateModified, ModifiedBy)
VALUES
(@AccountId, @PersonId, @FirstName, '''', @PostalAddress,
@BusinessAddress, @Phone, @Phone, @Fax, @CountryId, @Deleted,
@DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblMapPersonProfile
(PersonId, ProfileId, Deleted,
DateModified, ModifiedBy)
VALUES(@PersonId, @ProfileId, @Deleted,
@DateModified, @ModifiedBy)
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblAccount'',''Insert'',''New Account has been Inserted'',@Date, @ModifiedBy,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountUpdateByAdmin]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2005
-- Description: To Delete Account Temporaryly
-- Modified By: Jagsir Singh:- Insertion into Log Table
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountUpdateByAdmin]
(
-- Add the parameters for the stored procedure here
@AccountID int,
@ProfileId int,
@Name varchar(100),
@FirstName varchar(50),
@Description varchar(2000),
@Email varchar(100),
@MaximumAgency int,
@ExpiryDate datetime,
@ActivationDate datetime,
@CurrencyId Int,
@CountryId Int,
@Phone varchar(20),
@Fax varchar(20),
@PostalAddress varchar(500),
@BusinessAddress varchar(500),
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
)
as
DECLARE
@chkEmail int
BEGIN
SET @Result=0
-- SET @chkEmail =(SELECT Count(*) FROM tblPerson WHERE Email=@Email and Deleted=''0''
-- AND tblPerson.PersonId not in(SELECT pp.PersonId
-- FROM
-- tblMapPersonProfile AS pp
-- INNER JOIN
-- tblPerson as p ON
-- p.PersonId=pp.PersonId AND
-- p.AccountId=@AccountID))
--
-- IF @chkEmail > 0
-- BEGIN
-- SET @Result=-1
-- END
-- Else
-- BEGIN
BEGIN TRAN
UPDATE tblAccount
SET
Name=@Name,
Description=@Description,
MaximumAgency=@MaximumAgency,
ExpiryDate=@ExpiryDate,
Phone = @Phone,
Fax=@Fax,
PostalAddress=@PostalAddress,
BusinessAddress=@BusinessAddress,
CountryId=@CountryId,
CurrencyId=@CurrencyId,
ActivationDate=@ActivationDate,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
AccountID=@AccountID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
UPDATE tblPerson
SET
tblPerson.Email=@Email,
tblPerson.FirstName=@FirstName
WHERE
(SELECT top 1 pp.PersonId
FROM
tblMapPersonProfile AS pp
INNER JOIN
tblPerson as p ON
p.PersonId=pp.PersonId
INNER JOIN
tblAccount AS a ON
a.AccountId=tblPerson.AccountId AND
p.AccountId=a.AccountId
WHERE
pp.ProfileId=@ProfileId)
= tblPerson.PersonId
AND
AccountID=@AccountID
DECLARE @Date DATETIME
SET @Date=getdate()
exec UspTblCentralMaintenanceInsert ''tblAccount'',''Update'',''Account detail has been updated'',@Date, @ModifiedBy,@AccountID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
--END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspAccountLogs]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 26/Sep/2007
-- Description: View the log history
-- =============================================
CREATE PROCEDURE [dbo].[UspAccountLogs]
-- Add the parameters for the stored procedure here
@AccountId INT,
@ModBy VARCHAR(50) = NULL,
@MDate DATETIME = NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @TableName VARCHAR(50)
DECLARE @Action VARCHAR(20)
DECLARE @Detail VARCHAR(100)
DECLARE @Datemodified DATETIME
DECLARE @Date DATETIME
DECLARE @Time DATETIME
DECLARE @ModifiedByName VARCHAR(50)
DECLARE @ModifiedBy INT
DECLARE @ModifiedName VARCHAR(50)
DECLARE @ModifiedId INT
DECLARE @TempTable TABLE
(
TableName VARCHAR(50),
Action VARCHAR(20),
DETAIL VARCHAR(100),
Date1 DATETIME,
Time DATETIME,
ModifiedByName VARCHAR(50),
ModifiedId INT
)
DECLARE Curser CURSOR FOR
SELECT MaintenanceTable,Action,Detail,DateModified,ModifiedBy,ModifiedId FROM tblmaintenance WHERE AccountId=@AccountId
OPEN Curser
FETCH Curser INTO @TableName,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId
WHILE @@Fetch_Status = 0
BEGIN
SET @ModifiedByName = (SELECT FirstName FROM tblPerson WHERE PersonId=@ModifiedBy)
/* IF @TableName = ''tblCentralAdmin''
BEGIN
SET @ModifiedName=(SELECT UserName from tblCentralAdmin WHERE UserId=@ModifiedId)
END
*/
SET @Date = @DateModified
SET @Time = @DateModified
INSERT INTO @TempTable(TableName,Action,Detail,Date1,Time,ModifiedByName,ModifiedId)
VALUES(@TableName,@Action,@Detail,@Date,@Time,@ModifiedByName,@ModifiedId)
FETCH Curser INTO @TableName,@Action,@Detail,@DateModified,@ModifiedBy,@ModifiedId
END
IF(@MDate<>'''')
BEGIN
IF(@ModBy<>'''')
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedId
FROM @TempTable WHERE ModifiedByName like ''%'' + @ModBy + ''%''
AND convert(varchar,Date1,106) = convert(varchar,@MDate,106)
order by Date1 desc
END
ELSE
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedId
FROM @TempTable WHERE convert(varchar,Date1,106) = convert(varchar,@MDate,106)
order by Date1 desc
END
END
ELSE
IF(@ModBy<>'''')
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedId
FROM @TempTable WHERE ModifiedByName like ''%'' + @ModBy + ''%''
order by Date1 desc
END
ELSE
BEGIN
SELECT TableName,Action,Detail,Convert(varchar(17),Date1,113) as Date,
Convert(varchar,Time,108) as Time,ModifiedByName,ModifiedId
FROM @TempTable
order by Date1 desc
END
CLOSE Curser
DEALLOCATE Curser
RETURN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblCompanySelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 170907
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[UsptblCompanySelect]--1
-- Add the parameters for the stored procedure here
@AccountId int,
@CompanyId int=null,
@Status bit=0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Select comp.CompanyId,comp.Companyname,compcont.Telephone,comp.Deleted,Countryname from tblcompany comp inner join tblcountry cntry on
-- comp.countryid=cntry.countryid left join tblcompanycontact compcont on comp.companyid=compcont.companyid and [Default]=1 where comp.CompanyId in(Select a.CompanyId from tblCompanyAcess a inner join tblperson p on
--a.PersonId=p.PersonId where AccountId=@AccountId) ,compcont.Telephone
if (@CompanyId>0)
BEGIN
SELECT comp.CompanyId,comp.Companyname,comp.Deleted,Countryname FROM
tblcompany comp
inner join tblcountry cntry on
comp.countryid=cntry.countryid
left join
tblcompanycontact compcont on
comp.companyid=compcont.companyid and [Default]=1 where comp.CompanyId =@CompanyId
and comp.Deleted=@Status order by comp.DateModified desc
End
Else
Begin
Select comp.CompanyId,comp.Companyname,comp.Deleted,Countryname from
tblcompany comp
inner join tblcountry cntry on
comp.countryid=cntry.countryid
left join tblcompanycontact compcont on
comp.companyid=compcont.companyid and [Default]=1 where comp.CompanyId in
(select Companyid from tblcompanyacess a inner join tblperson p on a.personid=p.personid where p.AccountId=@AccountId and p.deleted=0)
and comp.Deleted=@Status order by comp.DateModified desc
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 4/9/2005
--Modified Date: 27/09/2007
--Modified By: Manpreet
--Jatin 18-12-2007
-- Description: To Delete Account Temporaryly
-- =============================================
CREATE PROCEDURE [dbo].[UspTblTalentUpdate]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@TalentId int,
@Country varchar(20),
@TalentName varchar(100) ,
@Email varchar(100),
@Fax varchar(20),
@Registered bit,
@PostalAddress varchar(1000),
@ResidentialAddress varchar(1000),
@Telephone varchar(20),
@Mobile varchar(20),
@ABN varchar(20),
@TFN varchar(20),
@TalentSubAccountGL varchar(20),
@SuperannuationRate float,
@DateModified datetime,
@ModifiedBy varchar(50)
)
as
BEGIN
BEGIN TRAN
UPDATE tblTalent
SET
TalentName=@TalentName,
Country=@Country,
ABN=@ABN,
TFN=@TFN,
PostalAddress=@PostalAddress,
ResidentialAddress=@ResidentialAddress,
TalentSubAccountGL=@TalentSubAccountGL,
SuperannuationRate=@SuperannuationRate,
DateModified=@DateModified,
ModifiedBy=@ModifiedBy
WHERE
TalentId=@TalentId
UPDATE [Talent].[dbo].[tblTalentContact]
SET [Telephone] =@Telephone
,[Fax] =@Fax
,[Mobile] =@Mobile
,[Email] =@Email
WHERE [Default]=''true'' and TalentId=@TalentId
Update tblperson
set FirstName=@TalentName
where PersonId=(Select PersonId from tbltalentaccess where TalentId=@TalentId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
-- UPDATE [Talent].[dbo].[tblTalentRegisterGST]
-- SET [Date] = getdate()
-- ,[Registered] = @Registered
-- WHERE TalentId=@TalentId
--
-- IF @@ERROR <> 0
-- BEGIN
-- ROLLBACK TRAN
-- END
UPDATE tblPerson
SET
tblPerson.Email=@Email
WHERE
(SELECT top 1 pp.PersonId
FROM tblMapPersonProfile as pp
INNER JOIN
tblTalent AS t ON
t.TalentId=@TalentID
INNER JOIN
tblTalentAccess AS a ON a.TalentId=@TalentID
WHERE
pp.ProfileId=@ProfileId
And
pp.PersonId=a.PersonId)
=tblPerson.PersonId
AND
AccountID=@AccountID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblTalent'',''Update'',''Talent detail updated'',@Date,@ModifiedBy,@TalentId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCompanyDeleted]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 17/9/2007
-- Description: To Delete Company
-- =============================================
--ModifiedBy Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblCompanyDeleted]
(
-- Add the parameters for the stored procedure here
@CompanyID int,
@AccountId INT,
@ModifiedBy INT,
@Result int output
)
as
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
BEGIN TRAN
UPDATE tblCompany SET Deleted=1, ModifiedBy=@ModifiedBy WHERE CompanyID=@CompanyID
UPDATE tblperson SET deleted =1, ModifiedBy=@ModifiedBy WHERE personid=(SELECT Personid FROM
tblcompanyacess WHERE Companyid=@CompanyID)
DECLARE @Date DATETIME
SET @Date=getdate()
EXEC UsplTblMaintainanceInsert_new ''tblCompany'',''Delete'',''Company Deleted'',@Date,@ModifiedBy,@CompanyID,@AccountId
IF @@Error<> 0
BEGIN
SET @Result=0
ROLLBACK TRAN
END
ELSE
BEGIN
SET @Result=1
COMMIT TRAN
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblCompanyUpdateByCompanyId ]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 17/9/2007
-- Description:
-- =============================================
--ModifiedBy Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UsptblCompanyUpdateByCompanyId ]
-- Add the parameters for the stored procedure here
@CompanyId int,
@CountryId int,
@CompanyName varchar(100),
@IsInvoiceByEmail bit,
@PostalAddress varchar(1000),
@BuisnessAddress varchar(1000),
@Telephone varchar(20),
@Fax varchar(20),
@Mobile varchar(20),
@Email varchar(100),
@AccountId INT,
@ModifiedBy INT,
@Result int output
AS
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Set @Result=0
Begin Tran
update tblCompany set CompanyName=@CompanyName,
PostalAddress=@PostalAddress,
IsInvoiceByEmail=@IsInvoiceByEmail,
DateModified=getdate(),
BusinessAddress=@BuisnessAddress ,
CountryId=@CountryId
where CompanyId=@CompanyId
update tblCompanyContact set CompanyName=@CompanyName,
Telephone=@Telephone,
Fax=@Fax,
Mobile=@Mobile,
DateModified=getdate(),
Email=@Email
where CompanyId=@CompanyId and [Default]=1
Update tblPerson
Set FirstName=@CompanyName,
DateModified=getdate()
Where PersonId=(Select PersonId From tblCompanyAcess where CompanyId=@CompanyId )
if @@Error<>0
RollBack tran
else
Commit tran
set @Result=1
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblCompany'',''Update'',''Company Updated'',@Date,@ModifiedBy,@CompanyId,@AccountId
-- Set @MaintenanceTable=''tblCompanycontact''
-- Set @Action=''Update''
-- Set @Detail=''Update''
-- exec UsplTblMaintainanceInsert @MaintenanceTable,@Action, @Detail
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAccountUserUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 17-sep-2007
-- Description: Detail of various person acc to their profile
-- =============================================
--ModifiedBy: Jagsir Singh (7/Nov/2007)
--Modified By: Jagsir Singh (18/Feb/2008) --- insert profileid
CREATE PROCEDURE [dbo].[UsptblAccountUserUpdate]
-- Add the parameters for the stored procedure here
@AccountId int,
@FirstName varchar(50),
@LastName varchar(50),
@ProfileId INT,
@CountryId int,
@PostalAddress varchar(1000),
@BusinessAddress varchar(1000),
@Telephone varchar(20),
@Mobile varchar(20),
@Fax varchar(20),
@Email varchar(100) ,
@PersonId int ,
@ModifiedBy INT,
@Result int Output
AS
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Begin tran
UPDATE [Talent].[dbo].[tblAccountuserPersonalInfo]
SET
[FirstName] = @FirstName
,[LastName] = @LastName
,[PostalAddress] = @PostalAddress
,[BuisnessAddress] = @BusinessAddress
,[Telephone] = @Telephone
,[Mobile] = @Mobile
,[Fax] = @Fax
,[CountryId] = @CountryId
,[DateModified] = getdate()
WHERE AccountId=@AccountId and PersonId=@PersonId
update tblPerson
SET
[FirstName] = @FirstName,
[DateModified] = getdate(),
[Email]=@Email where PersonId=@PersonId
UPDATE tblMapPersonProfile
SET ProfileId=@ProfileId
WHERE PersonId=@PersonId
if @@ERROR <> 0
Begin
Rollback tran
set @Result=0
end
else
Begin
Commit tran
set @Result=1
end
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblAccountuserPersonalInfo'',''Update'',
''User Detail Updated'',@Date,@ModifiedBy,@PersonId,@AccountId
END
--
--select * from tblperson where personid in(select personid from tblmappersonprofile where profileid=3) and deleted=0
--select * from tblperson where personid in (select personid from tblaccountuserpersonalinfo) and deleted=0 and status=1
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspAccountLogIn_NEW]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 5 sep 2007
-- Description:
--Modified by: Harendra Singh
--Modified Date: 18/12/2007
-- =============================================
CREATE PROCEDURE [dbo].[UspAccountLogIn_NEW]
@UserName VARCHAR(50),
@Password VARCHAR(100),
@Result INT OUTPUT
AS
SET NOCOUNT ON
DECLARE @CH INT
DECLARE @LogId INT
DECLARE @PersonId INT
DECLARE @AccountId INT
DECLARE @@Check INT
Declare @@IsActiveProfile BIT
SELECT @Accountid=AccountId FROM tblPerson
WHERE PersonName=@UserName AND Password=@Password
SELECT @@Check = Count(AccountId) FROM tblAccount
WHERE AccountId=@AccountId
AND SuspensionDate < getdate()
IF(@@Check<>0)
BEGIN
SET @Result=1 -- Account Suspended
END
ELSE
BEGIN
SELECT @@Check = Count(AccountId) FROM tblAccount
WHERE AccountId=@AccountId
AND ExpiryDate < getdate()
IF(@@Check<>0)
BEGIN
SET @Result=2 -- Account Expired
END
ELSE
BEGIN
SELECT @@Check = Count(AccountId) FROM tblAccount
WHERE AccountId=@AccountId
AND Deleted=''True''
IF(@@Check<>0)
BEGIN
SET @Result=3 -- Account Deleted
END
ELSE
BEGIN
SELECT @PersonId=PersonId
FROM tblPerson
WHERE PersonName=@UserName
AND
Password=@Password
AND
Deleted=''False''
IF(@PersonId<>0)
BEGIN
----Check that profile is active
Select @@IsActiveProfile =InActive from tblProfile PR
INNER JOIN tblMapPersonProfile MP
ON PR.ProfileId =MP.ProfileId
Where MP.PersonId=@PersonId
IF (@@IsActiveProfile=''False'')
Begin
SELECT p.PersonId,p.AccountId,PersonName,p.Email,p.FirstName,p.[Default],p.PassReset
FROM tblPerson p
INNER JOIN tblAccount a
ON p.AccountId=a.AccountId
WHERE p.PersonId=@PersonId
BEGIN TRAN
UPDATE tblPerson
SET LastLogin=getdate()
WHERE PersonId=@PersonId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SELECT mp.ProfileId,p.ProfileName
FROM tblMapPersonProfile mp,
tblProfile p
WHERE PersonId=@PersonId
AND
mp.ProfileId=p.ProfileId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=6
COMMIT TRAN
End
Else
Begin
SET @Result=5 -- Profile is Inactive
End
END
ELSE
BEGIN
SET @Result=4 -- Wrong User Name or Password
END
END
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblPersonDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 011007
-- Description: Delete Selected Person From PersonTable
-- =============================================
CREATE PROCEDURE [dbo].[UsptblPersonDelete]
-- Add the parameters for the stored procedure here
@PersonId int,
@Result int output
AS
BEGIN
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
UPDATE tblPerson SET Deleted=1 WHERE PersonId=@PersonId
SET @MaintenanceTable=''tblPerson''
SET @Action=''Update''
SET @Detail=''Delete user''
EXEC UsplTblMaintainanceInsert @MaintenanceTable,@Action, @Detail
IF @@Error<> 0
SET @Result=0
ELSE
SET @Result=1
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblGetUserAccess]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 18/Feb/2008
-- Description: Return User Access to Agency
-- =============================================
CREATE PROCEDURE [dbo].[UspTblGetUserAccess] --1,1
-- Add the parameters for the stored procedure here
@AccountId INT,
@AgencyId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT p.PersonId, p.PersonName,
CASE WHEN ((SELECT COUNT(*) FROM tblAgencyAccess AS aa
WHERE aa.AgencyId=@AgencyId AND aa.PersonId=p.PersonId) > 0)
THEN ''true'' ELSE ''false'' END AS IsAccess FROM tblPerson AS p
INNER JOIN tblMapPersonProfile AS mpp ON
mpp.ProfileId<>1 AND mpp.ProfileId=2 AND mpp.PersonId=p.PersonId
WHERE
p.AccountId=@AccountId AND p.Deleted=''false''
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspCompanyInfoInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Geeta
-- Create date: 11/9/2007
-- Description: For Login Process
----Modified By: Manpreet Singh
-----Modified Date: 19/9/2007
-- =============================================
-- ModifiedBy Jagsir Singh (30/Nov/2007)
CREATE procedure [dbo].[UspCompanyInfoInsert]
(
-- Add the parameters for the stored procedure here
@AccountId int,
@Password varchar(50),
@ProfileId int,
@CountryId Int,
@IsInvoiceByEmail bit,
@CompanyName varchar(50),
@UserName varchar(50),
@PostalAddress varchar(1000),
@BusinessAddress varchar(1000),
@Telephone varchar(20),
@Mobile varchar(20),
@Fax varchar(20),
@Email varchar(100),
@ModifiedBy INT,
@Result INT OUTPUT
)
AS
DECLARE
@chkUserName int,
@chkEmail int,
@PersonId int,
@CompanyId int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
SET NOCOUNT ON;
SET @Result=0
SET @chkEmail = (SELECT COUNT(*) FROM tblPerson WHERE Email=@Email AND AccountID=@AccountID and Deleted=0)
SET @chkUserName = (SELECT COUNT(*) FROM tblPerson WHERE PersonName=@UserName and Deleted=''0'')
IF @chkUsername > 0
BEGIN
SET @Result=-2
END
Else
BEGIN
BEGIN TRAN
INSERT INTO tblPerson(AccountID, Email, Password, PersonName,Firstname,DateModified,ModifiedBy,PassReset)
VALUES
(@AccountID, @Email, @Password, @UserName,@CompanyName,GetDate(),@ModifiedBy,''True'')
set @PersonId = (SELECT isnull(max(PersonID),1) from tblPerson)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblMapPersonProfile
(PersonId, ProfileId)
VALUES(@PersonId, @ProfileId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblCompany
(
CountryID,
CompanyName,
IsInvoiceByEmail,
PostalAddress,
BusinessAddress
)
VALUES
(
@CountryID,
@CompanyName,
@IsInvoiceByEmail,
@PostalAddress,
@BusinessAddress
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
Select @CompanyId=Max(CompanyId) from tblCompany
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblCompanyAcess
(
PersonId,
CompanyId
)
VALUES
(
@PersonId,
@CompanyId
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
Insert Into tblCompanyContact
(
CompanyId,
CompanyName,
Title,
Telephone,
Fax,
Mobile,
Email,
[Default]
)
Values
(
@CompanyId,
@companyName,
''Main Contact'',
@Telephone,
@fax,
@Mobile,
@Email,
1
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblCompany'',''Insert'',''Company Inserted'',@Date,@ModifiedBy,@CompanyId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
IF @chkEmail > 0
BEGIN
SET @Result=-1
END
Else
BEGIN
SET @Result=1
END
COMMIT TRAN
END
END'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAccountUserSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 17-sep-2007
-- Description: Detail of various person acc. to their profile
-- =============================================
--ModifiedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UsptblAccountUserSelect]--1,0
-- Add the parameters for the stored procedure here
@AccountId int,
@PersonId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF @PersonId > 0
BEGIN
SELECT p.PersonId, ap.FirstName,ap.LastName, ISNULL(convert(varchar,p.LastLogin,106),''Never'') as LastLogin, ap.CountryId,
p.AccountID, pr.ProfileName,p.Email,
ap.Telephone, ap.Mobile, ap.Fax,
ap.PostalAddress,ap.BuisnessAddress,pr.ProfileId
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId LEFT OUTER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId
WHERE p.AccountID = @AccountId AND p.PersonId=@PersonId
AND pr.profileid<3 and p.Deleted=0
END
ELSE
BEGIN
SELECT p.PersonId, p.FirstName, ISNULL(convert(varchar,p.LastLogin,106),''Never'') as LastLogin,
p.AccountID, pr.ProfileName,pr.ProfileId,[Default]
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId LEFT OUTER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblPersonSelectByProfile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: MANPREET SINGH
-- Create date: 170807
-- Description: Detail of various person acc to their profile
-- =============================================
CREATE PROCEDURE [dbo].[UsptblPersonSelectByProfile]
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT per.PersonId,PersonName,Email,per.Deleted ,Convert(varchar,LastLogin,107)+'' | ''+ Convert(varchar,LastLogin,108) as LastLogin
FROM tblPerson per inner join tblmappersonprofile map on per.personid=map.personid and
map.profileid=@ProfileId
WHERE Accountid=@AccountId and per.Deleted=0 ORDER BY per.DateModified desc
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblUserWiseDdlAgencies]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 4/Nov/2007
-- Description: Select only those Agencies on which the person has permissions to access
-- =============================================
CREATE PROCEDURE [dbo].[UspTblUserWiseDdlAgencies] --1,6
-- Add the parameters for the stored procedure here
@AccountId INT,
@PersonId INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @ProfileId INT
SELECT @ProfileId = mp.ProfileId
FROM tblMapPersonProfile mp
INNER JOIN tblPerson p
ON mp.PersonId=p.PersonId
AND p.PersonId=@personId
IF(@ProfileId=2)
BEGIN
SELECT a.AgencyId,a.AgencyName
FROM tblAgency a
INNER JOIN tblAgencyAccess aa
ON a.AgencyId=aa.AgencyId
WHERE aa.PersonId=@PersonId
AND a.AccountId=@AccountId
AND a.Deleted=''False''
END
ELSE
BEGIN
SELECT a.AgencyId,a.AgencyName
FROM tblAgency a
WHERE AccountId=@AccountId
AND a.deleted=''False''
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountChangePassword]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 7/9/2007
-- Description: Change the current password to new password
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountChangePassword]
-- Add the parameters for the stored procedure here
@OldPassword VARCHAR(100),
@NewPassword VARCHAR(100),
@PersonId INT,
@Name VARCHAR(100) OUTPUT,
@Profile VARCHAR(100) OUTPUT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Pass VARCHAR(100)
SELECT @Pass=Password
FROM tblPerson
WHERE PersonId=@PersonId
AND
Deleted=''False''
IF(@OldPassword=@Pass)
BEGIN
BEGIN TRAN
UPDATE tblPerson
SET Password=@NewPassword,
PassReset=''False'',
DateModified=getdate(),
ModifiedBy=@PersonId
WHERE PersonId=@PersonId
AND
Deleted=''False''
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SELECT @Name=FirstName
FROM tblPerson
WHERE PersonId=@PersonId
SET @Profile=(SELECT ProfileName
FROM tblProfile p
INNER JOIN tblMapPersonProfile mp
ON p.ProfileId=mp.ProfileId
WHERE mp.PersonId=@PersonId)
DECLARE @AccountId INT
SELECT @AccountId = AccountId
FROM tblPerson
WHERE PersonId=@PersonId And Deleted=''False''
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblPerson'',''Password changed'',''Old password has been changed with new one'',@Date,@PersonId,@PersonId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
SET @Result=1
END
ELSE
BEGIN
SET @Result=0
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblAccountRecoverPassword]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jagsir Singh
-- Create date: 7/9/2007
-- Description: To recover the password for Account user
-- =============================================
CREATE PROCEDURE [dbo].[UspTblAccountRecoverPassword]
-- Add the parameters for the stored procedure here
@UserName VARCHAR(50),
@Password Varchar(100),
@EmailId VARCHAR(100) OUTPUT,
@Name VARCHAR(100) OUTPUT,
@Profile VARCHAR(100) OUTPUT,
@Result INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
DECLARE @CH INT
SET @CH=(SELECT COUNT(*)
FROM tblPerson
WHERE PersonName=@UserName
AND
Deleted=''False'')
IF(@CH=1)
BEGIN
BEGIN TRAN
DECLARE @PersonId INT
SET @PersonId=(SELECT PersonId
FROM tblPerson
WHERE PersonName=@UserName
AND
Deleted=''False'')
SELECT @Name=FirstName
FROM tblPerson
WHERE PersonId=@PersonId
UPDATE tblPerson
SET Password=@Password,
DateModified=getdate(),
ModifiedBy=@PersonId,
PassReset=''True''
WHERE PersonId=@PersonId
SET @Profile=(SELECT ProfileName
FROM tblProfile p
INNER JOIN tblMapPersonProfile mp
ON p.ProfileId=mp.ProfileId
WHERE mp.PersonId=@PersonId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @EmailId=(SELECT Email
FROM tblPerson
WHERE PersonId=@PersonId)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @AccountId INT
SELECT @AccountId = AccountId
FROM tblPerson
WHERE PersonId=@PersonId And Deleted=''False''
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblPerson'',''Reset password'',''Password hes been reset by the user'',@Date,@PersonId,@PersonId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN
SET @Result=1
END
ELSE
BEGIN
SET @Result=0
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblTalentInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin
-- Create date: 5-sep-2007
-- Description:
--Jatin 18-12-2007
-- =============================================
-- ModififedBy: Jagsir Singh (30/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblTalentInsert]
-- Add the parameters for the stored procedure here
@AccountId int,
@PersonName varchar(50),
@Email varchar(100),
@Password varchar(100),
@ProfileId int,
@Country varchar(20),
@TalentName varchar(100),
@PostalAddress varchar(1000),
@ResidentialAddress varchar(1000),
@Telephone varchar(20),
@Registered bit,
@Mobile varchar(20),
@ABN varchar(20),
@TFN varchar(20),
@Fax varchar(20),
@TalentSubAccountGL varchar(20),
@SuperannuationRate float,
@Deleted bit,
@DateModified datetime,
@ModifiedBy int,
@Result INT OUTPUT
AS
DECLARE
@chkUsername int,
@chkEmail int,
@PersonId int,
@TalentId int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @Result=0
SET @chkEmail = (SELECT COUNT(*) FROM tblPerson WHERE Email=@Email and AccountId=@AccountId and Deleted=''0'')
SET @chkUserName = (SELECT COUNT(*) FROM tblPerson WHERE PersonName=@PersonName and Deleted=''0'')
IF @chkUsername > 0
BEGIN
SET @Result=-2
END
Else
BEGIN
BEGIN TRAN
INSERT INTO tblTalent
(Country, TalentName, ABN, TFN,
PostalAddress, ResidentialAddress,
TalentSubAccountGL, SuperannuationRate,
Deleted, DateModified, ModifiedBy)
VALUES(@Country, @TalentName, @ABN, @TFN,
@PostalAddress, @ResidentialAddress,
@TalentSubAccountGL, @SuperannuationRate,
@Deleted, @DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
set @TalentId = (SELECT isnull(max(TalentId),1) from tblTalent)
INSERT INTO [Talent].[dbo].[tblTalentContact]
([TalentId]
,[Title]
,[Telephone]
,[Fax]
,[Mobile]
,[Email]
,[Default]
)
VALUES
(@TalentId
,''main contact''
,@Telephone
,@Fax
,@Mobile
,''true''
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblPerson
(AccountID, PersonName,FirstName, Email, Password, Deleted,
DateModified, ModifiedBy,PassReset)
VALUES(@AccountID, @PersonName,@TalentName, @Email, @Password, @Deleted,
@DateModified, @ModifiedBy,''True'')
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO [Talent].[dbo].[tblTalentRegisterGST]
([TalentId]
,[Date]
,[Registered]
)
VALUES
(@TalentId
,getdate()
,@Registered
)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
set @PersonId = (SELECT isnull(max(PersonID),1) from tblPerson)
INSERT INTO tblMapPersonProfile
(PersonId, ProfileId, Deleted,
DateModified, ModifiedBy)
VALUES(@PersonId, @ProfileId, @Deleted,
@DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
INSERT INTO tblTalentAccess
(PersonId, TalentId, Deleted,
DateModified, ModifiedBy)
VALUES(@PersonId, @TalentId, @Deleted,
@DateModified, @ModifiedBy)
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblTalent'',''Insert'',''New Talent Added'',@Date,@ModifiedBy,@TalentId,@AccountId
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
IF @chkEmail > 0
BEGIN
SET @Result=-1
END
Else
BEGIN
SET @Result=1
END
COMMIT TRAN
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblPersonInsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 6-sep-2007
-- Description: Create a new USer !
-- =============================================
--ModifiedBy: Jagsir Singh (7/Nov/2007)
CREATE PROCEDURE [dbo].[UspTblPersonInsert]
-- Add the parameters for the stored procedure here
@AccountId int,
@ProfileId int,
@PersonName varchar(50),
@FirstName varchar(50),
@LastName varchar(50),
@CountryId int,
@PostalAddress varchar(1000),
@BusinessAddress varchar(1000),
@Telephone varchar(20),
@Mobile varchar(20),
@Fax varchar(20),
@Password varchar(100),
@Email varchar(100) ,
@ModifiedBy INT,
@Result int Output
AS
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
Declare @PersonId int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Set @Result=0
-- BEGIN TRAN
insert into TblPerson(AccountID,PersonName,FirstName,Password,Email,DateModified,ModifiedBy,PassReset)
values( @AccountId ,@PersonName,@FirstName,@Password,@Email,GETDATE(),@ModifiedBy,''True'')
select @PersonId=ISnull(max(PersonId),0) from tblperson --Select Latest inserted person id in person table
Insert into TblmapPersonProfile(PersonId,ProfileId) values(@PersonId,@ProfileId)
INSERT INTO [Talent].[dbo].[tblAccountuserPersonalInfo]
([PersonId]
,[AccountId]
,[FirstName]
,[LastName]
,[PostalAddress]
,[BuisnessAddress]
,[Telephone]
,[Mobile]
,[Fax]
,[CountryId]
)
VALUES
(@PersonId,
@AccountId
,@FirstName
,@LastName
,@PostalAddress
,@BusinessAddress
,@Telephone
,@Mobile
,@Fax
,@CountryId
)
DECLARE @Date DATETIME
SET @Date=getdate()
exec UsplTblMaintainanceInsert_new ''tblPerson'',''New User'',''New User has been created'',@Date, @ModifiedBy,@PersonId,@AccountId
-- if @@Error<>0 ---it means some error occur while executing Query then Rollback transaction
-- BEGIN
-- Rollback tran
-- END
-- Commit Tran
set @Result=1
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UsptblAccountUserSearch]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 8-jan-2008
-- Description: Detail of various person acc. to their profile
-- =============================================
CREATE PROCEDURE [dbo].[UsptblAccountUserSearch]--1,''m'',1
-- Add the parameters for the stored procedure here
@AccountId int,
@Firstname varchar(50),
@ProfileId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
IF @FirstName <>''''
BEGIN
if @Profileid>0
BEGIN
SELECT p.PersonId, ap.FirstName,ap.LastName, ISNULL(convert(varchar,p.LastLogin,106),''Never'')as LastLogin, ap.CountryId,
p.AccountID, pr.ProfileName,p.Email,pr.ProfileId,
ap.Telephone, ap.Mobile, ap.Fax,
ap.PostalAddress,ap.BuisnessAddress
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId and mp.profileid=@ProfileId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId INNER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId and ap.FirstName like ''%''+@Firstname +''%''
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
ELSE
BEGIN
SELECT p.PersonId, ap.FirstName,ap.LastName,ISNULL(convert(varchar,p.LastLogin,106),''Never'')as LastLogin, ap.CountryId,
p.AccountID, pr.ProfileName,p.Email,pr.ProfileId,
ap.Telephone, ap.Mobile, ap.Fax,
ap.PostalAddress,ap.BuisnessAddress
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId INNER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId and ap.FirstName like ''%''+@Firstname +''%''
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
END
Else
BEGIN
if @Profileid>0
BEGIN
SELECT p.PersonId, ap.FirstName,ap.LastName, ISNULL(convert(varchar,p.LastLogin,106),''Never'')as LastLogin, ap.CountryId,
p.AccountID, pr.ProfileName,p.Email,pr.ProfileId,
ap.Telephone, ap.Mobile, ap.Fax,
ap.PostalAddress,ap.BuisnessAddress
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId and mp.profileid=@ProfileId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId INNER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
ELSE
BEGIN
SELECT p.PersonId, p.FirstName, ISNULL(convert(varchar,p.LastLogin,106),''Never'')as LastLogin,
p.AccountID, pr.ProfileName,pr.ProfileId
FROM tblPerson p INNER JOIN
dbo.tblMapPersonProfile mp ON p.PersonId = mp.PersonId INNER JOIN
dbo.tblProfile pr ON mp.ProfileId = pr.ProfileId INNER JOIN
dbo.tblAccountuserPersonalInfo ap ON p.PersonId = ap.PersonId
WHERE p.AccountID = @AccountId
AND pr.profileid<3 and p.Deleted=0
order by p.datemodified desc
END
END
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspPersonLogIn]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 060807
-- Description: CHECK EXISTENCE OF PERSONNAME AND EMAIL IN PERSON TABLE
-- =============================================
CREATE PROCEDURE [dbo].[UspPersonLogIn]
@AccountId int,
@PersonName VARCHAR(50),
@Email varchar(100),
@Result int output
AS
SET NOCOUNT ON
if exists(SELECT PersonId FROM tblPerson WHERE PersonName=@PersonName)
set @Result=1
else
if exists(Select PersonId from tblPerson where Email=@Email and AccountId=@AccountId and Deleted=0)
set @Result=2
else
set @Result=0
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblReceiptInsertUpdate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Manpreet Singh
-- Create date: 211107
-- Description: Add/Update Receipt
--Modifiedby: Harendra Singh
--Modified Date: 291107
-- =============================================
CREATE PROCEDURE [dbo].[UspTblReceiptInsertUpdate]
@AccountId int,
@ReceiptId int=0,
@ProductionId int ,
@BankAccount varchar(20),
@CurrencyId int=0,
@ReceiptDate datetime,
@Amount float,
@Reference varchar(20),
@Description varchar(100),
-- @Posted bit,
@Type varchar(30),
@Result INT OUTPUT
AS
Declare @MaintenanceTable varchar(50)
Declare @Action varchar(100)
Declare @Detail varchar(1000)
Declare @Posted as bit
BEGIN
SET @Posted=''False''
SET @Result=0
BEGIN TRAN
if (@Type=''insert'' )
Begin
INSERT INTO [Talent].[dbo].[tblReceipt]
([ProductionId]
,[AccountId]
,[BankAccount]
,[CurrencyId]
,[ReceiptDate]
,[Amount]
,[Reference]
,[Description]
,[Posted]
)
VALUES
(
@ProductionId
,@AccountId
,@BankAccount
,@CurrencyId
,@ReceiptDate
,@Amount
,@Reference
,@Description
,@Posted
)
End
else if (@Type=''update'' )
Begin
UPDATE [Talent].[dbo].[tblReceipt]
SET [ProductionId] = @ProductionId
,[BankAccount] = @BankAccount
,[CurrencyId]=@CurrencyId
,[ReceiptDate] = @ReceiptDate
,[Amount] = @Amount
,[Reference] = @Reference
,[Description]=@Description
--,[Posted] = @Posted
WHERE ReceiptId= @ReceiptId and AccountId=@AccountId
End
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
SET @Result=1
COMMIT TRAN
if @Type=''insert''
Begin
Set @MaintenanceTable=''tblReceipt''
Set @Action=''Insert''
Set @Detail=''New Document has been inserted''
exec UsplTblMaintainanceInsert @MaintenanceTable,@Action, @Detail
End
if @Type=''update''
Begin
Set @MaintenanceTable=''tbl Receipt''
Set @Action=''update''
Set @Detail=''New Document has been updated''
exec UsplTblMaintainanceInsert @MaintenanceTable,@Action, @Detail
End
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspRptTalentEarning]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author: Jatin Kumar
-- Create date: 17/Dec/2007
--Modified date: 21/01/2008, 23/01/2008
-- Description: View Talent Earning to print
-- =============================================
CREATE PROCEDURE [dbo].[UspRptTalentEarning] --1,1,1
-- Add the parameters for the stored procedure here
@TalentId int,
@AgencyId Int,
@AccountId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT DISTINCT dbo.tblTalent.TalentName, dbo.tblProduction.ProductionTitle, dbo.tblAgency.AgencyName, dbo.tblAgencyContact.Email AS AgencyEmail,
dbo.tblAgency.PostalAddress, CONVERT(VARCHAR(15), dbo.tblInvoice.InvoicDate, 106) AS InvoicDate, dbo.tblLineType.LineType, CONVERT(VARCHAR(15), dbo.tblPayment.Date, 106) AS DatePaidToTalent,
dbo.tblPayment.Reference, CONVERT(VARCHAR(15), dbo.tblReceipt.ReceiptDate, 106) AS ReceiptDate, dbo.tblJob.Description AS JobDescription, dbo.tblCompany.CompanyName,
dbo.tblJob.IsEmployee, dbo.tblPaymentItem.Amount, dbo.tblSite.Version
FROM dbo.tblPaymentItem
INNER JOIN
dbo.tblPayment ON dbo.tblPaymentItem.PaymentId = dbo.tblPayment.PaymentID
INNER JOIN
dbo.tblReceipt ON dbo.tblPayment.ReceiptID = dbo.tblReceipt.ReceiptId
INNER JOIN
dbo.tblProduction ON dbo.tblPayment.ProductionId = dbo.tblProduction.ProductionID AND
dbo.tblReceipt.ProductionId = dbo.tblProduction.ProductionID
INNER JOIN
dbo.tblInvoice ON dbo.tblProduction.ProductionID = dbo.tblInvoice.ProductionId
INNER JOIN
dbo.tblJob ON dbo.tblProduction.ProductionID = dbo.tblJob.ProductionId
INNER JOIN
dbo.tblCompany ON dbo.tblProduction.CompanyId = dbo.tblCompany.CompanyId
INNER JOIN
dbo.tblLiability ON dbo.tblPaymentItem.LiabilityId = dbo.tblLiability.LiabilityId AND dbo.tblReceipt.ReceiptId = dbo.tblLiability.ReceiptId AND
dbo.tblInvoice.InvoiceId = dbo.tblLiability.InvoiceId
INNER JOIN
dbo.tblLineType ON dbo.tblLiability.LineTypeId = dbo.tblLineType.LineTypeId
INNER JOIN
dbo.tblAgency ON dbo.tblProduction.AgencyId = dbo.tblAgency.AgencyId AND dbo.tblInvoice.AgencyId = dbo.tblAgency.AgencyId
INNER JOIN
dbo.tblAgencyContact ON dbo.tblAgency.AgencyId = dbo.tblAgencyContact.AgencyId AND dbo.tblAgencyContact.[Default]=''1''
INNER JOIN
dbo.tblTalent ON dbo.tblInvoice.TalentId = dbo.tblTalent.TalentId AND dbo.tblJob.TalentId = dbo.tblTalent.TalentId
INNER JOIN
dbo.tblAccount ON dbo.tblPayment.AccountId = dbo.tblAccount.AccountId AND dbo.tblProduction.AccountId = dbo.tblAccount.AccountId AND
dbo.tblLiability.AccountId = dbo.tblAccount.AccountId
LEFT JOIN
dbo.tblSite ON dbo.tblSite.[Default]=1 AND dbo.tblSite.AccountId = dbo.tblAccount.AccountId
WHERE tblTalent.TalentId=@TalentId AND
dbo.tblAgency.AgencyId=@AgencyId AND
dbo.tblAccount.AccountId=@AccountId
END
'
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UspTblCheckRecieptCurrency]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:
-- Create date: <5/12/2007>
-- Description:
Comments