You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
230 lines
7.0 KiB
230 lines
7.0 KiB
use chongqingchunyi
|
|
/*
|
|
|
|
SELECT * FROM sysobjects where type = 'u' ORDER BY Name
|
|
|
|
|
|
DROP TABLE #CardInfo
|
|
|
|
CREATE TABLE #CardInfo
|
|
(
|
|
FBillTime DATETIME,
|
|
FCompNo VARCHAR(50),
|
|
FCardNo VARCHAR(50),
|
|
FName VARCHAR(50),
|
|
FMobile VARCHAR(50),
|
|
FAcctNo VARCHAR(50),
|
|
FAcctId BIGINT,
|
|
FDeposit DECIMAL(18,6),
|
|
FPayTypeNo VARCHAR(50),
|
|
FPayTypeId BIGINT,
|
|
FPayAmt DECIMAL(18,6),
|
|
FCardTypeNo VARCHAR(50),
|
|
FCardTypeId BIGINT,
|
|
FEmpNo VARCHAR(50),
|
|
FPW VARCHAR(50),
|
|
FMemo VARCHAR(2000),
|
|
FUserNo VARCHAR(50),
|
|
FCardExpiredDate DATETIME,
|
|
FAcctExpiredDate DATETIME,
|
|
FBizType VARCHAR(20),
|
|
FBizTypeName VARCHAR(20)
|
|
)
|
|
|
|
update TCardInfo set 卡有效期 = DATEADD(YEAR,100,GETDATE()) WHERE 卡有效期 = '' OR 卡有效期 = '不限期'
|
|
update TCardInfo set 账户有效期 = NULL WHERE 账户有效期 = '' OR 账户有效期 = '不限期'
|
|
|
|
INSERT #CardInfo (FBizTypeName,FBillTime,FCompNo,FCardNo,FName,FMobile,FAcctNo,FDeposit,FPayTypeNo,FPayAmt,FCardTypeNo,FCardExpiredDate,FAcctExpiredDate,FPW,FMemo,FEmpNo,FUserNo)
|
|
SELECT 业务类别,单据时间,门店编号,卡号,姓名,手机,账户编号,账户金额,支付方式编号,支付金额,卡类别编号,卡有效期,账户有效期,密码,卡备注,第一销售,登录用户编号
|
|
FROM TCardInfo
|
|
|
|
--账户
|
|
UPDATE A
|
|
SET A.FAcctId = B.FId
|
|
FROM TPayAccount AS B,#CardInfo AS A
|
|
WHERE A.FAcctNo = B.FNo
|
|
|
|
|
|
UPDATE A
|
|
SET A.FAcctId = B.FId
|
|
FROM TPayAccount AS B,#CardInfo AS A
|
|
WHERE A.FAcctNo = B.FName
|
|
AND ISNULL(A.FAcctId,0) = 0
|
|
|
|
--支付
|
|
UPDATE A
|
|
SET A.FPayTypeId = B.FId
|
|
FROM TPayAccount AS B,#CardInfo AS A
|
|
WHERE A.FPayTypeNo = B.FNo
|
|
AND ISNULL(A.FPayTypeId,0) = 0
|
|
|
|
|
|
UPDATE A
|
|
SET A.FPayTypeId = B.FId
|
|
FROM TPayAccount AS B,#CardInfo AS A
|
|
WHERE A.FPayTypeNo = B.FName
|
|
AND ISNULL(A.FPayTypeId,0) = 0
|
|
|
|
--卡类别
|
|
UPDATE A
|
|
SET A.FCardTypeId = B.FId
|
|
FROM TMemberCardType AS B,#CardInfo AS A
|
|
WHERE A.FCardTypeNo = B.FNo
|
|
AND ISNULL(A.FCardTypeId,0) = 0
|
|
|
|
UPDATE A
|
|
SET A.FCardTypeId = B.FId
|
|
FROM TMemberCardType AS B,#CardInfo AS A
|
|
WHERE A.FCardTypeNo = B.FName
|
|
AND ISNULL(A.FCardTypeId,0) = 0
|
|
|
|
UPDATE A
|
|
SET A.FCardTypeId = B.FId
|
|
FROM TMemberCardType AS B,#CardInfo AS A
|
|
WHERE A.FCardTypeNo = B.FNo + '-' + B.FName
|
|
AND ISNULL(A.FCardTypeId,0) = 0
|
|
|
|
|
|
select * from tCardInfo
|
|
|
|
SELECT * FROM #CardInfo
|
|
|
|
UPDATE #CardInfo SET FUserNo = 'admin'
|
|
UPDATE #CardInfo SET FBizType = 'CardRchg' WHERE FBizTypeName = '储值卡充值'
|
|
UPDATE #CardInfo SET FBizType = 'CardSale' WHERE FBizTypeName = '储值卡销售'
|
|
|
|
--生成卡号
|
|
|
|
|
|
DECLARE @BillTime DATETIME
|
|
SELECT @BillTime = GETDATE()
|
|
DECLARE @From INT
|
|
DECLARE @Count INT
|
|
|
|
SELECT @From = 50020223
|
|
SELECT @Count = 0
|
|
WHILE @Count < 200
|
|
BEGIN
|
|
|
|
PRINT @From
|
|
INSERT #CardInfo(FBillTime,FCompNo,FCardNo,FName,FMobile,FAcctId,FDeposit,FPayTypeId,FPayAmt,
|
|
FCardTypeNo,FEmpNo,FPW,FMemo,FUserNo,FCardExpiredDate,FAcctExpiredDate)
|
|
SELECT @BillTime,'001',@From,'团购贵宾','',5564130390216603050,600,0,0,
|
|
'1014','01010','111111','如做特价或购买产品、疗程等需原价的2倍购买','Admin','2119-04-25','2022-04-25'
|
|
|
|
SELECT @From = @From + 1
|
|
IF @From LIKE '%4'
|
|
SELECT @From = @From + 1
|
|
|
|
|
|
SET @Count = @Count + 1
|
|
END
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
UPDATE #CardInfo SET FBillTime = Getdate(),FCompNo = '001',FPayTypeId = 8,FPayAmt = FDeposit,FEmpNo = '01001',FPW = '',FMemo = '',FUserNo = 'Admin',FCardExpiredDate = '2119-04-25'
|
|
UPDATE #CardInfo SET FBizType = 'CardRchg'
|
|
|
|
|
|
|
|
BEGIN TRAN
|
|
|
|
|
|
DECLARE @BillTime DATETIME
|
|
DECLARE @CardNo VARCHAR(50)
|
|
DECLARE @CompNo VARCHAR(50)
|
|
DECLARE @UserNo VARCHAR(50)
|
|
DECLARE @Name VARCHAR(50)
|
|
DECLARE @Mobile VARCHAR(50)
|
|
DECLARE @Deposit DECIMAL(18,6)
|
|
DECLARE @CardTypeId BIGINT
|
|
DECLARE @EmpNo VARCHAR(50)
|
|
DECLARE @EmpId BIGINT
|
|
DECLARE @PW VARCHAR(50)
|
|
DECLARE @Memo VARCHAR(2000)
|
|
DECLARE @CompId BIGINT
|
|
DECLARE @UserId BIGINT
|
|
DECLARE @CardExpiredDate DATETIME
|
|
DECLARE @DeptId BIGINT
|
|
DECLARE @AcctExpiredDate DATETIME
|
|
DECLARE @PayTypeId BIGINT
|
|
DECLARE @PayAmt DECIMAL(18,6)
|
|
DECLARE @AcctId BIGINT
|
|
DECLARE @BizType VARCHAR(30)
|
|
|
|
DECLARE List CURSOR FOR
|
|
SELECT FBillTime,FUserNo,FCompNo,FCardNo,Fname,Fmobile,FDeposit,FCardTypeId,FEmpNo,FPW,Fmemo,FCardExpiredDate,FAcctExpiredDate,FPayTypeId,FPayAmt,FAcctId,FBizType FROM #CardInfo
|
|
OPEN List
|
|
FETCH List INTO @BillTime,@UserNo,@CompNo,@CardNo,@Name,@Mobile,@Deposit,@CardTypeId,@EmpNo,@PW,@Memo,@CardExpiredDate,@AcctExpiredDate,@PayTypeId,@PayAmt,@AcctId,@BizType
|
|
WHILE @@FETCH_STATUS = 0
|
|
BEGIN
|
|
DECLARE @NewBillId BIGINT
|
|
DECLARE @NewCardId BIGINT
|
|
DECLARE @NewMemId BIGINT
|
|
DECLARE @NewBillNo VARCHAR(200)
|
|
DECLARE @WorkDate VARCHAR(200)
|
|
|
|
SELECT @WorkDate = CONVERT(VARCHAR,@BillTime,23)
|
|
SELECT @CompId = FId FROM TCompany WHERE FNo=@CompNo
|
|
SELECT @UserId = FId FROM TUser WHERE FNo = @UserNo
|
|
SELECT @EmpId = FId,@DeptId = ISNULL(FDeptId,0) FROM TEmployee WHERE FNo = @EmpNo
|
|
|
|
SELECT @NewBillId = dbo.FNNewId()
|
|
|
|
IF @BizType = 'CardSale'
|
|
BEGIN
|
|
SELECT @NewCardId = dbo.FNNewId()
|
|
SELECT @NewMemId = dbo.FNNewId()
|
|
END
|
|
ELSE IF @BizType = 'CardRchg'
|
|
BEGIN
|
|
SELECT @NewMemId = FMemId,@NewCardId = FCardId FROM TMemberCard WHERE FCardNo = @CardNo
|
|
END
|
|
SELECT @DeptId = ISNULL(@DeptId,0)
|
|
|
|
EXEC PGetNewBillNo @CompId,@WorkDate,'TMemberSaleBill','Company+YYMMDD+9999','',@NewBillNo OUTPUT
|
|
|
|
|
|
INSERT TMemberSaleBill(FBillId,FCompId,FBillTime,FBillNo,FSerialNo,FBizType,FCustSourceId,FMemId,FMemNo,FMemState,FPayCardId,FPayCardTypeId,FPayCardNo,FDues,FNeedPoint,FPoint,FInvoiceNo,FOrderBillId,FRegBillId,FBillMemo,
|
|
FCreateTime,FCreatorId,FState,FAuditTime,FAuditorId,FInvalidTime,FInvaliderId,FModifiedFlag,FWorkDate)
|
|
SELECT @NewBillId,@CompId,@BillTime,@NewBillNo,@NewBillNo,'CardRchg',0,@NewMemId,@CardNo,1,0,0,'',0,0,0,'',0,0,'后台生成',
|
|
GETDATE(),@UserId,0,NULL,0,NULL,0,0,@WorkDate
|
|
|
|
INSERT TMemberSaleCard(FBillId,FCardId,FCardNo,FCardTypeId,FCardValueType,FOrigPrice,FCardFee,FSalePrice,FAcctId,FDeposit,FAcctId2,FDeposit2,FTimes,FMemo,FExpiredDate,FAcctExpiredDate,FAcctExpiredDate2,FOldExpiredDate,FOldAcctExpiredDate,FOldAcctExpiredDate2,
|
|
FIsUpgrade,FNewCardTypeId,FNewCardValueType,FNewCardNo,FOldCardNo,FDeptId)
|
|
SELECT @NewBillId,@NewCardId,@CardNo,@CardTypeId,1,@PayAmt,0,@PayAmt,@AcctId,@Deposit,0,0,0,@Memo,@CardExpiredDate,@AcctExpiredDate,null,null,null,null,
|
|
0,0,0,'','',0
|
|
|
|
INSERT TMemberSaleEmployee( FId,FBillId,FDetailId,FWorkType,FDeptId,FEmpId,FShareRate,FPerf,FComm)
|
|
SELECT dbo.FNNewId(),@NewBillId,0,12001,@DeptId,@EmpId,1,@PayAmt,0
|
|
|
|
IF @BizType = 'CardSale'
|
|
BEGIN
|
|
INSERT TMemberSaleInfo(FBillId,FName,FGender,FBirthdayType,FBirthday,FMobilePhone,FTelephone,FQQ,FWeChat,FIdCard,FAddress,FPlateNo,FDriverLicense,
|
|
FVehicleLicense,FInsurer,FPW,FValidationMode,FMemo,FRecvConsSMS,FRecvBulkSMS,FIntrId)
|
|
SELECT @NewBillId,@Name,0,'G',NULL,@Mobile,'','','','','','','',
|
|
'',0,@PW,1,'',1,1,0
|
|
END
|
|
|
|
IF @PayTypeId != 0 AND @PayAmt != 0
|
|
BEGIN
|
|
INSERT TMemberSalePayment( FId,FBillId,FPayTypeId,FPayAmt,FMemo)
|
|
SELECT dbo.FNNewId(),@NewBillId,@PayTypeId,@PayAmt,''
|
|
END
|
|
EXEC PAuditMemberSaleBill @NewBillId,1,@UserId
|
|
|
|
|
|
FETCH List INTO @BillTime,@UserNo,@CompNo,@CardNo,@Name,@Mobile,@Deposit,@CardTypeId,@EmpNo,@PW,@Memo,@CardExpiredDate,@AcctExpiredDate,@PayTypeId,@PayAmt,@AcctId,@BizType
|
|
|
|
END
|
|
CLOSE LIST
|
|
DEALLOCATE List
|
|
--ROLLBACK TRAN
|
|
|
|
--COMMIT TRAN
|
|
|
|
|
|
|