SlideShare une entreprise Scribd logo
1  sur  6
addInvoice
ALTERProcedure [dbo].[addInvoice](@INo Varchar(50),@IDate DateTime,@Cus
Varchar(50),@Total Numeric(18,2),@Paid Numeric(18,2),@rtAM
Numeric(18,2),@writeOff Numeric(18,2))AS
Begin
InsertInto INVOICE Values(@INo,@IDate,@Cus,@Total,@Paid,@rtAM,@writeOff)
Declare @credit Numeric(18,2)
set @Credit=@Total-(@Paid+@WriteOff+@rtAM)
If(@Credit>0)
      Begin
                  declare @bgCredit Numeric(18,2)
                  DECLARE @endCredit Numeric(18,2)
                  select @bgCredit=Credit from Customers Where C_ID=@Cus
                  set @endCredit=@bgCredit+@credit
                  Update Customers set CREDIT=@endCredit where C_ID=@Cus
                  InsertInto RecievableHistory
                  Values(@iDate,@Cus,@BgCredit,@Credit,0,0,@endCredit,@INo)
      end
if(@paid>0)
      Begin
            declare @bAM Numeric(18,2),@eAM Numeric(18,2)
            declare @CID Int
            set @CID=(SelectMax(ID)from cashFlow)
            if(@CID Isnull)
                        set @bAM=0
            else
                  set @bAM=(Select EndBalance from CashFlow where ID=@CID)
            set @eAM=@bAM+@Paid
            InsertInto CashFLow
            Values(@IDate,@bAM,@Paid,@eAM,@INo,N'    ',N'      ')
end
END


                       addInvoiceItem
ALTERProcedure [dbo].[addInvoiceItem](@INo Varchar(50),@PRONAME
NVARCHAR(100),
@W_CAPACITY NUMERIC(18,2),@UN NVarchar(50),
@Price Numeric(18,3),@Qty1 Numeric(18,2),@rtQty Numeric(18,2),
@Dis Numeric(18,2),@Am Numeric(18,2))as
Begin
declare @iDate DateTime
set @iDate=(Select INVDate from Invoice where InvNo=@iNo)
InsertInto InvoiceItems
Values(@INo,@PRONAME,@W_CAPACITY,@Un,@Price,@Qty1,@rtQty,@Dis,@AM)

if(@Qty1>0)
exec processStock 1,@iDate,@W_CAPACITY,@Qty1,N'    ',@ino,@PRONAME
if(@rtQty>0)
exec processStock 0,@iDate,@W_CAPACITY,@rtQty,N'       ',@ino,@PRONAME
END
END
deleteInvoice
ALTERProc [dbo].[deleteInvoice](@invNo Varchar(50))as

Declare @Cid Varchar(50),@credit Numeric(18,2)
Begin
set @Cid=(Select C_id from Invoice where InvNo=@InvNo)
set @Credit=(Select Credit from Invoice Where InvNo=@InvNo)

declare @rID Int
select @rid=CID from RecievableHistory
where C_ID=@CID and INVNO=@InvNo

update customers set credit=credit-@credit
where C_ID=@CID
deletefrom RecievableHistory where CID=@rid

Update RecievableHistory
set BeginBalance=BeginBalance-@credit,EndBalance=EndBalance-@Credit
where C_ID=@CID and CID>@rid

Declare ItemCur CURSOR SCROLL DYNAMIC
forselect PRONAME,QtyS,reQty,W_CAPACITY
from InvoiceItems where InvNo=@InvNo
Declare @pro nVarchar(50),@Qt Numeric(18,2),@retQt Numeric(18,2),@capacity
numeric(18,2)
open ItemCur
fetch first from ItemCur Into @pro,@qt,@retQt,@capacity
while(@@fetch_status=0)
Begin
if(@qt>0)
begin
      Declare @RID1 Int
      select @RID1=SID from StockHistory
      where TranType=N'    'and RefNo=@invNo
      Update StockHistory
      set BeginStock=BeginStock+@Qt,EndStock=EndStock+@Qt
      where SID>@RID1 and RefNo=@invNo
      deletefrom StockHistory where SID=@RID1
      Update WARTERS set Qty=Qty+@Qt
      where SUPLIERName=@Pro and W_capacity=@capacity
