【T1】T1飞跃版红字反冲,提示单据已生成了凭证,不能红冲。但是联查凭证不存在。

news2024/12/23 11:00:50

【问题描述】
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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/772667.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

若依vue -【 33 ~ 】

33 登录日志 系统管理 > 日志管理 > 登录日志 1 应用场景 统计用户的活跃度用户错误输入密码多少次 2 后台实现 &#xff08;1&#xff09;SysLoginController#login&#xff1a;登录 /*** 登录方法* * param loginBody 登录信息* return 结果*/PostMapping("…

(七)「消息队列」之 RabbitMQ 发布者确认(使用 .NET 客户端)

发布者确认&#xff08;Publisher Confirms&#xff09; 发布者确认是一个 RabbitMQ 扩展&#xff0c;用于实现可靠的发布。当在通道上启用发布者确认时&#xff0c;客户端发布的消息将由代理异步确认&#xff0c;这意味着它们已在服务器端得到处理。 0、引言 先决条件 本教程…

Spring、SpringBoot、SpringCloud、SpringCloud Alibaba、Elasticsearch版本对应,附下载地址

1、GitHub Alibaba 发布SpringCloud Alibaba和SpringCloud 、SpringBoot版本 Spring Cloud Alibaba VersionSpring Cloud VersionSpring Boot2022.0.0.0-RC2Spring Cloud 2022.0.03.02022.0.0.0-RC1Spring Cloud 2022.0.03.0.02021.0.5.0*Spring Cloud 2021.0.52.6.132021.0.4…

Linux查看某进程所部署的目录路径

1.首先查看系统中正在跑的进程都有什么 ps -ef 2.然后通过抓取你要看的进程名&#xff0c;比如哪些服务 ps -ef | grep xxxxx(服务名) Linux在启动一个进程时&#xff0c;系统会在 /proc 下创建一个以PID命名的文件夹&#xff1b; 在该文件夹下会有我们的进程的信息&#…

【蓝图】p28按键+鼠标点击实现开关门

p28&#xff0c;创建门的蓝图类 actor和组件的区别、门的轴心点修改 创建一个Actor 添加一个静态网格体组件 创建一个门框 同理创建一个门Door 注意&#xff08;当门的中心点不在边角上时&#xff09; 创建一个Scene组件 把物体变换位置 这时只需要旋转Scene就可以旋转…

开发者评价:Serverless 容器最值得推荐的能力是什么?

Kubernetes 作为云原生计算的基础项目&#xff0c;已经在开发者和企业中获得广泛支持。它可以帮助企业加快部署频率、提升应用弹性、优化资源利用率、改善系统可用性。然而其自身复杂性和陡峭的学习曲线依然让一些开发者望而生畏&#xff1b;与此同时&#xff0c;随着企业数字化…

RabbitMQ到底为什么要使用它?

导入 一个技术的衍生必然是为了解决现实出现的问题&#xff0c;在讲这个问题之前我们先了解一下传统开发中关于服务调用出现的问题&#xff08;痛点&#xff09;有哪些&#xff1f; 我们为什么要使用MQ&#xff1f; ①、同步——超时 在多服务体系架构中&#xff0c;必然存在…

掘金量化—Python SDK文档—5.API 介绍(2)

Python SDK文档 5.API介绍 5.6通用数据函数&#xff08;免费&#xff09; python 通用数据 API 包含在 gm3.0.148 版本及以上版本&#xff0c;不需要引入新库 get_symbol_infos - 查询标的基本信息 获取指定(范围)交易标的基本信息&#xff0c;与时间无关. 此函数为掘金公…

C# 动态字典(可以随机实时增删访问,保证先入先出的字典)

如果你有以下需求&#xff1a; 1. 需要对Dictionary进行遍历的同时移除或者添加元素 2. 需要按顺序遍历Dictionary并且保证先入先出 3. 需要即时的获取字典内的元素数量&#xff0c;即时增删 如果你觉得好&#xff0c;请给我的框架点一个免费的star&#xff0c;球球啦 Yueh0607…

如何将视频转换为AVI格式?3个方法轻松转换!

