【问题描述】
T1飞跃专业版,在经营历程中操作【红字反冲】的时候,
提示:单据已生成了凭证,不能红冲。
但是选中单据,点击联查凭证的时候,又提示【单据没有凭证】。
【解决方法】
针对账套库执行下述语句,
需要注意软件版本:飞跃19.5.0.1+财务15.0.2.5。
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/****** Object: Stored Procedure dbo.P_JudgeBillAct Script Date: 2011-01-06 12:32:40 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[P_JudgeBillAct]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[P_JudgeBillAct]
GO
CREATE PROCEDURE [dbo].[P_JudgeBillAct]
@i_OperType int,
@i_DftID int,
@i_BillDate varchar(10),
@i_BillType int,
@i_TableType smallint,
@i_WLDW_ID int,
@i_YSYF_Money numeric(28, 10),
@i_YSYF_Remain numeric(28, 10),
@i_tmpSyb smallint,
@i_VIP_ID int,
@i_ExcVIP_ID int,
@i_Exc_Integral numeric(18,2),
@o_CardMoney numeric(28, 10) output,
@o_ProdID int output, -- 返回商品单位错误的商品id
@o_DftDetailID int output -- 返回出错草稿明细IDhegx@ufida.com.cn
AS
set nocount on
Declare
@Result int,
@DateB varchar(10),
@ROD INT,
@DecimalDigits_Price INT
SELECT @DecimalDigits_Price = CONVERT(int,ifAllow) FROM SETSYSTEMINFO WHERE s_FullID ='0000600002'
if @i_OperType <> 15
begin
-- 判断发料出库单所调用的加工单是否已经作废select * from hintinfo where hintinfo like '%红冲%'
if (@i_BillType in (82, 86)) and (@i_OperType <> 16)
begin
if exists(select * from listsc1 left join mastersc on mastersc.s_id = listsc1.bill_id
where mastersc.billstate = -10 and listsc1.list_id in (select prod_ddid from listotherdft where bill_id = @i_DftID and Prod_ddid >0))
begin
-- set @o_ColorID = @i_DftID
return -62
end
if exists(select * from listsc1 left join mastersc on mastersc.s_id = listsc1.bill_id
where mastersc.billstate <> 3 and listsc1.list_id in (select prod_ddid from listotherdft where bill_id = @i_DftID and Prod_ddid >0))
begin
-- set @o_ColorID = @i_DftID
return -52
end
end
if @i_BillType in (60, 62, 63, 65)
begin
if exists(select s_FullID from SystemInfo where upper(s_Content)='INIORSTART' and upper(s_Values)='START')
begin
set @Result=-7
goto Error
end
end else
begin
if exists(select s_FullID from SystemInfo where upper(s_Content)='INIORSTART' and upper(s_Values)='INI')
begin
set @Result=-4
goto Error
end
select @DateB = s_Values from SystemInfo where upper(s_Content)='STARTDATE'
if @i_BillDate<@DateB
begin
set @Result=-8
goto Error
end
end
select @DateB=DateB from MonthPeriod where MonthName='本期'
if @i_BillDate<@DateB
begin
if @i_OperType = 16
set @Result=-60
else
set @Result=-32
goto Error
end
end else
begin
-- 审核已过帐单据,判断是否已进行了审核
if exists(select AutoID from MasterBill where AutoID = @i_DftID and BillState = 3)
begin
set @Result=-9
goto Error
end
-- 判断是否已进行了红冲
if exists(select AutoID from MasterBill where AutoID = @i_DftID and s_Syb < 0)
begin
set @Result=-33
goto Error
end
end
-- '判断系统是否正在进行抄帐'
if exists(select s_FullID from SystemInfo where s_FullID='00000' and s_JCQH='1')
begin
set @Result=-47
goto Error
end
if @i_OperType = 16
begin
-- 判断是否已进行了红冲
if exists(select AutoID from MasterBill where AutoID = @i_DftID and s_Syb < 0)
begin
set @Result=-33
goto Error
end
-- 判断是否单据已生成了凭证
if exists(select AutoID from MasterBill where AutoID = @i_DftID
and (MakeUfidaPZ='1' or MakeUfidaPZ='2' or MakeUfidaPZ='3'))
BEGIN
--金额为0的单据为了不在凭证制作的时候显示,也打上了标记(MakeUfidaPZ='1'),红冲的时候需要排除
IF not EXISTS(select AutoID from MasterBill where AutoID = @i_DftID --AND MakeUfidaPZ='1'
AND dbo.F_CMB_GetVoucherNoList(@i_DftID)='')
begin
SET @Result=-69
GOTO Error
END
end
-- 判断零售单是否被合并
if @i_BillType in (15, 16) and exists(select AutoID from MasterBill where AutoID = @i_DftID and left(Remark, 7) = '合并后的零售单' )
begin
set @Result=-80
goto Error
end
-- 红冲材料出库单、委外发料单,判断是否有相关调用存在
if (@i_BillType in (82, 86))
begin
-- SELECT @o_ProdID = ListOther.Prod_ID, @o_DftDetailID = ListOther.List_ID,
-- @o_CardMoney = th.Bill_ID
-- FROM ListOther as th INNER JOIN
-- ListOther ON th.Prod_DDID = ListOther.List_ID
-- where ListOther.Bill_ID = @i_DftID
--修改 BY 符义华 20101020
SELECT @o_ProdID = ListOther.Prod_ID, @o_CardMoney = ListOther.Bill_ID
FROM ListOther
INNER JOIN Masterbill ON Masterbill.AutoID = ListOther.Bill_ID
WHERE ListOther.Prod_DDBillID = @i_DftID and Masterbill.s_Syb = 0 and MasterBill.Billtype in (83, 87)
if (isNull(@o_ProdID,-1) > 0)
begin
set @Result=-87
goto Error
end else
begin
select @o_ProdID = -1, @o_DftDetailID = -1, @o_CardMoney = 0
end
end
--红冲产成品入库单,委外成品入库单,判断是否有相关调用存在 select * from billtype
/*
-- 红冲[成品入库]
-- 检查是否有调整分摊单调用成品入库
-- 有--则查看相应的调整分摊单是否被红冲:如果是,则继续,如果不是,则提示
-- 无--则继续
-- 如果有多张调整分摊单调用些成品入库单,则...
--*/
if (@i_BillType in (84, 88))
begin
SELECT @o_ProdID = listscfytz.Prod_ID, @o_CardMoney = listscfytz.Bill_ID FROM listscfytz
INNER JOIN Masterbill ON Masterbill.AutoID = listscfytz.Bill_ID
WHERE listscfytz.Prod_DDBillID = @i_DftID and Masterbill.s_Syb = 0 and MasterBill.Billtype in (151,152)
if (isNull(@o_ProdID,-1) > 0)
begin
set @Result=-87
goto Error
end else
begin
select @o_ProdID = -1, @o_DftDetailID = -1, @o_CardMoney = 0
end
end
-- 红冲总量盘点单,检查是否有相关过账单存在
if (@i_BillType=59)
begin
declare @BillDatetime datetime,
@StorID int,
@PDBill int
select @StorID = SIn_ID, @PDBill = RedOldID from MasterBill where AutoID = @i_DftID
SELECT @BillDatetime = a.BillDatetime
FROM MasterBillDft a INNER JOIN
MasterBillDft b ON a.s_ID = b.Change
WHERE (b.s_ID = @PDBill)
if exists(select s_ID from MasterBillDft where BillType = 67 and s_Syb = -3 and SIn_ID = @StorID)
begin
set @Result=-50
goto Error
end
-- if (
-- exists(
-- SELECT MasterBill.AutoID
-- FROM ListBuy INNER JOIN
-- MasterBill ON ListBuy.Bill_ID = MasterBill.AutoID
-- WHERE (DATEDIFF(second, MasterBill.BillDatetime, @BillDatetime)<0) and (MasterBill.BillType<>59)
-- and ListBuy.Stor_ID=@StorID and MasterBill.s_Syb=0
-- )
-- ) or
-- (
-- exists(
-- SELECT MasterBill.AutoID
-- FROM ListSale INNER JOIN
-- MasterBill ON ListSale.Bill_ID = MasterBill.AutoID
-- WHERE (DATEDIFF(second, MasterBill.BillDatetime, @BillDatetime)<0) and (MasterBill.BillType<>59)
-- and ListSale.Stor_ID=@StorID and MasterBill.s_Syb=0
-- )
-- ) or
-- (
-- exists(
-- SELECT MasterBill.AutoID
-- FROM ListOther INNER JOIN
-- MasterBill ON ListOther.Bill_ID = MasterBill.AutoID
-- WHERE (DATEDIFF(second, MasterBill.BillDatetime, @BillDatetime)<0) and (MasterBill.BillType<>59)
-- and ListOther.Stor_ID=@StorID and MasterBill.s_Syb=0
-- )
-- )
-- begin
-- set @Result = -51
-- goto Error
-- end
update a set a.s_Syb=-3 from MasterBillDft a, MasterBillDft b
where b.s_ID = @PDBill and a.s_ID = b.Change
if @@Error<>0 goto Error
if exists(select s_ID from MasterBillDft where s_ID = @PDBill and (PosGUID is Null) )
begin
-- 如果非门店上传,更新标识
update MasterBillDft set BillState=1, s_Syb=0 where s_id = @PDBill -- 更新盘点单标志
if @@Error<>0 goto Error
end else
begin
-- 如果为门店上传,删除草稿表中对应记录。以免在门店上传单据中重新显示出来
delete from MasterBillDft where s_id = @PDBill and (PosGUID is not Null)
if @@Error<>0 goto Error
end
end
-- if (@i_VIP_ID<>-1) and (@i_BillType in (1, 4, 15, 16))
-- begin
-- if exists(select DateE from b_vw_VIPCard where s_ID=@i_VIP_ID and CardType = 2)
-- begin
-- if @i_BillType in (15, 16)
-- SELECT @o_CardMoney=IsNull(Sum(ListSaleAcount.PayMoney),0)
-- FROM ListSaleAcount INNER JOIN
-- MoneyAccount ON ListSaleAcount.Act_ID = MoneyAccount.s_ID
-- where ListSaleAcount.Bill_ID=@i_DftID and MoneyAccount.s_FullID='0000200005'
-- if @i_BillType in (1, 4)
-- SELECT @o_CardMoney=IsNull(Card_Money,0)
-- FROM MasterBill where AutoID = @i_DftID
-- if @i_BillType in (1, 15)
-- set @o_CardMoney = -@o_CardMoney
-- end
-- end
end
else
begin
-- '判断进货/销售单据中订单情况'
if @i_BillType in (0, 1) and @i_OperType <> 15 --经营历程审核单据没有在ListBuyDft ListSaleDft里
begin
if ((@i_BillType = 0) and
exists(SELECT MasterOrder.BillState
FROM ListBuyDft INNER JOIN
MasterBillDft ON ListBuyDft.Bill_ID = MasterBillDft.s_ID INNER JOIN
ListOrder INNER JOIN
MasterOrder ON ListOrder.Bill_ID = MasterOrder.s_ID ON
ListBuyDft.Prod_DDID = ListOrder.List_ID
WHERE (MasterBillDft.s_ID = @i_DftID) and (MasterOrder.BillState <> 3)
)
) or
((@i_BillType = 1) and
exists(SELECT MasterOrder.BillState
FROM ListSaleDft INNER JOIN
MasterBillDft ON ListSaleDft.Bill_ID = MasterBillDft.s_ID INNER JOIN
ListOrder INNER JOIN
MasterOrder ON ListOrder.Bill_ID = MasterOrder.s_ID ON
ListSaleDft.Prod_DDID = ListOrder.List_ID
WHERE (MasterBillDft.s_ID = @i_DftID) and (MasterOrder.BillState <> 3)
)
)
begin
set @Result=-52
goto Error
end
if ((@i_BillType = 0) and
exists(SELECT MasterOrder.BillState
FROM ListBuyDft INNER JOIN
MasterBillDft ON ListBuyDft.Bill_ID = MasterBillDft.s_ID INNER JOIN
ListOrder INNER JOIN
MasterOrder ON ListOrder.Bill_ID = MasterOrder.s_ID ON
ListBuyDft.Prod_DDID = ListOrder.List_ID
WHERE (MasterBillDft.s_ID = @i_DftID) and (MasterOrder.Performstatus = 2) and (left(MasterOrder.Remark, 6) = '◎强制完成●')
)
) or
((@i_BillType = 1) and
exists(SELECT MasterOrder.BillState
FROM ListSaleDft INNER JOIN
MasterBillDft ON ListSaleDft.Bill_ID = MasterBillDft.s_ID INNER JOIN
ListOrder INNER JOIN
MasterOrder ON ListOrder.Bill_ID = MasterOrder.s_ID ON
ListSaleDft.Prod_DDID = ListOrder.List_ID
WHERE (MasterBillDft.s_ID = @i_DftID) and (MasterOrder.Performstatus = 2) and (left(MasterOrder.Remark, 6) = '◎强制完成●')
)
)
begin
set @Result=-53
goto Error
END
-- add by fhying@2012.06.12 for 订单或者订单明细被删除以后,需要提前判断一下,否则后面在修改订单数据的时候,会返回-1错误。
IF (
(@i_BillType = 0) AND
(EXISTS(select prod_DDID from dbo.ListBuyDft where prod_ddid not in (select list_id from listorder) and bill_ID = @i_DftID
AND prod_DDID<> -1))
)
OR
(
(@i_BillType = 1) AND
(EXISTS(select prod_DDID from dbo.ListSaleDft where prod_ddid not in (select list_id from listorder) and bill_ID = @i_DftID
AND prod_DDID<> -1))
)
BEGIN
if @i_BillType = 1
begin
select Top 1 @o_DftDetailID=List_ID from dbo.ListSaleDft where prod_ddid not in (select list_id from listorder) and bill_ID = @i_DftID AND prod_DDID<> -1
end
set @Result=-76
goto Error
END
-- add end.
end
-- '判断往来单位信用额度'
if @i_BillType in (1, 3, 14, 15, 61 )
and exists(select s_ID from MasterBillDft where s_ID = @i_DftID and (PosGUID is Null)) -- 如果是门店上传单据,不做拦截
begin
-- ================================= modified by fhying@2011.07.05 ===============================================================
-- 之前的逻辑有错误,仅判断了@i_tmpSyb=0的情况,而客户端在第二次提交过账时,该值为1,这时出现漏判,导致没有检查22号配置就过账了。
-- 客户端应该注意,只有 (@i_tmpSyb = 1) 和(@i_tmpSyb = 0)的情况才做了判断,如果不判断信用额度,可以传非0和非1的值。:)
/*
if (@i_tmpSyb = 0) and exists(select * from Units where s_ID=@i_WLDW_ID and IsNull(CreditLimit,0)<>0)
and exists(select * from Units where s_ID=@i_WLDW_ID and IsNull(CreditLimit,0)<(IsNull(AReceive,0)-IsNull(APayDue,0)+@i_YSYF_Remain))
begin
if exists(select * from SetSystemInfo where s_FullID='0000400022' and IfAllow='√')
begin
if exists(select * from SetSystemInfo where s_FullID='0000400015' and IfAllow='√')
begin
set @Result=-5
goto Error
end
end else
begin
set @Result=-6
goto Error
end
end
*/
if exists(select * from Units where s_ID=@i_WLDW_ID and IsNull(CreditLimit,0)<>0)
and exists(select * from Units where s_ID=@i_WLDW_ID and IsNull(CreditLimit,0)<(IsNull(AReceive,0)-IsNull(APayDue,0)+@i_YSYF_Remain))
begin
-- 第一次试图过账
if (@i_tmpSyb = 0)
begin
-- 是否允许超过额度过账
if exists(select * from SetSystemInfo where s_FullID='0000400022' and IfAllow='√')
begin
-- 是否提示?
if exists(select * from SetSystemInfo where s_FullID='0000400015' and IfAllow='√')
begin
set @Result=-5
goto Error
end
end
else
begin
set @Result=-6
goto Error
end
end
-- 第二次试图过账,不再判断提示的配置。@i_tmpSyb = 1表示是第一次返回客户端后,客户端再次提交过账。
else
if (@i_tmpSyb = 1)
begin
-- 是否允许超过额度过账
if not exists(select * from SetSystemInfo where s_FullID='0000400022' and IfAllow='√')
begin
set @Result=-6
goto Error
end
end
end
-- ================================= modified by fhying@2011.07.05 end ===========================================================
end
end
if @i_OperType in (11, 12, 13, 14)
begin
--成品入库调加工单,判断本次数量是否大于本次数量--select * from listotherscdft select * from masterbilldft where s_id = 1733
if @i_BillType=0
begin
if exists (select s_ID FROM MasterBillDft where isnull(SRACount_Money,0)>isnull(SumShippingMoney,0) and s_ID=@i_DftID )
begin
set @Result=-93
goto Error
end
end
if @i_BillType in (84, 88)
BEGIN
-- select BC.Prod_ID, BC.list_id,BC.Prod_Num, listsc1.LYNumber, listsc1.UseNumber from
-- (
-- select listotherdft.Prod_id,ListOtherSCdft.list_id,listotherscdft.prod_ddid, listotherscdft.bill_id,sum(Prod_Num) as Prod_Num from listotherscdft
-- left join listotherdft on listotherdft.List_ID = ListOtherSCdft.list_id where listotherscdft.bill_id = @i_DftID
-- group by listotherscdft.prod_ddid, listotherscdft.bill_id,listotherdft.Prod_id,ListOtherSCdft.list_id
-- )BC
-- left join listsc1 on listsc1.list_id = BC.Prod_DDID where BC.Prod_Num > (listsc1.LYNumber - listsc1.UseNumber)
select @ROD=IfAllow from dbo.SetSystemInformation where s_FullID='0000600001' --取系统小数位
select top 1 @o_ProdID = BC.Prod_ID, @o_DftDetailID = BC.list_id from
(
select listotherdft.Prod_id,ListOtherSCdft.list_id,listotherscdft.prod_ddid, listotherscdft.bill_id,sum(isNull(Prod_Num,0)) as Prod_Num from listotherscdft
left join listotherdft on listotherdft.List_ID = ListOtherSCdft.list_id where listotherscdft.bill_id = @i_DftID
group by listotherscdft.prod_ddid, listotherscdft.bill_id,listotherdft.Prod_id,ListOtherSCdft.list_id
)BC
left join listsc1 on listsc1.list_id = BC.Prod_DDID where ROUND(BC.Prod_Num,@ROD) >
ROUND(isNull(ListSC1.LYNumber,0)*isNull(ListSC1.pDW_Ratio,0) - isNull(ListSC1.UseNumber,0)*isNull(ListSC1.pDW_Ratio,0),@ROD)
if (isNull(@o_ProdID,-1) > 0)
begin
set @Result = -1008
goto Error
end
--检查工序成本是否超出
if exists(select * from ListOtherWPDft where bill_id = @i_DftID)
begin
declare @JGbill_id int,@JGList_ID int
--单个产品循环
DECLARE cur_JudgeJS_Money CURSOR read_only
FOR
select Prod_billddid,Prod_ddid from ListOtherWPDft where bill_id = @i_DftID group by Prod_billddid,Prod_ddid
OPEN cur_JudgeJS_Money
FETCH NEXT FROM cur_JudgeJS_Money INTO @JGbill_id,@JGList_ID
WHILE @@FETCH_STATUS = 0
BEGIN
--找出isnull(l.Prod_Money,0)>SumHB.SumCostMoney-isnull(JG.JS_Money,0) 产成品入库工序成本>加工单的未结成本
if exists(
select JG.List_ID,JG.bill_id,
l.Prod_Num as BCNumber,l.Prod_Money as BCMoney,SumHB.Qua_Number,SumHB.SumCostMoney,
isnull(JG.JS_Number,0) JS_Number,isnull(JG.JS_Money,0) JS_Money,
SumHB.Qua_Number-isnull(JG.JS_Number,0) as NoJS_Number,
SumHB.SumCostMoney-isnull(JG.JS_Money,0) as NoJS_Money
from ListSC_WP JG
left join ListOtherWPDft l on JG.List_ID=l.Prod_ddid and JG.Bill_ID=l.Prod_billddid AND l.Bill_id=@i_DftID
left join ( select ListHB.WP_ID,
SUM(isnull(ListHB.CP_Number,0)) CP_Number,
SUM(isnull(ListHB.Qua_Number,0)) Qua_Number,
SUM(isnull(ListHB.Act_Money,0)) SumCostMoney
from (
select HB.WP_ID,HB.CP_Number,HB.Qua_Number,(HB.Manpower_Money + HB.Cost_Money + HB.WWCost_TaxMoney) Act_Money
from ListSC_WP HB
left join ListSC_WP PG on PG.List_ID=HB.Old_WPList_ID --派工单上的Old_SCBill_ID就是加工单号
left join MasterSC M on HB.Bill_ID = M.s_ID
--left join MoneyList on MoneyList.Bill_ID = m.s_ID and MoneyList.Act_ID=68 --工序成本 当一张单有多条明细时,关联MoneyList就翻倍
where M.BillType in (502) and M.s_Syb>=0 and PG.Old_SCBill_ID=@JGbill_id and PG.Old_WPList_ID=@JGList_ID
union all
select HBTH.WP_ID,-HBTH.CP_Number,-HBTH.Qua_Number,-HBTH.Manpower_Money Act_Money
from ListSC_WP HBTH
left join ListSC_WP HB on HB.List_ID=HBTH.Old_WPList_ID
left join ListSC_WP PG on PG.List_ID=HB.Old_WPList_ID --派工单上的Old_SCBill_ID就是加工单号
left join MasterSC M on HBTH.Bill_ID = M.s_ID
--left join MoneyList on MoneyList.Bill_ID = m.s_ID and MoneyList.Act_ID=68 --工序成本
where M.BillType in (503) and M.s_Syb>=0 and PG.Old_SCBill_ID=@JGbill_id and PG.Old_WPList_ID=@JGList_ID
) ListHB
Group by ListHB.WP_ID
) SumHB on JG.WP_ID=SumHB.WP_ID
where JG.bill_id=@JGbill_id and JG.List_ID=@JGList_ID
and isnull(JG.JS_Number,0)<isnull(SumHB.Qua_Number,0)
and isnull(JG.JS_Money,0)<isnull(SumHB.SumCostMoney,0)
and isnull(l.Prod_Money,0)>SumHB.SumCostMoney-isnull(JG.JS_Money,0)
)
begin
set @Result = -1009
break
end
FETCH NEXT FROM cur_JudgeJS_Money INTO @JGbill_id,@JGList_ID
END
CLOSE cur_JudgeJS_Money
DEALLOCATE cur_JudgeJS_Money
if @Result = -1009 goto Error
end
END
if @i_BillType in (151)
begin
if exists(select WS_ID from Masterbilldft where s_ID=@i_DftID and WS_ID in (select s_ID from workshop where s_Syb<0 or s_SonCount<>0))
return -21
end
--工贸:费用分摊过账,调用的入库单是否已经被调用 select prod_DDID,* from listscfytz--select * from hintinfo where hintinfo like '%单据%'
-- select * from listscfytz
-- left join masterbill on masterbill.autoid = listscfytz.Bill_ID
-- where masterbill.s_syb >= 0 and prod_DDID in (select prod_DDID from listscfytzdft where ListSCFYTZDft.Bill_ID = @i_DftID)
if @i_BillType in (151)
begin
if exists(select 1 from listscfytz
left join masterbill on masterbill.autoid = listscfytz.Bill_ID
where masterbill.s_syb >= 0 and prod_DDID in (select prod_DDID from listscfytzdft where ListSCFYTZDft.Bill_ID = @i_DftID))
begin
set @Result = -1007
goto Error
end
end
--工贸:委外调整单调原入库单,判断是否入库单已经被调用完毕Prod_Number
--对当前单据内的所有调相同单据的明细进行SUM
--对已经被调整的明细进行SUM
--再对前两者SUM求和,与原入库比较
if @i_BillType in (152)
begin
if exists(
select 1 from
(
select a.prod_DDID, (isnull(a.Prod_Number, 0) + isnull(b.Prod_Number, 0)) as SUM_Prod_Number from
(select prod_DDID,sum(Prod_Number) as Prod_Number from listscfytzdft
left join masterbilldft on masterbilldft.s_id = listscfytzdft.bill_ID
where ListSCFYTZDft.Bill_ID = @i_DftID group by prod_DDID) a
left join
(select prod_DDID,sum(Prod_Number) as Prod_Number from listscfytz
left join masterbill on masterbill.autoid = listscfytz.bill_ID
where masterbill.s_syb >=0 group by prod_DDID) b on a.prod_DDID = b.prod_DDID
) aa
left join listother on listother.list_id = aa.prod_DDID where ( isnull(listother.Prod_Number,0) * isnull(listother.pDW_Ratio,0) ) < aa.SUM_Prod_Number
)
begin
set @Result = -1008
goto Error
end
end
-- 工贸:费用分摊、委外调整单,单据、库存一致性判断
IF @i_BillType IN (151, 152)
BEGIN
IF EXISTS(
SELECT a.*
FROM ListSCFYTZDft a
inner join product c on a.prod_id=c.s_id
left join storage g on a.prod_id=g.prod_id and a.stor_id=g.stor_id
and (c.costmethod=0
or (c.costmethod in (1,2) --and ROUND(a.costprice_0,@DecimalDigits_Price)=ROUND(g.costprice,@DecimalDigits_Price)
and a.OutFactoryDate=g.OutFactoryDate and a.SerNumber=g.SerNumber and a.prod_order=g.prod_order)
or (c.costmethod =3 --and ROUND(a.costprice_0,@DecimalDigits_Price)=ROUND(g.costprice,@DecimalDigits_Price)
and a.OutFactoryDate=g.OutFactoryDate and a.SerNumber=g.SerNumber and a.prod_order=g.prod_order)
)
WHERE a.Bill_ID = @i_DftID AND
( ROUND(a.StorNum, 6) <> ROUND(isNull(g.Prod_Number1,0), 6)
--OR ROUND(a.StorMoney, 3) <> ROUND(isNull(g.Prod_Number1*g.costprice,0), 3) --单价可能不一样 屏蔽
)
)
BEGIN
--PRINT(1111111111111111111)
set @Result = -1005
goto Error
end
---
-------------处理成本算法手工指定的商品 防止单据库存与实际库存存在尾差,用实际库存反向更新 手工指宝算法
if exists(select 1 FROM ListSCFYTZDft INNER JOIN Product on product.s_id = ListSCFYTZDft.Prod_ID
where ListSCFYTZDft.Bill_ID = @i_DftID and product.CostMethod = 3)
begin
if exists(select 1 FROM ListSCFYTZDft
INNER JOIN Product on product.s_id = ListSCFYTZDft.Prod_ID
left join Storage ON ListSCFYTZDft.Stor_ID = Storage.Stor_ID AND
ListSCFYTZDft.Prod_ID = Storage.Prod_ID AND
ListSCFYTZDft.SerNumber = Storage.SerNumber and
isNull(ListSCFYTZDft.OutFactoryDate,'') = isNull(Storage.OutFactoryDate,'') and ListSCFYTZDft.prod_order=Storage.prod_order
--and ROUND(ListSCFYTZDft.CostPrice_0,@DecimalDigits_Price) = ROUND(Storage.CostPrice,@DecimalDigits_Price)
where ListSCFYTZDft.Bill_ID = @i_DftID and product.CostMethod = 3)
begin
update ListSCFYTZDft set
StorNum = isNull(Storage.Prod_Number1,0),
StorMoney = isNull(case when Storage.Prod_Number2 = Storage.Prod_Number1 then Storage.CostMoney else Storage.Prod_Number1 * Storage.CostPrice end ,0)
FROM ListSCFYTZDft left outer JOIN
Storage ON ListSCFYTZDft.Stor_ID = Storage.Stor_ID AND
ListSCFYTZDft.Prod_ID = Storage.Prod_ID AND
ListSCFYTZDft.SerNumber = Storage.SerNumber and
ListSCFYTZDft.OutFactoryDate = Storage.OutFactoryDate and ListSCFYTZDft.prod_order=Storage.prod_order
--and ROUND(ListSCFYTZDft.CostPrice_0,@DecimalDigits_Price) = ROUND(Storage.CostPrice,@DecimalDigits_Price)
left join Product on product.s_id = ListSCFYTZDft.Prod_ID
WHERE ListSCFYTZDft.Bill_ID = @i_DftID and product.CostMethod = 3
if @@Error<>0 or @@Rowcount = 0 goto Error
end
else
BEGIN
--PRINT(222222222222)
set @Result = -1005
goto Error
end
end
------------------------------
-- 防止单据库存与实际库存存在尾差,用实际库存反向更新 非手工指定算法
if exists(select 1 FROM ListSCFYTZDft INNER JOIN Product on product.s_id = ListSCFYTZDft.Prod_ID
where ListSCFYTZDft.Bill_ID = @i_DftID and product.CostMethod in (0,1,2))
begin
if exists(select 1 FROM ListSCFYTZDft left outer JOIN
Storage ON ListSCFYTZDft.Stor_ID = Storage.Stor_ID AND
ListSCFYTZDft.Prod_ID = Storage.Prod_ID AND
ListSCFYTZDft.Prod_Order = Storage.Prod_Order)
begin
update ListSCFYTZDft set
StorNum = isNull(Storage.Prod_Number1,0),
StorMoney = isNull(case when Storage.Prod_Number2 = Storage.Prod_Number1 then Storage.CostMoney else Storage.Prod_Number1 * Storage.CostPrice end ,0)
FROM ListSCFYTZDft left outer JOIN
Storage ON ListSCFYTZDft.Stor_ID = Storage.Stor_ID AND
ListSCFYTZDft.Prod_ID = Storage.Prod_ID AND
ListSCFYTZDft.Prod_Order = Storage.Prod_Order
left join Product on product.s_id = ListSCFYTZDft.Prod_ID
WHERE ListSCFYTZDft.Bill_ID = @i_DftID and product.CostMethod in (0, 1, 2)
if @@Error<>0 or @@Rowcount = 0 goto Error
end
else
BEGIN
--PRINT(3333333333333)
set @Result = -1005
goto Error
end
end
-----
END
if (@i_TableType = 1)
begin
select top 1 @o_ProdID = ListBuyDft.Prod_ID, @o_DftDetailID = ListBuyDft.List_ID
FROM ListBuyDft
where ListBuyDft.Bill_ID = @i_DftID and
ListBuyDft.List_ID not in
(
SELECT ListBuyDft.List_ID
FROM ListBuyDft INNER JOIN
a_vw_JudgeProdDW ON ListBuyDft.Prod_ID = a_vw_JudgeProdDW.s_id AND
ListBuyDft.Prod_ProdDw = a_vw_JudgeProdDW.ProdDW and ListBuyDft.pDW_Ratio = a_vw_JudgeProdDW.pDW_Ratio
where ListBuyDft.Bill_ID = @i_DftID
)
end else
if (@i_TableType = 2) and ( not (@i_BillType in (15, 16)))
begin
select top 1 @o_ProdID = ListSaleDft.Prod_ID, @o_DftDetailID = ListSaleDft.List_ID
FROM ListSaleDft
where ListSaleDft.Bill_ID = @i_DftID and
ListSaleDft.List_ID not in
(
SELECT ListSaleDft.List_ID
FROM ListSaleDft INNER JOIN
a_vw_JudgeProdDW ON ListSaleDft.Prod_ID = a_vw_JudgeProdDW.s_id AND
ListSaleDft.Prod_ProdDw = a_vw_JudgeProdDW.ProdDW and ListSaleDft.pDW_Ratio = a_vw_JudgeProdDW.pDW_Ratio
where ListSaleDft.Bill_ID = @i_DftID
)
end else
if (@i_BillType in (15, 16))
begin
select top 1 @o_ProdID = ListRetailDft.Prod_ID, @o_DftDetailID = ListRetailDft.List_ID
FROM ListRetailDft
where ListRetailDft.Bill_ID = @i_DftID and
ListRetailDft.List_ID not in
(
SELECT ListRetailDft.List_ID
FROM ListRetailDft INNER JOIN
a_vw_JudgeProdDW ON ListRetailDft.Prod_ID = a_vw_JudgeProdDW.s_id AND
ListRetailDft.Prod_ProdDw = a_vw_JudgeProdDW.ProdDW and ListRetailDft.pDW_Ratio = a_vw_JudgeProdDW.pDW_Ratio
where ListRetailDft.Bill_ID = @i_DftID
)
end else
if (@i_TableType = 3)
begin
select top 1 @o_ProdID = ListOtherDft.Prod_ID, @o_DftDetailID = ListOtherDft.List_ID
FROM ListOtherDft
where ListOtherDft.Bill_ID = @i_DftID and
ListOtherDft.List_ID not in
(
SELECT ListOtherDft.List_ID
FROM ListOtherDft INNER JOIN
a_vw_JudgeProdDW ON ListOtherDft.Prod_ID = a_vw_JudgeProdDW.s_id AND
ListOtherDft.Prod_ProdDw = a_vw_JudgeProdDW.ProdDW and ListOtherDft.pDW_Ratio = a_vw_JudgeProdDW.pDW_Ratio
where ListOtherDft.Bill_ID = @i_DftID
)
end
set @o_ProdID = isNull(@o_ProdID, -1)
if @o_ProdID > 0
BEGIN
--先判断下商品是不是已删除
IF EXISTS(SELECT TOP 1 1 FROM product WHERE s_ID=@o_ProdID AND s_Syb=-1)
BEGIN
SET @Result = -13
GOTO Error
END
ELSE
begin
SET @Result = -2000
GOTO Error
end
end
-- '总量盘点单过账,检查相关分量盘点单状态'
if (@i_BillType=59)
and exists(select s_ID from MasterBillDft where s_ID = @i_DftID and (PosGUID is Null) ) -- 门店数据不做判断 v11.0
begin
declare @CK_ID int,
@FL_ID int,
@ZL_ID int
select @CK_ID = Change, @ZL_ID = PayMoney from MasterBillDft where s_ID = @i_DftID
if not exists(select s_ID from MasterBillDft where s_ID = @CK_ID and s_Syb = -3 and BillState <> -1)
begin
set @Result = -65
goto Error
end
if exists(select s_ID from MasterBillDft where Change = @CK_ID and BillState <> -1 and BillType = 66 and isNull(PayMoney,0) = 0)
begin
set @Result = -66
goto Error
end
if exists(select a.s_ID from MasterBillDft a , MasterBillDft b
where b.PayMoney = @i_DftID and a.SIn_ID = b.SIn_ID and a.s_Syb = -3 and a.BillState <> -1 and a.BillType = 66)
begin
set @Result=-46
goto Error
end
if exists(select s_ID from MasterBillDft
where s_ID = @i_DftID and s_Syb = -5)
begin
set @Result=-56
goto Error
end
end
-- 会员卡赠送单判断卡
if @i_BillType=11 and @i_ExcVIP_ID>0 and
exists(select s_ID from MasterBillDft where s_ID = @i_DftID and (POSGUID is null) )
begin
declare @Integral numeric(18,2),
@Syb_Integral bit
SELECT @Syb_Integral=VIPCardType.Syb_Integral, @Integral=IsNull(VIPCard.Integral,0)
FROM VIPCard INNER JOIN
VIPCardType ON VIPCard.CardType_ID = VIPCardType.s_ID
where VIPCard.s_ID=@i_ExcVIP_ID
if (select Remark from MasterBillDft where s_ID = @i_DftID)<>'[会员卡升级赠送礼品]'
begin
if @Syb_Integral=0
begin
set @Result=-301
goto Error
end
end
if @Integral < @i_Exc_Integral
begin
set @Result=-302
goto Error
end
end
end
return 0
Error:
if IsNull(@Result, 0)>=0 set @Result=-1
return @Result
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO