`id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`rent_shop_type`,`createtime`,`create_by`,`create_by_name`,`updatetime`,`update_by`,`update_by_name`,
`price_detail`,`need_pay`,`receive_pay`,`pay`,`bill_type`,`pay_way`,`pay_date`,`set_off`,`starttime`,`endtime`,`status`,`energy_fees_id`,`return_pay`,
`bill_remark`,`last_owe_call_time`,`last_owe_call_user`,`bussiness_manage_fee_need_pay`,`operating_manage_fee_need_pay`,`shop_id`,`shop_number`,
`is_preview`,`shop_info`,`rent_contract_id`,`property_contract_id`,`parent_bill_id`,`energy_reading_calcuteId`,`energy_reading_id`,`extra_create_from`
where `tenant_id` = #{tenantId}
and `id` = #{id} and `parent_tenant_id` = #{parentTenantId}and `merchant_id` = #{merchantId}and `rent_shop_type` = #{rentShopType}and `create_by` = #{createBy} and `create_by_name` like concat('%',#{createByName},'%')and `bill_type` = #{billType}and `pay_way` = #{payWay}and `status` = #{status}and `energy_fees_id` = #{energyFeesId}and `rent_contract_id` = #{rentContractId}and `property_contract_id` = #{propertyContractId}and `parent_bill_id` = #{parentBillId}and `is_preview` = #{isPreview}and `starttime` >= #{starttime}and `endtime` <= #{endtime}and `starttime` = #{starttimeEqual}and `endtime` = #{endtimeEqual}and `extra_create_from` = #{extraCreateFrom}and `extra_create_from` is null
and date_format(starttime,'%Y-%m') <= #{month} and date_format(endtime,'%Y-%m') >= #{month}
and (
(`starttime` <= #{oweBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7,9) and bill_type not in (13,21,5))
or
(`starttime` <= #{oweBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') > 0 and status not in (3,6,7,9) and bill_type in (13,21,5))
)
and (
(`starttime` > #{oweBillLastTime} and `starttime` <= #{nearBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7,9) and bill_type not in (13,21,5))
or
(`starttime` > #{oweBillLastTime} and `starttime` <= #{nearBillLastTime} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') > 0 and status not in (3,6,7,9) and bill_type in (13,21,5))
)
and (
(`starttime` <= #{needPayStartDay} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7,9) and bill_type not in (13,21,5))
or
(`starttime` <= #{needPayStartDay} and `receive_pay` - `pay` - IFNULL(`set_off`,'0') > 0 and status not in (3,6,7,9) and bill_type in (13,21,5))
)
and (
( `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7,9) and bill_type not in (13,21,5))
or
( `receive_pay` - `pay` - IFNULL(`set_off`,'0') > 0 and status not in (3,6,7,9) and bill_type in (13,21,5))
)
and (
( `receive_pay` - `pay` - IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') < 0 and bill_type not in (13,21,5))
or
( `receive_pay` - `pay` - IFNULL(`set_off`,'0') < 0 and bill_type in (13,21,5))
or status in (8)
)
and (
(`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') + IFNULL(`return_pay`,'0') > 0 and status not in (3,6,7,9) and bill_type not in (13,21,5))
or
(`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') > 0 and status not in (3,6,7,9) and bill_type in (13,21,5))
)
and `merchant_id` is not nulland `parent_bill_id` is not nulland `parent_bill_id` is nulland `energy_reading_calcuteId` = #{energyReadingCalcuteId}and `energy_reading_id` = #{energyReadingId}
and `energy_fees_id` in
#{eidItem}
and `rent_contract_id` in
#{ridItem}
and property_contract_id in
#{pidItem}
and `merchant_id` in
#{midItem}
and `status` in
#{stItem}
and id not in
#{nidItem}
and id in
#{idItem}
order by ${sortColumns}
limit #{limitStart},#{limitEnd}
delete from wx_all_bill where rent_contract_id = #{id}
delete from wx_all_bill where property_contract_id = #{id}
delete from wx_all_bill where is_preview = 1
and rent_contract_id = #{rentContractId}
and property_contract_id = #{propertyContractId}
delete from wx_all_bill where status = 2
and starttime >= #{shopEndtime} and IFNULL(`pay`,'0') <= 0 AND IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0
and rent_contract_id = #{rentContractId}
and property_contract_id = #{propertyContractId}
and merchant_id = #{merchantId}
delete from wx_all_bill where rent_contract_id = #{rentContractId}
and IFNULL(`pay`,'0') <= 0 AND IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0
and extra_create_from = #{extraCreateFrom} and `starttime` = #{starttimeEqual}
delete from wx_all_bill where extra_create_from = #{extraCreateFrom}
and IFNULL(`pay`,'0') <= 0 AND IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0
and `starttime` = #{starttimeEqual}
and rent_contract_id = #{rentContractId}
and property_contract_id = #{propertyContractId}
update wx_all_bill set is_preview = #{isPreview}
where rent_contract_id = #{rentContractId}
where property_contract_id = #{propertyContractId}
INSERT INTO wx_all_bill (
)
VALUES
(
#{item.id},#{item.tenantId},#{item.parentTenantId},#{item.merchantId},#{item.rentShopType},#{item.createtime},
#{item.createBy},#{item.createByName},#{item.updatetime},#{item.updateBy},#{item.updateByName},#{item.priceDetail},
#{item.needPay},#{item.receivePay},#{item.pay},#{item.billType},#{item.payWay},#{item.payDate},#{item.setOff},
#{item.starttime},#{item.endtime},#{item.status},#{item.energyFeesId},#{item.returnPay},#{item.billRemark},
#{item.lastOweCallTime},#{item.lastOweCallUser},#{item.bussinessManageFeeNeedPay},#{item.operatingManageFeeNeedPay},
#{item.shopId},#{item.shopNumber},#{item.isPreview},#{item.shopInfo},#{item.rentContractId},#{item.propertyContractId},
#{item.parentBillId},#{item.energyReadingCalcuteId},#{item.energyReadingId},#{item.extraCreateFrom}
)
delete from wx_all_bill where id = #{id} and tenant_id = #{tenantId}
delete from wx_all_bill where energy_reading_calcuteId = #{energyReadingCalcuteId} and tenant_id = #{tenantId} and status = 2 and pay <= 0 and IFNULL(`set_off`,'0') <= 0 and IFNULL(`return_pay`,'0') <= 0
update wx_all_bill set status = 6 where property_contract_id in
(select id from wx_property_contract where rent_contract_id = #{id})
and status != 3