You are on page 1of 30

USE [master] GO /****** Object: Database [UCBDatabase] Script Date: 08/23/2013 14:46:16 **** **/ CREATE DATABASE [UCBDatabase]

ON PRIMARY ( NAME = N'UCBDatabase', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQ L10.SQLEXPRESS\MSSQL\DATA\UCBDatabase.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED , FILEGROWTH = 10%) LOG ON ( NAME = N'UCBDatabase_log', FILENAME = N'c:\Program Files\Microsoft SQL Server\ MSSQL10.SQLEXPRESS\MSSQL\DATA\UCBDatabase_log.ldf' , SIZE = 1024KB , MAXSIZE = 2 048GB , FILEGROWTH = 10%) GO ALTER DATABASE [UCBDatabase] SET COMPATIBILITY_LEVEL = 100 GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin EXEC [UCBDatabase].[dbo].[sp_fulltext_database] @action = 'enable' end GO ALTER DATABASE [UCBDatabase] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [UCBDatabase] SET ANSI_NULLS OFF GO ALTER DATABASE [UCBDatabase] SET ANSI_PADDING OFF GO ALTER DATABASE [UCBDatabase] SET ANSI_WARNINGS OFF GO ALTER DATABASE [UCBDatabase] SET ARITHABORT OFF GO ALTER DATABASE [UCBDatabase] SET AUTO_CLOSE OFF GO ALTER DATABASE [UCBDatabase] SET AUTO_CREATE_STATISTICS ON GO ALTER DATABASE [UCBDatabase] SET AUTO_SHRINK OFF GO ALTER DATABASE [UCBDatabase] SET AUTO_UPDATE_STATISTICS ON GO ALTER DATABASE [UCBDatabase] SET CURSOR_CLOSE_ON_COMMIT OFF GO ALTER DATABASE [UCBDatabase] SET CURSOR_DEFAULT GLOBAL GO ALTER DATABASE [UCBDatabase] SET CONCAT_NULL_YIELDS_NULL OFF GO ALTER DATABASE [UCBDatabase] SET NUMERIC_ROUNDABORT OFF GO ALTER DATABASE [UCBDatabase] SET QUOTED_IDENTIFIER OFF GO ALTER DATABASE [UCBDatabase] SET RECURSIVE_TRIGGERS OFF GO ALTER DATABASE [UCBDatabase] SET ENABLE_BROKER GO ALTER DATABASE [UCBDatabase] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO ALTER DATABASE [UCBDatabase] SET DATE_CORRELATION_OPTIMIZATION OFF GO ALTER DATABASE [UCBDatabase] SET TRUSTWORTHY OFF GO ALTER DATABASE [UCBDatabase] SET ALLOW_SNAPSHOT_ISOLATION OFF GO

ALTER DATABASE [UCBDatabase] SET PARAMETERIZATION SIMPLE GO ALTER DATABASE [UCBDatabase] SET READ_COMMITTED_SNAPSHOT OFF GO ALTER DATABASE [UCBDatabase] SET HONOR_BROKER_PRIORITY OFF GO ALTER DATABASE [UCBDatabase] SET READ_WRITE GO ALTER DATABASE [UCBDatabase] SET RECOVERY SIMPLE GO ALTER DATABASE [UCBDatabase] SET MULTI_USER GO ALTER DATABASE [UCBDatabase] SET PAGE_VERIFY CHECKSUM GO ALTER DATABASE [UCBDatabase] SET DB_CHAINING OFF GO USE [UCBDatabase] GO /****** Object: Table [dbo].[TransactionTypes] Script Date: 08/23/2013 14:46 :18 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[TransactionTypes]( [TransactionTypeId] [int] IDENTITY(1,1) NOT NULL, [TransactionTypeName] [varchar](50) NOT NULL, CONSTRAINT [PK_TransactionTypes] PRIMARY KEY CLUSTERED ( [TransactionTypeId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[TransactionMode] Script Date: 08/23/2013 14:46: 18 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[TransactionMode]( [TransactionModeId] [int] IDENTITY(1,1) NOT NULL, [TransactionModeName] [varchar](20) NOT NULL, CONSTRAINT [PK_TransferType] PRIMARY KEY CLUSTERED ( [TransactionModeId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[Customers] Script Date: 08/23/2013 14:46:18 *** ***/

SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Customers]( [CustomerPK] [bigint] IDENTITY(1,1) NOT NULL, [CustomerId] [int] NOT NULL, [Address] [varchar](100) NOT NULL, [City] [varchar](50) NOT NULL, [State] [varchar](50) NOT NULL, [Country] [varchar](50) NOT NULL, [PhoneNo] [bigint] NOT NULL, [MobileNo] [bigint] NULL, [EmailId] [varchar](50) NULL, [Status] [varchar](50) NOT NULL, CONSTRAINT [PK_Customers_1] PRIMARY KEY CLUSTERED ( [CustomerPK] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[AccountTypes] Script Date: 08/23/2013 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[AccountTypes]( [AccTypeId] [int] IDENTITY(1,1) NOT NULL, [AccTypeName] [varchar](20) NOT NULL, [MinimumBalance] [float] NOT NULL, [DebitDayLimit] [float] NOT NULL, [TransferDayLimit] [float] NOT NULL, CONSTRAINT [PK_AccountType] PRIMARY KEY CLUSTERED ( [AccTypeId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[BusinessType] Script Date: 08/23/2013 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[BusinessType]( [BusinessTypeId] [int] IDENTITY(1,1) NOT NULL, [BusinessTypeName] [varchar](50) NOT NULL,

= OFF, AL

14:46:18

= OFF, AL

14:46:18

CONSTRAINT [PK_BusinessType] PRIMARY KEY CLUSTERED ( [BusinessTypeId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[LoginCredentials] Script Date: 08/23/2013 14:46 :18 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[LoginCredentials]( [LoginId] [varchar](50) NOT NULL, [Password] [varchar](20) NOT NULL, [UserType] [varchar](50) NOT NULL, [CustomerId] [int] NOT NULL, CONSTRAINT [PK_LoginCredentials] PRIMARY KEY CLUSTERED ( [LoginId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: StoredProcedure [dbo].[Login] Script Date: 08/23/2013 14:46: 28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Login] @userId AS VARCHAR(50), @password AS VARCHAR(50), @userType AS VARCHAR(20), @result AS BINARY OUTPUT AS IF exists (SELECT 'true' FROM LoginCredentials WHERE LoginId=@userId and [Passwo rd]=@password and UserType=@userType) BEGIN SET @result = 1; END ELSE BEGIN SET @result = 0; END GO /****** Object: StoredProcedure [dbo].[ChangePassword] Script Date: 08/23/20 13 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[ChangePassword]

( @userId VARCHAR(50), @oldpassword VARCHAR(50), @newPassword VARCHAR(50) , @result AS BINARY OUTPUT ) AS BEGIN TRY IF ((SELECT [Status] FROM Customers WHERE CustomerId = (SELECT CustomerI d FROM LoginCredentials WHERE LoginId=@userId))='Active') BEGIN UPDATE LoginCredentials SET [Password]=@newPassword WHERE (LoginId=@userId and [passwor d]=@oldpassword) SET @result=1 END ELSE SET @result=0 END TRY BEGIN catch SET @result=0 END catch GO /****** Object: StoredProcedure [dbo].[GetBusinessTypes] Script Date: 08/23/ 2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE procedure [dbo].[GetBusinessTypes] as begin select BusinessTypeName from BusinessType end GO /****** Object: Table [dbo].[Accounts] Script Date: 08/23/2013 14:46:28 **** **/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Accounts]( [AccountNo] [bigint] IDENTITY(1010000,1) NOT NULL, [CustomerId] [int] NOT NULL, [AccTypeId] [int] NOT NULL, [Balance] [float] NOT NULL, [OpenDate] [date] NOT NULL, [CloseDate] [date] NULL, CONSTRAINT [PK_Account] PRIMARY KEY CLUSTERED ( [AccountNo] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: StoredProcedure [dbo].[VerifyPassword] Script Date: 08/23/20 13 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON

GO CREATE PROCEDURE [dbo].[VerifyPassword] @password VARCHAR(50), @loginId varchar( 50), @result binary OUTPUT AS if exists(select 'true' from LoginCredentials where (LoginId=@loginId and[Passwo rd]=@password)) begin SET @result=1; end else begin Set @result=0; end GO /****** Object: StoredProcedure [dbo].[UpdateCustomerDetails] Script Date: 0 8/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[UpdateCustomerDetails] @Address varchar(100), @City varchar(50), @State varchar(50), @Country varchar(50), @PhoneNo bigint, @MobileNo bigint, @EmailId varchar(50), --@ContactName varchar(50), --@Website varchar(50), --@BusinessTypeId int, --@BusinessTypeName varchar(50), @LoginId varchar(50), @result binary output AS BEGIN DECLARE @customerid int --DECLARE @accountno bigint --DECLARE @accounttype varchar(20) SET @customerid=(SELECT CustomerId FROM LoginCredentials WHERE LoginId=@ LoginId) --SET @accountno=(SELECT AccountNo FROM Accounts WHERE CustomerId=@custo merid) --SET @accounttype=(SELECT AccTypeName FROM AccountTypes WHERE AccTypeId =(SELECT AccTypeId FROM Accounts WHERE AccountNo=@accountno)) INSERT INTO Customers VALUES(@customerid,@Address,@City,@State,@Country, @PhoneNo,@MobileNo,@EmailId,'Pending') --IF @accounttype='Current' -INSERT INTO CurrentAccounts VALUES(@BusinessTypeName,@BusinessTy peId,@ContactName,@accountno,@Website,'Pending'); SET @result=1 END GO /****** Object: Table [dbo].[Transactions] ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO

Script Date: 08/23/2013 14:46:28

SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Transactions]( [TransactionId] [int] IDENTITY(1,1) NOT NULL, [TransactionTypeId] [int] NOT NULL, [AccountNo] [bigint] NOT NULL, [Bank] [varchar](50) NULL, [TransactionAmount] [float] NOT NULL, [ClosingBalance] [float] NOT NULL, [TransactionDate] [date] NOT NULL, [TransactionStatus] [varchar](200) NULL, [TransactionModeId] [int] NOT NULL, CONSTRAINT [PK_Transactions] PRIMARY KEY CLUSTERED ( [TransactionId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[CurrentAccounts] Script Date: 08/23/2013 14:46: 28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[CurrentAccounts]( [BusinessName] [varchar](50) NOT NULL, [BusinessTypeId] [int] NOT NULL, [ContactName] [varchar](50) NOT NULL, [AccountNo] [bigint] NOT NULL, [Website] [varchar](50) NULL, [AccountStatus] [varchar](50) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: StoredProcedure [dbo].[ChequeDeposit] Script Date: 08/23/201 3 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[ChequeDeposit] @FromAccountNumber bigint, @ToAccountNumber bigint, @Amount float, @status binary output AS BEGIN SET NOCOUNT ON; declare @bal float; if exists(select 'true' from Accounts where AccountNo in (@FromAccountNu mber,@ToAccountNumber )) begin select @bal=[Balance] from [Accounts] where AccountNo=@FromAccountNumber

set @bal=@bal-@Amount update [Accounts] set [Balance]=@bal where AccountNo=@FromAccountNumber select @bal=[Balance] from [Accounts] where AccountNo=@ToAccountNumber set @bal=@bal+@Amount update [Accounts] set [Balance]=@bal where AccountNo=@ToAccountNumber set @status=1 end else begin set @status=0 end END GO /****** Object: Table [dbo].[ChequeBooks] Script Date: 08/23/2013 14:46:28 * *****/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[ChequeBooks]( [ChequeBookId] [int] IDENTITY(1,1) NOT NULL, [AccountNo] [bigint] NOT NULL, [NumberOfLeaves] [int] NOT NULL, [IssueDate] [date] NOT NULL, [RemainingLeaves] [int] NOT NULL, [ChequeBookStatus] [varchar](50) NOT NULL, CONSTRAINT [PK_ChequeBooks] PRIMARY KEY CLUSTERED ( [ChequeBookId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: StoredProcedure [dbo].[GetAccountTypeByLoginId] Script Date: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[GetAccountTypeByLoginId] @loginid varchar(50), @accounttype varchar(50) output AS BEGIN SET @accounttype=(SELECT AccTypeName FROM AccountTypes WHERE AccTypeId= (SELECT AccTypeId FROM Accounts WHERE CustomerId=( SELECT CustomerId FROM LoginCredenti als WHERE LoginId=@loginid))) END GO /****** Object: StoredProcedure [dbo].[GetAccountNoByLoginId] Script Date: 0 8/23/2013 14:46:28 ******/ SET ANSI_NULLS ON

GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[GetAccountNoByLoginId] (@LoginId VARCHAR(50), @AccountNo BIGINT OUTPUT) AS BEGIN SET @AccountNo = (SELECT AccountNo FROM Accounts WHERE CustomerId = (SEL ECT CustomerId FROM LoginCredentials WHERE LoginId = @LoginId)) END GO /****** Object: Table [dbo].[DebitCards] Script Date: 08/23/2013 14:46:28 ** ****/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[DebitCards]( [DebitCardNo] [bigint] IDENTITY(1234567800000000,1) NOT NULL, [DebitPinNo] [tinyint] NOT NULL, [ExpiryDate] [date] NOT NULL, [CVV] [int] NOT NULL, [AccountNo] [bigint] NOT NULL, [Status] [varchar](50) NOT NULL, CONSTRAINT [PK_DebitCards] PRIMARY KEY CLUSTERED ( [DebitCardNo] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: StoredProcedure [dbo].[CashWithDraw] Script Date: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[CashWithDraw] @AccountNumber bigint, @Amount float, @status binary output AS BEGIN SET NOCOUNT ON; declare @bal float if exists(select 'true' from Accounts where AccountNo=@AccountNumber ) begin select @bal=[Balance] from [Accounts] where AccountNo=@AccountNumber if exists(select 'true' from Accounts where @bal-500>=@Amount ) begin set @bal=@bal-@Amount update [Accounts] set [Balance]=@bal where AccountNo=@AccountNumber set @status=1 end else begin

set @status=0 end end else begin set @status=0 end END GO /****** Object: StoredProcedure [dbo].[CashDeposit] Script Date: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[CashDeposit] @AccountNumber bigint, @Amount float, @status binary output AS BEGIN SET NOCOUNT ON; declare @bal float; if exists(select 'true' from Accounts where AccountNo=@AccountNumber) begin select @bal=[Balance] from [Accounts] where AccountNo=@AccountNumber set @bal=@bal+@Amount update [Accounts] set [Balance]=@bal where AccountNo=@AccountNumber set @status=1 end else begin set @status=0 end END GO /****** Object: Table [dbo].[Payees] Script Date: 08/23/2013 14:46:28 ****** / SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Payees]( [PayeeId] [int] IDENTITY(1,1) NOT NULL, [PayeeName] [varchar](50) NOT NULL, [PayeeAccNo] [bigint] NOT NULL, [Bank] [varchar](50) NULL, [AccountNo] [bigint] NOT NULL, CONSTRAINT [PK_Payees] PRIMARY KEY CLUSTERED ( [PayeeId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO

SET ANSI_PADDING OFF GO /****** Object: Table [dbo].[SavingsAccounts] Script Date: 08/23/2013 14:46: 28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[SavingsAccounts]( [Name] [varchar](50) NOT NULL, [FatherName] [varchar](50) NOT NULL, [Gender] [varchar](6) NOT NULL, [DateOfBirth] [date] NOT NULL, [CompanyName] [varchar](50) NULL, [AccountNo] [bigint] NOT NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: StoredProcedure [dbo].[RetrieveUpdateRequests] Script Date: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[RetrieveUpdateRequests] AS BEGIN SELECT * FROM (SELECT c.CustomerId as CustId, c.Address, c.City, c.State, c.Country, c.PhoneNo , c.MobileNo, c.EmailId FROM Customers c where Status='Pending') t1 left outer join (SELECT ca.ContactName, ca.Website,a.CustomerId as CustId FROM CurrentAccounts c a, Accounts a where AccountStatus='Pending' and ca.AccountNo = a.AccountNo) t2 on t1.CustId = t2.CustId END GO /****** Object: StoredProcedure [dbo].[RetrieveRequests] 2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[RetrieveRequests] AS BEGIN

Script Date: 08/23/

SELECT c.CustomerId, c.Address, c.City, c.State, c.Country, c.PhoneNo, c.MobileNo, c.EmailId, c.Status,a.AccountNo,ca.ContactName,ca.Webs ite FROM Customers c INNER JOIN Accounts a ON c.CustomerId=a.CustomerId LEFT OUTER JOIN CurrentAccounts ca ON a.AccountNo=ca.AccountNo LEFT OUTER JOIN

SavingsAccounts sa ON a.AccountNo=sa.AccountNo WHERE c.Status='Pending' OR c.Status='New'; --AND a.AccTypeId=3 ; END GO /****** Object: StoredProcedure [dbo].[RejectUpdateRequests] Script Date: 08 /23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[RejectUpdateRequests] @CustomerId int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @AccountTypeId int SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=@Custom erId) SET @AccountTypeId=(SELECT AccTypeId FROM Accounts WHERE CustomerId=@Cus tomerId) Update Customers SET Status='Rejected' where Status='Pending' AND CustomerId=@CustomerId; IF @AccountTypeId=3 BEGIN UPDATE CurrentAccounts SET AccountStatus='Rejected' where AccountStatus='Pending' AND AccountNo=@accountnum; END SET @result=1 END GO /****** Object: StoredProcedure [dbo].[RejectAccountCreationRequests] Script Date: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[RejectAccountCreationRequests] @CustomerId int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @AccountTypeId int SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=@Custom erId) SET @AccountTypeId=(SELECT AccTypeId FROM Accounts WHERE CustomerId=@Cus tomerId) Update Customers SET Status='Rejected' where Status='New' AND CustomerId=@CustomerId; UPDATE LoginCredentials SET UserType='Rejected' WHERE UserType='New' AND CustomerId=@CustomerId;

IF @AccountTypeId=3 BEGIN UPDATE CurrentAccounts SET AccountStatus='Rejected' where AccountStatus='New' AND AccountNo=@accountnum; END SET @result=1 END GO /****** Object: StoredProcedure [dbo].[MiniStatement] Script Date: 08/23/201 3 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[MiniStatement] @AccountNo INT AS SELECT TOP 10 T.TransactionDate, T.TransactionStatus, T.TransactionAmount, T.ClosingBalance, TT.TransactionTypeName FROM Transactions T INNER JOIN TransactionTypes TT on TT.TransactionTypeId = T.Tr ansactionTypeId WHERE AccountNo=@AccountNo ORDER BY TransactionId DESC GO /****** Object: StoredProcedure [dbo].[GetUpdateRequests] Script Date: 08/23 /2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[GetUpdateRequests]--RetrieveUpdateRequests AS BEGIN SELECT * FROM (SELECT c.CustomerId as CustId, c.Address, c.City, c.State, c.Country, c.PhoneNo , c.MobileNo, c.EmailId FROM Customers c where Status='Pending') t1 left outer join (SELECT ca.ContactName, ca.Website,a.CustomerId as CustId FROM CurrentAccounts c a, Accounts a where AccountStatus='Pending' and ca.AccountNo = a.AccountNo) t2 on t1.CustId = t2.CustId END GO /****** Object: StoredProcedure [dbo].[GetProfileInfo] Script Date: 08/23/20 13 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[GetProfileInfo] @loginid varchar(50),@accounttype varcha r(50) AS BEGIN DECLARE @custid int

DECLARE @acntno bigint SET @custid=(SELECT CustomerId FROM LoginCredentials where LoginId=@logi nid) IF @accounttype='Current' SELECT c.CustomerId,c.[Address],c.City,c.[State],c.Country,c.Pho neNo,c.MobileNo,c.EmailId, ca.BusinessName,ca.BusinessTypeId,ca.ContactName,ca.Website FROM Customers c INNER JOIN Accounts a ON c.CustomerId=a.CustomerId INNER JOIN CurrentAccounts ca ON a.AccountNo=ca.AccountNo WHERE c.CustomerId=@custid AND c.Status='Active' ELSE SELECT c.CustomerId,c.[Address],c.City,c.[State],c.Country,c.Pho neNo,c.MobileNo,c.EmailId, sa.Name,sa.FatherName,sa.Gender,sa.DateOfBirth,sa.CompanyName FROM Customers c INNER JOIN Accounts a ON c.CustomerId=a.CustomerId INNER JOIN SavingsAccounts sa ON a.AccountNo=sa.AccountNo WHERE c.CustomerId=@custid AND c.Status='Active'--@custid END GO /****** Object: StoredProcedure [dbo].[GetPayees] Script Date: 08/23/2013 14 :46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[GetPayees] @loginId varchar(50) AS BEGIN SELECT PayeeName FROM Payees WHERE AccountNo = (SELECT DISTINCT AccountNo FROM A ccounts WHERE CustomerId = (SELECT DISTINCT CustomerId FROM LoginCredentials WHE RE LoginId = @loginId)) END GO /****** Object: StoredProcedure [dbo].[GetChequeBookRequests] Script Date: 0 8/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[GetChequeBookRequests] AS BEGIN SELECT * FROM ChequeBooks WHERE ChequeBookStatus='Pending' END GO /****** Object: StoredProcedure [dbo].[GetAccountCreationRequests] Script Da te: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[GetAccountCreationRequests] AS

BEGIN SELECT * FROM (SELECT c.CustomerId as CustId, c.Address, c.City, c.State, c.Country, c.PhoneNo , c.MobileNo, c.EmailId FROM Customers c where Status='New') t1 left outer join (SELECT ca.ContactName, ca.Website,a.CustomerId as CustId FROM CurrentAccounts c a, Accounts a where AccountStatus='New' and ca.AccountNo = a.AccountNo) t2 on t1.CustId = t2.CustId END GO /****** Object: StoredProcedure [dbo].[ForgotPassword] Script Date: 08/23/20 13 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[ForgotPassword] @userid VARCHAR(50), @accNo BIGINT, @deb itpin int, @status BINARY OUTPUT AS BEGIN IF ((SELECT [Status] FROM Customers WHERE CustomerId = (SELECT CustomerI d FROM LoginCredentials WHERE LoginId=@userid))='Active') BEGIN DECLARE @dPinNo int; SELECT @dPinNo=DebitPinNo FROM DebitCards WHERE AccountNo=@accNo IF (@debitpin = @dPinNo) BEGIN SET @status = 1 --'You will get your password through mail in 3 to 4 hours' END ELSE BEGIN SET @status = 0 --'Invalid Pin. Please TRY again' END END END GO /****** Object: StoredProcedure [dbo].[DisplayAccountCreationRequests] Scrip t Date: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[DisplayAccountCreationRequests] AS BEGIN DECLARE @custid int DECLARE @address varchar(100) DECLARE @city varchar(50) DECLARE @state varchar(50) DECLARE @country varchar(50) DECLARE @phonenumber bigint DECLARE @mob bigint DECLARE @email varchar(50) DECLARE @status varchar(50) DECLARE @accountnumber bigint DECLARE @accounttype int DECLARE @balance float

DECLARE ccursor CURSOR FOR SELECT c.CustomerId, c.Address, c.City, c.State, c.Country, c.PhoneNo, c.MobileNo, c.EmailId, c.IsActive, a.AccountNo, a.AccTypeId,a.Bala nce FROM Customers c INNER JOIN Accounts a ON c.CustomerId=a.CustomerId where c.IsActive='New'; OPEN ccursor FETCH NEXT FROM ccursor INTO @custid, @address, @city, @state, @country, @phonenumber, @mob, @email, @status, @accountnumber, @accounttype, @balance WHILE @@FETCH_STATUS=0 BEGIN Print @custid if @accounttype=3 SELECT ContactName,Website FROM CurrentAccounts WHERE Ac countNo=@accountnumber FETCH NEXT FROM ccursor INTO @custid, @addres s, @city, @state, @country, @phonenumbe r, @mob, @email, @status, @accountnum ber, @accounttyp e, @balance Print @custid; END CLOSE ccursor DEALLOCATE ccursor END GO /****** Object: StoredProcedure [dbo].[DetailedStatement] Script Date: 08/23 /2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[DetailedStatement] @AccountNo INT, @FromTransactionDate DATE, @ToTransactionDate DATE

AS SELECT T.TransactionDate, T.TransactionStatus, T.TransactionAmount, T.ClosingBalance, TT.TransactionTypeName FROM Transactions T INNER JOIN TransactionTypes TT on TT.TransactionTypeId = T.Tr ansactionTypeId WHERE AccountNo=@AccountNo AND TransactionDate BETWEEN @FromTransactionDate A ND @ToTransactionDate GO /****** Object: StoredProcedure [dbo].[Deposit] Script Date: 08/23/2013 14:4 6:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Deposit] @toAccNo INT, @bank VARCHAR(50), @amount FLOAT, @mode int, @status BINARY OUTPUT AS BEGIN BEGIN TRAN BEGIN TRY DECLARE @bal FLOAT; SELECT @bal = Balance FROM Accounts WHERE AccountNo = @t oAccNo; SET @bal = @bal + @amount; UPDATE Accounts SET Balance = @bal WHERE AccountNo = @to Accno; INSERT INTO Transactions VALUES (1,@toAccNo,@bank,@amoun t,@bal,getdate(),'Success',@mode) SET @status = 1; COMMIT TRAN END TRY BEGIN CATCH ROLLBACK TRAN SET @status = 0; END CATCH END GO /****** Object: StoredProcedure [dbo].[ApproveUpdateRequests] Script Date: 0 8/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[ApproveUpdateRequests] @CustomerId int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @AccountTypeId int SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=@Custom erId) SET @AccountTypeId=(SELECT AccTypeId FROM Accounts WHERE CustomerId=@Cus tomerId) Update Customers

SET Status='Inactive' where Status='Active' AND CustomerId=@CustomerId; Update Customers SET Status='Active' where Status='Pending' AND CustomerId=@CustomerId; IF @AccountTypeId=3 BEGIN UPDATE CurrentAccounts SET AccountStatus='Inactive' where AccountStatus='Active' AND AccountNo=@accountnum; UPDATE CurrentAccounts SET AccountStatus='Active' where AccountStatus='Pending' AND AccountNo=@accountnum; END SET @result=1 END GO /****** Object: StoredProcedure [dbo].[ApproveOrRejectChequeBookRequests] Sc ript Date: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[ApproveOrRejectChequeBookRequests] @AccountNumber bigint , @Status int AS BEGIN IF @Status=1 BEGIN UPDATE ChequeBooks SET ChequeBookStatus='Approved' WHERE Account No=@AccountNumber END ELSE IF @Status=2 BEGIN UPDATE ChequeBooks SET ChequeBookStatus='Rejected' WHERE Account No=@AccountNumber END END GO /****** Object: StoredProcedure [dbo].[ApproveAccountCreationRequests] Scrip t Date: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[ApproveAccountCreationRequests] @CustomerId int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @AccountTypeId int SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=@Custom erId) SET @AccountTypeId=(SELECT AccTypeId FROM Accounts WHERE CustomerId=@Cus

tomerId) UPDATE Customers SET Status='Active' WHERE Status='New' AND CustomerId=@CustomerId; UPDATE LoginCredentials SET UserType='User' WHERE UserType='New' AND CustomerId=@CustomerId; IF @AccountTypeId=3 BEGIN UPDATE CurrentAccounts SET AccountStatus='Active' WHERE AccountStatus='New' AND AccountNo=@accountnum; END SET @result=1 END GO /****** Object: StoredProcedure [dbo].[AddPayee] Script Date: 08/23/2013 14: 46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[AddPayee] (@payeeName VARCHAR(50), @payeeAccountNo BIGINT, @bankName VARCHAR(50), @accountNo BIGINT, @status BINARY OUTPUT ) AS BEGIN BEGIN TRY IF ((SELECT [Status] FROM Customers WHERE CustomerId = (SELECT CustomerI d FROM Accounts WHERE AccountNo=@accountNo))='Active') BEGIN INSERT INTO Payees VALUES (@payeeName,@payeeAccountNo,@bankName, @accountNo) SET @status = 1; END ELSE SET @status = 0; END TRY BEGIN CATCH SET @status = 0; END CATCH END GO /****** Object: StoredProcedure [dbo].[AccountSummaryForStatements] Script D ate: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[AccountSummaryForStatements] @LoginId varchar(50) AS IF exists (SELECT 'true ' FROM Logincredentials WHERE LoginId=@LoginId)

BEGIN DECLARE @Customername VARCHAR(50), @AccType VARCHAR(50), @AccountNo BIGINT, @closingBal FLOAT SELECT @AccountNo=AccountNo FROM Accounts WHERE CustomerId=(SELECT CustomerId FROM Logincredentials WHERE LoginId=@Loginid) SELECT @AccType=AccTypeName FROM AccountTypes WHERE AccTypeId=(SELECT AccTypeId FROM Accounts WHERE Accountno= @AccountNo ) IF (@AccType = 'SavingsRegular' ) BEGIN SELECT @customername=Name FROM SavingsAccounts WHERE AccountNo=@AccountNo END IF (@AccType = 'SavingsCorporate' ) BEGIN SELECT @customername=Name FROM SavingsAccounts WHERE AccountNo=@AccountNo END IF(@AccType = 'Current') BEGIN SELECT @customername=ContactName FROM CurrentAccounts WHERE AccountNo=@AccountNo END SELECT @closingBal=ClosingBalance FROM Transactions WHERE AccountNo=@AccountNo SELECT @Customername AS AccountHolderName, @AccountNo AS AccountNumber, @AccType AS AccountType, @closingBal AS NetBalance END GO /****** Object: StoredProcedure [dbo].[AccountSummary] Script Date: 08/23/20 13 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[AccountSummary] @LoginId VARCHAR(50) AS BEGIN IF ((SELECT [Status] FROM Customers WHERE CustomerId = (SELECT CustomerId FROM L oginCredentials WHERE LoginId=@LoginId))='Active') BEGIN DECLARE @Customername VARCHAR(50), @AccType VARCHAR(50), @AccountNo BIGINT, @closingBal FLOAT, @businessName VARCHAR(50) SET @AccountNo=(SELECT AccountNo FROM Accounts WHERE CustomerId=(SELECT CustomerId FROM Logincredential

s WHERE LoginId=@LoginId)) SET @AccType=(SELECT AccTypeName FROM AccountTypes WHERE AccTypeId=(SELECT AccTypeId FROM Accounts WHERE Ac countno=@AccountNo)) IF (@AccType = 'Current' ) BEGIN SET @Customername = (SELECT ContactName FROM CurrentAccounts WHE RE Accountno=@AccountNo) SET @businessName = (SELECT BusinessName FROM CurrentAccounts WH ERE Accountno=@AccountNo) SELECT @AccountNo AS AccountNumber, @AccType AS AccountType, @Cu stomername AS ContactName, @businessName AS BusinessName END ELSE BEGIN SET @Customername = (SELECT Name FROM SavingsAccounts WHERE Acco untno=@AccountNo) SET @closingBal = (SELECT ClosingBalance FROM Transactions WHER E Accountno=@AccountNo) SELECT @AccountNo AS AccountNumber, @AccType AS AccountType, @Cu stomername AS CustomerName, @closingBal AS ClosingBalance END END END GO /****** Object: StoredProcedure [dbo].[CreateSavingsAccount] Script Date: 08 /23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[CreateSavingsAccount] @nam e varchar(50), @fatherName varchar(50), @gender varchar(50), @birth date, @add ress varchar(50), @city varchar(100), @state varchar(100), @country varchar(100), @phno bigint, @bal float, @mob bigint, @email varchar(50), @acctypid int, @company varchar(50),

@opendate date, @loginId varchar(50), @password varchar(50) AS BEGIN DECLARE @cid int SELECT @cid= (max(CustomerId)+1) FROM Customers INSERT INTO Customers VALUES(@cid,@address,@city,@state,@country,@phno,@mob ,@email,'New'); INSERT INTO Accounts(CustomerId,AccTypeId,Balance,OpenDate) values(@cid,3,@b al,@opendate) DECLARE @acntNo bigint IF(@acctypid=1) BEGIN SELECT @acntNo=max(AccountNo) FROM Accounts INSERT INTO SavingsAccounts VALUES (@name,@fathername,@gender,@birth,'', @acntNo) END IF(@acctypid=2) BEGIN SELECT @acntNo=max(AccountNo) FROM Accounts INSERT INTO SavingsAccounts VALUES(@name,@fathername,@gender,@birth,@comp any,@acntNo) END INSERT INTO LoginCredentials VALUES(@loginId,@password,'New',@cid ) END GO /****** Object: StoredProcedure [dbo].[CreateCurrentAccount] Script Date: 08 /23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[CreateCurrentAccount]

@BusinessTypeName varchar(50), @BusinessName varchar(100), @ContactName varchar(50), @add ress varchar(50), @city varchar(100), @state varchar(100), @country varchar(100), @phno bigint, @bal float,

@mob bigint, @email varchar(50), @website varchar(50), @opendate date, @loginId varchar(50), @password varchar(50) AS BEGIN DECLARE @cid int SELECT @cid=(max(CustomerId)+1) from Customers INSERT INTO Customers values(@cid,@address,@city,@state,@country,@phno,@mob ,@em ail,'New'); INSERT INTO Accounts(CustomerId,AccTypeId,Balance,OpenDate) values(@cid,3,@bal,@ opendate) DECLARE @acntNo bigint DECLARE @BusinessTypeId int SELECT @acntNo=max(AccountNo) from Accounts SET @BusinessTypeId= (SELECT BusinessTypeId FROM BusinessType WHERE BusinessType Name=@BusinessTypeName) INSERT INTO CurrentAccounts values (@BusinessName,@BusinessTypeId,@ContactName,@ acntNo,@website,'New') INSERT INTO LoginCredentials values(@loginId,@password,'New',@cid) END GO /****** Object: StoredProcedure [dbo].[ChequeWithdraw] Script Date: 08/23/20 13 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[ChequeWithdraw] @frmAccNo bigint,@chequeId int, @amount float, @date date, @status VARCHAR(150) OUTPUT AS BEGIN IF (exists(SELECT * FROM Customers WHERE CustomerId = (SELECT CustomerId FROM Accounts WHERE AccountNo=@frmAccNo) and [Status] = 'Active')) BEGIN DECLARE @transactionSum FLOAT, @limit FLOAT; SET @transactionSum = (SELECT SUM(TransactionAmount) FROM Transa ctions WHERE AccountNo = @frmAccNo); IF ((@amount+@transactionSum) < (SELECT DebitDayLimit FROM Accou ntTypes WHERE AccTypeId = (SELECT AccTypeId FROM Accounts WHERE AccountNo = @frm AccNo))) BEGIN DECLARE @bal FLOAT; SELECT @bal = Balance FROM Accounts WHERE Accoun tNo = @frmAccNo; IF ((@bal-@amount) > (SELECT MinimumBalance FROM AccountTypes WHERE AccTypeId = (SELECT AccTypeId FROM Accounts WHERE AccountNo = @frmAccNo))) BEGIN

IF ((SELECT RemainingLeaves FROM ChequeB ooks WHERE AccountNo=@frmAccNo)>0) BEGIN SET @bal = @bal - @amount; UPDATE Accounts SET Balance = @b al WHERE AccountNo = @frmAccno; INSERT INTO Transactions VALUES (1,@frmAccNo,'UCB',@amount,@bal,getdate(),'Success',2) SET @status = 'Transaction Succe ssfull.'; END ELSE SET @status='Insufficient Cheque Leaves! Transaction Failed!' END ELSE BEGIN SET @bal = @bal - (0.02 * @amount); UPDATE Accounts SET Balance = @bal WHERE AccountNo = @frmAccno; SET @status='Insufficient Funds! Cheque Bounced! Transaction Failed!' END END ELSE SET @status='Daily Withdraw Limit Crossed! Transaction F ailed!' END end GO /****** Object: Table [dbo].[Cheques] Script Date: 08/23/2013 14:46:28 ***** */ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Cheques]( [ChequeId] [int] IDENTITY(1,1) NOT NULL, [NameOnCheque] [varchar](50) NOT NULL, [Amount] [float] NOT NULL, [BankName] [varchar](50) NULL, [Date] [date] NOT NULL, [Status] [varchar](20) NOT NULL, [ToAccountNo] [bigint] NOT NULL, [ChequeBookId] [int] NOT NULL, CONSTRAINT [PK_Cheque] PRIMARY KEY CLUSTERED ( [ChequeId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, AL LOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO /****** Object: StoredProcedure [dbo].[Withdraw] Script Date: 08/23/2013 14: 46:28 ******/ SET ANSI_NULLS ON GO

SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Withdraw] @frmAccNo INT, @bank VARCHAR(50), @amount FLOA T, @mode int, @status VARCHAR(100) OUTPUT AS BEGIN BEGIN TRAN BEGIN TRY IF ((SELECT [Status] FROM Customers WHERE CustomerId = (SELECT C ustomerId FROM Accounts WHERE AccountNo=@frmAccNo))='Active') BEGIN DECLARE @transactionSum FLOAT, @limit FLOAT; SET @transactionSum = (SELECT SUM(TransactionAmount) FRO M Transactions WHERE AccountNo = @frmAccNo); IF ((@amount+@transactionSum) < (SELECT DebitDayLimit FR OM AccountTypes WHERE AccTypeId = (SELECT AccTypeId FROM Accounts WHERE AccountN o = @frmAccNo))) BEGIN DECLARE @bal FLOAT; SELECT @bal = Balance FROM Accounts WHERE Accoun tNo = @frmAccNo; IF ((@bal-@amount) > (SELECT MinimumBalance FROM AccountTypes WHERE AccTypeId = (SELECT AccTypeId FROM Accounts WHERE AccountNo = @frmAccNo))) BEGIN DECLARE @flag BIT; SET @flag = 0; IF (@mode = 2) IF ((SELECT RemainingLeaves FROM ChequeBooks WHERE AccountNo=@frmAccNo)>0) SET @flag = 0; ELSE BEGIN SET @status = 'Insuffici ent Cheque Leaves! Transaction Failed!'; SET @flag = 1; END IF (@flag = 0) BEGIN SET @bal = @bal - @amount; UPDATE Accounts SET Balance = @b al WHERE AccountNo = @frmAccno; INSERT INTO Transactions VALUES (2,@frmAccNo,@bank,@amount,@bal,getdate(),'Success',@mode) SET @status = 'Transaction Succe ssfull.'; END END ELSE BEGIN IF (@mode = 2) BEGIN SET @bal = @bal - (0.02 * @amoun t); UPDATE Accounts SET Balance = @b al WHERE AccountNo = @frmAccno; SET @status = 'Insufficient Fund s! Cheque Bounced! Transaction Failed!'; END ELSE

SET @status = 'Insufficient Fund s! Transaction Failed!'; END END ELSE SET @status = 'Daily Withdraw Limit Crossed! Tra nsaction Failed!'; END ELSE SET @status = 0; COMMIT TRAN END TRY BEGIN CATCH ROLLBACK TRAN SET @status = 0; END CATCH END GO /****** Object: StoredProcedure [dbo].[StoreChequeRequests] Script Date: 08/ 23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[StoreChequeRequests] @loginid varchar(50), @NumberOfLeaves int, @result binary output AS BEGIN DECLARE @accountnum bigint DECLARE @accounttypeid bigint SET @accountnum=(SELECT AccountNo FROM Accounts WHERE CustomerId=( SELECT CustomerId FROM LoginCredentials WHERE LoginId=@loginid)) SET @accounttypeid=(SELECT AccTypeId FROM Accounts WHERE AccountNo=@accountnum) IF @accounttypeid=1 BEGIN IF (SELECT Balance FROM Accounts WHERE AccountNo=@accountnum)<(5 000+50) SET @result=0 ELSE BEGIN INSERT INTO ChequeBooks values(@accountnum,@NumberOfLeav es,getdate(),@NumberOfLeaves,'Pending') UPDATE Accounts SET Balance=Balance-50 WHERE AccountNo=@ accountnum SET @result=1 END END IF @accounttypeid=2 OR @accounttypeid=3 BEGIN IF (SELECT Balance FROM Accounts WHERE AccountNo=@accountnum)>50 BEGIN INSERT INTO ChequeBooks values(@accountnum,@NumberOfLeav es,getdate(),@NumberOfLeaves,'Pending') UPDATE Accounts SET Balance=Balance-50 WHERE AccountNo=@ accountnum SET @result=1 END

ELSE SET @result=0 END END GO /****** Object: StoredProcedure [dbo].[UpdateCurrentAccountDetails] Script D ate: 08/23/2013 14:46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[UpdateCurrentAccountDetails] @ContactName varchar(50), @Website varchar(50), @BusinessTypeId int, @BusinessTypeName varchar(50), @LoginId varchar(50), @result binary output AS BEGIN DECLARE @customerid int DECLARE @accountno bigint DECLARE @accounttype varchar(20) SET @customerid=(SELECT CustomerId FROM LoginCredentials WHERE LoginId=@ LoginId) SET @accountno=(SELECT AccountNo FROM Accounts WHERE CustomerId=@custome rid) INSERT INTO CurrentAccounts VALUES(@BusinessTypeName,@BusinessTypeId,@Co ntactName,@accountno,@Website,'Pending'); SET @result=1 END GO /****** Object: StoredProcedure [dbo].[Transfer] Script Date: 08/23/2013 14: 46:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[Transfer] @frmAccNo INT, @toAccNo INT, @bank VARCHAR(50) , @amount FLOAT, @mode INT, @status BINARY OUTPUT AS BEGIN BEGIN TRAN BEGIN TRY IF ((SELECT [Status] FROM Customers WHERE CustomerId = (SELECT C ustomerId FROM Accounts WHERE AccountNo=@frmAccNo))='Active') BEGIN DECLARE @transactionSum FLOAT, @limit FLOAT; SET @transactionSum = (SELECT SUM(TransactionAmount) FRO M Transactions WHERE AccountNo = @frmAccNo); IF ((@amount+@transactionSum) < (SELECT TransferDayLimit FROM AccountTypes WHERE AccTypeId = (SELECT AccTypeId FROM Accounts WHERE Accou ntNo = @frmAccNo))) BEGIN DECLARE @withdrawStatus BINARY; EXEC Withdraw @frmAccNo, @bank, @amount, @mode, @withdrawStatus OUTPUT; IF (@withdrawStatus = 1) UPDATE Transactions SET TransactionTypeI d = 3 WHERE TransactionId = (SELECT MAX(TransactionId) FROM Transactions)

ELSE SET @status = 0; IF (@bank = '') BEGIN DECLARE @depositStatus BINARY; EXEC Deposit @toAccNo, @bank, @amount, @ mode, @depositStatus output; IF (@depositStatus = 1) UPDATE Transactions SET Transact ionTypeId = 3 WHERE TransactionId = (SELECT MAX(TransactionId) FROM Transactions ) ELSE SET @status = 0; END COMMIT TRAN END ELSE SET @status = 0; END ELSE SET @status = 0; END TRY BEGIN CATCH ROLLBACK TRAN SET @status = 0; END CATCH END GO /****** Object: ForeignKey [FK_Accounts_AccountTypes] Script Date: 08/23/201 3 14:46:28 ******/ ALTER TABLE [dbo].[Accounts] WITH CHECK ADD CONSTRAINT [FK_Accounts_AccountTyp es] FOREIGN KEY([AccTypeId]) REFERENCES [dbo].[AccountTypes] ([AccTypeId]) GO ALTER TABLE [dbo].[Accounts] CHECK CONSTRAINT [FK_Accounts_AccountTypes] GO /****** Object: ForeignKey [FK_Transactions_Accounts] Script Date: 08/23/201 3 14:46:28 ******/ ALTER TABLE [dbo].[Transactions] WITH CHECK ADD CONSTRAINT [FK_Transactions_Ac counts] FOREIGN KEY([AccountNo]) REFERENCES [dbo].[Accounts] ([AccountNo]) GO ALTER TABLE [dbo].[Transactions] CHECK CONSTRAINT [FK_Transactions_Accounts] GO /****** Object: ForeignKey [FK_Transactions_TransactionMode] Script Date: 08 /23/2013 14:46:28 ******/ ALTER TABLE [dbo].[Transactions] WITH CHECK ADD CONSTRAINT [FK_Transactions_Tr ansactionMode] FOREIGN KEY([TransactionModeId]) REFERENCES [dbo].[TransactionMode] ([TransactionModeId]) GO ALTER TABLE [dbo].[Transactions] CHECK CONSTRAINT [FK_Transactions_TransactionMo de] GO /****** Object: ForeignKey [FK_Transactions_TransferTypes] Script Date: 08/2 3/2013 14:46:28 ******/ ALTER TABLE [dbo].[Transactions] WITH CHECK ADD CONSTRAINT [FK_Transactions_Tr ansferTypes] FOREIGN KEY([TransactionTypeId]) REFERENCES [dbo].[TransactionTypes] ([TransactionTypeId]) GO ALTER TABLE [dbo].[Transactions] CHECK CONSTRAINT [FK_Transactions_TransferTypes

] GO /****** Object: ForeignKey [FK_CurrentAccounts_Accounts1] Script Date: 08/23 /2013 14:46:28 ******/ ALTER TABLE [dbo].[CurrentAccounts] WITH CHECK ADD CONSTRAINT [FK_CurrentAccou nts_Accounts1] FOREIGN KEY([AccountNo]) REFERENCES [dbo].[Accounts] ([AccountNo]) GO ALTER TABLE [dbo].[CurrentAccounts] CHECK CONSTRAINT [FK_CurrentAccounts_Account s1] GO /****** Object: ForeignKey [FK_CurrentAccounts_BusinessType] Script Date: 08 /23/2013 14:46:28 ******/ ALTER TABLE [dbo].[CurrentAccounts] WITH CHECK ADD CONSTRAINT [FK_CurrentAccou nts_BusinessType] FOREIGN KEY([BusinessTypeId]) REFERENCES [dbo].[BusinessType] ([BusinessTypeId]) GO ALTER TABLE [dbo].[CurrentAccounts] CHECK CONSTRAINT [FK_CurrentAccounts_Busines sType] GO /****** Object: ForeignKey [FK_ChequeBooks_Accounts] Script Date: 08/23/2013 14:46:28 ******/ ALTER TABLE [dbo].[ChequeBooks] WITH CHECK ADD CONSTRAINT [FK_ChequeBooks_Acco unts] FOREIGN KEY([AccountNo]) REFERENCES [dbo].[Accounts] ([AccountNo]) GO ALTER TABLE [dbo].[ChequeBooks] CHECK CONSTRAINT [FK_ChequeBooks_Accounts] GO /****** Object: ForeignKey [FK_DebitCards_Accounts] Script Date: 08/23/2013 14:46:28 ******/ ALTER TABLE [dbo].[DebitCards] WITH CHECK ADD CONSTRAINT [FK_DebitCards_Accoun ts] FOREIGN KEY([AccountNo]) REFERENCES [dbo].[Accounts] ([AccountNo]) GO ALTER TABLE [dbo].[DebitCards] CHECK CONSTRAINT [FK_DebitCards_Accounts] GO /****** Object: ForeignKey [FK_Payees_Accounts] Script Date: 08/23/2013 14:4 6:28 ******/ ALTER TABLE [dbo].[Payees] WITH CHECK ADD CONSTRAINT [FK_Payees_Accounts] FORE IGN KEY([AccountNo]) REFERENCES [dbo].[Accounts] ([AccountNo]) GO ALTER TABLE [dbo].[Payees] CHECK CONSTRAINT [FK_Payees_Accounts] GO /****** Object: ForeignKey [FK_SavingsAccounts_Accounts] Script Date: 08/23/ 2013 14:46:28 ******/ ALTER TABLE [dbo].[SavingsAccounts] WITH CHECK ADD CONSTRAINT [FK_SavingsAccou nts_Accounts] FOREIGN KEY([AccountNo]) REFERENCES [dbo].[Accounts] ([AccountNo]) GO ALTER TABLE [dbo].[SavingsAccounts] CHECK CONSTRAINT [FK_SavingsAccounts_Account s] GO /****** Object: ForeignKey [FK_Cheques_Accounts] Script Date: 08/23/2013 14: 46:28 ******/ ALTER TABLE [dbo].[Cheques] WITH CHECK ADD CONSTRAINT [FK_Cheques_Accounts] FO REIGN KEY([ChequeBookId]) REFERENCES [dbo].[ChequeBooks] ([ChequeBookId]) GO ALTER TABLE [dbo].[Cheques] CHECK CONSTRAINT [FK_Cheques_Accounts]

GO