var oldFinaChargeStuYearItem = conn.Query<FinaChargeStuYearItemEntity>(@"select b.* from [dbo].[FinaChargeStuOrderDetail] a left join [dbo].[FinaChargeStuYearItem] b on a.ChargeItemCode=b.ChargeItemCode
where a.[FCSOId] = '"+item.Id+"' and b.FSYId = '"+ item.FSYId + "'");
where a.[FCSOId] = '"+item.Id+"' and b.FSYId = '"+ item.FSYId + "'");
//实缴、缴费余额更新
//FinaChargeStuYearItem表
conn.Execute(@"update [dbo].[FinaChargeStuYearItem] set SJAmount=b.SJAmount+a.SJAmount,NeedToPay=NeedToPay-a.SJAmount,PayFeeStatus=(case when(NeedToPay-a.SJAmount<=0) then 1 when(NeedToPay-a.SJAmount=Standard) then 0 else 4 end)
from [dbo].[FinaChargeStuOrderDetail] a left join [dbo].[FinaChargeStuYearItem] b on a.ChargeItemCode=b.ChargeItemCode
where a.[FCSOId]='" + item.Id + "' and b.FSYId='"+item.FSYId+"'");
where a.[FCSOId]='" + item.Id + "' and b.FSYId='"+item.FSYId+"'");
//FinaChargeStuYear表
conn.Execute(@" update FinaChargeStuYear set SJAmount=aa.SJAmount,NeedToPay=aa.NeedToPay,PayFeeStatus=(case when(aa.NeedToPay<=0) then 1 else 4 end)
from (select isnull(sum(a.[NeedToPay]),0) as [NeedToPay],isnull(sum(a.SJAmount),0) as SJAmount,a.FSYear,b.StuNo from FinaChargeStuYearItem a left join FinaChargeStuYear b on a.FSYId=b.FSYId
group by a.FSYear,b.StuNo ) aa left join
FinaChargeStuYear b on aa.stuno=b.stuno and aa.FSYear=b.FSYear
where aa.StuNo='" + item.StuNo+"' and aa.FSYear='"+item.YearNo+"'");
where aa.StuNo='" + item.StuNo+"' and aa.FSYear='"+item.YearNo+"'");
//FinaChargeStudent表
conn.Execute(@"update FinaChargeStudent set NeedToPay=a.NeedToPay
from (select isnull(sum([NeedToPay]),0) as [NeedToPay],StuNo from [FinaChargeStuYear] group by StuNo) a left join
FinaChargeStudent b on a.stuno=b.stuno where a.stuno='" + item.StuNo+"'");
FinaChargeStudent b on a.stuno=b.stuno where a.stuno='" + item.StuNo+"'");
//FinaChargeStuBalance流水表
//记录缴费后余额、待缴金额
var newFinaChargeStuYearItem = conn.Query<FinaChargeStuYearItemEntity>(@"select b.* from [dbo].[FinaChargeStuOrderDetail] a left join [dbo].[FinaChargeStuYearItem] b on a.ChargeItemCode=b.ChargeItemCode
where a.[FCSOId] = '" + item.Id + "' and b.FSYId = '" + item.FSYId + "'");
IEnumerable<FinaChargeStuOrderDetailEntity> detaillist =conn.Query<FinaChargeStuOrderDetailEntity>("select * from FinaChargeStuOrderDetail where FCSOId='"+item.Id+"'");
IEnumerable<FinaChargeStuOrderDetailEntity> detaillist =conn.Query<FinaChargeStuOrderDetailEntity>("select * from FinaChargeStuOrderDetail where FCSOId='"+item.Id+"'");
foreach (var finaChargeStuOrderDetailEntity in detaillist)
{
if (finaChargeStuOrderDetailEntity.SJAmount>0)
if (finaChargeStuOrderDetailEntity.SJAmount>0)
{
//计算学生缴费项目当前欠缴金额
var olditem = oldFinaChargeStuYearItem.FirstOrDefault(m => m.ChargeItemCode == finaChargeStuOrderDetailEntity.ChargeItemCode);
@@ -214,8 +250,8 @@ group by a.FSYear,b.StuNo ) aa left join
"'0','" + newitem.FSBlance + "',getdate(),'1')");
}
}
int PayFeeStatus = Convert.ToInt32(conn.ExecuteScalar("select PayFeeStatus from FinaChargeStuYear where StuNo='"+item.StuNo+"' and FSYear='"+item.YearNo+"'"));
if (PayFeeStatus==1)
int PayFeeStatus = Convert.ToInt32(conn.ExecuteScalar("select PayFeeStatus from FinaChargeStuYear where StuNo='"+item.StuNo+"' and FSYear='"+item.YearNo+"'"));