在数字化时代&#xff0c;视频成为了人们记录和分享重要时刻的主要方式之一。然而&#xff0c;不同设备和平台对视频格式的要求千差万别&#xff0c;有时您可能需要将视频转换为特定格式以便于播放或编辑。在本文中&#xff0c;我们将重点介绍将视频转换为AVI&#xff08;Audio…

python实现小波降噪

文章目录 小波分解小波系数小波降噪阈值确定的一些小知识点python 实现小波去噪小波分解 上图为对信号进行3层小波分解,其中,Approximation 为近似小波系数(信号的低频成分),Detail为细节小波系数(信号的高频成分),分解后得到四个小波系数分别为A3,D3,D2,D1。 小波系数 小…

易查分怎么上传成绩?

当使用易查分制作查询系统时&#xff0c;许多老师可能对于如何上传成绩感到困惑。有时候&#xff0c;导入成绩到易查分系统后&#xff0c;信息可能无法完全显示&#xff0c;而且也很难找到错误的原因。因此&#xff0c;今天我将与老师们分享一下易查分上传成绩的方法。这个技巧…

【软件测试】Git实战-分支的新建和合并(超细整理)

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 新建分支 首先&a…

ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)

用压缩包安装MySQL&#xff0c;执行mysql -u root -p命令&#xff0c;报错&#xff1a; ERROR 2003 (HY000): Cant connect to MySQL server on localhost:3306 (10061) 这是因为MySQL服务器没有启动&#xff0c;我打开任务管理器看了一下&#xff0c;确实没有启动&#xff0c;…

携手航天·追求卓越|诚邀优秀企业加入航天采购平台供应商库

近日&#xff0c;第九届中国&#xff08;国际&#xff09;商业航天高峰论坛在武汉开幕&#xff0c;中国载人航天工程副总设计师张海联在《我国载人月球探测发展总体考虑》主旨报告中介绍了中国载人登月的初步方案。为此&#xff0c;我国科研人员正在研制长征十号运载火箭、新一…

科技云报道:大模型“百团大战”,容联云的机会在哪里?

科技云报道原创。 “大模型的迭代是一场‘暴力’填数据、拔规模而造就的‘美学盛宴’”&#xff0c;中金公司研究团队在“AI浪潮之巅”系列报告中如是说。 在大模型发展初期&#xff0c;大模型或许还称得上是“大厂的游戏”&#xff0c;但半年之后的今天&#xff0c;国内10亿…

【Linux】日志与守护进程

目录 一、预备知识 二、打印日志 三、守护进程 1、前置知识 2、守护进程 一、预备知识 日志是有等级的&#xff0c;表明该条日志的重要程度&#xff0c;一般分为以下几个级别&#xff1a; #define DEBUG 0 //调试信息 #define INFO 1 //正常运行 #define WARNING 2 //报…

【Python爬虫+可视化案例】采集电商网站商品数据信息,并可视化分析

爬虫可视化案例 &#xff1a;苏宁易购 案例所需要掌握的知识点&#xff1a; selenium的使用html标签数据解析方法 需要准备的环境&#xff1a; python 3.8pycharm 2022专业版selenium python里面的第三方库 可以用来操作浏览器 爬虫代码展示 所需模块 【代码领取 请看文末…

017 - STM32学习笔记 - SPI读写FLASH(二)-flash数据写入与读取

016 - STM32学习笔记 - SPI访问Flash&#xff08;二&#xff09; 上节内容学习了通过SPI读取FLASH的JEDEC_ID&#xff0c;在flash资料的指令表中&#xff0c;还看到有很多指令可以使用&#xff0c;这节继续学习使用其他指令&#xff0c;程序模板采用上节的模板。 为了方便起…

为何异地销号这么难?这些注意事项要熟记!

最近有不少小伙伴私信小编&#xff0c;他们在网上办理的大流量手机号卡&#xff0c;用了一段时间之后想换其他的卡&#xff0c;所以想注销当前用的卡&#xff0c;但是注销的时候确实屡屡碰壁&#xff0c;程序还比较繁琐&#xff0c;有的甚至申请注销了几个月还注销不掉&#xf…