You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/word/新协航_设计文档/数据库建表文档/1.0/存储过程_初始化应收应付.sql

178 lines
5.6 KiB
MySQL

3 years ago
/*
select * from import_cargo
select * from code_currency
--select * from sys_module where description='<EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
select * from ch_fee where bsno='AA01'
delete from ch_fee where bsno='AA01'
and feename in('<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','β<EFBFBD><EFBFBD>','<EFBFBD><EFBFBD>˰','<EFBFBD><EFBFBD>ֵ˰')
select c.id,currid,c.name,price,[weight],price_limit,codename,
baolv,prepayments,balance,tax,tax_zz,tariff,m.seller,M.buyer
from import_cargo c
left join import_main M on m.contractno=c.contractno
left join code_currency cu on cu.gid=c.currid
where c.contractno='AA01'
*/
-----------------
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sMsCWStart]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sMsCWStart]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[sMsCWStart]
(@contractno varchar(50)
)
--WITH ENCRYPTION
AS
declare @id int
declare @name varchar(50)
declare @currid varchar(50)
declare @price numeric(18,3)
declare @price_agio numeric(18,3)
declare @weight numeric(18,3)
declare @price_limit numeric(18,3)
declare @baolv numeric(8,4)
declare @prepayments numeric(18,3)
declare @balance numeric(18,3)
declare @tariff varchar(20)
declare @tax numeric(8,3)
declare @tax_zz numeric(8,3)
declare @newgid varchar(50)
declare @seller varchar(50)
declare @buyer varchar(50)
declare @codename varchar(50)
declare @H numeric(18,3)
declare @W numeric(18,3)
declare @paypart tinyint
declare @exchangerate numeric(18,4)
--declare @contractno varchar(50)
--set @contractno='A1'
Begin
--delete from ch_fee where bsno=@contractno
--and feename in('<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>','β<EFBFBD><EFBFBD>','<EFBFBD><EFBFBD>˰','<EFBFBD><EFBFBD>ֵ˰')
declare cursor1 cursor for --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>α<EFBFBD>cursor1
--ʹ<EFBFBD><EFBFBD><EFBFBD>α<EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>select<EFBFBD><EFBFBD>)
select c.id,currid,c.name,price,price_agio,[weight],
price_limit,codename,baolv,prepayments,balance,tax,tax_zz,tariff,
m.seller,M.buyer,paypart,exchangerate
from import_cargo c
left join import_main M on m.contractno=c.contractno
left join code_currency cu on cu.gid=c.currid
where c.contractno=@contractno
open cursor1
fetch next from cursor1 into @id,@currid,@name,@price,@price_agio,@weight,
@price_limit,@codename,@baolv,@prepayments,@balance,@tax,@tax_zz,@tariff,
@seller,@buyer,@paypart,@exchangerate
while @@fetch_status=0 --<EFBFBD>ж<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
begin
set @H=@price*@weight
if (@price_limit=0) begin
set @W=@H*@baolv
end
if (@price_limit=1) begin
set @W=@price_limit*@weight*@baolv
end
--select @H,@W
set @newgid=(select newid())
insert into ch_fee --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>chfee <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
(GID,bsno,feetype,feename,customername,unitprice,
quantity,amount,
currency,SUBMITDATE,ExChangerate,remark)values
(@newgid,@contractno,2,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',@seller,@price-@price_agio,
@weight,(@price-@price_agio)*@weight*@exchangerate,
@codename,getdate(),@exchangerate,@name+' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:(<28><><EFBFBD><EFBFBD>'+convert(varchar(20),@price)
+'-<2D><><EFBFBD><EFBFBD>'+convert(varchar(20),@price_agio)+')<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'+convert(varchar(20),@weight)+'kg <20><><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>')
set @newgid=(select newid())
insert into ch_fee --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>chfee <EFBFBD><EFBFBD>˰
(GID,bsno,feetype,feename,customername,unitprice,
quantity,amount,currency,SUBMITDATE,ExChangerate,remark)values (
@newgid,@contractno,1,'<EFBFBD><EFBFBD>˰',@buyer,@W,
@Tax,@W*@Tax*@exchangerate,@codename,getdate(),@exchangerate,@name+' <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>'+CONVERT(varchar(20),@H)
+' <20><><EFBFBD><EFBFBD>'+CONVERT(varchar(20),@baolv)+' <20><>˰<EFBFBD>۸<EFBFBD>'+CONVERT(varchar(20),@W)
+' '+@tariff+'˰<EFBFBD><EFBFBD>:'+CONVERT(varchar(10),@tax*100)+'%')
set @newgid=(select newid())
insert into ch_fee --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>chfee <EFBFBD><EFBFBD>˰
(GID,bsno,feetype,feename,customername,unitprice,
quantity,amount,currency,SUBMITDATE,ExChangerate,remark)values (
@newgid,@contractno,2,'<EFBFBD><EFBFBD>˰','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',@W,
@Tax,@W*@Tax*@exchangerate,@codename,getdate(),@exchangerate,@name+' <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>'+CONVERT(varchar(20),@H)
+' <20><><EFBFBD><EFBFBD>'+CONVERT(varchar(20),@baolv)+' <20><>˰<EFBFBD>۸<EFBFBD>'+CONVERT(varchar(20),@W)
+' '+@tariff+'˰<EFBFBD><EFBFBD>:'+CONVERT(varchar(10),@tax*100)+'%')
set @newgid=(select newid())
insert into ch_fee --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>chfee <EFBFBD><EFBFBD>ֵ˰
(GID,bsno,feetype,feename,customername,unitprice,
quantity,amount,currency,SUBMITDATE,ExChangerate,remark)values (
@newgid,@contractno,1,'<EFBFBD><EFBFBD>ֵ˰',@buyer,@W*(1+@tax),
@Tax_zz,@W*(1+@tax)*@Tax_zz*@exchangerate,@codename,getdate(),@exchangerate,@name+' <20><>˰<EFBFBD>۸<EFBFBD>'+CONVERT(varchar(20),@W)
+' <20><>˰'
+CONVERT(varchar(50),@W*@tax)
+' <20><>ֵ˰<D6B5><CBB0>:'+CONVERT(varchar(10),@tax_zz*100)+'%')
set @newgid=(select newid())
insert into ch_fee --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>chfee <EFBFBD><EFBFBD>ֵ˰
(GID,bsno,feetype,feename,customername,unitprice,
quantity,amount,currency,SUBMITDATE,ExChangerate,remark)values (
@newgid,@contractno,2,'<EFBFBD><EFBFBD>ֵ˰','<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',@W*(1+@tax),
@Tax_zz,@W*(1+@tax)*@Tax_zz*@exchangerate,@codename,getdate(),@exchangerate,@name+' <20><>˰<EFBFBD>۸<EFBFBD>'+CONVERT(varchar(20),@W)
+' <20><>˰'
+CONVERT(varchar(50),@W*@tax)
+' <20><>ֵ˰<D6B5><CBB0>:'+CONVERT(varchar(10),@tax_zz*100)+'%')
if ((@paypart=0) or (@paypart=1)) begin
set @newgid=(select newid())
insert into ch_fee --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>chfee Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
(GID,bsno,feetype,feename,customername,unitprice,
quantity,amount,currency,SUBMITDATE,ExChangerate,remark)values
(@newgid,@contractno,1,'Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',@buyer,@prepayments,
1,@prepayments*@exchangerate,@codename,getdate(),@exchangerate,@name+' <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>')
end
if ((@paypart=0) or (@paypart=3)) begin
set @newgid=(select newid())
insert into ch_fee --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>chfee β<EFBFBD><EFBFBD>
(GID,bsno,feetype,feename,customername,unitprice,
quantity,amount,currency,SUBMITDATE,ExChangerate,remark)values
(@newgid,@contractno,1,'β<EFBFBD><EFBFBD>',@buyer,@balance,
1,@balance*@exchangerate,@codename,getdate(),@exchangerate,@name+' <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>')
end
fetch next from cursor1 into @id,@currid,@name,@price,@price_agio,@weight,
@price_limit,@codename,@baolv,@prepayments,@balance,@tax,@tax_zz,@tariff,
@seller,@buyer,@paypart,@exchangerate
end
close cursor1 --<EFBFBD>ر<EFBFBD><EFBFBD>α<EFBFBD>
deallocate cursor1
End
GO
--exec smsCWStart 'A1'