create procedure batch_income()
begin
	declare eb_id varchar(32);
	declare eb_contract_id varchar(50);
	declare eb_payment_number varchar(50);
	declare eb_rent_list_income varchar(50);
	declare eb_fact_date varchar(20);
	declare eb_client_bank varchar(200);
	declare eb_client_account varchar(200);
	declare eb_client_acc_number varchar(200);
	declare eb_own_bank varchar(200);
	declare eb_own_account varchar(200);
	declare eb_ownacc_number varchar(200);
	declare done boolean default false;
	declare ebank_data cursor for 
	select id,
	       contract_id,
	       payment_number,
	       rent_list_income,
	       fact_date,
	       client_bank,
	       client_account,
	       client_acc_number,
	       own_bank,
	       own_account,
	       ownacc_number from lc_ebank where id in(select ebank_number from lc_ebank_process);
	declare continue handler for not found set done=true;
	open ebank_data;
	myLoop:loop
		fetch ebank_data into eb_id,
				      eb_contract_id,
				      eb_payment_number,
				      eb_rent_list_income,
				      eb_fact_date,
				      eb_client_bank,
				      eb_client_account,
				      eb_client_acc_number,
				      eb_own_bank,
				      eb_own_account,
				      eb_ownacc_number;
		if done then leave myLoop;
		end if;
		if eb_contract_id is not null and eb_contract_id<>'' 
		and eb_payment_number is not null and eb_payment_number<>''
		and eb_rent_list_income is not null and eb_rent_list_income<>''
		then
		INSERT INTO lc_rent_income (id,
					     quot_id,
					     cust_id,
					     project_id,
					     project_plan_number,
					     contract_id,
					     contract_plan_number,
					     payment_number,
					     plan_id,
					     plan_list,
					     hire_list,
					     hire_date,
					     rent,
					     corpus,
					     interest,
					     penalty,
					     corpus_adjust,
					     interest_adjust,
					     penalty_adjust,
					     coin,
					     ebank_number,
					     hire_bank,
					     hire_account,
					     hire_number,
					     own_bank,
					     own_account,
					     own_number,
					     memo,
					     roll_back,
					     inputuserid,
					     inputorgid,
					     inputtime,
					     updateuserid,
					     updateorgid,
					     updatetime)
				SELECT 	     REPLACE(UUID(),'-',''),
					     quot_id,
					     cust_id,
					     project_id,
					     project_plan_number,
					     contract_id,
					     contract_plan_number,
					     payment_number,
					     id,
					     plan_list,
					     1,
					     eb_fact_date,
					     rent,
					     corpus,
					     interest,
					     penalty,
					     0,
					     0,
					     0,
					     coin,
					     eb_id,
					     eb_client_bank,
					     eb_client_account,
					     eb_client_acc_number,
					     eb_own_bank,
					     eb_own_account,
					     eb_ownacc_number,
					     memo,
					     0,
					     inputuserid,
					     inputorgid,
					     inputtime,
					     updateuserid,
					     updateorgid,
					     updatetime FROM lc_rent_plan WHERE contract_id=eb_contract_id AND payment_number=eb_payment_number AND plan_list=eb_rent_list_income;
		delete from lc_ebank_process where ebank_number=eb_id;
		update lc_ebank set had_money=had_money+mayope_money,mayope_money=mayope_money-mayope_money where id=eb_id;
		delete from lc_occupy_rent_list where payment_number=eb_payment_number and plan_list=eb_rent_list_income and flow_name='网银批量核销';
		end if;
	end loop myLoop;
	close ebank_data;
end;

