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.
sql-tools/批量开卡.sql

61 lines
2.7 KiB

1 year ago
use jinan_ashuangayue
BEGIN TRAN
DECLARE @MemName VARCHAR(50)
DECLARE @CompId BIGINT
DECLARE @CardTypeId BIGINT
DECLARE @PayTypeId BIGINT
DECLARE @PayAmt DECIMAL(18,6)
DECLARE @EmpId BIGINT
DECLARE @ExpiredDate DATETIME
DECLARE @DeptId BIGINT
SELECT @MemName = '<EFBFBD><EFBFBD><EFBFBD>Ϳ<EFBFBD>'
SELECT @CompId = FId FROM TCompany WHERE FNo = '003'
SELECT @CardTypeId = FId ,@DeptId = FDeptId FROM TMemberCardTYPE WHERE FNo = 'S001'
SELECT @PayTypeId = 8
SELECT @PayAmt = 300
SELECT @EmpId = FId FROM TEmployee WHERE FNo = '30000'
PRINT @CompId
SELECT @ExpiredDate = '2116-12-09'
DECLARE @I INT
SELECT @I = 419
WHILE @I <= 600
BEGIN
DECLARE @BillNo VARCHAR(30)
DECLARE @BillId BIGINT
DECLARE @BillTime DATETIME
DECLARE @Id BIGINT
DECLARE @CardNo VARCHAR(50)
DECLARE @MemId BIGINT
DECLARE @CardId BIGINT
SELECT @CardId = dbo.FNNewId()
SELECT @MemId = dbo.FNNewId()
SELECT @CardNo = '0000' + CAST(@I AS VARCHAR)
SELECT @BillTime = getdate()
SELECT @BillId = dbo.FNNewId()
EXEC PGetNewBillNo @CompId,@BillTime,'TMemberSaleBill','Prefix+Company+YYMMDD+9999','KK',@BillNo OUTPUT
print @BillNo
EXEC PInsertMemberSaleBill @BillId=@BillId,@CompId=@CompId,@BillTime=@BillTime,@BillNo=@BillNo,@SerialNo='',@BizType='CardSale',@CustSourceId=0,@MemId=@MemId,@MemNo=@CardNo,@MemState=1,@PayCardId=0,@PayCardTypeId=0,@PayCardNo='',@Dues=0,@NeedPoint=1,@Point=0,@InvoiceNo='',@OrderBillId=0,@RegBillId=0,@BillMemo='',@CreateTime=@BillTime,@CreatorId=1,@State=0,@AuditTime=NULL,@AuditorId=0,@InvalidTime=NULL,@InvaliderId=0,@ModifiedFlag=0,@WorkDate='2016-12-09'
EXEC PInsertMemberSaleInfo @IBillId=@BillId,@IName=@MemName,@IGender=0,@IBirthdayType='',@IBirthday=NULL,@IMobilePhone='',@ITelephone='',@IQQ='',@IWeChat='',@IIdCard='',@IAddress='',@IPW='',@IMemo='',@IRecvConsSMS=1,@IRecvBulkSMS=1,@IIntrId=0
EXEC PInsertMemberSaleCard @BillId=@BillId,@CardId=@CardId,@CardNo=@CardNo,@CardTypeId=@CardTypeId,@CardValueType=1,@OrigPrice=@PayAmt,@CardFee=0,@SalePrice=@PayAmt,@AcctId=3,@Deposit=@PayAmt,@AcctId2=0,@Deposit2=0,@Times=0,@Memo='',@ExpiredDate=@ExpiredDate,@AcctExpiredDate=NULL,@AcctExpiredDate2=NULL,@OldExpiredDate=NULL,@OldAcctExpiredDate=NULL,@OldAcctExpiredDate2=NULL,@IsUpgrade=0,@NewCardTypeId=0,@NewCardValueType=0,@NewCardNo='',@OldCardNo='',@DeptId=@DeptId
SELECT @Id = dbo.FNNewId()
EXEC PInsertMemberSaleEmployee @IId=@Id,@IBillId=@BillId,@IDetailId=0,@IWorkType=12001,@IDeptId=0,@IEmpId=6665025663666870015,@IShareRate=1,@IPerf=0,@IComm=0
SELECT @Id = dbo.FNNewId()
EXEC PInsertMemberSalePayment @IId=@Id,@IBillId=@BillId,@IPayTypeId=@PayTypeId,@IPayAmt=@PayAmt,@IMemo=''
EXEC PAuditMemberSaleBill @IBillId = @BillId,@IOperation = 1,@IUserId = 1
SELECT @I = @I+1
END
ROLLBACK TRAN
GO