|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF object_id('dbo.PCreateMemberSaleCardPayment','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PCreateMemberSaleCardPayment
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE dbo.PCreateMemberSaleCardPayment
|
|
|
|
|
(
|
|
|
|
|
@BillId bigint,
|
|
|
|
|
@BizType VARCHAR(30)
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
IF EXISTS(SELECT TOP 1 1 FROM TMemberSaleDetailPayment WHERE FBillId = @BillId)
|
|
|
|
|
BEGIN
|
|
|
|
|
print '<EFBFBD>Ѿ<EFBFBD>ִ<EFBFBD><EFBFBD>'
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
SELECT * INTO #Payment FROM TMemberSalePayment WHERE FBillId = @BillId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>֧<EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE @CashCardFee DECIMAL(18,6)
|
|
|
|
|
DECLARE @BankCardFee DECIMAL(18,6)
|
|
|
|
|
SET @CashCardFee = 0
|
|
|
|
|
SET @BankCardFee = 0
|
|
|
|
|
|
|
|
|
|
IF @BizType = 'CardSale'
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
|
|
DECLARE @Error INT
|
|
|
|
|
DECLARE @CardFee DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT @CardFee = FCardFee
|
|
|
|
|
FROM TMemberSaleCard WITH(NOLOCK)
|
|
|
|
|
WHERE FBillId=@BillId
|
|
|
|
|
|
|
|
|
|
IF @@ROWCOUNT = 0
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
|
|
RETURN -1
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF @CardFee > 0
|
|
|
|
|
BEGIN
|
|
|
|
|
DECLARE @CashPay DECIMAL(18,6)
|
|
|
|
|
SELECT @CashPay = ISNULL(FPayAmt,0) FROM #Payment WHERE FPayTypeId = 1
|
|
|
|
|
SET @CashPay = ISNULL(@CashPay,0)
|
|
|
|
|
IF @CardFee > @CashPay
|
|
|
|
|
BEGIN
|
|
|
|
|
DECLARE @BankPay DECIMAL(18,6)
|
|
|
|
|
SELECT @BankPay = ISNULL(FPayAmt,0) FROM #Payment WHERE FPayTypeId = 2
|
|
|
|
|
SET @BankPay = ISNULL(@BankPay,0)
|
|
|
|
|
IF @CardFee > @CashPay + @BankPay
|
|
|
|
|
BEGIN
|
|
|
|
|
RAISERROR('<EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD>֧<EFBFBD><EFBFBD>',18,1)
|
|
|
|
|
RETURN -1
|
|
|
|
|
END
|
|
|
|
|
SET @CashCardFee = @CashPay
|
|
|
|
|
SET @BankCardFee = @CardFee - @CashCardFee
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
ELSE
|
|
|
|
|
BEGIN
|
|
|
|
|
SET @CashCardFee = @CashPay - @CardFee
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF @CashCardFee > 0
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT TMemberSaleDetailPayment(FId,FBillId,FBizType,FDetailId,FPayTypeId,FPayAmt)
|
|
|
|
|
VALUES(dbo.FNGetNewId(),@BillId,@BizType,2,1,@CashCardFee)
|
|
|
|
|
END
|
|
|
|
|
IF @BankCardFee > 0
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT TMemberSaleDetailPayment(FId,FBillId,FBizType,FDetailId,FPayTypeId,FPayAmt)
|
|
|
|
|
VALUES(dbo.FNGetNewId(),@BillId,@BizType,2,2,@BankCardFee)
|
|
|
|
|
END
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ
|
|
|
|
|
INSERT TMemberSaleDetailPayment(FId,FBillId,FBizType,FDetailId,FPayTypeId,FPayAmt)
|
|
|
|
|
SELECT dbo.FNGetNewId(),@BillId,@BizType,1,ISNULL(FPayTypeId,1),ISNULL(CASE WHEN FPayTypeId = 1 THEN FPayAmt - @CashCardFee WHEN FPayTypeId = 2 THEN FPayAmt - @BankCardFee ELSE FPayAmt END,0) AS FPayAmt
|
|
|
|
|
FROM #Payment WITH(NOLOCK)
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DECLARE @sql VARCHAR(1000)
|
|
|
|
|
declare #sqlList cursor for
|
|
|
|
|
SELECT 'EXEC PCreateMemberSaleCardPayment ' + cast(FBillId AS VARCHAR(30)) + ',''' + FBizType + ''''
|
|
|
|
|
FROM TMemberSaleBill
|
|
|
|
|
WHERE FBizType IN( 'CardSale','CardRchg')
|
|
|
|
|
|
|
|
|
|
open #sqlList
|
|
|
|
|
fetch #sqlList into @sql
|
|
|
|
|
while @@fetch_status=0
|
|
|
|
|
begin
|
|
|
|
|
print @sql
|
|
|
|
|
EXEC (@sql)
|
|
|
|
|
fetch #sqlList into @sql
|
|
|
|
|
end
|
|
|
|
|
close #sqlList
|
|
|
|
|
deallocate #sqlList
|
|
|
|
|
|
|
|
|
|
|