end
if(@retQt>0)
Begin
Declare @RID2 Int
      select @RID2=SID from StockHistory
      where TranType=N'        'and RefNo=@invNo
      Update StockHistory
      set BeginStock=BeginStock-@retQt,EndStock=EndStock-@retQt
      where SID>@RID2 and RefNo=@invNo
      Deletefrom StockHistory where SID=@RID2
      Update WARTERS set Qty=Qty-@retQt
      where SuplierName=@Pro and W_capacity=@capacity
end
fetch next from ItemCur Into @pro,@qt,@retQt,@capacity
end
close itemCur
deallocate ItemCur
Deletefrom Invoice where InvNo=@invNo
deletefrom InvoiceItems where InvNo=@InvNo
END
deleteImport
ALTERProcedure [dbo].[deleteImport](@ImpNO Varchar(20))as
Begin
Declare @sup NVarchar(100),@RID Int,@credit Numeric(18,3),@InvRef Varchar(30)
Select @Sup=Supliername,@credit=Credit,@InvRef=Refno from Imports
where ImportNo=@ImpNo

select @RID=PID from PayableHistory Where SuplierName=@sup and RefNo=@InvRef
AND Credit>0
Deletefrom PayableHistory Where PID=@RID
Update PayableHistory Set BeginCredit=BeginCredit-
@Credit,EndCredit=EndCredit-@Credit
Where PID>@RID
Update Supliers set Credit=Credit-credit where SuplierName=@Sup
Declare imCursor CURSOR SCROLL DYNAMIC FORSELECT
Capacity,ImportQty+FreeQty,supliername
from ImportItems WHere ImportNo=@ImpNo
Declare @capcity numeric(18,2),@Qty Numeric(18,2),@supliername
asnvarchar(100)
Open ImCursor
Fetch first from imCursor Into
@capcity,@Qty,@supliername
While(@@fetch_Status=0)
      Begin
             declare @SID Int
             Select @SID=SID from StockHistory
             Where RefNo=@ImpNo and W_CAPACITY=@capcity
             Deletefrom StockHistory Where SID=@SID
             Update StockHistory
             Set BeginStock=BeginStock-@QTy,ENDStock=EndStock-@QTy
             Where Sid>@sid
             Update WARTERS set QTy=Qty-@QTY
             Where W_capacity=@capcity and supliername=@supliername
Fetch next from imCursor Into
@capcity,@Qty,@supliername
      End
close imCursor
deallocate imCursor
deletefrom ImportItems Where REFNO=@ImpNo
Deletefrom Imports Where REFNO=@ImpNo
END
END

                           doImportItem
ALTERProcedure [dbo].[doImportItem](@INo nVarchar(50),
@capacity numeric(18,2),@UN NVarchar(50),@Price Numeric(18,2),
@Qty Numeric(18,2),@FreeQty Numeric(18,2),@Disc Numeric(18,2),
@Am Numeric(18,2), @REFNO ASVARCHAR(50),@suppliername asnvarchar(100))as
Begin
declare @iDate DateTime
set @iDate=(Select ImportDate from Imports where ImportNo=@iNo)
InsertInto ImportItems
Values(@INo,@capacity,@Un,@Price,@Qty,@freeQty,@Disc,@AM,@REFNO,@suppliername
)
Declare @TTQT Numeric(18,2)
set @TTQT=@QTy+@FreeQty
exec processStock 0,@iDate,@capacity,@ttQT,N'        ',@ino,@suppliername
END
processStock
ALTERProc [dbo].[processStock](@State Int,@Date DateTime
,@WCAPACITY NUMERIC(18,2),@Qty Numeric(18,2),@Desc NVarchar(50),
@Ref Varchar(50),@suppliername asnvarchar(100))as
Begin
Declare @BStock Numeric(18),@EStock Numeric(18,2)
Select @BStock=QTY from WARTERS where W_CAPACITY=@WCAPACITY and
supliername=@suppliername
if(@State=0)--Import
      Begin
            set @eStock=@Bstock+@Qty
      end
if(@State=1)--Export
      Begin
      set @eStock=@Bstock-@Qty
      end
