/* 业务类型历史数据升级。采用插件升级与sql脚本升级 */
/**
 * 已开票数量=为红冲数量合计值
 * 已开票金额不等于0
 * 开票单.开票状态不等于已作废、已红冲、全部红冲
 */
UPDATE t_ar_finarbillentry_e fine_e SET finvoicedqty = (SELECT CASE WHEN sum( inv_e.funverifiedwriteoffqty )  IS NULL THEN 0 ELSE sum( inv_e.funverifiedwriteoffqty ) END FROM t_ar_invoice inv Left JOIN t_ar_invoiceentry inv_e ON inv_e.fid = inv.fid WHERE inv.finvoicestatus NOT IN ('3', '4', '8') AND inv_e.fsourcebillentryid = fine_e.FENTRYID ) WHERE fine_e.finvoicedamt <> 0;

/**
 * 已开票金额=0
 * 已开票数量=0
 */
UPDATE t_ar_finarbillentry_e SET finvoicedqty = 0 WHERE FINVOICEDAMT = 0;

UPDATE t_ar_finarbillentry_e fin_ext SET funinvoicedqty = ( select fin_e.fquantity - fin_ext.finvoicedqty as funinvoicedqty	from t_ar_finarbillentry fin_e 	where fin_e.FENTRYID = fin_ext.FENTRYID );