You are on page 1of 17

PROJECT CODE

Name: Muhammad Umer Farooq Malik

Reg-No:SP19-BCS-036
Section: 4B

Title
Star Academy System
Tbl_Student:
CREATE TABLE [dbo].[tbl_student](
[Id] [int] NOT NULL,
[StudentFullName] [nvarchar](50) NULL,
[Phone] [nvarchar](50) NULL,
[Cell] [nvarchar](50) NULL,
[CurrentAddress] [nvarchar](150) NULL,
[Town] [nvarchar](50) NULL,
[City] [nvarchar](50) NULL,
[District] [nvarchar](50) NULL,
[DateOfBirth] [datetime] NULL,
[EmailAddress] [nvarchar](50) NULL,
[Religion] [nvarchar](50) NULL,
[Gender] [nvarchar](50) NULL,
[Campus] [nvarchar](50) NULL,
[RegNo] [nvarchar](50) NULL,
[RollNo] [nvarchar](50) NULL,
[MissionInLife] [nvarchar](150) NULL,
[DateOfAdmission] [datetime] NULL,
[FK_ShiftID] [int] NULL,
[FK_FatherDetailID] [int] NULL,
[FK_SubjectID] [int] NULL,
[FK_EducationRecID] [int] NULL,
[FK_SiblingsID] [int] NULL,
[FK_OfficeUseOnlyID] [int] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_EducationRecID])


REFERENCES [dbo].[tbl_studenteducationalrecord] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_EducationRecID])


REFERENCES [dbo].[tbl_studenteducationalrecord] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_FatherDetailID])


REFERENCES [dbo].[tbl_studentfatherdetail] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_FatherDetailID])


REFERENCES [dbo].[tbl_studentfatherdetail] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_OfficeUseOnlyID])


REFERENCES [dbo].[tbl_studentofficeuseonly] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_OfficeUseOnlyID])


REFERENCES [dbo].[tbl_studentofficeuseonly] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_ShiftID])


REFERENCES [dbo].[tbl_shift] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_ShiftID])


REFERENCES [dbo].[tbl_shift] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_SiblingsID])


REFERENCES [dbo].[tbl_studentsiblings] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_SiblingsID])


REFERENCES [dbo].[tbl_studentsiblings] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_SubjectID])


REFERENCES [dbo].[tbl_studentsubject] ([Id])
GO

ALTER TABLE [dbo].[tbl_student] WITH CHECK ADD FOREIGN KEY([FK_SubjectID])


REFERENCES [dbo].[tbl_studentsubject] ([Id])
GO

Tbl_Student (Procedure):
create proc [dbo].[sp_student]
@Action nvarchar(50) = null,
@ShiftID nvarchar(50) = null,
@CID int = null,
@ClassID nvarchar(50) = null,
@ClassName nvarchar(50) = null,
@F_Id int = null,
@F_FatherName nvarchar(50) = null,
@F_ResidenceTel nvarchar(50) = null,
@F_Occupation nvarchar(100) = null,
@F_Qualification nvarchar(50) = null,
@F_CellNo nvarchar(50) = null,
@F_CNICNo nvarchar(50) = null,
@F_LivingWith nvarchar(50) = null,
@ER_Id int = null,
@ER_ExamPassed nvarchar(150) = null,
@ER_NameOfInstitute nvarchar(150) = null,
@ER_PassingYear nvarchar(150) = null,
@ER_ExaminingBoard nvarchar(150) = null,
@ER_MarksObtained nvarchar(150) = null,
@ER_Percentage nvarchar(150) = null,
@Sub_Id int = null,
@Sub_SubjectName nvarchar(50) = null,
@Sib_Id int = null,
@Sib_Name nvarchar(150) = null,
@Sib_Class nvarchar(150) = null,
@Sib_Institute nvarchar(150) = null,
@Sib_Profession nvarchar(150) = null,
@Sib_Organization nvarchar(150) = null,
@Sib_Designation nvarchar(150) = null,
@OR_Id int = null,
@OR_TutionFee decimal(20,2) = null,
@OR_AdmissionFee decimal(20,2) = null,
@OR_TestFund decimal(20,2) = null,
@OR_TotalFee decimal(20,2) = null,
@S_Id int = null,
@S_StudentFullName nvarchar(50) = null,
@S_Phone nvarchar(50) = null,
@S_Cell nvarchar(50) = null,
@S_CurrentAddress nvarchar(150) = null,
@S_Town nvarchar(50) = null,
@S_City nvarchar(50) = null,
@S_District nvarchar(50) = null,
@S_DateOfBirth DateTime = null,
@S_EmailAddress nvarchar(50) = null,
@S_Gender nvarchar(50) = null,
@S_Campus nvarchar(50) = null,
@S_RegNo nvarchar(50) = null,
@S_RollNo nvarchar(50) = null,
@S_Religion nvarchar(50) = null,
@S_MissionInLife nvarchar(150) = null,
@S_DateOfAdmission DateTime = null,
@IncomeID int=null,
@FID int =null