Update WARTERS
set Qty=@EStock
where W_CAPACITY=@WCAPACITY and supliername=@suppliername
InsertInto StockHistory
Values(@Date,@WCAPACITY,@BStock,@Qty,@DESC,@EStock,@REF)
END

                          doCPAIDDetail
ALTERProc [dbo].[doCPAIDDetail](@pNo Varchar(40),@date DateTime,@Cus
Varchar(50),
@Inv Varchar(50),@Total Numeric(18,2),@PAM Numeric(18,2))
AS
Begin
InsertInto CPAIDDETAILS
Values(@PNO,@Inv,@Total,@PAM)
Declare @Bg Numeric(18,2),@end Numeric(18,2)
Select @bg=Credit from Customers Where
C_ID=@Cus
set @end=@bg-@PAM
InsertInto RecievableHistory
Values(@date,@cus,@bg,0,@pam,0,@end,@inv)
Update Customers
set Credit=@end
Where C_ID=@cus
Update Invoice set Paid=Paid+@PAM
where INVNO=@INV
declare @bAM Numeric(18,2),@eAM Numeric(18,2)
             declare @CID Int
             set @CID=(SelectMax(ID)from cashFlow)
             if(@CID Isnull)
                         set @bAM=0
             else
                   set @bAM=(Select EndBalance from CashFlow where ID=@CID)
             set @eAM=@bAM+@pam
             InsertInto CashFLow
             Values(@Date,@bAM,@Pam,@eAM,@inv,N'            ',N'      ')

END
doimports
ALTERproc [dbo].[doimports](@IMPNO NVARCHAR(50),@IMPDATE DATETIME,
@SUPLIERS NVARCHAR(200),@TOTALAM NUMERIC(18,2),@PAID NUMERIC(18,2)
,@REFNO NVARCHAR(200),@USER VARCHAR(50))
ASBEGIN
INSERTINTO Imports
VALUES(@IMPNO,@IMPDATE,@SUPLIERS,@TOTALAM,@PAID,@REFNO,@USER)
declare @CREDIT numeric(18,2)
set @CREDIT=@TOTALAM-@PAID
if(@TOTALAM>0)
      begin
            declare @bAM Numeric(18,2),@eAM Numeric(18,2)
            declare @CID Int
            set @CID=(SelectMax(ID)from cashFlow)
            if(@CID Isnull)
                         set @bAM=0
            else
                   set @bAM=(Select EndBalance from CashFlow where ID=@CID)
            set @eAM=@bAM-@TOTALAM
            InsertInto CashFLow
            Values(@IMPDATE,@bAM,@TOTALAM,@eAM,@REFNO,N'         ',N'       ')
      end
if(@CREDIT>0)
      Begin
      declare @sbcredit numeric(18,2)
      declare @secredit numeric(18,2)
      select @sbcredit=credit from Supliers where supliername=@supliers
      set @secredit=@sbcredit+@credit
      insertinto PayableHistory
      values(@IMPDATE,@SUPLIERS,@sbcredit,@credit,0,0,@secredit,@REFNO)
      Update Supliers set Credit=@secredit
      where supliername=@supliers
      end
END

                                 RECIEC
ALTERPROC [dbo].[RECIEC](@RID VARCHAR(50),@CUSNAME NVARCHAR(100),@INVNO
VARCHAR(100),@DATE DATETIME,
@TOTAL NUMERIC(18,2),@PAID NUMERIC(18,2),@RETURN NUMERIC(18,2),@CREDIT
NUMERIC(18,2),
@PAY NUMERIC(18,2),@NEWCREDIT NUMERIC(18,2))AS
BEGIN
INSERTINTO Receic
VALUES(@RID,@CUSNAME,@INVNO,@DATE,@TOTAL,@PAID,@RETURN,@CREDIT,@PAY,@NEWCREDI
T)
END


                                DOCPAID
