ALTER PROCEDURE [fms].[KC_InsertBankPaymentReceipt]
(
@NEWID int=null,
@VoucherDate datetime=null,
--@VoucherNo varchar(30)=null,
@CompanyID int=null,
@VoucherType varchar(20)=null,
@VoucherAmount decimal(18,2)=null,
@InvoiceRefNo nchar(10)=null,
@BankName varchar(50)=NULL,
@TransactionType varchar(50)=null,
@InstrumentNo varchar(50)=NULL,
@InstrumentDate datetime=NULL,
@Narration varchar(500)=null,
@RegOrOpt varchar(20)=NULL,
@PostDated bit=NULL,
@DayBookID int=null,
--@FYear nvarchar(20)=null,
@SlNo int=null,
@LedgerID int=null,
@LedgerID2 int=null,
@DrAmount decimal=null,
@CrAmount decimal=null,
@CreatedOn DATETIME=null,
@CreatedBy INT=null,
@ModifiedOn DATETIME=null,
@ModifiedBy INT=null,
@Out varchar(20)=null Output
)
AS
BEGIN
BEGIN TRANSACTION
--===========Generate an user defined Voucher No ===============
DECLARE @VoucherNo varchar(30)
SELECT @VoucherNo = VoucherNo
FROM fms.FMS_Vouchers
WHERE VoucherType=@VoucherType
DECLARE @Year int
SELECT @Year=year(getdate())
DECLARE @FYear varchar(10)
IF month(getdate())<3
BEGIN
select @FYear=CONVERT(varchar, @Year-1) +'-'+ CONVERT(varchar, @Year)
END
ELSE
BEGIN
select @FYear=CONVERT(varchar, @Year) +'-'+ CONVERT(varchar, @Year+1)
END
IF @VoucherNo IS NULL
BEGIN
IF @VoucherType='BankPayment'
BEGIN
SELECT @VoucherNo='BP/000001/'+@FYear
END
IF @VoucherType='BankReceipt'
BEGIN
SELECT @VoucherNo='BR/000001/'+@FYear
END
IF @VoucherType='CashPayment'
BEGIN
SELECT @VoucherNo='CP/000001/'+@FYear
END
IF @VoucherType='CashReceipt'
BEGIN
SELECT @VoucherNo='CR/000001/'+@FYear
END
IF @VoucherType='JournalVoucher'
BEGIN
SELECT @VoucherNo='JV/000001/'+@FYear
END
IF @VoucherType='ContraVoucher'
BEGIN
SELECT @VoucherNo='CV/000001/'+@FYear
END
set @Out=@VoucherNo
END
ELSE
BEGIN
DECLARE @P1 VARCHAR(20)
DECLARE @P2 VARCHAR(20)
DECLARE @P3 VARCHAR(20)
set @P1=Substring(@VoucherNo,1,2)
set @P2=Substring(@VoucherNo,4,6)
set @P3=Substring(@VoucherNo,11,9)
set @P2=cast(@P2 as int)+1
set @P2=RIGHT('000000' + RTRIM(@P2), 6)
set @VoucherNo=@P1+'/'+@P2+'/'+@P3
--Select @P1, @P2, @P3, @VoucherNo
set @Out=@VoucherNo
END
--===========End of Generate an user defined Voucher No ========
INSERT INTO fms.FMS_Vouchers
(
VoucherDate,VoucherNo,CompanyID,VoucherType,VoucherAmount,InvoiceRefNo,BankName,TransactionType,
InstrumentNo,InstrumentDate,Narration,RegOrOpt,PostDated,DayBookID,
--FYear,
CreatedOn,CreatedBy,
ModifiedOn,ModifiedBy
)
VALUES
(
@VoucherDate,@VoucherNo,@CompanyID,@VoucherType,@VoucherAmount,@InvoiceRefNo,@BankName,
@TransactionType,@InstrumentNo,@InstrumentDate,@Narration,@RegOrOpt,@PostDated,@DayBookID,
--@FYear,
GETDATE(),@CreatedBy,GETDATE(),
@ModifiedBy
)
SET @NEWID=SCOPE_IDENTITY()
INSERT INTO fms.FMS_VoucherDetails
(VoucherID,SlNo,LedgerID,DrAmount,CrAmount,CreatedOn,CreatedBy,ModifiedOn,ModifiedBy) VALUES
(@NEWID,@SlNo,@LedgerID,@DrAmount,@CrAmount,GETDATE(),@CreatedBy,GETDATE(),@ModifiedBy)
INSERT INTO fms.FMS_VoucherDetails
(VoucherID,SlNo,LedgerID,DrAmount,CrAmount,CreatedOn,CreatedBy,ModifiedOn,ModifiedBy)
VALUES(@NEWID,@SlNo,@LedgerID2,@CrAmount,@DrAmount,GETDATE(),@CreatedBy,GETDATE(),@ModifiedBy)
IF @@ERROR!=0
ROLLBACK TRAN
else
COMMIT TRAN
select @Out
END
(
@NEWID int=null,
@VoucherDate datetime=null,
--@VoucherNo varchar(30)=null,
@CompanyID int=null,
@VoucherType varchar(20)=null,
@VoucherAmount decimal(18,2)=null,
@InvoiceRefNo nchar(10)=null,
@BankName varchar(50)=NULL,
@TransactionType varchar(50)=null,
@InstrumentNo varchar(50)=NULL,
@InstrumentDate datetime=NULL,
@Narration varchar(500)=null,
@RegOrOpt varchar(20)=NULL,
@PostDated bit=NULL,
@DayBookID int=null,
--@FYear nvarchar(20)=null,
@SlNo int=null,
@LedgerID int=null,
@LedgerID2 int=null,
@DrAmount decimal=null,
@CrAmount decimal=null,
@CreatedOn DATETIME=null,
@CreatedBy INT=null,
@ModifiedOn DATETIME=null,
@ModifiedBy INT=null,
@Out varchar(20)=null Output
)
AS
BEGIN
BEGIN TRANSACTION
--===========Generate an user defined Voucher No ===============
DECLARE @VoucherNo varchar(30)
SELECT @VoucherNo = VoucherNo
FROM fms.FMS_Vouchers
WHERE VoucherType=@VoucherType
DECLARE @Year int
SELECT @Year=year(getdate())
DECLARE @FYear varchar(10)
IF month(getdate())<3
BEGIN
select @FYear=CONVERT(varchar, @Year-1) +'-'+ CONVERT(varchar, @Year)
END
ELSE
BEGIN
select @FYear=CONVERT(varchar, @Year) +'-'+ CONVERT(varchar, @Year+1)
END
IF @VoucherNo IS NULL
BEGIN
IF @VoucherType='BankPayment'
BEGIN
SELECT @VoucherNo='BP/000001/'+@FYear
END
IF @VoucherType='BankReceipt'
BEGIN
SELECT @VoucherNo='BR/000001/'+@FYear
END
IF @VoucherType='CashPayment'
BEGIN
SELECT @VoucherNo='CP/000001/'+@FYear
END
IF @VoucherType='CashReceipt'
BEGIN
SELECT @VoucherNo='CR/000001/'+@FYear
END
IF @VoucherType='JournalVoucher'
BEGIN
SELECT @VoucherNo='JV/000001/'+@FYear
END
IF @VoucherType='ContraVoucher'
BEGIN
SELECT @VoucherNo='CV/000001/'+@FYear
END
set @Out=@VoucherNo
END
ELSE
BEGIN
DECLARE @P1 VARCHAR(20)
DECLARE @P2 VARCHAR(20)
DECLARE @P3 VARCHAR(20)
set @P1=Substring(@VoucherNo,1,2)
set @P2=Substring(@VoucherNo,4,6)
set @P3=Substring(@VoucherNo,11,9)
set @P2=cast(@P2 as int)+1
set @P2=RIGHT('000000' + RTRIM(@P2), 6)
set @VoucherNo=@P1+'/'+@P2+'/'+@P3
--Select @P1, @P2, @P3, @VoucherNo
set @Out=@VoucherNo
END
--===========End of Generate an user defined Voucher No ========
INSERT INTO fms.FMS_Vouchers
(
VoucherDate,VoucherNo,CompanyID,VoucherType,VoucherAmount,InvoiceRefNo,BankName,TransactionType,
InstrumentNo,InstrumentDate,Narration,RegOrOpt,PostDated,DayBookID,
--FYear,
CreatedOn,CreatedBy,
ModifiedOn,ModifiedBy
)
VALUES
(
@VoucherDate,@VoucherNo,@CompanyID,@VoucherType,@VoucherAmount,@InvoiceRefNo,@BankName,
@TransactionType,@InstrumentNo,@InstrumentDate,@Narration,@RegOrOpt,@PostDated,@DayBookID,
--@FYear,
GETDATE(),@CreatedBy,GETDATE(),
@ModifiedBy
)
SET @NEWID=SCOPE_IDENTITY()
INSERT INTO fms.FMS_VoucherDetails
(VoucherID,SlNo,LedgerID,DrAmount,CrAmount,CreatedOn,CreatedBy,ModifiedOn,ModifiedBy) VALUES
(@NEWID,@SlNo,@LedgerID,@DrAmount,@CrAmount,GETDATE(),@CreatedBy,GETDATE(),@ModifiedBy)
INSERT INTO fms.FMS_VoucherDetails
(VoucherID,SlNo,LedgerID,DrAmount,CrAmount,CreatedOn,CreatedBy,ModifiedOn,ModifiedBy)
VALUES(@NEWID,@SlNo,@LedgerID2,@CrAmount,@DrAmount,GETDATE(),@CreatedBy,GETDATE(),@ModifiedBy)
IF @@ERROR!=0
ROLLBACK TRAN
else
COMMIT TRAN
select @Out
END
Gr8 Coding
ReplyDeletegratis ds spellen