-- 付款单更新分录: 单头状态=已付款  set 分录.剩余可退金额=分录.应付金额
UPDATE T_CAS_PAYMENTBILLENTRY SET FEREMAINREFUNDAMT = FPAYABLEAMOUNT
WHERE FID IN (SELECT FID FROM T_CAS_PAYMENTBILL WHERE FBILLSTATUS = 'D' AND FTOTALREMAINREFUNDAMT = 0) AND FEREMAINREFUNDAMT = 0;

-- 付款单更新单头: 已付款 and 付款币别=本位币  set 整单剩余可退金额=付款金额, 整单剩余可退金额折本位币=付款金额
UPDATE T_CAS_PAYMENTBILL SET FTOTALREMAINREFUNDAMT = FACTPAYAMOUNT, FLOCALREMAINREFUNDAMT = FACTPAYAMOUNT
WHERE FBILLSTATUS = 'D' AND FCURRENCYID = FBASECURRENCYID AND FTOTALREMAINREFUNDAMT = 0;

-- 付款单更新单头: 已付款 and 付款币别!=本位币  set 整单剩余可退金额=付款金额, 整单剩余可退金额折本位币=付款金额折本位币
UPDATE T_CAS_PAYMENTBILL SET FTOTALREMAINREFUNDAMT = FACTPAYAMOUNT, FLOCALREMAINREFUNDAMT = FLOCALAMOUNT
WHERE FBILLSTATUS = 'D' AND FCURRENCYID != FBASECURRENCYID  AND FTOTALREMAINREFUNDAMT = 0;