ALTERProc [dbo].[DOCPAID](@CPNo Varchar(50),@pDate DateTime,@cus
NVarchar(100),
@total Numeric(18,2),@USER VARCHAR(50))as
Begin
InsertInto CPAIDS Values(@CPNo,@pDate,@cus,@total,@USER)
PAIDDetail
ALTERProc [dbo].[PAIDDetail](@pNo NVarchar(40),@IMPDATE DateTime,@supliers
NVarchar(50),
@Inv NVarchar(200),@credit Numeric(18,2),@PAM Numeric(18,2))
AS
Begin
InsertInto PAIDDETAILS
Values(@PNO,@Inv,@credit,@PAM)
      declare @sbcredit numeric(18,2)
      declare @secredit numeric(18,2)
      select @sbcredit=credit from Supliers where supliername=@supliers
      set @secredit=@sbcredit-@PAM
      insertinto PayableHistory
      values(@IMPDATE,@SUPLIERS,@sbcredit,0,@PAM,0,@secredit,@Inv)
      Update Supliers set Credit=@secredit
      where supliername=@supliers
Update imports set Paid=Paid+@PAM
WHERE REFNO=@INV AND SUPLIERNAME=@SUPLIERS
declare @bAM Numeric(18,2),@eAM Numeric(18,2)
            declare @CID Int
            set @CID=(SelectMax(ID)from cashFlow)
            if(@CID Isnull)
                        set @bAM=0
            else
                  set @bAM=(Select EndBalance from CashFlow where ID=@CID)
            set @eAM=@bAM-@pam
            InsertInto CashFLow
            Values(@IMPDATE,@bAM,@Pam,@eAM,@inv,N'            ',N'      ')

END

Contenu connexe

Tendances

STOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBASTOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBASenthil Kanth
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsVishvjeet Yadav
 
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...Salar Delavar Qashqai
 
Interactive financial analytics with vix(cboe)
Interactive financial analytics with vix(cboe)Interactive financial analytics with vix(cboe)
Interactive financial analytics with vix(cboe)Aiden Wu, FRM
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservationSwarup Kumar Boro
 
Nonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programmingNonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programmingSalar Delavar Qashqai
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptLaurence Svekis ✔
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
Geometric nonlinearity analysis of springs with rigid element displacement co...
Geometric nonlinearity analysis of springs with rigid element displacement co...Geometric nonlinearity analysis of springs with rigid element displacement co...
Geometric nonlinearity analysis of springs with rigid element displacement co...Salar Delavar Qashqai
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objectsHusain Dalal
 

Tendances (20)

STOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBASTOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBA
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
informatics practices practical file
informatics practices practical fileinformatics practices practical file
informatics practices practical file
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
Nonlinear analysis of fixed support beam with hinge by hinge method in c prog...
 
Interactive financial analytics with vix(cboe)
Interactive financial analytics with vix(cboe)Interactive financial analytics with vix(cboe)
Interactive financial analytics with vix(cboe)
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
Advance java
Advance javaAdvance java
Advance java
 
Ch 4
Ch 4Ch 4
Ch 4
 
PDBC
PDBCPDBC
PDBC
 
Nonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programmingNonlinear analysis of braced frame with hinge by hinge method in c programming
Nonlinear analysis of braced frame with hinge by hinge method in c programming
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
Geometric nonlinearity analysis of springs with rigid element displacement co...
Geometric nonlinearity analysis of springs with rigid element displacement co...Geometric nonlinearity analysis of springs with rigid element displacement co...
Geometric nonlinearity analysis of springs with rigid element displacement co...
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
Asssignment2
Asssignment2 Asssignment2
Asssignment2
 

En vedette

Queries assignment udf_and_triggers
Queries assignment udf_and_triggersQueries assignment udf_and_triggers
Queries assignment udf_and_triggersPriya Sharma
 
Relational / XML DB -SQL Server & Oracle Database
 Relational /  XML DB -SQL Server & Oracle Database Relational /  XML DB -SQL Server & Oracle Database
Relational / XML DB -SQL Server & Oracle DatabaseSunny U Okoro
 
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2Sunny U Okoro
 
Web Scripting Project JavaScripts and HTML WebPage
Web Scripting Project JavaScripts and HTML WebPageWeb Scripting Project JavaScripts and HTML WebPage
Web Scripting Project JavaScripts and HTML WebPageSunny U Okoro
 
Forall & bulk binds
Forall & bulk bindsForall & bulk binds
Forall & bulk bindsNawaz Sk
 