as
begin
/*
select * from staracademy.dbo.tbl_studentfatherdetail
select * from staracademy.dbo.tbl_studenteducationalrecord
select * from staracademy.dbo.tbl_studentsubject
select * from staracademy.dbo.tbl_studentsiblings
select * from staracademy.dbo.tbl_studentofficeuseonly
select * from staracademy.dbo.tbl_student
select * from staracademy.dbo.tbl_studentclasses
select * from tbl_income

*/

IF @Action='Insert'
begin

BEGIN TRANSACTION
BEGIN TRY
select * from staracademy.dbo.tbl_student

begin
insert into staracademy.dbo.tbl_studentfatherdetail
values(
@F_Id, @F_FatherName, @F_ResidenceTel, @F_Occupation,
@F_Qualification,
@F_CellNo, @F_CNICNo, @F_LivingWith
)
end;
begin
insert into staracademy.dbo.tbl_studenteducationalrecord
values(@ER_Id,@ER_ExamPassed,@ER_NameOfInstitute, @ER_PassingYear,
@ER_ExaminingBoard,
@ER_MarksObtained, @ER_Percentage
)
end;

begin
insert into staracademy.dbo.tbl_studentsubject values (
@Sub_Id, @Sub_SubjectName)
end;

begin
insert into staracademy.dbo.tbl_studentsiblings values (
@Sib_Id,@Sib_Name,@Sib_Class,@Sib_Institute,@Sib_Profession,
@Sib_Organization,@Sib_Designation)
end;

begin
insert into staracademy.dbo.tbl_studentofficeuseonly
values(
@OR_Id,@OR_TutionFee,@OR_AdmissionFee,@OR_TestFund, @OR_TotalFee)
end;

COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
print 'ERROR';
END CATCH;

begin

insert into staracademy.dbo.tbl_student


values(
@S_Id, @S_StudentFullName, @S_Phone,
@S_Cell, @S_CurrentAddress,
@S_Town, @S_City, @S_District,
@S_DateOfBirth, @S_EmailAddress,
@S_Religion, @S_Gender, @S_Campus,
@S_RegNo, @S_RollNo,
@S_MissionInLife, @S_DateOfAdmission, @ShiftID,
@F_Id,
@Sub_Id, @ER_Id,
@Sib_Id,@OR_Id)

