pc.id,
pc.deleted,
pc.created,
pc.modified,
pc.item_id, pc.name, pc.amount, pc.payment_date
select ,i.name as itemName
from payment_collection pc left join item i on pc.item_id = i.id
where i.deleted = 0 and pc.deleted = 0
and pc.item_id = #{dto.itemId}
and i.name like concat ('%',#{dto.itemName},'%')
and pc.name like concat ('%',#{dto.name},'%')
AND pc.payment_date >= concat( YEAR ( now())- 1, '-12-23' )
AND pc.payment_date <= concat( YEAR ( now()), '-12-22' )
AND pc.payment_date >= #{dto.lastMonth23}
AND pc.payment_date <= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
and DATE_FORMAT(pc.payment_date,'%Y') = #{dto.year}
and DATE_FORMAT(pc.payment_date,'%c') = #{dto.month}
and i.user_id in
#{userId}
AND pc.created BETWEEN #{dto.startDate} AND #{dto.endDate}
order by pc.payment_date DESC
SELECT
i.id,
i.business_no,
i.oa_no,
i.NAME,
i.client_unit,
u.name as client_manager,
i.sign_date,
i.amount,
off.id as orderFundId,
ifnull(( SELECT sum( amount ) FROM payment_collection WHERE item_id = i.id AND deleted = 0 ), 0 ) AS payedAmount,
(
i.amount -(
ifnull(( SELECT sum( amount ) FROM payment_collection WHERE item_id = i.id AND deleted = 0 ), 0 ))) AS NotPayedAmount
FROM
item i
left join (select id,business_id from order_fund where business_type='ITEM_BUSINESS' AND deleted = 0) off on off.business_id = i.id
left join user u on u.id = i.user_id
WHERE
i.deleted =0
and i.name like concat ('%',#{dto.itemName},'%')
and i.user_id in
#{userId}
order by i.id DESC