Lean Startup - by Hristo Neychev (bring your ideas to life faster, smarter, a...
Lean Startup - by Hristo Neychev (bring your ideas to life faster, smarter, a...Lean Startup - by Hristo Neychev (bring your ideas to life faster, smarter, a...
Lean Startup - by Hristo Neychev (bring your ideas to life faster, smarter, a...Hristo Neychev
 
This is a real sign in the mission district in calgary on 25th ave
This is a real sign in the mission district in calgary on 25th aveThis is a real sign in the mission district in calgary on 25th ave
This is a real sign in the mission district in calgary on 25th aveDerrick Walsh
 

En vedette (10)

Queries assignment udf_and_triggers
Queries assignment udf_and_triggersQueries assignment udf_and_triggers
Queries assignment udf_and_triggers
 
Relational / XML DB -SQL Server & Oracle Database
 Relational /  XML DB -SQL Server & Oracle Database Relational /  XML DB -SQL Server & Oracle Database
Relational / XML DB -SQL Server & Oracle Database
 
Ref cursor
Ref cursorRef cursor
Ref cursor
 
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2
 
Web Scripting Project JavaScripts and HTML WebPage
Web Scripting Project JavaScripts and HTML WebPageWeb Scripting Project JavaScripts and HTML WebPage
Web Scripting Project JavaScripts and HTML WebPage
 
Oracle SQL Self Study
Oracle SQL Self StudyOracle SQL Self Study
Oracle SQL Self Study
 
lect4
lect4lect4
lect4
 
Forall & bulk binds
Forall & bulk bindsForall & bulk binds
Forall & bulk binds
 
Lean Startup - by Hristo Neychev (bring your ideas to life faster, smarter, a...
Lean Startup - by Hristo Neychev (bring your ideas to life faster, smarter, a...Lean Startup - by Hristo Neychev (bring your ideas to life faster, smarter, a...
Lean Startup - by Hristo Neychev (bring your ideas to life faster, smarter, a...
 
This is a real sign in the mission district in calgary on 25th ave
This is a real sign in the mission district in calgary on 25th aveThis is a real sign in the mission district in calgary on 25th ave
This is a real sign in the mission district in calgary on 25th ave
 

Similaire à Add invoice

Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfarmanuelraj
 
Work in TDW
Work in TDWWork in TDW
Work in TDWsaso70
 
Advanced dot net
Advanced dot netAdvanced dot net
Advanced dot netssa2010
 
The resto txt Use for TM254 2021J TMA02 Question 6 .pdf
The resto txt     Use for TM254 2021J TMA02 Question 6 .pdfThe resto txt     Use for TM254 2021J TMA02 Question 6 .pdf
The resto txt Use for TM254 2021J TMA02 Question 6 .pdfgiriraj65
 
Beautiful Development ブレイクスルー体験記
Beautiful Development ブレイクスルー体験記Beautiful Development ブレイクスルー体験記
Beautiful Development ブレイクスルー体験記kentaro watanabe
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfarjuncollection
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankMd Mudassir
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++Pranav Ghildiyal
 
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...Altinity Ltd
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical fileMitul Patel
 

Similaire à Add invoice (20)

Marcus Portfolio
Marcus  PortfolioMarcus  Portfolio
Marcus Portfolio
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdf
 
Functions
FunctionsFunctions
Functions
 
project
projectproject
project
 
Work in TDW
Work in TDWWork in TDW
Work in TDW
 
Dat402
Dat402Dat402
Dat402
 
Advanced dot net
Advanced dot netAdvanced dot net
Advanced dot net
 
The resto txt Use for TM254 2021J TMA02 Question 6 .pdf
The resto txt     Use for TM254 2021J TMA02 Question 6 .pdfThe resto txt     Use for TM254 2021J TMA02 Question 6 .pdf
The resto txt Use for TM254 2021J TMA02 Question 6 .pdf
 
Beautiful Development ブレイクスルー体験記
Beautiful Development ブレイクスルー体験記Beautiful Development ブレイクスルー体験記
Beautiful Development ブレイクスルー体験記
 
Df
DfDf
Df
 
Df
DfDf
Df
 
Df
DfDf
Df
 
Df
DfDf
Df
 
Df
DfDf
Df
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdf
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 
C++ practical
C++ practicalC++ practical
C++ practical
 
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 

Add invoice

  • 1. addInvoice ALTERProcedure [dbo].[addInvoice](@INo Varchar(50),@IDate DateTime,@Cus Varchar(50),@Total Numeric(18,2),@Paid Numeric(18,2),@rtAM Numeric(18,2),@writeOff Numeric(18,2))AS Begin InsertInto INVOICE Values(@INo,@IDate,@Cus,@Total,@Paid,@rtAM,@writeOff) Declare @credit Numeric(18,2) set @Credit=@Total-(@Paid+@WriteOff+@rtAM) If(@Credit>0) Begin declare @bgCredit Numeric(18,2) DECLARE @endCredit Numeric(18,2) select @bgCredit=Credit from Customers Where C_ID=@Cus set @endCredit=@bgCredit+@credit Update Customers set CREDIT=@endCredit where C_ID=@Cus InsertInto RecievableHistory Values(@iDate,@Cus,@BgCredit,@Credit,0,0,@endCredit,@INo) end if(@paid>0) Begin declare @bAM Numeric(18,2),@eAM Numeric(18,2) declare @CID Int set @CID=(SelectMax(ID)from cashFlow) if(@CID Isnull) set @bAM=0 else set @bAM=(Select EndBalance from CashFlow where ID=@CID) set @eAM=@bAM+@Paid InsertInto CashFLow Values(@IDate,@bAM,@Paid,@eAM,@INo,N' ',N' ') end END addInvoiceItem ALTERProcedure [dbo].[addInvoiceItem](@INo Varchar(50),@PRONAME NVARCHAR(100), @W_CAPACITY NUMERIC(18,2),@UN NVarchar(50), @Price Numeric(18,3),@Qty1 Numeric(18,2),@rtQty Numeric(18,2), @Dis Numeric(18,2),@Am Numeric(18,2))as Begin declare @iDate DateTime set @iDate=(Select INVDate from Invoice where InvNo=@iNo) InsertInto InvoiceItems Values(@INo,@PRONAME,@W_CAPACITY,@Un,@Price,@Qty1,@rtQty,@Dis,@AM) if(@Qty1>0) exec processStock 1,@iDate,@W_CAPACITY,@Qty1,N' ',@ino,@PRONAME if(@rtQty>0) exec processStock 0,@iDate,@W_CAPACITY,@rtQty,N' ',@ino,@PRONAME END END
  • 2. deleteInvoice ALTERProc [dbo].[deleteInvoice](@invNo Varchar(50))as Declare @Cid Varchar(50),@credit Numeric(18,2) Begin set @Cid=(Select C_id from Invoice where InvNo=@InvNo) set @Credit=(Select Credit from Invoice Where InvNo=@InvNo) declare @rID Int select @rid=CID from RecievableHistory where C_ID=@CID and INVNO=@InvNo update customers set credit=credit-@credit where C_ID=@CID deletefrom RecievableHistory where CID=@rid Update RecievableHistory set BeginBalance=BeginBalance-@credit,EndBalance=EndBalance-@Credit where C_ID=@CID and CID>@rid Declare ItemCur CURSOR SCROLL DYNAMIC forselect PRONAME,QtyS,reQty,W_CAPACITY from InvoiceItems where InvNo=@InvNo Declare @pro nVarchar(50),@Qt Numeric(18,2),@retQt Numeric(18,2),@capacity numeric(18,2) open ItemCur fetch first from ItemCur Into @pro,@qt,@retQt,@capacity while(@@fetch_status=0) Begin if(@qt>0) begin Declare @RID1 Int select @RID1=SID from StockHistory where TranType=N' 'and RefNo=@invNo Update StockHistory set BeginStock=BeginStock+@Qt,EndStock=EndStock+@Qt where SID>@RID1 and RefNo=@invNo deletefrom StockHistory where SID=@RID1 Update WARTERS set Qty=Qty+@Qt where SUPLIERName=@Pro and W_capacity=@capacity end if(@retQt>0) Begin Declare @RID2 Int select @RID2=SID from StockHistory where TranType=N' 'and RefNo=@invNo Update StockHistory set BeginStock=BeginStock-@retQt,EndStock=EndStock-@retQt where SID>@RID2 and RefNo=@invNo Deletefrom StockHistory where SID=@RID2 Update WARTERS set Qty=Qty-@retQt where SuplierName=@Pro and W_capacity=@capacity end fetch next from ItemCur Into @pro,@qt,@retQt,@capacity end close itemCur deallocate ItemCur Deletefrom Invoice where InvNo=@invNo deletefrom InvoiceItems where InvNo=@InvNo END
  • 3. deleteImport ALTERProcedure [dbo].[deleteImport](@ImpNO Varchar(20))as Begin Declare @sup NVarchar(100),@RID Int,@credit Numeric(18,3),@InvRef Varchar(30) Select @Sup=Supliername,@credit=Credit,@InvRef=Refno from Imports where ImportNo=@ImpNo select @RID=PID from PayableHistory Where SuplierName=@sup and RefNo=@InvRef AND Credit>0 Deletefrom PayableHistory Where PID=@RID Update PayableHistory Set BeginCredit=BeginCredit- @Credit,EndCredit=EndCredit-@Credit Where PID>@RID Update Supliers set Credit=Credit-credit where SuplierName=@Sup Declare imCursor CURSOR SCROLL DYNAMIC FORSELECT Capacity,ImportQty+FreeQty,supliername from ImportItems WHere ImportNo=@ImpNo Declare @capcity numeric(18,2),@Qty Numeric(18,2),@supliername asnvarchar(100) Open ImCursor Fetch first from imCursor Into @capcity,@Qty,@supliername While(@@fetch_Status=0) Begin declare @SID Int Select @SID=SID from StockHistory Where RefNo=@ImpNo and W_CAPACITY=@capcity Deletefrom StockHistory Where SID=@SID Update StockHistory Set BeginStock=BeginStock-@QTy,ENDStock=EndStock-@QTy Where Sid>@sid Update WARTERS set QTy=Qty-@QTY Where W_capacity=@capcity and supliername=@supliername Fetch next from imCursor Into @capcity,@Qty,@supliername End close imCursor deallocate imCursor deletefrom ImportItems Where REFNO=@ImpNo Deletefrom Imports Where REFNO=@ImpNo END END doImportItem ALTERProcedure [dbo].[doImportItem](@INo nVarchar(50), @capacity numeric(18,2),@UN NVarchar(50),@Price Numeric(18,2), @Qty Numeric(18,2),@FreeQty Numeric(18,2),@Disc Numeric(18,2), @Am Numeric(18,2), @REFNO ASVARCHAR(50),@suppliername asnvarchar(100))as Begin declare @iDate DateTime set @iDate=(Select ImportDate from Imports where ImportNo=@iNo) InsertInto ImportItems Values(@INo,@capacity,@Un,@Price,@Qty,@freeQty,@Disc,@AM,@REFNO,@suppliername ) Declare @TTQT Numeric(18,2) set @TTQT=@QTy+@FreeQty exec processStock 0,@iDate,@capacity,@ttQT,N' ',@ino,@suppliername END
  • 4. processStock ALTERProc [dbo].[processStock](@State Int,@Date DateTime ,@WCAPACITY NUMERIC(18,2),@Qty Numeric(18,2),@Desc NVarchar(50), @Ref Varchar(50),@suppliername asnvarchar(100))as Begin Declare @BStock Numeric(18),@EStock Numeric(18,2) Select @BStock=QTY from WARTERS where W_CAPACITY=@WCAPACITY and supliername=@suppliername if(@State=0)--Import Begin set @eStock=@Bstock+@Qty end if(@State=1)--Export Begin set @eStock=@Bstock-@Qty end Update WARTERS set Qty=@EStock where W_CAPACITY=@WCAPACITY and supliername=@suppliername InsertInto StockHistory Values(@Date,@WCAPACITY,@BStock,@Qty,@DESC,@EStock,@REF) END doCPAIDDetail ALTERProc [dbo].[doCPAIDDetail](@pNo Varchar(40),@date DateTime,@Cus Varchar(50), @Inv Varchar(50),@Total Numeric(18,2),@PAM Numeric(18,2)) AS Begin InsertInto CPAIDDETAILS Values(@PNO,@Inv,@Total,@PAM) Declare @Bg Numeric(18,2),@end Numeric(18,2) Select @bg=Credit from Customers Where C_ID=@Cus set @end=@bg-@PAM InsertInto RecievableHistory Values(@date,@cus,@bg,0,@pam,0,@end,@inv) Update Customers set Credit=@end Where C_ID=@cus Update Invoice set Paid=Paid+@PAM where INVNO=@INV declare @bAM Numeric(18,2),@eAM Numeric(18,2) declare @CID Int set @CID=(SelectMax(ID)from cashFlow) if(@CID Isnull) set @bAM=0 else set @bAM=(Select EndBalance from CashFlow where ID=@CID) set @eAM=@bAM+@pam InsertInto CashFLow Values(@Date,@bAM,@Pam,@eAM,@inv,N' ',N' ') END
  • 5. doimports ALTERproc [dbo].[doimports](@IMPNO NVARCHAR(50),@IMPDATE DATETIME, @SUPLIERS NVARCHAR(200),@TOTALAM NUMERIC(18,2),@PAID NUMERIC(18,2) ,@REFNO NVARCHAR(200),@USER VARCHAR(50)) ASBEGIN INSERTINTO Imports VALUES(@IMPNO,@IMPDATE,@SUPLIERS,@TOTALAM,@PAID,@REFNO,@USER) declare @CREDIT numeric(18,2) set @CREDIT=@TOTALAM-@PAID if(@TOTALAM>0) begin declare @bAM Numeric(18,2),@eAM Numeric(18,2) declare @CID Int set @CID=(SelectMax(ID)from cashFlow) if(@CID Isnull) set @bAM=0 else set @bAM=(Select EndBalance from CashFlow where ID=@CID) set @eAM=@bAM-@TOTALAM InsertInto CashFLow Values(@IMPDATE,@bAM,@TOTALAM,@eAM,@REFNO,N' ',N' ') end if(@CREDIT>0) Begin declare @sbcredit numeric(18,2) declare @secredit numeric(18,2) select @sbcredit=credit from Supliers where supliername=@supliers set @secredit=@sbcredit+@credit insertinto PayableHistory values(@IMPDATE,@SUPLIERS,@sbcredit,@credit,0,0,@secredit,@REFNO) Update Supliers set Credit=@secredit where supliername=@supliers end END RECIEC ALTERPROC [dbo].[RECIEC](@RID VARCHAR(50),@CUSNAME NVARCHAR(100),@INVNO VARCHAR(100),@DATE DATETIME, @TOTAL NUMERIC(18,2),@PAID NUMERIC(18,2),@RETURN NUMERIC(18,2),@CREDIT NUMERIC(18,2), @PAY NUMERIC(18,2),@NEWCREDIT NUMERIC(18,2))AS BEGIN INSERTINTO Receic VALUES(@RID,@CUSNAME,@INVNO,@DATE,@TOTAL,@PAID,@RETURN,@CREDIT,@PAY,@NEWCREDI T) END DOCPAID ALTERProc [dbo].[DOCPAID](@CPNo Varchar(50),@pDate DateTime,@cus NVarchar(100), @total Numeric(18,2),@USER VARCHAR(50))as Begin InsertInto CPAIDS Values(@CPNo,@pDate,@cus,@total,@USER)
  • 6. PAIDDetail ALTERProc [dbo].[PAIDDetail](@pNo NVarchar(40),@IMPDATE DateTime,@supliers NVarchar(50), @Inv NVarchar(200),@credit Numeric(18,2),@PAM Numeric(18,2)) AS Begin InsertInto PAIDDETAILS Values(@PNO,@Inv,@credit,@PAM) declare @sbcredit numeric(18,2) declare @secredit numeric(18,2) select @sbcredit=credit from Supliers where supliername=@supliers set @secredit=@sbcredit-@PAM insertinto PayableHistory values(@IMPDATE,@SUPLIERS,@sbcredit,0,@PAM,0,@secredit,@Inv) Update Supliers set Credit=@secredit where supliername=@supliers Update imports set Paid=Paid+@PAM WHERE REFNO=@INV AND SUPLIERNAME=@SUPLIERS declare @bAM Numeric(18,2),@eAM Numeric(18,2) declare @CID Int set @CID=(SelectMax(ID)from cashFlow) if(@CID Isnull) set @bAM=0 else set @bAM=(Select EndBalance from CashFlow where ID=@CID) set @eAM=@bAM-@pam InsertInto CashFLow Values(@IMPDATE,@bAM,@Pam,@eAM,@inv,N' ',N' ') END