insert into tbl_income values(@IncomeID,@OR_TotalFee,'Student Admission


Fee',GETDATE(),@FID)

insert into tbl_studentclasses values(@CID,@ClassID,@ClassName,@S_Id)

end;

end

IF @Action='Select'
begin
select * from viw_student
end

IF @Action='Update'
begin
BEGIN TRANSACTION
BEGIN TRY

update staracademy.dbo.tbl_studentfatherdetail
set FatherName = isnull(@F_FatherName,FatherName),
ResidenceTel = isnull(@F_ResidenceTel,ResidenceTel),
Occupation = isnull(@F_Occupation,Occupation),
Qualification = isnull(@F_Qualification,Qualification),
CellNo = isnull(@F_CellNo,CellNo),
CNICNo = isnull(@F_CNICNo,CNICNo),
LivingWith = isnull(@F_LivingWith,LivingWith)

where Id = @F_Id;

update staracademy.dbo.tbl_studenteducationalrecord
set ExamPassed = isnull(@ER_ExamPassed,ExamPassed),
NameOfInstitute =
isnull(@ER_NameOfInstitute,NameOfInstitute),
PassingYear =
isnull(@ER_PassingYear,PassingYear),
ExaminingBoard =
isnull(@ER_ExaminingBoard,ExaminingBoard),
MarksObtained = isnull(@ER_MarksObtained,MarksObtained),
Percentage = isnull(@ER_Percentage,Percentage)

where Id = @ER_Id;

update staracademy.dbo.tbl_studentsubject
set SubjectName =
isnull(@Sub_SubjectName,SubjectName)

where Id = @Sub_Id;

update staracademy.dbo.tbl_studentsiblings

set Name = isnull(@Sib_Name,Name),


Class = isnull(@Sib_Class,Class),
Institute = isnull(@Sib_Institute,Institute),
Profession =
isnull(@Sib_Profession,Profession),
Organization = isnull(@Sib_Organization,Organization),
Designation =
isnull(@Sib_Designation,Designation)

where Id = @Sib_Id;

update staracademy.dbo.tbl_studentofficeuseonly

set TutionFee = isnull(@OR_TutionFee,TutionFee),


AdmissionFee = isnull(@OR_AdmissionFee,AdmissionFee),
TestFund = isnull(@OR_TestFund,TestFund),
TotalFee = isnull(@OR_TotalFee,TotalFee)

where Id = @OR_Id;

COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
print 'ERROR';
END CATCH;

update staracademy.dbo.tbl_student
set StudentFullName =
isnull(@S_StudentFullName,StudentFullName),
Phone = isnull(@S_Phone,Phone),
Cell = isnull(@S_Cell,Cell),
CurrentAddress =
isnull(@S_CurrentAddress,CurrentAddress),
Town = isnull(@S_Town,Town),
City = isnull(@S_City,City),
District =
isnull(@S_District,District),
DateOfBirth =
isnull(@S_DateOfBirth,DateOfBirth),
EmailAddress =
isnull(@S_EmailAddress,EmailAddress),
Religion =
isnull(@S_Religion,Religion),
Gender = isnull(@S_Gender,Gender),
Campus = isnull(@S_Campus,Campus),
RegNo = isnull(@S_RegNo,RegNo),
RollNo = isnull(@S_RollNo,RollNo),
MissionInLife =
isnull(@S_MissionInLife,MissionInLife),
DateOfAdmission =
isnull(@S_DateOfAdmission,DateOfAdmission),
FK_ShiftID =
isnull(@ShiftID,FK_ShiftID),
FK_FatherDetailID = isnull(@F_Id,FK_FatherDetailID),
FK_SubjectID = isnull(@Sub_Id,FK_SubjectID),
FK_EducationRecID = isnull(@ER_Id,FK_EducationRecID),
FK_SiblingsID = isnull(@Sib_Id,FK_SiblingsID),
FK_OfficeUseOnlyID = isnull(@OR_Id,FK_OfficeUseOnlyID)

where Id = @S_Id;

update staracademy.dbo.tbl_studentclasses

set ClassesId = isnull(@ClassID,ClassesId),


ClassesName =isnull(@ClassName,ClassesName),
FK_StudentID = Id

where Id = @CID;

update staracademy.dbo.tbl_income

set
IncomeAmount =@OR_TotalFee,
IncomeFrom = 'Student Admission Fee',
DateofIncome =@S_DateOfAdmission,
FID =@FID

where Id = @IncomeID;

end

IF @Action='Delete'
begin
BEGIN TRANSACTION
BEGIN TRY
delete from staracademy.dbo.tbl_studentclasses where Id=@CID;
delete from staracademy.dbo.tbl_student where Id=@S_Id;
delete from staracademy.dbo.tbl_studentfatherdetail where Id=@F_Id;
delete from staracademy.dbo.tbl_studenteducationalrecord where Id=@ER_Id
delete from staracademy.dbo.tbl_studentsubject where Id=@Sub_Id;
delete from staracademy.dbo.tbl_studentsiblings where Id=@Sib_Id
delete from staracademy.dbo.tbl_studentofficeuseonly where Id=@OR_Id;
delete from staracademy.dbo.tbl_income where Id=@IncomeID;

COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
print 'ERROR';
END CATCH;

end

end

Tbl_StudentClasses:

CREATE TABLE [dbo].[tbl_studentclasses](


[Id] [int] NOT NULL,
[ClassesId] [nvarchar](50) NULL,
[ClassesName] [nvarchar](50) NULL,
[FK_StudentID] [int] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tbl_studentclasses] WITH CHECK ADD FOREIGN KEY([FK_StudentID])


REFERENCES [dbo].[tbl_student] ([Id])
GO

ALTER TABLE [dbo].[tbl_studentclasses] WITH CHECK ADD FOREIGN KEY([FK_StudentID])


REFERENCES [dbo].[tbl_student] ([Id])
GO

Tbl_studentSubjects

CREATE TABLE [dbo].[tbl_studentsubject](


[Id] [int] NOT NULL,
[SubjectName] [nvarchar](150) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Tbl_studenteducationalrecord:

CREATE TABLE [dbo].[tbl_studenteducationalrecord](


[Id] [int] NOT NULL,
[ExamPassed] [nvarchar](150) NULL,
[NameOfInstitute] [nvarchar](150) NULL,
[PassingYear] [nvarchar](150) NULL,
[ExaminingBoard] [nvarchar](150) NULL,
[MarksObtained] [nvarchar](150) NULL,
[Percentage] [nvarchar](150) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Tbl_studenteEntryTest:

CREATE TABLE [dbo].[tbl_studententrytest](


[Id] [int] NOT NULL,
[FeeMonth] [nvarchar](50) NULL,
[DateOfAddmission] [datetime] NULL,
[ChallanIssuanceDate] [datetime] NULL,
[RollNo] [nvarchar](150) NULL,
[StudentName] [nvarchar](50) NULL,
[FatherName] [nvarchar](50) NULL,
[Class] [nvarchar](50) NULL,
[PackageFee] [decimal](20, 2) NULL,
[DiscountPercentage] [decimal](20, 2) NULL,
[DiscountAmount] [decimal](20, 2) NULL,
[BookCharges] [decimal](20, 2) NULL,
[TotalFeeToBePaid] [decimal](20, 2) NULL,
[Fine] [decimal](20, 2) NULL,
[Installment1] [decimal](20, 2) NULL,
[Installment2] [decimal](20, 2) NULL,
[Installment3] [decimal](20, 2) NULL,
[RemainingDues] [decimal](20, 2) NULL,
[AmountInFig] [decimal](20, 2) NULL,
[AmountInWord] [nvarchar](100) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Tbl_studenteFatherdetail:

CREATE TABLE [dbo].[tbl_studentfatherdetail](


[Id] [int] NOT NULL,
[FatherName] [nvarchar](50) NULL,
[ResidenceTel] [nvarchar](50) NULL,
[Occupation] [nvarchar](100) NULL,
[Qualification] [nvarchar](50) NULL,
[CellNo] [nvarchar](50) NULL,
[CNICNo] [nvarchar](50) NULL,
[LivingWith] [nvarchar](50) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Tbl_Employee:

CREATE TABLE [dbo].[tbl_employee](


[Id] [int] NOT NULL,
[EmployeeName] [nvarchar](50) NULL,
[EmployeeType] [nvarchar](50) NULL,
[Designation] [nvarchar](50) NULL,
[Phone] [nvarchar](50) NULL,
[CNIC] [nvarchar](50) NULL,
[Address] [nvarchar](100) NULL,
[Gender] [nvarchar](50) NULL,
[Email] [nvarchar](50) NULL,
[Qualification] [nvarchar](50) NULL,
[DOB] [datetime] NULL,
[DateOfJoin] [datetime] NULL,
[Salery] [decimal](20, 2) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Tbl_Employee (Procedure):
CREATE proc [dbo].[sp_employee]
@Action nvarchar(50),
@Id int=null,
@EmployeeName nvarchar(50)=null,
@EmployeeType nvarchar(50)=null,
@Designation nvarchar(50)=null,
@Phone nvarchar(50)=null,
@CNIC nvarchar(50)=null,
@Address nvarchar(150)=null,
@Gender nvarchar(50)=null,
@Email nvarchar(50)=null,
@Qualification nvarchar(50)=null,
@DOB DateTime=null,
@DateOfJoin DateTime=null,
@Salery decimal(20,2)=null
as
begin

IF @Action='Insert'
begin
insert into tbl_employee values
(@Id,@EmployeeName,@EmployeeType,@Designation,@Phone,@CNIC,@Address,@Gender,@Email,@Quali
fication,@DOB,@DateOfJoin,@Salery)
end

IF @Action='Update'
begin

Update tbl_employee set

EmployeeName=@EmployeeName,
EmployeeType=@EmployeeType,
Designation=@Designation,
Phone=@Phone,
CNIC=@CNIC,
Address=@Address,
Gender=@Gender,
Email=@Email,
Qualification=@Qualification,
DOB=@DOB,
DateOfJoin=@DateOfJoin,
Salery=@Salery

where Id=@Id
end
IF @Action='Select'

begin

select * from tbl_employee


end

IF @Action='SelectTeacher'

begin

select * from tbl_employee where EmployeeType='Teacher';


end

IF @Action='Delete'
begin
delete from tbl_employee where Id=@Id
end
end

GO

USE [staracademy]
GO

/****** Object: Table [dbo].[tbl_employeeadvance] Script Date: 12/31/2020 8:57:32 PM


******/
SET ANSI_NULLS ON
GO

Tbl_EmployeeAdvance:
CREATE TABLE [dbo].[tbl_employeeadvance](
[Id] [int] NOT NULL,
[FK_EmployeeID] [int] NULL,
[AdvanceAmount] [decimal](20, 2) NULL,
[AdvanceDate] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tbl_employeeadvance] WITH CHECK ADD FOREIGN KEY([FK_EmployeeID])


REFERENCES [dbo].[tbl_employee] ([Id])
GO
ALTER TABLE [dbo].[tbl_employeeadvance] WITH CHECK ADD FOREIGN KEY([FK_EmployeeID])
REFERENCES [dbo].[tbl_employee] ([Id])
GO

Tbl_EmployeeAdvance (Procedure):
CREATE proc [dbo].[sp_employadvance]
@Action nvarchar(50),
@Id int=null,
@FK_EmployeeID int=null,
@AdvanceAmount decimal(20,2)=null,
@AdvanceDate DateTime=null
as
begin

IF @Action='Insert'
begin
insert into tbl_employeeadvance values (@Id,@FK_EmployeeID,@AdvanceAmount,@AdvanceDate)
end

IF @Action='Update'
begin

Update tbl_employeeadvance set

Id=@Id,
FK_EmployeeID=@FK_EmployeeID,
AdvanceAmount=@AdvanceAmount,
AdvanceDate=@AdvanceDate
where Id=@Id
end

IF @Action='Select'

begin

SELECT
tbl_employeeadvance.Id,tbl_employee.Id as 'EmpId'
,tbl_employee.EmployeeName,tbl_employeeadvance.AdvanceAmount,tbl_employeeadvance.AdvanceD
ate
FROM tbl_employeeadvance

left join tbl_employee


on tbl_employeeadvance.FK_EmployeeID=tbl_employee.Id

end

IF @Action='Delete'
begin
delete from tbl_employeeadvance where Id=@Id
end
end
GO

Tbl_EmployeeLecturewiseSalary:
CREATE TABLE [dbo].[tbl_employeelecturewisesalary](
[Id] [int] NOT NULL,
[DateOfPay] [datetime] NULL,
[EmployeeName] [nvarchar](50) NULL,
[Designation] [nvarchar](50) NULL,
[PerLectureAmount] [decimal](20, 2) NULL,
[NoOfLecture] [nvarchar](50) NULL,
[LectureAmount] [decimal](20, 2) NULL,
[NoOfStudent] [nvarchar](50) NULL,
[Salary] [decimal](20, 2) NULL,
[AcademyTax] [decimal](20, 2) NULL,
[Advance] [decimal](20, 2) NULL,
[TotalSalary] [decimal](20, 2) NULL,
[FK_EmployeeID] [int] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[tbl_employeelecturewisesalary] WITH CHECK ADD CONSTRAINT


[FK_tbl_employeelecturewisesalary_tbl_employee] FOREIGN KEY([FK_EmployeeID])
REFERENCES [dbo].[tbl_employee] ([Id])
GO

ALTER TABLE [dbo].[tbl_employeelecturewisesalary] CHECK CONSTRAINT


[FK_tbl_employeelecturewisesalary_tbl_employee]
GO

Tbl_EmployeeLecturewiseSalary (Procedure):
CREATE proc [dbo].[sp_employeelecturewisesalary]
@Action nvarchar(50),
@Id int=null,
@DateOfPay DateTime=null,
@EmployeeName nvarchar(50)=null,
@Designation nvarchar(50)=null,
@PerLectureAmount decimal(20,2)=null,
@NoOfLecture nvarchar(50)=null,
@LectureAmount decimal(20,2)=null,
@NoOfStudent nvarchar(50)=null,
@Salary decimal(20,2)=null,
@AcademyTax decimal(20,2)=null,
@Advance decimal(20,2)=null,
@TotalSalary decimal(20,2)=null,
@FK_EmployeeID int=null,
@ExpenseID int =null,
@SaleryID int =null
as
begin

IF @Action='Insert'
begin
insert into tbl_employeelecturewisesalary values
(@Id,@DateOfPay,@EmployeeName,@Designation,@PerLectureAmount,@NoOfLecture,@LectureAmount,
@NoOfStudent,@Salary,@AcademyTax,@Advance,@TotalSalary,@FK_EmployeeID)

insert into staracademy.dbo.tbl_addexpense


values
(
@ExpenseID, 'Employee Lecture Salery', 'Employee Lecture Salery',
@TotalSalary, GETDATE(),@SaleryID
)

update tbl_employeeadvance set AdvanceAmount=AdvanceAmount-


@Advance where FK_EmployeeID=@FK_EmployeeID

end
IF @Action='Update'

begin

Update tbl_employeelecturewisesalary set

DateOfPay=@DateOfPay,
EmployeeName=@EmployeeName,
Designation=@Designation,
PerLectureAmount=@PerLectureAmount,
NoOfLecture=@NoOfLecture,
LectureAmount=@LectureAmount,
NoOfStudent=@NoOfStudent,
Salary=@Salary,
AcademyTax=@AcademyTax,
Advance=@Advance,
TotalSalary=@TotalSalary,
FK_EmployeeID=@FK_EmployeeID
where Id=@id

update tbl_addexpense set

ExpenseType='Employee Lecture Salery',


ExpenseDescription='Employee Lecture Salery',
Payment = @TotalSalary,
DateOfPay=GETDATE(),
SaleryID=@Id
where Id=@ExpenseID;
end

IF @Action='Select'

begin

SELECT tbl_employeelecturewisesalary.*,tbl_addexpense.Id as ExpenseID


FROM tbl_employeelecturewisesalary
left join tbl_addexpense on tbl_employeelecturewisesalary.Id=tbl_addexpense.SaleryID
where ExpenseType='Employee Lecture Salery'

end

IF @Action='Delete'
begin
delete from tbl_employeelecturewisesalary where Id=@Id
delete from tbl_addexpense where Id=@ExpenseID;
end
end

GO

You might also like