tijian_jichuang/Code/SOH.BLL.Host/t_tjhkBll.cs
2025-02-20 11:54:48 +08:00

330 lines
13 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SOH.Entities;
using SOH.Data;
using EAS.Services;
using EAS.Data.ORM;
using EAS.Data.Linq;
using SOH.Entities.DTO;
using EAS.Data.Access;
namespace SOH.BLL
{
[ServiceObject("团检应收回款")]
[ServiceBind(typeof(It_tjhk))]
public class t_tjhkBll : It_tjhk
{
public List<dto_tjkhht> GetKhhts(string khmc, int htbm, short nd,short fddm)
{
using (DbEntities db = new DbEntities())
{
bool skhmc = string.IsNullOrEmpty(khmc) ? true : false;
bool shtbm = htbm == 0 ? true : false;
bool snd = nd == 0 ? true : false;
var data = from a in db.t_hts
join b in db.t_khs
on a.khbm equals b.khbm
where true && (skhmc ? true : b.khmc.Contains(khmc)) && (shtbm ? true : a.htbm == htbm) && (snd ? true : a.nd == nd)&&a.fddm==fddm
select new dto_tjkhht
{
htbm = a.htbm,
khbm = a.khbm,
khmc = b.khmc,
nd = a.nd,
htbj = a.htbj,
htqsrq = a.htqsrq,
htjzrq = a.htjzrq,
ywdbdm = b.khlxr,
xsydh = a.khlxrdh,
htzt = a.htzt
};
if (data.Any())
{
return data.ToList();
}
else
{
return null;
}
}
}
public List<dto_tjhtzx> GetTjqk(int htbm)
{
using (DbEntities db = new DbEntities())
{
//var data = from a in db.t_ttgzbs
// join b in db.t_htfzbs on a.htfzbm equals b.htfzbm
// where a.htbm == htbm
// select new Entities.DTO.dto_tjfzxx
// {
// tm = a.tm,
// tmztz = a.tmztz,
// tjztz = (short)((a.tmztz > 0 || a.tmztz == -2) ? 1 : 0),
// htfzbm=a.htfzbm,
// htfzmc =b.htfzmc,
// fzjg=b.fzjg,
// fzzl=b.fzzl,
// ssjg=b.ssjg,
// gzfbj=b.gzfbj,
// jxgzfbj=b.jxgzfbj,
// czjjxbj=a.czjjxbj
// };
var data = from a in db.t_ttgzbs
join b in db.t_htfzbs on a.htfzbm equals b.htfzbm
where a.htbm == htbm&&b.gzfbj==0 //gzfbj=0标记团检公费
select new Entities.DTO.dto_tjfzxx
{
//tm = a.tm,
tmztz = a.tmztz,
tjztz = (short)((a.tmztz > 0 || a.tmztz == -2) ? 1 : 0),
htfzbm = a.htfzbm,
htfzmc = b.htfzmc,
fzjg = b.fzjg,
fzzl = b.fzzl,
ssjg = b.ssjg,
gzfbj = b.gzfbj,
jxgzfbj = b.jxgzfbj,
czjjxbj = a.czjjxbj
}
into k
group k by new { k.htfzbm, k.htfzmc, k.fzjg, k.ssjg, k.fzzl, k.gzfbj, k.jxgzfbj } into t
select new dto_tjhtzx
{
htfzbm = t.Key.htfzbm,
htfzmc = t.Key.htfzmc,
fzjg = t.Key.fzjg / 100,
fzzl = t.Key.fzzl,
ssjg = t.Key.ssjg / 100,
gzfbj = t.Key.gzfbj,
jxgzfbj = t.Key.jxgzfbj,
gzfbjmc = t.Key.gzfbj == 0 ? "公费" : "自费",
jxgzfbjmc = t.Key.jxgzfbj == 0 ? "公费" : "自费",
sjrs = t.Where(e => e.tmztz > 1 || e.tmztz == -2).Count(),
sjje = t.Where(e => e.tmztz > 1 || e.tmztz == -2).Sum(e => e.ssjg) / 100,
djyj= t.Where(e => e.tmztz > 1 || e.tmztz == -2).Sum(e => e.fzjg) / 100,
wjrs = t.Where(e => e.tmztz == 0 || e.tmztz == 1).Count(),
wjje = t.Where(e => e.tmztz == 0 || e.tmztz == 1).Sum(e => e.ssjg) / 100,
wdjyj = t.Where(e => e.tmztz == 0 || e.tmztz == 1).Sum(e => e.fzjg) / 100
};
if (data.Any())
{
return data.ToList();
}
else
{
return null;
}
}
}
public OperationResult DeleteWjry(List<t_ttgzb> ltt)
{
OperationResult or = new OperationResult();
if (ltt == null || ltt.Count == 0)
{
or.State = 0;
or.Message = "未找到要删除的未检人员";
return or;
}
using (DbEntities db = new DbEntities())
{
var tran = db.CreateTransaction();
try
{
for (int i = 0; i < ltt.Count; i++)
{
string sqldel1 = "delete from t_ttgzb where tm=" + ltt[i].tm + " and tmztz in (-1,0)";
db.DataAccessor.Execute(sqldel1);
}
tran.Commit();
or.State = 1;
or.Message = "未检人员删除成功";
return or;
}
catch (Exception ex)
{
tran.Rollback();
or.State = 0;
or.Message = "未检人员删除失败:"+(ex.InnerException??ex).Message;
return or;
}
}
}
//将未检人员设置为待查
public OperationResult SetDaiCha(List<t_ttgzb> ltt)
{
OperationResult or = new OperationResult();
if (ltt == null || ltt.Count == 0)
{
or.State = 0;
or.Message = "未找到要设置为待查的人员";
return or;
}
using (DbEntities db = new DbEntities())
{
var tran = db.CreateTransaction();
try
{
for (int i = 0; i < ltt.Count; i++)
{
string sqldel1 = "update t_ttgzb set tmztz=-2 where tm=" + ltt[i].tm + " and tmztz in (-1,0)";
db.DataAccessor.Execute(sqldel1);
}
tran.Commit();
or.State = 1;
or.Message = "设置待查成功";
return or;
}
catch (Exception ex)
{
tran.Rollback();
or.State = 0;
or.Message = "设置待查失败:" + (ex.InnerException ?? ex).Message;
return or;
}
}
}
/// <summary>
/// 合同结账
/// </summary>
/// <param name="htbm"></param>
/// <returns></returns>
public OperationResult HtJieZhang(int htbm)
{
OperationResult or = new OperationResult();
using (DbEntities db = new DbEntities())
{
//首先判断合同是否可以结账
//1.查询是否有未检人员
var datawj = from a in db.t_ttgzbs where a.htbm == htbm && (a.tmztz == 0 || a.tmztz == -1) select a;
if(datawj.Any())
{
or.State = 0;
or.Message = "合同分组中含有未检人员,结账前请先删除未检人员";
return or;
}
//2.判断交款总额是否大于公费体检金额
int jkje = 0; //交款总金额
int tjje = 0; //体检公费总金额
var data1 = from a in db.t_ttsfjls
where a.htbm == htbm
select a;
if (data1.Any())
{
jkje= data1.Sum(t => t.je);
}
//gzfbj是标识团检公费还是自费自费的不在这个计算之列
var data2 = from a in db.t_ttgzbs
join b in db.t_htfzbs
on a.htfzbm equals b.htfzbm
where a.htbm == htbm && a.tmztz != 0 && a.tmztz != -1 && b.gzfbj == 0
select new
{
a.tm,
b.ssjg
};
if (data2.Any()) //有人员进行了体检
{
tjje += data2.Sum(t => t.ssjg);
}
//查找公费加项里面的信息,t_jjxb中jjx=0的是加项
var data3 = from a in db.t_ttgzbs
join b in db.t_htfzbs on a.htfzbm equals b.htfzbm
join c in db.t_jjxbs
on a.tm equals c.tm
where a.htbm == htbm && a.tmztz != 0 && a.tmztz != -1 && b.jxgzfbj == 0 && c.jjx == 0
select new
{
a.tm,
c.jjxje
};
if (data3.Any())
{
tjje += data3.Sum(t => t.jjxje);
}
if(jkje<tjje) //
{
or.State = 0;
or.Message = "应交款不足(应交款小于公费体检金额),无法结账";
return or;
}
else
{
//var tran = db.CreateTransaction();
//进行结账
try
{
string sql1 = "update t_ht set htzt=2,JIEZHANGRQ=getdate(),upflag=0 where htbm="+htbm;
int result=db.DataAccessor.Execute(sql1);
if(result>0)
{
or.State = 1;
or.Message = "合同结账成功";
return or;
}
else
{
or.State = 0;
or.Message = "合同结账失败,未找到对应合同或发生系统错误";
return or;
}
}
catch(Exception ex)
{
or.State = 0;
or.Message = "合同结账失败:"+(ex.InnerException??ex).Message;
return or;
}
}
}
}
/// <summary>
/// 合同反结
/// </summary>
/// <param name="htbm"></param>
/// <returns></returns>
public OperationResult HtFanJie(int htbm)
{
OperationResult or = new OperationResult();
using (DbEntities db=new DbEntities())
{
try
{
string sql = "update t_ht set htzt=1,noJIEZHANGRQ=getdate(),upflag=1 where htbm=" + htbm;
int result = db.DataAccessor.Execute(sql);
if (result > 0)
{
or.State = 1;
or.Message = "合同反结成功";
return or;
}
else
{
or.State = 0;
or.Message = "合同反结失败,未找到对应合同或者发生系统错误";
return or;
}
}
catch(Exception ex)
{
or.State = 0;
or.Message = "合同反结失败:" + (ex.InnerException ?? ex).Message;
return or;
}
}
}
}
}