if exists ( select * from sysobjects where name = ' p_rz_prepare_jh ' and xtype = ' p ' )
drop procedure p_rz_prepare_jh
go
create procedure p_rz_prepare_jh
(
@ psorgcode varchar ( 10 ) ,
@ psbillno varchar ( 20 ) ,
@ psparams varchar ( 200 ) ,
@ psmsg varchar ( 2000 ) out
)
as
begin
declare @ optaccepttimes varchar ( 1 )
declare @ sacceptno varchar ( 20 )
declare @ sbilltype varchar ( 1 )
declare @ optupacceptrate numeric ( 19 , 4 )
declare @ billcost numeric ( 19 , 4 )
declare @ sorgcode varchar ( 10 )
declare @ ssupcode varchar ( 15 )
declare @ ssupstatus varchar ( 1 )
declare @ ssupvalidstatus varchar ( 1 )
declare @ ssupcontractstatus varchar ( 1 )
select @ sorgcode = orgcode , @ ssupcode = supcode from t_accept_head where billno = @ psbillno
if not exists ( select * from t_supplier where supcode = @ ssupcode )
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> Ӧ<EFBFBD> ̲<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ڣ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ܼ<EFBFBD> <EFBFBD> <EFBFBD> '
return ( - 1 )
end
select @ ssupstatus = supstatus ,
@ ssupvalidstatus = case when ( isnull ( validdate , ' ' ) = ' ' or validdate > = convert ( varchar ( 100 ) , getdate ( ) , 23 ) ) then ' 1 ' else ' 0 ' end ,
@ ssupcontractstatus = case when ( not exists ( select * from t_contract where supcode = t_supplier . supcode and contrstatus = ' 0 ' ) ) or
( exists ( select * from t_contract where supcode = t_supplier . supcode and contrstatus = ' 0 ' and convert ( varchar ( 100 ) , getdate ( ) , 23 ) between bgndate and enddate ) ) then ' 1 '
else ' 0 ' end
from t_supplier where supcode = @ ssupcode
if @ ssupstatus < > ' 0 '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <EFBFBD> ״̬<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ܼ<EFBFBD> <EFBFBD> <EFBFBD> '
return ( - 1 )
end
if @ ssupvalidstatus = ' 0 '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <EFBFBD> <EFBFBD> ѹ<EFBFBD> <EFBFBD> <EFBFBD> Ч<EFBFBD> ڣ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ܼ<EFBFBD> <EFBFBD> <EFBFBD> '
return ( - 1 )
end
if @ ssupcontractstatus = ' 0 '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> Ӧ<EFBFBD> ̺<EFBFBD> ͬ<EFBFBD> ѹ<EFBFBD> <EFBFBD> ڣ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ܼ<EFBFBD> <EFBFBD> <EFBFBD> '
return ( - 1 )
end
select @ optaccepttimes = accepttimes from t_shop where orgcode = @ psorgcode
set @ optaccepttimes = isnull ( @ optaccepttimes , ' 0 ' )
select @ optupacceptrate = convert ( numeric ( 19 , 4 ) , itemvalue ) from t_syscfg where section = ' SYSTEM ' and itemname = ' UpAcceptRate '
set @ optupacceptrate = isnull ( @ optupacceptrate , 10 )
select @ sacceptno = a . billno , @ sbilltype = a . billtype from t_accept_head a , t_accept_head h
where a . orderno = h . orderno and h . billno = @ psbillno and h . orderno < > ' ' and h . orderno is not null
and h . orderno in ( select billno from t_order_head where billno = h . orderno and billtype = ' 0 ' )
and a . rzdate is not null and a . rzdate < > ' ' and ( ( h . billtype = ' 3 ' and a . billtype = ' 3 ' and h . depcode = a . depcode )
or ( @ optaccepttimes = ' 0 ' and h . billtype in ( ' 0 ' , ' 1 ' , ' 2 ' ) and a . billtype in ( ' 0 ' , ' 1 ' , ' 2 ' ) ) )
if @ @ rowcount > 0
begin
if @ sbilltype = ' 3 '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> յ<EFBFBD> <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͵<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ѿ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ˵<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> յ<EFBFBD> '
return ( - 1 )
end
else
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> յ<EFBFBD> <EFBFBD> <EFBFBD> Ӧ<EFBFBD> IJɹ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ѿ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ˵<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> յ<EFBFBD> '
return ( - 1 )
end
end
select @ psmsg = coalesce ( @ psmsg + char ( 13 ) , ' ' ) + ' <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <EFBFBD> ' + plucode + ' <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ' + convert ( varchar ( 20 ) , convert ( numeric ( 19 , 2 ) , upcounts ) )
from ( select distinct a . billno , a . plucode , c . counts + a . dhcount - a . counts * ( 1 + ( @ optupacceptrate ) / 100 . 00 ) as upcounts
from ( select billno , plucode , sum ( counts ) as counts , sum ( dhcount ) as dhcount from t_order_body group by billno , plucode ) a ,
t_accept_head b , ( select billno , plucode , sum ( counts ) as counts from t_accept_body group by billno , plucode ) c
where a . billno = b . orderno and b . billno = c . billno and b . orderno < > ' ' and b . orderno is not null and b . billtype in ( ' 0 ' , ' 1 ' , ' 2 ' )
and a . plucode = c . plucode and b . billno = @ psbillno and ( a . counts > 0 ) and ( a . dhcount + c . counts - a . counts ) * 100 . 00 / a . counts > @ optupacceptrate ) a
if isnull ( @ psmsg , ' ' ) < > ' '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 趨<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ټ<EFBFBD> <EFBFBD> <EFBFBD> ' + char ( 13 ) + @ psmsg
return ( - 1 )
end
select @ psmsg = coalesce ( @ psmsg + char ( 13 ) , ' ' ) + ltrim ( plucode ) + ' - ' + pluname from t_accept_body d
where billno = @ psbillno and counts > 0 and cost < = 0
if isnull ( @ psmsg , ' ' ) < > ' '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϊ0<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ' + char ( 13 ) + @ psmsg
return ( - 1 )
end
select @ psmsg = coalesce ( @ psmsg + char ( 13 ) , ' ' ) + b . plucode + ' - ' + b . pluname from t_accept_body b , t_plu
where b . plucode = t_plu . plucode and b . billno = @ psbillno and b . depcode < > t_plu . depcode
if isnull ( @ psmsg , ' ' ) < > ' '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> IJ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ѿ<EFBFBD> <EFBFBD> ı 䣺' + char ( 13 ) + @ psmsg
return ( - 1 )
end
select @ psmsg = coalesce ( @ psmsg + char ( 13 ) , ' ' ) + ltrim ( plucode ) + ' - ' + pluname from t_accept_body d
where billno = @ psbillno and ( not exists ( select plucode from t_plu where plucode = d . plucode )
or not exists ( select plucode from t_plu_org where plucode = d . plucode and orgcode = @ sorgcode and isright = ' 1 ' ) )
if isnull ( @ psmsg , ' ' ) < > ' '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> Ѳ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ڻ<EFBFBD> <EFBFBD> ڻ<EFBFBD> <EFBFBD> <EFBFBD> [' + @ sorgcode + ' ]<5D> <> <EFBFBD> <EFBFBD> ӪȨ<D3AA> ޣ<EFBFBD> <DEA3> <EFBFBD> <DEB7> <EFBFBD> <EFBFBD> <EFBFBD> ' + char ( 13 ) + @ psmsg
return ( - 1 )
end
select @ psmsg = coalesce ( @ psmsg + char ( 13 ) , ' ' ) + a . plucode + ' - ' + a . pluname from t_accept_body a , t_plu_org b
where a . billno = @ psbillno and a . plucode = b . plucode and b . orgcode = @ sorgcode and b . mngstock = ' 0 '
if isnull ( @ psmsg , ' ' ) < > ' '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 棬<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ' + char ( 13 ) + @ psmsg
return ( - 1 )
end
select @ psmsg = coalesce ( @ psmsg + char ( 13 ) , ' ' ) + a . plucode + ' - ' + a . pluname from t_accept_body a , t_plu b
where a . billno = @ psbillno and a . plucode = b . plucode and b . plustatus = ' 2 '
if isnull ( @ psmsg , ' ' ) < > ' '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> Ѿ<EFBFBD> <EFBFBD> <EFBFBD> ̭<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ' + char ( 13 ) + @ psmsg
return ( - 1 )
end
set @ psmsg = ' '
return ( 1 )
end
go
if exists ( select * from sysobjects where name = ' p_rz_jh ' and xtype = ' p ' )
drop procedure p_rz_jh
go
create procedure p_rz_jh
(
@ psorgcode varchar ( 10 ) ,
@ psbillno varchar ( 20 ) ,
@ psparams varchar ( 200 ) ,
@ psmsg varchar ( 2000 ) out
)
as
begin
declare @ sorgcode varchar ( 10 )
declare @ finacode varchar ( 10 )
declare @ sameacc varchar ( 1 )
declare @ org_orgtype varchar ( 1 )
declare @ org_isdbdeploy varchar ( 1 )
declare @ org_isconfirm varchar ( 1 )
declare @ sedition varchar ( 20 )
declare @ scurver varchar ( 1 )
declare @ scurdate varchar ( 10 )
declare @ scurtime varchar ( 8 )
declare @ optplumultivendor varchar ( 10 )
declare @ optaccepttimes varchar ( 1 )
declare @ sbilltype varchar ( 1 )
declare @ acceptcounts numeric ( 19 , 4 )
declare @ splace varchar ( 1 )
declare @ bill_cost numeric ( 19 , 4 )
declare @ ssupcode varchar ( 15 )
declare @ svendorname varchar ( 100 )
declare @ ssupstatus varchar ( 1 )
declare @ ssupvaliddate varchar ( 20 )
declare @ ssupjymode varchar ( 1 )
declare @ sup_payable numeric ( 19 , 4 )
declare @ sup_prepaytotal numeric ( 19 , 4 )
declare @ sorderno varchar ( 20 )
declare @ sorderstate varchar ( 1 )
declare @ sorderbilltype varchar ( 1 )
declare @ stock_plutype varchar ( 1 )
declare @ detail_cost numeric ( 19 , 4 )
declare @ detail_netcost numeric ( 19 , 4 )
declare @ detail_total numeric ( 19 , 4 )
declare @ detail_jprice numeric ( 19 , 4 )
declare @ detail_netjprice numeric ( 19 , 4 )
declare @ detail_count numeric ( 19 , 4 )
declare @ detail_givecount numeric ( 19 , 4 )
declare @ detail_plucode varchar ( 20 )
declare @ detail_depcode varchar ( 10 )
declare @ detail_depname varchar ( 16 )
declare @ detail_price numeric ( 19 , 4 )
declare @ detail_jtaxrate numeric ( 19 , 4 )
declare @ detail_cgcount numeric ( 19 , 4 )
declare @ detail_counts numeric ( 19 , 4 )
declare @ detail_zpamount numeric ( 19 , 4 )
declare @ detail_zpnetamount numeric ( 19 , 4 )
declare @ detail_pluname varchar ( 40 )
declare @ fscost numeric ( 19 , 4 )
declare @ fsnetcost numeric ( 19 , 4 )
declare @ fstotal numeric ( 19 , 4 )
declare @ jccost numeric ( 19 , 4 )
declare @ jcnetcost numeric ( 19 , 4 )
declare @ jynetcost numeric ( 19 , 4 )
declare @ differnetcost numeric ( 19 , 4 )
declare @ sisneedadjnetcost varchar ( 1 )
declare @ jctotal numeric ( 19 , 4 )
declare @ jccount numeric ( 19 , 4 )
declare @ ssql varchar ( 2000 )
declare @ svbktablename varchar ( 20 )
declare @ spsacceptuptjprice varchar ( 20 )
declare @ sbranchno varchar ( 10 )
declare @ detailcs_plucode varchar ( 20 )
declare @ detailcs_colorcode varchar ( 10 )
declare @ detailcs_sizecode varchar ( 10 )
declare @ detailcs_cgcount numeric ( 19 , 4 )
declare @ detailcs_ccounts numeric ( 19 , 4 )
declare @ stateflg int
declare @ sisprntask varchar ( 1 )
declare @ sbatchprocbillno varchar ( 20 )
declare @ srefpsbillno varchar ( 20 )
declare @ scybillno varchar ( 20 )
declare @ sPjhNoDiffer varchar ( 1 )
declare @ vi_cnt int
set @ spsacceptuptjprice = null
set @ ssupjymode = ' '
set @ sisprntask = isnull ( @ psparams , ' 0 ' )
select @ spsacceptuptjprice = itemvalue from t_syscfg where section = ' SYSTEM ' and itemname = ' PsAcceptUptJPrice '
select @ optplumultivendor = itemvalue from t_syscfg where section = ' SYSTEM ' and itemname = ' PluMultiVendor '
set @ spsacceptuptjprice = isnull ( @ spsacceptuptjprice , ' FALSE ' )
select @ sedition = itemvalue from t_syscfg where section = ' SYSTEM ' and itemname = ' Edition '
select @ sorgcode = orgcode , @ sbilltype = billtype , @ ssupcode = supcode , @ svendorname = supname , @ sorderno = orderno , @ splace = place from t_accept_head where billno = @ psbillno
select @ org_orgtype = orgtype , @ org_isdbdeploy = isdbdeploy , @ org_isconfirm = isconfirm , @ finacode = isnull ( finacode , ' ' ) from t_shop where orgcode = @ sorgcode
select @ sorderbilltype = billtype from t_order_head where billno = @ sorderno
select @ scurver = itemvalue from t_syscfg where section = ' SYSTEM ' and itemname = ' VER '
select @ scurdate = convert ( varchar ( 100 ) , getdate ( ) , 23 ) , @ scurtime = convert ( varchar ( 100 ) , getdate ( ) , 108 )
select @ sbranchno = itemvalue from t_syscfg where section = ' SYSTEM ' and itemname = ' BranchNo '
select @ optaccepttimes = accepttimes from t_shop where orgcode = @ psorgcode
select @ sPjhNoDiffer = isnull ( itemvalue , ' 0 ' ) from t_syscfg where itemname = ' PjhNoDiffer ' and section = ' SYSTEM '
if @ sbilltype = ' 2 '
begin
exec p_get_finacode ' C009 ' , @ sorgcode , @ finacode out , @ sameacc out , @ psmsg out
if @ psmsg < > ' '
begin
return ( - 1 )
end
end
set @ scybillno = ' '
if @ sbilltype < > ' 3 '
begin
select @ acceptcounts = sum ( counts ) + sum ( givecount ) from t_accept_body where billno = @ psbillno
if @ acceptcounts = 0
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 0'
return ( - 1 )
end
delete from t_accept_body where billno = @ psbillno and counts = 0 and givecount = 0
delete from t_accept_cs_body where billno = @ psbillno and ccounts = 0
end
update b set b . price = g . price , b . total = case when o . plutype = ' 2 ' then 0 else round ( g . price * ( b . counts + b . givecount ) , 2 ) end ,
b . jxprice = case when o . plutype = ' 2 ' then 0 else round ( g . price * ( b . counts + b . givecount ) , 2 ) - b . cost end
from t_accept_body b , t_plu_org g , t_plu o
where b . billno = @ psbillno and b . plucode = g . plucode and b . plucode = o . plucode and b . price < > g . price and g . orgcode = @ sorgcode and g . isright = ' 1 '
update h set h . total = b . total , rzdate = @ scurdate , rztime = @ scurtime
from t_accept_head h , ( select isnull ( sum ( total ) , 0 ) as total from t_accept_body where billno = @ psbillno ) b
where billno = @ psbillno
if @ sbilltype < > ' 3 '
begin
select @ ssupstatus = supstatus , @ ssupvaliddate = validdate , @ ssupjymode = jymode from t_supplier where supcode = @ ssupcode
if @ @ rowcount = 0
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <EFBFBD> [' + @ ssupcode + ' ]<5D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> '
return ( - 1 )
end
else if @ ssupstatus < > ' 0 '
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <EFBFBD> [' + @ ssupcode + ' ]״̬<D7B4> <CCAC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> '
return ( - 1 )
end
else if isnull ( @ ssupvaliddate , ' ' ) < > ' ' and @ ssupvaliddate < @ scurdate
begin
set @ psmsg = ' <EFBFBD> <EFBFBD> Ӧ<EFBFBD> <EFBFBD> [' + @ ssupcode + ' ]<5D> ѹ<EFBFBD> <D1B9> <EFBFBD> Ч<EFBFBD> <D0A7> <EFBFBD> <EFBFBD> '
return ( - 1 )
end
end
if ( ( @ sbilltype = ' 1 ' ) or ( @ sbilltype = ' 2 ' ) ) and ( isnull ( @ sorderno , ' ' ) < > ' ' )
begin
select @ sorderstate = state from t_order_head where billno = @ sorderno
if @ @ rowcount < > 0
begin
if @ sorderstate < > ' 1 '
begin
select @ psmsg = coalesce ( @ psmsg + char ( 13 ) , ' ' ) + ' [ ' + billno + ' ] ' from t_accept_head
where rzdate < > ' ' and rzdate is not null and orderno = @ sorderno and billno < > @ psbillno order by billno
if isnull ( @ psmsg , ' ' ) = ' '
set @ psmsg = ' <EFBFBD> ɹ<EFBFBD> <EFBFBD> <EFBFBD> [' + @ sorderno + ' ]״̬<D7B4> <CCAC> <EFBFBD> ǡ<EFBFBD> ִ<EFBFBD> <D6B4> <EFBFBD> С <EFBFBD> '
else
set @ psmsg = ' <EFBFBD> ɹ<EFBFBD> <EFBFBD> <EFBFBD> [' + @ sorderno + ' ]<5D> Ѿ<EFBFBD> <D1BE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɣ <EFBFBD> <C9A3> <EFBFBD> <EFBFBD> յ<EFBFBD> <D5B5> <EFBFBD> Ϊ ' + char ( 13 ) + @ psmsg
return ( - 1 )
end
end
end
set @ svbktablename = ' t_vbk_ ' + substring ( convert ( varchar ( 100 ) , getdate ( ) , 112 ) , 1 , 6 )
exec p_create_vbk @ svbktablename , @ psmsg out
if isnull ( @ psmsg , ' ' ) < > ' '
begin
return ( - 1 )
end
update aid set hjprice = case when b . hjprice > aid . hjprice then b . hjprice else aid . hjprice end ,
ljprice = case when b . ljprice < aid . ljprice then b . ljprice else aid . ljprice end
- - 2023 - 12 - 12 <EFBFBD> <EFBFBD> <EFBFBD> ղ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ½ <EFBFBD> <EFBFBD> <EFBFBD>
- - ojprice = case when @ sbilltype < > ' 3 ' then aid . ojprice when ( @ sbilltype = ' 3 ' ) and ( @ spsacceptuptjprice = ' true ' ) then b . hjprice else aid . ojprice end
from t_plu_org aid , ( select plucode , max ( jprice ) hjprice , min ( jprice ) ljprice from t_accept_body where billno = @ psbillno and jprice < > 0 and isdscjprice = ' 0 ' group by plucode ) b
where aid . plucode = b . plucode and aid . orgcode = @ sorgcode and aid . isright = ' 1 '
insert into t_plu_org ( plucode , orgcode , isright , jprice , netjprice , price , vipprice , pfprice )
select b . plucode , @ sorgcode , ' 1 ' , b . jprice , b . netjprice , b . price , b . vipprice , b . pfprice
from t_accept_body a left join t_plu b on a . plucode = b . plucode
left join t_plu_org c on a . plucode = c . plucode and c . orgcode = @ sorgcode and isright = ' 1 '
where a . billno = @ psbillno and not b . plucode is null and c . plucode is null
set @ ssql = ' select plucode,pluname,depcode,depname,price,jtaxrate,cgcount,counts,givecount,
case when ( ' '' +@sbilltype+ '' ' = ' ' 3 ' ' and ' '' +@sorderno+ '' ' < > ' '' ' and ' '' +@sPjhNoDiffer+ '' ' = ' ' 0 ' ' ) then round ( cgcount * jprice , 2 ) else cost end as fscost ,
case when ( ' '' +@sbilltype+ '' ' = ' ' 3 ' ' and ' '' +@sorderno+ '' ' < > ' '' ' and ' '' +@sPjhNoDiffer+ '' ' = ' ' 0 ' ' ) then round ( cgcount * netjprice , 2 ) else netcost end as fsnetcost ,
case when ( ' '' +@sbilltype+ '' ' = ' ' 3 ' ' and ' '' +@sorderno+ '' ' < > ' '' ' and ' '' +@sPjhNoDiffer+ '' ' = ' ' 0 ' ' ) then round ( cgcount * price , 2 ) else total end as fstotal ,
case when ( ' '' +@sbilltype+ '' ' = ' ' 3 ' ' and ' '' +@sorderno+ '' ' < > ' '' ' and ' '' +@sPjhNoDiffer+ '' ' = ' ' 0 ' ' ) then cgcount else counts end counts ,
case when ( ' '' +@sbilltype+ '' ' = ' ' 3 ' ' and ' '' +@sorderno+ '' ' < > ' '' ' and ' '' +@sPjhNoDiffer+ '' ' = ' ' 0 ' ' ) then round ( cgcount * jprice , 2 ) else cost end as cost ,
case when ( ' '' +@sbilltype+ '' ' = ' ' 3 ' ' and ' '' +@sorderno+ '' ' < > ' '' ' and ' '' +@sPjhNoDiffer+ '' ' = ' ' 0 ' ' ) then round ( cgcount * netjprice , 2 ) else netcost end as netcost ,
jprice , netjprice from t_accept_body where billno = ' '' +@psbillno+ '' ''
if @ sbilltype < > ' 3 '
begin
set @ ssql = @ ssql + ' and counts+givecount<>0 '
end
exec ( ' declare cur cursor for ' + @ ssql )
open cur
fetch next from cur into @ detail_plucode , @ detail_pluname , @ detail_depcode , @ detail_depname , @ detail_price , @ detail_jtaxrate , @ detail_cgcount , @ detail_counts , @ detail_givecount , @ fscost , @ fsnetcost , @ fstotal , @ detail_count , @ detail_cost , @ detail_netcost , @ detail_jprice , @ detail_netjprice
while @ @ fetch_status = 0
begin
update a set gcount = case when @ splace = ' 0 ' then gcount + @ detail_count + @ detail_givecount else gcount end ,
ccount = case when @ splace = ' 1 ' then ccount + @ detail_count + @ detail_givecount else ccount end ,
newjhdate = case when not ( b . plutype = ' 0 ' and @ detail_jprice = 0 ) then @ scurdate else newjhdate end ,
yjdate = case when not ( b . plutype = ' 0 ' and @ detail_jprice = 0 ) then case when isnull ( yjdate , ' ' ) = ' ' then @ scurdate else yjdate end else yjdate end ,
jprice = case when gcount + ccount > = 0 and tzamount = 0 then round ( ( cost + @ detail_cost ) / ( gcount + ccount + @ detail_count + @ detail_givecount ) , 4 ) when gcount + ccount > = 0 and tzamount < 0 and tzamount + @ detail_cost < 0 then round ( cost / ( gcount + ccount + @ detail_count + @ detail_givecount ) , 4 ) when gcount + ccount < 0 then @ detail_jprice else round ( ( cost + @ detail_cost + tzamount ) / ( gcount + ccount + @ detail_count + @ detail_givecount ) , 4 ) end ,
netjprice = case when gcount + ccount > = 0 and tzamount = 0 then round ( ( netcost + @ detail_netcost ) / ( gcount + ccount + @ detail_count + @ detail_givecount ) , 4 ) when gcount + ccount > = 0 and tzamount < 0 and tzamount + @ detail_cost < 0 then round ( netcost / ( gcount + ccount + @ detail_count + @ detail_givecount ) , 4 ) when gcount + ccount < 0 then @ detail_netjprice else round ( ( netcost + @ detail_netcost + round ( tzamount / ( 1 + @ detail_jtaxrate / 100 . 00 ) , 2 ) ) / ( gcount + ccount + @ detail_count + @ detail_givecount ) , 4 ) end ,
tzamount = case when gcount + ccount > = 0 and tzamount < 0 and tzamount + @ detail_cost < 0 then tzamount + @ detail_cost when gcount + ccount < 0 then tzamount + cost + @ detail_cost - round ( @ detail_jprice * ( gcount + ccount + @ detail_count ) , 2 ) else 0 end ,
cost = case when gcount + ccount > = 0 and tzamount = 0 then cost + @ detail_cost when gcount + ccount > = 0 and tzamount < 0 and tzamount + @ detail_cost < 0 then cost when gcount + ccount < 0 then round ( @ detail_jprice * ( gcount + ccount + @ detail_count ) , 2 ) else cost + @ detail_cost + tzamount end ,
netcost = case when gcount + ccount > = 0 and tzamount = 0 then netcost + @ detail_netcost when gcount + ccount > = 0 and tzamount < 0 and tzamount + @ detail_cost < 0 then netcost when gcount + ccount < 0 then round ( round ( @ detail_jprice * ( gcount + ccount + @ detail_count ) , 2 ) / ( 1 + @ detail_jtaxrate / 100 . 00 ) , 2 ) else netcost + @ detail_netcost + round ( tzamount / ( 1 + @ detail_jtaxrate / 100 . 00 ) , 2 ) end ,
total = case when b . plutype = ' 2 ' then 0 else isnull ( a . total , 0 . 00 ) + round ( a . price * ( @ detail_count + @ detail_givecount ) , 2 ) end ,
@ stock_plutype = b . plutype ,
@ fstotal = case when b . plutype = ' 2 ' then 0 else @ fstotal end ,
@ jccount = gcount + ccount + @ detail_count + @ detail_givecount ,
@ jccost = case when gcount + ccount > = 0 then cost + @ detail_cost else round ( @ detail_jprice * ( gcount + ccount + @ detail_count ) , 2 ) end + case when gcount + ccount > = 0 then tzamount else tzamount + cost + @ detail_cost - round ( @ detail_jprice * ( gcount + ccount + @ detail_count ) , 2 ) end ,
@ jcnetcost = case when gcount + ccount > = 0 then netcost + @ detail_netcost else round ( @ detail_netjprice * ( gcount + ccount + @ detail_count ) , 2 ) end + round ( ( case when gcount + ccount > = 0 then tzamount else tzamount + cost + @ detail_cost - round ( @ detail_jprice * ( gcount + ccount + @ detail_count ) , 2 ) end ) / ( 1 + @ detail_jtaxrate / 100 . 00 ) , 2 ) ,
@ jynetcost = case when gcount + ccount > = 0 then 0 else netcost + @ detail_netcost + round ( tzamount / ( 1 + @ detail_jtaxrate / 100 . 00 ) , 2 ) end ,
@ sisneedadjnetcost = case when gcount + ccount > = 0 then ' 0 ' else ' 1 ' end ,
@ jctotal = case when b . plutype = ' 2 ' then 0 else isnull ( a . total , 0 . 00 ) + round ( a . price * ( @ detail_count + @ detail_givecount ) , 2 ) end
from t_plu_org a , t_plu b
where a . plucode = b . plucode and a . orgcode = @ sorgcode and a . plucode = @ detail_plucode and isright = ' 1 '
if ( @ sisneedadjnetcost = ' 1 ' ) and ( ( @ jynetcost - @ jcnetcost ) < > 0 )
begin
set @ differnetcost = @ jynetcost - @ jcnetcost
set @ jcnetcost = @ jynetcost
update t_plu_org set netcost = netcost + @ differnetcost where plucode = @ detail_plucode and orgcode = @ sorgcode
end
if exists ( select plucode from t_plu where plucode = @ detail_plucode and iszfcode = ' 1 ' )
begin
insert into t_plu_org ( plucode , orgcode , isright , jprice , netjprice , price , vipprice , pfprice )
select a . plucode , @ sorgcode , ' 1 ' , b . jprice , b . netjprice , b . price , b . vipprice , b . pfprice
from t_plu_org b , ( select plucode , innercode from t_plu where iszfcode = ' 2 ' and innercode = @ detail_plucode ) a
where b . plucode = a . innercode and b . orgcode = @ sorgcode and b . plucode = @ detail_plucode
and not exists ( select plucode from t_plu_org where orgcode = @ sorgcode and plucode = a . plucode )
update a set jprice = b . jprice , netjprice = b . netjprice from t_plu_org a ,
( select plucode , jprice , netjprice , orgcode from t_plu_org where plucode = @ detail_plucode and orgcode = @ sorgcode ) b ,
( select plucode , innercode from t_plu where iszfcode = ' 2 ' ) c
where a . plucode = c . plucode and b . plucode = c . innercode and a . orgcode = b . orgcode
end
declare @ tmpcounts numeric ( 19 , 4 )
set @ tmpcounts = @ detail_count + @ detail_givecount
if @ tmpcounts < > 0
begin
set @ detail_jprice = round ( @ fscost / @ tmpcounts , 4 )
set @ detail_netjprice = round ( @ fsnetcost / @ tmpcounts , 4 )
end
exec p_create_gbk_data @ scurdate , @ scurtime , @ detail_plucode , @ detail_depcode , @ psbillno , ' 0 ' , @ detail_jprice , @ detail_netjprice , @ detail_price ,
@ tmpcounts , @ fscost , @ fsnetcost , @ fstotal , @ jccount , @ jccost , @ jcnetcost , @ jctotal , @ sorgcode , ' ' , ' ' , @ psmsg
if @ sbilltype = ' 3 ' and @ sorderno < > ' '
-- 2023-12-29 14<31> <34> 38<33> <38> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϊ0<CEAA> <30> <EFBFBD> <EFBFBD> Ʒ Ҳ<C6B7> <D2B2> Ҫ<EFBFBD> <D2AA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ͳ<EFBFBD> <CDB2> 쵥
-- and ((@stock_plutype<>'2' and @detail_jprice<>0) or @stock_plutype='2')
begin
if @ detail_cgcount < > @ detail_counts
begin
if @ scybillno = ' '
begin
exec f_get_billno ' cy ' , @ sorgcode , ' 1 ' , @ scybillno output
end
set @ detail_zpamount = 0 . 00
set @ detail_zpnetamount = 0 . 00
select @ detail_zpamount = zpamount , @ detail_zpnetamount = zpnetamount from t_dist_body where billno = @ sorderno and PluCode = @ detail_plucode
if not exists ( select * from t_distdiffer_body where billno = @ scybillno and plucode = @ detail_plucode )
insert into t_distdiffer_body ( billno , supcode , plucode , pluname , jprice , netjprice , counts , differcount , differcost , differnetcost , remark , differmode , depcode , depname )
values ( @ scybillno , @ ssupcode , @ detail_plucode , @ detail_pluname , @ detail_jprice , @ detail_netjprice , @ detail_cgcount ,
@ detail_counts - @ detail_cgcount , - round ( @ detail_zpamount - @ fscost , 2 ) , - round ( @ detail_zpnetamount - @ fsnetcost , 2 ) ,
' <EFBFBD> <EFBFBD> <EFBFBD> Ͳ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ' , ' 0 ' , @ detail_depcode , @ detail_depname )
else
update t_distdiffer_body
set counts = counts + @ detail_cgcount , differcount = differcount + @ detail_counts - @ detail_cgcount ,
differcost = differcost - round ( @ detail_zpamount - @ fscost , 2 ) ,
differnetcost = differnetcost - round ( @ detail_zpnetamount - @ fsnetcost , 2 )
where billno = @ scybillno and plucode = @ detail_plucode
end
else
begin
set @ stateflg = 0
declare cur2 cursor for select d . plucode , colorcode , sizecode , ccounts , cgcount
from t_accept_cs_body d , t_plu g where billno = @ psbillno and g . plucode = d . plucode and g . plutype < > ' 2 ' and ccounts < > cgcount order by d . plucode , colorcode , sizecode
open cur2
fetch next from cur2 into @ detailcs_plucode , @ detailcs_colorcode , @ detailcs_sizecode , @ detailcs_ccounts , @ detailcs_cgcount
while @ @ fetch_status = 0
begin
if @ stateflg = 1
break
set @ stateflg = 1
if not exists ( select * from t_dist_differ where billno = @ psbillno and orgcode = @ sorgcode and plucode = @ detail_plucode )
insert into t_dist_differ ( billno , orgcode , differtype , supcode , oldbillno , plucode , bizdate , pluname , jprice , netjprice , counts , differcount , remark , differmode )
values ( @ psbillno , @ sorgcode , ' 0 ' , @ ssupcode , @ sorderno , @ detail_plucode , @ scurdate , @ detail_pluname , @ detail_jprice , @ detail_netjprice , @ detail_cgcount , @ detail_counts - @ detail_cgcount , ' ' , ' ' )
else
update t_dist_differ set counts = counts + @ detail_cgcount , differcount = differcount + @ detail_counts - @ detail_cgcount
where billno = @ psbillno and orgcode = @ sorgcode and plucode = @ detail_plucode
fetch next from cur2 into @ detailcs_plucode , @ detailcs_colorcode , @ detailcs_sizecode , @ detailcs_ccounts , @ detailcs_cgcount
end
close cur2
deallocate cur2
end
end
fetch next from cur into @ detail_plucode , @ detail_pluname , @ detail_depcode , @ detail_depname , @ detail_price , @ detail_jtaxrate , @ detail_cgcount , @ detail_counts , @ detail_givecount , @ fscost , @ fsnetcost , @ fstotal , @ detail_count , @ detail_cost , @ detail_netcost , @ detail_jprice , @ detail_netjprice
end
close cur
deallocate cur
if @ scybillno < > ' '
begin
insert into t_distdiffer_head
( billno , ywbillNo , orgcode , bizdate , differtype , contrno , differcount , differcost , differnetcost , lrdate , lrtime , rzdate , rztime ,
accdate , usercode , username , zdrcode , zdrname , shrcode , shrname , chkstatus , depcode , depname , remark
)
select
@ scybillno -- billno - varchar(20)
, @ psbillno -- ywbillNo - varchar(20)
, @ sorgcode -- orgcode - varchar(10)
, @ scurdate -- bizdate - varchar(10)
, ' 0 ' -- differtype - varchar(1)
, ' ' -- contrno - varchar(40)
, 0 -- differcount - numeric(19, 4)
, 0 -- differcost - numeric(19, 4)
, 0 -- differnetcost - numeric(19, 4)
, @ scurdate -- lrdate - varchar(10)
, @ scurtime -- lrtime - varchar(8)
, ' ' -- rzdate - varchar(10)
, ' ' -- rztime - varchar(8)
, ' ' -- accdate - varchar(10)
, usercode -- usercode - varchar(6)
, username -- username - varchar(10)
, zdrcode -- zdrcode - varchar(6)
, zdrname -- zdrname - varchar(10)
, ' ' -- shrcode - varchar(6)
, ' ' -- shrname - varchar(10)
, ' 9 ' -- chkstatus - varchar(1)
, depcode -- depcode - varchar(10)
, depname -- depname - varchar(16)
, ' ' -- remark - varchar(200)
from t_accept_head where billno = @ psbillno
--
update a
set differcount = b . differcount ,
differcost = b . differcost ,
differnetcost = b . differnetcost
from t_distdiffer_head a , ( select sum ( differcount ) differcount , sum ( differcost ) differcost , sum ( differnetcost ) differnetcost
from t_distdiffer_body where billno = @ scybillno ) b
where a . billno = @ scybillno
update t_dist_head
set differstate = ' 1 '
where billno = @ sorderno
end
if @ sedition = ' 4 '
begin
insert into t_plu_org_cs ( plucode , orgcode , colorcode , sizecode , csbarcode , gcount , ccount , remark )
select distinct a . plucode as plucode , @ sorgcode as orgcode , a . colorcode as colorcode , a . sizecode as sizecode , g . csbarcode as csbarcode , 0 as gcount , 0 as ccount , ' ' as remark
from t_accept_cs_body a , t_plu_cs g where a . plucode = g . plucode and a . colorcode = g . colorcode and a . sizecode = g . sizecode and a . billno = @ psbillno
and not exists ( select plucode from t_plu_org_cs o where o . plucode = a . plucode and o . colorcode = a . colorcode and o . sizecode = a . sizecode and o . orgcode = @ sorgcode )
update a set a . gcount = case when @ splace = ' 0 ' then a . gcount + b . ccounts else a . gcount end ,
a . ccount = case when @ splace = ' 0 ' then a . ccount else a . ccount + b . ccounts end
from t_plu_org_cs a , ( select plucode , colorcode , sizecode , sum ( ccounts ) as ccounts from t_accept_cs_body where billno = @ psbillno group by plucode , colorcode , sizecode ) b
where a . plucode = b . plucode and a . orgcode = @ sorgcode and a . colorcode = b . colorcode and a . sizecode = b . sizecode
if @ sbilltype = ' 3 ' and @ sorderno < > ' '
begin
declare cur cursor for select d . plucode , colorcode , sizecode , ccounts , cgcount from t_accept_cs_body d , t_plu g
where billno = @ psbillno and g . plucode = d . plucode and g . plutype < > ' 2 ' and ccounts < > cgcount order by d . plucode , colorcode , sizecode
open cur
fetch next from cur into @ detailcs_plucode , @ detailcs_colorcode , @ detailcs_sizecode , @ detailcs_ccounts , @ detailcs_cgcount
while @ @ fetch_status = 0
begin
if not exists ( select * from t_dist_differ_cs where billno = @ psbillno and orgcode = @ sorgcode and plucode = @ detailcs_plucode and colorcode = @ detailcs_colorcode and sizecode = @ detailcs_sizecode )
insert into t_dist_differ_cs ( billno , orgcode , plucode , colorcode , sizecode , ccounts , counts , remark )
values ( @ psbillno , @ sorgcode , @ detailcs_plucode , @ detailcs_colorcode , @ detailcs_sizecode , @ detailcs_ccounts - @ detailcs_cgcount , @ detailcs_cgcount , ' ' )
else
update t_dist_differ_cs set ccounts = ccounts + @ detailcs_ccounts - @ detailcs_cgcount , counts = counts + @ detailcs_cgcount
where billno = @ psbillno and orgcode = @ sorgcode and plucode = @ detailcs_plucode and colorcode = @ detailcs_colorcode and sizecode = @ detailcs_sizecode
fetch next from cur into @ detailcs_plucode , @ detailcs_colorcode , @ detailcs_sizecode , @ detailcs_ccounts , @ detailcs_cgcount
end
close cur
deallocate cur
end
end
if @ sbilltype = ' 3 ' and @ sorderno < > ' ' and @ sPjhNoDiffer = ' 0 '
begin
update b set counts = cgcount , punit = ' ' , pcount = 0 , itemcnt = 0 , sglcount = cgcount , b . cost = round ( cgcount * b . jprice , 2 ) , b . netcost = round ( cgcount * b . netjprice , 2 ) ,
b . total = case when plutype = ' 2 ' then 0 else round ( cgcount * b . price , 2 ) end , jxprice = case when c . plutype = ' 2 ' then 0 else round ( cgcount * ( b . price - b . jprice ) , 2 ) end
from t_accept_head a , t_accept_body b , t_plu c
where a . billno = b . billno and b . plucode = c . plucode and a . billno = @ psbillno and billtype = ' 3 ' and b . counts < > b . cgcount
end
if ( @ ssupjymode < > ' 2 ' or @ sbilltype = ' 3 ' ) and ( @ optplumultivendor = ' TRUE ' )
begin
insert into t_supaccept_detail ( billtype , billno , serialno , plucode , pluname , orgcode , orgname , supcode , supname , rzdate , rztime , jprice , netjprice , price , counts , cost , netcost , total , remark )
select ' 0 ' , billno , serialno , plucode , pluname , @ sorgcode , ( select top 1 orgname from t_shop where orgcode = @ sorgcode ) as orgname ,
@ ssupcode , @ svendorname , @ scurdate , @ scurtime , jprice , netjprice , price , counts + givecount , cost , netcost , total , remark
from t_accept_body where billno = @ psbillno
end
- - if ( @ ssupjymode < > ' 2 ' or @ sbilltype = ' 3 ' ) - - and ( @ optplumultivendor = ' TRUE ' )
- - begin
-- if @sbilltype<>'3'
-- begin
-- insert into t_plu_batch(orgcode,depcode,supcode,jymode,contrno,batchtype,billno,serialno,place,plucode,plutype,
-- batchno,srcbatchno,stkcount,jtaxrate,jprice,netjprice,cost,netcost,punit,itemcnt,productdate,jhdate,jhcount)
-- select h.orgcode,b.depcode,h.supcode,@ssupjymode,h.contrno,'0',h.billno,b.serialno,h.place,b.plucode,'0',
-- dbo.f_getstockpcno(h.billno,'0',row_number()over(order by b.plucode,b.serialno)),
-- dbo.f_getstockpcno(h.billno,'0',row_number()over(order by b.plucode,b.serialno)),
-- b.counts+b.givecount,b.jtaxrate,b.jprice,b.netjprice,b.cost,b.netcost,b.punit,b.itemcnt,
-- b.productdate,getdate(),b.counts+b.givecount
-- from t_accept_head h, t_accept_body b where h.billno=b.billno and h.billno=@psbillno
-- end
-- else
-- begin
-- select @srefpsbillno=substring(remark,1,charindex('|',remark,0)-1)
-- from t_accept_head where billno=@psbillno
-- if isnull(@srefpsbillno,'')=''
-- begin
-- set @psmsg='<27> Ҳ<EFBFBD> <D2B2> <EFBFBD> ԭʼ <D4AD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͵<EFBFBD> <CDB5> ţ<EFBFBD> <C5A3> <EFBFBD> <DEB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ο <EFBFBD> <CEBF> <EFBFBD> '
-- return(-1)
-- end
-- select @vi_cnt=count(*)
-- from t_batchproc_head
-- where ywbillno=@srefpsbillno
-- if @vi_cnt=0
-- begin
-- set @psmsg='<27> Ҳ<EFBFBD> <D2B2> <EFBFBD> ԭʼ <D4AD> <CABC> <EFBFBD> Ϳ <EFBFBD> <CDBF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ˵<EFBFBD> <CBB5> <EFBFBD> <EFBFBD> <EFBFBD> <DEB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ο <EFBFBD> <CEBF> <EFBFBD> '
-- return(-1)
-- end
-- insert into t_plu_batch(orgcode,depcode,supcode,jymode,contrno,batchtype,billno,serialno,place,plucode,plutype,
-- batchno,srcbatchno,stkcount,jtaxrate,jprice,netjprice,cost,netcost,punit,itemcnt,productdate,jhdate,jhcount)
-- select c.orgcode,d.depcode,c.supcode,'0','','0',c.billno,d.serialno,'0',d.plucode,b.plutype,
-- dbo.f_getstockpcno(c.billno,'0',b.serialno),b.srcbatchno,b.proccount,d.jtaxrate,d.jprice,d.netjprice,
-- round(d.cost*(b.proccount/d.counts),2),round(d.netcost*(b.proccount/d.counts),2),
-- d.punit,d.itemcnt,d.productdate,getdate(),b.proccount
-- from t_batchproc_head a,t_batchproc_body b,t_accept_head c,t_accept_body d
-- where a.billno=b.billno and a.ywbillno=@srefpsbillno and c.billno=@psbillno
-- and d.billno=c.billno and d.serialno=b.refserialno and d.plucode=b.plucode
-- end
-- exec f_get_billno 'pc',@psorgcode,'1',@sbatchprocbillno output
-- insert into t_batchproc_head(billno,billtype,ywtype,ywbillno,procdate,orgcode,place,proccount,cost,netcost,usercode,username,tag)
-- select @sbatchprocbillno,'0',case h.billtype when '0' then 'NJH' when '1' then 'JH' when '2' then 'ZJH' when '3' then 'PJH' end as billtype,
-- h.billno,getdate(),h.orgcode,h.place,(h.counts+h.givecount),h.cost,h.netcost,h.usercode,h.username,'0'
-- from t_accept_head h where h.billno=@psbillno
-- insert into t_batchproc_body(billno,serialno,depcode,supcode,plucode,pluname,spec,unit,plutype,batchno,srcbatchno,
-- contrno,jymode,proccount,jprice,netjprice,cost,netcost,refserialno,itemcnt)
-- select @sbatchprocbillno,row_number()over(order by s.serialno) as serialno,s.depcode,s.supcode,b.plucode,b.pluname,
-- b.spec,b.unit,s.plutype,s.batchno,s.srcbatchno,s.contrno,s.jymode,s.stkcount,s.jprice,s.netjprice,s.cost,s.netcost,b.serialno,b.itemcnt
-- from t_accept_body b,t_plu_batch s
-- where b.billno=s.billno and b.serialno=s.serialno and b.plucode=s.plucode and b.billno=@psbillno
- - end
update a set counts = b . counts , givecount = b . givecount , cost = b . cost , netcost = b . netcost , total = b . total
from t_accept_head a , ( select sum ( c . counts ) as counts , sum ( c . givecount ) as givecount , sum ( c . cost ) as cost , sum ( c . netcost ) as netcost , sum ( c . total ) as total from t_accept_body c where c . billno = @ psbillno ) b
where a . billno = @ psbillno
update a set jhtotal = jhtotal + b . cost , @ bill_cost = b . cost
from t_supplier a , t_accept_head b where a . supcode = @ ssupcode and a . supcode = b . supcode and b . billno = @ psbillno
select @ sup_payable = jhtotal - thtotal + tjtotal , @ sup_prepaytotal = prepay from t_supplier where supcode = @ ssupcode
set @ ssql = ' insert into t_vbk_ ' + substring ( convert ( varchar ( 100 ) , getdate ( ) , 112 ) , 1 , 6 ) + ' (orgcode,bookdate,booktime,supcode ,billno,billtype,fsamount,yfjytotal,prejytotal) '
+ ' values( '' ' + @ sorgcode + ' '' , '' ' + @ scurdate + ' '' , '' ' + @ scurtime + ' '' , '' ' + @ ssupcode + ' '' , '' ' + @ psbillno + ' '' , '' 0 '' , ' + convert ( varchar ( 20 ) , @ bill_cost ) + ' , ' + convert ( varchar ( 20 ) , @ sup_payable ) + ' , ' + convert ( varchar ( 20 ) , @ sup_prepaytotal ) + ' ) '
exec ( @ ssql )
if @ scurver = ' 1 ' and @ sbilltype = ' 3 ' and @ org_orgtype < > ' 2 ' and @ org_isdbdeploy = ' 1 ' and @ org_isconfirm = ' 0 '
begin
update t_accept_head set qrdate = @ scurdate where billno = @ psbillno
end
if @ scurver = ' 1 ' and @ sbilltype = ' 3 ' and @ org_orgtype < > ' 2 ' and @ org_isdbdeploy = ' 1 '
begin
update t_dist_head set diststate = ' 3 ' where billno = @ sorderno
end
if @ ssupjymode < > ' 2 ' and @ sbilltype < > ' 3 '
begin
insert into t_pay_bill ( orgcode , billtype , billno , bizdate , supcode , sqauremode , cost , paydate , jscost , zrcost , isfinished , total , contrno , finacode )
select orgcode , case when @ scurver = ' 1 ' and billtype = ' 2 ' then ' 3 ' else ' 0 ' end ,
billno , bizdate , supcode , sqauremode , cost , paydate , 0 , 0 , case when cost = 0 then ' 1 ' else ' 0 ' end , total , contrno , @ finacode
from t_accept_head where billno = @ psbillno
end
if @ sorderno < > ' ' and @ sorderbilltype = ' 0 ' and ( @ sbilltype = ' 0 ' or @ sbilltype = ' 1 ' or @ sbilltype = ' 2 ' )
begin
if @ sedition = ' 4 '
begin
update o set o . dhcount = o . dhcount + j . ccounts
from t_order_cs_body o , t_accept_cs_body j
where o . billno = @ sorderno and j . billno = @ psbillno and o . plucode = j . plucode
and o . serialno = j . serialno and o . colorcode = j . colorcode and o . sizecode = j . sizecode
end
update o set o . dhcount = o . dhcount + j . counts , o . dhcost = o . dhcost + j . cost , o . dhnetcost = o . dhnetcost + j . netcost
from t_order_body o , t_accept_body j
where o . billno = @ sorderno and j . billno = @ psbillno and o . plucode = j . plucode and o . serialno = j . serialno
update h set h . dhcount = b . dhcount , h . dhcost = b . dhcost , h . dhnetcost = b . dhnetcost
from t_order_head h , ( select sum ( dhcost ) as dhcost , sum ( dhcount ) as dhcount , sum ( dhnetcost ) as dhnetcost from t_order_body where billno = @ sorderno ) b
where h . billno = @ sorderno
if exists ( select plucode from t_order_body where dhcount < counts and billno = @ sorderno )
update t_order_head set goodsstate = ' 1 ' where billno = @ sorderno
else
update t_order_head set goodsstate = ' 2 ' , state = ' 2 ' where billno = @ sorderno
if @ optaccepttimes = ' 0 '
update t_order_head set state = ' 2 ' where billno = @ sorderno
else
update t_order_head set state = ' 2 ' where billno = @ sorderno and not exists ( select * from t_order_body where billno = @ sorderno and dhcount < counts )
end
if @ scurver = ' 1 ' and @ sbilltype = ' 2 ' and @ org_orgtype = ' 1 '
begin
insert into t_distpay_bill ( billno , billtype , shopcode , orgcode , rzdate , sqauremode , zpamount , jsamount , zramount , cost , netcost , total , isfinished , finacode )
select billno , ' 2 ' , orgcode , @ sbranchno , rzdate , sqauremode , cost , 0 , 0 , cost , netcost , total , ' 0 ' , @ finacode
from t_accept_head where billno = @ psbillno
update a set zsamount = zsamount + b . cost
from t_shop a , t_accept_head b where a . orgcode = @ sorgcode and a . orgcode = b . orgcode and b . billno = @ psbillno
end
if @ sisprntask = ' 1 '
begin
if @ sedition = ' 4 '
begin
insert into t_label_prn_task ( plucode , pluname , barcode , prncount , orgcode , price , vipprice , unit , spec , prodarea , prntype , remark , colorcode , sizecode , csbarcode )
select b . plucode , b . pluname , b . barcode , cast ( cb . ccounts as int ) , a . orgcode , b . price , d . vipprice , b . unit , b . spec , c . prodarea , ' 0 ' , b . billno ,
case when c . mngcs = ' 0 ' then ' ' else cb . colorcode end as colorcode , case when c . mngcs = ' 0 ' then ' ' else cb . sizecode end as sizecode ,
( select csbarcode from t_plu_cs gc where gc . plucode = cb . plucode and cb . colorcode = gc . colorcode and cb . sizecode = gc . sizecode ) as csbarcode
from t_accept_head a , t_accept_body b , t_plu c , t_plu_org d , t_accept_cs_body cb
where a . billno = b . billno and b . plucode = c . plucode and cb . billno = b . billno and cb . plucode = b . plucode and cb . serialno = b . serialno
and b . plucode = d . plucode and a . orgcode = d . orgcode and d . isright = ' 1 '
and c . isweight = ' 0 ' and left ( b . barcode , 2 ) = ' 20 ' and b . counts = cast ( b . counts as int ) and a . billno = @ psbillno
end
else
begin
insert into t_label_prn_task ( plucode , pluname , barcode , prncount , orgcode , price , vipprice , unit , spec , prodarea , prntype , remark )
select b . plucode , b . pluname , b . barcode , cast ( ( b . counts + b . givecount ) as int ) ,
a . orgcode , b . price , d . vipprice , b . unit , b . spec , c . prodarea , ' 0 ' , b . billno
from t_accept_head a , t_accept_body b , t_plu c , t_plu_org d
where a . billno = b . billno and b . plucode = c . plucode and b . plucode = d . plucode and a . orgcode = d . orgcode and d . isright = ' 1 '
and c . isweight = ' 0 ' and left ( b . barcode , 2 ) = ' 20 ' and b . counts = cast ( b . counts as int ) and a . billno = @ psbillno
end
end
if ( @ sbilltype = ' 1 ' ) and ( @ psparams = ' 9 ' )
begin
update t_order_head set state = ' 2 ' where billno = @ sorderno
end
if ( @ sbilltype = ' 2 ' )
begin
update t_order_head set state = ' 2 ' where billno = @ sorderno
end
if ( @ sbilltype = ' 2 ' ) and ( @ sameacc < > ' 1 ' )
begin
exec p_nosameacc_jh @ psbillno , @ psmsg out
end
set @ psmsg = ' '
return ( 1 )
end
go