-
Notifications
You must be signed in to change notification settings - Fork 0
/
deduct.sql
38 lines (32 loc) · 1000 Bytes
/
deduct.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
delimiter //
select count(*) OperatorLedgerEntries from OperatorLedger;
/*select UserId USID from User where Status!='deleted';*/
drop procedure if exists deduct;
CREATE PROCEDURE deduct()
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE msg varchar(1024) DEFAULT '';
DECLARE i INT DEFAULT 0;
DECLARE logId INT DEFAULT 0;
DECLARE opCt INT DEFAULT 0;
DECLARE id INT;
DECLARE total INT DEFAULT 0;
DECLARE users CURSOR FOR SELECT UserId FROM User where Status!='deleted';
/*delete from OperatorLedger;
*/
OPEN users;
SET total=FOUND_ROWS();
while i < total DO
fetch users into id;
set msg = concat(msg,' ',id);
insert into OperatorLedger(
EventNotes,ReqUserId,ReqDeviceId,CreditDeviceId,DebitUserId,Details,Time,AuditLogId,AuditNotes,Amount) values
('Debit',1,1,null,id,'Debited from deduct script',now(),null,null,-100);
SET i = i+1;
end while;
close users;
select concat('Periodic Debiting from Users with Ids : ',msg) Message;
End;
//
delimiter ;
call deduct();